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