From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: Ludovic Desroches <ludovic.desroches@atmel.com>,
linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Alexandre Belloni <alexandre.belloni@free-electrons.com>
Subject: [PATCH] i2c: at91: ensure state is restored after suspending
Date: Mon, 30 Jan 2017 18:25:33 +0100 [thread overview]
Message-ID: <20170130172533.31995-1-alexandre.belloni@free-electrons.com> (raw)
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 <alexandre.belloni@free-electrons.com>
---
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;
}
--
2.11.0
next reply other threads:[~2017-01-30 17:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-30 17:25 Alexandre Belloni [this message]
2017-01-30 17:44 ` Wolfram Sang
2017-02-06 14:35 ` Ludovic Desroches
2017-02-16 16:58 ` Alexandre Belloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170130172533.31995-1-alexandre.belloni@free-electrons.com \
--to=alexandre.belloni@free-electrons.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ludovic.desroches@atmel.com \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®