From patchwork Mon Aug 29 21:22:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 9304471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F08A60756 for ; Mon, 29 Aug 2016 21:24:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E034288FA for ; Mon, 29 Aug 2016 21:24:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E33C289C7; Mon, 29 Aug 2016 21:24:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D0226288FA for ; Mon, 29 Aug 2016 21:24:55 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1beU1b-0003UH-EQ; Mon, 29 Aug 2016 21:23:23 +0000 Received: from mail-pf0-x22c.google.com ([2607:f8b0:400e:c00::22c]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1beU1X-0003RZ-E6 for linux-arm-kernel@lists.infradead.org; Mon, 29 Aug 2016 21:23:20 +0000 Received: by mail-pf0-x22c.google.com with SMTP id y134so100624pfg.0 for ; Mon, 29 Aug 2016 14:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=EzinuMYy2TqvT6Plz6c65rZdhZ/0gabdMF9lu4fpZMI=; b=k0O7vlmjacyu+c5mOytSFiN5cSRQcKOqbzm+i0wi7s4u3npOSOi/znYUstChj9VV5z wumpj/2dmuTG8XHI1e42GdkGyXebb54YWbwMPQvnnIpqnMTN/H2NpTZkbrt3mfPfgzJV 320W2bwf4M/88BYg4ZbcXE24psCmDFDLIJ5VU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=EzinuMYy2TqvT6Plz6c65rZdhZ/0gabdMF9lu4fpZMI=; b=iPPqTVIZpjJbS2MY64sccIMOvUkle3C+EK+YJ0+4AeMmLV7sF1JrxKZrTsbCfy8cPP UyxyK2CEKGlrhlXSVtYrfVy6dqBTrxIhG/zt/Xi84tflZANk1vgAu/aFAZ+crjcYjCLw vXwgl66ng+jDgymvA6C2ltwnPKCQTd8lnjtoK1a6J0nZiV4uzitBEjqe0i83HGHq/LbL 6tqfqRuxjs6qDwaqVOZ2fZM3zchbulABAmWjCNXATmzvMxZa0/fb+URrXHDygz9F5Yo6 rQKDY1wFyKfEnbB49hXQi7b1wH91N2Oe9YiwLBux7NUlqd87CZoWO3snAT0SkL8/bGA1 OQ1A== X-Gm-Message-State: AE9vXwNCAxKrXdphX8JK2W+Zj6//Bzmw+MR/RGJft68OE7xZr26hIIIUMl2AYLL4ytvsnXhA X-Received: by 10.98.196.77 with SMTP id y74mr142963pff.97.1472505777990; Mon, 29 Aug 2016 14:22:57 -0700 (PDT) Received: from chromelab4.mtv.corp.google.com ([100.98.62.8]) by smtp.gmail.com with ESMTPSA id tm1sm51509843pac.23.2016.08.29.14.22.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Aug 2016 14:22:57 -0700 (PDT) From: Douglas Anderson To: wsa@the-dreams.de, heiko@sntech.de Subject: [PATCH] i2c: rk3x: Restore clock settings at resume time Date: Mon, 29 Aug 2016 14:22:36 -0700 Message-Id: <1472505756-8302-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160829_142319_574133_057ABA90 X-CRM114-Status: GOOD ( 11.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-i2c@vger.kernel.org, david.wu@rock-chips.com, linux-arm-kernel@lists.infradead.org, wxt@rock-chips.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Depending on a number of factors including: - Which exact Rockchip SoC we're working with - How deep we suspend - Which i2c port we're on We might lose the state of the i2c registers at suspend time. Specifically we've found that on rk3399 the i2c ports that are not in the PMU power domain lose their state with the current suspend depth configured by ARM Tursted Firmware. Note that there are very few actual i2c registers that aren't configured per transfer anyway so all we actually need to re-configure are the clock config registers. We'll just add a call to rk3x_i2c_adapt_div() at resume time and be done with it. NOTE: On rk3399 on ports whose power was lost, I put printouts in at resume time. I saw things like: before: con=0x00010300, div=0x00060006 after: con=0x00010200, div=0x00180025 Signed-off-by: Douglas Anderson Reviewed-by: David Wu Tested-by: David Wu --- Tested on chromeos-4.4 kernel with backports. drivers/i2c/busses/i2c-rk3x.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c index 3b87afe82f63..0df5ad6bfa31 100644 --- a/drivers/i2c/busses/i2c-rk3x.c +++ b/drivers/i2c/busses/i2c-rk3x.c @@ -1111,6 +1111,15 @@ static int rk3x_i2c_xfer(struct i2c_adapter *adap, return ret < 0 ? ret : num; } +static __maybe_unused int rk3x_i2c_resume(struct device *dev) +{ + struct rk3x_i2c *i2c = dev_get_drvdata(dev); + + rk3x_i2c_adapt_div(i2c, clk_get_rate(i2c->clk)); + + return 0; +} + static u32 rk3x_i2c_func(struct i2c_adapter *adap) { return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING; @@ -1332,12 +1341,15 @@ static int rk3x_i2c_remove(struct platform_device *pdev) return 0; } +static const SIMPLE_DEV_PM_OPS(rk3x_i2c_pm_ops, NULL, rk3x_i2c_resume); + static struct platform_driver rk3x_i2c_driver = { .probe = rk3x_i2c_probe, .remove = rk3x_i2c_remove, .driver = { .name = "rk3x-i2c", .of_match_table = rk3x_i2c_match, + .pm = &rk3x_i2c_pm_ops, }, };