History

Merge branch 'regulator-5.2' into regulator-next

Mark Brown committed 7 years ago

Commit e2a23af2 parents c7b5128 498209489 files · +1323 −2770Browse files

Unified · Split

89 files
  1. Documentation/devicetree/bindings/regulator/gpio-regulator.txt +22 −8
  2. Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt +43 −0
  3. drivers/mfd/wm831x-core.c +1 −1
  4. drivers/mfd/wm8400-core.c +0 −6
  5. drivers/regulator/88pm800.c +1 −17
  6. drivers/regulator/88pm8607.c +9 −34
  7. drivers/regulator/Kconfig +10 −1
  8. drivers/regulator/Makefile +1 −0
  9. drivers/regulator/ab3100.c +12 −33
  10. drivers/regulator/ab8500-ext.c +14 −35
  11. drivers/regulator/ab8500.c +9 −11
  12. drivers/regulator/act8865-regulator.c +21 −126
  13. drivers/regulator/anatop-regulator.c +27 −36
  14. drivers/regulator/arizona-ldo1.c +7 −12
  15. drivers/regulator/arizona-micsupp.c +7 −12
  16. drivers/regulator/as3711-regulator.c +7 −30
  17. drivers/regulator/as3722-regulator.c +86 −201
  18. drivers/regulator/axp20x-regulator.c +8 −15
  19. drivers/regulator/bcm590xx-regulator.c +2 −103
  20. drivers/regulator/bd718x7-regulator.c +2 −2
  21. drivers/regulator/core.c +9 −6
  22. drivers/regulator/cpcap-regulator.c +4 −11
  23. drivers/regulator/da903x.c +6 −10
  24. drivers/regulator/da9052-regulator.c +13 −42
  25. drivers/regulator/da9055-regulator.c +15 −74
  26. drivers/regulator/da9062-regulator.c +39 −107
  27. drivers/regulator/da9063-regulator.c +40 −94
  28. drivers/regulator/da9210-regulator.c +4 −19
  29. drivers/regulator/da9210-regulator.h +1 −16
  30. drivers/regulator/da9211-regulator.c +9 −15
  31. drivers/regulator/da9211-regulator.h +1 −10
  32. drivers/regulator/db8500-prcmu.c +44 −99
  33. drivers/regulator/dbx500-prcmu.h +0 −4
  34. drivers/regulator/fan53555.c +27 −33
  35. drivers/regulator/gpio-regulator.c +6 −16
  36. drivers/regulator/hi6421-regulator.c +88 −144
  37. drivers/regulator/hi6421v530-regulator.c +11 −15
  38. drivers/regulator/hi655x-regulator.c +13 −24
  39. drivers/regulator/lm363x-regulator.c +4 −4
  40. drivers/regulator/lp8755.c +12 −3
  41. drivers/regulator/lp87565-regulator.c +8 −41
  42. drivers/regulator/ltc3589.c +89 −180
  43. drivers/regulator/ltc3676.c +8 −2
  44. drivers/regulator/max14577-regulator.c +0 −55
  45. drivers/regulator/max77650-regulator.c +1 −1
  46. drivers/regulator/max8925-regulator.c +9 −67
  47. drivers/regulator/max8998.c +59 −241
  48. drivers/regulator/mcp16502.c +22 −45
  49. drivers/regulator/mt6311-regulator.c +4 −13
  50. drivers/regulator/mt6311-regulator.h +1 −9
  51. drivers/regulator/mt6323-regulator.c +14 −18
  52. drivers/regulator/mt6380-regulator.c +8 −17
  53. drivers/regulator/mt6397-regulator.c +12 −21
  54. drivers/regulator/of_regulator.c +3 −2
  55. drivers/regulator/palmas-regulator.c +0 −12
  56. drivers/regulator/pv88060-regulator.c +8 −14
  57. drivers/regulator/pv88060-regulator.h +1 −10
  58. drivers/regulator/pv88080-regulator.c +8 −14
  59. drivers/regulator/pv88080-regulator.h +1 −10
  60. drivers/regulator/pv88090-regulator.c +8 −14
  61. drivers/regulator/pv88090-regulator.h +1 −10
  62. drivers/regulator/rc5t583-regulator.c +3 −22
  63. drivers/regulator/rn5t618-regulator.c +4 −4
  64. drivers/regulator/s2mpa01.c +10 −31
  65. drivers/regulator/sc2731-regulator.c +1 −1
  66. drivers/regulator/sky81452-regulator.c +7 −19
  67. drivers/regulator/stm32-pwr.c +186 −0
  68. drivers/regulator/sy8106a-regulator.c +13 −27
  69. drivers/regulator/tps6507x-regulator.c +20 −93
  70. drivers/regulator/tps65086-regulator.c +2 −2
  71. drivers/regulator/tps65132-regulator.c +13 −16
  72. drivers/regulator/tps65217-regulator.c +3 −4
  73. drivers/regulator/tps65218-regulator.c +23 −33
  74. drivers/regulator/tps6524x-regulator.c +5 −6
  75. drivers/regulator/tps80031-regulator.c +16 −32
  76. drivers/regulator/twl-regulator.c +3 −3
  77. drivers/regulator/vctrl-regulator.c +1 −3
  78. drivers/regulator/vexpress-regulator.c +27 −45
  79. drivers/regulator/wm831x-dcdc.c +11 −12
  80. drivers/regulator/wm831x-isink.c +16 −50
  81. drivers/regulator/wm831x-ldo.c +9 −12
  82. drivers/regulator/wm8350-regulator.c +19 −83
  83. drivers/regulator/wm8400-regulator.c +16 −23
  84. drivers/regulator/wm8994-regulator.c +7 −12
  85. include/linux/mfd/palmas.h +0 −1
  86. include/linux/mfd/wm831x/regulator.h +1 −1
  87. include/linux/mfd/wm8400-private.h +0 −8
  88. include/linux/regulator/consumer.h +5 −0
  89. sound/soc/codecs/ab8500-codec.c +2 −2
Documentation/devicetree/bindings/regulator/gpio-regulator.txt+22−8
@@ -4,16 +4,30 @@ Required properties: · 3 unmodified lines
4- compatible : Must be "regulator-gpio".4- compatible : Must be "regulator-gpio".
5- regulator-name : Defined in regulator.txt as optional, but required5- regulator-name : Defined in regulator.txt as optional, but required
6 here.6 here.
7- states : Selection of available voltages and GPIO configs.7- gpios : Array of one or more GPIO pins used to select the
8 if there are no states, then use a fixed regulator8 regulator voltage/current listed in "states".
9- states : Selection of available voltages/currents provided by
10 this regulator and matching GPIO configurations to
11 achieve them. If there are no states in the "states"
12 array, use a fixed regulator instead.
9 13
10Optional properties:14Optional properties:
11- enable-gpio : GPIO to use to enable/disable the regulator.15- enable-gpios : GPIO used to enable/disable the regulator.
12- gpios : GPIO group used to control voltage.16 Warning, the GPIO phandle flags are ignored and the
13- gpios-states : gpios pin's initial states array. 0: LOW, 1: HIGH.17 GPIO polarity is controlled solely by the presence
14 defualt is LOW if nothing is specified.18 of "enable-active-high" DT property. This is due to
19 compatibility with old DTs.
20- enable-active-high : Polarity of "enable-gpio" GPIO is active HIGH.
21 Default is active LOW.
22- gpios-states : On operating systems, that don't support reading back
23 gpio values in output mode (most notably linux), this
24 array provides the state of GPIO pins set when
25 requesting them from the gpio controller. Systems,
26 that are capable of preserving state when requesting
27 the lines, are free to ignore this property.
28 0: LOW, 1: HIGH. Default is LOW if nothing else
29 is specified.
15- startup-delay-us : Startup time in microseconds.30- startup-delay-us : Startup time in microseconds.
16- enable-active-high : Polarity of GPIO is active high (default is low).
17- regulator-type : Specifies what is being regulated, must be either31- regulator-type : Specifies what is being regulated, must be either
18 "voltage" or "current", defaults to voltage.32 "voltage" or "current", defaults to voltage.
19 33
@@ -30,7 +44,7 @@ Example: · 10 unmodified lines
30 regulator-max-microvolt = <2600000>;44 regulator-max-microvolt = <2600000>;
31 regulator-boot-on;45 regulator-boot-on;
32 46
33 enable-gpio = <&gpio0 23 0x4>;47 enable-gpios = <&gpio0 23 0x4>;
34 gpios = <&gpio0 24 0x448 gpios = <&gpio0 24 0x4
35 &gpio0 25 0x4>;49 &gpio0 25 0x4>;
36 states = <1800000 0x350 states = <1800000 0x3
Documentation/devicetree/bindings/regulator/st,stm32mp1-pwr-reg.txt+43−0
@@ -0,0 +1,43 @@
1STM32MP1 PWR Regulators
2-----------------------
3
4Available Regulators in STM32MP1 PWR block are:
5 - reg11 for regulator 1V1
6 - reg18 for regulator 1V8
7 - usb33 for the swtich USB3V3
8
9Required properties:
10- compatible: Must be "st,stm32mp1,pwr-reg"
11- list of child nodes that specify the regulator reg11, reg18 or usb33
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- vdd-supply: phandle to the parent supply/regulator node for vdd input
16- vdd_3v3_usbfs-supply: phandle to the parent supply/regulator node for usb33
17
18Example:
19
20pwr_regulators: pwr@50001000 {
21 compatible = "st,stm32mp1,pwr-reg";
22 reg = <0x50001000 0x10>;
23 vdd-supply = <&vdd>;
24 vdd_3v3_usbfs-supply = <&vdd_usb>;
25
26 reg11: reg11 {
27 regulator-name = "reg11";
28 regulator-min-microvolt = <1100000>;
29 regulator-max-microvolt = <1100000>;
30 };
31
32 reg18: reg18 {
33 regulator-name = "reg18";
34 regulator-min-microvolt = <1800000>;
35 regulator-max-microvolt = <1800000>;
36 };
37
38 usb33: usb33 {
39 regulator-name = "usb33";
40 regulator-min-microvolt = <3300000>;
41 regulator-max-microvolt = <3300000>;
42 };
43};
drivers/mfd/wm831x-core.c+1−1
@@ -34,7 +34,7 @@ · 33 unmodified lines
34/* Current settings - values are 2*2^(reg_val/4) microamps. These are34/* Current settings - values are 2*2^(reg_val/4) microamps. These are
35 * exported since they are used by multiple drivers.35 * exported since they are used by multiple drivers.
36 */36 */
37int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {37const unsigned int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
38 2,38 2,
39 2,39 2,
40 3,40 3,
drivers/mfd/wm8400-core.c+0−6
@@ -35,12 +35,6 @@ static bool wm8400_volatile(struct device *dev, unsigned int reg) · 34 unmodified lines
35 }35 }
36}36}
37 37
38int wm8400_block_read(struct wm8400 *wm8400, u8 reg, int count, u16 *data)
39{
40 return regmap_bulk_read(wm8400->regmap, reg, data, count);
41}
42EXPORT_SYMBOL_GPL(wm8400_block_read);
43
44static int wm8400_register_codec(struct wm8400 *wm8400)38static int wm8400_register_codec(struct wm8400 *wm8400)
45{39{
46 const struct mfd_cell cell = {40 const struct mfd_cell cell = {
drivers/regulator/88pm800.c+1−17
@@ -77,11 +77,6 @@ struct pm800_regulator_info { · 76 unmodified lines
77 int max_ua;77 int max_ua;
78};78};
79 79
80struct pm800_regulators {
81 struct pm80x_chip *chip;
82 struct regmap *map;
83};
84
85/*80/*
86 * vreg - the buck regs string.81 * vreg - the buck regs string.
87 * ereg - the string for the enable register.82 * ereg - the string for the enable register.
@@ -235,7 +230,6 @@ static int pm800_regulator_probe(struct platform_device *pdev) · 147 unmodified lines
235{230{
236 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);231 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
237 struct pm80x_platform_data *pdata = dev_get_platdata(pdev->dev.parent);232 struct pm80x_platform_data *pdata = dev_get_platdata(pdev->dev.parent);
238 struct pm800_regulators *pm800_data;
239 struct regulator_config config = { };233 struct regulator_config config = { };
240 struct regulator_init_data *init_data;234 struct regulator_init_data *init_data;
241 int i, ret;235 int i, ret;
@@ -252,18 +246,8 @@ static int pm800_regulator_probe(struct platform_device *pdev) · 10 unmodified lines
252 return -EINVAL;246 return -EINVAL;
253 }247 }
254 248
255 pm800_data = devm_kzalloc(&pdev->dev, sizeof(*pm800_data),
256 GFP_KERNEL);
257 if (!pm800_data)
258 return -ENOMEM;
259
260 pm800_data->map = chip->subchip->regmap_power;
261 pm800_data->chip = chip;
262
263 platform_set_drvdata(pdev, pm800_data);
264
265 config.dev = chip->dev;249 config.dev = chip->dev;
266 config.regmap = pm800_data->map;250 config.regmap = chip->subchip->regmap_power;
267 for (i = 0; i < PM800_ID_RG_MAX; i++) {251 for (i = 0; i < PM800_ID_RG_MAX; i++) {
268 struct regulator_dev *regulator;252 struct regulator_dev *regulator;
269 253
drivers/regulator/88pm8607.c+9−34
@@ -235,6 +235,8 @@ static const struct regulator_ops pm8606_preg_ops = { · 234 unmodified lines
235{ \235{ \
236 .desc = { \236 .desc = { \
237 .name = "PREG", \237 .name = "PREG", \
238 .of_match = of_match_ptr("PREG"), \
239 .regulators_node = of_match_ptr("regulators"), \
238 .ops = &pm8606_preg_ops, \240 .ops = &pm8606_preg_ops, \
239 .type = REGULATOR_CURRENT, \241 .type = REGULATOR_CURRENT, \
240 .id = PM8606_ID_PREG, \242 .id = PM8606_ID_PREG, \
@@ -249,6 +251,8 @@ static const struct regulator_ops pm8606_preg_ops = { · 8 unmodified lines
249{ \251{ \
250 .desc = { \252 .desc = { \
251 .name = #vreg, \253 .name = #vreg, \
254 .of_match = of_match_ptr(#vreg), \
255 .regulators_node = of_match_ptr("regulators"), \
252 .ops = &pm8607_regulator_ops, \256 .ops = &pm8607_regulator_ops, \
253 .type = REGULATOR_VOLTAGE, \257 .type = REGULATOR_VOLTAGE, \
254 .id = PM8607_ID_##vreg, \258 .id = PM8607_ID_##vreg, \
@@ -270,6 +274,8 @@ static const struct regulator_ops pm8606_preg_ops = { · 15 unmodified lines
270{ \274{ \
271 .desc = { \275 .desc = { \
272 .name = "LDO" #_id, \276 .name = "LDO" #_id, \
277 .of_match = of_match_ptr("LDO" #_id), \
278 .regulators_node = of_match_ptr("regulators"), \
273 .ops = &pm8607_regulator_ops, \279 .ops = &pm8607_regulator_ops, \
274 .type = REGULATOR_VOLTAGE, \280 .type = REGULATOR_VOLTAGE, \
275 .id = PM8607_ID_LDO##_id, \281 .id = PM8607_ID_LDO##_id, \
@@ -309,36 +315,6 @@ static struct pm8607_regulator_info pm8606_regulator_info[] = { · 33 unmodified lines
309 PM8606_PREG(PREREGULATORB, 5),315 PM8606_PREG(PREREGULATORB, 5),
310};316};
311 317
312#ifdef CONFIG_OF
313static int pm8607_regulator_dt_init(struct platform_device *pdev,
314 struct pm8607_regulator_info *info,
315 struct regulator_config *config)
316{
317 struct device_node *nproot, *np;
318 nproot = pdev->dev.parent->of_node;
319 if (!nproot)
320 return -ENODEV;
321 nproot = of_get_child_by_name(nproot, "regulators");
322 if (!nproot) {
323 dev_err(&pdev->dev, "failed to find regulators node\n");
324 return -ENODEV;
325 }
326 for_each_child_of_node(nproot, np) {
327 if (of_node_name_eq(np, info->desc.name)) {
328 config->init_data =
329 of_get_regulator_init_data(&pdev->dev, np,
330 &info->desc);
331 config->of_node = np;
332 break;
333 }
334 }
335 of_node_put(nproot);
336 return 0;
337}
338#else
339#define pm8607_regulator_dt_init(x, y, z) (-1)
340#endif
341
342static int pm8607_regulator_probe(struct platform_device *pdev)318static int pm8607_regulator_probe(struct platform_device *pdev)
343{319{
344 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);320 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
@@ -373,12 +349,11 @@ static int pm8607_regulator_probe(struct platform_device *pdev) · 28 unmodified lines
373 if ((i == PM8607_ID_BUCK3) && chip->buck3_double)349 if ((i == PM8607_ID_BUCK3) && chip->buck3_double)
374 info->slope_double = 1;350 info->slope_double = 1;
375 351
376 config.dev = &pdev->dev;352 config.dev = chip->dev;
377 config.driver_data = info;353 config.driver_data = info;
378 354
379 if (pm8607_regulator_dt_init(pdev, info, &config))355 if (pdata)
380 if (pdata)356 config.init_data = pdata;
381 config.init_data = pdata;
382 357
383 if (chip->id == CHIP_PM8607)358 if (chip->id == CHIP_PM8607)
384 config.regmap = chip->regmap;359 config.regmap = chip->regmap;
drivers/regulator/Kconfig+10−1
@@ -223,6 +223,7 @@ config REGULATOR_CPCAP · 222 unmodified lines
223config REGULATOR_DA903X223config REGULATOR_DA903X
224 tristate "Dialog Semiconductor DA9030/DA9034 regulators"224 tristate "Dialog Semiconductor DA9030/DA9034 regulators"
225 depends on PMIC_DA903X225 depends on PMIC_DA903X
226 depends on !CC_IS_CLANG # https://bugs.llvm.org/show_bug.cgi?id=38789
226 help227 help
227 Say y here to support the BUCKs and LDOs regulators found on228 Say y here to support the BUCKs and LDOs regulators found on
228 Dialog Semiconductor DA9030/DA9034 PMIC.229 Dialog Semiconductor DA9030/DA9034 PMIC.
@@ -839,6 +840,13 @@ config REGULATOR_STM32_VREFBUF · 610 unmodified lines
839 This driver can also be built as a module. If so, the module840 This driver can also be built as a module. If so, the module
840 will be called stm32-vrefbuf.841 will be called stm32-vrefbuf.
841 842
843config REGULATOR_STM32_PWR
844 bool "STMicroelectronics STM32 PWR"
845 depends on ARCH_STM32 || COMPILE_TEST
846 help
847 This driver supports internal regulators (1V1, 1V8, 3V3) in the
848 STMicroelectronics STM32 chips.
849
842config REGULATOR_STPMIC1850config REGULATOR_STPMIC1
843 tristate "STMicroelectronics STPMIC1 PMIC Regulators"851 tristate "STMicroelectronics STPMIC1 PMIC Regulators"
844 depends on MFD_STPMIC1852 depends on MFD_STPMIC1
@@ -1010,7 +1018,8 @@ config REGULATOR_TWL4030 · 165 unmodified lines
1010config REGULATOR_UNIPHIER1018config REGULATOR_UNIPHIER
1011 tristate "UniPhier regulator driver"1019 tristate "UniPhier regulator driver"
1012 depends on ARCH_UNIPHIER || COMPILE_TEST1020 depends on ARCH_UNIPHIER || COMPILE_TEST
1013 depends on OF && MFD_SYSCON1021 depends on OF
1022 select REGMAP_MMIO
1014 default ARCH_UNIPHIER1023 default ARCH_UNIPHIER
1015 help1024 help
1016 Support for regulators implemented on Socionext UniPhier SoCs.1025 Support for regulators implemented on Socionext UniPhier SoCs.
drivers/regulator/Makefile+1−0
@@ -105,6 +105,7 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o · 104 unmodified lines
105obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o105obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
106obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o106obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
107obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o107obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
108obj-$(CONFIG_REGULATOR_STM32_PWR) += stm32-pwr.o
108obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o109obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o
109obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o110obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
110obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o111obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o
drivers/regulator/ab3100.c+12−33
@@ -48,7 +48,6 @@ · 47 unmodified lines
48 * @regreg: regulator register number in the AB310048 * @regreg: regulator register number in the AB3100
49 */49 */
50struct ab3100_regulator {50struct ab3100_regulator {
51 struct regulator_dev *rdev;
52 struct device *dev;51 struct device *dev;
53 struct ab3100_platform_data *plfdata;52 struct ab3100_platform_data *plfdata;
54 u8 regreg;53 u8 regreg;
@@ -354,14 +353,13 @@ static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg) · 299 unmodified lines
354 return 0;353 return 0;
355}354}
356 355
357static struct regulator_ops regulator_ops_fixed = {356static const struct regulator_ops regulator_ops_fixed = {
358 .list_voltage = regulator_list_voltage_linear,
359 .enable = ab3100_enable_regulator,357 .enable = ab3100_enable_regulator,
360 .disable = ab3100_disable_regulator,358 .disable = ab3100_disable_regulator,
361 .is_enabled = ab3100_is_enabled_regulator,359 .is_enabled = ab3100_is_enabled_regulator,
362};360};
363 361
364static struct regulator_ops regulator_ops_variable = {362static const struct regulator_ops regulator_ops_variable = {
365 .enable = ab3100_enable_regulator,363 .enable = ab3100_enable_regulator,
366 .disable = ab3100_disable_regulator,364 .disable = ab3100_disable_regulator,
367 .is_enabled = ab3100_is_enabled_regulator,365 .is_enabled = ab3100_is_enabled_regulator,
@@ -370,7 +368,7 @@ static struct regulator_ops regulator_ops_variable = { · 2 unmodified lines
370 .list_voltage = regulator_list_voltage_table,368 .list_voltage = regulator_list_voltage_table,
371};369};
372 370
373static struct regulator_ops regulator_ops_variable_sleepable = {371static const struct regulator_ops regulator_ops_variable_sleepable = {
374 .enable = ab3100_enable_regulator,372 .enable = ab3100_enable_regulator,
375 .disable = ab3100_disable_regulator,373 .disable = ab3100_disable_regulator,
376 .is_enabled = ab3100_is_enabled_regulator,374 .is_enabled = ab3100_is_enabled_regulator,
@@ -386,14 +384,14 @@ static struct regulator_ops regulator_ops_variable_sleepable = { · 9 unmodified lines
386 * is an on/off switch plain an simple. The external384 * is an on/off switch plain an simple. The external
387 * voltage is defined in the board set-up if any.385 * voltage is defined in the board set-up if any.
388 */386 */
389static struct regulator_ops regulator_ops_external = {387static const struct regulator_ops regulator_ops_external = {
390 .enable = ab3100_enable_regulator,388 .enable = ab3100_enable_regulator,
391 .disable = ab3100_disable_regulator,389 .disable = ab3100_disable_regulator,
392 .is_enabled = ab3100_is_enabled_regulator,390 .is_enabled = ab3100_is_enabled_regulator,
393 .get_voltage = ab3100_get_voltage_regulator_external,391 .get_voltage = ab3100_get_voltage_regulator_external,
394};392};
395 393
396static struct regulator_desc394static const struct regulator_desc
397ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {395ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
398 {396 {
399 .name = "LDO_A",397 .name = "LDO_A",
@@ -402,7 +400,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { · 2 unmodified lines
402 .n_voltages = 1,400 .n_voltages = 1,
403 .type = REGULATOR_VOLTAGE,401 .type = REGULATOR_VOLTAGE,
404 .owner = THIS_MODULE,402 .owner = THIS_MODULE,
405 .min_uV = LDO_A_VOLTAGE,403 .fixed_uV = LDO_A_VOLTAGE,
406 .enable_time = 200,404 .enable_time = 200,
407 },405 },
408 {406 {
@@ -412,7 +410,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { · 3 unmodified lines
412 .n_voltages = 1,410 .n_voltages = 1,
413 .type = REGULATOR_VOLTAGE,411 .type = REGULATOR_VOLTAGE,
414 .owner = THIS_MODULE,412 .owner = THIS_MODULE,
415 .min_uV = LDO_C_VOLTAGE,413 .fixed_uV = LDO_C_VOLTAGE,
416 .enable_time = 200,414 .enable_time = 200,
417 },415 },
418 {416 {
@@ -422,7 +420,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { · 3 unmodified lines
422 .n_voltages = 1,420 .n_voltages = 1,
423 .type = REGULATOR_VOLTAGE,421 .type = REGULATOR_VOLTAGE,
424 .owner = THIS_MODULE,422 .owner = THIS_MODULE,
425 .min_uV = LDO_D_VOLTAGE,423 .fixed_uV = LDO_D_VOLTAGE,
426 .enable_time = 200,424 .enable_time = 200,
427 },425 },
428 {426 {
@@ -500,7 +498,7 @@ static int ab3100_regulator_register(struct platform_device *pdev, · 71 unmodified lines
500 struct device_node *np,498 struct device_node *np,
501 unsigned long id)499 unsigned long id)
502{500{
503 struct regulator_desc *desc;501 const struct regulator_desc *desc;
504 struct ab3100_regulator *reg;502 struct ab3100_regulator *reg;
505 struct regulator_dev *rdev;503 struct regulator_dev *rdev;
506 struct regulator_config config = { };504 struct regulator_config config = { };
@@ -545,8 +543,6 @@ static int ab3100_regulator_register(struct platform_device *pdev, · 38 unmodified lines
545 return err;543 return err;
546 }544 }
547 545
548 /* Then set a pointer back to the registered regulator */
549 reg->rdev = rdev;
550 return 0;546 return 0;
551}547}
552 548
@@ -609,18 +605,6 @@ static const u8 ab3100_reg_initvals[] = { · 56 unmodified lines
609 LDO_D_SETTING,605 LDO_D_SETTING,
610};606};
611 607
612static int ab3100_regulators_remove(struct platform_device *pdev)
613{
614 int i;
615
616 for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
617 struct ab3100_regulator *reg = &ab3100_regulators[i];
618
619 reg->rdev = NULL;
620 }
621 return 0;
622}
623
624static int608static int
625ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)609ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
626{610{
@@ -647,10 +631,8 @@ ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np) · 20 unmodified lines
647 pdev, NULL, ab3100_regulator_matches[i].init_data,631 pdev, NULL, ab3100_regulator_matches[i].init_data,
648 ab3100_regulator_matches[i].of_node,632 ab3100_regulator_matches[i].of_node,
649 (unsigned long)ab3100_regulator_matches[i].driver_data);633 (unsigned long)ab3100_regulator_matches[i].driver_data);
650 if (err) {634 if (err)
651 ab3100_regulators_remove(pdev);
652 return err;635 return err;
653 }
654 }636 }
655 637
656 return 0;638 return 0;
@@ -705,14 +687,12 @@ static int ab3100_regulators_probe(struct platform_device *pdev) · 48 unmodified lines
705 687
706 /* Register the regulators */688 /* Register the regulators */
707 for (i = 0; i < AB3100_NUM_REGULATORS; i++) {689 for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
708 struct regulator_desc *desc = &ab3100_regulator_desc[i];690 const struct regulator_desc *desc = &ab3100_regulator_desc[i];
709 691
710 err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,692 err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,
711 desc->id);693 desc->id);
712 if (err) {694 if (err)
713 ab3100_regulators_remove(pdev);
714 return err;695 return err;
715 }
716 }696 }
717 697
718 return 0;698 return 0;
@@ -723,7 +703,6 @@ static struct platform_driver ab3100_regulators_driver = { · 4 unmodified lines
723 .name = "ab3100-regulators",703 .name = "ab3100-regulators",
724 },704 },
725 .probe = ab3100_regulators_probe,705 .probe = ab3100_regulators_probe,
726 .remove = ab3100_regulators_remove,
727};706};
728 707
729static __init int ab3100_regulators_init(void)708static __init int ab3100_regulators_init(void)
drivers/regulator/ab8500-ext.c+14−35
@@ -479,7 +479,6 @@ static struct ab8500_regulator_platform_data ab8500_regulator_plat_data = { · 478 unmodified lines
479 * struct ab8500_ext_regulator_info - ab8500 regulator information479 * struct ab8500_ext_regulator_info - ab8500 regulator information
480 * @dev: device pointer480 * @dev: device pointer
481 * @desc: regulator description481 * @desc: regulator description
482 * @rdev: regulator device
483 * @cfg: regulator configuration (extension of regulator FW configuration)482 * @cfg: regulator configuration (extension of regulator FW configuration)
484 * @update_bank: bank to control on/off483 * @update_bank: bank to control on/off
485 * @update_reg: register to control on/off484 * @update_reg: register to control on/off
@@ -495,7 +494,6 @@ static struct ab8500_regulator_platform_data ab8500_regulator_plat_data = { · 9 unmodified lines
495struct ab8500_ext_regulator_info {494struct ab8500_ext_regulator_info {
496 struct device *dev;495 struct device *dev;
497 struct regulator_desc desc;496 struct regulator_desc desc;
498 struct regulator_dev *rdev;
499 struct ab8500_ext_regulator_cfg *cfg;497 struct ab8500_ext_regulator_cfg *cfg;
500 u8 update_bank;498 u8 update_bank;
501 u8 update_reg;499 u8 update_reg;
@@ -530,7 +528,7 @@ static int ab8500_ext_regulator_enable(struct regulator_dev *rdev) · 28 unmodified lines
530 info->update_bank, info->update_reg,528 info->update_bank, info->update_reg,
531 info->update_mask, regval);529 info->update_mask, regval);
532 if (ret < 0) {530 if (ret < 0) {
533 dev_err(rdev_get_dev(info->rdev),531 dev_err(rdev_get_dev(rdev),
534 "couldn't set enable bits for regulator\n");532 "couldn't set enable bits for regulator\n");
535 return ret;533 return ret;
536 }534 }
@@ -566,7 +564,7 @@ static int ab8500_ext_regulator_disable(struct regulator_dev *rdev) · 29 unmodified lines
566 info->update_bank, info->update_reg,564 info->update_bank, info->update_reg,
567 info->update_mask, regval);565 info->update_mask, regval);
568 if (ret < 0) {566 if (ret < 0) {
569 dev_err(rdev_get_dev(info->rdev),567 dev_err(rdev_get_dev(rdev),
570 "couldn't set disable bits for regulator\n");568 "couldn't set disable bits for regulator\n");
571 return ret;569 return ret;
572 }570 }
@@ -720,7 +718,7 @@ static int ab8500_ext_list_voltage(struct regulator_dev *rdev, · 147 unmodified lines
720 return -EINVAL;718 return -EINVAL;
721}719}
722 720
723static struct regulator_ops ab8500_ext_regulator_ops = {721static const struct regulator_ops ab8500_ext_regulator_ops = {
724 .enable = ab8500_ext_regulator_enable,722 .enable = ab8500_ext_regulator_enable,
725 .disable = ab8500_ext_regulator_disable,723 .disable = ab8500_ext_regulator_disable,
726 .is_enabled = ab8500_ext_regulator_is_enabled,724 .is_enabled = ab8500_ext_regulator_is_enabled,
@@ -735,6 +733,7 @@ static struct ab8500_ext_regulator_info · 8 unmodified lines
735 [AB8500_EXT_SUPPLY1] = {733 [AB8500_EXT_SUPPLY1] = {
736 .desc = {734 .desc = {
737 .name = "VEXTSUPPLY1",735 .name = "VEXTSUPPLY1",
736 .of_match = of_match_ptr("ab8500_ext1"),
738 .ops = &ab8500_ext_regulator_ops,737 .ops = &ab8500_ext_regulator_ops,
739 .type = REGULATOR_VOLTAGE,738 .type = REGULATOR_VOLTAGE,
740 .id = AB8500_EXT_SUPPLY1,739 .id = AB8500_EXT_SUPPLY1,
@@ -752,6 +751,7 @@ static struct ab8500_ext_regulator_info · 11 unmodified lines
752 [AB8500_EXT_SUPPLY2] = {751 [AB8500_EXT_SUPPLY2] = {
753 .desc = {752 .desc = {
754 .name = "VEXTSUPPLY2",753 .name = "VEXTSUPPLY2",
754 .of_match = of_match_ptr("ab8500_ext2"),
755 .ops = &ab8500_ext_regulator_ops,755 .ops = &ab8500_ext_regulator_ops,
756 .type = REGULATOR_VOLTAGE,756 .type = REGULATOR_VOLTAGE,
757 .id = AB8500_EXT_SUPPLY2,757 .id = AB8500_EXT_SUPPLY2,
@@ -769,6 +769,7 @@ static struct ab8500_ext_regulator_info · 11 unmodified lines
769 [AB8500_EXT_SUPPLY3] = {769 [AB8500_EXT_SUPPLY3] = {
770 .desc = {770 .desc = {
771 .name = "VEXTSUPPLY3",771 .name = "VEXTSUPPLY3",
772 .of_match = of_match_ptr("ab8500_ext3"),
772 .ops = &ab8500_ext_regulator_ops,773 .ops = &ab8500_ext_regulator_ops,
773 .type = REGULATOR_VOLTAGE,774 .type = REGULATOR_VOLTAGE,
774 .id = AB8500_EXT_SUPPLY3,775 .id = AB8500_EXT_SUPPLY3,
@@ -785,30 +786,13 @@ static struct ab8500_ext_regulator_info · 10 unmodified lines
785 },786 },
786};787};
787 788
788static struct of_regulator_match ab8500_ext_regulator_match[] = {
789 { .name = "ab8500_ext1", .driver_data = (void *) AB8500_EXT_SUPPLY1, },
790 { .name = "ab8500_ext2", .driver_data = (void *) AB8500_EXT_SUPPLY2, },
791 { .name = "ab8500_ext3", .driver_data = (void *) AB8500_EXT_SUPPLY3, },
792};
793
794static int ab8500_ext_regulator_probe(struct platform_device *pdev)789static int ab8500_ext_regulator_probe(struct platform_device *pdev)
795{790{
796 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);791 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
797 struct ab8500_regulator_platform_data *pdata = &ab8500_regulator_plat_data;792 struct ab8500_regulator_platform_data *pdata = &ab8500_regulator_plat_data;
798 struct device_node *np = pdev->dev.of_node;
799 struct regulator_config config = { };793 struct regulator_config config = { };
800 int i, err;794 struct regulator_dev *rdev;
801 795 int i;
802 if (np) {
803 err = of_regulator_match(&pdev->dev, np,
804 ab8500_ext_regulator_match,
805 ARRAY_SIZE(ab8500_ext_regulator_match));
806 if (err < 0) {
807 dev_err(&pdev->dev,
808 "Error parsing regulator init data: %d\n", err);
809 return err;
810 }
811 }
812 796
813 if (!ab8500) {797 if (!ab8500) {
814 dev_err(&pdev->dev, "null mfd parent\n");798 dev_err(&pdev->dev, "null mfd parent\n");
@@ -844,23 +828,18 @@ static int ab8500_ext_regulator_probe(struct platform_device *pdev) · 29 unmodified lines
844 828
845 config.dev = &pdev->dev;829 config.dev = &pdev->dev;
846 config.driver_data = info;830 config.driver_data = info;
847 config.of_node = ab8500_ext_regulator_match[i].of_node;831 config.init_data = &pdata->ext_regulator[i];
848 config.init_data = (np) ?
849 ab8500_ext_regulator_match[i].init_data :
850 &pdata->ext_regulator[i];
851 832
852 /* register regulator with framework */833 /* register regulator with framework */
853 info->rdev = devm_regulator_register(&pdev->dev, &info->desc,834 rdev = devm_regulator_register(&pdev->dev, &info->desc,
854 &config);835 &config);
855 if (IS_ERR(info->rdev)) {836 if (IS_ERR(rdev)) {
856 err = PTR_ERR(info->rdev);
857 dev_err(&pdev->dev, "failed to register regulator %s\n",837 dev_err(&pdev->dev, "failed to register regulator %s\n",
858 info->desc.name);838 info->desc.name);
859 return err;839 return PTR_ERR(rdev);
860 }840 }
861 841
862 dev_dbg(rdev_get_dev(info->rdev),842 dev_dbg(&pdev->dev, "%s-probed\n", info->desc.name);
863 "%s-probed\n", info->desc.name);
864 }843 }
865 844
866 return 0;845 return 0;
drivers/regulator/ab8500.c+9−11
@@ -44,7 +44,6 @@ struct ab8500_shared_mode { · 43 unmodified lines
44 * struct ab8500_regulator_info - ab8500 regulator information44 * struct ab8500_regulator_info - ab8500 regulator information
45 * @dev: device pointer45 * @dev: device pointer
46 * @desc: regulator description46 * @desc: regulator description
47 * @regulator_dev: regulator device
48 * @shared_mode: used when mode is shared between two regulators47 * @shared_mode: used when mode is shared between two regulators
49 * @load_lp_uA: maximum load in idle (low power) mode48 * @load_lp_uA: maximum load in idle (low power) mode
50 * @update_bank: bank to control on/off49 * @update_bank: bank to control on/off
@@ -65,7 +64,6 @@ struct ab8500_shared_mode { · 14 unmodified lines
65struct ab8500_regulator_info {64struct ab8500_regulator_info {
66 struct device *dev;65 struct device *dev;
67 struct regulator_desc desc;66 struct regulator_desc desc;
68 struct regulator_dev *regulator;
69 struct ab8500_shared_mode *shared_mode;67 struct ab8500_shared_mode *shared_mode;
70 int load_lp_uA;68 int load_lp_uA;
71 u8 update_bank;69 u8 update_bank;
@@ -510,7 +508,7 @@ static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev, · 438 unmodified lines
510 return ret;508 return ret;
511}509}
512 510
513static struct regulator_ops ab8500_regulator_volt_mode_ops = {511static const struct regulator_ops ab8500_regulator_volt_mode_ops = {
514 .enable = ab8500_regulator_enable,512 .enable = ab8500_regulator_enable,
515 .disable = ab8500_regulator_disable,513 .disable = ab8500_regulator_disable,
516 .is_enabled = ab8500_regulator_is_enabled,514 .is_enabled = ab8500_regulator_is_enabled,
@@ -522,7 +520,7 @@ static struct regulator_ops ab8500_regulator_volt_mode_ops = { · 5 unmodified lines
522 .list_voltage = regulator_list_voltage_table,520 .list_voltage = regulator_list_voltage_table,
523};521};
524 522
525static struct regulator_ops ab8500_regulator_volt_ops = {523static const struct regulator_ops ab8500_regulator_volt_ops = {
526 .enable = ab8500_regulator_enable,524 .enable = ab8500_regulator_enable,
527 .disable = ab8500_regulator_disable,525 .disable = ab8500_regulator_disable,
528 .is_enabled = ab8500_regulator_is_enabled,526 .is_enabled = ab8500_regulator_is_enabled,
@@ -531,7 +529,7 @@ static struct regulator_ops ab8500_regulator_volt_ops = { · 2 unmodified lines
531 .list_voltage = regulator_list_voltage_table,529 .list_voltage = regulator_list_voltage_table,
532};530};
533 531
534static struct regulator_ops ab8500_regulator_mode_ops = {532static const struct regulator_ops ab8500_regulator_mode_ops = {
535 .enable = ab8500_regulator_enable,533 .enable = ab8500_regulator_enable,
536 .disable = ab8500_regulator_disable,534 .disable = ab8500_regulator_disable,
537 .is_enabled = ab8500_regulator_is_enabled,535 .is_enabled = ab8500_regulator_is_enabled,
@@ -541,14 +539,14 @@ static struct regulator_ops ab8500_regulator_mode_ops = { · 3 unmodified lines
541 .list_voltage = regulator_list_voltage_table,539 .list_voltage = regulator_list_voltage_table,
542};540};
543 541
544static struct regulator_ops ab8500_regulator_ops = {542static const struct regulator_ops ab8500_regulator_ops = {
545 .enable = ab8500_regulator_enable,543 .enable = ab8500_regulator_enable,
546 .disable = ab8500_regulator_disable,544 .disable = ab8500_regulator_disable,
547 .is_enabled = ab8500_regulator_is_enabled,545 .is_enabled = ab8500_regulator_is_enabled,
548 .list_voltage = regulator_list_voltage_table,546 .list_voltage = regulator_list_voltage_table,
549};547};
550 548
551static struct regulator_ops ab8500_regulator_anamic_mode_ops = {549static const struct regulator_ops ab8500_regulator_anamic_mode_ops = {
552 .enable = ab8500_regulator_enable,550 .enable = ab8500_regulator_enable,
553 .disable = ab8500_regulator_disable,551 .disable = ab8500_regulator_disable,
554 .is_enabled = ab8500_regulator_is_enabled,552 .is_enabled = ab8500_regulator_is_enabled,
@@ -1600,6 +1598,7 @@ static int ab8500_regulator_register(struct platform_device *pdev, · 1045 unmodified lines
1600 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);1598 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
1601 struct ab8500_regulator_info *info = NULL;1599 struct ab8500_regulator_info *info = NULL;
1602 struct regulator_config config = { };1600 struct regulator_config config = { };
1601 struct regulator_dev *rdev;
1603 1602
1604 /* assign per-regulator data */1603 /* assign per-regulator data */
1605 info = &abx500_regulator.info[id];1604 info = &abx500_regulator.info[id];
@@ -1621,12 +1620,11 @@ static int ab8500_regulator_register(struct platform_device *pdev, · 15 unmodified lines
1621 }1620 }
1622 1621
1623 /* register regulator with framework */1622 /* register regulator with framework */
1624 info->regulator = devm_regulator_register(&pdev->dev, &info->desc,1623 rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
1625 &config);1624 if (IS_ERR(rdev)) {
1626 if (IS_ERR(info->regulator)) {
1627 dev_err(&pdev->dev, "failed to register regulator %s\n",1625 dev_err(&pdev->dev, "failed to register regulator %s\n",
1628 info->desc.name);1626 info->desc.name);
1629 return PTR_ERR(info->regulator);1627 return PTR_ERR(rdev);
1630 }1628 }
1631 1629
1632 return 0;1630 return 0;
drivers/regulator/act8865-regulator.c+21−126
@@ -226,7 +226,7 @@ static const struct regulator_linear_range act8600_sudcdc_voltage_ranges[] = { · 225 unmodified lines
226 REGULATOR_LINEAR_RANGE(41400000, 248, 255, 0),226 REGULATOR_LINEAR_RANGE(41400000, 248, 255, 0),
227};227};
228 228
229static struct regulator_ops act8865_ops = {229static const struct regulator_ops act8865_ops = {
230 .list_voltage = regulator_list_voltage_linear_range,230 .list_voltage = regulator_list_voltage_linear_range,
231 .map_voltage = regulator_map_voltage_linear_range,231 .map_voltage = regulator_map_voltage_linear_range,
232 .get_voltage_sel = regulator_get_voltage_sel_regmap,232 .get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -236,7 +236,7 @@ static struct regulator_ops act8865_ops = { · 3 unmodified lines
236 .is_enabled = regulator_is_enabled_regmap,236 .is_enabled = regulator_is_enabled_regmap,
237};237};
238 238
239static struct regulator_ops act8865_ldo_ops = {239static const struct regulator_ops act8865_ldo_ops = {
240 .enable = regulator_enable_regmap,240 .enable = regulator_enable_regmap,
241 .disable = regulator_disable_regmap,241 .disable = regulator_disable_regmap,
242 .is_enabled = regulator_is_enabled_regmap,242 .is_enabled = regulator_is_enabled_regmap,
@@ -245,6 +245,8 @@ static struct regulator_ops act8865_ldo_ops = { · 2 unmodified lines
245#define ACT88xx_REG(_name, _family, _id, _vsel_reg, _supply) \245#define ACT88xx_REG(_name, _family, _id, _vsel_reg, _supply) \
246 [_family##_ID_##_id] = { \246 [_family##_ID_##_id] = { \
247 .name = _name, \247 .name = _name, \
248 .of_match = of_match_ptr(_name), \
249 .regulators_node = of_match_ptr("regulators"), \
248 .supply_name = _supply, \250 .supply_name = _supply, \
249 .id = _family##_ID_##_id, \251 .id = _family##_ID_##_id, \
250 .type = REGULATOR_VOLTAGE, \252 .type = REGULATOR_VOLTAGE, \
@@ -265,6 +267,8 @@ static const struct regulator_desc act8600_regulators[] = { · 14 unmodified lines
265 ACT88xx_REG("DCDC3", ACT8600, DCDC3, VSET, "vp3"),267 ACT88xx_REG("DCDC3", ACT8600, DCDC3, VSET, "vp3"),
266 {268 {
267 .name = "SUDCDC_REG4",269 .name = "SUDCDC_REG4",
270 .of_match = of_match_ptr("SUDCDC_REG4"),
271 .regulators_node = of_match_ptr("regulators"),
268 .id = ACT8600_ID_SUDCDC4,272 .id = ACT8600_ID_SUDCDC4,
269 .ops = &act8865_ops,273 .ops = &act8865_ops,
270 .type = REGULATOR_VOLTAGE,274 .type = REGULATOR_VOLTAGE,
@@ -283,6 +287,8 @@ static const struct regulator_desc act8600_regulators[] = { · 12 unmodified lines
283 ACT88xx_REG("LDO8", ACT8600, LDO8, VSET, "inl"),287 ACT88xx_REG("LDO8", ACT8600, LDO8, VSET, "inl"),
284 {288 {
285 .name = "LDO_REG9",289 .name = "LDO_REG9",
290 .of_match = of_match_ptr("LDO_REG9"),
291 .regulators_node = of_match_ptr("regulators"),
286 .id = ACT8600_ID_LDO9,292 .id = ACT8600_ID_LDO9,
287 .ops = &act8865_ldo_ops,293 .ops = &act8865_ldo_ops,
288 .type = REGULATOR_VOLTAGE,294 .type = REGULATOR_VOLTAGE,
@@ -294,6 +300,8 @@ static const struct regulator_desc act8600_regulators[] = { · 5 unmodified lines
294 },300 },
295 {301 {
296 .name = "LDO_REG10",302 .name = "LDO_REG10",
303 .of_match = of_match_ptr("LDO_REG10"),
304 .regulators_node = of_match_ptr("regulators"),
297 .id = ACT8600_ID_LDO10,305 .id = ACT8600_ID_LDO10,
298 .ops = &act8865_ldo_ops,306 .ops = &act8865_ldo_ops,
299 .type = REGULATOR_VOLTAGE,307 .type = REGULATOR_VOLTAGE,
@@ -348,110 +356,6 @@ static const struct of_device_id act8865_dt_ids[] = { · 48 unmodified lines
348 { }356 { }
349};357};
350MODULE_DEVICE_TABLE(of, act8865_dt_ids);358MODULE_DEVICE_TABLE(of, act8865_dt_ids);
351
352static struct of_regulator_match act8846_matches[] = {
353 [ACT8846_ID_REG1] = { .name = "REG1" },
354 [ACT8846_ID_REG2] = { .name = "REG2" },
355 [ACT8846_ID_REG3] = { .name = "REG3" },
356 [ACT8846_ID_REG4] = { .name = "REG4" },
357 [ACT8846_ID_REG5] = { .name = "REG5" },
358 [ACT8846_ID_REG6] = { .name = "REG6" },
359 [ACT8846_ID_REG7] = { .name = "REG7" },
360 [ACT8846_ID_REG8] = { .name = "REG8" },
361 [ACT8846_ID_REG9] = { .name = "REG9" },
362 [ACT8846_ID_REG10] = { .name = "REG10" },
363 [ACT8846_ID_REG11] = { .name = "REG11" },
364 [ACT8846_ID_REG12] = { .name = "REG12" },
365};
366
367static struct of_regulator_match act8865_matches[] = {
368 [ACT8865_ID_DCDC1] = { .name = "DCDC_REG1"},
369 [ACT8865_ID_DCDC2] = { .name = "DCDC_REG2"},
370 [ACT8865_ID_DCDC3] = { .name = "DCDC_REG3"},
371 [ACT8865_ID_LDO1] = { .name = "LDO_REG1"},
372 [ACT8865_ID_LDO2] = { .name = "LDO_REG2"},
373 [ACT8865_ID_LDO3] = { .name = "LDO_REG3"},
374 [ACT8865_ID_LDO4] = { .name = "LDO_REG4"},
375};
376
377static struct of_regulator_match act8600_matches[] = {
378 [ACT8600_ID_DCDC1] = { .name = "DCDC_REG1"},
379 [ACT8600_ID_DCDC2] = { .name = "DCDC_REG2"},
380 [ACT8600_ID_DCDC3] = { .name = "DCDC_REG3"},
381 [ACT8600_ID_SUDCDC4] = { .name = "SUDCDC_REG4"},
382 [ACT8600_ID_LDO5] = { .name = "LDO_REG5"},
383 [ACT8600_ID_LDO6] = { .name = "LDO_REG6"},
384 [ACT8600_ID_LDO7] = { .name = "LDO_REG7"},
385 [ACT8600_ID_LDO8] = { .name = "LDO_REG8"},
386 [ACT8600_ID_LDO9] = { .name = "LDO_REG9"},
387 [ACT8600_ID_LDO10] = { .name = "LDO_REG10"},
388};
389
390static int act8865_pdata_from_dt(struct device *dev,
391 struct act8865_platform_data *pdata,
392 unsigned long type)
393{
394 int matched, i, num_matches;
395 struct device_node *np;
396 struct act8865_regulator_data *regulator;
397 struct of_regulator_match *matches;
398
399 switch (type) {
400 case ACT8600:
401 matches = act8600_matches;
402 num_matches = ARRAY_SIZE(act8600_matches);
403 break;
404 case ACT8846:
405 matches = act8846_matches;
406 num_matches = ARRAY_SIZE(act8846_matches);
407 break;
408 case ACT8865:
409 matches = act8865_matches;
410 num_matches = ARRAY_SIZE(act8865_matches);
411 break;
412 default:
413 dev_err(dev, "invalid device id %lu\n", type);
414 return -EINVAL;
415 }
416
417 np = of_get_child_by_name(dev->of_node, "regulators");
418 if (!np) {
419 dev_err(dev, "missing 'regulators' subnode in DT\n");
420 return -EINVAL;
421 }
422
423 matched = of_regulator_match(dev, np, matches, num_matches);
424 of_node_put(np);
425 if (matched <= 0)
426 return matched;
427
428 pdata->regulators = devm_kcalloc(dev,
429 num_matches,
430 sizeof(struct act8865_regulator_data),
431 GFP_KERNEL);
432 if (!pdata->regulators)
433 return -ENOMEM;
434
435 pdata->num_regulators = num_matches;
436 regulator = pdata->regulators;
437
438 for (i = 0; i < num_matches; i++) {
439 regulator->id = i;
440 regulator->name = matches[i].name;
441 regulator->init_data = matches[i].init_data;
442 regulator->of_node = matches[i].of_node;
443 regulator++;
444 }
445
446 return 0;
447}
448#else
449static inline int act8865_pdata_from_dt(struct device *dev,
450 struct act8865_platform_data *pdata,
451 unsigned long type)
452{
453 return 0;
454}
455#endif359#endif
456 360
457static struct act8865_regulator_data *act8865_get_regulator_data(361static struct act8865_regulator_data *act8865_get_regulator_data(
@@ -459,9 +363,6 @@ static struct act8865_regulator_data *act8865_get_regulator_data( · 1 unmodified line
459{363{
460 int i;364 int i;
461 365
462 if (!pdata)
463 return NULL;
464
465 for (i = 0; i < pdata->num_regulators; i++) {366 for (i = 0; i < pdata->num_regulators; i++) {
466 if (pdata->regulators[i].id == id)367 if (pdata->regulators[i].id == id)
467 return &pdata->regulators[i];368 return &pdata->regulators[i];
@@ -484,7 +385,7 @@ static int act8865_pmic_probe(struct i2c_client *client, · 16 unmodified lines
484 const struct i2c_device_id *i2c_id)385 const struct i2c_device_id *i2c_id)
485{386{
486 const struct regulator_desc *regulators;387 const struct regulator_desc *regulators;
487 struct act8865_platform_data pdata_of, *pdata;388 struct act8865_platform_data *pdata = NULL;
488 struct device *dev = &client->dev;389 struct device *dev = &client->dev;
489 int i, ret, num_regulators;390 int i, ret, num_regulators;
490 struct act8865 *act8865;391 struct act8865 *act8865;
@@ -493,9 +394,7 @@ static int act8865_pmic_probe(struct i2c_client *client, · 2 unmodified lines
493 int off_reg, off_mask;394 int off_reg, off_mask;
494 int voltage_select = 0;395 int voltage_select = 0;
495 396
496 pdata = dev_get_platdata(dev);397 if (dev->of_node) {
497
498 if (dev->of_node && !pdata) {
499 const struct of_device_id *id;398 const struct of_device_id *id;
500 399
501 id = of_match_device(of_match_ptr(act8865_dt_ids), dev);400 id = of_match_device(of_match_ptr(act8865_dt_ids), dev);
@@ -509,6 +408,7 @@ static int act8865_pmic_probe(struct i2c_client *client, · 7 unmodified lines
509 NULL);408 NULL);
510 } else {409 } else {
511 type = i2c_id->driver_data;410 type = i2c_id->driver_data;
411 pdata = dev_get_platdata(dev);
512 }412 }
513 413
514 switch (type) {414 switch (type) {
@@ -543,14 +443,6 @@ static int act8865_pmic_probe(struct i2c_client *client, · 28 unmodified lines
543 return -EINVAL;443 return -EINVAL;
544 }444 }
545 445
546 if (dev->of_node && !pdata) {
547 ret = act8865_pdata_from_dt(dev, &pdata_of, type);
548 if (ret < 0)
549 return ret;
550
551 pdata = &pdata_of;
552 }
553
554 act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL);446 act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL);
555 if (!act8865)447 if (!act8865)
556 return -ENOMEM;448 return -ENOMEM;
@@ -577,17 +469,20 @@ static int act8865_pmic_probe(struct i2c_client *client, · 20 unmodified lines
577 for (i = 0; i < num_regulators; i++) {469 for (i = 0; i < num_regulators; i++) {
578 const struct regulator_desc *desc = &regulators[i];470 const struct regulator_desc *desc = &regulators[i];
579 struct regulator_config config = { };471 struct regulator_config config = { };
580 struct act8865_regulator_data *rdata;
581 struct regulator_dev *rdev;472 struct regulator_dev *rdev;
582 473
583 config.dev = dev;474 config.dev = dev;
584 config.driver_data = act8865;475 config.driver_data = act8865;
585 config.regmap = act8865->regmap;476 config.regmap = act8865->regmap;
586 477
587 rdata = act8865_get_regulator_data(desc->id, pdata);478 if (pdata) {
588 if (rdata) {479 struct act8865_regulator_data *rdata;
589 config.init_data = rdata->init_data;480
590 config.of_node = rdata->of_node;481 rdata = act8865_get_regulator_data(desc->id, pdata);
482 if (rdata) {
483 config.init_data = rdata->init_data;
484 config.of_node = rdata->of_node;
485 }
591 }486 }
592 487
593 rdev = devm_regulator_register(dev, desc, &config);488 rdev = devm_regulator_register(dev, desc, &config);
drivers/regulator/anatop-regulator.c+27−36
@@ -23,18 +23,10 @@ · 22 unmodified lines
23#define LDO_FET_FULL_ON 0x1f23#define LDO_FET_FULL_ON 0x1f
24 24
25struct anatop_regulator {25struct anatop_regulator {
26 u32 control_reg;
27 struct regmap *anatop;
28 int vol_bit_shift;
29 int vol_bit_width;
30 u32 delay_reg;26 u32 delay_reg;
31 int delay_bit_shift;27 int delay_bit_shift;
32 int delay_bit_width;28 int delay_bit_width;
33 int min_bit_val;
34 int min_voltage;
35 int max_voltage;
36 struct regulator_desc rdesc;29 struct regulator_desc rdesc;
37 struct regulator_init_data *initdata;
38 bool bypass;30 bool bypass;
39 int sel;31 int sel;
40};32};
@@ -55,7 +47,7 @@ static int anatop_regmap_set_voltage_time_sel(struct regulator_dev *reg, · 14 unmodified lines
55 * to calculate how many steps LDO need to47 * to calculate how many steps LDO need to
56 * ramp up, and how much delay needed. (us)48 * ramp up, and how much delay needed. (us)
57 */49 */
58 regmap_read(anatop_reg->anatop, anatop_reg->delay_reg, &val);50 regmap_read(reg->regmap, anatop_reg->delay_reg, &val);
59 val = (val >> anatop_reg->delay_bit_shift) &51 val = (val >> anatop_reg->delay_bit_shift) &
60 ((1 << anatop_reg->delay_bit_width) - 1);52 ((1 << anatop_reg->delay_bit_width) - 1);
61 ret = (new_sel - old_sel) * (LDO_RAMP_UP_UNIT_IN_CYCLES <<53 ret = (new_sel - old_sel) * (LDO_RAMP_UP_UNIT_IN_CYCLES <<
@@ -170,6 +162,13 @@ static int anatop_regulator_probe(struct platform_device *pdev) · 108 unmodified lines
170 struct anatop_regulator *sreg;162 struct anatop_regulator *sreg;
171 struct regulator_init_data *initdata;163 struct regulator_init_data *initdata;
172 struct regulator_config config = { };164 struct regulator_config config = { };
165 struct regmap *regmap;
166 u32 control_reg;
167 u32 vol_bit_shift;
168 u32 vol_bit_width;
169 u32 min_bit_val;
170 u32 min_voltage;
171 u32 max_voltage;
173 int ret = 0;172 int ret = 0;
174 u32 val;173 u32 val;
175 174
@@ -192,48 +191,41 @@ static int anatop_regulator_probe(struct platform_device *pdev) · 16 unmodified lines
192 return -ENOMEM;191 return -ENOMEM;
193 192
194 initdata->supply_regulator = "vin";193 initdata->supply_regulator = "vin";
195 sreg->initdata = initdata;
196 194
197 anatop_np = of_get_parent(np);195 anatop_np = of_get_parent(np);
198 if (!anatop_np)196 if (!anatop_np)
199 return -ENODEV;197 return -ENODEV;
200 sreg->anatop = syscon_node_to_regmap(anatop_np);198 regmap = syscon_node_to_regmap(anatop_np);
201 of_node_put(anatop_np);199 of_node_put(anatop_np);
202 if (IS_ERR(sreg->anatop))200 if (IS_ERR(regmap))
203 return PTR_ERR(sreg->anatop);201 return PTR_ERR(regmap);
204 202
205 ret = of_property_read_u32(np, "anatop-reg-offset",203 ret = of_property_read_u32(np, "anatop-reg-offset", &control_reg);
206 &sreg->control_reg);
207 if (ret) {204 if (ret) {
208 dev_err(dev, "no anatop-reg-offset property set\n");205 dev_err(dev, "no anatop-reg-offset property set\n");
209 return ret;206 return ret;
210 }207 }
211 ret = of_property_read_u32(np, "anatop-vol-bit-width",208 ret = of_property_read_u32(np, "anatop-vol-bit-width", &vol_bit_width);
212 &sreg->vol_bit_width);
213 if (ret) {209 if (ret) {
214 dev_err(dev, "no anatop-vol-bit-width property set\n");210 dev_err(dev, "no anatop-vol-bit-width property set\n");
215 return ret;211 return ret;
216 }212 }
217 ret = of_property_read_u32(np, "anatop-vol-bit-shift",213 ret = of_property_read_u32(np, "anatop-vol-bit-shift", &vol_bit_shift);
218 &sreg->vol_bit_shift);
219 if (ret) {214 if (ret) {
220 dev_err(dev, "no anatop-vol-bit-shift property set\n");215 dev_err(dev, "no anatop-vol-bit-shift property set\n");
221 return ret;216 return ret;
222 }217 }
223 ret = of_property_read_u32(np, "anatop-min-bit-val",218 ret = of_property_read_u32(np, "anatop-min-bit-val", &min_bit_val);
224 &sreg->min_bit_val);
225 if (ret) {219 if (ret) {
226 dev_err(dev, "no anatop-min-bit-val property set\n");220 dev_err(dev, "no anatop-min-bit-val property set\n");
227 return ret;221 return ret;
228 }222 }
229 ret = of_property_read_u32(np, "anatop-min-voltage",223 ret = of_property_read_u32(np, "anatop-min-voltage", &min_voltage);
230 &sreg->min_voltage);
231 if (ret) {224 if (ret) {
232 dev_err(dev, "no anatop-min-voltage property set\n");225 dev_err(dev, "no anatop-min-voltage property set\n");
233 return ret;226 return ret;
234 }227 }
235 ret = of_property_read_u32(np, "anatop-max-voltage",228 ret = of_property_read_u32(np, "anatop-max-voltage", &max_voltage);
236 &sreg->max_voltage);
237 if (ret) {229 if (ret) {
238 dev_err(dev, "no anatop-max-voltage property set\n");230 dev_err(dev, "no anatop-max-voltage property set\n");
239 return ret;231 return ret;
@@ -247,24 +239,23 @@ static int anatop_regulator_probe(struct platform_device *pdev) · 7 unmodified lines
247 of_property_read_u32(np, "anatop-delay-bit-shift",239 of_property_read_u32(np, "anatop-delay-bit-shift",
248 &sreg->delay_bit_shift);240 &sreg->delay_bit_shift);
249 241
250 rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage) / 25000 + 1242 rdesc->n_voltages = (max_voltage - min_voltage) / 25000 + 1
251 + sreg->min_bit_val;243 + min_bit_val;
252 rdesc->min_uV = sreg->min_voltage;244 rdesc->min_uV = min_voltage;
253 rdesc->uV_step = 25000;245 rdesc->uV_step = 25000;
254 rdesc->linear_min_sel = sreg->min_bit_val;246 rdesc->linear_min_sel = min_bit_val;
255 rdesc->vsel_reg = sreg->control_reg;247 rdesc->vsel_reg = control_reg;
256 rdesc->vsel_mask = ((1 << sreg->vol_bit_width) - 1) <<248 rdesc->vsel_mask = ((1 << vol_bit_width) - 1) << vol_bit_shift;
257 sreg->vol_bit_shift;
258 rdesc->min_dropout_uV = 125000;249 rdesc->min_dropout_uV = 125000;
259 250
260 config.dev = &pdev->dev;251 config.dev = &pdev->dev;
261 config.init_data = initdata;252 config.init_data = initdata;
262 config.driver_data = sreg;253 config.driver_data = sreg;
263 config.of_node = pdev->dev.of_node;254 config.of_node = pdev->dev.of_node;
264 config.regmap = sreg->anatop;255 config.regmap = regmap;
265 256
266 /* Only core regulators have the ramp up delay configuration. */257 /* Only core regulators have the ramp up delay configuration. */
267 if (sreg->control_reg && sreg->delay_bit_width) {258 if (control_reg && sreg->delay_bit_width) {
268 rdesc->ops = &anatop_core_rops;259 rdesc->ops = &anatop_core_rops;
269 260
270 ret = regmap_read(config.regmap, rdesc->vsel_reg, &val);261 ret = regmap_read(config.regmap, rdesc->vsel_reg, &val);
@@ -273,7 +264,7 @@ static int anatop_regulator_probe(struct platform_device *pdev) · 2 unmodified lines
273 return ret;264 return ret;
274 }265 }
275 266
276 sreg->sel = (val & rdesc->vsel_mask) >> sreg->vol_bit_shift;267 sreg->sel = (val & rdesc->vsel_mask) >> vol_bit_shift;
277 if (sreg->sel == LDO_FET_FULL_ON) {268 if (sreg->sel == LDO_FET_FULL_ON) {
278 sreg->sel = 0;269 sreg->sel = 0;
279 sreg->bypass = true;270 sreg->bypass = true;
@@ -306,7 +297,7 @@ static int anatop_regulator_probe(struct platform_device *pdev) · 26 unmodified lines
306 anatop_rops.disable = regulator_disable_regmap;297 anatop_rops.disable = regulator_disable_regmap;
307 anatop_rops.is_enabled = regulator_is_enabled_regmap;298 anatop_rops.is_enabled = regulator_is_enabled_regmap;
308 299
309 rdesc->enable_reg = sreg->control_reg;300 rdesc->enable_reg = control_reg;
310 rdesc->enable_mask = BIT(enable_bit);301 rdesc->enable_mask = BIT(enable_bit);
311 }302 }
312 }303 }
drivers/regulator/arizona-ldo1.c+7−12
@@ -1,15 +1,10 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * arizona-ldo1.c -- LDO1 supply for Arizona devices2//
3 *3// arizona-ldo1.c -- LDO1 supply for Arizona devices
4 * Copyright 2012 Wolfson Microelectronics PLC.4//
5 *5// Copyright 2012 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>6//
7 *7// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13 8
14#include <linux/module.h>9#include <linux/module.h>
15#include <linux/moduleparam.h>10#include <linux/moduleparam.h>
drivers/regulator/arizona-micsupp.c+7−12
@@ -1,15 +1,10 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * arizona-micsupp.c -- Microphone supply for Arizona devices2//
3 *3// arizona-micsupp.c -- Microphone supply for Arizona devices
4 * Copyright 2012 Wolfson Microelectronics PLC.4//
5 *5// Copyright 2012 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>6//
7 *7// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13 8
14#include <linux/module.h>9#include <linux/module.h>
15#include <linux/moduleparam.h>10#include <linux/moduleparam.h>
drivers/regulator/as3711-regulator.c+7−30
@@ -17,14 +17,6 @@ · 16 unmodified lines
17#include <linux/regulator/of_regulator.h>17#include <linux/regulator/of_regulator.h>
18#include <linux/slab.h>18#include <linux/slab.h>
19 19
20struct as3711_regulator_info {
21 struct regulator_desc desc;
22};
23
24struct as3711_regulator {
25 struct as3711_regulator_info *reg_info;
26};
27
28/*20/*
29 * The regulator API supports 4 modes of operataion: FAST, NORMAL, IDLE and21 * The regulator API supports 4 modes of operataion: FAST, NORMAL, IDLE and
30 * STANDBY. We map them in the following way to AS3711 SD1-4 DCDC modes:22 * STANDBY. We map them in the following way to AS3711 SD1-4 DCDC modes:
@@ -129,7 +121,6 @@ static const struct regulator_linear_range as3711_dldo_ranges[] = { · 98 unmodified lines
129 121
130#define AS3711_REG(_id, _en_reg, _en_bit, _vmask, _sfx) \122#define AS3711_REG(_id, _en_reg, _en_bit, _vmask, _sfx) \
131 [AS3711_REGULATOR_ ## _id] = { \123 [AS3711_REGULATOR_ ## _id] = { \
132 .desc = { \
133 .name = "as3711-regulator-" # _id, \124 .name = "as3711-regulator-" # _id, \
134 .id = AS3711_REGULATOR_ ## _id, \125 .id = AS3711_REGULATOR_ ## _id, \
135 .n_voltages = (_vmask + 1), \126 .n_voltages = (_vmask + 1), \
@@ -142,10 +133,9 @@ static const struct regulator_linear_range as3711_dldo_ranges[] = { · 6 unmodified lines
142 .enable_mask = BIT(_en_bit), \133 .enable_mask = BIT(_en_bit), \
143 .linear_ranges = as3711_ ## _sfx ## _ranges, \134 .linear_ranges = as3711_ ## _sfx ## _ranges, \
144 .n_linear_ranges = ARRAY_SIZE(as3711_ ## _sfx ## _ranges), \135 .n_linear_ranges = ARRAY_SIZE(as3711_ ## _sfx ## _ranges), \
145 }, \
146}136}
147 137
148static struct as3711_regulator_info as3711_reg_info[] = {138static const struct regulator_desc as3711_reg_desc[] = {
149 AS3711_REG(SD_1, SD_CONTROL, 0, 0x7f, sd),139 AS3711_REG(SD_1, SD_CONTROL, 0, 0x7f, sd),
150 AS3711_REG(SD_2, SD_CONTROL, 1, 0x7f, sd),140 AS3711_REG(SD_2, SD_CONTROL, 1, 0x7f, sd),
151 AS3711_REG(SD_3, SD_CONTROL, 2, 0x7f, sd),141 AS3711_REG(SD_3, SD_CONTROL, 2, 0x7f, sd),
@@ -161,7 +151,7 @@ static struct as3711_regulator_info as3711_reg_info[] = { · 9 unmodified lines
161 /* StepUp output voltage depends on supplying regulator */151 /* StepUp output voltage depends on supplying regulator */
162};152};
163 153
164#define AS3711_REGULATOR_NUM ARRAY_SIZE(as3711_reg_info)154#define AS3711_REGULATOR_NUM ARRAY_SIZE(as3711_reg_desc)
165 155
166static struct of_regulator_match156static struct of_regulator_match
167as3711_regulator_matches[AS3711_REGULATOR_NUM] = {157as3711_regulator_matches[AS3711_REGULATOR_NUM] = {
@@ -215,11 +205,8 @@ static int as3711_regulator_probe(struct platform_device *pdev) · 47 unmodified lines
215 struct as3711_regulator_pdata *pdata = dev_get_platdata(&pdev->dev);205 struct as3711_regulator_pdata *pdata = dev_get_platdata(&pdev->dev);
216 struct as3711 *as3711 = dev_get_drvdata(pdev->dev.parent);206 struct as3711 *as3711 = dev_get_drvdata(pdev->dev.parent);
217 struct regulator_config config = {.dev = &pdev->dev,};207 struct regulator_config config = {.dev = &pdev->dev,};
218 struct as3711_regulator *reg = NULL;
219 struct as3711_regulator *regs;
220 struct device_node *of_node[AS3711_REGULATOR_NUM] = {};208 struct device_node *of_node[AS3711_REGULATOR_NUM] = {};
221 struct regulator_dev *rdev;209 struct regulator_dev *rdev;
222 struct as3711_regulator_info *ri;
223 int ret;210 int ret;
224 int id;211 int id;
225 212
@@ -236,30 +223,20 @@ static int as3711_regulator_probe(struct platform_device *pdev) · 10 unmodified lines
236 }223 }
237 }224 }
238 225
239 regs = devm_kcalloc(&pdev->dev,226 for (id = 0; id < AS3711_REGULATOR_NUM; id++) {
240 AS3711_REGULATOR_NUM,
241 sizeof(struct as3711_regulator),
242 GFP_KERNEL);
243 if (!regs)
244 return -ENOMEM;
245
246 for (id = 0, ri = as3711_reg_info; id < AS3711_REGULATOR_NUM; ++id, ri++) {
247 reg = &regs[id];
248 reg->reg_info = ri;
249
250 config.init_data = pdata->init_data[id];227 config.init_data = pdata->init_data[id];
251 config.driver_data = reg;
252 config.regmap = as3711->regmap;228 config.regmap = as3711->regmap;
253 config.of_node = of_node[id];229 config.of_node = of_node[id];
254 230
255 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);231 rdev = devm_regulator_register(&pdev->dev, &as3711_reg_desc[id],
232 &config);
256 if (IS_ERR(rdev)) {233 if (IS_ERR(rdev)) {
257 dev_err(&pdev->dev, "Failed to register regulator %s\n",234 dev_err(&pdev->dev, "Failed to register regulator %s\n",
258 ri->desc.name);235 as3711_reg_desc[id].name);
259 return PTR_ERR(rdev);236 return PTR_ERR(rdev);
260 }237 }
261 }238 }
262 platform_set_drvdata(pdev, regs);239
263 return 0;240 return 0;
264}241}
265 242
drivers/regulator/as3722-regulator.c+86−201
@@ -81,7 +81,6 @@ struct as3722_regulator_config_data { · 80 unmodified lines
81struct as3722_regulators {81struct as3722_regulators {
82 struct device *dev;82 struct device *dev;
83 struct as3722 *as3722;83 struct as3722 *as3722;
84 struct regulator_dev *rdevs[AS3722_REGULATOR_ID_MAX];
85 struct regulator_desc desc[AS3722_REGULATOR_ID_MAX];84 struct regulator_desc desc[AS3722_REGULATOR_ID_MAX];
86 struct as3722_regulator_config_data85 struct as3722_regulator_config_data
87 reg_config_data[AS3722_REGULATOR_ID_MAX];86 reg_config_data[AS3722_REGULATOR_ID_MAX];
@@ -314,63 +313,10 @@ static const struct as3722_register_mapping as3722_reg_lookup[] = { · 226 unmodified lines
314 },313 },
315};314};
316 315
317 316static const unsigned int as3722_ldo_current[] = { 150000, 300000 };
318static const int as3722_ldo_current[] = { 150000, 300000 };317static const unsigned int as3722_sd016_current[] = {
319static const int as3722_sd016_current[] = { 2500000, 3000000, 3500000 };318 2500000, 3000000, 3500000
320 319};
321static int as3722_current_to_index(int min_uA, int max_uA,
322 const int *curr_table, int n_currents)
323{
324 int i;
325
326 for (i = n_currents - 1; i >= 0; i--) {
327 if ((min_uA <= curr_table[i]) && (curr_table[i] <= max_uA))
328 return i;
329 }
330 return -EINVAL;
331}
332
333static int as3722_ldo_get_current_limit(struct regulator_dev *rdev)
334{
335 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
336 struct as3722 *as3722 = as3722_regs->as3722;
337 int id = rdev_get_id(rdev);
338 u32 val;
339 int ret;
340
341 ret = as3722_read(as3722, as3722_reg_lookup[id].vsel_reg, &val);
342 if (ret < 0) {
343 dev_err(as3722_regs->dev, "Reg 0x%02x read failed: %d\n",
344 as3722_reg_lookup[id].vsel_reg, ret);
345 return ret;
346 }
347 if (val & AS3722_LDO_ILIMIT_MASK)
348 return 300000;
349 return 150000;
350}
351
352static int as3722_ldo_set_current_limit(struct regulator_dev *rdev,
353 int min_uA, int max_uA)
354{
355 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
356 struct as3722 *as3722 = as3722_regs->as3722;
357 int id = rdev_get_id(rdev);
358 int ret;
359 u32 reg = 0;
360
361 ret = as3722_current_to_index(min_uA, max_uA, as3722_ldo_current,
362 ARRAY_SIZE(as3722_ldo_current));
363 if (ret < 0) {
364 dev_err(as3722_regs->dev,
365 "Current range min:max = %d:%d does not support\n",
366 min_uA, max_uA);
367 return ret;
368 }
369 if (ret)
370 reg = AS3722_LDO_ILIMIT_BIT;
371 return as3722_update_bits(as3722, as3722_reg_lookup[id].vsel_reg,
372 AS3722_LDO_ILIMIT_MASK, reg);
373}
374 320
375static const struct regulator_ops as3722_ldo0_ops = {321static const struct regulator_ops as3722_ldo0_ops = {
376 .is_enabled = regulator_is_enabled_regmap,322 .is_enabled = regulator_is_enabled_regmap,
@@ -379,16 +325,16 @@ static const struct regulator_ops as3722_ldo0_ops = { · 2 unmodified lines
379 .list_voltage = regulator_list_voltage_linear,325 .list_voltage = regulator_list_voltage_linear,
380 .get_voltage_sel = regulator_get_voltage_sel_regmap,326 .get_voltage_sel = regulator_get_voltage_sel_regmap,
381 .set_voltage_sel = regulator_set_voltage_sel_regmap,327 .set_voltage_sel = regulator_set_voltage_sel_regmap,
382 .get_current_limit = as3722_ldo_get_current_limit,328 .get_current_limit = regulator_get_current_limit_regmap,
383 .set_current_limit = as3722_ldo_set_current_limit,329 .set_current_limit = regulator_set_current_limit_regmap,
384};330};
385 331
386static const struct regulator_ops as3722_ldo0_extcntrl_ops = {332static const struct regulator_ops as3722_ldo0_extcntrl_ops = {
387 .list_voltage = regulator_list_voltage_linear,333 .list_voltage = regulator_list_voltage_linear,
388 .get_voltage_sel = regulator_get_voltage_sel_regmap,334 .get_voltage_sel = regulator_get_voltage_sel_regmap,
389 .set_voltage_sel = regulator_set_voltage_sel_regmap,335 .set_voltage_sel = regulator_set_voltage_sel_regmap,
390 .get_current_limit = as3722_ldo_get_current_limit,336 .get_current_limit = regulator_get_current_limit_regmap,
391 .set_current_limit = as3722_ldo_set_current_limit,337 .set_current_limit = regulator_set_current_limit_regmap,
392};338};
393 339
394static int as3722_ldo3_set_tracking_mode(struct as3722_regulators *as3722_reg,340static int as3722_ldo3_set_tracking_mode(struct as3722_regulators *as3722_reg,
@@ -440,8 +386,8 @@ static const struct regulator_ops as3722_ldo6_ops = { · 45 unmodified lines
440 .set_voltage_sel = regulator_set_voltage_sel_regmap,386 .set_voltage_sel = regulator_set_voltage_sel_regmap,
441 .get_voltage_sel = regulator_get_voltage_sel_regmap,387 .get_voltage_sel = regulator_get_voltage_sel_regmap,
442 .list_voltage = regulator_list_voltage_linear_range,388 .list_voltage = regulator_list_voltage_linear_range,
443 .get_current_limit = as3722_ldo_get_current_limit,389 .get_current_limit = regulator_get_current_limit_regmap,
444 .set_current_limit = as3722_ldo_set_current_limit,390 .set_current_limit = regulator_set_current_limit_regmap,
445 .get_bypass = regulator_get_bypass_regmap,391 .get_bypass = regulator_get_bypass_regmap,
446 .set_bypass = regulator_set_bypass_regmap,392 .set_bypass = regulator_set_bypass_regmap,
447};393};
@@ -451,8 +397,8 @@ static const struct regulator_ops as3722_ldo6_extcntrl_ops = { · 3 unmodified lines
451 .set_voltage_sel = regulator_set_voltage_sel_regmap,397 .set_voltage_sel = regulator_set_voltage_sel_regmap,
452 .get_voltage_sel = regulator_get_voltage_sel_regmap,398 .get_voltage_sel = regulator_get_voltage_sel_regmap,
453 .list_voltage = regulator_list_voltage_linear_range,399 .list_voltage = regulator_list_voltage_linear_range,
454 .get_current_limit = as3722_ldo_get_current_limit,400 .get_current_limit = regulator_get_current_limit_regmap,
455 .set_current_limit = as3722_ldo_set_current_limit,401 .set_current_limit = regulator_set_current_limit_regmap,
456 .get_bypass = regulator_get_bypass_regmap,402 .get_bypass = regulator_get_bypass_regmap,
457 .set_bypass = regulator_set_bypass_regmap,403 .set_bypass = regulator_set_bypass_regmap,
458};404};
@@ -471,8 +417,8 @@ static const struct regulator_ops as3722_ldo_ops = { · 12 unmodified lines
471 .set_voltage_sel = regulator_set_voltage_sel_regmap,417 .set_voltage_sel = regulator_set_voltage_sel_regmap,
472 .get_voltage_sel = regulator_get_voltage_sel_regmap,418 .get_voltage_sel = regulator_get_voltage_sel_regmap,
473 .list_voltage = regulator_list_voltage_linear_range,419 .list_voltage = regulator_list_voltage_linear_range,
474 .get_current_limit = as3722_ldo_get_current_limit,420 .get_current_limit = regulator_get_current_limit_regmap,
475 .set_current_limit = as3722_ldo_set_current_limit,421 .set_current_limit = regulator_set_current_limit_regmap,
476};422};
477 423
478static const struct regulator_ops as3722_ldo_extcntrl_ops = {424static const struct regulator_ops as3722_ldo_extcntrl_ops = {
@@ -480,8 +426,8 @@ static const struct regulator_ops as3722_ldo_extcntrl_ops = { · 1 unmodified line
480 .set_voltage_sel = regulator_set_voltage_sel_regmap,426 .set_voltage_sel = regulator_set_voltage_sel_regmap,
481 .get_voltage_sel = regulator_get_voltage_sel_regmap,427 .get_voltage_sel = regulator_get_voltage_sel_regmap,
482 .list_voltage = regulator_list_voltage_linear_range,428 .list_voltage = regulator_list_voltage_linear_range,
483 .get_current_limit = as3722_ldo_get_current_limit,429 .get_current_limit = regulator_get_current_limit_regmap,
484 .set_current_limit = as3722_ldo_set_current_limit,430 .set_current_limit = regulator_set_current_limit_regmap,
485};431};
486 432
487static unsigned int as3722_sd_get_mode(struct regulator_dev *rdev)433static unsigned int as3722_sd_get_mode(struct regulator_dev *rdev)
@@ -539,85 +485,6 @@ static int as3722_sd_set_mode(struct regulator_dev *rdev, · 51 unmodified lines
539 return ret;485 return ret;
540}486}
541 487
542static int as3722_sd016_get_current_limit(struct regulator_dev *rdev)
543{
544 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
545 struct as3722 *as3722 = as3722_regs->as3722;
546 int id = rdev_get_id(rdev);
547 u32 val, reg;
548 int mask;
549 int ret;
550
551 switch (id) {
552 case AS3722_REGULATOR_ID_SD0:
553 reg = AS3722_OVCURRENT_REG;
554 mask = AS3722_OVCURRENT_SD0_TRIP_MASK;
555 break;
556 case AS3722_REGULATOR_ID_SD1:
557 reg = AS3722_OVCURRENT_REG;
558 mask = AS3722_OVCURRENT_SD1_TRIP_MASK;
559 break;
560 case AS3722_REGULATOR_ID_SD6:
561 reg = AS3722_OVCURRENT_DEB_REG;
562 mask = AS3722_OVCURRENT_SD6_TRIP_MASK;
563 break;
564 default:
565 return -EINVAL;
566 }
567 ret = as3722_read(as3722, reg, &val);
568 if (ret < 0) {
569 dev_err(as3722_regs->dev, "Reg 0x%02x read failed: %d\n",
570 reg, ret);
571 return ret;
572 }
573 val &= mask;
574 val >>= ffs(mask) - 1;
575 if (val == 3)
576 return -EINVAL;
577 return as3722_sd016_current[val];
578}
579
580static int as3722_sd016_set_current_limit(struct regulator_dev *rdev,
581 int min_uA, int max_uA)
582{
583 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
584 struct as3722 *as3722 = as3722_regs->as3722;
585 int id = rdev_get_id(rdev);
586 int ret;
587 int val;
588 int mask;
589 u32 reg;
590
591 ret = as3722_current_to_index(min_uA, max_uA, as3722_sd016_current,
592 ARRAY_SIZE(as3722_sd016_current));
593 if (ret < 0) {
594 dev_err(as3722_regs->dev,
595 "Current range min:max = %d:%d does not support\n",
596 min_uA, max_uA);
597 return ret;
598 }
599
600 switch (id) {
601 case AS3722_REGULATOR_ID_SD0:
602 reg = AS3722_OVCURRENT_REG;
603 mask = AS3722_OVCURRENT_SD0_TRIP_MASK;
604 break;
605 case AS3722_REGULATOR_ID_SD1:
606 reg = AS3722_OVCURRENT_REG;
607 mask = AS3722_OVCURRENT_SD1_TRIP_MASK;
608 break;
609 case AS3722_REGULATOR_ID_SD6:
610 reg = AS3722_OVCURRENT_DEB_REG;
611 mask = AS3722_OVCURRENT_SD6_TRIP_MASK;
612 break;
613 default:
614 return -EINVAL;
615 }
616 ret <<= ffs(mask) - 1;
617 val = ret & mask;
618 return as3722_update_bits(as3722, reg, mask, val);
619}
620
621static bool as3722_sd0_is_low_voltage(struct as3722_regulators *as3722_regs)488static bool as3722_sd0_is_low_voltage(struct as3722_regulators *as3722_regs)
622{489{
623 int err;490 int err;
@@ -649,8 +516,8 @@ static const struct regulator_ops as3722_sd016_ops = { · 25 unmodified lines
649 .map_voltage = regulator_map_voltage_linear,516 .map_voltage = regulator_map_voltage_linear,
650 .get_voltage_sel = regulator_get_voltage_sel_regmap,517 .get_voltage_sel = regulator_get_voltage_sel_regmap,
651 .set_voltage_sel = regulator_set_voltage_sel_regmap,518 .set_voltage_sel = regulator_set_voltage_sel_regmap,
652 .get_current_limit = as3722_sd016_get_current_limit,519 .get_current_limit = regulator_get_current_limit_regmap,
653 .set_current_limit = as3722_sd016_set_current_limit,520 .set_current_limit = regulator_set_current_limit_regmap,
654 .get_mode = as3722_sd_get_mode,521 .get_mode = as3722_sd_get_mode,
655 .set_mode = as3722_sd_set_mode,522 .set_mode = as3722_sd_set_mode,
656};523};
@@ -660,8 +527,8 @@ static const struct regulator_ops as3722_sd016_extcntrl_ops = { · 3 unmodified lines
660 .map_voltage = regulator_map_voltage_linear,527 .map_voltage = regulator_map_voltage_linear,
661 .get_voltage_sel = regulator_get_voltage_sel_regmap,528 .get_voltage_sel = regulator_get_voltage_sel_regmap,
662 .set_voltage_sel = regulator_set_voltage_sel_regmap,529 .set_voltage_sel = regulator_set_voltage_sel_regmap,
663 .get_current_limit = as3722_sd016_get_current_limit,530 .get_current_limit = regulator_get_current_limit_regmap,
664 .set_current_limit = as3722_sd016_set_current_limit,531 .set_current_limit = regulator_set_current_limit_regmap,
665 .get_mode = as3722_sd_get_mode,532 .get_mode = as3722_sd_get_mode,
666 .set_mode = as3722_sd_set_mode,533 .set_mode = as3722_sd_set_mode,
667};534};
@@ -807,42 +674,45 @@ static int as3722_regulator_probe(struct platform_device *pdev) · 139 unmodified lines
807 config.regmap = as3722->regmap;674 config.regmap = as3722->regmap;
808 675
809 for (id = 0; id < AS3722_REGULATOR_ID_MAX; id++) {676 for (id = 0; id < AS3722_REGULATOR_ID_MAX; id++) {
677 struct regulator_desc *desc;
678
679 desc = &as3722_regs->desc[id];
810 reg_config = &as3722_regs->reg_config_data[id];680 reg_config = &as3722_regs->reg_config_data[id];
811 681
812 as3722_regs->desc[id].name = as3722_reg_lookup[id].name;682 desc->name = as3722_reg_lookup[id].name;
813 as3722_regs->desc[id].supply_name = as3722_reg_lookup[id].sname;683 desc->supply_name = as3722_reg_lookup[id].sname;
814 as3722_regs->desc[id].id = as3722_reg_lookup[id].regulator_id;684 desc->id = as3722_reg_lookup[id].regulator_id;
815 as3722_regs->desc[id].n_voltages =685 desc->n_voltages = as3722_reg_lookup[id].n_voltages;
816 as3722_reg_lookup[id].n_voltages;686 desc->type = REGULATOR_VOLTAGE;
817 as3722_regs->desc[id].type = REGULATOR_VOLTAGE;687 desc->owner = THIS_MODULE;
818 as3722_regs->desc[id].owner = THIS_MODULE;688 desc->enable_reg = as3722_reg_lookup[id].enable_reg;
819 as3722_regs->desc[id].enable_reg =689 desc->enable_mask = as3722_reg_lookup[id].enable_mask;
820 as3722_reg_lookup[id].enable_reg;690 desc->vsel_reg = as3722_reg_lookup[id].vsel_reg;
821 as3722_regs->desc[id].enable_mask =691 desc->vsel_mask = as3722_reg_lookup[id].vsel_mask;
822 as3722_reg_lookup[id].enable_mask;
823 as3722_regs->desc[id].vsel_reg = as3722_reg_lookup[id].vsel_reg;
824 as3722_regs->desc[id].vsel_mask =
825 as3722_reg_lookup[id].vsel_mask;
826 switch (id) {692 switch (id) {
827 case AS3722_REGULATOR_ID_LDO0:693 case AS3722_REGULATOR_ID_LDO0:
828 if (reg_config->ext_control)694 if (reg_config->ext_control)
829 ops = &as3722_ldo0_extcntrl_ops;695 ops = &as3722_ldo0_extcntrl_ops;
830 else696 else
831 ops = &as3722_ldo0_ops;697 ops = &as3722_ldo0_ops;
832 as3722_regs->desc[id].min_uV = 825000;698 desc->min_uV = 825000;
833 as3722_regs->desc[id].uV_step = 25000;699 desc->uV_step = 25000;
834 as3722_regs->desc[id].linear_min_sel = 1;700 desc->linear_min_sel = 1;
835 as3722_regs->desc[id].enable_time = 500;701 desc->enable_time = 500;
702 desc->curr_table = as3722_ldo_current;
703 desc->n_current_limits = ARRAY_SIZE(as3722_ldo_current);
704 desc->csel_reg = as3722_reg_lookup[id].vsel_reg;
705 desc->csel_mask = AS3722_LDO_ILIMIT_MASK;
836 break;706 break;
837 case AS3722_REGULATOR_ID_LDO3:707 case AS3722_REGULATOR_ID_LDO3:
838 if (reg_config->ext_control)708 if (reg_config->ext_control)
839 ops = &as3722_ldo3_extcntrl_ops;709 ops = &as3722_ldo3_extcntrl_ops;
840 else710 else
841 ops = &as3722_ldo3_ops;711 ops = &as3722_ldo3_ops;
842 as3722_regs->desc[id].min_uV = 620000;712 desc->min_uV = 620000;
843 as3722_regs->desc[id].uV_step = 20000;713 desc->uV_step = 20000;
844 as3722_regs->desc[id].linear_min_sel = 1;714 desc->linear_min_sel = 1;
845 as3722_regs->desc[id].enable_time = 500;715 desc->enable_time = 500;
846 if (reg_config->enable_tracking) {716 if (reg_config->enable_tracking) {
847 ret = as3722_ldo3_set_tracking_mode(as3722_regs,717 ret = as3722_ldo3_set_tracking_mode(as3722_regs,
848 id, AS3722_LDO3_MODE_PMOS_TRACKING);718 id, AS3722_LDO3_MODE_PMOS_TRACKING);
@@ -859,18 +729,17 @@ static int as3722_regulator_probe(struct platform_device *pdev) · 10 unmodified lines
859 ops = &as3722_ldo6_extcntrl_ops;729 ops = &as3722_ldo6_extcntrl_ops;
860 else730 else
861 ops = &as3722_ldo6_ops;731 ops = &as3722_ldo6_ops;
862 as3722_regs->desc[id].enable_time = 500;732 desc->enable_time = 500;
863 as3722_regs->desc[id].bypass_reg =733 desc->bypass_reg = AS3722_LDO6_VOLTAGE_REG;
864 AS3722_LDO6_VOLTAGE_REG;734 desc->bypass_mask = AS3722_LDO_VSEL_MASK;
865 as3722_regs->desc[id].bypass_mask =735 desc->bypass_val_on = AS3722_LDO6_VSEL_BYPASS;
866 AS3722_LDO_VSEL_MASK;736 desc->bypass_val_off = AS3722_LDO6_VSEL_BYPASS;
867 as3722_regs->desc[id].bypass_val_on =737 desc->linear_ranges = as3722_ldo_ranges;
868 AS3722_LDO6_VSEL_BYPASS;738 desc->n_linear_ranges = ARRAY_SIZE(as3722_ldo_ranges);
869 as3722_regs->desc[id].bypass_val_off =739 desc->curr_table = as3722_ldo_current;
870 AS3722_LDO6_VSEL_BYPASS;740 desc->n_current_limits = ARRAY_SIZE(as3722_ldo_current);
871 as3722_regs->desc[id].linear_ranges = as3722_ldo_ranges;741 desc->csel_reg = as3722_reg_lookup[id].vsel_reg;
872 as3722_regs->desc[id].n_linear_ranges =742 desc->csel_mask = AS3722_LDO_ILIMIT_MASK;
873 ARRAY_SIZE(as3722_ldo_ranges);
874 break;743 break;
875 case AS3722_REGULATOR_ID_SD0:744 case AS3722_REGULATOR_ID_SD0:
876 case AS3722_REGULATOR_ID_SD1:745 case AS3722_REGULATOR_ID_SD1:
@@ -889,9 +758,25 @@ static int as3722_regulator_probe(struct platform_device *pdev) · 12 unmodified lines
889 AS3722_SD0_VSEL_MAX + 1;758 AS3722_SD0_VSEL_MAX + 1;
890 as3722_regs->desc[id].min_uV = 610000;759 as3722_regs->desc[id].min_uV = 610000;
891 }760 }
892 as3722_regs->desc[id].uV_step = 10000;761 desc->uV_step = 10000;
893 as3722_regs->desc[id].linear_min_sel = 1;762 desc->linear_min_sel = 1;
894 as3722_regs->desc[id].enable_time = 600;763 desc->enable_time = 600;
764 desc->curr_table = as3722_sd016_current;
765 desc->n_current_limits =
766 ARRAY_SIZE(as3722_sd016_current);
767 if (id == AS3722_REGULATOR_ID_SD0) {
768 desc->csel_reg = AS3722_OVCURRENT_REG;
769 desc->csel_mask =
770 AS3722_OVCURRENT_SD0_TRIP_MASK;
771 } else if (id == AS3722_REGULATOR_ID_SD1) {
772 desc->csel_reg = AS3722_OVCURRENT_REG;
773 desc->csel_mask =
774 AS3722_OVCURRENT_SD1_TRIP_MASK;
775 } else if (id == AS3722_REGULATOR_ID_SD6) {
776 desc->csel_reg = AS3722_OVCURRENT_DEB_REG;
777 desc->csel_mask =
778 AS3722_OVCURRENT_SD6_TRIP_MASK;
779 }
895 break;780 break;
896 case AS3722_REGULATOR_ID_SD2:781 case AS3722_REGULATOR_ID_SD2:
897 case AS3722_REGULATOR_ID_SD3:782 case AS3722_REGULATOR_ID_SD3:
@@ -901,9 +786,8 @@ static int as3722_regulator_probe(struct platform_device *pdev) · 3 unmodified lines
901 ops = &as3722_sd2345_extcntrl_ops;786 ops = &as3722_sd2345_extcntrl_ops;
902 else787 else
903 ops = &as3722_sd2345_ops;788 ops = &as3722_sd2345_ops;
904 as3722_regs->desc[id].linear_ranges =789 desc->linear_ranges = as3722_sd2345_ranges;
905 as3722_sd2345_ranges;790 desc->n_linear_ranges =
906 as3722_regs->desc[id].n_linear_ranges =
907 ARRAY_SIZE(as3722_sd2345_ranges);791 ARRAY_SIZE(as3722_sd2345_ranges);
908 break;792 break;
909 default:793 default:
@@ -911,17 +795,19 @@ static int as3722_regulator_probe(struct platform_device *pdev) · 1 unmodified line
911 ops = &as3722_ldo_extcntrl_ops;795 ops = &as3722_ldo_extcntrl_ops;
912 else796 else
913 ops = &as3722_ldo_ops;797 ops = &as3722_ldo_ops;
914 as3722_regs->desc[id].enable_time = 500;798 desc->enable_time = 500;
915 as3722_regs->desc[id].linear_ranges = as3722_ldo_ranges;799 desc->linear_ranges = as3722_ldo_ranges;
916 as3722_regs->desc[id].n_linear_ranges =800 desc->n_linear_ranges = ARRAY_SIZE(as3722_ldo_ranges);
917 ARRAY_SIZE(as3722_ldo_ranges);801 desc->curr_table = as3722_ldo_current;
802 desc->n_current_limits = ARRAY_SIZE(as3722_ldo_current);
803 desc->csel_reg = as3722_reg_lookup[id].vsel_reg;
804 desc->csel_mask = AS3722_LDO_ILIMIT_MASK;
918 break;805 break;
919 }806 }
920 as3722_regs->desc[id].ops = ops;807 desc->ops = ops;
921 config.init_data = reg_config->reg_init;808 config.init_data = reg_config->reg_init;
922 config.of_node = as3722_regulator_matches[id].of_node;809 config.of_node = as3722_regulator_matches[id].of_node;
923 rdev = devm_regulator_register(&pdev->dev,810 rdev = devm_regulator_register(&pdev->dev, desc, &config);
924 &as3722_regs->desc[id], &config);
925 if (IS_ERR(rdev)) {811 if (IS_ERR(rdev)) {
926 ret = PTR_ERR(rdev);812 ret = PTR_ERR(rdev);
927 dev_err(&pdev->dev, "regulator %d register failed %d\n",813 dev_err(&pdev->dev, "regulator %d register failed %d\n",
@@ -929,7 +815,6 @@ static int as3722_regulator_probe(struct platform_device *pdev) · 1 unmodified line
929 return ret;815 return ret;
930 }816 }
931 817
932 as3722_regs->rdevs[id] = rdev;
933 if (reg_config->ext_control) {818 if (reg_config->ext_control) {
934 ret = regulator_enable_regmap(rdev);819 ret = regulator_enable_regmap(rdev);
935 if (ret < 0) {820 if (ret < 0) {
drivers/regulator/axp20x-regulator.c+8−15
@@ -367,16 +367,14 @@ static const int axp209_dcdc2_ldo3_slew_rates[] = { · 366 unmodified lines
367static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)367static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)
368{368{
369 struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);369 struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);
370 const struct regulator_desc *desc;370 int id = rdev_get_id(rdev);
371 u8 reg, mask, enable, cfg = 0xff;371 u8 reg, mask, enable, cfg = 0xff;
372 const int *slew_rates;372 const int *slew_rates;
373 int rate_count = 0;373 int rate_count = 0;
374 374
375 desc = rdev->desc;
376
377 switch (axp20x->variant) {375 switch (axp20x->variant) {
378 case AXP209_ID:376 case AXP209_ID:
379 if (desc->id == AXP20X_DCDC2) {377 if (id == AXP20X_DCDC2) {
380 slew_rates = axp209_dcdc2_ldo3_slew_rates;378 slew_rates = axp209_dcdc2_ldo3_slew_rates;
381 rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates);379 rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates);
382 reg = AXP20X_DCDC2_LDO3_V_RAMP;380 reg = AXP20X_DCDC2_LDO3_V_RAMP;
@@ -388,7 +386,7 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp) · 5 unmodified lines
388 break;386 break;
389 }387 }
390 388
391 if (desc->id == AXP20X_LDO3) {389 if (id == AXP20X_LDO3) {
392 slew_rates = axp209_dcdc2_ldo3_slew_rates;390 slew_rates = axp209_dcdc2_ldo3_slew_rates;
393 rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates);391 rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates);
394 reg = AXP20X_DCDC2_LDO3_V_RAMP;392 reg = AXP20X_DCDC2_LDO3_V_RAMP;
@@ -435,16 +433,11 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp) · 40 unmodified lines
435static int axp20x_regulator_enable_regmap(struct regulator_dev *rdev)433static int axp20x_regulator_enable_regmap(struct regulator_dev *rdev)
436{434{
437 struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);435 struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);
438 const struct regulator_desc *desc;436 int id = rdev_get_id(rdev);
439
440 if (!rdev)
441 return -EINVAL;
442
443 desc = rdev->desc;
444 437
445 switch (axp20x->variant) {438 switch (axp20x->variant) {
446 case AXP209_ID:439 case AXP209_ID:
447 if ((desc->id == AXP20X_LDO3) &&440 if ((id == AXP20X_LDO3) &&
448 rdev->constraints && rdev->constraints->soft_start) {441 rdev->constraints && rdev->constraints->soft_start) {
449 int v_out;442 int v_out;
450 int ret;443 int ret;
@@ -1028,7 +1021,7 @@ static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq) · 577 unmodified lines
1028 * (See include/linux/mfd/axp20x.h)1021 * (See include/linux/mfd/axp20x.h)
1029 */1022 */
1030 reg = AXP803_DCDC_FREQ_CTRL;1023 reg = AXP803_DCDC_FREQ_CTRL;
1031 /* Fall through to the check below.*/1024 /* Fall through - to the check below.*/
1032 case AXP806_ID:1025 case AXP806_ID:
1033 /*1026 /*
1034 * AXP806 also have DCDC work frequency setting register at a1027 * AXP806 also have DCDC work frequency setting register at a
@@ -1119,12 +1112,12 @@ static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 work · 84 unmodified lines
1119 break;1112 break;
1120 1113
1121 case AXP806_ID:1114 case AXP806_ID:
1122 reg = AXP806_DCDC_MODE_CTRL2;
1123 /*1115 /*
1124 * AXP806 DCDC regulator IDs have the same range as AXP22X.1116 * AXP806 DCDC regulator IDs have the same range as AXP22X.
1125 * Fall through to the check below.
1126 * (See include/linux/mfd/axp20x.h)1117 * (See include/linux/mfd/axp20x.h)
1127 */1118 */
1119 reg = AXP806_DCDC_MODE_CTRL2;
1120 /* Fall through - to the check below. */
1128 case AXP221_ID:1121 case AXP221_ID:
1129 case AXP223_ID:1122 case AXP223_ID:
1130 case AXP809_ID:1123 case AXP809_ID:
drivers/regulator/bcm590xx-regulator.c+2−103
@@ -103,10 +103,6 @@ · 102 unmodified lines
103 ((n > BCM590XX_REG_VSR) && (n < BCM590XX_REG_VBUS))103 ((n > BCM590XX_REG_VSR) && (n < BCM590XX_REG_VBUS))
104#define BCM590XX_REG_IS_VBUS(n) (n == BCM590XX_REG_VBUS)104#define BCM590XX_REG_IS_VBUS(n) (n == BCM590XX_REG_VBUS)
105 105
106struct bcm590xx_board {
107 struct regulator_init_data *bcm590xx_pmu_init_data[BCM590XX_NUM_REGS];
108};
109
110/* LDO group A: supported voltages in microvolts */106/* LDO group A: supported voltages in microvolts */
111static const unsigned int ldo_a_table[] = {107static const unsigned int ldo_a_table[] = {
112 1200000, 1800000, 2500000, 2700000, 2800000,108 1200000, 1800000, 2500000, 2700000, 2800000,
@@ -280,105 +276,15 @@ static const struct regulator_ops bcm590xx_ops_vbus = { · 167 unmodified lines
280 .disable = regulator_disable_regmap,276 .disable = regulator_disable_regmap,
281};277};
282 278
283#define BCM590XX_MATCH(_name, _id) \
284 { \
285 .name = #_name, \
286 .driver_data = (void *)&bcm590xx_regs[BCM590XX_REG_##_id], \
287 }
288
289static struct of_regulator_match bcm590xx_matches[] = {
290 BCM590XX_MATCH(rfldo, RFLDO),
291 BCM590XX_MATCH(camldo1, CAMLDO1),
292 BCM590XX_MATCH(camldo2, CAMLDO2),
293 BCM590XX_MATCH(simldo1, SIMLDO1),
294 BCM590XX_MATCH(simldo2, SIMLDO2),
295 BCM590XX_MATCH(sdldo, SDLDO),
296 BCM590XX_MATCH(sdxldo, SDXLDO),
297 BCM590XX_MATCH(mmcldo1, MMCLDO1),
298 BCM590XX_MATCH(mmcldo2, MMCLDO2),
299 BCM590XX_MATCH(audldo, AUDLDO),
300 BCM590XX_MATCH(micldo, MICLDO),
301 BCM590XX_MATCH(usbldo, USBLDO),
302 BCM590XX_MATCH(vibldo, VIBLDO),
303 BCM590XX_MATCH(csr, CSR),
304 BCM590XX_MATCH(iosr1, IOSR1),
305 BCM590XX_MATCH(iosr2, IOSR2),
306 BCM590XX_MATCH(msr, MSR),
307 BCM590XX_MATCH(sdsr1, SDSR1),
308 BCM590XX_MATCH(sdsr2, SDSR2),
309 BCM590XX_MATCH(vsr, VSR),
310 BCM590XX_MATCH(gpldo1, GPLDO1),
311 BCM590XX_MATCH(gpldo2, GPLDO2),
312 BCM590XX_MATCH(gpldo3, GPLDO3),
313 BCM590XX_MATCH(gpldo4, GPLDO4),
314 BCM590XX_MATCH(gpldo5, GPLDO5),
315 BCM590XX_MATCH(gpldo6, GPLDO6),
316 BCM590XX_MATCH(vbus, VBUS),
317};
318
319static struct bcm590xx_board *bcm590xx_parse_dt_reg_data(
320 struct platform_device *pdev,
321 struct of_regulator_match **bcm590xx_reg_matches)
322{
323 struct bcm590xx_board *data;
324 struct device_node *np = pdev->dev.parent->of_node;
325 struct device_node *regulators;
326 struct of_regulator_match *matches = bcm590xx_matches;
327 int count = ARRAY_SIZE(bcm590xx_matches);
328 int idx = 0;
329 int ret;
330
331 if (!np) {
332 dev_err(&pdev->dev, "of node not found\n");
333 return NULL;
334 }
335
336 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
337 if (!data)
338 return NULL;
339
340 np = of_node_get(np);
341 regulators = of_get_child_by_name(np, "regulators");
342 if (!regulators) {
343 dev_warn(&pdev->dev, "regulator node not found\n");
344 return NULL;
345 }
346
347 ret = of_regulator_match(&pdev->dev, regulators, matches, count);
348 of_node_put(regulators);
349 if (ret < 0) {
350 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
351 ret);
352 return NULL;
353 }
354
355 *bcm590xx_reg_matches = matches;
356
357 for (idx = 0; idx < count; idx++) {
358 if (!matches[idx].init_data || !matches[idx].of_node)
359 continue;
360
361 data->bcm590xx_pmu_init_data[idx] = matches[idx].init_data;
362 }
363
364 return data;
365}
366
367static int bcm590xx_probe(struct platform_device *pdev)279static int bcm590xx_probe(struct platform_device *pdev)
368{280{
369 struct bcm590xx *bcm590xx = dev_get_drvdata(pdev->dev.parent);281 struct bcm590xx *bcm590xx = dev_get_drvdata(pdev->dev.parent);
370 struct bcm590xx_board *pmu_data = NULL;
371 struct bcm590xx_reg *pmu;282 struct bcm590xx_reg *pmu;
372 struct regulator_config config = { };283 struct regulator_config config = { };
373 struct bcm590xx_info *info;284 struct bcm590xx_info *info;
374 struct regulator_init_data *reg_data;
375 struct regulator_dev *rdev;285 struct regulator_dev *rdev;
376 struct of_regulator_match *bcm590xx_reg_matches = NULL;
377 int i;286 int i;
378 287
379 pmu_data = bcm590xx_parse_dt_reg_data(pdev,
380 &bcm590xx_reg_matches);
381
382 pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL);288 pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL);
383 if (!pmu)289 if (!pmu)
384 return -ENOMEM;290 return -ENOMEM;
@@ -397,13 +303,10 @@ static int bcm590xx_probe(struct platform_device *pdev) · 12 unmodified lines
397 info = bcm590xx_regs;303 info = bcm590xx_regs;
398 304
399 for (i = 0; i < BCM590XX_NUM_REGS; i++, info++) {305 for (i = 0; i < BCM590XX_NUM_REGS; i++, info++) {
400 if (pmu_data)
401 reg_data = pmu_data->bcm590xx_pmu_init_data[i];
402 else
403 reg_data = NULL;
404
405 /* Register the regulators */306 /* Register the regulators */
406 pmu->desc[i].name = info->name;307 pmu->desc[i].name = info->name;
308 pmu->desc[i].of_match = of_match_ptr(info->name);
309 pmu->desc[i].regulators_node = of_match_ptr("regulators");
407 pmu->desc[i].supply_name = info->vin_name;310 pmu->desc[i].supply_name = info->vin_name;
408 pmu->desc[i].id = i;311 pmu->desc[i].id = i;
409 pmu->desc[i].volt_table = info->volt_table;312 pmu->desc[i].volt_table = info->volt_table;
@@ -433,16 +336,12 @@ static int bcm590xx_probe(struct platform_device *pdev) · 23 unmodified lines
433 pmu->desc[i].owner = THIS_MODULE;336 pmu->desc[i].owner = THIS_MODULE;
434 337
435 config.dev = bcm590xx->dev;338 config.dev = bcm590xx->dev;
436 config.init_data = reg_data;
437 config.driver_data = pmu;339 config.driver_data = pmu;
438 if (BCM590XX_REG_IS_GPLDO(i) || BCM590XX_REG_IS_VBUS(i))340 if (BCM590XX_REG_IS_GPLDO(i) || BCM590XX_REG_IS_VBUS(i))
439 config.regmap = bcm590xx->regmap_sec;341 config.regmap = bcm590xx->regmap_sec;
440 else342 else
441 config.regmap = bcm590xx->regmap_pri;343 config.regmap = bcm590xx->regmap_pri;
442 344
443 if (bcm590xx_reg_matches)
444 config.of_node = bcm590xx_reg_matches[i].of_node;
445
446 rdev = devm_regulator_register(&pdev->dev, &pmu->desc[i],345 rdev = devm_regulator_register(&pdev->dev, &pmu->desc[i],
447 &config);346 &config);
448 if (IS_ERR(rdev)) {347 if (IS_ERR(rdev)) {
drivers/regulator/bd718x7-regulator.c+2−2
@@ -27,8 +27,8 @@ · 26 unmodified lines
27static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,27static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
28 int ramp_delay)28 int ramp_delay)
29{29{
30 int id = rdev->desc->id;30 int id = rdev_get_id(rdev);
31 unsigned int ramp_value = BUCK_RAMPRATE_10P00MV;31 unsigned int ramp_value;
32 32
33 dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,33 dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
34 ramp_delay);34 ramp_delay);
drivers/regulator/core.c+9−6
@@ -1339,9 +1339,7 @@ static int set_machine_constraints(struct regulator_dev *rdev, · 1338 unmodified lines
1339 * We'll only apply the initial system load if an1339 * We'll only apply the initial system load if an
1340 * initial mode wasn't specified.1340 * initial mode wasn't specified.
1341 */1341 */
1342 regulator_lock(rdev);
1343 drms_uA_update(rdev);1342 drms_uA_update(rdev);
1344 regulator_unlock(rdev);
1345 }1343 }
1346 1344
1347 if ((rdev->constraints->ramp_delay || rdev->constraints->ramp_disable)1345 if ((rdev->constraints->ramp_delay || rdev->constraints->ramp_disable)
@@ -3005,7 +3003,7 @@ EXPORT_SYMBOL_GPL(regulator_get_linear_step); · 1657 unmodified lines
3005 * @min_uV: Minimum required voltage in uV.3003 * @min_uV: Minimum required voltage in uV.
3006 * @max_uV: Maximum required voltage in uV.3004 * @max_uV: Maximum required voltage in uV.
3007 *3005 *
3008 * Returns a boolean or a negative error code.3006 * Returns a boolean.
3009 */3007 */
3010int regulator_is_supported_voltage(struct regulator *regulator,3008int regulator_is_supported_voltage(struct regulator *regulator,
3011 int min_uV, int max_uV)3009 int min_uV, int max_uV)
@@ -3029,7 +3027,7 @@ int regulator_is_supported_voltage(struct regulator *regulator, · 17 unmodified lines
3029 3027
3030 ret = regulator_count_voltages(regulator);3028 ret = regulator_count_voltages(regulator);
3031 if (ret < 0)3029 if (ret < 0)
3032 return ret;3030 return 0;
3033 voltages = ret;3031 voltages = ret;
3034 3032
3035 for (i = 0; i < voltages; i++) {3033 for (i = 0; i < voltages; i++) {
@@ -4345,8 +4343,6 @@ int regulator_bulk_get(struct device *dev, int num_consumers, · 1309 unmodified lines
4345 consumers[i].supply);4343 consumers[i].supply);
4346 if (IS_ERR(consumers[i].consumer)) {4344 if (IS_ERR(consumers[i].consumer)) {
4347 ret = PTR_ERR(consumers[i].consumer);4345 ret = PTR_ERR(consumers[i].consumer);
4348 dev_err(dev, "Failed to get supply '%s': %d\n",
4349 consumers[i].supply, ret);
4350 consumers[i].consumer = NULL;4346 consumers[i].consumer = NULL;
4351 goto err;4347 goto err;
4352 }4348 }
@@ -4355,6 +4351,13 @@ int regulator_bulk_get(struct device *dev, int num_consumers, · 2 unmodified lines
4355 return 0;4351 return 0;
4356 4352
4357err:4353err:
4354 if (ret != -EPROBE_DEFER)
4355 dev_err(dev, "Failed to get supply '%s': %d\n",
4356 consumers[i].supply, ret);
4357 else
4358 dev_dbg(dev, "Failed to get supply '%s', deferring\n",
4359 consumers[i].supply);
4360
4358 while (--i >= 0)4361 while (--i >= 0)
4359 regulator_put(consumers[i].consumer);4362 regulator_put(consumers[i].consumer);
4360 4363
drivers/regulator/cpcap-regulator.c+4−11
@@ -505,17 +505,12 @@ MODULE_DEVICE_TABLE(of, cpcap_regulator_id_table); · 504 unmodified lines
505static int cpcap_regulator_probe(struct platform_device *pdev)505static int cpcap_regulator_probe(struct platform_device *pdev)
506{506{
507 struct cpcap_ddata *ddata;507 struct cpcap_ddata *ddata;
508 const struct of_device_id *match;508 const struct cpcap_regulator *match_data;
509 struct regulator_config config;509 struct regulator_config config;
510 struct regulator_init_data init_data;
511 int i;510 int i;
512 511
513 match = of_match_device(of_match_ptr(cpcap_regulator_id_table),512 match_data = of_device_get_match_data(&pdev->dev);
514 &pdev->dev);513 if (!match_data) {
515 if (!match)
516 return -EINVAL;
517
518 if (!match->data) {
519 dev_err(&pdev->dev, "no configuration data found\n");514 dev_err(&pdev->dev, "no configuration data found\n");
520 515
521 return -ENODEV;516 return -ENODEV;
@@ -530,14 +525,12 @@ static int cpcap_regulator_probe(struct platform_device *pdev) · 8 unmodified lines
530 return -ENODEV;525 return -ENODEV;
531 526
532 ddata->dev = &pdev->dev;527 ddata->dev = &pdev->dev;
533 ddata->soc = match->data;528 ddata->soc = match_data;
534 platform_set_drvdata(pdev, ddata);529 platform_set_drvdata(pdev, ddata);
535 530
536 memset(&config, 0, sizeof(config));531 memset(&config, 0, sizeof(config));
537 memset(&init_data, 0, sizeof(init_data));
538 config.dev = &pdev->dev;532 config.dev = &pdev->dev;
539 config.regmap = ddata->reg;533 config.regmap = ddata->reg;
540 config.init_data = &init_data;
541 534
542 for (i = 0; i < CPCAP_NR_REGULATORS; i++) {535 for (i = 0; i < CPCAP_NR_REGULATORS; i++) {
543 const struct cpcap_regulator *regulator = &ddata->soc[i];536 const struct cpcap_regulator *regulator = &ddata->soc[i];
drivers/regulator/da903x.c+6−10
@@ -1,13 +1,9 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * Regulators driver for Dialog Semiconductor DA903x2//
3 *3// Regulators driver for Dialog Semiconductor DA903x
4 * Copyright (C) 2006-2008 Marvell International Ltd.4//
5 * Copyright (C) 2008 Compulab Ltd.5// Copyright (C) 2006-2008 Marvell International Ltd.
6 *6// Copyright (C) 2008 Compulab Ltd.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11 7
12#include <linux/kernel.h>8#include <linux/kernel.h>
13#include <linux/init.h>9#include <linux/init.h>
drivers/regulator/da9052-regulator.c+13−42
@@ -1,16 +1,10 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2* da9052-regulator.c: Regulator driver for DA90522//
3*3// da9052-regulator.c: Regulator driver for DA9052
4* Copyright(c) 2011 Dialog Semiconductor Ltd.4//
5*5// Copyright(c) 2011 Dialog Semiconductor Ltd.
6* Author: David Dajun Chen <dchen@diasemi.com>6//
7*7// Author: David Dajun Chen <dchen@diasemi.com>
8* This program is free software; you can redistribute it and/or modify
9* it under the terms of the GNU General Public License as published by
10* the Free Software Foundation; either version 2 of the License, or
11* (at your option) any later version.
12*
13*/
14 8
15#include <linux/module.h>9#include <linux/module.h>
16#include <linux/moduleparam.h>10#include <linux/moduleparam.h>
@@ -19,10 +13,8 @@ · 2 unmodified lines
19#include <linux/platform_device.h>13#include <linux/platform_device.h>
20#include <linux/regulator/driver.h>14#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h>15#include <linux/regulator/machine.h>
22#ifdef CONFIG_OF
23#include <linux/of.h>16#include <linux/of.h>
24#include <linux/regulator/of_regulator.h>17#include <linux/regulator/of_regulator.h>
25#endif
26 18
27#include <linux/mfd/da9052/da9052.h>19#include <linux/mfd/da9052/da9052.h>
28#include <linux/mfd/da9052/reg.h>20#include <linux/mfd/da9052/reg.h>
@@ -294,6 +286,8 @@ static const struct regulator_ops da9052_ldo_ops = { · 265 unmodified lines
294{\286{\
295 .reg_desc = {\287 .reg_desc = {\
296 .name = #_name,\288 .name = #_name,\
289 .of_match = of_match_ptr(#_name),\
290 .regulators_node = of_match_ptr("regulators"),\
297 .ops = &da9052_ldo_ops,\291 .ops = &da9052_ldo_ops,\
298 .type = REGULATOR_VOLTAGE,\292 .type = REGULATOR_VOLTAGE,\
299 .id = DA9052_ID_##_id,\293 .id = DA9052_ID_##_id,\
@@ -314,6 +308,8 @@ static const struct regulator_ops da9052_ldo_ops = { · 14 unmodified lines
314{\308{\
315 .reg_desc = {\309 .reg_desc = {\
316 .name = #_name,\310 .name = #_name,\
311 .of_match = of_match_ptr(#_name),\
312 .regulators_node = of_match_ptr("regulators"),\
317 .ops = &da9052_dcdc_ops,\313 .ops = &da9052_dcdc_ops,\
318 .type = REGULATOR_VOLTAGE,\314 .type = REGULATOR_VOLTAGE,\
319 .id = DA9052_ID_##_id,\315 .id = DA9052_ID_##_id,\
@@ -417,36 +413,11 @@ static int da9052_regulator_probe(struct platform_device *pdev) · 97 unmodified lines
417 return -EINVAL;413 return -EINVAL;
418 }414 }
419 415
420 config.dev = &pdev->dev;416 config.dev = da9052->dev;
421 config.driver_data = regulator;417 config.driver_data = regulator;
422 config.regmap = da9052->regmap;418 config.regmap = da9052->regmap;
423 if (pdata) {419 if (pdata)
424 config.init_data = pdata->regulators[cell->id];420 config.init_data = pdata->regulators[cell->id];
425 } else {
426#ifdef CONFIG_OF
427 struct device_node *nproot = da9052->dev->of_node;
428 struct device_node *np;
429
430 if (!nproot)
431 return -ENODEV;
432
433 nproot = of_get_child_by_name(nproot, "regulators");
434 if (!nproot)
435 return -ENODEV;
436
437 for_each_child_of_node(nproot, np) {
438 if (of_node_name_eq(np,
439 regulator->info->reg_desc.name)) {
440 config.init_data = of_get_regulator_init_data(
441 &pdev->dev, np,
442 &regulator->info->reg_desc);
443 config.of_node = np;
444 break;
445 }
446 }
447 of_node_put(nproot);
448#endif
449 }
450 421
451 regulator->rdev = devm_regulator_register(&pdev->dev,422 regulator->rdev = devm_regulator_register(&pdev->dev,
452 &regulator->info->reg_desc,423 &regulator->info->reg_desc,
drivers/regulator/da9055-regulator.c+15−74
@@ -1,16 +1,10 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2* Regulator driver for DA9055 PMIC2//
3*3// Regulator driver for DA9055 PMIC
4* Copyright(c) 2012 Dialog Semiconductor Ltd.4//
5*5// Copyright(c) 2012 Dialog Semiconductor Ltd.
6* Author: David Dajun Chen <dchen@diasemi.com>6//
7*7// Author: David Dajun Chen <dchen@diasemi.com>
8* This program is free software; you can redistribute it and/or modify
9* it under the terms of the GNU General Public License as published by
10* the Free Software Foundation; either version 2 of the License, or
11* (at your option) any later version.
12*
13*/
14 8
15#include <linux/module.h>9#include <linux/module.h>
16#include <linux/init.h>10#include <linux/init.h>
@@ -338,6 +332,8 @@ static const struct regulator_ops da9055_ldo_ops = { · 321 unmodified lines
338{\332{\
339 .reg_desc = {\333 .reg_desc = {\
340 .name = #_id,\334 .name = #_id,\
335 .of_match = of_match_ptr(#_id),\
336 .regulators_node = of_match_ptr("regulators"),\
341 .ops = &da9055_ldo_ops,\337 .ops = &da9055_ldo_ops,\
342 .type = REGULATOR_VOLTAGE,\338 .type = REGULATOR_VOLTAGE,\
343 .id = DA9055_ID_##_id,\339 .id = DA9055_ID_##_id,\
@@ -366,6 +362,8 @@ static const struct regulator_ops da9055_ldo_ops = { · 22 unmodified lines
366{\362{\
367 .reg_desc = {\363 .reg_desc = {\
368 .name = #_id,\364 .name = #_id,\
365 .of_match = of_match_ptr(#_id),\
366 .regulators_node = of_match_ptr("regulators"),\
369 .ops = &da9055_buck_ops,\367 .ops = &da9055_buck_ops,\
370 .type = REGULATOR_VOLTAGE,\368 .type = REGULATOR_VOLTAGE,\
371 .id = DA9055_ID_##_id,\369 .id = DA9055_ID_##_id,\
@@ -487,8 +485,10 @@ static irqreturn_t da9055_ldo5_6_oc_irq(int irq, void *data) · 115 unmodified lines
487{485{
488 struct da9055_regulator *regulator = data;486 struct da9055_regulator *regulator = data;
489 487
488 regulator_lock(regulator->rdev);
490 regulator_notifier_call_chain(regulator->rdev,489 regulator_notifier_call_chain(regulator->rdev,
491 REGULATOR_EVENT_OVER_CURRENT, NULL);490 REGULATOR_EVENT_OVER_CURRENT, NULL);
491 regulator_unlock(regulator->rdev);
492 492
493 return IRQ_HANDLED;493 return IRQ_HANDLED;
494}494}
@@ -507,59 +507,6 @@ static inline struct da9055_regulator_info *find_regulator_info(int id) · 12 unmodified lines
507 return NULL;507 return NULL;
508}508}
509 509
510#ifdef CONFIG_OF
511static struct of_regulator_match da9055_reg_matches[] = {
512 { .name = "BUCK1", },
513 { .name = "BUCK2", },
514 { .name = "LDO1", },
515 { .name = "LDO2", },
516 { .name = "LDO3", },
517 { .name = "LDO4", },
518 { .name = "LDO5", },
519 { .name = "LDO6", },
520};
521
522static int da9055_regulator_dt_init(struct platform_device *pdev,
523 struct da9055_regulator *regulator,
524 struct regulator_config *config,
525 int regid)
526{
527 struct device_node *nproot, *np;
528 int ret;
529
530 nproot = of_node_get(pdev->dev.parent->of_node);
531 if (!nproot)
532 return -ENODEV;
533
534 np = of_get_child_by_name(nproot, "regulators");
535 if (!np)
536 return -ENODEV;
537
538 ret = of_regulator_match(&pdev->dev, np, &da9055_reg_matches[regid], 1);
539 of_node_put(nproot);
540 if (ret < 0) {
541 dev_err(&pdev->dev, "Error matching regulator: %d\n", ret);
542 return ret;
543 }
544
545 config->init_data = da9055_reg_matches[regid].init_data;
546 config->of_node = da9055_reg_matches[regid].of_node;
547
548 if (!config->of_node)
549 return -ENODEV;
550
551 return 0;
552}
553#else
554static inline int da9055_regulator_dt_init(struct platform_device *pdev,
555 struct da9055_regulator *regulator,
556 struct regulator_config *config,
557 int regid)
558{
559 return -ENODEV;
560}
561#endif /* CONFIG_OF */
562
563static int da9055_regulator_probe(struct platform_device *pdev)510static int da9055_regulator_probe(struct platform_device *pdev)
564{511{
565 struct regulator_config config = { };512 struct regulator_config config = { };
@@ -580,18 +527,12 @@ static int da9055_regulator_probe(struct platform_device *pdev) · 14 unmodified lines
580 }527 }
581 528
582 regulator->da9055 = da9055;529 regulator->da9055 = da9055;
583 config.dev = &pdev->dev;530 config.dev = da9055->dev;
584 config.driver_data = regulator;531 config.driver_data = regulator;
585 config.regmap = da9055->regmap;532 config.regmap = da9055->regmap;
586 533
587 if (pdata) {534 if (pdata)
588 config.init_data = pdata->regulators[pdev->id];535 config.init_data = pdata->regulators[pdev->id];
589 } else {
590 ret = da9055_regulator_dt_init(pdev, regulator, &config,
591 pdev->id);
592 if (ret < 0)
593 return ret;
594 }
595 536
596 ret = da9055_gpio_init(regulator, &config, pdata, pdev->id);537 ret = da9055_gpio_init(regulator, &config, pdata, pdev->id);
597 if (ret < 0)538 if (ret < 0)
drivers/regulator/da9062-regulator.c+39−107
@@ -1,17 +1,8 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * Regulator device driver for DA9061 and DA9062.2//
3 * Copyright (C) 2015-2017 Dialog Semiconductor3// Regulator device driver for DA9061 and DA9062.
4 *4// Copyright (C) 2015-2017 Dialog Semiconductor
5 * This program is free software; you can redistribute it and/or5
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15#include <linux/kernel.h>6#include <linux/kernel.h>
16#include <linux/module.h>7#include <linux/module.h>
17#include <linux/init.h>8#include <linux/init.h>
@@ -53,16 +44,12 @@ enum { · 35 unmodified lines
53/* Regulator capabilities and registers description */44/* Regulator capabilities and registers description */
54struct da9062_regulator_info {45struct da9062_regulator_info {
55 struct regulator_desc desc;46 struct regulator_desc desc;
56 /* Current limiting */
57 unsigned int n_current_limits;
58 const int *current_limits;
59 /* Main register fields */47 /* Main register fields */
60 struct reg_field mode;48 struct reg_field mode;
61 struct reg_field suspend;49 struct reg_field suspend;
62 struct reg_field sleep;50 struct reg_field sleep;
63 struct reg_field suspend_sleep;51 struct reg_field suspend_sleep;
64 unsigned int suspend_vsel_reg;52 unsigned int suspend_vsel_reg;
65 struct reg_field ilimit;
66 /* Event detection bit */53 /* Event detection bit */
67 struct reg_field oc_event;54 struct reg_field oc_event;
68};55};
@@ -78,7 +65,6 @@ struct da9062_regulator { · 9 unmodified lines
78 struct regmap_field *suspend;65 struct regmap_field *suspend;
79 struct regmap_field *sleep;66 struct regmap_field *sleep;
80 struct regmap_field *suspend_sleep;67 struct regmap_field *suspend_sleep;
81 struct regmap_field *ilimit;
82};68};
83 69
84/* Encapsulates all information for the regulators driver */70/* Encapsulates all information for the regulators driver */
@@ -104,7 +90,7 @@ enum { · 19 unmodified lines
104 * - DA9062_ID_[BUCK1|BUCK2|BUCK4]90 * - DA9062_ID_[BUCK1|BUCK2|BUCK4]
105 * Entry indexes corresponds to register values.91 * Entry indexes corresponds to register values.
106 */92 */
107static const int da9062_buck_a_limits[] = {93static const unsigned int da9062_buck_a_limits[] = {
108 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,94 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,
109 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 200000095 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
110};96};
@@ -114,44 +100,11 @@ static const int da9062_buck_a_limits[] = { · 3 unmodified lines
114 * - DA9062_ID_BUCK3100 * - DA9062_ID_BUCK3
115 * Entry indexes corresponds to register values.101 * Entry indexes corresponds to register values.
116 */102 */
117static const int da9062_buck_b_limits[] = {103static const unsigned int da9062_buck_b_limits[] = {
118 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,104 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
119 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000105 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
120};106};
121 107
122static int da9062_set_current_limit(struct regulator_dev *rdev,
123 int min_ua, int max_ua)
124{
125 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
126 const struct da9062_regulator_info *rinfo = regl->info;
127 int n, tval;
128
129 for (n = rinfo->n_current_limits - 1; n >= 0; n--) {
130 tval = rinfo->current_limits[n];
131 if (tval >= min_ua && tval <= max_ua)
132 return regmap_field_write(regl->ilimit, n);
133 }
134
135 return -EINVAL;
136}
137
138static int da9062_get_current_limit(struct regulator_dev *rdev)
139{
140 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
141 const struct da9062_regulator_info *rinfo = regl->info;
142 unsigned int sel;
143 int ret;
144
145 ret = regmap_field_read(regl->ilimit, &sel);
146 if (ret < 0)
147 return ret;
148
149 if (sel >= rinfo->n_current_limits)
150 sel = rinfo->n_current_limits - 1;
151
152 return rinfo->current_limits[sel];
153}
154
155static int da9062_buck_set_mode(struct regulator_dev *rdev, unsigned mode)108static int da9062_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
156{109{
157 struct da9062_regulator *regl = rdev_get_drvdata(rdev);110 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
@@ -395,8 +348,8 @@ static const struct regulator_ops da9062_buck_ops = { · 237 unmodified lines
395 .get_voltage_sel = regulator_get_voltage_sel_regmap,348 .get_voltage_sel = regulator_get_voltage_sel_regmap,
396 .set_voltage_sel = regulator_set_voltage_sel_regmap,349 .set_voltage_sel = regulator_set_voltage_sel_regmap,
397 .list_voltage = regulator_list_voltage_linear,350 .list_voltage = regulator_list_voltage_linear,
398 .set_current_limit = da9062_set_current_limit,351 .set_current_limit = regulator_set_current_limit_regmap,
399 .get_current_limit = da9062_get_current_limit,352 .get_current_limit = regulator_get_current_limit_regmap,
400 .set_mode = da9062_buck_set_mode,353 .set_mode = da9062_buck_set_mode,
401 .get_mode = da9062_buck_get_mode,354 .get_mode = da9062_buck_get_mode,
402 .get_status = da9062_buck_get_status,355 .get_status = da9062_buck_get_status,
@@ -433,8 +386,10 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = { · 30 unmodified lines
433 .desc.min_uV = (300) * 1000,386 .desc.min_uV = (300) * 1000,
434 .desc.uV_step = (10) * 1000,387 .desc.uV_step = (10) * 1000,
435 .desc.n_voltages = ((1570) - (300))/(10) + 1,388 .desc.n_voltages = ((1570) - (300))/(10) + 1,
436 .current_limits = da9062_buck_a_limits,389 .desc.curr_table = da9062_buck_a_limits,
437 .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),390 .desc.n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
391 .desc.csel_reg = DA9062AA_BUCK_ILIM_C,
392 .desc.csel_mask = DA9062AA_BUCK1_ILIM_MASK,
438 .desc.enable_reg = DA9062AA_BUCK1_CONT,393 .desc.enable_reg = DA9062AA_BUCK1_CONT,
439 .desc.enable_mask = DA9062AA_BUCK1_EN_MASK,394 .desc.enable_mask = DA9062AA_BUCK1_EN_MASK,
440 .desc.vsel_reg = DA9062AA_VBUCK1_A,395 .desc.vsel_reg = DA9062AA_VBUCK1_A,
@@ -457,10 +412,6 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = { · 16 unmodified lines
457 __builtin_ffs((int)DA9062AA_VBUCK1_SEL_MASK) - 1,412 __builtin_ffs((int)DA9062AA_VBUCK1_SEL_MASK) - 1,
458 sizeof(unsigned int) * 8 -413 sizeof(unsigned int) * 8 -
459 __builtin_clz((DA9062AA_VBUCK1_SEL_MASK)) - 1),414 __builtin_clz((DA9062AA_VBUCK1_SEL_MASK)) - 1),
460 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
461 __builtin_ffs((int)DA9062AA_BUCK1_ILIM_MASK) - 1,
462 sizeof(unsigned int) * 8 -
463 __builtin_clz((DA9062AA_BUCK1_ILIM_MASK)) - 1),
464 },415 },
465 {416 {
466 .desc.id = DA9061_ID_BUCK2,417 .desc.id = DA9061_ID_BUCK2,
@@ -471,8 +422,10 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = { · 4 unmodified lines
471 .desc.min_uV = (800) * 1000,422 .desc.min_uV = (800) * 1000,
472 .desc.uV_step = (20) * 1000,423 .desc.uV_step = (20) * 1000,
473 .desc.n_voltages = ((3340) - (800))/(20) + 1,424 .desc.n_voltages = ((3340) - (800))/(20) + 1,
474 .current_limits = da9062_buck_b_limits,425 .desc.curr_table = da9062_buck_b_limits,
475 .n_current_limits = ARRAY_SIZE(da9062_buck_b_limits),426 .desc.n_current_limits = ARRAY_SIZE(da9062_buck_b_limits),
427 .desc.csel_reg = DA9062AA_BUCK_ILIM_A,
428 .desc.csel_mask = DA9062AA_BUCK3_ILIM_MASK,
476 .desc.enable_reg = DA9062AA_BUCK3_CONT,429 .desc.enable_reg = DA9062AA_BUCK3_CONT,
477 .desc.enable_mask = DA9062AA_BUCK3_EN_MASK,430 .desc.enable_mask = DA9062AA_BUCK3_EN_MASK,
478 .desc.vsel_reg = DA9062AA_VBUCK3_A,431 .desc.vsel_reg = DA9062AA_VBUCK3_A,
@@ -495,10 +448,6 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = { · 16 unmodified lines
495 __builtin_ffs((int)DA9062AA_VBUCK3_SEL_MASK) - 1,448 __builtin_ffs((int)DA9062AA_VBUCK3_SEL_MASK) - 1,
496 sizeof(unsigned int) * 8 -449 sizeof(unsigned int) * 8 -
497 __builtin_clz((DA9062AA_VBUCK3_SEL_MASK)) - 1),450 __builtin_clz((DA9062AA_VBUCK3_SEL_MASK)) - 1),
498 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_A,
499 __builtin_ffs((int)DA9062AA_BUCK3_ILIM_MASK) - 1,
500 sizeof(unsigned int) * 8 -
501 __builtin_clz((DA9062AA_BUCK3_ILIM_MASK)) - 1),
502 },451 },
503 {452 {
504 .desc.id = DA9061_ID_BUCK3,453 .desc.id = DA9061_ID_BUCK3,
@@ -509,8 +458,10 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = { · 4 unmodified lines
509 .desc.min_uV = (530) * 1000,458 .desc.min_uV = (530) * 1000,
510 .desc.uV_step = (10) * 1000,459 .desc.uV_step = (10) * 1000,
511 .desc.n_voltages = ((1800) - (530))/(10) + 1,460 .desc.n_voltages = ((1800) - (530))/(10) + 1,
512 .current_limits = da9062_buck_a_limits,461 .desc.curr_table = da9062_buck_a_limits,
513 .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),462 .desc.n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
463 .desc.csel_reg = DA9062AA_BUCK_ILIM_B,
464 .desc.csel_mask = DA9062AA_BUCK4_ILIM_MASK,
514 .desc.enable_reg = DA9062AA_BUCK4_CONT,465 .desc.enable_reg = DA9062AA_BUCK4_CONT,
515 .desc.enable_mask = DA9062AA_BUCK4_EN_MASK,466 .desc.enable_mask = DA9062AA_BUCK4_EN_MASK,
516 .desc.vsel_reg = DA9062AA_VBUCK4_A,467 .desc.vsel_reg = DA9062AA_VBUCK4_A,
@@ -533,10 +484,6 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = { · 16 unmodified lines
533 __builtin_ffs((int)DA9062AA_VBUCK4_SEL_MASK) - 1,484 __builtin_ffs((int)DA9062AA_VBUCK4_SEL_MASK) - 1,
534 sizeof(unsigned int) * 8 -485 sizeof(unsigned int) * 8 -
535 __builtin_clz((DA9062AA_VBUCK4_SEL_MASK)) - 1),486 __builtin_clz((DA9062AA_VBUCK4_SEL_MASK)) - 1),
536 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_B,
537 __builtin_ffs((int)DA9062AA_BUCK4_ILIM_MASK) - 1,
538 sizeof(unsigned int) * 8 -
539 __builtin_clz((DA9062AA_BUCK4_ILIM_MASK)) - 1),
540 },487 },
541 {488 {
542 .desc.id = DA9061_ID_LDO1,489 .desc.id = DA9061_ID_LDO1,
@@ -679,8 +626,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = { · 136 unmodified lines
679 .desc.min_uV = (300) * 1000,626 .desc.min_uV = (300) * 1000,
680 .desc.uV_step = (10) * 1000,627 .desc.uV_step = (10) * 1000,
681 .desc.n_voltages = ((1570) - (300))/(10) + 1,628 .desc.n_voltages = ((1570) - (300))/(10) + 1,
682 .current_limits = da9062_buck_a_limits,629 .desc.curr_table = da9062_buck_a_limits,
683 .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),630 .desc.n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
631 .desc.csel_reg = DA9062AA_BUCK_ILIM_C,
632 .desc.csel_mask = DA9062AA_BUCK1_ILIM_MASK,
684 .desc.enable_reg = DA9062AA_BUCK1_CONT,633 .desc.enable_reg = DA9062AA_BUCK1_CONT,
685 .desc.enable_mask = DA9062AA_BUCK1_EN_MASK,634 .desc.enable_mask = DA9062AA_BUCK1_EN_MASK,
686 .desc.vsel_reg = DA9062AA_VBUCK1_A,635 .desc.vsel_reg = DA9062AA_VBUCK1_A,
@@ -703,10 +652,6 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = { · 16 unmodified lines
703 __builtin_ffs((int)DA9062AA_VBUCK1_SEL_MASK) - 1,652 __builtin_ffs((int)DA9062AA_VBUCK1_SEL_MASK) - 1,
704 sizeof(unsigned int) * 8 -653 sizeof(unsigned int) * 8 -
705 __builtin_clz((DA9062AA_VBUCK1_SEL_MASK)) - 1),654 __builtin_clz((DA9062AA_VBUCK1_SEL_MASK)) - 1),
706 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
707 __builtin_ffs((int)DA9062AA_BUCK1_ILIM_MASK) - 1,
708 sizeof(unsigned int) * 8 -
709 __builtin_clz((DA9062AA_BUCK1_ILIM_MASK)) - 1),
710 },655 },
711 {656 {
712 .desc.id = DA9062_ID_BUCK2,657 .desc.id = DA9062_ID_BUCK2,
@@ -717,8 +662,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = { · 4 unmodified lines
717 .desc.min_uV = (300) * 1000,662 .desc.min_uV = (300) * 1000,
718 .desc.uV_step = (10) * 1000,663 .desc.uV_step = (10) * 1000,
719 .desc.n_voltages = ((1570) - (300))/(10) + 1,664 .desc.n_voltages = ((1570) - (300))/(10) + 1,
720 .current_limits = da9062_buck_a_limits,665 .desc.curr_table = da9062_buck_a_limits,
721 .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),666 .desc.n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
667 .desc.csel_reg = DA9062AA_BUCK_ILIM_C,
668 .desc.csel_mask = DA9062AA_BUCK2_ILIM_MASK,
722 .desc.enable_reg = DA9062AA_BUCK2_CONT,669 .desc.enable_reg = DA9062AA_BUCK2_CONT,
723 .desc.enable_mask = DA9062AA_BUCK2_EN_MASK,670 .desc.enable_mask = DA9062AA_BUCK2_EN_MASK,
724 .desc.vsel_reg = DA9062AA_VBUCK2_A,671 .desc.vsel_reg = DA9062AA_VBUCK2_A,
@@ -741,10 +688,6 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = { · 16 unmodified lines
741 __builtin_ffs((int)DA9062AA_VBUCK2_SEL_MASK) - 1,688 __builtin_ffs((int)DA9062AA_VBUCK2_SEL_MASK) - 1,
742 sizeof(unsigned int) * 8 -689 sizeof(unsigned int) * 8 -
743 __builtin_clz((DA9062AA_VBUCK2_SEL_MASK)) - 1),690 __builtin_clz((DA9062AA_VBUCK2_SEL_MASK)) - 1),
744 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
745 __builtin_ffs((int)DA9062AA_BUCK2_ILIM_MASK) - 1,
746 sizeof(unsigned int) * 8 -
747 __builtin_clz((DA9062AA_BUCK2_ILIM_MASK)) - 1),
748 },691 },
749 {692 {
750 .desc.id = DA9062_ID_BUCK3,693 .desc.id = DA9062_ID_BUCK3,
@@ -755,8 +698,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = { · 4 unmodified lines
755 .desc.min_uV = (800) * 1000,698 .desc.min_uV = (800) * 1000,
756 .desc.uV_step = (20) * 1000,699 .desc.uV_step = (20) * 1000,
757 .desc.n_voltages = ((3340) - (800))/(20) + 1,700 .desc.n_voltages = ((3340) - (800))/(20) + 1,
758 .current_limits = da9062_buck_b_limits,701 .desc.curr_table = da9062_buck_b_limits,
759 .n_current_limits = ARRAY_SIZE(da9062_buck_b_limits),702 .desc.n_current_limits = ARRAY_SIZE(da9062_buck_b_limits),
703 .desc.csel_reg = DA9062AA_BUCK_ILIM_A,
704 .desc.csel_mask = DA9062AA_BUCK3_ILIM_MASK,
760 .desc.enable_reg = DA9062AA_BUCK3_CONT,705 .desc.enable_reg = DA9062AA_BUCK3_CONT,
761 .desc.enable_mask = DA9062AA_BUCK3_EN_MASK,706 .desc.enable_mask = DA9062AA_BUCK3_EN_MASK,
762 .desc.vsel_reg = DA9062AA_VBUCK3_A,707 .desc.vsel_reg = DA9062AA_VBUCK3_A,
@@ -779,10 +724,6 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = { · 16 unmodified lines
779 __builtin_ffs((int)DA9062AA_VBUCK3_SEL_MASK) - 1,724 __builtin_ffs((int)DA9062AA_VBUCK3_SEL_MASK) - 1,
780 sizeof(unsigned int) * 8 -725 sizeof(unsigned int) * 8 -
781 __builtin_clz((DA9062AA_VBUCK3_SEL_MASK)) - 1),726 __builtin_clz((DA9062AA_VBUCK3_SEL_MASK)) - 1),
782 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_A,
783 __builtin_ffs((int)DA9062AA_BUCK3_ILIM_MASK) - 1,
784 sizeof(unsigned int) * 8 -
785 __builtin_clz((DA9062AA_BUCK3_ILIM_MASK)) - 1),
786 },727 },
787 {728 {
788 .desc.id = DA9062_ID_BUCK4,729 .desc.id = DA9062_ID_BUCK4,
@@ -793,8 +734,10 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = { · 4 unmodified lines
793 .desc.min_uV = (530) * 1000,734 .desc.min_uV = (530) * 1000,
794 .desc.uV_step = (10) * 1000,735 .desc.uV_step = (10) * 1000,
795 .desc.n_voltages = ((1800) - (530))/(10) + 1,736 .desc.n_voltages = ((1800) - (530))/(10) + 1,
796 .current_limits = da9062_buck_a_limits,737 .desc.curr_table = da9062_buck_a_limits,
797 .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),738 .desc.n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
739 .desc.csel_reg = DA9062AA_BUCK_ILIM_B,
740 .desc.csel_mask = DA9062AA_BUCK4_ILIM_MASK,
798 .desc.enable_reg = DA9062AA_BUCK4_CONT,741 .desc.enable_reg = DA9062AA_BUCK4_CONT,
799 .desc.enable_mask = DA9062AA_BUCK4_EN_MASK,742 .desc.enable_mask = DA9062AA_BUCK4_EN_MASK,
800 .desc.vsel_reg = DA9062AA_VBUCK4_A,743 .desc.vsel_reg = DA9062AA_VBUCK4_A,
@@ -817,10 +760,6 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = { · 16 unmodified lines
817 __builtin_ffs((int)DA9062AA_VBUCK4_SEL_MASK) - 1,760 __builtin_ffs((int)DA9062AA_VBUCK4_SEL_MASK) - 1,
818 sizeof(unsigned int) * 8 -761 sizeof(unsigned int) * 8 -
819 __builtin_clz((DA9062AA_VBUCK4_SEL_MASK)) - 1),762 __builtin_clz((DA9062AA_VBUCK4_SEL_MASK)) - 1),
820 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_B,
821 __builtin_ffs((int)DA9062AA_BUCK4_ILIM_MASK) - 1,
822 sizeof(unsigned int) * 8 -
823 __builtin_clz((DA9062AA_BUCK4_ILIM_MASK)) - 1),
824 },763 },
825 {764 {
826 .desc.id = DA9062_ID_LDO1,765 .desc.id = DA9062_ID_LDO1,
@@ -974,8 +913,10 @@ static irqreturn_t da9062_ldo_lim_event(int irq, void *data) · 147 unmodified lines
974 continue;913 continue;
975 914
976 if (BIT(regl->info->oc_event.lsb) & bits) {915 if (BIT(regl->info->oc_event.lsb) & bits) {
916 regulator_lock(regl->rdev);
977 regulator_notifier_call_chain(regl->rdev,917 regulator_notifier_call_chain(regl->rdev,
978 REGULATOR_EVENT_OVER_CURRENT, NULL);918 REGULATOR_EVENT_OVER_CURRENT, NULL);
919 regulator_unlock(regl->rdev);
979 handled = IRQ_HANDLED;920 handled = IRQ_HANDLED;
980 }921 }
981 }922 }
@@ -1063,15 +1004,6 @@ static int da9062_regulator_probe(struct platform_device *pdev) · 81 unmodified lines
1063 return PTR_ERR(regl->suspend_sleep);1004 return PTR_ERR(regl->suspend_sleep);
1064 }1005 }
1065 1006
1066 if (regl->info->ilimit.reg) {
1067 regl->ilimit = devm_regmap_field_alloc(
1068 &pdev->dev,
1069 chip->regmap,
1070 regl->info->ilimit);
1071 if (IS_ERR(regl->ilimit))
1072 return PTR_ERR(regl->ilimit);
1073 }
1074
1075 /* Register regulator */1007 /* Register regulator */
1076 memset(&config, 0, sizeof(config));1008 memset(&config, 0, sizeof(config));
1077 config.dev = chip->dev;1009 config.dev = chip->dev;
drivers/regulator/da9063-regulator.c+40−94
@@ -1,18 +1,12 @@
1// SPDX-License-Identifier: GPL-2.0+
2//
3// Regulator driver for DA9063 PMIC series
4//
5// Copyright 2012 Dialog Semiconductors Ltd.
6// Copyright 2013 Philipp Zabel, Pengutronix
7//
8// Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
1 9
2/*
3 * Regulator driver for DA9063 PMIC series
4 *
5 * Copyright 2012 Dialog Semiconductors Ltd.
6 * Copyright 2013 Philipp Zabel, Pengutronix
7 *
8 * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 */
16#include <linux/kernel.h>10#include <linux/kernel.h>
17#include <linux/module.h>11#include <linux/module.h>
18#include <linux/init.h>12#include <linux/init.h>
@@ -38,17 +32,12 @@ · 19 unmodified lines
38struct da9063_regulator_info {32struct da9063_regulator_info {
39 struct regulator_desc desc;33 struct regulator_desc desc;
40 34
41 /* Current limiting */
42 unsigned n_current_limits;
43 const int *current_limits;
44
45 /* DA9063 main register fields */35 /* DA9063 main register fields */
46 struct reg_field mode; /* buck mode of operation */36 struct reg_field mode; /* buck mode of operation */
47 struct reg_field suspend;37 struct reg_field suspend;
48 struct reg_field sleep;38 struct reg_field sleep;
49 struct reg_field suspend_sleep;39 struct reg_field suspend_sleep;
50 unsigned int suspend_vsel_reg;40 unsigned int suspend_vsel_reg;
51 struct reg_field ilimit;
52 41
53 /* DA9063 event detection bit */42 /* DA9063 event detection bit */
54 struct reg_field oc_event;43 struct reg_field oc_event;
@@ -73,15 +62,18 @@ struct da9063_regulator_info { · 18 unmodified lines
73 .suspend_vsel_reg = DA9063_REG_V##regl_name##_B62 .suspend_vsel_reg = DA9063_REG_V##regl_name##_B
74 63
75/* Macros for voltage DC/DC converters (BUCKs) */64/* Macros for voltage DC/DC converters (BUCKs) */
76#define DA9063_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array) \65#define DA9063_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array, \
66 creg, cmask) \
77 .desc.id = chip##_ID_##regl_name, \67 .desc.id = chip##_ID_##regl_name, \
78 .desc.name = __stringify(chip##_##regl_name), \68 .desc.name = __stringify(chip##_##regl_name), \
79 .desc.ops = &da9063_buck_ops, \69 .desc.ops = &da9063_buck_ops, \
80 .desc.min_uV = (min_mV) * 1000, \70 .desc.min_uV = (min_mV) * 1000, \
81 .desc.uV_step = (step_mV) * 1000, \71 .desc.uV_step = (step_mV) * 1000, \
82 .desc.n_voltages = ((max_mV) - (min_mV))/(step_mV) + 1, \72 .desc.n_voltages = ((max_mV) - (min_mV))/(step_mV) + 1, \
83 .current_limits = limits_array, \73 .desc.csel_reg = (creg), \
84 .n_current_limits = ARRAY_SIZE(limits_array)74 .desc.csel_mask = (cmask), \
75 .desc.curr_table = limits_array, \
76 .desc.n_current_limits = ARRAY_SIZE(limits_array)
85 77
86#define DA9063_BUCK_COMMON_FIELDS(regl_name) \78#define DA9063_BUCK_COMMON_FIELDS(regl_name) \
87 .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \79 .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \
@@ -112,7 +104,6 @@ struct da9063_regulator { · 24 unmodified lines
112 struct regmap_field *suspend;104 struct regmap_field *suspend;
113 struct regmap_field *sleep;105 struct regmap_field *sleep;
114 struct regmap_field *suspend_sleep;106 struct regmap_field *suspend_sleep;
115 struct regmap_field *ilimit;
116};107};
117 108
118/* Encapsulates all information for the regulators driver */109/* Encapsulates all information for the regulators driver */
@@ -134,65 +125,32 @@ enum { · 15 unmodified lines
134 125
135/* Current limits array (in uA) for BCORE1, BCORE2, BPRO.126/* Current limits array (in uA) for BCORE1, BCORE2, BPRO.
136 Entry indexes corresponds to register values. */127 Entry indexes corresponds to register values. */
137static const int da9063_buck_a_limits[] = {128static const unsigned int da9063_buck_a_limits[] = {
138 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,129 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,
139 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000130 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
140};131};
141 132
142/* Current limits array (in uA) for BMEM, BIO, BPERI.133/* Current limits array (in uA) for BMEM, BIO, BPERI.
143 Entry indexes corresponds to register values. */134 Entry indexes corresponds to register values. */
144static const int da9063_buck_b_limits[] = {135static const unsigned int da9063_buck_b_limits[] = {
145 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,136 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
146 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000137 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
147};138};
148 139
149/* Current limits array (in uA) for merged BCORE1 and BCORE2.140/* Current limits array (in uA) for merged BCORE1 and BCORE2.
150 Entry indexes corresponds to register values. */141 Entry indexes corresponds to register values. */
151static const int da9063_bcores_merged_limits[] = {142static const unsigned int da9063_bcores_merged_limits[] = {
152 1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,143 1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,
153 2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000144 2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000
154};145};
155 146
156/* Current limits array (in uA) for merged BMEM and BIO.147/* Current limits array (in uA) for merged BMEM and BIO.
157 Entry indexes corresponds to register values. */148 Entry indexes corresponds to register values. */
158static const int da9063_bmem_bio_merged_limits[] = {149static const unsigned int da9063_bmem_bio_merged_limits[] = {
159 3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,150 3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,
160 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000151 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000
161};152};
162 153
163static int da9063_set_current_limit(struct regulator_dev *rdev,
164 int min_uA, int max_uA)
165{
166 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
167 const struct da9063_regulator_info *rinfo = regl->info;
168 int n, tval;
169
170 for (n = rinfo->n_current_limits - 1; n >= 0; n--) {
171 tval = rinfo->current_limits[n];
172 if (tval >= min_uA && tval <= max_uA)
173 return regmap_field_write(regl->ilimit, n);
174 }
175
176 return -EINVAL;
177}
178
179static int da9063_get_current_limit(struct regulator_dev *rdev)
180{
181 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
182 const struct da9063_regulator_info *rinfo = regl->info;
183 unsigned int sel;
184 int ret;
185
186 ret = regmap_field_read(regl->ilimit, &sel);
187 if (ret < 0)
188 return ret;
189
190 if (sel >= rinfo->n_current_limits)
191 sel = rinfo->n_current_limits - 1;
192
193 return rinfo->current_limits[sel];
194}
195
196static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned mode)154static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
197{155{
198 struct da9063_regulator *regl = rdev_get_drvdata(rdev);156 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
@@ -434,8 +392,8 @@ static const struct regulator_ops da9063_buck_ops = { · 235 unmodified lines
434 .get_voltage_sel = regulator_get_voltage_sel_regmap,392 .get_voltage_sel = regulator_get_voltage_sel_regmap,
435 .set_voltage_sel = regulator_set_voltage_sel_regmap,393 .set_voltage_sel = regulator_set_voltage_sel_regmap,
436 .list_voltage = regulator_list_voltage_linear,394 .list_voltage = regulator_list_voltage_linear,
437 .set_current_limit = da9063_set_current_limit,395 .set_current_limit = regulator_set_current_limit_regmap,
438 .get_current_limit = da9063_get_current_limit,396 .get_current_limit = regulator_get_current_limit_regmap,
439 .set_mode = da9063_buck_set_mode,397 .set_mode = da9063_buck_set_mode,
440 .get_mode = da9063_buck_get_mode,398 .get_mode = da9063_buck_get_mode,
441 .get_status = da9063_buck_get_status,399 .get_status = da9063_buck_get_status,
@@ -465,69 +423,61 @@ static const struct regulator_ops da9063_ldo_ops = { · 23 unmodified lines
465static const struct da9063_regulator_info da9063_regulator_info[] = {423static const struct da9063_regulator_info da9063_regulator_info[] = {
466 {424 {
467 DA9063_BUCK(DA9063, BCORE1, 300, 10, 1570,425 DA9063_BUCK(DA9063, BCORE1, 300, 10, 1570,
468 da9063_buck_a_limits),426 da9063_buck_a_limits,
427 DA9063_REG_BUCK_ILIM_C, DA9063_BCORE1_ILIM_MASK),
469 DA9063_BUCK_COMMON_FIELDS(BCORE1),428 DA9063_BUCK_COMMON_FIELDS(BCORE1),
470 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),429 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),
471 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
472 DA9063_BCORE1_ILIM_MASK),
473 },430 },
474 {431 {
475 DA9063_BUCK(DA9063, BCORE2, 300, 10, 1570,432 DA9063_BUCK(DA9063, BCORE2, 300, 10, 1570,
476 da9063_buck_a_limits),433 da9063_buck_a_limits,
434 DA9063_REG_BUCK_ILIM_C, DA9063_BCORE2_ILIM_MASK),
477 DA9063_BUCK_COMMON_FIELDS(BCORE2),435 DA9063_BUCK_COMMON_FIELDS(BCORE2),
478 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE2_SEL),436 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE2_SEL),
479 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
480 DA9063_BCORE2_ILIM_MASK),
481 },437 },
482 {438 {
483 DA9063_BUCK(DA9063, BPRO, 530, 10, 1800,439 DA9063_BUCK(DA9063, BPRO, 530, 10, 1800,
484 da9063_buck_a_limits),440 da9063_buck_a_limits,
441 DA9063_REG_BUCK_ILIM_B, DA9063_BPRO_ILIM_MASK),
485 DA9063_BUCK_COMMON_FIELDS(BPRO),442 DA9063_BUCK_COMMON_FIELDS(BPRO),
486 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPRO_SEL),443 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPRO_SEL),
487 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_B,
488 DA9063_BPRO_ILIM_MASK),
489 },444 },
490 {445 {
491 DA9063_BUCK(DA9063, BMEM, 800, 20, 3340,446 DA9063_BUCK(DA9063, BMEM, 800, 20, 3340,
492 da9063_buck_b_limits),447 da9063_buck_b_limits,
448 DA9063_REG_BUCK_ILIM_A, DA9063_BMEM_ILIM_MASK),
493 DA9063_BUCK_COMMON_FIELDS(BMEM),449 DA9063_BUCK_COMMON_FIELDS(BMEM),
494 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),450 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),
495 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
496 DA9063_BMEM_ILIM_MASK),
497 },451 },
498 {452 {
499 DA9063_BUCK(DA9063, BIO, 800, 20, 3340,453 DA9063_BUCK(DA9063, BIO, 800, 20, 3340,
500 da9063_buck_b_limits),454 da9063_buck_b_limits,
455 DA9063_REG_BUCK_ILIM_A, DA9063_BIO_ILIM_MASK),
501 DA9063_BUCK_COMMON_FIELDS(BIO),456 DA9063_BUCK_COMMON_FIELDS(BIO),
502 .suspend = BFIELD(DA9063_REG_DVC_2, DA9063_VBIO_SEL),457 .suspend = BFIELD(DA9063_REG_DVC_2, DA9063_VBIO_SEL),
503 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
504 DA9063_BIO_ILIM_MASK),
505 },458 },
506 {459 {
507 DA9063_BUCK(DA9063, BPERI, 800, 20, 3340,460 DA9063_BUCK(DA9063, BPERI, 800, 20, 3340,
508 da9063_buck_b_limits),461 da9063_buck_b_limits,
462 DA9063_REG_BUCK_ILIM_B, DA9063_BPERI_ILIM_MASK),
509 DA9063_BUCK_COMMON_FIELDS(BPERI),463 DA9063_BUCK_COMMON_FIELDS(BPERI),
510 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPERI_SEL),464 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPERI_SEL),
511 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_B,
512 DA9063_BPERI_ILIM_MASK),
513 },465 },
514 {466 {
515 DA9063_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570,467 DA9063_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570,
516 da9063_bcores_merged_limits),468 da9063_bcores_merged_limits,
469 DA9063_REG_BUCK_ILIM_C, DA9063_BCORE1_ILIM_MASK),
517 /* BCORES_MERGED uses the same register fields as BCORE1 */470 /* BCORES_MERGED uses the same register fields as BCORE1 */
518 DA9063_BUCK_COMMON_FIELDS(BCORE1),471 DA9063_BUCK_COMMON_FIELDS(BCORE1),
519 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),472 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),
520 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
521 DA9063_BCORE1_ILIM_MASK),
522 },473 },
523 {474 {
524 DA9063_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340,475 DA9063_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340,
525 da9063_bmem_bio_merged_limits),476 da9063_bmem_bio_merged_limits,
477 DA9063_REG_BUCK_ILIM_A, DA9063_BMEM_ILIM_MASK),
526 /* BMEM_BIO_MERGED uses the same register fields as BMEM */478 /* BMEM_BIO_MERGED uses the same register fields as BMEM */
527 DA9063_BUCK_COMMON_FIELDS(BMEM),479 DA9063_BUCK_COMMON_FIELDS(BMEM),
528 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),480 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),
529 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
530 DA9063_BMEM_ILIM_MASK),
531 },481 },
532 {482 {
533 DA9063_LDO(DA9063, LDO3, 900, 20, 3440),483 DA9063_LDO(DA9063, LDO3, 900, 20, 3440),
@@ -615,9 +565,12 @@ static irqreturn_t da9063_ldo_lim_event(int irq, void *data) · 81 unmodified lines
615 if (regl->info->oc_event.reg != DA9063_REG_STATUS_D)565 if (regl->info->oc_event.reg != DA9063_REG_STATUS_D)
616 continue;566 continue;
617 567
618 if (BIT(regl->info->oc_event.lsb) & bits)568 if (BIT(regl->info->oc_event.lsb) & bits) {
569 regulator_lock(regl->rdev);
619 regulator_notifier_call_chain(regl->rdev,570 regulator_notifier_call_chain(regl->rdev,
620 REGULATOR_EVENT_OVER_CURRENT, NULL);571 REGULATOR_EVENT_OVER_CURRENT, NULL);
572 regulator_unlock(regl->rdev);
573 }
621 }574 }
622 575
623 return IRQ_HANDLED;576 return IRQ_HANDLED;
@@ -861,13 +814,6 @@ static int da9063_regulator_probe(struct platform_device *pdev) · 237 unmodified lines
861 return PTR_ERR(regl->suspend_sleep);814 return PTR_ERR(regl->suspend_sleep);
862 }815 }
863 816
864 if (regl->info->ilimit.reg) {
865 regl->ilimit = devm_regmap_field_alloc(&pdev->dev,
866 da9063->regmap, regl->info->ilimit);
867 if (IS_ERR(regl->ilimit))
868 return PTR_ERR(regl->ilimit);
869 }
870
871 /* Register regulator */817 /* Register regulator */
872 memset(&config, 0, sizeof(config));818 memset(&config, 0, sizeof(config));
873 config.dev = &pdev->dev;819 config.dev = &pdev->dev;
drivers/regulator/da9210-regulator.c+4−19
@@ -1,22 +1,7 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * da9210-regulator.c - Regulator device driver for DA92102//
3 * Copyright (C) 2013 Dialog Semiconductor Ltd.3// da9210-regulator.c - Regulator device driver for DA9210
4 *4// Copyright (C) 2013 Dialog Semiconductor Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20 5
21#include <linux/err.h>6#include <linux/err.h>
22#include <linux/i2c.h>7#include <linux/i2c.h>
drivers/regulator/da9210-regulator.h+1−16
@@ -1,22 +1,7 @@
1 1/* SPDX-License-Identifier: GPL-2.0+ */
2/*2/*
3 * da9210-regulator.h - Regulator definitions for DA92103 * da9210-regulator.h - Regulator definitions for DA9210
4 * Copyright (C) 2013 Dialog Semiconductor Ltd.4 * Copyright (C) 2013 Dialog Semiconductor Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */5 */
21 6
22#ifndef __DA9210_REGISTERS_H__7#ifndef __DA9210_REGISTERS_H__
drivers/regulator/da9211-regulator.c+9−15
@@ -1,18 +1,8 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * da9211-regulator.c - Regulator device driver for DA9211/DA92122//
3 * /DA9213/DA9223/DA9214/DA9224/DA9215/DA92253// da9211-regulator.c - Regulator device driver for DA9211/DA9212
4 * Copyright (C) 2015 Dialog Semiconductor Ltd.4// /DA9213/DA9223/DA9214/DA9224/DA9215/DA9225
5 *5// Copyright (C) 2015 Dialog Semiconductor Ltd.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 */
16 6
17#include <linux/err.h>7#include <linux/err.h>
18#include <linux/i2c.h>8#include <linux/i2c.h>
@@ -322,8 +312,10 @@ static irqreturn_t da9211_irq_handler(int irq, void *data) · 303 unmodified lines
322 goto error_i2c;312 goto error_i2c;
323 313
324 if (reg_val & DA9211_E_OV_CURR_A) {314 if (reg_val & DA9211_E_OV_CURR_A) {
315 regulator_lock(chip->rdev[0]);
325 regulator_notifier_call_chain(chip->rdev[0],316 regulator_notifier_call_chain(chip->rdev[0],
326 REGULATOR_EVENT_OVER_CURRENT, NULL);317 REGULATOR_EVENT_OVER_CURRENT, NULL);
318 regulator_unlock(chip->rdev[0]);
327 319
328 err = regmap_write(chip->regmap, DA9211_REG_EVENT_B,320 err = regmap_write(chip->regmap, DA9211_REG_EVENT_B,
329 DA9211_E_OV_CURR_A);321 DA9211_E_OV_CURR_A);
@@ -334,8 +326,10 @@ static irqreturn_t da9211_irq_handler(int irq, void *data) · 4 unmodified lines
334 }326 }
335 327
336 if (reg_val & DA9211_E_OV_CURR_B) {328 if (reg_val & DA9211_E_OV_CURR_B) {
329 regulator_lock(chip->rdev[1]);
337 regulator_notifier_call_chain(chip->rdev[1],330 regulator_notifier_call_chain(chip->rdev[1],
338 REGULATOR_EVENT_OVER_CURRENT, NULL);331 REGULATOR_EVENT_OVER_CURRENT, NULL);
332 regulator_unlock(chip->rdev[1]);
339 333
340 err = regmap_write(chip->regmap, DA9211_REG_EVENT_B,334 err = regmap_write(chip->regmap, DA9211_REG_EVENT_B,
341 DA9211_E_OV_CURR_B);335 DA9211_E_OV_CURR_B);
drivers/regulator/da9211-regulator.h+1−10
@@ -1,17 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/*2/*
2 * da9211-regulator.h - Regulator definitions for DA9211/DA92123 * da9211-regulator.h - Regulator definitions for DA9211/DA9212
3 * /DA9213/DA9223/DA9214/DA9224/DA9215/DA92254 * /DA9213/DA9223/DA9214/DA9224/DA9215/DA9225
4 * Copyright (C) 2015 Dialog Semiconductor Ltd.5 * Copyright (C) 2015 Dialog Semiconductor Ltd.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */6 */
16 7
17#ifndef __DA9211_REGISTERS_H__8#ifndef __DA9211_REGISTERS_H__
drivers/regulator/db8500-prcmu.c+44−99
@@ -75,7 +75,7 @@ static int db8500_regulator_is_enabled(struct regulator_dev *rdev) · 74 unmodified lines
75}75}
76 76
77/* db8500 regulator operations */77/* db8500 regulator operations */
78static struct regulator_ops db8500_regulator_ops = {78static const struct regulator_ops db8500_regulator_ops = {
79 .enable = db8500_regulator_enable,79 .enable = db8500_regulator_enable,
80 .disable = db8500_regulator_disable,80 .disable = db8500_regulator_disable,
81 .is_enabled = db8500_regulator_is_enabled,81 .is_enabled = db8500_regulator_is_enabled,
@@ -200,7 +200,7 @@ static int db8500_regulator_switch_is_enabled(struct regulator_dev *rdev) · 118 unmodified lines
200 return info->is_enabled;200 return info->is_enabled;
201}201}
202 202
203static struct regulator_ops db8500_regulator_switch_ops = {203static const struct regulator_ops db8500_regulator_switch_ops = {
204 .enable = db8500_regulator_switch_enable,204 .enable = db8500_regulator_switch_enable,
205 .disable = db8500_regulator_switch_disable,205 .disable = db8500_regulator_switch_disable,
206 .is_enabled = db8500_regulator_switch_is_enabled,206 .is_enabled = db8500_regulator_switch_is_enabled,
@@ -214,6 +214,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 7 unmodified lines
214 [DB8500_REGULATOR_VAPE] = {214 [DB8500_REGULATOR_VAPE] = {
215 .desc = {215 .desc = {
216 .name = "db8500-vape",216 .name = "db8500-vape",
217 .of_match = of_match_ptr("db8500_vape"),
217 .id = DB8500_REGULATOR_VAPE,218 .id = DB8500_REGULATOR_VAPE,
218 .ops = &db8500_regulator_ops,219 .ops = &db8500_regulator_ops,
219 .type = REGULATOR_VOLTAGE,220 .type = REGULATOR_VOLTAGE,
@@ -223,6 +224,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 3 unmodified lines
223 [DB8500_REGULATOR_VARM] = {224 [DB8500_REGULATOR_VARM] = {
224 .desc = {225 .desc = {
225 .name = "db8500-varm",226 .name = "db8500-varm",
227 .of_match = of_match_ptr("db8500_varm"),
226 .id = DB8500_REGULATOR_VARM,228 .id = DB8500_REGULATOR_VARM,
227 .ops = &db8500_regulator_ops,229 .ops = &db8500_regulator_ops,
228 .type = REGULATOR_VOLTAGE,230 .type = REGULATOR_VOLTAGE,
@@ -232,6 +234,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 3 unmodified lines
232 [DB8500_REGULATOR_VMODEM] = {234 [DB8500_REGULATOR_VMODEM] = {
233 .desc = {235 .desc = {
234 .name = "db8500-vmodem",236 .name = "db8500-vmodem",
237 .of_match = of_match_ptr("db8500_vmodem"),
235 .id = DB8500_REGULATOR_VMODEM,238 .id = DB8500_REGULATOR_VMODEM,
236 .ops = &db8500_regulator_ops,239 .ops = &db8500_regulator_ops,
237 .type = REGULATOR_VOLTAGE,240 .type = REGULATOR_VOLTAGE,
@@ -241,6 +244,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 3 unmodified lines
241 [DB8500_REGULATOR_VPLL] = {244 [DB8500_REGULATOR_VPLL] = {
242 .desc = {245 .desc = {
243 .name = "db8500-vpll",246 .name = "db8500-vpll",
247 .of_match = of_match_ptr("db8500_vpll"),
244 .id = DB8500_REGULATOR_VPLL,248 .id = DB8500_REGULATOR_VPLL,
245 .ops = &db8500_regulator_ops,249 .ops = &db8500_regulator_ops,
246 .type = REGULATOR_VOLTAGE,250 .type = REGULATOR_VOLTAGE,
@@ -250,6 +254,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 3 unmodified lines
250 [DB8500_REGULATOR_VSMPS1] = {254 [DB8500_REGULATOR_VSMPS1] = {
251 .desc = {255 .desc = {
252 .name = "db8500-vsmps1",256 .name = "db8500-vsmps1",
257 .of_match = of_match_ptr("db8500_vsmps1"),
253 .id = DB8500_REGULATOR_VSMPS1,258 .id = DB8500_REGULATOR_VSMPS1,
254 .ops = &db8500_regulator_ops,259 .ops = &db8500_regulator_ops,
255 .type = REGULATOR_VOLTAGE,260 .type = REGULATOR_VOLTAGE,
@@ -259,6 +264,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 3 unmodified lines
259 [DB8500_REGULATOR_VSMPS2] = {264 [DB8500_REGULATOR_VSMPS2] = {
260 .desc = {265 .desc = {
261 .name = "db8500-vsmps2",266 .name = "db8500-vsmps2",
267 .of_match = of_match_ptr("db8500_vsmps2"),
262 .id = DB8500_REGULATOR_VSMPS2,268 .id = DB8500_REGULATOR_VSMPS2,
263 .ops = &db8500_regulator_ops,269 .ops = &db8500_regulator_ops,
264 .type = REGULATOR_VOLTAGE,270 .type = REGULATOR_VOLTAGE,
@@ -271,6 +277,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 6 unmodified lines
271 [DB8500_REGULATOR_VSMPS3] = {277 [DB8500_REGULATOR_VSMPS3] = {
272 .desc = {278 .desc = {
273 .name = "db8500-vsmps3",279 .name = "db8500-vsmps3",
280 .of_match = of_match_ptr("db8500_vsmps3"),
274 .id = DB8500_REGULATOR_VSMPS3,281 .id = DB8500_REGULATOR_VSMPS3,
275 .ops = &db8500_regulator_ops,282 .ops = &db8500_regulator_ops,
276 .type = REGULATOR_VOLTAGE,283 .type = REGULATOR_VOLTAGE,
@@ -280,6 +287,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 3 unmodified lines
280 [DB8500_REGULATOR_VRF1] = {287 [DB8500_REGULATOR_VRF1] = {
281 .desc = {288 .desc = {
282 .name = "db8500-vrf1",289 .name = "db8500-vrf1",
290 .of_match = of_match_ptr("db8500_vrf1"),
283 .id = DB8500_REGULATOR_VRF1,291 .id = DB8500_REGULATOR_VRF1,
284 .ops = &db8500_regulator_ops,292 .ops = &db8500_regulator_ops,
285 .type = REGULATOR_VOLTAGE,293 .type = REGULATOR_VOLTAGE,
@@ -289,6 +297,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 3 unmodified lines
289 [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {297 [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {
290 .desc = {298 .desc = {
291 .name = "db8500-sva-mmdsp",299 .name = "db8500-sva-mmdsp",
300 .of_match = of_match_ptr("db8500_sva_mmdsp"),
292 .id = DB8500_REGULATOR_SWITCH_SVAMMDSP,301 .id = DB8500_REGULATOR_SWITCH_SVAMMDSP,
293 .ops = &db8500_regulator_switch_ops,302 .ops = &db8500_regulator_switch_ops,
294 .type = REGULATOR_VOLTAGE,303 .type = REGULATOR_VOLTAGE,
@@ -299,6 +308,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 4 unmodified lines
299 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {308 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
300 .desc = {309 .desc = {
301 .name = "db8500-sva-mmdsp-ret",310 .name = "db8500-sva-mmdsp-ret",
311 .of_match = of_match_ptr("db8500_sva_mmdsp_ret"),
302 .id = DB8500_REGULATOR_SWITCH_SVAMMDSPRET,312 .id = DB8500_REGULATOR_SWITCH_SVAMMDSPRET,
303 .ops = &db8500_regulator_switch_ops,313 .ops = &db8500_regulator_switch_ops,
304 .type = REGULATOR_VOLTAGE,314 .type = REGULATOR_VOLTAGE,
@@ -310,6 +320,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 5 unmodified lines
310 [DB8500_REGULATOR_SWITCH_SVAPIPE] = {320 [DB8500_REGULATOR_SWITCH_SVAPIPE] = {
311 .desc = {321 .desc = {
312 .name = "db8500-sva-pipe",322 .name = "db8500-sva-pipe",
323 .of_match = of_match_ptr("db8500_sva_pipe"),
313 .id = DB8500_REGULATOR_SWITCH_SVAPIPE,324 .id = DB8500_REGULATOR_SWITCH_SVAPIPE,
314 .ops = &db8500_regulator_switch_ops,325 .ops = &db8500_regulator_switch_ops,
315 .type = REGULATOR_VOLTAGE,326 .type = REGULATOR_VOLTAGE,
@@ -320,6 +331,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 4 unmodified lines
320 [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {331 [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
321 .desc = {332 .desc = {
322 .name = "db8500-sia-mmdsp",333 .name = "db8500-sia-mmdsp",
334 .of_match = of_match_ptr("db8500_sia_mmdsp"),
323 .id = DB8500_REGULATOR_SWITCH_SIAMMDSP,335 .id = DB8500_REGULATOR_SWITCH_SIAMMDSP,
324 .ops = &db8500_regulator_switch_ops,336 .ops = &db8500_regulator_switch_ops,
325 .type = REGULATOR_VOLTAGE,337 .type = REGULATOR_VOLTAGE,
@@ -330,6 +342,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 4 unmodified lines
330 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {342 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
331 .desc = {343 .desc = {
332 .name = "db8500-sia-mmdsp-ret",344 .name = "db8500-sia-mmdsp-ret",
345 .of_match = of_match_ptr("db8500_sia_mmdsp_ret"),
333 .id = DB8500_REGULATOR_SWITCH_SIAMMDSPRET,346 .id = DB8500_REGULATOR_SWITCH_SIAMMDSPRET,
334 .ops = &db8500_regulator_switch_ops,347 .ops = &db8500_regulator_switch_ops,
335 .type = REGULATOR_VOLTAGE,348 .type = REGULATOR_VOLTAGE,
@@ -341,6 +354,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 5 unmodified lines
341 [DB8500_REGULATOR_SWITCH_SIAPIPE] = {354 [DB8500_REGULATOR_SWITCH_SIAPIPE] = {
342 .desc = {355 .desc = {
343 .name = "db8500-sia-pipe",356 .name = "db8500-sia-pipe",
357 .of_match = of_match_ptr("db8500_sia_pipe"),
344 .id = DB8500_REGULATOR_SWITCH_SIAPIPE,358 .id = DB8500_REGULATOR_SWITCH_SIAPIPE,
345 .ops = &db8500_regulator_switch_ops,359 .ops = &db8500_regulator_switch_ops,
346 .type = REGULATOR_VOLTAGE,360 .type = REGULATOR_VOLTAGE,
@@ -351,6 +365,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 4 unmodified lines
351 [DB8500_REGULATOR_SWITCH_SGA] = {365 [DB8500_REGULATOR_SWITCH_SGA] = {
352 .desc = {366 .desc = {
353 .name = "db8500-sga",367 .name = "db8500-sga",
368 .of_match = of_match_ptr("db8500_sga"),
354 .id = DB8500_REGULATOR_SWITCH_SGA,369 .id = DB8500_REGULATOR_SWITCH_SGA,
355 .ops = &db8500_regulator_switch_ops,370 .ops = &db8500_regulator_switch_ops,
356 .type = REGULATOR_VOLTAGE,371 .type = REGULATOR_VOLTAGE,
@@ -361,6 +376,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 4 unmodified lines
361 [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {376 [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
362 .desc = {377 .desc = {
363 .name = "db8500-b2r2-mcde",378 .name = "db8500-b2r2-mcde",
379 .of_match = of_match_ptr("db8500_b2r2_mcde"),
364 .id = DB8500_REGULATOR_SWITCH_B2R2_MCDE,380 .id = DB8500_REGULATOR_SWITCH_B2R2_MCDE,
365 .ops = &db8500_regulator_switch_ops,381 .ops = &db8500_regulator_switch_ops,
366 .type = REGULATOR_VOLTAGE,382 .type = REGULATOR_VOLTAGE,
@@ -371,6 +387,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 4 unmodified lines
371 [DB8500_REGULATOR_SWITCH_ESRAM12] = {387 [DB8500_REGULATOR_SWITCH_ESRAM12] = {
372 .desc = {388 .desc = {
373 .name = "db8500-esram12",389 .name = "db8500-esram12",
390 .of_match = of_match_ptr("db8500_esram12"),
374 .id = DB8500_REGULATOR_SWITCH_ESRAM12,391 .id = DB8500_REGULATOR_SWITCH_ESRAM12,
375 .ops = &db8500_regulator_switch_ops,392 .ops = &db8500_regulator_switch_ops,
376 .type = REGULATOR_VOLTAGE,393 .type = REGULATOR_VOLTAGE,
@@ -382,6 +399,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 5 unmodified lines
382 [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {399 [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
383 .desc = {400 .desc = {
384 .name = "db8500-esram12-ret",401 .name = "db8500-esram12-ret",
402 .of_match = of_match_ptr("db8500_esram12_ret"),
385 .id = DB8500_REGULATOR_SWITCH_ESRAM12RET,403 .id = DB8500_REGULATOR_SWITCH_ESRAM12RET,
386 .ops = &db8500_regulator_switch_ops,404 .ops = &db8500_regulator_switch_ops,
387 .type = REGULATOR_VOLTAGE,405 .type = REGULATOR_VOLTAGE,
@@ -393,6 +411,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 5 unmodified lines
393 [DB8500_REGULATOR_SWITCH_ESRAM34] = {411 [DB8500_REGULATOR_SWITCH_ESRAM34] = {
394 .desc = {412 .desc = {
395 .name = "db8500-esram34",413 .name = "db8500-esram34",
414 .of_match = of_match_ptr("db8500_esram34"),
396 .id = DB8500_REGULATOR_SWITCH_ESRAM34,415 .id = DB8500_REGULATOR_SWITCH_ESRAM34,
397 .ops = &db8500_regulator_switch_ops,416 .ops = &db8500_regulator_switch_ops,
398 .type = REGULATOR_VOLTAGE,417 .type = REGULATOR_VOLTAGE,
@@ -404,6 +423,7 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 5 unmodified lines
404 [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {423 [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
405 .desc = {424 .desc = {
406 .name = "db8500-esram34-ret",425 .name = "db8500-esram34-ret",
426 .of_match = of_match_ptr("db8500_esram34_ret"),
407 .id = DB8500_REGULATOR_SWITCH_ESRAM34RET,427 .id = DB8500_REGULATOR_SWITCH_ESRAM34RET,
408 .ops = &db8500_regulator_switch_ops,428 .ops = &db8500_regulator_switch_ops,
409 .type = REGULATOR_VOLTAGE,429 .type = REGULATOR_VOLTAGE,
@@ -414,113 +434,38 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { · 4 unmodified lines
414 },434 },
415};435};
416 436
417static int db8500_regulator_register(struct platform_device *pdev,437static int db8500_regulator_probe(struct platform_device *pdev)
418 struct regulator_init_data *init_data,
419 int id,
420 struct device_node *np)
421{438{
439 struct regulator_init_data *db8500_init_data;
422 struct dbx500_regulator_info *info;440 struct dbx500_regulator_info *info;
423 struct regulator_config config = { };441 struct regulator_config config = { };
424 int err;442 struct regulator_dev *rdev;
425 443 int err, i;
426 /* assign per-regulator data */
427 info = &dbx500_regulator_info[id];
428 info->dev = &pdev->dev;
429
430 config.dev = &pdev->dev;
431 config.init_data = init_data;
432 config.driver_data = info;
433 config.of_node = np;
434
435 /* register with the regulator framework */
436 info->rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
437 if (IS_ERR(info->rdev)) {
438 err = PTR_ERR(info->rdev);
439 dev_err(&pdev->dev, "failed to register %s: err %i\n",
440 info->desc.name, err);
441 return err;
442 }
443
444 dev_dbg(rdev_get_dev(info->rdev),
445 "regulator-%s-probed\n", info->desc.name);
446 444
447 return 0;445 db8500_init_data = dev_get_platdata(&pdev->dev);
448}
449
450static struct of_regulator_match db8500_regulator_matches[] = {
451 { .name = "db8500_vape", .driver_data = (void *) DB8500_REGULATOR_VAPE, },
452 { .name = "db8500_varm", .driver_data = (void *) DB8500_REGULATOR_VARM, },
453 { .name = "db8500_vmodem", .driver_data = (void *) DB8500_REGULATOR_VMODEM, },
454 { .name = "db8500_vpll", .driver_data = (void *) DB8500_REGULATOR_VPLL, },
455 { .name = "db8500_vsmps1", .driver_data = (void *) DB8500_REGULATOR_VSMPS1, },
456 { .name = "db8500_vsmps2", .driver_data = (void *) DB8500_REGULATOR_VSMPS2, },
457 { .name = "db8500_vsmps3", .driver_data = (void *) DB8500_REGULATOR_VSMPS3, },
458 { .name = "db8500_vrf1", .driver_data = (void *) DB8500_REGULATOR_VRF1, },
459 { .name = "db8500_sva_mmdsp", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAMMDSP, },
460 { .name = "db8500_sva_mmdsp_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAMMDSPRET, },
461 { .name = "db8500_sva_pipe", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAPIPE, },
462 { .name = "db8500_sia_mmdsp", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAMMDSP, },
463 { .name = "db8500_sia_mmdsp_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAMMDSPRET, },
464 { .name = "db8500_sia_pipe", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAPIPE, },
465 { .name = "db8500_sga", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SGA, },
466 { .name = "db8500_b2r2_mcde", .driver_data = (void *) DB8500_REGULATOR_SWITCH_B2R2_MCDE, },
467 { .name = "db8500_esram12", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM12, },
468 { .name = "db8500_esram12_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM12RET, },
469 { .name = "db8500_esram34", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM34, },
470 { .name = "db8500_esram34_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM34RET, },
471};
472
473static int
474db8500_regulator_of_probe(struct platform_device *pdev,
475 struct device_node *np)
476{
477 int i, err;
478 446
479 for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {447 for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
480 err = db8500_regulator_register(448 /* assign per-regulator data */
481 pdev, db8500_regulator_matches[i].init_data,449 info = &dbx500_regulator_info[i];
482 i, db8500_regulator_matches[i].of_node);450
483 if (err)451 config.driver_data = info;
452 config.dev = &pdev->dev;
453 if (db8500_init_data)
454 config.init_data = &db8500_init_data[i];
455
456 rdev = devm_regulator_register(&pdev->dev, &info->desc,
457 &config);
458 if (IS_ERR(rdev)) {
459 err = PTR_ERR(rdev);
460 dev_err(&pdev->dev, "failed to register %s: err %i\n",
461 info->desc.name, err);
484 return err;462 return err;
485 }
486
487 return 0;
488}
489
490static int db8500_regulator_probe(struct platform_device *pdev)
491{
492 struct regulator_init_data *db8500_init_data =
493 dev_get_platdata(&pdev->dev);
494 struct device_node *np = pdev->dev.of_node;
495 int i, err;
496
497 /* register all regulators */
498 if (np) {
499 err = of_regulator_match(&pdev->dev, np,
500 db8500_regulator_matches,
501 ARRAY_SIZE(db8500_regulator_matches));
502 if (err < 0) {
503 dev_err(&pdev->dev,
504 "Error parsing regulator init data: %d\n", err);
505 return err;
506 }
507
508 err = db8500_regulator_of_probe(pdev, np);
509 if (err)
510 return err;
511 } else {
512 for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
513 err = db8500_regulator_register(pdev,
514 &db8500_init_data[i],
515 i, NULL);
516 if (err)
517 return err;
518 }463 }
464 dev_dbg(&pdev->dev, "regulator-%s-probed\n", info->desc.name);
519 }465 }
520 466
521 err = ux500_regulator_debug_init(pdev,467 ux500_regulator_debug_init(pdev, dbx500_regulator_info,
522 dbx500_regulator_info,468 ARRAY_SIZE(dbx500_regulator_info));
523 ARRAY_SIZE(dbx500_regulator_info));
524 return 0;469 return 0;
525}470}
526 471
drivers/regulator/dbx500-prcmu.h+0−4
@@ -15,18 +15,14 @@ · 14 unmodified lines
15 15
16/**16/**
17 * struct dbx500_regulator_info - dbx500 regulator information17 * struct dbx500_regulator_info - dbx500 regulator information
18 * @dev: device pointer
19 * @desc: regulator description18 * @desc: regulator description
20 * @rdev: regulator device pointer
21 * @is_enabled: status of the regulator19 * @is_enabled: status of the regulator
22 * @epod_id: id for EPOD (power domain)20 * @epod_id: id for EPOD (power domain)
23 * @is_ramret: RAM retention switch for EPOD (power domain)21 * @is_ramret: RAM retention switch for EPOD (power domain)
24 *22 *
25 */23 */
26struct dbx500_regulator_info {24struct dbx500_regulator_info {
27 struct device *dev;
28 struct regulator_desc desc;25 struct regulator_desc desc;
29 struct regulator_dev *rdev;
30 bool is_enabled;26 bool is_enabled;
31 u16 epod_id;27 u16 epod_id;
32 bool is_ramret;28 bool is_ramret;
drivers/regulator/fan53555.c+27−33
@@ -1,17 +1,13 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * FAN53555 Fairchild Digitally Programmable TinyBuck Regulator Driver.2//
3 *3// FAN53555 Fairchild Digitally Programmable TinyBuck Regulator Driver.
4 * Supported Part Numbers:4//
5 * FAN53555UC00X/01X/03X/04X/05X5// Supported Part Numbers:
6 *6// FAN53555UC00X/01X/03X/04X/05X
7 * Copyright (c) 2012 Marvell Technology Ltd.7//
8 * Yunfan Zhang <yfzhang@marvell.com>8// Copyright (c) 2012 Marvell Technology Ltd.
9 *9// Yunfan Zhang <yfzhang@marvell.com>
10 * This package is free software; you can redistribute it and/or modify10
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15#include <linux/module.h>11#include <linux/module.h>
16#include <linux/param.h>12#include <linux/param.h>
17#include <linux/err.h>13#include <linux/err.h>
@@ -91,10 +87,8 @@ enum { · 73 unmodified lines
91 87
92struct fan53555_device_info {88struct fan53555_device_info {
93 enum fan53555_vendor vendor;89 enum fan53555_vendor vendor;
94 struct regmap *regmap;
95 struct device *dev;90 struct device *dev;
96 struct regulator_desc desc;91 struct regulator_desc desc;
97 struct regulator_dev *rdev;
98 struct regulator_init_data *regulator;92 struct regulator_init_data *regulator;
99 /* IC Type and Rev */93 /* IC Type and Rev */
100 int chip_id;94 int chip_id;
@@ -106,8 +100,6 @@ struct fan53555_device_info { · 5 unmodified lines
106 unsigned int vsel_min;100 unsigned int vsel_min;
107 unsigned int vsel_step;101 unsigned int vsel_step;
108 unsigned int vsel_count;102 unsigned int vsel_count;
109 /* Voltage slew rate limiting */
110 unsigned int slew_rate;
111 /* Mode */103 /* Mode */
112 unsigned int mode_reg;104 unsigned int mode_reg;
113 unsigned int mode_mask;105 unsigned int mode_mask;
@@ -125,7 +117,7 @@ static int fan53555_set_suspend_voltage(struct regulator_dev *rdev, int uV) · 11 unmodified lines
125 ret = regulator_map_voltage_linear(rdev, uV, uV);117 ret = regulator_map_voltage_linear(rdev, uV, uV);
126 if (ret < 0)118 if (ret < 0)
127 return ret;119 return ret;
128 ret = regmap_update_bits(di->regmap, di->sleep_reg,120 ret = regmap_update_bits(rdev->regmap, di->sleep_reg,
129 di->desc.vsel_mask, ret);121 di->desc.vsel_mask, ret);
130 if (ret < 0)122 if (ret < 0)
131 return ret;123 return ret;
@@ -140,7 +132,7 @@ static int fan53555_set_suspend_enable(struct regulator_dev *rdev) · 8 unmodified lines
140{132{
141 struct fan53555_device_info *di = rdev_get_drvdata(rdev);133 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
142 134
143 return regmap_update_bits(di->regmap, di->sleep_reg,135 return regmap_update_bits(rdev->regmap, di->sleep_reg,
144 VSEL_BUCK_EN, VSEL_BUCK_EN);136 VSEL_BUCK_EN, VSEL_BUCK_EN);
145}137}
146 138
@@ -148,7 +140,7 @@ static int fan53555_set_suspend_disable(struct regulator_dev *rdev) · 1 unmodified line
148{140{
149 struct fan53555_device_info *di = rdev_get_drvdata(rdev);141 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
150 142
151 return regmap_update_bits(di->regmap, di->sleep_reg,143 return regmap_update_bits(rdev->regmap, di->sleep_reg,
152 VSEL_BUCK_EN, 0);144 VSEL_BUCK_EN, 0);
153}145}
154 146
@@ -158,11 +150,11 @@ static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode) · 3 unmodified lines
158 150
159 switch (mode) {151 switch (mode) {
160 case REGULATOR_MODE_FAST:152 case REGULATOR_MODE_FAST:
161 regmap_update_bits(di->regmap, di->mode_reg,153 regmap_update_bits(rdev->regmap, di->mode_reg,
162 di->mode_mask, di->mode_mask);154 di->mode_mask, di->mode_mask);
163 break;155 break;
164 case REGULATOR_MODE_NORMAL:156 case REGULATOR_MODE_NORMAL:
165 regmap_update_bits(di->regmap, di->vol_reg, di->mode_mask, 0);157 regmap_update_bits(rdev->regmap, di->vol_reg, di->mode_mask, 0);
166 break;158 break;
167 default:159 default:
168 return -EINVAL;160 return -EINVAL;
@@ -176,7 +168,7 @@ static unsigned int fan53555_get_mode(struct regulator_dev *rdev) · 7 unmodified lines
176 unsigned int val;168 unsigned int val;
177 int ret = 0;169 int ret = 0;
178 170
179 ret = regmap_read(di->regmap, di->mode_reg, &val);171 ret = regmap_read(rdev->regmap, di->mode_reg, &val);
180 if (ret < 0)172 if (ret < 0)
181 return ret;173 return ret;
182 if (val & di->mode_mask)174 if (val & di->mode_mask)
@@ -213,7 +205,7 @@ static int fan53555_set_ramp(struct regulator_dev *rdev, int ramp) · 30 unmodified lines
213 return -EINVAL;205 return -EINVAL;
214 }206 }
215 207
216 return regmap_update_bits(di->regmap, FAN53555_CONTROL,208 return regmap_update_bits(rdev->regmap, FAN53555_CONTROL,
217 CTL_SLEW_MASK, regval << CTL_SLEW_SHIFT);209 CTL_SLEW_MASK, regval << CTL_SLEW_SHIFT);
218}210}
219 211
@@ -396,6 +388,7 @@ static int fan53555_regulator_register(struct fan53555_device_info *di, · 176 unmodified lines
396 struct regulator_config *config)388 struct regulator_config *config)
397{389{
398 struct regulator_desc *rdesc = &di->desc;390 struct regulator_desc *rdesc = &di->desc;
391 struct regulator_dev *rdev;
399 392
400 rdesc->name = "fan53555-reg";393 rdesc->name = "fan53555-reg";
401 rdesc->supply_name = "vin";394 rdesc->supply_name = "vin";
@@ -410,8 +403,8 @@ static int fan53555_regulator_register(struct fan53555_device_info *di, · 8 unmodified lines
410 rdesc->vsel_mask = di->vsel_count - 1;403 rdesc->vsel_mask = di->vsel_count - 1;
411 rdesc->owner = THIS_MODULE;404 rdesc->owner = THIS_MODULE;
412 405
413 di->rdev = devm_regulator_register(di->dev, &di->desc, config);406 rdev = devm_regulator_register(di->dev, &di->desc, config);
414 return PTR_ERR_OR_ZERO(di->rdev);407 return PTR_ERR_OR_ZERO(rdev);
415}408}
416 409
417static const struct regmap_config fan53555_regmap_config = {410static const struct regmap_config fan53555_regmap_config = {
@@ -466,6 +459,7 @@ static int fan53555_regulator_probe(struct i2c_client *client, · 48 unmodified lines
466 struct fan53555_device_info *di;459 struct fan53555_device_info *di;
467 struct fan53555_platform_data *pdata;460 struct fan53555_platform_data *pdata;
468 struct regulator_config config = { };461 struct regulator_config config = { };
462 struct regmap *regmap;
469 unsigned int val;463 unsigned int val;
470 int ret;464 int ret;
471 465
@@ -502,22 +496,22 @@ static int fan53555_regulator_probe(struct i2c_client *client, · 30 unmodified lines
502 di->vendor = id->driver_data;496 di->vendor = id->driver_data;
503 }497 }
504 498
505 di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);499 regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
506 if (IS_ERR(di->regmap)) {500 if (IS_ERR(regmap)) {
507 dev_err(&client->dev, "Failed to allocate regmap!\n");501 dev_err(&client->dev, "Failed to allocate regmap!\n");
508 return PTR_ERR(di->regmap);502 return PTR_ERR(regmap);
509 }503 }
510 di->dev = &client->dev;504 di->dev = &client->dev;
511 i2c_set_clientdata(client, di);505 i2c_set_clientdata(client, di);
512 /* Get chip ID */506 /* Get chip ID */
513 ret = regmap_read(di->regmap, FAN53555_ID1, &val);507 ret = regmap_read(regmap, FAN53555_ID1, &val);
514 if (ret < 0) {508 if (ret < 0) {
515 dev_err(&client->dev, "Failed to get chip ID!\n");509 dev_err(&client->dev, "Failed to get chip ID!\n");
516 return ret;510 return ret;
517 }511 }
518 di->chip_id = val & DIE_ID;512 di->chip_id = val & DIE_ID;
519 /* Get chip revision */513 /* Get chip revision */
520 ret = regmap_read(di->regmap, FAN53555_ID2, &val);514 ret = regmap_read(regmap, FAN53555_ID2, &val);
521 if (ret < 0) {515 if (ret < 0) {
522 dev_err(&client->dev, "Failed to get chip Rev!\n");516 dev_err(&client->dev, "Failed to get chip Rev!\n");
523 return ret;517 return ret;
@@ -534,7 +528,7 @@ static int fan53555_regulator_probe(struct i2c_client *client, · 10 unmodified lines
534 /* Register regulator */528 /* Register regulator */
535 config.dev = di->dev;529 config.dev = di->dev;
536 config.init_data = di->regulator;530 config.init_data = di->regulator;
537 config.regmap = di->regmap;531 config.regmap = regmap;
538 config.driver_data = di;532 config.driver_data = di;
539 config.of_node = np;533 config.of_node = np;
540 534
drivers/regulator/gpio-regulator.c+6−16
@@ -36,7 +36,6 @@ · 35 unmodified lines
36 36
37struct gpio_regulator_data {37struct gpio_regulator_data {
38 struct regulator_desc desc;38 struct regulator_desc desc;
39 struct regulator_dev *dev;
40 39
41 struct gpio_desc **gpiods;40 struct gpio_desc **gpiods;
42 int nr_gpios;41 int nr_gpios;
@@ -125,7 +124,7 @@ static int gpio_regulator_set_current_limit(struct regulator_dev *dev, · 82 unmodified lines
125 return 0;124 return 0;
126}125}
127 126
128static struct regulator_ops gpio_regulator_voltage_ops = {127static const struct regulator_ops gpio_regulator_voltage_ops = {
129 .get_voltage = gpio_regulator_get_value,128 .get_voltage = gpio_regulator_get_value,
130 .set_voltage = gpio_regulator_set_voltage,129 .set_voltage = gpio_regulator_set_voltage,
131 .list_voltage = gpio_regulator_list_voltage,130 .list_voltage = gpio_regulator_list_voltage,
@@ -221,7 +220,7 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np, · 89 unmodified lines
221 return config;220 return config;
222}221}
223 222
224static struct regulator_ops gpio_regulator_current_ops = {223static const struct regulator_ops gpio_regulator_current_ops = {
225 .get_current_limit = gpio_regulator_get_value,224 .get_current_limit = gpio_regulator_get_value,
226 .set_current_limit = gpio_regulator_set_current_limit,225 .set_current_limit = gpio_regulator_set_current_limit,
227};226};
@@ -233,6 +232,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) · 5 unmodified lines
233 struct device_node *np = dev->of_node;232 struct device_node *np = dev->of_node;
234 struct gpio_regulator_data *drvdata;233 struct gpio_regulator_data *drvdata;
235 struct regulator_config cfg = { };234 struct regulator_config cfg = { };
235 struct regulator_dev *rdev;
236 enum gpiod_flags gflags;236 enum gpiod_flags gflags;
237 int ptr, ret, state, i;237 int ptr, ret, state, i;
238 238
@@ -326,9 +326,9 @@ static int gpio_regulator_probe(struct platform_device *pdev) · 87 unmodified lines
326 if (IS_ERR(cfg.ena_gpiod))326 if (IS_ERR(cfg.ena_gpiod))
327 return PTR_ERR(cfg.ena_gpiod);327 return PTR_ERR(cfg.ena_gpiod);
328 328
329 drvdata->dev = regulator_register(&drvdata->desc, &cfg);329 rdev = devm_regulator_register(dev, &drvdata->desc, &cfg);
330 if (IS_ERR(drvdata->dev)) {330 if (IS_ERR(rdev)) {
331 ret = PTR_ERR(drvdata->dev);331 ret = PTR_ERR(rdev);
332 dev_err(dev, "Failed to register regulator: %d\n", ret);332 dev_err(dev, "Failed to register regulator: %d\n", ret);
333 return ret;333 return ret;
334 }334 }
@@ -338,15 +338,6 @@ static int gpio_regulator_probe(struct platform_device *pdev) · 3 unmodified lines
338 return 0;338 return 0;
339}339}
340 340
341static int gpio_regulator_remove(struct platform_device *pdev)
342{
343 struct gpio_regulator_data *drvdata = platform_get_drvdata(pdev);
344
345 regulator_unregister(drvdata->dev);
346
347 return 0;
348}
349
350#if defined(CONFIG_OF)341#if defined(CONFIG_OF)
351static const struct of_device_id regulator_gpio_of_match[] = {342static const struct of_device_id regulator_gpio_of_match[] = {
352 { .compatible = "regulator-gpio", },343 { .compatible = "regulator-gpio", },
@@ -357,7 +348,6 @@ MODULE_DEVICE_TABLE(of, regulator_gpio_of_match); · 4 unmodified lines
357 348
358static struct platform_driver gpio_regulator_driver = {349static struct platform_driver gpio_regulator_driver = {
359 .probe = gpio_regulator_probe,350 .probe = gpio_regulator_probe,
360 .remove = gpio_regulator_remove,
361 .driver = {351 .driver = {
362 .name = "gpio-regulator",352 .name = "gpio-regulator",
363 .of_match_table = of_match_ptr(regulator_gpio_of_match),353 .of_match_table = of_match_ptr(regulator_gpio_of_match),
drivers/regulator/hi6421-regulator.c+88−144
@@ -1,17 +1,13 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * Device driver for regulators in Hi6421 IC2//
3 *3// Device driver for regulators in Hi6421 IC
4 * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd.4//
5 * http://www.hisilicon.com5// Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd.
6 * Copyright (c) <2013-2014> Linaro Ltd.6// http://www.hisilicon.com
7 * http://www.linaro.org7// Copyright (c) <2013-2014> Linaro Ltd.
8 *8// http://www.linaro.org
9 * Author: Guodong Xu <guodong.xu@linaro.org>9//
10 *10// Author: Guodong Xu <guodong.xu@linaro.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15 11
16#include <linux/slab.h>12#include <linux/slab.h>
17#include <linux/device.h>13#include <linux/device.h>
@@ -78,43 +74,6 @@ enum hi6421_regulator_id { · 60 unmodified lines
78 HI6421_NUM_REGULATORS,74 HI6421_NUM_REGULATORS,
79};75};
80 76
81#define HI6421_REGULATOR_OF_MATCH(_name, id) \
82{ \
83 .name = #_name, \
84 .driver_data = (void *) HI6421_##id, \
85}
86
87static struct of_regulator_match hi6421_regulator_match[] = {
88 HI6421_REGULATOR_OF_MATCH(hi6421_vout0, LDO0),
89 HI6421_REGULATOR_OF_MATCH(hi6421_vout1, LDO1),
90 HI6421_REGULATOR_OF_MATCH(hi6421_vout2, LDO2),
91 HI6421_REGULATOR_OF_MATCH(hi6421_vout3, LDO3),
92 HI6421_REGULATOR_OF_MATCH(hi6421_vout4, LDO4),
93 HI6421_REGULATOR_OF_MATCH(hi6421_vout5, LDO5),
94 HI6421_REGULATOR_OF_MATCH(hi6421_vout6, LDO6),
95 HI6421_REGULATOR_OF_MATCH(hi6421_vout7, LDO7),
96 HI6421_REGULATOR_OF_MATCH(hi6421_vout8, LDO8),
97 HI6421_REGULATOR_OF_MATCH(hi6421_vout9, LDO9),
98 HI6421_REGULATOR_OF_MATCH(hi6421_vout10, LDO10),
99 HI6421_REGULATOR_OF_MATCH(hi6421_vout11, LDO11),
100 HI6421_REGULATOR_OF_MATCH(hi6421_vout12, LDO12),
101 HI6421_REGULATOR_OF_MATCH(hi6421_vout13, LDO13),
102 HI6421_REGULATOR_OF_MATCH(hi6421_vout14, LDO14),
103 HI6421_REGULATOR_OF_MATCH(hi6421_vout15, LDO15),
104 HI6421_REGULATOR_OF_MATCH(hi6421_vout16, LDO16),
105 HI6421_REGULATOR_OF_MATCH(hi6421_vout17, LDO17),
106 HI6421_REGULATOR_OF_MATCH(hi6421_vout18, LDO18),
107 HI6421_REGULATOR_OF_MATCH(hi6421_vout19, LDO19),
108 HI6421_REGULATOR_OF_MATCH(hi6421_vout20, LDO20),
109 HI6421_REGULATOR_OF_MATCH(hi6421_vout_audio, LDOAUDIO),
110 HI6421_REGULATOR_OF_MATCH(hi6421_buck0, BUCK0),
111 HI6421_REGULATOR_OF_MATCH(hi6421_buck1, BUCK1),
112 HI6421_REGULATOR_OF_MATCH(hi6421_buck2, BUCK2),
113 HI6421_REGULATOR_OF_MATCH(hi6421_buck3, BUCK3),
114 HI6421_REGULATOR_OF_MATCH(hi6421_buck4, BUCK4),
115 HI6421_REGULATOR_OF_MATCH(hi6421_buck5, BUCK5),
116};
117
118/* LDO 0, 4~7, 9~14, 16~20 have same voltage table. */77/* LDO 0, 4~7, 9~14, 16~20 have same voltage table. */
119static const unsigned int ldo_0_voltages[] = {78static const unsigned int ldo_0_voltages[] = {
120 1500000, 1800000, 2400000, 2500000,79 1500000, 1800000, 2400000, 2500000,
@@ -157,6 +116,7 @@ static const struct regulator_ops hi6421_buck345_ops; · 36 unmodified lines
157#define HI6421_LDO_ENABLE_TIME (350)116#define HI6421_LDO_ENABLE_TIME (350)
158/*117/*
159 * _id - LDO id name string118 * _id - LDO id name string
119 * _match - of match name string
160 * v_table - voltage table120 * v_table - voltage table
161 * vreg - voltage select register121 * vreg - voltage select register
162 * vmask - voltage select mask122 * vmask - voltage select mask
@@ -166,11 +126,13 @@ static const struct regulator_ops hi6421_buck345_ops; · 3 unmodified lines
166 * ecomask - eco mode mask126 * ecomask - eco mode mask
167 * ecoamp - eco mode load uppler limit in uA127 * ecoamp - eco mode load uppler limit in uA
168 */128 */
169#define HI6421_LDO(_id, v_table, vreg, vmask, ereg, emask, \129#define HI6421_LDO(_id, _match, v_table, vreg, vmask, ereg, emask, \
170 odelay, ecomask, ecoamp) \130 odelay, ecomask, ecoamp) \
171 [HI6421_##_id] = { \131 [HI6421_##_id] = { \
172 .desc = { \132 .desc = { \
173 .name = #_id, \133 .name = #_id, \
134 .of_match = of_match_ptr(#_match), \
135 .regulators_node = of_match_ptr("regulators"), \
174 .ops = &hi6421_ldo_ops, \136 .ops = &hi6421_ldo_ops, \
175 .type = REGULATOR_VOLTAGE, \137 .type = REGULATOR_VOLTAGE, \
176 .id = HI6421_##_id, \138 .id = HI6421_##_id, \
@@ -191,6 +153,7 @@ static const struct regulator_ops hi6421_buck345_ops; · 14 unmodified lines
191/* HI6421 LDO1~3 are linear voltage regulators at fixed uV_step153/* HI6421 LDO1~3 are linear voltage regulators at fixed uV_step
192 *154 *
193 * _id - LDO id name string155 * _id - LDO id name string
156 * _match - of match name string
194 * _min_uV - minimum voltage supported in uV157 * _min_uV - minimum voltage supported in uV
195 * n_volt - number of votages available158 * n_volt - number of votages available
196 * vstep - voltage increase in each linear step in uV159 * vstep - voltage increase in each linear step in uV
@@ -202,11 +165,13 @@ static const struct regulator_ops hi6421_buck345_ops; · 5 unmodified lines
202 * ecomask - eco mode mask165 * ecomask - eco mode mask
203 * ecoamp - eco mode load uppler limit in uA166 * ecoamp - eco mode load uppler limit in uA
204 */167 */
205#define HI6421_LDO_LINEAR(_id, _min_uV, n_volt, vstep, vreg, vmask, \168#define HI6421_LDO_LINEAR(_id, _match, _min_uV, n_volt, vstep, vreg, vmask,\
206 ereg, emask, odelay, ecomask, ecoamp) \169 ereg, emask, odelay, ecomask, ecoamp) \
207 [HI6421_##_id] = { \170 [HI6421_##_id] = { \
208 .desc = { \171 .desc = { \
209 .name = #_id, \172 .name = #_id, \
173 .of_match = of_match_ptr(#_match), \
174 .regulators_node = of_match_ptr("regulators"), \
210 .ops = &hi6421_ldo_linear_ops, \175 .ops = &hi6421_ldo_linear_ops, \
211 .type = REGULATOR_VOLTAGE, \176 .type = REGULATOR_VOLTAGE, \
212 .id = HI6421_##_id, \177 .id = HI6421_##_id, \
@@ -228,6 +193,7 @@ static const struct regulator_ops hi6421_buck345_ops; · 15 unmodified lines
228/* HI6421 LDOAUDIO is a linear voltage regulator with two 4-step ranges193/* HI6421 LDOAUDIO is a linear voltage regulator with two 4-step ranges
229 *194 *
230 * _id - LDO id name string195 * _id - LDO id name string
196 * _match - of match name string
231 * n_volt - number of votages available197 * n_volt - number of votages available
232 * volt_ranges - array of regulator_linear_range198 * volt_ranges - array of regulator_linear_range
233 * vstep - voltage increase in each linear step in uV199 * vstep - voltage increase in each linear step in uV
@@ -239,11 +205,13 @@ static const struct regulator_ops hi6421_buck345_ops; · 5 unmodified lines
239 * ecomask - eco mode mask205 * ecomask - eco mode mask
240 * ecoamp - eco mode load uppler limit in uA206 * ecoamp - eco mode load uppler limit in uA
241 */207 */
242#define HI6421_LDO_LINEAR_RANGE(_id, n_volt, volt_ranges, vreg, vmask, \208#define HI6421_LDO_LINEAR_RANGE(_id, _match, n_volt, volt_ranges, vreg, vmask,\
243 ereg, emask, odelay, ecomask, ecoamp) \209 ereg, emask, odelay, ecomask, ecoamp) \
244 [HI6421_##_id] = { \210 [HI6421_##_id] = { \
245 .desc = { \211 .desc = { \
246 .name = #_id, \212 .name = #_id, \
213 .of_match = of_match_ptr(#_match), \
214 .regulators_node = of_match_ptr("regulators"), \
247 .ops = &hi6421_ldo_linear_range_ops, \215 .ops = &hi6421_ldo_linear_range_ops, \
248 .type = REGULATOR_VOLTAGE, \216 .type = REGULATOR_VOLTAGE, \
249 .id = HI6421_##_id, \217 .id = HI6421_##_id, \
@@ -265,6 +233,7 @@ static const struct regulator_ops hi6421_buck345_ops; · 15 unmodified lines
265/* HI6421 BUCK0/1/2 are linear voltage regulators at fixed uV_step233/* HI6421 BUCK0/1/2 are linear voltage regulators at fixed uV_step
266 *234 *
267 * _id - BUCK0/1/2 id name string235 * _id - BUCK0/1/2 id name string
236 * _match - of match name string
268 * vreg - voltage select register237 * vreg - voltage select register
269 * vmask - voltage select mask238 * vmask - voltage select mask
270 * ereg - enable register239 * ereg - enable register
@@ -273,11 +242,13 @@ static const struct regulator_ops hi6421_buck345_ops; · 2 unmodified lines
273 * etime - enable time242 * etime - enable time
274 * odelay - off/on delay time in uS243 * odelay - off/on delay time in uS
275 */244 */
276#define HI6421_BUCK012(_id, vreg, vmask, ereg, emask, sleepmask, \245#define HI6421_BUCK012(_id, _match, vreg, vmask, ereg, emask, sleepmask,\
277 etime, odelay) \246 etime, odelay) \
278 [HI6421_##_id] = { \247 [HI6421_##_id] = { \
279 .desc = { \248 .desc = { \
280 .name = #_id, \249 .name = #_id, \
250 .of_match = of_match_ptr(#_match), \
251 .regulators_node = of_match_ptr("regulators"), \
281 .ops = &hi6421_buck012_ops, \252 .ops = &hi6421_buck012_ops, \
282 .type = REGULATOR_VOLTAGE, \253 .type = REGULATOR_VOLTAGE, \
283 .id = HI6421_##_id, \254 .id = HI6421_##_id, \
@@ -299,6 +270,7 @@ static const struct regulator_ops hi6421_buck345_ops; · 15 unmodified lines
299 * that it supports SLEEP mode, so has different .ops.270 * that it supports SLEEP mode, so has different .ops.
300 *271 *
301 * _id - LDO id name string272 * _id - LDO id name string
273 * _match - of match name string
302 * v_table - voltage table274 * v_table - voltage table
303 * vreg - voltage select register275 * vreg - voltage select register
304 * vmask - voltage select mask276 * vmask - voltage select mask
@@ -307,11 +279,13 @@ static const struct regulator_ops hi6421_buck345_ops; · 2 unmodified lines
307 * odelay - off/on delay time in uS279 * odelay - off/on delay time in uS
308 * sleepmask - mask of sleep mode280 * sleepmask - mask of sleep mode
309 */281 */
310#define HI6421_BUCK345(_id, v_table, vreg, vmask, ereg, emask, \282#define HI6421_BUCK345(_id, _match, v_table, vreg, vmask, ereg, emask, \
311 odelay, sleepmask) \283 odelay, sleepmask) \
312 [HI6421_##_id] = { \284 [HI6421_##_id] = { \
313 .desc = { \285 .desc = { \
314 .name = #_id, \286 .name = #_id, \
287 .of_match = of_match_ptr(#_match), \
288 .regulators_node = of_match_ptr("regulators"), \
315 .ops = &hi6421_buck345_ops, \289 .ops = &hi6421_buck345_ops, \
316 .type = REGULATOR_VOLTAGE, \290 .type = REGULATOR_VOLTAGE, \
317 .id = HI6421_##_id, \291 .id = HI6421_##_id, \
@@ -331,59 +305,63 @@ static const struct regulator_ops hi6421_buck345_ops; · 13 unmodified lines
331/* HI6421 regulator information */305/* HI6421 regulator information */
332static struct hi6421_regulator_info306static struct hi6421_regulator_info
333 hi6421_regulator_info[HI6421_NUM_REGULATORS] = {307 hi6421_regulator_info[HI6421_NUM_REGULATORS] = {
334 HI6421_LDO(LDO0, ldo_0_voltages, 0x20, 0x07, 0x20, 0x10,308 HI6421_LDO(LDO0, hi6421_vout0, ldo_0_voltages, 0x20, 0x07, 0x20, 0x10,
335 10000, 0x20, 8000),309 10000, 0x20, 8000),
336 HI6421_LDO_LINEAR(LDO1, 1700000, 4, 100000, 0x21, 0x03, 0x21, 0x10,310 HI6421_LDO_LINEAR(LDO1, hi6421_vout1, 1700000, 4, 100000, 0x21, 0x03,
337 10000, 0x20, 5000),311 0x21, 0x10, 10000, 0x20, 5000),
338 HI6421_LDO_LINEAR(LDO2, 1050000, 8, 50000, 0x22, 0x07, 0x22, 0x10,312 HI6421_LDO_LINEAR(LDO2, hi6421_vout2, 1050000, 8, 50000, 0x22, 0x07,
339 20000, 0x20, 8000),313 0x22, 0x10, 20000, 0x20, 8000),
340 HI6421_LDO_LINEAR(LDO3, 1050000, 8, 50000, 0x23, 0x07, 0x23, 0x10,314 HI6421_LDO_LINEAR(LDO3, hi6421_vout3, 1050000, 8, 50000, 0x23, 0x07,
341 20000, 0x20, 8000),315 0x23, 0x10, 20000, 0x20, 8000),
342 HI6421_LDO(LDO4, ldo_0_voltages, 0x24, 0x07, 0x24, 0x10,316 HI6421_LDO(LDO4, hi6421_vout4, ldo_0_voltages, 0x24, 0x07, 0x24, 0x10,
343 20000, 0x20, 8000),317 20000, 0x20, 8000),
344 HI6421_LDO(LDO5, ldo_0_voltages, 0x25, 0x07, 0x25, 0x10,318 HI6421_LDO(LDO5, hi6421_vout5, ldo_0_voltages, 0x25, 0x07, 0x25, 0x10,
345 20000, 0x20, 8000),319 20000, 0x20, 8000),
346 HI6421_LDO(LDO6, ldo_0_voltages, 0x26, 0x07, 0x26, 0x10,320 HI6421_LDO(LDO6, hi6421_vout6, ldo_0_voltages, 0x26, 0x07, 0x26, 0x10,
347 20000, 0x20, 8000),321 20000, 0x20, 8000),
348 HI6421_LDO(LDO7, ldo_0_voltages, 0x27, 0x07, 0x27, 0x10,322 HI6421_LDO(LDO7, hi6421_vout7, ldo_0_voltages, 0x27, 0x07, 0x27, 0x10,
349 20000, 0x20, 5000),323 20000, 0x20, 5000),
350 HI6421_LDO(LDO8, ldo_8_voltages, 0x28, 0x07, 0x28, 0x10,324 HI6421_LDO(LDO8, hi6421_vout8, ldo_8_voltages, 0x28, 0x07, 0x28, 0x10,
351 20000, 0x20, 8000),325 20000, 0x20, 8000),
352 HI6421_LDO(LDO9, ldo_0_voltages, 0x29, 0x07, 0x29, 0x10,326 HI6421_LDO(LDO9, hi6421_vout9, ldo_0_voltages, 0x29, 0x07, 0x29, 0x10,
353 40000, 0x20, 8000),327 40000, 0x20, 8000),
354 HI6421_LDO(LDO10, ldo_0_voltages, 0x2a, 0x07, 0x2a, 0x10,328 HI6421_LDO(LDO10, hi6421_vout10, ldo_0_voltages, 0x2a, 0x07, 0x2a, 0x10,
355 40000, 0x20, 8000),329 40000, 0x20, 8000),
356 HI6421_LDO(LDO11, ldo_0_voltages, 0x2b, 0x07, 0x2b, 0x10,330 HI6421_LDO(LDO11, hi6421_vout11, ldo_0_voltages, 0x2b, 0x07, 0x2b, 0x10,
357 40000, 0x20, 8000),331 40000, 0x20, 8000),
358 HI6421_LDO(LDO12, ldo_0_voltages, 0x2c, 0x07, 0x2c, 0x10,332 HI6421_LDO(LDO12, hi6421_vout12, ldo_0_voltages, 0x2c, 0x07, 0x2c, 0x10,
359 40000, 0x20, 8000),333 40000, 0x20, 8000),
360 HI6421_LDO(LDO13, ldo_0_voltages, 0x2d, 0x07, 0x2d, 0x10,334 HI6421_LDO(LDO13, hi6421_vout13, ldo_0_voltages, 0x2d, 0x07, 0x2d, 0x10,
361 40000, 0x20, 8000),335 40000, 0x20, 8000),
362 HI6421_LDO(LDO14, ldo_0_voltages, 0x2e, 0x07, 0x2e, 0x10,336 HI6421_LDO(LDO14, hi6421_vout14, ldo_0_voltages, 0x2e, 0x07, 0x2e, 0x10,
363 40000, 0x20, 8000),337 40000, 0x20, 8000),
364 HI6421_LDO(LDO15, ldo_8_voltages, 0x2f, 0x07, 0x2f, 0x10,338 HI6421_LDO(LDO15, hi6421_vout15, ldo_8_voltages, 0x2f, 0x07, 0x2f, 0x10,
365 40000, 0x20, 8000),339 40000, 0x20, 8000),
366 HI6421_LDO(LDO16, ldo_0_voltages, 0x30, 0x07, 0x30, 0x10,340 HI6421_LDO(LDO16, hi6421_vout16, ldo_0_voltages, 0x30, 0x07, 0x30, 0x10,
367 40000, 0x20, 8000),341 40000, 0x20, 8000),
368 HI6421_LDO(LDO17, ldo_0_voltages, 0x31, 0x07, 0x31, 0x10,342 HI6421_LDO(LDO17, hi6421_vout17, ldo_0_voltages, 0x31, 0x07, 0x31, 0x10,
369 40000, 0x20, 8000),343 40000, 0x20, 8000),
370 HI6421_LDO(LDO18, ldo_0_voltages, 0x32, 0x07, 0x32, 0x10,344 HI6421_LDO(LDO18, hi6421_vout18, ldo_0_voltages, 0x32, 0x07, 0x32, 0x10,
371 40000, 0x20, 8000),345 40000, 0x20, 8000),
372 HI6421_LDO(LDO19, ldo_0_voltages, 0x33, 0x07, 0x33, 0x10,346 HI6421_LDO(LDO19, hi6421_vout19, ldo_0_voltages, 0x33, 0x07, 0x33, 0x10,
373 40000, 0x20, 8000),347 40000, 0x20, 8000),
374 HI6421_LDO(LDO20, ldo_0_voltages, 0x34, 0x07, 0x34, 0x10,348 HI6421_LDO(LDO20, hi6421_vout20, ldo_0_voltages, 0x34, 0x07, 0x34, 0x10,
375 40000, 0x20, 8000),349 40000, 0x20, 8000),
376 HI6421_LDO_LINEAR_RANGE(LDOAUDIO, 8, ldo_audio_volt_range, 0x36,350 HI6421_LDO_LINEAR_RANGE(LDOAUDIO, hi6421_vout_audio, 8,
377 0x70, 0x36, 0x01, 40000, 0x02, 5000),351 ldo_audio_volt_range, 0x36, 0x70, 0x36, 0x01,
378 HI6421_BUCK012(BUCK0, 0x0d, 0x7f, 0x0c, 0x01, 0x10, 400, 20000),352 40000, 0x02, 5000),
379 HI6421_BUCK012(BUCK1, 0x0f, 0x7f, 0x0e, 0x01, 0x10, 400, 20000),353 HI6421_BUCK012(BUCK0, hi6421_buck0, 0x0d, 0x7f, 0x0c, 0x01, 0x10, 400,
380 HI6421_BUCK012(BUCK2, 0x11, 0x7f, 0x10, 0x01, 0x10, 350, 100),354 20000),
381 HI6421_BUCK345(BUCK3, buck_3_voltages, 0x13, 0x07, 0x12, 0x01,355 HI6421_BUCK012(BUCK1, hi6421_buck1, 0x0f, 0x7f, 0x0e, 0x01, 0x10, 400,
382 20000, 0x10),356 20000),
383 HI6421_BUCK345(BUCK4, buck_4_voltages, 0x15, 0x07, 0x14, 0x01,357 HI6421_BUCK012(BUCK2, hi6421_buck2, 0x11, 0x7f, 0x10, 0x01, 0x10, 350,
384 20000, 0x10),358 100),
385 HI6421_BUCK345(BUCK5, buck_5_voltages, 0x17, 0x07, 0x16, 0x01,359 HI6421_BUCK345(BUCK3, hi6421_buck3, buck_3_voltages, 0x13, 0x07, 0x12,
386 20000, 0x10),360 0x01, 20000, 0x10),
361 HI6421_BUCK345(BUCK4, hi6421_buck4, buck_4_voltages, 0x15, 0x07, 0x14,
362 0x01, 20000, 0x10),
363 HI6421_BUCK345(BUCK5, hi6421_buck5, buck_5_voltages, 0x17, 0x07, 0x16,
364 0x01, 20000, 0x10),
387};365};
388 366
389static int hi6421_regulator_enable(struct regulator_dev *rdev)367static int hi6421_regulator_enable(struct regulator_dev *rdev)
@@ -552,42 +530,14 @@ static const struct regulator_ops hi6421_buck345_ops = { · 162 unmodified lines
552 .set_mode = hi6421_regulator_buck_set_mode,530 .set_mode = hi6421_regulator_buck_set_mode,
553};531};
554 532
555static int hi6421_regulator_register(struct platform_device *pdev,
556 struct regmap *rmap,
557 struct regulator_init_data *init_data,
558 int id, struct device_node *np)
559{
560 struct hi6421_regulator_info *info = NULL;
561 struct regulator_config config = { };
562 struct regulator_dev *rdev;
563
564 /* assign per-regulator data */
565 info = &hi6421_regulator_info[id];
566
567 config.dev = &pdev->dev;
568 config.init_data = init_data;
569 config.driver_data = info;
570 config.regmap = rmap;
571 config.of_node = np;
572
573 /* register regulator with framework */
574 rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
575 if (IS_ERR(rdev)) {
576 dev_err(&pdev->dev, "failed to register regulator %s\n",
577 info->desc.name);
578 return PTR_ERR(rdev);
579 }
580
581 return 0;
582}
583
584static int hi6421_regulator_probe(struct platform_device *pdev)533static int hi6421_regulator_probe(struct platform_device *pdev)
585{534{
586 struct device *dev = &pdev->dev;535 struct hi6421_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
587 struct device_node *np;
588 struct hi6421_pmic *pmic;
589 struct hi6421_regulator_pdata *pdata;536 struct hi6421_regulator_pdata *pdata;
590 int i, ret = 0;537 struct hi6421_regulator_info *info;
538 struct regulator_config config = { };
539 struct regulator_dev *rdev;
540 int i;
591 541
592 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);542 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
593 if (!pdata)543 if (!pdata)
@@ -595,27 +545,21 @@ static int hi6421_regulator_probe(struct platform_device *pdev) · 1 unmodified line
595 mutex_init(&pdata->lock);545 mutex_init(&pdata->lock);
596 platform_set_drvdata(pdev, pdata);546 platform_set_drvdata(pdev, pdata);
597 547
598 np = of_get_child_by_name(dev->parent->of_node, "regulators");
599 if (!np)
600 return -ENODEV;
601
602 ret = of_regulator_match(dev, np,
603 hi6421_regulator_match,
604 ARRAY_SIZE(hi6421_regulator_match));
605 of_node_put(np);
606 if (ret < 0) {
607 dev_err(dev, "Error parsing regulator init data: %d\n", ret);
608 return ret;
609 }
610
611 pmic = dev_get_drvdata(dev->parent);
612
613 for (i = 0; i < ARRAY_SIZE(hi6421_regulator_info); i++) {548 for (i = 0; i < ARRAY_SIZE(hi6421_regulator_info); i++) {
614 ret = hi6421_regulator_register(pdev, pmic->regmap,549 /* assign per-regulator data */
615 hi6421_regulator_match[i].init_data, i,550 info = &hi6421_regulator_info[i];
616 hi6421_regulator_match[i].of_node);551
617 if (ret)552 config.dev = pdev->dev.parent;
618 return ret;553 config.driver_data = info;
554 config.regmap = pmic->regmap;
555
556 rdev = devm_regulator_register(&pdev->dev, &info->desc,
557 &config);
558 if (IS_ERR(rdev)) {
559 dev_err(&pdev->dev, "failed to register regulator %s\n",
560 info->desc.name);
561 return PTR_ERR(rdev);
562 }
619 }563 }
620 564
621 return 0;565 return 0;
drivers/regulator/hi6421v530-regulator.c+11−15
@@ -1,18 +1,14 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * Device driver for regulators in Hi6421V530 IC2//
3 *3// Device driver for regulators in Hi6421V530 IC
4 * Copyright (c) <2017> HiSilicon Technologies Co., Ltd.4//
5 * http://www.hisilicon.com5// Copyright (c) <2017> HiSilicon Technologies Co., Ltd.
6 * Copyright (c) <2017> Linaro Ltd.6// http://www.hisilicon.com
7 * http://www.linaro.org7// Copyright (c) <2017> Linaro Ltd.
8 *8// http://www.linaro.org
9 * Author: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com>9//
10 * Guodong Xu <guodong.xu@linaro.org>10// Author: Wang Xiaoyin <hw.wangxiaoyin@hisilicon.com>
11 *11// Guodong Xu <guodong.xu@linaro.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16 12
17#include <linux/mfd/hi6421-pmic.h>13#include <linux/mfd/hi6421-pmic.h>
18#include <linux/module.h>14#include <linux/module.h>
drivers/regulator/hi655x-regulator.c+13−24
@@ -1,16 +1,12 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * Device driver for regulators in Hi655x IC2//
3 *3// Device driver for regulators in Hi655x IC
4 * Copyright (c) 2016 Hisilicon.4//
5 *5// Copyright (c) 2016 Hisilicon.
6 * Authors:6//
7 * Chen Feng <puck.chen@hisilicon.com>7// Authors:
8 * Fei Wang <w.f@huawei.com>8// Chen Feng <puck.chen@hisilicon.com>
9 *9// Fei Wang <w.f@huawei.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14 10
15#include <linux/bitops.h>11#include <linux/bitops.h>
16#include <linux/device.h>12#include <linux/device.h>
@@ -28,7 +24,6 @@ · 11 unmodified lines
28struct hi655x_regulator {24struct hi655x_regulator {
29 unsigned int disable_reg;25 unsigned int disable_reg;
30 unsigned int status_reg;26 unsigned int status_reg;
31 unsigned int ctrl_mask;
32 struct regulator_desc rdesc;27 struct regulator_desc rdesc;
33};28};
34 29
@@ -77,22 +72,18 @@ enum hi655x_regulator_id { · 42 unmodified lines
77static int hi655x_is_enabled(struct regulator_dev *rdev)72static int hi655x_is_enabled(struct regulator_dev *rdev)
78{73{
79 unsigned int value = 0;74 unsigned int value = 0;
80
81 struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);75 struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);
82 76
83 regmap_read(rdev->regmap, regulator->status_reg, &value);77 regmap_read(rdev->regmap, regulator->status_reg, &value);
84 return (value & BIT(regulator->ctrl_mask));78 return (value & rdev->desc->enable_mask);
85}79}
86 80
87static int hi655x_disable(struct regulator_dev *rdev)81static int hi655x_disable(struct regulator_dev *rdev)
88{82{
89 int ret = 0;
90
91 struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);83 struct hi655x_regulator *regulator = rdev_get_drvdata(rdev);
92 84
93 ret = regmap_write(rdev->regmap, regulator->disable_reg,85 return regmap_write(rdev->regmap, regulator->disable_reg,
94 BIT(regulator->ctrl_mask));86 rdev->desc->enable_mask);
95 return ret;
96}87}
97 88
98static const struct regulator_ops hi655x_regulator_ops = {89static const struct regulator_ops hi655x_regulator_ops = {
@@ -132,7 +123,6 @@ static const struct regulator_ops hi655x_ldo_linear_ops = { · 33 unmodified lines
132 }, \123 }, \
133 .disable_reg = HI655X_BUS_ADDR(dreg), \124 .disable_reg = HI655X_BUS_ADDR(dreg), \
134 .status_reg = HI655X_BUS_ADDR(sreg), \125 .status_reg = HI655X_BUS_ADDR(sreg), \
135 .ctrl_mask = cmask, \
136}126}
137 127
138#define HI655X_LDO_LINEAR(_ID, vreg, vmask, ereg, dreg, \128#define HI655X_LDO_LINEAR(_ID, vreg, vmask, ereg, dreg, \
@@ -155,10 +145,9 @@ static const struct regulator_ops hi655x_ldo_linear_ops = { · 16 unmodified lines
155 }, \145 }, \
156 .disable_reg = HI655X_BUS_ADDR(dreg), \146 .disable_reg = HI655X_BUS_ADDR(dreg), \
157 .status_reg = HI655X_BUS_ADDR(sreg), \147 .status_reg = HI655X_BUS_ADDR(sreg), \
158 .ctrl_mask = cmask, \
159}148}
160 149
161static struct hi655x_regulator regulators[] = {150static const struct hi655x_regulator regulators[] = {
162 HI655X_LDO_LINEAR(LDO2, 0x72, 0x07, 0x29, 0x2a, 0x2b, 0x01,151 HI655X_LDO_LINEAR(LDO2, 0x72, 0x07, 0x29, 0x2a, 0x2b, 0x01,
163 2500000, 8, 100000),152 2500000, 8, 100000),
164 HI655X_LDO(LDO7, 0x78, 0x07, 0x29, 0x2a, 0x2b, 0x06, ldo7_voltages),153 HI655X_LDO(LDO7, 0x78, 0x07, 0x29, 0x2a, 0x2b, 0x06, ldo7_voltages),
drivers/regulator/lm363x-regulator.c+4−4
@@ -48,7 +48,7 @@ static const int ldo_cont_enable_time[] = { · 47 unmodified lines
48static int lm363x_regulator_enable_time(struct regulator_dev *rdev)48static int lm363x_regulator_enable_time(struct regulator_dev *rdev)
49{49{
50 enum lm363x_regulator_id id = rdev_get_id(rdev);50 enum lm363x_regulator_id id = rdev_get_id(rdev);
51 u8 val, addr, mask;51 unsigned int val, addr, mask;
52 52
53 switch (id) {53 switch (id) {
54 case LM3631_LDO_CONT:54 case LM3631_LDO_CONT:
@@ -71,7 +71,7 @@ static int lm363x_regulator_enable_time(struct regulator_dev *rdev) · 16 unmodified lines
71 return 0;71 return 0;
72 }72 }
73 73
74 if (regmap_read(rdev->regmap, addr, (unsigned int *)&val))74 if (regmap_read(rdev->regmap, addr, &val))
75 return -EINVAL;75 return -EINVAL;
76 76
77 val = (val & mask) >> LM3631_ENTIME_SHIFT;77 val = (val & mask) >> LM3631_ENTIME_SHIFT;
@@ -82,13 +82,13 @@ static int lm363x_regulator_enable_time(struct regulator_dev *rdev) · 4 unmodified lines
82 return ENABLE_TIME_USEC * val;82 return ENABLE_TIME_USEC * val;
83}83}
84 84
85static struct regulator_ops lm363x_boost_voltage_table_ops = {85static const struct regulator_ops lm363x_boost_voltage_table_ops = {
86 .list_voltage = regulator_list_voltage_linear,86 .list_voltage = regulator_list_voltage_linear,
87 .set_voltage_sel = regulator_set_voltage_sel_regmap,87 .set_voltage_sel = regulator_set_voltage_sel_regmap,
88 .get_voltage_sel = regulator_get_voltage_sel_regmap,88 .get_voltage_sel = regulator_get_voltage_sel_regmap,
89};89};
90 90
91static struct regulator_ops lm363x_regulator_voltage_table_ops = {91static const struct regulator_ops lm363x_regulator_voltage_table_ops = {
92 .list_voltage = regulator_list_voltage_linear,92 .list_voltage = regulator_list_voltage_linear,
93 .set_voltage_sel = regulator_set_voltage_sel_regmap,93 .set_voltage_sel = regulator_set_voltage_sel_regmap,
94 .get_voltage_sel = regulator_get_voltage_sel_regmap,94 .get_voltage_sel = regulator_get_voltage_sel_regmap,
drivers/regulator/lp8755.c+12−3
@@ -372,10 +372,13 @@ static irqreturn_t lp8755_irq_handler(int irq, void *data) · 371 unmodified lines
372 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)372 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
373 if ((flag0 & (0x4 << icnt))373 if ((flag0 & (0x4 << icnt))
374 && (pchip->irqmask & (0x04 << icnt))374 && (pchip->irqmask & (0x04 << icnt))
375 && (pchip->rdev[icnt] != NULL))375 && (pchip->rdev[icnt] != NULL)) {
376 regulator_lock(pchip->rdev[icnt]);
376 regulator_notifier_call_chain(pchip->rdev[icnt],377 regulator_notifier_call_chain(pchip->rdev[icnt],
377 LP8755_EVENT_PWR_FAULT,378 LP8755_EVENT_PWR_FAULT,
378 NULL);379 NULL);
380 regulator_unlock(pchip->rdev[icnt]);
381 }
379 382
380 /* read flag1 register */383 /* read flag1 register */
381 ret = lp8755_read(pchip, 0x0E, &flag1);384 ret = lp8755_read(pchip, 0x0E, &flag1);
@@ -389,18 +392,24 @@ static irqreturn_t lp8755_irq_handler(int irq, void *data) · 7 unmodified lines
389 /* send OCP event to all regulator devices */392 /* send OCP event to all regulator devices */
390 if ((flag1 & 0x01) && (pchip->irqmask & 0x01))393 if ((flag1 & 0x01) && (pchip->irqmask & 0x01))
391 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)394 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
392 if (pchip->rdev[icnt] != NULL)395 if (pchip->rdev[icnt] != NULL) {
396 regulator_lock(pchip->rdev[icnt]);
393 regulator_notifier_call_chain(pchip->rdev[icnt],397 regulator_notifier_call_chain(pchip->rdev[icnt],
394 LP8755_EVENT_OCP,398 LP8755_EVENT_OCP,
395 NULL);399 NULL);
400 regulator_unlock(pchip->rdev[icnt]);
401 }
396 402
397 /* send OVP event to all regulator devices */403 /* send OVP event to all regulator devices */
398 if ((flag1 & 0x02) && (pchip->irqmask & 0x02))404 if ((flag1 & 0x02) && (pchip->irqmask & 0x02))
399 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)405 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
400 if (pchip->rdev[icnt] != NULL)406 if (pchip->rdev[icnt] != NULL) {
407 regulator_lock(pchip->rdev[icnt]);
401 regulator_notifier_call_chain(pchip->rdev[icnt],408 regulator_notifier_call_chain(pchip->rdev[icnt],
402 LP8755_EVENT_OVP,409 LP8755_EVENT_OVP,
403 NULL);410 NULL);
411 regulator_unlock(pchip->rdev[icnt]);
412 }
404 return IRQ_HANDLED;413 return IRQ_HANDLED;
405 414
406err_i2c:415err_i2c:
drivers/regulator/lp87565-regulator.c+8−41
@@ -34,6 +34,10 @@ · 33 unmodified lines
34 .ramp_delay = _delay, \34 .ramp_delay = _delay, \
35 .linear_ranges = _lr, \35 .linear_ranges = _lr, \
36 .n_linear_ranges = ARRAY_SIZE(_lr), \36 .n_linear_ranges = ARRAY_SIZE(_lr), \
37 .curr_table = lp87565_buck_uA, \
38 .n_current_limits = ARRAY_SIZE(lp87565_buck_uA),\
39 .csel_reg = (_cr), \
40 .csel_mask = LP87565_BUCK_CTRL_2_ILIM, \
37 }, \41 }, \
38 .ctrl2_reg = _cr, \42 .ctrl2_reg = _cr, \
39 }43 }
@@ -102,44 +106,7 @@ static int lp87565_buck_set_ramp_delay(struct regulator_dev *rdev, · 62 unmodified lines
102 return 0;106 return 0;
103}107}
104 108
105static int lp87565_buck_set_current_limit(struct regulator_dev *rdev,109/* Operations permitted on BUCKs */
106 int min_uA, int max_uA)
107{
108 int id = rdev_get_id(rdev);
109 struct lp87565 *lp87565 = rdev_get_drvdata(rdev);
110 int i;
111
112 for (i = ARRAY_SIZE(lp87565_buck_uA) - 1; i >= 0; i--) {
113 if (lp87565_buck_uA[i] >= min_uA &&
114 lp87565_buck_uA[i] <= max_uA)
115 return regmap_update_bits(lp87565->regmap,
116 regulators[id].ctrl2_reg,
117 LP87565_BUCK_CTRL_2_ILIM,
118 i << __ffs(LP87565_BUCK_CTRL_2_ILIM));
119 }
120
121 return -EINVAL;
122}
123
124static int lp87565_buck_get_current_limit(struct regulator_dev *rdev)
125{
126 int id = rdev_get_id(rdev);
127 struct lp87565 *lp87565 = rdev_get_drvdata(rdev);
128 int ret;
129 unsigned int val;
130
131 ret = regmap_read(lp87565->regmap, regulators[id].ctrl2_reg, &val);
132 if (ret)
133 return ret;
134
135 val = (val & LP87565_BUCK_CTRL_2_ILIM) >>
136 __ffs(LP87565_BUCK_CTRL_2_ILIM);
137
138 return (val < ARRAY_SIZE(lp87565_buck_uA)) ?
139 lp87565_buck_uA[val] : -EINVAL;
140}
141
142/* Operations permitted on BUCK0, BUCK1 */
143static const struct regulator_ops lp87565_buck_ops = {110static const struct regulator_ops lp87565_buck_ops = {
144 .is_enabled = regulator_is_enabled_regmap,111 .is_enabled = regulator_is_enabled_regmap,
145 .enable = regulator_enable_regmap,112 .enable = regulator_enable_regmap,
@@ -150,8 +117,8 @@ static const struct regulator_ops lp87565_buck_ops = { · 4 unmodified lines
150 .map_voltage = regulator_map_voltage_linear_range,117 .map_voltage = regulator_map_voltage_linear_range,
151 .set_voltage_time_sel = regulator_set_voltage_time_sel,118 .set_voltage_time_sel = regulator_set_voltage_time_sel,
152 .set_ramp_delay = lp87565_buck_set_ramp_delay,119 .set_ramp_delay = lp87565_buck_set_ramp_delay,
153 .set_current_limit = lp87565_buck_set_current_limit,120 .set_current_limit = regulator_set_current_limit_regmap,
154 .get_current_limit = lp87565_buck_get_current_limit,121 .get_current_limit = regulator_get_current_limit_regmap,
155};122};
156 123
157static const struct lp87565_regulator regulators[] = {124static const struct lp87565_regulator regulators[] = {
@@ -193,7 +160,7 @@ static int lp87565_regulator_probe(struct platform_device *pdev) · 35 unmodified lines
193 struct lp87565 *lp87565 = dev_get_drvdata(pdev->dev.parent);160 struct lp87565 *lp87565 = dev_get_drvdata(pdev->dev.parent);
194 struct regulator_config config = { };161 struct regulator_config config = { };
195 struct regulator_dev *rdev;162 struct regulator_dev *rdev;
196 int i, min_idx = LP87565_BUCK_1, max_idx = LP87565_BUCK_3;163 int i, min_idx = LP87565_BUCK_0, max_idx = LP87565_BUCK_3;
197 164
198 platform_set_drvdata(pdev, lp87565);165 platform_set_drvdata(pdev, lp87565);
199 166
drivers/regulator/ltc3589.c+89−180
@@ -1,21 +1,9 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * Linear Technology LTC3589,LTC3589-1 regulator support2//
3 *3// Linear Technology LTC3589,LTC3589-1 regulator support
4 * Copyright (c) 2014 Philipp Zabel <p.zabel@pengutronix.de>, Pengutronix4//
5 *5// Copyright (c) 2014 Philipp Zabel <p.zabel@pengutronix.de>, Pengutronix
6 * See file CREDITS for list of people who contributed to this6
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19#include <linux/i2c.h>7#include <linux/i2c.h>
20#include <linux/init.h>8#include <linux/init.h>
21#include <linux/interrupt.h>9#include <linux/interrupt.h>
@@ -84,19 +72,11 @@ enum ltc3589_reg { · 62 unmodified lines
84 LTC3589_NUM_REGULATORS,72 LTC3589_NUM_REGULATORS,
85};73};
86 74
87struct ltc3589_regulator {
88 struct regulator_desc desc;
89
90 /* External feedback voltage divider */
91 unsigned int r1;
92 unsigned int r2;
93};
94
95struct ltc3589 {75struct ltc3589 {
96 struct regmap *regmap;76 struct regmap *regmap;
97 struct device *dev;77 struct device *dev;
98 enum ltc3589_variant variant;78 enum ltc3589_variant variant;
99 struct ltc3589_regulator regulator_descs[LTC3589_NUM_REGULATORS];79 struct regulator_desc regulator_descs[LTC3589_NUM_REGULATORS];
100 struct regulator_dev *regulators[LTC3589_NUM_REGULATORS];80 struct regulator_dev *regulators[LTC3589_NUM_REGULATORS];
101};81};
102 82
@@ -196,131 +176,90 @@ static const struct regulator_ops ltc3589_table_regulator_ops = { · 93 unmodified lines
196 .get_voltage_sel = regulator_get_voltage_sel_regmap,176 .get_voltage_sel = regulator_get_voltage_sel_regmap,
197};177};
198 178
179static inline unsigned int ltc3589_scale(unsigned int uV, u32 r1, u32 r2)
180{
181 uint64_t tmp;
199 182
200#define LTC3589_REG(_name, _ops, en_bit, dtv1_reg, dtv_mask, go_bit) \183 if (uV == 0)
201 [LTC3589_ ## _name] = { \184 return 0;
202 .desc = { \
203 .name = #_name, \
204 .n_voltages = (dtv_mask) + 1, \
205 .min_uV = (go_bit) ? 362500 : 0, \
206 .uV_step = (go_bit) ? 12500 : 0, \
207 .ramp_delay = (go_bit) ? 1750 : 0, \
208 .fixed_uV = (dtv_mask) ? 0 : 800000, \
209 .ops = &ltc3589_ ## _ops ## _regulator_ops, \
210 .type = REGULATOR_VOLTAGE, \
211 .id = LTC3589_ ## _name, \
212 .owner = THIS_MODULE, \
213 .vsel_reg = (dtv1_reg), \
214 .vsel_mask = (dtv_mask), \
215 .apply_reg = (go_bit) ? LTC3589_VCCR : 0, \
216 .apply_bit = (go_bit), \
217 .enable_reg = (en_bit) ? LTC3589_OVEN : 0, \
218 .enable_mask = (en_bit), \
219 }, \
220 }
221
222#define LTC3589_LINEAR_REG(_name, _dtv1) \
223 LTC3589_REG(_name, linear, LTC3589_OVEN_ ## _name, \
224 LTC3589_ ## _dtv1, 0x1f, \
225 LTC3589_VCCR_ ## _name ## _GO)
226
227#define LTC3589_FIXED_REG(_name) \
228 LTC3589_REG(_name, fixed, LTC3589_OVEN_ ## _name, 0, 0, 0)
229
230static struct ltc3589_regulator ltc3589_regulators[LTC3589_NUM_REGULATORS] = {
231 LTC3589_LINEAR_REG(SW1, B1DTV1),
232 LTC3589_LINEAR_REG(SW2, B2DTV1),
233 LTC3589_LINEAR_REG(SW3, B3DTV1),
234 LTC3589_FIXED_REG(BB_OUT),
235 LTC3589_REG(LDO1, fixed_standby, 0, 0, 0, 0),
236 LTC3589_LINEAR_REG(LDO2, L2DTV1),
237 LTC3589_FIXED_REG(LDO3),
238 LTC3589_REG(LDO4, table, LTC3589_OVEN_LDO4, LTC3589_L2DTV2, 0x60, 0),
239};
240 185
241#ifdef CONFIG_OF186 tmp = (uint64_t)uV * r1;
242static struct of_regulator_match ltc3589_matches[LTC3589_NUM_REGULATORS] = {187 do_div(tmp, r2);
243 { .name = "sw1", },188 return uV + (unsigned int)tmp;
244 { .name = "sw2", },189}
245 { .name = "sw3", },
246 { .name = "bb-out", },
247 { .name = "ldo1", }, /* standby */
248 { .name = "ldo2", },
249 { .name = "ldo3", },
250 { .name = "ldo4", },
251};
252 190
253static int ltc3589_parse_regulators_dt(struct ltc3589 *ltc3589)191static int ltc3589_of_parse_cb(struct device_node *np,
192 const struct regulator_desc *desc,
193 struct regulator_config *config)
254{194{
255 struct device *dev = ltc3589->dev;195 struct ltc3589 *ltc3589 = config->driver_data;
256 struct device_node *node;196 struct regulator_desc *rdesc = &ltc3589->regulator_descs[desc->id];
257 int i, ret;197 u32 r[2];
198 int ret;
258 199
259 node = of_get_child_by_name(dev->of_node, "regulators");200 /* Parse feedback voltage dividers. LDO3 and LDO4 don't have them */
260 if (!node) {201 if (desc->id >= LTC3589_LDO3)
261 dev_err(dev, "regulators node not found\n");202 return 0;
262 return -EINVAL;
263 }
264 203
265 ret = of_regulator_match(dev, node, ltc3589_matches,204 ret = of_property_read_u32_array(np, "lltc,fb-voltage-divider", r, 2);
266 ARRAY_SIZE(ltc3589_matches));205 if (ret) {
267 of_node_put(node);206 dev_err(ltc3589->dev, "Failed to parse voltage divider: %d\n",
268 if (ret < 0) {
269 dev_err(dev, "Error parsing regulator init data: %d\n", ret);
270 return ret;
271 }
272 if (ret != LTC3589_NUM_REGULATORS) {
273 dev_err(dev, "Only %d regulators described in device tree\n",
274 ret);207 ret);
275 return -EINVAL;208 return ret;
276 }209 }
277 210
278 /* Parse feedback voltage dividers. LDO3 and LDO4 don't have them */211 if (!r[0] || !r[1])
279 for (i = 0; i < LTC3589_LDO3; i++) {212 return 0;
280 struct ltc3589_regulator *desc = &ltc3589->regulator_descs[i];
281 struct device_node *np = ltc3589_matches[i].of_node;
282 u32 vdiv[2];
283
284 ret = of_property_read_u32_array(np, "lltc,fb-voltage-divider",
285 vdiv, 2);
286 if (ret) {
287 dev_err(dev, "Failed to parse voltage divider: %d\n",
288 ret);
289 return ret;
290 }
291 213
292 desc->r1 = vdiv[0];214 rdesc->min_uV = ltc3589_scale(desc->min_uV, r[0], r[1]);
293 desc->r2 = vdiv[1];215 rdesc->uV_step = ltc3589_scale(desc->uV_step, r[0], r[1]);
294 }216 rdesc->fixed_uV = ltc3589_scale(desc->fixed_uV, r[0], r[1]);
295 217
296 return 0;218 return 0;
297}219}
298 220
299static inline struct regulator_init_data *match_init_data(int index)221#define LTC3589_REG(_name, _of_name, _ops, en_bit, dtv1_reg, dtv_mask, go_bit)\
300{222 [LTC3589_ ## _name] = { \
301 return ltc3589_matches[index].init_data;223 .name = #_name, \
302}224 .of_match = of_match_ptr(#_of_name), \
303 225 .regulators_node = of_match_ptr("regulators"), \
304static inline struct device_node *match_of_node(int index)226 .of_parse_cb = ltc3589_of_parse_cb, \
305{227 .n_voltages = (dtv_mask) + 1, \
306 return ltc3589_matches[index].of_node;228 .min_uV = (go_bit) ? 362500 : 0, \
307}229 .uV_step = (go_bit) ? 12500 : 0, \
308#else230 .ramp_delay = (go_bit) ? 1750 : 0, \
309static inline int ltc3589_parse_regulators_dt(struct ltc3589 *ltc3589)231 .fixed_uV = (dtv_mask) ? 0 : 800000, \
310{232 .ops = &ltc3589_ ## _ops ## _regulator_ops, \
311 return 0;233 .type = REGULATOR_VOLTAGE, \
312}234 .id = LTC3589_ ## _name, \
235 .owner = THIS_MODULE, \
236 .vsel_reg = (dtv1_reg), \
237 .vsel_mask = (dtv_mask), \
238 .apply_reg = (go_bit) ? LTC3589_VCCR : 0, \
239 .apply_bit = (go_bit), \
240 .enable_reg = (en_bit) ? LTC3589_OVEN : 0, \
241 .enable_mask = (en_bit), \
242 }
313 243
314static inline struct regulator_init_data *match_init_data(int index)244#define LTC3589_LINEAR_REG(_name, _of_name, _dtv1) \
315{245 LTC3589_REG(_name, _of_name, linear, LTC3589_OVEN_ ## _name, \
316 return NULL;246 LTC3589_ ## _dtv1, 0x1f, \
317}247 LTC3589_VCCR_ ## _name ## _GO)
318 248
319static inline struct device_node *match_of_node(int index)249#define LTC3589_FIXED_REG(_name, _of_name) \
320{250 LTC3589_REG(_name, _of_name, fixed, LTC3589_OVEN_ ## _name, 0, 0, 0)
321 return NULL;251
322}252static const struct regulator_desc ltc3589_regulators[] = {
323#endif253 LTC3589_LINEAR_REG(SW1, sw1, B1DTV1),
254 LTC3589_LINEAR_REG(SW2, sw2, B2DTV1),
255 LTC3589_LINEAR_REG(SW3, sw3, B3DTV1),
256 LTC3589_FIXED_REG(BB_OUT, bb-out),
257 LTC3589_REG(LDO1, ldo1, fixed_standby, 0, 0, 0, 0),
258 LTC3589_LINEAR_REG(LDO2, ldo2, L2DTV1),
259 LTC3589_FIXED_REG(LDO3, ldo3),
260 LTC3589_REG(LDO4, ldo4, table, LTC3589_OVEN_LDO4, LTC3589_L2DTV2,
261 0x60, 0),
262};
324 263
325static bool ltc3589_writeable_reg(struct device *dev, unsigned int reg)264static bool ltc3589_writeable_reg(struct device *dev, unsigned int reg)
326{265{
@@ -409,7 +348,6 @@ static const struct regmap_config ltc3589_regmap_config = { · 82 unmodified lines
409 .cache_type = REGCACHE_RBTREE,348 .cache_type = REGCACHE_RBTREE,
410};349};
411 350
412
413static irqreturn_t ltc3589_isr(int irq, void *dev_id)351static irqreturn_t ltc3589_isr(int irq, void *dev_id)
414{352{
415 struct ltc3589 *ltc3589 = dev_id;353 struct ltc3589 *ltc3589 = dev_id;
@@ -419,16 +357,22 @@ static irqreturn_t ltc3589_isr(int irq, void *dev_id) · 3 unmodified lines
419 357
420 if (irqstat & LTC3589_IRQSTAT_THERMAL_WARN) {358 if (irqstat & LTC3589_IRQSTAT_THERMAL_WARN) {
421 event = REGULATOR_EVENT_OVER_TEMP;359 event = REGULATOR_EVENT_OVER_TEMP;
422 for (i = 0; i < LTC3589_NUM_REGULATORS; i++)360 for (i = 0; i < LTC3589_NUM_REGULATORS; i++) {
361 regulator_lock(ltc3589->regulators[i]);
423 regulator_notifier_call_chain(ltc3589->regulators[i],362 regulator_notifier_call_chain(ltc3589->regulators[i],
424 event, NULL);363 event, NULL);
364 regulator_unlock(ltc3589->regulators[i]);
365 }
425 }366 }
426 367
427 if (irqstat & LTC3589_IRQSTAT_UNDERVOLT_WARN) {368 if (irqstat & LTC3589_IRQSTAT_UNDERVOLT_WARN) {
428 event = REGULATOR_EVENT_UNDER_VOLTAGE;369 event = REGULATOR_EVENT_UNDER_VOLTAGE;
429 for (i = 0; i < LTC3589_NUM_REGULATORS; i++)370 for (i = 0; i < LTC3589_NUM_REGULATORS; i++) {
371 regulator_lock(ltc3589->regulators[i]);
430 regulator_notifier_call_chain(ltc3589->regulators[i],372 regulator_notifier_call_chain(ltc3589->regulators[i],
431 event, NULL);373 event, NULL);
374 regulator_unlock(ltc3589->regulators[i]);
375 }
432 }376 }
433 377
434 /* Clear warning condition */378 /* Clear warning condition */
@@ -437,33 +381,11 @@ static irqreturn_t ltc3589_isr(int irq, void *dev_id) · 2 unmodified lines
437 return IRQ_HANDLED;381 return IRQ_HANDLED;
438}382}
439 383
440static inline unsigned int ltc3589_scale(unsigned int uV, u32 r1, u32 r2)
441{
442 uint64_t tmp;
443 if (uV == 0)
444 return 0;
445 tmp = (uint64_t)uV * r1;
446 do_div(tmp, r2);
447 return uV + (unsigned int)tmp;
448}
449
450static void ltc3589_apply_fb_voltage_divider(struct ltc3589_regulator *rdesc)
451{
452 struct regulator_desc *desc = &rdesc->desc;
453
454 if (!rdesc->r1 || !rdesc->r2)
455 return;
456
457 desc->min_uV = ltc3589_scale(desc->min_uV, rdesc->r1, rdesc->r2);
458 desc->uV_step = ltc3589_scale(desc->uV_step, rdesc->r1, rdesc->r2);
459 desc->fixed_uV = ltc3589_scale(desc->fixed_uV, rdesc->r1, rdesc->r2);
460}
461
462static int ltc3589_probe(struct i2c_client *client,384static int ltc3589_probe(struct i2c_client *client,
463 const struct i2c_device_id *id)385 const struct i2c_device_id *id)
464{386{
465 struct device *dev = &client->dev;387 struct device *dev = &client->dev;
466 struct ltc3589_regulator *descs;388 struct regulator_desc *descs;
467 struct ltc3589 *ltc3589;389 struct ltc3589 *ltc3589;
468 int i, ret;390 int i, ret;
469 391
@@ -482,11 +404,11 @@ static int ltc3589_probe(struct i2c_client *client, · 12 unmodified lines
482 descs = ltc3589->regulator_descs;404 descs = ltc3589->regulator_descs;
483 memcpy(descs, ltc3589_regulators, sizeof(ltc3589_regulators));405 memcpy(descs, ltc3589_regulators, sizeof(ltc3589_regulators));
484 if (ltc3589->variant == LTC3589) {406 if (ltc3589->variant == LTC3589) {
485 descs[LTC3589_LDO3].desc.fixed_uV = 1800000;407 descs[LTC3589_LDO3].fixed_uV = 1800000;
486 descs[LTC3589_LDO4].desc.volt_table = ltc3589_ldo4;408 descs[LTC3589_LDO4].volt_table = ltc3589_ldo4;
487 } else {409 } else {
488 descs[LTC3589_LDO3].desc.fixed_uV = 2800000;410 descs[LTC3589_LDO3].fixed_uV = 2800000;
489 descs[LTC3589_LDO4].desc.volt_table = ltc3589_12_ldo4;411 descs[LTC3589_LDO4].volt_table = ltc3589_12_ldo4;
490 }412 }
491 413
492 ltc3589->regmap = devm_regmap_init_i2c(client, &ltc3589_regmap_config);414 ltc3589->regmap = devm_regmap_init_i2c(client, &ltc3589_regmap_config);
@@ -496,25 +418,12 @@ static int ltc3589_probe(struct i2c_client *client, · 3 unmodified lines
496 return ret;418 return ret;
497 }419 }
498 420
499 ret = ltc3589_parse_regulators_dt(ltc3589);
500 if (ret)
501 return ret;
502
503 for (i = 0; i < LTC3589_NUM_REGULATORS; i++) {421 for (i = 0; i < LTC3589_NUM_REGULATORS; i++) {
504 struct ltc3589_regulator *rdesc = &ltc3589->regulator_descs[i];422 struct regulator_desc *desc = &ltc3589->regulator_descs[i];
505 struct regulator_desc *desc = &rdesc->desc;
506 struct regulator_init_data *init_data;
507 struct regulator_config config = { };423 struct regulator_config config = { };
508 424
509 init_data = match_init_data(i);
510
511 if (i < LTC3589_LDO3)
512 ltc3589_apply_fb_voltage_divider(rdesc);
513
514 config.dev = dev;425 config.dev = dev;
515 config.init_data = init_data;
516 config.driver_data = ltc3589;426 config.driver_data = ltc3589;
517 config.of_node = match_of_node(i);
518 427
519 ltc3589->regulators[i] = devm_regulator_register(dev, desc,428 ltc3589->regulators[i] = devm_regulator_register(dev, desc,
520 &config);429 &config);
drivers/regulator/ltc3676.c+8−2
@@ -285,17 +285,23 @@ static irqreturn_t ltc3676_isr(int irq, void *dev_id) · 284 unmodified lines
285 if (irqstat & LTC3676_IRQSTAT_THERMAL_WARN) {285 if (irqstat & LTC3676_IRQSTAT_THERMAL_WARN) {
286 dev_warn(dev, "Over-temperature Warning\n");286 dev_warn(dev, "Over-temperature Warning\n");
287 event = REGULATOR_EVENT_OVER_TEMP;287 event = REGULATOR_EVENT_OVER_TEMP;
288 for (i = 0; i < LTC3676_NUM_REGULATORS; i++)288 for (i = 0; i < LTC3676_NUM_REGULATORS; i++) {
289 regulator_lock(ltc3676->regulators[i]);
289 regulator_notifier_call_chain(ltc3676->regulators[i],290 regulator_notifier_call_chain(ltc3676->regulators[i],
290 event, NULL);291 event, NULL);
292 regulator_unlock(ltc3676->regulators[i]);
293 }
291 }294 }
292 295
293 if (irqstat & LTC3676_IRQSTAT_UNDERVOLT_WARN) {296 if (irqstat & LTC3676_IRQSTAT_UNDERVOLT_WARN) {
294 dev_info(dev, "Undervoltage Warning\n");297 dev_info(dev, "Undervoltage Warning\n");
295 event = REGULATOR_EVENT_UNDER_VOLTAGE;298 event = REGULATOR_EVENT_UNDER_VOLTAGE;
296 for (i = 0; i < LTC3676_NUM_REGULATORS; i++)299 for (i = 0; i < LTC3676_NUM_REGULATORS; i++) {
300 regulator_lock(ltc3676->regulators[i]);
297 regulator_notifier_call_chain(ltc3676->regulators[i],301 regulator_notifier_call_chain(ltc3676->regulators[i],
298 event, NULL);302 event, NULL);
303 regulator_unlock(ltc3676->regulators[i]);
304 }
299 }305 }
300 306
301 /* Clear warning condition */307 /* Clear warning condition */
drivers/regulator/max14577-regulator.c+0−55
@@ -155,58 +155,6 @@ static const struct regulator_desc max77836_supported_regulators[] = { · 154 unmodified lines
155 [MAX77836_LDO2] = MAX77836_LDO_REG(2),155 [MAX77836_LDO2] = MAX77836_LDO_REG(2),
156};156};
157 157
158#ifdef CONFIG_OF
159static struct of_regulator_match max14577_regulator_matches[] = {
160 { .name = "SAFEOUT", },
161 { .name = "CHARGER", },
162};
163
164static struct of_regulator_match max77836_regulator_matches[] = {
165 { .name = "SAFEOUT", },
166 { .name = "CHARGER", },
167 { .name = "LDO1", },
168 { .name = "LDO2", },
169};
170
171static inline struct regulator_init_data *match_init_data(int index,
172 enum maxim_device_type dev_type)
173{
174 switch (dev_type) {
175 case MAXIM_DEVICE_TYPE_MAX77836:
176 return max77836_regulator_matches[index].init_data;
177
178 case MAXIM_DEVICE_TYPE_MAX14577:
179 default:
180 return max14577_regulator_matches[index].init_data;
181 }
182}
183
184static inline struct device_node *match_of_node(int index,
185 enum maxim_device_type dev_type)
186{
187 switch (dev_type) {
188 case MAXIM_DEVICE_TYPE_MAX77836:
189 return max77836_regulator_matches[index].of_node;
190
191 case MAXIM_DEVICE_TYPE_MAX14577:
192 default:
193 return max14577_regulator_matches[index].of_node;
194 }
195}
196#else /* CONFIG_OF */
197static inline struct regulator_init_data *match_init_data(int index,
198 enum maxim_device_type dev_type)
199{
200 return NULL;
201}
202
203static inline struct device_node *match_of_node(int index,
204 enum maxim_device_type dev_type)
205{
206 return NULL;
207}
208#endif /* CONFIG_OF */
209
210/**158/**
211 * Registers for regulators of max77836 use different I2C slave addresses so159 * Registers for regulators of max77836 use different I2C slave addresses so
212 * different regmaps must be used for them.160 * different regmaps must be used for them.
@@ -265,9 +213,6 @@ static int max14577_regulator_probe(struct platform_device *pdev) · 52 unmodified lines
265 if (pdata && pdata->regulators) {213 if (pdata && pdata->regulators) {
266 config.init_data = pdata->regulators[i].initdata;214 config.init_data = pdata->regulators[i].initdata;
267 config.of_node = pdata->regulators[i].of_node;215 config.of_node = pdata->regulators[i].of_node;
268 } else {
269 config.init_data = match_init_data(i, dev_type);
270 config.of_node = match_of_node(i, dev_type);
271 }216 }
272 config.regmap = max14577_get_regmap(max14577,217 config.regmap = max14577_get_regmap(max14577,
273 supported_regulators[i].id);218 supported_regulators[i].id);
drivers/regulator/max77650-regulator.c+1−1
@@ -41,7 +41,7 @@ struct max77650_regulator_desc { · 40 unmodified lines
41 unsigned int regB;41 unsigned int regB;
42};42};
43 43
44static const u32 max77651_sbb1_regulator_volt_table[] = {44static const unsigned int max77651_sbb1_regulator_volt_table[] = {
45 2400000, 3200000, 4000000, 4800000,45 2400000, 3200000, 4000000, 4800000,
46 2450000, 3250000, 4050000, 4850000,46 2450000, 3250000, 4050000, 4850000,
47 2500000, 3300000, 4100000, 4900000,47 2500000, 3300000, 4100000, 4900000,
drivers/regulator/max8925-regulator.c+9−67
@@ -159,6 +159,8 @@ static const struct regulator_ops max8925_regulator_ldo_ops = { · 158 unmodified lines
159{ \159{ \
160 .desc = { \160 .desc = { \
161 .name = "SDV" #_id, \161 .name = "SDV" #_id, \
162 .of_match = of_match_ptr("SDV" #_id), \
163 .regulators_node = of_match_ptr("regulators"), \
162 .ops = &max8925_regulator_sdv_ops, \164 .ops = &max8925_regulator_sdv_ops, \
163 .type = REGULATOR_VOLTAGE, \165 .type = REGULATOR_VOLTAGE, \
164 .id = MAX8925_ID_SD##_id, \166 .id = MAX8925_ID_SD##_id, \
@@ -175,6 +177,8 @@ static const struct regulator_ops max8925_regulator_ldo_ops = { · 10 unmodified lines
175{ \177{ \
176 .desc = { \178 .desc = { \
177 .name = "LDO" #_id, \179 .name = "LDO" #_id, \
180 .of_match = of_match_ptr("LDO" #_id), \
181 .regulators_node = of_match_ptr("regulators"), \
178 .ops = &max8925_regulator_ldo_ops, \182 .ops = &max8925_regulator_ldo_ops, \
179 .type = REGULATOR_VOLTAGE, \183 .type = REGULATOR_VOLTAGE, \
180 .id = MAX8925_ID_LDO##_id, \184 .id = MAX8925_ID_LDO##_id, \
@@ -187,34 +191,6 @@ static const struct regulator_ops max8925_regulator_ldo_ops = { · 6 unmodified lines
187 .enable_reg = MAX8925_LDOCTL##_id, \191 .enable_reg = MAX8925_LDOCTL##_id, \
188}192}
189 193
190#ifdef CONFIG_OF
191static struct of_regulator_match max8925_regulator_matches[] = {
192 { .name = "SDV1",},
193 { .name = "SDV2",},
194 { .name = "SDV3",},
195 { .name = "LDO1",},
196 { .name = "LDO2",},
197 { .name = "LDO3",},
198 { .name = "LDO4",},
199 { .name = "LDO5",},
200 { .name = "LDO6",},
201 { .name = "LDO7",},
202 { .name = "LDO8",},
203 { .name = "LDO9",},
204 { .name = "LDO10",},
205 { .name = "LDO11",},
206 { .name = "LDO12",},
207 { .name = "LDO13",},
208 { .name = "LDO14",},
209 { .name = "LDO15",},
210 { .name = "LDO16",},
211 { .name = "LDO17",},
212 { .name = "LDO18",},
213 { .name = "LDO19",},
214 { .name = "LDO20",},
215};
216#endif
217
218static struct max8925_regulator_info max8925_regulator_info[] = {194static struct max8925_regulator_info max8925_regulator_info[] = {
219 MAX8925_SDV(1, 637.5, 1425, 12.5),195 MAX8925_SDV(1, 637.5, 1425, 12.5),
220 MAX8925_SDV(2, 650, 2225, 25),196 MAX8925_SDV(2, 650, 2225, 25),
@@ -242,37 +218,6 @@ static struct max8925_regulator_info max8925_regulator_info[] = { · 21 unmodified lines
242 MAX8925_LDO(20, 750, 3900, 50),218 MAX8925_LDO(20, 750, 3900, 50),
243};219};
244 220
245#ifdef CONFIG_OF
246static int max8925_regulator_dt_init(struct platform_device *pdev,
247 struct regulator_config *config,
248 int ridx)
249{
250 struct device_node *nproot, *np;
251 int rcount;
252
253 nproot = pdev->dev.parent->of_node;
254 if (!nproot)
255 return -ENODEV;
256 np = of_get_child_by_name(nproot, "regulators");
257 if (!np) {
258 dev_err(&pdev->dev, "failed to find regulators node\n");
259 return -ENODEV;
260 }
261
262 rcount = of_regulator_match(&pdev->dev, np,
263 &max8925_regulator_matches[ridx], 1);
264 of_node_put(np);
265 if (rcount < 0)
266 return rcount;
267 config->init_data = max8925_regulator_matches[ridx].init_data;
268 config->of_node = max8925_regulator_matches[ridx].of_node;
269
270 return 0;
271}
272#else
273#define max8925_regulator_dt_init(x, y, z) (-1)
274#endif
275
276static int max8925_regulator_probe(struct platform_device *pdev)221static int max8925_regulator_probe(struct platform_device *pdev)
277{222{
278 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);223 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
@@ -281,7 +226,7 @@ static int max8925_regulator_probe(struct platform_device *pdev) · 2 unmodified lines
281 struct max8925_regulator_info *ri;226 struct max8925_regulator_info *ri;
282 struct resource *res;227 struct resource *res;
283 struct regulator_dev *rdev;228 struct regulator_dev *rdev;
284 int i, regulator_idx;229 int i;
285 230
286 res = platform_get_resource(pdev, IORESOURCE_REG, 0);231 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
287 if (!res) {232 if (!res) {
@@ -290,10 +235,8 @@ static int max8925_regulator_probe(struct platform_device *pdev) · 2 unmodified lines
290 }235 }
291 for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) {236 for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) {
292 ri = &max8925_regulator_info[i];237 ri = &max8925_regulator_info[i];
293 if (ri->vol_reg == res->start) {238 if (ri->vol_reg == res->start)
294 regulator_idx = i;
295 break;239 break;
296 }
297 }240 }
298 241
299 if (i == ARRAY_SIZE(max8925_regulator_info)) {242 if (i == ARRAY_SIZE(max8925_regulator_info)) {
@@ -303,12 +246,11 @@ static int max8925_regulator_probe(struct platform_device *pdev) · 3 unmodified lines
303 }246 }
304 ri->i2c = chip->i2c;247 ri->i2c = chip->i2c;
305 248
306 config.dev = &pdev->dev;249 config.dev = chip->dev;
307 config.driver_data = ri;250 config.driver_data = ri;
308 251
309 if (max8925_regulator_dt_init(pdev, &config, regulator_idx))252 if (pdata)
310 if (pdata)253 config.init_data = pdata;
311 config.init_data = pdata;
312 254
313 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);255 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
314 if (IS_ERR(rdev)) {256 if (IS_ERR(rdev)) {
drivers/regulator/max8998.c+59−241
@@ -33,72 +33,6 @@ struct max8998_data { · 32 unmodified lines
33 unsigned int buck2_idx;33 unsigned int buck2_idx;
34};34};
35 35
36struct voltage_map_desc {
37 int min;
38 int max;
39 int step;
40};
41
42/* Voltage maps in uV*/
43static const struct voltage_map_desc ldo23_voltage_map_desc = {
44 .min = 800000, .step = 50000, .max = 1300000,
45};
46static const struct voltage_map_desc ldo456711_voltage_map_desc = {
47 .min = 1600000, .step = 100000, .max = 3600000,
48};
49static const struct voltage_map_desc ldo8_voltage_map_desc = {
50 .min = 3000000, .step = 100000, .max = 3600000,
51};
52static const struct voltage_map_desc ldo9_voltage_map_desc = {
53 .min = 2800000, .step = 100000, .max = 3100000,
54};
55static const struct voltage_map_desc ldo10_voltage_map_desc = {
56 .min = 950000, .step = 50000, .max = 1300000,
57};
58static const struct voltage_map_desc ldo1213_voltage_map_desc = {
59 .min = 800000, .step = 100000, .max = 3300000,
60};
61static const struct voltage_map_desc ldo1415_voltage_map_desc = {
62 .min = 1200000, .step = 100000, .max = 3300000,
63};
64static const struct voltage_map_desc ldo1617_voltage_map_desc = {
65 .min = 1600000, .step = 100000, .max = 3600000,
66};
67static const struct voltage_map_desc buck12_voltage_map_desc = {
68 .min = 750000, .step = 25000, .max = 1525000,
69};
70static const struct voltage_map_desc buck3_voltage_map_desc = {
71 .min = 1600000, .step = 100000, .max = 3600000,
72};
73static const struct voltage_map_desc buck4_voltage_map_desc = {
74 .min = 800000, .step = 100000, .max = 2300000,
75};
76
77static const struct voltage_map_desc *ldo_voltage_map[] = {
78 NULL,
79 NULL,
80 &ldo23_voltage_map_desc, /* LDO2 */
81 &ldo23_voltage_map_desc, /* LDO3 */
82 &ldo456711_voltage_map_desc, /* LDO4 */
83 &ldo456711_voltage_map_desc, /* LDO5 */
84 &ldo456711_voltage_map_desc, /* LDO6 */
85 &ldo456711_voltage_map_desc, /* LDO7 */
86 &ldo8_voltage_map_desc, /* LDO8 */
87 &ldo9_voltage_map_desc, /* LDO9 */
88 &ldo10_voltage_map_desc, /* LDO10 */
89 &ldo456711_voltage_map_desc, /* LDO11 */
90 &ldo1213_voltage_map_desc, /* LDO12 */
91 &ldo1213_voltage_map_desc, /* LDO13 */
92 &ldo1415_voltage_map_desc, /* LDO14 */
93 &ldo1415_voltage_map_desc, /* LDO15 */
94 &ldo1617_voltage_map_desc, /* LDO16 */
95 &ldo1617_voltage_map_desc, /* LDO17 */
96 &buck12_voltage_map_desc, /* BUCK1 */
97 &buck12_voltage_map_desc, /* BUCK2 */
98 &buck3_voltage_map_desc, /* BUCK3 */
99 &buck4_voltage_map_desc, /* BUCK4 */
100};
101
102static int max8998_get_enable_register(struct regulator_dev *rdev,36static int max8998_get_enable_register(struct regulator_dev *rdev,
103 int *reg, int *shift)37 int *reg, int *shift)
104{38{
@@ -400,7 +334,6 @@ static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev, · 295 unmodified lines
400{334{
401 struct max8998_data *max8998 = rdev_get_drvdata(rdev);335 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
402 struct i2c_client *i2c = max8998->iodev->i2c;336 struct i2c_client *i2c = max8998->iodev->i2c;
403 const struct voltage_map_desc *desc;
404 int buck = rdev_get_id(rdev);337 int buck = rdev_get_id(rdev);
405 u8 val = 0;338 u8 val = 0;
406 int difference, ret;339 int difference, ret;
@@ -408,8 +341,6 @@ static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev, · 1 unmodified line
408 if (buck < MAX8998_BUCK1 || buck > MAX8998_BUCK4)341 if (buck < MAX8998_BUCK1 || buck > MAX8998_BUCK4)
409 return -EINVAL;342 return -EINVAL;
410 343
411 desc = ldo_voltage_map[buck];
412
413 /* Voltage stabilization */344 /* Voltage stabilization */
414 ret = max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val);345 ret = max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val);
415 if (ret)346 if (ret)
@@ -420,14 +351,14 @@ static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev, · 4 unmodified lines
420 if (max8998->iodev->type == TYPE_MAX8998 && !(val & MAX8998_ENRAMP))351 if (max8998->iodev->type == TYPE_MAX8998 && !(val & MAX8998_ENRAMP))
421 return 0;352 return 0;
422 353
423 difference = (new_selector - old_selector) * desc->step / 1000;354 difference = (new_selector - old_selector) * rdev->desc->uV_step / 1000;
424 if (difference > 0)355 if (difference > 0)
425 return DIV_ROUND_UP(difference, (val & 0x0f) + 1);356 return DIV_ROUND_UP(difference, (val & 0x0f) + 1);
426 357
427 return 0;358 return 0;
428}359}
429 360
430static struct regulator_ops max8998_ldo_ops = {361static const struct regulator_ops max8998_ldo_ops = {
431 .list_voltage = regulator_list_voltage_linear,362 .list_voltage = regulator_list_voltage_linear,
432 .map_voltage = regulator_map_voltage_linear,363 .map_voltage = regulator_map_voltage_linear,
433 .is_enabled = max8998_ldo_is_enabled,364 .is_enabled = max8998_ldo_is_enabled,
@@ -437,7 +368,7 @@ static struct regulator_ops max8998_ldo_ops = { · 3 unmodified lines
437 .set_voltage_sel = max8998_set_voltage_ldo_sel,368 .set_voltage_sel = max8998_set_voltage_ldo_sel,
438};369};
439 370
440static struct regulator_ops max8998_buck_ops = {371static const struct regulator_ops max8998_buck_ops = {
441 .list_voltage = regulator_list_voltage_linear,372 .list_voltage = regulator_list_voltage_linear,
442 .map_voltage = regulator_map_voltage_linear,373 .map_voltage = regulator_map_voltage_linear,
443 .is_enabled = max8998_ldo_is_enabled,374 .is_enabled = max8998_ldo_is_enabled,
@@ -448,164 +379,59 @@ static struct regulator_ops max8998_buck_ops = { · 4 unmodified lines
448 .set_voltage_time_sel = max8998_set_voltage_buck_time_sel,379 .set_voltage_time_sel = max8998_set_voltage_buck_time_sel,
449};380};
450 381
451static struct regulator_ops max8998_others_ops = {382static const struct regulator_ops max8998_others_ops = {
452 .is_enabled = max8998_ldo_is_enabled,383 .is_enabled = max8998_ldo_is_enabled,
453 .enable = max8998_ldo_enable,384 .enable = max8998_ldo_enable,
454 .disable = max8998_ldo_disable,385 .disable = max8998_ldo_disable,
455};386};
456 387
457static struct regulator_desc regulators[] = {388#define MAX8998_LINEAR_REG(_name, _ops, _min, _step, _max) \
458 {389 { \
459 .name = "LDO2",390 .name = #_name, \
460 .id = MAX8998_LDO2,391 .id = MAX8998_##_name, \
461 .ops = &max8998_ldo_ops,392 .ops = _ops, \
462 .type = REGULATOR_VOLTAGE,393 .min_uV = (_min), \
463 .owner = THIS_MODULE,394 .uV_step = (_step), \
464 }, {395 .n_voltages = ((_max) - (_min)) / (_step) + 1, \
465 .name = "LDO3",396 .type = REGULATOR_VOLTAGE, \
466 .id = MAX8998_LDO3,397 .owner = THIS_MODULE, \
467 .ops = &max8998_ldo_ops,
468 .type = REGULATOR_VOLTAGE,
469 .owner = THIS_MODULE,
470 }, {
471 .name = "LDO4",
472 .id = MAX8998_LDO4,
473 .ops = &max8998_ldo_ops,
474 .type = REGULATOR_VOLTAGE,
475 .owner = THIS_MODULE,
476 }, {
477 .name = "LDO5",
478 .id = MAX8998_LDO5,
479 .ops = &max8998_ldo_ops,
480 .type = REGULATOR_VOLTAGE,
481 .owner = THIS_MODULE,
482 }, {
483 .name = "LDO6",
484 .id = MAX8998_LDO6,
485 .ops = &max8998_ldo_ops,
486 .type = REGULATOR_VOLTAGE,
487 .owner = THIS_MODULE,
488 }, {
489 .name = "LDO7",
490 .id = MAX8998_LDO7,
491 .ops = &max8998_ldo_ops,
492 .type = REGULATOR_VOLTAGE,
493 .owner = THIS_MODULE,
494 }, {
495 .name = "LDO8",
496 .id = MAX8998_LDO8,
497 .ops = &max8998_ldo_ops,
498 .type = REGULATOR_VOLTAGE,
499 .owner = THIS_MODULE,
500 }, {
501 .name = "LDO9",
502 .id = MAX8998_LDO9,
503 .ops = &max8998_ldo_ops,
504 .type = REGULATOR_VOLTAGE,
505 .owner = THIS_MODULE,
506 }, {
507 .name = "LDO10",
508 .id = MAX8998_LDO10,
509 .ops = &max8998_ldo_ops,
510 .type = REGULATOR_VOLTAGE,
511 .owner = THIS_MODULE,
512 }, {
513 .name = "LDO11",
514 .id = MAX8998_LDO11,
515 .ops = &max8998_ldo_ops,
516 .type = REGULATOR_VOLTAGE,
517 .owner = THIS_MODULE,
518 }, {
519 .name = "LDO12",
520 .id = MAX8998_LDO12,
521 .ops = &max8998_ldo_ops,
522 .type = REGULATOR_VOLTAGE,
523 .owner = THIS_MODULE,
524 }, {
525 .name = "LDO13",
526 .id = MAX8998_LDO13,
527 .ops = &max8998_ldo_ops,
528 .type = REGULATOR_VOLTAGE,
529 .owner = THIS_MODULE,
530 }, {
531 .name = "LDO14",
532 .id = MAX8998_LDO14,
533 .ops = &max8998_ldo_ops,
534 .type = REGULATOR_VOLTAGE,
535 .owner = THIS_MODULE,
536 }, {
537 .name = "LDO15",
538 .id = MAX8998_LDO15,
539 .ops = &max8998_ldo_ops,
540 .type = REGULATOR_VOLTAGE,
541 .owner = THIS_MODULE,
542 }, {
543 .name = "LDO16",
544 .id = MAX8998_LDO16,
545 .ops = &max8998_ldo_ops,
546 .type = REGULATOR_VOLTAGE,
547 .owner = THIS_MODULE,
548 }, {
549 .name = "LDO17",
550 .id = MAX8998_LDO17,
551 .ops = &max8998_ldo_ops,
552 .type = REGULATOR_VOLTAGE,
553 .owner = THIS_MODULE,
554 }, {
555 .name = "BUCK1",
556 .id = MAX8998_BUCK1,
557 .ops = &max8998_buck_ops,
558 .type = REGULATOR_VOLTAGE,
559 .owner = THIS_MODULE,
560 }, {
561 .name = "BUCK2",
562 .id = MAX8998_BUCK2,
563 .ops = &max8998_buck_ops,
564 .type = REGULATOR_VOLTAGE,
565 .owner = THIS_MODULE,
566 }, {
567 .name = "BUCK3",
568 .id = MAX8998_BUCK3,
569 .ops = &max8998_buck_ops,
570 .type = REGULATOR_VOLTAGE,
571 .owner = THIS_MODULE,
572 }, {
573 .name = "BUCK4",
574 .id = MAX8998_BUCK4,
575 .ops = &max8998_buck_ops,
576 .type = REGULATOR_VOLTAGE,
577 .owner = THIS_MODULE,
578 }, {
579 .name = "EN32KHz-AP",
580 .id = MAX8998_EN32KHZ_AP,
581 .ops = &max8998_others_ops,
582 .type = REGULATOR_VOLTAGE,
583 .owner = THIS_MODULE,
584 }, {
585 .name = "EN32KHz-CP",
586 .id = MAX8998_EN32KHZ_CP,
587 .ops = &max8998_others_ops,
588 .type = REGULATOR_VOLTAGE,
589 .owner = THIS_MODULE,
590 }, {
591 .name = "ENVICHG",
592 .id = MAX8998_ENVICHG,
593 .ops = &max8998_others_ops,
594 .type = REGULATOR_VOLTAGE,
595 .owner = THIS_MODULE,
596 }, {
597 .name = "ESAFEOUT1",
598 .id = MAX8998_ESAFEOUT1,
599 .ops = &max8998_others_ops,
600 .type = REGULATOR_VOLTAGE,
601 .owner = THIS_MODULE,
602 }, {
603 .name = "ESAFEOUT2",
604 .id = MAX8998_ESAFEOUT2,
605 .ops = &max8998_others_ops,
606 .type = REGULATOR_VOLTAGE,
607 .owner = THIS_MODULE,
608 }398 }
399
400#define MAX8998_OTHERS_REG(_name, _id) \
401 { \
402 .name = #_name, \
403 .id = _id, \
404 .ops = &max8998_others_ops, \
405 .type = REGULATOR_VOLTAGE, \
406 .owner = THIS_MODULE, \
407 }
408
409static const struct regulator_desc regulators[] = {
410 MAX8998_LINEAR_REG(LDO2, &max8998_ldo_ops, 800000, 50000, 1300000),
411 MAX8998_LINEAR_REG(LDO3, &max8998_ldo_ops, 800000, 50000, 1300000),
412 MAX8998_LINEAR_REG(LDO4, &max8998_ldo_ops, 1600000, 100000, 3600000),
413 MAX8998_LINEAR_REG(LDO5, &max8998_ldo_ops, 1600000, 100000, 3600000),
414 MAX8998_LINEAR_REG(LDO6, &max8998_ldo_ops, 1600000, 100000, 3600000),
415 MAX8998_LINEAR_REG(LDO7, &max8998_ldo_ops, 1600000, 100000, 3600000),
416 MAX8998_LINEAR_REG(LDO8, &max8998_ldo_ops, 3000000, 100000, 3600000),
417 MAX8998_LINEAR_REG(LDO9, &max8998_ldo_ops, 2800000, 100000, 3100000),
418 MAX8998_LINEAR_REG(LDO10, &max8998_ldo_ops, 950000, 50000, 1300000),
419 MAX8998_LINEAR_REG(LDO11, &max8998_ldo_ops, 1600000, 100000, 3600000),
420 MAX8998_LINEAR_REG(LDO12, &max8998_ldo_ops, 800000, 100000, 3300000),
421 MAX8998_LINEAR_REG(LDO13, &max8998_ldo_ops, 800000, 100000, 3300000),
422 MAX8998_LINEAR_REG(LDO14, &max8998_ldo_ops, 1200000, 100000, 3300000),
423 MAX8998_LINEAR_REG(LDO15, &max8998_ldo_ops, 1200000, 100000, 3300000),
424 MAX8998_LINEAR_REG(LDO16, &max8998_ldo_ops, 1600000, 100000, 3600000),
425 MAX8998_LINEAR_REG(LDO17, &max8998_ldo_ops, 1600000, 100000, 3600000),
426 MAX8998_LINEAR_REG(BUCK1, &max8998_buck_ops, 750000, 25000, 1525000),
427 MAX8998_LINEAR_REG(BUCK2, &max8998_buck_ops, 750000, 25000, 1525000),
428 MAX8998_LINEAR_REG(BUCK3, &max8998_buck_ops, 1600000, 100000, 3600000),
429 MAX8998_LINEAR_REG(BUCK4, &max8998_buck_ops, 800000, 100000, 2300000),
430 MAX8998_OTHERS_REG(EN32KHz-AP, MAX8998_EN32KHZ_AP),
431 MAX8998_OTHERS_REG(EN32KHz-CP, MAX8998_EN32KHZ_CP),
432 MAX8998_OTHERS_REG(ENVICHG, MAX8998_ENVICHG),
433 MAX8998_OTHERS_REG(ESAFEOUT1, MAX8998_ESAFEOUT1),
434 MAX8998_OTHERS_REG(ESAFEOUT2, MAX8998_ESAFEOUT2),
609};435};
610 436
611static int max8998_pmic_dt_parse_dvs_gpio(struct max8998_dev *iodev,437static int max8998_pmic_dt_parse_dvs_gpio(struct max8998_dev *iodev,
@@ -796,9 +622,11 @@ static int max8998_pmic_probe(struct platform_device *pdev) · 184 unmodified lines
796 622
797 /* Set predefined values for BUCK1 registers */623 /* Set predefined values for BUCK1 registers */
798 for (v = 0; v < ARRAY_SIZE(pdata->buck1_voltage); ++v) {624 for (v = 0; v < ARRAY_SIZE(pdata->buck1_voltage); ++v) {
625 int index = MAX8998_BUCK1 - MAX8998_LDO2;
626
799 i = 0;627 i = 0;
800 while (buck12_voltage_map_desc.min +628 while (regulators[index].min_uV +
801 buck12_voltage_map_desc.step*i629 regulators[index].uV_step * i
802 < pdata->buck1_voltage[v])630 < pdata->buck1_voltage[v])
803 i++;631 i++;
804 632
@@ -824,9 +652,11 @@ static int max8998_pmic_probe(struct platform_device *pdev) · 19 unmodified lines
824 652
825 /* Set predefined values for BUCK2 registers */653 /* Set predefined values for BUCK2 registers */
826 for (v = 0; v < ARRAY_SIZE(pdata->buck2_voltage); ++v) {654 for (v = 0; v < ARRAY_SIZE(pdata->buck2_voltage); ++v) {
655 int index = MAX8998_BUCK2 - MAX8998_LDO2;
656
827 i = 0;657 i = 0;
828 while (buck12_voltage_map_desc.min +658 while (regulators[index].min_uV +
829 buck12_voltage_map_desc.step*i659 regulators[index].uV_step * i
830 < pdata->buck2_voltage[v])660 < pdata->buck2_voltage[v])
831 i++;661 i++;
832 662
@@ -839,18 +669,7 @@ static int max8998_pmic_probe(struct platform_device *pdev) · 6 unmodified lines
839 }669 }
840 670
841 for (i = 0; i < pdata->num_regulators; i++) {671 for (i = 0; i < pdata->num_regulators; i++) {
842 const struct voltage_map_desc *desc;672 int index = pdata->regulators[i].id - MAX8998_LDO2;
843 int id = pdata->regulators[i].id;
844 int index = id - MAX8998_LDO2;
845
846 desc = ldo_voltage_map[id];
847 if (desc && regulators[index].ops != &max8998_others_ops) {
848 int count = (desc->max - desc->min) / desc->step + 1;
849
850 regulators[index].n_voltages = count;
851 regulators[index].min_uV = desc->min;
852 regulators[index].uV_step = desc->step;
853 }
854 673
855 config.dev = max8998->dev;674 config.dev = max8998->dev;
856 config.of_node = pdata->regulators[i].reg_node;675 config.of_node = pdata->regulators[i].reg_node;
@@ -867,7 +686,6 @@ static int max8998_pmic_probe(struct platform_device *pdev) · 10 unmodified lines
867 }686 }
868 }687 }
869 688
870
871 return 0;689 return 0;
872}690}
873 691
drivers/regulator/mcp16502.c+22−45
@@ -119,8 +119,6 @@ enum { · 118 unmodified lines
119 * @lpm: LPM GPIO descriptor119 * @lpm: LPM GPIO descriptor
120 */120 */
121struct mcp16502 {121struct mcp16502 {
122 struct regulator_dev *rdev[NUM_REGULATORS];
123 struct regmap *rmap;
124 struct gpio_desc *lpm;122 struct gpio_desc *lpm;
125};123};
126 124
@@ -179,13 +177,12 @@ static unsigned int mcp16502_get_mode(struct regulator_dev *rdev) · 52 unmodified lines
179{177{
180 unsigned int val;178 unsigned int val;
181 int ret, reg;179 int ret, reg;
182 struct mcp16502 *mcp = rdev_get_drvdata(rdev);
183 180
184 reg = mcp16502_get_reg(rdev, MCP16502_OPMODE_ACTIVE);181 reg = mcp16502_get_reg(rdev, MCP16502_OPMODE_ACTIVE);
185 if (reg < 0)182 if (reg < 0)
186 return reg;183 return reg;
187 184
188 ret = regmap_read(mcp->rmap, reg, &val);185 ret = regmap_read(rdev->regmap, reg, &val);
189 if (ret)186 if (ret)
190 return ret;187 return ret;
191 188
@@ -211,7 +208,6 @@ static int _mcp16502_set_mode(struct regulator_dev *rdev, unsigned int mode, · 19 unmodified lines
211{208{
212 int val;209 int val;
213 int reg;210 int reg;
214 struct mcp16502 *mcp = rdev_get_drvdata(rdev);
215 211
216 reg = mcp16502_get_reg(rdev, op_mode);212 reg = mcp16502_get_reg(rdev, op_mode);
217 if (reg < 0)213 if (reg < 0)
@@ -228,7 +224,7 @@ static int _mcp16502_set_mode(struct regulator_dev *rdev, unsigned int mode, · 10 unmodified lines
228 return -EINVAL;224 return -EINVAL;
229 }225 }
230 226
231 reg = regmap_update_bits(mcp->rmap, reg, MCP16502_MODE, val);227 reg = regmap_update_bits(rdev->regmap, reg, MCP16502_MODE, val);
232 return reg;228 return reg;
233}229}
234 230
@@ -247,9 +243,8 @@ static int mcp16502_get_status(struct regulator_dev *rdev) · 12 unmodified lines
247{243{
248 int ret;244 int ret;
249 unsigned int val;245 unsigned int val;
250 struct mcp16502 *mcp = rdev_get_drvdata(rdev);
251 246
252 ret = regmap_read(mcp->rmap, MCP16502_STAT_BASE(rdev_get_id(rdev)),247 ret = regmap_read(rdev->regmap, MCP16502_STAT_BASE(rdev_get_id(rdev)),
253 &val);248 &val);
254 if (ret)249 if (ret)
255 return ret;250 return ret;
@@ -290,7 +285,6 @@ static int mcp16502_suspend_get_target_reg(struct regulator_dev *rdev) · 34 unmodified lines
290 */285 */
291static int mcp16502_set_suspend_voltage(struct regulator_dev *rdev, int uV)286static int mcp16502_set_suspend_voltage(struct regulator_dev *rdev, int uV)
292{287{
293 struct mcp16502 *mcp = rdev_get_drvdata(rdev);
294 int sel = regulator_map_voltage_linear_range(rdev, uV, uV);288 int sel = regulator_map_voltage_linear_range(rdev, uV, uV);
295 int reg = mcp16502_suspend_get_target_reg(rdev);289 int reg = mcp16502_suspend_get_target_reg(rdev);
296 290
@@ -300,7 +294,7 @@ static int mcp16502_set_suspend_voltage(struct regulator_dev *rdev, int uV) · 3 unmodified lines
300 if (reg < 0)294 if (reg < 0)
301 return reg;295 return reg;
302 296
303 return regmap_update_bits(mcp->rmap, reg, MCP16502_VSEL, sel);297 return regmap_update_bits(rdev->regmap, reg, MCP16502_VSEL, sel);
304}298}
305 299
306/*300/*
@@ -328,13 +322,12 @@ static int mcp16502_set_suspend_mode(struct regulator_dev *rdev, · 21 unmodified lines
328 */322 */
329static int mcp16502_set_suspend_enable(struct regulator_dev *rdev)323static int mcp16502_set_suspend_enable(struct regulator_dev *rdev)
330{324{
331 struct mcp16502 *mcp = rdev_get_drvdata(rdev);
332 int reg = mcp16502_suspend_get_target_reg(rdev);325 int reg = mcp16502_suspend_get_target_reg(rdev);
333 326
334 if (reg < 0)327 if (reg < 0)
335 return reg;328 return reg;
336 329
337 return regmap_update_bits(mcp->rmap, reg, MCP16502_EN, MCP16502_EN);330 return regmap_update_bits(rdev->regmap, reg, MCP16502_EN, MCP16502_EN);
338}331}
339 332
340/*333/*
@@ -342,13 +335,12 @@ static int mcp16502_set_suspend_enable(struct regulator_dev *rdev) · 1 unmodified line
342 */335 */
343static int mcp16502_set_suspend_disable(struct regulator_dev *rdev)336static int mcp16502_set_suspend_disable(struct regulator_dev *rdev)
344{337{
345 struct mcp16502 *mcp = rdev_get_drvdata(rdev);
346 int reg = mcp16502_suspend_get_target_reg(rdev);338 int reg = mcp16502_suspend_get_target_reg(rdev);
347 339
348 if (reg < 0)340 if (reg < 0)
349 return reg;341 return reg;
350 342
351 return regmap_update_bits(mcp->rmap, reg, MCP16502_EN, 0);343 return regmap_update_bits(rdev->regmap, reg, MCP16502_EN, 0);
352}344}
353#endif /* CONFIG_SUSPEND */345#endif /* CONFIG_SUSPEND */
354 346
@@ -435,36 +427,15 @@ static const struct regmap_config mcp16502_regmap_config = { · 80 unmodified lines
435 .wr_table = &mcp16502_yes_reg_table,427 .wr_table = &mcp16502_yes_reg_table,
436};428};
437 429
438/*
439 * set_up_regulators() - initialize all regulators
440 */
441static int setup_regulators(struct mcp16502 *mcp, struct device *dev,
442 struct regulator_config config)
443{
444 int i;
445
446 for (i = 0; i < NUM_REGULATORS; i++) {
447 mcp->rdev[i] = devm_regulator_register(dev,
448 &mcp16502_desc[i],
449 &config);
450 if (IS_ERR(mcp->rdev[i])) {
451 dev_err(dev,
452 "failed to register %s regulator %ld\n",
453 mcp16502_desc[i].name, PTR_ERR(mcp->rdev[i]));
454 return PTR_ERR(mcp->rdev[i]);
455 }
456 }
457
458 return 0;
459}
460
461static int mcp16502_probe(struct i2c_client *client,430static int mcp16502_probe(struct i2c_client *client,
462 const struct i2c_device_id *id)431 const struct i2c_device_id *id)
463{432{
464 struct regulator_config config = { };433 struct regulator_config config = { };
434 struct regulator_dev *rdev;
465 struct device *dev;435 struct device *dev;
466 struct mcp16502 *mcp;436 struct mcp16502 *mcp;
467 int ret = 0;437 struct regmap *rmap;
438 int i, ret;
468 439
469 dev = &client->dev;440 dev = &client->dev;
470 config.dev = dev;441 config.dev = dev;
@@ -473,15 +444,15 @@ static int mcp16502_probe(struct i2c_client *client, · 2 unmodified lines
473 if (!mcp)444 if (!mcp)
474 return -ENOMEM;445 return -ENOMEM;
475 446
476 mcp->rmap = devm_regmap_init_i2c(client, &mcp16502_regmap_config);447 rmap = devm_regmap_init_i2c(client, &mcp16502_regmap_config);
477 if (IS_ERR(mcp->rmap)) {448 if (IS_ERR(rmap)) {
478 ret = PTR_ERR(mcp->rmap);449 ret = PTR_ERR(rmap);
479 dev_err(dev, "regmap init failed: %d\n", ret);450 dev_err(dev, "regmap init failed: %d\n", ret);
480 return ret;451 return ret;
481 }452 }
482 453
483 i2c_set_clientdata(client, mcp);454 i2c_set_clientdata(client, mcp);
484 config.regmap = mcp->rmap;455 config.regmap = rmap;
485 config.driver_data = mcp;456 config.driver_data = mcp;
486 457
487 mcp->lpm = devm_gpiod_get(dev, "lpm", GPIOD_OUT_LOW);458 mcp->lpm = devm_gpiod_get(dev, "lpm", GPIOD_OUT_LOW);
@@ -490,9 +461,15 @@ static int mcp16502_probe(struct i2c_client *client, · 2 unmodified lines
490 return PTR_ERR(mcp->lpm);461 return PTR_ERR(mcp->lpm);
491 }462 }
492 463
493 ret = setup_regulators(mcp, dev, config);464 for (i = 0; i < NUM_REGULATORS; i++) {
494 if (ret != 0)465 rdev = devm_regulator_register(dev, &mcp16502_desc[i], &config);
495 return ret;466 if (IS_ERR(rdev)) {
467 dev_err(dev,
468 "failed to register %s regulator %ld\n",
469 mcp16502_desc[i].name, PTR_ERR(rdev));
470 return PTR_ERR(rdev);
471 }
472 }
496 473
497 mcp16502_gpio_set_mode(mcp, MCP16502_OPMODE_ACTIVE);474 mcp16502_gpio_set_mode(mcp, MCP16502_OPMODE_ACTIVE);
498 475
drivers/regulator/mt6311-regulator.c+4−13
@@ -1,16 +1,7 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (c) 2015 MediaTek Inc.2//
3 * Author: Henry Chen <henryc.chen@mediatek.com>3// Copyright (c) 2015 MediaTek Inc.
4 *4// Author: Henry Chen <henryc.chen@mediatek.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14 5
15#include <linux/err.h>6#include <linux/err.h>
16#include <linux/gpio.h>7#include <linux/gpio.h>
drivers/regulator/mt6311-regulator.h+1−9
@@ -1,15 +1,7 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/*2/*
2 * Copyright (c) 2015 MediaTek Inc.3 * Copyright (c) 2015 MediaTek Inc.
3 * Author: Henry Chen <henryc.chen@mediatek.com>4 * Author: Henry Chen <henryc.chen@mediatek.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */5 */
14 6
15#ifndef __MT6311_REGULATOR_H__7#ifndef __MT6311_REGULATOR_H__
drivers/regulator/mt6323-regulator.c+14−18
@@ -1,11 +1,7 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (c) 2016 MediaTek Inc.2//
3 * Author: Chen Zhong <chen.zhong@mediatek.com>3// Copyright (c) 2016 MediaTek Inc.
4 *4// Author: Chen Zhong <chen.zhong@mediatek.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9 5
10#include <linux/module.h>6#include <linux/module.h>
11#include <linux/of.h>7#include <linux/of.h>
@@ -118,43 +114,43 @@ static const struct regulator_linear_range buck_volt_range3[] = { · 106 unmodified lines
118 REGULATOR_LINEAR_RANGE(500000, 0, 0x3f, 50000),114 REGULATOR_LINEAR_RANGE(500000, 0, 0x3f, 50000),
119};115};
120 116
121static const u32 ldo_volt_table1[] = {117static const unsigned int ldo_volt_table1[] = {
122 3300000, 3400000, 3500000, 3600000,118 3300000, 3400000, 3500000, 3600000,
123};119};
124 120
125static const u32 ldo_volt_table2[] = {121static const unsigned int ldo_volt_table2[] = {
126 1500000, 1800000, 2500000, 2800000,122 1500000, 1800000, 2500000, 2800000,
127};123};
128 124
129static const u32 ldo_volt_table3[] = {125static const unsigned int ldo_volt_table3[] = {
130 1800000, 3300000,126 1800000, 3300000,
131};127};
132 128
133static const u32 ldo_volt_table4[] = {129static const unsigned int ldo_volt_table4[] = {
134 3000000, 3300000,130 3000000, 3300000,
135};131};
136 132
137static const u32 ldo_volt_table5[] = {133static const unsigned int ldo_volt_table5[] = {
138 1200000, 1300000, 1500000, 1800000, 2000000, 2800000, 3000000, 3300000,134 1200000, 1300000, 1500000, 1800000, 2000000, 2800000, 3000000, 3300000,
139};135};
140 136
141static const u32 ldo_volt_table6[] = {137static const unsigned int ldo_volt_table6[] = {
142 1200000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 2000000,138 1200000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 2000000,
143};139};
144 140
145static const u32 ldo_volt_table7[] = {141static const unsigned int ldo_volt_table7[] = {
146 1200000, 1300000, 1500000, 1800000,142 1200000, 1300000, 1500000, 1800000,
147};143};
148 144
149static const u32 ldo_volt_table8[] = {145static const unsigned int ldo_volt_table8[] = {
150 1800000, 3000000,146 1800000, 3000000,
151};147};
152 148
153static const u32 ldo_volt_table9[] = {149static const unsigned int ldo_volt_table9[] = {
154 1200000, 1350000, 1500000, 1800000,150 1200000, 1350000, 1500000, 1800000,
155};151};
156 152
157static const u32 ldo_volt_table10[] = {153static const unsigned int ldo_volt_table10[] = {
158 1200000, 1300000, 1500000, 1800000,154 1200000, 1300000, 1500000, 1800000,
159};155};
160 156
drivers/regulator/mt6380-regulator.c+8−17
@@ -1,16 +1,7 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (c) 2017 MediaTek Inc.2//
3 * Author: Chenglin Xu <chenglin.xu@mediatek.com>3// Copyright (c) 2017 MediaTek Inc.
4 *4// Author: Chenglin Xu <chenglin.xu@mediatek.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14 5
15#include <linux/module.h>6#include <linux/module.h>
16#include <linux/of.h>7#include <linux/of.h>
@@ -173,19 +164,19 @@ static const struct regulator_linear_range buck_volt_range3[] = { · 156 unmodified lines
173 REGULATOR_LINEAR_RANGE(1200000, 0, 0x3c, 25000),164 REGULATOR_LINEAR_RANGE(1200000, 0, 0x3c, 25000),
174};165};
175 166
176static const u32 ldo_volt_table1[] = {167static const unsigned int ldo_volt_table1[] = {
177 1400000, 1350000, 1300000, 1250000, 1200000, 1150000, 1100000, 1050000,168 1400000, 1350000, 1300000, 1250000, 1200000, 1150000, 1100000, 1050000,
178};169};
179 170
180static const u32 ldo_volt_table2[] = {171static const unsigned int ldo_volt_table2[] = {
181 2200000, 3300000,172 2200000, 3300000,
182};173};
183 174
184static const u32 ldo_volt_table3[] = {175static const unsigned int ldo_volt_table3[] = {
185 1240000, 1390000, 1540000, 1840000,176 1240000, 1390000, 1540000, 1840000,
186};177};
187 178
188static const u32 ldo_volt_table4[] = {179static const unsigned int ldo_volt_table4[] = {
189 2200000, 3300000,180 2200000, 3300000,
190};181};
191 182
drivers/regulator/mt6397-regulator.c+12−21
@@ -1,16 +1,7 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * Copyright (c) 2014 MediaTek Inc.2//
3 * Author: Flora Fu <flora.fu@mediatek.com>3// Copyright (c) 2014 MediaTek Inc.
4 *4// Author: Flora Fu <flora.fu@mediatek.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14 5
15#include <linux/module.h>6#include <linux/module.h>
16#include <linux/of.h>7#include <linux/of.h>
@@ -123,35 +114,35 @@ static const struct regulator_linear_range buck_volt_range3[] = { · 106 unmodified lines
123 REGULATOR_LINEAR_RANGE(1500000, 0, 0x1f, 20000),114 REGULATOR_LINEAR_RANGE(1500000, 0, 0x1f, 20000),
124};115};
125 116
126static const u32 ldo_volt_table1[] = {117static const unsigned int ldo_volt_table1[] = {
127 1500000, 1800000, 2500000, 2800000,118 1500000, 1800000, 2500000, 2800000,
128};119};
129 120
130static const u32 ldo_volt_table2[] = {121static const unsigned int ldo_volt_table2[] = {
131 1800000, 3300000,122 1800000, 3300000,
132};123};
133 124
134static const u32 ldo_volt_table3[] = {125static const unsigned int ldo_volt_table3[] = {
135 3000000, 3300000,126 3000000, 3300000,
136};127};
137 128
138static const u32 ldo_volt_table4[] = {129static const unsigned int ldo_volt_table4[] = {
139 1220000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 3300000,130 1220000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 3300000,
140};131};
141 132
142static const u32 ldo_volt_table5[] = {133static const unsigned int ldo_volt_table5[] = {
143 1200000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 3300000,134 1200000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 3300000,
144};135};
145 136
146static const u32 ldo_volt_table5_v2[] = {137static const unsigned int ldo_volt_table5_v2[] = {
147 1200000, 1000000, 1500000, 1800000, 2500000, 2800000, 3000000, 3300000,138 1200000, 1000000, 1500000, 1800000, 2500000, 2800000, 3000000, 3300000,
148};139};
149 140
150static const u32 ldo_volt_table6[] = {141static const unsigned int ldo_volt_table6[] = {
151 1200000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 2000000,142 1200000, 1300000, 1500000, 1800000, 2500000, 2800000, 3000000, 2000000,
152};143};
153 144
154static const u32 ldo_volt_table7[] = {145static const unsigned int ldo_volt_table7[] = {
155 1300000, 1500000, 1800000, 2000000, 2500000, 2800000, 3000000, 3300000,146 1300000, 1500000, 1800000, 2000000, 2500000, 2800000, 3000000, 3300000,
156};147};
157 148
drivers/regulator/of_regulator.c+3−2
@@ -371,8 +371,9 @@ int of_regulator_match(struct device *dev, struct device_node *node, · 370 unmodified lines
371}371}
372EXPORT_SYMBOL_GPL(of_regulator_match);372EXPORT_SYMBOL_GPL(of_regulator_match);
373 373
374struct device_node *regulator_of_get_init_node(struct device *dev,374static struct
375 const struct regulator_desc *desc)375device_node *regulator_of_get_init_node(struct device *dev,
376 const struct regulator_desc *desc)
376{377{
377 struct device_node *search, *child;378 struct device_node *search, *child;
378 const char *name;379 const char *name;
drivers/regulator/palmas-regulator.c+0−12
@@ -991,9 +991,6 @@ static int palmas_ldo_registration(struct palmas_pmic *pmic, · 990 unmodified lines
991 return PTR_ERR(rdev);991 return PTR_ERR(rdev);
992 }992 }
993 993
994 /* Save regulator for cleanup */
995 pmic->rdev[id] = rdev;
996
997 /* Initialise sleep/init values from platform data */994 /* Initialise sleep/init values from platform data */
998 if (pdata) {995 if (pdata) {
999 reg_init = pdata->reg_init[id];996 reg_init = pdata->reg_init[id];
@@ -1101,9 +1098,6 @@ static int tps65917_ldo_registration(struct palmas_pmic *pmic, · 101 unmodified lines
1101 return PTR_ERR(rdev);1098 return PTR_ERR(rdev);
1102 }1099 }
1103 1100
1104 /* Save regulator for cleanup */
1105 pmic->rdev[id] = rdev;
1106
1107 /* Initialise sleep/init values from platform data */1101 /* Initialise sleep/init values from platform data */
1108 if (pdata) {1102 if (pdata) {
1109 reg_init = pdata->reg_init[id];1103 reg_init = pdata->reg_init[id];
@@ -1288,9 +1282,6 @@ static int palmas_smps_registration(struct palmas_pmic *pmic, · 178 unmodified lines
1288 pdev_name);1282 pdev_name);
1289 return PTR_ERR(rdev);1283 return PTR_ERR(rdev);
1290 }1284 }
1291
1292 /* Save regulator for cleanup */
1293 pmic->rdev[id] = rdev;
1294 }1285 }
1295 1286
1296 return 0;1287 return 0;
@@ -1395,9 +1386,6 @@ static int tps65917_smps_registration(struct palmas_pmic *pmic, · 98 unmodified lines
1395 pdev_name);1386 pdev_name);
1396 return PTR_ERR(rdev);1387 return PTR_ERR(rdev);
1397 }1388 }
1398
1399 /* Save regulator for cleanup */
1400 pmic->rdev[id] = rdev;
1401 }1389 }
1402 1390
1403 return 0;1391 return 0;
drivers/regulator/pv88060-regulator.c+8−14
@@ -1,17 +1,7 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * pv88060-regulator.c - Regulator device driver for PV880602//
3 * Copyright (C) 2015 Powerventure Semiconductor Ltd.3// pv88060-regulator.c - Regulator device driver for PV88060
4 *4// Copyright (C) 2015 Powerventure Semiconductor Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15 5
16#include <linux/err.h>6#include <linux/err.h>
17#include <linux/i2c.h>7#include <linux/i2c.h>
@@ -244,9 +234,11 @@ static irqreturn_t pv88060_irq_handler(int irq, void *data) · 226 unmodified lines
244 if (reg_val & PV88060_E_VDD_FLT) {234 if (reg_val & PV88060_E_VDD_FLT) {
245 for (i = 0; i < PV88060_MAX_REGULATORS; i++) {235 for (i = 0; i < PV88060_MAX_REGULATORS; i++) {
246 if (chip->rdev[i] != NULL) {236 if (chip->rdev[i] != NULL) {
237 regulator_lock(chip->rdev[i]);
247 regulator_notifier_call_chain(chip->rdev[i],238 regulator_notifier_call_chain(chip->rdev[i],
248 REGULATOR_EVENT_UNDER_VOLTAGE,239 REGULATOR_EVENT_UNDER_VOLTAGE,
249 NULL);240 NULL);
241 regulator_unlock(chip->rdev[i]);
250 }242 }
251 }243 }
252 244
@@ -261,9 +253,11 @@ static irqreturn_t pv88060_irq_handler(int irq, void *data) · 8 unmodified lines
261 if (reg_val & PV88060_E_OVER_TEMP) {253 if (reg_val & PV88060_E_OVER_TEMP) {
262 for (i = 0; i < PV88060_MAX_REGULATORS; i++) {254 for (i = 0; i < PV88060_MAX_REGULATORS; i++) {
263 if (chip->rdev[i] != NULL) {255 if (chip->rdev[i] != NULL) {
256 regulator_lock(chip->rdev[i]);
264 regulator_notifier_call_chain(chip->rdev[i],257 regulator_notifier_call_chain(chip->rdev[i],
265 REGULATOR_EVENT_OVER_TEMP,258 REGULATOR_EVENT_OVER_TEMP,
266 NULL);259 NULL);
260 regulator_unlock(chip->rdev[i]);
267 }261 }
268 }262 }
269 263
drivers/regulator/pv88060-regulator.h+1−10
@@ -1,16 +1,7 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/*2/*
2 * pv88060-regulator.h - Regulator definitions for PV880603 * pv88060-regulator.h - Regulator definitions for PV88060
3 * Copyright (C) 2015 Powerventure Semiconductor Ltd.4 * Copyright (C) 2015 Powerventure Semiconductor Ltd.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */5 */
15 6
16#ifndef __PV88060_REGISTERS_H__7#ifndef __PV88060_REGISTERS_H__
drivers/regulator/pv88080-regulator.c+8−14
@@ -1,17 +1,7 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * pv88080-regulator.c - Regulator device driver for PV880802//
3 * Copyright (C) 2016 Powerventure Semiconductor Ltd.3// pv88080-regulator.c - Regulator device driver for PV88080
4 *4// Copyright (C) 2016 Powerventure Semiconductor Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15 5
16#include <linux/err.h>6#include <linux/err.h>
17#include <linux/i2c.h>7#include <linux/i2c.h>
@@ -345,9 +335,11 @@ static irqreturn_t pv88080_irq_handler(int irq, void *data) · 327 unmodified lines
345 if (reg_val & PV88080_E_VDD_FLT) {335 if (reg_val & PV88080_E_VDD_FLT) {
346 for (i = 0; i < PV88080_MAX_REGULATORS; i++) {336 for (i = 0; i < PV88080_MAX_REGULATORS; i++) {
347 if (chip->rdev[i] != NULL) {337 if (chip->rdev[i] != NULL) {
338 regulator_lock(chip->rdev[i]);
348 regulator_notifier_call_chain(chip->rdev[i],339 regulator_notifier_call_chain(chip->rdev[i],
349 REGULATOR_EVENT_UNDER_VOLTAGE,340 REGULATOR_EVENT_UNDER_VOLTAGE,
350 NULL);341 NULL);
342 regulator_unlock(chip->rdev[i]);
351 }343 }
352 }344 }
353 345
@@ -362,9 +354,11 @@ static irqreturn_t pv88080_irq_handler(int irq, void *data) · 8 unmodified lines
362 if (reg_val & PV88080_E_OVER_TEMP) {354 if (reg_val & PV88080_E_OVER_TEMP) {
363 for (i = 0; i < PV88080_MAX_REGULATORS; i++) {355 for (i = 0; i < PV88080_MAX_REGULATORS; i++) {
364 if (chip->rdev[i] != NULL) {356 if (chip->rdev[i] != NULL) {
357 regulator_lock(chip->rdev[i]);
365 regulator_notifier_call_chain(chip->rdev[i],358 regulator_notifier_call_chain(chip->rdev[i],
366 REGULATOR_EVENT_OVER_TEMP,359 REGULATOR_EVENT_OVER_TEMP,
367 NULL);360 NULL);
361 regulator_unlock(chip->rdev[i]);
368 }362 }
369 }363 }
370 364
drivers/regulator/pv88080-regulator.h+1−10
@@ -1,16 +1,7 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/*2/*
2 * pv88080-regulator.h - Regulator definitions for PV880803 * pv88080-regulator.h - Regulator definitions for PV88080
3 * Copyright (C) 2016 Powerventure Semiconductor Ltd.4 * Copyright (C) 2016 Powerventure Semiconductor Ltd.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */5 */
15 6
16#ifndef __PV88080_REGISTERS_H__7#ifndef __PV88080_REGISTERS_H__
drivers/regulator/pv88090-regulator.c+8−14
@@ -1,17 +1,7 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * pv88090-regulator.c - Regulator device driver for PV880902//
3 * Copyright (C) 2015 Powerventure Semiconductor Ltd.3// pv88090-regulator.c - Regulator device driver for PV88090
4 *4// Copyright (C) 2015 Powerventure Semiconductor Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15 5
16#include <linux/err.h>6#include <linux/err.h>
17#include <linux/i2c.h>7#include <linux/i2c.h>
@@ -237,9 +227,11 @@ static irqreturn_t pv88090_irq_handler(int irq, void *data) · 219 unmodified lines
237 if (reg_val & PV88090_E_VDD_FLT) {227 if (reg_val & PV88090_E_VDD_FLT) {
238 for (i = 0; i < PV88090_MAX_REGULATORS; i++) {228 for (i = 0; i < PV88090_MAX_REGULATORS; i++) {
239 if (chip->rdev[i] != NULL) {229 if (chip->rdev[i] != NULL) {
230 regulator_lock(chip->rdev[i]);
240 regulator_notifier_call_chain(chip->rdev[i],231 regulator_notifier_call_chain(chip->rdev[i],
241 REGULATOR_EVENT_UNDER_VOLTAGE,232 REGULATOR_EVENT_UNDER_VOLTAGE,
242 NULL);233 NULL);
234 regulator_unlock(chip->rdev[i]);
243 }235 }
244 }236 }
245 237
@@ -254,9 +246,11 @@ static irqreturn_t pv88090_irq_handler(int irq, void *data) · 8 unmodified lines
254 if (reg_val & PV88090_E_OVER_TEMP) {246 if (reg_val & PV88090_E_OVER_TEMP) {
255 for (i = 0; i < PV88090_MAX_REGULATORS; i++) {247 for (i = 0; i < PV88090_MAX_REGULATORS; i++) {
256 if (chip->rdev[i] != NULL) {248 if (chip->rdev[i] != NULL) {
249 regulator_lock(chip->rdev[i]);
257 regulator_notifier_call_chain(chip->rdev[i],250 regulator_notifier_call_chain(chip->rdev[i],
258 REGULATOR_EVENT_OVER_TEMP,251 REGULATOR_EVENT_OVER_TEMP,
259 NULL);252 NULL);
253 regulator_unlock(chip->rdev[i]);
260 }254 }
261 }255 }
262 256
drivers/regulator/pv88090-regulator.h+1−10
@@ -1,16 +1,7 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/*2/*
2 * pv88090-regulator.h - Regulator definitions for PV880903 * pv88090-regulator.h - Regulator definitions for PV88090
3 * Copyright (C) 2015 Powerventure Semiconductor Ltd.4 * Copyright (C) 2015 Powerventure Semiconductor Ltd.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */5 */
15 6
16#ifndef __PV88090_REGISTERS_H__7#ifndef __PV88090_REGISTERS_H__
drivers/regulator/rc5t583-regulator.c+3−22
@@ -47,18 +47,13 @@ struct rc5t583_regulator_info { · 46 unmodified lines
47 struct regulator_desc desc;47 struct regulator_desc desc;
48};48};
49 49
50struct rc5t583_regulator {
51 struct rc5t583_regulator_info *reg_info;
52 struct regulator_dev *rdev;
53};
54
55static int rc5t583_regulator_enable_time(struct regulator_dev *rdev)50static int rc5t583_regulator_enable_time(struct regulator_dev *rdev)
56{51{
57 struct rc5t583_regulator *reg = rdev_get_drvdata(rdev);52 struct rc5t583_regulator_info *reg_info = rdev_get_drvdata(rdev);
58 int vsel = regulator_get_voltage_sel_regmap(rdev);53 int vsel = regulator_get_voltage_sel_regmap(rdev);
59 int curr_uV = regulator_list_voltage_linear(rdev, vsel);54 int curr_uV = regulator_list_voltage_linear(rdev, vsel);
60 55
61 return DIV_ROUND_UP(curr_uV, reg->reg_info->enable_uv_per_us);56 return DIV_ROUND_UP(curr_uV, reg_info->enable_uv_per_us);
62}57}
63 58
64static const struct regulator_ops rc5t583_ops = {59static const struct regulator_ops rc5t583_ops = {
@@ -120,8 +115,6 @@ static int rc5t583_regulator_probe(struct platform_device *pdev) · 55 unmodified lines
120 struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent);115 struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent);
121 struct rc5t583_platform_data *pdata = dev_get_platdata(rc5t583->dev);116 struct rc5t583_platform_data *pdata = dev_get_platdata(rc5t583->dev);
122 struct regulator_config config = { };117 struct regulator_config config = { };
123 struct rc5t583_regulator *reg = NULL;
124 struct rc5t583_regulator *regs;
125 struct regulator_dev *rdev;118 struct regulator_dev *rdev;
126 struct rc5t583_regulator_info *ri;119 struct rc5t583_regulator_info *ri;
127 int ret;120 int ret;
@@ -132,18 +125,8 @@ static int rc5t583_regulator_probe(struct platform_device *pdev) · 4 unmodified lines
132 return -ENODEV;125 return -ENODEV;
133 }126 }
134 127
135 regs = devm_kcalloc(&pdev->dev,
136 RC5T583_REGULATOR_MAX,
137 sizeof(struct rc5t583_regulator),
138 GFP_KERNEL);
139 if (!regs)
140 return -ENOMEM;
141
142
143 for (id = 0; id < RC5T583_REGULATOR_MAX; ++id) {128 for (id = 0; id < RC5T583_REGULATOR_MAX; ++id) {
144 reg = &regs[id];
145 ri = &rc5t583_reg_info[id];129 ri = &rc5t583_reg_info[id];
146 reg->reg_info = ri;
147 130
148 if (ri->deepsleep_id == RC5T583_DS_NONE)131 if (ri->deepsleep_id == RC5T583_DS_NONE)
149 goto skip_ext_pwr_config;132 goto skip_ext_pwr_config;
@@ -163,7 +146,7 @@ static int rc5t583_regulator_probe(struct platform_device *pdev) · 13 unmodified lines
163skip_ext_pwr_config:146skip_ext_pwr_config:
164 config.dev = &pdev->dev;147 config.dev = &pdev->dev;
165 config.init_data = pdata->reg_init_data[id];148 config.init_data = pdata->reg_init_data[id];
166 config.driver_data = reg;149 config.driver_data = ri;
167 config.regmap = rc5t583->regmap;150 config.regmap = rc5t583->regmap;
168 151
169 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);152 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
@@ -172,9 +155,7 @@ skip_ext_pwr_config: · 2 unmodified lines
172 ri->desc.name);155 ri->desc.name);
173 return PTR_ERR(rdev);156 return PTR_ERR(rdev);
174 }157 }
175 reg->rdev = rdev;
176 }158 }
177 platform_set_drvdata(pdev, regs);
178 return 0;159 return 0;
179}160}
180 161
drivers/regulator/rn5t618-regulator.c+4−4
@@ -46,7 +46,7 @@ static const struct regulator_ops rn5t618_reg_ops = { · 45 unmodified lines
46 .vsel_mask = (vmask), \46 .vsel_mask = (vmask), \
47 }47 }
48 48
49static struct regulator_desc rn5t567_regulators[] = {49static const struct regulator_desc rn5t567_regulators[] = {
50 /* DCDC */50 /* DCDC */
51 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),51 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
52 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),52 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
@@ -63,7 +63,7 @@ static struct regulator_desc rn5t567_regulators[] = { · 10 unmodified lines
63 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),63 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
64};64};
65 65
66static struct regulator_desc rn5t618_regulators[] = {66static const struct regulator_desc rn5t618_regulators[] = {
67 /* DCDC */67 /* DCDC */
68 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),68 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
69 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),69 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
@@ -79,7 +79,7 @@ static struct regulator_desc rn5t618_regulators[] = { · 9 unmodified lines
79 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),79 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
80};80};
81 81
82static struct regulator_desc rc5t619_regulators[] = {82static const struct regulator_desc rc5t619_regulators[] = {
83 /* DCDC */83 /* DCDC */
84 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),84 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
85 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),85 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
@@ -107,7 +107,7 @@ static int rn5t618_regulator_probe(struct platform_device *pdev) · 21 unmodified lines
107 struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);107 struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
108 struct regulator_config config = { };108 struct regulator_config config = { };
109 struct regulator_dev *rdev;109 struct regulator_dev *rdev;
110 struct regulator_desc *regulators;110 const struct regulator_desc *regulators;
111 int i;111 int i;
112 int num_regulators = 0;112 int num_regulators = 0;
113 113
drivers/regulator/s2mpa01.c+10−31
@@ -17,10 +17,7 @@ · 16 unmodified lines
17#include <linux/mfd/samsung/core.h>17#include <linux/mfd/samsung/core.h>
18#include <linux/mfd/samsung/s2mpa01.h>18#include <linux/mfd/samsung/s2mpa01.h>
19 19
20#define S2MPA01_REGULATOR_CNT ARRAY_SIZE(regulators)
21
22struct s2mpa01_info {20struct s2mpa01_info {
23 struct of_regulator_match rdata[S2MPA01_REGULATOR_MAX];
24 int ramp_delay24;21 int ramp_delay24;
25 int ramp_delay3;22 int ramp_delay3;
26 int ramp_delay5;23 int ramp_delay5;
@@ -232,6 +229,8 @@ static const struct regulator_ops s2mpa01_buck_ops = { · 205 unmodified lines
232 229
233#define regulator_desc_ldo(num, step) { \230#define regulator_desc_ldo(num, step) { \
234 .name = "LDO"#num, \231 .name = "LDO"#num, \
232 .of_match = of_match_ptr("LDO"#num), \
233 .regulators_node = of_match_ptr("regulators"), \
235 .id = S2MPA01_LDO##num, \234 .id = S2MPA01_LDO##num, \
236 .ops = &s2mpa01_ldo_ops, \235 .ops = &s2mpa01_ldo_ops, \
237 .type = REGULATOR_VOLTAGE, \236 .type = REGULATOR_VOLTAGE, \
@@ -247,6 +246,8 @@ static const struct regulator_ops s2mpa01_buck_ops = { · 9 unmodified lines
247 246
248#define regulator_desc_buck1_4(num) { \247#define regulator_desc_buck1_4(num) { \
249 .name = "BUCK"#num, \248 .name = "BUCK"#num, \
249 .of_match = of_match_ptr("BUCK"#num), \
250 .regulators_node = of_match_ptr("regulators"), \
250 .id = S2MPA01_BUCK##num, \251 .id = S2MPA01_BUCK##num, \
251 .ops = &s2mpa01_buck_ops, \252 .ops = &s2mpa01_buck_ops, \
252 .type = REGULATOR_VOLTAGE, \253 .type = REGULATOR_VOLTAGE, \
@@ -263,6 +264,8 @@ static const struct regulator_ops s2mpa01_buck_ops = { · 10 unmodified lines
263 264
264#define regulator_desc_buck5 { \265#define regulator_desc_buck5 { \
265 .name = "BUCK5", \266 .name = "BUCK5", \
267 .of_match = of_match_ptr("BUCK5"), \
268 .regulators_node = of_match_ptr("regulators"), \
266 .id = S2MPA01_BUCK5, \269 .id = S2MPA01_BUCK5, \
267 .ops = &s2mpa01_buck_ops, \270 .ops = &s2mpa01_buck_ops, \
268 .type = REGULATOR_VOLTAGE, \271 .type = REGULATOR_VOLTAGE, \
@@ -279,6 +282,8 @@ static const struct regulator_ops s2mpa01_buck_ops = { · 10 unmodified lines
279 282
280#define regulator_desc_buck6_10(num, min, step) { \283#define regulator_desc_buck6_10(num, min, step) { \
281 .name = "BUCK"#num, \284 .name = "BUCK"#num, \
285 .of_match = of_match_ptr("BUCK"#num), \
286 .regulators_node = of_match_ptr("regulators"), \
282 .id = S2MPA01_BUCK##num, \287 .id = S2MPA01_BUCK##num, \
283 .ops = &s2mpa01_buck_ops, \288 .ops = &s2mpa01_buck_ops, \
284 .type = REGULATOR_VOLTAGE, \289 .type = REGULATOR_VOLTAGE, \
@@ -336,9 +341,7 @@ static int s2mpa01_pmic_probe(struct platform_device *pdev) · 51 unmodified lines
336{341{
337 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);342 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
338 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev);343 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev);
339 struct device_node *reg_np = NULL;
340 struct regulator_config config = { };344 struct regulator_config config = { };
341 struct of_regulator_match *rdata;
342 struct s2mpa01_info *s2mpa01;345 struct s2mpa01_info *s2mpa01;
343 int i;346 int i;
344 347
@@ -346,39 +349,15 @@ static int s2mpa01_pmic_probe(struct platform_device *pdev) · 1 unmodified line
346 if (!s2mpa01)349 if (!s2mpa01)
347 return -ENOMEM;350 return -ENOMEM;
348 351
349 rdata = s2mpa01->rdata;352 config.dev = iodev->dev;
350 for (i = 0; i < S2MPA01_REGULATOR_CNT; i++)
351 rdata[i].name = regulators[i].name;
352
353 if (iodev->dev->of_node) {
354 reg_np = of_get_child_by_name(iodev->dev->of_node,
355 "regulators");
356 if (!reg_np) {
357 dev_err(&pdev->dev,
358 "could not find regulators sub-node\n");
359 return -EINVAL;
360 }
361
362 of_regulator_match(&pdev->dev, reg_np, rdata,
363 S2MPA01_REGULATOR_MAX);
364 of_node_put(reg_np);
365 }
366
367 platform_set_drvdata(pdev, s2mpa01);
368
369 config.dev = &pdev->dev;
370 config.regmap = iodev->regmap_pmic;353 config.regmap = iodev->regmap_pmic;
371 config.driver_data = s2mpa01;354 config.driver_data = s2mpa01;
372 355
373 for (i = 0; i < S2MPA01_REGULATOR_MAX; i++) {356 for (i = 0; i < S2MPA01_REGULATOR_MAX; i++) {
374 struct regulator_dev *rdev;357 struct regulator_dev *rdev;
358
375 if (pdata)359 if (pdata)
376 config.init_data = pdata->regulators[i].initdata;360 config.init_data = pdata->regulators[i].initdata;
377 else
378 config.init_data = rdata[i].init_data;
379
380 if (reg_np)
381 config.of_node = rdata[i].of_node;
382 361
383 rdev = devm_regulator_register(&pdev->dev,362 rdev = devm_regulator_register(&pdev->dev,
384 &regulators[i], &config);363 &regulators[i], &config);
drivers/regulator/sc2731-regulator.c+1−1
@@ -146,7 +146,7 @@ static const struct regulator_ops sc2731_regu_linear_ops = { · 145 unmodified lines
146 .vsel_mask = vmask, \146 .vsel_mask = vmask, \
147}147}
148 148
149static struct regulator_desc regulators[] = {149static const struct regulator_desc regulators[] = {
150 SC2731_REGU_LINEAR(BUCK_CPU0, SC2731_POWER_PD_SW,150 SC2731_REGU_LINEAR(BUCK_CPU0, SC2731_POWER_PD_SW,
151 SC2731_DCDC_CPU0_PD_MASK, SC2731_DCDC_CPU0_VOL,151 SC2731_DCDC_CPU0_PD_MASK, SC2731_DCDC_CPU0_VOL,
152 SC2731_DCDC_CPU0_VOL_MASK, 3125, 400000, 1996875),152 SC2731_DCDC_CPU0_VOL_MASK, 3125, 400000, 1996875),
drivers/regulator/sky81452-regulator.c+7−19
@@ -1,21 +1,9 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * sky81452-regulator.c SKY81452 regulator driver2//
3 *3// sky81452-regulator.c SKY81452 regulator driver
4 * Copyright 2014 Skyworks Solutions Inc.4//
5 * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>5// Copyright 2014 Skyworks Solutions Inc.
6 *6// Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19 7
20#include <linux/module.h>8#include <linux/module.h>
21#include <linux/kernel.h>9#include <linux/kernel.h>
@@ -34,7 +22,7 @@ · 12 unmodified lines
34#define SKY81452_LEN 0x4022#define SKY81452_LEN 0x40
35#define SKY81452_LOUT 0x1F23#define SKY81452_LOUT 0x1F
36 24
37static struct regulator_ops sky81452_reg_ops = {25static const struct regulator_ops sky81452_reg_ops = {
38 .list_voltage = regulator_list_voltage_linear_range,26 .list_voltage = regulator_list_voltage_linear_range,
39 .map_voltage = regulator_map_voltage_linear_range,27 .map_voltage = regulator_map_voltage_linear_range,
40 .get_voltage_sel = regulator_get_voltage_sel_regmap,28 .get_voltage_sel = regulator_get_voltage_sel_regmap,
drivers/regulator/stm32-pwr.c+186−0
@@ -0,0 +1,186 @@
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (C) STMicroelectronics 2019
3// Authors: Gabriel Fernandez <gabriel.fernandez@st.com>
4// Pascal Paillet <p.paillet@st.com>.
5
6#include <linux/io.h>
7#include <linux/iopoll.h>
8#include <linux/module.h>
9#include <linux/of_address.h>
10#include <linux/of_device.h>
11#include <linux/platform_device.h>
12#include <linux/regulator/driver.h>
13#include <linux/regulator/of_regulator.h>
14
15/*
16 * Registers description
17 */
18#define REG_PWR_CR3 0x0C
19
20#define USB_3_3_EN BIT(24)
21#define USB_3_3_RDY BIT(26)
22#define REG_1_8_EN BIT(28)
23#define REG_1_8_RDY BIT(29)
24#define REG_1_1_EN BIT(30)
25#define REG_1_1_RDY BIT(31)
26
27/* list of supported regulators */
28enum {
29 PWR_REG11,
30 PWR_REG18,
31 PWR_USB33,
32 STM32PWR_REG_NUM_REGS
33};
34
35static u32 ready_mask_table[STM32PWR_REG_NUM_REGS] = {
36 [PWR_REG11] = REG_1_1_RDY,
37 [PWR_REG18] = REG_1_8_RDY,
38 [PWR_USB33] = USB_3_3_RDY,
39};
40
41struct stm32_pwr_reg {
42 void __iomem *base;
43 u32 ready_mask;
44};
45
46static int stm32_pwr_reg_is_ready(struct regulator_dev *rdev)
47{
48 struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
49 u32 val;
50
51 val = readl_relaxed(priv->base + REG_PWR_CR3);
52
53 return (val & priv->ready_mask);
54}
55
56static int stm32_pwr_reg_is_enabled(struct regulator_dev *rdev)
57{
58 struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
59 u32 val;
60
61 val = readl_relaxed(priv->base + REG_PWR_CR3);
62
63 return (val & rdev->desc->enable_mask);
64}
65
66static int stm32_pwr_reg_enable(struct regulator_dev *rdev)
67{
68 struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
69 int ret;
70 u32 val;
71
72 val = readl_relaxed(priv->base + REG_PWR_CR3);
73 val |= rdev->desc->enable_mask;
74 writel_relaxed(val, priv->base + REG_PWR_CR3);
75
76 /* use an arbitrary timeout of 20ms */
77 ret = readx_poll_timeout(stm32_pwr_reg_is_ready, rdev, val, val,
78 100, 20 * 1000);
79 if (ret)
80 dev_err(&rdev->dev, "regulator enable timed out!\n");
81
82 return ret;
83}
84
85static int stm32_pwr_reg_disable(struct regulator_dev *rdev)
86{
87 struct stm32_pwr_reg *priv = rdev_get_drvdata(rdev);
88 int ret;
89 u32 val;
90
91 val = readl_relaxed(priv->base + REG_PWR_CR3);
92 val &= ~rdev->desc->enable_mask;
93 writel_relaxed(val, priv->base + REG_PWR_CR3);
94
95 /* use an arbitrary timeout of 20ms */
96 ret = readx_poll_timeout(stm32_pwr_reg_is_ready, rdev, val, !val,
97 100, 20 * 1000);
98 if (ret)
99 dev_err(&rdev->dev, "regulator disable timed out!\n");
100
101 return ret;
102}
103
104static const struct regulator_ops stm32_pwr_reg_ops = {
105 .enable = stm32_pwr_reg_enable,
106 .disable = stm32_pwr_reg_disable,
107 .is_enabled = stm32_pwr_reg_is_enabled,
108};
109
110#define PWR_REG(_id, _name, _volt, _en, _supply) \
111 [_id] = { \
112 .id = _id, \
113 .name = _name, \
114 .of_match = of_match_ptr(_name), \
115 .n_voltages = 1, \
116 .type = REGULATOR_VOLTAGE, \
117 .fixed_uV = _volt, \
118 .ops = &stm32_pwr_reg_ops, \
119 .enable_mask = _en, \
120 .owner = THIS_MODULE, \
121 .supply_name = _supply, \
122 } \
123
124static const struct regulator_desc stm32_pwr_desc[] = {
125 PWR_REG(PWR_REG11, "reg11", 1100000, REG_1_1_EN, "vdd"),
126 PWR_REG(PWR_REG18, "reg18", 1800000, REG_1_8_EN, "vdd"),
127 PWR_REG(PWR_USB33, "usb33", 3300000, USB_3_3_EN, "vdd_3v3_usbfs"),
128};
129
130static int stm32_pwr_regulator_probe(struct platform_device *pdev)
131{
132 struct device_node *np = pdev->dev.of_node;
133 struct stm32_pwr_reg *priv;
134 void __iomem *base;
135 struct regulator_dev *rdev;
136 struct regulator_config config = { };
137 int i, ret = 0;
138
139 base = of_iomap(np, 0);
140 if (!base) {
141 dev_err(&pdev->dev, "Unable to map IO memory\n");
142 return -ENOMEM;
143 }
144
145 config.dev = &pdev->dev;
146
147 for (i = 0; i < STM32PWR_REG_NUM_REGS; i++) {
148 priv = devm_kzalloc(&pdev->dev, sizeof(struct stm32_pwr_reg),
149 GFP_KERNEL);
150 if (!priv)
151 return -ENOMEM;
152 priv->base = base;
153 priv->ready_mask = ready_mask_table[i];
154 config.driver_data = priv;
155
156 rdev = devm_regulator_register(&pdev->dev,
157 &stm32_pwr_desc[i],
158 &config);
159 if (IS_ERR(rdev)) {
160 ret = PTR_ERR(rdev);
161 dev_err(&pdev->dev,
162 "Failed to register regulator: %d\n", ret);
163 break;
164 }
165 }
166 return ret;
167}
168
169static const struct of_device_id stm32_pwr_of_match[] = {
170 { .compatible = "st,stm32mp1,pwr-reg", },
171 {},
172};
173MODULE_DEVICE_TABLE(of, stm32_pwr_of_match);
174
175static struct platform_driver stm32_pwr_driver = {
176 .probe = stm32_pwr_regulator_probe,
177 .driver = {
178 .name = "stm32-pwr-regulator",
179 .of_match_table = of_match_ptr(stm32_pwr_of_match),
180 },
181};
182module_platform_driver(stm32_pwr_driver);
183
184MODULE_DESCRIPTION("STM32MP1 PWR voltage regulator driver");
185MODULE_AUTHOR("Pascal Paillet <p.paillet@st.com>");
186MODULE_LICENSE("GPL v2");
drivers/regulator/sy8106a-regulator.c+13−27
@@ -22,12 +22,6 @@ · 21 unmodified lines
22 */22 */
23#define SY8106A_GO_BIT BIT(7)23#define SY8106A_GO_BIT BIT(7)
24 24
25struct sy8106a {
26 struct regulator_dev *rdev;
27 struct regmap *regmap;
28 u32 fixed_voltage;
29};
30
31static const struct regmap_config sy8106a_regmap_config = {25static const struct regmap_config sy8106a_regmap_config = {
32 .reg_bits = 8,26 .reg_bits = 8,
33 .val_bits = 8,27 .val_bits = 8,
@@ -70,36 +64,32 @@ static const struct regulator_desc sy8106a_reg = { · 36 unmodified lines
70static int sy8106a_i2c_probe(struct i2c_client *i2c,64static int sy8106a_i2c_probe(struct i2c_client *i2c,
71 const struct i2c_device_id *id)65 const struct i2c_device_id *id)
72{66{
73 struct sy8106a *chip;
74 struct device *dev = &i2c->dev;67 struct device *dev = &i2c->dev;
75 struct regulator_dev *rdev = NULL;68 struct regulator_dev *rdev;
76 struct regulator_config config = { };69 struct regulator_config config = { };
70 struct regmap *regmap;
77 unsigned int reg, vsel;71 unsigned int reg, vsel;
72 u32 fixed_voltage;
78 int error;73 int error;
79 74
80 chip = devm_kzalloc(&i2c->dev, sizeof(struct sy8106a), GFP_KERNEL);
81 if (!chip)
82 return -ENOMEM;
83
84 error = of_property_read_u32(dev->of_node, "silergy,fixed-microvolt",75 error = of_property_read_u32(dev->of_node, "silergy,fixed-microvolt",
85 &chip->fixed_voltage);76 &fixed_voltage);
86 if (error)77 if (error)
87 return error;78 return error;
88 79
89 if (chip->fixed_voltage < SY8106A_MIN_MV * 1000 ||80 if (fixed_voltage < SY8106A_MIN_MV * 1000 ||
90 chip->fixed_voltage > SY8106A_MAX_MV * 1000)81 fixed_voltage > SY8106A_MAX_MV * 1000)
91 return -EINVAL;82 return -EINVAL;
92 83
93 chip->regmap = devm_regmap_init_i2c(i2c, &sy8106a_regmap_config);84 regmap = devm_regmap_init_i2c(i2c, &sy8106a_regmap_config);
94 if (IS_ERR(chip->regmap)) {85 if (IS_ERR(regmap)) {
95 error = PTR_ERR(chip->regmap);86 error = PTR_ERR(regmap);
96 dev_err(dev, "Failed to allocate register map: %d\n", error);87 dev_err(dev, "Failed to allocate register map: %d\n", error);
97 return error;88 return error;
98 }89 }
99 90
100 config.dev = &i2c->dev;91 config.dev = &i2c->dev;
101 config.regmap = chip->regmap;92 config.regmap = regmap;
102 config.driver_data = chip;
103 93
104 config.of_node = dev->of_node;94 config.of_node = dev->of_node;
105 config.init_data = of_get_regulator_init_data(dev, dev->of_node,95 config.init_data = of_get_regulator_init_data(dev, dev->of_node,
@@ -109,15 +99,15 @@ static int sy8106a_i2c_probe(struct i2c_client *i2c, · 3 unmodified lines
109 return -ENOMEM;99 return -ENOMEM;
110 100
111 /* Ensure GO_BIT is enabled when probing */101 /* Ensure GO_BIT is enabled when probing */
112 error = regmap_read(chip->regmap, SY8106A_REG_VOUT1_SEL, &reg);102 error = regmap_read(regmap, SY8106A_REG_VOUT1_SEL, &reg);
113 if (error)103 if (error)
114 return error;104 return error;
115 105
116 if (!(reg & SY8106A_GO_BIT)) {106 if (!(reg & SY8106A_GO_BIT)) {
117 vsel = (chip->fixed_voltage / 1000 - SY8106A_MIN_MV) /107 vsel = (fixed_voltage / 1000 - SY8106A_MIN_MV) /
118 SY8106A_STEP_MV;108 SY8106A_STEP_MV;
119 109
120 error = regmap_write(chip->regmap, SY8106A_REG_VOUT1_SEL,110 error = regmap_write(regmap, SY8106A_REG_VOUT1_SEL,
121 vsel | SY8106A_GO_BIT);111 vsel | SY8106A_GO_BIT);
122 if (error)112 if (error)
123 return error;113 return error;
@@ -131,10 +121,6 @@ static int sy8106a_i2c_probe(struct i2c_client *i2c, · 7 unmodified lines
131 return error;121 return error;
132 }122 }
133 123
134 chip->rdev = rdev;
135
136 i2c_set_clientdata(i2c, chip);
137
138 return 0;124 return 0;
139}125}
140 126
drivers/regulator/tps6507x-regulator.c+20−93
@@ -115,7 +115,6 @@ static struct tps_info tps6507x_pmic_regs[] = { · 114 unmodified lines
115struct tps6507x_pmic {115struct tps6507x_pmic {
116 struct regulator_desc desc[TPS6507X_NUM_REGULATOR];116 struct regulator_desc desc[TPS6507X_NUM_REGULATOR];
117 struct tps6507x_dev *mfd;117 struct tps6507x_dev *mfd;
118 struct regulator_dev *rdev[TPS6507X_NUM_REGULATOR];
119 struct tps_info *info[TPS6507X_NUM_REGULATOR];118 struct tps_info *info[TPS6507X_NUM_REGULATOR];
120 struct mutex io_lock;119 struct mutex io_lock;
121};120};
@@ -349,7 +348,7 @@ static int tps6507x_pmic_set_voltage_sel(struct regulator_dev *dev, · 227 unmodified lines
349 return tps6507x_pmic_reg_write(tps, reg, data);348 return tps6507x_pmic_reg_write(tps, reg, data);
350}349}
351 350
352static struct regulator_ops tps6507x_pmic_ops = {351static const struct regulator_ops tps6507x_pmic_ops = {
353 .is_enabled = tps6507x_pmic_is_enabled,352 .is_enabled = tps6507x_pmic_is_enabled,
354 .enable = tps6507x_pmic_enable,353 .enable = tps6507x_pmic_enable,
355 .disable = tps6507x_pmic_disable,354 .disable = tps6507x_pmic_disable,
@@ -359,66 +358,20 @@ static struct regulator_ops tps6507x_pmic_ops = { · 3 unmodified lines
359 .map_voltage = regulator_map_voltage_ascend,358 .map_voltage = regulator_map_voltage_ascend,
360};359};
361 360
362static struct of_regulator_match tps6507x_matches[] = {361static int tps6507x_pmic_of_parse_cb(struct device_node *np,
363 { .name = "VDCDC1"},362 const struct regulator_desc *desc,
364 { .name = "VDCDC2"},363 struct regulator_config *config)
365 { .name = "VDCDC3"},
366 { .name = "LDO1"},
367 { .name = "LDO2"},
368};
369
370static struct tps6507x_board *tps6507x_parse_dt_reg_data(
371 struct platform_device *pdev,
372 struct of_regulator_match **tps6507x_reg_matches)
373{364{
374 struct tps6507x_board *tps_board;365 struct tps6507x_pmic *tps = config->driver_data;
375 struct device_node *np = pdev->dev.parent->of_node;366 struct tps_info *info = tps->info[desc->id];
376 struct device_node *regulators;367 u32 prop;
377 struct of_regulator_match *matches;368 int ret;
378 struct regulator_init_data *reg_data;
379 int idx = 0, count, ret;
380
381 tps_board = devm_kzalloc(&pdev->dev, sizeof(*tps_board),
382 GFP_KERNEL);
383 if (!tps_board)
384 return NULL;
385
386 regulators = of_get_child_by_name(np, "regulators");
387 if (!regulators) {
388 dev_err(&pdev->dev, "regulator node not found\n");
389 return NULL;
390 }
391
392 count = ARRAY_SIZE(tps6507x_matches);
393 matches = tps6507x_matches;
394
395 ret = of_regulator_match(&pdev->dev, regulators, matches, count);
396 of_node_put(regulators);
397 if (ret < 0) {
398 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
399 ret);
400 return NULL;
401 }
402 369
403 *tps6507x_reg_matches = matches;370 ret = of_property_read_u32(np, "ti,defdcdc_default", &prop);
404 371 if (!ret)
405 reg_data = devm_kzalloc(&pdev->dev, (sizeof(struct regulator_init_data)372 info->defdcdc_default = prop;
406 * TPS6507X_NUM_REGULATOR), GFP_KERNEL);
407 if (!reg_data)
408 return NULL;
409
410 tps_board->tps6507x_pmic_init_data = reg_data;
411
412 for (idx = 0; idx < count; idx++) {
413 if (!matches[idx].init_data || !matches[idx].of_node)
414 continue;
415
416 memcpy(&reg_data[idx], matches[idx].init_data,
417 sizeof(struct regulator_init_data));
418
419 }
420 373
421 return tps_board;374 return 0;
422}375}
423 376
424static int tps6507x_pmic_probe(struct platform_device *pdev)377static int tps6507x_pmic_probe(struct platform_device *pdev)
@@ -426,14 +379,11 @@ static int tps6507x_pmic_probe(struct platform_device *pdev) · 1 unmodified line
426 struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);379 struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
427 struct tps_info *info = &tps6507x_pmic_regs[0];380 struct tps_info *info = &tps6507x_pmic_regs[0];
428 struct regulator_config config = { };381 struct regulator_config config = { };
429 struct regulator_init_data *init_data;382 struct regulator_init_data *init_data = NULL;
430 struct regulator_dev *rdev;383 struct regulator_dev *rdev;
431 struct tps6507x_pmic *tps;384 struct tps6507x_pmic *tps;
432 struct tps6507x_board *tps_board;385 struct tps6507x_board *tps_board;
433 struct of_regulator_match *tps6507x_reg_matches = NULL;
434 int i;386 int i;
435 int error;
436 unsigned int prop;
437 387
438 /**388 /**
439 * tps_board points to pmic related constants389 * tps_board points to pmic related constants
@@ -441,20 +391,8 @@ static int tps6507x_pmic_probe(struct platform_device *pdev) · 1 unmodified line
441 */391 */
442 392
443 tps_board = dev_get_platdata(tps6507x_dev->dev);393 tps_board = dev_get_platdata(tps6507x_dev->dev);
444 if (IS_ENABLED(CONFIG_OF) && !tps_board &&394 if (tps_board)
445 tps6507x_dev->dev->of_node)395 init_data = tps_board->tps6507x_pmic_init_data;
446 tps_board = tps6507x_parse_dt_reg_data(pdev,
447 &tps6507x_reg_matches);
448 if (!tps_board)
449 return -EINVAL;
450
451 /**
452 * init_data points to array of regulator_init structures
453 * coming from the board-evm file.
454 */
455 init_data = tps_board->tps6507x_pmic_init_data;
456 if (!init_data)
457 return -EINVAL;
458 396
459 tps = devm_kzalloc(&pdev->dev, sizeof(*tps), GFP_KERNEL);397 tps = devm_kzalloc(&pdev->dev, sizeof(*tps), GFP_KERNEL);
460 if (!tps)398 if (!tps)
@@ -468,13 +406,16 @@ static int tps6507x_pmic_probe(struct platform_device *pdev) · 7 unmodified lines
468 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) {406 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) {
469 /* Register the regulators */407 /* Register the regulators */
470 tps->info[i] = info;408 tps->info[i] = info;
471 if (init_data->driver_data) {409 if (init_data && init_data->driver_data) {
472 struct tps6507x_reg_platform_data *data =410 struct tps6507x_reg_platform_data *data =
473 init_data->driver_data;411 init_data->driver_data;
474 tps->info[i]->defdcdc_default = data->defdcdc_default;412 info->defdcdc_default = data->defdcdc_default;
475 }413 }
476 414
477 tps->desc[i].name = info->name;415 tps->desc[i].name = info->name;
416 tps->desc[i].of_match = of_match_ptr(info->name);
417 tps->desc[i].regulators_node = of_match_ptr("regulators");
418 tps->desc[i].of_parse_cb = tps6507x_pmic_of_parse_cb;
478 tps->desc[i].id = i;419 tps->desc[i].id = i;
479 tps->desc[i].n_voltages = info->table_len;420 tps->desc[i].n_voltages = info->table_len;
480 tps->desc[i].volt_table = info->table;421 tps->desc[i].volt_table = info->table;
@@ -486,17 +427,6 @@ static int tps6507x_pmic_probe(struct platform_device *pdev) · 5 unmodified lines
486 config.init_data = init_data;427 config.init_data = init_data;
487 config.driver_data = tps;428 config.driver_data = tps;
488 429
489 if (tps6507x_reg_matches) {
490 error = of_property_read_u32(
491 tps6507x_reg_matches[i].of_node,
492 "ti,defdcdc_default", &prop);
493
494 if (!error)
495 tps->info[i]->defdcdc_default = prop;
496
497 config.of_node = tps6507x_reg_matches[i].of_node;
498 }
499
500 rdev = devm_regulator_register(&pdev->dev, &tps->desc[i],430 rdev = devm_regulator_register(&pdev->dev, &tps->desc[i],
501 &config);431 &config);
502 if (IS_ERR(rdev)) {432 if (IS_ERR(rdev)) {
@@ -505,9 +435,6 @@ static int tps6507x_pmic_probe(struct platform_device *pdev) · 2 unmodified lines
505 pdev->name);435 pdev->name);
506 return PTR_ERR(rdev);436 return PTR_ERR(rdev);
507 }437 }
508
509 /* Save regulator for cleanup */
510 tps->rdev[i] = rdev;
511 }438 }
512 439
513 tps6507x_dev->pmic = tps;440 tps6507x_dev->pmic = tps;
drivers/regulator/tps65086-regulator.c+2−2
@@ -90,8 +90,8 @@ static const struct regulator_linear_range tps65086_buck345_25mv_ranges[] = { · 89 unmodified lines
90static const struct regulator_linear_range tps65086_ldoa1_ranges[] = {90static const struct regulator_linear_range tps65086_ldoa1_ranges[] = {
91 REGULATOR_LINEAR_RANGE(1350000, 0x0, 0x0, 0),91 REGULATOR_LINEAR_RANGE(1350000, 0x0, 0x0, 0),
92 REGULATOR_LINEAR_RANGE(1500000, 0x1, 0x7, 100000),92 REGULATOR_LINEAR_RANGE(1500000, 0x1, 0x7, 100000),
93 REGULATOR_LINEAR_RANGE(2300000, 0x8, 0xA, 100000),93 REGULATOR_LINEAR_RANGE(2300000, 0x8, 0xB, 100000),
94 REGULATOR_LINEAR_RANGE(2700000, 0xB, 0xD, 150000),94 REGULATOR_LINEAR_RANGE(2850000, 0xC, 0xD, 150000),
95 REGULATOR_LINEAR_RANGE(3300000, 0xE, 0xE, 0),95 REGULATOR_LINEAR_RANGE(3300000, 0xE, 0xE, 0),
96};96};
97 97
drivers/regulator/tps65132-regulator.c+13−16
@@ -55,10 +55,7 @@ struct tps65132_reg_pdata { · 54 unmodified lines
55 55
56struct tps65132_regulator {56struct tps65132_regulator {
57 struct device *dev;57 struct device *dev;
58 struct regmap *rmap;
59 struct regulator_desc *rdesc[TPS65132_MAX_REGULATORS];
60 struct tps65132_reg_pdata reg_pdata[TPS65132_MAX_REGULATORS];58 struct tps65132_reg_pdata reg_pdata[TPS65132_MAX_REGULATORS];
61 struct regulator_dev *rdev[TPS65132_MAX_REGULATORS];
62};59};
63 60
64static int tps65132_regulator_enable(struct regulator_dev *rdev)61static int tps65132_regulator_enable(struct regulator_dev *rdev)
@@ -120,7 +117,7 @@ static int tps65132_regulator_is_enabled(struct regulator_dev *rdev) · 55 unmodified lines
120 return 1;117 return 1;
121}118}
122 119
123static struct regulator_ops tps65132_regulator_ops = {120static const struct regulator_ops tps65132_regulator_ops = {
124 .enable = tps65132_regulator_enable,121 .enable = tps65132_regulator_enable,
125 .disable = tps65132_regulator_disable,122 .disable = tps65132_regulator_disable,
126 .is_enabled = tps65132_regulator_is_enabled,123 .is_enabled = tps65132_regulator_is_enabled,
@@ -196,7 +193,7 @@ static int tps65132_of_parse_cb(struct device_node *np, · 69 unmodified lines
196 .owner = THIS_MODULE, \193 .owner = THIS_MODULE, \
197 }194 }
198 195
199static struct regulator_desc tps_regs_desc[TPS65132_MAX_REGULATORS] = {196static const struct regulator_desc tps_regs_desc[TPS65132_MAX_REGULATORS] = {
200 TPS65132_REGULATOR_DESC(VPOS, outp),197 TPS65132_REGULATOR_DESC(VPOS, outp),
201 TPS65132_REGULATOR_DESC(VNEG, outn),198 TPS65132_REGULATOR_DESC(VNEG, outn),
202};199};
@@ -225,6 +222,8 @@ static int tps65132_probe(struct i2c_client *client, · 22 unmodified lines
225{222{
226 struct device *dev = &client->dev;223 struct device *dev = &client->dev;
227 struct tps65132_regulator *tps;224 struct tps65132_regulator *tps;
225 struct regulator_dev *rdev;
226 struct regmap *rmap;
228 struct regulator_config config = { };227 struct regulator_config config = { };
229 int id;228 int id;
230 int ret;229 int ret;
@@ -233,9 +232,9 @@ static int tps65132_probe(struct i2c_client *client, · 2 unmodified lines
233 if (!tps)232 if (!tps)
234 return -ENOMEM;233 return -ENOMEM;
235 234
236 tps->rmap = devm_regmap_init_i2c(client, &tps65132_regmap_config);235 rmap = devm_regmap_init_i2c(client, &tps65132_regmap_config);
237 if (IS_ERR(tps->rmap)) {236 if (IS_ERR(rmap)) {
238 ret = PTR_ERR(tps->rmap);237 ret = PTR_ERR(rmap);
239 dev_err(dev, "regmap init failed: %d\n", ret);238 dev_err(dev, "regmap init failed: %d\n", ret);
240 return ret;239 return ret;
241 }240 }
@@ -244,18 +243,16 @@ static int tps65132_probe(struct i2c_client *client, · 2 unmodified lines
244 tps->dev = dev;243 tps->dev = dev;
245 244
246 for (id = 0; id < TPS65132_MAX_REGULATORS; ++id) {245 for (id = 0; id < TPS65132_MAX_REGULATORS; ++id) {
247 tps->rdesc[id] = &tps_regs_desc[id];246 config.regmap = rmap;
248
249 config.regmap = tps->rmap;
250 config.dev = dev;247 config.dev = dev;
251 config.driver_data = tps;248 config.driver_data = tps;
252 249
253 tps->rdev[id] = devm_regulator_register(dev,250 rdev = devm_regulator_register(dev, &tps_regs_desc[id],
254 tps->rdesc[id], &config);251 &config);
255 if (IS_ERR(tps->rdev[id])) {252 if (IS_ERR(rdev)) {
256 ret = PTR_ERR(tps->rdev[id]);253 ret = PTR_ERR(rdev);
257 dev_err(dev, "regulator %s register failed: %d\n",254 dev_err(dev, "regulator %s register failed: %d\n",
258 tps->rdesc[id]->name, ret);255 tps_regs_desc[id].name, ret);
259 return ret;256 return ret;
260 }257 }
261 }258 }
drivers/regulator/tps65217-regulator.c+3−4
@@ -58,8 +58,7 @@ static const unsigned int LDO1_VSEL_table[] = { · 57 unmodified lines
58 58
59static const struct regulator_linear_range tps65217_uv1_ranges[] = {59static const struct regulator_linear_range tps65217_uv1_ranges[] = {
60 REGULATOR_LINEAR_RANGE(900000, 0, 24, 25000),60 REGULATOR_LINEAR_RANGE(900000, 0, 24, 25000),
61 REGULATOR_LINEAR_RANGE(1550000, 25, 30, 50000),61 REGULATOR_LINEAR_RANGE(1550000, 25, 52, 50000),
62 REGULATOR_LINEAR_RANGE(1850000, 31, 52, 50000),
63 REGULATOR_LINEAR_RANGE(3000000, 53, 55, 100000),62 REGULATOR_LINEAR_RANGE(3000000, 53, 55, 100000),
64 REGULATOR_LINEAR_RANGE(3300000, 56, 63, 0),63 REGULATOR_LINEAR_RANGE(3300000, 56, 63, 0),
65};64};
@@ -150,7 +149,7 @@ static int tps65217_pmic_set_suspend_disable(struct regulator_dev *dev) · 84 unmodified lines
150}149}
151 150
152/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */151/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */
153static struct regulator_ops tps65217_pmic_ops = {152static const struct regulator_ops tps65217_pmic_ops = {
154 .is_enabled = regulator_is_enabled_regmap,153 .is_enabled = regulator_is_enabled_regmap,
155 .enable = tps65217_pmic_enable,154 .enable = tps65217_pmic_enable,
156 .disable = tps65217_pmic_disable,155 .disable = tps65217_pmic_disable,
@@ -163,7 +162,7 @@ static struct regulator_ops tps65217_pmic_ops = { · 6 unmodified lines
163};162};
164 163
165/* Operations permitted on LDO1 */164/* Operations permitted on LDO1 */
166static struct regulator_ops tps65217_pmic_ldo1_ops = {165static const struct regulator_ops tps65217_pmic_ldo1_ops = {
167 .is_enabled = regulator_is_enabled_regmap,166 .is_enabled = regulator_is_enabled_regmap,
168 .enable = tps65217_pmic_enable,167 .enable = tps65217_pmic_enable,
169 .disable = tps65217_pmic_disable,168 .disable = tps65217_pmic_disable,
drivers/regulator/tps65218-regulator.c+23−33
@@ -29,7 +29,8 @@ · 28 unmodified lines
29#include <linux/mfd/tps65218.h>29#include <linux/mfd/tps65218.h>
30 30
31#define TPS65218_REGULATOR(_name, _of, _id, _type, _ops, _n, _vr, _vm, _er, \31#define TPS65218_REGULATOR(_name, _of, _id, _type, _ops, _n, _vr, _vm, _er, \
32 _em, _cr, _cm, _lr, _nlr, _delay, _fuv, _sr, _sm) \32 _em, _cr, _cm, _lr, _nlr, _delay, _fuv, _sr, _sm, \
33 _ct, _ncl) \
33 { \34 { \
34 .name = _name, \35 .name = _name, \
35 .of_match = _of, \36 .of_match = _of, \
@@ -42,6 +43,8 @@ · 6 unmodified lines
42 .vsel_mask = _vm, \43 .vsel_mask = _vm, \
43 .csel_reg = _cr, \44 .csel_reg = _cr, \
44 .csel_mask = _cm, \45 .csel_mask = _cm, \
46 .curr_table = _ct, \
47 .n_current_limits = _ncl, \
45 .enable_reg = _er, \48 .enable_reg = _er, \
46 .enable_mask = _em, \49 .enable_mask = _em, \
47 .volt_table = NULL, \50 .volt_table = NULL, \
@@ -162,7 +165,7 @@ static int tps65218_pmic_set_suspend_disable(struct regulator_dev *dev) · 114 unmodified lines
162}165}
163 166
164/* Operations permitted on DCDC1, DCDC2 */167/* Operations permitted on DCDC1, DCDC2 */
165static struct regulator_ops tps65218_dcdc12_ops = {168static const struct regulator_ops tps65218_dcdc12_ops = {
166 .is_enabled = regulator_is_enabled_regmap,169 .is_enabled = regulator_is_enabled_regmap,
167 .enable = tps65218_pmic_enable,170 .enable = tps65218_pmic_enable,
168 .disable = tps65218_pmic_disable,171 .disable = tps65218_pmic_disable,
@@ -176,7 +179,7 @@ static struct regulator_ops tps65218_dcdc12_ops = { · 7 unmodified lines
176};179};
177 180
178/* Operations permitted on DCDC3, DCDC4 and LDO1 */181/* Operations permitted on DCDC3, DCDC4 and LDO1 */
179static struct regulator_ops tps65218_ldo1_dcdc34_ops = {182static const struct regulator_ops tps65218_ldo1_dcdc34_ops = {
180 .is_enabled = regulator_is_enabled_regmap,183 .is_enabled = regulator_is_enabled_regmap,
181 .enable = tps65218_pmic_enable,184 .enable = tps65218_pmic_enable,
182 .disable = tps65218_pmic_disable,185 .disable = tps65218_pmic_disable,
@@ -188,8 +191,7 @@ static struct regulator_ops tps65218_ldo1_dcdc34_ops = { · 5 unmodified lines
188 .set_suspend_disable = tps65218_pmic_set_suspend_disable,191 .set_suspend_disable = tps65218_pmic_set_suspend_disable,
189};192};
190 193
191static const int ls3_currents[] = { 100000, 200000, 500000, 1000000 };194static const unsigned int ls3_currents[] = { 100000, 200000, 500000, 1000000 };
192
193 195
194static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev,196static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev,
195 int lim_uA)197 int lim_uA)
@@ -229,33 +231,17 @@ static int tps65218_pmic_set_current_limit(struct regulator_dev *dev, · 33 unmodified lines
229 TPS65218_PROTECT_L1);231 TPS65218_PROTECT_L1);
230}232}
231 233
232static int tps65218_pmic_get_current_limit(struct regulator_dev *dev)234static const struct regulator_ops tps65218_ls23_ops = {
233{
234 int retval;
235 unsigned int index;
236 struct tps65218 *tps = rdev_get_drvdata(dev);
237
238 retval = regmap_read(tps->regmap, dev->desc->csel_reg, &index);
239 if (retval < 0)
240 return retval;
241
242 index = (index & dev->desc->csel_mask) >>
243 __builtin_ctz(dev->desc->csel_mask);
244
245 return ls3_currents[index];
246}
247
248static struct regulator_ops tps65218_ls23_ops = {
249 .is_enabled = regulator_is_enabled_regmap,235 .is_enabled = regulator_is_enabled_regmap,
250 .enable = tps65218_pmic_enable,236 .enable = tps65218_pmic_enable,
251 .disable = tps65218_pmic_disable,237 .disable = tps65218_pmic_disable,
252 .set_input_current_limit = tps65218_pmic_set_input_current_lim,238 .set_input_current_limit = tps65218_pmic_set_input_current_lim,
253 .set_current_limit = tps65218_pmic_set_current_limit,239 .set_current_limit = tps65218_pmic_set_current_limit,
254 .get_current_limit = tps65218_pmic_get_current_limit,240 .get_current_limit = regulator_get_current_limit_regmap,
255};241};
256 242
257/* Operations permitted on DCDC5, DCDC6 */243/* Operations permitted on DCDC5, DCDC6 */
258static struct regulator_ops tps65218_dcdc56_pmic_ops = {244static const struct regulator_ops tps65218_dcdc56_pmic_ops = {
259 .is_enabled = regulator_is_enabled_regmap,245 .is_enabled = regulator_is_enabled_regmap,
260 .enable = tps65218_pmic_enable,246 .enable = tps65218_pmic_enable,
261 .disable = tps65218_pmic_disable,247 .disable = tps65218_pmic_disable,
@@ -270,53 +256,57 @@ static const struct regulator_desc regulators[] = { · 8 unmodified lines
270 TPS65218_CONTROL_DCDC1_MASK, TPS65218_REG_ENABLE1,256 TPS65218_CONTROL_DCDC1_MASK, TPS65218_REG_ENABLE1,
271 TPS65218_ENABLE1_DC1_EN, 0, 0, dcdc1_dcdc2_ranges,257 TPS65218_ENABLE1_DC1_EN, 0, 0, dcdc1_dcdc2_ranges,
272 2, 4000, 0, TPS65218_REG_SEQ3,258 2, 4000, 0, TPS65218_REG_SEQ3,
273 TPS65218_SEQ3_DC1_SEQ_MASK),259 TPS65218_SEQ3_DC1_SEQ_MASK, NULL, 0),
274 TPS65218_REGULATOR("DCDC2", "regulator-dcdc2", TPS65218_DCDC_2,260 TPS65218_REGULATOR("DCDC2", "regulator-dcdc2", TPS65218_DCDC_2,
275 REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64,261 REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64,
276 TPS65218_REG_CONTROL_DCDC2,262 TPS65218_REG_CONTROL_DCDC2,
277 TPS65218_CONTROL_DCDC2_MASK, TPS65218_REG_ENABLE1,263 TPS65218_CONTROL_DCDC2_MASK, TPS65218_REG_ENABLE1,
278 TPS65218_ENABLE1_DC2_EN, 0, 0, dcdc1_dcdc2_ranges,264 TPS65218_ENABLE1_DC2_EN, 0, 0, dcdc1_dcdc2_ranges,
279 2, 4000, 0, TPS65218_REG_SEQ3,265 2, 4000, 0, TPS65218_REG_SEQ3,
280 TPS65218_SEQ3_DC2_SEQ_MASK),266 TPS65218_SEQ3_DC2_SEQ_MASK, NULL, 0),
281 TPS65218_REGULATOR("DCDC3", "regulator-dcdc3", TPS65218_DCDC_3,267 TPS65218_REGULATOR("DCDC3", "regulator-dcdc3", TPS65218_DCDC_3,
282 REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64,268 REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64,
283 TPS65218_REG_CONTROL_DCDC3,269 TPS65218_REG_CONTROL_DCDC3,
284 TPS65218_CONTROL_DCDC3_MASK, TPS65218_REG_ENABLE1,270 TPS65218_CONTROL_DCDC3_MASK, TPS65218_REG_ENABLE1,
285 TPS65218_ENABLE1_DC3_EN, 0, 0, ldo1_dcdc3_ranges, 2,271 TPS65218_ENABLE1_DC3_EN, 0, 0, ldo1_dcdc3_ranges, 2,
286 0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC3_SEQ_MASK),272 0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC3_SEQ_MASK,
273 NULL, 0),
287 TPS65218_REGULATOR("DCDC4", "regulator-dcdc4", TPS65218_DCDC_4,274 TPS65218_REGULATOR("DCDC4", "regulator-dcdc4", TPS65218_DCDC_4,
288 REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 53,275 REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 53,
289 TPS65218_REG_CONTROL_DCDC4,276 TPS65218_REG_CONTROL_DCDC4,
290 TPS65218_CONTROL_DCDC4_MASK, TPS65218_REG_ENABLE1,277 TPS65218_CONTROL_DCDC4_MASK, TPS65218_REG_ENABLE1,
291 TPS65218_ENABLE1_DC4_EN, 0, 0, dcdc4_ranges, 2,278 TPS65218_ENABLE1_DC4_EN, 0, 0, dcdc4_ranges, 2,
292 0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC4_SEQ_MASK),279 0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC4_SEQ_MASK,
280 NULL, 0),
293 TPS65218_REGULATOR("DCDC5", "regulator-dcdc5", TPS65218_DCDC_5,281 TPS65218_REGULATOR("DCDC5", "regulator-dcdc5", TPS65218_DCDC_5,
294 REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1,282 REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1,
295 -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC5_EN, 0,283 -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC5_EN, 0,
296 0, NULL, 0, 0, 1000000, TPS65218_REG_SEQ5,284 0, NULL, 0, 0, 1000000, TPS65218_REG_SEQ5,
297 TPS65218_SEQ5_DC5_SEQ_MASK),285 TPS65218_SEQ5_DC5_SEQ_MASK, NULL, 0),
298 TPS65218_REGULATOR("DCDC6", "regulator-dcdc6", TPS65218_DCDC_6,286 TPS65218_REGULATOR("DCDC6", "regulator-dcdc6", TPS65218_DCDC_6,
299 REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1,287 REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1,
300 -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC6_EN, 0,288 -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC6_EN, 0,
301 0, NULL, 0, 0, 1800000, TPS65218_REG_SEQ5,289 0, NULL, 0, 0, 1800000, TPS65218_REG_SEQ5,
302 TPS65218_SEQ5_DC6_SEQ_MASK),290 TPS65218_SEQ5_DC6_SEQ_MASK, NULL, 0),
303 TPS65218_REGULATOR("LDO1", "regulator-ldo1", TPS65218_LDO_1,291 TPS65218_REGULATOR("LDO1", "regulator-ldo1", TPS65218_LDO_1,
304 REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64,292 REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64,
305 TPS65218_REG_CONTROL_LDO1,293 TPS65218_REG_CONTROL_LDO1,
306 TPS65218_CONTROL_LDO1_MASK, TPS65218_REG_ENABLE2,294 TPS65218_CONTROL_LDO1_MASK, TPS65218_REG_ENABLE2,
307 TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges,295 TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges,
308 2, 0, 0, TPS65218_REG_SEQ6,296 2, 0, 0, TPS65218_REG_SEQ6,
309 TPS65218_SEQ6_LDO1_SEQ_MASK),297 TPS65218_SEQ6_LDO1_SEQ_MASK, NULL, 0),
310 TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,298 TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,
311 REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,299 REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
312 TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN,300 TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN,
313 TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK,301 TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK,
314 NULL, 0, 0, 0, 0, 0),302 NULL, 0, 0, 0, 0, 0, ls3_currents,
303 ARRAY_SIZE(ls3_currents)),
315 TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3,304 TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3,
316 REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,305 REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
317 TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN,306 TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN,
318 TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK,307 TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK,
319 NULL, 0, 0, 0, 0, 0),308 NULL, 0, 0, 0, 0, 0, ls3_currents,
309 ARRAY_SIZE(ls3_currents)),
320};310};
321 311
322static int tps65218_regulator_probe(struct platform_device *pdev)312static int tps65218_regulator_probe(struct platform_device *pdev)
drivers/regulator/tps6524x-regulator.c+5−6
@@ -137,7 +137,6 @@ struct tps6524x { · 136 unmodified lines
137 struct spi_device *spi;137 struct spi_device *spi;
138 struct mutex lock;138 struct mutex lock;
139 struct regulator_desc desc[N_REGULATORS];139 struct regulator_desc desc[N_REGULATORS];
140 struct regulator_dev *rdev[N_REGULATORS];
141};140};
142 141
143static int __read_reg(struct tps6524x *hw, int reg)142static int __read_reg(struct tps6524x *hw, int reg)
@@ -565,7 +564,7 @@ static int is_supply_enabled(struct regulator_dev *rdev) · 421 unmodified lines
565 return read_field(hw, &info->enable);564 return read_field(hw, &info->enable);
566}565}
567 566
568static struct regulator_ops regulator_ops = {567static const struct regulator_ops regulator_ops = {
569 .is_enabled = is_supply_enabled,568 .is_enabled = is_supply_enabled,
570 .enable = enable_supply,569 .enable = enable_supply,
571 .disable = disable_supply,570 .disable = disable_supply,
@@ -584,6 +583,7 @@ static int pmic_probe(struct spi_device *spi) · 12 unmodified lines
584 const struct supply_info *info = supply_info;583 const struct supply_info *info = supply_info;
585 struct regulator_init_data *init_data;584 struct regulator_init_data *init_data;
586 struct regulator_config config = { };585 struct regulator_config config = { };
586 struct regulator_dev *rdev;
587 int i;587 int i;
588 588
589 init_data = dev_get_platdata(dev);589 init_data = dev_get_platdata(dev);
@@ -616,10 +616,9 @@ static int pmic_probe(struct spi_device *spi) · 26 unmodified lines
616 config.init_data = init_data;616 config.init_data = init_data;
617 config.driver_data = hw;617 config.driver_data = hw;
618 618
619 hw->rdev[i] = devm_regulator_register(dev, &hw->desc[i],619 rdev = devm_regulator_register(dev, &hw->desc[i], &config);
620 &config);620 if (IS_ERR(rdev))
621 if (IS_ERR(hw->rdev[i]))621 return PTR_ERR(rdev);
622 return PTR_ERR(hw->rdev[i]);
623 }622 }
624 623
625 return 0;624 return 0;
drivers/regulator/tps80031-regulator.c+16−32
@@ -1,27 +1,13 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * tps80031-regulator.c -- TI TPS80031 regulator driver.2//
3 *3// tps80031-regulator.c -- TI TPS80031 regulator driver.
4 * Regulator driver for TI TPS80031/TPS80032 Fully Integrated Power4//
5 * Management with Power Path and Battery Charger.5// Regulator driver for TI TPS80031/TPS80032 Fully Integrated Power
6 *6// Management with Power Path and Battery Charger.
7 * Copyright (c) 2012, NVIDIA Corporation.7//
8 *8// Copyright (c) 2012, NVIDIA Corporation.
9 * Author: Laxman Dewangan <ldewangan@nvidia.com>9//
10 *10// Author: Laxman Dewangan <ldewangan@nvidia.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation version 2.
14 *
15 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
16 * whether express or implied; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 * 02111-1307, USA
24 */
25 11
26#include <linux/delay.h>12#include <linux/delay.h>
27#include <linux/err.h>13#include <linux/err.h>
@@ -85,7 +71,6 @@ struct tps80031_regulator_info { · 57 unmodified lines
85 71
86struct tps80031_regulator {72struct tps80031_regulator {
87 struct device *dev;73 struct device *dev;
88 struct regulator_dev *rdev;
89 struct tps80031_regulator_info *rinfo;74 struct tps80031_regulator_info *rinfo;
90 75
91 u8 device_flags;76 u8 device_flags;
@@ -155,7 +140,7 @@ static int tps80031_reg_disable(struct regulator_dev *rdev) · 63 unmodified lines
155}140}
156 141
157/* DCDC voltages for the selector of 58 to 63 */142/* DCDC voltages for the selector of 58 to 63 */
158static int tps80031_dcdc_voltages[4][5] = {143static const int tps80031_dcdc_voltages[4][5] = {
159 { 1350, 1500, 1800, 1900, 2100},144 { 1350, 1500, 1800, 1900, 2100},
160 { 1350, 1500, 1800, 1900, 2100},145 { 1350, 1500, 1800, 1900, 2100},
161 { 2084, 2315, 2778, 2932, 3241},146 { 2084, 2315, 2778, 2932, 3241},
@@ -378,7 +363,7 @@ static int tps80031_vbus_disable(struct regulator_dev *rdev) · 216 unmodified lines
378 return ret;363 return ret;
379}364}
380 365
381static struct regulator_ops tps80031_dcdc_ops = {366static const struct regulator_ops tps80031_dcdc_ops = {
382 .list_voltage = tps80031_dcdc_list_voltage,367 .list_voltage = tps80031_dcdc_list_voltage,
383 .set_voltage_sel = tps80031_dcdc_set_voltage_sel,368 .set_voltage_sel = tps80031_dcdc_set_voltage_sel,
384 .get_voltage_sel = tps80031_dcdc_get_voltage_sel,369 .get_voltage_sel = tps80031_dcdc_get_voltage_sel,
@@ -387,7 +372,7 @@ static struct regulator_ops tps80031_dcdc_ops = { · 2 unmodified lines
387 .is_enabled = tps80031_reg_is_enabled,372 .is_enabled = tps80031_reg_is_enabled,
388};373};
389 374
390static struct regulator_ops tps80031_ldo_ops = {375static const struct regulator_ops tps80031_ldo_ops = {
391 .list_voltage = tps80031_ldo_list_voltage,376 .list_voltage = tps80031_ldo_list_voltage,
392 .map_voltage = tps80031_ldo_map_voltage,377 .map_voltage = tps80031_ldo_map_voltage,
393 .set_voltage_sel = regulator_set_voltage_sel_regmap,378 .set_voltage_sel = regulator_set_voltage_sel_regmap,
@@ -397,18 +382,18 @@ static struct regulator_ops tps80031_ldo_ops = { · 3 unmodified lines
397 .is_enabled = tps80031_reg_is_enabled,382 .is_enabled = tps80031_reg_is_enabled,
398};383};
399 384
400static struct regulator_ops tps80031_vbus_sw_ops = {385static const struct regulator_ops tps80031_vbus_sw_ops = {
401 .list_voltage = regulator_list_voltage_linear,386 .list_voltage = regulator_list_voltage_linear,
402 .enable = tps80031_vbus_enable,387 .enable = tps80031_vbus_enable,
403 .disable = tps80031_vbus_disable,388 .disable = tps80031_vbus_disable,
404 .is_enabled = tps80031_vbus_is_enabled,389 .is_enabled = tps80031_vbus_is_enabled,
405};390};
406 391
407static struct regulator_ops tps80031_vbus_hw_ops = {392static const struct regulator_ops tps80031_vbus_hw_ops = {
408 .list_voltage = regulator_list_voltage_linear,393 .list_voltage = regulator_list_voltage_linear,
409};394};
410 395
411static struct regulator_ops tps80031_ext_reg_ops = {396static const struct regulator_ops tps80031_ext_reg_ops = {
412 .list_voltage = regulator_list_voltage_linear,397 .list_voltage = regulator_list_voltage_linear,
413 .enable = tps80031_reg_enable,398 .enable = tps80031_reg_enable,
414 .disable = tps80031_reg_disable,399 .disable = tps80031_reg_disable,
@@ -736,7 +721,6 @@ static int tps80031_regulator_probe(struct platform_device *pdev) · 321 unmodified lines
736 ri->rinfo->desc.name);721 ri->rinfo->desc.name);
737 return PTR_ERR(rdev);722 return PTR_ERR(rdev);
738 }723 }
739 ri->rdev = rdev;
740 }724 }
741 725
742 platform_set_drvdata(pdev, pmic);726 platform_set_drvdata(pdev, pmic);
drivers/regulator/twl-regulator.c+3−3
@@ -392,7 +392,7 @@ static int twl4030ldo_get_voltage_sel(struct regulator_dev *rdev) · 391 unmodified lines
392 return vsel;392 return vsel;
393}393}
394 394
395static struct regulator_ops twl4030ldo_ops = {395static const struct regulator_ops twl4030ldo_ops = {
396 .list_voltage = twl4030ldo_list_voltage,396 .list_voltage = twl4030ldo_list_voltage,
397 397
398 .set_voltage_sel = twl4030ldo_set_voltage_sel,398 .set_voltage_sel = twl4030ldo_set_voltage_sel,
@@ -430,14 +430,14 @@ static int twl4030smps_get_voltage(struct regulator_dev *rdev) · 31 unmodified lines
430 return vsel * 12500 + 600000;430 return vsel * 12500 + 600000;
431}431}
432 432
433static struct regulator_ops twl4030smps_ops = {433static const struct regulator_ops twl4030smps_ops = {
434 .set_voltage = twl4030smps_set_voltage,434 .set_voltage = twl4030smps_set_voltage,
435 .get_voltage = twl4030smps_get_voltage,435 .get_voltage = twl4030smps_get_voltage,
436};436};
437 437
438/*----------------------------------------------------------------------*/438/*----------------------------------------------------------------------*/
439 439
440static struct regulator_ops twl4030fixed_ops = {440static const struct regulator_ops twl4030fixed_ops = {
441 .list_voltage = regulator_list_voltage_linear,441 .list_voltage = regulator_list_voltage_linear,
442 442
443 .enable = twl4030reg_enable,443 .enable = twl4030reg_enable,
drivers/regulator/vctrl-regulator.c+1−3
@@ -334,10 +334,8 @@ static int vctrl_init_vtable(struct platform_device *pdev) · 333 unmodified lines
334 ctrl_uV = regulator_list_voltage(ctrl_reg, i);334 ctrl_uV = regulator_list_voltage(ctrl_reg, i);
335 335
336 if (ctrl_uV < vrange_ctrl->min_uV ||336 if (ctrl_uV < vrange_ctrl->min_uV ||
337 ctrl_uV > vrange_ctrl->max_uV) {337 ctrl_uV > vrange_ctrl->max_uV)
338 rdesc->n_voltages--;338 rdesc->n_voltages--;
339 continue;
340 }
341 }339 }
342 340
343 if (rdesc->n_voltages == 0) {341 if (rdesc->n_voltages == 0) {
drivers/regulator/vexpress-regulator.c+27−45
@@ -1,15 +1,6 @@
1/*1// SPDX-License-Identifier: GPL-2.0
2 * This program is free software; you can redistribute it and/or modify2//
3 * it under the terms of the GNU General Public License version 2 as3// Copyright (C) 2012 ARM Limited
4 * published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * Copyright (C) 2012 ARM Limited
12 */
13 4
14#define DRVNAME "vexpress-regulator"5#define DRVNAME "vexpress-regulator"
15#define pr_fmt(fmt) DRVNAME ": " fmt6#define pr_fmt(fmt) DRVNAME ": " fmt
@@ -23,17 +14,10 @@ · 7 unmodified lines
23#include <linux/regulator/of_regulator.h>14#include <linux/regulator/of_regulator.h>
24#include <linux/vexpress.h>15#include <linux/vexpress.h>
25 16
26struct vexpress_regulator {
27 struct regulator_desc desc;
28 struct regulator_dev *regdev;
29 struct regmap *regmap;
30};
31
32static int vexpress_regulator_get_voltage(struct regulator_dev *regdev)17static int vexpress_regulator_get_voltage(struct regulator_dev *regdev)
33{18{
34 struct vexpress_regulator *reg = rdev_get_drvdata(regdev);19 unsigned int uV;
35 u32 uV;20 int err = regmap_read(regdev->regmap, 0, &uV);
36 int err = regmap_read(reg->regmap, 0, &uV);
37 21
38 return err ? err : uV;22 return err ? err : uV;
39}23}
@@ -41,60 +25,58 @@ static int vexpress_regulator_get_voltage(struct regulator_dev *regdev) · 1 unmodified line
41static int vexpress_regulator_set_voltage(struct regulator_dev *regdev,25static int vexpress_regulator_set_voltage(struct regulator_dev *regdev,
42 int min_uV, int max_uV, unsigned *selector)26 int min_uV, int max_uV, unsigned *selector)
43{27{
44 struct vexpress_regulator *reg = rdev_get_drvdata(regdev);28 return regmap_write(regdev->regmap, 0, min_uV);
45
46 return regmap_write(reg->regmap, 0, min_uV);
47}29}
48 30
49static struct regulator_ops vexpress_regulator_ops_ro = {31static const struct regulator_ops vexpress_regulator_ops_ro = {
50 .get_voltage = vexpress_regulator_get_voltage,32 .get_voltage = vexpress_regulator_get_voltage,
51};33};
52 34
53static struct regulator_ops vexpress_regulator_ops = {35static const struct regulator_ops vexpress_regulator_ops = {
54 .get_voltage = vexpress_regulator_get_voltage,36 .get_voltage = vexpress_regulator_get_voltage,
55 .set_voltage = vexpress_regulator_set_voltage,37 .set_voltage = vexpress_regulator_set_voltage,
56};38};
57 39
58static int vexpress_regulator_probe(struct platform_device *pdev)40static int vexpress_regulator_probe(struct platform_device *pdev)
59{41{
60 struct vexpress_regulator *reg;42 struct regulator_desc *desc;
61 struct regulator_init_data *init_data;43 struct regulator_init_data *init_data;
62 struct regulator_config config = { };44 struct regulator_config config = { };
45 struct regulator_dev *rdev;
46 struct regmap *regmap;
63 47
64 reg = devm_kzalloc(&pdev->dev, sizeof(*reg), GFP_KERNEL);48 desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL);
65 if (!reg)49 if (!desc)
66 return -ENOMEM;50 return -ENOMEM;
67 51
68 reg->regmap = devm_regmap_init_vexpress_config(&pdev->dev);52 regmap = devm_regmap_init_vexpress_config(&pdev->dev);
69 if (IS_ERR(reg->regmap))53 if (IS_ERR(regmap))
70 return PTR_ERR(reg->regmap);54 return PTR_ERR(regmap);
71 55
72 reg->desc.name = dev_name(&pdev->dev);56 desc->name = dev_name(&pdev->dev);
73 reg->desc.type = REGULATOR_VOLTAGE;57 desc->type = REGULATOR_VOLTAGE;
74 reg->desc.owner = THIS_MODULE;58 desc->owner = THIS_MODULE;
75 reg->desc.continuous_voltage_range = true;59 desc->continuous_voltage_range = true;
76 60
77 init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node,61 init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node,
78 &reg->desc);62 desc);
79 if (!init_data)63 if (!init_data)
80 return -EINVAL;64 return -EINVAL;
81 65
82 init_data->constraints.apply_uV = 0;66 init_data->constraints.apply_uV = 0;
83 if (init_data->constraints.min_uV && init_data->constraints.max_uV)67 if (init_data->constraints.min_uV && init_data->constraints.max_uV)
84 reg->desc.ops = &vexpress_regulator_ops;68 desc->ops = &vexpress_regulator_ops;
85 else69 else
86 reg->desc.ops = &vexpress_regulator_ops_ro;70 desc->ops = &vexpress_regulator_ops_ro;
87 71
72 config.regmap = regmap;
88 config.dev = &pdev->dev;73 config.dev = &pdev->dev;
89 config.init_data = init_data;74 config.init_data = init_data;
90 config.driver_data = reg;
91 config.of_node = pdev->dev.of_node;75 config.of_node = pdev->dev.of_node;
92 76
93 reg->regdev = devm_regulator_register(&pdev->dev, &reg->desc, &config);77 rdev = devm_regulator_register(&pdev->dev, desc, &config);
94 if (IS_ERR(reg->regdev))78 if (IS_ERR(rdev))
95 return PTR_ERR(reg->regdev);79 return PTR_ERR(rdev);
96
97 platform_set_drvdata(pdev, reg);
98 80
99 return 0;81 return 0;
100}82}
drivers/regulator/wm831x-dcdc.c+11−12
@@ -1,15 +1,10 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * wm831x-dcdc.c -- DC-DC buck convertor driver for the WM831x series2//
3 *3// wm831x-dcdc.c -- DC-DC buck converter driver for the WM831x series
4 * Copyright 2009 Wolfson Microelectronics PLC.4//
5 *5// Copyright 2009 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>6//
7 *7// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13 8
14#include <linux/module.h>9#include <linux/module.h>
15#include <linux/moduleparam.h>10#include <linux/moduleparam.h>
@@ -183,9 +178,11 @@ static irqreturn_t wm831x_dcdc_uv_irq(int irq, void *data) · 167 unmodified lines
183{178{
184 struct wm831x_dcdc *dcdc = data;179 struct wm831x_dcdc *dcdc = data;
185 180
181 regulator_lock(dcdc->regulator);
186 regulator_notifier_call_chain(dcdc->regulator,182 regulator_notifier_call_chain(dcdc->regulator,
187 REGULATOR_EVENT_UNDER_VOLTAGE,183 REGULATOR_EVENT_UNDER_VOLTAGE,
188 NULL);184 NULL);
185 regulator_unlock(dcdc->regulator);
189 186
190 return IRQ_HANDLED;187 return IRQ_HANDLED;
191}188}
@@ -194,9 +191,11 @@ static irqreturn_t wm831x_dcdc_oc_irq(int irq, void *data) · 2 unmodified lines
194{191{
195 struct wm831x_dcdc *dcdc = data;192 struct wm831x_dcdc *dcdc = data;
196 193
194 regulator_lock(dcdc->regulator);
197 regulator_notifier_call_chain(dcdc->regulator,195 regulator_notifier_call_chain(dcdc->regulator,
198 REGULATOR_EVENT_OVER_CURRENT,196 REGULATOR_EVENT_OVER_CURRENT,
199 NULL);197 NULL);
198 regulator_unlock(dcdc->regulator);
200 199
201 return IRQ_HANDLED;200 return IRQ_HANDLED;
202}201}
drivers/regulator/wm831x-isink.c+16−50
@@ -1,15 +1,10 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * wm831x-isink.c -- Current sink driver for the WM831x series2//
3 *3// wm831x-isink.c -- Current sink driver for the WM831x series
4 * Copyright 2009 Wolfson Microelectronics PLC.4//
5 *5// Copyright 2009 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>6//
7 *7// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13 8
14#include <linux/module.h>9#include <linux/module.h>
15#include <linux/moduleparam.h>10#include <linux/moduleparam.h>
@@ -92,57 +87,23 @@ static int wm831x_isink_is_enabled(struct regulator_dev *rdev) · 76 unmodified lines
92 return 0;87 return 0;
93}88}
94 89
95static int wm831x_isink_set_current(struct regulator_dev *rdev,
96 int min_uA, int max_uA)
97{
98 struct wm831x_isink *isink = rdev_get_drvdata(rdev);
99 struct wm831x *wm831x = isink->wm831x;
100 int ret, i;
101
102 for (i = 0; i < ARRAY_SIZE(wm831x_isinkv_values); i++) {
103 int val = wm831x_isinkv_values[i];
104 if (min_uA <= val && val <= max_uA) {
105 ret = wm831x_set_bits(wm831x, isink->reg,
106 WM831X_CS1_ISEL_MASK, i);
107 return ret;
108 }
109 }
110
111 return -EINVAL;
112}
113
114static int wm831x_isink_get_current(struct regulator_dev *rdev)
115{
116 struct wm831x_isink *isink = rdev_get_drvdata(rdev);
117 struct wm831x *wm831x = isink->wm831x;
118 int ret;
119
120 ret = wm831x_reg_read(wm831x, isink->reg);
121 if (ret < 0)
122 return ret;
123
124 ret &= WM831X_CS1_ISEL_MASK;
125 if (ret > WM831X_ISINK_MAX_ISEL)
126 ret = WM831X_ISINK_MAX_ISEL;
127
128 return wm831x_isinkv_values[ret];
129}
130
131static const struct regulator_ops wm831x_isink_ops = {90static const struct regulator_ops wm831x_isink_ops = {
132 .is_enabled = wm831x_isink_is_enabled,91 .is_enabled = wm831x_isink_is_enabled,
133 .enable = wm831x_isink_enable,92 .enable = wm831x_isink_enable,
134 .disable = wm831x_isink_disable,93 .disable = wm831x_isink_disable,
135 .set_current_limit = wm831x_isink_set_current,94 .set_current_limit = regulator_set_current_limit_regmap,
136 .get_current_limit = wm831x_isink_get_current,95 .get_current_limit = regulator_get_current_limit_regmap,
137};96};
138 97
139static irqreturn_t wm831x_isink_irq(int irq, void *data)98static irqreturn_t wm831x_isink_irq(int irq, void *data)
140{99{
141 struct wm831x_isink *isink = data;100 struct wm831x_isink *isink = data;
142 101
102 regulator_lock(isink->regulator);
143 regulator_notifier_call_chain(isink->regulator,103 regulator_notifier_call_chain(isink->regulator,
144 REGULATOR_EVENT_OVER_CURRENT,104 REGULATOR_EVENT_OVER_CURRENT,
145 NULL);105 NULL);
106 regulator_unlock(isink->regulator);
146 107
147 return IRQ_HANDLED;108 return IRQ_HANDLED;
148}109}
@@ -187,10 +148,15 @@ static int wm831x_isink_probe(struct platform_device *pdev) · 38 unmodified lines
187 isink->desc.ops = &wm831x_isink_ops;148 isink->desc.ops = &wm831x_isink_ops;
188 isink->desc.type = REGULATOR_CURRENT;149 isink->desc.type = REGULATOR_CURRENT;
189 isink->desc.owner = THIS_MODULE;150 isink->desc.owner = THIS_MODULE;
151 isink->desc.curr_table = wm831x_isinkv_values,
152 isink->desc.n_current_limits = ARRAY_SIZE(wm831x_isinkv_values),
153 isink->desc.csel_reg = isink->reg,
154 isink->desc.csel_mask = WM831X_CS1_ISEL_MASK,
190 155
191 config.dev = pdev->dev.parent;156 config.dev = pdev->dev.parent;
192 config.init_data = pdata->isink[id];157 config.init_data = pdata->isink[id];
193 config.driver_data = isink;158 config.driver_data = isink;
159 config.regmap = wm831x->regmap;
194 160
195 isink->regulator = devm_regulator_register(&pdev->dev, &isink->desc,161 isink->regulator = devm_regulator_register(&pdev->dev, &isink->desc,
196 &config);162 &config);
drivers/regulator/wm831x-ldo.c+9−12
@@ -1,15 +1,10 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * wm831x-ldo.c -- LDO driver for the WM831x series2//
3 *3// wm831x-ldo.c -- LDO driver for the WM831x series
4 * Copyright 2009 Wolfson Microelectronics PLC.4//
5 *5// Copyright 2009 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>6//
7 *7// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13 8
14#include <linux/module.h>9#include <linux/module.h>
15#include <linux/moduleparam.h>10#include <linux/moduleparam.h>
@@ -51,9 +46,11 @@ static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data) · 35 unmodified lines
51{46{
52 struct wm831x_ldo *ldo = data;47 struct wm831x_ldo *ldo = data;
53 48
49 regulator_lock(ldo->regulator);
54 regulator_notifier_call_chain(ldo->regulator,50 regulator_notifier_call_chain(ldo->regulator,
55 REGULATOR_EVENT_UNDER_VOLTAGE,51 REGULATOR_EVENT_UNDER_VOLTAGE,
56 NULL);52 NULL);
53 regulator_unlock(ldo->regulator);
57 54
58 return IRQ_HANDLED;55 return IRQ_HANDLED;
59}56}
drivers/regulator/wm8350-regulator.c+19−83
@@ -1,16 +1,11 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC2//
3 *3// wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.4//
5 *5// Copyright 2007, 2008 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood6//
7 * linux@wolfsonmicro.com7// Author: Liam Girdwood
8 *8// linux@wolfsonmicro.com
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14 9
15#include <linux/module.h>10#include <linux/module.h>
16#include <linux/moduleparam.h>11#include <linux/moduleparam.h>
@@ -28,7 +23,7 @@ · 11 unmodified lines
28#define WM8350_DCDC_MAX_VSEL 0x6623#define WM8350_DCDC_MAX_VSEL 0x66
29 24
30/* Microamps */25/* Microamps */
31static const int isink_cur[] = {26static const unsigned int isink_cur[] = {
32 4,27 4,
33 5,28 5,
34 6,29 6,
@@ -95,73 +90,6 @@ static const int isink_cur[] = { · 60 unmodified lines
95 22319190 223191
96};91};
97 92
98static int get_isink_val(int min_uA, int max_uA, u16 *setting)
99{
100 int i;
101
102 for (i = 0; i < ARRAY_SIZE(isink_cur); i++) {
103 if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) {
104 *setting = i;
105 return 0;
106 }
107 }
108 return -EINVAL;
109}
110
111static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA,
112 int max_uA)
113{
114 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
115 int isink = rdev_get_id(rdev);
116 u16 val, setting;
117 int ret;
118
119 ret = get_isink_val(min_uA, max_uA, &setting);
120 if (ret != 0)
121 return ret;
122
123 switch (isink) {
124 case WM8350_ISINK_A:
125 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
126 ~WM8350_CS1_ISEL_MASK;
127 wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_A,
128 val | setting);
129 break;
130 case WM8350_ISINK_B:
131 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
132 ~WM8350_CS1_ISEL_MASK;
133 wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_B,
134 val | setting);
135 break;
136 default:
137 return -EINVAL;
138 }
139
140 return 0;
141}
142
143static int wm8350_isink_get_current(struct regulator_dev *rdev)
144{
145 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
146 int isink = rdev_get_id(rdev);
147 u16 val;
148
149 switch (isink) {
150 case WM8350_ISINK_A:
151 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
152 WM8350_CS1_ISEL_MASK;
153 break;
154 case WM8350_ISINK_B:
155 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
156 WM8350_CS1_ISEL_MASK;
157 break;
158 default:
159 return 0;
160 }
161
162 return isink_cur[val];
163}
164
165/* turn on ISINK followed by DCDC */93/* turn on ISINK followed by DCDC */
166static int wm8350_isink_enable(struct regulator_dev *rdev)94static int wm8350_isink_enable(struct regulator_dev *rdev)
167{95{
@@ -982,8 +910,8 @@ static const struct regulator_ops wm8350_ldo_ops = { · 814 unmodified lines
982};910};
983 911
984static const struct regulator_ops wm8350_isink_ops = {912static const struct regulator_ops wm8350_isink_ops = {
985 .set_current_limit = wm8350_isink_set_current,913 .set_current_limit = regulator_set_current_limit_regmap,
986 .get_current_limit = wm8350_isink_get_current,914 .get_current_limit = regulator_get_current_limit_regmap,
987 .enable = wm8350_isink_enable,915 .enable = wm8350_isink_enable,
988 .disable = wm8350_isink_disable,916 .disable = wm8350_isink_disable,
989 .is_enabled = wm8350_isink_is_enabled,917 .is_enabled = wm8350_isink_is_enabled,
@@ -1138,6 +1066,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { · 148 unmodified lines
1138 .irq = WM8350_IRQ_CS1,1066 .irq = WM8350_IRQ_CS1,
1139 .type = REGULATOR_CURRENT,1067 .type = REGULATOR_CURRENT,
1140 .owner = THIS_MODULE,1068 .owner = THIS_MODULE,
1069 .curr_table = isink_cur,
1070 .n_current_limits = ARRAY_SIZE(isink_cur),
1071 .csel_reg = WM8350_CURRENT_SINK_DRIVER_A,
1072 .csel_mask = WM8350_CS1_ISEL_MASK,
1141 },1073 },
1142 {1074 {
1143 .name = "ISINKB",1075 .name = "ISINKB",
@@ -1146,6 +1078,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { · 2 unmodified lines
1146 .irq = WM8350_IRQ_CS2,1078 .irq = WM8350_IRQ_CS2,
1147 .type = REGULATOR_CURRENT,1079 .type = REGULATOR_CURRENT,
1148 .owner = THIS_MODULE,1080 .owner = THIS_MODULE,
1081 .curr_table = isink_cur,
1082 .n_current_limits = ARRAY_SIZE(isink_cur),
1083 .csel_reg = WM8350_CURRENT_SINK_DRIVER_B,
1084 .csel_mask = WM8350_CS2_ISEL_MASK,
1149 },1085 },
1150};1086};
1151 1087
drivers/regulator/wm8400-regulator.c+16−23
@@ -1,16 +1,10 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * Regulator support for WM84002//
3 *3// Regulator support for WM8400
4 * Copyright 2008 Wolfson Microelectronics PLC.4//
5 *5// Copyright 2008 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>6//
7 *7// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 */
14 8
15#include <linux/bug.h>9#include <linux/bug.h>
16#include <linux/err.h>10#include <linux/err.h>
@@ -36,13 +30,12 @@ static const struct regulator_ops wm8400_ldo_ops = { · 19 unmodified lines
36 30
37static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev)31static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev)
38{32{
39 struct wm8400 *wm8400 = rdev_get_drvdata(dev);33 struct regmap *rmap = rdev_get_regmap(dev);
40 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;34 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
41 u16 data[2];35 u16 data[2];
42 int ret;36 int ret;
43 37
44 ret = wm8400_block_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 2,38 ret = regmap_bulk_read(rmap, WM8400_DCDC1_CONTROL_1 + offset, data, 2);
45 data);
46 if (ret != 0)39 if (ret != 0)
47 return 0;40 return 0;
48 41
@@ -63,36 +56,36 @@ static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) · 14 unmodified lines
63 56
64static int wm8400_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode)57static int wm8400_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode)
65{58{
66 struct wm8400 *wm8400 = rdev_get_drvdata(dev);59 struct regmap *rmap = rdev_get_regmap(dev);
67 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;60 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
68 int ret;61 int ret;
69 62
70 switch (mode) {63 switch (mode) {
71 case REGULATOR_MODE_FAST:64 case REGULATOR_MODE_FAST:
72 /* Datasheet: active with force PWM */65 /* Datasheet: active with force PWM */
73 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset,66 ret = regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_2 + offset,
74 WM8400_DC1_FRC_PWM, WM8400_DC1_FRC_PWM);67 WM8400_DC1_FRC_PWM, WM8400_DC1_FRC_PWM);
75 if (ret != 0)68 if (ret != 0)
76 return ret;69 return ret;
77 70
78 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,71 return regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_1 + offset,
79 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,72 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
80 WM8400_DC1_ACTIVE);73 WM8400_DC1_ACTIVE);
81 74
82 case REGULATOR_MODE_NORMAL:75 case REGULATOR_MODE_NORMAL:
83 /* Datasheet: active */76 /* Datasheet: active */
84 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset,77 ret = regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_2 + offset,
85 WM8400_DC1_FRC_PWM, 0);78 WM8400_DC1_FRC_PWM, 0);
86 if (ret != 0)79 if (ret != 0)
87 return ret;80 return ret;
88 81
89 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,82 return regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_1 + offset,
90 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,83 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
91 WM8400_DC1_ACTIVE);84 WM8400_DC1_ACTIVE);
92 85
93 case REGULATOR_MODE_IDLE:86 case REGULATOR_MODE_IDLE:
94 /* Datasheet: standby */87 /* Datasheet: standby */
95 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,88 return regmap_update_bits(rmap, WM8400_DCDC1_CONTROL_1 + offset,
96 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, 0);89 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP, 0);
97 default:90 default:
98 return -EINVAL;91 return -EINVAL;
@@ -195,7 +188,7 @@ static struct regulator_desc regulators[] = { · 96 unmodified lines
195 .id = WM8400_DCDC2,188 .id = WM8400_DCDC2,
196 .ops = &wm8400_dcdc_ops,189 .ops = &wm8400_dcdc_ops,
197 .enable_reg = WM8400_DCDC2_CONTROL_1,190 .enable_reg = WM8400_DCDC2_CONTROL_1,
198 .enable_mask = WM8400_DC1_ENA_MASK,191 .enable_mask = WM8400_DC2_ENA_MASK,
199 .n_voltages = WM8400_DC2_VSEL_MASK + 1,192 .n_voltages = WM8400_DC2_VSEL_MASK + 1,
200 .vsel_reg = WM8400_DCDC2_CONTROL_1,193 .vsel_reg = WM8400_DCDC2_CONTROL_1,
201 .vsel_mask = WM8400_DC2_VSEL_MASK,194 .vsel_mask = WM8400_DC2_VSEL_MASK,
drivers/regulator/wm8994-regulator.c+7−12
@@ -1,15 +1,10 @@
1/*1// SPDX-License-Identifier: GPL-2.0+
2 * wm8994-regulator.c -- Regulator driver for the WM89942//
3 *3// wm8994-regulator.c -- Regulator driver for the WM8994
4 * Copyright 2009 Wolfson Microelectronics PLC.4//
5 *5// Copyright 2009 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>6//
7 *7// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13 8
14#include <linux/module.h>9#include <linux/module.h>
15#include <linux/moduleparam.h>10#include <linux/moduleparam.h>
include/linux/mfd/palmas.h+0−1
@@ -553,7 +553,6 @@ struct palmas_pmic { · 552 unmodified lines
553 struct palmas *palmas;553 struct palmas *palmas;
554 struct device *dev;554 struct device *dev;
555 struct regulator_desc desc[PALMAS_NUM_REGS];555 struct regulator_desc desc[PALMAS_NUM_REGS];
556 struct regulator_dev *rdev[PALMAS_NUM_REGS];
557 struct mutex mutex;556 struct mutex mutex;
558 557
559 int smps123;558 int smps123;
include/linux/mfd/wm831x/regulator.h+1−1
@@ -1213,6 +1213,6 @@ · 1212 unmodified lines
1213#define WM831X_LDO1_OK_WIDTH 1 /* LDO1_OK */1213#define WM831X_LDO1_OK_WIDTH 1 /* LDO1_OK */
1214 1214
1215#define WM831X_ISINK_MAX_ISEL 551215#define WM831X_ISINK_MAX_ISEL 55
1216extern int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1];1216extern const unsigned int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1];
1217 1217
1218#endif1218#endif
include/linux/mfd/wm8400-private.h+0−8
@@ -923,12 +923,4 @@ struct wm8400 { · 922 unmodified lines
923#define WM8400_LINE_CMP_VTHD_SHIFT 0 /* LINE_CMP_VTHD - [3:0] */923#define WM8400_LINE_CMP_VTHD_SHIFT 0 /* LINE_CMP_VTHD - [3:0] */
924#define WM8400_LINE_CMP_VTHD_WIDTH 4 /* LINE_CMP_VTHD - [3:0] */924#define WM8400_LINE_CMP_VTHD_WIDTH 4 /* LINE_CMP_VTHD - [3:0] */
925 925
926int wm8400_block_read(struct wm8400 *wm8400, u8 reg, int count, u16 *data);
927
928static inline int wm8400_set_bits(struct wm8400 *wm8400, u8 reg,
929 u16 mask, u16 val)
930{
931 return regmap_update_bits(wm8400->regmap, reg, mask, val);
932}
933
934#endif926#endif
include/linux/regulator/consumer.h+5−0
@@ -478,6 +478,11 @@ static inline int regulator_is_supported_voltage(struct regulator *regulator, · 477 unmodified lines
478 return 0;478 return 0;
479}479}
480 480
481static inline unsigned int regulator_get_linear_step(struct regulator *regulator)
482{
483 return 0;
484}
485
481static inline int regulator_set_current_limit(struct regulator *regulator,486static inline int regulator_set_current_limit(struct regulator *regulator,
482 int min_uA, int max_uA)487 int min_uA, int max_uA)
483{488{
sound/soc/codecs/ab8500-codec.c+2−2
@@ -1062,10 +1062,10 @@ static void anc_iir(struct snd_soc_component *component, unsigned int bnk, · 1061 unmodified lines
1062 snd_soc_component_update_bits(component, AB8500_ANCCONF1,1062 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1063 BIT(AB8500_ANCCONF1_ANCIIRINIT),1063 BIT(AB8500_ANCCONF1_ANCIIRINIT),
1064 BIT(AB8500_ANCCONF1_ANCIIRINIT));1064 BIT(AB8500_ANCCONF1_ANCIIRINIT));
1065 usleep_range(AB8500_ANC_SM_DELAY, AB8500_ANC_SM_DELAY);1065 usleep_range(AB8500_ANC_SM_DELAY, AB8500_ANC_SM_DELAY*2);
1066 snd_soc_component_update_bits(component, AB8500_ANCCONF1,1066 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1067 BIT(AB8500_ANCCONF1_ANCIIRINIT), 0);1067 BIT(AB8500_ANCCONF1_ANCIIRINIT), 0);
1068 usleep_range(AB8500_ANC_SM_DELAY, AB8500_ANC_SM_DELAY);1068 usleep_range(AB8500_ANC_SM_DELAY, AB8500_ANC_SM_DELAY*2);
1069 } else {1069 } else {
1070 snd_soc_component_update_bits(component, AB8500_ANCCONF1,1070 snd_soc_component_update_bits(component, AB8500_ANCCONF1,
1071 BIT(AB8500_ANCCONF1_ANCIIRUPDATE),1071 BIT(AB8500_ANCCONF1_ANCIIRUPDATE),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t