Krzysztof Kozlowski | d7d8d7a | 2018-08-07 18:11:23 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // max8997.c - mfd core driver for the Maxim 8966 and 8997 |
| 4 | // |
| 5 | // Copyright (C) 2011 Samsung Electronics |
| 6 | // MyungJoo Ham <myungjoo.ham@samsung.com> |
| 7 | // |
| 8 | // This driver is based on max8998.c |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 9 | |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 10 | #include <linux/err.h> |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
| 12 | #include <linux/i2c.h> |
Sachin Kamat | fb7d4a5 | 2013-10-16 14:26:51 +0530 | [diff] [blame] | 13 | #include <linux/of.h> |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 14 | #include <linux/of_irq.h> |
MyungJoo Ham | 01fdaab | 2011-08-19 14:39:40 +0900 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 16 | #include <linux/pm_runtime.h> |
Paul Gortmaker | 9cf0c21 | 2016-06-02 20:39:47 -0400 | [diff] [blame] | 17 | #include <linux/init.h> |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 18 | #include <linux/mutex.h> |
| 19 | #include <linux/mfd/core.h> |
| 20 | #include <linux/mfd/max8997.h> |
| 21 | #include <linux/mfd/max8997-private.h> |
| 22 | |
| 23 | #define I2C_ADDR_PMIC (0xCC >> 1) |
| 24 | #define I2C_ADDR_MUIC (0x4A >> 1) |
| 25 | #define I2C_ADDR_BATTERY (0x6C >> 1) |
| 26 | #define I2C_ADDR_RTC (0x0C >> 1) |
| 27 | #define I2C_ADDR_HAPTIC (0x90 >> 1) |
| 28 | |
Geert Uytterhoeven | 7c0517b | 2013-11-18 14:33:00 +0100 | [diff] [blame] | 29 | static const struct mfd_cell max8997_devs[] = { |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 30 | { .name = "max8997-pmic", }, |
| 31 | { .name = "max8997-rtc", }, |
| 32 | { .name = "max8997-battery", }, |
| 33 | { .name = "max8997-haptic", }, |
| 34 | { .name = "max8997-muic", }, |
Donggeun Kim | f6dd2db | 2011-12-14 18:23:55 +0900 | [diff] [blame] | 35 | { .name = "max8997-led", .id = 1 }, |
| 36 | { .name = "max8997-led", .id = 2 }, |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 37 | }; |
| 38 | |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 39 | #ifdef CONFIG_OF |
Krzysztof Kozlowski | f1eb2cb | 2014-05-13 12:58:49 +0200 | [diff] [blame] | 40 | static const struct of_device_id max8997_pmic_dt_match[] = { |
Jingoo Han | ed6ccdc | 2013-08-01 11:01:27 +0900 | [diff] [blame] | 41 | { .compatible = "maxim,max8997-pmic", .data = (void *)TYPE_MAX8997 }, |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 42 | {}, |
| 43 | }; |
| 44 | #endif |
| 45 | |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 46 | int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest) |
| 47 | { |
| 48 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
| 49 | int ret; |
| 50 | |
| 51 | mutex_lock(&max8997->iolock); |
| 52 | ret = i2c_smbus_read_byte_data(i2c, reg); |
| 53 | mutex_unlock(&max8997->iolock); |
| 54 | if (ret < 0) |
| 55 | return ret; |
| 56 | |
| 57 | ret &= 0xff; |
| 58 | *dest = ret; |
| 59 | return 0; |
| 60 | } |
| 61 | EXPORT_SYMBOL_GPL(max8997_read_reg); |
| 62 | |
| 63 | int max8997_bulk_read(struct i2c_client *i2c, u8 reg, int count, u8 *buf) |
| 64 | { |
| 65 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
| 66 | int ret; |
| 67 | |
| 68 | mutex_lock(&max8997->iolock); |
| 69 | ret = i2c_smbus_read_i2c_block_data(i2c, reg, count, buf); |
| 70 | mutex_unlock(&max8997->iolock); |
| 71 | if (ret < 0) |
| 72 | return ret; |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | EXPORT_SYMBOL_GPL(max8997_bulk_read); |
| 77 | |
| 78 | int max8997_write_reg(struct i2c_client *i2c, u8 reg, u8 value) |
| 79 | { |
| 80 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
| 81 | int ret; |
| 82 | |
| 83 | mutex_lock(&max8997->iolock); |
| 84 | ret = i2c_smbus_write_byte_data(i2c, reg, value); |
| 85 | mutex_unlock(&max8997->iolock); |
| 86 | return ret; |
| 87 | } |
| 88 | EXPORT_SYMBOL_GPL(max8997_write_reg); |
| 89 | |
| 90 | int max8997_bulk_write(struct i2c_client *i2c, u8 reg, int count, u8 *buf) |
| 91 | { |
| 92 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
| 93 | int ret; |
| 94 | |
| 95 | mutex_lock(&max8997->iolock); |
| 96 | ret = i2c_smbus_write_i2c_block_data(i2c, reg, count, buf); |
| 97 | mutex_unlock(&max8997->iolock); |
| 98 | if (ret < 0) |
| 99 | return ret; |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | EXPORT_SYMBOL_GPL(max8997_bulk_write); |
| 104 | |
| 105 | int max8997_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask) |
| 106 | { |
| 107 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
| 108 | int ret; |
| 109 | |
| 110 | mutex_lock(&max8997->iolock); |
| 111 | ret = i2c_smbus_read_byte_data(i2c, reg); |
| 112 | if (ret >= 0) { |
| 113 | u8 old_val = ret & 0xff; |
| 114 | u8 new_val = (val & mask) | (old_val & (~mask)); |
| 115 | ret = i2c_smbus_write_byte_data(i2c, reg, new_val); |
| 116 | } |
| 117 | mutex_unlock(&max8997->iolock); |
| 118 | return ret; |
| 119 | } |
| 120 | EXPORT_SYMBOL_GPL(max8997_update_reg); |
| 121 | |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 122 | /* |
| 123 | * Only the common platform data elements for max8997 are parsed here from the |
| 124 | * device tree. Other sub-modules of max8997 such as pmic, rtc and others have |
| 125 | * to parse their own platform data elements from device tree. |
| 126 | * |
| 127 | * The max8997 platform data structure is instantiated here and the drivers for |
| 128 | * the sub-modules need not instantiate another instance while parsing their |
| 129 | * platform data. |
| 130 | */ |
| 131 | static struct max8997_platform_data *max8997_i2c_parse_dt_pdata( |
| 132 | struct device *dev) |
| 133 | { |
| 134 | struct max8997_platform_data *pd; |
| 135 | |
| 136 | pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); |
Markus Elfring | f01b90b | 2018-01-15 09:35:17 +0100 | [diff] [blame] | 137 | if (!pd) |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 138 | return ERR_PTR(-ENOMEM); |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 139 | |
| 140 | pd->ono = irq_of_parse_and_map(dev->of_node, 1); |
| 141 | |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 142 | return pd; |
| 143 | } |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 144 | |
Lee Jones | 05fb7a5 | 2014-01-23 14:35:28 +0000 | [diff] [blame] | 145 | static inline unsigned long max8997_i2c_get_driver_data(struct i2c_client *i2c, |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 146 | const struct i2c_device_id *id) |
| 147 | { |
Manish Badarkhe | 01c3f11 | 2013-12-22 23:18:49 +0530 | [diff] [blame] | 148 | if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node) { |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 149 | const struct of_device_id *match; |
| 150 | match = of_match_node(max8997_pmic_dt_match, i2c->dev.of_node); |
Lee Jones | 05fb7a5 | 2014-01-23 14:35:28 +0000 | [diff] [blame] | 151 | return (unsigned long)match->data; |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 152 | } |
Lee Jones | 05fb7a5 | 2014-01-23 14:35:28 +0000 | [diff] [blame] | 153 | return id->driver_data; |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 154 | } |
| 155 | |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 156 | static int max8997_i2c_probe(struct i2c_client *i2c, |
| 157 | const struct i2c_device_id *id) |
| 158 | { |
| 159 | struct max8997_dev *max8997; |
Jingoo Han | 334a41ce | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 160 | struct max8997_platform_data *pdata = dev_get_platdata(&i2c->dev); |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 161 | int ret = 0; |
| 162 | |
Jingoo Han | 6922ffc | 2013-08-20 16:03:20 +0900 | [diff] [blame] | 163 | max8997 = devm_kzalloc(&i2c->dev, sizeof(struct max8997_dev), |
| 164 | GFP_KERNEL); |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 165 | if (max8997 == NULL) |
| 166 | return -ENOMEM; |
| 167 | |
| 168 | i2c_set_clientdata(i2c, max8997); |
| 169 | max8997->dev = &i2c->dev; |
| 170 | max8997->i2c = i2c; |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 171 | max8997->type = max8997_i2c_get_driver_data(i2c, id); |
MyungJoo Ham | 7eb3154 | 2011-08-18 16:37:35 +0900 | [diff] [blame] | 172 | max8997->irq = i2c->irq; |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 173 | |
Manish Badarkhe | 01c3f11 | 2013-12-22 23:18:49 +0530 | [diff] [blame] | 174 | if (IS_ENABLED(CONFIG_OF) && max8997->dev->of_node) { |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 175 | pdata = max8997_i2c_parse_dt_pdata(max8997->dev); |
Jingoo Han | 6922ffc | 2013-08-20 16:03:20 +0900 | [diff] [blame] | 176 | if (IS_ERR(pdata)) |
| 177 | return PTR_ERR(pdata); |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 178 | } |
| 179 | |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 180 | if (!pdata) |
Jingoo Han | 6922ffc | 2013-08-20 16:03:20 +0900 | [diff] [blame] | 181 | return ret; |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 182 | |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 183 | max8997->pdata = pdata; |
MyungJoo Ham | 7eb3154 | 2011-08-18 16:37:35 +0900 | [diff] [blame] | 184 | max8997->ono = pdata->ono; |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 185 | |
| 186 | mutex_init(&max8997->iolock); |
| 187 | |
| 188 | max8997->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC); |
Krzysztof Kozlowski | 97dc4ed | 2014-02-11 11:03:34 +0100 | [diff] [blame] | 189 | if (!max8997->rtc) { |
| 190 | dev_err(max8997->dev, "Failed to allocate I2C device for RTC\n"); |
| 191 | return -ENODEV; |
| 192 | } |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 193 | i2c_set_clientdata(max8997->rtc, max8997); |
Krzysztof Kozlowski | 97dc4ed | 2014-02-11 11:03:34 +0100 | [diff] [blame] | 194 | |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 195 | max8997->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); |
Krzysztof Kozlowski | 97dc4ed | 2014-02-11 11:03:34 +0100 | [diff] [blame] | 196 | if (!max8997->haptic) { |
| 197 | dev_err(max8997->dev, "Failed to allocate I2C device for Haptic\n"); |
| 198 | ret = -ENODEV; |
| 199 | goto err_i2c_haptic; |
| 200 | } |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 201 | i2c_set_clientdata(max8997->haptic, max8997); |
Krzysztof Kozlowski | 97dc4ed | 2014-02-11 11:03:34 +0100 | [diff] [blame] | 202 | |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 203 | max8997->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); |
Krzysztof Kozlowski | 97dc4ed | 2014-02-11 11:03:34 +0100 | [diff] [blame] | 204 | if (!max8997->muic) { |
| 205 | dev_err(max8997->dev, "Failed to allocate I2C device for MUIC\n"); |
| 206 | ret = -ENODEV; |
| 207 | goto err_i2c_muic; |
| 208 | } |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 209 | i2c_set_clientdata(max8997->muic, max8997); |
| 210 | |
| 211 | pm_runtime_set_active(max8997->dev); |
| 212 | |
MyungJoo Ham | 7eb3154 | 2011-08-18 16:37:35 +0900 | [diff] [blame] | 213 | max8997_irq_init(max8997); |
| 214 | |
Laszlo Papp | c1ec8fc | 2013-12-17 12:49:51 +0000 | [diff] [blame] | 215 | ret = mfd_add_devices(max8997->dev, -1, max8997_devs, |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 216 | ARRAY_SIZE(max8997_devs), |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 217 | NULL, 0, NULL); |
Laszlo Papp | c1ec8fc | 2013-12-17 12:49:51 +0000 | [diff] [blame] | 218 | if (ret < 0) { |
| 219 | dev_err(max8997->dev, "failed to add MFD devices %d\n", ret); |
| 220 | goto err_mfd; |
| 221 | } |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 222 | |
| 223 | /* |
| 224 | * TODO: enable others (flash, muic, rtc, battery, ...) and |
| 225 | * check the return value |
| 226 | */ |
| 227 | |
MyungJoo Ham | 01fdaab | 2011-08-19 14:39:40 +0900 | [diff] [blame] | 228 | /* MAX8997 has a power button input. */ |
Marek Szyprowski | efddff2 | 2018-09-05 13:54:07 +0200 | [diff] [blame] | 229 | device_init_wakeup(max8997->dev, true); |
MyungJoo Ham | 01fdaab | 2011-08-19 14:39:40 +0900 | [diff] [blame] | 230 | |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 231 | return ret; |
| 232 | |
| 233 | err_mfd: |
| 234 | mfd_remove_devices(max8997->dev); |
| 235 | i2c_unregister_device(max8997->muic); |
Krzysztof Kozlowski | 97dc4ed | 2014-02-11 11:03:34 +0100 | [diff] [blame] | 236 | err_i2c_muic: |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 237 | i2c_unregister_device(max8997->haptic); |
Krzysztof Kozlowski | 97dc4ed | 2014-02-11 11:03:34 +0100 | [diff] [blame] | 238 | err_i2c_haptic: |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 239 | i2c_unregister_device(max8997->rtc); |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 240 | return ret; |
| 241 | } |
| 242 | |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 243 | static const struct i2c_device_id max8997_i2c_id[] = { |
| 244 | { "max8997", TYPE_MAX8997 }, |
| 245 | { "max8966", TYPE_MAX8966 }, |
| 246 | { } |
| 247 | }; |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 248 | |
Sachin Kamat | b673e24c | 2012-06-04 16:39:07 +0530 | [diff] [blame] | 249 | static u8 max8997_dumpaddr_pmic[] = { |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 250 | MAX8997_REG_INT1MSK, |
| 251 | MAX8997_REG_INT2MSK, |
| 252 | MAX8997_REG_INT3MSK, |
| 253 | MAX8997_REG_INT4MSK, |
| 254 | MAX8997_REG_MAINCON1, |
| 255 | MAX8997_REG_MAINCON2, |
| 256 | MAX8997_REG_BUCKRAMP, |
| 257 | MAX8997_REG_BUCK1CTRL, |
| 258 | MAX8997_REG_BUCK1DVS1, |
| 259 | MAX8997_REG_BUCK1DVS2, |
| 260 | MAX8997_REG_BUCK1DVS3, |
| 261 | MAX8997_REG_BUCK1DVS4, |
| 262 | MAX8997_REG_BUCK1DVS5, |
| 263 | MAX8997_REG_BUCK1DVS6, |
| 264 | MAX8997_REG_BUCK1DVS7, |
| 265 | MAX8997_REG_BUCK1DVS8, |
| 266 | MAX8997_REG_BUCK2CTRL, |
| 267 | MAX8997_REG_BUCK2DVS1, |
| 268 | MAX8997_REG_BUCK2DVS2, |
| 269 | MAX8997_REG_BUCK2DVS3, |
| 270 | MAX8997_REG_BUCK2DVS4, |
| 271 | MAX8997_REG_BUCK2DVS5, |
| 272 | MAX8997_REG_BUCK2DVS6, |
| 273 | MAX8997_REG_BUCK2DVS7, |
| 274 | MAX8997_REG_BUCK2DVS8, |
| 275 | MAX8997_REG_BUCK3CTRL, |
| 276 | MAX8997_REG_BUCK3DVS, |
| 277 | MAX8997_REG_BUCK4CTRL, |
| 278 | MAX8997_REG_BUCK4DVS, |
| 279 | MAX8997_REG_BUCK5CTRL, |
| 280 | MAX8997_REG_BUCK5DVS1, |
| 281 | MAX8997_REG_BUCK5DVS2, |
| 282 | MAX8997_REG_BUCK5DVS3, |
| 283 | MAX8997_REG_BUCK5DVS4, |
| 284 | MAX8997_REG_BUCK5DVS5, |
| 285 | MAX8997_REG_BUCK5DVS6, |
| 286 | MAX8997_REG_BUCK5DVS7, |
| 287 | MAX8997_REG_BUCK5DVS8, |
| 288 | MAX8997_REG_BUCK6CTRL, |
| 289 | MAX8997_REG_BUCK6BPSKIPCTRL, |
| 290 | MAX8997_REG_BUCK7CTRL, |
| 291 | MAX8997_REG_BUCK7DVS, |
| 292 | MAX8997_REG_LDO1CTRL, |
| 293 | MAX8997_REG_LDO2CTRL, |
| 294 | MAX8997_REG_LDO3CTRL, |
| 295 | MAX8997_REG_LDO4CTRL, |
| 296 | MAX8997_REG_LDO5CTRL, |
| 297 | MAX8997_REG_LDO6CTRL, |
| 298 | MAX8997_REG_LDO7CTRL, |
| 299 | MAX8997_REG_LDO8CTRL, |
| 300 | MAX8997_REG_LDO9CTRL, |
| 301 | MAX8997_REG_LDO10CTRL, |
| 302 | MAX8997_REG_LDO11CTRL, |
| 303 | MAX8997_REG_LDO12CTRL, |
| 304 | MAX8997_REG_LDO13CTRL, |
| 305 | MAX8997_REG_LDO14CTRL, |
| 306 | MAX8997_REG_LDO15CTRL, |
| 307 | MAX8997_REG_LDO16CTRL, |
| 308 | MAX8997_REG_LDO17CTRL, |
| 309 | MAX8997_REG_LDO18CTRL, |
| 310 | MAX8997_REG_LDO21CTRL, |
| 311 | MAX8997_REG_MBCCTRL1, |
| 312 | MAX8997_REG_MBCCTRL2, |
| 313 | MAX8997_REG_MBCCTRL3, |
| 314 | MAX8997_REG_MBCCTRL4, |
| 315 | MAX8997_REG_MBCCTRL5, |
| 316 | MAX8997_REG_MBCCTRL6, |
| 317 | MAX8997_REG_OTPCGHCVS, |
| 318 | MAX8997_REG_SAFEOUTCTRL, |
| 319 | MAX8997_REG_LBCNFG1, |
| 320 | MAX8997_REG_LBCNFG2, |
| 321 | MAX8997_REG_BBCCTRL, |
| 322 | |
| 323 | MAX8997_REG_FLASH1_CUR, |
| 324 | MAX8997_REG_FLASH2_CUR, |
| 325 | MAX8997_REG_MOVIE_CUR, |
| 326 | MAX8997_REG_GSMB_CUR, |
| 327 | MAX8997_REG_BOOST_CNTL, |
| 328 | MAX8997_REG_LEN_CNTL, |
| 329 | MAX8997_REG_FLASH_CNTL, |
| 330 | MAX8997_REG_WDT_CNTL, |
| 331 | MAX8997_REG_MAXFLASH1, |
| 332 | MAX8997_REG_MAXFLASH2, |
| 333 | MAX8997_REG_FLASHSTATUSMASK, |
| 334 | |
| 335 | MAX8997_REG_GPIOCNTL1, |
| 336 | MAX8997_REG_GPIOCNTL2, |
| 337 | MAX8997_REG_GPIOCNTL3, |
| 338 | MAX8997_REG_GPIOCNTL4, |
| 339 | MAX8997_REG_GPIOCNTL5, |
| 340 | MAX8997_REG_GPIOCNTL6, |
| 341 | MAX8997_REG_GPIOCNTL7, |
| 342 | MAX8997_REG_GPIOCNTL8, |
| 343 | MAX8997_REG_GPIOCNTL9, |
| 344 | MAX8997_REG_GPIOCNTL10, |
| 345 | MAX8997_REG_GPIOCNTL11, |
| 346 | MAX8997_REG_GPIOCNTL12, |
| 347 | |
| 348 | MAX8997_REG_LDO1CONFIG, |
| 349 | MAX8997_REG_LDO2CONFIG, |
| 350 | MAX8997_REG_LDO3CONFIG, |
| 351 | MAX8997_REG_LDO4CONFIG, |
| 352 | MAX8997_REG_LDO5CONFIG, |
| 353 | MAX8997_REG_LDO6CONFIG, |
| 354 | MAX8997_REG_LDO7CONFIG, |
| 355 | MAX8997_REG_LDO8CONFIG, |
| 356 | MAX8997_REG_LDO9CONFIG, |
| 357 | MAX8997_REG_LDO10CONFIG, |
| 358 | MAX8997_REG_LDO11CONFIG, |
| 359 | MAX8997_REG_LDO12CONFIG, |
| 360 | MAX8997_REG_LDO13CONFIG, |
| 361 | MAX8997_REG_LDO14CONFIG, |
| 362 | MAX8997_REG_LDO15CONFIG, |
| 363 | MAX8997_REG_LDO16CONFIG, |
| 364 | MAX8997_REG_LDO17CONFIG, |
| 365 | MAX8997_REG_LDO18CONFIG, |
| 366 | MAX8997_REG_LDO21CONFIG, |
| 367 | |
| 368 | MAX8997_REG_DVSOKTIMER1, |
| 369 | MAX8997_REG_DVSOKTIMER2, |
| 370 | MAX8997_REG_DVSOKTIMER4, |
| 371 | MAX8997_REG_DVSOKTIMER5, |
| 372 | }; |
| 373 | |
Sachin Kamat | b673e24c | 2012-06-04 16:39:07 +0530 | [diff] [blame] | 374 | static u8 max8997_dumpaddr_muic[] = { |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 375 | MAX8997_MUIC_REG_INTMASK1, |
| 376 | MAX8997_MUIC_REG_INTMASK2, |
| 377 | MAX8997_MUIC_REG_INTMASK3, |
| 378 | MAX8997_MUIC_REG_CDETCTRL, |
| 379 | MAX8997_MUIC_REG_CONTROL1, |
| 380 | MAX8997_MUIC_REG_CONTROL2, |
| 381 | MAX8997_MUIC_REG_CONTROL3, |
| 382 | }; |
| 383 | |
Sachin Kamat | b673e24c | 2012-06-04 16:39:07 +0530 | [diff] [blame] | 384 | static u8 max8997_dumpaddr_haptic[] = { |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 385 | MAX8997_HAPTIC_REG_CONF1, |
| 386 | MAX8997_HAPTIC_REG_CONF2, |
| 387 | MAX8997_HAPTIC_REG_DRVCONF, |
| 388 | MAX8997_HAPTIC_REG_CYCLECONF1, |
| 389 | MAX8997_HAPTIC_REG_CYCLECONF2, |
| 390 | MAX8997_HAPTIC_REG_SIGCONF1, |
| 391 | MAX8997_HAPTIC_REG_SIGCONF2, |
| 392 | MAX8997_HAPTIC_REG_SIGCONF3, |
| 393 | MAX8997_HAPTIC_REG_SIGCONF4, |
| 394 | MAX8997_HAPTIC_REG_SIGDC1, |
| 395 | MAX8997_HAPTIC_REG_SIGDC2, |
| 396 | MAX8997_HAPTIC_REG_SIGPWMDC1, |
| 397 | MAX8997_HAPTIC_REG_SIGPWMDC2, |
| 398 | MAX8997_HAPTIC_REG_SIGPWMDC3, |
| 399 | MAX8997_HAPTIC_REG_SIGPWMDC4, |
| 400 | }; |
| 401 | |
| 402 | static int max8997_freeze(struct device *dev) |
| 403 | { |
Geliang Tang | 1b5420e | 2015-12-28 23:00:14 +0800 | [diff] [blame] | 404 | struct i2c_client *i2c = to_i2c_client(dev); |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 405 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
| 406 | int i; |
| 407 | |
| 408 | for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_pmic); i++) |
| 409 | max8997_read_reg(i2c, max8997_dumpaddr_pmic[i], |
| 410 | &max8997->reg_dump[i]); |
| 411 | |
| 412 | for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_muic); i++) |
| 413 | max8997_read_reg(i2c, max8997_dumpaddr_muic[i], |
| 414 | &max8997->reg_dump[i + MAX8997_REG_PMIC_END]); |
| 415 | |
| 416 | for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_haptic); i++) |
| 417 | max8997_read_reg(i2c, max8997_dumpaddr_haptic[i], |
| 418 | &max8997->reg_dump[i + MAX8997_REG_PMIC_END + |
| 419 | MAX8997_MUIC_REG_END]); |
| 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | static int max8997_restore(struct device *dev) |
| 425 | { |
Geliang Tang | 1b5420e | 2015-12-28 23:00:14 +0800 | [diff] [blame] | 426 | struct i2c_client *i2c = to_i2c_client(dev); |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 427 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
| 428 | int i; |
| 429 | |
| 430 | for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_pmic); i++) |
| 431 | max8997_write_reg(i2c, max8997_dumpaddr_pmic[i], |
| 432 | max8997->reg_dump[i]); |
| 433 | |
| 434 | for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_muic); i++) |
| 435 | max8997_write_reg(i2c, max8997_dumpaddr_muic[i], |
| 436 | max8997->reg_dump[i + MAX8997_REG_PMIC_END]); |
| 437 | |
| 438 | for (i = 0; i < ARRAY_SIZE(max8997_dumpaddr_haptic); i++) |
| 439 | max8997_write_reg(i2c, max8997_dumpaddr_haptic[i], |
| 440 | max8997->reg_dump[i + MAX8997_REG_PMIC_END + |
| 441 | MAX8997_MUIC_REG_END]); |
| 442 | |
| 443 | return 0; |
| 444 | } |
| 445 | |
MyungJoo Ham | 01fdaab | 2011-08-19 14:39:40 +0900 | [diff] [blame] | 446 | static int max8997_suspend(struct device *dev) |
| 447 | { |
Geliang Tang | 1b5420e | 2015-12-28 23:00:14 +0800 | [diff] [blame] | 448 | struct i2c_client *i2c = to_i2c_client(dev); |
MyungJoo Ham | 01fdaab | 2011-08-19 14:39:40 +0900 | [diff] [blame] | 449 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
| 450 | |
Marek Szyprowski | c1aaaa1 | 2018-09-05 16:36:06 +0200 | [diff] [blame] | 451 | disable_irq(max8997->irq); |
MyungJoo Ham | 01fdaab | 2011-08-19 14:39:40 +0900 | [diff] [blame] | 452 | if (device_may_wakeup(dev)) |
| 453 | irq_set_irq_wake(max8997->irq, 1); |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | static int max8997_resume(struct device *dev) |
| 458 | { |
Geliang Tang | 1b5420e | 2015-12-28 23:00:14 +0800 | [diff] [blame] | 459 | struct i2c_client *i2c = to_i2c_client(dev); |
MyungJoo Ham | 01fdaab | 2011-08-19 14:39:40 +0900 | [diff] [blame] | 460 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
| 461 | |
| 462 | if (device_may_wakeup(dev)) |
| 463 | irq_set_irq_wake(max8997->irq, 0); |
Marek Szyprowski | c1aaaa1 | 2018-09-05 16:36:06 +0200 | [diff] [blame] | 464 | enable_irq(max8997->irq); |
MyungJoo Ham | 01fdaab | 2011-08-19 14:39:40 +0900 | [diff] [blame] | 465 | return max8997_irq_resume(max8997); |
| 466 | } |
| 467 | |
Sachin Kamat | b673e24c | 2012-06-04 16:39:07 +0530 | [diff] [blame] | 468 | static const struct dev_pm_ops max8997_pm = { |
MyungJoo Ham | 01fdaab | 2011-08-19 14:39:40 +0900 | [diff] [blame] | 469 | .suspend = max8997_suspend, |
| 470 | .resume = max8997_resume, |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 471 | .freeze = max8997_freeze, |
| 472 | .restore = max8997_restore, |
| 473 | }; |
| 474 | |
| 475 | static struct i2c_driver max8997_i2c_driver = { |
| 476 | .driver = { |
| 477 | .name = "max8997", |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 478 | .pm = &max8997_pm, |
Paul Gortmaker | 9cf0c21 | 2016-06-02 20:39:47 -0400 | [diff] [blame] | 479 | .suppress_bind_attrs = true, |
Thomas Abraham | 77b71b3 | 2012-11-27 14:04:32 +0530 | [diff] [blame] | 480 | .of_match_table = of_match_ptr(max8997_pmic_dt_match), |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 481 | }, |
| 482 | .probe = max8997_i2c_probe, |
MyungJoo Ham | 527e7e9 | 2011-03-04 15:50:26 +0900 | [diff] [blame] | 483 | .id_table = max8997_i2c_id, |
| 484 | }; |
| 485 | |
| 486 | static int __init max8997_i2c_init(void) |
| 487 | { |
| 488 | return i2c_add_driver(&max8997_i2c_driver); |
| 489 | } |
| 490 | /* init early so consumer devices can complete system boot */ |
| 491 | subsys_initcall(max8997_i2c_init); |