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: 9304469 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 8597E601C0 for ; Mon, 29 Aug 2016 21:23:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 761A228998 for ; Mon, 29 Aug 2016 21:23:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A378289C7; Mon, 29 Aug 2016 21:23:32 +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=ham 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 14F4728998 for ; Mon, 29 Aug 2016 21:23:31 +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 1beU1j-0003Ux-8k; Mon, 29 Aug 2016 21:23:31 +0000 Received: from mail-pf0-x22a.google.com ([2607:f8b0:400e:c00::22a]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1beU1X-0003Ra-EE for linux-rockchip@lists.infradead.org; Mon, 29 Aug 2016 21:23:20 +0000 Received: by mail-pf0-x22a.google.com with SMTP id x72so81047pfd.2 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=k1STgY+DGQ9liZu46qdbmFmB/VDYGWNw5f1vGd9UeikRMcLMEps1s1PDAl45aGK8i2 Pj65asxEg4k1HyeSbglKpg25s2Ny6rQFmJxmk3ASMeWSUidvOc6CbsMGhAwN0uxA8fII 25GyiU5ubBhuJZ0R/JVty7pCoOfyE3NZwyi9C5DXIY5TQmnwDit5aTGsk3A9fkKYO4aL 0XvsToTDimSHTs0uPxLASpJlQbHc/Hw/V0ZvDPaIE5QoJvr2WHIVF0GOgLvkc369PxEh lxTAiBMsVvShPIs0y+3NWMcdQ2gmOIoPnsA90TukxBNLiNtflrhgByOFbHVig8uiMixb E2Yw== X-Gm-Message-State: AE9vXwNWFe0/NRUpFcyLbzU1dHD/U9z2NOdqAVbkk6wiBu8ciCoLsDUAzvyccqxXipPoD2Bl 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_548587_20FDB1E7 X-CRM114-Status: UNSURE ( 9.98 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms 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-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=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, }, };