From patchwork Mon Jan 30 17:25:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 9545777 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 17A81604A0 for ; Mon, 30 Jan 2017 17:26:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8E0625D9E for ; Mon, 30 Jan 2017 17:26:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCAD42811E; Mon, 30 Jan 2017 17:26:17 +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=-1.9 required=2.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6828325D9E for ; Mon, 30 Jan 2017 17:26:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cYFiY-0002y8-JY; Mon, 30 Jan 2017 17:26:14 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cYFiU-0002wd-Rk for linux-arm-kernel@lists.infradead.org; Mon, 30 Jan 2017 17:26:12 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 31FFC20DEB; Mon, 30 Jan 2017 18:25:54 +0100 (CET) Received: from localhost (unknown [88.191.26.124]) by mail.free-electrons.com (Postfix) with ESMTPSA id 10A1720B8A; Mon, 30 Jan 2017 18:25:44 +0100 (CET) From: Alexandre Belloni To: Wolfram Sang Subject: [PATCH] i2c: at91: ensure state is restored after suspending Date: Mon, 30 Jan 2017 18:25:33 +0100 Message-Id: <20170130172533.31995-1-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170130_092611_047347_0E0B5A6F X-CRM114-Status: GOOD ( 11.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ludovic Desroches , Alexandre Belloni , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org 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 When going to suspend, the I2C registers may be lost because the power to VDDcore is cut. Save them and restore them when resuming. Signed-off-by: Alexandre Belloni --- drivers/i2c/busses/i2c-at91.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c index 0b86c6173e07..633bdd899952 100644 --- a/drivers/i2c/busses/i2c-at91.c +++ b/drivers/i2c/busses/i2c-at91.c @@ -140,6 +140,12 @@ struct at91_twi_dev { unsigned transfer_status; struct i2c_adapter adapter; unsigned twi_cwgr_reg; + struct { + u32 mmr; + u32 imr; + u32 fmr; + u32 fimr; + } cache; struct at91_twi_pdata *pdata; bool use_dma; bool use_alt_cmd; @@ -1172,6 +1178,15 @@ static int at91_twi_runtime_resume(struct device *dev) static int at91_twi_suspend_noirq(struct device *dev) { + struct at91_twi_dev *twi_dev = dev_get_drvdata(dev); + + twi_dev->cache.mmr = at91_twi_read(twi_dev, AT91_TWI_MMR); + twi_dev->cache.imr = at91_twi_read(twi_dev, AT91_TWI_IMR); + if (twi_dev->fifo_size) { + twi_dev->cache.fmr = at91_twi_read(twi_dev, AT91_TWI_FMR); + twi_dev->cache.fimr = at91_twi_read(twi_dev, AT91_TWI_FIMR); + } + if (!pm_runtime_status_suspended(dev)) at91_twi_runtime_suspend(dev); @@ -1180,6 +1195,7 @@ static int at91_twi_suspend_noirq(struct device *dev) static int at91_twi_resume_noirq(struct device *dev) { + struct at91_twi_dev *twi_dev = dev_get_drvdata(dev); int ret; if (!pm_runtime_status_suspended(dev)) { @@ -1191,6 +1207,14 @@ static int at91_twi_resume_noirq(struct device *dev) pm_runtime_mark_last_busy(dev); pm_request_autosuspend(dev); + at91_init_twi_bus(twi_dev); + at91_twi_write(twi_dev, AT91_TWI_MMR, twi_dev->cache.mmr); + at91_twi_write(twi_dev, AT91_TWI_IER, twi_dev->cache.imr); + if (twi_dev->fifo_size) { + at91_twi_write(twi_dev, AT91_TWI_FMR, twi_dev->cache.fmr); + at91_twi_write(twi_dev, AT91_TWI_FIER, twi_dev->cache.fimr); + } + return 0; }