[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-id: <1292907880-3353-2-git-send-email-myungjoo.ham@samsung.com>
Date: Tue, 21 Dec 2010 14:04:40 +0900
From: MyungJoo Ham <myungjoo.ham@...sung.com>
To: linux-kernel@...r.kernel.org
Cc: Liam Girdwood <lrg@...mlogic.co.uk>,
Mark Brown <broonie@...nsource.wolfsonmicro.com>,
Axel Lin <axel.lin@...il.com>,
Kyungmin Park <kyungmin.park@...sung.com>
Subject: [PATCH 2/2] regulator: max8952 - support hibernation
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@...sung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@...sung.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists