From patchwork Mon Jul 31 04:51:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 108964 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1852116qge; Sun, 30 Jul 2017 21:52:18 -0700 (PDT) X-Received: by 10.84.211.110 with SMTP id b101mr15766460pli.441.1501476738614; Sun, 30 Jul 2017 21:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501476738; cv=none; d=google.com; s=arc-20160816; b=hvvhxGXWU0rD0XV2KKNjR4MBojgxNoUqeEHY08QRikPox1ILSKzoJ5TKBTsd6DHCq1 mqXH960dW5k970hSqGz8SOgZVHLlIjWf1/m2sSQBJIg2fvcANWz6dKlF4EO6vb7BOM6N GqMa8oekpoADojQgGzfONZtBvkBcIIXNgXTgdS6WFQgl4rNIQQ/5fZavYznOjGF27+3z EDt+RaUAsgwV0bBwK0qRs7Hpv4DHhrgoqo9pFARgWV1iJ76cEjJF7f16akDeofZIL637 8gQWyryLFtisN+LSCndmI7KDd5ngor3EIVH+0ZGJJzIC5VUytABViWhOLntXogiLIF9A 18hA== 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=lBl7NWKr8m/LcTy2qF6P+uuVmE66k2b6xK49iA42yxA=; b=n7W+UCiTh+ha6XuzWm3rKqgZT6+dqRFt+GmMlrpro2iINmlMKM0iHsLqf/6QMN4GJP 4/mHjYLzaDd7f6r2AORQrNqu8NbPraWBaG43Q0NEQvrGQKzcyL2C9u15xDnUkf7x/Pc+ LnlfL0IwHo61/O441ChAANUucd48jeftI9dudxjivXjH77ez7yMEP/JAuCj/V5YZSk7Y OivmXalvqXLear3WjGNTgAddnLE6VrwBHAb7wsi72/GsJgxR1jF0ynoNoMA3UGYUY6Xh yxzl9KiQhaPPmKPMImO88Osgfct/MohewxoJ6eed8u8p5i3Ju/k9kdnlMouUzS7alYVq yY2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.b=JM2crLcf; 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 s10si16509148plj.788.2017.07.30.21.52.18; Sun, 30 Jul 2017 21:52:18 -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=JM2crLcf; 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 S1751763AbdGaEwO (ORCPT + 26 others); Mon, 31 Jul 2017 00:52:14 -0400 Received: from conuserg-12.nifty.com ([210.131.2.79]:54891 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750789AbdGaEwL (ORCPT ); Mon, 31 Jul 2017 00:52:11 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-12.nifty.com with ESMTP id v6V4pDwC031504; Mon, 31 Jul 2017 13:51:15 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com v6V4pDwC031504 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1501476675; bh=lBl7NWKr8m/LcTy2qF6P+uuVmE66k2b6xK49iA42yxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JM2crLcf2hu8GIUmU8Zti686kYDJduaN59N0ikK526Bh49XoeEb7olmdIJpvDmgfn g18te48I0sxs/AFCUgsPclcjnHZ2KU8IFpSZH/Z828rbF0lwxjvUflp3GdsAUr4m+u +jDm//x+C+9NQHD3cu4aQDPxo/mcLuDpJuax/RsLDqnDM0L/uCCdVkrboV9hyc6msp le4pIhtG00sxPyJEondl8VfaPvNkInCe5vwNYhmNViwC/0yH7hvM46r7iTnvt3bxDL qdtc3HWZz9WA0HgcU+SOD9I9o1O7hsTuSj3XqCvHEZKvqoXHaDvDQsSVTe0IdJU0Sb 6UZT2uY5qaiCA== 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 2/2] i2c: uniphier-f: add PM suspend / resume support Date: Mon, 31 Jul 2017 13:51:08 +0900 Message-Id: <1501476668-18432-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501476668-18432-1-git-send-email-yamada.masahiro@socionext.com> References: <1501476668-18432-1-git-send-email-yamada.masahiro@socionext.com> 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 --- 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..74cf0752bbd0 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 uniphier_fi2c_suspend(struct device *dev) +{ + struct uniphier_fi2c_priv *priv = dev_get_drvdata(dev); + + clk_disable_unprepare(priv->clk); + + return 0; +} + +static int 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);