MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1 | /* |
| 2 | * max8997.c - Regulator driver for the Maxim 8997/8966 |
| 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 | |
| 24 | #include <linux/bug.h> |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 25 | #include <linux/err.h> |
| 26 | #include <linux/gpio.h> |
| 27 | #include <linux/slab.h> |
Paul Gortmaker | 65602c3 | 2011-07-17 16:28:23 -0400 | [diff] [blame] | 28 | #include <linux/module.h> |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
| 30 | #include <linux/regulator/driver.h> |
| 31 | #include <linux/regulator/machine.h> |
| 32 | #include <linux/mfd/max8997.h> |
| 33 | #include <linux/mfd/max8997-private.h> |
| 34 | |
| 35 | struct max8997_data { |
| 36 | struct device *dev; |
| 37 | struct max8997_dev *iodev; |
| 38 | int num_regulators; |
| 39 | struct regulator_dev **rdev; |
| 40 | int ramp_delay; /* in mV/us */ |
| 41 | |
MyungJoo Ham | 6e0414a | 2011-06-20 17:30:17 +0900 | [diff] [blame] | 42 | bool buck1_gpiodvs; |
| 43 | bool buck2_gpiodvs; |
| 44 | bool buck5_gpiodvs; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 45 | u8 buck1_vol[8]; |
| 46 | u8 buck2_vol[8]; |
| 47 | u8 buck5_vol[8]; |
MyungJoo Ham | 6e0414a | 2011-06-20 17:30:17 +0900 | [diff] [blame] | 48 | int buck125_gpios[3]; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 49 | int buck125_gpioindex; |
MyungJoo Ham | 6e0414a | 2011-06-20 17:30:17 +0900 | [diff] [blame] | 50 | bool ignore_gpiodvs_side_effect; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 51 | |
| 52 | u8 saved_states[MAX8997_REG_MAX]; |
| 53 | }; |
| 54 | |
| 55 | static inline void max8997_set_gpio(struct max8997_data *max8997) |
| 56 | { |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 57 | int set3 = (max8997->buck125_gpioindex) & 0x1; |
| 58 | int set2 = ((max8997->buck125_gpioindex) >> 1) & 0x1; |
| 59 | int set1 = ((max8997->buck125_gpioindex) >> 2) & 0x1; |
| 60 | |
MyungJoo Ham | 6e0414a | 2011-06-20 17:30:17 +0900 | [diff] [blame] | 61 | gpio_set_value(max8997->buck125_gpios[0], set1); |
| 62 | gpio_set_value(max8997->buck125_gpios[1], set2); |
| 63 | gpio_set_value(max8997->buck125_gpios[2], set3); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | struct voltage_map_desc { |
| 67 | int min; |
| 68 | int max; |
| 69 | int step; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* Voltage maps in mV */ |
| 73 | static const struct voltage_map_desc ldo_voltage_map_desc = { |
Axel Lin | 0fa310c | 2012-04-10 14:22:38 +0800 | [diff] [blame] | 74 | .min = 800, .max = 3950, .step = 50, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 75 | }; /* LDO1 ~ 18, 21 all */ |
| 76 | |
| 77 | static const struct voltage_map_desc buck1245_voltage_map_desc = { |
Axel Lin | 0fa310c | 2012-04-10 14:22:38 +0800 | [diff] [blame] | 78 | .min = 650, .max = 2225, .step = 25, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 79 | }; /* Buck1, 2, 4, 5 */ |
| 80 | |
| 81 | static const struct voltage_map_desc buck37_voltage_map_desc = { |
Axel Lin | 0fa310c | 2012-04-10 14:22:38 +0800 | [diff] [blame] | 82 | .min = 750, .max = 3900, .step = 50, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 83 | }; /* Buck3, 7 */ |
| 84 | |
| 85 | /* current map in mA */ |
| 86 | static const struct voltage_map_desc charger_current_map_desc = { |
Axel Lin | 0fa310c | 2012-04-10 14:22:38 +0800 | [diff] [blame] | 87 | .min = 200, .max = 950, .step = 50, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | static const struct voltage_map_desc topoff_current_map_desc = { |
Axel Lin | 0fa310c | 2012-04-10 14:22:38 +0800 | [diff] [blame] | 91 | .min = 50, .max = 200, .step = 10, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | static const struct voltage_map_desc *reg_voltage_map[] = { |
| 95 | [MAX8997_LDO1] = &ldo_voltage_map_desc, |
| 96 | [MAX8997_LDO2] = &ldo_voltage_map_desc, |
| 97 | [MAX8997_LDO3] = &ldo_voltage_map_desc, |
| 98 | [MAX8997_LDO4] = &ldo_voltage_map_desc, |
| 99 | [MAX8997_LDO5] = &ldo_voltage_map_desc, |
| 100 | [MAX8997_LDO6] = &ldo_voltage_map_desc, |
| 101 | [MAX8997_LDO7] = &ldo_voltage_map_desc, |
| 102 | [MAX8997_LDO8] = &ldo_voltage_map_desc, |
| 103 | [MAX8997_LDO9] = &ldo_voltage_map_desc, |
| 104 | [MAX8997_LDO10] = &ldo_voltage_map_desc, |
| 105 | [MAX8997_LDO11] = &ldo_voltage_map_desc, |
| 106 | [MAX8997_LDO12] = &ldo_voltage_map_desc, |
| 107 | [MAX8997_LDO13] = &ldo_voltage_map_desc, |
| 108 | [MAX8997_LDO14] = &ldo_voltage_map_desc, |
| 109 | [MAX8997_LDO15] = &ldo_voltage_map_desc, |
| 110 | [MAX8997_LDO16] = &ldo_voltage_map_desc, |
| 111 | [MAX8997_LDO17] = &ldo_voltage_map_desc, |
| 112 | [MAX8997_LDO18] = &ldo_voltage_map_desc, |
| 113 | [MAX8997_LDO21] = &ldo_voltage_map_desc, |
| 114 | [MAX8997_BUCK1] = &buck1245_voltage_map_desc, |
| 115 | [MAX8997_BUCK2] = &buck1245_voltage_map_desc, |
| 116 | [MAX8997_BUCK3] = &buck37_voltage_map_desc, |
| 117 | [MAX8997_BUCK4] = &buck1245_voltage_map_desc, |
| 118 | [MAX8997_BUCK5] = &buck1245_voltage_map_desc, |
| 119 | [MAX8997_BUCK6] = NULL, |
| 120 | [MAX8997_BUCK7] = &buck37_voltage_map_desc, |
| 121 | [MAX8997_EN32KHZ_AP] = NULL, |
| 122 | [MAX8997_EN32KHZ_CP] = NULL, |
| 123 | [MAX8997_ENVICHG] = NULL, |
| 124 | [MAX8997_ESAFEOUT1] = NULL, |
| 125 | [MAX8997_ESAFEOUT2] = NULL, |
| 126 | [MAX8997_CHARGER_CV] = NULL, |
| 127 | [MAX8997_CHARGER] = &charger_current_map_desc, |
| 128 | [MAX8997_CHARGER_TOPOFF] = &topoff_current_map_desc, |
| 129 | }; |
| 130 | |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 131 | static int max8997_list_voltage_safeout(struct regulator_dev *rdev, |
| 132 | unsigned int selector) |
| 133 | { |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 134 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 135 | |
| 136 | if (rid == MAX8997_ESAFEOUT1 || rid == MAX8997_ESAFEOUT2) { |
| 137 | switch (selector) { |
| 138 | case 0: |
| 139 | return 4850000; |
| 140 | case 1: |
| 141 | return 4900000; |
| 142 | case 2: |
| 143 | return 4950000; |
| 144 | case 3: |
| 145 | return 3300000; |
| 146 | default: |
| 147 | return -EINVAL; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return -EINVAL; |
| 152 | } |
| 153 | |
| 154 | static int max8997_list_voltage_charger_cv(struct regulator_dev *rdev, |
| 155 | unsigned int selector) |
| 156 | { |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 157 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 158 | |
| 159 | if (rid != MAX8997_CHARGER_CV) |
| 160 | goto err; |
| 161 | |
| 162 | switch (selector) { |
| 163 | case 0x00: |
| 164 | return 4200000; |
| 165 | case 0x01 ... 0x0E: |
| 166 | return 4000000 + 20000 * (selector - 0x01); |
| 167 | case 0x0F: |
| 168 | return 4350000; |
| 169 | default: |
| 170 | return -EINVAL; |
| 171 | } |
| 172 | err: |
| 173 | return -EINVAL; |
| 174 | } |
| 175 | |
| 176 | static int max8997_list_voltage(struct regulator_dev *rdev, |
| 177 | unsigned int selector) |
| 178 | { |
| 179 | const struct voltage_map_desc *desc; |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 180 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 181 | int val; |
| 182 | |
| 183 | if (rid >= ARRAY_SIZE(reg_voltage_map) || |
| 184 | rid < 0) |
| 185 | return -EINVAL; |
| 186 | |
| 187 | desc = reg_voltage_map[rid]; |
| 188 | if (desc == NULL) |
| 189 | return -EINVAL; |
| 190 | |
| 191 | val = desc->min + desc->step * selector; |
| 192 | if (val > desc->max) |
| 193 | return -EINVAL; |
| 194 | |
| 195 | return val * 1000; |
| 196 | } |
| 197 | |
| 198 | static int max8997_get_enable_register(struct regulator_dev *rdev, |
| 199 | int *reg, int *mask, int *pattern) |
| 200 | { |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 201 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 202 | |
| 203 | switch (rid) { |
| 204 | case MAX8997_LDO1 ... MAX8997_LDO21: |
| 205 | *reg = MAX8997_REG_LDO1CTRL + (rid - MAX8997_LDO1); |
| 206 | *mask = 0xC0; |
| 207 | *pattern = 0xC0; |
| 208 | break; |
| 209 | case MAX8997_BUCK1: |
| 210 | *reg = MAX8997_REG_BUCK1CTRL; |
| 211 | *mask = 0x01; |
| 212 | *pattern = 0x01; |
| 213 | break; |
| 214 | case MAX8997_BUCK2: |
| 215 | *reg = MAX8997_REG_BUCK2CTRL; |
| 216 | *mask = 0x01; |
| 217 | *pattern = 0x01; |
| 218 | break; |
| 219 | case MAX8997_BUCK3: |
| 220 | *reg = MAX8997_REG_BUCK3CTRL; |
| 221 | *mask = 0x01; |
| 222 | *pattern = 0x01; |
| 223 | break; |
| 224 | case MAX8997_BUCK4: |
| 225 | *reg = MAX8997_REG_BUCK4CTRL; |
| 226 | *mask = 0x01; |
| 227 | *pattern = 0x01; |
| 228 | break; |
| 229 | case MAX8997_BUCK5: |
| 230 | *reg = MAX8997_REG_BUCK5CTRL; |
| 231 | *mask = 0x01; |
| 232 | *pattern = 0x01; |
| 233 | break; |
| 234 | case MAX8997_BUCK6: |
| 235 | *reg = MAX8997_REG_BUCK6CTRL; |
| 236 | *mask = 0x01; |
| 237 | *pattern = 0x01; |
| 238 | break; |
| 239 | case MAX8997_BUCK7: |
| 240 | *reg = MAX8997_REG_BUCK7CTRL; |
| 241 | *mask = 0x01; |
| 242 | *pattern = 0x01; |
| 243 | break; |
| 244 | case MAX8997_EN32KHZ_AP ... MAX8997_EN32KHZ_CP: |
| 245 | *reg = MAX8997_REG_MAINCON1; |
| 246 | *mask = 0x01 << (rid - MAX8997_EN32KHZ_AP); |
| 247 | *pattern = 0x01 << (rid - MAX8997_EN32KHZ_AP); |
| 248 | break; |
| 249 | case MAX8997_ENVICHG: |
| 250 | *reg = MAX8997_REG_MBCCTRL1; |
| 251 | *mask = 0x80; |
| 252 | *pattern = 0x80; |
| 253 | break; |
| 254 | case MAX8997_ESAFEOUT1 ... MAX8997_ESAFEOUT2: |
| 255 | *reg = MAX8997_REG_SAFEOUTCTRL; |
| 256 | *mask = 0x40 << (rid - MAX8997_ESAFEOUT1); |
| 257 | *pattern = 0x40 << (rid - MAX8997_ESAFEOUT1); |
| 258 | break; |
| 259 | case MAX8997_CHARGER: |
| 260 | *reg = MAX8997_REG_MBCCTRL2; |
| 261 | *mask = 0x40; |
| 262 | *pattern = 0x40; |
| 263 | break; |
| 264 | default: |
| 265 | /* Not controllable or not exists */ |
| 266 | return -EINVAL; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static int max8997_reg_is_enabled(struct regulator_dev *rdev) |
| 273 | { |
| 274 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
| 275 | struct i2c_client *i2c = max8997->iodev->i2c; |
| 276 | int ret, reg, mask, pattern; |
| 277 | u8 val; |
| 278 | |
| 279 | ret = max8997_get_enable_register(rdev, ®, &mask, &pattern); |
Axel Lin | c245c08 | 2012-04-17 23:48:27 +0800 | [diff] [blame] | 280 | if (ret) |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 281 | return ret; |
| 282 | |
| 283 | ret = max8997_read_reg(i2c, reg, &val); |
| 284 | if (ret) |
| 285 | return ret; |
| 286 | |
| 287 | return (val & mask) == pattern; |
| 288 | } |
| 289 | |
| 290 | static int max8997_reg_enable(struct regulator_dev *rdev) |
| 291 | { |
| 292 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
| 293 | struct i2c_client *i2c = max8997->iodev->i2c; |
| 294 | int ret, reg, mask, pattern; |
| 295 | |
| 296 | ret = max8997_get_enable_register(rdev, ®, &mask, &pattern); |
| 297 | if (ret) |
| 298 | return ret; |
| 299 | |
| 300 | return max8997_update_reg(i2c, reg, pattern, mask); |
| 301 | } |
| 302 | |
| 303 | static int max8997_reg_disable(struct regulator_dev *rdev) |
| 304 | { |
| 305 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
| 306 | struct i2c_client *i2c = max8997->iodev->i2c; |
| 307 | int ret, reg, mask, pattern; |
| 308 | |
| 309 | ret = max8997_get_enable_register(rdev, ®, &mask, &pattern); |
| 310 | if (ret) |
| 311 | return ret; |
| 312 | |
| 313 | return max8997_update_reg(i2c, reg, ~pattern, mask); |
| 314 | } |
| 315 | |
| 316 | static int max8997_get_voltage_register(struct regulator_dev *rdev, |
| 317 | int *_reg, int *_shift, int *_mask) |
| 318 | { |
Axel Lin | 6f43c38 | 2012-03-13 11:22:41 +0800 | [diff] [blame] | 319 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 320 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 321 | int reg, shift = 0, mask = 0x3f; |
| 322 | |
| 323 | switch (rid) { |
| 324 | case MAX8997_LDO1 ... MAX8997_LDO21: |
| 325 | reg = MAX8997_REG_LDO1CTRL + (rid - MAX8997_LDO1); |
| 326 | break; |
| 327 | case MAX8997_BUCK1: |
| 328 | reg = MAX8997_REG_BUCK1DVS1; |
Axel Lin | 6f43c38 | 2012-03-13 11:22:41 +0800 | [diff] [blame] | 329 | if (max8997->buck1_gpiodvs) |
| 330 | reg += max8997->buck125_gpioindex; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 331 | break; |
| 332 | case MAX8997_BUCK2: |
| 333 | reg = MAX8997_REG_BUCK2DVS1; |
Axel Lin | 6f43c38 | 2012-03-13 11:22:41 +0800 | [diff] [blame] | 334 | if (max8997->buck2_gpiodvs) |
| 335 | reg += max8997->buck125_gpioindex; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 336 | break; |
| 337 | case MAX8997_BUCK3: |
| 338 | reg = MAX8997_REG_BUCK3DVS; |
| 339 | break; |
| 340 | case MAX8997_BUCK4: |
| 341 | reg = MAX8997_REG_BUCK4DVS; |
| 342 | break; |
| 343 | case MAX8997_BUCK5: |
| 344 | reg = MAX8997_REG_BUCK5DVS1; |
Axel Lin | 6f43c38 | 2012-03-13 11:22:41 +0800 | [diff] [blame] | 345 | if (max8997->buck5_gpiodvs) |
| 346 | reg += max8997->buck125_gpioindex; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 347 | break; |
| 348 | case MAX8997_BUCK7: |
| 349 | reg = MAX8997_REG_BUCK7DVS; |
| 350 | break; |
| 351 | case MAX8997_ESAFEOUT1 ... MAX8997_ESAFEOUT2: |
| 352 | reg = MAX8997_REG_SAFEOUTCTRL; |
| 353 | shift = (rid == MAX8997_ESAFEOUT2) ? 2 : 0; |
| 354 | mask = 0x3; |
| 355 | break; |
| 356 | case MAX8997_CHARGER_CV: |
| 357 | reg = MAX8997_REG_MBCCTRL3; |
| 358 | shift = 0; |
| 359 | mask = 0xf; |
| 360 | break; |
| 361 | case MAX8997_CHARGER: |
| 362 | reg = MAX8997_REG_MBCCTRL4; |
| 363 | shift = 0; |
| 364 | mask = 0xf; |
| 365 | break; |
| 366 | case MAX8997_CHARGER_TOPOFF: |
| 367 | reg = MAX8997_REG_MBCCTRL5; |
| 368 | shift = 0; |
| 369 | mask = 0xf; |
| 370 | break; |
| 371 | default: |
| 372 | return -EINVAL; |
| 373 | } |
| 374 | |
| 375 | *_reg = reg; |
| 376 | *_shift = shift; |
| 377 | *_mask = mask; |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 382 | static int max8997_get_voltage_sel(struct regulator_dev *rdev) |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 383 | { |
| 384 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 385 | struct i2c_client *i2c = max8997->iodev->i2c; |
| 386 | int reg, shift, mask, ret; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 387 | u8 val; |
| 388 | |
| 389 | ret = max8997_get_voltage_register(rdev, ®, &shift, &mask); |
| 390 | if (ret) |
| 391 | return ret; |
| 392 | |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 393 | ret = max8997_read_reg(i2c, reg, &val); |
| 394 | if (ret) |
| 395 | return ret; |
| 396 | |
| 397 | val >>= shift; |
| 398 | val &= mask; |
| 399 | |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 400 | return val; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | static inline int max8997_get_voltage_proper_val( |
| 404 | const struct voltage_map_desc *desc, |
| 405 | int min_vol, int max_vol) |
| 406 | { |
Axel Lin | 2358b77 | 2012-04-10 14:20:03 +0800 | [diff] [blame] | 407 | int i; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 408 | |
| 409 | if (desc == NULL) |
| 410 | return -EINVAL; |
| 411 | |
| 412 | if (max_vol < desc->min || min_vol > desc->max) |
| 413 | return -EINVAL; |
| 414 | |
Axel Lin | 2358b77 | 2012-04-10 14:20:03 +0800 | [diff] [blame] | 415 | if (min_vol < desc->min) |
| 416 | min_vol = desc->min; |
| 417 | |
| 418 | i = DIV_ROUND_UP(min_vol - desc->min, desc->step); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 419 | |
| 420 | if (desc->min + desc->step * i > max_vol) |
| 421 | return -EINVAL; |
| 422 | |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 423 | return i; |
| 424 | } |
| 425 | |
| 426 | static int max8997_set_voltage_charger_cv(struct regulator_dev *rdev, |
| 427 | int min_uV, int max_uV, unsigned *selector) |
| 428 | { |
| 429 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
| 430 | struct i2c_client *i2c = max8997->iodev->i2c; |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 431 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 432 | int lb, ub; |
| 433 | int reg, shift = 0, mask, ret = 0; |
| 434 | u8 val = 0x0; |
| 435 | |
| 436 | if (rid != MAX8997_CHARGER_CV) |
| 437 | return -EINVAL; |
| 438 | |
| 439 | ret = max8997_get_voltage_register(rdev, ®, &shift, &mask); |
| 440 | if (ret) |
| 441 | return ret; |
| 442 | |
| 443 | if (max_uV < 4000000 || min_uV > 4350000) |
| 444 | return -EINVAL; |
| 445 | |
| 446 | if (min_uV <= 4000000) { |
| 447 | if (max_uV >= 4000000) |
| 448 | return -EINVAL; |
| 449 | else |
| 450 | val = 0x1; |
| 451 | } else if (min_uV <= 4200000 && max_uV >= 4200000) |
| 452 | val = 0x0; |
| 453 | else { |
| 454 | lb = (min_uV - 4000001) / 20000 + 2; |
| 455 | ub = (max_uV - 4000000) / 20000 + 1; |
| 456 | |
| 457 | if (lb > ub) |
| 458 | return -EINVAL; |
| 459 | |
| 460 | if (lb < 0xf) |
| 461 | val = lb; |
| 462 | else { |
| 463 | if (ub >= 0xf) |
| 464 | val = 0xf; |
| 465 | else |
| 466 | return -EINVAL; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | *selector = val; |
| 471 | |
| 472 | ret = max8997_update_reg(i2c, reg, val << shift, mask); |
| 473 | |
| 474 | return ret; |
| 475 | } |
| 476 | |
| 477 | /* |
| 478 | * For LDO1 ~ LDO21, BUCK1~5, BUCK7, CHARGER, CHARGER_TOPOFF |
| 479 | * BUCK1, 2, and 5 are available if they are not controlled by gpio |
| 480 | */ |
| 481 | static int max8997_set_voltage_ldobuck(struct regulator_dev *rdev, |
| 482 | int min_uV, int max_uV, unsigned *selector) |
| 483 | { |
| 484 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
| 485 | struct i2c_client *i2c = max8997->iodev->i2c; |
| 486 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; |
| 487 | const struct voltage_map_desc *desc; |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 488 | int rid = rdev_get_id(rdev); |
Axel Lin | 62bc4d4 | 2012-04-11 22:58:03 +0800 | [diff] [blame] | 489 | int i, reg, shift, mask, ret; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 490 | |
| 491 | switch (rid) { |
| 492 | case MAX8997_LDO1 ... MAX8997_LDO21: |
| 493 | break; |
| 494 | case MAX8997_BUCK1 ... MAX8997_BUCK5: |
| 495 | break; |
| 496 | case MAX8997_BUCK6: |
| 497 | return -EINVAL; |
| 498 | case MAX8997_BUCK7: |
| 499 | break; |
| 500 | case MAX8997_CHARGER: |
| 501 | break; |
| 502 | case MAX8997_CHARGER_TOPOFF: |
| 503 | break; |
| 504 | default: |
| 505 | return -EINVAL; |
| 506 | } |
| 507 | |
| 508 | desc = reg_voltage_map[rid]; |
| 509 | |
| 510 | i = max8997_get_voltage_proper_val(desc, min_vol, max_vol); |
| 511 | if (i < 0) |
| 512 | return i; |
| 513 | |
| 514 | ret = max8997_get_voltage_register(rdev, ®, &shift, &mask); |
| 515 | if (ret) |
| 516 | return ret; |
| 517 | |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 518 | ret = max8997_update_reg(i2c, reg, i << shift, mask << shift); |
| 519 | *selector = i; |
| 520 | |
Axel Lin | 62bc4d4 | 2012-04-11 22:58:03 +0800 | [diff] [blame] | 521 | return ret; |
| 522 | } |
| 523 | |
| 524 | static int max8997_set_voltage_ldobuck_time_sel(struct regulator_dev *rdev, |
| 525 | unsigned int old_selector, |
| 526 | unsigned int new_selector) |
| 527 | { |
| 528 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
| 529 | int rid = rdev_get_id(rdev); |
| 530 | const struct voltage_map_desc *desc = reg_voltage_map[rid]; |
| 531 | |
| 532 | /* Delay is required only if the voltage is increasing */ |
| 533 | if (old_selector >= new_selector) |
| 534 | return 0; |
| 535 | |
| 536 | /* No need to delay if gpio_dvs_mode */ |
| 537 | switch (rid) { |
| 538 | case MAX8997_BUCK1: |
| 539 | if (max8997->buck1_gpiodvs) |
| 540 | return 0; |
| 541 | break; |
| 542 | case MAX8997_BUCK2: |
| 543 | if (max8997->buck2_gpiodvs) |
| 544 | return 0; |
| 545 | break; |
| 546 | case MAX8997_BUCK5: |
| 547 | if (max8997->buck5_gpiodvs) |
| 548 | return 0; |
| 549 | break; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 550 | } |
| 551 | |
Axel Lin | 62bc4d4 | 2012-04-11 22:58:03 +0800 | [diff] [blame] | 552 | switch (rid) { |
| 553 | case MAX8997_BUCK1: |
| 554 | case MAX8997_BUCK2: |
| 555 | case MAX8997_BUCK4: |
| 556 | case MAX8997_BUCK5: |
| 557 | return DIV_ROUND_UP(desc->step * (new_selector - old_selector), |
| 558 | max8997->ramp_delay); |
| 559 | } |
| 560 | |
| 561 | return 0; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /* |
| 565 | * Assess the damage on the voltage setting of BUCK1,2,5 by the change. |
| 566 | * |
| 567 | * When GPIO-DVS mode is used for multiple bucks, changing the voltage value |
| 568 | * of one of the bucks may affect that of another buck, which is the side |
| 569 | * effect of the change (set_voltage). This function examines the GPIO-DVS |
| 570 | * configurations and checks whether such side-effect exists. |
| 571 | */ |
| 572 | static int max8997_assess_side_effect(struct regulator_dev *rdev, |
| 573 | u8 new_val, int *best) |
| 574 | { |
| 575 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 576 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 577 | u8 *buckx_val[3]; |
| 578 | bool buckx_gpiodvs[3]; |
| 579 | int side_effect[8]; |
| 580 | int min_side_effect = INT_MAX; |
| 581 | int i; |
| 582 | |
| 583 | *best = -1; |
| 584 | |
| 585 | switch (rid) { |
| 586 | case MAX8997_BUCK1: |
| 587 | rid = 0; |
| 588 | break; |
| 589 | case MAX8997_BUCK2: |
| 590 | rid = 1; |
| 591 | break; |
| 592 | case MAX8997_BUCK5: |
| 593 | rid = 2; |
| 594 | break; |
| 595 | default: |
| 596 | return -EINVAL; |
| 597 | } |
| 598 | |
| 599 | buckx_val[0] = max8997->buck1_vol; |
| 600 | buckx_val[1] = max8997->buck2_vol; |
| 601 | buckx_val[2] = max8997->buck5_vol; |
MyungJoo Ham | 6e0414a | 2011-06-20 17:30:17 +0900 | [diff] [blame] | 602 | buckx_gpiodvs[0] = max8997->buck1_gpiodvs; |
| 603 | buckx_gpiodvs[1] = max8997->buck2_gpiodvs; |
| 604 | buckx_gpiodvs[2] = max8997->buck5_gpiodvs; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 605 | |
| 606 | for (i = 0; i < 8; i++) { |
| 607 | int others; |
| 608 | |
| 609 | if (new_val != (buckx_val[rid])[i]) { |
| 610 | side_effect[i] = -1; |
| 611 | continue; |
| 612 | } |
| 613 | |
| 614 | side_effect[i] = 0; |
| 615 | for (others = 0; others < 3; others++) { |
| 616 | int diff; |
| 617 | |
| 618 | if (others == rid) |
| 619 | continue; |
| 620 | if (buckx_gpiodvs[others] == false) |
| 621 | continue; /* Not affected */ |
| 622 | diff = (buckx_val[others])[i] - |
| 623 | (buckx_val[others])[max8997->buck125_gpioindex]; |
| 624 | if (diff > 0) |
| 625 | side_effect[i] += diff; |
| 626 | else if (diff < 0) |
| 627 | side_effect[i] -= diff; |
| 628 | } |
| 629 | if (side_effect[i] == 0) { |
| 630 | *best = i; |
| 631 | return 0; /* NO SIDE EFFECT! Use This! */ |
| 632 | } |
| 633 | if (side_effect[i] < min_side_effect) { |
| 634 | min_side_effect = side_effect[i]; |
| 635 | *best = i; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | if (*best == -1) |
| 640 | return -EINVAL; |
| 641 | |
| 642 | return side_effect[*best]; |
| 643 | } |
| 644 | |
| 645 | /* |
| 646 | * For Buck 1 ~ 5 and 7. If it is not controlled by GPIO, this calls |
| 647 | * max8997_set_voltage_ldobuck to do the job. |
| 648 | */ |
| 649 | static int max8997_set_voltage_buck(struct regulator_dev *rdev, |
| 650 | int min_uV, int max_uV, unsigned *selector) |
| 651 | { |
| 652 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 653 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 654 | const struct voltage_map_desc *desc; |
| 655 | int new_val, new_idx, damage, tmp_val, tmp_idx, tmp_dmg; |
| 656 | bool gpio_dvs_mode = false; |
| 657 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; |
| 658 | |
| 659 | if (rid < MAX8997_BUCK1 || rid > MAX8997_BUCK7) |
| 660 | return -EINVAL; |
| 661 | |
| 662 | switch (rid) { |
| 663 | case MAX8997_BUCK1: |
MyungJoo Ham | 6e0414a | 2011-06-20 17:30:17 +0900 | [diff] [blame] | 664 | if (max8997->buck1_gpiodvs) |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 665 | gpio_dvs_mode = true; |
| 666 | break; |
| 667 | case MAX8997_BUCK2: |
MyungJoo Ham | 6e0414a | 2011-06-20 17:30:17 +0900 | [diff] [blame] | 668 | if (max8997->buck2_gpiodvs) |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 669 | gpio_dvs_mode = true; |
| 670 | break; |
| 671 | case MAX8997_BUCK5: |
MyungJoo Ham | 6e0414a | 2011-06-20 17:30:17 +0900 | [diff] [blame] | 672 | if (max8997->buck5_gpiodvs) |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 673 | gpio_dvs_mode = true; |
| 674 | break; |
| 675 | } |
| 676 | |
| 677 | if (!gpio_dvs_mode) |
| 678 | return max8997_set_voltage_ldobuck(rdev, min_uV, max_uV, |
| 679 | selector); |
| 680 | |
| 681 | desc = reg_voltage_map[rid]; |
| 682 | new_val = max8997_get_voltage_proper_val(desc, min_vol, max_vol); |
| 683 | if (new_val < 0) |
| 684 | return new_val; |
| 685 | |
| 686 | tmp_dmg = INT_MAX; |
| 687 | tmp_idx = -1; |
| 688 | tmp_val = -1; |
| 689 | do { |
| 690 | damage = max8997_assess_side_effect(rdev, new_val, &new_idx); |
| 691 | if (damage == 0) |
| 692 | goto out; |
| 693 | |
| 694 | if (tmp_dmg > damage) { |
| 695 | tmp_idx = new_idx; |
| 696 | tmp_val = new_val; |
| 697 | tmp_dmg = damage; |
| 698 | } |
| 699 | |
| 700 | new_val++; |
Axel Lin | f55205f | 2012-04-11 20:53:58 +0800 | [diff] [blame] | 701 | } while (desc->min + desc->step * new_val <= desc->max); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 702 | |
| 703 | new_idx = tmp_idx; |
| 704 | new_val = tmp_val; |
| 705 | |
MyungJoo Ham | 6e0414a | 2011-06-20 17:30:17 +0900 | [diff] [blame] | 706 | if (max8997->ignore_gpiodvs_side_effect == false) |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 707 | return -EINVAL; |
| 708 | |
| 709 | dev_warn(&rdev->dev, "MAX8997 GPIO-DVS Side Effect Warning: GPIO SET:" |
| 710 | " %d -> %d\n", max8997->buck125_gpioindex, tmp_idx); |
| 711 | |
| 712 | out: |
| 713 | if (new_idx < 0 || new_val < 0) |
| 714 | return -EINVAL; |
| 715 | |
| 716 | max8997->buck125_gpioindex = new_idx; |
| 717 | max8997_set_gpio(max8997); |
| 718 | *selector = new_val; |
| 719 | |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | static const int safeoutvolt[] = { |
| 724 | 3300000, |
| 725 | 4850000, |
| 726 | 4900000, |
| 727 | 4950000, |
| 728 | }; |
| 729 | |
| 730 | /* For SAFEOUT1 and SAFEOUT2 */ |
| 731 | static int max8997_set_voltage_safeout(struct regulator_dev *rdev, |
| 732 | int min_uV, int max_uV, unsigned *selector) |
| 733 | { |
| 734 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
| 735 | struct i2c_client *i2c = max8997->iodev->i2c; |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 736 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 737 | int reg, shift = 0, mask, ret; |
| 738 | int i = 0; |
| 739 | u8 val; |
| 740 | |
| 741 | if (rid != MAX8997_ESAFEOUT1 && rid != MAX8997_ESAFEOUT2) |
| 742 | return -EINVAL; |
| 743 | |
| 744 | for (i = 0; i < ARRAY_SIZE(safeoutvolt); i++) { |
| 745 | if (min_uV <= safeoutvolt[i] && |
| 746 | max_uV >= safeoutvolt[i]) |
| 747 | break; |
| 748 | } |
| 749 | |
| 750 | if (i >= ARRAY_SIZE(safeoutvolt)) |
| 751 | return -EINVAL; |
| 752 | |
| 753 | if (i == 0) |
| 754 | val = 0x3; |
| 755 | else |
| 756 | val = i - 1; |
| 757 | |
| 758 | ret = max8997_get_voltage_register(rdev, ®, &shift, &mask); |
| 759 | if (ret) |
| 760 | return ret; |
| 761 | |
| 762 | ret = max8997_update_reg(i2c, reg, val << shift, mask << shift); |
| 763 | *selector = val; |
| 764 | |
| 765 | return ret; |
| 766 | } |
| 767 | |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 768 | static int max8997_reg_disable_suspend(struct regulator_dev *rdev) |
| 769 | { |
| 770 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
| 771 | struct i2c_client *i2c = max8997->iodev->i2c; |
| 772 | int ret, reg, mask, pattern; |
Axel Lin | b3e1348 | 2012-03-01 09:26:27 +0800 | [diff] [blame] | 773 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 774 | |
| 775 | ret = max8997_get_enable_register(rdev, ®, &mask, &pattern); |
| 776 | if (ret) |
| 777 | return ret; |
| 778 | |
| 779 | max8997_read_reg(i2c, reg, &max8997->saved_states[rid]); |
| 780 | |
| 781 | if (rid == MAX8997_LDO1 || |
| 782 | rid == MAX8997_LDO10 || |
| 783 | rid == MAX8997_LDO21) { |
| 784 | dev_dbg(&rdev->dev, "Conditional Power-Off for %s\n", |
| 785 | rdev->desc->name); |
| 786 | return max8997_update_reg(i2c, reg, 0x40, mask); |
| 787 | } |
| 788 | |
| 789 | dev_dbg(&rdev->dev, "Full Power-Off for %s (%xh -> %xh)\n", |
| 790 | rdev->desc->name, max8997->saved_states[rid] & mask, |
| 791 | (~pattern) & mask); |
| 792 | return max8997_update_reg(i2c, reg, ~pattern, mask); |
| 793 | } |
| 794 | |
| 795 | static struct regulator_ops max8997_ldo_ops = { |
| 796 | .list_voltage = max8997_list_voltage, |
| 797 | .is_enabled = max8997_reg_is_enabled, |
| 798 | .enable = max8997_reg_enable, |
| 799 | .disable = max8997_reg_disable, |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 800 | .get_voltage_sel = max8997_get_voltage_sel, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 801 | .set_voltage = max8997_set_voltage_ldobuck, |
Axel Lin | 62bc4d4 | 2012-04-11 22:58:03 +0800 | [diff] [blame] | 802 | .set_voltage_time_sel = max8997_set_voltage_ldobuck_time_sel, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 803 | .set_suspend_disable = max8997_reg_disable_suspend, |
| 804 | }; |
| 805 | |
| 806 | static struct regulator_ops max8997_buck_ops = { |
| 807 | .list_voltage = max8997_list_voltage, |
| 808 | .is_enabled = max8997_reg_is_enabled, |
| 809 | .enable = max8997_reg_enable, |
| 810 | .disable = max8997_reg_disable, |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 811 | .get_voltage_sel = max8997_get_voltage_sel, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 812 | .set_voltage = max8997_set_voltage_buck, |
Axel Lin | 62bc4d4 | 2012-04-11 22:58:03 +0800 | [diff] [blame] | 813 | .set_voltage_time_sel = max8997_set_voltage_ldobuck_time_sel, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 814 | .set_suspend_disable = max8997_reg_disable_suspend, |
| 815 | }; |
| 816 | |
| 817 | static struct regulator_ops max8997_fixedvolt_ops = { |
| 818 | .list_voltage = max8997_list_voltage, |
| 819 | .is_enabled = max8997_reg_is_enabled, |
| 820 | .enable = max8997_reg_enable, |
| 821 | .disable = max8997_reg_disable, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 822 | .set_suspend_disable = max8997_reg_disable_suspend, |
| 823 | }; |
| 824 | |
| 825 | static struct regulator_ops max8997_safeout_ops = { |
| 826 | .list_voltage = max8997_list_voltage_safeout, |
| 827 | .is_enabled = max8997_reg_is_enabled, |
| 828 | .enable = max8997_reg_enable, |
| 829 | .disable = max8997_reg_disable, |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 830 | .get_voltage_sel = max8997_get_voltage_sel, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 831 | .set_voltage = max8997_set_voltage_safeout, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 832 | .set_suspend_disable = max8997_reg_disable_suspend, |
| 833 | }; |
| 834 | |
| 835 | static struct regulator_ops max8997_fixedstate_ops = { |
| 836 | .list_voltage = max8997_list_voltage_charger_cv, |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 837 | .get_voltage_sel = max8997_get_voltage_sel, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 838 | .set_voltage = max8997_set_voltage_charger_cv, |
| 839 | }; |
| 840 | |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 841 | static int max8997_set_current_limit(struct regulator_dev *rdev, |
| 842 | int min_uA, int max_uA) |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 843 | { |
| 844 | unsigned dummy; |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 845 | int rid = rdev_get_id(rdev); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 846 | |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 847 | if (rid != MAX8997_CHARGER && rid != MAX8997_CHARGER_TOPOFF) |
| 848 | return -EINVAL; |
| 849 | |
| 850 | /* Reuse max8997_set_voltage_ldobuck to set current_limit. */ |
| 851 | return max8997_set_voltage_ldobuck(rdev, min_uA, max_uA, &dummy); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 852 | } |
| 853 | |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 854 | static int max8997_get_current_limit(struct regulator_dev *rdev) |
| 855 | { |
| 856 | int sel, rid = rdev_get_id(rdev); |
| 857 | |
| 858 | if (rid != MAX8997_CHARGER && rid != MAX8997_CHARGER_TOPOFF) |
| 859 | return -EINVAL; |
| 860 | |
| 861 | sel = max8997_get_voltage_sel(rdev); |
| 862 | if (sel < 0) |
| 863 | return sel; |
| 864 | |
| 865 | /* Reuse max8997_list_voltage to get current_limit. */ |
| 866 | return max8997_list_voltage(rdev, sel); |
| 867 | } |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 868 | |
| 869 | static struct regulator_ops max8997_charger_ops = { |
| 870 | .is_enabled = max8997_reg_is_enabled, |
| 871 | .enable = max8997_reg_enable, |
| 872 | .disable = max8997_reg_disable, |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 873 | .get_current_limit = max8997_get_current_limit, |
| 874 | .set_current_limit = max8997_set_current_limit, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 875 | }; |
| 876 | |
| 877 | static struct regulator_ops max8997_charger_fixedstate_ops = { |
Axel Lin | 9e96b3a | 2012-04-11 22:56:11 +0800 | [diff] [blame] | 878 | .get_current_limit = max8997_get_current_limit, |
| 879 | .set_current_limit = max8997_set_current_limit, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 880 | }; |
| 881 | |
Axel Lin | 4533f80 | 2012-03-13 14:53:58 +0800 | [diff] [blame] | 882 | #define MAX8997_VOLTAGE_REGULATOR(_name, _ops) {\ |
| 883 | .name = #_name, \ |
| 884 | .id = MAX8997_##_name, \ |
| 885 | .ops = &_ops, \ |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 886 | .type = REGULATOR_VOLTAGE, \ |
| 887 | .owner = THIS_MODULE, \ |
| 888 | } |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 889 | |
Axel Lin | 4533f80 | 2012-03-13 14:53:58 +0800 | [diff] [blame] | 890 | #define MAX8997_CURRENT_REGULATOR(_name, _ops) {\ |
| 891 | .name = #_name, \ |
| 892 | .id = MAX8997_##_name, \ |
| 893 | .ops = &_ops, \ |
| 894 | .type = REGULATOR_CURRENT, \ |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 895 | .owner = THIS_MODULE, \ |
| 896 | } |
| 897 | |
| 898 | static struct regulator_desc regulators[] = { |
Axel Lin | 4533f80 | 2012-03-13 14:53:58 +0800 | [diff] [blame] | 899 | MAX8997_VOLTAGE_REGULATOR(LDO1, max8997_ldo_ops), |
| 900 | MAX8997_VOLTAGE_REGULATOR(LDO2, max8997_ldo_ops), |
| 901 | MAX8997_VOLTAGE_REGULATOR(LDO3, max8997_ldo_ops), |
| 902 | MAX8997_VOLTAGE_REGULATOR(LDO4, max8997_ldo_ops), |
| 903 | MAX8997_VOLTAGE_REGULATOR(LDO5, max8997_ldo_ops), |
| 904 | MAX8997_VOLTAGE_REGULATOR(LDO6, max8997_ldo_ops), |
| 905 | MAX8997_VOLTAGE_REGULATOR(LDO7, max8997_ldo_ops), |
| 906 | MAX8997_VOLTAGE_REGULATOR(LDO8, max8997_ldo_ops), |
| 907 | MAX8997_VOLTAGE_REGULATOR(LDO9, max8997_ldo_ops), |
| 908 | MAX8997_VOLTAGE_REGULATOR(LDO10, max8997_ldo_ops), |
| 909 | MAX8997_VOLTAGE_REGULATOR(LDO11, max8997_ldo_ops), |
| 910 | MAX8997_VOLTAGE_REGULATOR(LDO12, max8997_ldo_ops), |
| 911 | MAX8997_VOLTAGE_REGULATOR(LDO13, max8997_ldo_ops), |
| 912 | MAX8997_VOLTAGE_REGULATOR(LDO14, max8997_ldo_ops), |
| 913 | MAX8997_VOLTAGE_REGULATOR(LDO15, max8997_ldo_ops), |
| 914 | MAX8997_VOLTAGE_REGULATOR(LDO16, max8997_ldo_ops), |
| 915 | MAX8997_VOLTAGE_REGULATOR(LDO17, max8997_ldo_ops), |
| 916 | MAX8997_VOLTAGE_REGULATOR(LDO18, max8997_ldo_ops), |
| 917 | MAX8997_VOLTAGE_REGULATOR(LDO21, max8997_ldo_ops), |
| 918 | MAX8997_VOLTAGE_REGULATOR(BUCK1, max8997_buck_ops), |
| 919 | MAX8997_VOLTAGE_REGULATOR(BUCK2, max8997_buck_ops), |
| 920 | MAX8997_VOLTAGE_REGULATOR(BUCK3, max8997_buck_ops), |
| 921 | MAX8997_VOLTAGE_REGULATOR(BUCK4, max8997_buck_ops), |
| 922 | MAX8997_VOLTAGE_REGULATOR(BUCK5, max8997_buck_ops), |
| 923 | MAX8997_VOLTAGE_REGULATOR(BUCK6, max8997_fixedvolt_ops), |
| 924 | MAX8997_VOLTAGE_REGULATOR(BUCK7, max8997_buck_ops), |
| 925 | MAX8997_VOLTAGE_REGULATOR(EN32KHZ_AP, max8997_fixedvolt_ops), |
| 926 | MAX8997_VOLTAGE_REGULATOR(EN32KHZ_CP, max8997_fixedvolt_ops), |
| 927 | MAX8997_VOLTAGE_REGULATOR(ENVICHG, max8997_fixedvolt_ops), |
| 928 | MAX8997_VOLTAGE_REGULATOR(ESAFEOUT1, max8997_safeout_ops), |
| 929 | MAX8997_VOLTAGE_REGULATOR(ESAFEOUT2, max8997_safeout_ops), |
| 930 | MAX8997_VOLTAGE_REGULATOR(CHARGER_CV, max8997_fixedstate_ops), |
| 931 | MAX8997_CURRENT_REGULATOR(CHARGER, max8997_charger_ops), |
| 932 | MAX8997_CURRENT_REGULATOR(CHARGER_TOPOFF, |
| 933 | max8997_charger_fixedstate_ops), |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 934 | }; |
| 935 | |
| 936 | static __devinit int max8997_pmic_probe(struct platform_device *pdev) |
| 937 | { |
| 938 | struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
| 939 | struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev); |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 940 | struct regulator_config config = { }; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 941 | struct regulator_dev **rdev; |
| 942 | struct max8997_data *max8997; |
| 943 | struct i2c_client *i2c; |
| 944 | int i, ret, size; |
| 945 | u8 max_buck1 = 0, max_buck2 = 0, max_buck5 = 0; |
| 946 | |
| 947 | if (!pdata) { |
| 948 | dev_err(pdev->dev.parent, "No platform init data supplied.\n"); |
| 949 | return -ENODEV; |
| 950 | } |
| 951 | |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 952 | max8997 = devm_kzalloc(&pdev->dev, sizeof(struct max8997_data), |
| 953 | GFP_KERNEL); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 954 | if (!max8997) |
| 955 | return -ENOMEM; |
| 956 | |
| 957 | size = sizeof(struct regulator_dev *) * pdata->num_regulators; |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 958 | max8997->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
| 959 | if (!max8997->rdev) |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 960 | return -ENOMEM; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 961 | |
| 962 | rdev = max8997->rdev; |
| 963 | max8997->dev = &pdev->dev; |
| 964 | max8997->iodev = iodev; |
| 965 | max8997->num_regulators = pdata->num_regulators; |
| 966 | platform_set_drvdata(pdev, max8997); |
| 967 | i2c = max8997->iodev->i2c; |
| 968 | |
| 969 | max8997->buck125_gpioindex = pdata->buck125_default_idx; |
MyungJoo Ham | 6e0414a | 2011-06-20 17:30:17 +0900 | [diff] [blame] | 970 | max8997->buck1_gpiodvs = pdata->buck1_gpiodvs; |
| 971 | max8997->buck2_gpiodvs = pdata->buck2_gpiodvs; |
| 972 | max8997->buck5_gpiodvs = pdata->buck5_gpiodvs; |
| 973 | memcpy(max8997->buck125_gpios, pdata->buck125_gpios, sizeof(int) * 3); |
| 974 | max8997->ignore_gpiodvs_side_effect = pdata->ignore_gpiodvs_side_effect; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 975 | |
| 976 | for (i = 0; i < 8; i++) { |
| 977 | max8997->buck1_vol[i] = ret = |
| 978 | max8997_get_voltage_proper_val( |
| 979 | &buck1245_voltage_map_desc, |
| 980 | pdata->buck1_voltage[i] / 1000, |
| 981 | pdata->buck1_voltage[i] / 1000 + |
| 982 | buck1245_voltage_map_desc.step); |
| 983 | if (ret < 0) |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 984 | goto err_out; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 985 | |
| 986 | max8997->buck2_vol[i] = ret = |
| 987 | max8997_get_voltage_proper_val( |
| 988 | &buck1245_voltage_map_desc, |
| 989 | pdata->buck2_voltage[i] / 1000, |
| 990 | pdata->buck2_voltage[i] / 1000 + |
| 991 | buck1245_voltage_map_desc.step); |
| 992 | if (ret < 0) |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 993 | goto err_out; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 994 | |
| 995 | max8997->buck5_vol[i] = ret = |
| 996 | max8997_get_voltage_proper_val( |
| 997 | &buck1245_voltage_map_desc, |
| 998 | pdata->buck5_voltage[i] / 1000, |
| 999 | pdata->buck5_voltage[i] / 1000 + |
| 1000 | buck1245_voltage_map_desc.step); |
| 1001 | if (ret < 0) |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 1002 | goto err_out; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1003 | |
| 1004 | if (max_buck1 < max8997->buck1_vol[i]) |
| 1005 | max_buck1 = max8997->buck1_vol[i]; |
| 1006 | if (max_buck2 < max8997->buck2_vol[i]) |
| 1007 | max_buck2 = max8997->buck2_vol[i]; |
| 1008 | if (max_buck5 < max8997->buck5_vol[i]) |
| 1009 | max_buck5 = max8997->buck5_vol[i]; |
| 1010 | } |
| 1011 | |
| 1012 | /* For the safety, set max voltage before setting up */ |
| 1013 | for (i = 0; i < 8; i++) { |
Axel Lin | ecb9c4f | 2011-05-16 18:20:34 +0800 | [diff] [blame] | 1014 | max8997_update_reg(i2c, MAX8997_REG_BUCK1DVS1 + i, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1015 | max_buck1, 0x3f); |
Axel Lin | ecb9c4f | 2011-05-16 18:20:34 +0800 | [diff] [blame] | 1016 | max8997_update_reg(i2c, MAX8997_REG_BUCK2DVS1 + i, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1017 | max_buck2, 0x3f); |
Axel Lin | ecb9c4f | 2011-05-16 18:20:34 +0800 | [diff] [blame] | 1018 | max8997_update_reg(i2c, MAX8997_REG_BUCK5DVS1 + i, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1019 | max_buck5, 0x3f); |
| 1020 | } |
| 1021 | |
| 1022 | /* |
| 1023 | * If buck 1, 2, and 5 do not care DVS GPIO settings, ignore them. |
| 1024 | * If at least one of them cares, set gpios. |
| 1025 | */ |
| 1026 | if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || |
| 1027 | pdata->buck5_gpiodvs) { |
| 1028 | bool gpio1set = false, gpio2set = false; |
| 1029 | |
| 1030 | if (!gpio_is_valid(pdata->buck125_gpios[0]) || |
| 1031 | !gpio_is_valid(pdata->buck125_gpios[1]) || |
| 1032 | !gpio_is_valid(pdata->buck125_gpios[2])) { |
| 1033 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); |
| 1034 | ret = -EINVAL; |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 1035 | goto err_out; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | ret = gpio_request(pdata->buck125_gpios[0], |
| 1039 | "MAX8997 SET1"); |
| 1040 | if (ret == -EBUSY) |
| 1041 | dev_warn(&pdev->dev, "Duplicated gpio request" |
| 1042 | " on SET1\n"); |
| 1043 | else if (ret) |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 1044 | goto err_out; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1045 | else |
| 1046 | gpio1set = true; |
| 1047 | |
| 1048 | ret = gpio_request(pdata->buck125_gpios[1], |
| 1049 | "MAX8997 SET2"); |
| 1050 | if (ret == -EBUSY) |
| 1051 | dev_warn(&pdev->dev, "Duplicated gpio request" |
| 1052 | " on SET2\n"); |
| 1053 | else if (ret) { |
| 1054 | if (gpio1set) |
| 1055 | gpio_free(pdata->buck125_gpios[0]); |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 1056 | goto err_out; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1057 | } else |
| 1058 | gpio2set = true; |
| 1059 | |
| 1060 | ret = gpio_request(pdata->buck125_gpios[2], |
| 1061 | "MAX8997 SET3"); |
| 1062 | if (ret == -EBUSY) |
| 1063 | dev_warn(&pdev->dev, "Duplicated gpio request" |
| 1064 | " on SET3\n"); |
| 1065 | else if (ret) { |
| 1066 | if (gpio1set) |
| 1067 | gpio_free(pdata->buck125_gpios[0]); |
| 1068 | if (gpio2set) |
| 1069 | gpio_free(pdata->buck125_gpios[1]); |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 1070 | goto err_out; |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | gpio_direction_output(pdata->buck125_gpios[0], |
| 1074 | (max8997->buck125_gpioindex >> 2) |
| 1075 | & 0x1); /* SET1 */ |
| 1076 | gpio_direction_output(pdata->buck125_gpios[1], |
| 1077 | (max8997->buck125_gpioindex >> 1) |
| 1078 | & 0x1); /* SET2 */ |
| 1079 | gpio_direction_output(pdata->buck125_gpios[2], |
| 1080 | (max8997->buck125_gpioindex >> 0) |
| 1081 | & 0x1); /* SET3 */ |
| 1082 | ret = 0; |
| 1083 | } |
| 1084 | |
| 1085 | /* DVS-GPIO disabled */ |
| 1086 | max8997_update_reg(i2c, MAX8997_REG_BUCK1CTRL, (pdata->buck1_gpiodvs) ? |
| 1087 | (1 << 1) : (0 << 1), 1 << 1); |
| 1088 | max8997_update_reg(i2c, MAX8997_REG_BUCK2CTRL, (pdata->buck2_gpiodvs) ? |
| 1089 | (1 << 1) : (0 << 1), 1 << 1); |
| 1090 | max8997_update_reg(i2c, MAX8997_REG_BUCK5CTRL, (pdata->buck5_gpiodvs) ? |
| 1091 | (1 << 1) : (0 << 1), 1 << 1); |
| 1092 | |
| 1093 | /* Initialize all the DVS related BUCK registers */ |
| 1094 | for (i = 0; i < 8; i++) { |
Axel Lin | ecb9c4f | 2011-05-16 18:20:34 +0800 | [diff] [blame] | 1095 | max8997_update_reg(i2c, MAX8997_REG_BUCK1DVS1 + i, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1096 | max8997->buck1_vol[i], |
| 1097 | 0x3f); |
Axel Lin | ecb9c4f | 2011-05-16 18:20:34 +0800 | [diff] [blame] | 1098 | max8997_update_reg(i2c, MAX8997_REG_BUCK2DVS1 + i, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1099 | max8997->buck2_vol[i], |
| 1100 | 0x3f); |
Axel Lin | ecb9c4f | 2011-05-16 18:20:34 +0800 | [diff] [blame] | 1101 | max8997_update_reg(i2c, MAX8997_REG_BUCK5DVS1 + i, |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1102 | max8997->buck5_vol[i], |
| 1103 | 0x3f); |
| 1104 | } |
| 1105 | |
Tushar Behera | dbb48e7 | 2011-06-21 09:08:59 +0530 | [diff] [blame] | 1106 | /* Misc Settings */ |
| 1107 | max8997->ramp_delay = 10; /* set 10mV/us, which is the default */ |
| 1108 | max8997_write_reg(i2c, MAX8997_REG_BUCKRAMP, (0xf << 4) | 0x9); |
| 1109 | |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1110 | for (i = 0; i < pdata->num_regulators; i++) { |
| 1111 | const struct voltage_map_desc *desc; |
| 1112 | int id = pdata->regulators[i].id; |
| 1113 | |
| 1114 | desc = reg_voltage_map[id]; |
| 1115 | if (desc) |
| 1116 | regulators[id].n_voltages = |
| 1117 | (desc->max - desc->min) / desc->step + 1; |
| 1118 | else if (id == MAX8997_ESAFEOUT1 || id == MAX8997_ESAFEOUT2) |
| 1119 | regulators[id].n_voltages = 4; |
| 1120 | else if (id == MAX8997_CHARGER_CV) |
| 1121 | regulators[id].n_voltages = 16; |
| 1122 | |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1123 | config.dev = max8997->dev; |
| 1124 | config.init_data = pdata->regulators[i].initdata; |
| 1125 | config.driver_data = max8997; |
| 1126 | |
| 1127 | rdev[i] = regulator_register(®ulators[id], &config); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1128 | if (IS_ERR(rdev[i])) { |
| 1129 | ret = PTR_ERR(rdev[i]); |
| 1130 | dev_err(max8997->dev, "regulator init failed for %d\n", |
| 1131 | id); |
| 1132 | rdev[i] = NULL; |
| 1133 | goto err; |
| 1134 | } |
| 1135 | } |
| 1136 | |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1137 | return 0; |
| 1138 | err: |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 1139 | while (--i >= 0) |
| 1140 | regulator_unregister(rdev[i]); |
| 1141 | err_out: |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1142 | return ret; |
| 1143 | } |
| 1144 | |
| 1145 | static int __devexit max8997_pmic_remove(struct platform_device *pdev) |
| 1146 | { |
| 1147 | struct max8997_data *max8997 = platform_get_drvdata(pdev); |
| 1148 | struct regulator_dev **rdev = max8997->rdev; |
| 1149 | int i; |
| 1150 | |
| 1151 | for (i = 0; i < max8997->num_regulators; i++) |
Axel Lin | 8ae5767 | 2012-04-19 09:44:13 +0800 | [diff] [blame] | 1152 | regulator_unregister(rdev[i]); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1153 | return 0; |
| 1154 | } |
| 1155 | |
| 1156 | static const struct platform_device_id max8997_pmic_id[] = { |
| 1157 | { "max8997-pmic", 0}, |
| 1158 | { }, |
| 1159 | }; |
Axel Lin | a51b907 | 2011-03-26 23:28:42 +0800 | [diff] [blame] | 1160 | MODULE_DEVICE_TABLE(platform, max8997_pmic_id); |
MyungJoo Ham | bd6ca2c | 2011-03-11 11:34:44 +0900 | [diff] [blame] | 1161 | |
| 1162 | static struct platform_driver max8997_pmic_driver = { |
| 1163 | .driver = { |
| 1164 | .name = "max8997-pmic", |
| 1165 | .owner = THIS_MODULE, |
| 1166 | }, |
| 1167 | .probe = max8997_pmic_probe, |
| 1168 | .remove = __devexit_p(max8997_pmic_remove), |
| 1169 | .id_table = max8997_pmic_id, |
| 1170 | }; |
| 1171 | |
| 1172 | static int __init max8997_pmic_init(void) |
| 1173 | { |
| 1174 | return platform_driver_register(&max8997_pmic_driver); |
| 1175 | } |
| 1176 | subsys_initcall(max8997_pmic_init); |
| 1177 | |
| 1178 | static void __exit max8997_pmic_cleanup(void) |
| 1179 | { |
| 1180 | platform_driver_unregister(&max8997_pmic_driver); |
| 1181 | } |
| 1182 | module_exit(max8997_pmic_cleanup); |
| 1183 | |
| 1184 | MODULE_DESCRIPTION("MAXIM 8997/8966 Regulator Driver"); |
| 1185 | MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); |
| 1186 | MODULE_LICENSE("GPL"); |