From patchwork Tue Dec 27 14:22:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 89092 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp5009015qgi; Tue, 27 Dec 2016 06:23:48 -0800 (PST) X-Received: by 10.99.96.9 with SMTP id u9mr53515847pgb.151.1482848628393; Tue, 27 Dec 2016 06:23:48 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w8si46571550pgw.107.2016.12.27.06.23.48; Tue, 27 Dec 2016 06:23:48 -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 S932523AbcL0OXr (ORCPT + 1 other); Tue, 27 Dec 2016 09:23:47 -0500 Received: from mail-pg0-f49.google.com ([74.125.83.49]:33008 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932500AbcL0OXr (ORCPT ); Tue, 27 Dec 2016 09:23:47 -0500 Received: by mail-pg0-f49.google.com with SMTP id g1so106465284pgn.0 for ; Tue, 27 Dec 2016 06:23:10 -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=QnDgUB6E23cIJrBI70IEybgi6KjmywQASWc9S7AuVGw=; b=FojtOS/c2EXxhLYpaBrD/3fb2vmCQEdbAWcufIuhiawtYuMASB7lmHR5f/HMsuscXX J4LkUVdo8+HFQYi7+wU2VsLme2OWYf/93nT73bLxkPsLmYm1avYqHMwDJadpDwfQFCYB EDuEWx8xAij1h6m52oAM4QWZqMmQHuSBpQoXM= 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=QnDgUB6E23cIJrBI70IEybgi6KjmywQASWc9S7AuVGw=; b=foGt3fpW0ykiOCy95agjQ6P5mVdrFKY+6gsxBrzM7WHE1jHWESFLa2doYT3IgojYM7 EdOWEesw4nZ0XPuIqOOHoTogdmlPLSFt3EontOtgrdzeNbvsf2ZkuD9hiDXih4CwWA6j QqofgUokZMefvCCv7X13k6brsC5CSV4r2nhTUHJqjsBzV0oamTeF8rZWODCVTProx5SZ V0vh2oLYSmoDPtpjSslojAlgPchoLi8Tec6PNpk0PFm//S05IsWsy05jJtWatm18YDx3 sYSZXnLWmOuRlu5het6oUrkFRtbGxpgrL6ILsy2zpq6aL/aVIkmgB8B+/URLP14uvAQp xgbA== X-Gm-Message-State: AIkVDXLeDuw01zl0JERuCqawEvEAfm4xCwKV4fHQf3ytGXQlXAxDqyjGLRxxGbUP4O2nP3Vl X-Received: by 10.98.67.138 with SMTP id l10mr30539435pfi.101.1482848589944; Tue, 27 Dec 2016 06:23:09 -0800 (PST) Received: from localhost.localdomain ([104.237.91.223]) by smtp.gmail.com with ESMTPSA id t184sm90796250pgt.36.2016.12.27.06.23.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Dec 2016 06:23:09 -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 Cc: linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, Zhangfei Gao Subject: [PATCH v3 resend] i2c: designware: add reset interface Date: Tue, 27 Dec 2016 22:22:40 +0800 Message-Id: <1482848560-3752-1-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: 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 Reviewed-by: Andy Shevchenko Tested-by: Ramiro Oliveira --- rebase to 4.10-rc1 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 Acked-by: Jarkko Nikula diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index 26250b4..302807c 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -88,6 +88,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 6ce4313..79c4b4e 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 @@ -199,6 +200,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); + } + if (pdata) { dev->clk_freq = pdata->i2c_scl_freq; } else { @@ -235,12 +244,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_10BIT_ADDR | DW_IC_DEFAULT_FUNCTIONALITY; @@ -286,10 +296,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) @@ -306,6 +324,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; }