From patchwork Fri Dec 23 13:40:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 9487451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 17B45600CB for ; Fri, 23 Dec 2016 13:43:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 085DD20072 for ; Fri, 23 Dec 2016 13:43:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F131A2041F; Fri, 23 Dec 2016 13:43:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 2AD0820072 for ; Fri, 23 Dec 2016 13:43:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cKQ6Z-00065h-NW; Fri, 23 Dec 2016 13:41:51 +0000 Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cKQ6U-00061a-Rj for linux-arm-kernel@lists.infradead.org; Fri, 23 Dec 2016 13:41:47 +0000 Received: by mail-pf0-x231.google.com with SMTP id i88so44536691pfk.2 for ; Fri, 23 Dec 2016 05:41:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=F7himK1UFk7MbH5VpJJ/DrZ4264P6tvKl1RMHwH20go=; b=Ay7XY8jKEHX4S+SjM3H/k1O4Ym7/7R8NoBraCG2OLRmwngytUNOrILAgvSk3dmt0Tw dudUhqi/6HSaluYv4T1HS0Are0358ub0+M5e4fBL9vL9LHXFlBv6k7wnF+Qa1L5M3/FK 57mhtsh/+Rmup+LF9P/z+O8ZtYovY5y5mZBpI= 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; bh=F7himK1UFk7MbH5VpJJ/DrZ4264P6tvKl1RMHwH20go=; b=mLiBa1enSTqRcDyxIOANFIvor7ID/8Ont6BKj5nIYruNRzFTRA8i44cwvodO5UUqeV qD/T1z3Fn8srFndTd/ZdE3Oqyd0JaG9zpik22GQjAJciCwmgxargdgFtWpbFI7INfOjb qLejJcoi2rL+rHFMUN4iVAcnrEj5fU/T2QWKRLRJ7sqEyrvsQ3X4+k1cA/1EVq2x+W09 fIGjHEdBcXGTtvh4yYh35BZnDy8NHi8DR7pK6HV7PB5IJJSFW5FXmzLTUX/7LzEZTsXe AhrJHsPsIVpzLP+7MstaueYh6Ks6sEPoWZGgqUoSGl3uz2Ie36B3+4G/kIDFm1jYkdxN fcEQ== X-Gm-Message-State: AIkVDXJ3x8fZhvdJ5NxYC/3vchKcYoyiefPfohktc1GiVFPjj38TXuhmErUNU8vZcLo/C5eP X-Received: by 10.98.12.138 with SMTP id 10mr13186079pfm.82.1482500485932; Fri, 23 Dec 2016 05:41:25 -0800 (PST) Received: from localhost.localdomain ([104.237.91.30]) by smtp.gmail.com with ESMTPSA id g77sm11021103pfk.50.2016.12.23.05.41.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Dec 2016 05:41:25 -0800 (PST) From: Zhangfei Gao To: Wolfram Sang , andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, jarkko.nikula@linux.intel.com, p.zabel@pengutronix.de Subject: [PATCH v3] i2c: designware: add reset interface Date: Fri, 23 Dec 2016 21:40:51 +0800 Message-Id: <1482500451-30137-1-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161223_054146_933524_C0D92C16 X-CRM114-Status: GOOD ( 14.56 ) 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: Zhangfei Gao , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some platforms like hi3660 need do reset first to allow accessing registers Signed-off-by: Zhangfei Gao Reviewed-by: Andy Shevchenko Tested-by: Ramiro Oliveira --- drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index 0d44d2a..94b14fa 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -80,6 +80,7 @@ struct dw_i2c_dev { void __iomem *base; struct completion cmd_complete; struct clk *clk; + struct reset_control *rst; u32 (*get_clk_rate_khz) (struct dw_i2c_dev *dev); struct dw_pci_controller *controller; int cmd_err; diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 0b42a12..1fbe66f 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -176,6 +177,14 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) dev->irq = irq; platform_set_drvdata(pdev, dev); + dev->rst = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL); + if (IS_ERR(dev->rst)) { + if (PTR_ERR(dev->rst) == -EPROBE_DEFER) + return -EPROBE_DEFER; + } else { + reset_control_deassert(dev->rst); + } + /* fast mode by default because of legacy reasons */ dev->clk_freq = 400000; @@ -207,12 +216,13 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) && dev->clk_freq != 1000000 && dev->clk_freq != 3400000) { dev_err(&pdev->dev, "Only 100kHz, 400kHz, 1MHz and 3.4MHz supported"); - return -EINVAL; + r = -EINVAL; + goto exit_reset; } r = i2c_dw_eval_lock_support(dev); if (r) - return r; + goto exit_reset; dev->functionality = I2C_FUNC_I2C | @@ -270,10 +280,18 @@ 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) + goto exit_probe; return r; + +exit_probe: + if (!dev->pm_runtime_disabled) + pm_runtime_disable(&pdev->dev); +exit_reset: + if (!IS_ERR_OR_NULL(dev->rst)) + reset_control_assert(dev->rst); + return r; } static int dw_i2c_plat_remove(struct platform_device *pdev) @@ -290,6 +308,8 @@ static int dw_i2c_plat_remove(struct platform_device *pdev) pm_runtime_put_sync(&pdev->dev); if (!dev->pm_runtime_disabled) pm_runtime_disable(&pdev->dev); + if (!IS_ERR_OR_NULL(dev->rst)) + reset_control_assert(dev->rst); return 0; }