1 /* 2 * twl-regulator.c -- support regulators in twl4030/twl6030 family chips 3 * 4 * Copyright (C) 2008 David Brownell 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 */ 11 12 #include <linux/module.h> 13 #include <linux/init.h> 14 #include <linux/err.h> 15 #include <linux/platform_device.h> 16 #include <linux/of.h> 17 #include <linux/of_device.h> 18 #include <linux/regulator/driver.h> 19 #include <linux/regulator/machine.h> 20 #include <linux/regulator/of_regulator.h> 21 #include <linux/i2c/twl.h> 22 23 24 /* 25 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a 26 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions 27 * include an audio codec, battery charger, and more voltage regulators. 28 * These chips are often used in OMAP-based systems. 29 * 30 * This driver implements software-based resource control for various 31 * voltage regulators. This is usually augmented with state machine 32 * based control. 33 */ 34 35 struct twlreg_info { 36 /* start of regulator's PM_RECEIVER control register bank */ 37 u8 base; 38 39 /* twl resource ID, for resource control state machine */ 40 u8 id; 41 42 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */ 43 u8 table_len; 44 const u16 *table; 45 46 /* State REMAP default configuration */ 47 u8 remap; 48 49 /* chip constraints on regulator behavior */ 50 u16 min_mV; 51 u16 max_mV; 52 53 u8 flags; 54 55 /* used by regulator core */ 56 struct regulator_desc desc; 57 58 /* chip specific features */ 59 unsigned long features; 60 61 /* 62 * optional override functions for voltage set/get 63 * these are currently only used for SMPS regulators 64 */ 65 int (*get_voltage)(void *data); 66 int (*set_voltage)(void *data, int target_uV); 67 68 /* data passed from board for external get/set voltage */ 69 void *data; 70 }; 71 72 73 /* LDO control registers ... offset is from the base of its register bank. 74 * The first three registers of all power resource banks help hardware to 75 * manage the various resource groups. 76 */ 77 /* Common offset in TWL4030/6030 */ 78 #define VREG_GRP 0 79 /* TWL4030 register offsets */ 80 #define VREG_TYPE 1 81 #define VREG_REMAP 2 82 #define VREG_DEDICATED 3 /* LDO control */ 83 #define VREG_VOLTAGE_SMPS_4030 9 84 /* TWL6030 register offsets */ 85 #define VREG_TRANS 1 86 #define VREG_STATE 2 87 #define VREG_VOLTAGE 3 88 #define VREG_VOLTAGE_SMPS 4 89 /* TWL6030 Misc register offsets */ 90 #define VREG_BC_ALL 1 91 #define VREG_BC_REF 2 92 #define VREG_BC_PROC 3 93 #define VREG_BC_CLK_RST 4 94 95 /* TWL6030 LDO register values for CFG_STATE */ 96 #define TWL6030_CFG_STATE_OFF 0x00 97 #define TWL6030_CFG_STATE_ON 0x01 98 #define TWL6030_CFG_STATE_OFF2 0x02 99 #define TWL6030_CFG_STATE_SLEEP 0x03 100 #define TWL6030_CFG_STATE_GRP_SHIFT 5 101 #define TWL6030_CFG_STATE_APP_SHIFT 2 102 #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT) 103 #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\ 104 TWL6030_CFG_STATE_APP_SHIFT) 105 106 /* Flags for SMPS Voltage reading */ 107 #define SMPS_OFFSET_EN BIT(0) 108 #define SMPS_EXTENDED_EN BIT(1) 109 110 /* twl6025 SMPS EPROM values */ 111 #define TWL6030_SMPS_OFFSET 0xB0 112 #define TWL6030_SMPS_MULT 0xB3 113 #define SMPS_MULTOFFSET_SMPS4 BIT(0) 114 #define SMPS_MULTOFFSET_VIO BIT(1) 115 #define SMPS_MULTOFFSET_SMPS3 BIT(6) 116 117 static inline int 118 twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset) 119 { 120 u8 value; 121 int status; 122 123 status = twl_i2c_read_u8(slave_subgp, 124 &value, info->base + offset); 125 return (status < 0) ? status : value; 126 } 127 128 static inline int 129 twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset, 130 u8 value) 131 { 132 return twl_i2c_write_u8(slave_subgp, 133 value, info->base + offset); 134 } 135 136 /*----------------------------------------------------------------------*/ 137 138 /* generic power resource operations, which work on all regulators */ 139 140 static int twlreg_grp(struct regulator_dev *rdev) 141 { 142 return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER, 143 VREG_GRP); 144 } 145 146 /* 147 * Enable/disable regulators by joining/leaving the P1 (processor) group. 148 * We assume nobody else is updating the DEV_GRP registers. 149 */ 150 /* definition for 4030 family */ 151 #define P3_GRP_4030 BIT(7) /* "peripherals" */ 152 #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */ 153 #define P1_GRP_4030 BIT(5) /* CPU/Linux */ 154 /* definition for 6030 family */ 155 #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */ 156 #define P2_GRP_6030 BIT(1) /* "peripherals" */ 157 #define P1_GRP_6030 BIT(0) /* CPU/Linux */ 158 159 static int twl4030reg_is_enabled(struct regulator_dev *rdev) 160 { 161 int state = twlreg_grp(rdev); 162 163 if (state < 0) 164 return state; 165 166 return state & P1_GRP_4030; 167 } 168 169 static int twl6030reg_is_enabled(struct regulator_dev *rdev) 170 { 171 struct twlreg_info *info = rdev_get_drvdata(rdev); 172 int grp = 0, val; 173 174 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) { 175 grp = twlreg_grp(rdev); 176 if (grp < 0) 177 return grp; 178 grp &= P1_GRP_6030; 179 } else { 180 grp = 1; 181 } 182 183 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); 184 val = TWL6030_CFG_STATE_APP(val); 185 186 return grp && (val == TWL6030_CFG_STATE_ON); 187 } 188 189 static int twl4030reg_enable(struct regulator_dev *rdev) 190 { 191 struct twlreg_info *info = rdev_get_drvdata(rdev); 192 int grp; 193 int ret; 194 195 grp = twlreg_grp(rdev); 196 if (grp < 0) 197 return grp; 198 199 grp |= P1_GRP_4030; 200 201 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); 202 203 return ret; 204 } 205 206 static int twl6030reg_enable(struct regulator_dev *rdev) 207 { 208 struct twlreg_info *info = rdev_get_drvdata(rdev); 209 int grp = 0; 210 int ret; 211 212 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) 213 grp = twlreg_grp(rdev); 214 if (grp < 0) 215 return grp; 216 217 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, 218 grp << TWL6030_CFG_STATE_GRP_SHIFT | 219 TWL6030_CFG_STATE_ON); 220 return ret; 221 } 222 223 static int twl4030reg_disable(struct regulator_dev *rdev) 224 { 225 struct twlreg_info *info = rdev_get_drvdata(rdev); 226 int grp; 227 int ret; 228 229 grp = twlreg_grp(rdev); 230 if (grp < 0) 231 return grp; 232 233 grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030); 234 235 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); 236 237 return ret; 238 } 239 240 static int twl6030reg_disable(struct regulator_dev *rdev) 241 { 242 struct twlreg_info *info = rdev_get_drvdata(rdev); 243 int grp = 0; 244 int ret; 245 246 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) 247 grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030; 248 249 /* For 6030, set the off state for all grps enabled */ 250 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, 251 (grp) << TWL6030_CFG_STATE_GRP_SHIFT | 252 TWL6030_CFG_STATE_OFF); 253 254 return ret; 255 } 256 257 static int twl4030reg_get_status(struct regulator_dev *rdev) 258 { 259 int state = twlreg_grp(rdev); 260 261 if (state < 0) 262 return state; 263 state &= 0x0f; 264 265 /* assume state != WARM_RESET; we'd not be running... */ 266 if (!state) 267 return REGULATOR_STATUS_OFF; 268 return (state & BIT(3)) 269 ? REGULATOR_STATUS_NORMAL 270 : REGULATOR_STATUS_STANDBY; 271 } 272 273 static int twl6030reg_get_status(struct regulator_dev *rdev) 274 { 275 struct twlreg_info *info = rdev_get_drvdata(rdev); 276 int val; 277 278 val = twlreg_grp(rdev); 279 if (val < 0) 280 return val; 281 282 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); 283 284 switch (TWL6030_CFG_STATE_APP(val)) { 285 case TWL6030_CFG_STATE_ON: 286 return REGULATOR_STATUS_NORMAL; 287 288 case TWL6030_CFG_STATE_SLEEP: 289 return REGULATOR_STATUS_STANDBY; 290 291 case TWL6030_CFG_STATE_OFF: 292 case TWL6030_CFG_STATE_OFF2: 293 default: 294 break; 295 } 296 297 return REGULATOR_STATUS_OFF; 298 } 299 300 static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode) 301 { 302 struct twlreg_info *info = rdev_get_drvdata(rdev); 303 unsigned message; 304 int status; 305 306 /* We can only set the mode through state machine commands... */ 307 switch (mode) { 308 case REGULATOR_MODE_NORMAL: 309 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE); 310 break; 311 case REGULATOR_MODE_STANDBY: 312 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP); 313 break; 314 default: 315 return -EINVAL; 316 } 317 318 /* Ensure the resource is associated with some group */ 319 status = twlreg_grp(rdev); 320 if (status < 0) 321 return status; 322 if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030))) 323 return -EACCES; 324 325 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 326 message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB); 327 if (status < 0) 328 return status; 329 330 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 331 message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB); 332 } 333 334 static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode) 335 { 336 struct twlreg_info *info = rdev_get_drvdata(rdev); 337 int grp = 0; 338 int val; 339 340 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) 341 grp = twlreg_grp(rdev); 342 343 if (grp < 0) 344 return grp; 345 346 /* Compose the state register settings */ 347 val = grp << TWL6030_CFG_STATE_GRP_SHIFT; 348 /* We can only set the mode through state machine commands... */ 349 switch (mode) { 350 case REGULATOR_MODE_NORMAL: 351 val |= TWL6030_CFG_STATE_ON; 352 break; 353 case REGULATOR_MODE_STANDBY: 354 val |= TWL6030_CFG_STATE_SLEEP; 355 break; 356 357 default: 358 return -EINVAL; 359 } 360 361 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val); 362 } 363 364 /*----------------------------------------------------------------------*/ 365 366 /* 367 * Support for adjustable-voltage LDOs uses a four bit (or less) voltage 368 * select field in its control register. We use tables indexed by VSEL 369 * to record voltages in milliVolts. (Accuracy is about three percent.) 370 * 371 * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon; 372 * currently handled by listing two slightly different VAUX2 regulators, 373 * only one of which will be configured. 374 * 375 * VSEL values documented as "TI cannot support these values" are flagged 376 * in these tables as UNSUP() values; we normally won't assign them. 377 * 378 * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported. 379 * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting. 380 */ 381 #define UNSUP_MASK 0x8000 382 383 #define UNSUP(x) (UNSUP_MASK | (x)) 384 #define IS_UNSUP(info, x) \ 385 ((UNSUP_MASK & (x)) && \ 386 !((info)->features & TWL4030_ALLOW_UNSUPPORTED)) 387 #define LDO_MV(x) (~UNSUP_MASK & (x)) 388 389 390 static const u16 VAUX1_VSEL_table[] = { 391 UNSUP(1500), UNSUP(1800), 2500, 2800, 392 3000, 3000, 3000, 3000, 393 }; 394 static const u16 VAUX2_4030_VSEL_table[] = { 395 UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300, 396 1500, 1800, UNSUP(1850), 2500, 397 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), 398 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), 399 }; 400 static const u16 VAUX2_VSEL_table[] = { 401 1700, 1700, 1900, 1300, 402 1500, 1800, 2000, 2500, 403 2100, 2800, 2200, 2300, 404 2400, 2400, 2400, 2400, 405 }; 406 static const u16 VAUX3_VSEL_table[] = { 407 1500, 1800, 2500, 2800, 408 3000, 3000, 3000, 3000, 409 }; 410 static const u16 VAUX4_VSEL_table[] = { 411 700, 1000, 1200, UNSUP(1300), 412 1500, 1800, UNSUP(1850), 2500, 413 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), 414 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), 415 }; 416 static const u16 VMMC1_VSEL_table[] = { 417 1850, 2850, 3000, 3150, 418 }; 419 static const u16 VMMC2_VSEL_table[] = { 420 UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300), 421 UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500), 422 2600, 2800, 2850, 3000, 423 3150, 3150, 3150, 3150, 424 }; 425 static const u16 VPLL1_VSEL_table[] = { 426 1000, 1200, 1300, 1800, 427 UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000), 428 }; 429 static const u16 VPLL2_VSEL_table[] = { 430 700, 1000, 1200, 1300, 431 UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500), 432 UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000), 433 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), 434 }; 435 static const u16 VSIM_VSEL_table[] = { 436 UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800, 437 2800, 3000, 3000, 3000, 438 }; 439 static const u16 VDAC_VSEL_table[] = { 440 1200, 1300, 1800, 1800, 441 }; 442 static const u16 VDD1_VSEL_table[] = { 443 800, 1450, 444 }; 445 static const u16 VDD2_VSEL_table[] = { 446 800, 1450, 1500, 447 }; 448 static const u16 VIO_VSEL_table[] = { 449 1800, 1850, 450 }; 451 static const u16 VINTANA2_VSEL_table[] = { 452 2500, 2750, 453 }; 454 455 static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) 456 { 457 struct twlreg_info *info = rdev_get_drvdata(rdev); 458 int mV = info->table[index]; 459 460 return IS_UNSUP(info, mV) ? 0 : (LDO_MV(mV) * 1000); 461 } 462 463 static int 464 twl4030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) 465 { 466 struct twlreg_info *info = rdev_get_drvdata(rdev); 467 468 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, 469 selector); 470 } 471 472 static int twl4030ldo_get_voltage(struct regulator_dev *rdev) 473 { 474 struct twlreg_info *info = rdev_get_drvdata(rdev); 475 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, 476 VREG_VOLTAGE); 477 478 if (vsel < 0) 479 return vsel; 480 481 vsel &= info->table_len - 1; 482 return LDO_MV(info->table[vsel]) * 1000; 483 } 484 485 static struct regulator_ops twl4030ldo_ops = { 486 .list_voltage = twl4030ldo_list_voltage, 487 488 .set_voltage_sel = twl4030ldo_set_voltage_sel, 489 .get_voltage = twl4030ldo_get_voltage, 490 491 .enable = twl4030reg_enable, 492 .disable = twl4030reg_disable, 493 .is_enabled = twl4030reg_is_enabled, 494 495 .set_mode = twl4030reg_set_mode, 496 497 .get_status = twl4030reg_get_status, 498 }; 499 500 static int 501 twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, 502 unsigned *selector) 503 { 504 struct twlreg_info *info = rdev_get_drvdata(rdev); 505 int vsel = DIV_ROUND_UP(min_uV - 600000, 12500); 506 507 if (info->set_voltage) { 508 return info->set_voltage(info->data, min_uV); 509 } else { 510 twlreg_write(info, TWL_MODULE_PM_RECEIVER, 511 VREG_VOLTAGE_SMPS_4030, vsel); 512 } 513 514 return 0; 515 } 516 517 static int twl4030smps_get_voltage(struct regulator_dev *rdev) 518 { 519 struct twlreg_info *info = rdev_get_drvdata(rdev); 520 int vsel; 521 522 if (info->get_voltage) 523 return info->get_voltage(info->data); 524 525 vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, 526 VREG_VOLTAGE_SMPS_4030); 527 528 return vsel * 12500 + 600000; 529 } 530 531 static struct regulator_ops twl4030smps_ops = { 532 .set_voltage = twl4030smps_set_voltage, 533 .get_voltage = twl4030smps_get_voltage, 534 }; 535 536 static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV, 537 int max_uV, unsigned *selector) 538 { 539 struct twlreg_info *info = rdev_get_drvdata(rdev); 540 541 if (info->set_voltage) 542 return info->set_voltage(info->data, min_uV); 543 544 return -ENODEV; 545 } 546 547 static int twl6030coresmps_get_voltage(struct regulator_dev *rdev) 548 { 549 struct twlreg_info *info = rdev_get_drvdata(rdev); 550 551 if (info->get_voltage) 552 return info->get_voltage(info->data); 553 554 return -ENODEV; 555 } 556 557 static struct regulator_ops twl6030coresmps_ops = { 558 .set_voltage = twl6030coresmps_set_voltage, 559 .get_voltage = twl6030coresmps_get_voltage, 560 }; 561 562 static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel) 563 { 564 struct twlreg_info *info = rdev_get_drvdata(rdev); 565 566 switch (sel) { 567 case 0: 568 return 0; 569 case 1 ... 24: 570 /* Linear mapping from 00000001 to 00011000: 571 * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001) 572 */ 573 return (info->min_mV + 100 * (sel - 1)) * 1000; 574 case 25 ... 30: 575 return -EINVAL; 576 case 31: 577 return 2750000; 578 default: 579 return -EINVAL; 580 } 581 } 582 583 static int 584 twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) 585 { 586 struct twlreg_info *info = rdev_get_drvdata(rdev); 587 588 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, 589 selector); 590 } 591 592 static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev) 593 { 594 struct twlreg_info *info = rdev_get_drvdata(rdev); 595 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE); 596 597 return vsel; 598 } 599 600 static struct regulator_ops twl6030ldo_ops = { 601 .list_voltage = twl6030ldo_list_voltage, 602 603 .set_voltage_sel = twl6030ldo_set_voltage_sel, 604 .get_voltage_sel = twl6030ldo_get_voltage_sel, 605 606 .enable = twl6030reg_enable, 607 .disable = twl6030reg_disable, 608 .is_enabled = twl6030reg_is_enabled, 609 610 .set_mode = twl6030reg_set_mode, 611 612 .get_status = twl6030reg_get_status, 613 }; 614 615 /*----------------------------------------------------------------------*/ 616 617 /* 618 * Fixed voltage LDOs don't have a VSEL field to update. 619 */ 620 static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index) 621 { 622 struct twlreg_info *info = rdev_get_drvdata(rdev); 623 624 return info->min_mV * 1000; 625 } 626 627 static int twlfixed_get_voltage(struct regulator_dev *rdev) 628 { 629 struct twlreg_info *info = rdev_get_drvdata(rdev); 630 631 return info->min_mV * 1000; 632 } 633 634 static struct regulator_ops twl4030fixed_ops = { 635 .list_voltage = twlfixed_list_voltage, 636 637 .get_voltage = twlfixed_get_voltage, 638 639 .enable = twl4030reg_enable, 640 .disable = twl4030reg_disable, 641 .is_enabled = twl4030reg_is_enabled, 642 643 .set_mode = twl4030reg_set_mode, 644 645 .get_status = twl4030reg_get_status, 646 }; 647 648 static struct regulator_ops twl6030fixed_ops = { 649 .list_voltage = twlfixed_list_voltage, 650 651 .get_voltage = twlfixed_get_voltage, 652 653 .enable = twl6030reg_enable, 654 .disable = twl6030reg_disable, 655 .is_enabled = twl6030reg_is_enabled, 656 657 .set_mode = twl6030reg_set_mode, 658 659 .get_status = twl6030reg_get_status, 660 }; 661 662 static struct regulator_ops twl6030_fixed_resource = { 663 .enable = twl6030reg_enable, 664 .disable = twl6030reg_disable, 665 .is_enabled = twl6030reg_is_enabled, 666 .get_status = twl6030reg_get_status, 667 }; 668 669 /* 670 * SMPS status and control 671 */ 672 673 static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index) 674 { 675 struct twlreg_info *info = rdev_get_drvdata(rdev); 676 677 int voltage = 0; 678 679 switch (info->flags) { 680 case SMPS_OFFSET_EN: 681 voltage = 100000; 682 /* fall through */ 683 case 0: 684 switch (index) { 685 case 0: 686 voltage = 0; 687 break; 688 case 58: 689 voltage = 1350 * 1000; 690 break; 691 case 59: 692 voltage = 1500 * 1000; 693 break; 694 case 60: 695 voltage = 1800 * 1000; 696 break; 697 case 61: 698 voltage = 1900 * 1000; 699 break; 700 case 62: 701 voltage = 2100 * 1000; 702 break; 703 default: 704 voltage += (600000 + (12500 * (index - 1))); 705 } 706 break; 707 case SMPS_EXTENDED_EN: 708 switch (index) { 709 case 0: 710 voltage = 0; 711 break; 712 case 58: 713 voltage = 2084 * 1000; 714 break; 715 case 59: 716 voltage = 2315 * 1000; 717 break; 718 case 60: 719 voltage = 2778 * 1000; 720 break; 721 case 61: 722 voltage = 2932 * 1000; 723 break; 724 case 62: 725 voltage = 3241 * 1000; 726 break; 727 default: 728 voltage = (1852000 + (38600 * (index - 1))); 729 } 730 break; 731 case SMPS_OFFSET_EN | SMPS_EXTENDED_EN: 732 switch (index) { 733 case 0: 734 voltage = 0; 735 break; 736 case 58: 737 voltage = 4167 * 1000; 738 break; 739 case 59: 740 voltage = 2315 * 1000; 741 break; 742 case 60: 743 voltage = 2778 * 1000; 744 break; 745 case 61: 746 voltage = 2932 * 1000; 747 break; 748 case 62: 749 voltage = 3241 * 1000; 750 break; 751 default: 752 voltage = (2161000 + (38600 * (index - 1))); 753 } 754 break; 755 } 756 757 return voltage; 758 } 759 760 static int 761 twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, 762 unsigned int *selector) 763 { 764 struct twlreg_info *info = rdev_get_drvdata(rdev); 765 int vsel = 0; 766 767 switch (info->flags) { 768 case 0: 769 if (min_uV == 0) 770 vsel = 0; 771 else if ((min_uV >= 600000) && (min_uV <= 1300000)) { 772 int calc_uV; 773 vsel = DIV_ROUND_UP(min_uV - 600000, 12500); 774 vsel++; 775 calc_uV = twl6030smps_list_voltage(rdev, vsel); 776 if (calc_uV > max_uV) 777 return -EINVAL; 778 } 779 /* Values 1..57 for vsel are linear and can be calculated 780 * values 58..62 are non linear. 781 */ 782 else if ((min_uV > 1900000) && (max_uV >= 2100000)) 783 vsel = 62; 784 else if ((min_uV > 1800000) && (max_uV >= 1900000)) 785 vsel = 61; 786 else if ((min_uV > 1500000) && (max_uV >= 1800000)) 787 vsel = 60; 788 else if ((min_uV > 1350000) && (max_uV >= 1500000)) 789 vsel = 59; 790 else if ((min_uV > 1300000) && (max_uV >= 1350000)) 791 vsel = 58; 792 else 793 return -EINVAL; 794 break; 795 case SMPS_OFFSET_EN: 796 if (min_uV == 0) 797 vsel = 0; 798 else if ((min_uV >= 700000) && (min_uV <= 1420000)) { 799 int calc_uV; 800 vsel = DIV_ROUND_UP(min_uV - 700000, 12500); 801 vsel++; 802 calc_uV = twl6030smps_list_voltage(rdev, vsel); 803 if (calc_uV > max_uV) 804 return -EINVAL; 805 } 806 /* Values 1..57 for vsel are linear and can be calculated 807 * values 58..62 are non linear. 808 */ 809 else if ((min_uV > 1900000) && (max_uV >= 2100000)) 810 vsel = 62; 811 else if ((min_uV > 1800000) && (max_uV >= 1900000)) 812 vsel = 61; 813 else if ((min_uV > 1350000) && (max_uV >= 1800000)) 814 vsel = 60; 815 else if ((min_uV > 1350000) && (max_uV >= 1500000)) 816 vsel = 59; 817 else if ((min_uV > 1300000) && (max_uV >= 1350000)) 818 vsel = 58; 819 else 820 return -EINVAL; 821 break; 822 case SMPS_EXTENDED_EN: 823 if (min_uV == 0) { 824 vsel = 0; 825 } else if ((min_uV >= 1852000) && (max_uV <= 4013600)) { 826 vsel = DIV_ROUND_UP(min_uV - 1852000, 38600); 827 vsel++; 828 } 829 break; 830 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN: 831 if (min_uV == 0) { 832 vsel = 0; 833 } else if ((min_uV >= 2161000) && (max_uV <= 4321000)) { 834 vsel = DIV_ROUND_UP(min_uV - 2161000, 38600); 835 vsel++; 836 } 837 break; 838 } 839 840 *selector = vsel; 841 842 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS, 843 vsel); 844 } 845 846 static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev) 847 { 848 struct twlreg_info *info = rdev_get_drvdata(rdev); 849 850 return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS); 851 } 852 853 static struct regulator_ops twlsmps_ops = { 854 .list_voltage = twl6030smps_list_voltage, 855 856 .set_voltage = twl6030smps_set_voltage, 857 .get_voltage_sel = twl6030smps_get_voltage_sel, 858 859 .enable = twl6030reg_enable, 860 .disable = twl6030reg_disable, 861 .is_enabled = twl6030reg_is_enabled, 862 863 .set_mode = twl6030reg_set_mode, 864 865 .get_status = twl6030reg_get_status, 866 }; 867 868 /*----------------------------------------------------------------------*/ 869 870 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ 871 remap_conf) \ 872 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ 873 remap_conf, TWL4030, twl4030fixed_ops) 874 #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \ 875 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \ 876 0x0, TWL6030, twl6030fixed_ops) 877 878 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ 879 static struct twlreg_info TWL4030_INFO_##label = { \ 880 .base = offset, \ 881 .id = num, \ 882 .table_len = ARRAY_SIZE(label##_VSEL_table), \ 883 .table = label##_VSEL_table, \ 884 .remap = remap_conf, \ 885 .desc = { \ 886 .name = #label, \ 887 .id = TWL4030_REG_##label, \ 888 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \ 889 .ops = &twl4030ldo_ops, \ 890 .type = REGULATOR_VOLTAGE, \ 891 .owner = THIS_MODULE, \ 892 .enable_time = turnon_delay, \ 893 }, \ 894 } 895 896 #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \ 897 static struct twlreg_info TWL4030_INFO_##label = { \ 898 .base = offset, \ 899 .id = num, \ 900 .remap = remap_conf, \ 901 .desc = { \ 902 .name = #label, \ 903 .id = TWL4030_REG_##label, \ 904 .ops = &twl4030smps_ops, \ 905 .type = REGULATOR_VOLTAGE, \ 906 .owner = THIS_MODULE, \ 907 .enable_time = turnon_delay, \ 908 }, \ 909 } 910 911 #define TWL6030_ADJUSTABLE_SMPS(label) \ 912 static struct twlreg_info TWL6030_INFO_##label = { \ 913 .desc = { \ 914 .name = #label, \ 915 .id = TWL6030_REG_##label, \ 916 .ops = &twl6030coresmps_ops, \ 917 .type = REGULATOR_VOLTAGE, \ 918 .owner = THIS_MODULE, \ 919 }, \ 920 } 921 922 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 923 static struct twlreg_info TWL6030_INFO_##label = { \ 924 .base = offset, \ 925 .min_mV = min_mVolts, \ 926 .max_mV = max_mVolts, \ 927 .desc = { \ 928 .name = #label, \ 929 .id = TWL6030_REG_##label, \ 930 .n_voltages = 32, \ 931 .ops = &twl6030ldo_ops, \ 932 .type = REGULATOR_VOLTAGE, \ 933 .owner = THIS_MODULE, \ 934 }, \ 935 } 936 937 #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 938 static struct twlreg_info TWL6025_INFO_##label = { \ 939 .base = offset, \ 940 .min_mV = min_mVolts, \ 941 .max_mV = max_mVolts, \ 942 .desc = { \ 943 .name = #label, \ 944 .id = TWL6025_REG_##label, \ 945 .n_voltages = 32, \ 946 .ops = &twl6030ldo_ops, \ 947 .type = REGULATOR_VOLTAGE, \ 948 .owner = THIS_MODULE, \ 949 }, \ 950 } 951 952 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ 953 family, operations) \ 954 static struct twlreg_info TWLFIXED_INFO_##label = { \ 955 .base = offset, \ 956 .id = num, \ 957 .min_mV = mVolts, \ 958 .remap = remap_conf, \ 959 .desc = { \ 960 .name = #label, \ 961 .id = family##_REG_##label, \ 962 .n_voltages = 1, \ 963 .ops = &operations, \ 964 .type = REGULATOR_VOLTAGE, \ 965 .owner = THIS_MODULE, \ 966 .enable_time = turnon_delay, \ 967 }, \ 968 } 969 970 #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \ 971 static struct twlreg_info TWLRES_INFO_##label = { \ 972 .base = offset, \ 973 .desc = { \ 974 .name = #label, \ 975 .id = TWL6030_REG_##label, \ 976 .ops = &twl6030_fixed_resource, \ 977 .type = REGULATOR_VOLTAGE, \ 978 .owner = THIS_MODULE, \ 979 .enable_time = turnon_delay, \ 980 }, \ 981 } 982 983 #define TWL6025_ADJUSTABLE_SMPS(label, offset) \ 984 static struct twlreg_info TWLSMPS_INFO_##label = { \ 985 .base = offset, \ 986 .min_mV = 600, \ 987 .max_mV = 2100, \ 988 .desc = { \ 989 .name = #label, \ 990 .id = TWL6025_REG_##label, \ 991 .n_voltages = 63, \ 992 .ops = &twlsmps_ops, \ 993 .type = REGULATOR_VOLTAGE, \ 994 .owner = THIS_MODULE, \ 995 }, \ 996 } 997 998 /* 999 * We list regulators here if systems need some level of 1000 * software control over them after boot. 1001 */ 1002 TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08); 1003 TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08); 1004 TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08); 1005 TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08); 1006 TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08); 1007 TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08); 1008 TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08); 1009 TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00); 1010 TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08); 1011 TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00); 1012 TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08); 1013 TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08); 1014 TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08); 1015 TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08); 1016 TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08); 1017 /* VUSBCP is managed *only* by the USB subchip */ 1018 /* 6030 REG with base as PMC Slave Misc : 0x0030 */ 1019 /* Turnon-delay and remap configuration values for 6030 are not 1020 verified since the specification is not public */ 1021 TWL6030_ADJUSTABLE_SMPS(VDD1); 1022 TWL6030_ADJUSTABLE_SMPS(VDD2); 1023 TWL6030_ADJUSTABLE_SMPS(VDD3); 1024 TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300); 1025 TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300); 1026 TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300); 1027 TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300); 1028 TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300); 1029 TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300); 1030 /* 6025 are renamed compared to 6030 versions */ 1031 TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300); 1032 TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300); 1033 TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300); 1034 TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300); 1035 TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300); 1036 TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300); 1037 TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300); 1038 TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300); 1039 TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300); 1040 TWL4030_FIXED_LDO(VINTANA2, 0x3f, 1500, 11, 100, 0x08); 1041 TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08); 1042 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08); 1043 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08); 1044 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08); 1045 TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0); 1046 TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0); 1047 TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0); 1048 TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0); 1049 TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0); 1050 TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0); 1051 TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0); 1052 TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34); 1053 TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10); 1054 TWL6025_ADJUSTABLE_SMPS(VIO, 0x16); 1055 1056 static u8 twl_get_smps_offset(void) 1057 { 1058 u8 value; 1059 1060 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value, 1061 TWL6030_SMPS_OFFSET); 1062 return value; 1063 } 1064 1065 static u8 twl_get_smps_mult(void) 1066 { 1067 u8 value; 1068 1069 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value, 1070 TWL6030_SMPS_MULT); 1071 return value; 1072 } 1073 1074 #define TWL_OF_MATCH(comp, family, label) \ 1075 { \ 1076 .compatible = comp, \ 1077 .data = &family##_INFO_##label, \ 1078 } 1079 1080 #define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label) 1081 #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label) 1082 #define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label) 1083 #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label) 1084 #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label) 1085 1086 static const struct of_device_id twl_of_match[] __devinitconst = { 1087 TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1), 1088 TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030), 1089 TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2), 1090 TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3), 1091 TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4), 1092 TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1), 1093 TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2), 1094 TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1), 1095 TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2), 1096 TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM), 1097 TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC), 1098 TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2), 1099 TWL4030_OF_MATCH("ti,twl4030-vio", VIO), 1100 TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1), 1101 TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2), 1102 TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1), 1103 TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2), 1104 TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3), 1105 TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030), 1106 TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030), 1107 TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030), 1108 TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC), 1109 TWL6030_OF_MATCH("ti,twl6030-vpp", VPP), 1110 TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM), 1111 TWL6025_OF_MATCH("ti,twl6025-ldo2", LDO2), 1112 TWL6025_OF_MATCH("ti,twl6025-ldo4", LDO4), 1113 TWL6025_OF_MATCH("ti,twl6025-ldo3", LDO3), 1114 TWL6025_OF_MATCH("ti,twl6025-ldo5", LDO5), 1115 TWL6025_OF_MATCH("ti,twl6025-ldo1", LDO1), 1116 TWL6025_OF_MATCH("ti,twl6025-ldo7", LDO7), 1117 TWL6025_OF_MATCH("ti,twl6025-ldo6", LDO6), 1118 TWL6025_OF_MATCH("ti,twl6025-ldoln", LDOLN), 1119 TWL6025_OF_MATCH("ti,twl6025-ldousb", LDOUSB), 1120 TWLFIXED_OF_MATCH("ti,twl4030-vintana2", VINTANA2), 1121 TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG), 1122 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5), 1123 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8), 1124 TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1), 1125 TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA), 1126 TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO), 1127 TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC), 1128 TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB), 1129 TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8), 1130 TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1), 1131 TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3), 1132 TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4), 1133 TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO), 1134 {}, 1135 }; 1136 MODULE_DEVICE_TABLE(of, twl_of_match); 1137 1138 static int __devinit twlreg_probe(struct platform_device *pdev) 1139 { 1140 int i, id; 1141 struct twlreg_info *info; 1142 struct regulator_init_data *initdata; 1143 struct regulation_constraints *c; 1144 struct regulator_dev *rdev; 1145 struct twl_regulator_driver_data *drvdata; 1146 const struct of_device_id *match; 1147 struct regulator_config config = { }; 1148 1149 match = of_match_device(twl_of_match, &pdev->dev); 1150 if (match) { 1151 info = match->data; 1152 id = info->desc.id; 1153 initdata = of_get_regulator_init_data(&pdev->dev, 1154 pdev->dev.of_node); 1155 drvdata = NULL; 1156 } else { 1157 id = pdev->id; 1158 initdata = pdev->dev.platform_data; 1159 for (i = 0, info = NULL; i < ARRAY_SIZE(twl_of_match); i++) { 1160 info = twl_of_match[i].data; 1161 if (info && info->desc.id == id) 1162 break; 1163 } 1164 if (i == ARRAY_SIZE(twl_of_match)) 1165 return -ENODEV; 1166 1167 drvdata = initdata->driver_data; 1168 if (!drvdata) 1169 return -EINVAL; 1170 } 1171 1172 if (!info) 1173 return -ENODEV; 1174 1175 if (!initdata) 1176 return -EINVAL; 1177 1178 if (drvdata) { 1179 /* copy the driver data into regulator data */ 1180 info->features = drvdata->features; 1181 info->data = drvdata->data; 1182 info->set_voltage = drvdata->set_voltage; 1183 info->get_voltage = drvdata->get_voltage; 1184 } 1185 1186 /* Constrain board-specific capabilities according to what 1187 * this driver and the chip itself can actually do. 1188 */ 1189 c = &initdata->constraints; 1190 c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY; 1191 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE 1192 | REGULATOR_CHANGE_MODE 1193 | REGULATOR_CHANGE_STATUS; 1194 switch (id) { 1195 case TWL4030_REG_VIO: 1196 case TWL4030_REG_VDD1: 1197 case TWL4030_REG_VDD2: 1198 case TWL4030_REG_VPLL1: 1199 case TWL4030_REG_VINTANA1: 1200 case TWL4030_REG_VINTANA2: 1201 case TWL4030_REG_VINTDIG: 1202 c->always_on = true; 1203 break; 1204 default: 1205 break; 1206 } 1207 1208 switch (id) { 1209 case TWL6025_REG_SMPS3: 1210 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3) 1211 info->flags |= SMPS_EXTENDED_EN; 1212 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3) 1213 info->flags |= SMPS_OFFSET_EN; 1214 break; 1215 case TWL6025_REG_SMPS4: 1216 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4) 1217 info->flags |= SMPS_EXTENDED_EN; 1218 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4) 1219 info->flags |= SMPS_OFFSET_EN; 1220 break; 1221 case TWL6025_REG_VIO: 1222 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO) 1223 info->flags |= SMPS_EXTENDED_EN; 1224 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO) 1225 info->flags |= SMPS_OFFSET_EN; 1226 break; 1227 } 1228 1229 config.dev = &pdev->dev; 1230 config.init_data = initdata; 1231 config.driver_data = info; 1232 config.of_node = pdev->dev.of_node; 1233 1234 rdev = regulator_register(&info->desc, &config); 1235 if (IS_ERR(rdev)) { 1236 dev_err(&pdev->dev, "can't register %s, %ld\n", 1237 info->desc.name, PTR_ERR(rdev)); 1238 return PTR_ERR(rdev); 1239 } 1240 platform_set_drvdata(pdev, rdev); 1241 1242 if (twl_class_is_4030()) 1243 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP, 1244 info->remap); 1245 1246 /* NOTE: many regulators support short-circuit IRQs (presentable 1247 * as REGULATOR_OVER_CURRENT notifications?) configured via: 1248 * - SC_CONFIG 1249 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4) 1250 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2) 1251 * - IT_CONFIG 1252 */ 1253 1254 return 0; 1255 } 1256 1257 static int __devexit twlreg_remove(struct platform_device *pdev) 1258 { 1259 regulator_unregister(platform_get_drvdata(pdev)); 1260 return 0; 1261 } 1262 1263 MODULE_ALIAS("platform:twl_reg"); 1264 1265 static struct platform_driver twlreg_driver = { 1266 .probe = twlreg_probe, 1267 .remove = __devexit_p(twlreg_remove), 1268 /* NOTE: short name, to work around driver model truncation of 1269 * "twl_regulator.12" (and friends) to "twl_regulator.1". 1270 */ 1271 .driver = { 1272 .name = "twl_reg", 1273 .owner = THIS_MODULE, 1274 .of_match_table = of_match_ptr(twl_of_match), 1275 }, 1276 }; 1277 1278 static int __init twlreg_init(void) 1279 { 1280 return platform_driver_register(&twlreg_driver); 1281 } 1282 subsys_initcall(twlreg_init); 1283 1284 static void __exit twlreg_exit(void) 1285 { 1286 platform_driver_unregister(&twlreg_driver); 1287 } 1288 module_exit(twlreg_exit) 1289 1290 MODULE_DESCRIPTION("TWL regulator driver"); 1291 MODULE_LICENSE("GPL"); 1292