Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6: (27 commits)
regulator: wm831x_reg_read() failure unnoticed in wm831x_aldo_get_mode()
twl-regulator: Fix reg_disable functionality for 4030 and 6030
twl-regulator: Add turnon delay to reg_enable
twl-regulator: Restore REMAP configuration in regulator probe
twl-regulator: Add turnon-delay and REMAP config to twlreg_info struct
twl-regulator: Define critical regulators as always_on
twl-regulator: Add all twl4030 regulators to twlreg_info
regulator: mc13783-regulator: correct the probing time.
regulator: Fix unbalanced disables/enables in regulator_bulk_{enable,disable} error path
regulator: core.c: Small coding style cleanup (indentation fixup)
drivers/regulator: use PTR_ERR to get error code
regulator: consumer.h - fix build when consumer.h is #included first.
regulator/mc13783: various cleanups
regulator/mc13783: rename source file to match other drivers
Fix some AB3100 regulator issues
regulator: keep index within bounds in da9034_get_ldo12_voltage()
regulator: Ensure val is initialised in 88pm8607 choose_voltage()
regulator: Remove duplicate consts from ab3100
regulator: Handle regulators without suspend mode configuration
regulator: Factor out regulator name pretty printing
...

+1982 -612
+685
drivers/regulator/88pm8607.c
··· 1 + /* 2 + * Regulators driver for Marvell 88PM8607 3 + * 4 + * Copyright (C) 2009 Marvell International Ltd. 5 + * Haojian Zhuang <haojian.zhuang@marvell.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 version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + #include <linux/kernel.h> 12 + #include <linux/init.h> 13 + #include <linux/err.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/regulator/driver.h> 16 + #include <linux/regulator/machine.h> 17 + #include <linux/mfd/88pm8607.h> 18 + 19 + struct pm8607_regulator_info { 20 + struct regulator_desc desc; 21 + struct pm8607_chip *chip; 22 + struct regulator_dev *regulator; 23 + 24 + int min_uV; 25 + int max_uV; 26 + int step_uV; 27 + int vol_reg; 28 + int vol_shift; 29 + int vol_nbits; 30 + int update_reg; 31 + int update_bit; 32 + int enable_reg; 33 + int enable_bit; 34 + int slope_double; 35 + }; 36 + 37 + static inline int check_range(struct pm8607_regulator_info *info, 38 + int min_uV, int max_uV) 39 + { 40 + if (max_uV < info->min_uV || min_uV > info->max_uV || min_uV > max_uV) 41 + return -EINVAL; 42 + 43 + return 0; 44 + } 45 + 46 + static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index) 47 + { 48 + struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 49 + uint8_t chip_id = info->chip->chip_id; 50 + int ret = -EINVAL; 51 + 52 + switch (info->desc.id) { 53 + case PM8607_ID_BUCK1: 54 + ret = (index < 0x1d) ? (index * 25000 + 800000) : 55 + ((index < 0x20) ? 1500000 : 56 + ((index < 0x40) ? ((index - 0x20) * 25000) : 57 + -EINVAL)); 58 + break; 59 + case PM8607_ID_BUCK3: 60 + ret = (index < 0x3d) ? (index * 25000) : 61 + ((index < 0x40) ? 1500000 : -EINVAL); 62 + if (ret < 0) 63 + break; 64 + if (info->slope_double) 65 + ret <<= 1; 66 + break; 67 + case PM8607_ID_LDO1: 68 + ret = (index == 0) ? 1800000 : 69 + ((index == 1) ? 1200000 : 70 + ((index == 2) ? 2800000 : -EINVAL)); 71 + break; 72 + case PM8607_ID_LDO5: 73 + ret = (index == 0) ? 2900000 : 74 + ((index == 1) ? 3000000 : 75 + ((index == 2) ? 3100000 : 3300000)); 76 + break; 77 + case PM8607_ID_LDO7: 78 + case PM8607_ID_LDO8: 79 + ret = (index < 3) ? (index * 50000 + 1800000) : 80 + ((index < 8) ? (index * 50000 + 2550000) : 81 + -EINVAL); 82 + break; 83 + case PM8607_ID_LDO12: 84 + ret = (index < 2) ? (index * 100000 + 1800000) : 85 + ((index < 7) ? (index * 100000 + 2500000) : 86 + ((index == 7) ? 3300000 : 1200000)); 87 + break; 88 + case PM8607_ID_LDO2: 89 + case PM8607_ID_LDO3: 90 + case PM8607_ID_LDO9: 91 + switch (chip_id) { 92 + case PM8607_CHIP_A0: 93 + case PM8607_CHIP_A1: 94 + ret = (index < 3) ? (index * 50000 + 1800000) : 95 + ((index < 8) ? (index * 50000 + 2550000) : 96 + -EINVAL); 97 + break; 98 + case PM8607_CHIP_B0: 99 + ret = (index < 3) ? (index * 50000 + 1800000) : 100 + ((index < 7) ? (index * 50000 + 2550000) : 101 + 3300000); 102 + break; 103 + } 104 + break; 105 + case PM8607_ID_LDO4: 106 + switch (chip_id) { 107 + case PM8607_CHIP_A0: 108 + case PM8607_CHIP_A1: 109 + ret = (index < 3) ? (index * 50000 + 1800000) : 110 + ((index < 8) ? (index * 50000 + 2550000) : 111 + -EINVAL); 112 + break; 113 + case PM8607_CHIP_B0: 114 + ret = (index < 3) ? (index * 50000 + 1800000) : 115 + ((index < 6) ? (index * 50000 + 2550000) : 116 + ((index == 6) ? 2900000 : 3300000)); 117 + break; 118 + } 119 + break; 120 + case PM8607_ID_LDO6: 121 + switch (chip_id) { 122 + case PM8607_CHIP_A0: 123 + case PM8607_CHIP_A1: 124 + ret = (index < 3) ? (index * 50000 + 1800000) : 125 + ((index < 8) ? (index * 50000 + 2450000) : 126 + -EINVAL); 127 + break; 128 + case PM8607_CHIP_B0: 129 + ret = (index < 2) ? (index * 50000 + 1800000) : 130 + ((index < 7) ? (index * 50000 + 2500000) : 131 + 3300000); 132 + break; 133 + } 134 + break; 135 + case PM8607_ID_LDO10: 136 + switch (chip_id) { 137 + case PM8607_CHIP_A0: 138 + case PM8607_CHIP_A1: 139 + ret = (index < 3) ? (index * 50000 + 1800000) : 140 + ((index < 8) ? (index * 50000 + 2550000) : 141 + 1200000); 142 + break; 143 + case PM8607_CHIP_B0: 144 + ret = (index < 3) ? (index * 50000 + 1800000) : 145 + ((index < 7) ? (index * 50000 + 2550000) : 146 + ((index == 7) ? 3300000 : 1200000)); 147 + break; 148 + } 149 + break; 150 + case PM8607_ID_LDO14: 151 + switch (chip_id) { 152 + case PM8607_CHIP_A0: 153 + case PM8607_CHIP_A1: 154 + ret = (index < 3) ? (index * 50000 + 1800000) : 155 + ((index < 8) ? (index * 50000 + 2550000) : 156 + -EINVAL); 157 + break; 158 + case PM8607_CHIP_B0: 159 + ret = (index < 2) ? (index * 50000 + 1800000) : 160 + ((index < 7) ? (index * 50000 + 2600000) : 161 + 3300000); 162 + break; 163 + } 164 + break; 165 + } 166 + return ret; 167 + } 168 + 169 + static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) 170 + { 171 + struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 172 + uint8_t chip_id = info->chip->chip_id; 173 + int val = -ENOENT; 174 + int ret; 175 + 176 + switch (info->desc.id) { 177 + case PM8607_ID_BUCK1: 178 + if (min_uV >= 800000) /* 800mV ~ 1500mV / 25mV */ 179 + val = (min_uV - 775001) / 25000; 180 + else { /* 25mV ~ 775mV / 25mV */ 181 + val = (min_uV + 249999) / 25000; 182 + val += 32; 183 + } 184 + break; 185 + case PM8607_ID_BUCK3: 186 + if (info->slope_double) 187 + min_uV = min_uV >> 1; 188 + val = (min_uV + 249999) / 25000; /* 0mV ~ 1500mV / 25mV */ 189 + 190 + break; 191 + case PM8607_ID_LDO1: 192 + if (min_uV > 1800000) 193 + val = 2; 194 + else if (min_uV > 1200000) 195 + val = 0; 196 + else 197 + val = 1; 198 + break; 199 + case PM8607_ID_LDO5: 200 + if (min_uV > 3100000) 201 + val = 3; 202 + else /* 2900mV ~ 3100mV / 100mV */ 203 + val = (min_uV - 2800001) / 100000; 204 + break; 205 + case PM8607_ID_LDO7: 206 + case PM8607_ID_LDO8: 207 + if (min_uV < 2700000) { /* 1800mV ~ 1900mV / 50mV */ 208 + if (min_uV <= 1800000) 209 + val = 0; /* 1800mv */ 210 + else if (min_uV <= 1900000) 211 + val = (min_uV - 1750001) / 50000; 212 + else 213 + val = 3; /* 2700mV */ 214 + } else { /* 2700mV ~ 2900mV / 50mV */ 215 + if (min_uV <= 2900000) { 216 + val = (min_uV - 2650001) / 50000; 217 + val += 3; 218 + } else 219 + val = -EINVAL; 220 + } 221 + break; 222 + case PM8607_ID_LDO10: 223 + if (min_uV > 2850000) 224 + val = 7; 225 + else if (min_uV <= 1200000) 226 + val = 8; 227 + else if (min_uV < 2700000) /* 1800mV ~ 1900mV / 50mV */ 228 + val = (min_uV - 1750001) / 50000; 229 + else { /* 2700mV ~ 2850mV / 50mV */ 230 + val = (min_uV - 2650001) / 50000; 231 + val += 3; 232 + } 233 + break; 234 + case PM8607_ID_LDO12: 235 + if (min_uV < 2700000) { /* 1800mV ~ 1900mV / 100mV */ 236 + if (min_uV <= 1200000) 237 + val = 8; /* 1200mV */ 238 + else if (min_uV <= 1800000) 239 + val = 0; /* 1800mV */ 240 + else if (min_uV <= 1900000) 241 + val = (min_uV - 1700001) / 100000; 242 + else 243 + val = 2; /* 2700mV */ 244 + } else { /* 2700mV ~ 3100mV / 100mV */ 245 + if (min_uV <= 3100000) { 246 + val = (min_uV - 2600001) / 100000; 247 + val += 2; 248 + } else if (min_uV <= 3300000) 249 + val = 7; 250 + else 251 + val = -EINVAL; 252 + } 253 + break; 254 + case PM8607_ID_LDO2: 255 + case PM8607_ID_LDO3: 256 + case PM8607_ID_LDO9: 257 + switch (chip_id) { 258 + case PM8607_CHIP_A0: 259 + case PM8607_CHIP_A1: 260 + if (min_uV < 2700000) /* 1800mV ~ 1900mV / 50mV */ 261 + if (min_uV <= 1800000) 262 + val = 0; 263 + else if (min_uV <= 1900000) 264 + val = (min_uV - 1750001) / 50000; 265 + else 266 + val = 3; /* 2700mV */ 267 + else { /* 2700mV ~ 2900mV / 50mV */ 268 + if (min_uV <= 2900000) { 269 + val = (min_uV - 2650001) / 50000; 270 + val += 3; 271 + } else 272 + val = -EINVAL; 273 + } 274 + break; 275 + case PM8607_CHIP_B0: 276 + if (min_uV < 2700000) { /* 1800mV ~ 1900mV / 50mV */ 277 + if (min_uV <= 1800000) 278 + val = 0; 279 + else if (min_uV <= 1900000) 280 + val = (min_uV - 1750001) / 50000; 281 + else 282 + val = 3; /* 2700mV */ 283 + } else { /* 2700mV ~ 2850mV / 50mV */ 284 + if (min_uV <= 2850000) { 285 + val = (min_uV - 2650001) / 50000; 286 + val += 3; 287 + } else if (min_uV <= 3300000) 288 + val = 7; 289 + else 290 + val = -EINVAL; 291 + } 292 + break; 293 + } 294 + break; 295 + case PM8607_ID_LDO4: 296 + switch (chip_id) { 297 + case PM8607_CHIP_A0: 298 + case PM8607_CHIP_A1: 299 + if (min_uV < 2700000) /* 1800mV ~ 1900mV / 50mV */ 300 + if (min_uV <= 1800000) 301 + val = 0; 302 + else if (min_uV <= 1900000) 303 + val = (min_uV - 1750001) / 50000; 304 + else 305 + val = 3; /* 2700mV */ 306 + else { /* 2700mV ~ 2900mV / 50mV */ 307 + if (min_uV <= 2900000) { 308 + val = (min_uV - 2650001) / 50000; 309 + val += 3; 310 + } else 311 + val = -EINVAL; 312 + } 313 + break; 314 + case PM8607_CHIP_B0: 315 + if (min_uV < 2700000) { /* 1800mV ~ 1900mV / 50mV */ 316 + if (min_uV <= 1800000) 317 + val = 0; 318 + else if (min_uV <= 1900000) 319 + val = (min_uV - 1750001) / 50000; 320 + else 321 + val = 3; /* 2700mV */ 322 + } else { /* 2700mV ~ 2800mV / 50mV */ 323 + if (min_uV <= 2850000) { 324 + val = (min_uV - 2650001) / 50000; 325 + val += 3; 326 + } else if (min_uV <= 2900000) 327 + val = 6; 328 + else if (min_uV <= 3300000) 329 + val = 7; 330 + else 331 + val = -EINVAL; 332 + } 333 + break; 334 + } 335 + break; 336 + case PM8607_ID_LDO6: 337 + switch (chip_id) { 338 + case PM8607_CHIP_A0: 339 + case PM8607_CHIP_A1: 340 + if (min_uV < 2600000) { /* 1800mV ~ 1900mV / 50mV */ 341 + if (min_uV <= 1800000) 342 + val = 0; 343 + else if (min_uV <= 1900000) 344 + val = (min_uV - 1750001) / 50000; 345 + else 346 + val = 3; /* 2600mV */ 347 + } else { /* 2600mV ~ 2800mV / 50mV */ 348 + if (min_uV <= 2800000) { 349 + val = (min_uV - 2550001) / 50000; 350 + val += 3; 351 + } else 352 + val = -EINVAL; 353 + } 354 + break; 355 + case PM8607_CHIP_B0: 356 + if (min_uV < 2600000) { /* 1800mV ~ 1850mV / 50mV */ 357 + if (min_uV <= 1800000) 358 + val = 0; 359 + else if (min_uV <= 1850000) 360 + val = (min_uV - 1750001) / 50000; 361 + else 362 + val = 2; /* 2600mV */ 363 + } else { /* 2600mV ~ 2800mV / 50mV */ 364 + if (min_uV <= 2800000) { 365 + val = (min_uV - 2550001) / 50000; 366 + val += 2; 367 + } else if (min_uV <= 3300000) 368 + val = 7; 369 + else 370 + val = -EINVAL; 371 + } 372 + break; 373 + } 374 + break; 375 + case PM8607_ID_LDO14: 376 + switch (chip_id) { 377 + case PM8607_CHIP_A0: 378 + case PM8607_CHIP_A1: 379 + if (min_uV < 2700000) { /* 1800mV ~ 1900mV / 50mV */ 380 + if (min_uV <= 1800000) 381 + val = 0; 382 + else if (min_uV <= 1900000) 383 + val = (min_uV - 1750001) / 50000; 384 + else 385 + val = 3; /* 2700mV */ 386 + } else { /* 2700mV ~ 2900mV / 50mV */ 387 + if (min_uV <= 2900000) { 388 + val = (min_uV - 2650001) / 50000; 389 + val += 3; 390 + } else 391 + val = -EINVAL; 392 + } 393 + break; 394 + case PM8607_CHIP_B0: 395 + if (min_uV < 2700000) { /* 1800mV ~ 1850mV / 50mV */ 396 + if (min_uV <= 1800000) 397 + val = 0; 398 + else if (min_uV <= 1850000) 399 + val = (min_uV - 1750001) / 50000; 400 + else 401 + val = 2; /* 2700mV */ 402 + } else { /* 2700mV ~ 2900mV / 50mV */ 403 + if (min_uV <= 2900000) { 404 + val = (min_uV - 2650001) / 50000; 405 + val += 2; 406 + } else if (min_uV <= 3300000) 407 + val = 7; 408 + else 409 + val = -EINVAL; 410 + } 411 + break; 412 + } 413 + break; 414 + } 415 + if (val >= 0) { 416 + ret = pm8607_list_voltage(rdev, val); 417 + if (ret > max_uV) { 418 + pr_err("exceed voltage range (%d %d) uV", 419 + min_uV, max_uV); 420 + return -EINVAL; 421 + } 422 + } else 423 + pr_err("invalid voltage range (%d %d) uV", min_uV, max_uV); 424 + return val; 425 + } 426 + 427 + static int pm8607_set_voltage(struct regulator_dev *rdev, 428 + int min_uV, int max_uV) 429 + { 430 + struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 431 + struct pm8607_chip *chip = info->chip; 432 + uint8_t val, mask; 433 + int ret; 434 + 435 + if (check_range(info, min_uV, max_uV)) { 436 + pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); 437 + return -EINVAL; 438 + } 439 + 440 + ret = choose_voltage(rdev, min_uV, max_uV); 441 + if (ret < 0) 442 + return -EINVAL; 443 + val = (uint8_t)(ret << info->vol_shift); 444 + mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 445 + 446 + ret = pm8607_set_bits(chip, info->vol_reg, mask, val); 447 + if (ret) 448 + return ret; 449 + switch (info->desc.id) { 450 + case PM8607_ID_BUCK1: 451 + case PM8607_ID_BUCK3: 452 + ret = pm8607_set_bits(chip, info->update_reg, 453 + 1 << info->update_bit, 454 + 1 << info->update_bit); 455 + break; 456 + } 457 + return ret; 458 + } 459 + 460 + static int pm8607_get_voltage(struct regulator_dev *rdev) 461 + { 462 + struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 463 + struct pm8607_chip *chip = info->chip; 464 + uint8_t val, mask; 465 + int ret; 466 + 467 + ret = pm8607_reg_read(chip, info->vol_reg); 468 + if (ret < 0) 469 + return ret; 470 + 471 + mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 472 + val = ((unsigned char)ret & mask) >> info->vol_shift; 473 + 474 + return pm8607_list_voltage(rdev, val); 475 + } 476 + 477 + static int pm8607_enable(struct regulator_dev *rdev) 478 + { 479 + struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 480 + struct pm8607_chip *chip = info->chip; 481 + 482 + return pm8607_set_bits(chip, info->enable_reg, 483 + 1 << info->enable_bit, 484 + 1 << info->enable_bit); 485 + } 486 + 487 + static int pm8607_disable(struct regulator_dev *rdev) 488 + { 489 + struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 490 + struct pm8607_chip *chip = info->chip; 491 + 492 + return pm8607_set_bits(chip, info->enable_reg, 493 + 1 << info->enable_bit, 0); 494 + } 495 + 496 + static int pm8607_is_enabled(struct regulator_dev *rdev) 497 + { 498 + struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 499 + struct pm8607_chip *chip = info->chip; 500 + int ret; 501 + 502 + ret = pm8607_reg_read(chip, info->enable_reg); 503 + if (ret < 0) 504 + return ret; 505 + 506 + return !!((unsigned char)ret & (1 << info->enable_bit)); 507 + } 508 + 509 + static struct regulator_ops pm8607_regulator_ops = { 510 + .set_voltage = pm8607_set_voltage, 511 + .get_voltage = pm8607_get_voltage, 512 + .enable = pm8607_enable, 513 + .disable = pm8607_disable, 514 + .is_enabled = pm8607_is_enabled, 515 + }; 516 + 517 + #define PM8607_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ 518 + { \ 519 + .desc = { \ 520 + .name = "BUCK" #_id, \ 521 + .ops = &pm8607_regulator_ops, \ 522 + .type = REGULATOR_VOLTAGE, \ 523 + .id = PM8607_ID_BUCK##_id, \ 524 + .owner = THIS_MODULE, \ 525 + }, \ 526 + .min_uV = (min) * 1000, \ 527 + .max_uV = (max) * 1000, \ 528 + .step_uV = (step) * 1000, \ 529 + .vol_reg = PM8607_##vreg, \ 530 + .vol_shift = (0), \ 531 + .vol_nbits = (nbits), \ 532 + .update_reg = PM8607_##ureg, \ 533 + .update_bit = (ubit), \ 534 + .enable_reg = PM8607_##ereg, \ 535 + .enable_bit = (ebit), \ 536 + .slope_double = (0), \ 537 + } 538 + 539 + #define PM8607_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \ 540 + { \ 541 + .desc = { \ 542 + .name = "LDO" #_id, \ 543 + .ops = &pm8607_regulator_ops, \ 544 + .type = REGULATOR_VOLTAGE, \ 545 + .id = PM8607_ID_LDO##_id, \ 546 + .owner = THIS_MODULE, \ 547 + }, \ 548 + .min_uV = (min) * 1000, \ 549 + .max_uV = (max) * 1000, \ 550 + .step_uV = (step) * 1000, \ 551 + .vol_reg = PM8607_##vreg, \ 552 + .vol_shift = (shift), \ 553 + .vol_nbits = (nbits), \ 554 + .enable_reg = PM8607_##ereg, \ 555 + .enable_bit = (ebit), \ 556 + .slope_double = (0), \ 557 + } 558 + 559 + static struct pm8607_regulator_info pm8607_regulator_info[] = { 560 + PM8607_DVC(1, 0, 1500, 25, BUCK1, 6, GO, 0, SUPPLIES_EN11, 0), 561 + PM8607_DVC(3, 0, 1500, 25, BUCK3, 6, GO, 2, SUPPLIES_EN11, 2), 562 + 563 + PM8607_LDO(1 , 1200, 2800, 0, LDO1 , 0, 2, SUPPLIES_EN11, 3), 564 + PM8607_LDO(2 , 1800, 3300, 0, LDO2 , 0, 3, SUPPLIES_EN11, 4), 565 + PM8607_LDO(3 , 1800, 3300, 0, LDO3 , 0, 3, SUPPLIES_EN11, 5), 566 + PM8607_LDO(4 , 1800, 3300, 0, LDO4 , 0, 3, SUPPLIES_EN11, 6), 567 + PM8607_LDO(5 , 2900, 3300, 0, LDO5 , 0, 2, SUPPLIES_EN11, 7), 568 + PM8607_LDO(6 , 1800, 3300, 0, LDO6 , 0, 3, SUPPLIES_EN12, 0), 569 + PM8607_LDO(7 , 1800, 2900, 0, LDO7 , 0, 3, SUPPLIES_EN12, 1), 570 + PM8607_LDO(8 , 1800, 2900, 0, LDO8 , 0, 3, SUPPLIES_EN12, 2), 571 + PM8607_LDO(9 , 1800, 3300, 0, LDO9 , 0, 3, SUPPLIES_EN12, 3), 572 + PM8607_LDO(10, 1200, 3300, 0, LDO10, 0, 4, SUPPLIES_EN11, 4), 573 + PM8607_LDO(12, 1200, 3300, 0, LDO12, 0, 4, SUPPLIES_EN11, 5), 574 + PM8607_LDO(14, 1800, 3300, 0, LDO14, 0, 3, SUPPLIES_EN11, 6), 575 + }; 576 + 577 + static inline struct pm8607_regulator_info *find_regulator_info(int id) 578 + { 579 + struct pm8607_regulator_info *info; 580 + int i; 581 + 582 + for (i = 0; i < ARRAY_SIZE(pm8607_regulator_info); i++) { 583 + info = &pm8607_regulator_info[i]; 584 + if (info->desc.id == id) 585 + return info; 586 + } 587 + return NULL; 588 + } 589 + 590 + static int __devinit pm8607_regulator_probe(struct platform_device *pdev) 591 + { 592 + struct pm8607_chip *chip = dev_get_drvdata(pdev->dev.parent); 593 + struct pm8607_platform_data *pdata = chip->dev->platform_data; 594 + struct pm8607_regulator_info *info = NULL; 595 + 596 + info = find_regulator_info(pdev->id); 597 + if (info == NULL) { 598 + dev_err(&pdev->dev, "invalid regulator ID specified\n"); 599 + return -EINVAL; 600 + } 601 + 602 + info->chip = chip; 603 + 604 + info->regulator = regulator_register(&info->desc, &pdev->dev, 605 + pdata->regulator[pdev->id], info); 606 + if (IS_ERR(info->regulator)) { 607 + dev_err(&pdev->dev, "failed to register regulator %s\n", 608 + info->desc.name); 609 + return PTR_ERR(info->regulator); 610 + } 611 + 612 + /* check DVC ramp slope double */ 613 + if (info->desc.id == PM8607_ID_BUCK3) 614 + if (info->chip->buck3_double) 615 + info->slope_double = 1; 616 + 617 + platform_set_drvdata(pdev, info); 618 + return 0; 619 + } 620 + 621 + static int __devexit pm8607_regulator_remove(struct platform_device *pdev) 622 + { 623 + struct pm8607_regulator_info *info = platform_get_drvdata(pdev); 624 + 625 + regulator_unregister(info->regulator); 626 + return 0; 627 + } 628 + 629 + #define PM8607_REGULATOR_DRIVER(_name) \ 630 + { \ 631 + .driver = { \ 632 + .name = "88pm8607-" #_name, \ 633 + .owner = THIS_MODULE, \ 634 + }, \ 635 + .probe = pm8607_regulator_probe, \ 636 + .remove = __devexit_p(pm8607_regulator_remove), \ 637 + } 638 + 639 + static struct platform_driver pm8607_regulator_driver[] = { 640 + PM8607_REGULATOR_DRIVER(buck1), 641 + PM8607_REGULATOR_DRIVER(buck2), 642 + PM8607_REGULATOR_DRIVER(buck3), 643 + PM8607_REGULATOR_DRIVER(ldo1), 644 + PM8607_REGULATOR_DRIVER(ldo2), 645 + PM8607_REGULATOR_DRIVER(ldo3), 646 + PM8607_REGULATOR_DRIVER(ldo4), 647 + PM8607_REGULATOR_DRIVER(ldo5), 648 + PM8607_REGULATOR_DRIVER(ldo6), 649 + PM8607_REGULATOR_DRIVER(ldo7), 650 + PM8607_REGULATOR_DRIVER(ldo8), 651 + PM8607_REGULATOR_DRIVER(ldo9), 652 + PM8607_REGULATOR_DRIVER(ldo10), 653 + PM8607_REGULATOR_DRIVER(ldo12), 654 + PM8607_REGULATOR_DRIVER(ldo14), 655 + }; 656 + 657 + static int __init pm8607_regulator_init(void) 658 + { 659 + int i, count, ret; 660 + 661 + count = ARRAY_SIZE(pm8607_regulator_driver); 662 + for (i = 0; i < count; i++) { 663 + ret = platform_driver_register(&pm8607_regulator_driver[i]); 664 + if (ret != 0) 665 + pr_err("Failed to register regulator driver: %d\n", 666 + ret); 667 + } 668 + return 0; 669 + } 670 + subsys_initcall(pm8607_regulator_init); 671 + 672 + static void __exit pm8607_regulator_exit(void) 673 + { 674 + int i, count; 675 + 676 + count = ARRAY_SIZE(pm8607_regulator_driver); 677 + for (i = 0; i < count; i++) 678 + platform_driver_unregister(&pm8607_regulator_driver[i]); 679 + } 680 + module_exit(pm8607_regulator_exit); 681 + 682 + MODULE_LICENSE("GPL"); 683 + MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); 684 + MODULE_DESCRIPTION("Regulator Driver for Marvell 88PM8607 PMIC"); 685 + MODULE_ALIAS("platform:88pm8607-regulator");
+13
drivers/regulator/Kconfig
··· 69 69 regulator via I2C bus. The provided regulator is suitable 70 70 for PXA27x chips to control VCC_CORE and VCC_USIM voltages. 71 71 72 + config REGULATOR_MAX8660 73 + tristate "Maxim 8660/8661 voltage regulator" 74 + depends on I2C 75 + help 76 + This driver controls a Maxim 8660/8661 voltage output 77 + regulator via I2C bus. 78 + 72 79 config REGULATOR_TWL4030 73 80 bool "TI TWL4030/TWL5030/TWL6030/TPS695x0 PMIC" 74 81 depends on TWL4030_CORE ··· 163 156 This driver supports TPS6507X voltage regulator chips. TPS6507X provides 164 157 three step-down converters and two general-purpose LDO voltage regulators. 165 158 It supports TI's software based Class-2 SmartReflex implementation. 159 + 160 + config REGULATOR_88PM8607 161 + bool "Marvell 88PM8607 Power regulators" 162 + depends on MFD_88PM8607=y 163 + help 164 + This driver supports 88PM8607 voltage regulator chips. 166 165 167 166 endif 168 167
+3 -1
drivers/regulator/Makefile
··· 12 12 obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o 13 13 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o 14 14 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o 15 + obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o 15 16 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o 16 17 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o 17 18 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o ··· 21 20 obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 22 21 obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 23 22 obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 24 - obj-$(CONFIG_REGULATOR_MC13783) += mc13783.o 23 + obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o 25 24 obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o 26 25 27 26 obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 28 27 obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 28 + obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o 29 29 30 30 ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
+7 -26
drivers/regulator/ab3100.c
··· 81 81 #define LDO_C_VOLTAGE 2650000 82 82 #define LDO_D_VOLTAGE 2650000 83 83 84 - static const int const ldo_e_buck_typ_voltages[] = { 84 + static const int ldo_e_buck_typ_voltages[] = { 85 85 1800000, 86 86 1400000, 87 87 1300000, ··· 91 91 900000, 92 92 }; 93 93 94 - static const int const ldo_f_typ_voltages[] = { 94 + static const int ldo_f_typ_voltages[] = { 95 95 1800000, 96 96 1400000, 97 97 1300000, ··· 102 102 2650000, 103 103 }; 104 104 105 - static const int const ldo_g_typ_voltages[] = { 105 + static const int ldo_g_typ_voltages[] = { 106 106 2850000, 107 107 2750000, 108 108 1800000, 109 109 1500000, 110 110 }; 111 111 112 - static const int const ldo_h_typ_voltages[] = { 112 + static const int ldo_h_typ_voltages[] = { 113 113 2750000, 114 114 1800000, 115 115 1500000, 116 116 1200000, 117 117 }; 118 118 119 - static const int const ldo_k_typ_voltages[] = { 119 + static const int ldo_k_typ_voltages[] = { 120 120 2750000, 121 121 1800000, 122 122 }; ··· 241 241 * LDO D is a special regulator. When it is disabled, the entire 242 242 * system is shut down. So this is handled specially. 243 243 */ 244 + pr_info("Called ab3100_disable_regulator\n"); 244 245 if (abreg->regreg == AB3100_LDO_D) { 245 - int i; 246 - 247 246 dev_info(&reg->dev, "disabling LDO D - shut down system\n"); 248 - /* 249 - * Set regulators to default values, ignore any errors, 250 - * we're going DOWN 251 - */ 252 - for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) { 253 - (void) ab3100_set_register_interruptible(abreg->ab3100, 254 - ab3100_reg_init_order[i], 255 - abreg->plfdata->reg_initvals[i]); 256 - } 257 - 258 247 /* Setting LDO D to 0x00 cuts the power to the SoC */ 259 248 return ab3100_set_register_interruptible(abreg->ab3100, 260 249 AB3100_LDO_D, 0x00U); 261 - 262 250 } 263 251 264 252 /* ··· 595 607 } 596 608 } 597 609 598 - if (err) { 599 - dev_err(&pdev->dev, 600 - "LDO D regulator initialization failed with error %d\n", 601 - err); 602 - return err; 603 - } 604 - 605 610 /* Register the regulators */ 606 611 for (i = 0; i < AB3100_NUM_REGULATORS; i++) { 607 612 struct ab3100_regulator *reg = &ab3100_regulators[i]; ··· 669 688 670 689 static __exit void ab3100_regulators_exit(void) 671 690 { 672 - platform_driver_register(&ab3100_regulators_driver); 691 + platform_driver_unregister(&ab3100_regulators_driver); 673 692 } 674 693 675 694 subsys_initcall(ab3100_regulators_init);
+147 -105
drivers/regulator/core.c
··· 66 66 static void _notifier_call_chain(struct regulator_dev *rdev, 67 67 unsigned long event, void *data); 68 68 69 + static const char *rdev_get_name(struct regulator_dev *rdev) 70 + { 71 + if (rdev->constraints && rdev->constraints->name) 72 + return rdev->constraints->name; 73 + else if (rdev->desc->name) 74 + return rdev->desc->name; 75 + else 76 + return ""; 77 + } 78 + 69 79 /* gets the regulator for a given consumer device */ 70 80 static struct regulator *get_device_regulator(struct device *dev) 71 81 { ··· 106 96 107 97 if (!rdev->constraints) { 108 98 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 109 - rdev->desc->name); 99 + rdev_get_name(rdev)); 110 100 return -ENODEV; 111 101 } 112 102 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { 113 103 printk(KERN_ERR "%s: operation not allowed for %s\n", 114 - __func__, rdev->desc->name); 104 + __func__, rdev_get_name(rdev)); 115 105 return -EPERM; 116 106 } 117 107 ··· 134 124 135 125 if (!rdev->constraints) { 136 126 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 137 - rdev->desc->name); 127 + rdev_get_name(rdev)); 138 128 return -ENODEV; 139 129 } 140 130 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { 141 131 printk(KERN_ERR "%s: operation not allowed for %s\n", 142 - __func__, rdev->desc->name); 132 + __func__, rdev_get_name(rdev)); 143 133 return -EPERM; 144 134 } 145 135 ··· 169 159 170 160 if (!rdev->constraints) { 171 161 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 172 - rdev->desc->name); 162 + rdev_get_name(rdev)); 173 163 return -ENODEV; 174 164 } 175 165 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { 176 166 printk(KERN_ERR "%s: operation not allowed for %s\n", 177 - __func__, rdev->desc->name); 167 + __func__, rdev_get_name(rdev)); 178 168 return -EPERM; 179 169 } 180 170 if (!(rdev->constraints->valid_modes_mask & mode)) { 181 171 printk(KERN_ERR "%s: invalid mode %x for %s\n", 182 - __func__, mode, rdev->desc->name); 172 + __func__, mode, rdev_get_name(rdev)); 183 173 return -EINVAL; 184 174 } 185 175 return 0; ··· 190 180 { 191 181 if (!rdev->constraints) { 192 182 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 193 - rdev->desc->name); 183 + rdev_get_name(rdev)); 194 184 return -ENODEV; 195 185 } 196 186 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { 197 187 printk(KERN_ERR "%s: operation not allowed for %s\n", 198 - __func__, rdev->desc->name); 188 + __func__, rdev_get_name(rdev)); 199 189 return -EPERM; 200 190 } 201 191 return 0; ··· 240 230 struct device_attribute *attr, char *buf) 241 231 { 242 232 struct regulator_dev *rdev = dev_get_drvdata(dev); 243 - const char *name; 244 233 245 - if (rdev->constraints && rdev->constraints->name) 246 - name = rdev->constraints->name; 247 - else if (rdev->desc->name) 248 - name = rdev->desc->name; 249 - else 250 - name = ""; 251 - 252 - return sprintf(buf, "%s\n", name); 234 + return sprintf(buf, "%s\n", rdev_get_name(rdev)); 253 235 } 254 236 255 237 static ssize_t regulator_print_opmode(char *buf, int mode) ··· 390 388 391 389 mutex_lock(&rdev->mutex); 392 390 list_for_each_entry(regulator, &rdev->consumer_list, list) 393 - uA += regulator->uA_load; 391 + uA += regulator->uA_load; 394 392 mutex_unlock(&rdev->mutex); 395 393 return sprintf(buf, "%d\n", uA); 396 394 } ··· 565 563 566 564 /* calc total requested load */ 567 565 list_for_each_entry(sibling, &rdev->consumer_list, list) 568 - current_uA += sibling->uA_load; 566 + current_uA += sibling->uA_load; 569 567 570 568 /* now get the optimum mode for our new total regulator load */ 571 569 mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV, ··· 581 579 struct regulator_state *rstate) 582 580 { 583 581 int ret = 0; 582 + bool can_set_state; 584 583 585 - /* enable & disable are mandatory for suspend control */ 586 - if (!rdev->desc->ops->set_suspend_enable || 587 - !rdev->desc->ops->set_suspend_disable) { 584 + can_set_state = rdev->desc->ops->set_suspend_enable && 585 + rdev->desc->ops->set_suspend_disable; 586 + 587 + /* If we have no suspend mode configration don't set anything; 588 + * only warn if the driver actually makes the suspend mode 589 + * configurable. 590 + */ 591 + if (!rstate->enabled && !rstate->disabled) { 592 + if (can_set_state) 593 + printk(KERN_WARNING "%s: No configuration for %s\n", 594 + __func__, rdev_get_name(rdev)); 595 + return 0; 596 + } 597 + 598 + if (rstate->enabled && rstate->disabled) { 599 + printk(KERN_ERR "%s: invalid configuration for %s\n", 600 + __func__, rdev_get_name(rdev)); 601 + return -EINVAL; 602 + } 603 + 604 + if (!can_set_state) { 588 605 printk(KERN_ERR "%s: no way to set suspend state\n", 589 606 __func__); 590 607 return -EINVAL; ··· 662 641 { 663 642 struct regulation_constraints *constraints = rdev->constraints; 664 643 char buf[80]; 665 - int count; 644 + int count = 0; 645 + int ret; 666 646 667 - if (rdev->desc->type == REGULATOR_VOLTAGE) { 647 + if (constraints->min_uV && constraints->max_uV) { 668 648 if (constraints->min_uV == constraints->max_uV) 669 - count = sprintf(buf, "%d mV ", 670 - constraints->min_uV / 1000); 649 + count += sprintf(buf + count, "%d mV ", 650 + constraints->min_uV / 1000); 671 651 else 672 - count = sprintf(buf, "%d <--> %d mV ", 673 - constraints->min_uV / 1000, 674 - constraints->max_uV / 1000); 675 - } else { 676 - if (constraints->min_uA == constraints->max_uA) 677 - count = sprintf(buf, "%d mA ", 678 - constraints->min_uA / 1000); 679 - else 680 - count = sprintf(buf, "%d <--> %d mA ", 681 - constraints->min_uA / 1000, 682 - constraints->max_uA / 1000); 652 + count += sprintf(buf + count, "%d <--> %d mV ", 653 + constraints->min_uV / 1000, 654 + constraints->max_uV / 1000); 683 655 } 656 + 657 + if (!constraints->min_uV || 658 + constraints->min_uV != constraints->max_uV) { 659 + ret = _regulator_get_voltage(rdev); 660 + if (ret > 0) 661 + count += sprintf(buf + count, "at %d mV ", ret / 1000); 662 + } 663 + 664 + if (constraints->min_uA && constraints->max_uA) { 665 + if (constraints->min_uA == constraints->max_uA) 666 + count += sprintf(buf + count, "%d mA ", 667 + constraints->min_uA / 1000); 668 + else 669 + count += sprintf(buf + count, "%d <--> %d mA ", 670 + constraints->min_uA / 1000, 671 + constraints->max_uA / 1000); 672 + } 673 + 674 + if (!constraints->min_uA || 675 + constraints->min_uA != constraints->max_uA) { 676 + ret = _regulator_get_current_limit(rdev); 677 + if (ret > 0) 678 + count += sprintf(buf + count, "at %d uA ", ret / 1000); 679 + } 680 + 684 681 if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) 685 682 count += sprintf(buf + count, "fast "); 686 683 if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL) ··· 708 669 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) 709 670 count += sprintf(buf + count, "standby"); 710 671 711 - printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); 672 + printk(KERN_INFO "regulator: %s: %s\n", rdev_get_name(rdev), buf); 712 673 } 713 674 714 - /** 715 - * set_machine_constraints - sets regulator constraints 716 - * @rdev: regulator source 717 - * @constraints: constraints to apply 718 - * 719 - * Allows platform initialisation code to define and constrain 720 - * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: 721 - * Constraints *must* be set by platform code in order for some 722 - * regulator operations to proceed i.e. set_voltage, set_current_limit, 723 - * set_mode. 724 - */ 725 - static int set_machine_constraints(struct regulator_dev *rdev, 675 + static int machine_constraints_voltage(struct regulator_dev *rdev, 726 676 struct regulation_constraints *constraints) 727 677 { 728 - int ret = 0; 729 - const char *name; 730 678 struct regulator_ops *ops = rdev->desc->ops; 679 + const char *name = rdev_get_name(rdev); 680 + int ret; 731 681 732 - if (constraints->name) 733 - name = constraints->name; 734 - else if (rdev->desc->name) 735 - name = rdev->desc->name; 736 - else 737 - name = "regulator"; 682 + /* do we need to apply the constraint voltage */ 683 + if (rdev->constraints->apply_uV && 684 + rdev->constraints->min_uV == rdev->constraints->max_uV && 685 + ops->set_voltage) { 686 + ret = ops->set_voltage(rdev, 687 + rdev->constraints->min_uV, rdev->constraints->max_uV); 688 + if (ret < 0) { 689 + printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n", 690 + __func__, 691 + rdev->constraints->min_uV, name); 692 + rdev->constraints = NULL; 693 + return ret; 694 + } 695 + } 738 696 739 697 /* constrain machine-level voltage specs to fit 740 698 * the actual range supported by this regulator. ··· 755 719 756 720 /* voltage constraints are optional */ 757 721 if ((cmin == 0) && (cmax == 0)) 758 - goto out; 722 + return 0; 759 723 760 724 /* else require explicit machine-level constraints */ 761 725 if (cmin <= 0 || cmax <= 0 || cmax < cmin) { 762 726 pr_err("%s: %s '%s' voltage constraints\n", 763 727 __func__, "invalid", name); 764 - ret = -EINVAL; 765 - goto out; 728 + return -EINVAL; 766 729 } 767 730 768 731 /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ ··· 783 748 if (max_uV < min_uV) { 784 749 pr_err("%s: %s '%s' voltage constraints\n", 785 750 __func__, "unsupportable", name); 786 - ret = -EINVAL; 787 - goto out; 751 + return -EINVAL; 788 752 } 789 753 790 754 /* use regulator's subset of machine constraints */ ··· 801 767 } 802 768 } 803 769 770 + return 0; 771 + } 772 + 773 + /** 774 + * set_machine_constraints - sets regulator constraints 775 + * @rdev: regulator source 776 + * @constraints: constraints to apply 777 + * 778 + * Allows platform initialisation code to define and constrain 779 + * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: 780 + * Constraints *must* be set by platform code in order for some 781 + * regulator operations to proceed i.e. set_voltage, set_current_limit, 782 + * set_mode. 783 + */ 784 + static int set_machine_constraints(struct regulator_dev *rdev, 785 + struct regulation_constraints *constraints) 786 + { 787 + int ret = 0; 788 + const char *name; 789 + struct regulator_ops *ops = rdev->desc->ops; 790 + 804 791 rdev->constraints = constraints; 805 792 806 - /* do we need to apply the constraint voltage */ 807 - if (rdev->constraints->apply_uV && 808 - rdev->constraints->min_uV == rdev->constraints->max_uV && 809 - ops->set_voltage) { 810 - ret = ops->set_voltage(rdev, 811 - rdev->constraints->min_uV, rdev->constraints->max_uV); 812 - if (ret < 0) { 813 - printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n", 814 - __func__, 815 - rdev->constraints->min_uV, name); 816 - rdev->constraints = NULL; 817 - goto out; 818 - } 819 - } 793 + name = rdev_get_name(rdev); 794 + 795 + ret = machine_constraints_voltage(rdev, constraints); 796 + if (ret != 0) 797 + goto out; 820 798 821 799 /* do we need to setup our suspend state */ 822 800 if (constraints->initial_state) { ··· 949 903 dev_name(&node->regulator->dev), 950 904 node->regulator->desc->name, 951 905 supply, 952 - dev_name(&rdev->dev), rdev->desc->name); 906 + dev_name(&rdev->dev), rdev_get_name(rdev)); 953 907 return -EBUSY; 954 908 } 955 909 ··· 1258 1212 ret = _regulator_enable(rdev->supply); 1259 1213 if (ret < 0) { 1260 1214 printk(KERN_ERR "%s: failed to enable %s: %d\n", 1261 - __func__, rdev->desc->name, ret); 1215 + __func__, rdev_get_name(rdev), ret); 1262 1216 return ret; 1263 1217 } 1264 1218 } ··· 1284 1238 } 1285 1239 } else if (ret < 0) { 1286 1240 printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", 1287 - __func__, rdev->desc->name, ret); 1241 + __func__, rdev_get_name(rdev), ret); 1288 1242 return ret; 1289 1243 } 1290 1244 /* Fallthrough on positive return values - already enabled */ ··· 1325 1279 1326 1280 if (WARN(rdev->use_count <= 0, 1327 1281 "unbalanced disables for %s\n", 1328 - rdev->desc->name)) 1282 + rdev_get_name(rdev))) 1329 1283 return -EIO; 1330 1284 1331 1285 /* are we the last user and permitted to disable ? */ ··· 1338 1292 ret = rdev->desc->ops->disable(rdev); 1339 1293 if (ret < 0) { 1340 1294 printk(KERN_ERR "%s: failed to disable %s\n", 1341 - __func__, rdev->desc->name); 1295 + __func__, rdev_get_name(rdev)); 1342 1296 return ret; 1343 1297 } 1344 1298 } ··· 1395 1349 ret = rdev->desc->ops->disable(rdev); 1396 1350 if (ret < 0) { 1397 1351 printk(KERN_ERR "%s: failed to force disable %s\n", 1398 - __func__, rdev->desc->name); 1352 + __func__, rdev_get_name(rdev)); 1399 1353 return ret; 1400 1354 } 1401 1355 /* notify other consumers that power has been forced off */ ··· 1812 1766 output_uV = rdev->desc->ops->get_voltage(rdev); 1813 1767 if (output_uV <= 0) { 1814 1768 printk(KERN_ERR "%s: invalid output voltage found for %s\n", 1815 - __func__, rdev->desc->name); 1769 + __func__, rdev_get_name(rdev)); 1816 1770 goto out; 1817 1771 } 1818 1772 ··· 1823 1777 input_uV = rdev->constraints->input_uV; 1824 1778 if (input_uV <= 0) { 1825 1779 printk(KERN_ERR "%s: invalid input voltage found for %s\n", 1826 - __func__, rdev->desc->name); 1780 + __func__, rdev_get_name(rdev)); 1827 1781 goto out; 1828 1782 } 1829 1783 1830 1784 /* calc total requested load for this regulator */ 1831 1785 list_for_each_entry(consumer, &rdev->consumer_list, list) 1832 - total_uA_load += consumer->uA_load; 1786 + total_uA_load += consumer->uA_load; 1833 1787 1834 1788 mode = rdev->desc->ops->get_optimum_mode(rdev, 1835 1789 input_uV, output_uV, ··· 1837 1791 ret = regulator_check_mode(rdev, mode); 1838 1792 if (ret < 0) { 1839 1793 printk(KERN_ERR "%s: failed to get optimum mode for %s @" 1840 - " %d uA %d -> %d uV\n", __func__, rdev->desc->name, 1794 + " %d uA %d -> %d uV\n", __func__, rdev_get_name(rdev), 1841 1795 total_uA_load, input_uV, output_uV); 1842 1796 goto out; 1843 1797 } ··· 1845 1799 ret = rdev->desc->ops->set_mode(rdev, mode); 1846 1800 if (ret < 0) { 1847 1801 printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", 1848 - __func__, mode, rdev->desc->name); 1802 + __func__, mode, rdev_get_name(rdev)); 1849 1803 goto out; 1850 1804 } 1851 1805 ret = mode; ··· 1898 1852 1899 1853 /* now notify regulator we supply */ 1900 1854 list_for_each_entry(_rdev, &rdev->supply_list, slist) { 1901 - mutex_lock(&_rdev->mutex); 1902 - _notifier_call_chain(_rdev, event, data); 1903 - mutex_unlock(&_rdev->mutex); 1855 + mutex_lock(&_rdev->mutex); 1856 + _notifier_call_chain(_rdev, event, data); 1857 + mutex_unlock(&_rdev->mutex); 1904 1858 } 1905 1859 } 1906 1860 ··· 1931 1885 consumers[i].consumer = regulator_get(dev, 1932 1886 consumers[i].supply); 1933 1887 if (IS_ERR(consumers[i].consumer)) { 1934 - dev_err(dev, "Failed to get supply '%s'\n", 1935 - consumers[i].supply); 1936 1888 ret = PTR_ERR(consumers[i].consumer); 1889 + dev_err(dev, "Failed to get supply '%s': %d\n", 1890 + consumers[i].supply, ret); 1937 1891 consumers[i].consumer = NULL; 1938 1892 goto err; 1939 1893 } ··· 1976 1930 return 0; 1977 1931 1978 1932 err: 1979 - printk(KERN_ERR "Failed to enable %s\n", consumers[i].supply); 1980 - for (i = 0; i < num_consumers; i++) 1933 + printk(KERN_ERR "Failed to enable %s: %d\n", consumers[i].supply, ret); 1934 + for (--i; i >= 0; --i) 1981 1935 regulator_disable(consumers[i].consumer); 1982 1936 1983 1937 return ret; ··· 2011 1965 return 0; 2012 1966 2013 1967 err: 2014 - printk(KERN_ERR "Failed to disable %s\n", consumers[i].supply); 2015 - for (i = 0; i < num_consumers; i++) 1968 + printk(KERN_ERR "Failed to disable %s: %d\n", consumers[i].supply, 1969 + ret); 1970 + for (--i; i >= 0; --i) 2016 1971 regulator_enable(consumers[i].consumer); 2017 1972 2018 1973 return ret; ··· 2363 2316 2364 2317 if (ret < 0) { 2365 2318 printk(KERN_ERR "%s: failed to prepare %s\n", 2366 - __func__, rdev->desc->name); 2319 + __func__, rdev_get_name(rdev)); 2367 2320 goto out; 2368 2321 } 2369 2322 } ··· 2476 2429 ops = rdev->desc->ops; 2477 2430 c = rdev->constraints; 2478 2431 2479 - if (c && c->name) 2480 - name = c->name; 2481 - else if (rdev->desc->name) 2482 - name = rdev->desc->name; 2483 - else 2484 - name = "regulator"; 2432 + name = rdev_get_name(rdev); 2485 2433 2486 2434 if (!ops->disable || (c && c->always_on)) 2487 2435 continue;
+1 -1
drivers/regulator/da903x.c
··· 331 331 static int da9034_list_ldo12_voltage(struct regulator_dev *rdev, 332 332 unsigned selector) 333 333 { 334 - if (selector > ARRAY_SIZE(da9034_ldo12_data)) 334 + if (selector >= ARRAY_SIZE(da9034_ldo12_data)) 335 335 return -EINVAL; 336 336 return da9034_ldo12_data[selector] * 1000; 337 337 }
+2 -2
drivers/regulator/lp3971.c
··· 446 446 lp3971->rdev[i] = regulator_register(&regulators[id], 447 447 lp3971->dev, pdata->regulators[i].initdata, lp3971); 448 448 449 - err = IS_ERR(lp3971->rdev[i]); 450 - if (err) { 449 + if (IS_ERR(lp3971->rdev[i])) { 450 + err = PTR_ERR(lp3971->rdev[i]); 451 451 dev_err(lp3971->dev, "regulator init failed: %d\n", 452 452 err); 453 453 goto error;
+510
drivers/regulator/max8660.c
··· 1 + /* 2 + * max8660.c -- Voltage regulation for the Maxim 8660/8661 3 + * 4 + * based on max1586.c and wm8400-regulator.c 5 + * 6 + * Copyright (C) 2009 Wolfram Sang, Pengutronix e.K. 7 + * 8 + * This program is free software; you can redistribute it and/or modify it 9 + * under the terms of the GNU General Public License as published by the Free 10 + * Software Foundation; version 2 of the License. 11 + * 12 + * This program is distributed in the hope that it will be useful, but WITHOUT 13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 + * more details. 16 + * 17 + * You should have received a copy of the GNU General Public License along with 18 + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 19 + * Place, Suite 330, Boston, MA 02111-1307 USA 20 + * 21 + * Some info: 22 + * 23 + * Datasheet: http://datasheets.maxim-ic.com/en/ds/MAX8660-MAX8661.pdf 24 + * 25 + * This chip is a bit nasty because it is a write-only device. Thus, the driver 26 + * uses shadow registers to keep track of its values. The main problem appears 27 + * to be the initialization: When Linux boots up, we cannot know if the chip is 28 + * in the default state or not, so we would have to pass such information in 29 + * platform_data. As this adds a bit of complexity to the driver, this is left 30 + * out for now until it is really needed. 31 + * 32 + * [A|S|M]DTV1 registers are currently not used, but [A|S|M]DTV2. 33 + * 34 + * If the driver is feature complete, it might be worth to check if one set of 35 + * functions for V3-V7 is sufficient. For maximum flexibility during 36 + * development, they are separated for now. 37 + * 38 + */ 39 + 40 + #include <linux/module.h> 41 + #include <linux/err.h> 42 + #include <linux/i2c.h> 43 + #include <linux/platform_device.h> 44 + #include <linux/regulator/driver.h> 45 + #include <linux/regulator/max8660.h> 46 + 47 + #define MAX8660_DCDC_MIN_UV 725000 48 + #define MAX8660_DCDC_MAX_UV 1800000 49 + #define MAX8660_DCDC_STEP 25000 50 + #define MAX8660_DCDC_MAX_SEL 0x2b 51 + 52 + #define MAX8660_LDO5_MIN_UV 1700000 53 + #define MAX8660_LDO5_MAX_UV 2000000 54 + #define MAX8660_LDO5_STEP 25000 55 + #define MAX8660_LDO5_MAX_SEL 0x0c 56 + 57 + #define MAX8660_LDO67_MIN_UV 1800000 58 + #define MAX8660_LDO67_MAX_UV 3300000 59 + #define MAX8660_LDO67_STEP 100000 60 + #define MAX8660_LDO67_MAX_SEL 0x0f 61 + 62 + enum { 63 + MAX8660_OVER1, 64 + MAX8660_OVER2, 65 + MAX8660_VCC1, 66 + MAX8660_ADTV1, 67 + MAX8660_ADTV2, 68 + MAX8660_SDTV1, 69 + MAX8660_SDTV2, 70 + MAX8660_MDTV1, 71 + MAX8660_MDTV2, 72 + MAX8660_L12VCR, 73 + MAX8660_FPWM, 74 + MAX8660_N_REGS, /* not a real register */ 75 + }; 76 + 77 + struct max8660 { 78 + struct i2c_client *client; 79 + u8 shadow_regs[MAX8660_N_REGS]; /* as chip is write only */ 80 + struct regulator_dev *rdev[]; 81 + }; 82 + 83 + static int max8660_write(struct max8660 *max8660, u8 reg, u8 mask, u8 val) 84 + { 85 + static const u8 max8660_addresses[MAX8660_N_REGS] = 86 + { 0x10, 0x12, 0x20, 0x23, 0x24, 0x29, 0x2a, 0x32, 0x33, 0x39, 0x80 }; 87 + 88 + int ret; 89 + u8 reg_val = (max8660->shadow_regs[reg] & mask) | val; 90 + dev_vdbg(&max8660->client->dev, "Writing reg %02x with %02x\n", 91 + max8660_addresses[reg], reg_val); 92 + 93 + ret = i2c_smbus_write_byte_data(max8660->client, 94 + max8660_addresses[reg], reg_val); 95 + if (ret == 0) 96 + max8660->shadow_regs[reg] = reg_val; 97 + 98 + return ret; 99 + } 100 + 101 + 102 + /* 103 + * DCDC functions 104 + */ 105 + 106 + static int max8660_dcdc_is_enabled(struct regulator_dev *rdev) 107 + { 108 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 109 + u8 val = max8660->shadow_regs[MAX8660_OVER1]; 110 + u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? 1 : 4; 111 + return !!(val & mask); 112 + } 113 + 114 + static int max8660_dcdc_enable(struct regulator_dev *rdev) 115 + { 116 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 117 + u8 bit = (rdev_get_id(rdev) == MAX8660_V3) ? 1 : 4; 118 + return max8660_write(max8660, MAX8660_OVER1, 0xff, bit); 119 + } 120 + 121 + static int max8660_dcdc_disable(struct regulator_dev *rdev) 122 + { 123 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 124 + u8 mask = (rdev_get_id(rdev) == MAX8660_V3) ? ~1 : ~4; 125 + return max8660_write(max8660, MAX8660_OVER1, mask, 0); 126 + } 127 + 128 + static int max8660_dcdc_list(struct regulator_dev *rdev, unsigned selector) 129 + { 130 + if (selector > MAX8660_DCDC_MAX_SEL) 131 + return -EINVAL; 132 + return MAX8660_DCDC_MIN_UV + selector * MAX8660_DCDC_STEP; 133 + } 134 + 135 + static int max8660_dcdc_get(struct regulator_dev *rdev) 136 + { 137 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 138 + u8 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2; 139 + u8 selector = max8660->shadow_regs[reg]; 140 + return MAX8660_DCDC_MIN_UV + selector * MAX8660_DCDC_STEP; 141 + } 142 + 143 + static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV) 144 + { 145 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 146 + u8 reg, selector, bits; 147 + int ret; 148 + 149 + if (min_uV < MAX8660_DCDC_MIN_UV || min_uV > MAX8660_DCDC_MAX_UV) 150 + return -EINVAL; 151 + if (max_uV < MAX8660_DCDC_MIN_UV || max_uV > MAX8660_DCDC_MAX_UV) 152 + return -EINVAL; 153 + 154 + selector = (min_uV - (MAX8660_DCDC_MIN_UV - MAX8660_DCDC_STEP + 1)) 155 + / MAX8660_DCDC_STEP; 156 + 157 + ret = max8660_dcdc_list(rdev, selector); 158 + if (ret < 0 || ret > max_uV) 159 + return -EINVAL; 160 + 161 + reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2; 162 + ret = max8660_write(max8660, reg, 0, selector); 163 + if (ret) 164 + return ret; 165 + 166 + /* Select target voltage register and activate regulation */ 167 + bits = (rdev_get_id(rdev) == MAX8660_V3) ? 0x03 : 0x30; 168 + return max8660_write(max8660, MAX8660_VCC1, 0xff, bits); 169 + } 170 + 171 + static struct regulator_ops max8660_dcdc_ops = { 172 + .is_enabled = max8660_dcdc_is_enabled, 173 + .list_voltage = max8660_dcdc_list, 174 + .set_voltage = max8660_dcdc_set, 175 + .get_voltage = max8660_dcdc_get, 176 + }; 177 + 178 + 179 + /* 180 + * LDO5 functions 181 + */ 182 + 183 + static int max8660_ldo5_list(struct regulator_dev *rdev, unsigned selector) 184 + { 185 + if (selector > MAX8660_LDO5_MAX_SEL) 186 + return -EINVAL; 187 + return MAX8660_LDO5_MIN_UV + selector * MAX8660_LDO5_STEP; 188 + } 189 + 190 + static int max8660_ldo5_get(struct regulator_dev *rdev) 191 + { 192 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 193 + u8 selector = max8660->shadow_regs[MAX8660_MDTV2]; 194 + 195 + return MAX8660_LDO5_MIN_UV + selector * MAX8660_LDO5_STEP; 196 + } 197 + 198 + static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV) 199 + { 200 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 201 + u8 selector; 202 + int ret; 203 + 204 + if (min_uV < MAX8660_LDO5_MIN_UV || min_uV > MAX8660_LDO5_MAX_UV) 205 + return -EINVAL; 206 + if (max_uV < MAX8660_LDO5_MIN_UV || max_uV > MAX8660_LDO5_MAX_UV) 207 + return -EINVAL; 208 + 209 + selector = (min_uV - (MAX8660_LDO5_MIN_UV - MAX8660_LDO5_STEP + 1)) 210 + / MAX8660_LDO5_STEP; 211 + ret = max8660_ldo5_list(rdev, selector); 212 + if (ret < 0 || ret > max_uV) 213 + return -EINVAL; 214 + 215 + ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector); 216 + if (ret) 217 + return ret; 218 + 219 + /* Select target voltage register and activate regulation */ 220 + return max8660_write(max8660, MAX8660_VCC1, 0xff, 0xc0); 221 + } 222 + 223 + static struct regulator_ops max8660_ldo5_ops = { 224 + .list_voltage = max8660_ldo5_list, 225 + .set_voltage = max8660_ldo5_set, 226 + .get_voltage = max8660_ldo5_get, 227 + }; 228 + 229 + 230 + /* 231 + * LDO67 functions 232 + */ 233 + 234 + static int max8660_ldo67_is_enabled(struct regulator_dev *rdev) 235 + { 236 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 237 + u8 val = max8660->shadow_regs[MAX8660_OVER2]; 238 + u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? 2 : 4; 239 + return !!(val & mask); 240 + } 241 + 242 + static int max8660_ldo67_enable(struct regulator_dev *rdev) 243 + { 244 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 245 + u8 bit = (rdev_get_id(rdev) == MAX8660_V6) ? 2 : 4; 246 + return max8660_write(max8660, MAX8660_OVER2, 0xff, bit); 247 + } 248 + 249 + static int max8660_ldo67_disable(struct regulator_dev *rdev) 250 + { 251 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 252 + u8 mask = (rdev_get_id(rdev) == MAX8660_V6) ? ~2 : ~4; 253 + return max8660_write(max8660, MAX8660_OVER2, mask, 0); 254 + } 255 + 256 + static int max8660_ldo67_list(struct regulator_dev *rdev, unsigned selector) 257 + { 258 + if (selector > MAX8660_LDO67_MAX_SEL) 259 + return -EINVAL; 260 + return MAX8660_LDO67_MIN_UV + selector * MAX8660_LDO67_STEP; 261 + } 262 + 263 + static int max8660_ldo67_get(struct regulator_dev *rdev) 264 + { 265 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 266 + u8 shift = (rdev_get_id(rdev) == MAX8660_V6) ? 0 : 4; 267 + u8 selector = (max8660->shadow_regs[MAX8660_L12VCR] >> shift) & 0xf; 268 + 269 + return MAX8660_LDO67_MIN_UV + selector * MAX8660_LDO67_STEP; 270 + } 271 + 272 + static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV, int max_uV) 273 + { 274 + struct max8660 *max8660 = rdev_get_drvdata(rdev); 275 + u8 selector; 276 + int ret; 277 + 278 + if (min_uV < MAX8660_LDO67_MIN_UV || min_uV > MAX8660_LDO67_MAX_UV) 279 + return -EINVAL; 280 + if (max_uV < MAX8660_LDO67_MIN_UV || max_uV > MAX8660_LDO67_MAX_UV) 281 + return -EINVAL; 282 + 283 + selector = (min_uV - (MAX8660_LDO67_MIN_UV - MAX8660_LDO67_STEP + 1)) 284 + / MAX8660_LDO67_STEP; 285 + 286 + ret = max8660_ldo67_list(rdev, selector); 287 + if (ret < 0 || ret > max_uV) 288 + return -EINVAL; 289 + 290 + if (rdev_get_id(rdev) == MAX8660_V6) 291 + return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector); 292 + else 293 + return max8660_write(max8660, MAX8660_L12VCR, 0x0f, selector << 4); 294 + } 295 + 296 + static struct regulator_ops max8660_ldo67_ops = { 297 + .is_enabled = max8660_ldo67_is_enabled, 298 + .enable = max8660_ldo67_enable, 299 + .disable = max8660_ldo67_disable, 300 + .list_voltage = max8660_ldo67_list, 301 + .get_voltage = max8660_ldo67_get, 302 + .set_voltage = max8660_ldo67_set, 303 + }; 304 + 305 + static struct regulator_desc max8660_reg[] = { 306 + { 307 + .name = "V3(DCDC)", 308 + .id = MAX8660_V3, 309 + .ops = &max8660_dcdc_ops, 310 + .type = REGULATOR_VOLTAGE, 311 + .n_voltages = MAX8660_DCDC_MAX_SEL + 1, 312 + .owner = THIS_MODULE, 313 + }, 314 + { 315 + .name = "V4(DCDC)", 316 + .id = MAX8660_V4, 317 + .ops = &max8660_dcdc_ops, 318 + .type = REGULATOR_VOLTAGE, 319 + .n_voltages = MAX8660_DCDC_MAX_SEL + 1, 320 + .owner = THIS_MODULE, 321 + }, 322 + { 323 + .name = "V5(LDO)", 324 + .id = MAX8660_V5, 325 + .ops = &max8660_ldo5_ops, 326 + .type = REGULATOR_VOLTAGE, 327 + .n_voltages = MAX8660_LDO5_MAX_SEL + 1, 328 + .owner = THIS_MODULE, 329 + }, 330 + { 331 + .name = "V6(LDO)", 332 + .id = MAX8660_V6, 333 + .ops = &max8660_ldo67_ops, 334 + .type = REGULATOR_VOLTAGE, 335 + .n_voltages = MAX8660_LDO67_MAX_SEL + 1, 336 + .owner = THIS_MODULE, 337 + }, 338 + { 339 + .name = "V7(LDO)", 340 + .id = MAX8660_V7, 341 + .ops = &max8660_ldo67_ops, 342 + .type = REGULATOR_VOLTAGE, 343 + .n_voltages = MAX8660_LDO67_MAX_SEL + 1, 344 + .owner = THIS_MODULE, 345 + }, 346 + }; 347 + 348 + static int max8660_probe(struct i2c_client *client, 349 + const struct i2c_device_id *i2c_id) 350 + { 351 + struct regulator_dev **rdev; 352 + struct max8660_platform_data *pdata = client->dev.platform_data; 353 + struct max8660 *max8660; 354 + int boot_on, i, id, ret = -EINVAL; 355 + 356 + if (pdata->num_subdevs > MAX8660_V_END) { 357 + dev_err(&client->dev, "Too much regulators found!\n"); 358 + goto out; 359 + } 360 + 361 + max8660 = kzalloc(sizeof(struct max8660) + 362 + sizeof(struct regulator_dev *) * MAX8660_V_END, 363 + GFP_KERNEL); 364 + if (!max8660) { 365 + ret = -ENOMEM; 366 + goto out; 367 + } 368 + 369 + max8660->client = client; 370 + rdev = max8660->rdev; 371 + 372 + if (pdata->en34_is_high) { 373 + /* Simulate always on */ 374 + max8660->shadow_regs[MAX8660_OVER1] = 5; 375 + } else { 376 + /* Otherwise devices can be toggled via software */ 377 + max8660_dcdc_ops.enable = max8660_dcdc_enable; 378 + max8660_dcdc_ops.disable = max8660_dcdc_disable; 379 + } 380 + 381 + /* 382 + * First, set up shadow registers to prevent glitches. As some 383 + * registers are shared between regulators, everything must be properly 384 + * set up for all regulators in advance. 385 + */ 386 + max8660->shadow_regs[MAX8660_ADTV1] = 387 + max8660->shadow_regs[MAX8660_ADTV2] = 388 + max8660->shadow_regs[MAX8660_SDTV1] = 389 + max8660->shadow_regs[MAX8660_SDTV2] = 0x1b; 390 + max8660->shadow_regs[MAX8660_MDTV1] = 391 + max8660->shadow_regs[MAX8660_MDTV2] = 0x04; 392 + 393 + for (i = 0; i < pdata->num_subdevs; i++) { 394 + 395 + if (!pdata->subdevs[i].platform_data) 396 + goto err_free; 397 + 398 + boot_on = pdata->subdevs[i].platform_data->constraints.boot_on; 399 + 400 + switch (pdata->subdevs[i].id) { 401 + case MAX8660_V3: 402 + if (boot_on) 403 + max8660->shadow_regs[MAX8660_OVER1] |= 1; 404 + break; 405 + 406 + case MAX8660_V4: 407 + if (boot_on) 408 + max8660->shadow_regs[MAX8660_OVER1] |= 4; 409 + break; 410 + 411 + case MAX8660_V5: 412 + break; 413 + 414 + case MAX8660_V6: 415 + if (boot_on) 416 + max8660->shadow_regs[MAX8660_OVER2] |= 2; 417 + break; 418 + 419 + case MAX8660_V7: 420 + if (!strcmp(i2c_id->name, "max8661")) { 421 + dev_err(&client->dev, "Regulator not on this chip!\n"); 422 + goto err_free; 423 + } 424 + 425 + if (boot_on) 426 + max8660->shadow_regs[MAX8660_OVER2] |= 4; 427 + break; 428 + 429 + default: 430 + dev_err(&client->dev, "invalid regulator %s\n", 431 + pdata->subdevs[i].name); 432 + goto err_free; 433 + } 434 + } 435 + 436 + /* Finally register devices */ 437 + for (i = 0; i < pdata->num_subdevs; i++) { 438 + 439 + id = pdata->subdevs[i].id; 440 + 441 + rdev[i] = regulator_register(&max8660_reg[id], &client->dev, 442 + pdata->subdevs[i].platform_data, 443 + max8660); 444 + if (IS_ERR(rdev[i])) { 445 + ret = PTR_ERR(rdev[i]); 446 + dev_err(&client->dev, "failed to register %s\n", 447 + max8660_reg[id].name); 448 + goto err_unregister; 449 + } 450 + } 451 + 452 + i2c_set_clientdata(client, rdev); 453 + dev_info(&client->dev, "Maxim 8660/8661 regulator driver loaded\n"); 454 + return 0; 455 + 456 + err_unregister: 457 + while (--i >= 0) 458 + regulator_unregister(rdev[i]); 459 + err_free: 460 + kfree(max8660); 461 + out: 462 + return ret; 463 + } 464 + 465 + static int max8660_remove(struct i2c_client *client) 466 + { 467 + struct regulator_dev **rdev = i2c_get_clientdata(client); 468 + int i; 469 + 470 + for (i = 0; i < MAX8660_V_END; i++) 471 + if (rdev[i]) 472 + regulator_unregister(rdev[i]); 473 + kfree(rdev); 474 + i2c_set_clientdata(client, NULL); 475 + 476 + return 0; 477 + } 478 + 479 + static const struct i2c_device_id max8660_id[] = { 480 + { "max8660", 0 }, 481 + { "max8661", 0 }, 482 + { } 483 + }; 484 + MODULE_DEVICE_TABLE(i2c, max8660_id); 485 + 486 + static struct i2c_driver max8660_driver = { 487 + .probe = max8660_probe, 488 + .remove = max8660_remove, 489 + .driver = { 490 + .name = "max8660", 491 + }, 492 + .id_table = max8660_id, 493 + }; 494 + 495 + static int __init max8660_init(void) 496 + { 497 + return i2c_add_driver(&max8660_driver); 498 + } 499 + subsys_initcall(max8660_init); 500 + 501 + static void __exit max8660_exit(void) 502 + { 503 + i2c_del_driver(&max8660_driver); 504 + } 505 + module_exit(max8660_exit); 506 + 507 + /* Module information */ 508 + MODULE_DESCRIPTION("MAXIM 8660/8661 voltage regulator driver"); 509 + MODULE_AUTHOR("Wolfram Sang"); 510 + MODULE_LICENSE("GPL v2");
+245
drivers/regulator/mc13783-regulator.c
··· 1 + /* 2 + * Regulator Driver for Freescale MC13783 PMIC 3 + * 4 + * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + 11 + #include <linux/mfd/mc13783.h> 12 + #include <linux/regulator/machine.h> 13 + #include <linux/regulator/driver.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/kernel.h> 16 + #include <linux/init.h> 17 + #include <linux/err.h> 18 + 19 + #define MC13783_REG_SWITCHERS4 28 20 + #define MC13783_REG_SWITCHERS4_PLLEN (1 << 18) 21 + 22 + #define MC13783_REG_SWITCHERS5 29 23 + #define MC13783_REG_SWITCHERS5_SW3EN (1 << 20) 24 + 25 + #define MC13783_REG_REGULATORMODE0 32 26 + #define MC13783_REG_REGULATORMODE0_VAUDIOEN (1 << 0) 27 + #define MC13783_REG_REGULATORMODE0_VIOHIEN (1 << 3) 28 + #define MC13783_REG_REGULATORMODE0_VIOLOEN (1 << 6) 29 + #define MC13783_REG_REGULATORMODE0_VDIGEN (1 << 9) 30 + #define MC13783_REG_REGULATORMODE0_VGENEN (1 << 12) 31 + #define MC13783_REG_REGULATORMODE0_VRFDIGEN (1 << 15) 32 + #define MC13783_REG_REGULATORMODE0_VRFREFEN (1 << 18) 33 + #define MC13783_REG_REGULATORMODE0_VRFCPEN (1 << 21) 34 + 35 + #define MC13783_REG_REGULATORMODE1 33 36 + #define MC13783_REG_REGULATORMODE1_VSIMEN (1 << 0) 37 + #define MC13783_REG_REGULATORMODE1_VESIMEN (1 << 3) 38 + #define MC13783_REG_REGULATORMODE1_VCAMEN (1 << 6) 39 + #define MC13783_REG_REGULATORMODE1_VRFBGEN (1 << 9) 40 + #define MC13783_REG_REGULATORMODE1_VVIBEN (1 << 11) 41 + #define MC13783_REG_REGULATORMODE1_VRF1EN (1 << 12) 42 + #define MC13783_REG_REGULATORMODE1_VRF2EN (1 << 15) 43 + #define MC13783_REG_REGULATORMODE1_VMMC1EN (1 << 18) 44 + #define MC13783_REG_REGULATORMODE1_VMMC2EN (1 << 21) 45 + 46 + #define MC13783_REG_POWERMISC 34 47 + #define MC13783_REG_POWERMISC_GPO1EN (1 << 6) 48 + #define MC13783_REG_POWERMISC_GPO2EN (1 << 8) 49 + #define MC13783_REG_POWERMISC_GPO3EN (1 << 10) 50 + #define MC13783_REG_POWERMISC_GPO4EN (1 << 12) 51 + 52 + struct mc13783_regulator { 53 + struct regulator_desc desc; 54 + int reg; 55 + int enable_bit; 56 + }; 57 + 58 + static struct regulator_ops mc13783_regulator_ops; 59 + 60 + #define MC13783_DEFINE(prefix, _name, _reg) \ 61 + [MC13783_ ## prefix ## _ ## _name] = { \ 62 + .desc = { \ 63 + .name = #prefix "_" #_name, \ 64 + .ops = &mc13783_regulator_ops, \ 65 + .type = REGULATOR_VOLTAGE, \ 66 + .id = MC13783_ ## prefix ## _ ## _name, \ 67 + .owner = THIS_MODULE, \ 68 + }, \ 69 + .reg = MC13783_REG_ ## _reg, \ 70 + .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \ 71 + } 72 + 73 + #define MC13783_DEFINE_SW(_name, _reg) MC13783_DEFINE(SW, _name, _reg) 74 + #define MC13783_DEFINE_REGU(_name, _reg) MC13783_DEFINE(REGU, _name, _reg) 75 + 76 + static struct mc13783_regulator mc13783_regulators[] = { 77 + MC13783_DEFINE_SW(SW3, SWITCHERS5), 78 + MC13783_DEFINE_SW(PLL, SWITCHERS4), 79 + 80 + MC13783_DEFINE_REGU(VAUDIO, REGULATORMODE0), 81 + MC13783_DEFINE_REGU(VIOHI, REGULATORMODE0), 82 + MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0), 83 + MC13783_DEFINE_REGU(VDIG, REGULATORMODE0), 84 + MC13783_DEFINE_REGU(VGEN, REGULATORMODE0), 85 + MC13783_DEFINE_REGU(VRFDIG, REGULATORMODE0), 86 + MC13783_DEFINE_REGU(VRFREF, REGULATORMODE0), 87 + MC13783_DEFINE_REGU(VRFCP, REGULATORMODE0), 88 + MC13783_DEFINE_REGU(VSIM, REGULATORMODE1), 89 + MC13783_DEFINE_REGU(VESIM, REGULATORMODE1), 90 + MC13783_DEFINE_REGU(VCAM, REGULATORMODE1), 91 + MC13783_DEFINE_REGU(VRFBG, REGULATORMODE1), 92 + MC13783_DEFINE_REGU(VVIB, REGULATORMODE1), 93 + MC13783_DEFINE_REGU(VRF1, REGULATORMODE1), 94 + MC13783_DEFINE_REGU(VRF2, REGULATORMODE1), 95 + MC13783_DEFINE_REGU(VMMC1, REGULATORMODE1), 96 + MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1), 97 + MC13783_DEFINE_REGU(GPO1, POWERMISC), 98 + MC13783_DEFINE_REGU(GPO2, POWERMISC), 99 + MC13783_DEFINE_REGU(GPO3, POWERMISC), 100 + MC13783_DEFINE_REGU(GPO4, POWERMISC), 101 + }; 102 + 103 + struct mc13783_regulator_priv { 104 + struct mc13783 *mc13783; 105 + struct regulator_dev *regulators[]; 106 + }; 107 + 108 + static int mc13783_regulator_enable(struct regulator_dev *rdev) 109 + { 110 + struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); 111 + int id = rdev_get_id(rdev); 112 + int ret; 113 + 114 + dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 115 + 116 + mc13783_lock(priv->mc13783); 117 + ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].reg, 118 + mc13783_regulators[id].enable_bit, 119 + mc13783_regulators[id].enable_bit); 120 + mc13783_unlock(priv->mc13783); 121 + 122 + return ret; 123 + } 124 + 125 + static int mc13783_regulator_disable(struct regulator_dev *rdev) 126 + { 127 + struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); 128 + int id = rdev_get_id(rdev); 129 + int ret; 130 + 131 + dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 132 + 133 + mc13783_lock(priv->mc13783); 134 + ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].reg, 135 + mc13783_regulators[id].enable_bit, 0); 136 + mc13783_unlock(priv->mc13783); 137 + 138 + return ret; 139 + } 140 + 141 + static int mc13783_regulator_is_enabled(struct regulator_dev *rdev) 142 + { 143 + struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); 144 + int ret, id = rdev_get_id(rdev); 145 + unsigned int val; 146 + 147 + mc13783_lock(priv->mc13783); 148 + ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val); 149 + mc13783_unlock(priv->mc13783); 150 + 151 + if (ret) 152 + return ret; 153 + 154 + return (val & mc13783_regulators[id].enable_bit) != 0; 155 + } 156 + 157 + static struct regulator_ops mc13783_regulator_ops = { 158 + .enable = mc13783_regulator_enable, 159 + .disable = mc13783_regulator_disable, 160 + .is_enabled = mc13783_regulator_is_enabled, 161 + }; 162 + 163 + static int __devinit mc13783_regulator_probe(struct platform_device *pdev) 164 + { 165 + struct mc13783_regulator_priv *priv; 166 + struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent); 167 + struct mc13783_regulator_platform_data *pdata = 168 + dev_get_platdata(&pdev->dev); 169 + struct mc13783_regulator_init_data *init_data; 170 + int i, ret; 171 + 172 + dev_dbg(&pdev->dev, "mc13783_regulator_probe id %d\n", pdev->id); 173 + 174 + priv = kzalloc(sizeof(*priv) + 175 + pdata->num_regulators * sizeof(priv->regulators[0]), 176 + GFP_KERNEL); 177 + if (!priv) 178 + return -ENOMEM; 179 + 180 + priv->mc13783 = mc13783; 181 + 182 + for (i = 0; i < pdata->num_regulators; i++) { 183 + init_data = &pdata->regulators[i]; 184 + priv->regulators[i] = regulator_register( 185 + &mc13783_regulators[init_data->id].desc, 186 + &pdev->dev, init_data->init_data, priv); 187 + 188 + if (IS_ERR(priv->regulators[i])) { 189 + dev_err(&pdev->dev, "failed to register regulator %s\n", 190 + mc13783_regulators[i].desc.name); 191 + ret = PTR_ERR(priv->regulators[i]); 192 + goto err; 193 + } 194 + } 195 + 196 + platform_set_drvdata(pdev, priv); 197 + 198 + return 0; 199 + err: 200 + while (--i >= 0) 201 + regulator_unregister(priv->regulators[i]); 202 + 203 + kfree(priv); 204 + 205 + return ret; 206 + } 207 + 208 + static int __devexit mc13783_regulator_remove(struct platform_device *pdev) 209 + { 210 + struct mc13783_regulator_priv *priv = platform_get_drvdata(pdev); 211 + struct mc13783_regulator_platform_data *pdata = 212 + dev_get_platdata(&pdev->dev); 213 + int i; 214 + 215 + for (i = 0; i < pdata->num_regulators; i++) 216 + regulator_unregister(priv->regulators[i]); 217 + 218 + return 0; 219 + } 220 + 221 + static struct platform_driver mc13783_regulator_driver = { 222 + .driver = { 223 + .name = "mc13783-regulator", 224 + .owner = THIS_MODULE, 225 + }, 226 + .remove = __devexit_p(mc13783_regulator_remove), 227 + .probe = mc13783_regulator_probe, 228 + }; 229 + 230 + static int __init mc13783_regulator_init(void) 231 + { 232 + return platform_driver_register(&mc13783_regulator_driver); 233 + } 234 + subsys_initcall(mc13783_regulator_init); 235 + 236 + static void __exit mc13783_regulator_exit(void) 237 + { 238 + platform_driver_unregister(&mc13783_regulator_driver); 239 + } 240 + module_exit(mc13783_regulator_exit); 241 + 242 + MODULE_LICENSE("GPL v2"); 243 + MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de"); 244 + MODULE_DESCRIPTION("Regulator Driver for Freescale MC13783 PMIC"); 245 + MODULE_ALIAS("platform:mc13783-regulator");
-410
drivers/regulator/mc13783.c
··· 1 - /* 2 - * Regulator Driver for Freescale MC13783 PMIC 3 - * 4 - * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. 9 - */ 10 - 11 - #include <linux/mfd/mc13783-private.h> 12 - #include <linux/regulator/machine.h> 13 - #include <linux/regulator/driver.h> 14 - #include <linux/platform_device.h> 15 - #include <linux/mfd/mc13783.h> 16 - #include <linux/kernel.h> 17 - #include <linux/init.h> 18 - #include <linux/err.h> 19 - 20 - struct mc13783_regulator { 21 - struct regulator_desc desc; 22 - int reg; 23 - int enable_bit; 24 - }; 25 - 26 - static struct regulator_ops mc13783_regulator_ops; 27 - 28 - static struct mc13783_regulator mc13783_regulators[] = { 29 - [MC13783_SW_SW3] = { 30 - .desc = { 31 - .name = "SW_SW3", 32 - .ops = &mc13783_regulator_ops, 33 - .type = REGULATOR_VOLTAGE, 34 - .id = MC13783_SW_SW3, 35 - .owner = THIS_MODULE, 36 - }, 37 - .reg = MC13783_REG_SWITCHERS_5, 38 - .enable_bit = MC13783_SWCTRL_SW3_EN, 39 - }, 40 - [MC13783_SW_PLL] = { 41 - .desc = { 42 - .name = "SW_PLL", 43 - .ops = &mc13783_regulator_ops, 44 - .type = REGULATOR_VOLTAGE, 45 - .id = MC13783_SW_PLL, 46 - .owner = THIS_MODULE, 47 - }, 48 - .reg = MC13783_REG_SWITCHERS_4, 49 - .enable_bit = MC13783_SWCTRL_PLL_EN, 50 - }, 51 - [MC13783_REGU_VAUDIO] = { 52 - .desc = { 53 - .name = "REGU_VAUDIO", 54 - .ops = &mc13783_regulator_ops, 55 - .type = REGULATOR_VOLTAGE, 56 - .id = MC13783_REGU_VAUDIO, 57 - .owner = THIS_MODULE, 58 - }, 59 - .reg = MC13783_REG_REGULATOR_MODE_0, 60 - .enable_bit = MC13783_REGCTRL_VAUDIO_EN, 61 - }, 62 - [MC13783_REGU_VIOHI] = { 63 - .desc = { 64 - .name = "REGU_VIOHI", 65 - .ops = &mc13783_regulator_ops, 66 - .type = REGULATOR_VOLTAGE, 67 - .id = MC13783_REGU_VIOHI, 68 - .owner = THIS_MODULE, 69 - }, 70 - .reg = MC13783_REG_REGULATOR_MODE_0, 71 - .enable_bit = MC13783_REGCTRL_VIOHI_EN, 72 - }, 73 - [MC13783_REGU_VIOLO] = { 74 - .desc = { 75 - .name = "REGU_VIOLO", 76 - .ops = &mc13783_regulator_ops, 77 - .type = REGULATOR_VOLTAGE, 78 - .id = MC13783_REGU_VIOLO, 79 - .owner = THIS_MODULE, 80 - }, 81 - .reg = MC13783_REG_REGULATOR_MODE_0, 82 - .enable_bit = MC13783_REGCTRL_VIOLO_EN, 83 - }, 84 - [MC13783_REGU_VDIG] = { 85 - .desc = { 86 - .name = "REGU_VDIG", 87 - .ops = &mc13783_regulator_ops, 88 - .type = REGULATOR_VOLTAGE, 89 - .id = MC13783_REGU_VDIG, 90 - .owner = THIS_MODULE, 91 - }, 92 - .reg = MC13783_REG_REGULATOR_MODE_0, 93 - .enable_bit = MC13783_REGCTRL_VDIG_EN, 94 - }, 95 - [MC13783_REGU_VGEN] = { 96 - .desc = { 97 - .name = "REGU_VGEN", 98 - .ops = &mc13783_regulator_ops, 99 - .type = REGULATOR_VOLTAGE, 100 - .id = MC13783_REGU_VGEN, 101 - .owner = THIS_MODULE, 102 - }, 103 - .reg = MC13783_REG_REGULATOR_MODE_0, 104 - .enable_bit = MC13783_REGCTRL_VGEN_EN, 105 - }, 106 - [MC13783_REGU_VRFDIG] = { 107 - .desc = { 108 - .name = "REGU_VRFDIG", 109 - .ops = &mc13783_regulator_ops, 110 - .type = REGULATOR_VOLTAGE, 111 - .id = MC13783_REGU_VRFDIG, 112 - .owner = THIS_MODULE, 113 - }, 114 - .reg = MC13783_REG_REGULATOR_MODE_0, 115 - .enable_bit = MC13783_REGCTRL_VRFDIG_EN, 116 - }, 117 - [MC13783_REGU_VRFREF] = { 118 - .desc = { 119 - .name = "REGU_VRFREF", 120 - .ops = &mc13783_regulator_ops, 121 - .type = REGULATOR_VOLTAGE, 122 - .id = MC13783_REGU_VRFREF, 123 - .owner = THIS_MODULE, 124 - }, 125 - .reg = MC13783_REG_REGULATOR_MODE_0, 126 - .enable_bit = MC13783_REGCTRL_VRFREF_EN, 127 - }, 128 - [MC13783_REGU_VRFCP] = { 129 - .desc = { 130 - .name = "REGU_VRFCP", 131 - .ops = &mc13783_regulator_ops, 132 - .type = REGULATOR_VOLTAGE, 133 - .id = MC13783_REGU_VRFCP, 134 - .owner = THIS_MODULE, 135 - }, 136 - .reg = MC13783_REG_REGULATOR_MODE_0, 137 - .enable_bit = MC13783_REGCTRL_VRFCP_EN, 138 - }, 139 - [MC13783_REGU_VSIM] = { 140 - .desc = { 141 - .name = "REGU_VSIM", 142 - .ops = &mc13783_regulator_ops, 143 - .type = REGULATOR_VOLTAGE, 144 - .id = MC13783_REGU_VSIM, 145 - .owner = THIS_MODULE, 146 - }, 147 - .reg = MC13783_REG_REGULATOR_MODE_1, 148 - .enable_bit = MC13783_REGCTRL_VSIM_EN, 149 - }, 150 - [MC13783_REGU_VESIM] = { 151 - .desc = { 152 - .name = "REGU_VESIM", 153 - .ops = &mc13783_regulator_ops, 154 - .type = REGULATOR_VOLTAGE, 155 - .id = MC13783_REGU_VESIM, 156 - .owner = THIS_MODULE, 157 - }, 158 - .reg = MC13783_REG_REGULATOR_MODE_1, 159 - .enable_bit = MC13783_REGCTRL_VESIM_EN, 160 - }, 161 - [MC13783_REGU_VCAM] = { 162 - .desc = { 163 - .name = "REGU_VCAM", 164 - .ops = &mc13783_regulator_ops, 165 - .type = REGULATOR_VOLTAGE, 166 - .id = MC13783_REGU_VCAM, 167 - .owner = THIS_MODULE, 168 - }, 169 - .reg = MC13783_REG_REGULATOR_MODE_1, 170 - .enable_bit = MC13783_REGCTRL_VCAM_EN, 171 - }, 172 - [MC13783_REGU_VRFBG] = { 173 - .desc = { 174 - .name = "REGU_VRFBG", 175 - .ops = &mc13783_regulator_ops, 176 - .type = REGULATOR_VOLTAGE, 177 - .id = MC13783_REGU_VRFBG, 178 - .owner = THIS_MODULE, 179 - }, 180 - .reg = MC13783_REG_REGULATOR_MODE_1, 181 - .enable_bit = MC13783_REGCTRL_VRFBG_EN, 182 - }, 183 - [MC13783_REGU_VVIB] = { 184 - .desc = { 185 - .name = "REGU_VVIB", 186 - .ops = &mc13783_regulator_ops, 187 - .type = REGULATOR_VOLTAGE, 188 - .id = MC13783_REGU_VVIB, 189 - .owner = THIS_MODULE, 190 - }, 191 - .reg = MC13783_REG_REGULATOR_MODE_1, 192 - .enable_bit = MC13783_REGCTRL_VVIB_EN, 193 - }, 194 - [MC13783_REGU_VRF1] = { 195 - .desc = { 196 - .name = "REGU_VRF1", 197 - .ops = &mc13783_regulator_ops, 198 - .type = REGULATOR_VOLTAGE, 199 - .id = MC13783_REGU_VRF1, 200 - .owner = THIS_MODULE, 201 - }, 202 - .reg = MC13783_REG_REGULATOR_MODE_1, 203 - .enable_bit = MC13783_REGCTRL_VRF1_EN, 204 - }, 205 - [MC13783_REGU_VRF2] = { 206 - .desc = { 207 - .name = "REGU_VRF2", 208 - .ops = &mc13783_regulator_ops, 209 - .type = REGULATOR_VOLTAGE, 210 - .id = MC13783_REGU_VRF2, 211 - .owner = THIS_MODULE, 212 - }, 213 - .reg = MC13783_REG_REGULATOR_MODE_1, 214 - .enable_bit = MC13783_REGCTRL_VRF2_EN, 215 - }, 216 - [MC13783_REGU_VMMC1] = { 217 - .desc = { 218 - .name = "REGU_VMMC1", 219 - .ops = &mc13783_regulator_ops, 220 - .type = REGULATOR_VOLTAGE, 221 - .id = MC13783_REGU_VMMC1, 222 - .owner = THIS_MODULE, 223 - }, 224 - .reg = MC13783_REG_REGULATOR_MODE_1, 225 - .enable_bit = MC13783_REGCTRL_VMMC1_EN, 226 - }, 227 - [MC13783_REGU_VMMC2] = { 228 - .desc = { 229 - .name = "REGU_VMMC2", 230 - .ops = &mc13783_regulator_ops, 231 - .type = REGULATOR_VOLTAGE, 232 - .id = MC13783_REGU_VMMC2, 233 - .owner = THIS_MODULE, 234 - }, 235 - .reg = MC13783_REG_REGULATOR_MODE_1, 236 - .enable_bit = MC13783_REGCTRL_VMMC2_EN, 237 - }, 238 - [MC13783_REGU_GPO1] = { 239 - .desc = { 240 - .name = "REGU_GPO1", 241 - .ops = &mc13783_regulator_ops, 242 - .type = REGULATOR_VOLTAGE, 243 - .id = MC13783_REGU_GPO1, 244 - .owner = THIS_MODULE, 245 - }, 246 - .reg = MC13783_REG_POWER_MISCELLANEOUS, 247 - .enable_bit = MC13783_REGCTRL_GPO1_EN, 248 - }, 249 - [MC13783_REGU_GPO2] = { 250 - .desc = { 251 - .name = "REGU_GPO2", 252 - .ops = &mc13783_regulator_ops, 253 - .type = REGULATOR_VOLTAGE, 254 - .id = MC13783_REGU_GPO2, 255 - .owner = THIS_MODULE, 256 - }, 257 - .reg = MC13783_REG_POWER_MISCELLANEOUS, 258 - .enable_bit = MC13783_REGCTRL_GPO2_EN, 259 - }, 260 - [MC13783_REGU_GPO3] = { 261 - .desc = { 262 - .name = "REGU_GPO3", 263 - .ops = &mc13783_regulator_ops, 264 - .type = REGULATOR_VOLTAGE, 265 - .id = MC13783_REGU_GPO3, 266 - .owner = THIS_MODULE, 267 - }, 268 - .reg = MC13783_REG_POWER_MISCELLANEOUS, 269 - .enable_bit = MC13783_REGCTRL_GPO3_EN, 270 - }, 271 - [MC13783_REGU_GPO4] = { 272 - .desc = { 273 - .name = "REGU_GPO4", 274 - .ops = &mc13783_regulator_ops, 275 - .type = REGULATOR_VOLTAGE, 276 - .id = MC13783_REGU_GPO4, 277 - .owner = THIS_MODULE, 278 - }, 279 - .reg = MC13783_REG_POWER_MISCELLANEOUS, 280 - .enable_bit = MC13783_REGCTRL_GPO4_EN, 281 - }, 282 - }; 283 - 284 - struct mc13783_priv { 285 - struct regulator_desc desc[ARRAY_SIZE(mc13783_regulators)]; 286 - struct mc13783 *mc13783; 287 - struct regulator_dev *regulators[0]; 288 - }; 289 - 290 - static int mc13783_enable(struct regulator_dev *rdev) 291 - { 292 - struct mc13783_priv *priv = rdev_get_drvdata(rdev); 293 - int id = rdev_get_id(rdev); 294 - 295 - dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 296 - 297 - return mc13783_set_bits(priv->mc13783, mc13783_regulators[id].reg, 298 - mc13783_regulators[id].enable_bit, 299 - mc13783_regulators[id].enable_bit); 300 - } 301 - 302 - static int mc13783_disable(struct regulator_dev *rdev) 303 - { 304 - struct mc13783_priv *priv = rdev_get_drvdata(rdev); 305 - int id = rdev_get_id(rdev); 306 - 307 - dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 308 - 309 - return mc13783_set_bits(priv->mc13783, mc13783_regulators[id].reg, 310 - mc13783_regulators[id].enable_bit, 0); 311 - } 312 - 313 - static int mc13783_is_enabled(struct regulator_dev *rdev) 314 - { 315 - struct mc13783_priv *priv = rdev_get_drvdata(rdev); 316 - int ret, id = rdev_get_id(rdev); 317 - unsigned int val; 318 - 319 - ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val); 320 - if (ret) 321 - return ret; 322 - 323 - return (val & mc13783_regulators[id].enable_bit) != 0; 324 - } 325 - 326 - static struct regulator_ops mc13783_regulator_ops = { 327 - .enable = mc13783_enable, 328 - .disable = mc13783_disable, 329 - .is_enabled = mc13783_is_enabled, 330 - }; 331 - 332 - static int __devinit mc13783_regulator_probe(struct platform_device *pdev) 333 - { 334 - struct mc13783_priv *priv; 335 - struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent); 336 - struct mc13783_regulator_init_data *init_data; 337 - int i, ret; 338 - 339 - dev_dbg(&pdev->dev, "mc13783_regulator_probe id %d\n", pdev->id); 340 - 341 - priv = kzalloc(sizeof(*priv) + mc13783->num_regulators * sizeof(void *), 342 - GFP_KERNEL); 343 - if (!priv) 344 - return -ENOMEM; 345 - 346 - priv->mc13783 = mc13783; 347 - 348 - for (i = 0; i < mc13783->num_regulators; i++) { 349 - init_data = &mc13783->regulators[i]; 350 - priv->regulators[i] = regulator_register( 351 - &mc13783_regulators[init_data->id].desc, 352 - &pdev->dev, init_data->init_data, priv); 353 - 354 - if (IS_ERR(priv->regulators[i])) { 355 - dev_err(&pdev->dev, "failed to register regulator %s\n", 356 - mc13783_regulators[i].desc.name); 357 - ret = PTR_ERR(priv->regulators[i]); 358 - goto err; 359 - } 360 - } 361 - 362 - platform_set_drvdata(pdev, priv); 363 - 364 - return 0; 365 - err: 366 - while (--i >= 0) 367 - regulator_unregister(priv->regulators[i]); 368 - 369 - kfree(priv); 370 - 371 - return ret; 372 - } 373 - 374 - static int __devexit mc13783_regulator_remove(struct platform_device *pdev) 375 - { 376 - struct mc13783_priv *priv = platform_get_drvdata(pdev); 377 - struct mc13783 *mc13783 = priv->mc13783; 378 - int i; 379 - 380 - for (i = 0; i < mc13783->num_regulators; i++) 381 - regulator_unregister(priv->regulators[i]); 382 - 383 - return 0; 384 - } 385 - 386 - static struct platform_driver mc13783_regulator_driver = { 387 - .driver = { 388 - .name = "mc13783-regulator", 389 - .owner = THIS_MODULE, 390 - }, 391 - .remove = __devexit_p(mc13783_regulator_remove), 392 - }; 393 - 394 - static int __init mc13783_regulator_init(void) 395 - { 396 - return platform_driver_probe(&mc13783_regulator_driver, 397 - mc13783_regulator_probe); 398 - } 399 - subsys_initcall(mc13783_regulator_init); 400 - 401 - static void __exit mc13783_regulator_exit(void) 402 - { 403 - platform_driver_unregister(&mc13783_regulator_driver); 404 - } 405 - module_exit(mc13783_regulator_exit); 406 - 407 - MODULE_LICENSE("GPL"); 408 - MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de"); 409 - MODULE_DESCRIPTION("Regulator Driver for Freescale MC13783 PMIC"); 410 - MODULE_ALIAS("platform:mc13783-regulator");
+98 -47
drivers/regulator/twl-regulator.c
··· 12 12 #include <linux/module.h> 13 13 #include <linux/init.h> 14 14 #include <linux/err.h> 15 + #include <linux/delay.h> 15 16 #include <linux/platform_device.h> 16 17 #include <linux/regulator/driver.h> 17 18 #include <linux/regulator/machine.h> ··· 40 39 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */ 41 40 u8 table_len; 42 41 const u16 *table; 42 + 43 + /* regulator specific turn-on delay */ 44 + u16 delay; 45 + 46 + /* State REMAP default configuration */ 47 + u8 remap; 43 48 44 49 /* chip constraints on regulator behavior */ 45 50 u16 min_mV; ··· 135 128 { 136 129 struct twlreg_info *info = rdev_get_drvdata(rdev); 137 130 int grp; 131 + int ret; 138 132 139 133 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); 140 134 if (grp < 0) ··· 146 138 else 147 139 grp |= P1_GRP_6030; 148 140 149 - return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); 141 + ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); 142 + 143 + udelay(info->delay); 144 + 145 + return ret; 150 146 } 151 147 152 148 static int twlreg_disable(struct regulator_dev *rdev) ··· 163 151 return grp; 164 152 165 153 if (twl_class_is_4030()) 166 - grp &= ~P1_GRP_4030; 154 + grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030); 167 155 else 168 - grp &= ~P1_GRP_6030; 156 + grp &= ~(P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030); 169 157 170 158 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); 171 159 } ··· 306 294 static const u16 VDAC_VSEL_table[] = { 307 295 1200, 1300, 1800, 1800, 308 296 }; 297 + static const u16 VDD1_VSEL_table[] = { 298 + 800, 1450, 299 + }; 300 + static const u16 VDD2_VSEL_table[] = { 301 + 800, 1450, 1500, 302 + }; 303 + static const u16 VIO_VSEL_table[] = { 304 + 1800, 1850, 305 + }; 306 + static const u16 VINTANA2_VSEL_table[] = { 307 + 2500, 2750, 308 + }; 309 309 static const u16 VAUX1_6030_VSEL_table[] = { 310 310 1000, 1300, 1800, 2500, 311 311 2800, 2900, 3000, 3000, ··· 438 414 439 415 /*----------------------------------------------------------------------*/ 440 416 441 - #define TWL4030_ADJUSTABLE_LDO(label, offset, num) \ 442 - TWL_ADJUSTABLE_LDO(label, offset, num, TWL4030) 443 - #define TWL4030_FIXED_LDO(label, offset, mVolts, num) \ 444 - TWL_FIXED_LDO(label, offset, mVolts, num, TWL4030) 445 - #define TWL6030_ADJUSTABLE_LDO(label, offset, num) \ 446 - TWL_ADJUSTABLE_LDO(label, offset, num, TWL6030) 447 - #define TWL6030_FIXED_LDO(label, offset, mVolts, num) \ 448 - TWL_FIXED_LDO(label, offset, mVolts, num, TWL6030) 417 + #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ 418 + TWL_ADJUSTABLE_LDO(label, offset, num, turnon_delay, \ 419 + remap_conf, TWL4030) 420 + #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ 421 + remap_conf) \ 422 + TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ 423 + remap_conf, TWL4030) 424 + #define TWL6030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, \ 425 + remap_conf) \ 426 + TWL_ADJUSTABLE_LDO(label, offset, num, turnon_delay, \ 427 + remap_conf, TWL6030) 428 + #define TWL6030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ 429 + remap_conf) \ 430 + TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ 431 + remap_conf, TWL6030) 449 432 450 - #define TWL_ADJUSTABLE_LDO(label, offset, num, family) { \ 433 + #define TWL_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf, \ 434 + family) { \ 451 435 .base = offset, \ 452 436 .id = num, \ 453 437 .table_len = ARRAY_SIZE(label##_VSEL_table), \ 454 438 .table = label##_VSEL_table, \ 439 + .delay = turnon_delay, \ 440 + .remap = remap_conf, \ 455 441 .desc = { \ 456 442 .name = #label, \ 457 443 .id = family##_REG_##label, \ ··· 472 438 }, \ 473 439 } 474 440 475 - #define TWL_FIXED_LDO(label, offset, mVolts, num, family) { \ 441 + #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ 442 + family) { \ 476 443 .base = offset, \ 477 444 .id = num, \ 478 445 .min_mV = mVolts, \ 446 + .delay = turnon_delay, \ 447 + .remap = remap_conf, \ 479 448 .desc = { \ 480 449 .name = #label, \ 481 450 .id = family##_REG_##label, \ ··· 494 457 * software control over them after boot. 495 458 */ 496 459 static struct twlreg_info twl_regs[] = { 497 - TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1), 498 - TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2), 499 - TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2), 500 - TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3), 501 - TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4), 502 - TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5), 503 - TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6), 504 - /* 505 - TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7), 506 - */ 507 - TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8), 508 - TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9), 509 - TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10), 510 - /* 511 - TWL4030_ADJUSTABLE_LDO(VINTANA1, 0x3f, 11), 512 - TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12), 513 - TWL4030_ADJUSTABLE_LDO(VINTDIG, 0x47, 13), 514 - TWL4030_SMPS(VIO, 0x4b, 14), 515 - TWL4030_SMPS(VDD1, 0x55, 15), 516 - TWL4030_SMPS(VDD2, 0x63, 16), 517 - */ 518 - TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17), 519 - TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18), 520 - TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19), 460 + TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08), 461 + TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08), 462 + TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08), 463 + TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08), 464 + TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08), 465 + TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08), 466 + TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08), 467 + TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00), 468 + TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08), 469 + TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00), 470 + TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08), 471 + TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08), 472 + TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08), 473 + TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08), 474 + TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08), 475 + TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08), 476 + TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08), 477 + TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08), 478 + TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08), 479 + TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08), 521 480 /* VUSBCP is managed *only* by the USB subchip */ 522 481 523 482 /* 6030 REG with base as PMC Slave Misc : 0x0030 */ 524 - TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1), 525 - TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 2), 526 - TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 3), 527 - TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 4), 528 - TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 5), 529 - TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 7), 530 - TWL6030_FIXED_LDO(VANA, 0x50, 2100, 15), 531 - TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 16), 532 - TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 17), 533 - TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 18) 483 + /* Turnon-delay and remap configuration values for 6030 are not 484 + verified since the specification is not public */ 485 + TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1, 0, 0x08), 486 + TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 2, 0, 0x08), 487 + TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 3, 0, 0x08), 488 + TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 4, 0, 0x08), 489 + TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 5, 0, 0x08), 490 + TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 7, 0, 0x08), 491 + TWL6030_FIXED_LDO(VANA, 0x50, 2100, 15, 0, 0x08), 492 + TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 16, 0, 0x08), 493 + TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 17, 0, 0x08), 494 + TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 18, 0, 0x08) 534 495 }; 535 496 536 497 static int twlreg_probe(struct platform_device *pdev) ··· 560 525 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE 561 526 | REGULATOR_CHANGE_MODE 562 527 | REGULATOR_CHANGE_STATUS; 528 + switch (pdev->id) { 529 + case TWL4030_REG_VIO: 530 + case TWL4030_REG_VDD1: 531 + case TWL4030_REG_VDD2: 532 + case TWL4030_REG_VPLL1: 533 + case TWL4030_REG_VINTANA1: 534 + case TWL4030_REG_VINTANA2: 535 + case TWL4030_REG_VINTDIG: 536 + c->always_on = true; 537 + break; 538 + default: 539 + break; 540 + } 563 541 564 542 rdev = regulator_register(&info->desc, &pdev->dev, initdata, info); 565 543 if (IS_ERR(rdev)) { ··· 581 533 return PTR_ERR(rdev); 582 534 } 583 535 platform_set_drvdata(pdev, rdev); 536 + 537 + twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP, 538 + info->remap); 584 539 585 540 /* NOTE: many regulators support short-circuit IRQs (presentable 586 541 * as REGULATOR_OVER_CURRENT notifications?) configured via:
+189 -18
drivers/regulator/wm831x-dcdc.c
··· 19 19 #include <linux/i2c.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/regulator/driver.h> 22 + #include <linux/regulator/machine.h> 23 + #include <linux/gpio.h> 22 24 23 25 #include <linux/mfd/wm831x/core.h> 24 26 #include <linux/mfd/wm831x/regulator.h> ··· 41 39 #define WM831X_DCDC_CONTROL_2 1 42 40 #define WM831X_DCDC_ON_CONFIG 2 43 41 #define WM831X_DCDC_SLEEP_CONTROL 3 42 + #define WM831X_DCDC_DVS_CONTROL 4 44 43 45 44 /* 46 45 * Shared ··· 53 50 int base; 54 51 struct wm831x *wm831x; 55 52 struct regulator_dev *regulator; 53 + int dvs_gpio; 54 + int dvs_gpio_state; 55 + int on_vsel; 56 + int dvs_vsel; 56 57 }; 57 58 58 59 static int wm831x_dcdc_is_enabled(struct regulator_dev *rdev) ··· 247 240 return -EINVAL; 248 241 } 249 242 250 - static int wm831x_buckv_set_voltage_int(struct regulator_dev *rdev, int reg, 251 - int min_uV, int max_uV) 243 + static int wm831x_buckv_select_min_voltage(struct regulator_dev *rdev, 244 + int min_uV, int max_uV) 252 245 { 253 - struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 254 - struct wm831x *wm831x = dcdc->wm831x; 255 246 u16 vsel; 256 247 257 248 if (min_uV < 600000) ··· 262 257 if (wm831x_buckv_list_voltage(rdev, vsel) > max_uV) 263 258 return -EINVAL; 264 259 265 - return wm831x_set_bits(wm831x, reg, WM831X_DC1_ON_VSEL_MASK, vsel); 260 + return vsel; 261 + } 262 + 263 + static int wm831x_buckv_select_max_voltage(struct regulator_dev *rdev, 264 + int min_uV, int max_uV) 265 + { 266 + u16 vsel; 267 + 268 + if (max_uV < 600000 || max_uV > 1800000) 269 + return -EINVAL; 270 + 271 + vsel = ((max_uV - 600000) / 12500) + 8; 272 + 273 + if (wm831x_buckv_list_voltage(rdev, vsel) < min_uV || 274 + wm831x_buckv_list_voltage(rdev, vsel) < max_uV) 275 + return -EINVAL; 276 + 277 + return vsel; 278 + } 279 + 280 + static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state) 281 + { 282 + struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 283 + 284 + if (state == dcdc->dvs_gpio_state) 285 + return 0; 286 + 287 + dcdc->dvs_gpio_state = state; 288 + gpio_set_value(dcdc->dvs_gpio, state); 289 + 290 + /* Should wait for DVS state change to be asserted if we have 291 + * a GPIO for it, for now assume the device is configured 292 + * for the fastest possible transition. 293 + */ 294 + 295 + return 0; 266 296 } 267 297 268 298 static int wm831x_buckv_set_voltage(struct regulator_dev *rdev, 269 - int min_uV, int max_uV) 299 + int min_uV, int max_uV) 270 300 { 271 301 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 272 - u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 302 + struct wm831x *wm831x = dcdc->wm831x; 303 + int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 304 + int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL; 305 + int vsel, ret; 273 306 274 - return wm831x_buckv_set_voltage_int(rdev, reg, min_uV, max_uV); 307 + vsel = wm831x_buckv_select_min_voltage(rdev, min_uV, max_uV); 308 + if (vsel < 0) 309 + return vsel; 310 + 311 + /* If this value is already set then do a GPIO update if we can */ 312 + if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) 313 + return wm831x_buckv_set_dvs(rdev, 0); 314 + 315 + if (dcdc->dvs_gpio && dcdc->dvs_vsel == vsel) 316 + return wm831x_buckv_set_dvs(rdev, 1); 317 + 318 + /* Always set the ON status to the minimum voltage */ 319 + ret = wm831x_set_bits(wm831x, on_reg, WM831X_DC1_ON_VSEL_MASK, vsel); 320 + if (ret < 0) 321 + return ret; 322 + dcdc->on_vsel = vsel; 323 + 324 + if (!dcdc->dvs_gpio) 325 + return ret; 326 + 327 + /* Kick the voltage transition now */ 328 + ret = wm831x_buckv_set_dvs(rdev, 0); 329 + if (ret < 0) 330 + return ret; 331 + 332 + /* Set the high voltage as the DVS voltage. This is optimised 333 + * for CPUfreq usage, most processors will keep the maximum 334 + * voltage constant and lower the minimum with the frequency. */ 335 + vsel = wm831x_buckv_select_max_voltage(rdev, min_uV, max_uV); 336 + if (vsel < 0) { 337 + /* This should never happen - at worst the same vsel 338 + * should be chosen */ 339 + WARN_ON(vsel < 0); 340 + return 0; 341 + } 342 + 343 + /* Don't bother if it's the same VSEL we're already using */ 344 + if (vsel == dcdc->on_vsel) 345 + return 0; 346 + 347 + ret = wm831x_set_bits(wm831x, dvs_reg, WM831X_DC1_DVS_VSEL_MASK, vsel); 348 + if (ret == 0) 349 + dcdc->dvs_vsel = vsel; 350 + else 351 + dev_warn(wm831x->dev, "Failed to set DCDC DVS VSEL: %d\n", 352 + ret); 353 + 354 + return 0; 275 355 } 276 356 277 357 static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev, 278 - int uV) 358 + int uV) 279 359 { 280 360 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 361 + struct wm831x *wm831x = dcdc->wm831x; 281 362 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 363 + int vsel; 282 364 283 - return wm831x_buckv_set_voltage_int(rdev, reg, uV, uV); 365 + vsel = wm831x_buckv_select_min_voltage(rdev, uV, uV); 366 + if (vsel < 0) 367 + return vsel; 368 + 369 + return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel); 284 370 } 285 371 286 372 static int wm831x_buckv_get_voltage(struct regulator_dev *rdev) 287 373 { 288 374 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 289 - struct wm831x *wm831x = dcdc->wm831x; 290 - u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 291 - int val; 292 375 293 - val = wm831x_reg_read(wm831x, reg); 294 - if (val < 0) 295 - return val; 296 - 297 - return wm831x_buckv_list_voltage(rdev, val & WM831X_DC1_ON_VSEL_MASK); 376 + if (dcdc->dvs_gpio && dcdc->dvs_gpio_state) 377 + return wm831x_buckv_list_voltage(rdev, dcdc->dvs_vsel); 378 + else 379 + return wm831x_buckv_list_voltage(rdev, dcdc->on_vsel); 298 380 } 299 381 300 382 /* Current limit options */ ··· 438 346 .set_suspend_mode = wm831x_dcdc_set_suspend_mode, 439 347 }; 440 348 349 + /* 350 + * Set up DVS control. We just log errors since we can still run 351 + * (with reduced performance) if we fail. 352 + */ 353 + static __devinit void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc, 354 + struct wm831x_buckv_pdata *pdata) 355 + { 356 + struct wm831x *wm831x = dcdc->wm831x; 357 + int ret; 358 + u16 ctrl; 359 + 360 + if (!pdata || !pdata->dvs_gpio) 361 + return; 362 + 363 + switch (pdata->dvs_control_src) { 364 + case 1: 365 + ctrl = 2 << WM831X_DC1_DVS_SRC_SHIFT; 366 + break; 367 + case 2: 368 + ctrl = 3 << WM831X_DC1_DVS_SRC_SHIFT; 369 + break; 370 + default: 371 + dev_err(wm831x->dev, "Invalid DVS control source %d for %s\n", 372 + pdata->dvs_control_src, dcdc->name); 373 + return; 374 + } 375 + 376 + ret = wm831x_set_bits(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL, 377 + WM831X_DC1_DVS_SRC_MASK, ctrl); 378 + if (ret < 0) { 379 + dev_err(wm831x->dev, "Failed to set %s DVS source: %d\n", 380 + dcdc->name, ret); 381 + return; 382 + } 383 + 384 + ret = gpio_request(pdata->dvs_gpio, "DCDC DVS"); 385 + if (ret < 0) { 386 + dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n", 387 + dcdc->name, ret); 388 + return; 389 + } 390 + 391 + /* gpiolib won't let us read the GPIO status so pick the higher 392 + * of the two existing voltages so we take it as platform data. 393 + */ 394 + dcdc->dvs_gpio_state = pdata->dvs_init_state; 395 + 396 + ret = gpio_direction_output(pdata->dvs_gpio, dcdc->dvs_gpio_state); 397 + if (ret < 0) { 398 + dev_err(wm831x->dev, "Failed to enable %s DVS GPIO: %d\n", 399 + dcdc->name, ret); 400 + gpio_free(pdata->dvs_gpio); 401 + return; 402 + } 403 + 404 + dcdc->dvs_gpio = pdata->dvs_gpio; 405 + } 406 + 441 407 static __devinit int wm831x_buckv_probe(struct platform_device *pdev) 442 408 { 443 409 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); ··· 533 383 dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1; 534 384 dcdc->desc.ops = &wm831x_buckv_ops; 535 385 dcdc->desc.owner = THIS_MODULE; 386 + 387 + ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG); 388 + if (ret < 0) { 389 + dev_err(wm831x->dev, "Failed to read ON VSEL: %d\n", ret); 390 + goto err; 391 + } 392 + dcdc->on_vsel = ret & WM831X_DC1_ON_VSEL_MASK; 393 + 394 + ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG); 395 + if (ret < 0) { 396 + dev_err(wm831x->dev, "Failed to read DVS VSEL: %d\n", ret); 397 + goto err; 398 + } 399 + dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK; 400 + 401 + if (pdata->dcdc[id]) 402 + wm831x_buckv_dvs_init(dcdc, pdata->dcdc[id]->driver_data); 536 403 537 404 dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev, 538 405 pdata->dcdc[id], dcdc); ··· 589 422 err_regulator: 590 423 regulator_unregister(dcdc->regulator); 591 424 err: 425 + if (dcdc->dvs_gpio) 426 + gpio_free(dcdc->dvs_gpio); 592 427 kfree(dcdc); 593 428 return ret; 594 429 } ··· 603 434 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "HC"), dcdc); 604 435 wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc); 605 436 regulator_unregister(dcdc->regulator); 437 + if (dcdc->dvs_gpio) 438 + gpio_free(dcdc->dvs_gpio); 606 439 kfree(dcdc); 607 440 608 441 return 0;
+1 -1
drivers/regulator/wm831x-ldo.c
··· 470 470 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 471 471 struct wm831x *wm831x = ldo->wm831x; 472 472 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; 473 - unsigned int ret; 473 + int ret; 474 474 475 475 ret = wm831x_reg_read(wm831x, on_reg); 476 476 if (ret < 0)
+17
include/linux/mfd/wm831x/pdata.h
··· 41 41 int timeout; /** Charge cycle timeout, in minutes */ 42 42 }; 43 43 44 + /** 45 + * Configuration for the WM831x DC-DC BuckWise convertors. This 46 + * should be passed as driver_data in the regulator_init_data. 47 + * 48 + * Currently all the configuration is for the fast DVS switching 49 + * support of the devices. This allows MFPs on the device to be 50 + * configured as an input to switch between two output voltages, 51 + * allowing voltage transitions without the expense of an access over 52 + * I2C or SPI buses. 53 + */ 54 + struct wm831x_buckv_pdata { 55 + int dvs_gpio; /** CPU GPIO to use for DVS switching */ 56 + int dvs_control_src; /** Hardware DVS source to use (1 or 2) */ 57 + int dvs_init_state; /** DVS state to expect on startup */ 58 + int dvs_state_gpio; /** CPU GPIO to use for monitoring status */ 59 + }; 60 + 44 61 /* Sources for status LED configuration. Values are register values 45 62 * plus 1 to allow for a zero default for preserve. 46 63 */
+2
include/linux/regulator/consumer.h
··· 35 35 #ifndef __LINUX_REGULATOR_CONSUMER_H_ 36 36 #define __LINUX_REGULATOR_CONSUMER_H_ 37 37 38 + #include <linux/device.h> 39 + 38 40 /* 39 41 * Regulator operating modes. 40 42 *
+5 -1
include/linux/regulator/machine.h
··· 43 43 /** 44 44 * struct regulator_state - regulator state during low power system states 45 45 * 46 - * This describes a regulators state during a system wide low power state. 46 + * This describes a regulators state during a system wide low power 47 + * state. One of enabled or disabled must be set for the 48 + * configuration to be applied. 47 49 * 48 50 * @uV: Operating voltage during suspend. 49 51 * @mode: Operating mode during suspend. 50 52 * @enabled: Enabled during suspend. 53 + * @disabled: Disabled during suspend. 51 54 */ 52 55 struct regulator_state { 53 56 int uV; /* suspend voltage */ 54 57 unsigned int mode; /* suspend regulator operating mode */ 55 58 int enabled; /* is regulator enabled in this suspend state */ 59 + int disabled; /* is the regulator disbled in this suspend state */ 56 60 }; 57 61 58 62 /**
+57
include/linux/regulator/max8660.h
··· 1 + /* 2 + * max8660.h -- Voltage regulation for the Maxim 8660/8661 3 + * 4 + * Copyright (C) 2009 Wolfram Sang, Pengutronix e.K. 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; version 2 of the License. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + * 15 + * You should have received a copy of the GNU General Public License 16 + * along with this program; if not, write to the Free Software 17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 + */ 19 + 20 + #ifndef __LINUX_REGULATOR_MAX8660_H 21 + #define __LINUX_REGULATOR_MAX8660_H 22 + 23 + #include <linux/regulator/machine.h> 24 + 25 + enum { 26 + MAX8660_V3, 27 + MAX8660_V4, 28 + MAX8660_V5, 29 + MAX8660_V6, 30 + MAX8660_V7, 31 + MAX8660_V_END, 32 + }; 33 + 34 + /** 35 + * max8660_subdev_data - regulator subdev data 36 + * @id: regulator id 37 + * @name: regulator name 38 + * @platform_data: regulator init data 39 + */ 40 + struct max8660_subdev_data { 41 + int id; 42 + char *name; 43 + struct regulator_init_data *platform_data; 44 + }; 45 + 46 + /** 47 + * max8660_platform_data - platform data for max8660 48 + * @num_subdevs: number of regulators used 49 + * @subdevs: pointer to regulators used 50 + * @en34_is_high: if EN34 is driven high, regulators cannot be en-/disabled. 51 + */ 52 + struct max8660_platform_data { 53 + int num_subdevs; 54 + struct max8660_subdev_data *subdevs; 55 + unsigned en34_is_high:1; 56 + }; 57 + #endif