From patchwork Mon Jul 31 05:53:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 108968 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1894647qge; Sun, 30 Jul 2017 22:54:32 -0700 (PDT) X-Received: by 10.84.140.129 with SMTP id 1mr15650568plt.379.1501480472839; Sun, 30 Jul 2017 22:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501480472; cv=none; d=google.com; s=arc-20160816; b=iPSg9tZDuxSZo81vi8z28Oe8pTaIoD7b7ALYKlxtR2vtNlq+OqGn4VNNuyqu6xGo+2 gP86afRTPJTyoWOo3y4aP7eawQDpHA9sjcFYrfqYMk8fWKVO5pAKD0s0QxWEu0L/EeHv oVuxPuk/zR4NGFnMOAIGHLp8J1q/YIbWgqyhw3oeAVnbPCh4Qghm9T8KXEjWaWQfgdjc DzXZhMmSZOqLyMl833KlcS+fmL4JzGHTKilTiSUe0h08BuWGDxC73+NJRf+hTfJ0SJia PeA+8x2svnQPiC8PmWX7TfKtH2S795i4IIAhKplH0Vn6CTHBgmUUMmYAgK12w7nlSyLW RVkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=zBKyDLohnWTFa/7jbLLPoz53LBUxxWQEPG9Z1H01AB0=; b=aLY/G8s3SXmZMjBhgMCKb6wLzhg8l/7a95tQXpU47zNrjZ4tZQz72rc0DGIbl/A7Y4 EdAyzX/6w/0XZJC50SVAYjg9Vw0dxQHp0x+aOOOLx0nm7tt7Fzhe36ehCfizAGu8OoNM vyGMB4NhUB+rZg/ueS+kiP8HRPJsBm9TNTg0SbI0E620+9kKd8w8hxwxu31RQvSqON1b L2rx2Rh4HVna+PENqSd4Ek2l/enitpvPYFzrBddslzuDU1tjnUIuMlKg5vJZSPJWW++8 8tYtnoFsxhxW2lkep74AU3R5yM1u92nDLiKzUOgxadfhtYdH1h95HwfJ2eCxy2UemY0E ZblA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.b=rsOiR+lE; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x190si15830777pgd.606.2017.07.30.22.54.32; Sun, 30 Jul 2017 22:54:32 -0700 (PDT) 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=pass header.i=@nifty.com header.b=rsOiR+lE; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750869AbdGaFyb (ORCPT + 1 other); Mon, 31 Jul 2017 01:54:31 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:53140 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750739AbdGaFya (ORCPT ); Mon, 31 Jul 2017 01:54:30 -0400 X-Greylist: delayed 3738 seconds by postgrey-1.27 at vger.kernel.org; Mon, 31 Jul 2017 01:54:29 EDT 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 v6V5rG2G013340; Mon, 31 Jul 2017 14:53:18 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com v6V5rG2G013340 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1501480399; bh=zBKyDLohnWTFa/7jbLLPoz53LBUxxWQEPG9Z1H01AB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rsOiR+lEnMx+sy9XwmtuLHvKosGHcibOsyqByOlv1XW7CVMvsletgvWlfkwhz+DIk L8GfcJbUzVmCZChnaPIFVcDcVJiKTzTaLW+uenw7qRVrd5Yt5YyZ41Hud9UMin/vMN 4Dd+Bo2kTuhLU8GNb3o5GUgqFE8NP98BYHi7ZmoKuef03OI7lei1HDUxi2GGr9SMKz Z79Vt24XQ2+PW77HRTnGC5ihxErvyGAG9xYTw2Ay441TNnZNAen2+a6jVngBEOvXDo ghZefSCrciqw5Ds2v7fqa76BPLFUSSKi4xrNBhcaC9gII5CQXpGkuTFus+n/mgvWVG fB01GipFEfcQQ== 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 2/2] i2c: uniphier-f: add suspend / resume support Date: Mon, 31 Jul 2017 14:53:07 +0900 Message-Id: <1501480387-15692-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501480387-15692-1-git-send-email-yamada.masahiro@socionext.com> References: <1501480387-15692-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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-f.c | 46 +++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c index beee31892295..9918bdd81619 100644 --- a/drivers/i2c/busses/i2c-uniphier-f.c +++ b/drivers/i2c/busses/i2c-uniphier-f.c @@ -97,6 +97,7 @@ struct uniphier_fi2c_priv { int error; unsigned int flags; unsigned int busy_cnt; + unsigned int clk_cycle; }; static void uniphier_fi2c_fill_txfifo(struct uniphier_fi2c_priv *priv, @@ -461,9 +462,9 @@ static struct i2c_bus_recovery_info uniphier_fi2c_bus_recovery_info = { .unprepare_recovery = uniphier_fi2c_unprepare_recovery, }; -static void uniphier_fi2c_hw_init(struct uniphier_fi2c_priv *priv, - u32 bus_speed, unsigned long clk_rate) +static void uniphier_fi2c_hw_init(struct uniphier_fi2c_priv *priv) { + unsigned int cyc = priv->clk_cycle; u32 tmp; tmp = readl(priv->membase + UNIPHIER_FI2C_CR); @@ -472,12 +473,10 @@ static void uniphier_fi2c_hw_init(struct uniphier_fi2c_priv *priv, uniphier_fi2c_reset(priv); - tmp = clk_rate / bus_speed; - - writel(tmp, priv->membase + UNIPHIER_FI2C_CYC); - writel(tmp / 2, priv->membase + UNIPHIER_FI2C_LCTL); - writel(tmp / 2, priv->membase + UNIPHIER_FI2C_SSUT); - writel(tmp / 16, priv->membase + UNIPHIER_FI2C_DSUT); + writel(cyc, priv->membase + UNIPHIER_FI2C_CYC); + writel(cyc / 2, priv->membase + UNIPHIER_FI2C_LCTL); + writel(cyc / 2, priv->membase + UNIPHIER_FI2C_SSUT); + writel(cyc / 16, priv->membase + UNIPHIER_FI2C_DSUT); uniphier_fi2c_prepare_operation(priv); } @@ -531,6 +530,7 @@ static int uniphier_fi2c_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_fi2c_algo; @@ -541,7 +541,7 @@ static int uniphier_fi2c_probe(struct platform_device *pdev) i2c_set_adapdata(&priv->adap, priv); platform_set_drvdata(pdev, priv); - uniphier_fi2c_hw_init(priv, bus_speed, clk_rate); + uniphier_fi2c_hw_init(priv); ret = devm_request_irq(dev, irq, uniphier_fi2c_interrupt, 0, pdev->name, priv); @@ -568,6 +568,33 @@ static int uniphier_fi2c_remove(struct platform_device *pdev) return 0; } +static int __maybe_unused uniphier_fi2c_suspend(struct device *dev) +{ + struct uniphier_fi2c_priv *priv = dev_get_drvdata(dev); + + clk_disable_unprepare(priv->clk); + + return 0; +} + +static int __maybe_unused uniphier_fi2c_resume(struct device *dev) +{ + struct uniphier_fi2c_priv *priv = dev_get_drvdata(dev); + int ret; + + ret = clk_prepare_enable(priv->clk); + if (ret) + return ret; + + uniphier_fi2c_hw_init(priv); + + return 0; +} + +static const struct dev_pm_ops uniphier_fi2c_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(uniphier_fi2c_suspend, uniphier_fi2c_resume) +}; + static const struct of_device_id uniphier_fi2c_match[] = { { .compatible = "socionext,uniphier-fi2c" }, { /* sentinel */ } @@ -580,6 +607,7 @@ static struct platform_driver uniphier_fi2c_drv = { .driver = { .name = "uniphier-fi2c", .of_match_table = uniphier_fi2c_match, + .pm = &uniphier_fi2c_pm_ops, }, }; module_platform_driver(uniphier_fi2c_drv);