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

Merge tag 'regulator-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator into next/drivers

The pxa regulator branch removes the bq24022 driver, while a lot of
other regulator drivers got added in the regulator tree. This
resolves the trivial conflicts by merging in the regulator patches
that are already merged into v3.4.

Conflicts:
drivers/regulator/Kconfig
drivers/regulator/Makefile

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+3742 -1130
+68
Documentation/devicetree/bindings/regulator/twl-regulator.txt
··· 1 + TWL family of regulators 2 + 3 + Required properties: 4 + For twl6030 regulators/LDOs 5 + - compatible: 6 + - "ti,twl6030-vaux1" for VAUX1 LDO 7 + - "ti,twl6030-vaux2" for VAUX2 LDO 8 + - "ti,twl6030-vaux3" for VAUX3 LDO 9 + - "ti,twl6030-vmmc" for VMMC LDO 10 + - "ti,twl6030-vpp" for VPP LDO 11 + - "ti,twl6030-vusim" for VUSIM LDO 12 + - "ti,twl6030-vana" for VANA LDO 13 + - "ti,twl6030-vcxio" for VCXIO LDO 14 + - "ti,twl6030-vdac" for VDAC LDO 15 + - "ti,twl6030-vusb" for VUSB LDO 16 + - "ti,twl6030-v1v8" for V1V8 LDO 17 + - "ti,twl6030-v2v1" for V2V1 LDO 18 + - "ti,twl6030-clk32kg" for CLK32KG RESOURCE 19 + - "ti,twl6030-vdd1" for VDD1 SMPS 20 + - "ti,twl6030-vdd2" for VDD2 SMPS 21 + - "ti,twl6030-vdd3" for VDD3 SMPS 22 + For twl6025 regulators/LDOs 23 + - compatible: 24 + - "ti,twl6025-ldo1" for LDO1 LDO 25 + - "ti,twl6025-ldo2" for LDO2 LDO 26 + - "ti,twl6025-ldo3" for LDO3 LDO 27 + - "ti,twl6025-ldo4" for LDO4 LDO 28 + - "ti,twl6025-ldo5" for LDO5 LDO 29 + - "ti,twl6025-ldo6" for LDO6 LDO 30 + - "ti,twl6025-ldo7" for LDO7 LDO 31 + - "ti,twl6025-ldoln" for LDOLN LDO 32 + - "ti,twl6025-ldousb" for LDOUSB LDO 33 + - "ti,twl6025-smps3" for SMPS3 SMPS 34 + - "ti,twl6025-smps4" for SMPS4 SMPS 35 + - "ti,twl6025-vio" for VIO SMPS 36 + For twl4030 regulators/LDOs 37 + - compatible: 38 + - "ti,twl4030-vaux1" for VAUX1 LDO 39 + - "ti,twl4030-vaux2" for VAUX2 LDO 40 + - "ti,twl5030-vaux2" for VAUX2 LDO 41 + - "ti,twl4030-vaux3" for VAUX3 LDO 42 + - "ti,twl4030-vaux4" for VAUX4 LDO 43 + - "ti,twl4030-vmmc1" for VMMC1 LDO 44 + - "ti,twl4030-vmmc2" for VMMC2 LDO 45 + - "ti,twl4030-vpll1" for VPLL1 LDO 46 + - "ti,twl4030-vpll2" for VPLL2 LDO 47 + - "ti,twl4030-vsim" for VSIM LDO 48 + - "ti,twl4030-vdac" for VDAC LDO 49 + - "ti,twl4030-vintana2" for VINTANA2 LDO 50 + - "ti,twl4030-vio" for VIO LDO 51 + - "ti,twl4030-vdd1" for VDD1 SMPS 52 + - "ti,twl4030-vdd2" for VDD2 SMPS 53 + - "ti,twl4030-vintana1" for VINTANA1 LDO 54 + - "ti,twl4030-vintdig" for VINTDIG LDO 55 + - "ti,twl4030-vusb1v5" for VUSB1V5 LDO 56 + - "ti,twl4030-vusb1v8" for VUSB1V8 LDO 57 + - "ti,twl4030-vusb3v1" for VUSB3V1 LDO 58 + 59 + Optional properties: 60 + - Any optional property defined in bindings/regulator/regulator.txt 61 + 62 + Example: 63 + 64 + xyz: regulator@0 { 65 + compatible = "ti,twl6030-vaux1"; 66 + regulator-min-microvolt = <1000000>; 67 + regulator-max-microvolt = <3000000>; 68 + };
+5
Documentation/driver-model/devres.txt
··· 271 271 pcim_iounmap() 272 272 pcim_iomap_table() : array of mapped addresses indexed by BAR 273 273 pcim_iomap_regions() : do request_region() and iomap() on multiple BARs 274 + 275 + REGULATOR 276 + devm_regulator_get() 277 + devm_regulator_put() 278 + devm_regulator_bulk_get()
+9
arch/arm/mach-imx/mach-pcm037.c
··· 32 32 #include <linux/usb/ulpi.h> 33 33 #include <linux/gfp.h> 34 34 #include <linux/memblock.h> 35 + #include <linux/regulator/machine.h> 36 + #include <linux/regulator/fixed.h> 35 37 36 38 #include <media/soc_camera.h> 37 39 ··· 572 570 } 573 571 __setup("otg_mode=", pcm037_otg_mode); 574 572 573 + static struct regulator_consumer_supply dummy_supplies[] = { 574 + REGULATOR_SUPPLY("vdd33a", "smsc911x"), 575 + REGULATOR_SUPPLY("vddvario", "smsc911x"), 576 + }; 577 + 575 578 /* 576 579 * Board specific initialization. 577 580 */ ··· 585 578 int ret; 586 579 587 580 imx31_soc_init(); 581 + 582 + regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies)); 588 583 589 584 mxc_iomux_set_gpr(MUX_PGP_UH2, 1); 590 585
-2
arch/arm/mach-u300/i2c.c
··· 60 60 */ 61 61 static struct regulator_consumer_supply supply_ldo_d[] = { 62 62 { 63 - .dev = NULL, 64 63 .supply = "vana15", /* Powers the SoC (CPU etc) */ 65 64 }, 66 65 }; ··· 91 92 */ 92 93 static struct regulator_consumer_supply supply_ldo_ext[] = { 93 94 { 94 - .dev = NULL, 95 95 .supply = "vext", /* External power */ 96 96 }, 97 97 };
+9
arch/arm/plat-mxc/3ds_debugboard.c
··· 16 16 #include <linux/platform_device.h> 17 17 #include <linux/gpio.h> 18 18 #include <linux/smsc911x.h> 19 + #include <linux/regulator/machine.h> 20 + #include <linux/regulator/fixed.h> 19 21 20 22 #include <mach/hardware.h> 21 23 ··· 150 148 .irq_unmask = expio_unmask_irq, 151 149 }; 152 150 151 + static struct regulator_consumer_supply dummy_supplies[] = { 152 + REGULATOR_SUPPLY("vdd33a", "smsc911x"), 153 + REGULATOR_SUPPLY("vddvario", "smsc911x"), 154 + }; 155 + 153 156 int __init mxc_expio_init(u32 base, u32 p_irq) 154 157 { 155 158 int i; ··· 195 188 irq_set_chained_handler(p_irq, mxc_expio_irq_handler); 196 189 197 190 /* Register Lan device on the debugboard */ 191 + regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies)); 192 + 198 193 smsc911x_resources[0].start = LAN9217_BASE_ADDR(base); 199 194 smsc911x_resources[0].end = LAN9217_BASE_ADDR(base) + 0x100 - 1; 200 195 platform_device_register(&smsc_lan9217_device);
+44 -5
drivers/mfd/twl-core.c
··· 617 617 unsigned num_consumers, unsigned long features) 618 618 { 619 619 unsigned sub_chip_id; 620 + struct twl_regulator_driver_data drv_data; 621 + 620 622 /* regulator framework demands init_data ... */ 621 623 if (!pdata) 622 624 return NULL; ··· 628 626 pdata->num_consumer_supplies = num_consumers; 629 627 } 630 628 631 - pdata->driver_data = (void *)features; 629 + if (pdata->driver_data) { 630 + /* If we have existing drv_data, just add the flags */ 631 + struct twl_regulator_driver_data *tmp; 632 + tmp = pdata->driver_data; 633 + tmp->features |= features; 634 + } else { 635 + /* add new driver data struct, used only during init */ 636 + drv_data.features = features; 637 + drv_data.set_voltage = NULL; 638 + drv_data.get_voltage = NULL; 639 + drv_data.data = NULL; 640 + pdata->driver_data = &drv_data; 641 + } 632 642 633 643 /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */ 634 644 sub_chip_id = twl_map[TWL_MODULE_PM_MASTER].sid; ··· 763 749 764 750 /* we need to connect regulators to this transceiver */ 765 751 if (twl_has_regulator() && child) { 766 - usb1v5.dev = child; 767 - usb1v8.dev = child; 768 - usb3v1.dev = child; 752 + usb1v5.dev_name = dev_name(child); 753 + usb1v8.dev_name = dev_name(child); 754 + usb3v1.dev_name = dev_name(child); 769 755 } 770 756 } 771 757 if (twl_has_usb() && pdata->usb && twl_class_is_6030()) { ··· 811 797 return PTR_ERR(child); 812 798 /* we need to connect regulators to this transceiver */ 813 799 if (twl_has_regulator() && child) 814 - usb3v3.dev = child; 800 + usb3v3.dev_name = dev_name(child); 815 801 } else if (twl_has_regulator() && twl_class_is_6030()) { 816 802 if (features & TWL6025_SUBCLASS) 817 803 child = add_regulator(TWL6025_REG_LDOUSB, ··· 947 933 /* twl6030 regulators */ 948 934 if (twl_has_regulator() && twl_class_is_6030() && 949 935 !(features & TWL6025_SUBCLASS)) { 936 + child = add_regulator(TWL6030_REG_VDD1, pdata->vdd1, 937 + features); 938 + if (IS_ERR(child)) 939 + return PTR_ERR(child); 940 + 941 + child = add_regulator(TWL6030_REG_VDD2, pdata->vdd2, 942 + features); 943 + if (IS_ERR(child)) 944 + return PTR_ERR(child); 945 + 946 + child = add_regulator(TWL6030_REG_VDD3, pdata->vdd3, 947 + features); 948 + if (IS_ERR(child)) 949 + return PTR_ERR(child); 950 + 951 + child = add_regulator(TWL6030_REG_V1V8, pdata->v1v8, 952 + features); 953 + if (IS_ERR(child)) 954 + return PTR_ERR(child); 955 + 956 + child = add_regulator(TWL6030_REG_V2V1, pdata->v2v1, 957 + features); 958 + if (IS_ERR(child)) 959 + return PTR_ERR(child); 960 + 950 961 child = add_regulator(TWL6030_REG_VMMC, pdata->vmmc, 951 962 features); 952 963 if (IS_ERR(child))
+204 -165
drivers/regulator/Kconfig
··· 74 74 and the platform has to provide a mapping of GPIO-states 75 75 to target volts/amps. 76 76 77 + config REGULATOR_AD5398 78 + tristate "Analog Devices AD5398/AD5821 regulators" 79 + depends on I2C 80 + help 81 + This driver supports AD5398 and AD5821 current regulator chips. 82 + If building into module, its name is ad5398.ko. 83 + 84 + config REGULATOR_AAT2870 85 + tristate "AnalogicTech AAT2870 Regulators" 86 + depends on MFD_AAT2870_CORE 87 + help 88 + If you have a AnalogicTech AAT2870 say Y to enable the 89 + regulator driver. 90 + 91 + config REGULATOR_DA903X 92 + tristate "Dialog Semiconductor DA9030/DA9034 regulators" 93 + depends on PMIC_DA903X 94 + help 95 + Say y here to support the BUCKs and LDOs regulators found on 96 + Dialog Semiconductor DA9030/DA9034 PMIC. 97 + 98 + config REGULATOR_DA9052 99 + tristate "Dialog Semiconductor DA9052/DA9053 regulators" 100 + depends on PMIC_DA9052 101 + help 102 + This driver supports the voltage regulators of DA9052-BC and 103 + DA9053-AA/Bx PMIC. 104 + 105 + config REGULATOR_ANATOP 106 + tristate "Freescale i.MX on-chip ANATOP LDO regulators" 107 + depends on MFD_ANATOP 108 + help 109 + Say y here to support Freescale i.MX on-chip ANATOP LDOs 110 + regulators. It is recommended that this option be 111 + enabled on i.MX6 platform. 112 + 113 + config REGULATOR_MC13XXX_CORE 114 + tristate 115 + 116 + config REGULATOR_MC13783 117 + tristate "Freescale MC13783 regulator driver" 118 + depends on MFD_MC13783 119 + select REGULATOR_MC13XXX_CORE 120 + help 121 + Say y here to support the regulators found on the Freescale MC13783 122 + PMIC. 123 + 124 + config REGULATOR_MC13892 125 + tristate "Freescale MC13892 regulator driver" 126 + depends on MFD_MC13XXX 127 + select REGULATOR_MC13XXX_CORE 128 + help 129 + Say y here to support the regulators found on the Freescale MC13892 130 + PMIC. 131 + 132 + config REGULATOR_ISL6271A 133 + tristate "Intersil ISL6271A Power regulator" 134 + depends on I2C 135 + help 136 + This driver supports ISL6271A voltage regulator chip. 137 + 138 + config REGULATOR_88PM8607 139 + bool "Marvell 88PM8607 Power regulators" 140 + depends on MFD_88PM860X=y 141 + help 142 + This driver supports 88PM8607 voltage regulator chips. 143 + 77 144 config REGULATOR_MAX1586 78 145 tristate "Maxim 1586/1587 voltage regulator" 79 146 depends on I2C ··· 195 128 via I2C bus. The provided regulator is suitable for S3C6410 196 129 and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages. 197 130 131 + config REGULATOR_PCAP 132 + tristate "Motorola PCAP2 regulator driver" 133 + depends on EZX_PCAP 134 + help 135 + This driver provides support for the voltage regulators of the 136 + PCAP2 PMIC. 137 + 138 + config REGULATOR_LP3971 139 + tristate "National Semiconductors LP3971 PMIC regulator driver" 140 + depends on I2C 141 + help 142 + Say Y here to support the voltage regulators and convertors 143 + on National Semiconductors LP3971 PMIC 144 + 145 + config REGULATOR_LP3972 146 + tristate "National Semiconductors LP3972 PMIC regulator driver" 147 + depends on I2C 148 + help 149 + Say Y here to support the voltage regulators and convertors 150 + on National Semiconductors LP3972 PMIC 151 + 152 + config REGULATOR_PCF50633 153 + tristate "NXP PCF50633 regulator driver" 154 + depends on MFD_PCF50633 155 + help 156 + Say Y here to support the voltage regulators and convertors 157 + on PCF50633 158 + 159 + config REGULATOR_S5M8767 160 + tristate "Samsung S5M8767A voltage regulator" 161 + depends on MFD_S5M_CORE 162 + help 163 + This driver supports a Samsung S5M8767A voltage output regulator 164 + via I2C bus. S5M8767A have 9 Bucks and 28 LDOs output and 165 + supports DVS mode with 8bits of output voltage control. 166 + 167 + config REGULATOR_AB3100 168 + tristate "ST-Ericsson AB3100 Regulator functions" 169 + depends on AB3100_CORE 170 + default y if AB3100_CORE 171 + help 172 + These regulators correspond to functionality in the 173 + AB3100 analog baseband dealing with power regulators 174 + for the system. 175 + 176 + config REGULATOR_AB8500 177 + bool "ST-Ericsson AB8500 Power Regulators" 178 + depends on AB8500_CORE 179 + help 180 + This driver supports the regulators found on the ST-Ericsson mixed 181 + signal AB8500 PMIC 182 + 183 + config REGULATOR_DBX500_PRCMU 184 + bool 185 + 186 + config REGULATOR_DB8500_PRCMU 187 + bool "ST-Ericsson DB8500 Voltage Domain Regulators" 188 + depends on MFD_DB8500_PRCMU 189 + select REGULATOR_DBX500_PRCMU 190 + help 191 + This driver supports the voltage domain regulators controlled by the 192 + DB8500 PRCMU 193 + 194 + config REGULATOR_TPS6105X 195 + tristate "TI TPS6105X Power regulators" 196 + depends on TPS6105X 197 + default y if TPS6105X 198 + help 199 + This driver supports TPS61050/TPS61052 voltage regulator chips. 200 + It is a single boost converter primarily for white LEDs and 201 + audio amplifiers. 202 + 203 + config REGULATOR_TPS62360 204 + tristate "TI TPS62360 Power Regulator" 205 + depends on I2C 206 + select REGMAP_I2C 207 + help 208 + This driver supports TPS62360 voltage regulator chip. This 209 + regulator is meant for processor core supply. This chip is 210 + high-frequency synchronous step down dc-dc converter optimized 211 + for battery-powered portable applications. 212 + 213 + config REGULATOR_TPS65023 214 + tristate "TI TPS65023 Power regulators" 215 + depends on I2C 216 + select REGMAP_I2C 217 + help 218 + This driver supports TPS65023 voltage regulator chips. TPS65023 provides 219 + three step-down converters and two general-purpose LDO voltage regulators. 220 + It supports TI's software based Class-2 SmartReflex implementation. 221 + 222 + config REGULATOR_TPS6507X 223 + tristate "TI TPS6507X Power regulators" 224 + depends on I2C 225 + help 226 + This driver supports TPS6507X voltage regulator chips. TPS6507X provides 227 + three step-down converters and two general-purpose LDO voltage regulators. 228 + It supports TI's software based Class-2 SmartReflex implementation. 229 + 230 + config REGULATOR_TPS65217 231 + tristate "TI TPS65217 Power regulators" 232 + depends on MFD_TPS65217 233 + help 234 + This driver supports TPS65217 voltage regulator chips. TPS65217 235 + provides three step-down converters and four general-purpose LDO 236 + voltage regulators. It supports software based voltage control 237 + for different voltage domains 238 + 239 + config REGULATOR_TPS6524X 240 + tristate "TI TPS6524X Power regulators" 241 + depends on SPI 242 + help 243 + This driver supports TPS6524X voltage regulator chips. TPS6524X 244 + provides three step-down converters and two general-purpose LDO 245 + voltage regulators. This device is interfaced using a customized 246 + serial interface currently supported on the sequencer serial 247 + port controller. 248 + 249 + config REGULATOR_TPS6586X 250 + tristate "TI TPS6586X Power regulators" 251 + depends on MFD_TPS6586X 252 + help 253 + This driver supports TPS6586X voltage regulator chips. 254 + 255 + config REGULATOR_TPS65910 256 + tristate "TI TPS65910/TPS65911 Power Regulators" 257 + depends on MFD_TPS65910 258 + help 259 + This driver supports TPS65910/TPS65911 voltage regulator chips. 260 + 261 + config REGULATOR_TPS65912 262 + tristate "TI TPS65912 Power regulator" 263 + depends on (MFD_TPS65912_I2C || MFD_TPS65912_SPI) 264 + help 265 + This driver supports TPS65912 voltage regulator chip. 266 + 198 267 config REGULATOR_TWL4030 199 268 bool "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" 200 269 depends on TWL4030_CORE ··· 339 136 this family of companion chips. 340 137 341 138 config REGULATOR_WM831X 342 - tristate "Wolfson Microelcronics WM831x PMIC regulators" 139 + tristate "Wolfson Microelectronics WM831x PMIC regulators" 343 140 depends on MFD_WM831X 344 141 help 345 142 Support the voltage and current regulators of the WM831x series ··· 365 162 help 366 163 This driver provides support for the voltage regulators on the 367 164 WM8994 CODEC. 368 - 369 - config REGULATOR_DA903X 370 - tristate "Support regulators on Dialog Semiconductor DA9030/DA9034 PMIC" 371 - depends on PMIC_DA903X 372 - help 373 - Say y here to support the BUCKs and LDOs regulators found on 374 - Dialog Semiconductor DA9030/DA9034 PMIC. 375 - 376 - config REGULATOR_DA9052 377 - tristate "Dialog DA9052/DA9053 regulators" 378 - depends on PMIC_DA9052 379 - help 380 - This driver supports the voltage regulators of DA9052-BC and 381 - DA9053-AA/Bx PMIC. 382 - 383 - config REGULATOR_PCF50633 384 - tristate "PCF50633 regulator driver" 385 - depends on MFD_PCF50633 386 - help 387 - Say Y here to support the voltage regulators and convertors 388 - on PCF50633 389 - 390 - config REGULATOR_LP3971 391 - tristate "National Semiconductors LP3971 PMIC regulator driver" 392 - depends on I2C 393 - help 394 - Say Y here to support the voltage regulators and convertors 395 - on National Semiconductors LP3971 PMIC 396 - 397 - config REGULATOR_LP3972 398 - tristate "National Semiconductors LP3972 PMIC regulator driver" 399 - depends on I2C 400 - help 401 - Say Y here to support the voltage regulators and convertors 402 - on National Semiconductors LP3972 PMIC 403 - 404 - config REGULATOR_PCAP 405 - tristate "PCAP2 regulator driver" 406 - depends on EZX_PCAP 407 - help 408 - This driver provides support for the voltage regulators of the 409 - PCAP2 PMIC. 410 - 411 - config REGULATOR_MC13XXX_CORE 412 - tristate 413 - 414 - config REGULATOR_MC13783 415 - tristate "Support regulators on Freescale MC13783 PMIC" 416 - depends on MFD_MC13783 417 - select REGULATOR_MC13XXX_CORE 418 - help 419 - Say y here to support the regulators found on the Freescale MC13783 420 - PMIC. 421 - 422 - config REGULATOR_MC13892 423 - tristate "Support regulators on Freescale MC13892 PMIC" 424 - depends on MFD_MC13XXX 425 - select REGULATOR_MC13XXX_CORE 426 - help 427 - Say y here to support the regulators found on the Freescale MC13892 428 - PMIC. 429 - 430 - config REGULATOR_AB3100 431 - tristate "ST-Ericsson AB3100 Regulator functions" 432 - depends on AB3100_CORE 433 - default y if AB3100_CORE 434 - help 435 - These regulators correspond to functionality in the 436 - AB3100 analog baseband dealing with power regulators 437 - for the system. 438 - 439 - config REGULATOR_TPS6105X 440 - tristate "TI TPS6105X Power regulators" 441 - depends on TPS6105X 442 - default y if TPS6105X 443 - help 444 - This driver supports TPS61050/TPS61052 voltage regulator chips. 445 - It is a single boost converter primarily for white LEDs and 446 - audio amplifiers. 447 - 448 - config REGULATOR_TPS65023 449 - tristate "TI TPS65023 Power regulators" 450 - depends on I2C 451 - select REGMAP_I2C 452 - help 453 - This driver supports TPS65023 voltage regulator chips. TPS65023 provides 454 - three step-down converters and two general-purpose LDO voltage regulators. 455 - It supports TI's software based Class-2 SmartReflex implementation. 456 - 457 - config REGULATOR_TPS6507X 458 - tristate "TI TPS6507X Power regulators" 459 - depends on I2C 460 - help 461 - This driver supports TPS6507X voltage regulator chips. TPS6507X provides 462 - three step-down converters and two general-purpose LDO voltage regulators. 463 - It supports TI's software based Class-2 SmartReflex implementation. 464 - 465 - config REGULATOR_TPS65912 466 - tristate "TI TPS65912 Power regulator" 467 - depends on (MFD_TPS65912_I2C || MFD_TPS65912_SPI) 468 - help 469 - This driver supports TPS65912 voltage regulator chip. 470 - 471 - config REGULATOR_88PM8607 472 - bool "Marvell 88PM8607 Power regulators" 473 - depends on MFD_88PM860X=y 474 - help 475 - This driver supports 88PM8607 voltage regulator chips. 476 - 477 - config REGULATOR_ISL6271A 478 - tristate "Intersil ISL6271A Power regulator" 479 - depends on I2C 480 - help 481 - This driver supports ISL6271A voltage regulator chip. 482 - 483 - config REGULATOR_AD5398 484 - tristate "Analog Devices AD5398/AD5821 regulators" 485 - depends on I2C 486 - help 487 - This driver supports AD5398 and AD5821 current regulator chips. 488 - If building into module, its name is ad5398.ko. 489 - 490 - config REGULATOR_AB8500 491 - bool "ST-Ericsson AB8500 Power Regulators" 492 - depends on AB8500_CORE 493 - help 494 - This driver supports the regulators found on the ST-Ericsson mixed 495 - signal AB8500 PMIC 496 - 497 - config REGULATOR_DB8500_PRCMU 498 - bool "ST-Ericsson DB8500 Voltage Domain Regulators" 499 - depends on MFD_DB8500_PRCMU 500 - help 501 - This driver supports the voltage domain regulators controlled by the 502 - DB8500 PRCMU 503 - 504 - config REGULATOR_TPS6586X 505 - tristate "TI TPS6586X Power regulators" 506 - depends on MFD_TPS6586X 507 - help 508 - This driver supports TPS6586X voltage regulator chips. 509 - 510 - config REGULATOR_TPS6524X 511 - tristate "TI TPS6524X Power regulators" 512 - depends on SPI 513 - help 514 - This driver supports TPS6524X voltage regulator chips. TPS6524X 515 - provides three step-down converters and two general-purpose LDO 516 - voltage regulators. This device is interfaced using a customized 517 - serial interface currently supported on the sequencer serial 518 - port controller. 519 - 520 - config REGULATOR_TPS65910 521 - tristate "TI TPS65910 Power Regulator" 522 - depends on MFD_TPS65910 523 - help 524 - This driver supports TPS65910 voltage regulator chips. 525 - 526 - config REGULATOR_AAT2870 527 - tristate "AnalogicTech AAT2870 Regulators" 528 - depends on MFD_AAT2870_CORE 529 - help 530 - If you have a AnalogicTech AAT2870 say Y to enable the 531 - regulator driver. 532 165 533 166 endif 534 167
+28 -22
drivers/regulator/Makefile
··· 3 3 # 4 4 5 5 6 - obj-$(CONFIG_REGULATOR) += core.o dummy.o 6 + obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o 7 7 obj-$(CONFIG_OF) += of_regulator.o 8 8 obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o 9 9 obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o 10 10 obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o 11 11 12 12 obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o 13 + obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o 14 + obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o 15 + obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o 16 + obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o 13 17 obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o 18 + obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o 19 + obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 20 + obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 21 + obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o 22 + obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o 23 + obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o 14 24 obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o 15 25 obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o 16 26 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o 17 - obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o 18 27 obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o 19 28 obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o 20 29 obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o 21 30 obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o 22 31 obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o 23 32 obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o 33 + obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o 34 + obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o 35 + obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o 36 + obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 37 + obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 38 + obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o 39 + obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o 40 + obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o 41 + obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 42 + obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 43 + obj-$(CONFIG_REGULATOR_TPS65217) += tps65217-regulator.o 44 + obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o 45 + obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o 46 + obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o 47 + obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o 48 + obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o 24 49 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o 25 50 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o 26 51 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o 27 52 obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o 28 53 obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o 29 54 obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o 30 - obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o 31 - obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 32 - obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 33 - obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 34 - obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 35 - obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o 36 - obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o 37 - obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o 38 - obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o 39 - obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o 40 - obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 41 - obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 42 - obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o 43 - obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o 44 - obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o 45 - obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o 46 - obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o 47 - obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o 48 - obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o 49 - obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o 55 + 50 56 51 57 ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
+7 -7
drivers/regulator/aat2870-regulator.c
··· 31 31 #include <linux/mfd/aat2870.h> 32 32 33 33 struct aat2870_regulator { 34 - struct platform_device *pdev; 34 + struct aat2870_data *aat2870; 35 35 struct regulator_desc desc; 36 36 37 37 const int *voltages; /* uV */ ··· 60 60 unsigned selector) 61 61 { 62 62 struct aat2870_regulator *ri = rdev_get_drvdata(rdev); 63 - struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent); 63 + struct aat2870_data *aat2870 = ri->aat2870; 64 64 65 65 return aat2870->update(aat2870, ri->voltage_addr, ri->voltage_mask, 66 66 selector << ri->voltage_shift); ··· 69 69 static int aat2870_ldo_get_voltage_sel(struct regulator_dev *rdev) 70 70 { 71 71 struct aat2870_regulator *ri = rdev_get_drvdata(rdev); 72 - struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent); 72 + struct aat2870_data *aat2870 = ri->aat2870; 73 73 u8 val; 74 74 int ret; 75 75 ··· 83 83 static int aat2870_ldo_enable(struct regulator_dev *rdev) 84 84 { 85 85 struct aat2870_regulator *ri = rdev_get_drvdata(rdev); 86 - struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent); 86 + struct aat2870_data *aat2870 = ri->aat2870; 87 87 88 88 return aat2870->update(aat2870, ri->enable_addr, ri->enable_mask, 89 89 ri->enable_mask); ··· 92 92 static int aat2870_ldo_disable(struct regulator_dev *rdev) 93 93 { 94 94 struct aat2870_regulator *ri = rdev_get_drvdata(rdev); 95 - struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent); 95 + struct aat2870_data *aat2870 = ri->aat2870; 96 96 97 97 return aat2870->update(aat2870, ri->enable_addr, ri->enable_mask, 0); 98 98 } ··· 100 100 static int aat2870_ldo_is_enabled(struct regulator_dev *rdev) 101 101 { 102 102 struct aat2870_regulator *ri = rdev_get_drvdata(rdev); 103 - struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent); 103 + struct aat2870_data *aat2870 = ri->aat2870; 104 104 u8 val; 105 105 int ret; 106 106 ··· 185 185 dev_err(&pdev->dev, "Invalid device ID, %d\n", pdev->id); 186 186 return -EINVAL; 187 187 } 188 - ri->pdev = pdev; 188 + ri->aat2870 = dev_get_drvdata(pdev->dev.parent); 189 189 190 190 rdev = regulator_register(&ri->desc, &pdev->dev, 191 191 pdev->dev.platform_data, ri, NULL);
+4 -6
drivers/regulator/ab8500.c
··· 201 201 return info->voltages[selector]; 202 202 } 203 203 204 - static int ab8500_regulator_get_voltage(struct regulator_dev *rdev) 204 + static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev) 205 205 { 206 206 int ret, val; 207 207 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); ··· 229 229 /* vintcore has a different layout */ 230 230 val = regval & info->voltage_mask; 231 231 if (info->desc.id == AB8500_LDO_INTCORE) 232 - ret = info->voltages[val >> 0x3]; 232 + return val >> 0x3; 233 233 else 234 - ret = info->voltages[val]; 235 - 236 - return ret; 234 + return val; 237 235 } 238 236 239 237 static int ab8500_get_best_voltage_index(struct regulator_dev *rdev, ··· 318 320 .enable = ab8500_regulator_enable, 319 321 .disable = ab8500_regulator_disable, 320 322 .is_enabled = ab8500_regulator_is_enabled, 321 - .get_voltage = ab8500_regulator_get_voltage, 323 + .get_voltage_sel = ab8500_regulator_get_voltage_sel, 322 324 .set_voltage = ab8500_regulator_set_voltage, 323 325 .list_voltage = ab8500_list_voltage, 324 326 .enable_time = ab8500_regulator_enable_time,
+2 -2
drivers/regulator/ad5398.c
··· 94 94 if (max_uA > chip->max_uA || max_uA < chip->min_uA) 95 95 return -EINVAL; 96 96 97 - selector = ((min_uA - chip->min_uA) * chip->current_level + 98 - range_uA - 1) / range_uA; 97 + selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level, 98 + range_uA); 99 99 if (ad5398_calc_current(chip, selector) > max_uA) 100 100 return -EINVAL; 101 101
+241
drivers/regulator/anatop-regulator.c
··· 1 + /* 2 + * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved. 3 + */ 4 + 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 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + 16 + * You should have received a copy of the GNU General Public License along 17 + * with this program; if not, write to the Free Software Foundation, Inc., 18 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 + */ 20 + 21 + #include <linux/slab.h> 22 + #include <linux/device.h> 23 + #include <linux/module.h> 24 + #include <linux/err.h> 25 + #include <linux/io.h> 26 + #include <linux/platform_device.h> 27 + #include <linux/of.h> 28 + #include <linux/of_address.h> 29 + #include <linux/mfd/anatop.h> 30 + #include <linux/regulator/driver.h> 31 + #include <linux/regulator/of_regulator.h> 32 + 33 + struct anatop_regulator { 34 + const char *name; 35 + u32 control_reg; 36 + struct anatop *mfd; 37 + int vol_bit_shift; 38 + int vol_bit_width; 39 + int min_bit_val; 40 + int min_voltage; 41 + int max_voltage; 42 + struct regulator_desc rdesc; 43 + struct regulator_init_data *initdata; 44 + }; 45 + 46 + static int anatop_set_voltage(struct regulator_dev *reg, int min_uV, 47 + int max_uV, unsigned *selector) 48 + { 49 + struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); 50 + u32 val, sel; 51 + int uv; 52 + 53 + uv = min_uV; 54 + dev_dbg(&reg->dev, "%s: uv %d, min %d, max %d\n", __func__, 55 + uv, anatop_reg->min_voltage, 56 + anatop_reg->max_voltage); 57 + 58 + if (uv < anatop_reg->min_voltage) { 59 + if (max_uV > anatop_reg->min_voltage) 60 + uv = anatop_reg->min_voltage; 61 + else 62 + return -EINVAL; 63 + } 64 + 65 + if (!anatop_reg->control_reg) 66 + return -ENOTSUPP; 67 + 68 + sel = DIV_ROUND_UP(uv - anatop_reg->min_voltage, 25000); 69 + if (sel * 25000 + anatop_reg->min_voltage > anatop_reg->max_voltage) 70 + return -EINVAL; 71 + val = anatop_reg->min_bit_val + sel; 72 + *selector = sel; 73 + dev_dbg(&reg->dev, "%s: calculated val %d\n", __func__, val); 74 + anatop_set_bits(anatop_reg->mfd, 75 + anatop_reg->control_reg, 76 + anatop_reg->vol_bit_shift, 77 + anatop_reg->vol_bit_width, 78 + val); 79 + 80 + return 0; 81 + } 82 + 83 + static int anatop_get_voltage_sel(struct regulator_dev *reg) 84 + { 85 + struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); 86 + u32 val; 87 + 88 + if (!anatop_reg->control_reg) 89 + return -ENOTSUPP; 90 + 91 + val = anatop_get_bits(anatop_reg->mfd, 92 + anatop_reg->control_reg, 93 + anatop_reg->vol_bit_shift, 94 + anatop_reg->vol_bit_width); 95 + 96 + return val - anatop_reg->min_bit_val; 97 + } 98 + 99 + static int anatop_list_voltage(struct regulator_dev *reg, unsigned selector) 100 + { 101 + struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); 102 + int uv; 103 + 104 + uv = anatop_reg->min_voltage + selector * 25000; 105 + dev_dbg(&reg->dev, "vddio = %d, selector = %u\n", uv, selector); 106 + 107 + return uv; 108 + } 109 + 110 + static struct regulator_ops anatop_rops = { 111 + .set_voltage = anatop_set_voltage, 112 + .get_voltage_sel = anatop_get_voltage_sel, 113 + .list_voltage = anatop_list_voltage, 114 + }; 115 + 116 + static int __devinit anatop_regulator_probe(struct platform_device *pdev) 117 + { 118 + struct device *dev = &pdev->dev; 119 + struct device_node *np = dev->of_node; 120 + struct regulator_desc *rdesc; 121 + struct regulator_dev *rdev; 122 + struct anatop_regulator *sreg; 123 + struct regulator_init_data *initdata; 124 + struct anatop *anatopmfd = dev_get_drvdata(pdev->dev.parent); 125 + int ret = 0; 126 + 127 + initdata = of_get_regulator_init_data(dev, np); 128 + sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL); 129 + if (!sreg) 130 + return -ENOMEM; 131 + sreg->initdata = initdata; 132 + sreg->name = kstrdup(of_get_property(np, "regulator-name", NULL), 133 + GFP_KERNEL); 134 + rdesc = &sreg->rdesc; 135 + memset(rdesc, 0, sizeof(*rdesc)); 136 + rdesc->name = sreg->name; 137 + rdesc->ops = &anatop_rops; 138 + rdesc->type = REGULATOR_VOLTAGE; 139 + rdesc->owner = THIS_MODULE; 140 + sreg->mfd = anatopmfd; 141 + ret = of_property_read_u32(np, "reg", &sreg->control_reg); 142 + if (ret) { 143 + dev_err(dev, "no reg property set\n"); 144 + goto anatop_probe_end; 145 + } 146 + ret = of_property_read_u32(np, "anatop-vol-bit-width", 147 + &sreg->vol_bit_width); 148 + if (ret) { 149 + dev_err(dev, "no anatop-vol-bit-width property set\n"); 150 + goto anatop_probe_end; 151 + } 152 + ret = of_property_read_u32(np, "anatop-vol-bit-shift", 153 + &sreg->vol_bit_shift); 154 + if (ret) { 155 + dev_err(dev, "no anatop-vol-bit-shift property set\n"); 156 + goto anatop_probe_end; 157 + } 158 + ret = of_property_read_u32(np, "anatop-min-bit-val", 159 + &sreg->min_bit_val); 160 + if (ret) { 161 + dev_err(dev, "no anatop-min-bit-val property set\n"); 162 + goto anatop_probe_end; 163 + } 164 + ret = of_property_read_u32(np, "anatop-min-voltage", 165 + &sreg->min_voltage); 166 + if (ret) { 167 + dev_err(dev, "no anatop-min-voltage property set\n"); 168 + goto anatop_probe_end; 169 + } 170 + ret = of_property_read_u32(np, "anatop-max-voltage", 171 + &sreg->max_voltage); 172 + if (ret) { 173 + dev_err(dev, "no anatop-max-voltage property set\n"); 174 + goto anatop_probe_end; 175 + } 176 + 177 + rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage) 178 + / 25000 + 1; 179 + 180 + /* register regulator */ 181 + rdev = regulator_register(rdesc, dev, 182 + initdata, sreg, pdev->dev.of_node); 183 + if (IS_ERR(rdev)) { 184 + dev_err(dev, "failed to register %s\n", 185 + rdesc->name); 186 + ret = PTR_ERR(rdev); 187 + goto anatop_probe_end; 188 + } 189 + 190 + platform_set_drvdata(pdev, rdev); 191 + 192 + anatop_probe_end: 193 + if (ret) 194 + kfree(sreg->name); 195 + 196 + return ret; 197 + } 198 + 199 + static int __devexit anatop_regulator_remove(struct platform_device *pdev) 200 + { 201 + struct regulator_dev *rdev = platform_get_drvdata(pdev); 202 + struct anatop_regulator *sreg = rdev_get_drvdata(rdev); 203 + const char *name = sreg->name; 204 + 205 + regulator_unregister(rdev); 206 + kfree(name); 207 + 208 + return 0; 209 + } 210 + 211 + static struct of_device_id __devinitdata of_anatop_regulator_match_tbl[] = { 212 + { .compatible = "fsl,anatop-regulator", }, 213 + { /* end */ } 214 + }; 215 + 216 + static struct platform_driver anatop_regulator = { 217 + .driver = { 218 + .name = "anatop_regulator", 219 + .owner = THIS_MODULE, 220 + .of_match_table = of_anatop_regulator_match_tbl, 221 + }, 222 + .probe = anatop_regulator_probe, 223 + .remove = anatop_regulator_remove, 224 + }; 225 + 226 + static int __init anatop_regulator_init(void) 227 + { 228 + return platform_driver_register(&anatop_regulator); 229 + } 230 + postcore_initcall(anatop_regulator_init); 231 + 232 + static void __exit anatop_regulator_exit(void) 233 + { 234 + platform_driver_unregister(&anatop_regulator); 235 + } 236 + module_exit(anatop_regulator_exit); 237 + 238 + MODULE_AUTHOR("Nancy Chen <Nancy.Chen@freescale.com>, " 239 + "Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>"); 240 + MODULE_DESCRIPTION("ANATOP Regulator driver"); 241 + MODULE_LICENSE("GPL v2");
+143 -57
drivers/regulator/core.c
··· 13 13 * 14 14 */ 15 15 16 - #define pr_fmt(fmt) "%s: " fmt, __func__ 17 - 18 16 #include <linux/kernel.h> 19 17 #include <linux/init.h> 20 18 #include <linux/debugfs.h> ··· 52 54 static bool has_full_constraints; 53 55 static bool board_wants_dummy_regulator; 54 56 55 - #ifdef CONFIG_DEBUG_FS 56 57 static struct dentry *debugfs_root; 57 - #endif 58 58 59 59 /* 60 60 * struct regulator_map ··· 80 84 char *supply_name; 81 85 struct device_attribute dev_attr; 82 86 struct regulator_dev *rdev; 83 - #ifdef CONFIG_DEBUG_FS 84 87 struct dentry *debugfs; 85 - #endif 86 88 }; 87 89 88 90 static int _regulator_is_enabled(struct regulator_dev *rdev); ··· 148 154 regnode = of_parse_phandle(dev->of_node, prop_name, 0); 149 155 150 156 if (!regnode) { 151 - dev_warn(dev, "%s property in node %s references invalid phandle", 157 + dev_dbg(dev, "Looking up %s property in node %s failed", 152 158 prop_name, dev->of_node->full_name); 153 159 return NULL; 154 160 } ··· 801 807 count += sprintf(buf + count, "standby"); 802 808 803 809 rdev_info(rdev, "%s\n", buf); 810 + 811 + if ((constraints->min_uV != constraints->max_uV) && 812 + !(constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) 813 + rdev_warn(rdev, 814 + "Voltage range but no REGULATOR_CHANGE_VOLTAGE\n"); 804 815 } 805 816 806 817 static int machine_constraints_voltage(struct regulator_dev *rdev, ··· 995 996 /** 996 997 * set_consumer_device_supply - Bind a regulator to a symbolic supply 997 998 * @rdev: regulator source 998 - * @consumer_dev: device the supply applies to 999 999 * @consumer_dev_name: dev_name() string for device supply applies to 1000 1000 * @supply: symbolic name for supply 1001 1001 * ··· 1002 1004 * sources to symbolic names for supplies for use by devices. Devices 1003 1005 * should use these symbolic names to request regulators, avoiding the 1004 1006 * need to provide board-specific regulator names as platform data. 1005 - * 1006 - * Only one of consumer_dev and consumer_dev_name may be specified. 1007 1007 */ 1008 1008 static int set_consumer_device_supply(struct regulator_dev *rdev, 1009 - struct device *consumer_dev, const char *consumer_dev_name, 1010 - const char *supply) 1009 + const char *consumer_dev_name, 1010 + const char *supply) 1011 1011 { 1012 1012 struct regulator_map *node; 1013 1013 int has_dev; 1014 - 1015 - if (consumer_dev && consumer_dev_name) 1016 - return -EINVAL; 1017 - 1018 - if (!consumer_dev_name && consumer_dev) 1019 - consumer_dev_name = dev_name(consumer_dev); 1020 1014 1021 1015 if (supply == NULL) 1022 1016 return -EINVAL; ··· 1029 1039 if (strcmp(node->supply, supply) != 0) 1030 1040 continue; 1031 1041 1032 - dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n", 1033 - dev_name(&node->regulator->dev), 1034 - node->regulator->desc->name, 1035 - supply, 1036 - dev_name(&rdev->dev), rdev_get_name(rdev)); 1042 + pr_debug("%s: %s/%s is '%s' supply; fail %s/%s\n", 1043 + consumer_dev_name, 1044 + dev_name(&node->regulator->dev), 1045 + node->regulator->desc->name, 1046 + supply, 1047 + dev_name(&rdev->dev), rdev_get_name(rdev)); 1037 1048 return -EBUSY; 1038 1049 } 1039 1050 ··· 1133 1142 goto attr_err; 1134 1143 } 1135 1144 1136 - #ifdef CONFIG_DEBUG_FS 1137 1145 regulator->debugfs = debugfs_create_dir(regulator->supply_name, 1138 1146 rdev->debugfs); 1139 - if (IS_ERR_OR_NULL(regulator->debugfs)) { 1147 + if (!regulator->debugfs) { 1140 1148 rdev_warn(rdev, "Failed to create debugfs directory\n"); 1141 - regulator->debugfs = NULL; 1142 1149 } else { 1143 1150 debugfs_create_u32("uA_load", 0444, regulator->debugfs, 1144 1151 &regulator->uA_load); ··· 1145 1156 debugfs_create_u32("max_uV", 0444, regulator->debugfs, 1146 1157 &regulator->max_uV); 1147 1158 } 1148 - #endif 1149 1159 1150 1160 mutex_unlock(&rdev->mutex); 1151 1161 return regulator; ··· 1308 1320 } 1309 1321 EXPORT_SYMBOL_GPL(regulator_get); 1310 1322 1323 + static void devm_regulator_release(struct device *dev, void *res) 1324 + { 1325 + regulator_put(*(struct regulator **)res); 1326 + } 1327 + 1328 + /** 1329 + * devm_regulator_get - Resource managed regulator_get() 1330 + * @dev: device for regulator "consumer" 1331 + * @id: Supply name or regulator ID. 1332 + * 1333 + * Managed regulator_get(). Regulators returned from this function are 1334 + * automatically regulator_put() on driver detach. See regulator_get() for more 1335 + * information. 1336 + */ 1337 + struct regulator *devm_regulator_get(struct device *dev, const char *id) 1338 + { 1339 + struct regulator **ptr, *regulator; 1340 + 1341 + ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL); 1342 + if (!ptr) 1343 + return ERR_PTR(-ENOMEM); 1344 + 1345 + regulator = regulator_get(dev, id); 1346 + if (!IS_ERR(regulator)) { 1347 + *ptr = regulator; 1348 + devres_add(dev, ptr); 1349 + } else { 1350 + devres_free(ptr); 1351 + } 1352 + 1353 + return regulator; 1354 + } 1355 + EXPORT_SYMBOL_GPL(devm_regulator_get); 1356 + 1311 1357 /** 1312 1358 * regulator_get_exclusive - obtain exclusive access to a regulator. 1313 1359 * @dev: device for regulator "consumer" ··· 1387 1365 mutex_lock(&regulator_list_mutex); 1388 1366 rdev = regulator->rdev; 1389 1367 1390 - #ifdef CONFIG_DEBUG_FS 1391 1368 debugfs_remove_recursive(regulator->debugfs); 1392 - #endif 1393 1369 1394 1370 /* remove any sysfs entries */ 1395 1371 if (regulator->dev) { ··· 1406 1386 mutex_unlock(&regulator_list_mutex); 1407 1387 } 1408 1388 EXPORT_SYMBOL_GPL(regulator_put); 1389 + 1390 + static int devm_regulator_match(struct device *dev, void *res, void *data) 1391 + { 1392 + struct regulator **r = res; 1393 + if (!r || !*r) { 1394 + WARN_ON(!r || !*r); 1395 + return 0; 1396 + } 1397 + return *r == data; 1398 + } 1399 + 1400 + /** 1401 + * devm_regulator_put - Resource managed regulator_put() 1402 + * @regulator: regulator to free 1403 + * 1404 + * Deallocate a regulator allocated with devm_regulator_get(). Normally 1405 + * this function will not need to be called and the resource management 1406 + * code will ensure that the resource is freed. 1407 + */ 1408 + void devm_regulator_put(struct regulator *regulator) 1409 + { 1410 + int rc; 1411 + 1412 + rc = devres_destroy(regulator->dev, devm_regulator_release, 1413 + devm_regulator_match, regulator); 1414 + WARN_ON(rc); 1415 + } 1416 + EXPORT_SYMBOL_GPL(devm_regulator_put); 1409 1417 1410 1418 static int _regulator_can_change_status(struct regulator_dev *rdev) 1411 1419 { ··· 1890 1842 if (ret < 0) 1891 1843 return ret; 1892 1844 old_selector = ret; 1893 - delay = rdev->desc->ops->set_voltage_time_sel(rdev, 1845 + ret = rdev->desc->ops->set_voltage_time_sel(rdev, 1894 1846 old_selector, selector); 1847 + if (ret < 0) 1848 + rdev_warn(rdev, "set_voltage_time_sel() failed: %d\n", ret); 1849 + else 1850 + delay = ret; 1895 1851 } 1896 1852 1897 1853 if (best_val != INT_MAX) { ··· 2446 2394 return 0; 2447 2395 2448 2396 err: 2449 - for (i = 0; i < num_consumers && consumers[i].consumer; i++) 2397 + while (--i >= 0) 2450 2398 regulator_put(consumers[i].consumer); 2451 2399 2452 2400 return ret; 2453 2401 } 2454 2402 EXPORT_SYMBOL_GPL(regulator_bulk_get); 2403 + 2404 + /** 2405 + * devm_regulator_bulk_get - managed get multiple regulator consumers 2406 + * 2407 + * @dev: Device to supply 2408 + * @num_consumers: Number of consumers to register 2409 + * @consumers: Configuration of consumers; clients are stored here. 2410 + * 2411 + * @return 0 on success, an errno on failure. 2412 + * 2413 + * This helper function allows drivers to get several regulator 2414 + * consumers in one operation with management, the regulators will 2415 + * automatically be freed when the device is unbound. If any of the 2416 + * regulators cannot be acquired then any regulators that were 2417 + * allocated will be freed before returning to the caller. 2418 + */ 2419 + int devm_regulator_bulk_get(struct device *dev, int num_consumers, 2420 + struct regulator_bulk_data *consumers) 2421 + { 2422 + int i; 2423 + int ret; 2424 + 2425 + for (i = 0; i < num_consumers; i++) 2426 + consumers[i].consumer = NULL; 2427 + 2428 + for (i = 0; i < num_consumers; i++) { 2429 + consumers[i].consumer = devm_regulator_get(dev, 2430 + consumers[i].supply); 2431 + if (IS_ERR(consumers[i].consumer)) { 2432 + ret = PTR_ERR(consumers[i].consumer); 2433 + dev_err(dev, "Failed to get supply '%s': %d\n", 2434 + consumers[i].supply, ret); 2435 + consumers[i].consumer = NULL; 2436 + goto err; 2437 + } 2438 + } 2439 + 2440 + return 0; 2441 + 2442 + err: 2443 + for (i = 0; i < num_consumers && consumers[i].consumer; i++) 2444 + devm_regulator_put(consumers[i].consumer); 2445 + 2446 + return ret; 2447 + } 2448 + EXPORT_SYMBOL_GPL(devm_regulator_bulk_get); 2455 2449 2456 2450 static void regulator_bulk_enable_async(void *data, async_cookie_t cookie) 2457 2451 { ··· 2542 2444 return 0; 2543 2445 2544 2446 err: 2545 - for (i = 0; i < num_consumers; i++) 2546 - if (consumers[i].ret == 0) 2547 - regulator_disable(consumers[i].consumer); 2548 - else 2549 - pr_err("Failed to enable %s: %d\n", 2550 - consumers[i].supply, consumers[i].ret); 2447 + pr_err("Failed to enable %s: %d\n", consumers[i].supply, ret); 2448 + while (--i >= 0) 2449 + regulator_disable(consumers[i].consumer); 2551 2450 2552 2451 return ret; 2553 2452 } ··· 2558 2463 * @return 0 on success, an errno on failure 2559 2464 * 2560 2465 * This convenience API allows consumers to disable multiple regulator 2561 - * clients in a single API call. If any consumers cannot be enabled 2562 - * then any others that were disabled will be disabled again prior to 2466 + * clients in a single API call. If any consumers cannot be disabled 2467 + * then any others that were disabled will be enabled again prior to 2563 2468 * return. 2564 2469 */ 2565 2470 int regulator_bulk_disable(int num_consumers, ··· 2568 2473 int i; 2569 2474 int ret; 2570 2475 2571 - for (i = 0; i < num_consumers; i++) { 2476 + for (i = num_consumers - 1; i >= 0; --i) { 2572 2477 ret = regulator_disable(consumers[i].consumer); 2573 2478 if (ret != 0) 2574 2479 goto err; ··· 2578 2483 2579 2484 err: 2580 2485 pr_err("Failed to disable %s: %d\n", consumers[i].supply, ret); 2581 - for (--i; i >= 0; --i) 2486 + for (++i; i < num_consumers; ++i) 2582 2487 regulator_enable(consumers[i].consumer); 2583 2488 2584 2489 return ret; ··· 2805 2710 2806 2711 static void rdev_init_debugfs(struct regulator_dev *rdev) 2807 2712 { 2808 - #ifdef CONFIG_DEBUG_FS 2809 2713 rdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root); 2810 - if (IS_ERR(rdev->debugfs) || !rdev->debugfs) { 2714 + if (!rdev->debugfs) { 2811 2715 rdev_warn(rdev, "Failed to create debugfs directory\n"); 2812 - rdev->debugfs = NULL; 2813 2716 return; 2814 2717 } 2815 2718 ··· 2815 2722 &rdev->use_count); 2816 2723 debugfs_create_u32("open_count", 0444, rdev->debugfs, 2817 2724 &rdev->open_count); 2818 - #endif 2819 2725 } 2820 2726 2821 2727 /** ··· 2947 2855 if (init_data) { 2948 2856 for (i = 0; i < init_data->num_consumer_supplies; i++) { 2949 2857 ret = set_consumer_device_supply(rdev, 2950 - init_data->consumer_supplies[i].dev, 2951 2858 init_data->consumer_supplies[i].dev_name, 2952 2859 init_data->consumer_supplies[i].supply); 2953 2860 if (ret < 0) { ··· 2993 2902 return; 2994 2903 2995 2904 mutex_lock(&regulator_list_mutex); 2996 - #ifdef CONFIG_DEBUG_FS 2997 2905 debugfs_remove_recursive(rdev->debugfs); 2998 - #endif 2999 2906 flush_work_sync(&rdev->disable_work.work); 3000 2907 WARN_ON(rdev->open_count); 3001 2908 unset_regulator_supplies(rdev); ··· 3203 3114 3204 3115 return ret; 3205 3116 } 3117 + #endif 3206 3118 3207 3119 static const struct file_operations supply_map_fops = { 3120 + #ifdef CONFIG_DEBUG_FS 3208 3121 .read = supply_map_read_file, 3209 3122 .llseek = default_llseek, 3210 - }; 3211 3123 #endif 3124 + }; 3212 3125 3213 3126 static int __init regulator_init(void) 3214 3127 { ··· 3218 3127 3219 3128 ret = class_register(&regulator_class); 3220 3129 3221 - #ifdef CONFIG_DEBUG_FS 3222 3130 debugfs_root = debugfs_create_dir("regulator", NULL); 3223 - if (IS_ERR(debugfs_root) || !debugfs_root) { 3131 + if (!debugfs_root) 3224 3132 pr_warn("regulator: Failed to create debugfs directory\n"); 3225 - debugfs_root = NULL; 3226 - } 3227 3133 3228 - if (IS_ERR(debugfs_create_file("supply_map", 0444, debugfs_root, 3229 - NULL, &supply_map_fops))) 3230 - pr_warn("regulator: Failed to create supplies debugfs\n"); 3231 - #endif 3134 + debugfs_create_file("supply_map", 0444, debugfs_root, NULL, 3135 + &supply_map_fops); 3232 3136 3233 3137 regulator_dummy_init(); 3234 3138
+6 -6
drivers/regulator/da903x.c
··· 119 119 return -EINVAL; 120 120 } 121 121 122 - val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 122 + val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); 123 123 *selector = val; 124 124 val <<= info->vol_shift; 125 125 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; ··· 202 202 return -EINVAL; 203 203 } 204 204 205 - val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 205 + val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); 206 206 *selector = val; 207 207 val <<= info->vol_shift; 208 208 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; ··· 233 233 234 234 thresh = (info->max_uV + info->min_uV) / 2; 235 235 if (min_uV < thresh) { 236 - val = (thresh - min_uV + info->step_uV - 1) / info->step_uV; 236 + val = DIV_ROUND_UP(thresh - min_uV, info->step_uV); 237 237 val |= 0x4; 238 238 } else { 239 - val = (min_uV - thresh + info->step_uV - 1) / info->step_uV; 239 + val = DIV_ROUND_UP(min_uV - thresh, info->step_uV); 240 240 } 241 241 242 242 *selector = val; ··· 281 281 return -EINVAL; 282 282 } 283 283 284 - val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 284 + val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); 285 285 *selector = val; 286 286 val <<= info->vol_shift; 287 287 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; ··· 307 307 return -EINVAL; 308 308 } 309 309 310 - val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 310 + val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); 311 311 val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val); 312 312 *selector = val; 313 313 val <<= info->vol_shift;
+32 -86
drivers/regulator/db8500-prcmu.c
··· 18 18 #include <linux/regulator/machine.h> 19 19 #include <linux/regulator/db8500-prcmu.h> 20 20 #include <linux/module.h> 21 - 22 - /* 23 - * power state reference count 24 - */ 25 - static int power_state_active_cnt; /* will initialize to zero */ 26 - static DEFINE_SPINLOCK(power_state_active_lock); 27 - 28 - static void power_state_active_enable(void) 29 - { 30 - unsigned long flags; 31 - 32 - spin_lock_irqsave(&power_state_active_lock, flags); 33 - power_state_active_cnt++; 34 - spin_unlock_irqrestore(&power_state_active_lock, flags); 35 - } 36 - 37 - static int power_state_active_disable(void) 38 - { 39 - int ret = 0; 40 - unsigned long flags; 41 - 42 - spin_lock_irqsave(&power_state_active_lock, flags); 43 - if (power_state_active_cnt <= 0) { 44 - pr_err("power state: unbalanced enable/disable calls\n"); 45 - ret = -EINVAL; 46 - goto out; 47 - } 48 - 49 - power_state_active_cnt--; 50 - out: 51 - spin_unlock_irqrestore(&power_state_active_lock, flags); 52 - return ret; 53 - } 54 - 55 - /* 56 - * Exported interface for CPUIdle only. This function is called when interrupts 57 - * are turned off. Hence, no locking. 58 - */ 59 - int power_state_active_is_enabled(void) 60 - { 61 - return (power_state_active_cnt > 0); 62 - } 63 - 64 - /** 65 - * struct db8500_regulator_info - db8500 regulator information 66 - * @dev: device pointer 67 - * @desc: regulator description 68 - * @rdev: regulator device pointer 69 - * @is_enabled: status of the regulator 70 - * @epod_id: id for EPOD (power domain) 71 - * @is_ramret: RAM retention switch for EPOD (power domain) 72 - * @operating_point: operating point (only for vape, to be removed) 73 - * 74 - */ 75 - struct db8500_regulator_info { 76 - struct device *dev; 77 - struct regulator_desc desc; 78 - struct regulator_dev *rdev; 79 - bool is_enabled; 80 - u16 epod_id; 81 - bool is_ramret; 82 - bool exclude_from_power_state; 83 - unsigned int operating_point; 84 - }; 21 + #include "dbx500-prcmu.h" 85 22 86 23 static int db8500_regulator_enable(struct regulator_dev *rdev) 87 24 { 88 - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); 25 + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); 89 26 90 27 if (info == NULL) 91 28 return -EINVAL; ··· 30 93 dev_vdbg(rdev_get_dev(rdev), "regulator-%s-enable\n", 31 94 info->desc.name); 32 95 33 - info->is_enabled = true; 34 - if (!info->exclude_from_power_state) 35 - power_state_active_enable(); 96 + if (!info->is_enabled) { 97 + info->is_enabled = true; 98 + if (!info->exclude_from_power_state) 99 + power_state_active_enable(); 100 + } 36 101 37 102 return 0; 38 103 } 39 104 40 105 static int db8500_regulator_disable(struct regulator_dev *rdev) 41 106 { 42 - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); 107 + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); 43 108 int ret = 0; 44 109 45 110 if (info == NULL) ··· 50 111 dev_vdbg(rdev_get_dev(rdev), "regulator-%s-disable\n", 51 112 info->desc.name); 52 113 53 - info->is_enabled = false; 54 - if (!info->exclude_from_power_state) 55 - ret = power_state_active_disable(); 114 + if (info->is_enabled) { 115 + info->is_enabled = false; 116 + if (!info->exclude_from_power_state) 117 + ret = power_state_active_disable(); 118 + } 56 119 57 120 return ret; 58 121 } 59 122 60 123 static int db8500_regulator_is_enabled(struct regulator_dev *rdev) 61 124 { 62 - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); 125 + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); 63 126 64 127 if (info == NULL) 65 128 return -EINVAL; ··· 138 197 */ 139 198 static int db8500_regulator_switch_enable(struct regulator_dev *rdev) 140 199 { 141 - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); 200 + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); 142 201 int ret; 143 202 144 203 if (info == NULL) ··· 162 221 163 222 static int db8500_regulator_switch_disable(struct regulator_dev *rdev) 164 223 { 165 - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); 224 + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); 166 225 int ret; 167 226 168 227 if (info == NULL) ··· 186 245 187 246 static int db8500_regulator_switch_is_enabled(struct regulator_dev *rdev) 188 247 { 189 - struct db8500_regulator_info *info = rdev_get_drvdata(rdev); 248 + struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); 190 249 191 250 if (info == NULL) 192 251 return -EINVAL; ··· 207 266 /* 208 267 * Regulator information 209 268 */ 210 - static struct db8500_regulator_info 211 - db8500_regulator_info[DB8500_NUM_REGULATORS] = { 269 + static struct dbx500_regulator_info 270 + dbx500_regulator_info[DB8500_NUM_REGULATORS] = { 212 271 [DB8500_REGULATOR_VAPE] = { 213 272 .desc = { 214 273 .name = "db8500-vape", ··· 417 476 int i, err; 418 477 419 478 /* register all regulators */ 420 - for (i = 0; i < ARRAY_SIZE(db8500_regulator_info); i++) { 421 - struct db8500_regulator_info *info; 479 + for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { 480 + struct dbx500_regulator_info *info; 422 481 struct regulator_init_data *init_data = &db8500_init_data[i]; 423 482 424 483 /* assign per-regulator data */ 425 - info = &db8500_regulator_info[i]; 484 + info = &dbx500_regulator_info[i]; 426 485 info->dev = &pdev->dev; 427 486 428 487 /* register with the regulator framework */ ··· 435 494 436 495 /* if failing, unregister all earlier regulators */ 437 496 while (--i >= 0) { 438 - info = &db8500_regulator_info[i]; 497 + info = &dbx500_regulator_info[i]; 439 498 regulator_unregister(info->rdev); 440 499 } 441 500 return err; ··· 444 503 dev_dbg(rdev_get_dev(info->rdev), 445 504 "regulator-%s-probed\n", info->desc.name); 446 505 } 506 + err = ux500_regulator_debug_init(pdev, 507 + dbx500_regulator_info, 508 + ARRAY_SIZE(dbx500_regulator_info)); 447 509 448 - return 0; 510 + return err; 449 511 } 450 512 451 513 static int __exit db8500_regulator_remove(struct platform_device *pdev) 452 514 { 453 515 int i; 454 516 455 - for (i = 0; i < ARRAY_SIZE(db8500_regulator_info); i++) { 456 - struct db8500_regulator_info *info; 457 - info = &db8500_regulator_info[i]; 517 + ux500_regulator_debug_exit(); 518 + 519 + for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { 520 + struct dbx500_regulator_info *info; 521 + info = &dbx500_regulator_info[i]; 458 522 459 523 dev_vdbg(rdev_get_dev(info->rdev), 460 524 "regulator-%s-remove\n", info->desc.name);
+241
drivers/regulator/dbx500-prcmu.c
··· 1 + /* 2 + * Copyright (C) ST-Ericsson SA 2010 3 + * 4 + * License Terms: GNU General Public License v2 5 + * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson 6 + * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson 7 + * 8 + * UX500 common part of Power domain regulators 9 + */ 10 + 11 + #include <linux/kernel.h> 12 + #include <linux/err.h> 13 + #include <linux/regulator/driver.h> 14 + #include <linux/debugfs.h> 15 + #include <linux/seq_file.h> 16 + #include <linux/slab.h> 17 + 18 + #include "dbx500-prcmu.h" 19 + 20 + /* 21 + * power state reference count 22 + */ 23 + static int power_state_active_cnt; /* will initialize to zero */ 24 + static DEFINE_SPINLOCK(power_state_active_lock); 25 + 26 + int power_state_active_get(void) 27 + { 28 + unsigned long flags; 29 + int cnt; 30 + 31 + spin_lock_irqsave(&power_state_active_lock, flags); 32 + cnt = power_state_active_cnt; 33 + spin_unlock_irqrestore(&power_state_active_lock, flags); 34 + 35 + return cnt; 36 + } 37 + 38 + void power_state_active_enable(void) 39 + { 40 + unsigned long flags; 41 + 42 + spin_lock_irqsave(&power_state_active_lock, flags); 43 + power_state_active_cnt++; 44 + spin_unlock_irqrestore(&power_state_active_lock, flags); 45 + } 46 + 47 + int power_state_active_disable(void) 48 + { 49 + int ret = 0; 50 + unsigned long flags; 51 + 52 + spin_lock_irqsave(&power_state_active_lock, flags); 53 + if (power_state_active_cnt <= 0) { 54 + pr_err("power state: unbalanced enable/disable calls\n"); 55 + ret = -EINVAL; 56 + goto out; 57 + } 58 + 59 + power_state_active_cnt--; 60 + out: 61 + spin_unlock_irqrestore(&power_state_active_lock, flags); 62 + return ret; 63 + } 64 + 65 + #ifdef CONFIG_REGULATOR_DEBUG 66 + 67 + static struct ux500_regulator_debug { 68 + struct dentry *dir; 69 + struct dentry *status_file; 70 + struct dentry *power_state_cnt_file; 71 + struct dbx500_regulator_info *regulator_array; 72 + int num_regulators; 73 + u8 *state_before_suspend; 74 + u8 *state_after_suspend; 75 + } rdebug; 76 + 77 + void ux500_regulator_suspend_debug(void) 78 + { 79 + int i; 80 + for (i = 0; i < rdebug.num_regulators; i++) 81 + rdebug.state_before_suspend[i] = 82 + rdebug.regulator_array[i].is_enabled; 83 + } 84 + 85 + void ux500_regulator_resume_debug(void) 86 + { 87 + int i; 88 + for (i = 0; i < rdebug.num_regulators; i++) 89 + rdebug.state_after_suspend[i] = 90 + rdebug.regulator_array[i].is_enabled; 91 + } 92 + 93 + static int ux500_regulator_power_state_cnt_print(struct seq_file *s, void *p) 94 + { 95 + struct device *dev = s->private; 96 + int err; 97 + 98 + /* print power state count */ 99 + err = seq_printf(s, "ux500-regulator power state count: %i\n", 100 + power_state_active_get()); 101 + if (err < 0) 102 + dev_err(dev, "seq_printf overflow\n"); 103 + 104 + return 0; 105 + } 106 + 107 + static int ux500_regulator_power_state_cnt_open(struct inode *inode, 108 + struct file *file) 109 + { 110 + return single_open(file, ux500_regulator_power_state_cnt_print, 111 + inode->i_private); 112 + } 113 + 114 + static const struct file_operations ux500_regulator_power_state_cnt_fops = { 115 + .open = ux500_regulator_power_state_cnt_open, 116 + .read = seq_read, 117 + .llseek = seq_lseek, 118 + .release = single_release, 119 + .owner = THIS_MODULE, 120 + }; 121 + 122 + static int ux500_regulator_status_print(struct seq_file *s, void *p) 123 + { 124 + struct device *dev = s->private; 125 + int err; 126 + int i; 127 + 128 + /* print dump header */ 129 + err = seq_printf(s, "ux500-regulator status:\n"); 130 + if (err < 0) 131 + dev_err(dev, "seq_printf overflow\n"); 132 + 133 + err = seq_printf(s, "%31s : %8s : %8s\n", "current", 134 + "before", "after"); 135 + if (err < 0) 136 + dev_err(dev, "seq_printf overflow\n"); 137 + 138 + for (i = 0; i < rdebug.num_regulators; i++) { 139 + struct dbx500_regulator_info *info; 140 + /* Access per-regulator data */ 141 + info = &rdebug.regulator_array[i]; 142 + 143 + /* print status */ 144 + err = seq_printf(s, "%20s : %8s : %8s : %8s\n", info->desc.name, 145 + info->is_enabled ? "enabled" : "disabled", 146 + rdebug.state_before_suspend[i] ? "enabled" : "disabled", 147 + rdebug.state_after_suspend[i] ? "enabled" : "disabled"); 148 + if (err < 0) 149 + dev_err(dev, "seq_printf overflow\n"); 150 + } 151 + 152 + return 0; 153 + } 154 + 155 + static int ux500_regulator_status_open(struct inode *inode, struct file *file) 156 + { 157 + return single_open(file, ux500_regulator_status_print, 158 + inode->i_private); 159 + } 160 + 161 + static const struct file_operations ux500_regulator_status_fops = { 162 + .open = ux500_regulator_status_open, 163 + .read = seq_read, 164 + .llseek = seq_lseek, 165 + .release = single_release, 166 + .owner = THIS_MODULE, 167 + }; 168 + 169 + int __attribute__((weak)) dbx500_regulator_testcase( 170 + struct dbx500_regulator_info *regulator_info, 171 + int num_regulators) 172 + { 173 + return 0; 174 + } 175 + 176 + int __devinit 177 + ux500_regulator_debug_init(struct platform_device *pdev, 178 + struct dbx500_regulator_info *regulator_info, 179 + int num_regulators) 180 + { 181 + /* create directory */ 182 + rdebug.dir = debugfs_create_dir("ux500-regulator", NULL); 183 + if (!rdebug.dir) 184 + goto exit_no_debugfs; 185 + 186 + /* create "status" file */ 187 + rdebug.status_file = debugfs_create_file("status", 188 + S_IRUGO, rdebug.dir, &pdev->dev, 189 + &ux500_regulator_status_fops); 190 + if (!rdebug.status_file) 191 + goto exit_destroy_dir; 192 + 193 + /* create "power-state-count" file */ 194 + rdebug.power_state_cnt_file = debugfs_create_file("power-state-count", 195 + S_IRUGO, rdebug.dir, &pdev->dev, 196 + &ux500_regulator_power_state_cnt_fops); 197 + if (!rdebug.power_state_cnt_file) 198 + goto exit_destroy_status; 199 + 200 + rdebug.regulator_array = regulator_info; 201 + rdebug.num_regulators = num_regulators; 202 + 203 + rdebug.state_before_suspend = kzalloc(num_regulators, GFP_KERNEL); 204 + if (!rdebug.state_before_suspend) { 205 + dev_err(&pdev->dev, 206 + "could not allocate memory for saving state\n"); 207 + goto exit_destroy_power_state; 208 + } 209 + 210 + rdebug.state_after_suspend = kzalloc(num_regulators, GFP_KERNEL); 211 + if (!rdebug.state_after_suspend) { 212 + dev_err(&pdev->dev, 213 + "could not allocate memory for saving state\n"); 214 + goto exit_free; 215 + } 216 + 217 + dbx500_regulator_testcase(regulator_info, num_regulators); 218 + return 0; 219 + 220 + exit_free: 221 + kfree(rdebug.state_before_suspend); 222 + exit_destroy_power_state: 223 + debugfs_remove(rdebug.power_state_cnt_file); 224 + exit_destroy_status: 225 + debugfs_remove(rdebug.status_file); 226 + exit_destroy_dir: 227 + debugfs_remove(rdebug.dir); 228 + exit_no_debugfs: 229 + dev_err(&pdev->dev, "failed to create debugfs entries.\n"); 230 + return -ENOMEM; 231 + } 232 + 233 + int __devexit ux500_regulator_debug_exit(void) 234 + { 235 + debugfs_remove_recursive(rdebug.dir); 236 + kfree(rdebug.state_after_suspend); 237 + kfree(rdebug.state_before_suspend); 238 + 239 + return 0; 240 + } 241 + #endif
+63
drivers/regulator/dbx500-prcmu.h
··· 1 + /* 2 + * Copyright (C) ST-Ericsson SA 2010 3 + * 4 + * Author: Bengt Jonsson <bengt.jonsson@stericsson.com> for ST-Ericsson, 5 + * Jonas Aaberg <jonas.aberg@stericsson.com> for ST-Ericsson 6 + * 7 + * License Terms: GNU General Public License v2 8 + * 9 + */ 10 + 11 + #ifndef DBX500_REGULATOR_H 12 + #define DBX500_REGULATOR_H 13 + 14 + #include <linux/platform_device.h> 15 + 16 + /** 17 + * struct dbx500_regulator_info - dbx500 regulator information 18 + * @dev: device pointer 19 + * @desc: regulator description 20 + * @rdev: regulator device pointer 21 + * @is_enabled: status of the regulator 22 + * @epod_id: id for EPOD (power domain) 23 + * @is_ramret: RAM retention switch for EPOD (power domain) 24 + * @operating_point: operating point (only for vape, to be removed) 25 + * 26 + */ 27 + struct dbx500_regulator_info { 28 + struct device *dev; 29 + struct regulator_desc desc; 30 + struct regulator_dev *rdev; 31 + bool is_enabled; 32 + u16 epod_id; 33 + bool is_ramret; 34 + bool exclude_from_power_state; 35 + unsigned int operating_point; 36 + }; 37 + 38 + void power_state_active_enable(void); 39 + int power_state_active_disable(void); 40 + 41 + 42 + #ifdef CONFIG_REGULATOR_DEBUG 43 + int ux500_regulator_debug_init(struct platform_device *pdev, 44 + struct dbx500_regulator_info *regulator_info, 45 + int num_regulators); 46 + 47 + int ux500_regulator_debug_exit(void); 48 + #else 49 + 50 + static inline int ux500_regulator_debug_init(struct platform_device *pdev, 51 + struct dbx500_regulator_info *regulator_info, 52 + int num_regulators) 53 + { 54 + return 0; 55 + } 56 + 57 + static inline int ux500_regulator_debug_exit(void) 58 + { 59 + return 0; 60 + } 61 + 62 + #endif 63 + #endif
+53
drivers/regulator/fixed-helper.c
··· 1 + #include <linux/slab.h> 2 + #include <linux/platform_device.h> 3 + #include <linux/regulator/machine.h> 4 + #include <linux/regulator/fixed.h> 5 + 6 + struct fixed_regulator_data { 7 + struct fixed_voltage_config cfg; 8 + struct regulator_init_data init_data; 9 + struct platform_device pdev; 10 + }; 11 + 12 + static void regulator_fixed_release(struct device *dev) 13 + { 14 + struct fixed_regulator_data *data = container_of(dev, 15 + struct fixed_regulator_data, pdev.dev); 16 + kfree(data); 17 + } 18 + 19 + /** 20 + * regulator_register_fixed - register a no-op fixed regulator 21 + * @name: supply name 22 + * @id: platform device id 23 + * @supplies: consumers for this regulator 24 + * @num_supplies: number of consumers 25 + */ 26 + struct platform_device *regulator_register_fixed(int id, 27 + struct regulator_consumer_supply *supplies, int num_supplies) 28 + { 29 + struct fixed_regulator_data *data; 30 + 31 + data = kzalloc(sizeof(*data), GFP_KERNEL); 32 + if (!data) 33 + return NULL; 34 + 35 + data->cfg.supply_name = "dummy"; 36 + data->cfg.microvolts = 0; 37 + data->cfg.gpio = -EINVAL; 38 + data->cfg.enabled_at_boot = 1; 39 + data->cfg.init_data = &data->init_data; 40 + 41 + data->init_data.constraints.always_on = 1; 42 + data->init_data.consumer_supplies = supplies; 43 + data->init_data.num_consumer_supplies = num_supplies; 44 + 45 + data->pdev.name = "reg-fixed-voltage"; 46 + data->pdev.id = id; 47 + data->pdev.dev.platform_data = &data->cfg; 48 + data->pdev.dev.release = regulator_fixed_release; 49 + 50 + platform_device_register(&data->pdev); 51 + 52 + return &data->pdev; 53 + }
+3 -1
drivers/regulator/fixed.c
··· 192 192 drvdata->desc.type = REGULATOR_VOLTAGE; 193 193 drvdata->desc.owner = THIS_MODULE; 194 194 drvdata->desc.ops = &fixed_voltage_ops; 195 - drvdata->desc.n_voltages = 1; 195 + 196 + if (config->microvolts) 197 + drvdata->desc.n_voltages = 1; 196 198 197 199 drvdata->microvolts = config->microvolts; 198 200 drvdata->gpio = config->gpio;
+3 -11
drivers/regulator/isl6271a-regulator.c
··· 63 63 unsigned *selector) 64 64 { 65 65 struct isl_pmic *pmic = rdev_get_drvdata(dev); 66 - int vsel, err, data; 66 + int err, data; 67 67 68 68 if (minuV < ISL6271A_VOLTAGE_MIN || minuV > ISL6271A_VOLTAGE_MAX) 69 69 return -EINVAL; 70 70 if (maxuV < ISL6271A_VOLTAGE_MIN || maxuV > ISL6271A_VOLTAGE_MAX) 71 71 return -EINVAL; 72 72 73 - /* Align to 50000 mV */ 74 - vsel = minuV - (minuV % ISL6271A_VOLTAGE_STEP); 75 - 76 - /* If the result fell out of [minuV,maxuV] range, put it back */ 77 - if (vsel < minuV) 78 - vsel += ISL6271A_VOLTAGE_STEP; 79 - 80 - /* Convert the microvolts to data for the chip */ 81 - data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP; 82 - 73 + data = DIV_ROUND_UP(minuV - ISL6271A_VOLTAGE_MIN, 74 + ISL6271A_VOLTAGE_STEP); 83 75 *selector = data; 84 76 85 77 mutex_lock(&pmic->mtx);
+2 -2
drivers/regulator/max1586.c
··· 76 76 if (min_uV < max1586->min_uV) 77 77 min_uV = max1586->min_uV; 78 78 79 - *selector = ((min_uV - max1586->min_uV) * MAX1586_V3_MAX_VSEL + 80 - range_uV - 1) / range_uV; 79 + *selector = DIV_ROUND_UP((min_uV - max1586->min_uV) * 80 + MAX1586_V3_MAX_VSEL, range_uV); 81 81 if (max1586_v3_calc_voltage(max1586, *selector) > max_uV) 82 82 return -EINVAL; 83 83
+2 -3
drivers/regulator/max8649.c
··· 101 101 min_uV, max_uV); 102 102 return -EINVAL; 103 103 } 104 - data = (min_uV - MAX8649_DCDC_VMIN + MAX8649_DCDC_STEP - 1) 105 - / MAX8649_DCDC_STEP; 104 + data = DIV_ROUND_UP(min_uV - MAX8649_DCDC_VMIN, MAX8649_DCDC_STEP); 106 105 mask = MAX8649_VOL_MASK; 107 106 *selector = data & mask; 108 107 ··· 269 270 ret); 270 271 goto out; 271 272 } 272 - dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", ret); 273 + dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", val); 273 274 274 275 /* enable VID0 & VID1 */ 275 276 regmap_update_bits(info->regmap, MAX8649_CONTROL, MAX8649_VID_MASK, 0);
+9 -7
drivers/regulator/max8660.c
··· 153 153 if (max_uV < MAX8660_DCDC_MIN_UV || max_uV > MAX8660_DCDC_MAX_UV) 154 154 return -EINVAL; 155 155 156 - selector = (min_uV - (MAX8660_DCDC_MIN_UV - MAX8660_DCDC_STEP + 1)) 157 - / MAX8660_DCDC_STEP; 158 - *s = selector; 156 + selector = DIV_ROUND_UP(min_uV - MAX8660_DCDC_MIN_UV, 157 + MAX8660_DCDC_STEP); 159 158 160 159 ret = max8660_dcdc_list(rdev, selector); 161 160 if (ret < 0 || ret > max_uV) 162 161 return -EINVAL; 162 + 163 + *s = selector; 163 164 164 165 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2; 165 166 ret = max8660_write(max8660, reg, 0, selector); ··· 211 210 if (max_uV < MAX8660_LDO5_MIN_UV || max_uV > MAX8660_LDO5_MAX_UV) 212 211 return -EINVAL; 213 212 214 - selector = (min_uV - (MAX8660_LDO5_MIN_UV - MAX8660_LDO5_STEP + 1)) 215 - / MAX8660_LDO5_STEP; 213 + selector = DIV_ROUND_UP(min_uV - MAX8660_LDO5_MIN_UV, 214 + MAX8660_LDO5_STEP); 215 + 216 216 ret = max8660_ldo5_list(rdev, selector); 217 217 if (ret < 0 || ret > max_uV) 218 218 return -EINVAL; ··· 289 287 if (max_uV < MAX8660_LDO67_MIN_UV || max_uV > MAX8660_LDO67_MAX_UV) 290 288 return -EINVAL; 291 289 292 - selector = (min_uV - (MAX8660_LDO67_MIN_UV - MAX8660_LDO67_STEP + 1)) 293 - / MAX8660_LDO67_STEP; 290 + selector = DIV_ROUND_UP(min_uV - MAX8660_LDO67_MIN_UV, 291 + MAX8660_LDO67_STEP); 294 292 295 293 ret = max8660_ldo67_list(rdev, selector); 296 294 if (ret < 0 || ret > max_uV)
+2 -2
drivers/regulator/max8925-regulator.c
··· 73 73 min_uV, max_uV); 74 74 return -EINVAL; 75 75 } 76 - data = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 76 + data = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); 77 77 *selector = data; 78 78 data <<= info->vol_shift; 79 79 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; ··· 140 140 if (uV < SD1_DVM_VMIN || uV > SD1_DVM_VMAX) 141 141 return -EINVAL; 142 142 143 - data = (uV - SD1_DVM_VMIN + SD1_DVM_STEP - 1) / SD1_DVM_STEP; 143 + data = DIV_ROUND_UP(uV - SD1_DVM_VMIN, SD1_DVM_STEP); 144 144 data <<= SD1_DVM_SHIFT; 145 145 mask = 3 << SD1_DVM_SHIFT; 146 146
+16 -21
drivers/regulator/max8997.c
··· 130 130 [MAX8997_CHARGER_TOPOFF] = &topoff_current_map_desc, 131 131 }; 132 132 133 - static inline int max8997_get_rid(struct regulator_dev *rdev) 134 - { 135 - return rdev_get_id(rdev); 136 - } 137 - 138 133 static int max8997_list_voltage_safeout(struct regulator_dev *rdev, 139 134 unsigned int selector) 140 135 { 141 - int rid = max8997_get_rid(rdev); 136 + int rid = rdev_get_id(rdev); 142 137 143 138 if (rid == MAX8997_ESAFEOUT1 || rid == MAX8997_ESAFEOUT2) { 144 139 switch (selector) { ··· 156 161 static int max8997_list_voltage_charger_cv(struct regulator_dev *rdev, 157 162 unsigned int selector) 158 163 { 159 - int rid = max8997_get_rid(rdev); 164 + int rid = rdev_get_id(rdev); 160 165 161 166 if (rid != MAX8997_CHARGER_CV) 162 167 goto err; ··· 179 184 unsigned int selector) 180 185 { 181 186 const struct voltage_map_desc *desc; 182 - int rid = max8997_get_rid(rdev); 187 + int rid = rdev_get_id(rdev); 183 188 int val; 184 189 185 190 if (rid >= ARRAY_SIZE(reg_voltage_map) || ··· 200 205 static int max8997_get_enable_register(struct regulator_dev *rdev, 201 206 int *reg, int *mask, int *pattern) 202 207 { 203 - int rid = max8997_get_rid(rdev); 208 + int rid = rdev_get_id(rdev); 204 209 205 210 switch (rid) { 206 211 case MAX8997_LDO1 ... MAX8997_LDO21: ··· 320 325 static int max8997_get_voltage_register(struct regulator_dev *rdev, 321 326 int *_reg, int *_shift, int *_mask) 322 327 { 323 - int rid = max8997_get_rid(rdev); 328 + int rid = rdev_get_id(rdev); 324 329 int reg, shift = 0, mask = 0x3f; 325 330 326 331 switch (rid) { ··· 381 386 struct max8997_data *max8997 = rdev_get_drvdata(rdev); 382 387 struct i2c_client *i2c = max8997->iodev->i2c; 383 388 int reg, shift, mask, ret; 384 - int rid = max8997_get_rid(rdev); 389 + int rid = rdev_get_id(rdev); 385 390 u8 val; 386 391 387 392 ret = max8997_get_voltage_register(rdev, &reg, &shift, &mask); ··· 441 446 { 442 447 struct max8997_data *max8997 = rdev_get_drvdata(rdev); 443 448 struct i2c_client *i2c = max8997->iodev->i2c; 444 - int rid = max8997_get_rid(rdev); 449 + int rid = rdev_get_id(rdev); 445 450 int lb, ub; 446 451 int reg, shift = 0, mask, ret = 0; 447 452 u8 val = 0x0; ··· 498 503 struct i2c_client *i2c = max8997->iodev->i2c; 499 504 int min_vol = min_uV / 1000, max_vol = max_uV / 1000; 500 505 const struct voltage_map_desc *desc; 501 - int rid = max8997_get_rid(rdev); 506 + int rid = rdev_get_id(rdev); 502 507 int reg, shift = 0, mask, ret; 503 508 int i; 504 509 u8 org; ··· 559 564 u8 new_val, int *best) 560 565 { 561 566 struct max8997_data *max8997 = rdev_get_drvdata(rdev); 562 - int rid = max8997_get_rid(rdev); 567 + int rid = rdev_get_id(rdev); 563 568 u8 *buckx_val[3]; 564 569 bool buckx_gpiodvs[3]; 565 570 int side_effect[8]; ··· 636 641 int min_uV, int max_uV, unsigned *selector) 637 642 { 638 643 struct max8997_data *max8997 = rdev_get_drvdata(rdev); 639 - int rid = max8997_get_rid(rdev); 644 + int rid = rdev_get_id(rdev); 640 645 const struct voltage_map_desc *desc; 641 646 int new_val, new_idx, damage, tmp_val, tmp_idx, tmp_dmg; 642 647 bool gpio_dvs_mode = false; ··· 719 724 { 720 725 struct max8997_data *max8997 = rdev_get_drvdata(rdev); 721 726 struct i2c_client *i2c = max8997->iodev->i2c; 722 - int rid = max8997_get_rid(rdev); 727 + int rid = rdev_get_id(rdev); 723 728 int reg, shift = 0, mask, ret; 724 729 int i = 0; 725 730 u8 val; ··· 761 766 struct max8997_data *max8997 = rdev_get_drvdata(rdev); 762 767 struct i2c_client *i2c = max8997->iodev->i2c; 763 768 int ret, reg, mask, pattern; 764 - int rid = max8997_get_rid(rdev); 769 + int rid = rdev_get_id(rdev); 765 770 766 771 ret = max8997_get_enable_register(rdev, &reg, &mask, &pattern); 767 772 if (ret) ··· 903 908 }, 904 909 regulator_desc_buck(7), 905 910 { 906 - .name = "EN32KHz AP", 911 + .name = "EN32KHz_AP", 907 912 .id = MAX8997_EN32KHZ_AP, 908 913 .ops = &max8997_fixedvolt_ops, 909 914 .type = REGULATOR_VOLTAGE, 910 915 .owner = THIS_MODULE, 911 916 }, { 912 - .name = "EN32KHz CP", 917 + .name = "EN32KHz_CP", 913 918 .id = MAX8997_EN32KHZ_CP, 914 919 .ops = &max8997_fixedvolt_ops, 915 920 .type = REGULATOR_VOLTAGE, ··· 933 938 .type = REGULATOR_VOLTAGE, 934 939 .owner = THIS_MODULE, 935 940 }, { 936 - .name = "CHARGER CV", 941 + .name = "CHARGER_CV", 937 942 .id = MAX8997_CHARGER_CV, 938 943 .ops = &max8997_fixedstate_ops, 939 944 .type = REGULATOR_VOLTAGE, ··· 945 950 .type = REGULATOR_CURRENT, 946 951 .owner = THIS_MODULE, 947 952 }, { 948 - .name = "CHARGER TOPOFF", 953 + .name = "CHARGER_TOPOFF", 949 954 .id = MAX8997_CHARGER_TOPOFF, 950 955 .ops = &max8997_charger_fixedstate_ops, 951 956 .type = REGULATOR_CURRENT,
+5 -11
drivers/regulator/max8998.c
··· 112 112 &buck4_voltage_map_desc, /* BUCK4 */ 113 113 }; 114 114 115 - static inline int max8998_get_ldo(struct regulator_dev *rdev) 116 - { 117 - return rdev_get_id(rdev); 118 - } 119 - 120 115 static int max8998_list_voltage(struct regulator_dev *rdev, 121 116 unsigned int selector) 122 117 { 123 118 const struct voltage_map_desc *desc; 124 - int ldo = max8998_get_ldo(rdev); 119 + int ldo = rdev_get_id(rdev); 125 120 int val; 126 121 127 122 if (ldo >= ARRAY_SIZE(ldo_voltage_map)) ··· 136 141 static int max8998_get_enable_register(struct regulator_dev *rdev, 137 142 int *reg, int *shift) 138 143 { 139 - int ldo = max8998_get_ldo(rdev); 144 + int ldo = rdev_get_id(rdev); 140 145 141 146 switch (ldo) { 142 147 case MAX8998_LDO2 ... MAX8998_LDO5: ··· 217 222 static int max8998_get_voltage_register(struct regulator_dev *rdev, 218 223 int *_reg, int *_shift, int *_mask) 219 224 { 220 - int ldo = max8998_get_ldo(rdev); 225 + int ldo = rdev_get_id(rdev); 221 226 struct max8998_data *max8998 = rdev_get_drvdata(rdev); 222 227 int reg, shift = 0, mask = 0xff; 223 228 ··· 305 310 struct i2c_client *i2c = max8998->iodev->i2c; 306 311 int min_vol = min_uV / 1000, max_vol = max_uV / 1000; 307 312 const struct voltage_map_desc *desc; 308 - int ldo = max8998_get_ldo(rdev); 313 + int ldo = rdev_get_id(rdev); 309 314 int reg, shift = 0, mask, ret; 310 315 int i = 0; 311 316 ··· 357 362 struct i2c_client *i2c = max8998->iodev->i2c; 358 363 int min_vol = min_uV / 1000, max_vol = max_uV / 1000; 359 364 const struct voltage_map_desc *desc; 360 - int buck = max8998_get_ldo(rdev); 365 + int buck = rdev_get_id(rdev); 361 366 int reg, shift = 0, mask, ret; 362 367 int difference = 0, i = 0, j = 0, previous_vol = 0; 363 368 u8 val = 0; ··· 824 829 buck12_voltage_map_desc.step*i 825 830 < (pdata->buck2_voltage2 / 1000)) 826 831 i++; 827 - printk(KERN_ERR "i2:%d, buck2_idx:%d\n", i, max8998->buck2_idx); 828 832 max8998->buck2_vol[1] = i; 829 833 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE2, i); 830 834 if (ret)
+3
drivers/regulator/mc13783-regulator.c
··· 344 344 345 345 dev_dbg(&pdev->dev, "%s id %d\n", __func__, pdev->id); 346 346 347 + if (!pdata) 348 + return -EINVAL; 349 + 347 350 priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + 348 351 pdata->num_regulators * sizeof(priv->regulators[0]), 349 352 GFP_KERNEL);
+13 -14
drivers/regulator/pcf50633-regulator.c
··· 142 142 case PCF50633_REGULATOR_LDO5: 143 143 case PCF50633_REGULATOR_LDO6: 144 144 case PCF50633_REGULATOR_HCLDO: 145 + case PCF50633_REGULATOR_MEMLDO: 145 146 volt_bits = ldo_voltage_bits(millivolts); 146 147 break; 147 148 default: ··· 176 175 case PCF50633_REGULATOR_LDO5: 177 176 case PCF50633_REGULATOR_LDO6: 178 177 case PCF50633_REGULATOR_HCLDO: 178 + case PCF50633_REGULATOR_MEMLDO: 179 179 millivolts = ldo_voltage_value(bits); 180 180 break; 181 181 default: ··· 218 216 switch (regulator_id) { 219 217 case PCF50633_REGULATOR_AUTO: 220 218 index += 0x2f; 221 - break; 222 - case PCF50633_REGULATOR_HCLDO: 223 - index += 0x01; 224 219 break; 225 220 default: 226 221 break; ··· 287 288 288 289 static struct regulator_desc regulators[] = { 289 290 [PCF50633_REGULATOR_AUTO] = 290 - PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO, 80), 291 + PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO, 81), 291 292 [PCF50633_REGULATOR_DOWN1] = 292 - PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1, 95), 293 + PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1, 96), 293 294 [PCF50633_REGULATOR_DOWN2] = 294 - PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2, 95), 295 + PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2, 96), 295 296 [PCF50633_REGULATOR_LDO1] = 296 - PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1, 27), 297 + PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1, 28), 297 298 [PCF50633_REGULATOR_LDO2] = 298 - PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2, 27), 299 + PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2, 28), 299 300 [PCF50633_REGULATOR_LDO3] = 300 - PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3, 27), 301 + PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3, 28), 301 302 [PCF50633_REGULATOR_LDO4] = 302 - PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4, 27), 303 + PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4, 28), 303 304 [PCF50633_REGULATOR_LDO5] = 304 - PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5, 27), 305 + PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5, 28), 305 306 [PCF50633_REGULATOR_LDO6] = 306 - PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6, 27), 307 + PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6, 28), 307 308 [PCF50633_REGULATOR_HCLDO] = 308 - PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO, 26), 309 + PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO, 28), 309 310 [PCF50633_REGULATOR_MEMLDO] = 310 - PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO, 0), 311 + PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO, 28), 311 312 }; 312 313 313 314 static int __devinit pcf50633_regulator_probe(struct platform_device *pdev)
+790
drivers/regulator/s5m8767.c
··· 1 + /* 2 + * s5m8767.c 3 + * 4 + * Copyright (c) 2011 Samsung Electronics Co., Ltd 5 + * http://www.samsung.com 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License as published by the 9 + * Free Software Foundation; either version 2 of the License, or (at your 10 + * option) any later version. 11 + * 12 + */ 13 + 14 + #include <linux/bug.h> 15 + #include <linux/delay.h> 16 + #include <linux/err.h> 17 + #include <linux/gpio.h> 18 + #include <linux/slab.h> 19 + #include <linux/module.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/regulator/driver.h> 22 + #include <linux/regulator/machine.h> 23 + #include <linux/mfd/s5m87xx/s5m-core.h> 24 + #include <linux/mfd/s5m87xx/s5m-pmic.h> 25 + 26 + struct s5m8767_info { 27 + struct device *dev; 28 + struct s5m87xx_dev *iodev; 29 + int num_regulators; 30 + struct regulator_dev **rdev; 31 + 32 + int ramp_delay; 33 + bool buck2_ramp; 34 + bool buck3_ramp; 35 + bool buck4_ramp; 36 + 37 + bool buck2_gpiodvs; 38 + bool buck3_gpiodvs; 39 + bool buck4_gpiodvs; 40 + u8 buck2_vol[8]; 41 + u8 buck3_vol[8]; 42 + u8 buck4_vol[8]; 43 + int buck_gpios[3]; 44 + int buck_gpioindex; 45 + }; 46 + 47 + struct s5m_voltage_desc { 48 + int max; 49 + int min; 50 + int step; 51 + }; 52 + 53 + static const struct s5m_voltage_desc buck_voltage_val1 = { 54 + .max = 2225000, 55 + .min = 650000, 56 + .step = 6250, 57 + }; 58 + 59 + static const struct s5m_voltage_desc buck_voltage_val2 = { 60 + .max = 1600000, 61 + .min = 600000, 62 + .step = 6250, 63 + }; 64 + 65 + static const struct s5m_voltage_desc buck_voltage_val3 = { 66 + .max = 3000000, 67 + .min = 750000, 68 + .step = 12500, 69 + }; 70 + 71 + static const struct s5m_voltage_desc ldo_voltage_val1 = { 72 + .max = 3950000, 73 + .min = 800000, 74 + .step = 50000, 75 + }; 76 + 77 + static const struct s5m_voltage_desc ldo_voltage_val2 = { 78 + .max = 2375000, 79 + .min = 800000, 80 + .step = 25000, 81 + }; 82 + 83 + static const struct s5m_voltage_desc *reg_voltage_map[] = { 84 + [S5M8767_LDO1] = &ldo_voltage_val2, 85 + [S5M8767_LDO2] = &ldo_voltage_val2, 86 + [S5M8767_LDO3] = &ldo_voltage_val1, 87 + [S5M8767_LDO4] = &ldo_voltage_val1, 88 + [S5M8767_LDO5] = &ldo_voltage_val1, 89 + [S5M8767_LDO6] = &ldo_voltage_val2, 90 + [S5M8767_LDO7] = &ldo_voltage_val2, 91 + [S5M8767_LDO8] = &ldo_voltage_val2, 92 + [S5M8767_LDO9] = &ldo_voltage_val1, 93 + [S5M8767_LDO10] = &ldo_voltage_val1, 94 + [S5M8767_LDO11] = &ldo_voltage_val1, 95 + [S5M8767_LDO12] = &ldo_voltage_val1, 96 + [S5M8767_LDO13] = &ldo_voltage_val1, 97 + [S5M8767_LDO14] = &ldo_voltage_val1, 98 + [S5M8767_LDO15] = &ldo_voltage_val2, 99 + [S5M8767_LDO16] = &ldo_voltage_val1, 100 + [S5M8767_LDO17] = &ldo_voltage_val1, 101 + [S5M8767_LDO18] = &ldo_voltage_val1, 102 + [S5M8767_LDO19] = &ldo_voltage_val1, 103 + [S5M8767_LDO20] = &ldo_voltage_val1, 104 + [S5M8767_LDO21] = &ldo_voltage_val1, 105 + [S5M8767_LDO22] = &ldo_voltage_val1, 106 + [S5M8767_LDO23] = &ldo_voltage_val1, 107 + [S5M8767_LDO24] = &ldo_voltage_val1, 108 + [S5M8767_LDO25] = &ldo_voltage_val1, 109 + [S5M8767_LDO26] = &ldo_voltage_val1, 110 + [S5M8767_LDO27] = &ldo_voltage_val1, 111 + [S5M8767_LDO28] = &ldo_voltage_val1, 112 + [S5M8767_BUCK1] = &buck_voltage_val1, 113 + [S5M8767_BUCK2] = &buck_voltage_val2, 114 + [S5M8767_BUCK3] = &buck_voltage_val2, 115 + [S5M8767_BUCK4] = &buck_voltage_val2, 116 + [S5M8767_BUCK5] = &buck_voltage_val1, 117 + [S5M8767_BUCK6] = &buck_voltage_val1, 118 + [S5M8767_BUCK7] = NULL, 119 + [S5M8767_BUCK8] = NULL, 120 + [S5M8767_BUCK9] = &buck_voltage_val3, 121 + }; 122 + 123 + static int s5m8767_list_voltage(struct regulator_dev *rdev, 124 + unsigned int selector) 125 + { 126 + const struct s5m_voltage_desc *desc; 127 + int reg_id = rdev_get_id(rdev); 128 + int val; 129 + 130 + if (reg_id >= ARRAY_SIZE(reg_voltage_map) || reg_id < 0) 131 + return -EINVAL; 132 + 133 + desc = reg_voltage_map[reg_id]; 134 + if (desc == NULL) 135 + return -EINVAL; 136 + 137 + val = desc->min + desc->step * selector; 138 + if (val > desc->max) 139 + return -EINVAL; 140 + 141 + return val; 142 + } 143 + 144 + static int s5m8767_get_register(struct regulator_dev *rdev, int *reg) 145 + { 146 + int reg_id = rdev_get_id(rdev); 147 + 148 + switch (reg_id) { 149 + case S5M8767_LDO1 ... S5M8767_LDO2: 150 + *reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1); 151 + break; 152 + case S5M8767_LDO3 ... S5M8767_LDO28: 153 + *reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3); 154 + break; 155 + case S5M8767_BUCK1: 156 + *reg = S5M8767_REG_BUCK1CTRL1; 157 + break; 158 + case S5M8767_BUCK2 ... S5M8767_BUCK4: 159 + *reg = S5M8767_REG_BUCK2CTRL + (reg_id - S5M8767_BUCK2) * 9; 160 + break; 161 + case S5M8767_BUCK5: 162 + *reg = S5M8767_REG_BUCK5CTRL1; 163 + break; 164 + case S5M8767_BUCK6 ... S5M8767_BUCK9: 165 + *reg = S5M8767_REG_BUCK6CTRL1 + (reg_id - S5M8767_BUCK6) * 2; 166 + break; 167 + default: 168 + return -EINVAL; 169 + } 170 + 171 + return 0; 172 + } 173 + 174 + static int s5m8767_reg_is_enabled(struct regulator_dev *rdev) 175 + { 176 + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 177 + int ret, reg; 178 + int mask = 0xc0, pattern = 0xc0; 179 + u8 val; 180 + 181 + ret = s5m8767_get_register(rdev, &reg); 182 + if (ret == -EINVAL) 183 + return 1; 184 + else if (ret) 185 + return ret; 186 + 187 + ret = s5m_reg_read(s5m8767->iodev, reg, &val); 188 + if (ret) 189 + return ret; 190 + 191 + return (val & mask) == pattern; 192 + } 193 + 194 + static int s5m8767_reg_enable(struct regulator_dev *rdev) 195 + { 196 + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 197 + int ret, reg; 198 + int mask = 0xc0, pattern = 0xc0; 199 + 200 + ret = s5m8767_get_register(rdev, &reg); 201 + if (ret) 202 + return ret; 203 + 204 + return s5m_reg_update(s5m8767->iodev, reg, pattern, mask); 205 + } 206 + 207 + static int s5m8767_reg_disable(struct regulator_dev *rdev) 208 + { 209 + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 210 + int ret, reg; 211 + int mask = 0xc0, pattern = 0xc0; 212 + 213 + ret = s5m8767_get_register(rdev, &reg); 214 + if (ret) 215 + return ret; 216 + 217 + return s5m_reg_update(s5m8767->iodev, reg, ~pattern, mask); 218 + } 219 + 220 + static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg) 221 + { 222 + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 223 + int reg_id = rdev_get_id(rdev); 224 + int reg; 225 + 226 + switch (reg_id) { 227 + case S5M8767_LDO1 ... S5M8767_LDO2: 228 + reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1); 229 + break; 230 + case S5M8767_LDO3 ... S5M8767_LDO28: 231 + reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3); 232 + break; 233 + case S5M8767_BUCK1: 234 + reg = S5M8767_REG_BUCK1CTRL2; 235 + break; 236 + case S5M8767_BUCK2: 237 + reg = S5M8767_REG_BUCK2DVS1; 238 + if (s5m8767->buck2_gpiodvs) 239 + reg += s5m8767->buck_gpioindex; 240 + break; 241 + case S5M8767_BUCK3: 242 + reg = S5M8767_REG_BUCK3DVS1; 243 + if (s5m8767->buck3_gpiodvs) 244 + reg += s5m8767->buck_gpioindex; 245 + break; 246 + case S5M8767_BUCK4: 247 + reg = S5M8767_REG_BUCK4DVS1; 248 + if (s5m8767->buck4_gpiodvs) 249 + reg += s5m8767->buck_gpioindex; 250 + break; 251 + case S5M8767_BUCK5: 252 + reg = S5M8767_REG_BUCK5CTRL2; 253 + break; 254 + case S5M8767_BUCK6 ... S5M8767_BUCK9: 255 + reg = S5M8767_REG_BUCK6CTRL2 + (reg_id - S5M8767_BUCK6) * 2; 256 + break; 257 + default: 258 + return -EINVAL; 259 + } 260 + 261 + *_reg = reg; 262 + 263 + return 0; 264 + } 265 + 266 + static int s5m8767_get_voltage_sel(struct regulator_dev *rdev) 267 + { 268 + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 269 + int reg, mask, ret; 270 + int reg_id = rdev_get_id(rdev); 271 + u8 val; 272 + 273 + ret = s5m8767_get_voltage_register(rdev, &reg); 274 + if (ret) 275 + return ret; 276 + 277 + mask = (reg_id < S5M8767_BUCK1) ? 0x3f : 0xff; 278 + 279 + ret = s5m_reg_read(s5m8767->iodev, reg, &val); 280 + if (ret) 281 + return ret; 282 + 283 + val &= mask; 284 + 285 + return val; 286 + } 287 + 288 + static int s5m8767_convert_voltage_to_sel( 289 + const struct s5m_voltage_desc *desc, 290 + int min_vol, int max_vol) 291 + { 292 + int selector = 0; 293 + 294 + if (desc == NULL) 295 + return -EINVAL; 296 + 297 + if (max_vol < desc->min || min_vol > desc->max) 298 + return -EINVAL; 299 + 300 + selector = (min_vol - desc->min) / desc->step; 301 + 302 + if (desc->min + desc->step * selector > max_vol) 303 + return -EINVAL; 304 + 305 + return selector; 306 + } 307 + 308 + static int s5m8767_set_voltage(struct regulator_dev *rdev, 309 + int min_uV, int max_uV, unsigned *selector) 310 + { 311 + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 312 + const struct s5m_voltage_desc *desc; 313 + int reg_id = rdev_get_id(rdev); 314 + int reg, mask, ret; 315 + int i; 316 + u8 val; 317 + 318 + switch (reg_id) { 319 + case S5M8767_LDO1 ... S5M8767_LDO28: 320 + mask = 0x3f; 321 + break; 322 + case S5M8767_BUCK1 ... S5M8767_BUCK6: 323 + mask = 0xff; 324 + break; 325 + case S5M8767_BUCK7 ... S5M8767_BUCK8: 326 + return -EINVAL; 327 + case S5M8767_BUCK9: 328 + mask = 0xff; 329 + break; 330 + default: 331 + return -EINVAL; 332 + } 333 + 334 + desc = reg_voltage_map[reg_id]; 335 + 336 + i = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV); 337 + if (i < 0) 338 + return i; 339 + 340 + ret = s5m8767_get_voltage_register(rdev, &reg); 341 + if (ret) 342 + return ret; 343 + 344 + s5m_reg_read(s5m8767->iodev, reg, &val); 345 + val = val & mask; 346 + 347 + ret = s5m_reg_write(s5m8767->iodev, reg, val); 348 + *selector = i; 349 + 350 + return ret; 351 + } 352 + 353 + static inline void s5m8767_set_high(struct s5m8767_info *s5m8767) 354 + { 355 + int temp_index = s5m8767->buck_gpioindex; 356 + 357 + gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); 358 + gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); 359 + gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); 360 + } 361 + 362 + static inline void s5m8767_set_low(struct s5m8767_info *s5m8767) 363 + { 364 + int temp_index = s5m8767->buck_gpioindex; 365 + 366 + gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); 367 + gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); 368 + gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); 369 + } 370 + 371 + static int s5m8767_set_voltage_buck(struct regulator_dev *rdev, 372 + int min_uV, int max_uV, unsigned *selector) 373 + { 374 + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 375 + int reg_id = rdev_get_id(rdev); 376 + const struct s5m_voltage_desc *desc; 377 + int new_val, old_val, i = 0; 378 + 379 + if (reg_id < S5M8767_BUCK1 || reg_id > S5M8767_BUCK6) 380 + return -EINVAL; 381 + 382 + switch (reg_id) { 383 + case S5M8767_BUCK1: 384 + return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); 385 + case S5M8767_BUCK2 ... S5M8767_BUCK4: 386 + break; 387 + case S5M8767_BUCK5 ... S5M8767_BUCK6: 388 + return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); 389 + case S5M8767_BUCK9: 390 + return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); 391 + } 392 + 393 + desc = reg_voltage_map[reg_id]; 394 + new_val = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV); 395 + if (new_val < 0) 396 + return new_val; 397 + 398 + switch (reg_id) { 399 + case S5M8767_BUCK2: 400 + if (s5m8767->buck2_gpiodvs) { 401 + while (s5m8767->buck2_vol[i] != new_val) 402 + i++; 403 + } else 404 + return s5m8767_set_voltage(rdev, min_uV, 405 + max_uV, selector); 406 + break; 407 + case S5M8767_BUCK3: 408 + if (s5m8767->buck3_gpiodvs) { 409 + while (s5m8767->buck3_vol[i] != new_val) 410 + i++; 411 + } else 412 + return s5m8767_set_voltage(rdev, min_uV, 413 + max_uV, selector); 414 + break; 415 + case S5M8767_BUCK4: 416 + if (s5m8767->buck3_gpiodvs) { 417 + while (s5m8767->buck4_vol[i] != new_val) 418 + i++; 419 + } else 420 + return s5m8767_set_voltage(rdev, min_uV, 421 + max_uV, selector); 422 + break; 423 + } 424 + 425 + old_val = s5m8767->buck_gpioindex; 426 + s5m8767->buck_gpioindex = i; 427 + 428 + if (i > old_val) 429 + s5m8767_set_high(s5m8767); 430 + else 431 + s5m8767_set_low(s5m8767); 432 + 433 + *selector = new_val; 434 + return 0; 435 + } 436 + 437 + static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, 438 + unsigned int old_sel, 439 + unsigned int new_sel) 440 + { 441 + struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 442 + const struct s5m_voltage_desc *desc; 443 + int reg_id = rdev_get_id(rdev); 444 + 445 + desc = reg_voltage_map[reg_id]; 446 + 447 + if (old_sel < new_sel) 448 + return DIV_ROUND_UP(desc->step * (new_sel - old_sel), 449 + s5m8767->ramp_delay * 1000); 450 + return 0; 451 + } 452 + 453 + static struct regulator_ops s5m8767_ldo_ops = { 454 + .list_voltage = s5m8767_list_voltage, 455 + .is_enabled = s5m8767_reg_is_enabled, 456 + .enable = s5m8767_reg_enable, 457 + .disable = s5m8767_reg_disable, 458 + .get_voltage_sel = s5m8767_get_voltage_sel, 459 + .set_voltage = s5m8767_set_voltage, 460 + .set_voltage_time_sel = s5m8767_set_voltage_time_sel, 461 + }; 462 + 463 + static struct regulator_ops s5m8767_buck_ops = { 464 + .list_voltage = s5m8767_list_voltage, 465 + .is_enabled = s5m8767_reg_is_enabled, 466 + .enable = s5m8767_reg_enable, 467 + .disable = s5m8767_reg_disable, 468 + .get_voltage_sel = s5m8767_get_voltage_sel, 469 + .set_voltage = s5m8767_set_voltage_buck, 470 + .set_voltage_time_sel = s5m8767_set_voltage_time_sel, 471 + }; 472 + 473 + #define regulator_desc_ldo(num) { \ 474 + .name = "LDO"#num, \ 475 + .id = S5M8767_LDO##num, \ 476 + .ops = &s5m8767_ldo_ops, \ 477 + .type = REGULATOR_VOLTAGE, \ 478 + .owner = THIS_MODULE, \ 479 + } 480 + #define regulator_desc_buck(num) { \ 481 + .name = "BUCK"#num, \ 482 + .id = S5M8767_BUCK##num, \ 483 + .ops = &s5m8767_buck_ops, \ 484 + .type = REGULATOR_VOLTAGE, \ 485 + .owner = THIS_MODULE, \ 486 + } 487 + 488 + static struct regulator_desc regulators[] = { 489 + regulator_desc_ldo(1), 490 + regulator_desc_ldo(2), 491 + regulator_desc_ldo(3), 492 + regulator_desc_ldo(4), 493 + regulator_desc_ldo(5), 494 + regulator_desc_ldo(6), 495 + regulator_desc_ldo(7), 496 + regulator_desc_ldo(8), 497 + regulator_desc_ldo(9), 498 + regulator_desc_ldo(10), 499 + regulator_desc_ldo(11), 500 + regulator_desc_ldo(12), 501 + regulator_desc_ldo(13), 502 + regulator_desc_ldo(14), 503 + regulator_desc_ldo(15), 504 + regulator_desc_ldo(16), 505 + regulator_desc_ldo(17), 506 + regulator_desc_ldo(18), 507 + regulator_desc_ldo(19), 508 + regulator_desc_ldo(20), 509 + regulator_desc_ldo(21), 510 + regulator_desc_ldo(22), 511 + regulator_desc_ldo(23), 512 + regulator_desc_ldo(24), 513 + regulator_desc_ldo(25), 514 + regulator_desc_ldo(26), 515 + regulator_desc_ldo(27), 516 + regulator_desc_ldo(28), 517 + regulator_desc_buck(1), 518 + regulator_desc_buck(2), 519 + regulator_desc_buck(3), 520 + regulator_desc_buck(4), 521 + regulator_desc_buck(5), 522 + regulator_desc_buck(6), 523 + regulator_desc_buck(7), 524 + regulator_desc_buck(8), 525 + regulator_desc_buck(9), 526 + }; 527 + 528 + static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) 529 + { 530 + struct s5m87xx_dev *iodev = dev_get_drvdata(pdev->dev.parent); 531 + struct s5m_platform_data *pdata = dev_get_platdata(iodev->dev); 532 + struct regulator_dev **rdev; 533 + struct s5m8767_info *s5m8767; 534 + int i, ret, size; 535 + 536 + if (!pdata) { 537 + dev_err(pdev->dev.parent, "Platform data not supplied\n"); 538 + return -ENODEV; 539 + } 540 + 541 + if (pdata->buck2_gpiodvs) { 542 + if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) { 543 + dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); 544 + return -EINVAL; 545 + } 546 + } 547 + 548 + if (pdata->buck3_gpiodvs) { 549 + if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) { 550 + dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); 551 + return -EINVAL; 552 + } 553 + } 554 + 555 + if (pdata->buck4_gpiodvs) { 556 + if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) { 557 + dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); 558 + return -EINVAL; 559 + } 560 + } 561 + 562 + s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info), 563 + GFP_KERNEL); 564 + if (!s5m8767) 565 + return -ENOMEM; 566 + 567 + size = sizeof(struct regulator_dev *) * (S5M8767_REG_MAX - 2); 568 + s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); 569 + if (!s5m8767->rdev) 570 + return -ENOMEM; 571 + 572 + rdev = s5m8767->rdev; 573 + s5m8767->dev = &pdev->dev; 574 + s5m8767->iodev = iodev; 575 + s5m8767->num_regulators = S5M8767_REG_MAX - 2; 576 + platform_set_drvdata(pdev, s5m8767); 577 + 578 + s5m8767->buck_gpioindex = pdata->buck_default_idx; 579 + s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs; 580 + s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs; 581 + s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs; 582 + s5m8767->buck_gpios[0] = pdata->buck_gpios[0]; 583 + s5m8767->buck_gpios[1] = pdata->buck_gpios[1]; 584 + s5m8767->buck_gpios[2] = pdata->buck_gpios[2]; 585 + s5m8767->ramp_delay = pdata->buck_ramp_delay; 586 + s5m8767->buck2_ramp = pdata->buck2_ramp_enable; 587 + s5m8767->buck3_ramp = pdata->buck3_ramp_enable; 588 + s5m8767->buck4_ramp = pdata->buck4_ramp_enable; 589 + 590 + for (i = 0; i < 8; i++) { 591 + if (s5m8767->buck2_gpiodvs) { 592 + s5m8767->buck2_vol[i] = 593 + s5m8767_convert_voltage_to_sel( 594 + &buck_voltage_val2, 595 + pdata->buck2_voltage[i], 596 + pdata->buck2_voltage[i] + 597 + buck_voltage_val2.step); 598 + } 599 + 600 + if (s5m8767->buck3_gpiodvs) { 601 + s5m8767->buck3_vol[i] = 602 + s5m8767_convert_voltage_to_sel( 603 + &buck_voltage_val2, 604 + pdata->buck3_voltage[i], 605 + pdata->buck3_voltage[i] + 606 + buck_voltage_val2.step); 607 + } 608 + 609 + if (s5m8767->buck4_gpiodvs) { 610 + s5m8767->buck4_vol[i] = 611 + s5m8767_convert_voltage_to_sel( 612 + &buck_voltage_val2, 613 + pdata->buck4_voltage[i], 614 + pdata->buck4_voltage[i] + 615 + buck_voltage_val2.step); 616 + } 617 + } 618 + 619 + if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || 620 + pdata->buck4_gpiodvs) { 621 + if (gpio_is_valid(pdata->buck_gpios[0]) && 622 + gpio_is_valid(pdata->buck_gpios[1]) && 623 + gpio_is_valid(pdata->buck_gpios[2])) { 624 + ret = gpio_request(pdata->buck_gpios[0], 625 + "S5M8767 SET1"); 626 + if (ret == -EBUSY) 627 + dev_warn(&pdev->dev, "Duplicated gpio request for SET1\n"); 628 + 629 + ret = gpio_request(pdata->buck_gpios[1], 630 + "S5M8767 SET2"); 631 + if (ret == -EBUSY) 632 + dev_warn(&pdev->dev, "Duplicated gpio request for SET2\n"); 633 + 634 + ret = gpio_request(pdata->buck_gpios[2], 635 + "S5M8767 SET3"); 636 + if (ret == -EBUSY) 637 + dev_warn(&pdev->dev, "Duplicated gpio request for SET3\n"); 638 + /* SET1 GPIO */ 639 + gpio_direction_output(pdata->buck_gpios[0], 640 + (s5m8767->buck_gpioindex >> 2) & 0x1); 641 + /* SET2 GPIO */ 642 + gpio_direction_output(pdata->buck_gpios[1], 643 + (s5m8767->buck_gpioindex >> 1) & 0x1); 644 + /* SET3 GPIO */ 645 + gpio_direction_output(pdata->buck_gpios[2], 646 + (s5m8767->buck_gpioindex >> 0) & 0x1); 647 + ret = 0; 648 + } else { 649 + dev_err(&pdev->dev, "GPIO NOT VALID\n"); 650 + ret = -EINVAL; 651 + return ret; 652 + } 653 + } 654 + 655 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 656 + (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); 657 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 658 + (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); 659 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 660 + (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); 661 + 662 + /* Initialize GPIO DVS registers */ 663 + for (i = 0; i < 8; i++) { 664 + if (s5m8767->buck2_gpiodvs) { 665 + s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS1 + i, 666 + s5m8767->buck2_vol[i]); 667 + } 668 + 669 + if (s5m8767->buck3_gpiodvs) { 670 + s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS1 + i, 671 + s5m8767->buck3_vol[i]); 672 + } 673 + 674 + if (s5m8767->buck4_gpiodvs) { 675 + s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS1 + i, 676 + s5m8767->buck4_vol[i]); 677 + } 678 + } 679 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 0x78, 0xff); 680 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 0x58, 0xff); 681 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 0x78, 0xff); 682 + 683 + if (s5m8767->buck2_ramp) 684 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08); 685 + 686 + if (s5m8767->buck3_ramp) 687 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x04, 0x04); 688 + 689 + if (s5m8767->buck4_ramp) 690 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x02, 0x02); 691 + 692 + if (s5m8767->buck2_ramp || s5m8767->buck3_ramp 693 + || s5m8767->buck4_ramp) { 694 + switch (s5m8767->ramp_delay) { 695 + case 15: 696 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 697 + 0xc0, 0xf0); 698 + break; 699 + case 25: 700 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 701 + 0xd0, 0xf0); 702 + break; 703 + case 50: 704 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 705 + 0xe0, 0xf0); 706 + break; 707 + case 100: 708 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 709 + 0xf0, 0xf0); 710 + break; 711 + default: 712 + s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 713 + 0x90, 0xf0); 714 + } 715 + } 716 + 717 + for (i = 0; i < pdata->num_regulators; i++) { 718 + const struct s5m_voltage_desc *desc; 719 + int id = pdata->regulators[i].id; 720 + 721 + desc = reg_voltage_map[id]; 722 + if (desc) 723 + regulators[id].n_voltages = 724 + (desc->max - desc->min) / desc->step + 1; 725 + 726 + rdev[i] = regulator_register(&regulators[id], s5m8767->dev, 727 + pdata->regulators[i].initdata, s5m8767, NULL); 728 + if (IS_ERR(rdev[i])) { 729 + ret = PTR_ERR(rdev[i]); 730 + dev_err(s5m8767->dev, "regulator init failed for %d\n", 731 + id); 732 + rdev[i] = NULL; 733 + goto err; 734 + } 735 + } 736 + 737 + return 0; 738 + err: 739 + for (i = 0; i < s5m8767->num_regulators; i++) 740 + if (rdev[i]) 741 + regulator_unregister(rdev[i]); 742 + 743 + return ret; 744 + } 745 + 746 + static int __devexit s5m8767_pmic_remove(struct platform_device *pdev) 747 + { 748 + struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev); 749 + struct regulator_dev **rdev = s5m8767->rdev; 750 + int i; 751 + 752 + for (i = 0; i < s5m8767->num_regulators; i++) 753 + if (rdev[i]) 754 + regulator_unregister(rdev[i]); 755 + 756 + return 0; 757 + } 758 + 759 + static const struct platform_device_id s5m8767_pmic_id[] = { 760 + { "s5m8767-pmic", 0}, 761 + { }, 762 + }; 763 + MODULE_DEVICE_TABLE(platform, s5m8767_pmic_id); 764 + 765 + static struct platform_driver s5m8767_pmic_driver = { 766 + .driver = { 767 + .name = "s5m8767-pmic", 768 + .owner = THIS_MODULE, 769 + }, 770 + .probe = s5m8767_pmic_probe, 771 + .remove = __devexit_p(s5m8767_pmic_remove), 772 + .id_table = s5m8767_pmic_id, 773 + }; 774 + 775 + static int __init s5m8767_pmic_init(void) 776 + { 777 + return platform_driver_register(&s5m8767_pmic_driver); 778 + } 779 + subsys_initcall(s5m8767_pmic_init); 780 + 781 + static void __exit s5m8767_pmic_exit(void) 782 + { 783 + platform_driver_unregister(&s5m8767_pmic_driver); 784 + } 785 + module_exit(s5m8767_pmic_exit); 786 + 787 + /* Module information */ 788 + MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); 789 + MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver"); 790 + MODULE_LICENSE("GPL");
+472
drivers/regulator/tps62360-regulator.c
··· 1 + /* 2 + * tps62360.c -- TI tps62360 3 + * 4 + * Driver for processor core supply tps62360 and tps62361B 5 + * 6 + * Copyright (c) 2012, NVIDIA Corporation. 7 + * 8 + * Author: Laxman Dewangan <ldewangan@nvidia.com> 9 + * 10 + * This program is free software; you can redistribute it and/or 11 + * modify it under the terms of the GNU General Public License as 12 + * published by the Free Software Foundation version 2. 13 + * 14 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 15 + * whether express or implied; without even the implied warranty of 16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 + * General Public License for more details. 18 + * 19 + * You should have received a copy of the GNU General Public License 20 + * along with this program; if not, write to the Free Software 21 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 22 + * 02111-1307, USA 23 + */ 24 + 25 + #include <linux/kernel.h> 26 + #include <linux/module.h> 27 + #include <linux/init.h> 28 + #include <linux/err.h> 29 + #include <linux/platform_device.h> 30 + #include <linux/regulator/driver.h> 31 + #include <linux/regulator/machine.h> 32 + #include <linux/regulator/tps62360.h> 33 + #include <linux/gpio.h> 34 + #include <linux/i2c.h> 35 + #include <linux/delay.h> 36 + #include <linux/slab.h> 37 + #include <linux/regmap.h> 38 + 39 + /* Register definitions */ 40 + #define REG_VSET0 0 41 + #define REG_VSET1 1 42 + #define REG_VSET2 2 43 + #define REG_VSET3 3 44 + #define REG_CONTROL 4 45 + #define REG_TEMP 5 46 + #define REG_RAMPCTRL 6 47 + #define REG_CHIPID 8 48 + 49 + enum chips {TPS62360, TPS62361}; 50 + 51 + #define TPS62360_BASE_VOLTAGE 770 52 + #define TPS62360_N_VOLTAGES 64 53 + 54 + #define TPS62361_BASE_VOLTAGE 500 55 + #define TPS62361_N_VOLTAGES 128 56 + 57 + /* tps 62360 chip information */ 58 + struct tps62360_chip { 59 + const char *name; 60 + struct device *dev; 61 + struct regulator_desc desc; 62 + struct i2c_client *client; 63 + struct regulator_dev *rdev; 64 + struct regmap *regmap; 65 + int chip_id; 66 + int vsel0_gpio; 67 + int vsel1_gpio; 68 + int voltage_base; 69 + u8 voltage_reg_mask; 70 + bool en_internal_pulldn; 71 + bool en_force_pwm; 72 + bool en_discharge; 73 + bool valid_gpios; 74 + int lru_index[4]; 75 + int curr_vset_vsel[4]; 76 + int curr_vset_id; 77 + }; 78 + 79 + /* 80 + * find_voltage_set_register: Find new voltage configuration register 81 + * (VSET) id. 82 + * The finding of the new VSET register will be based on the LRU mechanism. 83 + * Each VSET register will have different voltage configured . This 84 + * Function will look if any of the VSET register have requested voltage set 85 + * or not. 86 + * - If it is already there then it will make that register as most 87 + * recently used and return as found so that caller need not to set 88 + * the VSET register but need to set the proper gpios to select this 89 + * VSET register. 90 + * - If requested voltage is not found then it will use the least 91 + * recently mechanism to get new VSET register for new configuration 92 + * and will return not_found so that caller need to set new VSET 93 + * register and then gpios (both). 94 + */ 95 + static bool find_voltage_set_register(struct tps62360_chip *tps, 96 + int req_vsel, int *vset_reg_id) 97 + { 98 + int i; 99 + bool found = false; 100 + int new_vset_reg = tps->lru_index[3]; 101 + int found_index = 3; 102 + for (i = 0; i < 4; ++i) { 103 + if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) { 104 + new_vset_reg = tps->lru_index[i]; 105 + found_index = i; 106 + found = true; 107 + goto update_lru_index; 108 + } 109 + } 110 + 111 + update_lru_index: 112 + for (i = found_index; i > 0; i--) 113 + tps->lru_index[i] = tps->lru_index[i - 1]; 114 + 115 + tps->lru_index[0] = new_vset_reg; 116 + *vset_reg_id = new_vset_reg; 117 + return found; 118 + } 119 + 120 + static int tps62360_dcdc_get_voltage(struct regulator_dev *dev) 121 + { 122 + struct tps62360_chip *tps = rdev_get_drvdata(dev); 123 + int vsel; 124 + unsigned int data; 125 + int ret; 126 + 127 + ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data); 128 + if (ret < 0) { 129 + dev_err(tps->dev, "%s: Error in reading register %d\n", 130 + __func__, REG_VSET0 + tps->curr_vset_id); 131 + return ret; 132 + } 133 + vsel = (int)data & tps->voltage_reg_mask; 134 + return (tps->voltage_base + vsel * 10) * 1000; 135 + } 136 + 137 + static int tps62360_dcdc_set_voltage(struct regulator_dev *dev, 138 + int min_uV, int max_uV, unsigned *selector) 139 + { 140 + struct tps62360_chip *tps = rdev_get_drvdata(dev); 141 + int vsel; 142 + int ret; 143 + bool found = false; 144 + int new_vset_id = tps->curr_vset_id; 145 + 146 + if (max_uV < min_uV) 147 + return -EINVAL; 148 + 149 + if (min_uV > 150 + ((tps->voltage_base + (tps->desc.n_voltages - 1) * 10) * 1000)) 151 + return -EINVAL; 152 + 153 + if (max_uV < tps->voltage_base * 1000) 154 + return -EINVAL; 155 + 156 + vsel = DIV_ROUND_UP(min_uV - (tps->voltage_base * 1000), 10000); 157 + if (selector) 158 + *selector = (vsel & tps->voltage_reg_mask); 159 + 160 + /* 161 + * If gpios are available to select the VSET register then least 162 + * recently used register for new configuration. 163 + */ 164 + if (tps->valid_gpios) 165 + found = find_voltage_set_register(tps, vsel, &new_vset_id); 166 + 167 + if (!found) { 168 + ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id, 169 + tps->voltage_reg_mask, vsel); 170 + if (ret < 0) { 171 + dev_err(tps->dev, "%s: Error in updating register %d\n", 172 + __func__, REG_VSET0 + new_vset_id); 173 + return ret; 174 + } 175 + tps->curr_vset_id = new_vset_id; 176 + tps->curr_vset_vsel[new_vset_id] = vsel; 177 + } 178 + 179 + /* Select proper VSET register vio gpios */ 180 + if (tps->valid_gpios) { 181 + gpio_set_value_cansleep(tps->vsel0_gpio, 182 + new_vset_id & 0x1); 183 + gpio_set_value_cansleep(tps->vsel1_gpio, 184 + (new_vset_id >> 1) & 0x1); 185 + } 186 + return 0; 187 + } 188 + 189 + static int tps62360_dcdc_list_voltage(struct regulator_dev *dev, 190 + unsigned selector) 191 + { 192 + struct tps62360_chip *tps = rdev_get_drvdata(dev); 193 + 194 + if (selector >= tps->desc.n_voltages) 195 + return -EINVAL; 196 + return (tps->voltage_base + selector * 10) * 1000; 197 + } 198 + 199 + static struct regulator_ops tps62360_dcdc_ops = { 200 + .get_voltage = tps62360_dcdc_get_voltage, 201 + .set_voltage = tps62360_dcdc_set_voltage, 202 + .list_voltage = tps62360_dcdc_list_voltage, 203 + }; 204 + 205 + static int tps62360_init_force_pwm(struct tps62360_chip *tps, 206 + struct tps62360_regulator_platform_data *pdata, 207 + int vset_id) 208 + { 209 + unsigned int data; 210 + int ret; 211 + ret = regmap_read(tps->regmap, REG_VSET0 + vset_id, &data); 212 + if (ret < 0) { 213 + dev_err(tps->dev, "%s() fails in writing reg %d\n", 214 + __func__, REG_VSET0 + vset_id); 215 + return ret; 216 + } 217 + tps->curr_vset_vsel[vset_id] = data & tps->voltage_reg_mask; 218 + if (pdata->en_force_pwm) 219 + data |= BIT(7); 220 + else 221 + data &= ~BIT(7); 222 + ret = regmap_write(tps->regmap, REG_VSET0 + vset_id, data); 223 + if (ret < 0) 224 + dev_err(tps->dev, "%s() fails in writing reg %d\n", 225 + __func__, REG_VSET0 + vset_id); 226 + return ret; 227 + } 228 + 229 + static int tps62360_init_dcdc(struct tps62360_chip *tps, 230 + struct tps62360_regulator_platform_data *pdata) 231 + { 232 + int ret; 233 + int i; 234 + 235 + /* Initailize internal pull up/down control */ 236 + if (tps->en_internal_pulldn) 237 + ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0); 238 + else 239 + ret = regmap_write(tps->regmap, REG_CONTROL, 0x0); 240 + if (ret < 0) { 241 + dev_err(tps->dev, "%s() fails in writing reg %d\n", 242 + __func__, REG_CONTROL); 243 + return ret; 244 + } 245 + 246 + /* Initailize force PWM mode */ 247 + if (tps->valid_gpios) { 248 + for (i = 0; i < 4; ++i) { 249 + ret = tps62360_init_force_pwm(tps, pdata, i); 250 + if (ret < 0) 251 + return ret; 252 + } 253 + } else { 254 + ret = tps62360_init_force_pwm(tps, pdata, tps->curr_vset_id); 255 + if (ret < 0) 256 + return ret; 257 + } 258 + 259 + /* Reset output discharge path to reduce power consumption */ 260 + ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0); 261 + if (ret < 0) 262 + dev_err(tps->dev, "%s() fails in updating reg %d\n", 263 + __func__, REG_RAMPCTRL); 264 + return ret; 265 + } 266 + 267 + static const struct regmap_config tps62360_regmap_config = { 268 + .reg_bits = 8, 269 + .val_bits = 8, 270 + }; 271 + 272 + static int __devinit tps62360_probe(struct i2c_client *client, 273 + const struct i2c_device_id *id) 274 + { 275 + struct tps62360_regulator_platform_data *pdata; 276 + struct regulator_dev *rdev; 277 + struct tps62360_chip *tps; 278 + int ret; 279 + int i; 280 + 281 + pdata = client->dev.platform_data; 282 + if (!pdata) { 283 + dev_err(&client->dev, "%s() Err: Platform data not found\n", 284 + __func__); 285 + return -EIO; 286 + } 287 + 288 + tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 289 + if (!tps) { 290 + dev_err(&client->dev, "%s() Err: Memory allocation fails\n", 291 + __func__); 292 + return -ENOMEM; 293 + } 294 + 295 + tps->en_force_pwm = pdata->en_force_pwm; 296 + tps->en_discharge = pdata->en_discharge; 297 + tps->en_internal_pulldn = pdata->en_internal_pulldn; 298 + tps->vsel0_gpio = pdata->vsel0_gpio; 299 + tps->vsel1_gpio = pdata->vsel1_gpio; 300 + tps->client = client; 301 + tps->dev = &client->dev; 302 + tps->name = id->name; 303 + tps->voltage_base = (id->driver_data == TPS62360) ? 304 + TPS62360_BASE_VOLTAGE : TPS62361_BASE_VOLTAGE; 305 + tps->voltage_reg_mask = (id->driver_data == TPS62360) ? 0x3F : 0x7F; 306 + 307 + tps->desc.name = id->name; 308 + tps->desc.id = 0; 309 + tps->desc.n_voltages = (id->driver_data == TPS62360) ? 310 + TPS62360_N_VOLTAGES : TPS62361_N_VOLTAGES; 311 + tps->desc.ops = &tps62360_dcdc_ops; 312 + tps->desc.type = REGULATOR_VOLTAGE; 313 + tps->desc.owner = THIS_MODULE; 314 + tps->regmap = regmap_init_i2c(client, &tps62360_regmap_config); 315 + if (IS_ERR(tps->regmap)) { 316 + ret = PTR_ERR(tps->regmap); 317 + dev_err(&client->dev, "%s() Err: Failed to allocate register" 318 + "map: %d\n", __func__, ret); 319 + return ret; 320 + } 321 + i2c_set_clientdata(client, tps); 322 + 323 + tps->curr_vset_id = (pdata->vsel1_def_state & 1) * 2 + 324 + (pdata->vsel0_def_state & 1); 325 + tps->lru_index[0] = tps->curr_vset_id; 326 + tps->valid_gpios = false; 327 + 328 + if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) { 329 + ret = gpio_request(tps->vsel0_gpio, "tps62360-vsel0"); 330 + if (ret) { 331 + dev_err(&client->dev, 332 + "Err: Could not obtain vsel0 GPIO %d: %d\n", 333 + tps->vsel0_gpio, ret); 334 + goto err_gpio0; 335 + } 336 + ret = gpio_direction_output(tps->vsel0_gpio, 337 + pdata->vsel0_def_state); 338 + if (ret) { 339 + dev_err(&client->dev, "Err: Could not set direction of" 340 + "vsel0 GPIO %d: %d\n", tps->vsel0_gpio, ret); 341 + gpio_free(tps->vsel0_gpio); 342 + goto err_gpio0; 343 + } 344 + 345 + ret = gpio_request(tps->vsel1_gpio, "tps62360-vsel1"); 346 + if (ret) { 347 + dev_err(&client->dev, 348 + "Err: Could not obtain vsel1 GPIO %d: %d\n", 349 + tps->vsel1_gpio, ret); 350 + goto err_gpio1; 351 + } 352 + ret = gpio_direction_output(tps->vsel1_gpio, 353 + pdata->vsel1_def_state); 354 + if (ret) { 355 + dev_err(&client->dev, "Err: Could not set direction of" 356 + "vsel1 GPIO %d: %d\n", tps->vsel1_gpio, ret); 357 + gpio_free(tps->vsel1_gpio); 358 + goto err_gpio1; 359 + } 360 + tps->valid_gpios = true; 361 + 362 + /* 363 + * Initialize the lru index with vset_reg id 364 + * The index 0 will be most recently used and 365 + * set with the tps->curr_vset_id */ 366 + for (i = 0; i < 4; ++i) 367 + tps->lru_index[i] = i; 368 + tps->lru_index[0] = tps->curr_vset_id; 369 + tps->lru_index[tps->curr_vset_id] = 0; 370 + } 371 + 372 + ret = tps62360_init_dcdc(tps, pdata); 373 + if (ret < 0) { 374 + dev_err(tps->dev, "%s() Err: Init fails with = %d\n", 375 + __func__, ret); 376 + goto err_init; 377 + } 378 + 379 + /* Register the regulators */ 380 + rdev = regulator_register(&tps->desc, &client->dev, 381 + &pdata->reg_init_data, tps, NULL); 382 + if (IS_ERR(rdev)) { 383 + dev_err(tps->dev, "%s() Err: Failed to register %s\n", 384 + __func__, id->name); 385 + ret = PTR_ERR(rdev); 386 + goto err_init; 387 + } 388 + 389 + tps->rdev = rdev; 390 + return 0; 391 + 392 + err_init: 393 + if (gpio_is_valid(tps->vsel1_gpio)) 394 + gpio_free(tps->vsel1_gpio); 395 + err_gpio1: 396 + if (gpio_is_valid(tps->vsel0_gpio)) 397 + gpio_free(tps->vsel0_gpio); 398 + err_gpio0: 399 + regmap_exit(tps->regmap); 400 + return ret; 401 + } 402 + 403 + /** 404 + * tps62360_remove - tps62360 driver i2c remove handler 405 + * @client: i2c driver client device structure 406 + * 407 + * Unregister TPS driver as an i2c client device driver 408 + */ 409 + static int __devexit tps62360_remove(struct i2c_client *client) 410 + { 411 + struct tps62360_chip *tps = i2c_get_clientdata(client); 412 + 413 + if (gpio_is_valid(tps->vsel1_gpio)) 414 + gpio_free(tps->vsel1_gpio); 415 + 416 + if (gpio_is_valid(tps->vsel0_gpio)) 417 + gpio_free(tps->vsel0_gpio); 418 + 419 + regulator_unregister(tps->rdev); 420 + regmap_exit(tps->regmap); 421 + return 0; 422 + } 423 + 424 + static void tps62360_shutdown(struct i2c_client *client) 425 + { 426 + struct tps62360_chip *tps = i2c_get_clientdata(client); 427 + int st; 428 + 429 + if (!tps->en_discharge) 430 + return; 431 + 432 + /* Configure the output discharge path */ 433 + st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2)); 434 + if (st < 0) 435 + dev_err(tps->dev, "%s() fails in updating reg %d\n", 436 + __func__, REG_RAMPCTRL); 437 + } 438 + 439 + static const struct i2c_device_id tps62360_id[] = { 440 + {.name = "tps62360", .driver_data = TPS62360}, 441 + {.name = "tps62361", .driver_data = TPS62361}, 442 + {}, 443 + }; 444 + 445 + MODULE_DEVICE_TABLE(i2c, tps62360_id); 446 + 447 + static struct i2c_driver tps62360_i2c_driver = { 448 + .driver = { 449 + .name = "tps62360", 450 + .owner = THIS_MODULE, 451 + }, 452 + .probe = tps62360_probe, 453 + .remove = __devexit_p(tps62360_remove), 454 + .shutdown = tps62360_shutdown, 455 + .id_table = tps62360_id, 456 + }; 457 + 458 + static int __init tps62360_init(void) 459 + { 460 + return i2c_add_driver(&tps62360_i2c_driver); 461 + } 462 + subsys_initcall(tps62360_init); 463 + 464 + static void __exit tps62360_cleanup(void) 465 + { 466 + i2c_del_driver(&tps62360_i2c_driver); 467 + } 468 + module_exit(tps62360_cleanup); 469 + 470 + MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); 471 + MODULE_DESCRIPTION("TPS62360 voltage regulator driver"); 472 + MODULE_LICENSE("GPL v2");
-4
drivers/regulator/tps65023-regulator.c
··· 491 491 regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, 492 492 TPS65023_REG_CTRL2_CORE_ADJ, TPS65023_REG_CTRL2_CORE_ADJ); 493 493 494 - /* Enable setting output voltage by I2C */ 495 - regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, 496 - TPS65023_REG_CTRL2_CORE_ADJ, TPS65023_REG_CTRL2_CORE_ADJ); 497 - 498 494 return 0; 499 495 500 496 fail:
+89 -244
drivers/regulator/tps6507x-regulator.c
··· 238 238 return err; 239 239 } 240 240 241 - static int tps6507x_pmic_dcdc_is_enabled(struct regulator_dev *dev) 241 + static int tps6507x_pmic_is_enabled(struct regulator_dev *dev) 242 242 { 243 243 struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 244 - int data, dcdc = rdev_get_id(dev); 244 + int data, rid = rdev_get_id(dev); 245 245 u8 shift; 246 246 247 - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) 247 + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) 248 248 return -EINVAL; 249 249 250 - shift = TPS6507X_MAX_REG_ID - dcdc; 250 + shift = TPS6507X_MAX_REG_ID - rid; 251 251 data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1); 252 252 253 253 if (data < 0) ··· 256 256 return (data & 1<<shift) ? 1 : 0; 257 257 } 258 258 259 - static int tps6507x_pmic_ldo_is_enabled(struct regulator_dev *dev) 259 + static int tps6507x_pmic_enable(struct regulator_dev *dev) 260 260 { 261 261 struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 262 - int data, ldo = rdev_get_id(dev); 262 + int rid = rdev_get_id(dev); 263 263 u8 shift; 264 264 265 - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 265 + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) 266 266 return -EINVAL; 267 267 268 - shift = TPS6507X_MAX_REG_ID - ldo; 269 - data = tps6507x_pmic_reg_read(tps, TPS6507X_REG_CON_CTRL1); 270 - 271 - if (data < 0) 272 - return data; 273 - else 274 - return (data & 1<<shift) ? 1 : 0; 275 - } 276 - 277 - static int tps6507x_pmic_dcdc_enable(struct regulator_dev *dev) 278 - { 279 - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 280 - int dcdc = rdev_get_id(dev); 281 - u8 shift; 282 - 283 - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) 284 - return -EINVAL; 285 - 286 - shift = TPS6507X_MAX_REG_ID - dcdc; 268 + shift = TPS6507X_MAX_REG_ID - rid; 287 269 return tps6507x_pmic_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); 288 270 } 289 271 290 - static int tps6507x_pmic_dcdc_disable(struct regulator_dev *dev) 272 + static int tps6507x_pmic_disable(struct regulator_dev *dev) 291 273 { 292 274 struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 293 - int dcdc = rdev_get_id(dev); 275 + int rid = rdev_get_id(dev); 294 276 u8 shift; 295 277 296 - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) 278 + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) 297 279 return -EINVAL; 298 280 299 - shift = TPS6507X_MAX_REG_ID - dcdc; 281 + shift = TPS6507X_MAX_REG_ID - rid; 300 282 return tps6507x_pmic_clear_bits(tps, TPS6507X_REG_CON_CTRL1, 301 283 1 << shift); 302 284 } 303 285 304 - static int tps6507x_pmic_ldo_enable(struct regulator_dev *dev) 286 + static int tps6507x_pmic_get_voltage(struct regulator_dev *dev) 305 287 { 306 288 struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 307 - int ldo = rdev_get_id(dev); 308 - u8 shift; 309 - 310 - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 311 - return -EINVAL; 312 - 313 - shift = TPS6507X_MAX_REG_ID - ldo; 314 - return tps6507x_pmic_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); 315 - } 316 - 317 - static int tps6507x_pmic_ldo_disable(struct regulator_dev *dev) 318 - { 319 - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 320 - int ldo = rdev_get_id(dev); 321 - u8 shift; 322 - 323 - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 324 - return -EINVAL; 325 - 326 - shift = TPS6507X_MAX_REG_ID - ldo; 327 - return tps6507x_pmic_clear_bits(tps, TPS6507X_REG_CON_CTRL1, 328 - 1 << shift); 329 - } 330 - 331 - static int tps6507x_pmic_dcdc_get_voltage(struct regulator_dev *dev) 332 - { 333 - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 334 - int data, dcdc = rdev_get_id(dev); 335 - u8 reg; 336 - 337 - switch (dcdc) { 338 - case TPS6507X_DCDC_1: 339 - reg = TPS6507X_REG_DEFDCDC1; 340 - break; 341 - case TPS6507X_DCDC_2: 342 - if (tps->info[dcdc]->defdcdc_default) 343 - reg = TPS6507X_REG_DEFDCDC2_HIGH; 344 - else 345 - reg = TPS6507X_REG_DEFDCDC2_LOW; 346 - break; 347 - case TPS6507X_DCDC_3: 348 - if (tps->info[dcdc]->defdcdc_default) 349 - reg = TPS6507X_REG_DEFDCDC3_HIGH; 350 - else 351 - reg = TPS6507X_REG_DEFDCDC3_LOW; 352 - break; 353 - default: 354 - return -EINVAL; 355 - } 356 - 357 - data = tps6507x_pmic_reg_read(tps, reg); 358 - if (data < 0) 359 - return data; 360 - 361 - data &= TPS6507X_DEFDCDCX_DCDC_MASK; 362 - return tps->info[dcdc]->table[data] * 1000; 363 - } 364 - 365 - static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev, 366 - int min_uV, int max_uV, 367 - unsigned *selector) 368 - { 369 - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 370 - int data, vsel, dcdc = rdev_get_id(dev); 371 - u8 reg; 372 - 373 - switch (dcdc) { 374 - case TPS6507X_DCDC_1: 375 - reg = TPS6507X_REG_DEFDCDC1; 376 - break; 377 - case TPS6507X_DCDC_2: 378 - if (tps->info[dcdc]->defdcdc_default) 379 - reg = TPS6507X_REG_DEFDCDC2_HIGH; 380 - else 381 - reg = TPS6507X_REG_DEFDCDC2_LOW; 382 - break; 383 - case TPS6507X_DCDC_3: 384 - if (tps->info[dcdc]->defdcdc_default) 385 - reg = TPS6507X_REG_DEFDCDC3_HIGH; 386 - else 387 - reg = TPS6507X_REG_DEFDCDC3_LOW; 388 - break; 389 - default: 390 - return -EINVAL; 391 - } 392 - 393 - if (min_uV < tps->info[dcdc]->min_uV 394 - || min_uV > tps->info[dcdc]->max_uV) 395 - return -EINVAL; 396 - if (max_uV < tps->info[dcdc]->min_uV 397 - || max_uV > tps->info[dcdc]->max_uV) 398 - return -EINVAL; 399 - 400 - for (vsel = 0; vsel < tps->info[dcdc]->table_len; vsel++) { 401 - int mV = tps->info[dcdc]->table[vsel]; 402 - int uV = mV * 1000; 403 - 404 - /* Break at the first in-range value */ 405 - if (min_uV <= uV && uV <= max_uV) 406 - break; 407 - } 408 - 409 - /* write to the register in case we found a match */ 410 - if (vsel == tps->info[dcdc]->table_len) 411 - return -EINVAL; 412 - 413 - *selector = vsel; 414 - 415 - data = tps6507x_pmic_reg_read(tps, reg); 416 - if (data < 0) 417 - return data; 418 - 419 - data &= ~TPS6507X_DEFDCDCX_DCDC_MASK; 420 - data |= vsel; 421 - 422 - return tps6507x_pmic_reg_write(tps, reg, data); 423 - } 424 - 425 - static int tps6507x_pmic_ldo_get_voltage(struct regulator_dev *dev) 426 - { 427 - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 428 - int data, ldo = rdev_get_id(dev); 289 + int data, rid = rdev_get_id(dev); 429 290 u8 reg, mask; 430 291 431 - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 292 + switch (rid) { 293 + case TPS6507X_DCDC_1: 294 + reg = TPS6507X_REG_DEFDCDC1; 295 + mask = TPS6507X_DEFDCDCX_DCDC_MASK; 296 + break; 297 + case TPS6507X_DCDC_2: 298 + if (tps->info[rid]->defdcdc_default) 299 + reg = TPS6507X_REG_DEFDCDC2_HIGH; 300 + else 301 + reg = TPS6507X_REG_DEFDCDC2_LOW; 302 + mask = TPS6507X_DEFDCDCX_DCDC_MASK; 303 + break; 304 + case TPS6507X_DCDC_3: 305 + if (tps->info[rid]->defdcdc_default) 306 + reg = TPS6507X_REG_DEFDCDC3_HIGH; 307 + else 308 + reg = TPS6507X_REG_DEFDCDC3_LOW; 309 + mask = TPS6507X_DEFDCDCX_DCDC_MASK; 310 + break; 311 + case TPS6507X_LDO_1: 312 + reg = TPS6507X_REG_LDO_CTRL1; 313 + mask = TPS6507X_REG_LDO_CTRL1_LDO1_MASK; 314 + break; 315 + case TPS6507X_LDO_2: 316 + reg = TPS6507X_REG_DEFLDO2; 317 + mask = TPS6507X_REG_DEFLDO2_LDO2_MASK; 318 + break; 319 + default: 432 320 return -EINVAL; 433 - else { 434 - reg = (ldo == TPS6507X_LDO_1 ? 435 - TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2); 436 - mask = (ldo == TPS6507X_LDO_1 ? 437 - TPS6507X_REG_LDO_CTRL1_LDO1_MASK : 438 - TPS6507X_REG_DEFLDO2_LDO2_MASK); 439 321 } 440 322 441 323 data = tps6507x_pmic_reg_read(tps, reg); ··· 325 443 return data; 326 444 327 445 data &= mask; 328 - return tps->info[ldo]->table[data] * 1000; 446 + return tps->info[rid]->table[data] * 1000; 329 447 } 330 448 331 - static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev, 332 - int min_uV, int max_uV, 333 - unsigned *selector) 449 + static int tps6507x_pmic_set_voltage_sel(struct regulator_dev *dev, 450 + unsigned selector) 334 451 { 335 452 struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 336 - int data, vsel, ldo = rdev_get_id(dev); 453 + int data, rid = rdev_get_id(dev); 337 454 u8 reg, mask; 338 455 339 - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 456 + switch (rid) { 457 + case TPS6507X_DCDC_1: 458 + reg = TPS6507X_REG_DEFDCDC1; 459 + mask = TPS6507X_DEFDCDCX_DCDC_MASK; 460 + break; 461 + case TPS6507X_DCDC_2: 462 + if (tps->info[rid]->defdcdc_default) 463 + reg = TPS6507X_REG_DEFDCDC2_HIGH; 464 + else 465 + reg = TPS6507X_REG_DEFDCDC2_LOW; 466 + mask = TPS6507X_DEFDCDCX_DCDC_MASK; 467 + break; 468 + case TPS6507X_DCDC_3: 469 + if (tps->info[rid]->defdcdc_default) 470 + reg = TPS6507X_REG_DEFDCDC3_HIGH; 471 + else 472 + reg = TPS6507X_REG_DEFDCDC3_LOW; 473 + mask = TPS6507X_DEFDCDCX_DCDC_MASK; 474 + break; 475 + case TPS6507X_LDO_1: 476 + reg = TPS6507X_REG_LDO_CTRL1; 477 + mask = TPS6507X_REG_LDO_CTRL1_LDO1_MASK; 478 + break; 479 + case TPS6507X_LDO_2: 480 + reg = TPS6507X_REG_DEFLDO2; 481 + mask = TPS6507X_REG_DEFLDO2_LDO2_MASK; 482 + break; 483 + default: 340 484 return -EINVAL; 341 - else { 342 - reg = (ldo == TPS6507X_LDO_1 ? 343 - TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2); 344 - mask = (ldo == TPS6507X_LDO_1 ? 345 - TPS6507X_REG_LDO_CTRL1_LDO1_MASK : 346 - TPS6507X_REG_DEFLDO2_LDO2_MASK); 347 485 } 348 - 349 - if (min_uV < tps->info[ldo]->min_uV || min_uV > tps->info[ldo]->max_uV) 350 - return -EINVAL; 351 - if (max_uV < tps->info[ldo]->min_uV || max_uV > tps->info[ldo]->max_uV) 352 - return -EINVAL; 353 - 354 - for (vsel = 0; vsel < tps->info[ldo]->table_len; vsel++) { 355 - int mV = tps->info[ldo]->table[vsel]; 356 - int uV = mV * 1000; 357 - 358 - /* Break at the first in-range value */ 359 - if (min_uV <= uV && uV <= max_uV) 360 - break; 361 - } 362 - 363 - if (vsel == tps->info[ldo]->table_len) 364 - return -EINVAL; 365 - 366 - *selector = vsel; 367 486 368 487 data = tps6507x_pmic_reg_read(tps, reg); 369 488 if (data < 0) 370 489 return data; 371 490 372 491 data &= ~mask; 373 - data |= vsel; 492 + data |= selector; 374 493 375 494 return tps6507x_pmic_reg_write(tps, reg, data); 376 495 } 377 496 378 - static int tps6507x_pmic_dcdc_list_voltage(struct regulator_dev *dev, 497 + static int tps6507x_pmic_list_voltage(struct regulator_dev *dev, 379 498 unsigned selector) 380 499 { 381 500 struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 382 - int dcdc = rdev_get_id(dev); 501 + int rid = rdev_get_id(dev); 383 502 384 - if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) 503 + if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) 385 504 return -EINVAL; 386 505 387 - if (selector >= tps->info[dcdc]->table_len) 388 - return -EINVAL; 389 - else 390 - return tps->info[dcdc]->table[selector] * 1000; 391 - } 392 - 393 - static int tps6507x_pmic_ldo_list_voltage(struct regulator_dev *dev, 394 - unsigned selector) 395 - { 396 - struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 397 - int ldo = rdev_get_id(dev); 398 - 399 - if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 400 - return -EINVAL; 401 - 402 - if (selector >= tps->info[ldo]->table_len) 506 + if (selector >= tps->info[rid]->table_len) 403 507 return -EINVAL; 404 508 else 405 - return tps->info[ldo]->table[selector] * 1000; 509 + return tps->info[rid]->table[selector] * 1000; 406 510 } 407 511 408 - /* Operations permitted on VDCDCx */ 409 - static struct regulator_ops tps6507x_pmic_dcdc_ops = { 410 - .is_enabled = tps6507x_pmic_dcdc_is_enabled, 411 - .enable = tps6507x_pmic_dcdc_enable, 412 - .disable = tps6507x_pmic_dcdc_disable, 413 - .get_voltage = tps6507x_pmic_dcdc_get_voltage, 414 - .set_voltage = tps6507x_pmic_dcdc_set_voltage, 415 - .list_voltage = tps6507x_pmic_dcdc_list_voltage, 512 + static struct regulator_ops tps6507x_pmic_ops = { 513 + .is_enabled = tps6507x_pmic_is_enabled, 514 + .enable = tps6507x_pmic_enable, 515 + .disable = tps6507x_pmic_disable, 516 + .get_voltage = tps6507x_pmic_get_voltage, 517 + .set_voltage_sel = tps6507x_pmic_set_voltage_sel, 518 + .list_voltage = tps6507x_pmic_list_voltage, 416 519 }; 417 520 418 - /* Operations permitted on LDOx */ 419 - static struct regulator_ops tps6507x_pmic_ldo_ops = { 420 - .is_enabled = tps6507x_pmic_ldo_is_enabled, 421 - .enable = tps6507x_pmic_ldo_enable, 422 - .disable = tps6507x_pmic_ldo_disable, 423 - .get_voltage = tps6507x_pmic_ldo_get_voltage, 424 - .set_voltage = tps6507x_pmic_ldo_set_voltage, 425 - .list_voltage = tps6507x_pmic_ldo_list_voltage, 426 - }; 427 - 428 - static __devinit 429 - int tps6507x_pmic_probe(struct platform_device *pdev) 521 + static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) 430 522 { 431 523 struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent); 432 524 struct tps_info *info = &tps6507x_pmic_regs[0]; ··· 449 593 tps->desc[i].name = info->name; 450 594 tps->desc[i].id = i; 451 595 tps->desc[i].n_voltages = info->table_len; 452 - tps->desc[i].ops = (i > TPS6507X_DCDC_3 ? 453 - &tps6507x_pmic_ldo_ops : &tps6507x_pmic_dcdc_ops); 596 + tps->desc[i].ops = &tps6507x_pmic_ops; 454 597 tps->desc[i].type = REGULATOR_VOLTAGE; 455 598 tps->desc[i].owner = THIS_MODULE; 456 599 ··· 503 648 .remove = __devexit_p(tps6507x_pmic_remove), 504 649 }; 505 650 506 - /** 507 - * tps6507x_pmic_init 508 - * 509 - * Module init function 510 - */ 511 651 static int __init tps6507x_pmic_init(void) 512 652 { 513 653 return platform_driver_register(&tps6507x_pmic_driver); 514 654 } 515 655 subsys_initcall(tps6507x_pmic_init); 516 656 517 - /** 518 - * tps6507x_pmic_cleanup 519 - * 520 - * Module exit function 521 - */ 522 657 static void __exit tps6507x_pmic_cleanup(void) 523 658 { 524 659 platform_driver_unregister(&tps6507x_pmic_driver);
+378
drivers/regulator/tps65217-regulator.c
··· 1 + /* 2 + * tps65217-regulator.c 3 + * 4 + * Regulator driver for TPS65217 PMIC 5 + * 6 + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 7 + * 8 + * This program is free software; you can redistribute it and/or 9 + * modify it under the terms of the GNU General Public License as 10 + * published by the Free Software Foundation version 2. 11 + * 12 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any 13 + * kind, whether express or implied; without even the implied warranty 14 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 20 + #include <linux/device.h> 21 + #include <linux/init.h> 22 + #include <linux/err.h> 23 + #include <linux/platform_device.h> 24 + 25 + #include <linux/regulator/driver.h> 26 + #include <linux/regulator/machine.h> 27 + #include <linux/mfd/tps65217.h> 28 + 29 + #define TPS65217_REGULATOR(_name, _id, _ops, _n) \ 30 + { \ 31 + .name = _name, \ 32 + .id = _id, \ 33 + .ops = &_ops, \ 34 + .n_voltages = _n, \ 35 + .type = REGULATOR_VOLTAGE, \ 36 + .owner = THIS_MODULE, \ 37 + } \ 38 + 39 + #define TPS65217_INFO(_nm, _min, _max, _f1, _f2, _t, _n, _em, _vr, _vm) \ 40 + { \ 41 + .name = _nm, \ 42 + .min_uV = _min, \ 43 + .max_uV = _max, \ 44 + .vsel_to_uv = _f1, \ 45 + .uv_to_vsel = _f2, \ 46 + .table = _t, \ 47 + .table_len = _n, \ 48 + .enable_mask = _em, \ 49 + .set_vout_reg = _vr, \ 50 + .set_vout_mask = _vm, \ 51 + } 52 + 53 + static const int LDO1_VSEL_table[] = { 54 + 1000000, 1100000, 1200000, 1250000, 55 + 1300000, 1350000, 1400000, 1500000, 56 + 1600000, 1800000, 2500000, 2750000, 57 + 2800000, 3000000, 3100000, 3300000, 58 + }; 59 + 60 + static int tps65217_vsel_to_uv1(unsigned int vsel) 61 + { 62 + int uV = 0; 63 + 64 + if (vsel > 63) 65 + return -EINVAL; 66 + 67 + if (vsel <= 24) 68 + uV = vsel * 25000 + 900000; 69 + else if (vsel <= 52) 70 + uV = (vsel - 24) * 50000 + 1500000; 71 + else if (vsel < 56) 72 + uV = (vsel - 52) * 100000 + 2900000; 73 + else 74 + uV = 3300000; 75 + 76 + return uV; 77 + } 78 + 79 + static int tps65217_uv_to_vsel1(int uV, unsigned int *vsel) 80 + { 81 + if ((uV < 0) && (uV > 3300000)) 82 + return -EINVAL; 83 + 84 + if (uV <= 1500000) 85 + *vsel = DIV_ROUND_UP(uV - 900000, 25000); 86 + else if (uV <= 2900000) 87 + *vsel = 24 + DIV_ROUND_UP(uV - 1500000, 50000); 88 + else if (uV < 3300000) 89 + *vsel = 52 + DIV_ROUND_UP(uV - 2900000, 100000); 90 + else 91 + *vsel = 56; 92 + 93 + return 0; 94 + } 95 + 96 + static int tps65217_vsel_to_uv2(unsigned int vsel) 97 + { 98 + int uV = 0; 99 + 100 + if (vsel > 31) 101 + return -EINVAL; 102 + 103 + if (vsel <= 8) 104 + uV = vsel * 50000 + 1500000; 105 + else if (vsel <= 13) 106 + uV = (vsel - 8) * 100000 + 1900000; 107 + else 108 + uV = (vsel - 13) * 50000 + 2400000; 109 + 110 + return uV; 111 + } 112 + 113 + static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel) 114 + { 115 + if ((uV < 0) && (uV > 3300000)) 116 + return -EINVAL; 117 + 118 + if (uV <= 1900000) 119 + *vsel = DIV_ROUND_UP(uV - 1500000, 50000); 120 + else if (uV <= 2400000) 121 + *vsel = 8 + DIV_ROUND_UP(uV - 1900000, 100000); 122 + else 123 + *vsel = 13 + DIV_ROUND_UP(uV - 2400000, 50000); 124 + 125 + return 0; 126 + } 127 + 128 + static struct tps_info tps65217_pmic_regs[] = { 129 + TPS65217_INFO("DCDC1", 900000, 1800000, tps65217_vsel_to_uv1, 130 + tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC1_EN, 131 + TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK), 132 + TPS65217_INFO("DCDC2", 900000, 3300000, tps65217_vsel_to_uv1, 133 + tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC2_EN, 134 + TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK), 135 + TPS65217_INFO("DCDC3", 900000, 1500000, tps65217_vsel_to_uv1, 136 + tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC3_EN, 137 + TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK), 138 + TPS65217_INFO("LDO1", 1000000, 3300000, NULL, NULL, LDO1_VSEL_table, 139 + 16, TPS65217_ENABLE_LDO1_EN, TPS65217_REG_DEFLDO1, 140 + TPS65217_DEFLDO1_LDO1_MASK), 141 + TPS65217_INFO("LDO2", 900000, 3300000, tps65217_vsel_to_uv1, 142 + tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_LDO2_EN, 143 + TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK), 144 + TPS65217_INFO("LDO3", 1800000, 3300000, tps65217_vsel_to_uv2, 145 + tps65217_uv_to_vsel2, NULL, 32, 146 + TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN, 147 + TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK), 148 + TPS65217_INFO("LDO4", 1800000, 3300000, tps65217_vsel_to_uv2, 149 + tps65217_uv_to_vsel2, NULL, 32, 150 + TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN, 151 + TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK), 152 + }; 153 + 154 + static int tps65217_pmic_is_enabled(struct regulator_dev *dev) 155 + { 156 + int ret; 157 + struct tps65217 *tps = rdev_get_drvdata(dev); 158 + unsigned int data, rid = rdev_get_id(dev); 159 + 160 + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) 161 + return -EINVAL; 162 + 163 + ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data); 164 + if (ret) 165 + return ret; 166 + 167 + return (data & tps->info[rid]->enable_mask) ? 1 : 0; 168 + } 169 + 170 + static int tps65217_pmic_enable(struct regulator_dev *dev) 171 + { 172 + struct tps65217 *tps = rdev_get_drvdata(dev); 173 + unsigned int rid = rdev_get_id(dev); 174 + 175 + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) 176 + return -EINVAL; 177 + 178 + /* Enable the regulator and password protection is level 1 */ 179 + return tps65217_set_bits(tps, TPS65217_REG_ENABLE, 180 + tps->info[rid]->enable_mask, 181 + tps->info[rid]->enable_mask, 182 + TPS65217_PROTECT_L1); 183 + } 184 + 185 + static int tps65217_pmic_disable(struct regulator_dev *dev) 186 + { 187 + struct tps65217 *tps = rdev_get_drvdata(dev); 188 + unsigned int rid = rdev_get_id(dev); 189 + 190 + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) 191 + return -EINVAL; 192 + 193 + /* Disable the regulator and password protection is level 1 */ 194 + return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, 195 + tps->info[rid]->enable_mask, TPS65217_PROTECT_L1); 196 + } 197 + 198 + static int tps65217_pmic_get_voltage_sel(struct regulator_dev *dev) 199 + { 200 + int ret; 201 + struct tps65217 *tps = rdev_get_drvdata(dev); 202 + unsigned int selector, rid = rdev_get_id(dev); 203 + 204 + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) 205 + return -EINVAL; 206 + 207 + ret = tps65217_reg_read(tps, tps->info[rid]->set_vout_reg, &selector); 208 + if (ret) 209 + return ret; 210 + 211 + selector &= tps->info[rid]->set_vout_mask; 212 + 213 + return selector; 214 + } 215 + 216 + static int tps65217_pmic_ldo1_set_voltage_sel(struct regulator_dev *dev, 217 + unsigned selector) 218 + { 219 + struct tps65217 *tps = rdev_get_drvdata(dev); 220 + int ldo = rdev_get_id(dev); 221 + 222 + if (ldo != TPS65217_LDO_1) 223 + return -EINVAL; 224 + 225 + if (selector >= tps->info[ldo]->table_len) 226 + return -EINVAL; 227 + 228 + /* Set the voltage based on vsel value and write protect level is 2 */ 229 + return tps65217_set_bits(tps, tps->info[ldo]->set_vout_reg, 230 + tps->info[ldo]->set_vout_mask, 231 + selector, TPS65217_PROTECT_L2); 232 + } 233 + 234 + static int tps65217_pmic_set_voltage(struct regulator_dev *dev, 235 + int min_uV, int max_uV, unsigned *selector) 236 + { 237 + int ret; 238 + struct tps65217 *tps = rdev_get_drvdata(dev); 239 + unsigned int rid = rdev_get_id(dev); 240 + 241 + /* LDO1 implements set_voltage_sel callback */ 242 + if (rid == TPS65217_LDO_1) 243 + return -EINVAL; 244 + 245 + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) 246 + return -EINVAL; 247 + 248 + if (min_uV < tps->info[rid]->min_uV 249 + || min_uV > tps->info[rid]->max_uV) 250 + return -EINVAL; 251 + 252 + if (max_uV < tps->info[rid]->min_uV 253 + || max_uV > tps->info[rid]->max_uV) 254 + return -EINVAL; 255 + 256 + ret = tps->info[rid]->uv_to_vsel(min_uV, selector); 257 + if (ret) 258 + return ret; 259 + 260 + /* Set the voltage based on vsel value and write protect level is 2 */ 261 + ret = tps65217_set_bits(tps, tps->info[rid]->set_vout_reg, 262 + tps->info[rid]->set_vout_mask, 263 + *selector, TPS65217_PROTECT_L2); 264 + 265 + /* Set GO bit for DCDCx to initiate voltage transistion */ 266 + switch (rid) { 267 + case TPS65217_DCDC_1 ... TPS65217_DCDC_3: 268 + ret = tps65217_set_bits(tps, TPS65217_REG_DEFSLEW, 269 + TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO, 270 + TPS65217_PROTECT_L2); 271 + break; 272 + } 273 + 274 + return ret; 275 + } 276 + 277 + static int tps65217_pmic_list_voltage(struct regulator_dev *dev, 278 + unsigned selector) 279 + { 280 + struct tps65217 *tps = rdev_get_drvdata(dev); 281 + unsigned int rid = rdev_get_id(dev); 282 + 283 + if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) 284 + return -EINVAL; 285 + 286 + if (selector >= tps->info[rid]->table_len) 287 + return -EINVAL; 288 + 289 + if (tps->info[rid]->table) 290 + return tps->info[rid]->table[selector]; 291 + 292 + return tps->info[rid]->vsel_to_uv(selector); 293 + } 294 + 295 + /* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ 296 + static struct regulator_ops tps65217_pmic_ops = { 297 + .is_enabled = tps65217_pmic_is_enabled, 298 + .enable = tps65217_pmic_enable, 299 + .disable = tps65217_pmic_disable, 300 + .get_voltage_sel = tps65217_pmic_get_voltage_sel, 301 + .set_voltage = tps65217_pmic_set_voltage, 302 + .list_voltage = tps65217_pmic_list_voltage, 303 + }; 304 + 305 + /* Operations permitted on LDO1 */ 306 + static struct regulator_ops tps65217_pmic_ldo1_ops = { 307 + .is_enabled = tps65217_pmic_is_enabled, 308 + .enable = tps65217_pmic_enable, 309 + .disable = tps65217_pmic_disable, 310 + .get_voltage_sel = tps65217_pmic_get_voltage_sel, 311 + .set_voltage_sel = tps65217_pmic_ldo1_set_voltage_sel, 312 + .list_voltage = tps65217_pmic_list_voltage, 313 + }; 314 + 315 + static struct regulator_desc regulators[] = { 316 + TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64), 317 + TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64), 318 + TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64), 319 + TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16), 320 + TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64), 321 + TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32), 322 + TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32), 323 + }; 324 + 325 + static int __devinit tps65217_regulator_probe(struct platform_device *pdev) 326 + { 327 + struct regulator_dev *rdev; 328 + struct tps65217 *tps; 329 + struct tps_info *info = &tps65217_pmic_regs[pdev->id]; 330 + 331 + /* Already set by core driver */ 332 + tps = dev_to_tps65217(pdev->dev.parent); 333 + tps->info[pdev->id] = info; 334 + 335 + rdev = regulator_register(&regulators[pdev->id], &pdev->dev, 336 + pdev->dev.platform_data, tps, NULL); 337 + if (IS_ERR(rdev)) 338 + return PTR_ERR(rdev); 339 + 340 + platform_set_drvdata(pdev, rdev); 341 + 342 + return 0; 343 + } 344 + 345 + static int __devexit tps65217_regulator_remove(struct platform_device *pdev) 346 + { 347 + struct regulator_dev *rdev = platform_get_drvdata(pdev); 348 + 349 + platform_set_drvdata(pdev, NULL); 350 + regulator_unregister(rdev); 351 + 352 + return 0; 353 + } 354 + 355 + static struct platform_driver tps65217_regulator_driver = { 356 + .driver = { 357 + .name = "tps65217-pmic", 358 + }, 359 + .probe = tps65217_regulator_probe, 360 + .remove = __devexit_p(tps65217_regulator_remove), 361 + }; 362 + 363 + static int __init tps65217_regulator_init(void) 364 + { 365 + return platform_driver_register(&tps65217_regulator_driver); 366 + } 367 + subsys_initcall(tps65217_regulator_init); 368 + 369 + static void __exit tps65217_regulator_exit(void) 370 + { 371 + platform_driver_unregister(&tps65217_regulator_driver); 372 + } 373 + module_exit(tps65217_regulator_exit); 374 + 375 + MODULE_AUTHOR("AnilKumar Ch <anilkumar@ti.com>"); 376 + MODULE_DESCRIPTION("TPS65217 voltage regulator driver"); 377 + MODULE_ALIAS("platform:tps65217-pmic"); 378 + MODULE_LICENSE("GPL v2");
+1 -3
drivers/regulator/tps6524x-regulator.c
··· 108 108 #define N_DCDC 3 109 109 #define N_LDO 2 110 110 #define N_SWITCH 2 111 - #define N_REGULATORS (3 /* DCDC */ + \ 112 - 2 /* LDO */ + \ 113 - 2 /* switch */) 111 + #define N_REGULATORS (N_DCDC + N_LDO + N_SWITCH) 114 112 115 113 #define FIXED_ILIMSEL BIT(0) 116 114 #define FIXED_VOLTAGE BIT(1)
+1 -1
drivers/regulator/tps6586x-regulator.c
··· 383 383 int id = pdev->id; 384 384 int err; 385 385 386 - dev_dbg(&pdev->dev, "Probing reulator %d\n", id); 386 + dev_dbg(&pdev->dev, "Probing regulator %d\n", id); 387 387 388 388 ri = find_regulator_info(id); 389 389 if (ri == NULL) {
+344 -54
drivers/regulator/tps65910-regulator.c
··· 26 26 #include <linux/mfd/tps65910.h> 27 27 28 28 #define TPS65910_SUPPLY_STATE_ENABLED 0x1 29 + #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \ 30 + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \ 31 + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \ 32 + TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) 29 33 30 34 /* supported VIO voltages in milivolts */ 31 35 static const u16 VIO_VSEL_table[] = { ··· 87 83 const char *name; 88 84 unsigned min_uV; 89 85 unsigned max_uV; 90 - u8 table_len; 91 - const u16 *table; 86 + u8 n_voltages; 87 + const u16 *voltage_table; 88 + int enable_time_us; 92 89 }; 93 90 94 91 static struct tps_info tps65910_regs[] = { 95 92 { 96 93 .name = "VRTC", 94 + .enable_time_us = 2200, 97 95 }, 98 96 { 99 97 .name = "VIO", 100 98 .min_uV = 1500000, 101 99 .max_uV = 3300000, 102 - .table_len = ARRAY_SIZE(VIO_VSEL_table), 103 - .table = VIO_VSEL_table, 100 + .n_voltages = ARRAY_SIZE(VIO_VSEL_table), 101 + .voltage_table = VIO_VSEL_table, 102 + .enable_time_us = 350, 104 103 }, 105 104 { 106 105 .name = "VDD1", 107 106 .min_uV = 600000, 108 107 .max_uV = 4500000, 108 + .enable_time_us = 350, 109 109 }, 110 110 { 111 111 .name = "VDD2", 112 112 .min_uV = 600000, 113 113 .max_uV = 4500000, 114 + .enable_time_us = 350, 114 115 }, 115 116 { 116 117 .name = "VDD3", 117 118 .min_uV = 5000000, 118 119 .max_uV = 5000000, 119 - .table_len = ARRAY_SIZE(VDD3_VSEL_table), 120 - .table = VDD3_VSEL_table, 120 + .n_voltages = ARRAY_SIZE(VDD3_VSEL_table), 121 + .voltage_table = VDD3_VSEL_table, 122 + .enable_time_us = 200, 121 123 }, 122 124 { 123 125 .name = "VDIG1", 124 126 .min_uV = 1200000, 125 127 .max_uV = 2700000, 126 - .table_len = ARRAY_SIZE(VDIG1_VSEL_table), 127 - .table = VDIG1_VSEL_table, 128 + .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table), 129 + .voltage_table = VDIG1_VSEL_table, 130 + .enable_time_us = 100, 128 131 }, 129 132 { 130 133 .name = "VDIG2", 131 134 .min_uV = 1000000, 132 135 .max_uV = 1800000, 133 - .table_len = ARRAY_SIZE(VDIG2_VSEL_table), 134 - .table = VDIG2_VSEL_table, 136 + .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table), 137 + .voltage_table = VDIG2_VSEL_table, 138 + .enable_time_us = 100, 135 139 }, 136 140 { 137 141 .name = "VPLL", 138 142 .min_uV = 1000000, 139 143 .max_uV = 2500000, 140 - .table_len = ARRAY_SIZE(VPLL_VSEL_table), 141 - .table = VPLL_VSEL_table, 144 + .n_voltages = ARRAY_SIZE(VPLL_VSEL_table), 145 + .voltage_table = VPLL_VSEL_table, 146 + .enable_time_us = 100, 142 147 }, 143 148 { 144 149 .name = "VDAC", 145 150 .min_uV = 1800000, 146 151 .max_uV = 2850000, 147 - .table_len = ARRAY_SIZE(VDAC_VSEL_table), 148 - .table = VDAC_VSEL_table, 152 + .n_voltages = ARRAY_SIZE(VDAC_VSEL_table), 153 + .voltage_table = VDAC_VSEL_table, 154 + .enable_time_us = 100, 149 155 }, 150 156 { 151 157 .name = "VAUX1", 152 158 .min_uV = 1800000, 153 159 .max_uV = 2850000, 154 - .table_len = ARRAY_SIZE(VAUX1_VSEL_table), 155 - .table = VAUX1_VSEL_table, 160 + .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table), 161 + .voltage_table = VAUX1_VSEL_table, 162 + .enable_time_us = 100, 156 163 }, 157 164 { 158 165 .name = "VAUX2", 159 166 .min_uV = 1800000, 160 167 .max_uV = 3300000, 161 - .table_len = ARRAY_SIZE(VAUX2_VSEL_table), 162 - .table = VAUX2_VSEL_table, 168 + .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table), 169 + .voltage_table = VAUX2_VSEL_table, 170 + .enable_time_us = 100, 163 171 }, 164 172 { 165 173 .name = "VAUX33", 166 174 .min_uV = 1800000, 167 175 .max_uV = 3300000, 168 - .table_len = ARRAY_SIZE(VAUX33_VSEL_table), 169 - .table = VAUX33_VSEL_table, 176 + .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table), 177 + .voltage_table = VAUX33_VSEL_table, 178 + .enable_time_us = 100, 170 179 }, 171 180 { 172 181 .name = "VMMC", 173 182 .min_uV = 1800000, 174 183 .max_uV = 3300000, 175 - .table_len = ARRAY_SIZE(VMMC_VSEL_table), 176 - .table = VMMC_VSEL_table, 184 + .n_voltages = ARRAY_SIZE(VMMC_VSEL_table), 185 + .voltage_table = VMMC_VSEL_table, 186 + .enable_time_us = 100, 177 187 }, 178 188 }; 179 189 180 190 static struct tps_info tps65911_regs[] = { 181 191 { 192 + .name = "VRTC", 193 + .enable_time_us = 2200, 194 + }, 195 + { 182 196 .name = "VIO", 183 197 .min_uV = 1500000, 184 198 .max_uV = 3300000, 185 - .table_len = ARRAY_SIZE(VIO_VSEL_table), 186 - .table = VIO_VSEL_table, 199 + .n_voltages = ARRAY_SIZE(VIO_VSEL_table), 200 + .voltage_table = VIO_VSEL_table, 201 + .enable_time_us = 350, 187 202 }, 188 203 { 189 204 .name = "VDD1", 190 205 .min_uV = 600000, 191 206 .max_uV = 4500000, 207 + .n_voltages = 73, 208 + .enable_time_us = 350, 192 209 }, 193 210 { 194 211 .name = "VDD2", 195 212 .min_uV = 600000, 196 213 .max_uV = 4500000, 214 + .n_voltages = 73, 215 + .enable_time_us = 350, 197 216 }, 198 217 { 199 218 .name = "VDDCTRL", 200 219 .min_uV = 600000, 201 220 .max_uV = 1400000, 221 + .n_voltages = 65, 222 + .enable_time_us = 900, 202 223 }, 203 224 { 204 225 .name = "LDO1", 205 226 .min_uV = 1000000, 206 227 .max_uV = 3300000, 228 + .n_voltages = 47, 229 + .enable_time_us = 420, 207 230 }, 208 231 { 209 232 .name = "LDO2", 210 233 .min_uV = 1000000, 211 234 .max_uV = 3300000, 235 + .n_voltages = 47, 236 + .enable_time_us = 420, 212 237 }, 213 238 { 214 239 .name = "LDO3", 215 240 .min_uV = 1000000, 216 241 .max_uV = 3300000, 242 + .n_voltages = 24, 243 + .enable_time_us = 230, 217 244 }, 218 245 { 219 246 .name = "LDO4", 220 247 .min_uV = 1000000, 221 248 .max_uV = 3300000, 249 + .n_voltages = 47, 250 + .enable_time_us = 230, 222 251 }, 223 252 { 224 253 .name = "LDO5", 225 254 .min_uV = 1000000, 226 255 .max_uV = 3300000, 256 + .n_voltages = 24, 257 + .enable_time_us = 230, 227 258 }, 228 259 { 229 260 .name = "LDO6", 230 261 .min_uV = 1000000, 231 262 .max_uV = 3300000, 263 + .n_voltages = 24, 264 + .enable_time_us = 230, 232 265 }, 233 266 { 234 267 .name = "LDO7", 235 268 .min_uV = 1000000, 236 269 .max_uV = 3300000, 270 + .n_voltages = 24, 271 + .enable_time_us = 230, 237 272 }, 238 273 { 239 274 .name = "LDO8", 240 275 .min_uV = 1000000, 241 276 .max_uV = 3300000, 277 + .n_voltages = 24, 278 + .enable_time_us = 230, 242 279 }, 280 + }; 281 + 282 + #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits)) 283 + static unsigned int tps65910_ext_sleep_control[] = { 284 + 0, 285 + EXT_CONTROL_REG_BITS(VIO, 1, 0), 286 + EXT_CONTROL_REG_BITS(VDD1, 1, 1), 287 + EXT_CONTROL_REG_BITS(VDD2, 1, 2), 288 + EXT_CONTROL_REG_BITS(VDD3, 1, 3), 289 + EXT_CONTROL_REG_BITS(VDIG1, 0, 1), 290 + EXT_CONTROL_REG_BITS(VDIG2, 0, 2), 291 + EXT_CONTROL_REG_BITS(VPLL, 0, 6), 292 + EXT_CONTROL_REG_BITS(VDAC, 0, 7), 293 + EXT_CONTROL_REG_BITS(VAUX1, 0, 3), 294 + EXT_CONTROL_REG_BITS(VAUX2, 0, 4), 295 + EXT_CONTROL_REG_BITS(VAUX33, 0, 5), 296 + EXT_CONTROL_REG_BITS(VMMC, 0, 0), 297 + }; 298 + 299 + static unsigned int tps65911_ext_sleep_control[] = { 300 + 0, 301 + EXT_CONTROL_REG_BITS(VIO, 1, 0), 302 + EXT_CONTROL_REG_BITS(VDD1, 1, 1), 303 + EXT_CONTROL_REG_BITS(VDD2, 1, 2), 304 + EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3), 305 + EXT_CONTROL_REG_BITS(LDO1, 0, 1), 306 + EXT_CONTROL_REG_BITS(LDO2, 0, 2), 307 + EXT_CONTROL_REG_BITS(LDO3, 0, 7), 308 + EXT_CONTROL_REG_BITS(LDO4, 0, 6), 309 + EXT_CONTROL_REG_BITS(LDO5, 0, 3), 310 + EXT_CONTROL_REG_BITS(LDO6, 0, 0), 311 + EXT_CONTROL_REG_BITS(LDO7, 0, 5), 312 + EXT_CONTROL_REG_BITS(LDO8, 0, 4), 243 313 }; 244 314 245 315 struct tps65910_reg { ··· 325 247 int num_regulators; 326 248 int mode; 327 249 int (*get_ctrl_reg)(int); 250 + unsigned int *ext_sleep_control; 251 + unsigned int board_ext_control[TPS65910_NUM_REGS]; 328 252 }; 329 253 330 254 static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg) ··· 509 429 return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED); 510 430 } 511 431 432 + static int tps65910_enable_time(struct regulator_dev *dev) 433 + { 434 + struct tps65910_reg *pmic = rdev_get_drvdata(dev); 435 + int id = rdev_get_id(dev); 436 + return pmic->info[id]->enable_time_us; 437 + } 512 438 513 439 static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode) 514 440 { ··· 553 467 if (value < 0) 554 468 return value; 555 469 556 - if (value & LDO_ST_ON_BIT) 470 + if (!(value & LDO_ST_ON_BIT)) 557 471 return REGULATOR_MODE_STANDBY; 558 472 else if (value & LDO_ST_MODE_BIT) 559 473 return REGULATOR_MODE_IDLE; ··· 561 475 return REGULATOR_MODE_NORMAL; 562 476 } 563 477 564 - static int tps65910_get_voltage_dcdc(struct regulator_dev *dev) 478 + static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) 565 479 { 566 480 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 567 - int id = rdev_get_id(dev), voltage = 0; 481 + int id = rdev_get_id(dev); 568 482 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0; 569 483 570 484 switch (id) { ··· 608 522 srvsel = 3; 609 523 if (srvsel > vselmax) 610 524 srvsel = vselmax; 611 - srvsel -= 3; 612 - 613 - voltage = (srvsel * VDD1_2_OFFSET + VDD1_2_MIN_VOLT) * 100; 525 + return srvsel - 3; 614 526 } else { 615 527 616 528 /* normalise to valid range*/ ··· 616 532 opvsel = 3; 617 533 if (opvsel > vselmax) 618 534 opvsel = vselmax; 619 - opvsel -= 3; 620 - 621 - voltage = (opvsel * VDD1_2_OFFSET + VDD1_2_MIN_VOLT) * 100; 535 + return opvsel - 3; 622 536 } 623 - 624 - voltage *= mult; 625 - 626 - return voltage; 537 + return -EINVAL; 627 538 } 628 539 629 540 static int tps65910_get_voltage(struct regulator_dev *dev) ··· 651 572 return -EINVAL; 652 573 } 653 574 654 - voltage = pmic->info[id]->table[value] * 1000; 575 + voltage = pmic->info[id]->voltage_table[value] * 1000; 655 576 656 577 return voltage; 657 578 } ··· 701 622 step_mv = 100; 702 623 break; 703 624 case TPS65910_REG_VIO: 704 - return pmic->info[id]->table[value] * 1000; 705 - break; 625 + value &= LDO_SEL_MASK; 626 + value >>= LDO_SEL_SHIFT; 627 + return pmic->info[id]->voltage_table[value] * 1000; 706 628 default: 707 629 return -EINVAL; 708 630 } ··· 711 631 return (LDO_MIN_VOLT + value * step_mv) * 1000; 712 632 } 713 633 714 - static int tps65910_set_voltage_dcdc(struct regulator_dev *dev, 715 - unsigned selector) 634 + static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev, 635 + unsigned selector) 716 636 { 717 637 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 718 638 int id = rdev_get_id(dev), vsel; ··· 749 669 return 0; 750 670 } 751 671 752 - static int tps65910_set_voltage(struct regulator_dev *dev, unsigned selector) 672 + static int tps65910_set_voltage_sel(struct regulator_dev *dev, 673 + unsigned selector) 753 674 { 754 675 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 755 676 int reg, id = rdev_get_id(dev); ··· 776 695 return -EINVAL; 777 696 } 778 697 779 - static int tps65911_set_voltage(struct regulator_dev *dev, unsigned selector) 698 + static int tps65911_set_voltage_sel(struct regulator_dev *dev, 699 + unsigned selector) 780 700 { 781 701 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 782 702 int reg, id = rdev_get_id(dev); ··· 797 715 case TPS65911_REG_LDO6: 798 716 case TPS65911_REG_LDO7: 799 717 case TPS65911_REG_LDO8: 800 - case TPS65910_REG_VIO: 801 718 return tps65910_modify_bits(pmic, reg, 802 719 (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK); 720 + case TPS65910_REG_VIO: 721 + return tps65910_modify_bits(pmic, reg, 722 + (selector << LDO_SEL_SHIFT), LDO_SEL_MASK); 803 723 } 804 724 805 725 return -EINVAL; ··· 840 756 if (id < TPS65910_REG_VIO || id > TPS65910_REG_VMMC) 841 757 return -EINVAL; 842 758 843 - if (selector >= pmic->info[id]->table_len) 759 + if (selector >= pmic->info[id]->n_voltages) 844 760 return -EINVAL; 845 761 else 846 - voltage = pmic->info[id]->table[selector] * 1000; 762 + voltage = pmic->info[id]->voltage_table[selector] * 1000; 847 763 848 764 return voltage; 849 765 } ··· 879 795 step_mv = 100; 880 796 break; 881 797 case TPS65910_REG_VIO: 882 - return pmic->info[id]->table[selector] * 1000; 798 + return pmic->info[id]->voltage_table[selector] * 1000; 883 799 default: 884 800 return -EINVAL; 885 801 } ··· 887 803 return (LDO_MIN_VOLT + selector * step_mv) * 1000; 888 804 } 889 805 806 + static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev *dev, 807 + unsigned int old_selector, unsigned int new_selector) 808 + { 809 + int id = rdev_get_id(dev); 810 + int old_volt, new_volt; 811 + 812 + old_volt = tps65910_list_voltage_dcdc(dev, old_selector); 813 + if (old_volt < 0) 814 + return old_volt; 815 + 816 + new_volt = tps65910_list_voltage_dcdc(dev, new_selector); 817 + if (new_volt < 0) 818 + return new_volt; 819 + 820 + /* VDD1 and VDD2 are 12.5mV/us, VDDCTRL is 100mV/20us */ 821 + switch (id) { 822 + case TPS65910_REG_VDD1: 823 + case TPS65910_REG_VDD2: 824 + return DIV_ROUND_UP(abs(old_volt - new_volt), 12500); 825 + case TPS65911_REG_VDDCTRL: 826 + return DIV_ROUND_UP(abs(old_volt - new_volt), 5000); 827 + } 828 + return -EINVAL; 829 + } 830 + 890 831 /* Regulator ops (except VRTC) */ 891 832 static struct regulator_ops tps65910_ops_dcdc = { 892 833 .is_enabled = tps65910_is_enabled, 893 834 .enable = tps65910_enable, 894 835 .disable = tps65910_disable, 836 + .enable_time = tps65910_enable_time, 895 837 .set_mode = tps65910_set_mode, 896 838 .get_mode = tps65910_get_mode, 897 - .get_voltage = tps65910_get_voltage_dcdc, 898 - .set_voltage_sel = tps65910_set_voltage_dcdc, 839 + .get_voltage_sel = tps65910_get_voltage_dcdc_sel, 840 + .set_voltage_sel = tps65910_set_voltage_dcdc_sel, 841 + .set_voltage_time_sel = tps65910_set_voltage_dcdc_time_sel, 899 842 .list_voltage = tps65910_list_voltage_dcdc, 900 843 }; 901 844 ··· 930 819 .is_enabled = tps65910_is_enabled, 931 820 .enable = tps65910_enable, 932 821 .disable = tps65910_disable, 822 + .enable_time = tps65910_enable_time, 933 823 .set_mode = tps65910_set_mode, 934 824 .get_mode = tps65910_get_mode, 935 825 .get_voltage = tps65910_get_voltage_vdd3, ··· 941 829 .is_enabled = tps65910_is_enabled, 942 830 .enable = tps65910_enable, 943 831 .disable = tps65910_disable, 832 + .enable_time = tps65910_enable_time, 944 833 .set_mode = tps65910_set_mode, 945 834 .get_mode = tps65910_get_mode, 946 835 .get_voltage = tps65910_get_voltage, 947 - .set_voltage_sel = tps65910_set_voltage, 836 + .set_voltage_sel = tps65910_set_voltage_sel, 948 837 .list_voltage = tps65910_list_voltage, 949 838 }; 950 839 ··· 953 840 .is_enabled = tps65910_is_enabled, 954 841 .enable = tps65910_enable, 955 842 .disable = tps65910_disable, 843 + .enable_time = tps65910_enable_time, 956 844 .set_mode = tps65910_set_mode, 957 845 .get_mode = tps65910_get_mode, 958 846 .get_voltage = tps65911_get_voltage, 959 - .set_voltage_sel = tps65911_set_voltage, 847 + .set_voltage_sel = tps65911_set_voltage_sel, 960 848 .list_voltage = tps65911_list_voltage, 961 849 }; 850 + 851 + static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic, 852 + int id, int ext_sleep_config) 853 + { 854 + struct tps65910 *mfd = pmic->mfd; 855 + u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF; 856 + u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF); 857 + int ret; 858 + 859 + /* 860 + * Regulator can not be control from multiple external input EN1, EN2 861 + * and EN3 together. 862 + */ 863 + if (ext_sleep_config & EXT_SLEEP_CONTROL) { 864 + int en_count; 865 + en_count = ((ext_sleep_config & 866 + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0); 867 + en_count += ((ext_sleep_config & 868 + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0); 869 + en_count += ((ext_sleep_config & 870 + TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0); 871 + en_count += ((ext_sleep_config & 872 + TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0); 873 + if (en_count > 1) { 874 + dev_err(mfd->dev, 875 + "External sleep control flag is not proper\n"); 876 + return -EINVAL; 877 + } 878 + } 879 + 880 + pmic->board_ext_control[id] = ext_sleep_config; 881 + 882 + /* External EN1 control */ 883 + if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) 884 + ret = tps65910_set_bits(mfd, 885 + TPS65910_EN1_LDO_ASS + regoffs, bit_pos); 886 + else 887 + ret = tps65910_clear_bits(mfd, 888 + TPS65910_EN1_LDO_ASS + regoffs, bit_pos); 889 + if (ret < 0) { 890 + dev_err(mfd->dev, 891 + "Error in configuring external control EN1\n"); 892 + return ret; 893 + } 894 + 895 + /* External EN2 control */ 896 + if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) 897 + ret = tps65910_set_bits(mfd, 898 + TPS65910_EN2_LDO_ASS + regoffs, bit_pos); 899 + else 900 + ret = tps65910_clear_bits(mfd, 901 + TPS65910_EN2_LDO_ASS + regoffs, bit_pos); 902 + if (ret < 0) { 903 + dev_err(mfd->dev, 904 + "Error in configuring external control EN2\n"); 905 + return ret; 906 + } 907 + 908 + /* External EN3 control for TPS65910 LDO only */ 909 + if ((tps65910_chip_id(mfd) == TPS65910) && 910 + (id >= TPS65910_REG_VDIG1)) { 911 + if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) 912 + ret = tps65910_set_bits(mfd, 913 + TPS65910_EN3_LDO_ASS + regoffs, bit_pos); 914 + else 915 + ret = tps65910_clear_bits(mfd, 916 + TPS65910_EN3_LDO_ASS + regoffs, bit_pos); 917 + if (ret < 0) { 918 + dev_err(mfd->dev, 919 + "Error in configuring external control EN3\n"); 920 + return ret; 921 + } 922 + } 923 + 924 + /* Return if no external control is selected */ 925 + if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) { 926 + /* Clear all sleep controls */ 927 + ret = tps65910_clear_bits(mfd, 928 + TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos); 929 + if (!ret) 930 + ret = tps65910_clear_bits(mfd, 931 + TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); 932 + if (ret < 0) 933 + dev_err(mfd->dev, 934 + "Error in configuring SLEEP register\n"); 935 + return ret; 936 + } 937 + 938 + /* 939 + * For regulator that has separate operational and sleep register make 940 + * sure that operational is used and clear sleep register to turn 941 + * regulator off when external control is inactive 942 + */ 943 + if ((id == TPS65910_REG_VDD1) || 944 + (id == TPS65910_REG_VDD2) || 945 + ((id == TPS65911_REG_VDDCTRL) && 946 + (tps65910_chip_id(mfd) == TPS65911))) { 947 + int op_reg_add = pmic->get_ctrl_reg(id) + 1; 948 + int sr_reg_add = pmic->get_ctrl_reg(id) + 2; 949 + int opvsel = tps65910_reg_read(pmic, op_reg_add); 950 + int srvsel = tps65910_reg_read(pmic, sr_reg_add); 951 + if (opvsel & VDD1_OP_CMD_MASK) { 952 + u8 reg_val = srvsel & VDD1_OP_SEL_MASK; 953 + ret = tps65910_reg_write(pmic, op_reg_add, reg_val); 954 + if (ret < 0) { 955 + dev_err(mfd->dev, 956 + "Error in configuring op register\n"); 957 + return ret; 958 + } 959 + } 960 + ret = tps65910_reg_write(pmic, sr_reg_add, 0); 961 + if (ret < 0) { 962 + dev_err(mfd->dev, "Error in settting sr register\n"); 963 + return ret; 964 + } 965 + } 966 + 967 + ret = tps65910_clear_bits(mfd, 968 + TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos); 969 + if (!ret) { 970 + if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) 971 + ret = tps65910_set_bits(mfd, 972 + TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); 973 + else 974 + ret = tps65910_clear_bits(mfd, 975 + TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); 976 + } 977 + if (ret < 0) 978 + dev_err(mfd->dev, 979 + "Error in configuring SLEEP register\n"); 980 + 981 + return ret; 982 + } 962 983 963 984 static __devinit int tps65910_probe(struct platform_device *pdev) 964 985 { ··· 1124 877 case TPS65910: 1125 878 pmic->get_ctrl_reg = &tps65910_get_ctrl_register; 1126 879 pmic->num_regulators = ARRAY_SIZE(tps65910_regs); 880 + pmic->ext_sleep_control = tps65910_ext_sleep_control; 1127 881 info = tps65910_regs; 1128 882 break; 1129 883 case TPS65911: 1130 884 pmic->get_ctrl_reg = &tps65911_get_ctrl_register; 1131 885 pmic->num_regulators = ARRAY_SIZE(tps65911_regs); 886 + pmic->ext_sleep_control = tps65911_ext_sleep_control; 1132 887 info = tps65911_regs; 1133 888 break; 1134 889 default: ··· 1175 926 1176 927 pmic->desc[i].name = info->name; 1177 928 pmic->desc[i].id = i; 1178 - pmic->desc[i].n_voltages = info->table_len; 929 + pmic->desc[i].n_voltages = info->n_voltages; 1179 930 1180 931 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) { 1181 932 pmic->desc[i].ops = &tps65910_ops_dcdc; ··· 1192 943 else 1193 944 pmic->desc[i].ops = &tps65911_ops; 1194 945 } 946 + 947 + err = tps65910_set_ext_sleep_config(pmic, i, 948 + pmic_plat_data->regulator_ext_sleep_control[i]); 949 + /* 950 + * Failing on regulator for configuring externally control 951 + * is not a serious issue, just throw warning. 952 + */ 953 + if (err < 0) 954 + dev_warn(tps65910->dev, 955 + "Failed to initialise ext control config\n"); 1195 956 1196 957 pmic->desc[i].type = REGULATOR_VOLTAGE; 1197 958 pmic->desc[i].owner = THIS_MODULE; ··· 1249 990 return 0; 1250 991 } 1251 992 993 + static void tps65910_shutdown(struct platform_device *pdev) 994 + { 995 + struct tps65910_reg *pmic = platform_get_drvdata(pdev); 996 + int i; 997 + 998 + /* 999 + * Before bootloader jumps to kernel, it makes sure that required 1000 + * external control signals are in desired state so that given rails 1001 + * can be configure accordingly. 1002 + * If rails are configured to be controlled from external control 1003 + * then before shutting down/rebooting the system, the external 1004 + * control configuration need to be remove from the rails so that 1005 + * its output will be available as per register programming even 1006 + * if external controls are removed. This is require when the POR 1007 + * value of the control signals are not in active state and before 1008 + * bootloader initializes it, the system requires the rail output 1009 + * to be active for booting. 1010 + */ 1011 + for (i = 0; i < pmic->num_regulators; i++) { 1012 + int err; 1013 + if (!pmic->rdev[i]) 1014 + continue; 1015 + 1016 + err = tps65910_set_ext_sleep_config(pmic, i, 0); 1017 + if (err < 0) 1018 + dev_err(&pdev->dev, 1019 + "Error in clearing external control\n"); 1020 + } 1021 + } 1022 + 1252 1023 static struct platform_driver tps65910_driver = { 1253 1024 .driver = { 1254 1025 .name = "tps65910-pmic", ··· 1286 997 }, 1287 998 .probe = tps65910_probe, 1288 999 .remove = __devexit_p(tps65910_remove), 1000 + .shutdown = tps65910_shutdown, 1289 1001 }; 1290 1002 1291 1003 static int __init tps65910_init(void) ··· 1302 1012 module_exit(tps65910_cleanup); 1303 1013 1304 1014 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); 1305 - MODULE_DESCRIPTION("TPS6507x voltage regulator driver"); 1015 + MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver"); 1306 1016 MODULE_LICENSE("GPL v2"); 1307 1017 MODULE_ALIAS("platform:tps65910-pmic");
+85 -297
drivers/regulator/tps65912-regulator.c
··· 114 114 struct mutex io_lock; 115 115 int mode; 116 116 int (*get_ctrl_reg)(int); 117 - int dcdc1_range; 118 - int dcdc2_range; 119 - int dcdc3_range; 120 - int dcdc4_range; 117 + int dcdc_range[TPS65912_NUM_DCDC]; 121 118 int pwm_mode_reg; 122 119 int eco_reg; 123 120 }; ··· 122 125 static int tps65912_get_range(struct tps65912_reg *pmic, int id) 123 126 { 124 127 struct tps65912 *mfd = pmic->mfd; 125 - 126 - if (id > TPS65912_REG_DCDC4) 127 - return 0; 128 + int range; 128 129 129 130 switch (id) { 130 131 case TPS65912_REG_DCDC1: 131 - pmic->dcdc1_range = tps65912_reg_read(mfd, 132 - TPS65912_DCDC1_LIMIT); 133 - if (pmic->dcdc1_range < 0) 134 - return pmic->dcdc1_range; 135 - pmic->dcdc1_range = (pmic->dcdc1_range & 136 - DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT; 137 - return pmic->dcdc1_range; 132 + range = tps65912_reg_read(mfd, TPS65912_DCDC1_LIMIT); 133 + break; 138 134 case TPS65912_REG_DCDC2: 139 - pmic->dcdc2_range = tps65912_reg_read(mfd, 140 - TPS65912_DCDC2_LIMIT); 141 - if (pmic->dcdc2_range < 0) 142 - return pmic->dcdc2_range; 143 - pmic->dcdc2_range = (pmic->dcdc2_range & 144 - DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT; 145 - return pmic->dcdc2_range; 135 + range = tps65912_reg_read(mfd, TPS65912_DCDC2_LIMIT); 136 + break; 146 137 case TPS65912_REG_DCDC3: 147 - pmic->dcdc3_range = tps65912_reg_read(mfd, 148 - TPS65912_DCDC3_LIMIT); 149 - if (pmic->dcdc3_range < 0) 150 - return pmic->dcdc3_range; 151 - pmic->dcdc3_range = (pmic->dcdc3_range & 152 - DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT; 153 - return pmic->dcdc3_range; 138 + range = tps65912_reg_read(mfd, TPS65912_DCDC3_LIMIT); 139 + break; 154 140 case TPS65912_REG_DCDC4: 155 - pmic->dcdc4_range = tps65912_reg_read(mfd, 156 - TPS65912_DCDC4_LIMIT); 157 - if (pmic->dcdc4_range < 0) 158 - return pmic->dcdc4_range; 159 - pmic->dcdc4_range = (pmic->dcdc4_range & 160 - DCDC_LIMIT_RANGE_MASK) >> DCDC_LIMIT_RANGE_SHIFT; 161 - return pmic->dcdc4_range; 141 + range = tps65912_reg_read(mfd, TPS65912_DCDC4_LIMIT); 142 + break; 162 143 default: 163 144 return 0; 164 145 } 146 + 147 + if (range >= 0) 148 + range = (range & DCDC_LIMIT_RANGE_MASK) 149 + >> DCDC_LIMIT_RANGE_SHIFT; 150 + 151 + pmic->dcdc_range[id] = range; 152 + return range; 165 153 } 166 154 167 155 static unsigned long tps65912_vsel_to_uv_range0(u8 vsel) ··· 201 219 202 220 static int tps65912_get_ctrl_register(int id) 203 221 { 204 - switch (id) { 205 - case TPS65912_REG_DCDC1: 206 - return TPS65912_DCDC1_AVS; 207 - case TPS65912_REG_DCDC2: 208 - return TPS65912_DCDC2_AVS; 209 - case TPS65912_REG_DCDC3: 210 - return TPS65912_DCDC3_AVS; 211 - case TPS65912_REG_DCDC4: 212 - return TPS65912_DCDC4_AVS; 213 - case TPS65912_REG_LDO1: 214 - return TPS65912_LDO1_AVS; 215 - case TPS65912_REG_LDO2: 216 - return TPS65912_LDO2_AVS; 217 - case TPS65912_REG_LDO3: 218 - return TPS65912_LDO3_AVS; 219 - case TPS65912_REG_LDO4: 220 - return TPS65912_LDO4_AVS; 221 - case TPS65912_REG_LDO5: 222 - return TPS65912_LDO5; 223 - case TPS65912_REG_LDO6: 224 - return TPS65912_LDO6; 225 - case TPS65912_REG_LDO7: 226 - return TPS65912_LDO7; 227 - case TPS65912_REG_LDO8: 228 - return TPS65912_LDO8; 229 - case TPS65912_REG_LDO9: 230 - return TPS65912_LDO9; 231 - case TPS65912_REG_LDO10: 232 - return TPS65912_LDO10; 233 - default: 222 + if (id >= TPS65912_REG_DCDC1 && id <= TPS65912_REG_LDO4) 223 + return id * 3 + TPS65912_DCDC1_AVS; 224 + else if (id >= TPS65912_REG_LDO5 && id <= TPS65912_REG_LDO10) 225 + return id - TPS65912_REG_LDO5 + TPS65912_LDO5; 226 + else 234 227 return -EINVAL; 235 - } 236 228 } 237 229 238 - static int tps65912_get_dcdc_sel_register(struct tps65912_reg *pmic, int id) 230 + static int tps65912_get_sel_register(struct tps65912_reg *pmic, int id) 239 231 { 240 232 struct tps65912 *mfd = pmic->mfd; 241 - int opvsel = 0, sr = 0; 233 + int opvsel; 242 234 u8 reg = 0; 243 235 244 - if (id < TPS65912_REG_DCDC1 || id > TPS65912_REG_DCDC4) 236 + if (id >= TPS65912_REG_DCDC1 && id <= TPS65912_REG_LDO4) { 237 + opvsel = tps65912_reg_read(mfd, id * 3 + TPS65912_DCDC1_OP); 238 + if (opvsel & OP_SELREG_MASK) 239 + reg = id * 3 + TPS65912_DCDC1_AVS; 240 + else 241 + reg = id * 3 + TPS65912_DCDC1_OP; 242 + } else if (id >= TPS65912_REG_LDO5 && id <= TPS65912_REG_LDO10) { 243 + reg = id - TPS65912_REG_LDO5 + TPS65912_LDO5; 244 + } else { 245 245 return -EINVAL; 246 - 247 - switch (id) { 248 - case TPS65912_REG_DCDC1: 249 - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC1_OP); 250 - sr = ((opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT); 251 - if (sr) 252 - reg = TPS65912_DCDC1_AVS; 253 - else 254 - reg = TPS65912_DCDC1_OP; 255 - break; 256 - case TPS65912_REG_DCDC2: 257 - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC2_OP); 258 - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; 259 - if (sr) 260 - reg = TPS65912_DCDC2_AVS; 261 - else 262 - reg = TPS65912_DCDC2_OP; 263 - break; 264 - case TPS65912_REG_DCDC3: 265 - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC3_OP); 266 - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; 267 - if (sr) 268 - reg = TPS65912_DCDC3_AVS; 269 - else 270 - reg = TPS65912_DCDC3_OP; 271 - break; 272 - case TPS65912_REG_DCDC4: 273 - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC4_OP); 274 - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; 275 - if (sr) 276 - reg = TPS65912_DCDC4_AVS; 277 - else 278 - reg = TPS65912_DCDC4_OP; 279 - break; 280 - } 281 - return reg; 282 - } 283 - 284 - static int tps65912_get_ldo_sel_register(struct tps65912_reg *pmic, int id) 285 - { 286 - struct tps65912 *mfd = pmic->mfd; 287 - int opvsel = 0, sr = 0; 288 - u8 reg = 0; 289 - 290 - if (id < TPS65912_REG_LDO1 || id > TPS65912_REG_LDO10) 291 - return -EINVAL; 292 - 293 - switch (id) { 294 - case TPS65912_REG_LDO1: 295 - opvsel = tps65912_reg_read(mfd, TPS65912_LDO1_OP); 296 - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; 297 - if (sr) 298 - reg = TPS65912_LDO1_AVS; 299 - else 300 - reg = TPS65912_LDO1_OP; 301 - break; 302 - case TPS65912_REG_LDO2: 303 - opvsel = tps65912_reg_read(mfd, TPS65912_LDO2_OP); 304 - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; 305 - if (sr) 306 - reg = TPS65912_LDO2_AVS; 307 - else 308 - reg = TPS65912_LDO2_OP; 309 - break; 310 - case TPS65912_REG_LDO3: 311 - opvsel = tps65912_reg_read(mfd, TPS65912_LDO3_OP); 312 - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; 313 - if (sr) 314 - reg = TPS65912_LDO3_AVS; 315 - else 316 - reg = TPS65912_LDO3_OP; 317 - break; 318 - case TPS65912_REG_LDO4: 319 - opvsel = tps65912_reg_read(mfd, TPS65912_LDO4_OP); 320 - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; 321 - if (sr) 322 - reg = TPS65912_LDO4_AVS; 323 - else 324 - reg = TPS65912_LDO4_OP; 325 - break; 326 - case TPS65912_REG_LDO5: 327 - reg = TPS65912_LDO5; 328 - break; 329 - case TPS65912_REG_LDO6: 330 - reg = TPS65912_LDO6; 331 - break; 332 - case TPS65912_REG_LDO7: 333 - reg = TPS65912_LDO7; 334 - break; 335 - case TPS65912_REG_LDO8: 336 - reg = TPS65912_LDO8; 337 - break; 338 - case TPS65912_REG_LDO9: 339 - reg = TPS65912_LDO9; 340 - break; 341 - case TPS65912_REG_LDO10: 342 - reg = TPS65912_LDO10; 343 - break; 344 246 } 345 247 346 248 return reg; ··· 372 506 return mode; 373 507 } 374 508 375 - static int tps65912_get_voltage_dcdc(struct regulator_dev *dev) 376 - { 377 - struct tps65912_reg *pmic = rdev_get_drvdata(dev); 378 - struct tps65912 *mfd = pmic->mfd; 379 - int id = rdev_get_id(dev), voltage = 0, range; 380 - int opvsel = 0, avsel = 0, sr, vsel; 381 - 382 - switch (id) { 383 - case TPS65912_REG_DCDC1: 384 - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC1_OP); 385 - avsel = tps65912_reg_read(mfd, TPS65912_DCDC1_AVS); 386 - range = pmic->dcdc1_range; 387 - break; 388 - case TPS65912_REG_DCDC2: 389 - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC2_OP); 390 - avsel = tps65912_reg_read(mfd, TPS65912_DCDC2_AVS); 391 - range = pmic->dcdc2_range; 392 - break; 393 - case TPS65912_REG_DCDC3: 394 - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC3_OP); 395 - avsel = tps65912_reg_read(mfd, TPS65912_DCDC3_AVS); 396 - range = pmic->dcdc3_range; 397 - break; 398 - case TPS65912_REG_DCDC4: 399 - opvsel = tps65912_reg_read(mfd, TPS65912_DCDC4_OP); 400 - avsel = tps65912_reg_read(mfd, TPS65912_DCDC4_AVS); 401 - range = pmic->dcdc4_range; 402 - break; 403 - default: 404 - return -EINVAL; 405 - } 406 - 407 - sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT; 408 - if (sr) 409 - vsel = avsel; 410 - else 411 - vsel = opvsel; 412 - vsel &= 0x3F; 413 - 414 - switch (range) { 415 - case 0: 416 - /* 0.5 - 1.2875V in 12.5mV steps */ 417 - voltage = tps65912_vsel_to_uv_range0(vsel); 418 - break; 419 - case 1: 420 - /* 0.7 - 1.4875V in 12.5mV steps */ 421 - voltage = tps65912_vsel_to_uv_range1(vsel); 422 - break; 423 - case 2: 424 - /* 0.5 - 2.075V in 25mV steps */ 425 - voltage = tps65912_vsel_to_uv_range2(vsel); 426 - break; 427 - case 3: 428 - /* 0.5 - 3.8V in 50mV steps */ 429 - voltage = tps65912_vsel_to_uv_range3(vsel); 430 - break; 431 - } 432 - return voltage; 433 - } 434 - 435 - static int tps65912_set_voltage_dcdc(struct regulator_dev *dev, 436 - unsigned selector) 437 - { 438 - struct tps65912_reg *pmic = rdev_get_drvdata(dev); 439 - struct tps65912 *mfd = pmic->mfd; 440 - int id = rdev_get_id(dev); 441 - int value; 442 - u8 reg; 443 - 444 - reg = tps65912_get_dcdc_sel_register(pmic, id); 445 - value = tps65912_reg_read(mfd, reg); 446 - value &= 0xC0; 447 - return tps65912_reg_write(mfd, reg, selector | value); 448 - } 449 - 450 - static int tps65912_get_voltage_ldo(struct regulator_dev *dev) 451 - { 452 - struct tps65912_reg *pmic = rdev_get_drvdata(dev); 453 - struct tps65912 *mfd = pmic->mfd; 454 - int id = rdev_get_id(dev); 455 - int vsel = 0; 456 - u8 reg; 457 - 458 - reg = tps65912_get_ldo_sel_register(pmic, id); 459 - vsel = tps65912_reg_read(mfd, reg); 460 - vsel &= 0x3F; 461 - 462 - return tps65912_vsel_to_uv_ldo(vsel); 463 - } 464 - 465 - static int tps65912_set_voltage_ldo(struct regulator_dev *dev, 466 - unsigned selector) 467 - { 468 - struct tps65912_reg *pmic = rdev_get_drvdata(dev); 469 - struct tps65912 *mfd = pmic->mfd; 470 - int id = rdev_get_id(dev), reg, value; 471 - 472 - reg = tps65912_get_ldo_sel_register(pmic, id); 473 - value = tps65912_reg_read(mfd, reg); 474 - value &= 0xC0; 475 - return tps65912_reg_write(mfd, reg, selector | value); 476 - } 477 - 478 509 static int tps65912_list_voltage_dcdc(struct regulator_dev *dev, 479 510 unsigned selector) 480 511 { 481 512 struct tps65912_reg *pmic = rdev_get_drvdata(dev); 482 513 int range, voltage = 0, id = rdev_get_id(dev); 483 514 484 - switch (id) { 485 - case TPS65912_REG_DCDC1: 486 - range = pmic->dcdc1_range; 487 - break; 488 - case TPS65912_REG_DCDC2: 489 - range = pmic->dcdc2_range; 490 - break; 491 - case TPS65912_REG_DCDC3: 492 - range = pmic->dcdc3_range; 493 - break; 494 - case TPS65912_REG_DCDC4: 495 - range = pmic->dcdc4_range; 496 - break; 497 - default: 515 + if (id > TPS65912_REG_DCDC4) 498 516 return -EINVAL; 499 - } 517 + 518 + range = pmic->dcdc_range[id]; 500 519 501 520 switch (range) { 502 521 case 0: ··· 404 653 return voltage; 405 654 } 406 655 656 + static int tps65912_get_voltage_dcdc(struct regulator_dev *dev) 657 + { 658 + struct tps65912_reg *pmic = rdev_get_drvdata(dev); 659 + struct tps65912 *mfd = pmic->mfd; 660 + int id = rdev_get_id(dev); 661 + int reg, vsel; 662 + 663 + reg = tps65912_get_sel_register(pmic, id); 664 + if (reg < 0) 665 + return reg; 666 + 667 + vsel = tps65912_reg_read(mfd, reg); 668 + vsel &= 0x3F; 669 + 670 + return tps65912_list_voltage_dcdc(dev, vsel); 671 + } 672 + 673 + static int tps65912_set_voltage_sel(struct regulator_dev *dev, 674 + unsigned selector) 675 + { 676 + struct tps65912_reg *pmic = rdev_get_drvdata(dev); 677 + struct tps65912 *mfd = pmic->mfd; 678 + int id = rdev_get_id(dev); 679 + int value; 680 + u8 reg; 681 + 682 + reg = tps65912_get_sel_register(pmic, id); 683 + value = tps65912_reg_read(mfd, reg); 684 + value &= 0xC0; 685 + return tps65912_reg_write(mfd, reg, selector | value); 686 + } 687 + 688 + static int tps65912_get_voltage_ldo(struct regulator_dev *dev) 689 + { 690 + struct tps65912_reg *pmic = rdev_get_drvdata(dev); 691 + struct tps65912 *mfd = pmic->mfd; 692 + int id = rdev_get_id(dev); 693 + int vsel = 0; 694 + u8 reg; 695 + 696 + reg = tps65912_get_sel_register(pmic, id); 697 + vsel = tps65912_reg_read(mfd, reg); 698 + vsel &= 0x3F; 699 + 700 + return tps65912_vsel_to_uv_ldo(vsel); 701 + } 702 + 407 703 static int tps65912_list_voltage_ldo(struct regulator_dev *dev, 408 704 unsigned selector) 409 705 { ··· 470 672 .set_mode = tps65912_set_mode, 471 673 .get_mode = tps65912_get_mode, 472 674 .get_voltage = tps65912_get_voltage_dcdc, 473 - .set_voltage_sel = tps65912_set_voltage_dcdc, 675 + .set_voltage_sel = tps65912_set_voltage_sel, 474 676 .list_voltage = tps65912_list_voltage_dcdc, 475 677 }; 476 678 ··· 480 682 .enable = tps65912_reg_enable, 481 683 .disable = tps65912_reg_disable, 482 684 .get_voltage = tps65912_get_voltage_ldo, 483 - .set_voltage_sel = tps65912_set_voltage_ldo, 685 + .set_voltage_sel = tps65912_set_voltage_sel, 484 686 .list_voltage = tps65912_list_voltage_ldo, 485 687 }; 486 688 ··· 568 770 .remove = __devexit_p(tps65912_remove), 569 771 }; 570 772 571 - /** 572 - * tps65912_init 573 - * 574 - * Module init function 575 - */ 576 773 static int __init tps65912_init(void) 577 774 { 578 775 return platform_driver_register(&tps65912_driver); 579 776 } 580 777 subsys_initcall(tps65912_init); 581 778 582 - /** 583 - * tps65912_cleanup 584 - * 585 - * Module exit function 586 - */ 587 779 static void __exit tps65912_cleanup(void) 588 780 { 589 781 platform_driver_unregister(&tps65912_driver);
+245 -80
drivers/regulator/twl-regulator.c
··· 14 14 #include <linux/err.h> 15 15 #include <linux/delay.h> 16 16 #include <linux/platform_device.h> 17 + #include <linux/of.h> 18 + #include <linux/of_device.h> 17 19 #include <linux/regulator/driver.h> 18 20 #include <linux/regulator/machine.h> 21 + #include <linux/regulator/of_regulator.h> 19 22 #include <linux/i2c/twl.h> 20 23 21 24 ··· 61 58 62 59 /* chip specific features */ 63 60 unsigned long features; 61 + 62 + /* 63 + * optional override functions for voltage set/get 64 + * these are currently only used for SMPS regulators 65 + */ 66 + int (*get_voltage)(void *data); 67 + int (*set_voltage)(void *data, int target_uV); 68 + 69 + /* data passed from board for external get/set voltage */ 70 + void *data; 64 71 }; 65 72 66 73 ··· 535 522 struct twlreg_info *info = rdev_get_drvdata(rdev); 536 523 int vsel = DIV_ROUND_UP(min_uV - 600000, 12500); 537 524 538 - twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS_4030, 539 - vsel); 525 + if (info->set_voltage) { 526 + return info->set_voltage(info->data, min_uV); 527 + } else { 528 + twlreg_write(info, TWL_MODULE_PM_RECEIVER, 529 + VREG_VOLTAGE_SMPS_4030, vsel); 530 + } 531 + 540 532 return 0; 541 533 } 542 534 543 535 static int twl4030smps_get_voltage(struct regulator_dev *rdev) 544 536 { 545 537 struct twlreg_info *info = rdev_get_drvdata(rdev); 546 - int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, 538 + int vsel; 539 + 540 + if (info->get_voltage) 541 + return info->get_voltage(info->data); 542 + 543 + vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, 547 544 VREG_VOLTAGE_SMPS_4030); 548 545 549 546 return vsel * 12500 + 600000; ··· 562 539 static struct regulator_ops twl4030smps_ops = { 563 540 .set_voltage = twl4030smps_set_voltage, 564 541 .get_voltage = twl4030smps_get_voltage, 542 + }; 543 + 544 + static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV, 545 + int max_uV, unsigned *selector) 546 + { 547 + struct twlreg_info *info = rdev_get_drvdata(rdev); 548 + 549 + if (info->set_voltage) 550 + return info->set_voltage(info->data, min_uV); 551 + 552 + return -ENODEV; 553 + } 554 + 555 + static int twl6030coresmps_get_voltage(struct regulator_dev *rdev) 556 + { 557 + struct twlreg_info *info = rdev_get_drvdata(rdev); 558 + 559 + if (info->get_voltage) 560 + return info->get_voltage(info->data); 561 + 562 + return -ENODEV; 563 + } 564 + 565 + static struct regulator_ops twl6030coresmps_ops = { 566 + .set_voltage = twl6030coresmps_set_voltage, 567 + .get_voltage = twl6030coresmps_get_voltage, 565 568 }; 566 569 567 570 static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) ··· 804 755 case 0: 805 756 if (min_uV == 0) 806 757 vsel = 0; 807 - else if ((min_uV >= 600000) && (max_uV <= 1300000)) { 758 + else if ((min_uV >= 600000) && (min_uV <= 1300000)) { 759 + int calc_uV; 808 760 vsel = (min_uV - 600000) / 125; 809 761 if (vsel % 100) 810 762 vsel += 100; 811 763 vsel /= 100; 812 764 vsel++; 765 + calc_uV = twl6030smps_list_voltage(rdev, vsel); 766 + if (calc_uV > max_uV) 767 + return -EINVAL; 813 768 } 814 769 /* Values 1..57 for vsel are linear and can be calculated 815 770 * values 58..62 are non linear. ··· 834 781 case SMPS_OFFSET_EN: 835 782 if (min_uV == 0) 836 783 vsel = 0; 837 - else if ((min_uV >= 700000) && (max_uV <= 1420000)) { 784 + else if ((min_uV >= 700000) && (min_uV <= 1420000)) { 785 + int calc_uV; 838 786 vsel = (min_uV - 700000) / 125; 839 787 if (vsel % 100) 840 788 vsel += 100; 841 789 vsel /= 100; 842 790 vsel++; 791 + calc_uV = twl6030smps_list_voltage(rdev, vsel); 792 + if (calc_uV > max_uV) 793 + return -EINVAL; 843 794 } 844 795 /* Values 1..57 for vsel are linear and can be calculated 845 796 * values 58..62 are non linear. ··· 876 819 if (min_uV == 0) 877 820 vsel = 0; 878 821 else if ((min_uV >= 2161000) && (max_uV <= 4321000)) { 879 - vsel = (min_uV - 1852000) / 386; 822 + vsel = (min_uV - 2161000) / 386; 880 823 if (vsel % 100) 881 824 vsel += 100; 882 825 vsel /= 100; ··· 923 866 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \ 924 867 0x0, TWL6030, twl6030fixed_ops) 925 868 926 - #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) { \ 869 + #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ 870 + static struct twlreg_info TWL4030_INFO_##label = { \ 927 871 .base = offset, \ 928 872 .id = num, \ 929 873 .table_len = ARRAY_SIZE(label##_VSEL_table), \ ··· 942 884 } 943 885 944 886 #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \ 945 - { \ 887 + static struct twlreg_info TWL4030_INFO_##label = { \ 946 888 .base = offset, \ 947 889 .id = num, \ 948 890 .delay = turnon_delay, \ ··· 956 898 }, \ 957 899 } 958 900 959 - #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \ 901 + #define TWL6030_ADJUSTABLE_SMPS(label) \ 902 + static struct twlreg_info TWL6030_INFO_##label = { \ 903 + .desc = { \ 904 + .name = #label, \ 905 + .id = TWL6030_REG_##label, \ 906 + .ops = &twl6030coresmps_ops, \ 907 + .type = REGULATOR_VOLTAGE, \ 908 + .owner = THIS_MODULE, \ 909 + }, \ 910 + } 911 + 912 + #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 913 + static struct twlreg_info TWL6030_INFO_##label = { \ 960 914 .base = offset, \ 961 915 .min_mV = min_mVolts, \ 962 916 .max_mV = max_mVolts, \ ··· 982 912 }, \ 983 913 } 984 914 985 - #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \ 915 + #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 916 + static struct twlreg_info TWL6025_INFO_##label = { \ 986 917 .base = offset, \ 987 918 .min_mV = min_mVolts, \ 988 919 .max_mV = max_mVolts, \ ··· 998 927 } 999 928 1000 929 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ 1001 - family, operations) { \ 930 + family, operations) \ 931 + static struct twlreg_info TWLFIXED_INFO_##label = { \ 1002 932 .base = offset, \ 1003 933 .id = num, \ 1004 934 .min_mV = mVolts, \ ··· 1015 943 }, \ 1016 944 } 1017 945 1018 - #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) { \ 946 + #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \ 947 + static struct twlreg_info TWLRES_INFO_##label = { \ 1019 948 .base = offset, \ 1020 949 .delay = turnon_delay, \ 1021 950 .desc = { \ ··· 1028 955 }, \ 1029 956 } 1030 957 1031 - #define TWL6025_ADJUSTABLE_SMPS(label, offset) { \ 958 + #define TWL6025_ADJUSTABLE_SMPS(label, offset) \ 959 + static struct twlreg_info TWLSMPS_INFO_##label = { \ 1032 960 .base = offset, \ 1033 961 .min_mV = 600, \ 1034 962 .max_mV = 2100, \ ··· 1047 973 * We list regulators here if systems need some level of 1048 974 * software control over them after boot. 1049 975 */ 1050 - static struct twlreg_info twl_regs[] = { 1051 - TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08), 1052 - TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08), 1053 - TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08), 1054 - TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08), 1055 - TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08), 1056 - TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08), 1057 - TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08), 1058 - TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00), 1059 - TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08), 1060 - TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00), 1061 - TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08), 1062 - TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08), 1063 - TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08), 1064 - TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08), 1065 - TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08), 1066 - TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08), 1067 - TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08), 1068 - TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08), 1069 - TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08), 1070 - TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08), 1071 - /* VUSBCP is managed *only* by the USB subchip */ 1072 - 1073 - /* 6030 REG with base as PMC Slave Misc : 0x0030 */ 1074 - /* Turnon-delay and remap configuration values for 6030 are not 1075 - verified since the specification is not public */ 1076 - TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300), 1077 - TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300), 1078 - TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300), 1079 - TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300), 1080 - TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300), 1081 - TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300), 1082 - TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0), 1083 - TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0), 1084 - TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0), 1085 - TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0), 1086 - TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0), 1087 - 1088 - /* 6025 are renamed compared to 6030 versions */ 1089 - TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300), 1090 - TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300), 1091 - TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300), 1092 - TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300), 1093 - TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300), 1094 - TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300), 1095 - TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300), 1096 - TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300), 1097 - TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300), 1098 - 1099 - TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34), 1100 - TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10), 1101 - TWL6025_ADJUSTABLE_SMPS(VIO, 0x16), 1102 - }; 976 + TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08); 977 + TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08); 978 + TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08); 979 + TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08); 980 + TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08); 981 + TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08); 982 + TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08); 983 + TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00); 984 + TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08); 985 + TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00); 986 + TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08); 987 + TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08); 988 + TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08); 989 + TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08); 990 + TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08); 991 + /* VUSBCP is managed *only* by the USB subchip */ 992 + /* 6030 REG with base as PMC Slave Misc : 0x0030 */ 993 + /* Turnon-delay and remap configuration values for 6030 are not 994 + verified since the specification is not public */ 995 + TWL6030_ADJUSTABLE_SMPS(VDD1); 996 + TWL6030_ADJUSTABLE_SMPS(VDD2); 997 + TWL6030_ADJUSTABLE_SMPS(VDD3); 998 + TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300); 999 + TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300); 1000 + TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300); 1001 + TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300); 1002 + TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300); 1003 + TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300); 1004 + /* 6025 are renamed compared to 6030 versions */ 1005 + TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300); 1006 + TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300); 1007 + TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300); 1008 + TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300); 1009 + TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300); 1010 + TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300); 1011 + TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300); 1012 + TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300); 1013 + TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300); 1014 + TWL4030_FIXED_LDO(VINTANA2, 0x3f, 1500, 11, 100, 0x08); 1015 + TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08); 1016 + TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08); 1017 + TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08); 1018 + TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08); 1019 + TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0); 1020 + TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0); 1021 + TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0); 1022 + TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0); 1023 + TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0); 1024 + TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0); 1025 + TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0); 1026 + TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34); 1027 + TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10); 1028 + TWL6025_ADJUSTABLE_SMPS(VIO, 0x16); 1103 1029 1104 1030 static u8 twl_get_smps_offset(void) 1105 1031 { ··· 1119 1045 return value; 1120 1046 } 1121 1047 1048 + #define TWL_OF_MATCH(comp, family, label) \ 1049 + { \ 1050 + .compatible = comp, \ 1051 + .data = &family##_INFO_##label, \ 1052 + } 1053 + 1054 + #define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label) 1055 + #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label) 1056 + #define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label) 1057 + #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label) 1058 + #define TWLRES_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLRES, label) 1059 + #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label) 1060 + 1061 + static const struct of_device_id twl_of_match[] __devinitconst = { 1062 + TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1), 1063 + TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030), 1064 + TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2), 1065 + TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3), 1066 + TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4), 1067 + TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1), 1068 + TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2), 1069 + TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1), 1070 + TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2), 1071 + TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM), 1072 + TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC), 1073 + TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2), 1074 + TWL4030_OF_MATCH("ti,twl4030-vio", VIO), 1075 + TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1), 1076 + TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2), 1077 + TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1), 1078 + TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2), 1079 + TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3), 1080 + TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030), 1081 + TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030), 1082 + TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030), 1083 + TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC), 1084 + TWL6030_OF_MATCH("ti,twl6030-vpp", VPP), 1085 + TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM), 1086 + TWL6025_OF_MATCH("ti,twl6025-ldo2", LDO2), 1087 + TWL6025_OF_MATCH("ti,twl6025-ldo4", LDO4), 1088 + TWL6025_OF_MATCH("ti,twl6025-ldo3", LDO3), 1089 + TWL6025_OF_MATCH("ti,twl6025-ldo5", LDO5), 1090 + TWL6025_OF_MATCH("ti,twl6025-ldo1", LDO1), 1091 + TWL6025_OF_MATCH("ti,twl6025-ldo7", LDO7), 1092 + TWL6025_OF_MATCH("ti,twl6025-ldo6", LDO6), 1093 + TWL6025_OF_MATCH("ti,twl6025-ldoln", LDOLN), 1094 + TWL6025_OF_MATCH("ti,twl6025-ldousb", LDOUSB), 1095 + TWLFIXED_OF_MATCH("ti,twl4030-vintana2", VINTANA2), 1096 + TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG), 1097 + TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5), 1098 + TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8), 1099 + TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1), 1100 + TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA), 1101 + TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO), 1102 + TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC), 1103 + TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB), 1104 + TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8), 1105 + TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1), 1106 + TWLRES_OF_MATCH("ti,twl6030-clk32kg", CLK32KG), 1107 + TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3), 1108 + TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4), 1109 + TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO), 1110 + {}, 1111 + }; 1112 + MODULE_DEVICE_TABLE(of, twl_of_match); 1113 + 1122 1114 static int __devinit twlreg_probe(struct platform_device *pdev) 1123 1115 { 1124 - int i; 1116 + int i, id; 1125 1117 struct twlreg_info *info; 1126 1118 struct regulator_init_data *initdata; 1127 1119 struct regulation_constraints *c; 1128 1120 struct regulator_dev *rdev; 1121 + struct twl_regulator_driver_data *drvdata; 1122 + const struct of_device_id *match; 1129 1123 1130 - for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) { 1131 - if (twl_regs[i].desc.id != pdev->id) 1132 - continue; 1133 - info = twl_regs + i; 1134 - break; 1124 + match = of_match_device(twl_of_match, &pdev->dev); 1125 + if (match) { 1126 + info = match->data; 1127 + id = info->desc.id; 1128 + initdata = of_get_regulator_init_data(&pdev->dev, 1129 + pdev->dev.of_node); 1130 + drvdata = NULL; 1131 + } else { 1132 + id = pdev->id; 1133 + initdata = pdev->dev.platform_data; 1134 + for (i = 0, info = NULL; i < ARRAY_SIZE(twl_of_match); i++) { 1135 + info = twl_of_match[i].data; 1136 + if (!info || info->desc.id != id) 1137 + continue; 1138 + break; 1139 + } 1140 + drvdata = initdata->driver_data; 1141 + if (!drvdata) 1142 + return -EINVAL; 1135 1143 } 1144 + 1136 1145 if (!info) 1137 1146 return -ENODEV; 1138 1147 1139 - initdata = pdev->dev.platform_data; 1140 1148 if (!initdata) 1141 1149 return -EINVAL; 1142 1150 1143 - /* copy the features into regulator data */ 1144 - info->features = (unsigned long)initdata->driver_data; 1151 + if (drvdata) { 1152 + /* copy the driver data into regulator data */ 1153 + info->features = drvdata->features; 1154 + info->data = drvdata->data; 1155 + info->set_voltage = drvdata->set_voltage; 1156 + info->get_voltage = drvdata->get_voltage; 1157 + } 1145 1158 1146 1159 /* Constrain board-specific capabilities according to what 1147 1160 * this driver and the chip itself can actually do. ··· 1238 1077 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE 1239 1078 | REGULATOR_CHANGE_MODE 1240 1079 | REGULATOR_CHANGE_STATUS; 1241 - switch (pdev->id) { 1080 + switch (id) { 1242 1081 case TWL4030_REG_VIO: 1243 1082 case TWL4030_REG_VDD1: 1244 1083 case TWL4030_REG_VDD2: ··· 1252 1091 break; 1253 1092 } 1254 1093 1255 - switch (pdev->id) { 1094 + switch (id) { 1256 1095 case TWL6025_REG_SMPS3: 1257 1096 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3) 1258 1097 info->flags |= SMPS_EXTENDED_EN; ··· 1273 1112 break; 1274 1113 } 1275 1114 1276 - rdev = regulator_register(&info->desc, &pdev->dev, initdata, info, NULL); 1115 + rdev = regulator_register(&info->desc, &pdev->dev, initdata, info, 1116 + pdev->dev.of_node); 1277 1117 if (IS_ERR(rdev)) { 1278 1118 dev_err(&pdev->dev, "can't register %s, %ld\n", 1279 1119 info->desc.name, PTR_ERR(rdev)); ··· 1311 1149 /* NOTE: short name, to work around driver model truncation of 1312 1150 * "twl_regulator.12" (and friends) to "twl_regulator.1". 1313 1151 */ 1314 - .driver.name = "twl_reg", 1315 - .driver.owner = THIS_MODULE, 1152 + .driver = { 1153 + .name = "twl_reg", 1154 + .owner = THIS_MODULE, 1155 + .of_match_table = of_match_ptr(twl_of_match), 1156 + }, 1316 1157 }; 1317 1158 1318 1159 static int __init twlreg_init(void)
+3 -3
drivers/regulator/wm8350-regulator.c
··· 186 186 return 0; 187 187 } 188 188 189 - return (isink_cur[val] + 50) / 100; 189 + return DIV_ROUND_CLOSEST(isink_cur[val], 100); 190 190 } 191 191 192 192 /* turn on ISINK followed by DCDC */ ··· 1544 1544 return -ENOMEM; 1545 1545 } 1546 1546 1547 - led->isink_consumer.dev = &pdev->dev; 1547 + led->isink_consumer.dev_name = dev_name(&pdev->dev); 1548 1548 led->isink_consumer.supply = "led_isink"; 1549 1549 led->isink_init.num_consumer_supplies = 1; 1550 1550 led->isink_init.consumer_supplies = &led->isink_consumer; ··· 1559 1559 return ret; 1560 1560 } 1561 1561 1562 - led->dcdc_consumer.dev = &pdev->dev; 1562 + led->dcdc_consumer.dev_name = dev_name(&pdev->dev); 1563 1563 led->dcdc_consumer.supply = "led_vcc"; 1564 1564 led->dcdc_init.num_consumer_supplies = 1; 1565 1565 led->dcdc_init.consumer_supplies = &led->dcdc_consumer;
+3 -3
drivers/regulator/wm8400-regulator.c
··· 78 78 79 79 if (min_uV < 1700000) { 80 80 /* Steps of 50mV from 900mV; */ 81 - val = (min_uV - 850001) / 50000; 81 + val = DIV_ROUND_UP(min_uV - 900000, 50000); 82 82 83 83 if ((val * 50000) + 900000 > max_uV) 84 84 return -EINVAL; 85 85 BUG_ON((val * 50000) + 900000 < min_uV); 86 86 } else { 87 87 /* Steps of 100mV from 1700mV */ 88 - val = ((min_uV - 1600001) / 100000); 88 + val = DIV_ROUND_UP(min_uV - 1700000, 100000); 89 89 90 90 if ((val * 100000) + 1700000 > max_uV) 91 91 return -EINVAL; ··· 168 168 if (min_uV < 850000) 169 169 return -EINVAL; 170 170 171 - val = (min_uV - 825001) / 25000; 171 + val = DIV_ROUND_UP(min_uV - 850000, 25000); 172 172 173 173 if (850000 + (25000 * val) > max_uV) 174 174 return -EINVAL;
+1 -3
drivers/regulator/wm8994-regulator.c
··· 241 241 if (!pdata) 242 242 return -ENODEV; 243 243 244 - ldo = kzalloc(sizeof(struct wm8994_ldo), GFP_KERNEL); 244 + ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_ldo), GFP_KERNEL); 245 245 if (ldo == NULL) { 246 246 dev_err(&pdev->dev, "Unable to allocate private data\n"); 247 247 return -ENOMEM; ··· 285 285 if (gpio_is_valid(ldo->enable)) 286 286 gpio_free(ldo->enable); 287 287 err: 288 - kfree(ldo); 289 288 return ret; 290 289 } 291 290 ··· 297 298 regulator_unregister(ldo->regulator); 298 299 if (gpio_is_valid(ldo->enable)) 299 300 gpio_free(ldo->enable); 300 - kfree(ldo); 301 301 302 302 return 0; 303 303 }
+12 -2
include/linux/i2c/twl.h
··· 712 712 struct regulator_init_data *vaux1; 713 713 struct regulator_init_data *vaux2; 714 714 struct regulator_init_data *vaux3; 715 + struct regulator_init_data *vdd1; 716 + struct regulator_init_data *vdd2; 717 + struct regulator_init_data *vdd3; 715 718 /* TWL4030 LDO regulators */ 716 719 struct regulator_init_data *vpll1; 717 720 struct regulator_init_data *vpll2; ··· 723 720 struct regulator_init_data *vsim; 724 721 struct regulator_init_data *vaux4; 725 722 struct regulator_init_data *vio; 726 - struct regulator_init_data *vdd1; 727 - struct regulator_init_data *vdd2; 728 723 struct regulator_init_data *vintana1; 729 724 struct regulator_init_data *vintana2; 730 725 struct regulator_init_data *vintdig; ··· 734 733 struct regulator_init_data *vcxio; 735 734 struct regulator_init_data *vusb; 736 735 struct regulator_init_data *clk32kg; 736 + struct regulator_init_data *v1v8; 737 + struct regulator_init_data *v2v1; 737 738 /* TWL6025 LDO regulators */ 738 739 struct regulator_init_data *ldo1; 739 740 struct regulator_init_data *ldo2; ··· 750 747 struct regulator_init_data *smps3; 751 748 struct regulator_init_data *smps4; 752 749 struct regulator_init_data *vio6025; 750 + }; 751 + 752 + struct twl_regulator_driver_data { 753 + int (*set_voltage)(void *data, int target_uV); 754 + int (*get_voltage)(void *data); 755 + void *data; 756 + unsigned long features; 753 757 }; 754 758 755 759 /*----------------------------------------------------------------------*/
+7
include/linux/mfd/tps65910.h
··· 768 768 /* Max number of TPS65910/11 regulators */ 769 769 #define TPS65910_NUM_REGS 13 770 770 771 + /* External sleep controls through EN1/EN2/EN3/SLEEP inputs */ 772 + #define TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 0x1 773 + #define TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 0x2 774 + #define TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 0x4 775 + #define TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP 0x8 776 + 771 777 /** 772 778 * struct tps65910_board 773 779 * Board platform data may be used to initialize regulators. ··· 785 779 int irq_base; 786 780 int vmbch_threshold; 787 781 int vmbch2_threshold; 782 + unsigned long regulator_ext_sleep_control[TPS65910_NUM_REGS]; 788 783 struct regulator_init_data *tps65910_pmic_init_data[TPS65910_NUM_REGS]; 789 784 }; 790 785
+22
include/linux/regulator/consumer.h
··· 132 132 /* regulator get and put */ 133 133 struct regulator *__must_check regulator_get(struct device *dev, 134 134 const char *id); 135 + struct regulator *__must_check devm_regulator_get(struct device *dev, 136 + const char *id); 135 137 struct regulator *__must_check regulator_get_exclusive(struct device *dev, 136 138 const char *id); 137 139 void regulator_put(struct regulator *regulator); 140 + void devm_regulator_put(struct regulator *regulator); 138 141 139 142 /* regulator output control and status */ 140 143 int regulator_enable(struct regulator *regulator); ··· 148 145 149 146 int regulator_bulk_get(struct device *dev, int num_consumers, 150 147 struct regulator_bulk_data *consumers); 148 + int devm_regulator_bulk_get(struct device *dev, int num_consumers, 149 + struct regulator_bulk_data *consumers); 151 150 int regulator_bulk_enable(int num_consumers, 152 151 struct regulator_bulk_data *consumers); 153 152 int regulator_bulk_disable(int num_consumers, ··· 205 200 */ 206 201 return NULL; 207 202 } 203 + 204 + static inline struct regulator *__must_check 205 + devm_regulator_get(struct device *dev, const char *id) 206 + { 207 + return NULL; 208 + } 209 + 208 210 static inline void regulator_put(struct regulator *regulator) 211 + { 212 + } 213 + 214 + static inline void devm_regulator_put(struct regulator *regulator) 209 215 { 210 216 } 211 217 ··· 249 233 static inline int regulator_bulk_get(struct device *dev, 250 234 int num_consumers, 251 235 struct regulator_bulk_data *consumers) 236 + { 237 + return 0; 238 + } 239 + 240 + static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers, 241 + struct regulator_bulk_data *consumers) 252 242 { 253 243 return 0; 254 244 }
+2 -4
include/linux/regulator/driver.h
··· 104 104 int (*disable) (struct regulator_dev *); 105 105 int (*is_enabled) (struct regulator_dev *); 106 106 107 - /* get/set regulator operating mode (defined in regulator.h) */ 107 + /* get/set regulator operating mode (defined in consumer.h) */ 108 108 int (*set_mode) (struct regulator_dev *, unsigned int mode); 109 109 unsigned int (*get_mode) (struct regulator_dev *); 110 110 ··· 135 135 int (*set_suspend_enable) (struct regulator_dev *); 136 136 int (*set_suspend_disable) (struct regulator_dev *); 137 137 138 - /* set regulator suspend operating mode (defined in regulator.h) */ 138 + /* set regulator suspend operating mode (defined in consumer.h) */ 139 139 int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); 140 140 }; 141 141 ··· 207 207 208 208 void *reg_data; /* regulator_dev data */ 209 209 210 - #ifdef CONFIG_DEBUG_FS 211 210 struct dentry *debugfs; 212 - #endif 213 211 }; 214 212 215 213 struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
+13
include/linux/regulator/fixed.h
··· 48 48 struct regulator_init_data *init_data; 49 49 }; 50 50 51 + struct regulator_consumer_supply; 52 + 53 + #if IS_ENABLED(CONFIG_REGULATOR) 54 + struct platform_device *regulator_register_fixed(int id, 55 + struct regulator_consumer_supply *supplies, int num_supplies); 56 + #else 57 + static inline struct platform_device *regulator_register_fixed(int id, 58 + struct regulator_consumer_supply *supplies, int num_supplies) 59 + { 60 + return NULL; 61 + } 62 + #endif 63 + 51 64 #endif
-2
include/linux/regulator/machine.h
··· 139 139 * make struct device available late such as I2C and is the preferred 140 140 * form. 141 141 * 142 - * @dev: Device structure for the consumer. 143 142 * @dev_name: Result of dev_name() for the consumer. 144 143 * @supply: Name for the supply. 145 144 */ 146 145 struct regulator_consumer_supply { 147 - struct device *dev; /* consumer */ 148 146 const char *dev_name; /* dev_name() for consumer */ 149 147 const char *supply; /* consumer supply - e.g. "vcc" */ 150 148 };
+57
include/linux/regulator/tps62360.h
··· 1 + /* 2 + * tps62360.h -- TI tps62360 3 + * 4 + * Interface for regulator driver for TI TPS62360 Processor core supply 5 + * 6 + * Copyright (C) 2012 NVIDIA Corporation 7 + 8 + * Author: Laxman Dewangan <ldewangan@nvidia.com> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + * 15 + * This program is distributed in the hope that it will be useful, but WITHOUT 16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 18 + * more details. 19 + * 20 + * You should have received a copy of the GNU General Public License along 21 + * with this program; if not, write to the Free Software Foundation, Inc., 22 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 23 + * 24 + */ 25 + 26 + #ifndef __LINUX_REGULATOR_TPS62360_H 27 + #define __LINUX_REGULATOR_TPS62360_H 28 + 29 + #include <linux/regulator/machine.h> 30 + 31 + /* 32 + * struct tps62360_regulator_platform_data - tps62360 regulator platform data. 33 + * 34 + * @reg_init_data: The regulator init data. 35 + * @en_force_pwm: Enable force pwm or not. 36 + * @en_discharge: Enable discharge the output capacitor via internal 37 + * register. 38 + * @en_internal_pulldn: internal pull down enable or not. 39 + * @vsel0_gpio: Gpio number for vsel0. It should be -1 if this is tied with 40 + * fixed logic. 41 + * @vsel1_gpio: Gpio number for vsel1. It should be -1 if this is tied with 42 + * fixed logic. 43 + * @vsel0_def_state: Default state of vsel0. 1 if it is high else 0. 44 + * @vsel1_def_state: Default state of vsel1. 1 if it is high else 0. 45 + */ 46 + struct tps62360_regulator_platform_data { 47 + struct regulator_init_data reg_init_data; 48 + bool en_force_pwm; 49 + bool en_discharge; 50 + bool en_internal_pulldn; 51 + int vsel0_gpio; 52 + int vsel1_gpio; 53 + int vsel0_def_state; 54 + int vsel1_def_state; 55 + }; 56 + 57 + #endif /* __LINUX_REGULATOR_TPS62360_H */