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

Merge remote-tracking branches 'regulator/topic/tps65086' and 'regulator/topic/twl' into regulator-next

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