Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 1 | /* |
Joonyoung Shim | 2c7e6f5 | 2010-09-10 18:36:39 +0200 | [diff] [blame] | 2 | * max8998.c - mfd core driver for the Maxim 8998 |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2009-2010 Samsung Electronics |
| 5 | * Kyungmin Park <kyungmin.park@samsung.com> |
| 6 | * Marek Szyprowski <m.szyprowski@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 23 | #include <linux/err.h> |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 24 | #include <linux/module.h> |
| 25 | #include <linux/moduleparam.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/i2c.h> |
MyungJoo Ham | cdd137c | 2010-12-23 17:53:36 +0900 | [diff] [blame] | 29 | #include <linux/interrupt.h> |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 30 | #include <linux/of.h> |
| 31 | #include <linux/of_irq.h> |
MyungJoo Ham | cdd137c | 2010-12-23 17:53:36 +0900 | [diff] [blame] | 32 | #include <linux/pm_runtime.h> |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 33 | #include <linux/mutex.h> |
| 34 | #include <linux/mfd/core.h> |
| 35 | #include <linux/mfd/max8998.h> |
| 36 | #include <linux/mfd/max8998-private.h> |
| 37 | |
Joonyoung Shim | 9b16c0a | 2010-08-06 11:28:08 +0900 | [diff] [blame] | 38 | #define RTC_I2C_ADDR (0x0c >> 1) |
| 39 | |
Geert Uytterhoeven | 7c0517b | 2013-11-18 14:33:00 +0100 | [diff] [blame] | 40 | static const struct mfd_cell max8998_devs[] = { |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 41 | { |
| 42 | .name = "max8998-pmic", |
Joonyoung Shim | 9b16c0a | 2010-08-06 11:28:08 +0900 | [diff] [blame] | 43 | }, { |
| 44 | .name = "max8998-rtc", |
Donggeun Kim | bb4ce97 | 2011-06-24 19:04:18 +0900 | [diff] [blame] | 45 | }, { |
| 46 | .name = "max8998-battery", |
Joonyoung Shim | 9b16c0a | 2010-08-06 11:28:08 +0900 | [diff] [blame] | 47 | }, |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 48 | }; |
| 49 | |
Geert Uytterhoeven | 7c0517b | 2013-11-18 14:33:00 +0100 | [diff] [blame] | 50 | static const struct mfd_cell lp3974_devs[] = { |
MyungJoo Ham | 337ce5d | 2011-01-04 14:17:39 +0900 | [diff] [blame] | 51 | { |
| 52 | .name = "lp3974-pmic", |
| 53 | }, { |
| 54 | .name = "lp3974-rtc", |
| 55 | }, |
| 56 | }; |
| 57 | |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 58 | int max8998_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest) |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 59 | { |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 60 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 61 | int ret; |
| 62 | |
| 63 | mutex_lock(&max8998->iolock); |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 64 | ret = i2c_smbus_read_byte_data(i2c, reg); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 65 | mutex_unlock(&max8998->iolock); |
| 66 | if (ret < 0) |
| 67 | return ret; |
| 68 | |
| 69 | ret &= 0xff; |
| 70 | *dest = ret; |
| 71 | return 0; |
| 72 | } |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 73 | EXPORT_SYMBOL(max8998_read_reg); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 74 | |
Joonyoung Shim | 2c7e6f5 | 2010-09-10 18:36:39 +0200 | [diff] [blame] | 75 | int max8998_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf) |
| 76 | { |
| 77 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
| 78 | int ret; |
| 79 | |
| 80 | mutex_lock(&max8998->iolock); |
| 81 | ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf); |
| 82 | mutex_unlock(&max8998->iolock); |
| 83 | if (ret < 0) |
| 84 | return ret; |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | EXPORT_SYMBOL(max8998_bulk_read); |
| 89 | |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 90 | int max8998_write_reg(struct i2c_client *i2c, u8 reg, u8 value) |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 91 | { |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 92 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 93 | int ret; |
| 94 | |
| 95 | mutex_lock(&max8998->iolock); |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 96 | ret = i2c_smbus_write_byte_data(i2c, reg, value); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 97 | mutex_unlock(&max8998->iolock); |
| 98 | return ret; |
| 99 | } |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 100 | EXPORT_SYMBOL(max8998_write_reg); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 101 | |
Joonyoung Shim | 9b16c0a | 2010-08-06 11:28:08 +0900 | [diff] [blame] | 102 | int max8998_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf) |
| 103 | { |
| 104 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
| 105 | int ret; |
| 106 | |
| 107 | mutex_lock(&max8998->iolock); |
| 108 | ret = i2c_smbus_write_i2c_block_data(i2c, reg, count, buf); |
| 109 | mutex_unlock(&max8998->iolock); |
| 110 | if (ret < 0) |
| 111 | return ret; |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | EXPORT_SYMBOL(max8998_bulk_write); |
| 116 | |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 117 | int max8998_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask) |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 118 | { |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 119 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 120 | int ret; |
| 121 | |
| 122 | mutex_lock(&max8998->iolock); |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 123 | ret = i2c_smbus_read_byte_data(i2c, reg); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 124 | if (ret >= 0) { |
| 125 | u8 old_val = ret & 0xff; |
| 126 | u8 new_val = (val & mask) | (old_val & (~mask)); |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 127 | ret = i2c_smbus_write_byte_data(i2c, reg, new_val); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 128 | } |
| 129 | mutex_unlock(&max8998->iolock); |
| 130 | return ret; |
| 131 | } |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 132 | EXPORT_SYMBOL(max8998_update_reg); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 133 | |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 134 | #ifdef CONFIG_OF |
Krzysztof Kozlowski | e920574 | 2014-05-13 12:58:48 +0200 | [diff] [blame] | 135 | static const struct of_device_id max8998_dt_match[] = { |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 136 | { .compatible = "maxim,max8998", .data = (void *)TYPE_MAX8998 }, |
| 137 | { .compatible = "national,lp3974", .data = (void *)TYPE_LP3974 }, |
| 138 | { .compatible = "ti,lp3974", .data = (void *)TYPE_LP3974 }, |
| 139 | {}, |
| 140 | }; |
| 141 | MODULE_DEVICE_TABLE(of, max8998_dt_match); |
| 142 | #endif |
| 143 | |
| 144 | /* |
| 145 | * Only the common platform data elements for max8998 are parsed here from the |
| 146 | * device tree. Other sub-modules of max8998 such as pmic, rtc and others have |
| 147 | * to parse their own platform data elements from device tree. |
| 148 | * |
| 149 | * The max8998 platform data structure is instantiated here and the drivers for |
| 150 | * the sub-modules need not instantiate another instance while parsing their |
| 151 | * platform data. |
| 152 | */ |
| 153 | static struct max8998_platform_data *max8998_i2c_parse_dt_pdata( |
| 154 | struct device *dev) |
| 155 | { |
| 156 | struct max8998_platform_data *pd; |
| 157 | |
| 158 | pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); |
| 159 | if (!pd) |
| 160 | return ERR_PTR(-ENOMEM); |
| 161 | |
| 162 | pd->ono = irq_of_parse_and_map(dev->of_node, 1); |
| 163 | |
| 164 | /* |
| 165 | * ToDo: the 'wakeup' member in the platform data is more of a linux |
| 166 | * specfic information. Hence, there is no binding for that yet and |
| 167 | * not parsed here. |
| 168 | */ |
| 169 | return pd; |
| 170 | } |
| 171 | |
Lee Jones | 8bace2d | 2014-02-03 08:22:30 +0000 | [diff] [blame] | 172 | static inline unsigned long max8998_i2c_get_driver_data(struct i2c_client *i2c, |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 173 | const struct i2c_device_id *id) |
| 174 | { |
| 175 | if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) { |
| 176 | const struct of_device_id *match; |
| 177 | match = of_match_node(max8998_dt_match, i2c->dev.of_node); |
Lee Jones | 8bace2d | 2014-02-03 08:22:30 +0000 | [diff] [blame] | 178 | return (unsigned long)match->data; |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 179 | } |
| 180 | |
Lee Jones | 8bace2d | 2014-02-03 08:22:30 +0000 | [diff] [blame] | 181 | return id->driver_data; |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 184 | static int max8998_i2c_probe(struct i2c_client *i2c, |
| 185 | const struct i2c_device_id *id) |
| 186 | { |
Jingoo Han | 334a41c | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 187 | struct max8998_platform_data *pdata = dev_get_platdata(&i2c->dev); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 188 | struct max8998_dev *max8998; |
| 189 | int ret = 0; |
| 190 | |
Jingoo Han | 0010dd3 | 2013-08-20 16:04:42 +0900 | [diff] [blame] | 191 | max8998 = devm_kzalloc(&i2c->dev, sizeof(struct max8998_dev), |
| 192 | GFP_KERNEL); |
Axel Lin | 8f1f151 | 2010-08-09 14:48:16 +0800 | [diff] [blame] | 193 | if (max8998 == NULL) |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 194 | return -ENOMEM; |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 195 | |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 196 | if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) { |
| 197 | pdata = max8998_i2c_parse_dt_pdata(&i2c->dev); |
| 198 | if (IS_ERR(pdata)) { |
| 199 | ret = PTR_ERR(pdata); |
| 200 | goto err; |
| 201 | } |
| 202 | } |
| 203 | |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 204 | i2c_set_clientdata(i2c, max8998); |
| 205 | max8998->dev = &i2c->dev; |
Joonyoung Shim | 676e02d | 2010-08-06 11:28:06 +0900 | [diff] [blame] | 206 | max8998->i2c = i2c; |
Joonyoung Shim | 2c7e6f5 | 2010-09-10 18:36:39 +0200 | [diff] [blame] | 207 | max8998->irq = i2c->irq; |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 208 | max8998->type = max8998_i2c_get_driver_data(i2c, id); |
| 209 | max8998->pdata = pdata; |
Joonyoung Shim | 2c7e6f5 | 2010-09-10 18:36:39 +0200 | [diff] [blame] | 210 | if (pdata) { |
| 211 | max8998->ono = pdata->ono; |
| 212 | max8998->irq_base = pdata->irq_base; |
MyungJoo Ham | cdd137c | 2010-12-23 17:53:36 +0900 | [diff] [blame] | 213 | max8998->wakeup = pdata->wakeup; |
Joonyoung Shim | 2c7e6f5 | 2010-09-10 18:36:39 +0200 | [diff] [blame] | 214 | } |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 215 | mutex_init(&max8998->iolock); |
| 216 | |
Joonyoung Shim | 9b16c0a | 2010-08-06 11:28:08 +0900 | [diff] [blame] | 217 | max8998->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR); |
Krzysztof Kozlowski | ed26f87 | 2014-02-11 11:03:35 +0100 | [diff] [blame] | 218 | if (!max8998->rtc) { |
| 219 | dev_err(&i2c->dev, "Failed to allocate I2C device for RTC\n"); |
| 220 | return -ENODEV; |
| 221 | } |
Joonyoung Shim | 9b16c0a | 2010-08-06 11:28:08 +0900 | [diff] [blame] | 222 | i2c_set_clientdata(max8998->rtc, max8998); |
| 223 | |
Joonyoung Shim | 2c7e6f5 | 2010-09-10 18:36:39 +0200 | [diff] [blame] | 224 | max8998_irq_init(max8998); |
| 225 | |
MyungJoo Ham | cdd137c | 2010-12-23 17:53:36 +0900 | [diff] [blame] | 226 | pm_runtime_set_active(max8998->dev); |
| 227 | |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 228 | switch (max8998->type) { |
MyungJoo Ham | 337ce5d | 2011-01-04 14:17:39 +0900 | [diff] [blame] | 229 | case TYPE_LP3974: |
| 230 | ret = mfd_add_devices(max8998->dev, -1, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 231 | lp3974_devs, ARRAY_SIZE(lp3974_devs), |
| 232 | NULL, 0, NULL); |
MyungJoo Ham | 337ce5d | 2011-01-04 14:17:39 +0900 | [diff] [blame] | 233 | break; |
| 234 | case TYPE_MAX8998: |
| 235 | ret = mfd_add_devices(max8998->dev, -1, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 236 | max8998_devs, ARRAY_SIZE(max8998_devs), |
| 237 | NULL, 0, NULL); |
MyungJoo Ham | 337ce5d | 2011-01-04 14:17:39 +0900 | [diff] [blame] | 238 | break; |
| 239 | default: |
| 240 | ret = -EINVAL; |
| 241 | } |
| 242 | |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 243 | if (ret < 0) |
| 244 | goto err; |
| 245 | |
Jonghwan Choi | 7ef7359 | 2011-11-29 17:17:51 +0900 | [diff] [blame] | 246 | device_init_wakeup(max8998->dev, max8998->wakeup); |
| 247 | |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 248 | return ret; |
| 249 | |
| 250 | err: |
| 251 | mfd_remove_devices(max8998->dev); |
Axel Lin | 7484552 | 2010-10-22 08:31:49 +0800 | [diff] [blame] | 252 | max8998_irq_exit(max8998); |
| 253 | i2c_unregister_device(max8998->rtc); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 254 | return ret; |
| 255 | } |
| 256 | |
| 257 | static int max8998_i2c_remove(struct i2c_client *i2c) |
| 258 | { |
| 259 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
| 260 | |
| 261 | mfd_remove_devices(max8998->dev); |
Axel Lin | 7484552 | 2010-10-22 08:31:49 +0800 | [diff] [blame] | 262 | max8998_irq_exit(max8998); |
| 263 | i2c_unregister_device(max8998->rtc); |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | static const struct i2c_device_id max8998_i2c_id[] = { |
Lukasz Majewski | 509bd47 | 2010-09-27 14:32:24 +0200 | [diff] [blame] | 269 | { "max8998", TYPE_MAX8998 }, |
| 270 | { "lp3974", TYPE_LP3974}, |
Kyungmin Park | f8539dd | 2010-08-23 13:46:49 +0900 | [diff] [blame] | 271 | { } |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 272 | }; |
| 273 | MODULE_DEVICE_TABLE(i2c, max8998_i2c_id); |
| 274 | |
MyungJoo Ham | cdd137c | 2010-12-23 17:53:36 +0900 | [diff] [blame] | 275 | static int max8998_suspend(struct device *dev) |
| 276 | { |
| 277 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
| 278 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
| 279 | |
Jonghwan Choi | 7ef7359 | 2011-11-29 17:17:51 +0900 | [diff] [blame] | 280 | if (device_may_wakeup(dev)) |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 281 | irq_set_irq_wake(max8998->irq, 1); |
MyungJoo Ham | cdd137c | 2010-12-23 17:53:36 +0900 | [diff] [blame] | 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | static int max8998_resume(struct device *dev) |
| 286 | { |
| 287 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
| 288 | struct max8998_dev *max8998 = i2c_get_clientdata(i2c); |
| 289 | |
Jonghwan Choi | 7ef7359 | 2011-11-29 17:17:51 +0900 | [diff] [blame] | 290 | if (device_may_wakeup(dev)) |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 291 | irq_set_irq_wake(max8998->irq, 0); |
MyungJoo Ham | cdd137c | 2010-12-23 17:53:36 +0900 | [diff] [blame] | 292 | /* |
| 293 | * In LP3974, if IRQ registers are not "read & clear" |
| 294 | * when it's set during sleep, the interrupt becomes |
| 295 | * disabled. |
| 296 | */ |
| 297 | return max8998_irq_resume(i2c_get_clientdata(i2c)); |
| 298 | } |
| 299 | |
| 300 | struct max8998_reg_dump { |
| 301 | u8 addr; |
| 302 | u8 val; |
| 303 | }; |
| 304 | #define SAVE_ITEM(x) { .addr = (x), .val = 0x0, } |
Mark Brown | 44be0a4 | 2011-01-20 21:47:31 +0000 | [diff] [blame] | 305 | static struct max8998_reg_dump max8998_dump[] = { |
MyungJoo Ham | cdd137c | 2010-12-23 17:53:36 +0900 | [diff] [blame] | 306 | SAVE_ITEM(MAX8998_REG_IRQM1), |
| 307 | SAVE_ITEM(MAX8998_REG_IRQM2), |
| 308 | SAVE_ITEM(MAX8998_REG_IRQM3), |
| 309 | SAVE_ITEM(MAX8998_REG_IRQM4), |
| 310 | SAVE_ITEM(MAX8998_REG_STATUSM1), |
| 311 | SAVE_ITEM(MAX8998_REG_STATUSM2), |
| 312 | SAVE_ITEM(MAX8998_REG_CHGR1), |
| 313 | SAVE_ITEM(MAX8998_REG_CHGR2), |
| 314 | SAVE_ITEM(MAX8998_REG_LDO_ACTIVE_DISCHARGE1), |
| 315 | SAVE_ITEM(MAX8998_REG_LDO_ACTIVE_DISCHARGE1), |
| 316 | SAVE_ITEM(MAX8998_REG_BUCK_ACTIVE_DISCHARGE3), |
| 317 | SAVE_ITEM(MAX8998_REG_ONOFF1), |
| 318 | SAVE_ITEM(MAX8998_REG_ONOFF2), |
| 319 | SAVE_ITEM(MAX8998_REG_ONOFF3), |
| 320 | SAVE_ITEM(MAX8998_REG_ONOFF4), |
| 321 | SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE1), |
| 322 | SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE2), |
| 323 | SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE3), |
| 324 | SAVE_ITEM(MAX8998_REG_BUCK1_VOLTAGE4), |
| 325 | SAVE_ITEM(MAX8998_REG_BUCK2_VOLTAGE1), |
| 326 | SAVE_ITEM(MAX8998_REG_BUCK2_VOLTAGE2), |
| 327 | SAVE_ITEM(MAX8998_REG_LDO2_LDO3), |
| 328 | SAVE_ITEM(MAX8998_REG_LDO4), |
| 329 | SAVE_ITEM(MAX8998_REG_LDO5), |
| 330 | SAVE_ITEM(MAX8998_REG_LDO6), |
| 331 | SAVE_ITEM(MAX8998_REG_LDO7), |
| 332 | SAVE_ITEM(MAX8998_REG_LDO8_LDO9), |
| 333 | SAVE_ITEM(MAX8998_REG_LDO10_LDO11), |
| 334 | SAVE_ITEM(MAX8998_REG_LDO12), |
| 335 | SAVE_ITEM(MAX8998_REG_LDO13), |
| 336 | SAVE_ITEM(MAX8998_REG_LDO14), |
| 337 | SAVE_ITEM(MAX8998_REG_LDO15), |
| 338 | SAVE_ITEM(MAX8998_REG_LDO16), |
| 339 | SAVE_ITEM(MAX8998_REG_LDO17), |
| 340 | SAVE_ITEM(MAX8998_REG_BKCHR), |
| 341 | SAVE_ITEM(MAX8998_REG_LBCNFG1), |
| 342 | SAVE_ITEM(MAX8998_REG_LBCNFG2), |
| 343 | }; |
| 344 | /* Save registers before hibernation */ |
| 345 | static int max8998_freeze(struct device *dev) |
| 346 | { |
| 347 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
| 348 | int i; |
| 349 | |
| 350 | for (i = 0; i < ARRAY_SIZE(max8998_dump); i++) |
| 351 | max8998_read_reg(i2c, max8998_dump[i].addr, |
| 352 | &max8998_dump[i].val); |
| 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | /* Restore registers after hibernation */ |
| 358 | static int max8998_restore(struct device *dev) |
| 359 | { |
| 360 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); |
| 361 | int i; |
| 362 | |
| 363 | for (i = 0; i < ARRAY_SIZE(max8998_dump); i++) |
| 364 | max8998_write_reg(i2c, max8998_dump[i].addr, |
| 365 | max8998_dump[i].val); |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
Mark Brown | 44be0a4 | 2011-01-20 21:47:31 +0000 | [diff] [blame] | 370 | static const struct dev_pm_ops max8998_pm = { |
MyungJoo Ham | cdd137c | 2010-12-23 17:53:36 +0900 | [diff] [blame] | 371 | .suspend = max8998_suspend, |
| 372 | .resume = max8998_resume, |
| 373 | .freeze = max8998_freeze, |
| 374 | .restore = max8998_restore, |
| 375 | }; |
| 376 | |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 377 | static struct i2c_driver max8998_i2c_driver = { |
| 378 | .driver = { |
| 379 | .name = "max8998", |
| 380 | .owner = THIS_MODULE, |
MyungJoo Ham | cdd137c | 2010-12-23 17:53:36 +0900 | [diff] [blame] | 381 | .pm = &max8998_pm, |
Tomasz Figa | ee999fb | 2013-06-25 16:08:10 +0200 | [diff] [blame] | 382 | .of_match_table = of_match_ptr(max8998_dt_match), |
Kyungmin Park | 156f252 | 2010-06-16 09:04:16 +0200 | [diff] [blame] | 383 | }, |
| 384 | .probe = max8998_i2c_probe, |
| 385 | .remove = max8998_i2c_remove, |
| 386 | .id_table = max8998_i2c_id, |
| 387 | }; |
| 388 | |
| 389 | static int __init max8998_i2c_init(void) |
| 390 | { |
| 391 | return i2c_add_driver(&max8998_i2c_driver); |
| 392 | } |
| 393 | /* init early so consumer devices can complete system boot */ |
| 394 | subsys_initcall(max8998_i2c_init); |
| 395 | |
| 396 | static void __exit max8998_i2c_exit(void) |
| 397 | { |
| 398 | i2c_del_driver(&max8998_i2c_driver); |
| 399 | } |
| 400 | module_exit(max8998_i2c_exit); |
| 401 | |
| 402 | MODULE_DESCRIPTION("MAXIM 8998 multi-function core driver"); |
| 403 | MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>"); |
| 404 | MODULE_LICENSE("GPL"); |