Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: twl: split twl6030 logic into its own file

In order to not break existing users, we keep using the same
CONFIG symbol.
This makes it easier to add support for TWL6032 and refactor
mfd/twl-core.
Checkpatch warnings are inherited from twl-regulator.c and will
be addressed in a subsequent patch.

Signed-off-by: Nicolae Rosia <Nicolae_Rosia@mentor.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Nicolae Rosia and committed by
Mark Brown
cac28ae6 8313a4fb

+812 -596
+1
MAINTAINERS
··· 8721 8721 F: drivers/regulator/tps65218-regulator.c 8722 8722 F: drivers/regulator/tps65910-regulator.c 8723 8723 F: drivers/regulator/twl-regulator.c 8724 + F: drivers/regulator/twl6030-regulator.c 8724 8725 F: include/linux/i2c-omap.h 8725 8726 8726 8727 OMAP DEVICE TREE SUPPORT
+1 -1
drivers/regulator/Makefile
··· 104 104 obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o 105 105 obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o 106 106 obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o 107 - obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o 107 + obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o 108 108 obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress-regulator.o 109 109 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o 110 110 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o
+5 -595
drivers/regulator/twl-regulator.c
··· 24 24 #include <linux/delay.h> 25 25 26 26 /* 27 - * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a 27 + * The TWL4030/TW5030/TPS659x0 family chips include power management, a 28 28 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions 29 29 * include an audio codec, battery charger, and more voltage regulators. 30 30 * These chips are often used in OMAP-based systems. ··· 81 81 #define VREG_STATE 2 82 82 #define VREG_VOLTAGE 3 83 83 #define VREG_VOLTAGE_SMPS 4 84 - /* TWL6030 Misc register offsets */ 85 - #define VREG_BC_ALL 1 86 - #define VREG_BC_REF 2 87 - #define VREG_BC_PROC 3 88 - #define VREG_BC_CLK_RST 4 89 - 90 - /* TWL6030 LDO register values for CFG_STATE */ 91 - #define TWL6030_CFG_STATE_OFF 0x00 92 - #define TWL6030_CFG_STATE_ON 0x01 93 - #define TWL6030_CFG_STATE_OFF2 0x02 94 - #define TWL6030_CFG_STATE_SLEEP 0x03 95 - #define TWL6030_CFG_STATE_GRP_SHIFT 5 96 - #define TWL6030_CFG_STATE_APP_SHIFT 2 97 - #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT) 98 - #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\ 99 - TWL6030_CFG_STATE_APP_SHIFT) 100 - 101 - /* Flags for SMPS Voltage reading */ 102 - #define SMPS_OFFSET_EN BIT(0) 103 - #define SMPS_EXTENDED_EN BIT(1) 104 - 105 - /* twl6032 SMPS EPROM values */ 106 - #define TWL6030_SMPS_OFFSET 0xB0 107 - #define TWL6030_SMPS_MULT 0xB3 108 - #define SMPS_MULTOFFSET_SMPS4 BIT(0) 109 - #define SMPS_MULTOFFSET_VIO BIT(1) 110 - #define SMPS_MULTOFFSET_SMPS3 BIT(6) 111 84 112 85 static inline int 113 86 twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset) ··· 132 159 return state; 133 160 134 161 return state & P1_GRP_4030; 135 - } 136 - 137 - static int twl6030reg_is_enabled(struct regulator_dev *rdev) 138 - { 139 - struct twlreg_info *info = rdev_get_drvdata(rdev); 140 - int grp = 0, val; 141 - 142 - if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) { 143 - grp = twlreg_grp(rdev); 144 - if (grp < 0) 145 - return grp; 146 - grp &= P1_GRP_6030; 147 - } else { 148 - grp = 1; 149 - } 150 - 151 - val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); 152 - val = TWL6030_CFG_STATE_APP(val); 153 - 154 - return grp && (val == TWL6030_CFG_STATE_ON); 155 162 } 156 163 157 164 #define PB_I2C_BUSY BIT(0) ··· 219 266 return ret; 220 267 } 221 268 222 - static int twl6030reg_enable(struct regulator_dev *rdev) 223 - { 224 - struct twlreg_info *info = rdev_get_drvdata(rdev); 225 - int grp = 0; 226 - int ret; 227 - 228 - if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) 229 - grp = twlreg_grp(rdev); 230 - if (grp < 0) 231 - return grp; 232 - 233 - ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, 234 - grp << TWL6030_CFG_STATE_GRP_SHIFT | 235 - TWL6030_CFG_STATE_ON); 236 - return ret; 237 - } 238 - 239 269 static int twl4030reg_disable(struct regulator_dev *rdev) 240 270 { 241 271 struct twlreg_info *info = rdev_get_drvdata(rdev); ··· 232 296 grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030); 233 297 234 298 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); 235 - 236 - return ret; 237 - } 238 - 239 - static int twl6030reg_disable(struct regulator_dev *rdev) 240 - { 241 - struct twlreg_info *info = rdev_get_drvdata(rdev); 242 - int grp = 0; 243 - int ret; 244 - 245 - if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) 246 - grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030; 247 - 248 - /* For 6030, set the off state for all grps enabled */ 249 - ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, 250 - (grp) << TWL6030_CFG_STATE_GRP_SHIFT | 251 - TWL6030_CFG_STATE_OFF); 252 299 253 300 return ret; 254 301 } ··· 250 331 return (state & BIT(3)) 251 332 ? REGULATOR_STATUS_NORMAL 252 333 : REGULATOR_STATUS_STANDBY; 253 - } 254 - 255 - static int twl6030reg_get_status(struct regulator_dev *rdev) 256 - { 257 - struct twlreg_info *info = rdev_get_drvdata(rdev); 258 - int val; 259 - 260 - val = twlreg_grp(rdev); 261 - if (val < 0) 262 - return val; 263 - 264 - val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); 265 - 266 - switch (TWL6030_CFG_STATE_APP(val)) { 267 - case TWL6030_CFG_STATE_ON: 268 - return REGULATOR_STATUS_NORMAL; 269 - 270 - case TWL6030_CFG_STATE_SLEEP: 271 - return REGULATOR_STATUS_STANDBY; 272 - 273 - case TWL6030_CFG_STATE_OFF: 274 - case TWL6030_CFG_STATE_OFF2: 275 - default: 276 - break; 277 - } 278 - 279 - return REGULATOR_STATUS_OFF; 280 334 } 281 335 282 336 static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode) ··· 282 390 default: 283 391 return -EINVAL; 284 392 } 285 - } 286 - 287 - static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode) 288 - { 289 - struct twlreg_info *info = rdev_get_drvdata(rdev); 290 - int grp = 0; 291 - int val; 292 - 293 - if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) 294 - grp = twlreg_grp(rdev); 295 - 296 - if (grp < 0) 297 - return grp; 298 - 299 - /* Compose the state register settings */ 300 - val = grp << TWL6030_CFG_STATE_GRP_SHIFT; 301 - /* We can only set the mode through state machine commands... */ 302 - switch (mode) { 303 - case REGULATOR_MODE_NORMAL: 304 - val |= TWL6030_CFG_STATE_ON; 305 - break; 306 - case REGULATOR_MODE_STANDBY: 307 - val |= TWL6030_CFG_STATE_SLEEP; 308 - break; 309 - 310 - default: 311 - return -EINVAL; 312 - } 313 - 314 - return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val); 315 393 } 316 394 317 395 /*----------------------------------------------------------------------*/ ··· 441 579 .get_voltage = twl4030smps_get_voltage, 442 580 }; 443 581 444 - static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV, 445 - int max_uV, unsigned *selector) 446 - { 447 - return -ENODEV; 448 - } 449 - 450 - static int twl6030coresmps_get_voltage(struct regulator_dev *rdev) 451 - { 452 - return -ENODEV; 453 - } 454 - 455 - static struct regulator_ops twl6030coresmps_ops = { 456 - .set_voltage = twl6030coresmps_set_voltage, 457 - .get_voltage = twl6030coresmps_get_voltage, 458 - }; 459 - 460 - static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel) 461 - { 462 - struct twlreg_info *info = rdev_get_drvdata(rdev); 463 - 464 - switch (sel) { 465 - case 0: 466 - return 0; 467 - case 1 ... 24: 468 - /* Linear mapping from 00000001 to 00011000: 469 - * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001) 470 - */ 471 - return (info->min_mV + 100 * (sel - 1)) * 1000; 472 - case 25 ... 30: 473 - return -EINVAL; 474 - case 31: 475 - return 2750000; 476 - default: 477 - return -EINVAL; 478 - } 479 - } 480 - 481 - static int 482 - twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) 483 - { 484 - struct twlreg_info *info = rdev_get_drvdata(rdev); 485 - 486 - return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, 487 - selector); 488 - } 489 - 490 - static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev) 491 - { 492 - struct twlreg_info *info = rdev_get_drvdata(rdev); 493 - int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE); 494 - 495 - return vsel; 496 - } 497 - 498 - static struct regulator_ops twl6030ldo_ops = { 499 - .list_voltage = twl6030ldo_list_voltage, 500 - 501 - .set_voltage_sel = twl6030ldo_set_voltage_sel, 502 - .get_voltage_sel = twl6030ldo_get_voltage_sel, 503 - 504 - .enable = twl6030reg_enable, 505 - .disable = twl6030reg_disable, 506 - .is_enabled = twl6030reg_is_enabled, 507 - 508 - .set_mode = twl6030reg_set_mode, 509 - 510 - .get_status = twl6030reg_get_status, 511 - }; 512 - 513 582 /*----------------------------------------------------------------------*/ 514 583 515 584 static struct regulator_ops twl4030fixed_ops = { ··· 453 660 .set_mode = twl4030reg_set_mode, 454 661 455 662 .get_status = twl4030reg_get_status, 456 - }; 457 - 458 - static struct regulator_ops twl6030fixed_ops = { 459 - .list_voltage = regulator_list_voltage_linear, 460 - 461 - .enable = twl6030reg_enable, 462 - .disable = twl6030reg_disable, 463 - .is_enabled = twl6030reg_is_enabled, 464 - 465 - .set_mode = twl6030reg_set_mode, 466 - 467 - .get_status = twl6030reg_get_status, 468 - }; 469 - 470 - /* 471 - * SMPS status and control 472 - */ 473 - 474 - static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index) 475 - { 476 - struct twlreg_info *info = rdev_get_drvdata(rdev); 477 - 478 - int voltage = 0; 479 - 480 - switch (info->flags) { 481 - case SMPS_OFFSET_EN: 482 - voltage = 100000; 483 - /* fall through */ 484 - case 0: 485 - switch (index) { 486 - case 0: 487 - voltage = 0; 488 - break; 489 - case 58: 490 - voltage = 1350 * 1000; 491 - break; 492 - case 59: 493 - voltage = 1500 * 1000; 494 - break; 495 - case 60: 496 - voltage = 1800 * 1000; 497 - break; 498 - case 61: 499 - voltage = 1900 * 1000; 500 - break; 501 - case 62: 502 - voltage = 2100 * 1000; 503 - break; 504 - default: 505 - voltage += (600000 + (12500 * (index - 1))); 506 - } 507 - break; 508 - case SMPS_EXTENDED_EN: 509 - switch (index) { 510 - case 0: 511 - voltage = 0; 512 - break; 513 - case 58: 514 - voltage = 2084 * 1000; 515 - break; 516 - case 59: 517 - voltage = 2315 * 1000; 518 - break; 519 - case 60: 520 - voltage = 2778 * 1000; 521 - break; 522 - case 61: 523 - voltage = 2932 * 1000; 524 - break; 525 - case 62: 526 - voltage = 3241 * 1000; 527 - break; 528 - default: 529 - voltage = (1852000 + (38600 * (index - 1))); 530 - } 531 - break; 532 - case SMPS_OFFSET_EN | SMPS_EXTENDED_EN: 533 - switch (index) { 534 - case 0: 535 - voltage = 0; 536 - break; 537 - case 58: 538 - voltage = 4167 * 1000; 539 - break; 540 - case 59: 541 - voltage = 2315 * 1000; 542 - break; 543 - case 60: 544 - voltage = 2778 * 1000; 545 - break; 546 - case 61: 547 - voltage = 2932 * 1000; 548 - break; 549 - case 62: 550 - voltage = 3241 * 1000; 551 - break; 552 - default: 553 - voltage = (2161000 + (38600 * (index - 1))); 554 - } 555 - break; 556 - } 557 - 558 - return voltage; 559 - } 560 - 561 - static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV, 562 - int max_uV) 563 - { 564 - struct twlreg_info *info = rdev_get_drvdata(rdev); 565 - int vsel = 0; 566 - 567 - switch (info->flags) { 568 - case 0: 569 - if (min_uV == 0) 570 - vsel = 0; 571 - else if ((min_uV >= 600000) && (min_uV <= 1300000)) { 572 - vsel = DIV_ROUND_UP(min_uV - 600000, 12500); 573 - vsel++; 574 - } 575 - /* Values 1..57 for vsel are linear and can be calculated 576 - * values 58..62 are non linear. 577 - */ 578 - else if ((min_uV > 1900000) && (min_uV <= 2100000)) 579 - vsel = 62; 580 - else if ((min_uV > 1800000) && (min_uV <= 1900000)) 581 - vsel = 61; 582 - else if ((min_uV > 1500000) && (min_uV <= 1800000)) 583 - vsel = 60; 584 - else if ((min_uV > 1350000) && (min_uV <= 1500000)) 585 - vsel = 59; 586 - else if ((min_uV > 1300000) && (min_uV <= 1350000)) 587 - vsel = 58; 588 - else 589 - return -EINVAL; 590 - break; 591 - case SMPS_OFFSET_EN: 592 - if (min_uV == 0) 593 - vsel = 0; 594 - else if ((min_uV >= 700000) && (min_uV <= 1420000)) { 595 - vsel = DIV_ROUND_UP(min_uV - 700000, 12500); 596 - vsel++; 597 - } 598 - /* Values 1..57 for vsel are linear and can be calculated 599 - * values 58..62 are non linear. 600 - */ 601 - else if ((min_uV > 1900000) && (min_uV <= 2100000)) 602 - vsel = 62; 603 - else if ((min_uV > 1800000) && (min_uV <= 1900000)) 604 - vsel = 61; 605 - else if ((min_uV > 1350000) && (min_uV <= 1800000)) 606 - vsel = 60; 607 - else if ((min_uV > 1350000) && (min_uV <= 1500000)) 608 - vsel = 59; 609 - else if ((min_uV > 1300000) && (min_uV <= 1350000)) 610 - vsel = 58; 611 - else 612 - return -EINVAL; 613 - break; 614 - case SMPS_EXTENDED_EN: 615 - if (min_uV == 0) { 616 - vsel = 0; 617 - } else if ((min_uV >= 1852000) && (max_uV <= 4013600)) { 618 - vsel = DIV_ROUND_UP(min_uV - 1852000, 38600); 619 - vsel++; 620 - } 621 - break; 622 - case SMPS_OFFSET_EN|SMPS_EXTENDED_EN: 623 - if (min_uV == 0) { 624 - vsel = 0; 625 - } else if ((min_uV >= 2161000) && (min_uV <= 4321000)) { 626 - vsel = DIV_ROUND_UP(min_uV - 2161000, 38600); 627 - vsel++; 628 - } 629 - break; 630 - } 631 - 632 - return vsel; 633 - } 634 - 635 - static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev, 636 - unsigned int selector) 637 - { 638 - struct twlreg_info *info = rdev_get_drvdata(rdev); 639 - 640 - return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS, 641 - selector); 642 - } 643 - 644 - static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev) 645 - { 646 - struct twlreg_info *info = rdev_get_drvdata(rdev); 647 - 648 - return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS); 649 - } 650 - 651 - static struct regulator_ops twlsmps_ops = { 652 - .list_voltage = twl6030smps_list_voltage, 653 - .map_voltage = twl6030smps_map_voltage, 654 - 655 - .set_voltage_sel = twl6030smps_set_voltage_sel, 656 - .get_voltage_sel = twl6030smps_get_voltage_sel, 657 - 658 - .enable = twl6030reg_enable, 659 - .disable = twl6030reg_disable, 660 - .is_enabled = twl6030reg_is_enabled, 661 - 662 - .set_mode = twl6030reg_set_mode, 663 - 664 - .get_status = twl6030reg_get_status, 665 663 }; 666 664 667 665 /*----------------------------------------------------------------------*/ ··· 492 908 }, \ 493 909 } 494 910 495 - #define TWL6030_ADJUSTABLE_SMPS(label) \ 496 - static const struct twlreg_info TWL6030_INFO_##label = { \ 497 - .desc = { \ 498 - .name = #label, \ 499 - .id = TWL6030_REG_##label, \ 500 - .ops = &twl6030coresmps_ops, \ 501 - .type = REGULATOR_VOLTAGE, \ 502 - .owner = THIS_MODULE, \ 503 - }, \ 504 - } 505 - 506 - #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 507 - static const struct twlreg_info TWL6030_INFO_##label = { \ 508 - .base = offset, \ 509 - .min_mV = min_mVolts, \ 510 - .max_mV = max_mVolts, \ 511 - .desc = { \ 512 - .name = #label, \ 513 - .id = TWL6030_REG_##label, \ 514 - .n_voltages = 32, \ 515 - .ops = &twl6030ldo_ops, \ 516 - .type = REGULATOR_VOLTAGE, \ 517 - .owner = THIS_MODULE, \ 518 - }, \ 519 - } 520 - 521 - #define TWL6032_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 522 - static const struct twlreg_info TWL6032_INFO_##label = { \ 523 - .base = offset, \ 524 - .min_mV = min_mVolts, \ 525 - .max_mV = max_mVolts, \ 526 - .desc = { \ 527 - .name = #label, \ 528 - .id = TWL6032_REG_##label, \ 529 - .n_voltages = 32, \ 530 - .ops = &twl6030ldo_ops, \ 531 - .type = REGULATOR_VOLTAGE, \ 532 - .owner = THIS_MODULE, \ 533 - }, \ 534 - } 535 - 536 - #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \ 537 - static const struct twlreg_info TWLFIXED_INFO_##label = { \ 538 - .base = offset, \ 539 - .id = 0, \ 540 - .min_mV = mVolts, \ 541 - .remap = 0, \ 542 - .desc = { \ 543 - .name = #label, \ 544 - .id = TWL6030##_REG_##label, \ 545 - .n_voltages = 1, \ 546 - .ops = &twl6030fixed_ops, \ 547 - .type = REGULATOR_VOLTAGE, \ 548 - .owner = THIS_MODULE, \ 549 - .min_uV = mVolts * 1000, \ 550 - .enable_time = turnon_delay, \ 551 - .of_map_mode = NULL, \ 552 - }, \ 553 - } 554 - 555 911 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ 556 912 remap_conf) \ 557 913 static const struct twlreg_info TWLFIXED_INFO_##label = { \ ··· 509 985 .min_uV = mVolts * 1000, \ 510 986 .enable_time = turnon_delay, \ 511 987 .of_map_mode = twl4030reg_map_mode, \ 512 - }, \ 513 - } 514 - 515 - #define TWL6032_ADJUSTABLE_SMPS(label, offset) \ 516 - static const struct twlreg_info TWLSMPS_INFO_##label = { \ 517 - .base = offset, \ 518 - .min_mV = 600, \ 519 - .max_mV = 2100, \ 520 - .desc = { \ 521 - .name = #label, \ 522 - .id = TWL6032_REG_##label, \ 523 - .n_voltages = 63, \ 524 - .ops = &twlsmps_ops, \ 525 - .type = REGULATOR_VOLTAGE, \ 526 - .owner = THIS_MODULE, \ 527 988 }, \ 528 989 } 529 990 ··· 532 1023 TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08); 533 1024 TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08); 534 1025 /* VUSBCP is managed *only* by the USB subchip */ 535 - /* 6030 REG with base as PMC Slave Misc : 0x0030 */ 536 - /* Turnon-delay and remap configuration values for 6030 are not 537 - verified since the specification is not public */ 538 - TWL6030_ADJUSTABLE_SMPS(VDD1); 539 - TWL6030_ADJUSTABLE_SMPS(VDD2); 540 - TWL6030_ADJUSTABLE_SMPS(VDD3); 541 - TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300); 542 - TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300); 543 - TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300); 544 - TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300); 545 - TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300); 546 - TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300); 547 - /* 6025 are renamed compared to 6030 versions */ 548 - TWL6032_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300); 549 - TWL6032_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300); 550 - TWL6032_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300); 551 - TWL6032_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300); 552 - TWL6032_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300); 553 - TWL6032_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300); 554 - TWL6032_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300); 555 - TWL6032_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300); 556 - TWL6032_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300); 557 1026 TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08); 558 1027 TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08); 559 1028 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08); 560 1029 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08); 561 1030 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08); 562 - TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0); 563 - TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0); 564 - TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0); 565 - TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0); 566 - TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0); 567 - TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0); 568 - TWL6032_ADJUSTABLE_SMPS(SMPS3, 0x34); 569 - TWL6032_ADJUSTABLE_SMPS(SMPS4, 0x10); 570 - TWL6032_ADJUSTABLE_SMPS(VIO, 0x16); 571 - 572 - static u8 twl_get_smps_offset(void) 573 - { 574 - u8 value; 575 - 576 - twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value, 577 - TWL6030_SMPS_OFFSET); 578 - return value; 579 - } 580 - 581 - static u8 twl_get_smps_mult(void) 582 - { 583 - u8 value; 584 - 585 - twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value, 586 - TWL6030_SMPS_MULT); 587 - return value; 588 - } 589 1031 590 1032 #define TWL_OF_MATCH(comp, family, label) \ 591 1033 { \ ··· 566 1106 TWL4030_OF_MATCH("ti,twl4030-vio", VIO), 567 1107 TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1), 568 1108 TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2), 569 - TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1), 570 - TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2), 571 - TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3), 572 - TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030), 573 - TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030), 574 - TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030), 575 - TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC), 576 - TWL6030_OF_MATCH("ti,twl6030-vpp", VPP), 577 - TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM), 578 - TWL6032_OF_MATCH("ti,twl6032-ldo2", LDO2), 579 - TWL6032_OF_MATCH("ti,twl6032-ldo4", LDO4), 580 - TWL6032_OF_MATCH("ti,twl6032-ldo3", LDO3), 581 - TWL6032_OF_MATCH("ti,twl6032-ldo5", LDO5), 582 - TWL6032_OF_MATCH("ti,twl6032-ldo1", LDO1), 583 - TWL6032_OF_MATCH("ti,twl6032-ldo7", LDO7), 584 - TWL6032_OF_MATCH("ti,twl6032-ldo6", LDO6), 585 - TWL6032_OF_MATCH("ti,twl6032-ldoln", LDOLN), 586 - TWL6032_OF_MATCH("ti,twl6032-ldousb", LDOUSB), 587 1109 TWLFIXED_OF_MATCH("ti,twl4030-vintana1", VINTANA1), 588 1110 TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG), 589 1111 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5), 590 1112 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8), 591 1113 TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1), 592 - TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA), 593 - TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO), 594 - TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC), 595 - TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB), 596 - TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8), 597 - TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1), 598 - TWLSMPS_OF_MATCH("ti,twl6032-smps3", SMPS3), 599 - TWLSMPS_OF_MATCH("ti,twl6032-smps4", SMPS4), 600 - TWLSMPS_OF_MATCH("ti,twl6032-vio", VIO), 601 1114 {}, 602 1115 }; 603 1116 MODULE_DEVICE_TABLE(of, twl_of_match); ··· 626 1193 break; 627 1194 } 628 1195 629 - switch (id) { 630 - case TWL6032_REG_SMPS3: 631 - if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3) 632 - info->flags |= SMPS_EXTENDED_EN; 633 - if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3) 634 - info->flags |= SMPS_OFFSET_EN; 635 - break; 636 - case TWL6032_REG_SMPS4: 637 - if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4) 638 - info->flags |= SMPS_EXTENDED_EN; 639 - if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4) 640 - info->flags |= SMPS_OFFSET_EN; 641 - break; 642 - case TWL6032_REG_VIO: 643 - if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO) 644 - info->flags |= SMPS_EXTENDED_EN; 645 - if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO) 646 - info->flags |= SMPS_OFFSET_EN; 647 - break; 648 - } 649 - 650 1196 config.dev = &pdev->dev; 651 1197 config.init_data = initdata; 652 1198 config.driver_data = info; ··· 639 1227 } 640 1228 platform_set_drvdata(pdev, rdev); 641 1229 642 - if (twl_class_is_4030()) 643 - twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP, 644 - info->remap); 1230 + twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP, info->remap); 645 1231 646 1232 /* NOTE: many regulators support short-circuit IRQs (presentable 647 1233 * as REGULATOR_OVER_CURRENT notifications?) configured via: ··· 652 1242 return 0; 653 1243 } 654 1244 655 - MODULE_ALIAS("platform:twl_reg"); 1245 + MODULE_ALIAS("platform:twl4030_reg"); 656 1246 657 1247 static struct platform_driver twlreg_driver = { 658 1248 .probe = twlreg_probe, ··· 660 1250 * "twl_regulator.12" (and friends) to "twl_regulator.1". 661 1251 */ 662 1252 .driver = { 663 - .name = "twl_reg", 1253 + .name = "twl4030_reg", 664 1254 .of_match_table = of_match_ptr(twl_of_match), 665 1255 }, 666 1256 }; ··· 677 1267 } 678 1268 module_exit(twlreg_exit) 679 1269 680 - MODULE_DESCRIPTION("TWL regulator driver"); 1270 + MODULE_DESCRIPTION("TWL4030 regulator driver"); 681 1271 MODULE_LICENSE("GPL");
+805
drivers/regulator/twl6030-regulator.c
··· 1 + /* 2 + * Split TWL6030 logic from twl-regulator.c: 3 + * Copyright (C) 2008 David Brownell 4 + * 5 + * Copyright (C) 2016 Nicolae Rosia <nicolae.rosia@gmail.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + */ 12 + 13 + #include <linux/module.h> 14 + #include <linux/string.h> 15 + #include <linux/slab.h> 16 + #include <linux/init.h> 17 + #include <linux/err.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/of.h> 20 + #include <linux/of_device.h> 21 + #include <linux/regulator/driver.h> 22 + #include <linux/regulator/machine.h> 23 + #include <linux/regulator/of_regulator.h> 24 + #include <linux/i2c/twl.h> 25 + #include <linux/delay.h> 26 + 27 + struct twlreg_info { 28 + /* start of regulator's PM_RECEIVER control register bank */ 29 + u8 base; 30 + 31 + /* twl resource ID, for resource control state machine */ 32 + u8 id; 33 + 34 + /* voltage in mV = table[VSEL]; table_len must be a power-of-two */ 35 + u8 table_len; 36 + const u16 *table; 37 + 38 + /* State REMAP default configuration */ 39 + u8 remap; 40 + 41 + /* chip constraints on regulator behavior */ 42 + u16 min_mV; 43 + u16 max_mV; 44 + 45 + u8 flags; 46 + 47 + /* used by regulator core */ 48 + struct regulator_desc desc; 49 + 50 + /* chip specific features */ 51 + unsigned long features; 52 + 53 + /* data passed from board for external get/set voltage */ 54 + void *data; 55 + }; 56 + 57 + 58 + /* LDO control registers ... offset is from the base of its register bank. 59 + * The first three registers of all power resource banks help hardware to 60 + * manage the various resource groups. 61 + */ 62 + /* Common offset in TWL4030/6030 */ 63 + #define VREG_GRP 0 64 + /* TWL6030 register offsets */ 65 + #define VREG_TRANS 1 66 + #define VREG_STATE 2 67 + #define VREG_VOLTAGE 3 68 + #define VREG_VOLTAGE_SMPS 4 69 + /* TWL6030 Misc register offsets */ 70 + #define VREG_BC_ALL 1 71 + #define VREG_BC_REF 2 72 + #define VREG_BC_PROC 3 73 + #define VREG_BC_CLK_RST 4 74 + 75 + /* TWL6030 LDO register values for CFG_STATE */ 76 + #define TWL6030_CFG_STATE_OFF 0x00 77 + #define TWL6030_CFG_STATE_ON 0x01 78 + #define TWL6030_CFG_STATE_OFF2 0x02 79 + #define TWL6030_CFG_STATE_SLEEP 0x03 80 + #define TWL6030_CFG_STATE_GRP_SHIFT 5 81 + #define TWL6030_CFG_STATE_APP_SHIFT 2 82 + #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT) 83 + #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\ 84 + TWL6030_CFG_STATE_APP_SHIFT) 85 + 86 + /* Flags for SMPS Voltage reading */ 87 + #define SMPS_OFFSET_EN BIT(0) 88 + #define SMPS_EXTENDED_EN BIT(1) 89 + 90 + /* twl6032 SMPS EPROM values */ 91 + #define TWL6030_SMPS_OFFSET 0xB0 92 + #define TWL6030_SMPS_MULT 0xB3 93 + #define SMPS_MULTOFFSET_SMPS4 BIT(0) 94 + #define SMPS_MULTOFFSET_VIO BIT(1) 95 + #define SMPS_MULTOFFSET_SMPS3 BIT(6) 96 + 97 + static inline int 98 + twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset) 99 + { 100 + u8 value; 101 + int status; 102 + 103 + status = twl_i2c_read_u8(slave_subgp, 104 + &value, info->base + offset); 105 + return (status < 0) ? status : value; 106 + } 107 + 108 + static inline int 109 + twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset, 110 + u8 value) 111 + { 112 + return twl_i2c_write_u8(slave_subgp, 113 + value, info->base + offset); 114 + } 115 + 116 + /* generic power resource operations, which work on all regulators */ 117 + static int twlreg_grp(struct regulator_dev *rdev) 118 + { 119 + return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER, 120 + VREG_GRP); 121 + } 122 + 123 + /* 124 + * Enable/disable regulators by joining/leaving the P1 (processor) group. 125 + * We assume nobody else is updating the DEV_GRP registers. 126 + */ 127 + /* definition for 6030 family */ 128 + #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */ 129 + #define P2_GRP_6030 BIT(1) /* "peripherals" */ 130 + #define P1_GRP_6030 BIT(0) /* CPU/Linux */ 131 + 132 + static int twl6030reg_is_enabled(struct regulator_dev *rdev) 133 + { 134 + struct twlreg_info *info = rdev_get_drvdata(rdev); 135 + int grp = 0, val; 136 + 137 + if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) { 138 + grp = twlreg_grp(rdev); 139 + if (grp < 0) 140 + return grp; 141 + grp &= P1_GRP_6030; 142 + } else { 143 + grp = 1; 144 + } 145 + 146 + val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); 147 + val = TWL6030_CFG_STATE_APP(val); 148 + 149 + return grp && (val == TWL6030_CFG_STATE_ON); 150 + } 151 + 152 + #define PB_I2C_BUSY BIT(0) 153 + #define PB_I2C_BWEN BIT(1) 154 + 155 + 156 + static int twl6030reg_enable(struct regulator_dev *rdev) 157 + { 158 + struct twlreg_info *info = rdev_get_drvdata(rdev); 159 + int grp = 0; 160 + int ret; 161 + 162 + if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) 163 + grp = twlreg_grp(rdev); 164 + if (grp < 0) 165 + return grp; 166 + 167 + ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, 168 + grp << TWL6030_CFG_STATE_GRP_SHIFT | 169 + TWL6030_CFG_STATE_ON); 170 + return ret; 171 + } 172 + 173 + static int twl6030reg_disable(struct regulator_dev *rdev) 174 + { 175 + struct twlreg_info *info = rdev_get_drvdata(rdev); 176 + int grp = 0; 177 + int ret; 178 + 179 + if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) 180 + grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030; 181 + 182 + /* For 6030, set the off state for all grps enabled */ 183 + ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, 184 + (grp) << TWL6030_CFG_STATE_GRP_SHIFT | 185 + TWL6030_CFG_STATE_OFF); 186 + 187 + return ret; 188 + } 189 + 190 + static int twl6030reg_get_status(struct regulator_dev *rdev) 191 + { 192 + struct twlreg_info *info = rdev_get_drvdata(rdev); 193 + int val; 194 + 195 + val = twlreg_grp(rdev); 196 + if (val < 0) 197 + return val; 198 + 199 + val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); 200 + 201 + switch (TWL6030_CFG_STATE_APP(val)) { 202 + case TWL6030_CFG_STATE_ON: 203 + return REGULATOR_STATUS_NORMAL; 204 + 205 + case TWL6030_CFG_STATE_SLEEP: 206 + return REGULATOR_STATUS_STANDBY; 207 + 208 + case TWL6030_CFG_STATE_OFF: 209 + case TWL6030_CFG_STATE_OFF2: 210 + default: 211 + break; 212 + } 213 + 214 + return REGULATOR_STATUS_OFF; 215 + } 216 + 217 + static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode) 218 + { 219 + struct twlreg_info *info = rdev_get_drvdata(rdev); 220 + int grp = 0; 221 + int val; 222 + 223 + if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) 224 + grp = twlreg_grp(rdev); 225 + 226 + if (grp < 0) 227 + return grp; 228 + 229 + /* Compose the state register settings */ 230 + val = grp << TWL6030_CFG_STATE_GRP_SHIFT; 231 + /* We can only set the mode through state machine commands... */ 232 + switch (mode) { 233 + case REGULATOR_MODE_NORMAL: 234 + val |= TWL6030_CFG_STATE_ON; 235 + break; 236 + case REGULATOR_MODE_STANDBY: 237 + val |= TWL6030_CFG_STATE_SLEEP; 238 + break; 239 + 240 + default: 241 + return -EINVAL; 242 + } 243 + 244 + return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val); 245 + } 246 + 247 + static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV, 248 + int max_uV, unsigned *selector) 249 + { 250 + return -ENODEV; 251 + } 252 + 253 + static int twl6030coresmps_get_voltage(struct regulator_dev *rdev) 254 + { 255 + return -ENODEV; 256 + } 257 + 258 + static struct regulator_ops twl6030coresmps_ops = { 259 + .set_voltage = twl6030coresmps_set_voltage, 260 + .get_voltage = twl6030coresmps_get_voltage, 261 + }; 262 + 263 + static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel) 264 + { 265 + struct twlreg_info *info = rdev_get_drvdata(rdev); 266 + 267 + switch (sel) { 268 + case 0: 269 + return 0; 270 + case 1 ... 24: 271 + /* Linear mapping from 00000001 to 00011000: 272 + * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001) 273 + */ 274 + return (info->min_mV + 100 * (sel - 1)) * 1000; 275 + case 25 ... 30: 276 + return -EINVAL; 277 + case 31: 278 + return 2750000; 279 + default: 280 + return -EINVAL; 281 + } 282 + } 283 + 284 + static int 285 + twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) 286 + { 287 + struct twlreg_info *info = rdev_get_drvdata(rdev); 288 + 289 + return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, 290 + selector); 291 + } 292 + 293 + static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev) 294 + { 295 + struct twlreg_info *info = rdev_get_drvdata(rdev); 296 + int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE); 297 + 298 + return vsel; 299 + } 300 + 301 + static struct regulator_ops twl6030ldo_ops = { 302 + .list_voltage = twl6030ldo_list_voltage, 303 + 304 + .set_voltage_sel = twl6030ldo_set_voltage_sel, 305 + .get_voltage_sel = twl6030ldo_get_voltage_sel, 306 + 307 + .enable = twl6030reg_enable, 308 + .disable = twl6030reg_disable, 309 + .is_enabled = twl6030reg_is_enabled, 310 + 311 + .set_mode = twl6030reg_set_mode, 312 + 313 + .get_status = twl6030reg_get_status, 314 + }; 315 + 316 + static struct regulator_ops twl6030fixed_ops = { 317 + .list_voltage = regulator_list_voltage_linear, 318 + 319 + .enable = twl6030reg_enable, 320 + .disable = twl6030reg_disable, 321 + .is_enabled = twl6030reg_is_enabled, 322 + 323 + .set_mode = twl6030reg_set_mode, 324 + 325 + .get_status = twl6030reg_get_status, 326 + }; 327 + 328 + /* 329 + * SMPS status and control 330 + */ 331 + 332 + static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index) 333 + { 334 + struct twlreg_info *info = rdev_get_drvdata(rdev); 335 + 336 + int voltage = 0; 337 + 338 + switch (info->flags) { 339 + case SMPS_OFFSET_EN: 340 + voltage = 100000; 341 + /* fall through */ 342 + case 0: 343 + switch (index) { 344 + case 0: 345 + voltage = 0; 346 + break; 347 + case 58: 348 + voltage = 1350 * 1000; 349 + break; 350 + case 59: 351 + voltage = 1500 * 1000; 352 + break; 353 + case 60: 354 + voltage = 1800 * 1000; 355 + break; 356 + case 61: 357 + voltage = 1900 * 1000; 358 + break; 359 + case 62: 360 + voltage = 2100 * 1000; 361 + break; 362 + default: 363 + voltage += (600000 + (12500 * (index - 1))); 364 + } 365 + break; 366 + case SMPS_EXTENDED_EN: 367 + switch (index) { 368 + case 0: 369 + voltage = 0; 370 + break; 371 + case 58: 372 + voltage = 2084 * 1000; 373 + break; 374 + case 59: 375 + voltage = 2315 * 1000; 376 + break; 377 + case 60: 378 + voltage = 2778 * 1000; 379 + break; 380 + case 61: 381 + voltage = 2932 * 1000; 382 + break; 383 + case 62: 384 + voltage = 3241 * 1000; 385 + break; 386 + default: 387 + voltage = (1852000 + (38600 * (index - 1))); 388 + } 389 + break; 390 + case SMPS_OFFSET_EN | SMPS_EXTENDED_EN: 391 + switch (index) { 392 + case 0: 393 + voltage = 0; 394 + break; 395 + case 58: 396 + voltage = 4167 * 1000; 397 + break; 398 + case 59: 399 + voltage = 2315 * 1000; 400 + break; 401 + case 60: 402 + voltage = 2778 * 1000; 403 + break; 404 + case 61: 405 + voltage = 2932 * 1000; 406 + break; 407 + case 62: 408 + voltage = 3241 * 1000; 409 + break; 410 + default: 411 + voltage = (2161000 + (38600 * (index - 1))); 412 + } 413 + break; 414 + } 415 + 416 + return voltage; 417 + } 418 + 419 + static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV, 420 + int max_uV) 421 + { 422 + struct twlreg_info *info = rdev_get_drvdata(rdev); 423 + int vsel = 0; 424 + 425 + switch (info->flags) { 426 + case 0: 427 + if (min_uV == 0) 428 + vsel = 0; 429 + else if ((min_uV >= 600000) && (min_uV <= 1300000)) { 430 + vsel = DIV_ROUND_UP(min_uV - 600000, 12500); 431 + vsel++; 432 + } 433 + /* Values 1..57 for vsel are linear and can be calculated 434 + * values 58..62 are non linear. 435 + */ 436 + else if ((min_uV > 1900000) && (min_uV <= 2100000)) 437 + vsel = 62; 438 + else if ((min_uV > 1800000) && (min_uV <= 1900000)) 439 + vsel = 61; 440 + else if ((min_uV > 1500000) && (min_uV <= 1800000)) 441 + vsel = 60; 442 + else if ((min_uV > 1350000) && (min_uV <= 1500000)) 443 + vsel = 59; 444 + else if ((min_uV > 1300000) && (min_uV <= 1350000)) 445 + vsel = 58; 446 + else 447 + return -EINVAL; 448 + break; 449 + case SMPS_OFFSET_EN: 450 + if (min_uV == 0) 451 + vsel = 0; 452 + else if ((min_uV >= 700000) && (min_uV <= 1420000)) { 453 + vsel = DIV_ROUND_UP(min_uV - 700000, 12500); 454 + vsel++; 455 + } 456 + /* Values 1..57 for vsel are linear and can be calculated 457 + * values 58..62 are non linear. 458 + */ 459 + else if ((min_uV > 1900000) && (min_uV <= 2100000)) 460 + vsel = 62; 461 + else if ((min_uV > 1800000) && (min_uV <= 1900000)) 462 + vsel = 61; 463 + else if ((min_uV > 1350000) && (min_uV <= 1800000)) 464 + vsel = 60; 465 + else if ((min_uV > 1350000) && (min_uV <= 1500000)) 466 + vsel = 59; 467 + else if ((min_uV > 1300000) && (min_uV <= 1350000)) 468 + vsel = 58; 469 + else 470 + return -EINVAL; 471 + break; 472 + case SMPS_EXTENDED_EN: 473 + if (min_uV == 0) { 474 + vsel = 0; 475 + } else if ((min_uV >= 1852000) && (max_uV <= 4013600)) { 476 + vsel = DIV_ROUND_UP(min_uV - 1852000, 38600); 477 + vsel++; 478 + } 479 + break; 480 + case SMPS_OFFSET_EN|SMPS_EXTENDED_EN: 481 + if (min_uV == 0) { 482 + vsel = 0; 483 + } else if ((min_uV >= 2161000) && (min_uV <= 4321000)) { 484 + vsel = DIV_ROUND_UP(min_uV - 2161000, 38600); 485 + vsel++; 486 + } 487 + break; 488 + } 489 + 490 + return vsel; 491 + } 492 + 493 + static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev, 494 + unsigned int selector) 495 + { 496 + struct twlreg_info *info = rdev_get_drvdata(rdev); 497 + 498 + return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS, 499 + selector); 500 + } 501 + 502 + static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev) 503 + { 504 + struct twlreg_info *info = rdev_get_drvdata(rdev); 505 + 506 + return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS); 507 + } 508 + 509 + static struct regulator_ops twlsmps_ops = { 510 + .list_voltage = twl6030smps_list_voltage, 511 + .map_voltage = twl6030smps_map_voltage, 512 + 513 + .set_voltage_sel = twl6030smps_set_voltage_sel, 514 + .get_voltage_sel = twl6030smps_get_voltage_sel, 515 + 516 + .enable = twl6030reg_enable, 517 + .disable = twl6030reg_disable, 518 + .is_enabled = twl6030reg_is_enabled, 519 + 520 + .set_mode = twl6030reg_set_mode, 521 + 522 + .get_status = twl6030reg_get_status, 523 + }; 524 + 525 + /*----------------------------------------------------------------------*/ 526 + 527 + #define TWL6030_ADJUSTABLE_SMPS(label) \ 528 + static const struct twlreg_info TWL6030_INFO_##label = { \ 529 + .desc = { \ 530 + .name = #label, \ 531 + .id = TWL6030_REG_##label, \ 532 + .ops = &twl6030coresmps_ops, \ 533 + .type = REGULATOR_VOLTAGE, \ 534 + .owner = THIS_MODULE, \ 535 + }, \ 536 + } 537 + 538 + #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 539 + static const struct twlreg_info TWL6030_INFO_##label = { \ 540 + .base = offset, \ 541 + .min_mV = min_mVolts, \ 542 + .max_mV = max_mVolts, \ 543 + .desc = { \ 544 + .name = #label, \ 545 + .id = TWL6030_REG_##label, \ 546 + .n_voltages = 32, \ 547 + .ops = &twl6030ldo_ops, \ 548 + .type = REGULATOR_VOLTAGE, \ 549 + .owner = THIS_MODULE, \ 550 + }, \ 551 + } 552 + 553 + #define TWL6032_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 554 + static const struct twlreg_info TWL6032_INFO_##label = { \ 555 + .base = offset, \ 556 + .min_mV = min_mVolts, \ 557 + .max_mV = max_mVolts, \ 558 + .desc = { \ 559 + .name = #label, \ 560 + .id = TWL6032_REG_##label, \ 561 + .n_voltages = 32, \ 562 + .ops = &twl6030ldo_ops, \ 563 + .type = REGULATOR_VOLTAGE, \ 564 + .owner = THIS_MODULE, \ 565 + }, \ 566 + } 567 + 568 + #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \ 569 + static const struct twlreg_info TWLFIXED_INFO_##label = { \ 570 + .base = offset, \ 571 + .id = 0, \ 572 + .min_mV = mVolts, \ 573 + .remap = 0, \ 574 + .desc = { \ 575 + .name = #label, \ 576 + .id = TWL6030##_REG_##label, \ 577 + .n_voltages = 1, \ 578 + .ops = &twl6030fixed_ops, \ 579 + .type = REGULATOR_VOLTAGE, \ 580 + .owner = THIS_MODULE, \ 581 + .min_uV = mVolts * 1000, \ 582 + .enable_time = turnon_delay, \ 583 + .of_map_mode = NULL, \ 584 + }, \ 585 + } 586 + 587 + #define TWL6032_ADJUSTABLE_SMPS(label, offset) \ 588 + static const struct twlreg_info TWLSMPS_INFO_##label = { \ 589 + .base = offset, \ 590 + .min_mV = 600, \ 591 + .max_mV = 2100, \ 592 + .desc = { \ 593 + .name = #label, \ 594 + .id = TWL6032_REG_##label, \ 595 + .n_voltages = 63, \ 596 + .ops = &twlsmps_ops, \ 597 + .type = REGULATOR_VOLTAGE, \ 598 + .owner = THIS_MODULE, \ 599 + }, \ 600 + } 601 + 602 + /* VUSBCP is managed *only* by the USB subchip */ 603 + /* 6030 REG with base as PMC Slave Misc : 0x0030 */ 604 + /* Turnon-delay and remap configuration values for 6030 are not 605 + verified since the specification is not public */ 606 + TWL6030_ADJUSTABLE_SMPS(VDD1); 607 + TWL6030_ADJUSTABLE_SMPS(VDD2); 608 + TWL6030_ADJUSTABLE_SMPS(VDD3); 609 + TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300); 610 + TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300); 611 + TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300); 612 + TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300); 613 + TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300); 614 + TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300); 615 + /* 6025 are renamed compared to 6030 versions */ 616 + TWL6032_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300); 617 + TWL6032_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300); 618 + TWL6032_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300); 619 + TWL6032_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300); 620 + TWL6032_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300); 621 + TWL6032_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300); 622 + TWL6032_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300); 623 + TWL6032_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300); 624 + TWL6032_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300); 625 + TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0); 626 + TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0); 627 + TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0); 628 + TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0); 629 + TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0); 630 + TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0); 631 + TWL6032_ADJUSTABLE_SMPS(SMPS3, 0x34); 632 + TWL6032_ADJUSTABLE_SMPS(SMPS4, 0x10); 633 + TWL6032_ADJUSTABLE_SMPS(VIO, 0x16); 634 + 635 + static u8 twl_get_smps_offset(void) 636 + { 637 + u8 value; 638 + 639 + twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value, 640 + TWL6030_SMPS_OFFSET); 641 + return value; 642 + } 643 + 644 + static u8 twl_get_smps_mult(void) 645 + { 646 + u8 value; 647 + 648 + twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value, 649 + TWL6030_SMPS_MULT); 650 + return value; 651 + } 652 + 653 + #define TWL_OF_MATCH(comp, family, label) \ 654 + { \ 655 + .compatible = comp, \ 656 + .data = &family##_INFO_##label, \ 657 + } 658 + 659 + #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label) 660 + #define TWL6032_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6032, label) 661 + #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label) 662 + #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label) 663 + 664 + static const struct of_device_id twl_of_match[] = { 665 + TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1), 666 + TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2), 667 + TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3), 668 + TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030), 669 + TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030), 670 + TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030), 671 + TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC), 672 + TWL6030_OF_MATCH("ti,twl6030-vpp", VPP), 673 + TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM), 674 + TWL6032_OF_MATCH("ti,twl6032-ldo2", LDO2), 675 + TWL6032_OF_MATCH("ti,twl6032-ldo4", LDO4), 676 + TWL6032_OF_MATCH("ti,twl6032-ldo3", LDO3), 677 + TWL6032_OF_MATCH("ti,twl6032-ldo5", LDO5), 678 + TWL6032_OF_MATCH("ti,twl6032-ldo1", LDO1), 679 + TWL6032_OF_MATCH("ti,twl6032-ldo7", LDO7), 680 + TWL6032_OF_MATCH("ti,twl6032-ldo6", LDO6), 681 + TWL6032_OF_MATCH("ti,twl6032-ldoln", LDOLN), 682 + TWL6032_OF_MATCH("ti,twl6032-ldousb", LDOUSB), 683 + TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA), 684 + TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO), 685 + TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC), 686 + TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB), 687 + TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8), 688 + TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1), 689 + TWLSMPS_OF_MATCH("ti,twl6032-smps3", SMPS3), 690 + TWLSMPS_OF_MATCH("ti,twl6032-smps4", SMPS4), 691 + TWLSMPS_OF_MATCH("ti,twl6032-vio", VIO), 692 + {}, 693 + }; 694 + MODULE_DEVICE_TABLE(of, twl_of_match); 695 + 696 + static int twlreg_probe(struct platform_device *pdev) 697 + { 698 + int id; 699 + struct twlreg_info *info; 700 + const struct twlreg_info *template; 701 + struct regulator_init_data *initdata; 702 + struct regulation_constraints *c; 703 + struct regulator_dev *rdev; 704 + const struct of_device_id *match; 705 + struct regulator_config config = { }; 706 + 707 + match = of_match_device(twl_of_match, &pdev->dev); 708 + if (!match) 709 + return -ENODEV; 710 + 711 + template = match->data; 712 + if (!template) 713 + return -ENODEV; 714 + 715 + id = template->desc.id; 716 + initdata = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node, 717 + &template->desc); 718 + if (!initdata) 719 + return -EINVAL; 720 + 721 + info = devm_kmemdup(&pdev->dev, template, sizeof(*info), GFP_KERNEL); 722 + if (!info) 723 + return -ENOMEM; 724 + 725 + /* Constrain board-specific capabilities according to what 726 + * this driver and the chip itself can actually do. 727 + */ 728 + c = &initdata->constraints; 729 + c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY; 730 + c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE 731 + | REGULATOR_CHANGE_MODE 732 + | REGULATOR_CHANGE_STATUS; 733 + 734 + switch (id) { 735 + case TWL6032_REG_SMPS3: 736 + if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3) 737 + info->flags |= SMPS_EXTENDED_EN; 738 + if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3) 739 + info->flags |= SMPS_OFFSET_EN; 740 + break; 741 + case TWL6032_REG_SMPS4: 742 + if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4) 743 + info->flags |= SMPS_EXTENDED_EN; 744 + if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4) 745 + info->flags |= SMPS_OFFSET_EN; 746 + break; 747 + case TWL6032_REG_VIO: 748 + if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO) 749 + info->flags |= SMPS_EXTENDED_EN; 750 + if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO) 751 + info->flags |= SMPS_OFFSET_EN; 752 + break; 753 + } 754 + 755 + config.dev = &pdev->dev; 756 + config.init_data = initdata; 757 + config.driver_data = info; 758 + config.of_node = pdev->dev.of_node; 759 + 760 + rdev = devm_regulator_register(&pdev->dev, &info->desc, &config); 761 + if (IS_ERR(rdev)) { 762 + dev_err(&pdev->dev, "can't register %s, %ld\n", 763 + info->desc.name, PTR_ERR(rdev)); 764 + return PTR_ERR(rdev); 765 + } 766 + platform_set_drvdata(pdev, rdev); 767 + 768 + /* NOTE: many regulators support short-circuit IRQs (presentable 769 + * as REGULATOR_OVER_CURRENT notifications?) configured via: 770 + * - SC_CONFIG 771 + * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4) 772 + * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2) 773 + * - IT_CONFIG 774 + */ 775 + 776 + return 0; 777 + } 778 + 779 + MODULE_ALIAS("platform:twl6030_reg"); 780 + 781 + static struct platform_driver twlreg_driver = { 782 + .probe = twlreg_probe, 783 + /* NOTE: short name, to work around driver model truncation of 784 + * "twl_regulator.12" (and friends) to "twl_regulator.1". 785 + */ 786 + .driver = { 787 + .name = "twl6030_reg", 788 + .of_match_table = of_match_ptr(twl_of_match), 789 + }, 790 + }; 791 + 792 + static int __init twlreg_init(void) 793 + { 794 + return platform_driver_register(&twlreg_driver); 795 + } 796 + subsys_initcall(twlreg_init); 797 + 798 + static void __exit twlreg_exit(void) 799 + { 800 + platform_driver_unregister(&twlreg_driver); 801 + } 802 + module_exit(twlreg_exit) 803 + 804 + MODULE_DESCRIPTION("TWL6030 regulator driver"); 805 + MODULE_LICENSE("GPL");