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

Merge tag 'regulator-v4.4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator

Pull regulator updates from Mark Brown:
"This is quite a quiet release in terms of volume of patches but it
includes a couple of really nice core changes - the work Sascha has
done in particular is something I've wanted to get done for a long
time but just never got round to myself.

Highlights include:

- Support from Sascha Hauer for setting the voltage of parent
supplies based on requests from their children. This is used both
to allow set_voltage() to work through a dumb switch and to improve
the efficiency of systems where DCDCs are used to supply LDOs by
minimising the voltage drop over the LDOs.

- Removal of regulator_list by Tomeu Vizoso, meaning we're not
duplicating the device list maintained by the driver core.

- Support for Wolfson/Cirrus WM8998 and WM1818"

* tag 'regulator-v4.4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (29 commits)
regulator: Use regulator_lock_supply() for get_voltage() too
regulator: arizona: Add regulator specific device tree binding document
regulator: stw481x: compile on COMPILE_TEST
regulator: qcom-smd: Correct set_load() unit
regulator: core: Propagate voltage changes to supply regulators
regulator: core: Factor out regulator_map_voltage
regulator: i.MX anatop: Allow supply regulator
regulator: introduce min_dropout_uV
regulator: core: create unlocked version of regulator_set_voltage
regulator: arizona-ldo1: Fix handling of GPIO 0
regulator: da9053: Update regulator for DA9053 BC silicon support
regulator: max77802: Separate sections for nodes and properties
regulator: max77802: Add input supply properties to DT binding doc
regulator: axp20x: set supply names for AXP22X DC1SW/DC5LDO internally
regulator: axp20x: Drop AXP221 DC1SW and DC5LDO regulator supplies from bindings
mfd: tps6105x: Use i2c regmap to access registers
regulator: act8865: add DT binding for property "active-semi,vsel-high"
regulator: act8865: support output voltage by VSET2[] bits
regulator: arizona: add support for WM8998 and WM1814
regulator: core: create unlocked version of regulator_list_voltage
...

+733 -460
+2 -2
Documentation/devicetree/bindings/mfd/axp20x.txt
··· 60 60 DCDC3 : DC-DC buck : vin3-supply 61 61 DCDC4 : DC-DC buck : vin4-supply 62 62 DCDC5 : DC-DC buck : vin5-supply 63 - DC1SW : On/Off Switch : dcdc1-supply : DCDC1 secondary output 64 - DC5LDO : LDO : dcdc5-supply : input from DCDC5 63 + DC1SW : On/Off Switch : : DCDC1 secondary output 64 + DC5LDO : LDO : : input from DCDC5 65 65 ALDO1 : LDO : aldoin-supply : shared supply 66 66 ALDO2 : LDO : aldoin-supply : shared supply 67 67 ALDO3 : LDO : aldoin-supply : shared supply
+3
Documentation/devicetree/bindings/regulator/act8865-regulator.txt
··· 8 8 Optional properties: 9 9 - system-power-controller: Telling whether or not this pmic is controlling 10 10 the system power. See Documentation/devicetree/bindings/power/power-controller.txt . 11 + - active-semi,vsel-high: Indicates the VSEL pin is high. 12 + If this property is missing, assume the VSEL pin is low(0). 11 13 12 14 Optional input supply properties: 13 15 - for act8600: ··· 51 49 pmic: act8865@5b { 52 50 compatible = "active-semi,act8865"; 53 51 reg = <0x5b>; 52 + active-semi,vsel-high; 54 53 status = "disabled"; 55 54 56 55 regulators {
+1
Documentation/devicetree/bindings/regulator/anatop-regulator.txt
··· 13 13 - anatop-delay-reg-offset: Anatop MFD step time register offset 14 14 - anatop-delay-bit-shift: Bit shift for the step time register 15 15 - anatop-delay-bit-width: Number of bits used in the step time register 16 + - vin-supply: The supply for this regulator 16 17 17 18 Any property defined as part of the core regulator 18 19 binding, defined in regulator.txt, can also be used.
+17
Documentation/devicetree/bindings/regulator/arizona-regulator.txt
··· 1 + Cirrus Logic Arizona class audio SoCs 2 + 3 + These devices are audio SoCs with extensive digital capabilities and a range 4 + of analogue I/O. 5 + 6 + This document lists regulator specific bindings, see the primary binding 7 + document: 8 + ../mfd/arizona.txt 9 + 10 + Optional properties: 11 + - wlf,ldoena : GPIO specifier for the GPIO controlling LDOENA 12 + 13 + Optional subnodes: 14 + - ldo1 : Initial data for the LDO1 regulator, as covered in 15 + Documentation/devicetree/bindings/regulator/regulator.txt 16 + - micvdd : Initial data for the MICVDD regulator, as covered in 17 + Documentation/devicetree/bindings/regulator/regulator.txt
+24 -1
Documentation/devicetree/bindings/regulator/max77802.txt
··· 8 8 9 9 Following properties should be present in main device node of the MFD chip. 10 10 11 - Optional node: 11 + Optional properties: 12 + - inb1-supply: The input supply for BUCK1 13 + - inb2-supply: The input supply for BUCK2 14 + - inb3-supply: The input supply for BUCK3 15 + - inb4-supply: The input supply for BUCK4 16 + - inb5-supply: The input supply for BUCK5 17 + - inb6-supply: The input supply for BUCK6 18 + - inb7-supply: The input supply for BUCK7 19 + - inb8-supply: The input supply for BUCK8 20 + - inb9-supply: The input supply for BUCK9 21 + - inb10-supply: The input supply for BUCK10 22 + - inl1-supply: The input supply for LDO8 and LDO15 23 + - inl2-supply: The input supply for LDO17, LDO27, LDO30 and LDO35 24 + - inl3-supply: The input supply for LDO3, LDO5, LDO6 and LDO7 25 + - inl4-supply: The input supply for LDO10, LDO11, LDO13 and LDO14 26 + - inl5-supply: The input supply for LDO9 and LDO19 27 + - inl6-supply: The input supply for LDO4, LDO21, LDO24 and LDO33 28 + - inl7-supply: The input supply for LDO18, LDO20, LDO28 and LDO29 29 + - inl9-supply: The input supply for LDO12, LDO23, LDO25, LDO26, LDO32 and LDO34 30 + - inl10-supply: The input supply for LDO1 and LDO2 31 + 32 + Optional nodes: 12 33 - regulators : The regulators of max77802 have to be instantiated 13 34 under subnode named "regulators" using the following format. 14 35 ··· 78 57 reg = <0x09>; 79 58 #address-cells = <1>; 80 59 #size-cells = <0>; 60 + 61 + inb1-supply = <&parent_reg>; 81 62 82 63 regulators { 83 64 ldo1_reg: LDO1 {
+1
Documentation/devicetree/bindings/regulator/regulator.txt
··· 11 11 - regulator-always-on: boolean, regulator should never be disabled 12 12 - regulator-boot-on: bootloader/firmware enabled regulator 13 13 - regulator-allow-bypass: allow the regulator to go into bypass mode 14 + - regulator-allow-set-load: allow the regulator performance level to be configured 14 15 - <name>-supply: phandle to the parent supply/regulator node 15 16 - regulator-ramp-delay: ramp delay for regulator(in uV/uS) 16 17 For hardware which supports disabling ramp rate, it should be explicitly
+60
Documentation/devicetree/bindings/regulator/tps65023.txt
··· 1 + TPS65023 family of regulators 2 + 3 + Required properties: 4 + - compatible: Must be one of the following. 5 + "ti,tps65020", 6 + "ti,tps65021", 7 + "ti,tps65023", 8 + - reg: I2C slave address 9 + - regulators: list of regulators provided by this controller, must be named 10 + after their hardware counterparts: VDCDC[1-3] and LDO[1-2] 11 + - regulators: This is the list of child nodes that specify the regulator 12 + initialization data for defined regulators. The definition for each of 13 + these nodes is defined using the standard binding for regulators found at 14 + Documentation/devicetree/bindings/regulator/regulator.txt. 15 + 16 + Each regulator is defined using the standard binding for regulators. 17 + 18 + Example: 19 + 20 + tps65023@48 { 21 + compatible = "ti,tps65023"; 22 + reg = <0x48>; 23 + 24 + regulators { 25 + VDCDC1 { 26 + regulator-name = "vdd_mpu"; 27 + regulator-always-on; 28 + regulator-min-microvolt = <1200000>; 29 + regulator-max-microvolt = <1200000>; 30 + }; 31 + 32 + VDCDC2 { 33 + regulator-name = "vdd_core"; 34 + regulator-always-on; 35 + regulator-min-microvolt = <3300000>; 36 + regulator-max-microvolt = <3300000>; 37 + }; 38 + 39 + VDCDC3 { 40 + regulator-name = "vdd_io"; 41 + regulator-always-on; 42 + regulator-min-microvolt = <1800000>; 43 + regulator-max-microvolt = <1800000>; 44 + }; 45 + 46 + LDO1 { 47 + regulator-name = "vdd_usb18"; 48 + regulator-always-on; 49 + regulator-min-microvolt = <1800000>; 50 + regulator-max-microvolt = <1800000>; 51 + }; 52 + 53 + LDO2 { 54 + regulator-name = "vdd_usb33"; 55 + regulator-always-on; 56 + regulator-min-microvolt = <3300000>; 57 + regulator-max-microvolt = <3300000>; 58 + }; 59 + }; 60 + };
+13 -65
drivers/mfd/tps6105x.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/init.h> 18 18 #include <linux/i2c.h> 19 - #include <linux/mutex.h> 19 + #include <linux/regmap.h> 20 20 #include <linux/gpio.h> 21 21 #include <linux/spinlock.h> 22 22 #include <linux/slab.h> ··· 25 25 #include <linux/mfd/core.h> 26 26 #include <linux/mfd/tps6105x.h> 27 27 28 - int tps6105x_set(struct tps6105x *tps6105x, u8 reg, u8 value) 29 - { 30 - int ret; 31 - 32 - ret = mutex_lock_interruptible(&tps6105x->lock); 33 - if (ret) 34 - return ret; 35 - ret = i2c_smbus_write_byte_data(tps6105x->client, reg, value); 36 - mutex_unlock(&tps6105x->lock); 37 - if (ret < 0) 38 - return ret; 39 - 40 - return 0; 41 - } 42 - EXPORT_SYMBOL(tps6105x_set); 43 - 44 - int tps6105x_get(struct tps6105x *tps6105x, u8 reg, u8 *buf) 45 - { 46 - int ret; 47 - 48 - ret = mutex_lock_interruptible(&tps6105x->lock); 49 - if (ret) 50 - return ret; 51 - ret = i2c_smbus_read_byte_data(tps6105x->client, reg); 52 - mutex_unlock(&tps6105x->lock); 53 - if (ret < 0) 54 - return ret; 55 - 56 - *buf = ret; 57 - return 0; 58 - } 59 - EXPORT_SYMBOL(tps6105x_get); 60 - 61 - /* 62 - * Masks off the bits in the mask and sets the bits in the bitvalues 63 - * parameter in one atomic operation 64 - */ 65 - int tps6105x_mask_and_set(struct tps6105x *tps6105x, u8 reg, 66 - u8 bitmask, u8 bitvalues) 67 - { 68 - int ret; 69 - u8 regval; 70 - 71 - ret = mutex_lock_interruptible(&tps6105x->lock); 72 - if (ret) 73 - return ret; 74 - ret = i2c_smbus_read_byte_data(tps6105x->client, reg); 75 - if (ret < 0) 76 - goto fail; 77 - regval = ret; 78 - regval = (~bitmask & regval) | (bitmask & bitvalues); 79 - ret = i2c_smbus_write_byte_data(tps6105x->client, reg, regval); 80 - fail: 81 - mutex_unlock(&tps6105x->lock); 82 - if (ret < 0) 83 - return ret; 84 - 85 - return 0; 86 - } 87 - EXPORT_SYMBOL(tps6105x_mask_and_set); 28 + static struct regmap_config tps6105x_regmap_config = { 29 + .reg_bits = 8, 30 + .val_bits = 8, 31 + .max_register = TPS6105X_REG_3, 32 + }; 88 33 89 34 static int tps6105x_startup(struct tps6105x *tps6105x) 90 35 { 91 36 int ret; 92 - u8 regval; 37 + unsigned int regval; 93 38 94 - ret = tps6105x_get(tps6105x, TPS6105X_REG_0, &regval); 39 + ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, &regval); 95 40 if (ret) 96 41 return ret; 97 42 switch (regval >> TPS6105X_REG0_MODE_SHIFT) { ··· 90 145 if (!tps6105x) 91 146 return -ENOMEM; 92 147 148 + tps6105x->regmap = devm_regmap_init_i2c(client, &tps6105x_regmap_config); 149 + if (IS_ERR(tps6105x->regmap)) 150 + return PTR_ERR(tps6105x->regmap); 151 + 93 152 i2c_set_clientdata(client, tps6105x); 94 153 tps6105x->client = client; 95 154 pdata = dev_get_platdata(&client->dev); 96 155 tps6105x->pdata = pdata; 97 - mutex_init(&tps6105x->lock); 98 156 99 157 ret = tps6105x_startup(tps6105x); 100 158 if (ret) { ··· 146 198 mfd_remove_devices(&client->dev); 147 199 148 200 /* Put chip in shutdown mode */ 149 - tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0, 201 + regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0, 150 202 TPS6105X_REG0_MODE_MASK, 151 203 TPS6105X_MODE_SHUTDOWN << TPS6105X_REG0_MODE_SHIFT); 152 204
+1 -1
drivers/regulator/Kconfig
··· 627 627 628 628 config REGULATOR_STW481X_VMMC 629 629 bool "ST Microelectronics STW481X VMMC regulator" 630 - depends on MFD_STW481X 630 + depends on MFD_STW481X || COMPILE_TEST 631 631 default y if MFD_STW481X 632 632 help 633 633 This driver supports the internal VMMC regulator in the STw481x
+22 -2
drivers/regulator/act8865-regulator.c
··· 261 261 ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"), 262 262 }; 263 263 264 + static const struct regulator_desc act8865_alt_regulators[] = { 265 + ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET2, "vp1"), 266 + ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET2, "vp2"), 267 + ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET2, "vp3"), 268 + ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"), 269 + ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"), 270 + ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"), 271 + ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"), 272 + }; 273 + 264 274 #ifdef CONFIG_OF 265 275 static const struct of_device_id act8865_dt_ids[] = { 266 276 { .compatible = "active-semi,act8600", .data = (void *)ACT8600 }, ··· 423 413 struct act8865 *act8865; 424 414 unsigned long type; 425 415 int off_reg, off_mask; 416 + int voltage_select = 0; 426 417 427 418 pdata = dev_get_platdata(dev); 428 419 ··· 435 424 return -ENODEV; 436 425 437 426 type = (unsigned long) id->data; 427 + 428 + voltage_select = !!of_get_property(dev->of_node, 429 + "active-semi,vsel-high", 430 + NULL); 438 431 } else { 439 432 type = i2c_id->driver_data; 440 433 } ··· 457 442 off_mask = ACT8846_OFF_SYSMASK; 458 443 break; 459 444 case ACT8865: 460 - regulators = act8865_regulators; 461 - num_regulators = ARRAY_SIZE(act8865_regulators); 445 + if (voltage_select) { 446 + regulators = act8865_alt_regulators; 447 + num_regulators = ARRAY_SIZE(act8865_alt_regulators); 448 + } else { 449 + regulators = act8865_regulators; 450 + num_regulators = ARRAY_SIZE(act8865_regulators); 451 + } 462 452 off_reg = ACT8865_SYS_CTRL; 463 453 off_mask = ACT8865_MSTROFF; 464 454 break;
+3
drivers/regulator/anatop-regulator.c
··· 30 30 #include <linux/regmap.h> 31 31 #include <linux/regulator/driver.h> 32 32 #include <linux/regulator/of_regulator.h> 33 + #include <linux/regulator/machine.h> 33 34 34 35 #define LDO_RAMP_UP_UNIT_IN_CYCLES 64 /* 64 cycles per step */ 35 36 #define LDO_RAMP_UP_FREQ_IN_MHZ 24 /* cycle based on 24M OSC */ ··· 200 199 rdesc->owner = THIS_MODULE; 201 200 202 201 initdata = of_get_regulator_init_data(dev, np, rdesc); 202 + initdata->supply_regulator = "vin"; 203 203 sreg->initdata = initdata; 204 204 205 205 anatop_np = of_get_parent(np); ··· 264 262 rdesc->vsel_reg = sreg->control_reg; 265 263 rdesc->vsel_mask = ((1 << sreg->vol_bit_width) - 1) << 266 264 sreg->vol_bit_shift; 265 + rdesc->min_dropout_uV = 125000; 267 266 268 267 config.dev = &pdev->dev; 269 268 config.init_data = initdata;
+15 -5
drivers/regulator/arizona-ldo1.c
··· 17 17 #include <linux/bitops.h> 18 18 #include <linux/err.h> 19 19 #include <linux/of.h> 20 + #include <linux/of_gpio.h> 20 21 #include <linux/platform_device.h> 21 22 #include <linux/regulator/driver.h> 22 23 #include <linux/regulator/machine.h> ··· 190 189 { 191 190 struct arizona_pdata *pdata = &arizona->pdata; 192 191 struct arizona_ldo1 *ldo1 = config->driver_data; 192 + struct device_node *np = arizona->dev->of_node; 193 193 struct device_node *init_node, *dcvdd_node; 194 194 struct regulator_init_data *init_data; 195 195 196 - pdata->ldoena = arizona_of_get_named_gpio(arizona, "wlf,ldoena", true); 196 + pdata->ldoena = of_get_named_gpio(np, "wlf,ldoena", 0); 197 + if (pdata->ldoena < 0) { 198 + dev_warn(arizona->dev, 199 + "LDOENA GPIO property missing/malformed: %d\n", 200 + pdata->ldoena); 201 + pdata->ldoena = 0; 202 + } else { 203 + config->ena_gpio_initialized = true; 204 + } 197 205 198 - init_node = of_get_child_by_name(arizona->dev->of_node, "ldo1"); 199 - dcvdd_node = of_parse_phandle(arizona->dev->of_node, "DCVDD-supply", 0); 206 + init_node = of_get_child_by_name(np, "ldo1"); 207 + dcvdd_node = of_parse_phandle(np, "DCVDD-supply", 0); 200 208 201 209 if (init_node) { 202 210 config->of_node = init_node; ··· 255 245 switch (arizona->type) { 256 246 case WM5102: 257 247 case WM8997: 248 + case WM8998: 249 + case WM1814: 258 250 desc = &arizona_ldo1_hc; 259 251 ldo1->init_data = arizona_ldo1_dvfs; 260 252 break; ··· 284 272 ret = arizona_ldo1_of_get_pdata(arizona, &config, desc); 285 273 if (ret < 0) 286 274 return ret; 287 - 288 - config.ena_gpio_initialized = true; 289 275 } 290 276 } 291 277
+50 -4
drivers/regulator/axp20x-regulator.c
··· 196 196 AXP_DESC(AXP22X, DCDC5, "dcdc5", "vin5", 1000, 2550, 50, 197 197 AXP22X_DCDC5_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL1, BIT(5)), 198 198 /* secondary switchable output of DCDC1 */ 199 - AXP_DESC_SW(AXP22X, DC1SW, "dc1sw", "dcdc1", 1600, 3400, 100, 199 + AXP_DESC_SW(AXP22X, DC1SW, "dc1sw", NULL, 1600, 3400, 100, 200 200 AXP22X_DCDC1_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL2, BIT(7)), 201 201 /* LDO regulator internally chained to DCDC5 */ 202 - AXP_DESC(AXP22X, DC5LDO, "dc5ldo", "dcdc5", 700, 1400, 100, 202 + AXP_DESC(AXP22X, DC5LDO, "dc5ldo", NULL, 700, 1400, 100, 203 203 AXP22X_DC5LDO_V_OUT, 0x7, AXP22X_PWR_OUT_CTRL1, BIT(0)), 204 204 AXP_DESC(AXP22X, ALDO1, "aldo1", "aldoin", 700, 3300, 100, 205 205 AXP22X_ALDO1_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL1, BIT(6)), ··· 350 350 }; 351 351 int ret, i, nregulators; 352 352 u32 workmode; 353 + const char *axp22x_dc1_name = axp22x_regulators[AXP22X_DCDC1].name; 354 + const char *axp22x_dc5_name = axp22x_regulators[AXP22X_DCDC5].name; 353 355 354 356 switch (axp20x->variant) { 355 357 case AXP202_ID: ··· 373 371 axp20x_regulator_parse_dt(pdev); 374 372 375 373 for (i = 0; i < nregulators; i++) { 376 - rdev = devm_regulator_register(&pdev->dev, &regulators[i], 377 - &config); 374 + const struct regulator_desc *desc = &regulators[i]; 375 + struct regulator_desc *new_desc; 376 + 377 + /* 378 + * Regulators DC1SW and DC5LDO are connected internally, 379 + * so we have to handle their supply names separately. 380 + * 381 + * We always register the regulators in proper sequence, 382 + * so the supply names are correctly read. See the last 383 + * part of this loop to see where we save the DT defined 384 + * name. 385 + */ 386 + if (regulators == axp22x_regulators) { 387 + if (i == AXP22X_DC1SW) { 388 + new_desc = devm_kzalloc(&pdev->dev, 389 + sizeof(*desc), 390 + GFP_KERNEL); 391 + *new_desc = regulators[i]; 392 + new_desc->supply_name = axp22x_dc1_name; 393 + desc = new_desc; 394 + } else if (i == AXP22X_DC5LDO) { 395 + new_desc = devm_kzalloc(&pdev->dev, 396 + sizeof(*desc), 397 + GFP_KERNEL); 398 + *new_desc = regulators[i]; 399 + new_desc->supply_name = axp22x_dc5_name; 400 + desc = new_desc; 401 + } 402 + } 403 + 404 + rdev = devm_regulator_register(&pdev->dev, desc, &config); 378 405 if (IS_ERR(rdev)) { 379 406 dev_err(&pdev->dev, "Failed to register %s\n", 380 407 regulators[i].name); ··· 418 387 if (axp20x_set_dcdc_workmode(rdev, i, workmode)) 419 388 dev_err(&pdev->dev, "Failed to set workmode on %s\n", 420 389 rdev->desc->name); 390 + } 391 + 392 + /* 393 + * Save AXP22X DCDC1 / DCDC5 regulator names for later. 394 + */ 395 + if (regulators == axp22x_regulators) { 396 + /* Can we use rdev->constraints->name instead? */ 397 + if (i == AXP22X_DCDC1) 398 + of_property_read_string(rdev->dev.of_node, 399 + "regulator-name", 400 + &axp22x_dc1_name); 401 + else if (i == AXP22X_DCDC5) 402 + of_property_read_string(rdev->dev.of_node, 403 + "regulator-name", 404 + &axp22x_dc5_name); 421 405 } 422 406 } 423 407
+1 -1
drivers/regulator/bcm590xx-regulator.c
··· 244 244 break; 245 245 case BCM590XX_REG_VBUS: 246 246 reg = BCM590XX_OTG_CTRL; 247 - }; 247 + } 248 248 249 249 250 250 return reg;
+350 -168
drivers/regulator/core.c
··· 51 51 pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) 52 52 53 53 static DEFINE_MUTEX(regulator_list_mutex); 54 - static LIST_HEAD(regulator_list); 55 54 static LIST_HEAD(regulator_map_list); 56 55 static LIST_HEAD(regulator_ena_gpio_list); 57 56 static LIST_HEAD(regulator_supply_alias_list); 58 57 static bool has_full_constraints; 59 58 60 59 static struct dentry *debugfs_root; 60 + 61 + static struct class regulator_class; 61 62 62 63 /* 63 64 * struct regulator_map ··· 133 132 } 134 133 135 134 /** 135 + * regulator_lock_supply - lock a regulator and its supplies 136 + * @rdev: regulator source 137 + */ 138 + static void regulator_lock_supply(struct regulator_dev *rdev) 139 + { 140 + struct regulator *supply; 141 + int i = 0; 142 + 143 + while (1) { 144 + mutex_lock_nested(&rdev->mutex, i++); 145 + supply = rdev->supply; 146 + 147 + if (!rdev->supply) 148 + return; 149 + 150 + rdev = supply->rdev; 151 + } 152 + } 153 + 154 + /** 155 + * regulator_unlock_supply - unlock a regulator and its supplies 156 + * @rdev: regulator source 157 + */ 158 + static void regulator_unlock_supply(struct regulator_dev *rdev) 159 + { 160 + struct regulator *supply; 161 + 162 + while (1) { 163 + mutex_unlock(&rdev->mutex); 164 + supply = rdev->supply; 165 + 166 + if (!rdev->supply) 167 + return; 168 + 169 + rdev = supply->rdev; 170 + } 171 + } 172 + 173 + /** 136 174 * of_get_regulator - get a regulator device node based on supply name 137 175 * @dev: Device pointer for the consumer (of regulator) device 138 176 * @supply: regulator supply name ··· 220 180 return -ENODEV; 221 181 } 222 182 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { 223 - rdev_err(rdev, "operation not allowed\n"); 183 + rdev_err(rdev, "voltage operation not allowed\n"); 224 184 return -EPERM; 225 185 } 226 186 ··· 280 240 return -ENODEV; 281 241 } 282 242 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { 283 - rdev_err(rdev, "operation not allowed\n"); 243 + rdev_err(rdev, "current operation not allowed\n"); 284 244 return -EPERM; 285 245 } 286 246 ··· 317 277 return -ENODEV; 318 278 } 319 279 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { 320 - rdev_err(rdev, "operation not allowed\n"); 280 + rdev_err(rdev, "mode operation not allowed\n"); 321 281 return -EPERM; 322 282 } 323 283 ··· 341 301 return -ENODEV; 342 302 } 343 303 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { 344 - rdev_dbg(rdev, "operation not allowed\n"); 304 + rdev_dbg(rdev, "drms operation not allowed\n"); 345 305 return -EPERM; 346 306 } 347 307 return 0; ··· 1365 1325 } 1366 1326 } 1367 1327 1328 + static int of_node_match(struct device *dev, const void *data) 1329 + { 1330 + return dev->of_node == data; 1331 + } 1332 + 1333 + static struct regulator_dev *of_find_regulator_by_node(struct device_node *np) 1334 + { 1335 + struct device *dev; 1336 + 1337 + dev = class_find_device(&regulator_class, NULL, np, of_node_match); 1338 + 1339 + return dev ? dev_to_rdev(dev) : NULL; 1340 + } 1341 + 1342 + static int regulator_match(struct device *dev, const void *data) 1343 + { 1344 + struct regulator_dev *r = dev_to_rdev(dev); 1345 + 1346 + return strcmp(rdev_get_name(r), data) == 0; 1347 + } 1348 + 1349 + static struct regulator_dev *regulator_lookup_by_name(const char *name) 1350 + { 1351 + struct device *dev; 1352 + 1353 + dev = class_find_device(&regulator_class, NULL, name, regulator_match); 1354 + 1355 + return dev ? dev_to_rdev(dev) : NULL; 1356 + } 1357 + 1358 + /** 1359 + * regulator_dev_lookup - lookup a regulator device. 1360 + * @dev: device for regulator "consumer". 1361 + * @supply: Supply name or regulator ID. 1362 + * @ret: 0 on success, -ENODEV if lookup fails permanently, -EPROBE_DEFER if 1363 + * lookup could succeed in the future. 1364 + * 1365 + * If successful, returns a struct regulator_dev that corresponds to the name 1366 + * @supply and with the embedded struct device refcount incremented by one, 1367 + * or NULL on failure. The refcount must be dropped by calling put_device(). 1368 + */ 1368 1369 static struct regulator_dev *regulator_dev_lookup(struct device *dev, 1369 1370 const char *supply, 1370 1371 int *ret) ··· 1421 1340 if (dev && dev->of_node) { 1422 1341 node = of_get_regulator(dev, supply); 1423 1342 if (node) { 1424 - list_for_each_entry(r, &regulator_list, list) 1425 - if (r->dev.parent && 1426 - node == r->dev.of_node) 1427 - return r; 1343 + r = of_find_regulator_by_node(node); 1344 + if (r) 1345 + return r; 1428 1346 *ret = -EPROBE_DEFER; 1429 1347 return NULL; 1430 1348 } else { ··· 1441 1361 if (dev) 1442 1362 devname = dev_name(dev); 1443 1363 1444 - list_for_each_entry(r, &regulator_list, list) 1445 - if (strcmp(rdev_get_name(r), supply) == 0) 1446 - return r; 1364 + r = regulator_lookup_by_name(supply); 1365 + if (r) 1366 + return r; 1447 1367 1368 + mutex_lock(&regulator_list_mutex); 1448 1369 list_for_each_entry(map, &regulator_map_list, list) { 1449 1370 /* If the mapping has a device set up it must match */ 1450 1371 if (map->dev_name && 1451 1372 (!devname || strcmp(map->dev_name, devname))) 1452 1373 continue; 1453 1374 1454 - if (strcmp(map->supply, supply) == 0) 1375 + if (strcmp(map->supply, supply) == 0 && 1376 + get_device(&map->regulator->dev)) { 1377 + mutex_unlock(&regulator_list_mutex); 1455 1378 return map->regulator; 1379 + } 1456 1380 } 1457 - 1381 + mutex_unlock(&regulator_list_mutex); 1458 1382 1459 1383 return NULL; 1460 1384 } ··· 1493 1409 1494 1410 if (have_full_constraints()) { 1495 1411 r = dummy_regulator_rdev; 1412 + get_device(&r->dev); 1496 1413 } else { 1497 1414 dev_err(dev, "Failed to resolve %s-supply for %s\n", 1498 1415 rdev->supply_name, rdev->desc->name); ··· 1503 1418 1504 1419 /* Recursively resolve the supply of the supply */ 1505 1420 ret = regulator_resolve_supply(r); 1506 - if (ret < 0) 1421 + if (ret < 0) { 1422 + put_device(&r->dev); 1507 1423 return ret; 1424 + } 1508 1425 1509 1426 ret = set_supply(rdev, r); 1510 - if (ret < 0) 1427 + if (ret < 0) { 1428 + put_device(&r->dev); 1511 1429 return ret; 1430 + } 1512 1431 1513 1432 /* Cascade always-on state to supply */ 1514 1433 if (_regulator_is_enabled(rdev) && rdev->supply) { ··· 1548 1459 else 1549 1460 ret = -EPROBE_DEFER; 1550 1461 1551 - mutex_lock(&regulator_list_mutex); 1552 - 1553 1462 rdev = regulator_dev_lookup(dev, id, &ret); 1554 1463 if (rdev) 1555 1464 goto found; ··· 1559 1472 * succeed, so, quit with appropriate error value 1560 1473 */ 1561 1474 if (ret && ret != -ENODEV) 1562 - goto out; 1475 + return regulator; 1563 1476 1564 1477 if (!devname) 1565 1478 devname = "deviceless"; ··· 1573 1486 devname, id); 1574 1487 1575 1488 rdev = dummy_regulator_rdev; 1489 + get_device(&rdev->dev); 1576 1490 goto found; 1577 1491 /* Don't log an error when called from regulator_get_optional() */ 1578 1492 } else if (!have_full_constraints() || exclusive) { 1579 1493 dev_warn(dev, "dummy supplies not allowed\n"); 1580 1494 } 1581 1495 1582 - mutex_unlock(&regulator_list_mutex); 1583 1496 return regulator; 1584 1497 1585 1498 found: 1586 1499 if (rdev->exclusive) { 1587 1500 regulator = ERR_PTR(-EPERM); 1588 - goto out; 1501 + put_device(&rdev->dev); 1502 + return regulator; 1589 1503 } 1590 1504 1591 1505 if (exclusive && rdev->open_count) { 1592 1506 regulator = ERR_PTR(-EBUSY); 1593 - goto out; 1507 + put_device(&rdev->dev); 1508 + return regulator; 1594 1509 } 1595 1510 1596 1511 ret = regulator_resolve_supply(rdev); 1597 1512 if (ret < 0) { 1598 1513 regulator = ERR_PTR(ret); 1599 - goto out; 1514 + put_device(&rdev->dev); 1515 + return regulator; 1600 1516 } 1601 1517 1602 - if (!try_module_get(rdev->owner)) 1603 - goto out; 1518 + if (!try_module_get(rdev->owner)) { 1519 + put_device(&rdev->dev); 1520 + return regulator; 1521 + } 1604 1522 1605 1523 regulator = create_regulator(rdev, dev, id); 1606 1524 if (regulator == NULL) { 1607 1525 regulator = ERR_PTR(-ENOMEM); 1526 + put_device(&rdev->dev); 1608 1527 module_put(rdev->owner); 1609 - goto out; 1528 + return regulator; 1610 1529 } 1611 1530 1612 1531 rdev->open_count++; ··· 1625 1532 else 1626 1533 rdev->use_count = 0; 1627 1534 } 1628 - 1629 - out: 1630 - mutex_unlock(&regulator_list_mutex); 1631 1535 1632 1536 return regulator; 1633 1537 } ··· 1723 1633 1724 1634 rdev->open_count--; 1725 1635 rdev->exclusive = 0; 1636 + put_device(&rdev->dev); 1726 1637 mutex_unlock(&rdev->mutex); 1727 1638 1728 1639 kfree(regulator->supply_name); ··· 2403 2312 return rdev->desc->ops->is_enabled(rdev); 2404 2313 } 2405 2314 2315 + static int _regulator_list_voltage(struct regulator *regulator, 2316 + unsigned selector, int lock) 2317 + { 2318 + struct regulator_dev *rdev = regulator->rdev; 2319 + const struct regulator_ops *ops = rdev->desc->ops; 2320 + int ret; 2321 + 2322 + if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) 2323 + return rdev->desc->fixed_uV; 2324 + 2325 + if (ops->list_voltage) { 2326 + if (selector >= rdev->desc->n_voltages) 2327 + return -EINVAL; 2328 + if (lock) 2329 + mutex_lock(&rdev->mutex); 2330 + ret = ops->list_voltage(rdev, selector); 2331 + if (lock) 2332 + mutex_unlock(&rdev->mutex); 2333 + } else if (rdev->supply) { 2334 + ret = _regulator_list_voltage(rdev->supply, selector, lock); 2335 + } else { 2336 + return -EINVAL; 2337 + } 2338 + 2339 + if (ret > 0) { 2340 + if (ret < rdev->constraints->min_uV) 2341 + ret = 0; 2342 + else if (ret > rdev->constraints->max_uV) 2343 + ret = 0; 2344 + } 2345 + 2346 + return ret; 2347 + } 2348 + 2406 2349 /** 2407 2350 * regulator_is_enabled - is the regulator output enabled 2408 2351 * @regulator: regulator source ··· 2526 2401 */ 2527 2402 int regulator_list_voltage(struct regulator *regulator, unsigned selector) 2528 2403 { 2529 - struct regulator_dev *rdev = regulator->rdev; 2530 - const struct regulator_ops *ops = rdev->desc->ops; 2531 - int ret; 2532 - 2533 - if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) 2534 - return rdev->desc->fixed_uV; 2535 - 2536 - if (ops->list_voltage) { 2537 - if (selector >= rdev->desc->n_voltages) 2538 - return -EINVAL; 2539 - mutex_lock(&rdev->mutex); 2540 - ret = ops->list_voltage(rdev, selector); 2541 - mutex_unlock(&rdev->mutex); 2542 - } else if (rdev->supply) { 2543 - ret = regulator_list_voltage(rdev->supply, selector); 2544 - } else { 2545 - return -EINVAL; 2546 - } 2547 - 2548 - if (ret > 0) { 2549 - if (ret < rdev->constraints->min_uV) 2550 - ret = 0; 2551 - else if (ret > rdev->constraints->max_uV) 2552 - ret = 0; 2553 - } 2554 - 2555 - return ret; 2404 + return _regulator_list_voltage(regulator, selector, 1); 2556 2405 } 2557 2406 EXPORT_SYMBOL_GPL(regulator_list_voltage); 2558 2407 ··· 2661 2562 } 2662 2563 EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); 2663 2564 2565 + static int regulator_map_voltage(struct regulator_dev *rdev, int min_uV, 2566 + int max_uV) 2567 + { 2568 + const struct regulator_desc *desc = rdev->desc; 2569 + 2570 + if (desc->ops->map_voltage) 2571 + return desc->ops->map_voltage(rdev, min_uV, max_uV); 2572 + 2573 + if (desc->ops->list_voltage == regulator_list_voltage_linear) 2574 + return regulator_map_voltage_linear(rdev, min_uV, max_uV); 2575 + 2576 + if (desc->ops->list_voltage == regulator_list_voltage_linear_range) 2577 + return regulator_map_voltage_linear_range(rdev, min_uV, max_uV); 2578 + 2579 + return regulator_map_voltage_iterate(rdev, min_uV, max_uV); 2580 + } 2581 + 2664 2582 static int _regulator_call_set_voltage(struct regulator_dev *rdev, 2665 2583 int min_uV, int max_uV, 2666 2584 unsigned *selector) ··· 2766 2650 } 2767 2651 2768 2652 } else if (rdev->desc->ops->set_voltage_sel) { 2769 - if (rdev->desc->ops->map_voltage) { 2770 - ret = rdev->desc->ops->map_voltage(rdev, min_uV, 2771 - max_uV); 2772 - } else { 2773 - if (rdev->desc->ops->list_voltage == 2774 - regulator_list_voltage_linear) 2775 - ret = regulator_map_voltage_linear(rdev, 2776 - min_uV, max_uV); 2777 - else if (rdev->desc->ops->list_voltage == 2778 - regulator_list_voltage_linear_range) 2779 - ret = regulator_map_voltage_linear_range(rdev, 2780 - min_uV, max_uV); 2781 - else 2782 - ret = regulator_map_voltage_iterate(rdev, 2783 - min_uV, max_uV); 2784 - } 2785 - 2653 + ret = regulator_map_voltage(rdev, min_uV, max_uV); 2786 2654 if (ret >= 0) { 2787 2655 best_val = rdev->desc->ops->list_voltage(rdev, ret); 2788 2656 if (min_uV <= best_val && max_uV >= best_val) { ··· 2817 2717 return ret; 2818 2718 } 2819 2719 2820 - /** 2821 - * regulator_set_voltage - set regulator output voltage 2822 - * @regulator: regulator source 2823 - * @min_uV: Minimum required voltage in uV 2824 - * @max_uV: Maximum acceptable voltage in uV 2825 - * 2826 - * Sets a voltage regulator to the desired output voltage. This can be set 2827 - * during any regulator state. IOW, regulator can be disabled or enabled. 2828 - * 2829 - * If the regulator is enabled then the voltage will change to the new value 2830 - * immediately otherwise if the regulator is disabled the regulator will 2831 - * output at the new voltage when enabled. 2832 - * 2833 - * NOTE: If the regulator is shared between several devices then the lowest 2834 - * request voltage that meets the system constraints will be used. 2835 - * Regulator system constraints must be set for this regulator before 2836 - * calling this function otherwise this call will fail. 2837 - */ 2838 - int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) 2720 + static int regulator_set_voltage_unlocked(struct regulator *regulator, 2721 + int min_uV, int max_uV) 2839 2722 { 2840 2723 struct regulator_dev *rdev = regulator->rdev; 2841 2724 int ret = 0; 2842 2725 int old_min_uV, old_max_uV; 2843 2726 int current_uV; 2844 - 2845 - mutex_lock(&rdev->mutex); 2727 + int best_supply_uV = 0; 2728 + int supply_change_uV = 0; 2846 2729 2847 2730 /* If we're setting the same range as last time the change 2848 2731 * should be a noop (some cpufreq implementations use the same ··· 2869 2786 if (ret < 0) 2870 2787 goto out2; 2871 2788 2789 + if (rdev->supply && (rdev->desc->min_dropout_uV || 2790 + !rdev->desc->ops->get_voltage)) { 2791 + int current_supply_uV; 2792 + int selector; 2793 + 2794 + selector = regulator_map_voltage(rdev, min_uV, max_uV); 2795 + if (selector < 0) { 2796 + ret = selector; 2797 + goto out2; 2798 + } 2799 + 2800 + best_supply_uV = _regulator_list_voltage(regulator, selector, 0); 2801 + if (best_supply_uV < 0) { 2802 + ret = best_supply_uV; 2803 + goto out2; 2804 + } 2805 + 2806 + best_supply_uV += rdev->desc->min_dropout_uV; 2807 + 2808 + current_supply_uV = _regulator_get_voltage(rdev->supply->rdev); 2809 + if (current_supply_uV < 0) { 2810 + ret = current_supply_uV; 2811 + goto out2; 2812 + } 2813 + 2814 + supply_change_uV = best_supply_uV - current_supply_uV; 2815 + } 2816 + 2817 + if (supply_change_uV > 0) { 2818 + ret = regulator_set_voltage_unlocked(rdev->supply, 2819 + best_supply_uV, INT_MAX); 2820 + if (ret) { 2821 + dev_err(&rdev->dev, "Failed to increase supply voltage: %d\n", 2822 + ret); 2823 + goto out2; 2824 + } 2825 + } 2826 + 2872 2827 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); 2873 2828 if (ret < 0) 2874 2829 goto out2; 2875 2830 2831 + if (supply_change_uV < 0) { 2832 + ret = regulator_set_voltage_unlocked(rdev->supply, 2833 + best_supply_uV, INT_MAX); 2834 + if (ret) 2835 + dev_warn(&rdev->dev, "Failed to decrease supply voltage: %d\n", 2836 + ret); 2837 + /* No need to fail here */ 2838 + ret = 0; 2839 + } 2840 + 2876 2841 out: 2877 - mutex_unlock(&rdev->mutex); 2878 2842 return ret; 2879 2843 out2: 2880 2844 regulator->min_uV = old_min_uV; 2881 2845 regulator->max_uV = old_max_uV; 2882 - mutex_unlock(&rdev->mutex); 2846 + 2847 + return ret; 2848 + } 2849 + 2850 + /** 2851 + * regulator_set_voltage - set regulator output voltage 2852 + * @regulator: regulator source 2853 + * @min_uV: Minimum required voltage in uV 2854 + * @max_uV: Maximum acceptable voltage in uV 2855 + * 2856 + * Sets a voltage regulator to the desired output voltage. This can be set 2857 + * during any regulator state. IOW, regulator can be disabled or enabled. 2858 + * 2859 + * If the regulator is enabled then the voltage will change to the new value 2860 + * immediately otherwise if the regulator is disabled the regulator will 2861 + * output at the new voltage when enabled. 2862 + * 2863 + * NOTE: If the regulator is shared between several devices then the lowest 2864 + * request voltage that meets the system constraints will be used. 2865 + * Regulator system constraints must be set for this regulator before 2866 + * calling this function otherwise this call will fail. 2867 + */ 2868 + int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) 2869 + { 2870 + int ret = 0; 2871 + 2872 + regulator_lock_supply(regulator->rdev); 2873 + 2874 + ret = regulator_set_voltage_unlocked(regulator, min_uV, max_uV); 2875 + 2876 + regulator_unlock_supply(regulator->rdev); 2877 + 2883 2878 return ret; 2884 2879 } 2885 2880 EXPORT_SYMBOL_GPL(regulator_set_voltage); ··· 3110 2949 } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) { 3111 2950 ret = rdev->desc->fixed_uV; 3112 2951 } else if (rdev->supply) { 3113 - ret = regulator_get_voltage(rdev->supply); 2952 + ret = _regulator_get_voltage(rdev->supply->rdev); 3114 2953 } else { 3115 2954 return -EINVAL; 3116 2955 } ··· 3133 2972 { 3134 2973 int ret; 3135 2974 3136 - mutex_lock(&regulator->rdev->mutex); 2975 + regulator_lock_supply(regulator->rdev); 3137 2976 3138 2977 ret = _regulator_get_voltage(regulator->rdev); 3139 2978 3140 - mutex_unlock(&regulator->rdev->mutex); 2979 + regulator_unlock_supply(regulator->rdev); 3141 2980 3142 2981 return ret; 3143 2982 } ··· 3971 3810 } 3972 3811 } 3973 3812 3974 - list_add(&rdev->list, &regulator_list); 3975 - 3976 3813 rdev_init_debugfs(rdev); 3977 3814 out: 3978 3815 mutex_unlock(&regulator_list_mutex); ··· 4024 3865 } 4025 3866 EXPORT_SYMBOL_GPL(regulator_unregister); 4026 3867 3868 + static int _regulator_suspend_prepare(struct device *dev, void *data) 3869 + { 3870 + struct regulator_dev *rdev = dev_to_rdev(dev); 3871 + const suspend_state_t *state = data; 3872 + int ret; 3873 + 3874 + mutex_lock(&rdev->mutex); 3875 + ret = suspend_prepare(rdev, *state); 3876 + mutex_unlock(&rdev->mutex); 3877 + 3878 + return ret; 3879 + } 3880 + 4027 3881 /** 4028 3882 * regulator_suspend_prepare - prepare regulators for system wide suspend 4029 3883 * @state: system suspend state ··· 4046 3874 */ 4047 3875 int regulator_suspend_prepare(suspend_state_t state) 4048 3876 { 4049 - struct regulator_dev *rdev; 4050 - int ret = 0; 4051 - 4052 3877 /* ON is handled by regulator active state */ 4053 3878 if (state == PM_SUSPEND_ON) 4054 3879 return -EINVAL; 4055 3880 4056 - mutex_lock(&regulator_list_mutex); 4057 - list_for_each_entry(rdev, &regulator_list, list) { 4058 - 4059 - mutex_lock(&rdev->mutex); 4060 - ret = suspend_prepare(rdev, state); 4061 - mutex_unlock(&rdev->mutex); 4062 - 4063 - if (ret < 0) { 4064 - rdev_err(rdev, "failed to prepare\n"); 4065 - goto out; 4066 - } 4067 - } 4068 - out: 4069 - mutex_unlock(&regulator_list_mutex); 4070 - return ret; 3881 + return class_for_each_device(&regulator_class, NULL, &state, 3882 + _regulator_suspend_prepare); 4071 3883 } 4072 3884 EXPORT_SYMBOL_GPL(regulator_suspend_prepare); 3885 + 3886 + static int _regulator_suspend_finish(struct device *dev, void *data) 3887 + { 3888 + struct regulator_dev *rdev = dev_to_rdev(dev); 3889 + int ret; 3890 + 3891 + mutex_lock(&rdev->mutex); 3892 + if (rdev->use_count > 0 || rdev->constraints->always_on) { 3893 + if (!_regulator_is_enabled(rdev)) { 3894 + ret = _regulator_do_enable(rdev); 3895 + if (ret) 3896 + dev_err(dev, 3897 + "Failed to resume regulator %d\n", 3898 + ret); 3899 + } 3900 + } else { 3901 + if (!have_full_constraints()) 3902 + goto unlock; 3903 + if (!_regulator_is_enabled(rdev)) 3904 + goto unlock; 3905 + 3906 + ret = _regulator_do_disable(rdev); 3907 + if (ret) 3908 + dev_err(dev, "Failed to suspend regulator %d\n", ret); 3909 + } 3910 + unlock: 3911 + mutex_unlock(&rdev->mutex); 3912 + 3913 + /* Keep processing regulators in spite of any errors */ 3914 + return 0; 3915 + } 4073 3916 4074 3917 /** 4075 3918 * regulator_suspend_finish - resume regulators from system wide suspend ··· 4094 3907 */ 4095 3908 int regulator_suspend_finish(void) 4096 3909 { 4097 - struct regulator_dev *rdev; 4098 - int ret = 0, error; 4099 - 4100 - mutex_lock(&regulator_list_mutex); 4101 - list_for_each_entry(rdev, &regulator_list, list) { 4102 - mutex_lock(&rdev->mutex); 4103 - if (rdev->use_count > 0 || rdev->constraints->always_on) { 4104 - if (!_regulator_is_enabled(rdev)) { 4105 - error = _regulator_do_enable(rdev); 4106 - if (error) 4107 - ret = error; 4108 - } 4109 - } else { 4110 - if (!have_full_constraints()) 4111 - goto unlock; 4112 - if (!_regulator_is_enabled(rdev)) 4113 - goto unlock; 4114 - 4115 - error = _regulator_do_disable(rdev); 4116 - if (error) 4117 - ret = error; 4118 - } 4119 - unlock: 4120 - mutex_unlock(&rdev->mutex); 4121 - } 4122 - mutex_unlock(&regulator_list_mutex); 4123 - return ret; 3910 + return class_for_each_device(&regulator_class, NULL, NULL, 3911 + _regulator_suspend_finish); 4124 3912 } 4125 3913 EXPORT_SYMBOL_GPL(regulator_suspend_finish); 4126 3914 ··· 4215 4053 }; 4216 4054 4217 4055 #ifdef CONFIG_DEBUG_FS 4056 + struct summary_data { 4057 + struct seq_file *s; 4058 + struct regulator_dev *parent; 4059 + int level; 4060 + }; 4061 + 4062 + static void regulator_summary_show_subtree(struct seq_file *s, 4063 + struct regulator_dev *rdev, 4064 + int level); 4065 + 4066 + static int regulator_summary_show_children(struct device *dev, void *data) 4067 + { 4068 + struct regulator_dev *rdev = dev_to_rdev(dev); 4069 + struct summary_data *summary_data = data; 4070 + 4071 + if (rdev->supply && rdev->supply->rdev == summary_data->parent) 4072 + regulator_summary_show_subtree(summary_data->s, rdev, 4073 + summary_data->level + 1); 4074 + 4075 + return 0; 4076 + } 4077 + 4218 4078 static void regulator_summary_show_subtree(struct seq_file *s, 4219 4079 struct regulator_dev *rdev, 4220 4080 int level) 4221 4081 { 4222 - struct list_head *list = s->private; 4223 - struct regulator_dev *child; 4224 4082 struct regulation_constraints *c; 4225 4083 struct regulator *consumer; 4084 + struct summary_data summary_data; 4226 4085 4227 4086 if (!rdev) 4228 4087 return; ··· 4293 4110 seq_puts(s, "\n"); 4294 4111 } 4295 4112 4296 - list_for_each_entry(child, list, list) { 4297 - /* handle only non-root regulators supplied by current rdev */ 4298 - if (!child->supply || child->supply->rdev != rdev) 4299 - continue; 4113 + summary_data.s = s; 4114 + summary_data.level = level; 4115 + summary_data.parent = rdev; 4300 4116 4301 - regulator_summary_show_subtree(s, child, level + 1); 4302 - } 4117 + class_for_each_device(&regulator_class, NULL, &summary_data, 4118 + regulator_summary_show_children); 4119 + } 4120 + 4121 + static int regulator_summary_show_roots(struct device *dev, void *data) 4122 + { 4123 + struct regulator_dev *rdev = dev_to_rdev(dev); 4124 + struct seq_file *s = data; 4125 + 4126 + if (!rdev->supply) 4127 + regulator_summary_show_subtree(s, rdev, 0); 4128 + 4129 + return 0; 4303 4130 } 4304 4131 4305 4132 static int regulator_summary_show(struct seq_file *s, void *data) 4306 4133 { 4307 - struct list_head *list = s->private; 4308 - struct regulator_dev *rdev; 4309 - 4310 4134 seq_puts(s, " regulator use open bypass voltage current min max\n"); 4311 4135 seq_puts(s, "-------------------------------------------------------------------------------\n"); 4312 4136 4313 - mutex_lock(&regulator_list_mutex); 4314 - 4315 - list_for_each_entry(rdev, list, list) { 4316 - if (rdev->supply) 4317 - continue; 4318 - 4319 - regulator_summary_show_subtree(s, rdev, 0); 4320 - } 4321 - 4322 - mutex_unlock(&regulator_list_mutex); 4137 + class_for_each_device(&regulator_class, NULL, s, 4138 + regulator_summary_show_roots); 4323 4139 4324 4140 return 0; 4325 4141 } ··· 4352 4170 &supply_map_fops); 4353 4171 4354 4172 debugfs_create_file("regulator_summary", 0444, debugfs_root, 4355 - &regulator_list, &regulator_summary_fops); 4173 + NULL, &regulator_summary_fops); 4356 4174 4357 4175 regulator_dummy_init(); 4358 4176
+1
drivers/regulator/da9052-regulator.c
··· 381 381 case DA9053_AA: 382 382 case DA9053_BA: 383 383 case DA9053_BB: 384 + case DA9053_BC: 384 385 for (i = 0; i < ARRAY_SIZE(da9053_regulator_info); i++) { 385 386 info = &da9053_regulator_info[i]; 386 387 if (info->reg_desc.id == id)
+1 -1
drivers/regulator/da9063-regulator.c
··· 698 698 rdata->initdata = da9063_matches[i].init_data; 699 699 700 700 n++; 701 - }; 701 + } 702 702 703 703 *da9063_reg_matches = da9063_matches; 704 704 return pdata;
+3
drivers/regulator/of_regulator.c
··· 76 76 if (of_property_read_bool(np, "regulator-allow-bypass")) 77 77 constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS; 78 78 79 + if (of_property_read_bool(np, "regulator-allow-set-load")) 80 + constraints->valid_ops_mask |= REGULATOR_CHANGE_DRMS; 81 + 79 82 ret = of_property_read_u32(np, "regulator-ramp-delay", &pval); 80 83 if (!ret) { 81 84 if (pval)
+29 -6
drivers/regulator/pwm-regulator.c
··· 69 69 70 70 drvdata->state = selector; 71 71 72 - ret = pwm_enable(drvdata->pwm); 73 - if (ret) { 74 - dev_err(&rdev->dev, "Failed to enable PWM\n"); 75 - return ret; 76 - } 77 - 78 72 return 0; 79 73 } 80 74 ··· 81 87 return -EINVAL; 82 88 83 89 return drvdata->duty_cycle_table[selector].uV; 90 + } 91 + 92 + static int pwm_regulator_enable(struct regulator_dev *dev) 93 + { 94 + struct pwm_regulator_data *drvdata = rdev_get_drvdata(dev); 95 + 96 + return pwm_enable(drvdata->pwm); 97 + } 98 + 99 + static int pwm_regulator_disable(struct regulator_dev *dev) 100 + { 101 + struct pwm_regulator_data *drvdata = rdev_get_drvdata(dev); 102 + 103 + pwm_disable(drvdata->pwm); 104 + 105 + return 0; 106 + } 107 + 108 + static int pwm_regulator_is_enabled(struct regulator_dev *dev) 109 + { 110 + struct pwm_regulator_data *drvdata = rdev_get_drvdata(dev); 111 + 112 + return pwm_is_enabled(drvdata->pwm); 84 113 } 85 114 86 115 /** ··· 161 144 .get_voltage_sel = pwm_regulator_get_voltage_sel, 162 145 .list_voltage = pwm_regulator_list_voltage, 163 146 .map_voltage = regulator_map_voltage_iterate, 147 + .enable = pwm_regulator_enable, 148 + .disable = pwm_regulator_disable, 149 + .is_enabled = pwm_regulator_is_enabled, 164 150 }; 165 151 166 152 static struct regulator_ops pwm_regulator_voltage_continuous_ops = { 167 153 .get_voltage = pwm_regulator_get_voltage, 168 154 .set_voltage = pwm_regulator_set_voltage, 155 + .enable = pwm_regulator_enable, 156 + .disable = pwm_regulator_disable, 157 + .is_enabled = pwm_regulator_is_enabled, 169 158 }; 170 159 171 160 static struct regulator_desc pwm_regulator_desc = {
+14 -14
drivers/regulator/qcom_smd-regulator.c
··· 36 36 }; 37 37 38 38 struct rpm_regulator_req { 39 - u32 key; 40 - u32 nbytes; 41 - u32 value; 39 + __le32 key; 40 + __le32 nbytes; 41 + __le32 value; 42 42 }; 43 43 44 44 #define RPM_KEY_SWEN 0x6e657773 /* "swen" */ ··· 62 62 struct rpm_regulator_req req; 63 63 int ret; 64 64 65 - req.key = RPM_KEY_SWEN; 66 - req.nbytes = sizeof(u32); 67 - req.value = 1; 65 + req.key = cpu_to_le32(RPM_KEY_SWEN); 66 + req.nbytes = cpu_to_le32(sizeof(u32)); 67 + req.value = cpu_to_le32(1); 68 68 69 69 ret = rpm_reg_write_active(vreg, &req, sizeof(req)); 70 70 if (!ret) ··· 86 86 struct rpm_regulator_req req; 87 87 int ret; 88 88 89 - req.key = RPM_KEY_SWEN; 90 - req.nbytes = sizeof(u32); 89 + req.key = cpu_to_le32(RPM_KEY_SWEN); 90 + req.nbytes = cpu_to_le32(sizeof(u32)); 91 91 req.value = 0; 92 92 93 93 ret = rpm_reg_write_active(vreg, &req, sizeof(req)); ··· 113 113 struct rpm_regulator_req req; 114 114 int ret = 0; 115 115 116 - req.key = RPM_KEY_UV; 117 - req.nbytes = sizeof(u32); 118 - req.value = min_uV; 116 + req.key = cpu_to_le32(RPM_KEY_UV); 117 + req.nbytes = cpu_to_le32(sizeof(u32)); 118 + req.value = cpu_to_le32(min_uV); 119 119 120 120 ret = rpm_reg_write_active(vreg, &req, sizeof(req)); 121 121 if (!ret) ··· 129 129 struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 130 130 struct rpm_regulator_req req; 131 131 132 - req.key = RPM_KEY_MA; 133 - req.nbytes = sizeof(u32); 134 - req.value = load_uA; 132 + req.key = cpu_to_le32(RPM_KEY_MA); 133 + req.nbytes = cpu_to_le32(sizeof(u32)); 134 + req.value = cpu_to_le32(load_uA / 1000); 135 135 136 136 return rpm_reg_write_active(vreg, &req, sizeof(req)); 137 137 }
+8 -8
drivers/regulator/tps6105x-regulator.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/init.h> 16 16 #include <linux/err.h> 17 - #include <linux/i2c.h> 17 + #include <linux/regmap.h> 18 18 #include <linux/platform_device.h> 19 19 #include <linux/regulator/driver.h> 20 20 #include <linux/mfd/core.h> ··· 33 33 int ret; 34 34 35 35 /* Activate voltage mode */ 36 - ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0, 36 + ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0, 37 37 TPS6105X_REG0_MODE_MASK, 38 38 TPS6105X_REG0_MODE_VOLTAGE << TPS6105X_REG0_MODE_SHIFT); 39 39 if (ret) ··· 48 48 int ret; 49 49 50 50 /* Set into shutdown mode */ 51 - ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0, 51 + ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0, 52 52 TPS6105X_REG0_MODE_MASK, 53 53 TPS6105X_REG0_MODE_SHUTDOWN << TPS6105X_REG0_MODE_SHIFT); 54 54 if (ret) ··· 60 60 static int tps6105x_regulator_is_enabled(struct regulator_dev *rdev) 61 61 { 62 62 struct tps6105x *tps6105x = rdev_get_drvdata(rdev); 63 - u8 regval; 63 + unsigned int regval; 64 64 int ret; 65 65 66 - ret = tps6105x_get(tps6105x, TPS6105X_REG_0, &regval); 66 + ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, &regval); 67 67 if (ret) 68 68 return ret; 69 69 regval &= TPS6105X_REG0_MODE_MASK; ··· 78 78 static int tps6105x_regulator_get_voltage_sel(struct regulator_dev *rdev) 79 79 { 80 80 struct tps6105x *tps6105x = rdev_get_drvdata(rdev); 81 - u8 regval; 81 + unsigned int regval; 82 82 int ret; 83 83 84 - ret = tps6105x_get(tps6105x, TPS6105X_REG_0, &regval); 84 + ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, &regval); 85 85 if (ret) 86 86 return ret; 87 87 ··· 96 96 struct tps6105x *tps6105x = rdev_get_drvdata(rdev); 97 97 int ret; 98 98 99 - ret = tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0, 99 + ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0, 100 100 TPS6105X_REG0_VOLTAGE_MASK, 101 101 selector << TPS6105X_REG0_VOLTAGE_SHIFT); 102 102 if (ret)
+109 -175
drivers/regulator/tps65023-regulator.c
··· 86 86 87 87 #define TPS65023_MAX_REG_ID TPS65023_LDO_2 88 88 89 + #define TPS65023_REGULATOR_DCDC(_num, _t, _em) \ 90 + { \ 91 + .name = "VDCDC"#_num, \ 92 + .of_match = of_match_ptr("VDCDC"#_num), \ 93 + .regulators_node = of_match_ptr("regulators"), \ 94 + .id = TPS65023_DCDC_##_num, \ 95 + .n_voltages = ARRAY_SIZE(_t), \ 96 + .ops = &tps65023_dcdc_ops, \ 97 + .type = REGULATOR_VOLTAGE, \ 98 + .owner = THIS_MODULE, \ 99 + .volt_table = _t, \ 100 + .vsel_reg = TPS65023_REG_DEF_CORE, \ 101 + .vsel_mask = ARRAY_SIZE(_t) - 1, \ 102 + .enable_mask = _em, \ 103 + .enable_reg = TPS65023_REG_REG_CTRL, \ 104 + .apply_reg = TPS65023_REG_CON_CTRL2, \ 105 + .apply_bit = TPS65023_REG_CTRL2_GO, \ 106 + } \ 107 + 108 + #define TPS65023_REGULATOR_LDO(_num, _t, _vm) \ 109 + { \ 110 + .name = "LDO"#_num, \ 111 + .of_match = of_match_ptr("LDO"#_num), \ 112 + .regulators_node = of_match_ptr("regulators"), \ 113 + .id = TPS65023_LDO_##_num, \ 114 + .n_voltages = ARRAY_SIZE(_t), \ 115 + .ops = &tps65023_ldo_ops, \ 116 + .type = REGULATOR_VOLTAGE, \ 117 + .owner = THIS_MODULE, \ 118 + .volt_table = _t, \ 119 + .vsel_reg = TPS65023_REG_LDO_CTRL, \ 120 + .vsel_mask = _vm, \ 121 + .enable_mask = 1 << (_num), \ 122 + .enable_reg = TPS65023_REG_REG_CTRL, \ 123 + } \ 124 + 89 125 /* Supported voltage values for regulators */ 90 126 static const unsigned int VCORE_VSEL_table[] = { 91 127 800000, 825000, 850000, 875000, ··· 160 124 2500000, 2800000, 3000000, 3300000, 161 125 }; 162 126 163 - /* Regulator specific details */ 164 - struct tps_info { 165 - const char *name; 166 - u8 table_len; 167 - const unsigned int *table; 168 - }; 169 - 170 127 /* PMIC details */ 171 128 struct tps_pmic { 172 - struct regulator_desc desc[TPS65023_NUM_REGULATOR]; 173 129 struct regulator_dev *rdev[TPS65023_NUM_REGULATOR]; 174 - const struct tps_info *info[TPS65023_NUM_REGULATOR]; 130 + const struct tps_driver_data *driver_data; 175 131 struct regmap *regmap; 176 - u8 core_regulator; 177 132 }; 178 133 179 134 /* Struct passed as driver data */ 180 135 struct tps_driver_data { 181 - const struct tps_info *info; 136 + const struct regulator_desc *desc; 182 137 u8 core_regulator; 183 138 }; 184 139 ··· 181 154 if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) 182 155 return -EINVAL; 183 156 184 - if (dcdc != tps->core_regulator) 157 + if (dcdc != tps->driver_data->core_regulator) 185 158 return 0; 186 159 187 160 return regulator_get_voltage_sel_regmap(dev); ··· 193 166 struct tps_pmic *tps = rdev_get_drvdata(dev); 194 167 int dcdc = rdev_get_id(dev); 195 168 196 - if (dcdc != tps->core_regulator) 169 + if (dcdc != tps->driver_data->core_regulator) 197 170 return -EINVAL; 198 171 199 172 return regulator_set_voltage_sel_regmap(dev, selector); ··· 226 199 .val_bits = 8, 227 200 }; 228 201 202 + static const struct regulator_desc tps65020_regulators[] = { 203 + TPS65023_REGULATOR_DCDC(1, DCDC_FIXED_3300000_VSEL_table, 0x20), 204 + TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_1800000_VSEL_table, 0x10), 205 + TPS65023_REGULATOR_DCDC(3, VCORE_VSEL_table, 0x08), 206 + TPS65023_REGULATOR_LDO(1, TPS65020_LDO_VSEL_table, 0x07), 207 + TPS65023_REGULATOR_LDO(2, TPS65020_LDO_VSEL_table, 0x70), 208 + }; 209 + 210 + static const struct regulator_desc tps65021_regulators[] = { 211 + TPS65023_REGULATOR_DCDC(1, DCDC_FIXED_3300000_VSEL_table, 0x20), 212 + TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_1800000_VSEL_table, 0x10), 213 + TPS65023_REGULATOR_DCDC(3, VCORE_VSEL_table, 0x08), 214 + TPS65023_REGULATOR_LDO(1, TPS65023_LDO1_VSEL_table, 0x07), 215 + TPS65023_REGULATOR_LDO(2, TPS65023_LDO2_VSEL_table, 0x70), 216 + }; 217 + 218 + static const struct regulator_desc tps65023_regulators[] = { 219 + TPS65023_REGULATOR_DCDC(1, VCORE_VSEL_table, 0x20), 220 + TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_3300000_VSEL_table, 0x10), 221 + TPS65023_REGULATOR_DCDC(3, DCDC_FIXED_1800000_VSEL_table, 0x08), 222 + TPS65023_REGULATOR_LDO(1, TPS65023_LDO1_VSEL_table, 0x07), 223 + TPS65023_REGULATOR_LDO(2, TPS65023_LDO2_VSEL_table, 0x70), 224 + }; 225 + 226 + static struct tps_driver_data tps65020_drv_data = { 227 + .desc = tps65020_regulators, 228 + .core_regulator = TPS65023_DCDC_3, 229 + }; 230 + 231 + static struct tps_driver_data tps65021_drv_data = { 232 + .desc = tps65021_regulators, 233 + .core_regulator = TPS65023_DCDC_3, 234 + }; 235 + 236 + static struct tps_driver_data tps65023_drv_data = { 237 + .desc = tps65023_regulators, 238 + .core_regulator = TPS65023_DCDC_1, 239 + }; 240 + 229 241 static int tps_65023_probe(struct i2c_client *client, 230 242 const struct i2c_device_id *id) 231 243 { 232 - const struct tps_driver_data *drv_data = (void *)id->driver_data; 233 - const struct tps_info *info = drv_data->info; 244 + struct regulator_init_data *init_data = dev_get_platdata(&client->dev); 234 245 struct regulator_config config = { }; 235 - struct regulator_init_data *init_data; 236 - struct regulator_dev *rdev; 237 246 struct tps_pmic *tps; 238 247 int i; 239 248 int error; 240 249 241 - /** 242 - * init_data points to array of regulator_init structures 243 - * coming from the board-evm file. 244 - */ 245 - init_data = dev_get_platdata(&client->dev); 246 - if (!init_data) 247 - return -EIO; 248 - 249 250 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 250 251 if (!tps) 251 252 return -ENOMEM; 253 + 254 + tps->driver_data = (struct tps_driver_data *)id->driver_data; 252 255 253 256 tps->regmap = devm_regmap_init_i2c(client, &tps65023_regmap_config); 254 257 if (IS_ERR(tps->regmap)) { ··· 289 232 } 290 233 291 234 /* common for all regulators */ 292 - tps->core_regulator = drv_data->core_regulator; 235 + config.dev = &client->dev; 236 + config.driver_data = tps; 237 + config.regmap = tps->regmap; 293 238 294 - for (i = 0; i < TPS65023_NUM_REGULATOR; i++, info++, init_data++) { 295 - /* Store regulator specific information */ 296 - tps->info[i] = info; 297 - 298 - tps->desc[i].name = info->name; 299 - tps->desc[i].id = i; 300 - tps->desc[i].n_voltages = info->table_len; 301 - tps->desc[i].volt_table = info->table; 302 - tps->desc[i].ops = (i > TPS65023_DCDC_3 ? 303 - &tps65023_ldo_ops : &tps65023_dcdc_ops); 304 - tps->desc[i].type = REGULATOR_VOLTAGE; 305 - tps->desc[i].owner = THIS_MODULE; 306 - 307 - tps->desc[i].enable_reg = TPS65023_REG_REG_CTRL; 308 - switch (i) { 309 - case TPS65023_LDO_1: 310 - tps->desc[i].vsel_reg = TPS65023_REG_LDO_CTRL; 311 - tps->desc[i].vsel_mask = 0x07; 312 - tps->desc[i].enable_mask = 1 << 1; 313 - break; 314 - case TPS65023_LDO_2: 315 - tps->desc[i].vsel_reg = TPS65023_REG_LDO_CTRL; 316 - tps->desc[i].vsel_mask = 0x70; 317 - tps->desc[i].enable_mask = 1 << 2; 318 - break; 319 - default: /* DCDCx */ 320 - tps->desc[i].enable_mask = 321 - 1 << (TPS65023_NUM_REGULATOR - i); 322 - tps->desc[i].vsel_reg = TPS65023_REG_DEF_CORE; 323 - tps->desc[i].vsel_mask = info->table_len - 1; 324 - tps->desc[i].apply_reg = TPS65023_REG_CON_CTRL2; 325 - tps->desc[i].apply_bit = TPS65023_REG_CTRL2_GO; 326 - } 327 - 328 - config.dev = &client->dev; 329 - config.init_data = init_data; 330 - config.driver_data = tps; 331 - config.regmap = tps->regmap; 239 + for (i = 0; i < TPS65023_NUM_REGULATOR; i++) { 240 + if (init_data) 241 + config.init_data = &init_data[i]; 332 242 333 243 /* Register the regulators */ 334 - rdev = devm_regulator_register(&client->dev, &tps->desc[i], 335 - &config); 336 - if (IS_ERR(rdev)) { 244 + tps->rdev[i] = devm_regulator_register(&client->dev, 245 + &tps->driver_data->desc[i], &config); 246 + if (IS_ERR(tps->rdev[i])) { 337 247 dev_err(&client->dev, "failed to register %s\n", 338 248 id->name); 339 - return PTR_ERR(rdev); 249 + return PTR_ERR(tps->rdev[i]); 340 250 } 341 - 342 - /* Save regulator for cleanup */ 343 - tps->rdev[i] = rdev; 344 251 } 345 252 346 253 i2c_set_clientdata(client, tps); ··· 317 296 return 0; 318 297 } 319 298 320 - static const struct tps_info tps65020_regs[] = { 321 - { 322 - .name = "VDCDC1", 323 - .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), 324 - .table = DCDC_FIXED_3300000_VSEL_table, 325 - }, 326 - { 327 - .name = "VDCDC2", 328 - .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), 329 - .table = DCDC_FIXED_1800000_VSEL_table, 330 - }, 331 - { 332 - .name = "VDCDC3", 333 - .table_len = ARRAY_SIZE(VCORE_VSEL_table), 334 - .table = VCORE_VSEL_table, 335 - }, 336 - { 337 - .name = "LDO1", 338 - .table_len = ARRAY_SIZE(TPS65020_LDO_VSEL_table), 339 - .table = TPS65020_LDO_VSEL_table, 340 - }, 341 - { 342 - .name = "LDO2", 343 - .table_len = ARRAY_SIZE(TPS65020_LDO_VSEL_table), 344 - .table = TPS65020_LDO_VSEL_table, 345 - }, 299 + static const struct of_device_id tps65023_of_match[] = { 300 + { .compatible = "ti,tps65020", .data = &tps65020_drv_data}, 301 + { .compatible = "ti,tps65021", .data = &tps65021_drv_data}, 302 + { .compatible = "ti,tps65023", .data = &tps65023_drv_data}, 303 + {}, 346 304 }; 347 - 348 - static const struct tps_info tps65021_regs[] = { 349 - { 350 - .name = "VDCDC1", 351 - .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), 352 - .table = DCDC_FIXED_3300000_VSEL_table, 353 - }, 354 - { 355 - .name = "VDCDC2", 356 - .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), 357 - .table = DCDC_FIXED_1800000_VSEL_table, 358 - }, 359 - { 360 - .name = "VDCDC3", 361 - .table_len = ARRAY_SIZE(VCORE_VSEL_table), 362 - .table = VCORE_VSEL_table, 363 - }, 364 - { 365 - .name = "LDO1", 366 - .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), 367 - .table = TPS65023_LDO1_VSEL_table, 368 - }, 369 - { 370 - .name = "LDO2", 371 - .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), 372 - .table = TPS65023_LDO2_VSEL_table, 373 - }, 374 - }; 375 - 376 - static const struct tps_info tps65023_regs[] = { 377 - { 378 - .name = "VDCDC1", 379 - .table_len = ARRAY_SIZE(VCORE_VSEL_table), 380 - .table = VCORE_VSEL_table, 381 - }, 382 - { 383 - .name = "VDCDC2", 384 - .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), 385 - .table = DCDC_FIXED_3300000_VSEL_table, 386 - }, 387 - { 388 - .name = "VDCDC3", 389 - .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), 390 - .table = DCDC_FIXED_1800000_VSEL_table, 391 - }, 392 - { 393 - .name = "LDO1", 394 - .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), 395 - .table = TPS65023_LDO1_VSEL_table, 396 - }, 397 - { 398 - .name = "LDO2", 399 - .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), 400 - .table = TPS65023_LDO2_VSEL_table, 401 - }, 402 - }; 403 - 404 - static struct tps_driver_data tps65020_drv_data = { 405 - .info = tps65020_regs, 406 - .core_regulator = TPS65023_DCDC_3, 407 - }; 408 - 409 - static struct tps_driver_data tps65021_drv_data = { 410 - .info = tps65021_regs, 411 - .core_regulator = TPS65023_DCDC_3, 412 - }; 413 - 414 - static struct tps_driver_data tps65023_drv_data = { 415 - .info = tps65023_regs, 416 - .core_regulator = TPS65023_DCDC_1, 417 - }; 305 + MODULE_DEVICE_TABLE(of, tps65023_of_match); 418 306 419 307 static const struct i2c_device_id tps_65023_id[] = { 420 - {.name = "tps65023", 421 - .driver_data = (unsigned long) &tps65023_drv_data}, 422 - {.name = "tps65021", 423 - .driver_data = (unsigned long) &tps65021_drv_data,}, 424 - {.name = "tps65020", 425 - .driver_data = (unsigned long) &tps65020_drv_data}, 308 + { 309 + .name = "tps65023", 310 + .driver_data = (kernel_ulong_t)&tps65023_drv_data 311 + }, { 312 + .name = "tps65021", 313 + .driver_data = (kernel_ulong_t)&tps65021_drv_data 314 + }, { 315 + .name = "tps65020", 316 + .driver_data = (kernel_ulong_t)&tps65020_drv_data 317 + }, 426 318 { }, 427 319 }; 428 - 429 320 MODULE_DEVICE_TABLE(i2c, tps_65023_id); 430 321 431 322 static struct i2c_driver tps_65023_i2c_driver = { 432 323 .driver = { 433 324 .name = "tps65023", 325 + .of_match_table = of_match_ptr(tps65023_of_match), 434 326 }, 435 327 .probe = tps_65023_probe, 436 328 .id_table = tps_65023_id,
+3 -7
include/linux/mfd/tps6105x.h
··· 10 10 #define MFD_TPS6105X_H 11 11 12 12 #include <linux/i2c.h> 13 + #include <linux/regmap.h> 13 14 #include <linux/regulator/machine.h> 14 15 15 16 /* ··· 83 82 84 83 /** 85 84 * struct tps6105x - state holder for the TPS6105x drivers 86 - * @mutex: mutex to serialize I2C accesses 87 85 * @i2c_client: corresponding I2C client 88 86 * @regulator: regulator device if used in voltage mode 87 + * @regmap: used for i2c communcation on accessing registers 89 88 */ 90 89 struct tps6105x { 91 90 struct tps6105x_platform_data *pdata; 92 - struct mutex lock; 93 91 struct i2c_client *client; 94 92 struct regulator_dev *regulator; 93 + struct regmap *regmap; 95 94 }; 96 - 97 - extern int tps6105x_set(struct tps6105x *tps6105x, u8 reg, u8 value); 98 - extern int tps6105x_get(struct tps6105x *tps6105x, u8 reg, u8 *buf); 99 - extern int tps6105x_mask_and_set(struct tps6105x *tps6105x, u8 reg, 100 - u8 bitmask, u8 bitvalues); 101 95 102 96 #endif
+2
include/linux/regulator/driver.h
··· 245 245 * @linear_min_sel: Minimal selector for starting linear mapping 246 246 * @fixed_uV: Fixed voltage of rails. 247 247 * @ramp_delay: Time to settle down after voltage change (unit: uV/us) 248 + * @min_dropout_uV: The minimum dropout voltage this regulator can handle 248 249 * @linear_ranges: A constant table of possible voltage ranges. 249 250 * @n_linear_ranges: Number of entries in the @linear_ranges table. 250 251 * @volt_table: Voltage mapping table (if table based mapping) ··· 293 292 unsigned int linear_min_sel; 294 293 int fixed_uV; 295 294 unsigned int ramp_delay; 295 + int min_dropout_uV; 296 296 297 297 const struct regulator_linear_range *linear_ranges; 298 298 int n_linear_ranges;