Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC |
| 3 | * |
| 4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. |
| 5 | * |
| 6 | * Author: Liam Girdwood |
| 7 | * linux@wolfsonmicro.com |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/moduleparam.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/bitops.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/i2c.h> |
| 21 | #include <linux/mfd/wm8350/core.h> |
| 22 | #include <linux/mfd/wm8350/pmic.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/regulator/driver.h> |
| 25 | #include <linux/regulator/machine.h> |
| 26 | |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 27 | /* Maximum value possible for VSEL */ |
| 28 | #define WM8350_DCDC_MAX_VSEL 0x66 |
| 29 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 30 | /* Microamps */ |
| 31 | static const int isink_cur[] = { |
| 32 | 4, |
| 33 | 5, |
| 34 | 6, |
| 35 | 7, |
| 36 | 8, |
| 37 | 10, |
| 38 | 11, |
| 39 | 14, |
| 40 | 16, |
| 41 | 19, |
| 42 | 23, |
| 43 | 27, |
| 44 | 32, |
| 45 | 39, |
| 46 | 46, |
| 47 | 54, |
| 48 | 65, |
| 49 | 77, |
| 50 | 92, |
| 51 | 109, |
| 52 | 130, |
| 53 | 154, |
| 54 | 183, |
| 55 | 218, |
| 56 | 259, |
| 57 | 308, |
| 58 | 367, |
| 59 | 436, |
| 60 | 518, |
| 61 | 616, |
| 62 | 733, |
| 63 | 872, |
| 64 | 1037, |
| 65 | 1233, |
| 66 | 1466, |
| 67 | 1744, |
| 68 | 2073, |
| 69 | 2466, |
| 70 | 2933, |
| 71 | 3487, |
| 72 | 4147, |
| 73 | 4932, |
| 74 | 5865, |
| 75 | 6975, |
| 76 | 8294, |
| 77 | 9864, |
| 78 | 11730, |
| 79 | 13949, |
| 80 | 16589, |
| 81 | 19728, |
| 82 | 23460, |
| 83 | 27899, |
| 84 | 33178, |
| 85 | 39455, |
| 86 | 46920, |
| 87 | 55798, |
| 88 | 66355, |
| 89 | 78910, |
| 90 | 93840, |
| 91 | 111596, |
| 92 | 132710, |
| 93 | 157820, |
| 94 | 187681, |
| 95 | 223191 |
| 96 | }; |
| 97 | |
| 98 | static int get_isink_val(int min_uA, int max_uA, u16 *setting) |
| 99 | { |
| 100 | int i; |
| 101 | |
Axel Lin | 3a74403 | 2012-03-27 15:20:08 +0800 | [diff] [blame] | 102 | for (i = 0; i < ARRAY_SIZE(isink_cur); i++) { |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 103 | if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) { |
| 104 | *setting = i; |
| 105 | return 0; |
| 106 | } |
| 107 | } |
| 108 | return -EINVAL; |
| 109 | } |
| 110 | |
| 111 | static inline int wm8350_ldo_val_to_mvolts(unsigned int val) |
| 112 | { |
| 113 | if (val < 16) |
| 114 | return (val * 50) + 900; |
| 115 | else |
| 116 | return ((val - 16) * 100) + 1800; |
| 117 | |
| 118 | } |
| 119 | |
| 120 | static inline unsigned int wm8350_ldo_mvolts_to_val(int mV) |
| 121 | { |
| 122 | if (mV < 1800) |
| 123 | return (mV - 900) / 50; |
| 124 | else |
| 125 | return ((mV - 1800) / 100) + 16; |
| 126 | } |
| 127 | |
| 128 | static inline int wm8350_dcdc_val_to_mvolts(unsigned int val) |
| 129 | { |
| 130 | return (val * 25) + 850; |
| 131 | } |
| 132 | |
| 133 | static inline unsigned int wm8350_dcdc_mvolts_to_val(int mV) |
| 134 | { |
| 135 | return (mV - 850) / 25; |
| 136 | } |
| 137 | |
| 138 | static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA, |
| 139 | int max_uA) |
| 140 | { |
| 141 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 142 | int isink = rdev_get_id(rdev); |
| 143 | u16 val, setting; |
| 144 | int ret; |
| 145 | |
| 146 | ret = get_isink_val(min_uA, max_uA, &setting); |
| 147 | if (ret != 0) |
| 148 | return ret; |
| 149 | |
| 150 | switch (isink) { |
| 151 | case WM8350_ISINK_A: |
| 152 | val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) & |
| 153 | ~WM8350_CS1_ISEL_MASK; |
| 154 | wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_A, |
| 155 | val | setting); |
| 156 | break; |
| 157 | case WM8350_ISINK_B: |
| 158 | val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) & |
| 159 | ~WM8350_CS1_ISEL_MASK; |
| 160 | wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_B, |
| 161 | val | setting); |
| 162 | break; |
| 163 | default: |
| 164 | return -EINVAL; |
| 165 | } |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static int wm8350_isink_get_current(struct regulator_dev *rdev) |
| 171 | { |
| 172 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 173 | int isink = rdev_get_id(rdev); |
| 174 | u16 val; |
| 175 | |
| 176 | switch (isink) { |
| 177 | case WM8350_ISINK_A: |
| 178 | val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) & |
| 179 | WM8350_CS1_ISEL_MASK; |
| 180 | break; |
| 181 | case WM8350_ISINK_B: |
| 182 | val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) & |
| 183 | WM8350_CS1_ISEL_MASK; |
| 184 | break; |
| 185 | default: |
| 186 | return 0; |
| 187 | } |
| 188 | |
Axel Lin | fa5a97b | 2012-03-27 15:21:45 +0800 | [diff] [blame] | 189 | return isink_cur[val]; |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* turn on ISINK followed by DCDC */ |
| 193 | static int wm8350_isink_enable(struct regulator_dev *rdev) |
| 194 | { |
| 195 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 196 | int isink = rdev_get_id(rdev); |
| 197 | |
| 198 | switch (isink) { |
| 199 | case WM8350_ISINK_A: |
| 200 | switch (wm8350->pmic.isink_A_dcdc) { |
| 201 | case WM8350_DCDC_2: |
| 202 | case WM8350_DCDC_5: |
| 203 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7, |
| 204 | WM8350_CS1_ENA); |
| 205 | wm8350_set_bits(wm8350, WM8350_CSA_FLASH_CONTROL, |
| 206 | WM8350_CS1_DRIVE); |
| 207 | wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, |
| 208 | 1 << (wm8350->pmic.isink_A_dcdc - |
| 209 | WM8350_DCDC_1)); |
| 210 | break; |
| 211 | default: |
| 212 | return -EINVAL; |
| 213 | } |
| 214 | break; |
| 215 | case WM8350_ISINK_B: |
| 216 | switch (wm8350->pmic.isink_B_dcdc) { |
| 217 | case WM8350_DCDC_2: |
| 218 | case WM8350_DCDC_5: |
| 219 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7, |
| 220 | WM8350_CS2_ENA); |
| 221 | wm8350_set_bits(wm8350, WM8350_CSB_FLASH_CONTROL, |
| 222 | WM8350_CS2_DRIVE); |
| 223 | wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, |
| 224 | 1 << (wm8350->pmic.isink_B_dcdc - |
| 225 | WM8350_DCDC_1)); |
| 226 | break; |
| 227 | default: |
| 228 | return -EINVAL; |
| 229 | } |
| 230 | break; |
| 231 | default: |
| 232 | return -EINVAL; |
| 233 | } |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int wm8350_isink_disable(struct regulator_dev *rdev) |
| 238 | { |
| 239 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 240 | int isink = rdev_get_id(rdev); |
| 241 | |
| 242 | switch (isink) { |
| 243 | case WM8350_ISINK_A: |
| 244 | switch (wm8350->pmic.isink_A_dcdc) { |
| 245 | case WM8350_DCDC_2: |
| 246 | case WM8350_DCDC_5: |
| 247 | wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, |
| 248 | 1 << (wm8350->pmic.isink_A_dcdc - |
| 249 | WM8350_DCDC_1)); |
| 250 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7, |
| 251 | WM8350_CS1_ENA); |
| 252 | break; |
| 253 | default: |
| 254 | return -EINVAL; |
| 255 | } |
| 256 | break; |
| 257 | case WM8350_ISINK_B: |
| 258 | switch (wm8350->pmic.isink_B_dcdc) { |
| 259 | case WM8350_DCDC_2: |
| 260 | case WM8350_DCDC_5: |
| 261 | wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, |
| 262 | 1 << (wm8350->pmic.isink_B_dcdc - |
| 263 | WM8350_DCDC_1)); |
| 264 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7, |
| 265 | WM8350_CS2_ENA); |
| 266 | break; |
| 267 | default: |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | break; |
| 271 | default: |
| 272 | return -EINVAL; |
| 273 | } |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | static int wm8350_isink_is_enabled(struct regulator_dev *rdev) |
| 278 | { |
| 279 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 280 | int isink = rdev_get_id(rdev); |
| 281 | |
| 282 | switch (isink) { |
| 283 | case WM8350_ISINK_A: |
| 284 | return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) & |
| 285 | 0x8000; |
| 286 | case WM8350_ISINK_B: |
| 287 | return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) & |
| 288 | 0x8000; |
| 289 | } |
| 290 | return -EINVAL; |
| 291 | } |
| 292 | |
Mark Brown | 75c8ac2 | 2010-01-04 17:24:01 +0000 | [diff] [blame] | 293 | static int wm8350_isink_enable_time(struct regulator_dev *rdev) |
| 294 | { |
| 295 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 296 | int isink = rdev_get_id(rdev); |
| 297 | int reg; |
| 298 | |
| 299 | switch (isink) { |
| 300 | case WM8350_ISINK_A: |
| 301 | reg = wm8350_reg_read(wm8350, WM8350_CSA_FLASH_CONTROL); |
| 302 | break; |
| 303 | case WM8350_ISINK_B: |
| 304 | reg = wm8350_reg_read(wm8350, WM8350_CSB_FLASH_CONTROL); |
| 305 | break; |
| 306 | default: |
| 307 | return -EINVAL; |
| 308 | } |
| 309 | |
| 310 | if (reg & WM8350_CS1_FLASH_MODE) { |
| 311 | switch (reg & WM8350_CS1_ON_RAMP_MASK) { |
| 312 | case 0: |
| 313 | return 0; |
| 314 | case 1: |
| 315 | return 1950; |
| 316 | case 2: |
| 317 | return 3910; |
| 318 | case 3: |
| 319 | return 7800; |
| 320 | } |
| 321 | } else { |
| 322 | switch (reg & WM8350_CS1_ON_RAMP_MASK) { |
| 323 | case 0: |
| 324 | return 0; |
| 325 | case 1: |
| 326 | return 250000; |
| 327 | case 2: |
| 328 | return 500000; |
| 329 | case 3: |
| 330 | return 1000000; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return -EINVAL; |
| 335 | } |
| 336 | |
| 337 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 338 | int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode, |
| 339 | u16 trigger, u16 duration, u16 on_ramp, u16 off_ramp, |
| 340 | u16 drive) |
| 341 | { |
| 342 | switch (isink) { |
| 343 | case WM8350_ISINK_A: |
| 344 | wm8350_reg_write(wm8350, WM8350_CSA_FLASH_CONTROL, |
| 345 | (mode ? WM8350_CS1_FLASH_MODE : 0) | |
| 346 | (trigger ? WM8350_CS1_TRIGSRC : 0) | |
| 347 | duration | on_ramp | off_ramp | drive); |
| 348 | break; |
| 349 | case WM8350_ISINK_B: |
| 350 | wm8350_reg_write(wm8350, WM8350_CSB_FLASH_CONTROL, |
| 351 | (mode ? WM8350_CS2_FLASH_MODE : 0) | |
| 352 | (trigger ? WM8350_CS2_TRIGSRC : 0) | |
| 353 | duration | on_ramp | off_ramp | drive); |
| 354 | break; |
| 355 | default: |
| 356 | return -EINVAL; |
| 357 | } |
| 358 | return 0; |
| 359 | } |
| 360 | EXPORT_SYMBOL_GPL(wm8350_isink_set_flash); |
| 361 | |
| 362 | static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV, |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 363 | int max_uV, unsigned *selector) |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 364 | { |
| 365 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 366 | int volt_reg, dcdc = rdev_get_id(rdev), mV, |
| 367 | min_mV = min_uV / 1000, max_mV = max_uV / 1000; |
| 368 | u16 val; |
| 369 | |
| 370 | if (min_mV < 850 || min_mV > 4025) |
| 371 | return -EINVAL; |
| 372 | if (max_mV < 850 || max_mV > 4025) |
| 373 | return -EINVAL; |
| 374 | |
| 375 | /* step size is 25mV */ |
| 376 | mV = (min_mV - 826) / 25; |
| 377 | if (wm8350_dcdc_val_to_mvolts(mV) > max_mV) |
| 378 | return -EINVAL; |
| 379 | BUG_ON(wm8350_dcdc_val_to_mvolts(mV) < min_mV); |
| 380 | |
| 381 | switch (dcdc) { |
| 382 | case WM8350_DCDC_1: |
| 383 | volt_reg = WM8350_DCDC1_CONTROL; |
| 384 | break; |
| 385 | case WM8350_DCDC_3: |
| 386 | volt_reg = WM8350_DCDC3_CONTROL; |
| 387 | break; |
| 388 | case WM8350_DCDC_4: |
| 389 | volt_reg = WM8350_DCDC4_CONTROL; |
| 390 | break; |
| 391 | case WM8350_DCDC_6: |
| 392 | volt_reg = WM8350_DCDC6_CONTROL; |
| 393 | break; |
| 394 | case WM8350_DCDC_2: |
| 395 | case WM8350_DCDC_5: |
| 396 | default: |
| 397 | return -EINVAL; |
| 398 | } |
| 399 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 400 | *selector = mV; |
| 401 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 402 | /* all DCDCs have same mV bits */ |
| 403 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; |
| 404 | wm8350_reg_write(wm8350, volt_reg, val | mV); |
| 405 | return 0; |
| 406 | } |
| 407 | |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 408 | static int wm8350_dcdc_list_voltage(struct regulator_dev *rdev, |
| 409 | unsigned selector) |
| 410 | { |
| 411 | if (selector > WM8350_DCDC_MAX_VSEL) |
| 412 | return -EINVAL; |
| 413 | return wm8350_dcdc_val_to_mvolts(selector) * 1000; |
| 414 | } |
| 415 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 416 | static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) |
| 417 | { |
| 418 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 419 | int volt_reg, mV = uV / 1000, dcdc = rdev_get_id(rdev); |
| 420 | u16 val; |
| 421 | |
| 422 | dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, mV); |
| 423 | |
| 424 | if (mV && (mV < 850 || mV > 4025)) { |
| 425 | dev_err(wm8350->dev, |
| 426 | "DCDC%d suspend voltage %d mV out of range\n", |
| 427 | dcdc, mV); |
| 428 | return -EINVAL; |
| 429 | } |
| 430 | if (mV == 0) |
| 431 | mV = 850; |
| 432 | |
| 433 | switch (dcdc) { |
| 434 | case WM8350_DCDC_1: |
| 435 | volt_reg = WM8350_DCDC1_LOW_POWER; |
| 436 | break; |
| 437 | case WM8350_DCDC_3: |
| 438 | volt_reg = WM8350_DCDC3_LOW_POWER; |
| 439 | break; |
| 440 | case WM8350_DCDC_4: |
| 441 | volt_reg = WM8350_DCDC4_LOW_POWER; |
| 442 | break; |
| 443 | case WM8350_DCDC_6: |
| 444 | volt_reg = WM8350_DCDC6_LOW_POWER; |
| 445 | break; |
| 446 | case WM8350_DCDC_2: |
| 447 | case WM8350_DCDC_5: |
| 448 | default: |
| 449 | return -EINVAL; |
| 450 | } |
| 451 | |
| 452 | /* all DCDCs have same mV bits */ |
| 453 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; |
| 454 | wm8350_reg_write(wm8350, volt_reg, |
| 455 | val | wm8350_dcdc_mvolts_to_val(mV)); |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | static int wm8350_dcdc_set_suspend_enable(struct regulator_dev *rdev) |
| 460 | { |
| 461 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 462 | int dcdc = rdev_get_id(rdev); |
| 463 | u16 val; |
| 464 | |
| 465 | switch (dcdc) { |
| 466 | case WM8350_DCDC_1: |
| 467 | val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER) |
| 468 | & ~WM8350_DCDC_HIB_MODE_MASK; |
| 469 | wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER, |
Axel Lin | eb41681 | 2012-03-23 06:25:05 +0800 | [diff] [blame] | 470 | val | wm8350->pmic.dcdc1_hib_mode); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 471 | break; |
| 472 | case WM8350_DCDC_3: |
| 473 | val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER) |
| 474 | & ~WM8350_DCDC_HIB_MODE_MASK; |
| 475 | wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER, |
Axel Lin | eb41681 | 2012-03-23 06:25:05 +0800 | [diff] [blame] | 476 | val | wm8350->pmic.dcdc3_hib_mode); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 477 | break; |
| 478 | case WM8350_DCDC_4: |
| 479 | val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER) |
| 480 | & ~WM8350_DCDC_HIB_MODE_MASK; |
| 481 | wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER, |
Axel Lin | eb41681 | 2012-03-23 06:25:05 +0800 | [diff] [blame] | 482 | val | wm8350->pmic.dcdc4_hib_mode); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 483 | break; |
| 484 | case WM8350_DCDC_6: |
| 485 | val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER) |
| 486 | & ~WM8350_DCDC_HIB_MODE_MASK; |
| 487 | wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER, |
Axel Lin | eb41681 | 2012-03-23 06:25:05 +0800 | [diff] [blame] | 488 | val | wm8350->pmic.dcdc6_hib_mode); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 489 | break; |
| 490 | case WM8350_DCDC_2: |
| 491 | case WM8350_DCDC_5: |
| 492 | default: |
| 493 | return -EINVAL; |
| 494 | } |
| 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | static int wm8350_dcdc_set_suspend_disable(struct regulator_dev *rdev) |
| 500 | { |
| 501 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 502 | int dcdc = rdev_get_id(rdev); |
| 503 | u16 val; |
| 504 | |
| 505 | switch (dcdc) { |
| 506 | case WM8350_DCDC_1: |
| 507 | val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER); |
| 508 | wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; |
| 509 | wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER, |
Axel Lin | cee1a79 | 2012-03-29 10:47:36 +0800 | [diff] [blame] | 510 | val | WM8350_DCDC_HIB_MODE_DIS); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 511 | break; |
| 512 | case WM8350_DCDC_3: |
| 513 | val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER); |
| 514 | wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; |
| 515 | wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER, |
Axel Lin | cee1a79 | 2012-03-29 10:47:36 +0800 | [diff] [blame] | 516 | val | WM8350_DCDC_HIB_MODE_DIS); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 517 | break; |
| 518 | case WM8350_DCDC_4: |
| 519 | val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER); |
| 520 | wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; |
| 521 | wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER, |
Axel Lin | cee1a79 | 2012-03-29 10:47:36 +0800 | [diff] [blame] | 522 | val | WM8350_DCDC_HIB_MODE_DIS); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 523 | break; |
| 524 | case WM8350_DCDC_6: |
| 525 | val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER); |
| 526 | wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; |
| 527 | wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER, |
Axel Lin | cee1a79 | 2012-03-29 10:47:36 +0800 | [diff] [blame] | 528 | val | WM8350_DCDC_HIB_MODE_DIS); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 529 | break; |
| 530 | case WM8350_DCDC_2: |
| 531 | case WM8350_DCDC_5: |
| 532 | default: |
| 533 | return -EINVAL; |
| 534 | } |
| 535 | |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | static int wm8350_dcdc25_set_suspend_enable(struct regulator_dev *rdev) |
| 540 | { |
| 541 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 542 | int dcdc = rdev_get_id(rdev); |
| 543 | u16 val; |
| 544 | |
| 545 | switch (dcdc) { |
| 546 | case WM8350_DCDC_2: |
| 547 | val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL) |
| 548 | & ~WM8350_DC2_HIB_MODE_MASK; |
| 549 | wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val | |
Axel Lin | 9300928 | 2012-03-23 06:27:10 +0800 | [diff] [blame] | 550 | (WM8350_DC2_HIB_MODE_ACTIVE << WM8350_DC2_HIB_MODE_SHIFT)); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 551 | break; |
| 552 | case WM8350_DCDC_5: |
| 553 | val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL) |
Axel Lin | 9300928 | 2012-03-23 06:27:10 +0800 | [diff] [blame] | 554 | & ~WM8350_DC5_HIB_MODE_MASK; |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 555 | wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val | |
Axel Lin | 9300928 | 2012-03-23 06:27:10 +0800 | [diff] [blame] | 556 | (WM8350_DC5_HIB_MODE_ACTIVE << WM8350_DC5_HIB_MODE_SHIFT)); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 557 | break; |
| 558 | default: |
| 559 | return -EINVAL; |
| 560 | } |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | static int wm8350_dcdc25_set_suspend_disable(struct regulator_dev *rdev) |
| 565 | { |
| 566 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 567 | int dcdc = rdev_get_id(rdev); |
| 568 | u16 val; |
| 569 | |
| 570 | switch (dcdc) { |
| 571 | case WM8350_DCDC_2: |
| 572 | val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL) |
| 573 | & ~WM8350_DC2_HIB_MODE_MASK; |
| 574 | wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val | |
Axel Lin | 9300928 | 2012-03-23 06:27:10 +0800 | [diff] [blame] | 575 | (WM8350_DC2_HIB_MODE_DISABLE << WM8350_DC2_HIB_MODE_SHIFT)); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 576 | break; |
| 577 | case WM8350_DCDC_5: |
| 578 | val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL) |
Axel Lin | 9300928 | 2012-03-23 06:27:10 +0800 | [diff] [blame] | 579 | & ~WM8350_DC5_HIB_MODE_MASK; |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 580 | wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val | |
Axel Lin | 9300928 | 2012-03-23 06:27:10 +0800 | [diff] [blame] | 581 | (WM8350_DC5_HIB_MODE_DISABLE << WM8350_DC5_HIB_MODE_SHIFT)); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 582 | break; |
| 583 | default: |
| 584 | return -EINVAL; |
| 585 | } |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev, |
| 590 | unsigned int mode) |
| 591 | { |
| 592 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 593 | int dcdc = rdev_get_id(rdev); |
| 594 | u16 *hib_mode; |
| 595 | |
| 596 | switch (dcdc) { |
| 597 | case WM8350_DCDC_1: |
| 598 | hib_mode = &wm8350->pmic.dcdc1_hib_mode; |
| 599 | break; |
| 600 | case WM8350_DCDC_3: |
| 601 | hib_mode = &wm8350->pmic.dcdc3_hib_mode; |
| 602 | break; |
| 603 | case WM8350_DCDC_4: |
| 604 | hib_mode = &wm8350->pmic.dcdc4_hib_mode; |
| 605 | break; |
| 606 | case WM8350_DCDC_6: |
| 607 | hib_mode = &wm8350->pmic.dcdc6_hib_mode; |
| 608 | break; |
| 609 | case WM8350_DCDC_2: |
| 610 | case WM8350_DCDC_5: |
| 611 | default: |
| 612 | return -EINVAL; |
| 613 | } |
| 614 | |
| 615 | switch (mode) { |
| 616 | case REGULATOR_MODE_NORMAL: |
| 617 | *hib_mode = WM8350_DCDC_HIB_MODE_IMAGE; |
| 618 | break; |
| 619 | case REGULATOR_MODE_IDLE: |
| 620 | *hib_mode = WM8350_DCDC_HIB_MODE_STANDBY; |
| 621 | break; |
| 622 | case REGULATOR_MODE_STANDBY: |
| 623 | *hib_mode = WM8350_DCDC_HIB_MODE_LDO_IM; |
| 624 | break; |
| 625 | default: |
| 626 | return -EINVAL; |
| 627 | } |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) |
| 633 | { |
| 634 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 635 | int volt_reg, mV = uV / 1000, ldo = rdev_get_id(rdev); |
| 636 | u16 val; |
| 637 | |
| 638 | dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, mV); |
| 639 | |
| 640 | if (mV < 900 || mV > 3300) { |
| 641 | dev_err(wm8350->dev, "LDO%d voltage %d mV out of range\n", |
| 642 | ldo, mV); |
| 643 | return -EINVAL; |
| 644 | } |
| 645 | |
| 646 | switch (ldo) { |
| 647 | case WM8350_LDO_1: |
| 648 | volt_reg = WM8350_LDO1_LOW_POWER; |
| 649 | break; |
| 650 | case WM8350_LDO_2: |
| 651 | volt_reg = WM8350_LDO2_LOW_POWER; |
| 652 | break; |
| 653 | case WM8350_LDO_3: |
| 654 | volt_reg = WM8350_LDO3_LOW_POWER; |
| 655 | break; |
| 656 | case WM8350_LDO_4: |
| 657 | volt_reg = WM8350_LDO4_LOW_POWER; |
| 658 | break; |
| 659 | default: |
| 660 | return -EINVAL; |
| 661 | } |
| 662 | |
| 663 | /* all LDOs have same mV bits */ |
| 664 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; |
| 665 | wm8350_reg_write(wm8350, volt_reg, |
| 666 | val | wm8350_ldo_mvolts_to_val(mV)); |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | static int wm8350_ldo_set_suspend_enable(struct regulator_dev *rdev) |
| 671 | { |
| 672 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 673 | int volt_reg, ldo = rdev_get_id(rdev); |
| 674 | u16 val; |
| 675 | |
| 676 | switch (ldo) { |
| 677 | case WM8350_LDO_1: |
| 678 | volt_reg = WM8350_LDO1_LOW_POWER; |
| 679 | break; |
| 680 | case WM8350_LDO_2: |
| 681 | volt_reg = WM8350_LDO2_LOW_POWER; |
| 682 | break; |
| 683 | case WM8350_LDO_3: |
| 684 | volt_reg = WM8350_LDO3_LOW_POWER; |
| 685 | break; |
| 686 | case WM8350_LDO_4: |
| 687 | volt_reg = WM8350_LDO4_LOW_POWER; |
| 688 | break; |
| 689 | default: |
| 690 | return -EINVAL; |
| 691 | } |
| 692 | |
| 693 | /* all LDOs have same mV bits */ |
| 694 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK; |
| 695 | wm8350_reg_write(wm8350, volt_reg, val); |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev) |
| 700 | { |
| 701 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 702 | int volt_reg, ldo = rdev_get_id(rdev); |
| 703 | u16 val; |
| 704 | |
| 705 | switch (ldo) { |
| 706 | case WM8350_LDO_1: |
| 707 | volt_reg = WM8350_LDO1_LOW_POWER; |
| 708 | break; |
| 709 | case WM8350_LDO_2: |
| 710 | volt_reg = WM8350_LDO2_LOW_POWER; |
| 711 | break; |
| 712 | case WM8350_LDO_3: |
| 713 | volt_reg = WM8350_LDO3_LOW_POWER; |
| 714 | break; |
| 715 | case WM8350_LDO_4: |
| 716 | volt_reg = WM8350_LDO4_LOW_POWER; |
| 717 | break; |
| 718 | default: |
| 719 | return -EINVAL; |
| 720 | } |
| 721 | |
| 722 | /* all LDOs have same mV bits */ |
| 723 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK; |
Axel Lin | cee1a79 | 2012-03-29 10:47:36 +0800 | [diff] [blame] | 724 | wm8350_reg_write(wm8350, volt_reg, val | WM8350_LDO1_HIB_MODE_DIS); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV, |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 729 | int max_uV, unsigned *selector) |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 730 | { |
| 731 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 732 | int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000, |
| 733 | max_mV = max_uV / 1000; |
| 734 | u16 val; |
| 735 | |
| 736 | if (min_mV < 900 || min_mV > 3300) |
| 737 | return -EINVAL; |
| 738 | if (max_mV < 900 || max_mV > 3300) |
| 739 | return -EINVAL; |
| 740 | |
| 741 | if (min_mV < 1800) { |
| 742 | /* step size is 50mV < 1800mV */ |
| 743 | mV = (min_mV - 851) / 50; |
| 744 | if (wm8350_ldo_val_to_mvolts(mV) > max_mV) |
| 745 | return -EINVAL; |
| 746 | BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV); |
| 747 | } else { |
| 748 | /* step size is 100mV > 1800mV */ |
| 749 | mV = ((min_mV - 1701) / 100) + 16; |
| 750 | if (wm8350_ldo_val_to_mvolts(mV) > max_mV) |
| 751 | return -EINVAL; |
| 752 | BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV); |
| 753 | } |
| 754 | |
| 755 | switch (ldo) { |
| 756 | case WM8350_LDO_1: |
| 757 | volt_reg = WM8350_LDO1_CONTROL; |
| 758 | break; |
| 759 | case WM8350_LDO_2: |
| 760 | volt_reg = WM8350_LDO2_CONTROL; |
| 761 | break; |
| 762 | case WM8350_LDO_3: |
| 763 | volt_reg = WM8350_LDO3_CONTROL; |
| 764 | break; |
| 765 | case WM8350_LDO_4: |
| 766 | volt_reg = WM8350_LDO4_CONTROL; |
| 767 | break; |
| 768 | default: |
| 769 | return -EINVAL; |
| 770 | } |
| 771 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 772 | *selector = mV; |
| 773 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 774 | /* all LDOs have same mV bits */ |
| 775 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; |
| 776 | wm8350_reg_write(wm8350, volt_reg, val | mV); |
| 777 | return 0; |
| 778 | } |
| 779 | |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 780 | static int wm8350_ldo_list_voltage(struct regulator_dev *rdev, |
| 781 | unsigned selector) |
| 782 | { |
| 783 | if (selector > WM8350_LDO1_VSEL_MASK) |
| 784 | return -EINVAL; |
| 785 | return wm8350_ldo_val_to_mvolts(selector) * 1000; |
| 786 | } |
| 787 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 788 | int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, |
| 789 | u16 stop, u16 fault) |
| 790 | { |
| 791 | int slot_reg; |
| 792 | u16 val; |
| 793 | |
| 794 | dev_dbg(wm8350->dev, "%s %d start %d stop %d\n", |
| 795 | __func__, dcdc, start, stop); |
| 796 | |
| 797 | /* slot valid ? */ |
| 798 | if (start > 15 || stop > 15) |
| 799 | return -EINVAL; |
| 800 | |
| 801 | switch (dcdc) { |
| 802 | case WM8350_DCDC_1: |
| 803 | slot_reg = WM8350_DCDC1_TIMEOUTS; |
| 804 | break; |
| 805 | case WM8350_DCDC_2: |
| 806 | slot_reg = WM8350_DCDC2_TIMEOUTS; |
| 807 | break; |
| 808 | case WM8350_DCDC_3: |
| 809 | slot_reg = WM8350_DCDC3_TIMEOUTS; |
| 810 | break; |
| 811 | case WM8350_DCDC_4: |
| 812 | slot_reg = WM8350_DCDC4_TIMEOUTS; |
| 813 | break; |
| 814 | case WM8350_DCDC_5: |
| 815 | slot_reg = WM8350_DCDC5_TIMEOUTS; |
| 816 | break; |
| 817 | case WM8350_DCDC_6: |
| 818 | slot_reg = WM8350_DCDC6_TIMEOUTS; |
| 819 | break; |
| 820 | default: |
| 821 | return -EINVAL; |
| 822 | } |
| 823 | |
| 824 | val = wm8350_reg_read(wm8350, slot_reg) & |
| 825 | ~(WM8350_DC1_ENSLOT_MASK | WM8350_DC1_SDSLOT_MASK | |
| 826 | WM8350_DC1_ERRACT_MASK); |
| 827 | wm8350_reg_write(wm8350, slot_reg, |
| 828 | val | (start << WM8350_DC1_ENSLOT_SHIFT) | |
| 829 | (stop << WM8350_DC1_SDSLOT_SHIFT) | |
| 830 | (fault << WM8350_DC1_ERRACT_SHIFT)); |
| 831 | |
| 832 | return 0; |
| 833 | } |
| 834 | EXPORT_SYMBOL_GPL(wm8350_dcdc_set_slot); |
| 835 | |
| 836 | int wm8350_ldo_set_slot(struct wm8350 *wm8350, int ldo, u16 start, u16 stop) |
| 837 | { |
| 838 | int slot_reg; |
| 839 | u16 val; |
| 840 | |
| 841 | dev_dbg(wm8350->dev, "%s %d start %d stop %d\n", |
| 842 | __func__, ldo, start, stop); |
| 843 | |
| 844 | /* slot valid ? */ |
| 845 | if (start > 15 || stop > 15) |
| 846 | return -EINVAL; |
| 847 | |
| 848 | switch (ldo) { |
| 849 | case WM8350_LDO_1: |
| 850 | slot_reg = WM8350_LDO1_TIMEOUTS; |
| 851 | break; |
| 852 | case WM8350_LDO_2: |
| 853 | slot_reg = WM8350_LDO2_TIMEOUTS; |
| 854 | break; |
| 855 | case WM8350_LDO_3: |
| 856 | slot_reg = WM8350_LDO3_TIMEOUTS; |
| 857 | break; |
| 858 | case WM8350_LDO_4: |
| 859 | slot_reg = WM8350_LDO4_TIMEOUTS; |
| 860 | break; |
| 861 | default: |
| 862 | return -EINVAL; |
| 863 | } |
| 864 | |
| 865 | val = wm8350_reg_read(wm8350, slot_reg) & ~WM8350_LDO1_SDSLOT_MASK; |
| 866 | wm8350_reg_write(wm8350, slot_reg, val | ((start << 10) | (stop << 6))); |
| 867 | return 0; |
| 868 | } |
| 869 | EXPORT_SYMBOL_GPL(wm8350_ldo_set_slot); |
| 870 | |
| 871 | int wm8350_dcdc25_set_mode(struct wm8350 *wm8350, int dcdc, u16 mode, |
| 872 | u16 ilim, u16 ramp, u16 feedback) |
| 873 | { |
| 874 | u16 val; |
| 875 | |
| 876 | dev_dbg(wm8350->dev, "%s %d mode: %s %s\n", __func__, dcdc, |
| 877 | mode ? "normal" : "boost", ilim ? "low" : "normal"); |
| 878 | |
| 879 | switch (dcdc) { |
| 880 | case WM8350_DCDC_2: |
| 881 | val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL) |
| 882 | & ~(WM8350_DC2_MODE_MASK | WM8350_DC2_ILIM_MASK | |
| 883 | WM8350_DC2_RMP_MASK | WM8350_DC2_FBSRC_MASK); |
| 884 | wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val | |
| 885 | (mode << WM8350_DC2_MODE_SHIFT) | |
| 886 | (ilim << WM8350_DC2_ILIM_SHIFT) | |
| 887 | (ramp << WM8350_DC2_RMP_SHIFT) | |
| 888 | (feedback << WM8350_DC2_FBSRC_SHIFT)); |
| 889 | break; |
| 890 | case WM8350_DCDC_5: |
| 891 | val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL) |
| 892 | & ~(WM8350_DC5_MODE_MASK | WM8350_DC5_ILIM_MASK | |
| 893 | WM8350_DC5_RMP_MASK | WM8350_DC5_FBSRC_MASK); |
| 894 | wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val | |
| 895 | (mode << WM8350_DC5_MODE_SHIFT) | |
| 896 | (ilim << WM8350_DC5_ILIM_SHIFT) | |
| 897 | (ramp << WM8350_DC5_RMP_SHIFT) | |
| 898 | (feedback << WM8350_DC5_FBSRC_SHIFT)); |
| 899 | break; |
| 900 | default: |
| 901 | return -EINVAL; |
| 902 | } |
| 903 | |
| 904 | return 0; |
| 905 | } |
| 906 | EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode); |
| 907 | |
| 908 | static int wm8350_dcdc_enable(struct regulator_dev *rdev) |
| 909 | { |
| 910 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 911 | int dcdc = rdev_get_id(rdev); |
| 912 | u16 shift; |
| 913 | |
| 914 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) |
| 915 | return -EINVAL; |
| 916 | |
| 917 | shift = dcdc - WM8350_DCDC_1; |
| 918 | wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | static int wm8350_dcdc_disable(struct regulator_dev *rdev) |
| 923 | { |
| 924 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 925 | int dcdc = rdev_get_id(rdev); |
| 926 | u16 shift; |
| 927 | |
| 928 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) |
| 929 | return -EINVAL; |
| 930 | |
| 931 | shift = dcdc - WM8350_DCDC_1; |
| 932 | wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); |
| 933 | |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | static int wm8350_ldo_enable(struct regulator_dev *rdev) |
| 938 | { |
| 939 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 940 | int ldo = rdev_get_id(rdev); |
| 941 | u16 shift; |
| 942 | |
| 943 | if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4) |
| 944 | return -EINVAL; |
| 945 | |
| 946 | shift = (ldo - WM8350_LDO_1) + 8; |
| 947 | wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); |
| 948 | return 0; |
| 949 | } |
| 950 | |
| 951 | static int wm8350_ldo_disable(struct regulator_dev *rdev) |
| 952 | { |
| 953 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 954 | int ldo = rdev_get_id(rdev); |
| 955 | u16 shift; |
| 956 | |
| 957 | if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4) |
| 958 | return -EINVAL; |
| 959 | |
| 960 | shift = (ldo - WM8350_LDO_1) + 8; |
| 961 | wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); |
| 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | static int force_continuous_enable(struct wm8350 *wm8350, int dcdc, int enable) |
| 966 | { |
| 967 | int reg = 0, ret; |
| 968 | |
| 969 | switch (dcdc) { |
| 970 | case WM8350_DCDC_1: |
| 971 | reg = WM8350_DCDC1_FORCE_PWM; |
| 972 | break; |
| 973 | case WM8350_DCDC_3: |
| 974 | reg = WM8350_DCDC3_FORCE_PWM; |
| 975 | break; |
| 976 | case WM8350_DCDC_4: |
| 977 | reg = WM8350_DCDC4_FORCE_PWM; |
| 978 | break; |
| 979 | case WM8350_DCDC_6: |
| 980 | reg = WM8350_DCDC6_FORCE_PWM; |
| 981 | break; |
| 982 | default: |
| 983 | return -EINVAL; |
| 984 | } |
| 985 | |
| 986 | if (enable) |
| 987 | ret = wm8350_set_bits(wm8350, reg, |
| 988 | WM8350_DCDC1_FORCE_PWM_ENA); |
| 989 | else |
| 990 | ret = wm8350_clear_bits(wm8350, reg, |
| 991 | WM8350_DCDC1_FORCE_PWM_ENA); |
| 992 | return ret; |
| 993 | } |
| 994 | |
| 995 | static int wm8350_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode) |
| 996 | { |
| 997 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 998 | int dcdc = rdev_get_id(rdev); |
| 999 | u16 val; |
| 1000 | |
| 1001 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) |
| 1002 | return -EINVAL; |
| 1003 | |
| 1004 | if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5) |
| 1005 | return -EINVAL; |
| 1006 | |
| 1007 | val = 1 << (dcdc - WM8350_DCDC_1); |
| 1008 | |
| 1009 | switch (mode) { |
| 1010 | case REGULATOR_MODE_FAST: |
| 1011 | /* force continuous mode */ |
| 1012 | wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val); |
| 1013 | wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val); |
| 1014 | force_continuous_enable(wm8350, dcdc, 1); |
| 1015 | break; |
| 1016 | case REGULATOR_MODE_NORMAL: |
| 1017 | /* active / pulse skipping */ |
| 1018 | wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val); |
| 1019 | wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val); |
| 1020 | force_continuous_enable(wm8350, dcdc, 0); |
| 1021 | break; |
| 1022 | case REGULATOR_MODE_IDLE: |
| 1023 | /* standby mode */ |
| 1024 | force_continuous_enable(wm8350, dcdc, 0); |
| 1025 | wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val); |
| 1026 | wm8350_clear_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val); |
| 1027 | break; |
| 1028 | case REGULATOR_MODE_STANDBY: |
| 1029 | /* LDO mode */ |
| 1030 | force_continuous_enable(wm8350, dcdc, 0); |
| 1031 | wm8350_set_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val); |
| 1032 | break; |
| 1033 | } |
| 1034 | |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
| 1038 | static unsigned int wm8350_dcdc_get_mode(struct regulator_dev *rdev) |
| 1039 | { |
| 1040 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 1041 | int dcdc = rdev_get_id(rdev); |
| 1042 | u16 mask, sleep, active, force; |
| 1043 | int mode = REGULATOR_MODE_NORMAL; |
Mark Brown | 33f301a | 2009-02-26 19:24:20 +0000 | [diff] [blame] | 1044 | int reg; |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1045 | |
Mark Brown | 33f301a | 2009-02-26 19:24:20 +0000 | [diff] [blame] | 1046 | switch (dcdc) { |
| 1047 | case WM8350_DCDC_1: |
| 1048 | reg = WM8350_DCDC1_FORCE_PWM; |
| 1049 | break; |
| 1050 | case WM8350_DCDC_3: |
| 1051 | reg = WM8350_DCDC3_FORCE_PWM; |
| 1052 | break; |
| 1053 | case WM8350_DCDC_4: |
| 1054 | reg = WM8350_DCDC4_FORCE_PWM; |
| 1055 | break; |
| 1056 | case WM8350_DCDC_6: |
| 1057 | reg = WM8350_DCDC6_FORCE_PWM; |
| 1058 | break; |
| 1059 | default: |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1060 | return -EINVAL; |
Mark Brown | 33f301a | 2009-02-26 19:24:20 +0000 | [diff] [blame] | 1061 | } |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1062 | |
| 1063 | mask = 1 << (dcdc - WM8350_DCDC_1); |
| 1064 | active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask; |
Mark Brown | 33f301a | 2009-02-26 19:24:20 +0000 | [diff] [blame] | 1065 | force = wm8350_reg_read(wm8350, reg) & WM8350_DCDC1_FORCE_PWM_ENA; |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1066 | sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask; |
Mark Brown | 33f301a | 2009-02-26 19:24:20 +0000 | [diff] [blame] | 1067 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1068 | dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x", |
| 1069 | mask, active, sleep, force); |
| 1070 | |
| 1071 | if (active && !sleep) { |
| 1072 | if (force) |
| 1073 | mode = REGULATOR_MODE_FAST; |
| 1074 | else |
| 1075 | mode = REGULATOR_MODE_NORMAL; |
| 1076 | } else if (!active && !sleep) |
| 1077 | mode = REGULATOR_MODE_IDLE; |
Axel Lin | 8ecee36 | 2010-09-06 14:06:07 +0800 | [diff] [blame] | 1078 | else if (sleep) |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1079 | mode = REGULATOR_MODE_STANDBY; |
| 1080 | |
| 1081 | return mode; |
| 1082 | } |
| 1083 | |
| 1084 | static unsigned int wm8350_ldo_get_mode(struct regulator_dev *rdev) |
| 1085 | { |
| 1086 | return REGULATOR_MODE_NORMAL; |
| 1087 | } |
| 1088 | |
| 1089 | struct wm8350_dcdc_efficiency { |
| 1090 | int uA_load_min; |
| 1091 | int uA_load_max; |
| 1092 | unsigned int mode; |
| 1093 | }; |
| 1094 | |
| 1095 | static const struct wm8350_dcdc_efficiency dcdc1_6_efficiency[] = { |
| 1096 | {0, 10000, REGULATOR_MODE_STANDBY}, /* 0 - 10mA - LDO */ |
| 1097 | {10000, 100000, REGULATOR_MODE_IDLE}, /* 10mA - 100mA - Standby */ |
| 1098 | {100000, 1000000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */ |
| 1099 | {-1, -1, REGULATOR_MODE_NORMAL}, |
| 1100 | }; |
| 1101 | |
| 1102 | static const struct wm8350_dcdc_efficiency dcdc3_4_efficiency[] = { |
| 1103 | {0, 10000, REGULATOR_MODE_STANDBY}, /* 0 - 10mA - LDO */ |
| 1104 | {10000, 100000, REGULATOR_MODE_IDLE}, /* 10mA - 100mA - Standby */ |
| 1105 | {100000, 800000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */ |
| 1106 | {-1, -1, REGULATOR_MODE_NORMAL}, |
| 1107 | }; |
| 1108 | |
| 1109 | static unsigned int get_mode(int uA, const struct wm8350_dcdc_efficiency *eff) |
| 1110 | { |
| 1111 | int i = 0; |
| 1112 | |
| 1113 | while (eff[i].uA_load_min != -1) { |
| 1114 | if (uA >= eff[i].uA_load_min && uA <= eff[i].uA_load_max) |
| 1115 | return eff[i].mode; |
| 1116 | } |
| 1117 | return REGULATOR_MODE_NORMAL; |
| 1118 | } |
| 1119 | |
| 1120 | /* Query the regulator for it's most efficient mode @ uV,uA |
| 1121 | * WM8350 regulator efficiency is pretty similar over |
| 1122 | * different input and output uV. |
| 1123 | */ |
| 1124 | static unsigned int wm8350_dcdc_get_optimum_mode(struct regulator_dev *rdev, |
| 1125 | int input_uV, int output_uV, |
| 1126 | int output_uA) |
| 1127 | { |
| 1128 | int dcdc = rdev_get_id(rdev), mode; |
| 1129 | |
| 1130 | switch (dcdc) { |
| 1131 | case WM8350_DCDC_1: |
| 1132 | case WM8350_DCDC_6: |
| 1133 | mode = get_mode(output_uA, dcdc1_6_efficiency); |
| 1134 | break; |
| 1135 | case WM8350_DCDC_3: |
| 1136 | case WM8350_DCDC_4: |
| 1137 | mode = get_mode(output_uA, dcdc3_4_efficiency); |
| 1138 | break; |
| 1139 | default: |
| 1140 | mode = REGULATOR_MODE_NORMAL; |
| 1141 | break; |
| 1142 | } |
| 1143 | return mode; |
| 1144 | } |
| 1145 | |
| 1146 | static int wm8350_dcdc_is_enabled(struct regulator_dev *rdev) |
| 1147 | { |
| 1148 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 1149 | int dcdc = rdev_get_id(rdev), shift; |
| 1150 | |
| 1151 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) |
| 1152 | return -EINVAL; |
| 1153 | |
| 1154 | shift = dcdc - WM8350_DCDC_1; |
| 1155 | return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED) |
| 1156 | & (1 << shift); |
| 1157 | } |
| 1158 | |
| 1159 | static int wm8350_ldo_is_enabled(struct regulator_dev *rdev) |
| 1160 | { |
| 1161 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 1162 | int ldo = rdev_get_id(rdev), shift; |
| 1163 | |
| 1164 | if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4) |
| 1165 | return -EINVAL; |
| 1166 | |
| 1167 | shift = (ldo - WM8350_LDO_1) + 8; |
| 1168 | return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED) |
| 1169 | & (1 << shift); |
| 1170 | } |
| 1171 | |
| 1172 | static struct regulator_ops wm8350_dcdc_ops = { |
| 1173 | .set_voltage = wm8350_dcdc_set_voltage, |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1174 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 1175 | .list_voltage = wm8350_dcdc_list_voltage, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1176 | .enable = wm8350_dcdc_enable, |
| 1177 | .disable = wm8350_dcdc_disable, |
| 1178 | .get_mode = wm8350_dcdc_get_mode, |
| 1179 | .set_mode = wm8350_dcdc_set_mode, |
| 1180 | .get_optimum_mode = wm8350_dcdc_get_optimum_mode, |
| 1181 | .is_enabled = wm8350_dcdc_is_enabled, |
| 1182 | .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage, |
| 1183 | .set_suspend_enable = wm8350_dcdc_set_suspend_enable, |
| 1184 | .set_suspend_disable = wm8350_dcdc_set_suspend_disable, |
| 1185 | .set_suspend_mode = wm8350_dcdc_set_suspend_mode, |
| 1186 | }; |
| 1187 | |
| 1188 | static struct regulator_ops wm8350_dcdc2_5_ops = { |
| 1189 | .enable = wm8350_dcdc_enable, |
| 1190 | .disable = wm8350_dcdc_disable, |
| 1191 | .is_enabled = wm8350_dcdc_is_enabled, |
| 1192 | .set_suspend_enable = wm8350_dcdc25_set_suspend_enable, |
| 1193 | .set_suspend_disable = wm8350_dcdc25_set_suspend_disable, |
| 1194 | }; |
| 1195 | |
| 1196 | static struct regulator_ops wm8350_ldo_ops = { |
| 1197 | .set_voltage = wm8350_ldo_set_voltage, |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1198 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 1199 | .list_voltage = wm8350_ldo_list_voltage, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1200 | .enable = wm8350_ldo_enable, |
| 1201 | .disable = wm8350_ldo_disable, |
| 1202 | .is_enabled = wm8350_ldo_is_enabled, |
| 1203 | .get_mode = wm8350_ldo_get_mode, |
| 1204 | .set_suspend_voltage = wm8350_ldo_set_suspend_voltage, |
| 1205 | .set_suspend_enable = wm8350_ldo_set_suspend_enable, |
| 1206 | .set_suspend_disable = wm8350_ldo_set_suspend_disable, |
| 1207 | }; |
| 1208 | |
| 1209 | static struct regulator_ops wm8350_isink_ops = { |
| 1210 | .set_current_limit = wm8350_isink_set_current, |
| 1211 | .get_current_limit = wm8350_isink_get_current, |
| 1212 | .enable = wm8350_isink_enable, |
| 1213 | .disable = wm8350_isink_disable, |
| 1214 | .is_enabled = wm8350_isink_is_enabled, |
Mark Brown | 75c8ac2 | 2010-01-04 17:24:01 +0000 | [diff] [blame] | 1215 | .enable_time = wm8350_isink_enable_time, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1216 | }; |
| 1217 | |
Mark Brown | 47924b6 | 2012-04-03 20:47:15 +0100 | [diff] [blame] | 1218 | static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1219 | { |
| 1220 | .name = "DCDC1", |
| 1221 | .id = WM8350_DCDC_1, |
| 1222 | .ops = &wm8350_dcdc_ops, |
| 1223 | .irq = WM8350_IRQ_UV_DC1, |
| 1224 | .type = REGULATOR_VOLTAGE, |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 1225 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1226 | .vsel_reg = WM8350_DCDC1_CONTROL, |
| 1227 | .vsel_mask = WM8350_DC1_VSEL_MASK, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1228 | .owner = THIS_MODULE, |
| 1229 | }, |
| 1230 | { |
| 1231 | .name = "DCDC2", |
| 1232 | .id = WM8350_DCDC_2, |
| 1233 | .ops = &wm8350_dcdc2_5_ops, |
| 1234 | .irq = WM8350_IRQ_UV_DC2, |
| 1235 | .type = REGULATOR_VOLTAGE, |
| 1236 | .owner = THIS_MODULE, |
| 1237 | }, |
| 1238 | { |
| 1239 | .name = "DCDC3", |
| 1240 | .id = WM8350_DCDC_3, |
| 1241 | .ops = &wm8350_dcdc_ops, |
| 1242 | .irq = WM8350_IRQ_UV_DC3, |
| 1243 | .type = REGULATOR_VOLTAGE, |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 1244 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1245 | .vsel_reg = WM8350_DCDC3_CONTROL, |
| 1246 | .vsel_mask = WM8350_DC3_VSEL_MASK, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1247 | .owner = THIS_MODULE, |
| 1248 | }, |
| 1249 | { |
| 1250 | .name = "DCDC4", |
| 1251 | .id = WM8350_DCDC_4, |
| 1252 | .ops = &wm8350_dcdc_ops, |
| 1253 | .irq = WM8350_IRQ_UV_DC4, |
| 1254 | .type = REGULATOR_VOLTAGE, |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 1255 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1256 | .vsel_reg = WM8350_DCDC4_CONTROL, |
| 1257 | .vsel_mask = WM8350_DC4_VSEL_MASK, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1258 | .owner = THIS_MODULE, |
| 1259 | }, |
| 1260 | { |
| 1261 | .name = "DCDC5", |
| 1262 | .id = WM8350_DCDC_5, |
| 1263 | .ops = &wm8350_dcdc2_5_ops, |
| 1264 | .irq = WM8350_IRQ_UV_DC5, |
| 1265 | .type = REGULATOR_VOLTAGE, |
| 1266 | .owner = THIS_MODULE, |
| 1267 | }, |
| 1268 | { |
| 1269 | .name = "DCDC6", |
| 1270 | .id = WM8350_DCDC_6, |
| 1271 | .ops = &wm8350_dcdc_ops, |
| 1272 | .irq = WM8350_IRQ_UV_DC6, |
| 1273 | .type = REGULATOR_VOLTAGE, |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 1274 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1275 | .vsel_reg = WM8350_DCDC6_CONTROL, |
| 1276 | .vsel_mask = WM8350_DC6_VSEL_MASK, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1277 | .owner = THIS_MODULE, |
| 1278 | }, |
| 1279 | { |
| 1280 | .name = "LDO1", |
| 1281 | .id = WM8350_LDO_1, |
| 1282 | .ops = &wm8350_ldo_ops, |
| 1283 | .irq = WM8350_IRQ_UV_LDO1, |
| 1284 | .type = REGULATOR_VOLTAGE, |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 1285 | .n_voltages = WM8350_LDO1_VSEL_MASK + 1, |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1286 | .vsel_reg = WM8350_LDO1_CONTROL, |
| 1287 | .vsel_mask = WM8350_LDO1_VSEL_MASK, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1288 | .owner = THIS_MODULE, |
| 1289 | }, |
| 1290 | { |
| 1291 | .name = "LDO2", |
| 1292 | .id = WM8350_LDO_2, |
| 1293 | .ops = &wm8350_ldo_ops, |
| 1294 | .irq = WM8350_IRQ_UV_LDO2, |
| 1295 | .type = REGULATOR_VOLTAGE, |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 1296 | .n_voltages = WM8350_LDO2_VSEL_MASK + 1, |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1297 | .vsel_reg = WM8350_LDO2_CONTROL, |
| 1298 | .vsel_mask = WM8350_LDO2_VSEL_MASK, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1299 | .owner = THIS_MODULE, |
| 1300 | }, |
| 1301 | { |
| 1302 | .name = "LDO3", |
| 1303 | .id = WM8350_LDO_3, |
| 1304 | .ops = &wm8350_ldo_ops, |
| 1305 | .irq = WM8350_IRQ_UV_LDO3, |
| 1306 | .type = REGULATOR_VOLTAGE, |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 1307 | .n_voltages = WM8350_LDO3_VSEL_MASK + 1, |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1308 | .vsel_reg = WM8350_LDO3_CONTROL, |
| 1309 | .vsel_mask = WM8350_LDO3_VSEL_MASK, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1310 | .owner = THIS_MODULE, |
| 1311 | }, |
| 1312 | { |
| 1313 | .name = "LDO4", |
| 1314 | .id = WM8350_LDO_4, |
| 1315 | .ops = &wm8350_ldo_ops, |
| 1316 | .irq = WM8350_IRQ_UV_LDO4, |
| 1317 | .type = REGULATOR_VOLTAGE, |
Mark Brown | 221a7c7 | 2009-03-02 16:32:47 +0000 | [diff] [blame] | 1318 | .n_voltages = WM8350_LDO4_VSEL_MASK + 1, |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1319 | .vsel_reg = WM8350_LDO4_CONTROL, |
| 1320 | .vsel_mask = WM8350_LDO4_VSEL_MASK, |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1321 | .owner = THIS_MODULE, |
| 1322 | }, |
| 1323 | { |
| 1324 | .name = "ISINKA", |
| 1325 | .id = WM8350_ISINK_A, |
| 1326 | .ops = &wm8350_isink_ops, |
| 1327 | .irq = WM8350_IRQ_CS1, |
| 1328 | .type = REGULATOR_CURRENT, |
| 1329 | .owner = THIS_MODULE, |
| 1330 | }, |
| 1331 | { |
| 1332 | .name = "ISINKB", |
| 1333 | .id = WM8350_ISINK_B, |
| 1334 | .ops = &wm8350_isink_ops, |
| 1335 | .irq = WM8350_IRQ_CS2, |
| 1336 | .type = REGULATOR_CURRENT, |
| 1337 | .owner = THIS_MODULE, |
| 1338 | }, |
| 1339 | }; |
| 1340 | |
Mark Brown | 5a65edb | 2009-11-04 16:10:51 +0000 | [diff] [blame] | 1341 | static irqreturn_t pmic_uv_handler(int irq, void *data) |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1342 | { |
| 1343 | struct regulator_dev *rdev = (struct regulator_dev *)data; |
Mark Brown | 5a65edb | 2009-11-04 16:10:51 +0000 | [diff] [blame] | 1344 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1345 | |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 1346 | mutex_lock(&rdev->mutex); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1347 | if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2) |
| 1348 | regulator_notifier_call_chain(rdev, |
| 1349 | REGULATOR_EVENT_REGULATION_OUT, |
| 1350 | wm8350); |
| 1351 | else |
| 1352 | regulator_notifier_call_chain(rdev, |
| 1353 | REGULATOR_EVENT_UNDER_VOLTAGE, |
| 1354 | wm8350); |
Jonathan Cameron | b136fb4 | 2009-01-19 18:20:58 +0000 | [diff] [blame] | 1355 | mutex_unlock(&rdev->mutex); |
Mark Brown | 5a65edb | 2009-11-04 16:10:51 +0000 | [diff] [blame] | 1356 | |
| 1357 | return IRQ_HANDLED; |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | static int wm8350_regulator_probe(struct platform_device *pdev) |
| 1361 | { |
| 1362 | struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev); |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1363 | struct regulator_config config = { }; |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1364 | struct regulator_dev *rdev; |
| 1365 | int ret; |
| 1366 | u16 val; |
| 1367 | |
| 1368 | if (pdev->id < WM8350_DCDC_1 || pdev->id > WM8350_ISINK_B) |
| 1369 | return -ENODEV; |
| 1370 | |
| 1371 | /* do any regulatior specific init */ |
| 1372 | switch (pdev->id) { |
| 1373 | case WM8350_DCDC_1: |
| 1374 | val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER); |
| 1375 | wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; |
| 1376 | break; |
| 1377 | case WM8350_DCDC_3: |
| 1378 | val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER); |
| 1379 | wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; |
| 1380 | break; |
| 1381 | case WM8350_DCDC_4: |
| 1382 | val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER); |
| 1383 | wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; |
| 1384 | break; |
| 1385 | case WM8350_DCDC_6: |
| 1386 | val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER); |
| 1387 | wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK; |
| 1388 | break; |
| 1389 | } |
| 1390 | |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1391 | config.dev = &pdev->dev; |
| 1392 | config.init_data = pdev->dev.platform_data; |
| 1393 | config.driver_data = dev_get_drvdata(&pdev->dev); |
Mark Brown | b4ec87a | 2012-04-30 21:00:10 +0100 | [diff] [blame^] | 1394 | config.regmap = wm8350->regmap; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1395 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1396 | /* register regulator */ |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1397 | rdev = regulator_register(&wm8350_reg[pdev->id], &config); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1398 | if (IS_ERR(rdev)) { |
| 1399 | dev_err(&pdev->dev, "failed to register %s\n", |
| 1400 | wm8350_reg[pdev->id].name); |
| 1401 | return PTR_ERR(rdev); |
| 1402 | } |
| 1403 | |
| 1404 | /* register regulator IRQ */ |
| 1405 | ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq, |
Mark Brown | 5a65edb | 2009-11-04 16:10:51 +0000 | [diff] [blame] | 1406 | pmic_uv_handler, 0, "UV", rdev); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1407 | if (ret < 0) { |
| 1408 | regulator_unregister(rdev); |
| 1409 | dev_err(&pdev->dev, "failed to register regulator %s IRQ\n", |
| 1410 | wm8350_reg[pdev->id].name); |
| 1411 | return ret; |
| 1412 | } |
| 1413 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1414 | return 0; |
| 1415 | } |
| 1416 | |
| 1417 | static int wm8350_regulator_remove(struct platform_device *pdev) |
| 1418 | { |
| 1419 | struct regulator_dev *rdev = platform_get_drvdata(pdev); |
| 1420 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
| 1421 | |
Mark Brown | f99344f | 2010-01-05 13:59:07 +0000 | [diff] [blame] | 1422 | wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq, rdev); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1423 | |
| 1424 | regulator_unregister(rdev); |
| 1425 | |
| 1426 | return 0; |
| 1427 | } |
| 1428 | |
| 1429 | int wm8350_register_regulator(struct wm8350 *wm8350, int reg, |
| 1430 | struct regulator_init_data *initdata) |
| 1431 | { |
| 1432 | struct platform_device *pdev; |
| 1433 | int ret; |
Roel Kluin | 4dee4d4 | 2009-06-15 22:30:39 +0200 | [diff] [blame] | 1434 | if (reg < 0 || reg >= NUM_WM8350_REGULATORS) |
| 1435 | return -EINVAL; |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1436 | |
| 1437 | if (wm8350->pmic.pdev[reg]) |
| 1438 | return -EBUSY; |
| 1439 | |
Mark Brown | 645524a | 2008-12-18 23:12:16 +0100 | [diff] [blame] | 1440 | if (reg >= WM8350_DCDC_1 && reg <= WM8350_DCDC_6 && |
| 1441 | reg > wm8350->pmic.max_dcdc) |
| 1442 | return -ENODEV; |
| 1443 | if (reg >= WM8350_ISINK_A && reg <= WM8350_ISINK_B && |
| 1444 | reg > wm8350->pmic.max_isink) |
| 1445 | return -ENODEV; |
| 1446 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1447 | pdev = platform_device_alloc("wm8350-regulator", reg); |
| 1448 | if (!pdev) |
| 1449 | return -ENOMEM; |
| 1450 | |
| 1451 | wm8350->pmic.pdev[reg] = pdev; |
| 1452 | |
| 1453 | initdata->driver_data = wm8350; |
| 1454 | |
| 1455 | pdev->dev.platform_data = initdata; |
| 1456 | pdev->dev.parent = wm8350->dev; |
| 1457 | platform_set_drvdata(pdev, wm8350); |
| 1458 | |
| 1459 | ret = platform_device_add(pdev); |
| 1460 | |
| 1461 | if (ret != 0) { |
| 1462 | dev_err(wm8350->dev, "Failed to register regulator %d: %d\n", |
| 1463 | reg, ret); |
Axel Lin | e9a1c51 | 2010-07-26 10:41:58 +0800 | [diff] [blame] | 1464 | platform_device_put(pdev); |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1465 | wm8350->pmic.pdev[reg] = NULL; |
| 1466 | } |
| 1467 | |
| 1468 | return ret; |
| 1469 | } |
| 1470 | EXPORT_SYMBOL_GPL(wm8350_register_regulator); |
| 1471 | |
Mark Brown | 0081e80 | 2008-12-04 16:52:33 +0000 | [diff] [blame] | 1472 | /** |
| 1473 | * wm8350_register_led - Register a WM8350 LED output |
| 1474 | * |
| 1475 | * @param wm8350 The WM8350 device to configure. |
| 1476 | * @param lednum LED device index to create. |
| 1477 | * @param dcdc The DCDC to use for the LED. |
| 1478 | * @param isink The ISINK to use for the LED. |
| 1479 | * @param pdata Configuration for the LED. |
| 1480 | * |
| 1481 | * The WM8350 supports the use of an ISINK together with a DCDC to |
| 1482 | * provide a power-efficient LED driver. This function registers the |
| 1483 | * regulators and instantiates the platform device for a LED. The |
| 1484 | * operating modes for the LED regulators must be configured using |
| 1485 | * wm8350_isink_set_flash(), wm8350_dcdc25_set_mode() and |
| 1486 | * wm8350_dcdc_set_slot() prior to calling this function. |
| 1487 | */ |
| 1488 | int wm8350_register_led(struct wm8350 *wm8350, int lednum, int dcdc, int isink, |
| 1489 | struct wm8350_led_platform_data *pdata) |
| 1490 | { |
| 1491 | struct wm8350_led *led; |
| 1492 | struct platform_device *pdev; |
| 1493 | int ret; |
| 1494 | |
Roel Kluin | 8dd2c9e | 2009-01-17 16:06:40 +0100 | [diff] [blame] | 1495 | if (lednum >= ARRAY_SIZE(wm8350->pmic.led) || lednum < 0) { |
Mark Brown | 0081e80 | 2008-12-04 16:52:33 +0000 | [diff] [blame] | 1496 | dev_err(wm8350->dev, "Invalid LED index %d\n", lednum); |
| 1497 | return -ENODEV; |
| 1498 | } |
| 1499 | |
| 1500 | led = &wm8350->pmic.led[lednum]; |
| 1501 | |
| 1502 | if (led->pdev) { |
| 1503 | dev_err(wm8350->dev, "LED %d already allocated\n", lednum); |
| 1504 | return -EINVAL; |
| 1505 | } |
| 1506 | |
| 1507 | pdev = platform_device_alloc("wm8350-led", lednum); |
| 1508 | if (pdev == NULL) { |
| 1509 | dev_err(wm8350->dev, "Failed to allocate LED %d\n", lednum); |
| 1510 | return -ENOMEM; |
| 1511 | } |
| 1512 | |
Mark Brown | 34ce8d0 | 2012-02-02 13:45:09 +0000 | [diff] [blame] | 1513 | led->isink_consumer.dev_name = dev_name(&pdev->dev); |
Mark Brown | 0081e80 | 2008-12-04 16:52:33 +0000 | [diff] [blame] | 1514 | led->isink_consumer.supply = "led_isink"; |
| 1515 | led->isink_init.num_consumer_supplies = 1; |
| 1516 | led->isink_init.consumer_supplies = &led->isink_consumer; |
| 1517 | led->isink_init.constraints.min_uA = 0; |
| 1518 | led->isink_init.constraints.max_uA = pdata->max_uA; |
Mark Brown | a2fad9b | 2010-01-04 15:30:54 +0000 | [diff] [blame] | 1519 | led->isink_init.constraints.valid_ops_mask |
| 1520 | = REGULATOR_CHANGE_CURRENT | REGULATOR_CHANGE_STATUS; |
Mark Brown | 0081e80 | 2008-12-04 16:52:33 +0000 | [diff] [blame] | 1521 | led->isink_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL; |
| 1522 | ret = wm8350_register_regulator(wm8350, isink, &led->isink_init); |
| 1523 | if (ret != 0) { |
| 1524 | platform_device_put(pdev); |
| 1525 | return ret; |
| 1526 | } |
| 1527 | |
Mark Brown | 34ce8d0 | 2012-02-02 13:45:09 +0000 | [diff] [blame] | 1528 | led->dcdc_consumer.dev_name = dev_name(&pdev->dev); |
Mark Brown | 0081e80 | 2008-12-04 16:52:33 +0000 | [diff] [blame] | 1529 | led->dcdc_consumer.supply = "led_vcc"; |
| 1530 | led->dcdc_init.num_consumer_supplies = 1; |
| 1531 | led->dcdc_init.consumer_supplies = &led->dcdc_consumer; |
| 1532 | led->dcdc_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL; |
Mark Brown | a2fad9b | 2010-01-04 15:30:54 +0000 | [diff] [blame] | 1533 | led->dcdc_init.constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS; |
Mark Brown | 0081e80 | 2008-12-04 16:52:33 +0000 | [diff] [blame] | 1534 | ret = wm8350_register_regulator(wm8350, dcdc, &led->dcdc_init); |
| 1535 | if (ret != 0) { |
| 1536 | platform_device_put(pdev); |
| 1537 | return ret; |
| 1538 | } |
| 1539 | |
| 1540 | switch (isink) { |
| 1541 | case WM8350_ISINK_A: |
| 1542 | wm8350->pmic.isink_A_dcdc = dcdc; |
| 1543 | break; |
| 1544 | case WM8350_ISINK_B: |
| 1545 | wm8350->pmic.isink_B_dcdc = dcdc; |
| 1546 | break; |
| 1547 | } |
| 1548 | |
| 1549 | pdev->dev.platform_data = pdata; |
| 1550 | pdev->dev.parent = wm8350->dev; |
| 1551 | ret = platform_device_add(pdev); |
| 1552 | if (ret != 0) { |
| 1553 | dev_err(wm8350->dev, "Failed to register LED %d: %d\n", |
| 1554 | lednum, ret); |
| 1555 | platform_device_put(pdev); |
| 1556 | return ret; |
| 1557 | } |
| 1558 | |
| 1559 | led->pdev = pdev; |
| 1560 | |
| 1561 | return 0; |
| 1562 | } |
| 1563 | EXPORT_SYMBOL_GPL(wm8350_register_led); |
| 1564 | |
Mark Brown | da09155 | 2008-10-10 15:58:15 +0100 | [diff] [blame] | 1565 | static struct platform_driver wm8350_regulator_driver = { |
| 1566 | .probe = wm8350_regulator_probe, |
| 1567 | .remove = wm8350_regulator_remove, |
| 1568 | .driver = { |
| 1569 | .name = "wm8350-regulator", |
| 1570 | }, |
| 1571 | }; |
| 1572 | |
| 1573 | static int __init wm8350_regulator_init(void) |
| 1574 | { |
| 1575 | return platform_driver_register(&wm8350_regulator_driver); |
| 1576 | } |
| 1577 | subsys_initcall(wm8350_regulator_init); |
| 1578 | |
| 1579 | static void __exit wm8350_regulator_exit(void) |
| 1580 | { |
| 1581 | platform_driver_unregister(&wm8350_regulator_driver); |
| 1582 | } |
| 1583 | module_exit(wm8350_regulator_exit); |
| 1584 | |
| 1585 | /* Module information */ |
| 1586 | MODULE_AUTHOR("Liam Girdwood"); |
| 1587 | MODULE_DESCRIPTION("WM8350 voltage and current regulator driver"); |
| 1588 | MODULE_LICENSE("GPL"); |
Mark Brown | 38c53c8 | 2009-04-28 11:13:55 +0100 | [diff] [blame] | 1589 | MODULE_ALIAS("platform:wm8350-regulator"); |