From patchwork Thu Dec 15 08:59:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 9475667 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 D1EFC60825 for ; Thu, 15 Dec 2016 09:02:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B28FD2868F for ; Thu, 15 Dec 2016 09:02:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A41A8286FF; Thu, 15 Dec 2016 09:02:46 +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 4E43B2868F for ; Thu, 15 Dec 2016 09:02:46 +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 1cHRuW-0004HQ-B1; Thu, 15 Dec 2016 09:01:08 +0000 Received: from mail-pg0-x22e.google.com ([2607:f8b0:400e:c05::22e]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cHRuS-0004EA-Km for linux-arm-kernel@lists.infradead.org; Thu, 15 Dec 2016 09:01:05 +0000 Received: by mail-pg0-x22e.google.com with SMTP id 3so18110141pgd.0 for ; Thu, 15 Dec 2016 01:00:44 -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:in-reply-to:references; bh=3AdTbzKmdxMHQH+5vX4qlfmgWd8JyFG6w0HaakStms4=; b=KXxgTC4GIcjJWj+ovWEYRx5bY35s4JG9JLvJTpiDfdRMt1jQ4BsHisoYKuOmYEuOAW BSRd+2b+woltzK/UUR6+jAEc2KQRT9OTJN6TV76edYKtWsGsB7dMZ74TQOvybm+spO3l 59jSvOTYWjNmldW9RcRdX3RptoCXMMwV6ym4I= 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=3AdTbzKmdxMHQH+5vX4qlfmgWd8JyFG6w0HaakStms4=; b=K7T3sKER7wfHZw6+B5swehlE+JZnGbSaUzInzGrlL09GMPc1aePlumuK5FSELyWALO krNFUT9F/oP9XTMCmiFkc9T5E7KBH2ZFnTxCD016v/UPTyK7qigx/xNZz6rrqT0tpyJB QqMKvaNRZwe2rFMAheVhGc+1JU7P6aKR1x6HUaT5CeAN1JIpPxGXp0uR8PVOczYL06Gl 6zgCGbQ20hmUxg4CgaDiTGOVicCi4qqSwf+j34udf9ZAMQmv9iHu9h8YDzLB7TRqyMMZ YCmMhFTsCAdRi9uaCtTYCnCXf79JD7pGXv0oomY1Yh5y2LEsXxCllf3EcfQJ+PkkuVhG xsYw== X-Gm-Message-State: AKaTC03gyx/BRCJU9IHfLMsrMj6CtwJttPwB6S3ISpxvcBPmuSZYAPSNwiWJmrTLnRdubqFR X-Received: by 10.84.210.167 with SMTP id a36mr433346pli.125.1481792443655; Thu, 15 Dec 2016 01:00:43 -0800 (PST) Received: from localhost.localdomain ([45.56.152.32]) by smtp.gmail.com with ESMTPSA id x123sm2606178pgb.3.2016.12.15.01.00.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Dec 2016 01:00:43 -0800 (PST) From: Zhangfei Gao To: Wolfram Sang , andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, jarkko.nikula@linux.intel.com Subject: [PATCH v2] i2c: designware: add reset interface Date: Thu, 15 Dec 2016 16:59:48 +0800 Message-Id: <1481792388-13781-1-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479789700-19532-1-git-send-email-zhangfei.gao@linaro.org> References: <1479789700-19532-1-git-send-email-zhangfei.gao@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161215_010104_714121_CCE9DCAA X-CRM114-Status: GOOD ( 15.06 ) 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..e9016ae 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(&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; }