From patchwork Thu Sep 5 16:17:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 173169 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp936406ilq; Thu, 5 Sep 2019 09:19:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxg2tFNBizYP5eZ0q6CEPObau+kipbnzg6n/jrX22FEuz9/jAUZyCY/LUIwEZX+TH34f9sh X-Received: by 2002:aa7:9085:: with SMTP id i5mr4901078pfa.136.1567700357114; Thu, 05 Sep 2019 09:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567700357; cv=none; d=google.com; s=arc-20160816; b=bBiq+gOnaXNed+dZ1sL9VXvdhN5e7uRZJZ6PsAJ2I+g0s2PXtfr6Ta4dIy+B2DagkO mobl6G5wn3VEobei5cMcrh/8+9LeFCqRPn5aEPlKAjAVgnOy8ZwgiDXqNmdGymzO4X5G ChbTBe7HVHVR98xcP1d3EhiKV/dRjd2noknVwm0NEjINAG2gk9Z/mm+m1sQ2HJw/gdWc J/cXVoPtEh3zMCPxPN092KqCx28aep2yMy2va8OfVj+V11A7H7+vv8vU8+od70LCPIfj qsTYSxBMu7zUP/7wiPVwl6WYhqKfzjvUS00hb7CSUGIvHIy+UuGOsGhNH9Cm5+36ZClf UVyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=gVFpbnmwR/H0XIcZNgb2GdBzjOFgaobM9Yxc91rkUEw=; b=b3l/W6Fi0icuP8/Ex21+LF8qiI2JZSRxYtn/zmAYZ+FNDoBVRcj0+ROYlqMLU0xc85 SGcq5qESFEZQl1Y7pC+MvOPUxQjDkLcsg6QhEXtLiNrONjmpf74FV5OcTHAvA6FLN31R eIjxPPwMZwwKyipd/Wo4VgiD3vqRSvRbgHOGk5b+phXkjWRgPVLhAF/C5YKem0GjgGgJ ErzrO1INOROmk3nGQzvEHsjjagZR21Ne/kgAFyVMd29gcjL2YbZ7U6OYoiiBIfL4fdMR XhltOY0udBNC4G8K59uviaIjCKzzHOyyvjaDhFureNNDkKk3OIY6foKZ6Ci5yZAugGH5 0MSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Dr/9HzD6"; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n23si2377768plp.273.2019.09.05.09.19.16; Thu, 05 Sep 2019 09:19:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Dr/9HzD6"; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389407AbfIEQTP (ORCPT + 5 others); Thu, 5 Sep 2019 12:19:15 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:38511 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388240AbfIEQSO (ORCPT ); Thu, 5 Sep 2019 12:18:14 -0400 Received: by mail-pl1-f194.google.com with SMTP id w11so1536451plp.5 for ; Thu, 05 Sep 2019 09:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gVFpbnmwR/H0XIcZNgb2GdBzjOFgaobM9Yxc91rkUEw=; b=Dr/9HzD6iWPfceKw7JxoqfNkPUkVwEJIvJ6qPHqxv0lvskG3nUTwAbc8W7CdTnpWNZ E7/74MJVoS89JAhyqoEzJccajtDV8UlDwLBe8qTFagb2kZG4kmB7cyrIpxAKBzTCNmzu paRFo5MSQ8Hzwh37g3MidoLPOqizim/nuyd3ERaPZo1p8+qfX3DuSC9+dQks+Ezp/Lj/ d9GaXIqusviMB8769avG6rrHw+IRW05Bhx3JuyBbS04PBMIjMsAbUalHeiMMPmdUGQNc APry6qeospuB2zMpOCseNSbRDbfzQdeqsw9Wj1F3zJq1Wuh8fO/rKTkiE1tnL3tT+yyv YTuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gVFpbnmwR/H0XIcZNgb2GdBzjOFgaobM9Yxc91rkUEw=; b=YvGADZTCIJGBhuD90cm3MPwimS8E4aptLpP9lzVR9uRoyw3r9hdWi0LYJhpURX5Nzd udd+YyMNCgs8VyVaZcVdLPbBWM6OPhmLQZL7Mo2ghuFcooHUNGZd141bFMfywyUk0+2P gssD6myusGq/FIze0YeTAqoGu9/M4Vog/BSGdRyDg+weH8ytIIUZ0kSImU+x6K9l7bYE xxI0Wpm23U9e+qwpiFp4LHSbbTFeFTfqCDIWWlRffEmxKebhMgitrmtYtwAvKpjMIX+R lCp+lYjjQ57/ActeU6stTDXrH53xaHmQ9wfn2RvXJeXGh0zN1JuEGwk9HTKxRt7nRHLz TFKA== X-Gm-Message-State: APjAAAXSB1me0IGXEj+n1s65CHk0IABxHVSeYEVw1Y1X0xs1uMcHMcP7 hwasEiing/vdOBwV+LFa1SMlL87zbBQ= X-Received: by 2002:a17:902:9f97:: with SMTP id g23mr4381121plq.248.1567700293310; Thu, 05 Sep 2019 09:18:13 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id m129sm6324005pga.39.2019.09.05.09.18.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2019 09:18:12 -0700 (PDT) From: Mathieu Poirier To: stable@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-omap@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pci@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [BACKPORT 4.14.y 10/18] PCI: dra7xx: Add shutdown handler to cleanly turn off clocks Date: Thu, 5 Sep 2019 10:17:51 -0600 Message-Id: <20190905161759.28036-11-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190905161759.28036-1-mathieu.poirier@linaro.org> References: <20190905161759.28036-1-mathieu.poirier@linaro.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Keerthy commit 9c049bea083fea21373b8baf51fe49acbe24e105 upstream Add shutdown handler to cleanly turn off clocks. This will help in cases of kexec where in a new kernel can boot abruptly. Signed-off-by: Keerthy Signed-off-by: Bjorn Helgaas Acked-by: Kishon Vijay Abraham I Signed-off-by: Mathieu Poirier --- drivers/pci/dwc/pci-dra7xx.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) -- 2.17.1 diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c index 7f5dfa169d0f..2e0d0b29cdcb 100644 --- a/drivers/pci/dwc/pci-dra7xx.c +++ b/drivers/pci/dwc/pci-dra7xx.c @@ -817,6 +817,22 @@ static int dra7xx_pcie_resume_noirq(struct device *dev) } #endif +void dra7xx_pcie_shutdown(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev); + int ret; + + dra7xx_pcie_stop_link(dra7xx->pci); + + ret = pm_runtime_put_sync(dev); + if (ret < 0) + dev_dbg(dev, "pm_runtime_put_sync failed\n"); + + pm_runtime_disable(dev); + dra7xx_pcie_disable_phy(dra7xx); +} + static const struct dev_pm_ops dra7xx_pcie_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend, dra7xx_pcie_resume) SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend_noirq, @@ -830,5 +846,6 @@ static struct platform_driver dra7xx_pcie_driver = { .suppress_bind_attrs = true, .pm = &dra7xx_pcie_pm_ops, }, + .shutdown = dra7xx_pcie_shutdown, }; builtin_platform_driver_probe(dra7xx_pcie_driver, dra7xx_pcie_probe); From patchwork Thu Sep 5 16:17:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 173167 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp936062ilq; Thu, 5 Sep 2019 09:19:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVNgeNAi1cup3NLf4feEXf5CpDT7kvdAhqvzOvT0PkLGDusRPJf0MLJWNwPJ0krBek77jj X-Received: by 2002:a17:902:9f82:: with SMTP id g2mr4404014plq.63.1567700341946; Thu, 05 Sep 2019 09:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567700341; cv=none; d=google.com; s=arc-20160816; b=LBrORO7EEA+lEAmy3cJA7EpWxfaDV6my9xpJdwwzP+1ZW6iwBXzlzPIqQi+VDVDJYU qrcqBNlfEy790KOkTfKWRQdQ8PfcDM/J9HjtT2NtqjVEY0x8LztfxLCp2Y75iZkmDj1E /Sz1STo6jl3tMOraTjOjncD5fOPXRKaOQDDKjeGw6H9q7SyGjXZav0dhwolE4Xee/rpw mQ4dJB6rP/bc9ygIQI0KUOa+u/jKXDXo21NL24UiCyyo+EvI99PHl9Fv69qZwJUUyoZR ROS4x4s2K5DQOGus3t53s0Sctitpx2LgcRx/o5jRBWAqSx7Kd7/sRbmYcGo1jQ9BlxdJ KUiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=tpqdWISBmI7/K+eXW/BM3B61WGwPfixYNx9jyTHk1dU=; b=yIkmiJFDeRAGuIhDoCqb2PZUhA/bSRYEtsNkQI+VdqQqnK4qG9Tjt708B62JU2tWrJ W3YFTSPXA7pFlCaRF0lfqd0M4IUEUmdV1GF5tGRp6g58TVM2/P3Nsywd6wWBAeVIQQuX qKgmdlX2h3CJP2reHAl0lAY6/ZD3ArUkqCXqmia5XyI6wL/P6nKxAKmWJyt368K2Ihkb NgKrdQN2ijEJNYnWY8TYuuqiCppS53PrGrj4ubeBHxpCqi5vqZLg5EdjEi3mexUIJtVN V14vOGNI/4He50S9WQ7AEoqYATVWM2GAD8pRlOTn5J2/1atk7ggjxApOiQFKjuiOPN62 HExQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K5DiiY2F; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6si2276359pge.44.2019.09.05.09.19.01; Thu, 05 Sep 2019 09:19:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K5DiiY2F; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388442AbfIEQSP (ORCPT + 5 others); Thu, 5 Sep 2019 12:18:15 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38108 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388334AbfIEQSP (ORCPT ); Thu, 5 Sep 2019 12:18:15 -0400 Received: by mail-pf1-f194.google.com with SMTP id h195so2075907pfe.5 for ; Thu, 05 Sep 2019 09:18:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tpqdWISBmI7/K+eXW/BM3B61WGwPfixYNx9jyTHk1dU=; b=K5DiiY2Fgz6MUrPKTtz10HsJkolwwVvGrdqBD69mgIMaQbkMXiTRCgCbb2ZyUxaTSS TsurgVMOb8XwbIXgdyeF+rfzsvnXsAM1sHLEQ4y5Ke840f0eEdtxvvN3Pb5ZdVwNLiXE UV+r4cWr5AN6DgFXtNn2GrDrgfsbA6uZcFqrnHfIbgan0lx/1+ZKIyh6gDp63fdh/v9I KCxMrdpVzkF4eB9dCxcnzu4IORv5zjU09dggJmJTVefvcrHEGmUqyNXgA3hCndJldZef 81oH34LbhykA0VcHebAOIDd2RLBykltXAikm9fusMU2Bx4GGt+Kmw89s92q1rKZ+QSBQ hcng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tpqdWISBmI7/K+eXW/BM3B61WGwPfixYNx9jyTHk1dU=; b=ZPRvt+xL8h2o7N4L39NLKNAh3K1CoALHZIw1Kg+zPN+RWMUN3kCFarFuuP0P6ycLW+ IuN/ENyk6VJSYeZw+J+bY3hpivIHf5l8qxmq+JCZ4zdzw79qNXBkAUAHgLCXMvPdw8Z2 P4kJhh01OqZhVZmGLRgI3GPr/8P+k0ZQnjMV6YIaUqY+dDrpe3xx/0IPX+/bI0i/08lc rRFLP+6S8pzMsPbCDgapg2zB+RCtaH671E/XIC32TFcGKC1fHcl+obGkQt8GrURNcjQ0 S8clTrHBTkZN9oAs+KB6+9DKVlAHk031hrFtoFIt85PYAT8Z5gCCDYXsh+gpiuHMEUSC W0tw== X-Gm-Message-State: APjAAAWqU6DVzPYXeUdZtZziDmNWFZJamz6u34mZ1UBj/Hn0XhO9Ifpy cp1iYixgqnm9ozwv3a7pF+UcAg== X-Received: by 2002:aa7:8e08:: with SMTP id c8mr849847pfr.238.1567700294324; Thu, 05 Sep 2019 09:18:14 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id m129sm6324005pga.39.2019.09.05.09.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2019 09:18:13 -0700 (PDT) From: Mathieu Poirier To: stable@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-omap@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pci@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [BACKPORT 4.14.y 11/18] misc: pci_endpoint_test: Fix BUG_ON error during pci_disable_msi() Date: Thu, 5 Sep 2019 10:17:52 -0600 Message-Id: <20190905161759.28036-12-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190905161759.28036-1-mathieu.poirier@linaro.org> References: <20190905161759.28036-1-mathieu.poirier@linaro.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Kishon Vijay Abraham I commit b7636e816adcb52bc96b6fb7bc9d141cbfd17ddb upstream pci_disable_msi() throws a Kernel BUG if the driver has successfully requested an IRQ and not released it. Fix it here by freeing IRQs before invoking pci_disable_msi(). Signed-off-by: Kishon Vijay Abraham I Signed-off-by: Bjorn Helgaas Signed-off-by: Mathieu Poirier --- drivers/misc/pci_endpoint_test.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.17.1 diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 504fa680825d..230f1e8538dc 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -92,6 +92,7 @@ struct pci_endpoint_test { void __iomem *bar[6]; struct completion irq_raised; int last_irq; + int num_irqs; /* mutex to protect the ioctls */ struct mutex mutex; struct miscdevice miscdev; @@ -514,6 +515,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, irq = pci_alloc_irq_vectors(pdev, 1, 32, PCI_IRQ_MSI); if (irq < 0) dev_err(dev, "failed to get MSI interrupts\n"); + test->num_irqs = irq; } err = devm_request_irq(dev, pdev->irq, pci_endpoint_test_irqhandler, @@ -581,6 +583,9 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, pci_iounmap(pdev, test->bar[bar]); } + for (i = 0; i < irq; i++) + devm_free_irq(dev, pdev->irq + i, test); + err_disable_msi: pci_disable_msi(pdev); pci_release_regions(pdev); @@ -594,6 +599,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, static void pci_endpoint_test_remove(struct pci_dev *pdev) { int id; + int i; enum pci_barno bar; struct pci_endpoint_test *test = pci_get_drvdata(pdev); struct miscdevice *misc_device = &test->miscdev; @@ -609,6 +615,8 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) if (test->bar[bar]) pci_iounmap(pdev, test->bar[bar]); } + for (i = 0; i < test->num_irqs; i++) + devm_free_irq(&pdev->dev, pdev->irq + i, test); pci_disable_msi(pdev); pci_release_regions(pdev); pci_disable_device(pdev); From patchwork Thu Sep 5 16:17:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 173161 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp935248ilq; Thu, 5 Sep 2019 09:18:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+pRhKYuEnvE3CThgimIVw5TpRtan8ZWwhAGnST8wCob248r0dzc29cHNB215HtFaBP1P6 X-Received: by 2002:a63:cc14:: with SMTP id x20mr4011220pgf.142.1567700306199; Thu, 05 Sep 2019 09:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567700306; cv=none; d=google.com; s=arc-20160816; b=IgS9uFhb5TPg8N51U2c2mYrRKFtgyeT1/SYJXRfmyYqyOSui3XNqK/VHS6c9aRYwsG SxY7n3pB5yIBGYE+rYxwDLm4hsKLiqFNI7nga1p6mUbHzQ4kaRqg6ginJaeIjzR7q691 fhNOyXU5aclB7Yw09EaJzLugsszLRZV99AcdDDNRKMPt2cEMMzPNYHljr16pGLtBDvto x55oWN8InbPBP0R/lU0R6BxX7DQbpLVEfM60hvZTOG5NBpUJZyTzFjr7UdGd6MooxgB3 qBrJg1pY402ZIxokwrVSNnk2IPnJnlqPrnE3HLrmcnXs+cDcfnriFAQDV0xG72gpMKsF Nshw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=hTEru9Lo54OU309HOwpQ2LAFUsKEGLtu5GnynJbae0I=; b=V9mWPrDbCFux0lCT0bFNYxuN1JC1b2LjS9L0ObgKfC3L4IZpjLA4p8wcApUjkX30dH pRShq8IQircHNSYMGDoPgLLGI/+eaGRnSU90zmpYQHHf+CVK8Ccy5Ta1t7p6Gbl8llwY rfq1rceyr0A9ohIRqiIMxe3TP2xfjdYiPpLVlioAYM3QpWMPJLZcBQBpV3rA51j95R5p j/svh7ep5N8o31oTSlqQiFVda74DaY9Ie5bFuni07AJ6Rva0f9mObV0mIryg62V21a3g GMNqImcgFQwxkdqZzJkN5l/EsVdbYbp+aDEpyKPEgj6ZSkbzdcl8+u4ERL3GxWxOQtu6 y+JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UXrdRBNR; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b13si2148057pgr.460.2019.09.05.09.18.26; Thu, 05 Sep 2019 09:18:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UXrdRBNR; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388874AbfIEQSY (ORCPT + 5 others); Thu, 5 Sep 2019 12:18:24 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37751 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388740AbfIEQSW (ORCPT ); Thu, 5 Sep 2019 12:18:22 -0400 Received: by mail-pf1-f194.google.com with SMTP id y9so2078993pfl.4 for ; Thu, 05 Sep 2019 09:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hTEru9Lo54OU309HOwpQ2LAFUsKEGLtu5GnynJbae0I=; b=UXrdRBNRv4eBFBI2US9eb56BJw2QFySRmdCdiI/+LAIvG/m2c60c9K3NqHc9JzTcvb d8dwqHteqwZIJwmYizpsubVkvO7TeVXDOVTe6aX5zdW2UD3IAtqJ/uiyS9Lx2SPK8Tif Ec3qJAS3tr4mZ7bec9KhbwJfgkz2i4i8m38SHu1mvaoBC5wPzGtmlDymSmvre0XS7bbB i4Ro8UZZSf2iDGafbRHglF0mzarE9YVWxA+kdHTx/AktvE3YQZ90hkW58NANUCfMxmkq vIUoM/uekP6tFp8QDwySUHFho1wZKNrREHBB6M0EcCmSSQ1TR8BMwXKfB/JtNSwWr7kI o+bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hTEru9Lo54OU309HOwpQ2LAFUsKEGLtu5GnynJbae0I=; b=rR0V2Jo375shssr04SDGhzY1jLshfTHqHsBSnDPzkgYYgqaAikHUOeJphGF5AEo76T AW8xvivzQS6Ea/3rwMlGY/LlrgyHHcZ07F10zgVbl865m0o5f/173dfzx8TvhZjlUXAq UnlQoky/siheIEb+xARHKvscwpDlJ1pnWzRV3odbaGFsRIPNKPHUX61YBj7kDM7tHFG4 iZhxWl8YLyvIAS9VSGCfvabwFwP6rhD6fUSFKq4M8QHa6Bjd+i58d43CQyDW5NDgldvu eUkdBiZCYa0vu5tA7BYzJkEUpLbfXbxqVteAn3SleocxO6QKbB7mTqrhXoKdrHYM+xG8 XhWA== X-Gm-Message-State: APjAAAXjSnZr+jD78TjFO1ahgcYgNpeQDakbptM6hI9Lf9R5lNBEm4Nv dXtlipzEG5hEPyOmRYmXv5JRwA== X-Received: by 2002:a63:a35c:: with SMTP id v28mr3980810pgn.144.1567700301882; Thu, 05 Sep 2019 09:18:21 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id m129sm6324005pga.39.2019.09.05.09.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2019 09:18:21 -0700 (PDT) From: Mathieu Poirier To: stable@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-omap@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pci@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [BACKPORT 4.14.y 17/18] i2c: omap: Trigger bus recovery in lockup case Date: Thu, 5 Sep 2019 10:17:58 -0600 Message-Id: <20190905161759.28036-18-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190905161759.28036-1-mathieu.poirier@linaro.org> References: <20190905161759.28036-1-mathieu.poirier@linaro.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Claudio Foellmi commit 93367bfca98f36cece57c01dbce6ea1b4ac58245 upstream A very conservative check for bus activity (to prevent interference in multimaster setups) prevented the bus recovery methods from being triggered in the case that SDA or SCL was stuck low. This defeats the purpose of the recovery mechanism, which was introduced for exactly this situation (a slave device keeping SDA pulled down). Also added a check to make sure SDA is low before attempting recovery. If SDA is not stuck low, recovery will not help, so we can skip it. Note that bus lockups can persist across reboots. The only other options are to reset or power cycle the offending slave device, and many i2c slaves do not even have a reset pin. If we see that one of the lines is low for the entire timeout duration, we can actually be sure that there is no other master driving the bus. It is therefore save for us to attempt a bus recovery. Signed-off-by: Claudio Foellmi Tested-by: Vignesh R Reviewed-by: Grygorii Strashko [wsa: fixed one return code to -EBUSY] Signed-off-by: Wolfram Sang Signed-off-by: Mathieu Poirier --- drivers/i2c/busses/i2c-omap.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index 12ba183693d6..a03564f41ad0 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c @@ -486,6 +486,22 @@ static int omap_i2c_init(struct omap_i2c_dev *omap) return 0; } +/* + * Try bus recovery, but only if SDA is actually low. + */ +static int omap_i2c_recover_bus(struct omap_i2c_dev *omap) +{ + u16 systest; + + systest = omap_i2c_read_reg(omap, OMAP_I2C_SYSTEST_REG); + if ((systest & OMAP_I2C_SYSTEST_SCL_I_FUNC) && + (systest & OMAP_I2C_SYSTEST_SDA_I_FUNC)) + return 0; /* bus seems to already be fine */ + if (!(systest & OMAP_I2C_SYSTEST_SCL_I_FUNC)) + return -EBUSY; /* recovery would not fix SCL */ + return i2c_recover_bus(&omap->adapter); +} + /* * Waiting on Bus Busy */ @@ -496,7 +512,7 @@ static int omap_i2c_wait_for_bb(struct omap_i2c_dev *omap) timeout = jiffies + OMAP_I2C_TIMEOUT; while (omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) { if (time_after(jiffies, timeout)) - return i2c_recover_bus(&omap->adapter); + return omap_i2c_recover_bus(omap); msleep(1); } @@ -577,8 +593,13 @@ static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *omap) } if (time_after(jiffies, timeout)) { + /* + * SDA or SCL were low for the entire timeout without + * any activity detected. Most likely, a slave is + * locking up the bus with no master driving the clock. + */ dev_warn(omap->dev, "timeout waiting for bus ready\n"); - return -ETIMEDOUT; + return omap_i2c_recover_bus(omap); } msleep(1);