mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: MyungJoo Ham <myungjoo.ham@samsung.com>
To: linux-kernel@vger.kernel.org
Cc: Liam Girdwood <lrg@slimlogic.co.uk>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Axel Lin <axel.lin@gmail.com>,
	Kyungmin Park <kyungmin.park@samsung.com>
Subject: [PATCH 2/2] regulator: max8952 - support hibernation
Date: Tue, 21 Dec 2010 14:04:40 +0900	[thread overview]
Message-ID: <1292907880-3353-2-git-send-email-myungjoo.ham@samsung.com> (raw)
In-Reply-To: <1292907880-3353-1-git-send-email-myungjoo.ham@samsung.com>

Unlike suspend, where the registers of max8952 are not reset, during
hibernation, the register values are reset with an instance of
hibernation.

This patch lets max8952 save and restore register values during
hibernation.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 drivers/regulator/max8952.c |   61 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c
index c7dae2b..530d3b6 100644
--- a/drivers/regulator/max8952.c
+++ b/drivers/regulator/max8952.c
@@ -30,10 +30,11 @@
 #include <linux/gpio.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/pm_runtime.h>
 
 /* Registers */
 enum {
-	MAX8952_REG_MODE0,
+	MAX8952_REG_MODE0 = 0,
 	MAX8952_REG_MODE1,
 	MAX8952_REG_MODE2,
 	MAX8952_REG_MODE3,
@@ -311,6 +312,8 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, max8952);
 
+	pm_runtime_set_active(max8952->dev);
+
 	return 0;
 
 err_reg:
@@ -340,11 +343,67 @@ static const struct i2c_device_id max8952_ids[] = {
 };
 MODULE_DEVICE_TABLE(i2c, max8952_ids);
 
+struct max8952_reg_dump {
+	u8	addr;
+	u8	val;
+};
+#define SAVE_ITEM(x)	{ .addr = (x), .val = 0x0, }
+static struct max8952_reg_dump max8952_dump[] = {
+	SAVE_ITEM(MAX8952_REG_MODE0),
+	SAVE_ITEM(MAX8952_REG_MODE1),
+	SAVE_ITEM(MAX8952_REG_MODE2),
+	SAVE_ITEM(MAX8952_REG_MODE3),
+	SAVE_ITEM(MAX8952_REG_CONTROL),
+	SAVE_ITEM(MAX8952_REG_SYNC),
+	SAVE_ITEM(MAX8952_REG_RAMP),
+};
+
+/* Save registers before hibernation */
+static int max8952_freeze(struct device *dev)
+{
+	struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
+	struct max8952_data *max8952 = i2c_get_clientdata(i2c);
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(max8952_dump); i++) {
+		int val = max8952_read_reg(max8952, max8952_dump[i].addr);
+		if (val >= 0)
+			max8952_dump[i].val = val;
+		else {
+			dev_emerg(dev, "reading error %d\n", val);
+			return val;
+		}
+	}
+
+	return 0;
+}
+
+/* Restore registers after hibernation */
+static int max8952_restore(struct device *dev)
+{
+	struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
+	struct max8952_data *max8952 = i2c_get_clientdata(i2c);
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(max8952_dump); i++)
+		max8952_write_reg(max8952, max8952_dump[i].addr,
+				max8952_dump[i].val);
+
+	return 0;
+}
+
+static const struct dev_pm_ops max8952_pm = {
+	.freeze = max8952_freeze,
+	.restore = max8952_restore,
+};
+
 static struct i2c_driver max8952_pmic_driver = {
 	.probe		= max8952_pmic_probe,
 	.remove		= __devexit_p(max8952_pmic_remove),
 	.driver		= {
 		.name	= "max8952",
+		.owner	= THIS_MODULE,
+		.pm	= &max8952_pm,
 	},
 	.id_table	= max8952_ids,
 };
-- 
1.7.1


  reply	other threads:[~2010-12-21  5:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-21  5:04 [PATCH 1/2] regulator: max8952 - fix max8952_set_voltage check condition MyungJoo Ham
2010-12-21  5:04 ` MyungJoo Ham [this message]
2010-12-21 11:32   ` [PATCH 2/2] regulator: max8952 - support hibernation Mark Brown
2010-12-21 11:30 ` [PATCH 1/2] regulator: max8952 - fix max8952_set_voltage check condition Mark Brown
2010-12-21 12:58 ` Liam Girdwood

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=1292907880-3353-2-git-send-email-myungjoo.ham@samsung.com \
    --to=myungjoo.ham@samsung.com \
    --cc=axel.lin@gmail.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@slimlogic.co.uk \
    /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®