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: 88123 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp674707qgi; Thu, 15 Dec 2016 01:00:46 -0800 (PST) X-Received: by 10.84.216.8 with SMTP id m8mr507604pli.116.1481792446056; Thu, 15 Dec 2016 01:00:46 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l91si1512433plb.38.2016.12.15.01.00.45; Thu, 15 Dec 2016 01:00:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755589AbcLOJAo (ORCPT + 1 other); Thu, 15 Dec 2016 04:00:44 -0500 Received: from mail-pg0-f42.google.com ([74.125.83.42]:36288 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755384AbcLOJAo (ORCPT ); Thu, 15 Dec 2016 04:00:44 -0500 Received: by mail-pg0-f42.google.com with SMTP id f188so18008646pgc.3 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=iVDfCds6g1i27uPpKldGlhs1KQTasnCkLHwJrvbou1xcuu1CPgN3vmROPmXOnskkFj dX6P3wP9pcSNKzX7e3YbTpPv5kwmwTDWO1MHO/P1lB1LTjs/X4KgofQprSRPQ8yr2QXl O7Gk4cdHoBbS36jOIdObIvr0ftxlj8NHUjGi8T/aJfnWi9x4NDgDcMToZJtcaO+g/HFd +XJ03haAqWKM3qX/dBJO8Ds6CvYdpb/CoNZ/F9h8j+L+5f8yb8ylKPPyGIZlYOc7JDAS dP8ZJ9zkgDNVopjogM1td4y/kksWXBlBy6fATZ0ioKA1BlFW5uPVFa1LBvb+cULadmg8 456w== X-Gm-Message-State: AKaTC03WkkqjJ9UnsRmuRe8X2t8vuGt3od0619VPr0Lsyftc5xoar2giUMMR1/WqVIamsik9 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 Cc: linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, Zhangfei Gao 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> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Some platforms like hi3660 need do reset first to allow accessing registers Signed-off-by: Zhangfei Gao --- drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Andy Shevchenko Tested-by: Ramiro Oliveira 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; }