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

Merge remote-tracking branches 'regulator/topic/core', 'regulator/topic/bypass', 'regulator/topic/tol', 'regulator/topic/drivers' and 'regulator/topic/tps6586x' into regulator-next

+1417 -563
+21
Documentation/ABI/testing/sysfs-class-regulator
··· 349 349 350 350 This will be one of the same strings reported by 351 351 the "state" attribute. 352 + 353 + What: /sys/class/regulator/.../bypass 354 + Date: September 2012 355 + KernelVersion: 3.7 356 + Contact: Mark Brown <broonie@opensource.wolfsonmicro.com> 357 + Description: 358 + Some regulator directories will contain a field called 359 + bypass. This indicates if the device is in bypass mode. 360 + 361 + This will be one of the following strings: 362 + 363 + 'enabled' 364 + 'disabled' 365 + 'unknown' 366 + 367 + 'enabled' means the regulator is in bypass mode. 368 + 369 + 'disabled' means that the regulator is regulating. 370 + 371 + 'unknown' means software cannot determine the state, or 372 + the reported state is invalid.
+4 -1
Documentation/devicetree/bindings/regulator/regulator.txt
··· 11 11 - regulator-boot-on: bootloader/firmware enabled regulator 12 12 - <name>-supply: phandle to the parent supply/regulator node 13 13 - regulator-ramp-delay: ramp delay for regulator(in uV/uS) 14 + 15 + Deprecated properties: 14 16 - regulator-compatible: If a regulator chip contains multiple 15 17 regulators, and if the chip's binding contains a child node that 16 18 describes each regulator, then this property indicates which regulator 17 - this child node is intended to configure. 19 + this child node is intended to configure. If this property is missing, 20 + the node's name will be used instead. 18 21 19 22 Example: 20 23
+7 -24
Documentation/devicetree/bindings/regulator/tps65217.txt
··· 22 22 compatible = "ti,tps65217"; 23 23 24 24 regulators { 25 - #address-cells = <1>; 26 - #size-cells = <0>; 27 - 28 - dcdc1_reg: regulator@0 { 29 - reg = <0>; 30 - regulator-compatible = "dcdc1"; 25 + dcdc1_reg: dcdc1 { 31 26 regulator-min-microvolt = <900000>; 32 27 regulator-max-microvolt = <1800000>; 33 28 regulator-boot-on; 34 29 regulator-always-on; 35 30 }; 36 31 37 - dcdc2_reg: regulator@1 { 38 - reg = <1>; 39 - regulator-compatible = "dcdc2"; 32 + dcdc2_reg: dcdc2 { 40 33 regulator-min-microvolt = <900000>; 41 34 regulator-max-microvolt = <3300000>; 42 35 regulator-boot-on; 43 36 regulator-always-on; 44 37 }; 45 38 46 - dcdc3_reg: regulator@2 { 47 - reg = <2>; 48 - regulator-compatible = "dcdc3"; 39 + dcdc3_reg: dcc3 { 49 40 regulator-min-microvolt = <900000>; 50 41 regulator-max-microvolt = <1500000>; 51 42 regulator-boot-on; 52 43 regulator-always-on; 53 44 }; 54 45 55 - ldo1_reg: regulator@3 { 56 - reg = <3>; 57 - regulator-compatible = "ldo1"; 46 + ldo1_reg: ldo1 { 58 47 regulator-min-microvolt = <1000000>; 59 48 regulator-max-microvolt = <3300000>; 60 49 regulator-boot-on; 61 50 regulator-always-on; 62 51 }; 63 52 64 - ldo2_reg: regulator@4 { 65 - reg = <4>; 66 - regulator-compatible = "ldo2"; 53 + ldo2_reg: ldo2 { 67 54 regulator-min-microvolt = <900000>; 68 55 regulator-max-microvolt = <3300000>; 69 56 regulator-boot-on; 70 57 regulator-always-on; 71 58 }; 72 59 73 - ldo3_reg: regulator@5 { 74 - reg = <5>; 75 - regulator-compatible = "ldo3"; 60 + ldo3_reg: ldo3 { 76 61 regulator-min-microvolt = <1800000>; 77 62 regulator-max-microvolt = <3300000>; 78 63 regulator-boot-on; 79 64 regulator-always-on; 80 65 }; 81 66 82 - ldo4_reg: regulator@6 { 83 - reg = <6>; 84 - regulator-compatible = "ldo4"; 67 + ldo4_reg: ldo4 { 85 68 regulator-min-microvolt = <1800000>; 86 69 regulator-max-microvolt = <3300000>; 87 70 regulator-boot-on;
+29 -44
Documentation/devicetree/bindings/regulator/tps6586x.txt
··· 6 6 - interrupts: the interrupt outputs of the controller 7 7 - #gpio-cells: number of cells to describe a GPIO 8 8 - gpio-controller: mark the device as a GPIO controller 9 - - regulators: list of regulators provided by this controller, must have 10 - property "regulator-compatible" to match their hardware counterparts: 11 - sm[0-2], ldo[0-9] and ldo_rtc 9 + - regulators: A node that houses a sub-node for each regulator within the 10 + device. Each sub-node is identified using the node's name (or the deprecated 11 + regulator-compatible property if present), with valid values listed below. 12 + The content of each sub-node is defined by the standard binding for 13 + regulators; see regulator.txt. 14 + sys, sm[0-2], ldo[0-9] and ldo_rtc 15 + - sys-supply: The input supply for SYS. 12 16 - vin-sm0-supply: The input supply for the SM0. 13 17 - vin-sm1-supply: The input supply for the SM1. 14 18 - vin-sm2-supply: The input supply for the SM2. ··· 24 20 25 21 Each regulator is defined using the standard binding for regulators. 26 22 23 + Note: LDO5 and LDO_RTC is supplied by SYS regulator internally and driver 24 + take care of making proper parent child relationship. 25 + 27 26 Example: 28 27 29 28 pmu: tps6586x@34 { ··· 37 30 #gpio-cells = <2>; 38 31 gpio-controller; 39 32 33 + sys-supply = <&some_reg>; 40 34 vin-sm0-supply = <&some_reg>; 41 35 vin-sm1-supply = <&some_reg>; 42 36 vin-sm2-supply = <&some_reg>; ··· 48 40 vinldo9-supply = <...>; 49 41 50 42 regulators { 51 - #address-cells = <1>; 52 - #size-cells = <0>; 43 + sys_reg: sys { 44 + regulator-name = "vdd_sys"; 45 + regulator-boot-on; 46 + regulator-always-on; 47 + }; 53 48 54 - sm0_reg: regulator@0 { 55 - reg = <0>; 56 - regulator-compatible = "sm0"; 49 + sm0_reg: sm0 { 57 50 regulator-min-microvolt = < 725000>; 58 51 regulator-max-microvolt = <1500000>; 59 52 regulator-boot-on; 60 53 regulator-always-on; 61 54 }; 62 55 63 - sm1_reg: regulator@1 { 64 - reg = <1>; 65 - regulator-compatible = "sm1"; 56 + sm1_reg: sm1 { 66 57 regulator-min-microvolt = < 725000>; 67 58 regulator-max-microvolt = <1500000>; 68 59 regulator-boot-on; 69 60 regulator-always-on; 70 61 }; 71 62 72 - sm2_reg: regulator@2 { 73 - reg = <2>; 74 - regulator-compatible = "sm2"; 63 + sm2_reg: sm2 { 75 64 regulator-min-microvolt = <3000000>; 76 65 regulator-max-microvolt = <4550000>; 77 66 regulator-boot-on; 78 67 regulator-always-on; 79 68 }; 80 69 81 - ldo0_reg: regulator@3 { 82 - reg = <3>; 83 - regulator-compatible = "ldo0"; 70 + ldo0_reg: ldo0 { 84 71 regulator-name = "PCIE CLK"; 85 72 regulator-min-microvolt = <3300000>; 86 73 regulator-max-microvolt = <3300000>; 87 74 }; 88 75 89 - ldo1_reg: regulator@4 { 90 - reg = <4>; 91 - regulator-compatible = "ldo1"; 76 + ldo1_reg: ldo1 { 92 77 regulator-min-microvolt = < 725000>; 93 78 regulator-max-microvolt = <1500000>; 94 79 }; 95 80 96 - ldo2_reg: regulator@5 { 97 - reg = <5>; 98 - regulator-compatible = "ldo2"; 81 + ldo2_reg: ldo2 { 99 82 regulator-min-microvolt = < 725000>; 100 83 regulator-max-microvolt = <1500000>; 101 84 }; 102 85 103 - ldo3_reg: regulator@6 { 104 - reg = <6>; 105 - regulator-compatible = "ldo3"; 86 + ldo3_reg: ldo3 { 106 87 regulator-min-microvolt = <1250000>; 107 88 regulator-max-microvolt = <3300000>; 108 89 }; 109 90 110 - ldo4_reg: regulator@7 { 111 - reg = <7>; 112 - regulator-compatible = "ldo4"; 91 + ldo4_reg: ldo4 { 113 92 regulator-min-microvolt = <1700000>; 114 93 regulator-max-microvolt = <2475000>; 115 94 }; 116 95 117 - ldo5_reg: regulator@8 { 118 - reg = <8>; 119 - regulator-compatible = "ldo5"; 96 + ldo5_reg: ldo5 { 120 97 regulator-min-microvolt = <1250000>; 121 98 regulator-max-microvolt = <3300000>; 122 99 }; 123 100 124 - ldo6_reg: regulator@9 { 125 - reg = <9>; 126 - regulator-compatible = "ldo6"; 101 + ldo6_reg: ldo6 { 127 102 regulator-min-microvolt = <1250000>; 128 103 regulator-max-microvolt = <3300000>; 129 104 }; 130 105 131 - ldo7_reg: regulator@10 { 132 - reg = <10>; 133 - regulator-compatible = "ldo7"; 106 + ldo7_reg: ldo7 { 134 107 regulator-min-microvolt = <1250000>; 135 108 regulator-max-microvolt = <3300000>; 136 109 }; 137 110 138 - ldo8_reg: regulator@11 { 139 - reg = <11>; 140 - regulator-compatible = "ldo8"; 111 + ldo8_reg: ldo8 { 141 112 regulator-min-microvolt = <1250000>; 142 113 regulator-max-microvolt = <3300000>; 143 114 }; 144 115 145 - ldo9_reg: regulator@12 { 146 - reg = <12>; 147 - regulator-compatible = "ldo9"; 116 + ldo9_reg: ldo9 { 148 117 regulator-min-microvolt = <1250000>; 149 118 regulator-max-microvolt = <3300000>; 150 119 };
+10 -2
arch/arm/mach-tegra/board-harmony-power.c
··· 67 67 }, \ 68 68 } 69 69 70 + static struct regulator_init_data sys_data = { 71 + .supply_regulator = "vdd_5v0", 72 + .constraints = { 73 + .name = "vdd_sys", 74 + }, 75 + }; 76 + 70 77 HARMONY_REGULATOR_INIT(sm0, "vdd_sm0", "vdd_sys", 725, 1500, 1); 71 78 HARMONY_REGULATOR_INIT(sm1, "vdd_sm1", "vdd_sys", 725, 1500, 1); 72 79 HARMONY_REGULATOR_INIT(sm2, "vdd_sm2", "vdd_sys", 3000, 4550, 1); ··· 81 74 HARMONY_REGULATOR_INIT(ldo2, "vdd_ldo2", "vdd_sm2", 725, 1500, 0); 82 75 HARMONY_REGULATOR_INIT(ldo3, "vdd_ldo3", "vdd_sm2", 1250, 3300, 1); 83 76 HARMONY_REGULATOR_INIT(ldo4, "vdd_ldo4", "vdd_sm2", 1700, 2475, 1); 84 - HARMONY_REGULATOR_INIT(ldo5, "vdd_ldo5", NULL, 1250, 3300, 1); 77 + HARMONY_REGULATOR_INIT(ldo5, "vdd_ldo5", "vdd_sys", 1250, 3300, 1); 85 78 HARMONY_REGULATOR_INIT(ldo6, "vdd_ldo6", "vdd_sm2", 1250, 3300, 0); 86 79 HARMONY_REGULATOR_INIT(ldo7, "vdd_ldo7", "vdd_sm2", 1250, 3300, 0); 87 80 HARMONY_REGULATOR_INIT(ldo8, "vdd_ldo8", "vdd_sm2", 1250, 3300, 0); ··· 95 88 } 96 89 97 90 static struct tps6586x_subdev_info tps_devs[] = { 91 + TPS_REG(SYS, &sys_data), 98 92 TPS_REG(SM_0, &sm0_data), 99 93 TPS_REG(SM_1, &sm1_data), 100 94 TPS_REG(SM_2, &sm2_data), ··· 128 120 129 121 int __init harmony_regulator_init(void) 130 122 { 131 - regulator_register_always_on(0, "vdd_sys", 123 + regulator_register_always_on(0, "vdd_5v0", 132 124 NULL, 0, 5000000); 133 125 134 126 if (machine_is_harmony()) {
+5
drivers/extcon/extcon-arizona.c
··· 434 434 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE, 435 435 ARIZONA_JD1_ENA, ARIZONA_JD1_ENA); 436 436 437 + ret = regulator_allow_bypass(info->micvdd, true); 438 + if (ret != 0) 439 + dev_warn(arizona->dev, "Failed to set MICVDD to bypass: %d\n", 440 + ret); 441 + 437 442 pm_runtime_put(&pdev->dev); 438 443 439 444 return 0;
+13
drivers/mfd/tps6586x.c
··· 25 25 #include <linux/i2c.h> 26 26 #include <linux/regmap.h> 27 27 #include <linux/regulator/of_regulator.h> 28 + #include <linux/regulator/machine.h> 28 29 29 30 #include <linux/mfd/core.h> 30 31 #include <linux/mfd/tps6586x.h> ··· 347 346 348 347 #ifdef CONFIG_OF 349 348 static struct of_regulator_match tps6586x_matches[] = { 349 + { .name = "sys", .driver_data = (void *)TPS6586X_ID_SYS }, 350 350 { .name = "sm0", .driver_data = (void *)TPS6586X_ID_SM_0 }, 351 351 { .name = "sm1", .driver_data = (void *)TPS6586X_ID_SM_1 }, 352 352 { .name = "sm2", .driver_data = (void *)TPS6586X_ID_SM_2 }, ··· 371 369 struct tps6586x_platform_data *pdata; 372 370 struct tps6586x_subdev_info *devs; 373 371 struct device_node *regs; 372 + const char *sys_rail_name = NULL; 374 373 unsigned int count; 375 374 unsigned int i, j; 376 375 int err; ··· 394 391 return NULL; 395 392 396 393 for (i = 0, j = 0; i < num && j < count; i++) { 394 + struct regulator_init_data *reg_idata; 395 + 397 396 if (!tps6586x_matches[i].init_data) 398 397 continue; 399 398 399 + reg_idata = tps6586x_matches[i].init_data; 400 400 devs[j].name = "tps6586x-regulator"; 401 401 devs[j].platform_data = tps6586x_matches[i].init_data; 402 402 devs[j].id = (int)tps6586x_matches[i].driver_data; 403 + if (devs[j].id == TPS6586X_ID_SYS) 404 + sys_rail_name = reg_idata->constraints.name; 405 + 406 + if ((devs[j].id == TPS6586X_ID_LDO_5) || 407 + (devs[j].id == TPS6586X_ID_LDO_RTC)) 408 + reg_idata->supply_regulator = sys_rail_name; 409 + 403 410 devs[j].of_node = tps6586x_matches[i].of_node; 404 411 j++; 405 412 }
+28 -10
drivers/regulator/Kconfig
··· 33 33 help 34 34 If this option is enabled then when a regulator lookup fails 35 35 and the board has not specified that it has provided full 36 - constraints then the regulator core will provide an always 37 - enabled dummy regulator will be provided, allowing consumer 38 - drivers to continue. 36 + constraints the regulator core will provide an always 37 + enabled dummy regulator, allowing consumer drivers to continue. 39 38 40 39 A warning will be generated when this substitution is done. 41 40 ··· 49 50 tristate "Virtual regulator consumer support" 50 51 help 51 52 This driver provides a virtual consumer for the voltage and 52 - current regulator API which provides sysfs controls for 53 - configuring the supplies requested. This is mainly useful 54 - for test purposes. 53 + current regulator API which provides sysfs controls for 54 + configuring the supplies requested. This is mainly useful 55 + for test purposes. 55 56 56 - If unsure, say no. 57 + If unsure, say no. 57 58 58 59 config REGULATOR_USERSPACE_CONSUMER 59 60 tristate "Userspace regulator consumer support" ··· 62 63 from user space. Userspace consumer driver provides ability to 63 64 control power supplies for such devices. 64 65 65 - If unsure, say no. 66 + If unsure, say no. 66 67 67 68 config REGULATOR_GPIO 68 69 tristate "GPIO regulator support" ··· 108 109 help 109 110 This driver supports the voltage regulators of DA9052-BC and 110 111 DA9053-AA/Bx PMIC. 112 + 113 + config REGULATOR_FAN53555 114 + tristate "Fairchild FAN53555 Regulator" 115 + depends on I2C 116 + select REGMAP_I2C 117 + help 118 + This driver supports Fairchild FAN53555 Digitally Programmable 119 + TinyBuck Regulator. The FAN53555 is a step-down switching voltage 120 + regulator that delivers a digitally programmable output from an 121 + input voltage supply of 2.5V to 5.5V. The output voltage is 122 + programmed through an I2C interface. 111 123 112 124 config REGULATOR_ANATOP 113 125 tristate "Freescale i.MX on-chip ANATOP LDO regulators" ··· 181 171 help 182 172 This driver controls a Maxim 8660/8661 voltage output 183 173 regulator via I2C bus. 174 + 175 + config REGULATOR_MAX8907 176 + tristate "Maxim 8907 voltage regulator" 177 + depends on MFD_MAX8907 178 + help 179 + This driver controls a Maxim 8907 voltage output regulator 180 + via I2C bus. The provided regulator is suitable for Tegra 181 + chip to control Step-Down DC-DC and LDOs. 184 182 185 183 config REGULATOR_MAX8925 186 184 tristate "Maxim MAX8925 Power Management IC" ··· 265 247 266 248 config REGULATOR_PCF50633 267 249 tristate "NXP PCF50633 regulator driver" 268 - depends on MFD_PCF50633 250 + depends on MFD_PCF50633 269 251 help 270 252 Say Y here to support the voltage regulators and convertors 271 253 on PCF50633 ··· 434 416 depends on MFD_WM8350 435 417 help 436 418 This driver provides support for the voltage and current regulators 437 - of the WM8350 AudioPlus PMIC. 419 + of the WM8350 AudioPlus PMIC. 438 420 439 421 config REGULATOR_WM8400 440 422 tristate "Wolfson Microelectronics WM8400 AudioPlus PMIC"
+2
drivers/regulator/Makefile
··· 20 20 obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 21 21 obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o 22 22 obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o 23 + obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o 23 24 obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o 24 25 obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o 25 26 obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o ··· 31 30 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o 32 31 obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o 33 32 obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o 33 + obj-$(CONFIG_REGULATOR_MAX8907) += max8907-regulator.o 34 34 obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o 35 35 obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o 36 36 obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o
+1 -1
drivers/regulator/aat2870-regulator.c
··· 162 162 static int aat2870_regulator_probe(struct platform_device *pdev) 163 163 { 164 164 struct aat2870_regulator *ri; 165 - struct regulator_config config = { 0 }; 165 + struct regulator_config config = { }; 166 166 struct regulator_dev *rdev; 167 167 168 168 ri = aat2870_get_regulator(pdev->id);
-6
drivers/regulator/ab3100.c
··· 347 347 return abreg->plfdata->external_voltage; 348 348 } 349 349 350 - static int ab3100_get_fixed_voltage_regulator(struct regulator_dev *reg) 351 - { 352 - return reg->desc->min_uV; 353 - } 354 - 355 350 static struct regulator_ops regulator_ops_fixed = { 356 351 .list_voltage = regulator_list_voltage_linear, 357 352 .enable = ab3100_enable_regulator, 358 353 .disable = ab3100_disable_regulator, 359 354 .is_enabled = ab3100_is_enabled_regulator, 360 - .get_voltage = ab3100_get_fixed_voltage_regulator, 361 355 }; 362 356 363 357 static struct regulator_ops regulator_ops_variable = {
+11 -25
drivers/regulator/ab8500.c
··· 37 37 * @voltage_bank: bank to control regulator voltage 38 38 * @voltage_reg: register to control regulator voltage 39 39 * @voltage_mask: mask to control regulator voltage 40 + * @voltage_shift: shift to control regulator voltage 40 41 * @delay: startup/set voltage delay in us 41 42 */ 42 43 struct ab8500_regulator_info { ··· 51 50 u8 voltage_bank; 52 51 u8 voltage_reg; 53 52 u8 voltage_mask; 53 + u8 voltage_shift; 54 54 unsigned int delay; 55 55 }; 56 56 ··· 197 195 } 198 196 199 197 dev_vdbg(rdev_get_dev(rdev), 200 - "%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," 201 - " 0x%x\n", 202 - info->desc.name, info->voltage_bank, info->voltage_reg, 203 - info->voltage_mask, regval); 198 + "%s-get_voltage (bank, reg, mask, shift, value): " 199 + "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", 200 + info->desc.name, info->voltage_bank, 201 + info->voltage_reg, info->voltage_mask, 202 + info->voltage_shift, regval); 204 203 205 - /* vintcore has a different layout */ 206 204 val = regval & info->voltage_mask; 207 - if (info->desc.id == AB8500_LDO_INTCORE) 208 - return val >> 0x3; 209 - else 210 - return val; 205 + return val >> info->voltage_shift; 211 206 } 212 207 213 208 static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev, ··· 220 221 } 221 222 222 223 /* set the registers for the request */ 223 - regval = (u8)selector; 224 + regval = (u8)selector << info->voltage_shift; 224 225 ret = abx500_mask_and_set_register_interruptible(info->dev, 225 226 info->voltage_bank, info->voltage_reg, 226 227 info->voltage_mask, regval); ··· 235 236 info->voltage_mask, regval); 236 237 237 238 return ret; 238 - } 239 - 240 - static int ab8500_regulator_enable_time(struct regulator_dev *rdev) 241 - { 242 - struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 243 - 244 - return info->delay; 245 239 } 246 240 247 241 static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev, ··· 253 261 .get_voltage_sel = ab8500_regulator_get_voltage_sel, 254 262 .set_voltage_sel = ab8500_regulator_set_voltage_sel, 255 263 .list_voltage = regulator_list_voltage_table, 256 - .enable_time = ab8500_regulator_enable_time, 257 264 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, 258 265 }; 259 - 260 - static int ab8500_fixed_get_voltage(struct regulator_dev *rdev) 261 - { 262 - return rdev->desc->min_uV; 263 - } 264 266 265 267 static struct regulator_ops ab8500_regulator_fixed_ops = { 266 268 .enable = ab8500_regulator_enable, 267 269 .disable = ab8500_regulator_disable, 268 270 .is_enabled = ab8500_regulator_is_enabled, 269 - .get_voltage = ab8500_fixed_get_voltage, 270 271 .list_voltage = regulator_list_voltage_linear, 271 - .enable_time = ab8500_regulator_enable_time, 272 272 }; 273 273 274 274 static struct ab8500_regulator_info ··· 342 358 .voltage_bank = 0x03, 343 359 .voltage_reg = 0x80, 344 360 .voltage_mask = 0x38, 361 + .voltage_shift = 3, 345 362 }, 346 363 347 364 /* ··· 359 374 .owner = THIS_MODULE, 360 375 .n_voltages = 1, 361 376 .min_uV = 2000000, 377 + .enable_time = 10000, 362 378 }, 363 379 .delay = 10000, 364 380 .update_bank = 0x03,
+5 -1
drivers/regulator/arizona-ldo1.c
··· 39 39 .map_voltage = regulator_map_voltage_linear, 40 40 .get_voltage_sel = regulator_get_voltage_sel_regmap, 41 41 .set_voltage_sel = regulator_set_voltage_sel_regmap, 42 + .get_bypass = regulator_get_bypass_regmap, 43 + .set_bypass = regulator_set_bypass_regmap, 42 44 }; 43 45 44 46 static const struct regulator_desc arizona_ldo1 = { ··· 51 49 52 50 .vsel_reg = ARIZONA_LDO1_CONTROL_1, 53 51 .vsel_mask = ARIZONA_LDO1_VSEL_MASK, 52 + .bypass_reg = ARIZONA_LDO1_CONTROL_1, 53 + .bypass_mask = ARIZONA_LDO1_BYPASS, 54 54 .min_uV = 900000, 55 55 .uV_step = 50000, 56 - .n_voltages = 7, 56 + .n_voltages = 6, 57 57 58 58 .owner = THIS_MODULE, 59 59 };
+5
drivers/regulator/arizona-micsupp.c
··· 82 82 83 83 .get_voltage_sel = regulator_get_voltage_sel_regmap, 84 84 .set_voltage_sel = regulator_set_voltage_sel_regmap, 85 + 86 + .get_bypass = regulator_get_bypass_regmap, 87 + .set_bypass = regulator_set_bypass_regmap, 85 88 }; 86 89 87 90 static const struct regulator_desc arizona_micsupp = { ··· 98 95 .vsel_mask = ARIZONA_LDO2_VSEL_MASK, 99 96 .enable_reg = ARIZONA_MIC_CHARGE_PUMP_1, 100 97 .enable_mask = ARIZONA_CPMIC_ENA, 98 + .bypass_reg = ARIZONA_MIC_CHARGE_PUMP_1, 99 + .bypass_mask = ARIZONA_CPMIC_BYPASS, 101 100 102 101 .owner = THIS_MODULE, 103 102 };
+147 -6
drivers/regulator/core.c
··· 77 77 struct device *dev; 78 78 struct list_head list; 79 79 unsigned int always_on:1; 80 + unsigned int bypass:1; 80 81 int uA_load; 81 82 int min_uV; 82 83 int max_uV; ··· 395 394 case REGULATOR_STATUS_STANDBY: 396 395 label = "standby"; 397 396 break; 397 + case REGULATOR_STATUS_BYPASS: 398 + label = "bypass"; 399 + break; 398 400 case REGULATOR_STATUS_UNDEFINED: 399 401 label = "undefined"; 400 402 break; ··· 589 585 static DEVICE_ATTR(suspend_standby_state, 0444, 590 586 regulator_suspend_standby_state_show, NULL); 591 587 588 + static ssize_t regulator_bypass_show(struct device *dev, 589 + struct device_attribute *attr, char *buf) 590 + { 591 + struct regulator_dev *rdev = dev_get_drvdata(dev); 592 + const char *report; 593 + bool bypass; 594 + int ret; 595 + 596 + ret = rdev->desc->ops->get_bypass(rdev, &bypass); 597 + 598 + if (ret != 0) 599 + report = "unknown"; 600 + else if (bypass) 601 + report = "enabled"; 602 + else 603 + report = "disabled"; 604 + 605 + return sprintf(buf, "%s\n", report); 606 + } 607 + static DEVICE_ATTR(bypass, 0444, 608 + regulator_bypass_show, NULL); 592 609 593 610 /* 594 611 * These are the only attributes are present for all regulators. ··· 802 777 count += sprintf(buf + count, "idle "); 803 778 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) 804 779 count += sprintf(buf + count, "standby"); 780 + 781 + if (!count) 782 + sprintf(buf, "no parameters"); 805 783 806 784 rdev_info(rdev, "%s\n", buf); 807 785 ··· 1002 974 err = -ENOMEM; 1003 975 return err; 1004 976 } 977 + supply_rdev->open_count++; 1005 978 1006 979 return 0; 1007 980 } ··· 1749 1720 if (regulator->always_on) 1750 1721 return 0; 1751 1722 1723 + if (!ms) 1724 + return regulator_disable(regulator); 1725 + 1752 1726 mutex_lock(&rdev->mutex); 1753 1727 rdev->deferred_disables++; 1754 1728 mutex_unlock(&rdev->mutex); ··· 2210 2178 } 2211 2179 } 2212 2180 2213 - if (ret == 0 && best_val >= 0) 2181 + if (ret == 0 && best_val >= 0) { 2182 + unsigned long data = best_val; 2183 + 2214 2184 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, 2215 - (void *)best_val); 2185 + (void *)data); 2186 + } 2216 2187 2217 2188 trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val); 2218 2189 ··· 2326 2291 EXPORT_SYMBOL_GPL(regulator_set_voltage_time); 2327 2292 2328 2293 /** 2329 - *regulator_set_voltage_time_sel - get raise/fall time 2330 - * @regulator: regulator source 2294 + * regulator_set_voltage_time_sel - get raise/fall time 2295 + * @rdev: regulator source device 2331 2296 * @old_selector: selector for starting voltage 2332 2297 * @new_selector: selector for target voltage 2333 2298 * ··· 2423 2388 ret = rdev->desc->ops->list_voltage(rdev, sel); 2424 2389 } else if (rdev->desc->ops->get_voltage) { 2425 2390 ret = rdev->desc->ops->get_voltage(rdev); 2391 + } else if (rdev->desc->ops->list_voltage) { 2392 + ret = rdev->desc->ops->list_voltage(rdev, 0); 2426 2393 } else { 2427 2394 return -EINVAL; 2428 2395 } ··· 2709 2672 return ret; 2710 2673 } 2711 2674 EXPORT_SYMBOL_GPL(regulator_set_optimum_mode); 2675 + 2676 + /** 2677 + * regulator_set_bypass_regmap - Default set_bypass() using regmap 2678 + * 2679 + * @rdev: device to operate on. 2680 + * @enable: state to set. 2681 + */ 2682 + int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable) 2683 + { 2684 + unsigned int val; 2685 + 2686 + if (enable) 2687 + val = rdev->desc->bypass_mask; 2688 + else 2689 + val = 0; 2690 + 2691 + return regmap_update_bits(rdev->regmap, rdev->desc->bypass_reg, 2692 + rdev->desc->bypass_mask, val); 2693 + } 2694 + EXPORT_SYMBOL_GPL(regulator_set_bypass_regmap); 2695 + 2696 + /** 2697 + * regulator_get_bypass_regmap - Default get_bypass() using regmap 2698 + * 2699 + * @rdev: device to operate on. 2700 + * @enable: current state. 2701 + */ 2702 + int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable) 2703 + { 2704 + unsigned int val; 2705 + int ret; 2706 + 2707 + ret = regmap_read(rdev->regmap, rdev->desc->bypass_reg, &val); 2708 + if (ret != 0) 2709 + return ret; 2710 + 2711 + *enable = val & rdev->desc->bypass_mask; 2712 + 2713 + return 0; 2714 + } 2715 + EXPORT_SYMBOL_GPL(regulator_get_bypass_regmap); 2716 + 2717 + /** 2718 + * regulator_allow_bypass - allow the regulator to go into bypass mode 2719 + * 2720 + * @regulator: Regulator to configure 2721 + * @allow: enable or disable bypass mode 2722 + * 2723 + * Allow the regulator to go into bypass mode if all other consumers 2724 + * for the regulator also enable bypass mode and the machine 2725 + * constraints allow this. Bypass mode means that the regulator is 2726 + * simply passing the input directly to the output with no regulation. 2727 + */ 2728 + int regulator_allow_bypass(struct regulator *regulator, bool enable) 2729 + { 2730 + struct regulator_dev *rdev = regulator->rdev; 2731 + int ret = 0; 2732 + 2733 + if (!rdev->desc->ops->set_bypass) 2734 + return 0; 2735 + 2736 + if (rdev->constraints && 2737 + !(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_BYPASS)) 2738 + return 0; 2739 + 2740 + mutex_lock(&rdev->mutex); 2741 + 2742 + if (enable && !regulator->bypass) { 2743 + rdev->bypass_count++; 2744 + 2745 + if (rdev->bypass_count == rdev->open_count) { 2746 + ret = rdev->desc->ops->set_bypass(rdev, enable); 2747 + if (ret != 0) 2748 + rdev->bypass_count--; 2749 + } 2750 + 2751 + } else if (!enable && regulator->bypass) { 2752 + rdev->bypass_count--; 2753 + 2754 + if (rdev->bypass_count != rdev->open_count) { 2755 + ret = rdev->desc->ops->set_bypass(rdev, enable); 2756 + if (ret != 0) 2757 + rdev->bypass_count++; 2758 + } 2759 + } 2760 + 2761 + if (ret == 0) 2762 + regulator->bypass = enable; 2763 + 2764 + mutex_unlock(&rdev->mutex); 2765 + 2766 + return ret; 2767 + } 2768 + EXPORT_SYMBOL_GPL(regulator_allow_bypass); 2712 2769 2713 2770 /** 2714 2771 * regulator_register_notifier - register regulator event notifier ··· 3142 3011 3143 3012 /* some attributes need specific methods to be displayed */ 3144 3013 if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) || 3145 - (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0)) { 3014 + (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) || 3015 + (ops->list_voltage && ops->list_voltage(rdev, 0) >= 0)) { 3146 3016 status = device_create_file(dev, &dev_attr_microvolts); 3147 3017 if (status < 0) 3148 3018 return status; ··· 3165 3033 } 3166 3034 if (ops->get_status) { 3167 3035 status = device_create_file(dev, &dev_attr_status); 3036 + if (status < 0) 3037 + return status; 3038 + } 3039 + if (ops->get_bypass) { 3040 + status = device_create_file(dev, &dev_attr_bypass); 3168 3041 if (status < 0) 3169 3042 return status; 3170 3043 } ··· 3261 3124 &rdev->use_count); 3262 3125 debugfs_create_u32("open_count", 0444, rdev->debugfs, 3263 3126 &rdev->open_count); 3127 + debugfs_create_u32("bypass_count", 0444, rdev->debugfs, 3128 + &rdev->bypass_count); 3264 3129 } 3265 3130 3266 3131 /** ··· 3328 3189 rdev->desc = regulator_desc; 3329 3190 if (config->regmap) 3330 3191 rdev->regmap = config->regmap; 3331 - else 3192 + else if (dev_get_regmap(dev, NULL)) 3332 3193 rdev->regmap = dev_get_regmap(dev, NULL); 3194 + else if (dev->parent) 3195 + rdev->regmap = dev_get_regmap(dev->parent, NULL); 3333 3196 INIT_LIST_HEAD(&rdev->consumer_list); 3334 3197 INIT_LIST_HEAD(&rdev->list); 3335 3198 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
+2 -2
drivers/regulator/da9052-regulator.c
··· 133 133 max_uA < da9052_current_limits[row][DA9052_MIN_UA]) 134 134 return -EINVAL; 135 135 136 - for (i = 0; i < DA9052_CURRENT_RANGE; i++) { 137 - if (min_uA <= da9052_current_limits[row][i]) { 136 + for (i = DA9052_CURRENT_RANGE - 1; i >= 0; i--) { 137 + if (da9052_current_limits[row][i] <= max_uA) { 138 138 reg_val = i; 139 139 break; 140 140 }
+1 -1
drivers/regulator/dummy.c
··· 30 30 static struct regulator_ops dummy_ops; 31 31 32 32 static struct regulator_desc dummy_desc = { 33 - .name = "dummy", 33 + .name = "regulator-dummy", 34 34 .id = -1, 35 35 .type = REGULATOR_VOLTAGE, 36 36 .owner = THIS_MODULE,
+322
drivers/regulator/fan53555.c
··· 1 + /* 2 + * FAN53555 Fairchild Digitally Programmable TinyBuck Regulator Driver. 3 + * 4 + * Supported Part Numbers: 5 + * FAN53555UC00X/01X/03X/04X/05X 6 + * 7 + * Copyright (c) 2012 Marvell Technology Ltd. 8 + * Yunfan Zhang <yfzhang@marvell.com> 9 + * 10 + * This package is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 as 12 + * published by the Free Software Foundation. 13 + * 14 + */ 15 + #include <linux/module.h> 16 + #include <linux/param.h> 17 + #include <linux/err.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/regulator/driver.h> 20 + #include <linux/regulator/machine.h> 21 + #include <linux/i2c.h> 22 + #include <linux/slab.h> 23 + #include <linux/regmap.h> 24 + #include <linux/regulator/fan53555.h> 25 + 26 + /* Voltage setting */ 27 + #define FAN53555_VSEL0 0x00 28 + #define FAN53555_VSEL1 0x01 29 + /* Control register */ 30 + #define FAN53555_CONTROL 0x02 31 + /* IC Type */ 32 + #define FAN53555_ID1 0x03 33 + /* IC mask version */ 34 + #define FAN53555_ID2 0x04 35 + /* Monitor register */ 36 + #define FAN53555_MONITOR 0x05 37 + 38 + /* VSEL bit definitions */ 39 + #define VSEL_BUCK_EN (1 << 7) 40 + #define VSEL_MODE (1 << 6) 41 + #define VSEL_NSEL_MASK 0x3F 42 + /* Chip ID and Verison */ 43 + #define DIE_ID 0x0F /* ID1 */ 44 + #define DIE_REV 0x0F /* ID2 */ 45 + /* Control bit definitions */ 46 + #define CTL_OUTPUT_DISCHG (1 << 7) 47 + #define CTL_SLEW_MASK (0x7 << 4) 48 + #define CTL_SLEW_SHIFT 4 49 + #define CTL_RESET (1 << 2) 50 + 51 + #define FAN53555_NVOLTAGES 64 /* Numbers of voltages */ 52 + 53 + /* IC Type */ 54 + enum { 55 + FAN53555_CHIP_ID_00 = 0, 56 + FAN53555_CHIP_ID_01, 57 + FAN53555_CHIP_ID_02, 58 + FAN53555_CHIP_ID_03, 59 + FAN53555_CHIP_ID_04, 60 + FAN53555_CHIP_ID_05, 61 + }; 62 + 63 + struct fan53555_device_info { 64 + struct regmap *regmap; 65 + struct device *dev; 66 + struct regulator_desc desc; 67 + struct regulator_dev *rdev; 68 + struct regulator_init_data *regulator; 69 + /* IC Type and Rev */ 70 + int chip_id; 71 + int chip_rev; 72 + /* Voltage setting register */ 73 + unsigned int vol_reg; 74 + unsigned int sleep_reg; 75 + /* Voltage range and step(linear) */ 76 + unsigned int vsel_min; 77 + unsigned int vsel_step; 78 + /* Voltage slew rate limiting */ 79 + unsigned int slew_rate; 80 + /* Sleep voltage cache */ 81 + unsigned int sleep_vol_cache; 82 + }; 83 + 84 + static int fan53555_set_suspend_voltage(struct regulator_dev *rdev, int uV) 85 + { 86 + struct fan53555_device_info *di = rdev_get_drvdata(rdev); 87 + int ret; 88 + 89 + if (di->sleep_vol_cache == uV) 90 + return 0; 91 + ret = regulator_map_voltage_linear(rdev, uV, uV); 92 + if (ret < 0) 93 + return -EINVAL; 94 + ret = regmap_update_bits(di->regmap, di->sleep_reg, 95 + VSEL_NSEL_MASK, ret); 96 + if (ret < 0) 97 + return -EINVAL; 98 + /* Cache the sleep voltage setting. 99 + * Might not be the real voltage which is rounded */ 100 + di->sleep_vol_cache = uV; 101 + 102 + return 0; 103 + } 104 + 105 + static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode) 106 + { 107 + struct fan53555_device_info *di = rdev_get_drvdata(rdev); 108 + 109 + switch (mode) { 110 + case REGULATOR_MODE_FAST: 111 + regmap_update_bits(di->regmap, di->vol_reg, 112 + VSEL_MODE, VSEL_MODE); 113 + break; 114 + case REGULATOR_MODE_NORMAL: 115 + regmap_update_bits(di->regmap, di->vol_reg, VSEL_MODE, 0); 116 + break; 117 + default: 118 + return -EINVAL; 119 + } 120 + return 0; 121 + } 122 + 123 + static unsigned int fan53555_get_mode(struct regulator_dev *rdev) 124 + { 125 + struct fan53555_device_info *di = rdev_get_drvdata(rdev); 126 + unsigned int val; 127 + int ret = 0; 128 + 129 + ret = regmap_read(di->regmap, di->vol_reg, &val); 130 + if (ret < 0) 131 + return ret; 132 + if (val & VSEL_MODE) 133 + return REGULATOR_MODE_FAST; 134 + else 135 + return REGULATOR_MODE_NORMAL; 136 + } 137 + 138 + static struct regulator_ops fan53555_regulator_ops = { 139 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 140 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 141 + .map_voltage = regulator_map_voltage_linear, 142 + .list_voltage = regulator_list_voltage_linear, 143 + .set_suspend_voltage = fan53555_set_suspend_voltage, 144 + .enable = regulator_enable_regmap, 145 + .disable = regulator_disable_regmap, 146 + .is_enabled = regulator_is_enabled_regmap, 147 + .set_mode = fan53555_set_mode, 148 + .get_mode = fan53555_get_mode, 149 + }; 150 + 151 + /* For 00,01,03,05 options: 152 + * VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V. 153 + * For 04 option: 154 + * VOUT = 0.603V + NSELx * 12.826mV, from 0.603 to 1.411V. 155 + * */ 156 + static int fan53555_device_setup(struct fan53555_device_info *di, 157 + struct fan53555_platform_data *pdata) 158 + { 159 + unsigned int reg, data, mask; 160 + 161 + /* Setup voltage control register */ 162 + switch (pdata->sleep_vsel_id) { 163 + case FAN53555_VSEL_ID_0: 164 + di->sleep_reg = FAN53555_VSEL0; 165 + di->vol_reg = FAN53555_VSEL1; 166 + break; 167 + case FAN53555_VSEL_ID_1: 168 + di->sleep_reg = FAN53555_VSEL1; 169 + di->vol_reg = FAN53555_VSEL0; 170 + break; 171 + default: 172 + dev_err(di->dev, "Invalid VSEL ID!\n"); 173 + return -EINVAL; 174 + } 175 + /* Init voltage range and step */ 176 + switch (di->chip_id) { 177 + case FAN53555_CHIP_ID_00: 178 + case FAN53555_CHIP_ID_01: 179 + case FAN53555_CHIP_ID_03: 180 + case FAN53555_CHIP_ID_05: 181 + di->vsel_min = 600000; 182 + di->vsel_step = 10000; 183 + break; 184 + case FAN53555_CHIP_ID_04: 185 + di->vsel_min = 603000; 186 + di->vsel_step = 12826; 187 + break; 188 + default: 189 + dev_err(di->dev, 190 + "Chip ID[%d]\n not supported!\n", di->chip_id); 191 + return -EINVAL; 192 + } 193 + /* Init slew rate */ 194 + if (pdata->slew_rate & 0x7) 195 + di->slew_rate = pdata->slew_rate; 196 + else 197 + di->slew_rate = FAN53555_SLEW_RATE_64MV; 198 + reg = FAN53555_CONTROL; 199 + data = di->slew_rate << CTL_SLEW_SHIFT; 200 + mask = CTL_SLEW_MASK; 201 + return regmap_update_bits(di->regmap, reg, mask, data); 202 + } 203 + 204 + static int fan53555_regulator_register(struct fan53555_device_info *di, 205 + struct regulator_config *config) 206 + { 207 + struct regulator_desc *rdesc = &di->desc; 208 + 209 + rdesc->name = "fan53555-reg"; 210 + rdesc->ops = &fan53555_regulator_ops; 211 + rdesc->type = REGULATOR_VOLTAGE; 212 + rdesc->n_voltages = FAN53555_NVOLTAGES; 213 + rdesc->enable_reg = di->vol_reg; 214 + rdesc->enable_mask = VSEL_BUCK_EN; 215 + rdesc->min_uV = di->vsel_min; 216 + rdesc->uV_step = di->vsel_step; 217 + rdesc->vsel_reg = di->vol_reg; 218 + rdesc->vsel_mask = VSEL_NSEL_MASK; 219 + rdesc->owner = THIS_MODULE; 220 + 221 + di->rdev = regulator_register(&di->desc, config); 222 + if (IS_ERR(di->rdev)) 223 + return PTR_ERR(di->rdev); 224 + return 0; 225 + 226 + } 227 + 228 + static struct regmap_config fan53555_regmap_config = { 229 + .reg_bits = 8, 230 + .val_bits = 8, 231 + }; 232 + 233 + static int __devinit fan53555_regulator_probe(struct i2c_client *client, 234 + const struct i2c_device_id *id) 235 + { 236 + struct fan53555_device_info *di; 237 + struct fan53555_platform_data *pdata; 238 + struct regulator_config config = { }; 239 + unsigned int val; 240 + int ret; 241 + 242 + pdata = client->dev.platform_data; 243 + if (!pdata || !pdata->regulator) { 244 + dev_err(&client->dev, "Platform data not found!\n"); 245 + return -ENODEV; 246 + } 247 + 248 + di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info), 249 + GFP_KERNEL); 250 + if (!di) { 251 + dev_err(&client->dev, "Failed to allocate device info data!\n"); 252 + return -ENOMEM; 253 + } 254 + di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config); 255 + if (IS_ERR(di->regmap)) { 256 + dev_err(&client->dev, "Failed to allocate regmap!\n"); 257 + return PTR_ERR(di->regmap); 258 + } 259 + di->dev = &client->dev; 260 + di->regulator = pdata->regulator; 261 + i2c_set_clientdata(client, di); 262 + /* Get chip ID */ 263 + ret = regmap_read(di->regmap, FAN53555_ID1, &val); 264 + if (ret < 0) { 265 + dev_err(&client->dev, "Failed to get chip ID!\n"); 266 + return -ENODEV; 267 + } 268 + di->chip_id = val & DIE_ID; 269 + /* Get chip revision */ 270 + ret = regmap_read(di->regmap, FAN53555_ID2, &val); 271 + if (ret < 0) { 272 + dev_err(&client->dev, "Failed to get chip Rev!\n"); 273 + return -ENODEV; 274 + } 275 + di->chip_rev = val & DIE_REV; 276 + dev_info(&client->dev, "FAN53555 Option[%d] Rev[%d] Detected!\n", 277 + di->chip_id, di->chip_rev); 278 + /* Device init */ 279 + ret = fan53555_device_setup(di, pdata); 280 + if (ret < 0) { 281 + dev_err(&client->dev, "Failed to setup device!\n"); 282 + return ret; 283 + } 284 + /* Register regulator */ 285 + config.dev = di->dev; 286 + config.init_data = di->regulator; 287 + config.regmap = di->regmap; 288 + config.driver_data = di; 289 + ret = fan53555_regulator_register(di, &config); 290 + if (ret < 0) 291 + dev_err(&client->dev, "Failed to register regulator!\n"); 292 + return ret; 293 + 294 + } 295 + 296 + static int __devexit fan53555_regulator_remove(struct i2c_client *client) 297 + { 298 + struct fan53555_device_info *di = i2c_get_clientdata(client); 299 + 300 + regulator_unregister(di->rdev); 301 + return 0; 302 + } 303 + 304 + static const struct i2c_device_id fan53555_id[] = { 305 + {"fan53555", -1}, 306 + { }, 307 + }; 308 + 309 + static struct i2c_driver fan53555_regulator_driver = { 310 + .driver = { 311 + .name = "fan53555-regulator", 312 + }, 313 + .probe = fan53555_regulator_probe, 314 + .remove = __devexit_p(fan53555_regulator_remove), 315 + .id_table = fan53555_id, 316 + }; 317 + 318 + module_i2c_driver(fan53555_regulator_driver); 319 + 320 + MODULE_AUTHOR("Yunfan Zhang <yfzhang@marvell.com>"); 321 + MODULE_DESCRIPTION("FAN53555 regulator driver"); 322 + MODULE_LICENSE("GPL v2");
-6
drivers/regulator/isl6271a-regulator.c
··· 73 73 .map_voltage = regulator_map_voltage_linear, 74 74 }; 75 75 76 - static int isl6271a_get_fixed_voltage(struct regulator_dev *dev) 77 - { 78 - return dev->desc->min_uV; 79 - } 80 - 81 76 static struct regulator_ops isl_fixed_ops = { 82 - .get_voltage = isl6271a_get_fixed_voltage, 83 77 .list_voltage = regulator_list_voltage_linear, 84 78 }; 85 79
+35 -53
drivers/regulator/lp872x.c
··· 86 86 #define EXTERN_DVS_USED 0 87 87 #define MAX_DELAY 6 88 88 89 + /* Default DVS Mode */ 90 + #define LP8720_DEFAULT_DVS 0 91 + #define LP8725_DEFAULT_DVS BIT(2) 92 + 89 93 /* dump registers in regmap-debugfs */ 90 94 #define MAX_REGISTERS 0x0F 91 95 ··· 273 269 return val > MAX_DELAY ? 0 : val * time_step_us; 274 270 } 275 271 276 - static void lp872x_set_dvs(struct lp872x *lp, int gpio) 272 + static void lp872x_set_dvs(struct lp872x *lp, enum lp872x_dvs_sel dvs_sel, 273 + int gpio) 277 274 { 278 - enum lp872x_dvs_sel dvs_sel = lp->pdata->dvs->vsel; 279 275 enum lp872x_dvs_state state; 280 276 281 277 state = dvs_sel == SEL_V1 ? DVS_HIGH : DVS_LOW; ··· 343 339 struct lp872x *lp = rdev_get_drvdata(rdev); 344 340 enum lp872x_regulator_id buck = rdev_get_id(rdev); 345 341 u8 addr, mask = LP872X_VOUT_M; 346 - struct lp872x_dvs *dvs = lp->pdata->dvs; 342 + struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL; 347 343 348 344 if (dvs && gpio_is_valid(dvs->gpio)) 349 - lp872x_set_dvs(lp, dvs->gpio); 345 + lp872x_set_dvs(lp, dvs->vsel, dvs->gpio); 350 346 351 347 addr = lp872x_select_buck_vout_addr(lp, buck); 352 348 if (!lp872x_is_valid_buck_addr(addr)) ··· 378 374 { 379 375 struct lp872x *lp = rdev_get_drvdata(rdev); 380 376 enum lp872x_regulator_id buck = rdev_get_id(rdev); 381 - int i, max = ARRAY_SIZE(lp8725_buck_uA); 382 - u8 addr, val; 377 + int i; 378 + u8 addr; 383 379 384 380 switch (buck) { 385 381 case LP8725_ID_BUCK1: ··· 392 388 return -EINVAL; 393 389 } 394 390 395 - for (i = 0 ; i < max ; i++) 391 + for (i = ARRAY_SIZE(lp8725_buck_uA) - 1 ; i >= 0; i--) { 396 392 if (lp8725_buck_uA[i] >= min_uA && 397 393 lp8725_buck_uA[i] <= max_uA) 398 - break; 394 + return lp872x_update_bits(lp, addr, 395 + LP8725_BUCK_CL_M, 396 + i << LP8725_BUCK_CL_S); 397 + } 399 398 400 - if (i == max) 401 - return -EINVAL; 402 - 403 - val = i << LP8725_BUCK_CL_S; 404 - 405 - return lp872x_update_bits(lp, addr, LP8725_BUCK_CL_M, val); 399 + return -EINVAL; 406 400 } 407 401 408 402 static int lp8725_buck_get_current_limit(struct regulator_dev *rdev) ··· 729 727 }, 730 728 }; 731 729 732 - static int lp872x_check_dvs_validity(struct lp872x *lp) 733 - { 734 - struct lp872x_dvs *dvs = lp->pdata->dvs; 735 - u8 val = 0; 736 - int ret; 737 - 738 - ret = lp872x_read_byte(lp, LP872X_GENERAL_CFG, &val); 739 - if (ret) 740 - return ret; 741 - 742 - ret = 0; 743 - if (lp->chipid == LP8720) { 744 - if (val & LP8720_EXT_DVS_M) 745 - ret = dvs ? 0 : -EINVAL; 746 - } else { 747 - if ((val & LP8725_DVS1_M) == EXTERN_DVS_USED) 748 - ret = dvs ? 0 : -EINVAL; 749 - } 750 - 751 - return ret; 752 - } 753 - 754 730 static int lp872x_init_dvs(struct lp872x *lp) 755 731 { 756 732 int ret, gpio; 757 - struct lp872x_dvs *dvs = lp->pdata->dvs; 733 + struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL; 758 734 enum lp872x_dvs_state pinstate; 735 + u8 mask[] = { LP8720_EXT_DVS_M, LP8725_DVS1_M | LP8725_DVS2_M }; 736 + u8 default_dvs_mode[] = { LP8720_DEFAULT_DVS, LP8725_DEFAULT_DVS }; 759 737 760 - ret = lp872x_check_dvs_validity(lp); 761 - if (ret) { 762 - dev_warn(lp->dev, "invalid dvs data: %d\n", ret); 763 - return ret; 764 - } 738 + if (!dvs) 739 + goto set_default_dvs_mode; 765 740 766 741 gpio = dvs->gpio; 767 742 if (!gpio_is_valid(gpio)) { ··· 757 778 lp->dvs_gpio = gpio; 758 779 759 780 return 0; 781 + 782 + set_default_dvs_mode: 783 + return lp872x_update_bits(lp, LP872X_GENERAL_CFG, mask[lp->chipid], 784 + default_dvs_mode[lp->chipid]); 760 785 } 761 786 762 787 static int lp872x_config(struct lp872x *lp) ··· 768 785 struct lp872x_platform_data *pdata = lp->pdata; 769 786 int ret; 770 787 771 - if (!pdata->update_config) 772 - return 0; 788 + if (!pdata || !pdata->update_config) 789 + goto init_dvs; 773 790 774 791 ret = lp872x_write_byte(lp, LP872X_GENERAL_CFG, pdata->general_config); 775 792 if (ret) 776 793 return ret; 777 794 795 + init_dvs: 778 796 return lp872x_init_dvs(lp); 779 797 } 780 798 781 799 static struct regulator_init_data 782 800 *lp872x_find_regulator_init_data(int id, struct lp872x *lp) 783 801 { 802 + struct lp872x_platform_data *pdata = lp->pdata; 784 803 int i; 785 804 805 + if (!pdata) 806 + return NULL; 807 + 786 808 for (i = 0; i < lp->num_regulators; i++) { 787 - if (lp->pdata->regulator_data[i].id == id) 788 - return lp->pdata->regulator_data[i].init_data; 809 + if (pdata->regulator_data[i].id == id) 810 + return pdata->regulator_data[i].init_data; 789 811 } 790 812 791 813 return NULL; ··· 851 863 static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id) 852 864 { 853 865 struct lp872x *lp; 854 - struct lp872x_platform_data *pdata = cl->dev.platform_data; 855 866 int ret, size, num_regulators; 856 867 const int lp872x_num_regulators[] = { 857 868 [LP8720] = LP8720_NUM_REGULATORS, 858 869 [LP8725] = LP8725_NUM_REGULATORS, 859 870 }; 860 - 861 - if (!pdata) { 862 - dev_err(&cl->dev, "no platform data\n"); 863 - return -EINVAL; 864 - } 865 871 866 872 lp = devm_kzalloc(&cl->dev, sizeof(struct lp872x), GFP_KERNEL); 867 873 if (!lp) ··· 876 894 } 877 895 878 896 lp->dev = &cl->dev; 879 - lp->pdata = pdata; 897 + lp->pdata = cl->dev.platform_data; 880 898 lp->chipid = id->driver_data; 881 899 lp->num_regulators = num_regulators; 882 900 i2c_set_clientdata(cl, lp);
+15 -65
drivers/regulator/lp8788-buck.c
··· 69 69 #define PIN_HIGH 1 70 70 #define ENABLE_TIME_USEC 32 71 71 72 + #define BUCK_FPWM_MASK(x) (1 << (x)) 73 + #define BUCK_FPWM_SHIFT(x) (x) 74 + 72 75 enum lp8788_dvs_state { 73 76 DVS_LOW = GPIOF_OUT_INIT_LOW, 74 77 DVS_HIGH = GPIOF_OUT_INIT_HIGH, ··· 89 86 BUCK4, 90 87 }; 91 88 92 - struct lp8788_pwm_map { 93 - u8 mask; 94 - u8 shift; 95 - }; 96 - 97 89 struct lp8788_buck { 98 90 struct lp8788 *lp; 99 91 struct regulator_dev *regulator; 100 - struct lp8788_pwm_map *pmap; 101 92 void *dvs; 102 93 }; 103 94 ··· 101 104 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, 102 105 1550000, 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000, 103 106 1950000, 2000000, 104 - }; 105 - 106 - /* buck pwm mode selection : used for set/get_mode in regulator ops 107 - * @forced pwm : fast mode 108 - * @auto pwm : normal mode 109 - */ 110 - static struct lp8788_pwm_map buck_pmap[] = { 111 - [BUCK1] = { 112 - .mask = LP8788_FPWM_BUCK1_M, 113 - .shift = LP8788_FPWM_BUCK1_S, 114 - }, 115 - [BUCK2] = { 116 - .mask = LP8788_FPWM_BUCK2_M, 117 - .shift = LP8788_FPWM_BUCK2_S, 118 - }, 119 - [BUCK3] = { 120 - .mask = LP8788_FPWM_BUCK3_M, 121 - .shift = LP8788_FPWM_BUCK3_S, 122 - }, 123 - [BUCK4] = { 124 - .mask = LP8788_FPWM_BUCK4_M, 125 - .shift = LP8788_FPWM_BUCK4_S, 126 - }, 127 107 }; 128 108 129 109 static const u8 buck1_vout_addr[] = { ··· 321 347 static int lp8788_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) 322 348 { 323 349 struct lp8788_buck *buck = rdev_get_drvdata(rdev); 324 - struct lp8788_pwm_map *pmap = buck->pmap; 325 - u8 val; 350 + enum lp8788_buck_id id = rdev_get_id(rdev); 351 + u8 mask, val; 326 352 327 - if (!pmap) 328 - return -EINVAL; 329 - 353 + mask = BUCK_FPWM_MASK(id); 330 354 switch (mode) { 331 355 case REGULATOR_MODE_FAST: 332 - val = LP8788_FORCE_PWM << pmap->shift; 356 + val = LP8788_FORCE_PWM << BUCK_FPWM_SHIFT(id); 333 357 break; 334 358 case REGULATOR_MODE_NORMAL: 335 - val = LP8788_AUTO_PWM << pmap->shift; 359 + val = LP8788_AUTO_PWM << BUCK_FPWM_SHIFT(id); 336 360 break; 337 361 default: 338 362 return -EINVAL; 339 363 } 340 364 341 - return lp8788_update_bits(buck->lp, LP8788_BUCK_PWM, pmap->mask, val); 365 + return lp8788_update_bits(buck->lp, LP8788_BUCK_PWM, mask, val); 342 366 } 343 367 344 368 static unsigned int lp8788_buck_get_mode(struct regulator_dev *rdev) 345 369 { 346 370 struct lp8788_buck *buck = rdev_get_drvdata(rdev); 347 - struct lp8788_pwm_map *pmap = buck->pmap; 371 + enum lp8788_buck_id id = rdev_get_id(rdev); 348 372 u8 val; 349 373 int ret; 350 - 351 - if (!pmap) 352 - return -EINVAL; 353 374 354 375 ret = lp8788_read_byte(buck->lp, LP8788_BUCK_PWM, &val); 355 376 if (ret) 356 377 return ret; 357 378 358 - return val & pmap->mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; 379 + return val & BUCK_FPWM_MASK(id) ? 380 + REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; 359 381 } 360 382 361 383 static struct regulator_ops lp8788_buck12_ops = { ··· 429 459 }, 430 460 }; 431 461 432 - static int lp8788_set_default_dvs_ctrl_mode(struct lp8788 *lp, 433 - enum lp8788_buck_id id) 434 - { 435 - u8 mask, val; 436 - 437 - switch (id) { 438 - case BUCK1: 439 - mask = LP8788_BUCK1_DVS_SEL_M; 440 - val = LP8788_BUCK1_DVS_I2C; 441 - break; 442 - case BUCK2: 443 - mask = LP8788_BUCK2_DVS_SEL_M; 444 - val = LP8788_BUCK2_DVS_I2C; 445 - break; 446 - default: 447 - return 0; 448 - } 449 - 450 - return lp8788_update_bits(lp, LP8788_BUCK_DVS_SEL, mask, val); 451 - } 452 - 453 462 static int _gpio_request(struct lp8788_buck *buck, int gpio, char *name) 454 463 { 455 464 struct device *dev = buck->lp->dev; ··· 479 530 struct lp8788_platform_data *pdata = buck->lp->pdata; 480 531 u8 mask[] = { LP8788_BUCK1_DVS_SEL_M, LP8788_BUCK2_DVS_SEL_M }; 481 532 u8 val[] = { LP8788_BUCK1_DVS_PIN, LP8788_BUCK2_DVS_PIN }; 533 + u8 default_dvs_mode[] = { LP8788_BUCK1_DVS_I2C, LP8788_BUCK2_DVS_I2C }; 482 534 483 535 /* no dvs for buck3, 4 */ 484 536 if (id == BUCK3 || id == BUCK4) ··· 500 550 val[id]); 501 551 502 552 set_default_dvs_mode: 503 - return lp8788_set_default_dvs_ctrl_mode(buck->lp, id); 553 + return lp8788_update_bits(buck->lp, LP8788_BUCK_DVS_SEL, mask[id], 554 + default_dvs_mode[id]); 504 555 } 505 556 506 557 static __devinit int lp8788_buck_probe(struct platform_device *pdev) ··· 518 567 return -ENOMEM; 519 568 520 569 buck->lp = lp; 521 - buck->pmap = &buck_pmap[id]; 522 570 523 571 ret = lp8788_init_dvs(buck, id); 524 572 if (ret)
+8
drivers/regulator/lp8788-ldo.c
··· 496 496 .name = "dldo12", 497 497 .id = DLDO12, 498 498 .ops = &lp8788_ldo_voltage_fixed_ops, 499 + .n_voltages = 1, 499 500 .type = REGULATOR_VOLTAGE, 500 501 .owner = THIS_MODULE, 501 502 .enable_reg = LP8788_EN_LDO_B, ··· 522 521 .name = "aldo2", 523 522 .id = ALDO2, 524 523 .ops = &lp8788_ldo_voltage_fixed_ops, 524 + .n_voltages = 1, 525 525 .type = REGULATOR_VOLTAGE, 526 526 .owner = THIS_MODULE, 527 527 .enable_reg = LP8788_EN_LDO_B, ··· 532 530 .name = "aldo3", 533 531 .id = ALDO3, 534 532 .ops = &lp8788_ldo_voltage_fixed_ops, 533 + .n_voltages = 1, 535 534 .type = REGULATOR_VOLTAGE, 536 535 .owner = THIS_MODULE, 537 536 .enable_reg = LP8788_EN_LDO_B, ··· 542 539 .name = "aldo4", 543 540 .id = ALDO4, 544 541 .ops = &lp8788_ldo_voltage_fixed_ops, 542 + .n_voltages = 1, 545 543 .type = REGULATOR_VOLTAGE, 546 544 .owner = THIS_MODULE, 547 545 .enable_reg = LP8788_EN_LDO_B, ··· 552 548 .name = "aldo5", 553 549 .id = ALDO5, 554 550 .ops = &lp8788_ldo_voltage_fixed_ops, 551 + .n_voltages = 1, 555 552 .type = REGULATOR_VOLTAGE, 556 553 .owner = THIS_MODULE, 557 554 .enable_reg = LP8788_EN_LDO_C, ··· 588 583 .name = "aldo8", 589 584 .id = ALDO8, 590 585 .ops = &lp8788_ldo_voltage_fixed_ops, 586 + .n_voltages = 1, 591 587 .type = REGULATOR_VOLTAGE, 592 588 .owner = THIS_MODULE, 593 589 .enable_reg = LP8788_EN_LDO_C, ··· 598 592 .name = "aldo9", 599 593 .id = ALDO9, 600 594 .ops = &lp8788_ldo_voltage_fixed_ops, 595 + .n_voltages = 1, 601 596 .type = REGULATOR_VOLTAGE, 602 597 .owner = THIS_MODULE, 603 598 .enable_reg = LP8788_EN_LDO_C, ··· 608 601 .name = "aldo10", 609 602 .id = ALDO10, 610 603 .ops = &lp8788_ldo_voltage_fixed_ops, 604 + .n_voltages = 1, 611 605 .type = REGULATOR_VOLTAGE, 612 606 .owner = THIS_MODULE, 613 607 .enable_reg = LP8788_EN_LDO_C,
+11 -19
drivers/regulator/max77686.c
··· 66 66 }; 67 67 68 68 struct max77686_data { 69 - struct regulator_dev **rdev; 69 + struct regulator_dev *rdev[MAX77686_REGULATORS]; 70 70 }; 71 71 72 72 static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) ··· 265 265 rmatch.of_node = NULL; 266 266 of_regulator_match(iodev->dev, regulators_np, &rmatch, 1); 267 267 rdata[i].initdata = rmatch.init_data; 268 + rdata[i].of_node = rmatch.of_node; 268 269 } 269 270 270 271 pdata->regulators = rdata; ··· 284 283 { 285 284 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); 286 285 struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev); 287 - struct regulator_dev **rdev; 288 286 struct max77686_data *max77686; 289 - int i, size; 290 - int ret = 0; 287 + int i, ret = 0; 291 288 struct regulator_config config = { }; 292 289 293 290 dev_dbg(&pdev->dev, "%s\n", __func__); ··· 312 313 if (!max77686) 313 314 return -ENOMEM; 314 315 315 - size = sizeof(struct regulator_dev *) * MAX77686_REGULATORS; 316 - max77686->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); 317 - if (!max77686->rdev) 318 - return -ENOMEM; 319 - 320 - rdev = max77686->rdev; 321 316 config.dev = &pdev->dev; 322 317 config.regmap = iodev->regmap; 323 318 platform_set_drvdata(pdev, max77686); 324 319 325 320 for (i = 0; i < MAX77686_REGULATORS; i++) { 326 321 config.init_data = pdata->regulators[i].initdata; 322 + config.of_node = pdata->regulators[i].of_node; 327 323 328 - rdev[i] = regulator_register(&regulators[i], &config); 329 - if (IS_ERR(rdev[i])) { 330 - ret = PTR_ERR(rdev[i]); 324 + max77686->rdev[i] = regulator_register(&regulators[i], &config); 325 + if (IS_ERR(max77686->rdev[i])) { 326 + ret = PTR_ERR(max77686->rdev[i]); 331 327 dev_err(&pdev->dev, 332 328 "regulator init failed for %d\n", i); 333 - rdev[i] = NULL; 334 - goto err; 329 + max77686->rdev[i] = NULL; 330 + goto err; 335 331 } 336 332 } 337 333 338 334 return 0; 339 335 err: 340 336 while (--i >= 0) 341 - regulator_unregister(rdev[i]); 337 + regulator_unregister(max77686->rdev[i]); 342 338 return ret; 343 339 } 344 340 345 341 static int __devexit max77686_pmic_remove(struct platform_device *pdev) 346 342 { 347 343 struct max77686_data *max77686 = platform_get_drvdata(pdev); 348 - struct regulator_dev **rdev = max77686->rdev; 349 344 int i; 350 345 351 346 for (i = 0; i < MAX77686_REGULATORS; i++) 352 - if (rdev[i]) 353 - regulator_unregister(rdev[i]); 347 + regulator_unregister(max77686->rdev[i]); 354 348 355 349 return 0; 356 350 }
+408
drivers/regulator/max8907-regulator.c
··· 1 + /* 2 + * max8907-regulator.c -- support regulators in max8907 3 + * 4 + * Copyright (C) 2010 Gyungoh Yoo <jack.yoo@maxim-ic.com> 5 + * Copyright (C) 2010-2012, NVIDIA CORPORATION. All rights reserved. 6 + * 7 + * Portions based on drivers/regulator/tps65910-regulator.c, 8 + * Copyright 2010 Texas Instruments Inc. 9 + * Author: Graeme Gregory <gg@slimlogic.co.uk> 10 + * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk> 11 + * 12 + * This program is free software; you can redistribute it and/or modify 13 + * it under the terms of the GNU General Public License version 2 as 14 + * published by the Free Software Foundation. 15 + */ 16 + 17 + #include <linux/err.h> 18 + #include <linux/init.h> 19 + #include <linux/mfd/core.h> 20 + #include <linux/mfd/max8907.h> 21 + #include <linux/module.h> 22 + #include <linux/of.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/regulator/driver.h> 25 + #include <linux/regulator/machine.h> 26 + #include <linux/regulator/of_regulator.h> 27 + #include <linux/regmap.h> 28 + #include <linux/slab.h> 29 + 30 + #define MAX8907_II2RR_VERSION_MASK 0xF0 31 + #define MAX8907_II2RR_VERSION_REV_A 0x00 32 + #define MAX8907_II2RR_VERSION_REV_B 0x10 33 + #define MAX8907_II2RR_VERSION_REV_C 0x30 34 + 35 + struct max8907_regulator { 36 + struct regulator_desc desc[MAX8907_NUM_REGULATORS]; 37 + struct regulator_dev *rdev[MAX8907_NUM_REGULATORS]; 38 + }; 39 + 40 + #define REG_MBATT() \ 41 + [MAX8907_MBATT] = { \ 42 + .name = "MBATT", \ 43 + .supply_name = "mbatt", \ 44 + .id = MAX8907_MBATT, \ 45 + .ops = &max8907_mbatt_ops, \ 46 + .type = REGULATOR_VOLTAGE, \ 47 + .owner = THIS_MODULE, \ 48 + } 49 + 50 + #define REG_LDO(ids, supply, base, min, max, step) \ 51 + [MAX8907_##ids] = { \ 52 + .name = #ids, \ 53 + .supply_name = supply, \ 54 + .id = MAX8907_##ids, \ 55 + .n_voltages = ((max) - (min)) / (step) + 1, \ 56 + .ops = &max8907_ldo_ops, \ 57 + .type = REGULATOR_VOLTAGE, \ 58 + .owner = THIS_MODULE, \ 59 + .min_uV = (min), \ 60 + .uV_step = (step), \ 61 + .vsel_reg = (base) + MAX8907_VOUT, \ 62 + .vsel_mask = 0x3f, \ 63 + .enable_reg = (base) + MAX8907_CTL, \ 64 + .enable_mask = MAX8907_MASK_LDO_EN, \ 65 + } 66 + 67 + #define REG_FIXED(ids, supply, voltage) \ 68 + [MAX8907_##ids] = { \ 69 + .name = #ids, \ 70 + .supply_name = supply, \ 71 + .id = MAX8907_##ids, \ 72 + .n_voltages = 1, \ 73 + .ops = &max8907_fixed_ops, \ 74 + .type = REGULATOR_VOLTAGE, \ 75 + .owner = THIS_MODULE, \ 76 + .min_uV = (voltage), \ 77 + } 78 + 79 + #define REG_OUT5V(ids, supply, base, voltage) \ 80 + [MAX8907_##ids] = { \ 81 + .name = #ids, \ 82 + .supply_name = supply, \ 83 + .id = MAX8907_##ids, \ 84 + .n_voltages = 1, \ 85 + .ops = &max8907_out5v_ops, \ 86 + .type = REGULATOR_VOLTAGE, \ 87 + .owner = THIS_MODULE, \ 88 + .min_uV = (voltage), \ 89 + .enable_reg = (base), \ 90 + .enable_mask = MAX8907_MASK_OUT5V_EN, \ 91 + } 92 + 93 + #define REG_BBAT(ids, supply, base, min, max, step) \ 94 + [MAX8907_##ids] = { \ 95 + .name = #ids, \ 96 + .supply_name = supply, \ 97 + .id = MAX8907_##ids, \ 98 + .n_voltages = ((max) - (min)) / (step) + 1, \ 99 + .ops = &max8907_bbat_ops, \ 100 + .type = REGULATOR_VOLTAGE, \ 101 + .owner = THIS_MODULE, \ 102 + .min_uV = (min), \ 103 + .uV_step = (step), \ 104 + .vsel_reg = (base), \ 105 + .vsel_mask = MAX8907_MASK_VBBATTCV, \ 106 + } 107 + 108 + #define LDO_750_50(id, supply, base) REG_LDO(id, supply, (base), \ 109 + 750000, 3900000, 50000) 110 + #define LDO_650_25(id, supply, base) REG_LDO(id, supply, (base), \ 111 + 650000, 2225000, 25000) 112 + 113 + static struct regulator_ops max8907_mbatt_ops = { 114 + }; 115 + 116 + static struct regulator_ops max8907_ldo_ops = { 117 + .list_voltage = regulator_list_voltage_linear, 118 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 119 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 120 + .enable = regulator_enable_regmap, 121 + .disable = regulator_disable_regmap, 122 + .is_enabled = regulator_is_enabled_regmap, 123 + }; 124 + 125 + static struct regulator_ops max8907_ldo_hwctl_ops = { 126 + .list_voltage = regulator_list_voltage_linear, 127 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 128 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 129 + }; 130 + 131 + static struct regulator_ops max8907_fixed_ops = { 132 + .list_voltage = regulator_list_voltage_linear, 133 + }; 134 + 135 + static struct regulator_ops max8907_out5v_ops = { 136 + .list_voltage = regulator_list_voltage_linear, 137 + .enable = regulator_enable_regmap, 138 + .disable = regulator_disable_regmap, 139 + .is_enabled = regulator_is_enabled_regmap, 140 + }; 141 + 142 + static struct regulator_ops max8907_out5v_hwctl_ops = { 143 + .list_voltage = regulator_list_voltage_linear, 144 + }; 145 + 146 + static struct regulator_ops max8907_bbat_ops = { 147 + .list_voltage = regulator_list_voltage_linear, 148 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 149 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 150 + }; 151 + 152 + static struct regulator_desc max8907_regulators[] = { 153 + REG_MBATT(), 154 + REG_LDO(SD1, "in-v1", MAX8907_REG_SDCTL1, 650000, 2225000, 25000), 155 + REG_LDO(SD2, "in-v2", MAX8907_REG_SDCTL2, 637500, 1425000, 12500), 156 + REG_LDO(SD3, "in-v3", MAX8907_REG_SDCTL3, 750000, 3900000, 50000), 157 + LDO_750_50(LDO1, "in1", MAX8907_REG_LDOCTL1), 158 + LDO_650_25(LDO2, "in2", MAX8907_REG_LDOCTL2), 159 + LDO_650_25(LDO3, "in3", MAX8907_REG_LDOCTL3), 160 + LDO_750_50(LDO4, "in4", MAX8907_REG_LDOCTL4), 161 + LDO_750_50(LDO5, "in5", MAX8907_REG_LDOCTL5), 162 + LDO_750_50(LDO6, "in6", MAX8907_REG_LDOCTL6), 163 + LDO_750_50(LDO7, "in7", MAX8907_REG_LDOCTL7), 164 + LDO_750_50(LDO8, "in8", MAX8907_REG_LDOCTL8), 165 + LDO_750_50(LDO9, "in9", MAX8907_REG_LDOCTL9), 166 + LDO_750_50(LDO10, "in10", MAX8907_REG_LDOCTL10), 167 + LDO_750_50(LDO11, "in11", MAX8907_REG_LDOCTL11), 168 + LDO_750_50(LDO12, "in12", MAX8907_REG_LDOCTL12), 169 + LDO_750_50(LDO13, "in13", MAX8907_REG_LDOCTL13), 170 + LDO_750_50(LDO14, "in14", MAX8907_REG_LDOCTL14), 171 + LDO_750_50(LDO15, "in15", MAX8907_REG_LDOCTL15), 172 + LDO_750_50(LDO16, "in16", MAX8907_REG_LDOCTL16), 173 + LDO_650_25(LDO17, "in17", MAX8907_REG_LDOCTL17), 174 + LDO_650_25(LDO18, "in18", MAX8907_REG_LDOCTL18), 175 + LDO_750_50(LDO19, "in19", MAX8907_REG_LDOCTL19), 176 + LDO_750_50(LDO20, "in20", MAX8907_REG_LDOCTL20), 177 + REG_OUT5V(OUT5V, "mbatt", MAX8907_REG_OUT5VEN, 5000000), 178 + REG_OUT5V(OUT33V, "mbatt", MAX8907_REG_OUT33VEN, 3300000), 179 + REG_BBAT(BBAT, "MBATT", MAX8907_REG_BBAT_CNFG, 180 + 2400000, 3000000, 200000), 181 + REG_FIXED(SDBY, "MBATT", 1200000), 182 + REG_FIXED(VRTC, "MBATT", 3300000), 183 + }; 184 + 185 + #ifdef CONFIG_OF 186 + 187 + #define MATCH(_name, _id) \ 188 + [MAX8907_##_id] = { \ 189 + .name = #_name, \ 190 + .driver_data = (void *)&max8907_regulators[MAX8907_##_id], \ 191 + } 192 + 193 + static struct of_regulator_match max8907_matches[] = { 194 + MATCH(mbatt, MBATT), 195 + MATCH(sd1, SD1), 196 + MATCH(sd2, SD2), 197 + MATCH(sd3, SD3), 198 + MATCH(ldo1, LDO1), 199 + MATCH(ldo2, LDO2), 200 + MATCH(ldo3, LDO3), 201 + MATCH(ldo4, LDO4), 202 + MATCH(ldo5, LDO5), 203 + MATCH(ldo6, LDO6), 204 + MATCH(ldo7, LDO7), 205 + MATCH(ldo8, LDO8), 206 + MATCH(ldo9, LDO9), 207 + MATCH(ldo10, LDO10), 208 + MATCH(ldo11, LDO11), 209 + MATCH(ldo12, LDO12), 210 + MATCH(ldo13, LDO13), 211 + MATCH(ldo14, LDO14), 212 + MATCH(ldo15, LDO15), 213 + MATCH(ldo16, LDO16), 214 + MATCH(ldo17, LDO17), 215 + MATCH(ldo18, LDO18), 216 + MATCH(ldo19, LDO19), 217 + MATCH(ldo20, LDO20), 218 + MATCH(out5v, OUT5V), 219 + MATCH(out33v, OUT33V), 220 + MATCH(bbat, BBAT), 221 + MATCH(sdby, SDBY), 222 + MATCH(vrtc, VRTC), 223 + }; 224 + 225 + static int max8907_regulator_parse_dt(struct platform_device *pdev) 226 + { 227 + struct device_node *np = pdev->dev.parent->of_node; 228 + struct device_node *regulators; 229 + int ret; 230 + 231 + if (!pdev->dev.parent->of_node) 232 + return 0; 233 + 234 + regulators = of_find_node_by_name(np, "regulators"); 235 + if (!regulators) { 236 + dev_err(&pdev->dev, "regulators node not found\n"); 237 + return -EINVAL; 238 + } 239 + 240 + ret = of_regulator_match(pdev->dev.parent, regulators, 241 + max8907_matches, 242 + ARRAY_SIZE(max8907_matches)); 243 + if (ret < 0) { 244 + dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", 245 + ret); 246 + return ret; 247 + } 248 + 249 + return 0; 250 + } 251 + 252 + static inline struct regulator_init_data *match_init_data(int index) 253 + { 254 + return max8907_matches[index].init_data; 255 + } 256 + 257 + static inline struct device_node *match_of_node(int index) 258 + { 259 + return max8907_matches[index].of_node; 260 + } 261 + #else 262 + static int max8907_regulator_parse_dt(struct platform_device *pdev) 263 + { 264 + return 0; 265 + } 266 + 267 + static inline struct regulator_init_data *match_init_data(int index) 268 + { 269 + return NULL; 270 + } 271 + 272 + static inline struct device_node *match_of_node(int index) 273 + { 274 + return NULL; 275 + } 276 + #endif 277 + 278 + static __devinit int max8907_regulator_probe(struct platform_device *pdev) 279 + { 280 + struct max8907 *max8907 = dev_get_drvdata(pdev->dev.parent); 281 + struct max8907_platform_data *pdata = dev_get_platdata(max8907->dev); 282 + int ret; 283 + struct max8907_regulator *pmic; 284 + unsigned int val; 285 + int i; 286 + struct regulator_config config = {}; 287 + struct regulator_init_data *idata; 288 + const char *mbatt_rail_name = NULL; 289 + 290 + ret = max8907_regulator_parse_dt(pdev); 291 + if (ret) 292 + return ret; 293 + 294 + pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); 295 + if (!pmic) { 296 + dev_err(&pdev->dev, "Failed to alloc pmic\n"); 297 + return -ENOMEM; 298 + } 299 + platform_set_drvdata(pdev, pmic); 300 + 301 + memcpy(pmic->desc, max8907_regulators, sizeof(pmic->desc)); 302 + 303 + /* Backwards compatibility with MAX8907B; SD1 uses different voltages */ 304 + regmap_read(max8907->regmap_gen, MAX8907_REG_II2RR, &val); 305 + if ((val & MAX8907_II2RR_VERSION_MASK) == 306 + MAX8907_II2RR_VERSION_REV_B) { 307 + pmic->desc[MAX8907_SD1].min_uV = 637500; 308 + pmic->desc[MAX8907_SD1].uV_step = 12500; 309 + pmic->desc[MAX8907_SD1].n_voltages = 310 + (1425000 - 637500) / 12500 + 1; 311 + } 312 + 313 + for (i = 0; i < MAX8907_NUM_REGULATORS; i++) { 314 + config.dev = pdev->dev.parent; 315 + if (pdata) 316 + idata = pdata->init_data[i]; 317 + else 318 + idata = match_init_data(i); 319 + config.init_data = idata; 320 + config.driver_data = pmic; 321 + config.regmap = max8907->regmap_gen; 322 + config.of_node = match_of_node(i); 323 + 324 + switch (pmic->desc[i].id) { 325 + case MAX8907_MBATT: 326 + if (idata && idata->constraints.name) 327 + mbatt_rail_name = idata->constraints.name; 328 + else 329 + mbatt_rail_name = pmic->desc[i].name; 330 + break; 331 + case MAX8907_BBAT: 332 + case MAX8907_SDBY: 333 + case MAX8907_VRTC: 334 + idata->supply_regulator = mbatt_rail_name; 335 + break; 336 + } 337 + 338 + if (pmic->desc[i].ops == &max8907_ldo_ops) { 339 + regmap_read(config.regmap, pmic->desc[i].enable_reg, 340 + &val); 341 + if ((val & MAX8907_MASK_LDO_SEQ) != 342 + MAX8907_MASK_LDO_SEQ) 343 + pmic->desc[i].ops = &max8907_ldo_hwctl_ops; 344 + } else if (pmic->desc[i].ops == &max8907_out5v_ops) { 345 + regmap_read(config.regmap, pmic->desc[i].enable_reg, 346 + &val); 347 + if ((val & (MAX8907_MASK_OUT5V_VINEN | 348 + MAX8907_MASK_OUT5V_ENSRC)) != 349 + MAX8907_MASK_OUT5V_ENSRC) 350 + pmic->desc[i].ops = &max8907_out5v_hwctl_ops; 351 + } 352 + 353 + pmic->rdev[i] = regulator_register(&pmic->desc[i], &config); 354 + if (IS_ERR(pmic->rdev[i])) { 355 + dev_err(&pdev->dev, 356 + "failed to register %s regulator\n", 357 + pmic->desc[i].name); 358 + ret = PTR_ERR(pmic->rdev[i]); 359 + goto err_unregister_regulator; 360 + } 361 + } 362 + 363 + return 0; 364 + 365 + err_unregister_regulator: 366 + while (--i >= 0) 367 + regulator_unregister(pmic->rdev[i]); 368 + return ret; 369 + } 370 + 371 + static __devexit int max8907_regulator_remove(struct platform_device *pdev) 372 + { 373 + struct max8907_regulator *pmic = platform_get_drvdata(pdev); 374 + int i; 375 + 376 + for (i = 0; i < MAX8907_NUM_REGULATORS; i++) 377 + regulator_unregister(pmic->rdev[i]); 378 + 379 + return 0; 380 + } 381 + 382 + static struct platform_driver max8907_regulator_driver = { 383 + .driver = { 384 + .name = "max8907-regulator", 385 + .owner = THIS_MODULE, 386 + }, 387 + .probe = max8907_regulator_probe, 388 + .remove = __devexit_p(max8907_regulator_remove), 389 + }; 390 + 391 + static int __init max8907_regulator_init(void) 392 + { 393 + return platform_driver_register(&max8907_regulator_driver); 394 + } 395 + 396 + subsys_initcall(max8907_regulator_init); 397 + 398 + static void __exit max8907_reg_exit(void) 399 + { 400 + platform_driver_unregister(&max8907_regulator_driver); 401 + } 402 + 403 + module_exit(max8907_reg_exit); 404 + 405 + MODULE_DESCRIPTION("MAX8907 regulator driver"); 406 + MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@maxim-ic.com>"); 407 + MODULE_LICENSE("GPL v2"); 408 + MODULE_ALIAS("platform:max8907-regulator");
+74 -15
drivers/regulator/mc13783-regulator.c
··· 21 21 #include <linux/module.h> 22 22 #include "mc13xxx.h" 23 23 24 + #define MC13783_REG_SWITCHERS0 24 25 + /* Enable does not exist for SW1A */ 26 + #define MC13783_REG_SWITCHERS0_SW1AEN 0 27 + #define MC13783_REG_SWITCHERS0_SW1AVSEL 0 28 + #define MC13783_REG_SWITCHERS0_SW1AVSEL_M (63 << 0) 29 + 30 + #define MC13783_REG_SWITCHERS1 25 31 + /* Enable does not exist for SW1B */ 32 + #define MC13783_REG_SWITCHERS1_SW1BEN 0 33 + #define MC13783_REG_SWITCHERS1_SW1BVSEL 0 34 + #define MC13783_REG_SWITCHERS1_SW1BVSEL_M (63 << 0) 35 + 36 + #define MC13783_REG_SWITCHERS2 26 37 + /* Enable does not exist for SW2A */ 38 + #define MC13783_REG_SWITCHERS2_SW2AEN 0 39 + #define MC13783_REG_SWITCHERS2_SW2AVSEL 0 40 + #define MC13783_REG_SWITCHERS2_SW2AVSEL_M (63 << 0) 41 + 42 + #define MC13783_REG_SWITCHERS3 27 43 + /* Enable does not exist for SW2B */ 44 + #define MC13783_REG_SWITCHERS3_SW2BEN 0 45 + #define MC13783_REG_SWITCHERS3_SW2BVSEL 0 46 + #define MC13783_REG_SWITCHERS3_SW2BVSEL_M (63 << 0) 47 + 24 48 #define MC13783_REG_SWITCHERS5 29 25 49 #define MC13783_REG_SWITCHERS5_SW3EN (1 << 20) 26 50 #define MC13783_REG_SWITCHERS5_SW3VSEL 18 ··· 117 93 118 94 119 95 /* Voltage Values */ 96 + static const int mc13783_sw1x_val[] = { 97 + 900000, 925000, 950000, 975000, 98 + 1000000, 1025000, 1050000, 1075000, 99 + 1100000, 1125000, 1150000, 1175000, 100 + 1200000, 1225000, 1250000, 1275000, 101 + 1300000, 1325000, 1350000, 1375000, 102 + 1400000, 1425000, 1450000, 1475000, 103 + 1500000, 1525000, 1550000, 1575000, 104 + 1600000, 1625000, 1650000, 1675000, 105 + 1700000, 1700000, 1700000, 1700000, 106 + 1800000, 1800000, 1800000, 1800000, 107 + 1850000, 1850000, 1850000, 1850000, 108 + 2000000, 2000000, 2000000, 2000000, 109 + 2100000, 2100000, 2100000, 2100000, 110 + 2200000, 2200000, 2200000, 2200000, 111 + 2200000, 2200000, 2200000, 2200000, 112 + 2200000, 2200000, 2200000, 2200000, 113 + }; 114 + 115 + static const int mc13783_sw2x_val[] = { 116 + 900000, 925000, 950000, 975000, 117 + 1000000, 1025000, 1050000, 1075000, 118 + 1100000, 1125000, 1150000, 1175000, 119 + 1200000, 1225000, 1250000, 1275000, 120 + 1300000, 1325000, 1350000, 1375000, 121 + 1400000, 1425000, 1450000, 1475000, 122 + 1500000, 1525000, 1550000, 1575000, 123 + 1600000, 1625000, 1650000, 1675000, 124 + 1700000, 1700000, 1700000, 1700000, 125 + 1800000, 1800000, 1800000, 1800000, 126 + 1900000, 1900000, 1900000, 1900000, 127 + 2000000, 2000000, 2000000, 2000000, 128 + 2100000, 2100000, 2100000, 2100000, 129 + 2200000, 2200000, 2200000, 2200000, 130 + 2200000, 2200000, 2200000, 2200000, 131 + 2200000, 2200000, 2200000, 2200000, 132 + }; 133 + 120 134 static const unsigned int mc13783_sw3_val[] = { 121 135 5000000, 5000000, 5000000, 5500000, 122 136 }; ··· 250 188 MC13783_DEFINE(REG, _name, _reg, _vsel_reg, _voltages) 251 189 252 190 static struct mc13xxx_regulator mc13783_regulators[] = { 191 + MC13783_DEFINE_SW(SW1A, SWITCHERS0, SWITCHERS0, mc13783_sw1x_val), 192 + MC13783_DEFINE_SW(SW1B, SWITCHERS1, SWITCHERS1, mc13783_sw1x_val), 193 + MC13783_DEFINE_SW(SW2A, SWITCHERS2, SWITCHERS2, mc13783_sw2x_val), 194 + MC13783_DEFINE_SW(SW2B, SWITCHERS3, SWITCHERS3, mc13783_sw2x_val), 253 195 MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val), 254 196 255 197 MC13783_FIXED_DEFINE(REG, VAUDIO, REGULATORMODE0, mc13783_vaudio_val), ··· 304 238 305 239 BUG_ON(val & ~mask); 306 240 241 + mc13xxx_lock(priv->mc13xxx); 307 242 ret = mc13xxx_reg_read(mc13783, MC13783_REG_POWERMISC, &valread); 308 243 if (ret) 309 - return ret; 244 + goto out; 310 245 311 246 /* Update the stored state for Power Gates. */ 312 247 priv->powermisc_pwgt_state = ··· 320 253 valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) | 321 254 priv->powermisc_pwgt_state; 322 255 323 - return mc13xxx_reg_write(mc13783, MC13783_REG_POWERMISC, valread); 256 + ret = mc13xxx_reg_write(mc13783, MC13783_REG_POWERMISC, valread); 257 + out: 258 + mc13xxx_unlock(priv->mc13xxx); 259 + return ret; 324 260 } 325 261 326 262 static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev) ··· 331 261 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 332 262 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; 333 263 int id = rdev_get_id(rdev); 334 - int ret; 335 264 u32 en_val = mc13xxx_regulators[id].enable_bit; 336 265 337 266 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); ··· 340 271 id == MC13783_REG_PWGT2SPI) 341 272 en_val = 0; 342 273 343 - mc13xxx_lock(priv->mc13xxx); 344 - ret = mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit, 274 + return mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit, 345 275 en_val); 346 - mc13xxx_unlock(priv->mc13xxx); 347 - 348 - return ret; 349 276 } 350 277 351 278 static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev) ··· 349 284 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 350 285 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; 351 286 int id = rdev_get_id(rdev); 352 - int ret; 353 287 u32 dis_val = 0; 354 288 355 289 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); ··· 358 294 id == MC13783_REG_PWGT2SPI) 359 295 dis_val = mc13xxx_regulators[id].enable_bit; 360 296 361 - mc13xxx_lock(priv->mc13xxx); 362 - ret = mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit, 297 + return mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit, 363 298 dis_val); 364 - mc13xxx_unlock(priv->mc13xxx); 365 - 366 - return ret; 367 299 } 368 300 369 301 static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev) ··· 390 330 .is_enabled = mc13783_gpo_regulator_is_enabled, 391 331 .list_voltage = regulator_list_voltage_table, 392 332 .set_voltage = mc13xxx_fixed_regulator_set_voltage, 393 - .get_voltage = mc13xxx_fixed_regulator_get_voltage, 394 333 }; 395 334 396 335 static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
+26 -51
drivers/regulator/mc13892-regulator.c
··· 305 305 306 306 BUG_ON(val & ~mask); 307 307 308 + mc13xxx_lock(priv->mc13xxx); 308 309 ret = mc13xxx_reg_read(mc13892, MC13892_POWERMISC, &valread); 309 310 if (ret) 310 - return ret; 311 + goto out; 311 312 312 313 /* Update the stored state for Power Gates. */ 313 314 priv->powermisc_pwgt_state = ··· 321 320 valread = (valread & ~MC13892_POWERMISC_PWGTSPI_M) | 322 321 priv->powermisc_pwgt_state; 323 322 324 - return mc13xxx_reg_write(mc13892, MC13892_POWERMISC, valread); 323 + ret = mc13xxx_reg_write(mc13892, MC13892_POWERMISC, valread); 324 + out: 325 + mc13xxx_unlock(priv->mc13xxx); 326 + return ret; 325 327 } 326 328 327 329 static int mc13892_gpo_regulator_enable(struct regulator_dev *rdev) 328 330 { 329 331 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 330 332 int id = rdev_get_id(rdev); 331 - int ret; 332 333 u32 en_val = mc13892_regulators[id].enable_bit; 333 334 u32 mask = mc13892_regulators[id].enable_bit; 334 335 ··· 343 340 if (id == MC13892_GPO4) 344 341 mask |= MC13892_POWERMISC_GPO4ADINEN; 345 342 346 - mc13xxx_lock(priv->mc13xxx); 347 - ret = mc13892_powermisc_rmw(priv, mask, en_val); 348 - mc13xxx_unlock(priv->mc13xxx); 349 - 350 - return ret; 343 + return mc13892_powermisc_rmw(priv, mask, en_val); 351 344 } 352 345 353 346 static int mc13892_gpo_regulator_disable(struct regulator_dev *rdev) 354 347 { 355 348 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 356 349 int id = rdev_get_id(rdev); 357 - int ret; 358 350 u32 dis_val = 0; 359 351 360 352 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); ··· 358 360 if (id == MC13892_PWGT1SPI || id == MC13892_PWGT2SPI) 359 361 dis_val = mc13892_regulators[id].enable_bit; 360 362 361 - mc13xxx_lock(priv->mc13xxx); 362 - ret = mc13892_powermisc_rmw(priv, mc13892_regulators[id].enable_bit, 363 + return mc13892_powermisc_rmw(priv, mc13892_regulators[id].enable_bit, 363 364 dis_val); 364 - mc13xxx_unlock(priv->mc13xxx); 365 - 366 - return ret; 367 365 } 368 366 369 367 static int mc13892_gpo_regulator_is_enabled(struct regulator_dev *rdev) ··· 390 396 .is_enabled = mc13892_gpo_regulator_is_enabled, 391 397 .list_voltage = regulator_list_voltage_table, 392 398 .set_voltage = mc13xxx_fixed_regulator_set_voltage, 393 - .get_voltage = mc13xxx_fixed_regulator_get_voltage, 394 399 }; 395 400 396 - static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev) 401 + static int mc13892_sw_regulator_get_voltage_sel(struct regulator_dev *rdev) 397 402 { 398 403 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 399 404 int ret, id = rdev_get_id(rdev); 400 - unsigned int val, hi; 405 + unsigned int val; 401 406 402 407 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 403 408 ··· 407 414 if (ret) 408 415 return ret; 409 416 410 - hi = val & MC13892_SWITCHERS0_SWxHI; 411 417 val = (val & mc13892_regulators[id].vsel_mask) 412 418 >> mc13892_regulators[id].vsel_shift; 413 419 414 420 dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val); 415 - 416 - if (hi) 417 - val = (25000 * val) + 1100000; 418 - else 419 - val = (25000 * val) + 600000; 420 421 421 422 return val; 422 423 } ··· 419 432 unsigned selector) 420 433 { 421 434 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 422 - int hi, value, mask, id = rdev_get_id(rdev); 423 - u32 valread; 435 + int volt, mask, id = rdev_get_id(rdev); 436 + u32 reg_value; 424 437 int ret; 425 438 426 - value = rdev->desc->volt_table[selector]; 439 + volt = rdev->desc->volt_table[selector]; 440 + mask = mc13892_regulators[id].vsel_mask; 441 + reg_value = selector << mc13892_regulators[id].vsel_shift; 442 + 443 + if (volt > 1375000) { 444 + mask |= MC13892_SWITCHERS0_SWxHI; 445 + reg_value |= MC13892_SWITCHERS0_SWxHI; 446 + } else if (volt < 1100000) { 447 + mask |= MC13892_SWITCHERS0_SWxHI; 448 + reg_value &= ~MC13892_SWITCHERS0_SWxHI; 449 + } 427 450 428 451 mc13xxx_lock(priv->mc13xxx); 429 - ret = mc13xxx_reg_read(priv->mc13xxx, 430 - mc13892_regulators[id].vsel_reg, &valread); 431 - if (ret) 432 - goto err; 433 - 434 - if (value > 1375000) 435 - hi = 1; 436 - else if (value < 1100000) 437 - hi = 0; 438 - else 439 - hi = valread & MC13892_SWITCHERS0_SWxHI; 440 - 441 - if (hi) { 442 - value = (value - 1100000) / 25000; 443 - value |= MC13892_SWITCHERS0_SWxHI; 444 - } else 445 - value = (value - 600000) / 25000; 446 - 447 - mask = mc13892_regulators[id].vsel_mask | MC13892_SWITCHERS0_SWxHI; 448 - valread = (valread & ~mask) | 449 - (value << mc13892_regulators[id].vsel_shift); 450 - ret = mc13xxx_reg_write(priv->mc13xxx, mc13892_regulators[id].vsel_reg, 451 - valread); 452 - err: 452 + ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].reg, mask, 453 + reg_value); 453 454 mc13xxx_unlock(priv->mc13xxx); 454 455 455 456 return ret; ··· 446 471 static struct regulator_ops mc13892_sw_regulator_ops = { 447 472 .list_voltage = regulator_list_voltage_table, 448 473 .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel, 449 - .get_voltage = mc13892_sw_regulator_get_voltage, 474 + .get_voltage_sel = mc13892_sw_regulator_get_voltage_sel, 450 475 }; 451 476 452 477 static int mc13892_vcam_set_mode(struct regulator_dev *rdev, unsigned int mode)
+4 -13
drivers/regulator/mc13xxx-regulator-core.c
··· 143 143 __func__, id, min_uV, max_uV); 144 144 145 145 if (min_uV <= rdev->desc->volt_table[0] && 146 - rdev->desc->volt_table[0] <= max_uV) 146 + rdev->desc->volt_table[0] <= max_uV) { 147 + *selector = 0; 147 148 return 0; 148 - else 149 + } else { 149 150 return -EINVAL; 151 + } 150 152 } 151 153 EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_set_voltage); 152 - 153 - int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev) 154 - { 155 - int id = rdev_get_id(rdev); 156 - 157 - dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 158 - 159 - return rdev->desc->volt_table[0]; 160 - } 161 - EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_get_voltage); 162 154 163 155 struct regulator_ops mc13xxx_fixed_regulator_ops = { 164 156 .enable = mc13xxx_regulator_enable, ··· 158 166 .is_enabled = mc13xxx_regulator_is_enabled, 159 167 .list_voltage = regulator_list_voltage_table, 160 168 .set_voltage = mc13xxx_fixed_regulator_set_voltage, 161 - .get_voltage = mc13xxx_fixed_regulator_get_voltage, 162 169 }; 163 170 EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_ops); 164 171
-1
drivers/regulator/mc13xxx.h
··· 34 34 35 35 extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, 36 36 int min_uV, int max_uV, unsigned *selector); 37 - extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev); 38 37 39 38 #ifdef CONFIG_OF 40 39 extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
+12 -13
drivers/regulator/of_regulator.c
··· 92 92 EXPORT_SYMBOL_GPL(of_get_regulator_init_data); 93 93 94 94 /** 95 - * of_regulator_match - extract regulator init data when node 96 - * property "regulator-compatible" matches with the regulator name. 95 + * of_regulator_match - extract multiple regulator init data from device tree. 97 96 * @dev: device requesting the data 98 97 * @node: parent device node of the regulators 99 98 * @matches: match table for the regulators 100 99 * @num_matches: number of entries in match table 101 100 * 102 - * This function uses a match table specified by the regulator driver and 103 - * looks up the corresponding init data in the device tree if 104 - * regulator-compatible matches. Note that the match table is modified 101 + * This function uses a match table specified by the regulator driver to 102 + * parse regulator init data from the device tree. @node is expected to 103 + * contain a set of child nodes, each providing the init data for one 104 + * regulator. The data parsed from a child node will be matched to a regulator 105 + * based on either the deprecated property regulator-compatible if present, 106 + * or otherwise the child node's name. Note that the match table is modified 105 107 * in place. 106 108 * 107 109 * Returns the number of matches found or a negative error code on failure. ··· 114 112 { 115 113 unsigned int count = 0; 116 114 unsigned int i; 117 - const char *regulator_comp; 115 + const char *name; 118 116 struct device_node *child; 119 117 120 118 if (!dev || !node) 121 119 return -EINVAL; 122 120 123 121 for_each_child_of_node(node, child) { 124 - regulator_comp = of_get_property(child, 122 + name = of_get_property(child, 125 123 "regulator-compatible", NULL); 126 - if (!regulator_comp) { 127 - dev_err(dev, "regulator-compatible is missing for node %s\n", 128 - child->name); 129 - continue; 130 - } 124 + if (!name) 125 + name = child->name; 131 126 for (i = 0; i < num_matches; i++) { 132 127 struct of_regulator_match *match = &matches[i]; 133 128 if (match->of_node) 134 129 continue; 135 130 136 - if (strcmp(match->name, regulator_comp)) 131 + if (strcmp(match->name, name)) 137 132 continue; 138 133 139 134 match->init_data =
+5 -40
drivers/regulator/palmas-regulator.c
··· 443 443 return 850000 + (selector * 50000); 444 444 } 445 445 446 - static int palmas_get_voltage_ldo_sel(struct regulator_dev *dev) 447 - { 448 - struct palmas_pmic *pmic = rdev_get_drvdata(dev); 449 - int id = rdev_get_id(dev); 450 - int selector; 451 - unsigned int reg; 452 - unsigned int addr; 453 - 454 - addr = palmas_regs_info[id].vsel_addr; 455 - 456 - palmas_ldo_read(pmic->palmas, addr, &reg); 457 - 458 - selector = reg & PALMAS_LDO1_VOLTAGE_VSEL_MASK; 459 - 460 - /* Adjust selector to match list_voltage ranges */ 461 - if (selector > 49) 462 - selector = 49; 463 - 464 - return selector; 465 - } 466 - 467 - static int palmas_set_voltage_ldo_sel(struct regulator_dev *dev, 468 - unsigned selector) 469 - { 470 - struct palmas_pmic *pmic = rdev_get_drvdata(dev); 471 - int id = rdev_get_id(dev); 472 - unsigned int reg = 0; 473 - unsigned int addr; 474 - 475 - addr = palmas_regs_info[id].vsel_addr; 476 - 477 - reg = selector; 478 - 479 - palmas_ldo_write(pmic->palmas, addr, reg); 480 - 481 - return 0; 482 - } 483 - 484 446 static int palmas_map_voltage_ldo(struct regulator_dev *rdev, 485 447 int min_uV, int max_uV) 486 448 { ··· 467 505 .is_enabled = palmas_is_enabled_ldo, 468 506 .enable = regulator_enable_regmap, 469 507 .disable = regulator_disable_regmap, 470 - .get_voltage_sel = palmas_get_voltage_ldo_sel, 471 - .set_voltage_sel = palmas_set_voltage_ldo_sel, 508 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 509 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 472 510 .list_voltage = palmas_list_voltage_ldo, 473 511 .map_voltage = palmas_map_voltage_ldo, 474 512 }; ··· 719 757 720 758 pmic->desc[id].type = REGULATOR_VOLTAGE; 721 759 pmic->desc[id].owner = THIS_MODULE; 760 + pmic->desc[id].vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, 761 + palmas_regs_info[id].vsel_addr); 762 + pmic->desc[id].vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK; 722 763 pmic->desc[id].enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, 723 764 palmas_regs_info[id].ctrl_addr); 724 765 pmic->desc[id].enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE;
+8 -19
drivers/regulator/s2mps11.c
··· 24 24 #include <linux/mfd/samsung/s2mps11.h> 25 25 26 26 struct s2mps11_info { 27 - struct regulator_dev **rdev; 27 + struct regulator_dev *rdev[S2MPS11_REGULATOR_MAX]; 28 28 29 29 int ramp_delay2; 30 30 int ramp_delay34; ··· 236 236 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); 237 237 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev); 238 238 struct regulator_config config = { }; 239 - struct regulator_dev **rdev; 240 239 struct s2mps11_info *s2mps11; 241 - int i, ret, size; 240 + int i, ret; 242 241 unsigned char ramp_enable, ramp_reg = 0; 243 242 244 243 if (!pdata) { ··· 250 251 if (!s2mps11) 251 252 return -ENOMEM; 252 253 253 - size = sizeof(struct regulator_dev *) * S2MPS11_REGULATOR_MAX; 254 - s2mps11->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); 255 - if (!s2mps11->rdev) { 256 - return -ENOMEM; 257 - } 258 - 259 - rdev = s2mps11->rdev; 260 254 platform_set_drvdata(pdev, s2mps11); 261 255 262 256 s2mps11->ramp_delay2 = pdata->buck2_ramp_delay; ··· 289 297 config.init_data = pdata->regulators[i].initdata; 290 298 config.driver_data = s2mps11; 291 299 292 - rdev[i] = regulator_register(&regulators[i], &config); 293 - if (IS_ERR(rdev[i])) { 294 - ret = PTR_ERR(rdev[i]); 300 + s2mps11->rdev[i] = regulator_register(&regulators[i], &config); 301 + if (IS_ERR(s2mps11->rdev[i])) { 302 + ret = PTR_ERR(s2mps11->rdev[i]); 295 303 dev_err(&pdev->dev, "regulator init failed for %d\n", 296 304 i); 297 - rdev[i] = NULL; 305 + s2mps11->rdev[i] = NULL; 298 306 goto err; 299 307 } 300 308 } ··· 302 310 return 0; 303 311 err: 304 312 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) 305 - if (rdev[i]) 306 - regulator_unregister(rdev[i]); 313 + regulator_unregister(s2mps11->rdev[i]); 307 314 308 315 return ret; 309 316 } ··· 310 319 static int __devexit s2mps11_pmic_remove(struct platform_device *pdev) 311 320 { 312 321 struct s2mps11_info *s2mps11 = platform_get_drvdata(pdev); 313 - struct regulator_dev **rdev = s2mps11->rdev; 314 322 int i; 315 323 316 324 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) 317 - if (rdev[i]) 318 - regulator_unregister(rdev[i]); 325 + regulator_unregister(s2mps11->rdev[i]); 319 326 320 327 return 0; 321 328 }
+4 -6
drivers/regulator/tps6524x-regulator.c
··· 502 502 if (info->n_ilimsels == 1) 503 503 return -EINVAL; 504 504 505 - for (i = 0; i < info->n_ilimsels; i++) 505 + for (i = info->n_ilimsels - 1; i >= 0; i--) { 506 506 if (min_uA <= info->ilimsels[i] && 507 507 max_uA >= info->ilimsels[i]) 508 - break; 508 + return write_field(hw, &info->ilimsel, i); 509 + } 509 510 510 - if (i >= info->n_ilimsels) 511 - return -EINVAL; 512 - 513 - return write_field(hw, &info->ilimsel, i); 511 + return -EINVAL; 514 512 } 515 513 516 514 static int get_current_limit(struct regulator_dev *rdev)
+29 -67
drivers/regulator/tps6586x-regulator.c
··· 57 57 struct tps6586x_regulator { 58 58 struct regulator_desc desc; 59 59 60 - int volt_reg; 61 - int volt_shift; 62 - int volt_nbits; 63 60 int enable_bit[2]; 64 61 int enable_reg[2]; 65 62 ··· 78 81 int ret, val, rid = rdev_get_id(rdev); 79 82 uint8_t mask; 80 83 81 - val = selector << ri->volt_shift; 82 - mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; 84 + val = selector << (ffs(rdev->desc->vsel_mask) - 1); 85 + mask = rdev->desc->vsel_mask; 83 86 84 - ret = tps6586x_update(parent, ri->volt_reg, val, mask); 87 + ret = tps6586x_update(parent, rdev->desc->vsel_reg, val, mask); 85 88 if (ret) 86 89 return ret; 87 90 ··· 97 100 return ret; 98 101 } 99 102 100 - static int tps6586x_get_voltage_sel(struct regulator_dev *rdev) 101 - { 102 - struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); 103 - struct device *parent = to_tps6586x_dev(rdev); 104 - uint8_t val, mask; 105 - int ret; 106 - 107 - ret = tps6586x_read(parent, ri->volt_reg, &val); 108 - if (ret) 109 - return ret; 110 - 111 - mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; 112 - val = (val & mask) >> ri->volt_shift; 113 - 114 - if (val >= ri->desc.n_voltages) 115 - BUG(); 116 - 117 - return val; 118 - } 119 - 120 - static int tps6586x_regulator_enable(struct regulator_dev *rdev) 121 - { 122 - struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); 123 - struct device *parent = to_tps6586x_dev(rdev); 124 - 125 - return tps6586x_set_bits(parent, ri->enable_reg[0], 126 - 1 << ri->enable_bit[0]); 127 - } 128 - 129 - static int tps6586x_regulator_disable(struct regulator_dev *rdev) 130 - { 131 - struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); 132 - struct device *parent = to_tps6586x_dev(rdev); 133 - 134 - return tps6586x_clr_bits(parent, ri->enable_reg[0], 135 - 1 << ri->enable_bit[0]); 136 - } 137 - 138 - static int tps6586x_regulator_is_enabled(struct regulator_dev *rdev) 139 - { 140 - struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); 141 - struct device *parent = to_tps6586x_dev(rdev); 142 - uint8_t reg_val; 143 - int ret; 144 - 145 - ret = tps6586x_read(parent, ri->enable_reg[0], &reg_val); 146 - if (ret) 147 - return ret; 148 - 149 - return !!(reg_val & (1 << ri->enable_bit[0])); 150 - } 151 - 152 103 static struct regulator_ops tps6586x_regulator_ops = { 153 104 .list_voltage = regulator_list_voltage_table, 154 - .get_voltage_sel = tps6586x_get_voltage_sel, 105 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 155 106 .set_voltage_sel = tps6586x_set_voltage_sel, 156 107 157 - .is_enabled = tps6586x_regulator_is_enabled, 158 - .enable = tps6586x_regulator_enable, 159 - .disable = tps6586x_regulator_disable, 108 + .is_enabled = regulator_is_enabled_regmap, 109 + .enable = regulator_enable_regmap, 110 + .disable = regulator_disable_regmap, 111 + }; 112 + 113 + static struct regulator_ops tps6586x_sys_regulator_ops = { 160 114 }; 161 115 162 116 static const unsigned int tps6586x_ldo0_voltages[] = { ··· 150 202 .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ 151 203 .volt_table = tps6586x_##vdata##_voltages, \ 152 204 .owner = THIS_MODULE, \ 205 + .enable_reg = TPS6586X_SUPPLY##ereg0, \ 206 + .enable_mask = 1 << (ebit0), \ 207 + .vsel_reg = TPS6586X_##vreg, \ 208 + .vsel_mask = ((1 << (nbits)) - 1) << (shift), \ 153 209 }, \ 154 - .volt_reg = TPS6586X_##vreg, \ 155 - .volt_shift = (shift), \ 156 - .volt_nbits = (nbits), \ 157 210 .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \ 158 211 .enable_bit[0] = (ebit0), \ 159 212 .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \ ··· 179 230 TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ 180 231 } 181 232 233 + #define TPS6586X_SYS_REGULATOR() \ 234 + { \ 235 + .desc = { \ 236 + .supply_name = "sys", \ 237 + .name = "REG-SYS", \ 238 + .ops = &tps6586x_sys_regulator_ops, \ 239 + .type = REGULATOR_VOLTAGE, \ 240 + .id = TPS6586X_ID_SYS, \ 241 + .owner = THIS_MODULE, \ 242 + }, \ 243 + } 244 + 182 245 static struct tps6586x_regulator tps6586x_regulator[] = { 246 + TPS6586X_SYS_REGULATOR(), 183 247 TPS6586X_LDO(LDO_0, "vinldo01", ldo0, SUPPLYV1, 5, 3, ENC, 0, END, 0), 184 248 TPS6586X_LDO(LDO_3, "vinldo23", ldo, SUPPLYV4, 0, 3, ENC, 2, END, 2), 185 - TPS6586X_LDO(LDO_5, NULL, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6), 249 + TPS6586X_LDO(LDO_5, "REG-SYS", ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6), 186 250 TPS6586X_LDO(LDO_6, "vinldo678", ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4), 187 251 TPS6586X_LDO(LDO_7, "vinldo678", ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5), 188 252 TPS6586X_LDO(LDO_8, "vinldo678", ldo, SUPPLYV2, 5, 3, ENC, 6, END, 6), 189 253 TPS6586X_LDO(LDO_9, "vinldo9", ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7), 190 - TPS6586X_LDO(LDO_RTC, NULL, ldo, SUPPLYV4, 3, 3, V4, 7, V4, 7), 254 + TPS6586X_LDO(LDO_RTC, "REG-SYS", ldo, SUPPLYV4, 3, 3, V4, 7, V4, 7), 191 255 TPS6586X_LDO(LDO_1, "vinldo01", dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1), 192 256 TPS6586X_LDO(SM_2, "vin-sm2", sm2, SUPPLYV2, 0, 5, ENC, 7, END, 7), 193 257
+51 -59
drivers/regulator/twl-regulator.c
··· 10 10 */ 11 11 12 12 #include <linux/module.h> 13 + #include <linux/string.h> 14 + #include <linux/slab.h> 13 15 #include <linux/init.h> 14 16 #include <linux/err.h> 15 17 #include <linux/platform_device.h> ··· 626 624 return info->min_mV * 1000; 627 625 } 628 626 629 - static int twlfixed_get_voltage(struct regulator_dev *rdev) 630 - { 631 - struct twlreg_info *info = rdev_get_drvdata(rdev); 632 - 633 - return info->min_mV * 1000; 634 - } 635 - 636 627 static struct regulator_ops twl4030fixed_ops = { 637 628 .list_voltage = twlfixed_list_voltage, 638 - 639 - .get_voltage = twlfixed_get_voltage, 640 629 641 630 .enable = twl4030reg_enable, 642 631 .disable = twl4030reg_disable, ··· 641 648 static struct regulator_ops twl6030fixed_ops = { 642 649 .list_voltage = twlfixed_list_voltage, 643 650 644 - .get_voltage = twlfixed_get_voltage, 645 - 646 651 .enable = twl6030reg_enable, 647 652 .disable = twl6030reg_disable, 648 653 .is_enabled = twl6030reg_is_enabled, 649 654 650 655 .set_mode = twl6030reg_set_mode, 651 656 652 - .get_status = twl6030reg_get_status, 653 - }; 654 - 655 - static struct regulator_ops twl6030_fixed_resource = { 656 - .enable = twl6030reg_enable, 657 - .disable = twl6030reg_disable, 658 - .is_enabled = twl6030reg_is_enabled, 659 657 .get_status = twl6030reg_get_status, 660 658 }; 661 659 ··· 741 757 return voltage; 742 758 } 743 759 744 - static int 745 - twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, 746 - unsigned int *selector) 760 + static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV, 761 + int max_uV) 747 762 { 748 - struct twlreg_info *info = rdev_get_drvdata(rdev); 749 - int vsel = 0; 763 + struct twlreg_info *info = rdev_get_drvdata(rdev); 764 + int vsel = 0; 750 765 751 766 switch (info->flags) { 752 767 case 0: 753 768 if (min_uV == 0) 754 769 vsel = 0; 755 770 else if ((min_uV >= 600000) && (min_uV <= 1300000)) { 756 - int calc_uV; 757 771 vsel = DIV_ROUND_UP(min_uV - 600000, 12500); 758 772 vsel++; 759 - calc_uV = twl6030smps_list_voltage(rdev, vsel); 760 - if (calc_uV > max_uV) 761 - return -EINVAL; 762 773 } 763 774 /* Values 1..57 for vsel are linear and can be calculated 764 775 * values 58..62 are non linear. 765 776 */ 766 - else if ((min_uV > 1900000) && (max_uV >= 2100000)) 777 + else if ((min_uV > 1900000) && (min_uV <= 2100000)) 767 778 vsel = 62; 768 - else if ((min_uV > 1800000) && (max_uV >= 1900000)) 779 + else if ((min_uV > 1800000) && (min_uV <= 1900000)) 769 780 vsel = 61; 770 - else if ((min_uV > 1500000) && (max_uV >= 1800000)) 781 + else if ((min_uV > 1500000) && (min_uV <= 1800000)) 771 782 vsel = 60; 772 - else if ((min_uV > 1350000) && (max_uV >= 1500000)) 783 + else if ((min_uV > 1350000) && (min_uV <= 1500000)) 773 784 vsel = 59; 774 - else if ((min_uV > 1300000) && (max_uV >= 1350000)) 785 + else if ((min_uV > 1300000) && (min_uV <= 1350000)) 775 786 vsel = 58; 776 787 else 777 788 return -EINVAL; ··· 775 796 if (min_uV == 0) 776 797 vsel = 0; 777 798 else if ((min_uV >= 700000) && (min_uV <= 1420000)) { 778 - int calc_uV; 779 799 vsel = DIV_ROUND_UP(min_uV - 700000, 12500); 780 800 vsel++; 781 - calc_uV = twl6030smps_list_voltage(rdev, vsel); 782 - if (calc_uV > max_uV) 783 - return -EINVAL; 784 801 } 785 802 /* Values 1..57 for vsel are linear and can be calculated 786 803 * values 58..62 are non linear. 787 804 */ 788 - else if ((min_uV > 1900000) && (max_uV >= 2100000)) 805 + else if ((min_uV > 1900000) && (min_uV <= 2100000)) 789 806 vsel = 62; 790 - else if ((min_uV > 1800000) && (max_uV >= 1900000)) 807 + else if ((min_uV > 1800000) && (min_uV <= 1900000)) 791 808 vsel = 61; 792 - else if ((min_uV > 1350000) && (max_uV >= 1800000)) 809 + else if ((min_uV > 1350000) && (min_uV <= 1800000)) 793 810 vsel = 60; 794 - else if ((min_uV > 1350000) && (max_uV >= 1500000)) 811 + else if ((min_uV > 1350000) && (min_uV <= 1500000)) 795 812 vsel = 59; 796 - else if ((min_uV > 1300000) && (max_uV >= 1350000)) 813 + else if ((min_uV > 1300000) && (min_uV <= 1350000)) 797 814 vsel = 58; 798 815 else 799 816 return -EINVAL; ··· 805 830 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN: 806 831 if (min_uV == 0) { 807 832 vsel = 0; 808 - } else if ((min_uV >= 2161000) && (max_uV <= 4321000)) { 833 + } else if ((min_uV >= 2161000) && (min_uV <= 4321000)) { 809 834 vsel = DIV_ROUND_UP(min_uV - 2161000, 38600); 810 835 vsel++; 811 836 } 812 837 break; 813 838 } 814 839 815 - *selector = vsel; 840 + return vsel; 841 + } 842 + 843 + static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev, 844 + unsigned int selector) 845 + { 846 + struct twlreg_info *info = rdev_get_drvdata(rdev); 816 847 817 848 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS, 818 - vsel); 849 + selector); 819 850 } 820 851 821 852 static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev) ··· 833 852 834 853 static struct regulator_ops twlsmps_ops = { 835 854 .list_voltage = twl6030smps_list_voltage, 855 + .map_voltage = twl6030smps_map_voltage, 836 856 837 - .set_voltage = twl6030smps_set_voltage, 857 + .set_voltage_sel = twl6030smps_set_voltage_sel, 838 858 .get_voltage_sel = twl6030smps_get_voltage_sel, 839 859 840 860 .enable = twl6030reg_enable, ··· 858 876 0x0, TWL6030, twl6030fixed_ops) 859 877 860 878 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ 861 - static struct twlreg_info TWL4030_INFO_##label = { \ 879 + static const struct twlreg_info TWL4030_INFO_##label = { \ 862 880 .base = offset, \ 863 881 .id = num, \ 864 882 .table_len = ARRAY_SIZE(label##_VSEL_table), \ ··· 876 894 } 877 895 878 896 #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \ 879 - static struct twlreg_info TWL4030_INFO_##label = { \ 897 + static const struct twlreg_info TWL4030_INFO_##label = { \ 880 898 .base = offset, \ 881 899 .id = num, \ 882 900 .remap = remap_conf, \ ··· 891 909 } 892 910 893 911 #define TWL6030_ADJUSTABLE_SMPS(label) \ 894 - static struct twlreg_info TWL6030_INFO_##label = { \ 912 + static const struct twlreg_info TWL6030_INFO_##label = { \ 895 913 .desc = { \ 896 914 .name = #label, \ 897 915 .id = TWL6030_REG_##label, \ ··· 902 920 } 903 921 904 922 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 905 - static struct twlreg_info TWL6030_INFO_##label = { \ 923 + static const struct twlreg_info TWL6030_INFO_##label = { \ 906 924 .base = offset, \ 907 925 .min_mV = min_mVolts, \ 908 926 .max_mV = max_mVolts, \ ··· 917 935 } 918 936 919 937 #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ 920 - static struct twlreg_info TWL6025_INFO_##label = { \ 938 + static const struct twlreg_info TWL6025_INFO_##label = { \ 921 939 .base = offset, \ 922 940 .min_mV = min_mVolts, \ 923 941 .max_mV = max_mVolts, \ ··· 933 951 934 952 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ 935 953 family, operations) \ 936 - static struct twlreg_info TWLFIXED_INFO_##label = { \ 954 + static const struct twlreg_info TWLFIXED_INFO_##label = { \ 937 955 .base = offset, \ 938 956 .id = num, \ 939 957 .min_mV = mVolts, \ ··· 963 981 } 964 982 965 983 #define TWL6025_ADJUSTABLE_SMPS(label, offset) \ 966 - static struct twlreg_info TWLSMPS_INFO_##label = { \ 984 + static const struct twlreg_info TWLSMPS_INFO_##label = { \ 967 985 .base = offset, \ 968 986 .min_mV = 600, \ 969 987 .max_mV = 2100, \ ··· 1120 1138 { 1121 1139 int i, id; 1122 1140 struct twlreg_info *info; 1141 + const struct twlreg_info *template; 1123 1142 struct regulator_init_data *initdata; 1124 1143 struct regulation_constraints *c; 1125 1144 struct regulator_dev *rdev; ··· 1130 1147 1131 1148 match = of_match_device(twl_of_match, &pdev->dev); 1132 1149 if (match) { 1133 - info = match->data; 1134 - id = info->desc.id; 1150 + template = match->data; 1151 + id = template->desc.id; 1135 1152 initdata = of_get_regulator_init_data(&pdev->dev, 1136 1153 pdev->dev.of_node); 1137 1154 drvdata = NULL; 1138 1155 } else { 1139 1156 id = pdev->id; 1140 1157 initdata = pdev->dev.platform_data; 1141 - for (i = 0, info = NULL; i < ARRAY_SIZE(twl_of_match); i++) { 1142 - info = twl_of_match[i].data; 1143 - if (info && info->desc.id == id) 1158 + for (i = 0, template = NULL; i < ARRAY_SIZE(twl_of_match); i++) { 1159 + template = twl_of_match[i].data; 1160 + if (template && template->desc.id == id) 1144 1161 break; 1145 1162 } 1146 1163 if (i == ARRAY_SIZE(twl_of_match)) ··· 1151 1168 return -EINVAL; 1152 1169 } 1153 1170 1154 - if (!info) 1171 + if (!template) 1155 1172 return -ENODEV; 1156 1173 1157 1174 if (!initdata) 1158 1175 return -EINVAL; 1176 + 1177 + info = kmemdup(template, sizeof (*info), GFP_KERNEL); 1178 + if (!info) 1179 + return -ENOMEM; 1159 1180 1160 1181 if (drvdata) { 1161 1182 /* copy the driver data into regulator data */ ··· 1221 1234 if (IS_ERR(rdev)) { 1222 1235 dev_err(&pdev->dev, "can't register %s, %ld\n", 1223 1236 info->desc.name, PTR_ERR(rdev)); 1237 + kfree(info); 1224 1238 return PTR_ERR(rdev); 1225 1239 } 1226 1240 platform_set_drvdata(pdev, rdev); ··· 1243 1255 1244 1256 static int __devexit twlreg_remove(struct platform_device *pdev) 1245 1257 { 1246 - regulator_unregister(platform_get_drvdata(pdev)); 1258 + struct regulator_dev *rdev = platform_get_drvdata(pdev); 1259 + struct twlreg_info *info = rdev->reg_data; 1260 + 1261 + regulator_unregister(rdev); 1262 + kfree(info); 1247 1263 return 0; 1248 1264 } 1249 1265
+5 -6
drivers/regulator/wm831x-dcdc.c
··· 339 339 u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2; 340 340 int i; 341 341 342 - for (i = 0; i < ARRAY_SIZE(wm831x_dcdc_ilim); i++) { 342 + for (i = ARRAY_SIZE(wm831x_dcdc_ilim) - 1; i >= 0; i--) { 343 343 if ((min_uA <= wm831x_dcdc_ilim[i]) && 344 344 (wm831x_dcdc_ilim[i] <= max_uA)) 345 - break; 345 + return wm831x_set_bits(wm831x, reg, 346 + WM831X_DC1_HC_THR_MASK, 347 + i << WM831X_DC1_HC_THR_SHIFT); 346 348 } 347 - if (i == ARRAY_SIZE(wm831x_dcdc_ilim)) 348 - return -EINVAL; 349 349 350 - return wm831x_set_bits(wm831x, reg, WM831X_DC1_HC_THR_MASK, 351 - i << WM831X_DC1_HC_THR_SHIFT); 350 + return -EINVAL; 352 351 } 353 352 354 353 static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
+12
drivers/regulator/wm831x-ldo.c
··· 205 205 206 206 /* Is it reporting under voltage? */ 207 207 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); 208 + if (ret < 0) 209 + return ret; 208 210 if (ret & mask) 209 211 return REGULATOR_STATUS_ERROR; 210 212 ··· 239 237 .set_mode = wm831x_gp_ldo_set_mode, 240 238 .get_status = wm831x_gp_ldo_get_status, 241 239 .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode, 240 + .get_bypass = regulator_get_bypass_regmap, 241 + .set_bypass = regulator_set_bypass_regmap, 242 242 243 243 .is_enabled = regulator_is_enabled_regmap, 244 244 .enable = regulator_enable_regmap, ··· 297 293 ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK; 298 294 ldo->desc.enable_reg = WM831X_LDO_ENABLE; 299 295 ldo->desc.enable_mask = 1 << id; 296 + ldo->desc.bypass_reg = ldo->base; 297 + ldo->desc.bypass_mask = WM831X_LDO1_SWI; 300 298 301 299 config.dev = pdev->dev.parent; 302 300 if (pdata) ··· 475 469 476 470 /* Is it reporting under voltage? */ 477 471 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); 472 + if (ret < 0) 473 + return ret; 478 474 if (ret & mask) 479 475 return REGULATOR_STATUS_ERROR; 480 476 ··· 496 488 .get_mode = wm831x_aldo_get_mode, 497 489 .set_mode = wm831x_aldo_set_mode, 498 490 .get_status = wm831x_aldo_get_status, 491 + .set_bypass = regulator_set_bypass_regmap, 492 + .get_bypass = regulator_get_bypass_regmap, 499 493 500 494 .is_enabled = regulator_is_enabled_regmap, 501 495 .enable = regulator_enable_regmap, ··· 554 544 ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK; 555 545 ldo->desc.enable_reg = WM831X_LDO_ENABLE; 556 546 ldo->desc.enable_mask = 1 << id; 547 + ldo->desc.bypass_reg = ldo->base; 548 + ldo->desc.bypass_mask = WM831X_LDO7_SWI; 557 549 558 550 config.dev = pdev->dev.parent; 559 551 if (pdata)
+1 -6
drivers/regulator/wm8400-regulator.c
··· 120 120 121 121 case REGULATOR_MODE_IDLE: 122 122 /* Datasheet: standby */ 123 - ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 124 - WM8400_DC1_ACTIVE, 0); 125 - if (ret != 0) 126 - return ret; 127 123 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 128 - WM8400_DC1_SLEEP, 0); 129 - 124 + WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, 0); 130 125 default: 131 126 return -EINVAL; 132 127 }
+1
include/linux/mfd/max77686.h
··· 74 74 struct max77686_regulator_data { 75 75 int id; 76 76 struct regulator_init_data *initdata; 77 + struct device_node *of_node; 77 78 }; 78 79 79 80 enum max77686_opmode {
+1
include/linux/mfd/tps6586x.h
··· 14 14 #define TPS6586X_SLEW_RATE_MASK 0x07 15 15 16 16 enum { 17 + TPS6586X_ID_SYS, 17 18 TPS6586X_ID_SM_0, 18 19 TPS6586X_ID_SM_1, 19 20 TPS6586X_ID_SM_2,
+15
include/linux/regulator/consumer.h
··· 177 177 unsigned int regulator_get_mode(struct regulator *regulator); 178 178 int regulator_set_optimum_mode(struct regulator *regulator, int load_uA); 179 179 180 + int regulator_allow_bypass(struct regulator *regulator, bool allow); 181 + 180 182 /* regulator notifier block */ 181 183 int regulator_register_notifier(struct regulator *regulator, 182 184 struct notifier_block *nb); ··· 330 328 return REGULATOR_MODE_NORMAL; 331 329 } 332 330 331 + static inline int regulator_allow_bypass(struct regulator *regulator, 332 + bool allow) 333 + { 334 + return 0; 335 + } 336 + 333 337 static inline int regulator_register_notifier(struct regulator *regulator, 334 338 struct notifier_block *nb) 335 339 { ··· 359 351 } 360 352 361 353 #endif 354 + 355 + static inline int regulator_set_voltage_tol(struct regulator *regulator, 356 + int new_uV, int tol_uV) 357 + { 358 + return regulator_set_voltage(regulator, 359 + new_uV - tol_uV, new_uV + tol_uV); 360 + } 362 361 363 362 #endif
+17 -1
include/linux/regulator/driver.h
··· 32 32 REGULATOR_STATUS_NORMAL, 33 33 REGULATOR_STATUS_IDLE, 34 34 REGULATOR_STATUS_STANDBY, 35 + /* The regulator is enabled but not regulating */ 36 + REGULATOR_STATUS_BYPASS, 35 37 /* in case that any other status doesn't apply */ 36 38 REGULATOR_STATUS_UNDEFINED, 37 39 }; ··· 60 58 * regulator_desc.n_voltages. Voltages may be reported in any order. 61 59 * 62 60 * @set_current_limit: Configure a limit for a current-limited regulator. 61 + * The driver should select the current closest to max_uA. 63 62 * @get_current_limit: Get the configured limit for a current-limited regulator. 64 63 * 65 64 * @set_mode: Set the configured operating mode for the regulator. ··· 69 66 * REGULATOR_STATUS value (or negative errno) 70 67 * @get_optimum_mode: Get the most efficient operating mode for the regulator 71 68 * when running with the specified parameters. 69 + * 70 + * @set_bypass: Set the regulator in bypass mode. 71 + * @get_bypass: Get the regulator bypass mode state. 72 72 * 73 73 * @enable_time: Time taken for the regulator voltage output voltage to 74 74 * stabilise after being enabled, in microseconds. ··· 138 132 /* get most efficient regulator operating mode for load */ 139 133 unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, 140 134 int output_uV, int load_uA); 135 + 136 + /* control and report on bypass mode */ 137 + int (*set_bypass)(struct regulator_dev *dev, bool enable); 138 + int (*get_bypass)(struct regulator_dev *dev, bool *enable); 141 139 142 140 /* the operations below are for configuration of regulator state when 143 141 * its parent PMIC enters a global STANDBY/HIBERNATE state */ ··· 215 205 unsigned int vsel_mask; 216 206 unsigned int enable_reg; 217 207 unsigned int enable_mask; 208 + unsigned int bypass_reg; 209 + unsigned int bypass_mask; 218 210 219 211 unsigned int enable_time; 220 212 }; ··· 233 221 * @driver_data: private regulator data 234 222 * @of_node: OpenFirmware node to parse for device tree bindings (may be 235 223 * NULL). 236 - * @regmap: regmap to use for core regmap helpers 224 + * @regmap: regmap to use for core regmap helpers if dev_get_regulator() is 225 + * insufficient. 237 226 * @ena_gpio: GPIO controlling regulator enable. 238 227 * @ena_gpio_invert: Sense for GPIO enable control. 239 228 * @ena_gpio_flags: Flags to use when calling gpio_request_one() ··· 266 253 int exclusive; 267 254 u32 use_count; 268 255 u32 open_count; 256 + u32 bypass_count; 269 257 270 258 /* lists we belong to */ 271 259 struct list_head list; /* list of all regulators */ ··· 324 310 int regulator_set_voltage_time_sel(struct regulator_dev *rdev, 325 311 unsigned int old_selector, 326 312 unsigned int new_selector); 313 + int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable); 314 + int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable); 327 315 328 316 void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); 329 317
+60
include/linux/regulator/fan53555.h
··· 1 + /* 2 + * fan53555.h - Fairchild Regulator FAN53555 Driver 3 + * 4 + * Copyright (C) 2012 Marvell Technology Ltd. 5 + * Yunfan Zhang <yfzhang@marvell.com> 6 + * 7 + * This package is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + * 11 + */ 12 + 13 + #ifndef __FAN53555_H__ 14 + 15 + /* VSEL ID */ 16 + enum { 17 + FAN53555_VSEL_ID_0 = 0, 18 + FAN53555_VSEL_ID_1, 19 + }; 20 + 21 + /* Transition slew rate limiting from a low to high voltage. 22 + * ----------------------- 23 + * Bin |Slew Rate(mV/uS) 24 + * ------|---------------- 25 + * 000 | 64.00 26 + * ------|---------------- 27 + * 001 | 32.00 28 + * ------|---------------- 29 + * 010 | 16.00 30 + * ------|---------------- 31 + * 011 | 8.00 32 + * ------|---------------- 33 + * 100 | 4.00 34 + * ------|---------------- 35 + * 101 | 2.00 36 + * ------|---------------- 37 + * 110 | 1.00 38 + * ------|---------------- 39 + * 111 | 0.50 40 + * ----------------------- 41 + */ 42 + enum { 43 + FAN53555_SLEW_RATE_64MV = 0, 44 + FAN53555_SLEW_RATE_32MV, 45 + FAN53555_SLEW_RATE_16MV, 46 + FAN53555_SLEW_RATE_8MV, 47 + FAN53555_SLEW_RATE_4MV, 48 + FAN53555_SLEW_RATE_2MV, 49 + FAN53555_SLEW_RATE_1MV, 50 + FAN53555_SLEW_RATE_0_5MV, 51 + }; 52 + 53 + struct fan53555_platform_data { 54 + struct regulator_init_data *regulator; 55 + unsigned int slew_rate; 56 + /* Sleep VSEL ID */ 57 + unsigned int sleep_vsel_id; 58 + }; 59 + 60 + #endif /* __FAN53555_H__ */
+2
include/linux/regulator/machine.h
··· 32 32 * board/machine. 33 33 * STATUS: Regulator can be enabled and disabled. 34 34 * DRMS: Dynamic Regulator Mode Switching is enabled for this regulator. 35 + * BYPASS: Regulator can be put into bypass mode 35 36 */ 36 37 37 38 #define REGULATOR_CHANGE_VOLTAGE 0x1 ··· 40 39 #define REGULATOR_CHANGE_MODE 0x4 41 40 #define REGULATOR_CHANGE_STATUS 0x8 42 41 #define REGULATOR_CHANGE_DRMS 0x10 42 + #define REGULATOR_CHANGE_BYPASS 0x20 43 43 44 44 /** 45 45 * struct regulator_state - regulator state during low power system states