From patchwork Mon Jul 31 05:53:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 108969 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1894708qge; Sun, 30 Jul 2017 22:54:37 -0700 (PDT) X-Received: by 10.99.56.5 with SMTP id f5mr9008509pga.162.1501480477165; Sun, 30 Jul 2017 22:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501480477; cv=none; d=google.com; s=arc-20160816; b=cHbXyp+IwDjQoJNDexaRfCFIsGmDijXWQ4WXS9R6imGZ7d+RMAIFuaNgCBYMOOlsOU 5cZhwfz24But0mSyiY5nBYbY3nGW8aY9OupsUlKtoYzeAnMBwMpnDChXOpIjhZedFnEt cdJRix622siGp39eCHz2B9vY/RyI3GUu24aVrWAS4JVeerkUwxBRfw4A9XtdHvtcfd6d LPIiuP6YLlbqlrhW1q49jsz9M2h3nf0c3cVRe3PfO+daXlCbvzqzI430i4Bw/4mCllGh 2tqM2vXpYTMtcReQioyMusMpGbEMCHt2RMElXwh5xm1G8579UKECq8qqW5GE+GLQV1cJ KCJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=wgITSmAcx29OIZR4Wr+pBf5ayeR8R6vpn4LpQbF/7HM=; b=U3GrejGJ+Uz0GH/0bgOq0Bh7pVcuzN9ANCaO0Wmm/Sp0nLD00aghVZ/RPe2vnxShKZ M0wUxi4l/e8vFY5DevbyQw9mTnLmt+OhuTQM4IQ+58+Hk1Qsq6BhE1flkUYvYhLq3yEV o/v2IjhhamWNGt6pZ+TbgCKkRlYsvpZxsixZ9Rwd4Eg1b/rW7yuVnn8fn2ms5ldh3H/p yjMoDjp0X+wgMm+Tb7GN/GLsDEmx741h7q03YXmlk2A0xDIj7Ni/nnGJ7np4RnUIf2xG xPdzGu9DZqTos8CSF/H0PZ6SkkW6E4uX3+hwB8diEiOw2859NOIGAkLDaSMSuCT1WCdr 7LTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.b=LBTJNQ+B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u135si220840pgc.332.2017.07.30.22.54.36; Sun, 30 Jul 2017 22:54:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.b=LBTJNQ+B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751595AbdGaFye (ORCPT + 26 others); Mon, 31 Jul 2017 01:54:34 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:53168 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750846AbdGaFyb (ORCPT ); Mon, 31 Jul 2017 01:54:31 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id v6V5rG2F013340; Mon, 31 Jul 2017 14:53:17 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com v6V5rG2F013340 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1501480398; bh=wgITSmAcx29OIZR4Wr+pBf5ayeR8R6vpn4LpQbF/7HM=; h=From:To:Cc:Subject:Date:From; b=LBTJNQ+BjNaC/KCoPYyNXRdqlKYZCekbajOaJUbMFhzGYIbwBQYFSfYVZdnzBr5zE nTH7RMiIyKMP8EpKoh8SdGSDK8bVJaex8PJNLCxTJIORFrSb3MmsDJwAhsioSsyvb8 dNKWDNuqLVDi3t0HGYzR+fU9kdCfJ6qV5kDDkKAM16wWjr350+/GAwgjBdiW3v7HRn B175smq+oTPnGjCjdys+qjamka9vwHdoS26NuUPl4x9CdkjtoGn4jNq0FFGaLjvaQ0 nbAmHUTVhuiUa4/mqEgMAFYhzMbN7jA0yQNc4NaPlQsFkYTuQhaVugqTfGGuZlZQaq E5h2j2PGcrXWg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-i2c@vger.kernel.org Cc: Masami Hiramatsu , Jassi Brar , Masahiro Yamada , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Wolfram Sang Subject: [PATCH v2 1/2] i2c: uniphier: add suspend / resume support Date: Mon, 31 Jul 2017 14:53:06 +0900 Message-Id: <1501480387-15692-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When resuming, set up registers that have been lost in the sleep state. Also, add clock handling in the resume / suspend hooks. Signed-off-by: Masahiro Yamada --- Changes in v2: - Fix define but not used warning drivers/i2c/busses/i2c-uniphier.c | 40 ++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/i2c/busses/i2c-uniphier.c b/drivers/i2c/busses/i2c-uniphier.c index 777c0fe93653..bb181b088291 100644 --- a/drivers/i2c/busses/i2c-uniphier.c +++ b/drivers/i2c/busses/i2c-uniphier.c @@ -53,6 +53,7 @@ struct uniphier_i2c_priv { void __iomem *membase; struct clk *clk; unsigned int busy_cnt; + unsigned int clk_cycle; }; static irqreturn_t uniphier_i2c_interrupt(int irq, void *dev_id) @@ -316,13 +317,13 @@ static struct i2c_bus_recovery_info uniphier_i2c_bus_recovery_info = { .unprepare_recovery = uniphier_i2c_unprepare_recovery, }; -static void uniphier_i2c_hw_init(struct uniphier_i2c_priv *priv, - u32 bus_speed, unsigned long clk_rate) +static void uniphier_i2c_hw_init(struct uniphier_i2c_priv *priv) { + unsigned int cyc = priv->clk_cycle; + uniphier_i2c_reset(priv, true); - writel((clk_rate / bus_speed / 2 << 16) | (clk_rate / bus_speed), - priv->membase + UNIPHIER_I2C_CLK); + writel((cyc / 2 << 16) | cyc, priv->membase + UNIPHIER_I2C_CLK); uniphier_i2c_reset(priv, false); } @@ -376,6 +377,7 @@ static int uniphier_i2c_probe(struct platform_device *pdev) goto disable_clk; } + priv->clk_cycle = clk_rate / bus_speed; init_completion(&priv->comp); priv->adap.owner = THIS_MODULE; priv->adap.algo = &uniphier_i2c_algo; @@ -386,7 +388,7 @@ static int uniphier_i2c_probe(struct platform_device *pdev) i2c_set_adapdata(&priv->adap, priv); platform_set_drvdata(pdev, priv); - uniphier_i2c_hw_init(priv, bus_speed, clk_rate); + uniphier_i2c_hw_init(priv); ret = devm_request_irq(dev, irq, uniphier_i2c_interrupt, 0, pdev->name, priv); @@ -413,6 +415,33 @@ static int uniphier_i2c_remove(struct platform_device *pdev) return 0; } +static int __maybe_unused uniphier_i2c_suspend(struct device *dev) +{ + struct uniphier_i2c_priv *priv = dev_get_drvdata(dev); + + clk_disable_unprepare(priv->clk); + + return 0; +} + +static int __maybe_unused uniphier_i2c_resume(struct device *dev) +{ + struct uniphier_i2c_priv *priv = dev_get_drvdata(dev); + int ret; + + ret = clk_prepare_enable(priv->clk); + if (ret) + return ret; + + uniphier_i2c_hw_init(priv); + + return 0; +} + +static const struct dev_pm_ops uniphier_i2c_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(uniphier_i2c_suspend, uniphier_i2c_resume) +}; + static const struct of_device_id uniphier_i2c_match[] = { { .compatible = "socionext,uniphier-i2c" }, { /* sentinel */ } @@ -425,6 +454,7 @@ static struct platform_driver uniphier_i2c_drv = { .driver = { .name = "uniphier-i2c", .of_match_table = uniphier_i2c_match, + .pm = &uniphier_i2c_pm_ops, }, }; module_platform_driver(uniphier_i2c_drv);