From patchwork Fri Apr 22 08:49:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 8907181 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0B1A1BF29F for ; Fri, 22 Apr 2016 08:55:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 28E06201C0 for ; Fri, 22 Apr 2016 08:55:33 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0E644201B4 for ; Fri, 22 Apr 2016 08:55:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1atWqI-0003AV-UP; Fri, 22 Apr 2016 08:53:38 +0000 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1atWqG-00032t-Aq for linux-arm-kernel@lists.infradead.org; Fri, 22 Apr 2016 08:53:36 +0000 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u3M8qIJU010891; Fri, 22 Apr 2016 01:53:11 -0700 Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 22bmwfjuv3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 22 Apr 2016 01:53:11 -0700 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1104.5; Fri, 22 Apr 2016 01:53:09 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server id 15.0.1104.5 via Frontend Transport; Fri, 22 Apr 2016 01:53:09 -0700 Received: from xhacker.marvell.com (unknown [10.37.130.144]) by maili.marvell.com (Postfix) with ESMTP id E39C23F7041; Fri, 22 Apr 2016 01:53:08 -0700 (PDT) From: Jisheng Zhang To: , , , Subject: [PATCH v4] i2c: designware-platdrv: fix unbalanced clk enable and prepare Date: Fri, 22 Apr 2016 16:49:31 +0800 Message-ID: <1461314971-5944-1-git-send-email-jszhang@marvell.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-04-22_07:, , signatures=0 X-Proofpoint-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1603290000 definitions=main-1604220126 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160422_015336_529077_EB96E628 X-CRM114-Status: GOOD ( 10.52 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jisheng Zhang , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If i2c_dw_probe() fails, we should disable and unprepare the clock, otherwise the clock enable and prepare is left unbalanced. In dw_i2c_plat_remove(), we'd better to not rely on runtime PM to disable and unprepare the clock since CONFIG_PM may be disabled when configuring the kernel. So we explicitly disable and unprepare the clock in dw_i2c_plat_remove() rather than implicitly rely on pm_runtime_put_sync(). To keep the device usage count balanced, we call pm_runtime_put_noidle() to decrease the usage count. Signed-off-by: Jisheng Zhang --- Since v3: - use runtime PM rather than rpm in commit msg - remove duplicated "(" in commit msg Since v2:  - s/clk/clock  - describe why use pm_runtime_put_noidle() Since v1:  - fix commit msg: "not rely on rpm" rather than "rely on rpm"  - call i2c_dw_plat_prepare_clk after pm_rumtime_disable() drivers/i2c/busses/i2c-designware-platdrv.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index d656657..a771781 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -253,8 +253,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) } r = i2c_dw_probe(dev); - if (r && !dev->pm_runtime_disabled) - pm_runtime_disable(&pdev->dev); + if (r) { + if (!dev->pm_runtime_disabled) + pm_runtime_disable(&pdev->dev); + i2c_dw_plat_prepare_clk(dev, false); + } return r; } @@ -264,15 +267,16 @@ static int dw_i2c_plat_remove(struct platform_device *pdev) struct dw_i2c_dev *dev = platform_get_drvdata(pdev); pm_runtime_get_sync(&pdev->dev); + pm_runtime_dont_use_autosuspend(&pdev->dev); + if (!dev->pm_runtime_disabled) + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); i2c_del_adapter(&dev->adapter); i2c_dw_disable(dev); - pm_runtime_dont_use_autosuspend(&pdev->dev); - pm_runtime_put_sync(&pdev->dev); - if (!dev->pm_runtime_disabled) - pm_runtime_disable(&pdev->dev); + i2c_dw_plat_prepare_clk(dev, false); return 0; }