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/max77686', 'regulator/topic/max77693', 'regulator/topic/max77802', 'regulator/topic/power-off' and 'regulator/topic/rk808' into regulator-next

+623 -313
+18
Documentation/devicetree/bindings/power/power-controller.txt
··· 1 + * Generic system power control capability 2 + 3 + Power-management integrated circuits or miscellaneous hardware components are 4 + sometimes able to control the system power. The device driver associated with these 5 + components might need to define this capability, which tells the kernel that 6 + it can be used to switch off the system. The corresponding device must have the 7 + standard property "system-power-controller" in its device node. This property 8 + marks the device as able to control the system power. In order to test if this 9 + property is found programmatically, use the helper function 10 + "of_device_is_system_power_controller" from of.h . 11 + 12 + Example: 13 + 14 + act8846: act8846@5 { 15 + compatible = "active-semi,act8846"; 16 + status = "okay"; 17 + system-power-controller; 18 + }
+4
Documentation/devicetree/bindings/regulator/act8865-regulator.txt
··· 5 5 - compatible: "active-semi,act8846" or "active-semi,act8865" 6 6 - reg: I2C slave address 7 7 8 + Optional properties: 9 + - system-power-controller: Telling whether or not this pmic is controlling 10 + the system power. See Documentation/devicetree/bindings/power/power-controller.txt . 11 + 8 12 Any standard regulator properties can be used to configure the single regulator. 9 13 10 14 The valid names for regulators are:
+35
Documentation/devicetree/bindings/regulator/max77802.txt
··· 25 25 example: LDO1, LDO2, LDO35. 26 26 -BUCKn : for BUCKs, where n can lie in range 1 to 10. 27 27 example: BUCK1, BUCK5, BUCK10. 28 + 29 + The max77802 regulator supports two different operating modes: Normal and Low 30 + Power Mode. Some regulators support the modes to be changed at startup or by 31 + the consumers during normal operation while others only support to change the 32 + mode during system suspend. The standard regulator suspend states binding can 33 + be used to configure the regulator operating mode. 34 + 35 + The regulators that support the standard "regulator-initial-mode" property, 36 + changing their mode during normal operation are: LDOs 1, 3, 20 and 21. 37 + 38 + The possible values for "regulator-initial-mode" and "regulator-mode" are: 39 + 1: Normal regulator voltage output mode. 40 + 3: Low Power which reduces the quiescent current down to only 1uA 41 + 42 + The list of valid modes are defined in the dt-bindings/clock/maxim,max77802.h 43 + header and can be included by device tree source files. 44 + 45 + The standard "regulator-mode" property can only be used for regulators that 46 + support changing their mode to Low Power Mode during suspend. These regulators 47 + are: BUCKs 2-4 and LDOs 1-35. Also, it only takes effect if the regulator has 48 + been enabled for the given suspend state using "regulator-on-in-suspend" and 49 + has not been disabled for that state using "regulator-off-in-suspend". 50 + 28 51 Example: 29 52 30 53 max77802@09 { ··· 59 36 #size-cells = <0>; 60 37 61 38 regulators { 39 + ldo1_reg: LDO1 { 40 + regulator-name = "vdd_1v0"; 41 + regulator-min-microvolt = <1000000>; 42 + regulator-max-microvolt = <1000000>; 43 + regulator-always-on; 44 + regulator-initial-mode = <MAX77802_OPMODE_LP>; 45 + }; 46 + 62 47 ldo11_reg: LDO11 { 63 48 regulator-name = "vdd_ldo11"; 64 49 regulator-min-microvolt = <1900000>; 65 50 regulator-max-microvolt = <1900000>; 66 51 regulator-always-on; 52 + regulator-state-mem { 53 + regulator-on-in-suspend; 54 + regulator-mode = <MAX77802_OPMODE_LP>; 55 + }; 67 56 }; 68 57 69 58 buck1_reg: BUCK1 {
+22
Documentation/devicetree/bindings/regulator/regulator.txt
··· 19 19 design requires. This property describes the total system ramp time 20 20 required due to the combination of internal ramping of the regulator itself, 21 21 and board design issues such as trace capacitance and load on the supply. 22 + - regulator-state-mem sub-root node for Suspend-to-RAM mode 23 + : suspend to memory, the device goes to sleep, but all data stored in memory, 24 + only some external interrupt can wake the device. 25 + - regulator-state-disk sub-root node for Suspend-to-DISK mode 26 + : suspend to disk, this state operates similarly to Suspend-to-RAM, 27 + but includes a final step of writing memory contents to disk. 28 + - regulator-state-[mem/disk] node has following common properties: 29 + - regulator-on-in-suspend: regulator should be on in suspend state. 30 + - regulator-off-in-suspend: regulator should be off in suspend state. 31 + - regulator-suspend-microvolt: regulator should be set to this voltage 32 + in suspend. 33 + - regulator-mode: operating mode in the given suspend state. 34 + The set of possible operating modes depends on the capabilities of 35 + every hardware so the valid modes are documented on each regulator 36 + device tree binding document. 37 + - regulator-initial-mode: initial operating mode. The set of possible operating 38 + modes depends on the capabilities of every hardware so each device binding 39 + documentation explains which values the regulator supports. 22 40 23 41 Deprecated properties: 24 42 - regulator-compatible: If a regulator chip contains multiple ··· 52 34 regulator-max-microvolt = <2500000>; 53 35 regulator-always-on; 54 36 vin-supply = <&vin>; 37 + 38 + regulator-state-mem { 39 + regulator-on-in-suspend; 40 + }; 55 41 }; 56 42 57 43 Regulator Consumers:
+2 -1
drivers/regulator/88pm8607.c
··· 330 330 for_each_child_of_node(nproot, np) { 331 331 if (!of_node_cmp(np->name, info->desc.name)) { 332 332 config->init_data = 333 - of_get_regulator_init_data(&pdev->dev, np); 333 + of_get_regulator_init_data(&pdev->dev, np, 334 + &info->desc); 334 335 config->of_node = np; 335 336 break; 336 337 }
+31
drivers/regulator/act8865-regulator.c
··· 61 61 #define ACT8846_REG12_VSET 0xa0 62 62 #define ACT8846_REG12_CTRL 0xa1 63 63 #define ACT8846_REG13_CTRL 0xb1 64 + #define ACT8846_GLB_OFF_CTRL 0xc3 65 + #define ACT8846_OFF_SYSMASK 0x18 64 66 65 67 /* 66 68 * ACT8865 Global Register Map. ··· 86 84 #define ACT8865_LDO3_CTRL 0x61 87 85 #define ACT8865_LDO4_VSET 0x64 88 86 #define ACT8865_LDO4_CTRL 0x65 87 + #define ACT8865_MSTROFF 0x20 89 88 90 89 /* 91 90 * Field Definitions. ··· 101 98 102 99 struct act8865 { 103 100 struct regmap *regmap; 101 + int off_reg; 102 + int off_mask; 104 103 }; 105 104 106 105 static const struct regmap_config act8865_regmap_config = { ··· 280 275 return NULL; 281 276 } 282 277 278 + static struct i2c_client *act8865_i2c_client; 279 + static void act8865_power_off(void) 280 + { 281 + struct act8865 *act8865; 282 + 283 + act8865 = i2c_get_clientdata(act8865_i2c_client); 284 + regmap_write(act8865->regmap, act8865->off_reg, act8865->off_mask); 285 + while (1); 286 + } 287 + 283 288 static int act8865_pmic_probe(struct i2c_client *client, 284 289 const struct i2c_device_id *i2c_id) 285 290 { ··· 300 285 int i, ret, num_regulators; 301 286 struct act8865 *act8865; 302 287 unsigned long type; 288 + int off_reg, off_mask; 303 289 304 290 pdata = dev_get_platdata(dev); 305 291 ··· 320 304 case ACT8846: 321 305 regulators = act8846_regulators; 322 306 num_regulators = ARRAY_SIZE(act8846_regulators); 307 + off_reg = ACT8846_GLB_OFF_CTRL; 308 + off_mask = ACT8846_OFF_SYSMASK; 323 309 break; 324 310 case ACT8865: 325 311 regulators = act8865_regulators; 326 312 num_regulators = ARRAY_SIZE(act8865_regulators); 313 + off_reg = ACT8865_SYS_CTRL; 314 + off_mask = ACT8865_MSTROFF; 327 315 break; 328 316 default: 329 317 dev_err(dev, "invalid device id %lu\n", type); ··· 363 343 dev_err(&client->dev, "Failed to allocate register map: %d\n", 364 344 ret); 365 345 return ret; 346 + } 347 + 348 + if (of_device_is_system_power_controller(dev->of_node)) { 349 + if (!pm_power_off) { 350 + act8865_i2c_client = client; 351 + act8865->off_reg = off_reg; 352 + act8865->off_mask = off_mask; 353 + pm_power_off = act8865_power_off; 354 + } else { 355 + dev_err(dev, "Failed to set poweroff capability, already defined\n"); 356 + } 366 357 } 367 358 368 359 /* Finally register devices */
+3 -2
drivers/regulator/anatop-regulator.c
··· 189 189 int ret = 0; 190 190 u32 val; 191 191 192 - initdata = of_get_regulator_init_data(dev, np); 193 192 sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL); 194 193 if (!sreg) 195 194 return -ENOMEM; 196 - sreg->initdata = initdata; 197 195 sreg->name = of_get_property(np, "regulator-name", NULL); 198 196 rdesc = &sreg->rdesc; 199 197 rdesc->name = sreg->name; 200 198 rdesc->type = REGULATOR_VOLTAGE; 201 199 rdesc->owner = THIS_MODULE; 200 + 201 + initdata = of_get_regulator_init_data(dev, np, rdesc); 202 + sreg->initdata = initdata; 202 203 203 204 anatop_np = of_get_parent(np); 204 205 if (!anatop_np)
+5 -3
drivers/regulator/arizona-ldo1.c
··· 179 179 }; 180 180 181 181 static int arizona_ldo1_of_get_pdata(struct arizona *arizona, 182 - struct regulator_config *config) 182 + struct regulator_config *config, 183 + const struct regulator_desc *desc) 183 184 { 184 185 struct arizona_pdata *pdata = &arizona->pdata; 185 186 struct arizona_ldo1 *ldo1 = config->driver_data; ··· 195 194 if (init_node) { 196 195 config->of_node = init_node; 197 196 198 - init_data = of_get_regulator_init_data(arizona->dev, init_node); 197 + init_data = of_get_regulator_init_data(arizona->dev, init_node, 198 + desc); 199 199 200 200 if (init_data) { 201 201 init_data->consumer_supplies = &ldo1->supply; ··· 259 257 260 258 if (IS_ENABLED(CONFIG_OF)) { 261 259 if (!dev_get_platdata(arizona->dev)) { 262 - ret = arizona_ldo1_of_get_pdata(arizona, &config); 260 + ret = arizona_ldo1_of_get_pdata(arizona, &config, desc); 263 261 if (ret < 0) 264 262 return ret; 265 263
+5 -3
drivers/regulator/arizona-micsupp.c
··· 198 198 }; 199 199 200 200 static int arizona_micsupp_of_get_pdata(struct arizona *arizona, 201 - struct regulator_config *config) 201 + struct regulator_config *config, 202 + const struct regulator_desc *desc) 202 203 { 203 204 struct arizona_pdata *pdata = &arizona->pdata; 204 205 struct arizona_micsupp *micsupp = config->driver_data; ··· 211 210 if (np) { 212 211 config->of_node = np; 213 212 214 - init_data = of_get_regulator_init_data(arizona->dev, np); 213 + init_data = of_get_regulator_init_data(arizona->dev, np, desc); 215 214 216 215 if (init_data) { 217 216 init_data->consumer_supplies = &micsupp->supply; ··· 265 264 266 265 if (IS_ENABLED(CONFIG_OF)) { 267 266 if (!dev_get_platdata(arizona->dev)) { 268 - ret = arizona_micsupp_of_get_pdata(arizona, &config); 267 + ret = arizona_micsupp_of_get_pdata(arizona, &config, 268 + desc); 269 269 if (ret < 0) 270 270 return ret; 271 271 }
+2 -1
drivers/regulator/da9052-regulator.c
··· 436 436 if (!of_node_cmp(np->name, 437 437 regulator->info->reg_desc.name)) { 438 438 config.init_data = of_get_regulator_init_data( 439 - &pdev->dev, np); 439 + &pdev->dev, np, 440 + &regulator->info->reg_desc); 440 441 config.of_node = np; 441 442 break; 442 443 }
+1 -1
drivers/regulator/da9210-regulator.c
··· 147 147 148 148 config.dev = &i2c->dev; 149 149 config.init_data = pdata ? &pdata->da9210_constraints : 150 - of_get_regulator_init_data(dev, dev->of_node); 150 + of_get_regulator_init_data(dev, dev->of_node, &da9210_reg); 151 151 config.driver_data = chip; 152 152 config.regmap = chip->regmap; 153 153 config.of_node = dev->of_node;
+9 -8
drivers/regulator/fan53555.c
··· 302 302 }; 303 303 304 304 static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev, 305 - struct device_node *np) 305 + struct device_node *np, 306 + const struct regulator_desc *desc) 306 307 { 307 308 struct fan53555_platform_data *pdata; 308 309 int ret; ··· 313 312 if (!pdata) 314 313 return NULL; 315 314 316 - pdata->regulator = of_get_regulator_init_data(dev, np); 315 + pdata->regulator = of_get_regulator_init_data(dev, np, desc); 317 316 318 317 ret = of_property_read_u32(np, "fcs,suspend-voltage-selector", 319 318 &tmp); ··· 348 347 unsigned int val; 349 348 int ret; 350 349 350 + di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info), 351 + GFP_KERNEL); 352 + if (!di) 353 + return -ENOMEM; 354 + 351 355 pdata = dev_get_platdata(&client->dev); 352 356 if (!pdata) 353 - pdata = fan53555_parse_dt(&client->dev, np); 357 + pdata = fan53555_parse_dt(&client->dev, np, &di->desc); 354 358 355 359 if (!pdata || !pdata->regulator) { 356 360 dev_err(&client->dev, "Platform data not found!\n"); 357 361 return -ENODEV; 358 362 } 359 - 360 - di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info), 361 - GFP_KERNEL); 362 - if (!di) 363 - return -ENOMEM; 364 363 365 364 di->regulator = pdata->regulator; 366 365 if (client->dev.of_node) {
+11 -8
drivers/regulator/fixed.c
··· 40 40 /** 41 41 * of_get_fixed_voltage_config - extract fixed_voltage_config structure info 42 42 * @dev: device requesting for fixed_voltage_config 43 + * @desc: regulator description 43 44 * 44 45 * Populates fixed_voltage_config structure by extracting data from device 45 46 * tree node, returns a pointer to the populated structure of NULL if memory 46 47 * alloc fails. 47 48 */ 48 49 static struct fixed_voltage_config * 49 - of_get_fixed_voltage_config(struct device *dev) 50 + of_get_fixed_voltage_config(struct device *dev, 51 + const struct regulator_desc *desc) 50 52 { 51 53 struct fixed_voltage_config *config; 52 54 struct device_node *np = dev->of_node; ··· 59 57 if (!config) 60 58 return ERR_PTR(-ENOMEM); 61 59 62 - config->init_data = of_get_regulator_init_data(dev, dev->of_node); 60 + config->init_data = of_get_regulator_init_data(dev, dev->of_node, desc); 63 61 if (!config->init_data) 64 62 return ERR_PTR(-EINVAL); 65 63 ··· 114 112 struct regulator_config cfg = { }; 115 113 int ret; 116 114 115 + drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data), 116 + GFP_KERNEL); 117 + if (!drvdata) 118 + return -ENOMEM; 119 + 117 120 if (pdev->dev.of_node) { 118 - config = of_get_fixed_voltage_config(&pdev->dev); 121 + config = of_get_fixed_voltage_config(&pdev->dev, 122 + &drvdata->desc); 119 123 if (IS_ERR(config)) 120 124 return PTR_ERR(config); 121 125 } else { ··· 129 121 } 130 122 131 123 if (!config) 132 - return -ENOMEM; 133 - 134 - drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data), 135 - GFP_KERNEL); 136 - if (!drvdata) 137 124 return -ENOMEM; 138 125 139 126 drvdata->desc.name = devm_kstrdup(&pdev->dev,
+10 -8
drivers/regulator/gpio-regulator.c
··· 133 133 }; 134 134 135 135 static struct gpio_regulator_config * 136 - of_get_gpio_regulator_config(struct device *dev, struct device_node *np) 136 + of_get_gpio_regulator_config(struct device *dev, struct device_node *np, 137 + const struct regulator_desc *desc) 137 138 { 138 139 struct gpio_regulator_config *config; 139 140 const char *regtype; ··· 147 146 if (!config) 148 147 return ERR_PTR(-ENOMEM); 149 148 150 - config->init_data = of_get_regulator_init_data(dev, np); 149 + config->init_data = of_get_regulator_init_data(dev, np, desc); 151 150 if (!config->init_data) 152 151 return ERR_PTR(-EINVAL); 153 152 ··· 251 250 struct regulator_config cfg = { }; 252 251 int ptr, ret, state; 253 252 254 - if (np) { 255 - config = of_get_gpio_regulator_config(&pdev->dev, np); 256 - if (IS_ERR(config)) 257 - return PTR_ERR(config); 258 - } 259 - 260 253 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), 261 254 GFP_KERNEL); 262 255 if (drvdata == NULL) 263 256 return -ENOMEM; 257 + 258 + if (np) { 259 + config = of_get_gpio_regulator_config(&pdev->dev, np, 260 + &drvdata->desc); 261 + if (IS_ERR(config)) 262 + return PTR_ERR(config); 263 + } 264 264 265 265 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); 266 266 if (drvdata->desc.name == NULL) {
+80 -92
drivers/regulator/max77686.c
··· 45 45 #define MAX77686_DVS_MINUV 600000 46 46 #define MAX77686_DVS_UVSTEP 12500 47 47 48 + /* 49 + * Values used for configuring LDOs and bucks. 50 + * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26 51 + */ 52 + #define MAX77686_LDO_LOWPOWER 0x1 53 + /* 54 + * On/off controlled by PWRREQ: 55 + * - LDO2, 6-8, 10-12, 14-16 56 + * - buck[1234] 57 + */ 58 + #define MAX77686_OFF_PWRREQ 0x1 59 + /* Low power mode controlled by PWRREQ: All LDOs */ 60 + #define MAX77686_LDO_LOWPOWER_PWRREQ 0x2 61 + /* Forcing low power mode: buck[234] */ 62 + #define MAX77686_BUCK_LOWPOWER 0x2 63 + #define MAX77686_NORMAL 0x3 64 + 48 65 #define MAX77686_OPMODE_SHIFT 6 49 66 #define MAX77686_OPMODE_BUCK234_SHIFT 4 50 67 #define MAX77686_OPMODE_MASK 0x3 ··· 82 65 }; 83 66 84 67 struct max77686_data { 68 + /* Array indexed by regulator id */ 85 69 unsigned int opmode[MAX77686_REGULATORS]; 86 70 }; 87 71 88 - /* Some BUCKS supports Normal[ON/OFF] mode during suspend */ 89 - static int max77686_buck_set_suspend_disable(struct regulator_dev *rdev) 72 + static unsigned int max77686_get_opmode_shift(int id) 90 73 { 91 - unsigned int val; 74 + switch (id) { 75 + case MAX77686_BUCK1: 76 + case MAX77686_BUCK5 ... MAX77686_BUCK9: 77 + return 0; 78 + case MAX77686_BUCK2 ... MAX77686_BUCK4: 79 + return MAX77686_OPMODE_BUCK234_SHIFT; 80 + default: 81 + /* all LDOs */ 82 + return MAX77686_OPMODE_SHIFT; 83 + } 84 + } 85 + 86 + /* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */ 87 + static int max77686_set_suspend_disable(struct regulator_dev *rdev) 88 + { 89 + unsigned int val, shift; 92 90 struct max77686_data *max77686 = rdev_get_drvdata(rdev); 93 91 int ret, id = rdev_get_id(rdev); 94 92 95 - if (id == MAX77686_BUCK1) 96 - val = 0x1; 97 - else 98 - val = 0x1 << MAX77686_OPMODE_BUCK234_SHIFT; 93 + shift = max77686_get_opmode_shift(id); 94 + val = MAX77686_OFF_PWRREQ; 99 95 100 96 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 101 - rdev->desc->enable_mask, val); 97 + rdev->desc->enable_mask, val << shift); 102 98 if (ret) 103 99 return ret; 104 100 ··· 133 103 134 104 switch (mode) { 135 105 case REGULATOR_MODE_IDLE: /* ON in LP Mode */ 136 - val = 0x2 << MAX77686_OPMODE_SHIFT; 106 + val = MAX77686_LDO_LOWPOWER_PWRREQ; 137 107 break; 138 108 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ 139 - val = 0x3 << MAX77686_OPMODE_SHIFT; 109 + val = MAX77686_NORMAL; 140 110 break; 141 111 default: 142 112 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", ··· 145 115 } 146 116 147 117 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 148 - rdev->desc->enable_mask, val); 118 + rdev->desc->enable_mask, 119 + val << MAX77686_OPMODE_SHIFT); 149 120 if (ret) 150 121 return ret; 151 122 ··· 164 133 165 134 switch (mode) { 166 135 case REGULATOR_MODE_STANDBY: /* switch off */ 167 - val = 0x1 << MAX77686_OPMODE_SHIFT; 136 + val = MAX77686_OFF_PWRREQ; 168 137 break; 169 138 case REGULATOR_MODE_IDLE: /* ON in LP Mode */ 170 - val = 0x2 << MAX77686_OPMODE_SHIFT; 139 + val = MAX77686_LDO_LOWPOWER_PWRREQ; 171 140 break; 172 141 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ 173 - val = 0x3 << MAX77686_OPMODE_SHIFT; 142 + val = MAX77686_NORMAL; 174 143 break; 175 144 default: 176 145 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", ··· 179 148 } 180 149 181 150 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 182 - rdev->desc->enable_mask, val); 151 + rdev->desc->enable_mask, 152 + val << MAX77686_OPMODE_SHIFT); 183 153 if (ret) 184 154 return ret; 185 155 ··· 191 159 static int max77686_enable(struct regulator_dev *rdev) 192 160 { 193 161 struct max77686_data *max77686 = rdev_get_drvdata(rdev); 162 + unsigned int shift; 163 + int id = rdev_get_id(rdev); 164 + 165 + shift = max77686_get_opmode_shift(id); 166 + 167 + if (max77686->opmode[id] == MAX77686_OFF_PWRREQ) 168 + max77686->opmode[id] = MAX77686_NORMAL; 194 169 195 170 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 196 171 rdev->desc->enable_mask, 197 - max77686->opmode[rdev_get_id(rdev)]); 172 + max77686->opmode[id] << shift); 198 173 } 199 174 200 175 static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) ··· 251 212 .set_voltage_sel = regulator_set_voltage_sel_regmap, 252 213 .set_voltage_time_sel = regulator_set_voltage_time_sel, 253 214 .set_suspend_mode = max77686_ldo_set_suspend_mode, 215 + .set_suspend_disable = max77686_set_suspend_disable, 254 216 }; 255 217 256 218 static struct regulator_ops max77686_buck1_ops = { ··· 263 223 .get_voltage_sel = regulator_get_voltage_sel_regmap, 264 224 .set_voltage_sel = regulator_set_voltage_sel_regmap, 265 225 .set_voltage_time_sel = regulator_set_voltage_time_sel, 266 - .set_suspend_disable = max77686_buck_set_suspend_disable, 226 + .set_suspend_disable = max77686_set_suspend_disable, 267 227 }; 268 228 269 229 static struct regulator_ops max77686_buck_dvs_ops = { ··· 276 236 .set_voltage_sel = regulator_set_voltage_sel_regmap, 277 237 .set_voltage_time_sel = regulator_set_voltage_time_sel, 278 238 .set_ramp_delay = max77686_set_ramp_delay, 279 - .set_suspend_disable = max77686_buck_set_suspend_disable, 239 + .set_suspend_disable = max77686_set_suspend_disable, 280 240 }; 281 241 282 242 #define regulator_desc_ldo(num) { \ 283 243 .name = "LDO"#num, \ 244 + .of_match = of_match_ptr("LDO"#num), \ 245 + .regulators_node = of_match_ptr("voltage-regulators"), \ 284 246 .id = MAX77686_LDO##num, \ 285 247 .ops = &max77686_ops, \ 286 248 .type = REGULATOR_VOLTAGE, \ ··· 299 257 } 300 258 #define regulator_desc_lpm_ldo(num) { \ 301 259 .name = "LDO"#num, \ 260 + .of_match = of_match_ptr("LDO"#num), \ 261 + .regulators_node = of_match_ptr("voltage-regulators"), \ 302 262 .id = MAX77686_LDO##num, \ 303 263 .ops = &max77686_ldo_ops, \ 304 264 .type = REGULATOR_VOLTAGE, \ ··· 317 273 } 318 274 #define regulator_desc_ldo_low(num) { \ 319 275 .name = "LDO"#num, \ 276 + .of_match = of_match_ptr("LDO"#num), \ 277 + .regulators_node = of_match_ptr("voltage-regulators"), \ 320 278 .id = MAX77686_LDO##num, \ 321 279 .ops = &max77686_ldo_ops, \ 322 280 .type = REGULATOR_VOLTAGE, \ ··· 335 289 } 336 290 #define regulator_desc_ldo1_low(num) { \ 337 291 .name = "LDO"#num, \ 292 + .of_match = of_match_ptr("LDO"#num), \ 293 + .regulators_node = of_match_ptr("voltage-regulators"), \ 338 294 .id = MAX77686_LDO##num, \ 339 295 .ops = &max77686_ops, \ 340 296 .type = REGULATOR_VOLTAGE, \ ··· 353 305 } 354 306 #define regulator_desc_buck(num) { \ 355 307 .name = "BUCK"#num, \ 308 + .of_match = of_match_ptr("BUCK"#num), \ 309 + .regulators_node = of_match_ptr("voltage-regulators"), \ 356 310 .id = MAX77686_BUCK##num, \ 357 311 .ops = &max77686_ops, \ 358 312 .type = REGULATOR_VOLTAGE, \ ··· 370 320 } 371 321 #define regulator_desc_buck1(num) { \ 372 322 .name = "BUCK"#num, \ 323 + .of_match = of_match_ptr("BUCK"#num), \ 324 + .regulators_node = of_match_ptr("voltage-regulators"), \ 373 325 .id = MAX77686_BUCK##num, \ 374 326 .ops = &max77686_buck1_ops, \ 375 327 .type = REGULATOR_VOLTAGE, \ ··· 387 335 } 388 336 #define regulator_desc_buck_dvs(num) { \ 389 337 .name = "BUCK"#num, \ 338 + .of_match = of_match_ptr("BUCK"#num), \ 339 + .regulators_node = of_match_ptr("voltage-regulators"), \ 390 340 .id = MAX77686_BUCK##num, \ 391 341 .ops = &max77686_buck_dvs_ops, \ 392 342 .type = REGULATOR_VOLTAGE, \ ··· 404 350 << MAX77686_OPMODE_BUCK234_SHIFT, \ 405 351 } 406 352 407 - static struct regulator_desc regulators[] = { 353 + static const struct regulator_desc regulators[] = { 408 354 regulator_desc_ldo1_low(1), 409 355 regulator_desc_ldo_low(2), 410 356 regulator_desc_ldo(3), ··· 442 388 regulator_desc_buck(9), 443 389 }; 444 390 445 - #ifdef CONFIG_OF 446 - static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev, 447 - struct max77686_platform_data *pdata) 448 - { 449 - struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); 450 - struct device_node *pmic_np, *regulators_np; 451 - struct max77686_regulator_data *rdata; 452 - struct of_regulator_match rmatch = { }; 453 - unsigned int i; 454 - 455 - pmic_np = iodev->dev->of_node; 456 - regulators_np = of_get_child_by_name(pmic_np, "voltage-regulators"); 457 - if (!regulators_np) { 458 - dev_err(&pdev->dev, "could not find regulators sub-node\n"); 459 - return -EINVAL; 460 - } 461 - 462 - pdata->num_regulators = ARRAY_SIZE(regulators); 463 - rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) * 464 - pdata->num_regulators, GFP_KERNEL); 465 - if (!rdata) { 466 - of_node_put(regulators_np); 467 - return -ENOMEM; 468 - } 469 - 470 - for (i = 0; i < pdata->num_regulators; i++) { 471 - rmatch.name = regulators[i].name; 472 - rmatch.init_data = NULL; 473 - rmatch.of_node = NULL; 474 - of_regulator_match(&pdev->dev, regulators_np, &rmatch, 1); 475 - rdata[i].initdata = rmatch.init_data; 476 - rdata[i].of_node = rmatch.of_node; 477 - } 478 - 479 - pdata->regulators = rdata; 480 - of_node_put(regulators_np); 481 - 482 - return 0; 483 - } 484 - #else 485 - static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev, 486 - struct max77686_platform_data *pdata) 487 - { 488 - return 0; 489 - } 490 - #endif /* CONFIG_OF */ 491 - 492 391 static int max77686_pmic_probe(struct platform_device *pdev) 493 392 { 494 393 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); 495 - struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev); 496 394 struct max77686_data *max77686; 497 - int i, ret = 0; 395 + int i; 498 396 struct regulator_config config = { }; 499 397 500 398 dev_dbg(&pdev->dev, "%s\n", __func__); 501 - 502 - if (!pdata) { 503 - dev_err(&pdev->dev, "no platform data found for regulator\n"); 504 - return -ENODEV; 505 - } 506 - 507 - if (iodev->dev->of_node) { 508 - ret = max77686_pmic_dt_parse_pdata(pdev, pdata); 509 - if (ret) 510 - return ret; 511 - } 512 - 513 - if (pdata->num_regulators != MAX77686_REGULATORS) { 514 - dev_err(&pdev->dev, 515 - "Invalid initial data for regulator's initialiation\n"); 516 - return -EINVAL; 517 - } 518 399 519 400 max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data), 520 401 GFP_KERNEL); 521 402 if (!max77686) 522 403 return -ENOMEM; 523 404 524 - config.dev = &pdev->dev; 405 + config.dev = iodev->dev; 525 406 config.regmap = iodev->regmap; 526 407 config.driver_data = max77686; 527 408 platform_set_drvdata(pdev, max77686); 528 409 529 410 for (i = 0; i < MAX77686_REGULATORS; i++) { 530 411 struct regulator_dev *rdev; 412 + int id = regulators[i].id; 531 413 532 - config.init_data = pdata->regulators[i].initdata; 533 - config.of_node = pdata->regulators[i].of_node; 534 - 535 - max77686->opmode[i] = regulators[i].enable_mask; 414 + max77686->opmode[id] = MAX77686_NORMAL; 536 415 rdev = devm_regulator_register(&pdev->dev, 537 416 &regulators[i], &config); 538 417 if (IS_ERR(rdev)) { 418 + int ret = PTR_ERR(rdev); 539 419 dev_err(&pdev->dev, 540 - "regulator init failed for %d\n", i); 541 - return PTR_ERR(rdev); 420 + "regulator init failed for %d: %d\n", i, ret); 421 + return ret; 542 422 } 543 423 } 544 424
+1 -1
drivers/regulator/max77693.c
··· 139 139 .enable_mask = SAFEOUT_CTRL_ENSAFEOUT##_num##_MASK , \ 140 140 } 141 141 142 - static struct regulator_desc regulators[] = { 142 + static const struct regulator_desc regulators[] = { 143 143 regulator_desc_esafeout(1), 144 144 regulator_desc_esafeout(2), 145 145 {
+139 -115
drivers/regulator/max77802.c
··· 33 33 #include <linux/regulator/of_regulator.h> 34 34 #include <linux/mfd/max77686.h> 35 35 #include <linux/mfd/max77686-private.h> 36 + #include <dt-bindings/regulator/maxim,max77802.h> 36 37 37 38 /* Default ramp delay in case it is not manually set */ 38 39 #define MAX77802_RAMP_DELAY 100000 /* uV/us */ ··· 49 48 #define MAX77802_RAMP_RATE_SHIFT_2BIT 6 50 49 #define MAX77802_RAMP_RATE_MASK_4BIT 0xF0 51 50 #define MAX77802_RAMP_RATE_SHIFT_4BIT 4 51 + 52 + #define MAX77802_STATUS_OFF 0x0 53 + #define MAX77802_OFF_PWRREQ 0x1 54 + #define MAX77802_LP_PWRREQ 0x2 52 55 53 56 /* MAX77802 has two register formats: 2-bit and 4-bit */ 54 57 static const unsigned int ramp_table_77802_2bit[] = { ··· 70 65 }; 71 66 72 67 struct max77802_regulator_prv { 68 + /* Array indexed by regulator id */ 73 69 unsigned int opmode[MAX77802_REG_MAX]; 74 70 }; 71 + 72 + static inline unsigned int max77802_map_mode(unsigned int mode) 73 + { 74 + return mode == MAX77802_OPMODE_NORMAL ? 75 + REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY; 76 + } 75 77 76 78 static int max77802_get_opmode_shift(int id) 77 79 { ··· 95 83 return -EINVAL; 96 84 } 97 85 98 - /* 99 - * Some BUCKS supports Normal[ON/OFF] mode during suspend 86 + /** 87 + * max77802_set_suspend_disable - Disable the regulator during system suspend 88 + * @rdev: regulator to mark as disabled 100 89 * 101 - * BUCK 1, 6, 2-4, 5, 7-10 (all) 102 - * 103 - * The other mode (0x02) will make PWRREQ switch between normal 104 - * and low power. 90 + * All regulators expect LDO 1, 3, 20 and 21 support OFF by PWRREQ. 91 + * Configure the regulator so the PMIC will turn it OFF during system suspend. 105 92 */ 106 - static int max77802_buck_set_suspend_disable(struct regulator_dev *rdev) 93 + static int max77802_set_suspend_disable(struct regulator_dev *rdev) 107 94 { 108 - unsigned int val = MAX77802_OPMODE_STANDBY; 95 + unsigned int val = MAX77802_OFF_PWRREQ; 109 96 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); 110 97 int id = rdev_get_id(rdev); 111 98 int shift = max77802_get_opmode_shift(id); ··· 115 104 } 116 105 117 106 /* 118 - * Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state 119 - * (Enable Control Logic1 by PWRREQ) 107 + * Some LDOs support Low Power Mode while the system is running. 120 108 * 121 - * LDOs 2, 4-19, 22-35. 122 - * 109 + * LDOs 1, 3, 20, 21. 123 110 */ 124 - static int max77802_ldo_set_suspend_mode_logic1(struct regulator_dev *rdev, 125 - unsigned int mode) 111 + static int max77802_set_mode(struct regulator_dev *rdev, unsigned int mode) 126 112 { 127 113 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); 128 114 int id = rdev_get_id(rdev); ··· 127 119 int shift = max77802_get_opmode_shift(id); 128 120 129 121 switch (mode) { 130 - case REGULATOR_MODE_IDLE: /* ON in LP Mode */ 131 - val = MAX77802_OPMODE_LP; 122 + case REGULATOR_MODE_STANDBY: 123 + val = MAX77802_OPMODE_LP; /* ON in Low Power Mode */ 132 124 break; 133 - case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ 134 - val = MAX77802_OPMODE_NORMAL; 135 - break; 136 - case REGULATOR_MODE_STANDBY: /* ON/OFF by PWRREQ */ 137 - val = MAX77802_OPMODE_STANDBY; 125 + case REGULATOR_MODE_NORMAL: 126 + val = MAX77802_OPMODE_NORMAL; /* ON in Normal Mode */ 138 127 break; 139 128 default: 140 129 dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n", ··· 144 139 rdev->desc->enable_mask, val << shift); 145 140 } 146 141 147 - /* 148 - * Mode 1 (Output[ON/OFF] by PWRREQ) is not supported on some LDOs 149 - * (Enable Control Logic2 by PWRREQ) 142 + static unsigned max77802_get_mode(struct regulator_dev *rdev) 143 + { 144 + struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); 145 + int id = rdev_get_id(rdev); 146 + 147 + return max77802_map_mode(max77802->opmode[id]); 148 + } 149 + 150 + /** 151 + * max77802_set_suspend_mode - set regulator opmode when the system is suspended 152 + * @rdev: regulator to change mode 153 + * @mode: operating mode to be set 150 154 * 151 - * LDOs 1, 20, 21, and 3, 155 + * Will set the operating mode for the regulators during system suspend. 156 + * This function is valid for the three different enable control logics: 152 157 * 158 + * Enable Control Logic1 by PWRREQ (BUCK 2-4 and LDOs 2, 4-19, 22-35) 159 + * Enable Control Logic2 by PWRREQ (LDOs 1, 20, 21) 160 + * Enable Control Logic3 by PWRREQ (LDO 3) 161 + * 162 + * If setting the regulator mode fails, the function only warns but does 163 + * not return an error code to avoid the regulator core to stop setting 164 + * the operating mode for the remaining regulators. 153 165 */ 154 - static int max77802_ldo_set_suspend_mode_logic2(struct regulator_dev *rdev, 155 - unsigned int mode) 166 + static int max77802_set_suspend_mode(struct regulator_dev *rdev, 167 + unsigned int mode) 156 168 { 157 169 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); 158 170 int id = rdev_get_id(rdev); 159 171 unsigned int val; 160 172 int shift = max77802_get_opmode_shift(id); 161 173 174 + /* 175 + * If the regulator has been disabled for suspend 176 + * then is invalid to try setting a suspend mode. 177 + */ 178 + if (max77802->opmode[id] == MAX77802_OFF_PWRREQ) { 179 + dev_warn(&rdev->dev, "%s: is disabled, mode: 0x%x not set\n", 180 + rdev->desc->name, mode); 181 + return 0; 182 + } 183 + 162 184 switch (mode) { 163 - case REGULATOR_MODE_IDLE: /* ON in LP Mode */ 164 - val = MAX77802_OPMODE_LP; 185 + case REGULATOR_MODE_STANDBY: 186 + /* 187 + * If the regulator opmode is normal then enable 188 + * ON in Low Power Mode by PWRREQ. If the mode is 189 + * already Low Power then no action is required. 190 + */ 191 + if (max77802->opmode[id] == MAX77802_OPMODE_NORMAL) 192 + val = MAX77802_LP_PWRREQ; 193 + else 194 + return 0; 165 195 break; 166 - case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ 167 - val = MAX77802_OPMODE_NORMAL; 168 - break; 196 + case REGULATOR_MODE_NORMAL: 197 + /* 198 + * If the regulator operating mode is Low Power then 199 + * normal is not a valid opmode in suspend. If the 200 + * mode is already normal then no action is required. 201 + */ 202 + if (max77802->opmode[id] == MAX77802_OPMODE_LP) 203 + dev_warn(&rdev->dev, "%s: in Low Power: 0x%x invalid\n", 204 + rdev->desc->name, mode); 205 + return 0; 169 206 default: 170 207 dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n", 171 208 rdev->desc->name, mode); 172 209 return -EINVAL; 173 210 } 174 211 175 - max77802->opmode[id] = val; 176 212 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 177 213 rdev->desc->enable_mask, val << shift); 178 214 } ··· 223 177 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); 224 178 int id = rdev_get_id(rdev); 225 179 int shift = max77802_get_opmode_shift(id); 180 + 181 + if (max77802->opmode[id] == MAX77802_OFF_PWRREQ) 182 + max77802->opmode[id] = MAX77802_OPMODE_NORMAL; 226 183 227 184 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 228 185 rdev->desc->enable_mask, ··· 296 247 .get_voltage_sel = regulator_get_voltage_sel_regmap, 297 248 .set_voltage_sel = regulator_set_voltage_sel_regmap, 298 249 .set_voltage_time_sel = regulator_set_voltage_time_sel, 299 - .set_suspend_mode = max77802_ldo_set_suspend_mode_logic1, 250 + .set_suspend_disable = max77802_set_suspend_disable, 251 + .set_suspend_mode = max77802_set_suspend_mode, 300 252 }; 301 253 302 254 /* ··· 312 262 .get_voltage_sel = regulator_get_voltage_sel_regmap, 313 263 .set_voltage_sel = regulator_set_voltage_sel_regmap, 314 264 .set_voltage_time_sel = regulator_set_voltage_time_sel, 315 - .set_suspend_mode = max77802_ldo_set_suspend_mode_logic2, 265 + .set_mode = max77802_set_mode, 266 + .get_mode = max77802_get_mode, 267 + .set_suspend_mode = max77802_set_suspend_mode, 316 268 }; 317 269 318 270 /* BUCKS 1, 6 */ ··· 328 276 .set_voltage_sel = regulator_set_voltage_sel_regmap, 329 277 .set_voltage_time_sel = regulator_set_voltage_time_sel, 330 278 .set_ramp_delay = max77802_set_ramp_delay_4bit, 331 - .set_suspend_disable = max77802_buck_set_suspend_disable, 279 + .set_suspend_disable = max77802_set_suspend_disable, 332 280 }; 333 281 334 - /* BUCKs 2-4, 5, 7-10 */ 282 + /* BUCKs 2-4 */ 283 + static struct regulator_ops max77802_buck_234_ops = { 284 + .list_voltage = regulator_list_voltage_linear, 285 + .map_voltage = regulator_map_voltage_linear, 286 + .is_enabled = regulator_is_enabled_regmap, 287 + .enable = max77802_enable, 288 + .disable = regulator_disable_regmap, 289 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 290 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 291 + .set_voltage_time_sel = regulator_set_voltage_time_sel, 292 + .set_ramp_delay = max77802_set_ramp_delay_2bit, 293 + .set_suspend_disable = max77802_set_suspend_disable, 294 + .set_suspend_mode = max77802_set_suspend_mode, 295 + }; 296 + 297 + /* BUCKs 5, 7-10 */ 335 298 static struct regulator_ops max77802_buck_dvs_ops = { 336 299 .list_voltage = regulator_list_voltage_linear, 337 300 .map_voltage = regulator_map_voltage_linear, ··· 357 290 .set_voltage_sel = regulator_set_voltage_sel_regmap, 358 291 .set_voltage_time_sel = regulator_set_voltage_time_sel, 359 292 .set_ramp_delay = max77802_set_ramp_delay_2bit, 360 - .set_suspend_disable = max77802_buck_set_suspend_disable, 293 + .set_suspend_disable = max77802_set_suspend_disable, 361 294 }; 362 295 363 296 /* LDOs 3-7, 9-14, 18-26, 28, 29, 32-34 */ 364 297 #define regulator_77802_desc_p_ldo(num, supply, log) { \ 365 298 .name = "LDO"#num, \ 299 + .of_match = of_match_ptr("LDO"#num), \ 300 + .regulators_node = of_match_ptr("regulators"), \ 366 301 .id = MAX77802_LDO##num, \ 367 302 .supply_name = "inl"#supply, \ 368 303 .ops = &max77802_ldo_ops_logic##log, \ ··· 378 309 .vsel_mask = MAX77802_VSEL_MASK, \ 379 310 .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \ 380 311 .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \ 312 + .of_map_mode = max77802_map_mode, \ 381 313 } 382 314 383 315 /* LDOs 1, 2, 8, 15, 17, 27, 30, 35 */ 384 316 #define regulator_77802_desc_n_ldo(num, supply, log) { \ 385 317 .name = "LDO"#num, \ 318 + .of_match = of_match_ptr("LDO"#num), \ 319 + .regulators_node = of_match_ptr("regulators"), \ 386 320 .id = MAX77802_LDO##num, \ 387 321 .supply_name = "inl"#supply, \ 388 322 .ops = &max77802_ldo_ops_logic##log, \ ··· 399 327 .vsel_mask = MAX77802_VSEL_MASK, \ 400 328 .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \ 401 329 .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \ 330 + .of_map_mode = max77802_map_mode, \ 402 331 } 403 332 404 333 /* BUCKs 1, 6 */ 405 334 #define regulator_77802_desc_16_buck(num) { \ 406 335 .name = "BUCK"#num, \ 336 + .of_match = of_match_ptr("BUCK"#num), \ 337 + .regulators_node = of_match_ptr("regulators"), \ 407 338 .id = MAX77802_BUCK##num, \ 408 339 .supply_name = "inb"#num, \ 409 340 .ops = &max77802_buck_16_dvs_ops, \ ··· 420 345 .vsel_mask = MAX77802_DVS_VSEL_MASK, \ 421 346 .enable_reg = MAX77802_REG_BUCK ## num ## CTRL, \ 422 347 .enable_mask = MAX77802_OPMODE_MASK, \ 348 + .of_map_mode = max77802_map_mode, \ 423 349 } 424 350 425 351 /* BUCKS 2-4 */ 426 352 #define regulator_77802_desc_234_buck(num) { \ 427 353 .name = "BUCK"#num, \ 354 + .of_match = of_match_ptr("BUCK"#num), \ 355 + .regulators_node = of_match_ptr("regulators"), \ 428 356 .id = MAX77802_BUCK##num, \ 429 357 .supply_name = "inb"#num, \ 430 - .ops = &max77802_buck_dvs_ops, \ 358 + .ops = &max77802_buck_234_ops, \ 431 359 .type = REGULATOR_VOLTAGE, \ 432 360 .owner = THIS_MODULE, \ 433 361 .min_uV = 600000, \ ··· 442 364 .enable_reg = MAX77802_REG_BUCK ## num ## CTRL1, \ 443 365 .enable_mask = MAX77802_OPMODE_MASK << \ 444 366 MAX77802_OPMODE_BUCK234_SHIFT, \ 367 + .of_map_mode = max77802_map_mode, \ 445 368 } 446 369 447 370 /* BUCK 5 */ 448 371 #define regulator_77802_desc_buck5(num) { \ 449 372 .name = "BUCK"#num, \ 373 + .of_match = of_match_ptr("BUCK"#num), \ 374 + .regulators_node = of_match_ptr("regulators"), \ 450 375 .id = MAX77802_BUCK##num, \ 451 376 .supply_name = "inb"#num, \ 452 377 .ops = &max77802_buck_dvs_ops, \ ··· 463 382 .vsel_mask = MAX77802_VSEL_MASK, \ 464 383 .enable_reg = MAX77802_REG_BUCK5CTRL, \ 465 384 .enable_mask = MAX77802_OPMODE_MASK, \ 385 + .of_map_mode = max77802_map_mode, \ 466 386 } 467 387 468 388 /* BUCKs 7-10 */ 469 389 #define regulator_77802_desc_buck7_10(num) { \ 470 390 .name = "BUCK"#num, \ 391 + .of_match = of_match_ptr("BUCK"#num), \ 392 + .regulators_node = of_match_ptr("regulators"), \ 471 393 .id = MAX77802_BUCK##num, \ 472 394 .supply_name = "inb"#num, \ 473 395 .ops = &max77802_buck_dvs_ops, \ ··· 484 400 .vsel_mask = MAX77802_VSEL_MASK, \ 485 401 .enable_reg = MAX77802_REG_BUCK7CTRL + (num - 7) * 3, \ 486 402 .enable_mask = MAX77802_OPMODE_MASK, \ 403 + .of_map_mode = max77802_map_mode, \ 487 404 } 488 405 489 - static struct regulator_desc regulators[] = { 406 + static const struct regulator_desc regulators[] = { 490 407 regulator_77802_desc_16_buck(1), 491 408 regulator_77802_desc_234_buck(2), 492 409 regulator_77802_desc_234_buck(3), ··· 532 447 regulator_77802_desc_n_ldo(35, 2, 1), 533 448 }; 534 449 535 - #ifdef CONFIG_OF 536 - static int max77802_pmic_dt_parse_pdata(struct platform_device *pdev, 537 - struct max77686_platform_data *pdata) 538 - { 539 - struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); 540 - struct device_node *pmic_np, *regulators_np; 541 - struct max77686_regulator_data *rdata; 542 - struct of_regulator_match rmatch = { }; 543 - unsigned int i; 544 - 545 - pmic_np = iodev->dev->of_node; 546 - regulators_np = of_get_child_by_name(pmic_np, "regulators"); 547 - if (!regulators_np) { 548 - dev_err(&pdev->dev, "could not find regulators sub-node\n"); 549 - return -EINVAL; 550 - } 551 - 552 - pdata->num_regulators = ARRAY_SIZE(regulators); 553 - rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) * 554 - pdata->num_regulators, GFP_KERNEL); 555 - if (!rdata) { 556 - of_node_put(regulators_np); 557 - return -ENOMEM; 558 - } 559 - 560 - for (i = 0; i < pdata->num_regulators; i++) { 561 - rmatch.name = regulators[i].name; 562 - rmatch.init_data = NULL; 563 - rmatch.of_node = NULL; 564 - if (of_regulator_match(&pdev->dev, regulators_np, &rmatch, 565 - 1) != 1) { 566 - dev_warn(&pdev->dev, "No matching regulator for '%s'\n", 567 - rmatch.name); 568 - continue; 569 - } 570 - rdata[i].initdata = rmatch.init_data; 571 - rdata[i].of_node = rmatch.of_node; 572 - rdata[i].id = regulators[i].id; 573 - } 574 - 575 - pdata->regulators = rdata; 576 - of_node_put(regulators_np); 577 - 578 - return 0; 579 - } 580 - #else 581 - static int max77802_pmic_dt_parse_pdata(struct platform_device *pdev, 582 - struct max77686_platform_data *pdata) 583 - { 584 - return 0; 585 - } 586 - #endif /* CONFIG_OF */ 587 - 588 450 static int max77802_pmic_probe(struct platform_device *pdev) 589 451 { 590 452 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); 591 - struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev); 592 453 struct max77802_regulator_prv *max77802; 593 - int i, ret = 0, val; 454 + int i, val; 594 455 struct regulator_config config = { }; 595 - 596 - /* This is allocated by the MFD driver */ 597 - if (!pdata) { 598 - dev_err(&pdev->dev, "no platform data found for regulator\n"); 599 - return -ENODEV; 600 - } 601 456 602 457 max77802 = devm_kzalloc(&pdev->dev, 603 458 sizeof(struct max77802_regulator_prv), 604 459 GFP_KERNEL); 605 460 if (!max77802) 606 461 return -ENOMEM; 607 - 608 - if (iodev->dev->of_node) { 609 - ret = max77802_pmic_dt_parse_pdata(pdev, pdata); 610 - if (ret) 611 - return ret; 612 - } 613 462 614 463 config.dev = iodev->dev; 615 464 config.regmap = iodev->regmap; ··· 552 533 553 534 for (i = 0; i < MAX77802_REG_MAX; i++) { 554 535 struct regulator_dev *rdev; 555 - int id = pdata->regulators[i].id; 536 + int id = regulators[i].id; 556 537 int shift = max77802_get_opmode_shift(id); 557 - 558 - config.init_data = pdata->regulators[i].initdata; 559 - config.of_node = pdata->regulators[i].of_node; 538 + int ret; 560 539 561 540 ret = regmap_read(iodev->regmap, regulators[i].enable_reg, &val); 562 - val = val >> shift & MAX77802_OPMODE_MASK; 541 + if (ret < 0) { 542 + dev_warn(&pdev->dev, 543 + "cannot read current mode for %d\n", i); 544 + val = MAX77802_OPMODE_NORMAL; 545 + } else { 546 + val = val >> shift & MAX77802_OPMODE_MASK; 547 + } 563 548 564 549 /* 565 550 * If the regulator is disabled and the system warm rebooted, 566 551 * the hardware reports OFF as the regulator operating mode. 567 552 * Default to operating mode NORMAL in that case. 568 553 */ 569 - if (val == MAX77802_OPMODE_OFF) 554 + if (val == MAX77802_STATUS_OFF) 570 555 max77802->opmode[id] = MAX77802_OPMODE_NORMAL; 571 556 else 572 557 max77802->opmode[id] = val; ··· 578 555 rdev = devm_regulator_register(&pdev->dev, 579 556 &regulators[i], &config); 580 557 if (IS_ERR(rdev)) { 558 + ret = PTR_ERR(rdev); 581 559 dev_err(&pdev->dev, 582 - "regulator init failed for %d\n", i); 583 - return PTR_ERR(rdev); 560 + "regulator init failed for %d: %d\n", i, ret); 561 + return ret; 584 562 } 585 563 } 586 564
+1 -1
drivers/regulator/max8952.c
··· 174 174 if (of_property_read_u32(np, "max8952,ramp-speed", &pd->ramp_speed)) 175 175 dev_warn(dev, "max8952,ramp-speed property not specified, defaulting to 32mV/us\n"); 176 176 177 - pd->reg_data = of_get_regulator_init_data(dev, np); 177 + pd->reg_data = of_get_regulator_init_data(dev, np, &regulator); 178 178 if (!pd->reg_data) { 179 179 dev_err(dev, "Failed to parse regulator init data\n"); 180 180 return NULL;
+2 -1
drivers/regulator/max8973-regulator.c
··· 458 458 459 459 config.dev = &client->dev; 460 460 config.init_data = pdata ? pdata->reg_init_data : 461 - of_get_regulator_init_data(&client->dev, client->dev.of_node); 461 + of_get_regulator_init_data(&client->dev, client->dev.of_node, 462 + &max->desc); 462 463 config.driver_data = max; 463 464 config.of_node = client->dev.of_node; 464 465 config.regmap = max->regmap;
+2 -1
drivers/regulator/max8997.c
··· 953 953 954 954 rdata->id = i; 955 955 rdata->initdata = of_get_regulator_init_data(&pdev->dev, 956 - reg_np); 956 + reg_np, 957 + &regulators[i]); 957 958 rdata->reg_node = reg_np; 958 959 rdata++; 959 960 }
+3 -2
drivers/regulator/max8998.c
··· 686 686 continue; 687 687 688 688 rdata->id = regulators[i].id; 689 - rdata->initdata = of_get_regulator_init_data( 690 - iodev->dev, reg_np); 689 + rdata->initdata = of_get_regulator_init_data(iodev->dev, 690 + reg_np, 691 + &regulators[i]); 691 692 rdata->reg_node = reg_np; 692 693 ++rdata; 693 694 }
+2 -1
drivers/regulator/mc13xxx-regulator-core.c
··· 194 194 regulators[i].desc.name)) { 195 195 p->id = i; 196 196 p->init_data = of_get_regulator_init_data( 197 - &pdev->dev, child); 197 + &pdev->dev, child, 198 + &regulators[i].desc); 198 199 p->node = child; 199 200 p++; 200 201
+81 -6
drivers/regulator/of_regulator.c
··· 19 19 20 20 #include "internal.h" 21 21 22 + static const char *const regulator_states[PM_SUSPEND_MAX + 1] = { 23 + [PM_SUSPEND_MEM] = "regulator-state-mem", 24 + [PM_SUSPEND_MAX] = "regulator-state-disk", 25 + }; 26 + 22 27 static void of_get_regulation_constraints(struct device_node *np, 23 - struct regulator_init_data **init_data) 28 + struct regulator_init_data **init_data, 29 + const struct regulator_desc *desc) 24 30 { 25 31 const __be32 *min_uV, *max_uV; 26 32 struct regulation_constraints *constraints = &(*init_data)->constraints; 27 - int ret; 33 + struct regulator_state *suspend_state; 34 + struct device_node *suspend_np; 35 + int ret, i; 28 36 u32 pval; 29 37 30 38 constraints->name = of_get_property(np, "regulator-name", NULL); ··· 81 73 ret = of_property_read_u32(np, "regulator-enable-ramp-delay", &pval); 82 74 if (!ret) 83 75 constraints->enable_time = pval; 76 + 77 + if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) { 78 + if (desc && desc->of_map_mode) { 79 + ret = desc->of_map_mode(pval); 80 + if (ret == -EINVAL) 81 + pr_err("%s: invalid mode %u\n", np->name, pval); 82 + else 83 + constraints->initial_mode = ret; 84 + } else { 85 + pr_warn("%s: mapping for mode %d not defined\n", 86 + np->name, pval); 87 + } 88 + } 89 + 90 + for (i = 0; i < ARRAY_SIZE(regulator_states); i++) { 91 + switch (i) { 92 + case PM_SUSPEND_MEM: 93 + suspend_state = &constraints->state_mem; 94 + break; 95 + case PM_SUSPEND_MAX: 96 + suspend_state = &constraints->state_disk; 97 + break; 98 + case PM_SUSPEND_ON: 99 + case PM_SUSPEND_FREEZE: 100 + case PM_SUSPEND_STANDBY: 101 + default: 102 + continue; 103 + }; 104 + 105 + suspend_np = of_get_child_by_name(np, regulator_states[i]); 106 + if (!suspend_np || !suspend_state) 107 + continue; 108 + 109 + if (!of_property_read_u32(suspend_np, "regulator-mode", 110 + &pval)) { 111 + if (desc && desc->of_map_mode) { 112 + ret = desc->of_map_mode(pval); 113 + if (ret == -EINVAL) 114 + pr_err("%s: invalid mode %u\n", 115 + np->name, pval); 116 + else 117 + suspend_state->mode = ret; 118 + } else { 119 + pr_warn("%s: mapping for mode %d not defined\n", 120 + np->name, pval); 121 + } 122 + } 123 + 124 + if (of_property_read_bool(suspend_np, 125 + "regulator-on-in-suspend")) 126 + suspend_state->enabled = true; 127 + else if (of_property_read_bool(suspend_np, 128 + "regulator-off-in-suspend")) 129 + suspend_state->disabled = true; 130 + 131 + if (!of_property_read_u32(suspend_np, 132 + "regulator-suspend-microvolt", &pval)) 133 + suspend_state->uV = pval; 134 + 135 + of_node_put(suspend_np); 136 + suspend_state = NULL; 137 + suspend_np = NULL; 138 + } 84 139 } 85 140 86 141 /** 87 142 * of_get_regulator_init_data - extract regulator_init_data structure info 88 143 * @dev: device requesting for regulator_init_data 144 + * @node: regulator device node 145 + * @desc: regulator description 89 146 * 90 147 * Populates regulator_init_data structure by extracting data from device 91 148 * tree node, returns a pointer to the populated struture or NULL if memory 92 149 * alloc fails. 93 150 */ 94 151 struct regulator_init_data *of_get_regulator_init_data(struct device *dev, 95 - struct device_node *node) 152 + struct device_node *node, 153 + const struct regulator_desc *desc) 96 154 { 97 155 struct regulator_init_data *init_data; 98 156 ··· 169 95 if (!init_data) 170 96 return NULL; /* Out of memory? */ 171 97 172 - of_get_regulation_constraints(node, &init_data); 98 + of_get_regulation_constraints(node, &init_data, desc); 173 99 return init_data; 174 100 } 175 101 EXPORT_SYMBOL_GPL(of_get_regulator_init_data); ··· 250 176 continue; 251 177 252 178 match->init_data = 253 - of_get_regulator_init_data(dev, child); 179 + of_get_regulator_init_data(dev, child, 180 + match->desc); 254 181 if (!match->init_data) { 255 182 dev_err(dev, 256 183 "failed to parse DT for regulator %s\n", ··· 299 224 if (strcmp(desc->of_match, name)) 300 225 continue; 301 226 302 - init_data = of_get_regulator_init_data(dev, child); 227 + init_data = of_get_regulator_init_data(dev, child, desc); 303 228 if (!init_data) { 304 229 dev_err(dev, 305 230 "failed to parse DT for regulator %s\n",
+2 -1
drivers/regulator/pwm-regulator.c
··· 149 149 return ret; 150 150 } 151 151 152 - config.init_data = of_get_regulator_init_data(&pdev->dev, np); 152 + config.init_data = of_get_regulator_init_data(&pdev->dev, np, 153 + &drvdata->desc); 153 154 if (!config.init_data) 154 155 return -ENOMEM; 155 156
+5 -4
drivers/regulator/qcom_rpm-regulator.c
··· 643 643 match = of_match_device(rpm_of_match, &pdev->dev); 644 644 template = match->data; 645 645 646 - initdata = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node); 647 - if (!initdata) 648 - return -EINVAL; 649 - 650 646 vreg = devm_kmalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL); 651 647 if (!vreg) { 652 648 dev_err(&pdev->dev, "failed to allocate vreg\n"); ··· 661 665 dev_err(&pdev->dev, "unable to retrieve handle to rpm\n"); 662 666 return -ENODEV; 663 667 } 668 + 669 + initdata = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node, 670 + &vreg->desc); 671 + if (!initdata) 672 + return -EINVAL; 664 673 665 674 key = "reg"; 666 675 ret = of_property_read_u32(pdev->dev.of_node, key, &val);
+54 -3
drivers/regulator/rk808-regulator.c
··· 36 36 #define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET) 37 37 #define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET) 38 38 39 + /* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */ 40 + #define RK808_SLP_REG_OFFSET 1 41 + 42 + /* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */ 43 + #define RK808_SLP_SET_OFF_REG_OFFSET 2 44 + 39 45 static const int rk808_buck_config_regs[] = { 40 46 RK808_BUCK1_CONFIG_REG, 41 47 RK808_BUCK2_CONFIG_REG, ··· 97 91 RK808_RAMP_RATE_MASK, ramp_value); 98 92 } 99 93 94 + int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv) 95 + { 96 + unsigned int reg; 97 + int sel = regulator_map_voltage_linear_range(rdev, uv, uv); 98 + 99 + if (sel < 0) 100 + return -EINVAL; 101 + 102 + reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET; 103 + 104 + return regmap_update_bits(rdev->regmap, reg, 105 + rdev->desc->vsel_mask, 106 + sel); 107 + } 108 + 109 + int rk808_set_suspend_enable(struct regulator_dev *rdev) 110 + { 111 + unsigned int reg; 112 + 113 + reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET; 114 + 115 + return regmap_update_bits(rdev->regmap, reg, 116 + rdev->desc->enable_mask, 117 + 0); 118 + } 119 + 120 + int rk808_set_suspend_disable(struct regulator_dev *rdev) 121 + { 122 + unsigned int reg; 123 + 124 + reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET; 125 + 126 + return regmap_update_bits(rdev->regmap, reg, 127 + rdev->desc->enable_mask, 128 + rdev->desc->enable_mask); 129 + } 130 + 100 131 static struct regulator_ops rk808_buck1_2_ops = { 101 132 .list_voltage = regulator_list_voltage_linear_range, 102 133 .map_voltage = regulator_map_voltage_linear_range, ··· 143 100 .disable = regulator_disable_regmap, 144 101 .is_enabled = regulator_is_enabled_regmap, 145 102 .set_ramp_delay = rk808_set_ramp_delay, 103 + .set_suspend_voltage = rk808_set_suspend_voltage, 104 + .set_suspend_enable = rk808_set_suspend_enable, 105 + .set_suspend_disable = rk808_set_suspend_disable, 146 106 }; 147 107 148 108 static struct regulator_ops rk808_reg_ops = { ··· 156 110 .enable = regulator_enable_regmap, 157 111 .disable = regulator_disable_regmap, 158 112 .is_enabled = regulator_is_enabled_regmap, 113 + .set_suspend_voltage = rk808_set_suspend_voltage, 114 + .set_suspend_enable = rk808_set_suspend_enable, 115 + .set_suspend_disable = rk808_set_suspend_disable, 159 116 }; 160 117 161 118 static struct regulator_ops rk808_switch_ops = { 162 - .enable = regulator_enable_regmap, 163 - .disable = regulator_disable_regmap, 164 - .is_enabled = regulator_is_enabled_regmap, 119 + .enable = regulator_enable_regmap, 120 + .disable = regulator_disable_regmap, 121 + .is_enabled = regulator_is_enabled_regmap, 122 + .set_suspend_enable = rk808_set_suspend_enable, 123 + .set_suspend_disable = rk808_set_suspend_disable, 165 124 }; 166 125 167 126 static const struct regulator_desc rk808_reg[] = {
+2 -1
drivers/regulator/s5m8767.c
··· 581 581 582 582 rdata->id = i; 583 583 rdata->initdata = of_get_regulator_init_data( 584 - &pdev->dev, reg_np); 584 + &pdev->dev, reg_np, 585 + &regulators[i]); 585 586 rdata->reg_node = reg_np; 586 587 rdata++; 587 588 rmode->id = i;
+1 -1
drivers/regulator/sky81452-regulator.c
··· 76 76 return NULL; 77 77 } 78 78 79 - init_data = of_get_regulator_init_data(dev, np); 79 + init_data = of_get_regulator_init_data(dev, np, &sky81452_reg); 80 80 81 81 of_node_put(np); 82 82 return init_data;
+2 -1
drivers/regulator/stw481x-vmmc.c
··· 72 72 config.regmap = stw481x->map; 73 73 config.of_node = pdev->dev.of_node; 74 74 config.init_data = of_get_regulator_init_data(&pdev->dev, 75 - pdev->dev.of_node); 75 + pdev->dev.of_node, 76 + &vmmc_regulator); 76 77 77 78 stw481x->vmmc_regulator = devm_regulator_register(&pdev->dev, 78 79 &vmmc_regulator, &config);
+2 -1
drivers/regulator/ti-abb-regulator.c
··· 837 837 return -EINVAL; 838 838 } 839 839 840 - initdata = of_get_regulator_init_data(dev, pdev->dev.of_node); 840 + initdata = of_get_regulator_init_data(dev, pdev->dev.of_node, 841 + &abb->rdesc); 841 842 if (!initdata) { 842 843 dev_err(dev, "%s: Unable to alloc regulator init data\n", 843 844 __func__);
+23 -20
drivers/regulator/tps51632-regulator.c
··· 221 221 MODULE_DEVICE_TABLE(of, tps51632_of_match); 222 222 223 223 static struct tps51632_regulator_platform_data * 224 - of_get_tps51632_platform_data(struct device *dev) 224 + of_get_tps51632_platform_data(struct device *dev, 225 + const struct regulator_desc *desc) 225 226 { 226 227 struct tps51632_regulator_platform_data *pdata; 227 228 struct device_node *np = dev->of_node; ··· 231 230 if (!pdata) 232 231 return NULL; 233 232 234 - pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node); 233 + pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node, 234 + desc); 235 235 if (!pdata->reg_init_data) { 236 236 dev_err(dev, "Not able to get OF regulator init data\n"); 237 237 return NULL; ··· 250 248 } 251 249 #else 252 250 static struct tps51632_regulator_platform_data * 253 - of_get_tps51632_platform_data(struct device *dev) 251 + of_get_tps51632_platform_data(struct device *dev, 252 + const struct regulator_desc *desc) 254 253 { 255 254 return NULL; 256 255 } ··· 276 273 } 277 274 } 278 275 276 + tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 277 + if (!tps) 278 + return -ENOMEM; 279 + 280 + tps->dev = &client->dev; 281 + tps->desc.name = client->name; 282 + tps->desc.id = 0; 283 + tps->desc.ramp_delay = TPS51632_DEFAULT_RAMP_DELAY; 284 + tps->desc.min_uV = TPS51632_MIN_VOLTAGE; 285 + tps->desc.uV_step = TPS51632_VOLTAGE_STEP_10mV; 286 + tps->desc.linear_min_sel = TPS51632_MIN_VSEL; 287 + tps->desc.n_voltages = TPS51632_MAX_VSEL + 1; 288 + tps->desc.ops = &tps51632_dcdc_ops; 289 + tps->desc.type = REGULATOR_VOLTAGE; 290 + tps->desc.owner = THIS_MODULE; 291 + 279 292 pdata = dev_get_platdata(&client->dev); 280 293 if (!pdata && client->dev.of_node) 281 - pdata = of_get_tps51632_platform_data(&client->dev); 294 + pdata = of_get_tps51632_platform_data(&client->dev, &tps->desc); 282 295 if (!pdata) { 283 296 dev_err(&client->dev, "No Platform data\n"); 284 297 return -EINVAL; ··· 314 295 return -EINVAL; 315 296 } 316 297 } 317 - 318 - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 319 - if (!tps) 320 - return -ENOMEM; 321 - 322 - tps->dev = &client->dev; 323 - tps->desc.name = client->name; 324 - tps->desc.id = 0; 325 - tps->desc.ramp_delay = TPS51632_DEFAULT_RAMP_DELAY; 326 - tps->desc.min_uV = TPS51632_MIN_VOLTAGE; 327 - tps->desc.uV_step = TPS51632_VOLTAGE_STEP_10mV; 328 - tps->desc.linear_min_sel = TPS51632_MIN_VSEL; 329 - tps->desc.n_voltages = TPS51632_MAX_VSEL + 1; 330 - tps->desc.ops = &tps51632_dcdc_ops; 331 - tps->desc.type = REGULATOR_VOLTAGE; 332 - tps->desc.owner = THIS_MODULE; 333 298 334 299 if (pdata->enable_pwm_dvfs) 335 300 tps->desc.vsel_reg = TPS51632_VOLTAGE_BASE_REG;
+17 -14
drivers/regulator/tps62360-regulator.c
··· 293 293 }; 294 294 295 295 static struct tps62360_regulator_platform_data * 296 - of_get_tps62360_platform_data(struct device *dev) 296 + of_get_tps62360_platform_data(struct device *dev, 297 + const struct regulator_desc *desc) 297 298 { 298 299 struct tps62360_regulator_platform_data *pdata; 299 300 struct device_node *np = dev->of_node; ··· 303 302 if (!pdata) 304 303 return NULL; 305 304 306 - pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node); 305 + pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node, 306 + desc); 307 307 if (!pdata->reg_init_data) { 308 308 dev_err(dev, "Not able to get OF regulator init data\n"); 309 309 return NULL; ··· 352 350 353 351 pdata = dev_get_platdata(&client->dev); 354 352 353 + tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 354 + if (!tps) 355 + return -ENOMEM; 356 + 357 + tps->desc.name = client->name; 358 + tps->desc.id = 0; 359 + tps->desc.ops = &tps62360_dcdc_ops; 360 + tps->desc.type = REGULATOR_VOLTAGE; 361 + tps->desc.owner = THIS_MODULE; 362 + tps->desc.uV_step = 10000; 363 + 355 364 if (client->dev.of_node) { 356 365 const struct of_device_id *match; 357 366 match = of_match_device(of_match_ptr(tps62360_of_match), ··· 373 360 } 374 361 chip_id = (int)(long)match->data; 375 362 if (!pdata) 376 - pdata = of_get_tps62360_platform_data(&client->dev); 363 + pdata = of_get_tps62360_platform_data(&client->dev, 364 + &tps->desc); 377 365 } else if (id) { 378 366 chip_id = id->driver_data; 379 367 } else { ··· 387 373 __func__); 388 374 return -EIO; 389 375 } 390 - 391 - tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 392 - if (!tps) 393 - return -ENOMEM; 394 376 395 377 tps->en_discharge = pdata->en_discharge; 396 378 tps->en_internal_pulldn = pdata->en_internal_pulldn; ··· 410 400 default: 411 401 return -ENODEV; 412 402 } 413 - 414 - tps->desc.name = client->name; 415 - tps->desc.id = 0; 416 - tps->desc.ops = &tps62360_dcdc_ops; 417 - tps->desc.type = REGULATOR_VOLTAGE; 418 - tps->desc.owner = THIS_MODULE; 419 - tps->desc.uV_step = 10000; 420 403 421 404 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config); 422 405 if (IS_ERR(tps->regmap)) {
+2 -1
drivers/regulator/tps65218-regulator.c
··· 231 231 232 232 template = match->data; 233 233 id = template->id; 234 - init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node); 234 + init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node, 235 + &regulators[id]); 235 236 236 237 platform_set_drvdata(pdev, tps); 237 238
+2 -1
drivers/regulator/twl-regulator.c
··· 1104 1104 template = match->data; 1105 1105 id = template->desc.id; 1106 1106 initdata = of_get_regulator_init_data(&pdev->dev, 1107 - pdev->dev.of_node); 1107 + pdev->dev.of_node, 1108 + &template->desc); 1108 1109 drvdata = NULL; 1109 1110 } else { 1110 1111 id = pdev->id;
+2 -1
drivers/regulator/vexpress.c
··· 74 74 reg->desc.owner = THIS_MODULE; 75 75 reg->desc.continuous_voltage_range = true; 76 76 77 - init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node); 77 + init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node, 78 + &reg->desc); 78 79 if (!init_data) 79 80 return -EINVAL; 80 81
+18
include/dt-bindings/regulator/maxim,max77802.h
··· 1 + /* 2 + * Copyright (C) 2014 Google, Inc 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + * Device Tree binding constants for the Maxim 77802 PMIC regulators 9 + */ 10 + 11 + #ifndef _DT_BINDINGS_REGULATOR_MAXIM_MAX77802_H 12 + #define _DT_BINDINGS_REGULATOR_MAXIM_MAX77802_H 13 + 14 + /* Regulator operating modes */ 15 + #define MAX77802_OPMODE_LP 1 16 + #define MAX77802_OPMODE_NORMAL 3 17 + 18 + #endif /* _DT_BINDINGS_REGULATOR_MAXIM_MAX77802_H */
-7
include/linux/mfd/max77686.h
··· 131 131 MAX77686_OPMODE_STANDBY, 132 132 }; 133 133 134 - enum max77802_opmode { 135 - MAX77802_OPMODE_OFF, 136 - MAX77802_OPMODE_STANDBY, 137 - MAX77802_OPMODE_LP, 138 - MAX77802_OPMODE_NORMAL, 139 - }; 140 - 141 134 struct max77686_opmode_data { 142 135 int id; 143 136 int mode;
+11
include/linux/of.h
··· 922 922 /* CONFIG_OF_RESOLVE api */ 923 923 extern int of_resolve_phandles(struct device_node *tree); 924 924 925 + /** 926 + * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node 927 + * @np: Pointer to the given device_node 928 + * 929 + * return true if present false otherwise 930 + */ 931 + static inline bool of_device_is_system_power_controller(const struct device_node *np) 932 + { 933 + return of_property_read_bool(np, "system-power-controller"); 934 + } 935 + 925 936 #endif /* _LINUX_OF_H */
+4
include/linux/regulator/driver.h
··· 243 243 * 244 244 * @enable_time: Time taken for initial enable of regulator (in uS). 245 245 * @off_on_delay: guard time (in uS), before re-enabling a regulator 246 + * 247 + * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode 246 248 */ 247 249 struct regulator_desc { 248 250 const char *name; ··· 287 285 unsigned int enable_time; 288 286 289 287 unsigned int off_on_delay; 288 + 289 + unsigned int (*of_map_mode)(unsigned int mode); 290 290 }; 291 291 292 292 /**
+7 -2
include/linux/regulator/of_regulator.h
··· 6 6 #ifndef __LINUX_OF_REG_H 7 7 #define __LINUX_OF_REG_H 8 8 9 + struct regulator_desc; 10 + 9 11 struct of_regulator_match { 10 12 const char *name; 11 13 void *driver_data; 12 14 struct regulator_init_data *init_data; 13 15 struct device_node *of_node; 16 + const struct regulator_desc *desc; 14 17 }; 15 18 16 19 #if defined(CONFIG_OF) 17 20 extern struct regulator_init_data 18 21 *of_get_regulator_init_data(struct device *dev, 19 - struct device_node *node); 22 + struct device_node *node, 23 + const struct regulator_desc *desc); 20 24 extern int of_regulator_match(struct device *dev, struct device_node *node, 21 25 struct of_regulator_match *matches, 22 26 unsigned int num_matches); 23 27 #else 24 28 static inline struct regulator_init_data 25 29 *of_get_regulator_init_data(struct device *dev, 26 - struct device_node *node) 30 + struct device_node *node, 31 + const struct regulator_desc *desc) 27 32 { 28 33 return NULL; 29 34 }