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