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: 88950 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp3327185qgi; Fri, 23 Dec 2016 05:41:28 -0800 (PST) X-Received: by 10.84.143.233 with SMTP id 96mr29871526plz.27.1482500488323; Fri, 23 Dec 2016 05:41:28 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q28si34211478pfl.44.2016.12.23.05.41.28; Fri, 23 Dec 2016 05:41:28 -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 S1755808AbcLWNl1 (ORCPT + 1 other); Fri, 23 Dec 2016 08:41:27 -0500 Received: from mail-pf0-f180.google.com ([209.85.192.180]:33968 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755223AbcLWNl0 (ORCPT ); Fri, 23 Dec 2016 08:41:26 -0500 Received: by mail-pf0-f180.google.com with SMTP id c4so44683225pfb.1 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=NWxtUc9GOhY+qXh5KiG3batXveYBrRQDatUwvRR3qhOXbKl4YQTpdxidqjpm5VIgEe IyrVYq6vHZKi6nLW0mPF3JdglVvnmEzcdj3RN/8uxjQorVm5dZYKBPWQkCoTQNj6pI2O qQDFqxBO7VPMGCAh1uUpomJZKInBeDDlyCtZ6qqHq/N86VsbWZuvomFTQ1vsivz/JdF9 JnyyTY5WCaSt5PkRMVeMPfVrAPyTp6GpApAqJxRv9KK4blUhZHKDTSRkxsxdvDunqeqW wh0m6hfEwU/uSvwO5Kpj4EOU06MWYGIStXaLc+TFmq6tbl/s4zLSDxjGlFcRqBamGnCb DEbA== X-Gm-Message-State: AIkVDXJh8w2bOdRQTlFyCs55GIub3mrnke/1bPh9KyH+sVRMw6odcgZv9jo8LRcREOuBUhDr 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 Cc: linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, Zhangfei Gao 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 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 --- 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 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; }