14f3fb287SKrzysztof Kozlowski // SPDX-License-Identifier: GPL-2.0+
24f3fb287SKrzysztof Kozlowski //
34f3fb287SKrzysztof Kozlowski // Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
44f3fb287SKrzysztof Kozlowski // http://www.samsung.com
5cb74685eSSangbeom Kim
6cb74685eSSangbeom Kim #include <linux/bug.h>
7cb74685eSSangbeom Kim #include <linux/err.h>
81c984942SLinus Walleij #include <linux/gpio/consumer.h>
9cb74685eSSangbeom Kim #include <linux/slab.h>
10cb74685eSSangbeom Kim #include <linux/module.h>
11a50c6b32SYadwinder Singh Brar #include <linux/of.h>
12939c0277SYadwinder Singh Brar #include <linux/regmap.h>
13cb74685eSSangbeom Kim #include <linux/platform_device.h>
14cb74685eSSangbeom Kim #include <linux/regulator/driver.h>
15cb74685eSSangbeom Kim #include <linux/regulator/machine.h>
16a50c6b32SYadwinder Singh Brar #include <linux/regulator/of_regulator.h>
17cb74685eSSangbeom Kim #include <linux/mfd/samsung/core.h>
18cb74685eSSangbeom Kim #include <linux/mfd/samsung/s2mps11.h>
1976b9840bSChanwoo Choi #include <linux/mfd/samsung/s2mps13.h>
2015f77300SKrzysztof Kozlowski #include <linux/mfd/samsung/s2mps14.h>
2151af2067SThomas Abraham #include <linux/mfd/samsung/s2mps15.h>
2200e2573dSChanwoo Choi #include <linux/mfd/samsung/s2mpu02.h>
23a50c6b32SYadwinder Singh Brar
2432c848e3SKrzysztof Kozlowski /* The highest number of possible regulators for supported devices. */
2532c848e3SKrzysztof Kozlowski #define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX
26cb74685eSSangbeom Kim struct s2mps11_info {
27cb74685eSSangbeom Kim int ramp_delay2;
28cb74685eSSangbeom Kim int ramp_delay34;
29cb74685eSSangbeom Kim int ramp_delay5;
30cb74685eSSangbeom Kim int ramp_delay16;
31cb74685eSSangbeom Kim int ramp_delay7810;
32cb74685eSSangbeom Kim int ramp_delay9;
3300e2573dSChanwoo Choi
3400e2573dSChanwoo Choi enum sec_device_type dev_type;
3500e2573dSChanwoo Choi
3605be09bbSKrzysztof Kozlowski /*
3765d80db2SKrzysztof Kozlowski * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether
3876b9840bSChanwoo Choi * the suspend mode was enabled.
3905be09bbSKrzysztof Kozlowski */
4032c848e3SKrzysztof Kozlowski DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
4100e2573dSChanwoo Choi
427ddec641SKrzysztof Kozlowski /*
437ddec641SKrzysztof Kozlowski * Array (size: number of regulators) with GPIO-s for external
447ddec641SKrzysztof Kozlowski * sleep control.
457ddec641SKrzysztof Kozlowski */
461c984942SLinus Walleij struct gpio_desc **ext_control_gpiod;
47cb74685eSSangbeom Kim };
48cb74685eSSangbeom Kim
get_ramp_delay(int ramp_delay)49cb74685eSSangbeom Kim static int get_ramp_delay(int ramp_delay)
50cb74685eSSangbeom Kim {
51cb74685eSSangbeom Kim unsigned char cnt = 0;
52cb74685eSSangbeom Kim
5390068348SYadwinder Singh Brar ramp_delay /= 6250;
54cb74685eSSangbeom Kim
55cb74685eSSangbeom Kim while (true) {
56cb74685eSSangbeom Kim ramp_delay = ramp_delay >> 1;
57cb74685eSSangbeom Kim if (ramp_delay == 0)
58cb74685eSSangbeom Kim break;
59cb74685eSSangbeom Kim cnt++;
60cb74685eSSangbeom Kim }
61f8f1d48bSAxel Lin
62f8f1d48bSAxel Lin if (cnt > 3)
63f8f1d48bSAxel Lin cnt = 3;
64f8f1d48bSAxel Lin
65cb74685eSSangbeom Kim return cnt;
66cb74685eSSangbeom Kim }
67cb74685eSSangbeom Kim
s2mps11_regulator_set_voltage_time_sel(struct regulator_dev * rdev,unsigned int old_selector,unsigned int new_selector)681e1598edSYadwinder Singh Brar static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
691e1598edSYadwinder Singh Brar unsigned int old_selector,
701e1598edSYadwinder Singh Brar unsigned int new_selector)
711e1598edSYadwinder Singh Brar {
721e1598edSYadwinder Singh Brar struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
73df33799cSKrzysztof Kozlowski int rdev_id = rdev_get_id(rdev);
741e1598edSYadwinder Singh Brar unsigned int ramp_delay = 0;
751e1598edSYadwinder Singh Brar int old_volt, new_volt;
761e1598edSYadwinder Singh Brar
77df33799cSKrzysztof Kozlowski switch (rdev_id) {
781e1598edSYadwinder Singh Brar case S2MPS11_BUCK2:
791e1598edSYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay2;
801e1598edSYadwinder Singh Brar break;
811e1598edSYadwinder Singh Brar case S2MPS11_BUCK3:
821e1598edSYadwinder Singh Brar case S2MPS11_BUCK4:
831e1598edSYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay34;
841e1598edSYadwinder Singh Brar break;
851e1598edSYadwinder Singh Brar case S2MPS11_BUCK5:
861e1598edSYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay5;
871e1598edSYadwinder Singh Brar break;
881e1598edSYadwinder Singh Brar case S2MPS11_BUCK6:
891e1598edSYadwinder Singh Brar case S2MPS11_BUCK1:
901e1598edSYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay16;
911e1598edSYadwinder Singh Brar break;
921e1598edSYadwinder Singh Brar case S2MPS11_BUCK7:
931e1598edSYadwinder Singh Brar case S2MPS11_BUCK8:
941e1598edSYadwinder Singh Brar case S2MPS11_BUCK10:
951e1598edSYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay7810;
961e1598edSYadwinder Singh Brar break;
971e1598edSYadwinder Singh Brar case S2MPS11_BUCK9:
981e1598edSYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay9;
991e1598edSYadwinder Singh Brar }
1001e1598edSYadwinder Singh Brar
1011e1598edSYadwinder Singh Brar if (ramp_delay == 0)
1021e1598edSYadwinder Singh Brar ramp_delay = rdev->desc->ramp_delay;
1031e1598edSYadwinder Singh Brar
1041e1598edSYadwinder Singh Brar old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
1051e1598edSYadwinder Singh Brar new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
1061e1598edSYadwinder Singh Brar
1071e1598edSYadwinder Singh Brar return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
1081e1598edSYadwinder Singh Brar }
1091e1598edSYadwinder Singh Brar
s2mps11_set_ramp_delay(struct regulator_dev * rdev,int ramp_delay)110939c0277SYadwinder Singh Brar static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
111939c0277SYadwinder Singh Brar {
112939c0277SYadwinder Singh Brar struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
113939c0277SYadwinder Singh Brar unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
114939c0277SYadwinder Singh Brar unsigned int ramp_enable = 1, enable_shift = 0;
115df33799cSKrzysztof Kozlowski int rdev_id = rdev_get_id(rdev);
116939c0277SYadwinder Singh Brar int ret;
117939c0277SYadwinder Singh Brar
118df33799cSKrzysztof Kozlowski switch (rdev_id) {
119939c0277SYadwinder Singh Brar case S2MPS11_BUCK1:
120939c0277SYadwinder Singh Brar if (ramp_delay > s2mps11->ramp_delay16)
121939c0277SYadwinder Singh Brar s2mps11->ramp_delay16 = ramp_delay;
122939c0277SYadwinder Singh Brar else
123939c0277SYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay16;
124939c0277SYadwinder Singh Brar
125939c0277SYadwinder Singh Brar ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
126939c0277SYadwinder Singh Brar break;
127939c0277SYadwinder Singh Brar case S2MPS11_BUCK2:
128939c0277SYadwinder Singh Brar enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
129939c0277SYadwinder Singh Brar if (!ramp_delay) {
130939c0277SYadwinder Singh Brar ramp_enable = 0;
131939c0277SYadwinder Singh Brar break;
132939c0277SYadwinder Singh Brar }
133939c0277SYadwinder Singh Brar
134939c0277SYadwinder Singh Brar s2mps11->ramp_delay2 = ramp_delay;
135939c0277SYadwinder Singh Brar ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
136939c0277SYadwinder Singh Brar ramp_reg = S2MPS11_REG_RAMP;
137939c0277SYadwinder Singh Brar break;
138939c0277SYadwinder Singh Brar case S2MPS11_BUCK3:
139939c0277SYadwinder Singh Brar enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
140939c0277SYadwinder Singh Brar if (!ramp_delay) {
141939c0277SYadwinder Singh Brar ramp_enable = 0;
142939c0277SYadwinder Singh Brar break;
143939c0277SYadwinder Singh Brar }
144939c0277SYadwinder Singh Brar
145939c0277SYadwinder Singh Brar if (ramp_delay > s2mps11->ramp_delay34)
146939c0277SYadwinder Singh Brar s2mps11->ramp_delay34 = ramp_delay;
147939c0277SYadwinder Singh Brar else
148939c0277SYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay34;
149939c0277SYadwinder Singh Brar
150939c0277SYadwinder Singh Brar ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
151939c0277SYadwinder Singh Brar ramp_reg = S2MPS11_REG_RAMP;
152939c0277SYadwinder Singh Brar break;
153939c0277SYadwinder Singh Brar case S2MPS11_BUCK4:
154939c0277SYadwinder Singh Brar enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
155939c0277SYadwinder Singh Brar if (!ramp_delay) {
156939c0277SYadwinder Singh Brar ramp_enable = 0;
157939c0277SYadwinder Singh Brar break;
158939c0277SYadwinder Singh Brar }
159939c0277SYadwinder Singh Brar
160939c0277SYadwinder Singh Brar if (ramp_delay > s2mps11->ramp_delay34)
161939c0277SYadwinder Singh Brar s2mps11->ramp_delay34 = ramp_delay;
162939c0277SYadwinder Singh Brar else
163939c0277SYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay34;
164939c0277SYadwinder Singh Brar
165939c0277SYadwinder Singh Brar ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
166939c0277SYadwinder Singh Brar ramp_reg = S2MPS11_REG_RAMP;
167939c0277SYadwinder Singh Brar break;
168939c0277SYadwinder Singh Brar case S2MPS11_BUCK5:
169939c0277SYadwinder Singh Brar s2mps11->ramp_delay5 = ramp_delay;
170939c0277SYadwinder Singh Brar ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
171939c0277SYadwinder Singh Brar break;
172939c0277SYadwinder Singh Brar case S2MPS11_BUCK6:
173939c0277SYadwinder Singh Brar enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
174939c0277SYadwinder Singh Brar if (!ramp_delay) {
175939c0277SYadwinder Singh Brar ramp_enable = 0;
176939c0277SYadwinder Singh Brar break;
177939c0277SYadwinder Singh Brar }
178939c0277SYadwinder Singh Brar
179939c0277SYadwinder Singh Brar if (ramp_delay > s2mps11->ramp_delay16)
180939c0277SYadwinder Singh Brar s2mps11->ramp_delay16 = ramp_delay;
181939c0277SYadwinder Singh Brar else
182939c0277SYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay16;
183939c0277SYadwinder Singh Brar
184939c0277SYadwinder Singh Brar ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
185939c0277SYadwinder Singh Brar break;
186939c0277SYadwinder Singh Brar case S2MPS11_BUCK7:
187939c0277SYadwinder Singh Brar case S2MPS11_BUCK8:
188939c0277SYadwinder Singh Brar case S2MPS11_BUCK10:
189939c0277SYadwinder Singh Brar if (ramp_delay > s2mps11->ramp_delay7810)
190939c0277SYadwinder Singh Brar s2mps11->ramp_delay7810 = ramp_delay;
191939c0277SYadwinder Singh Brar else
192939c0277SYadwinder Singh Brar ramp_delay = s2mps11->ramp_delay7810;
193939c0277SYadwinder Singh Brar
194939c0277SYadwinder Singh Brar ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
195939c0277SYadwinder Singh Brar break;
196939c0277SYadwinder Singh Brar case S2MPS11_BUCK9:
197939c0277SYadwinder Singh Brar s2mps11->ramp_delay9 = ramp_delay;
198939c0277SYadwinder Singh Brar ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
199939c0277SYadwinder Singh Brar break;
200939c0277SYadwinder Singh Brar default:
201939c0277SYadwinder Singh Brar return 0;
202939c0277SYadwinder Singh Brar }
203939c0277SYadwinder Singh Brar
204939c0277SYadwinder Singh Brar if (!ramp_enable)
205939c0277SYadwinder Singh Brar goto ramp_disable;
206939c0277SYadwinder Singh Brar
207b203e0dfSKrzysztof Kozlowski /* Ramp delay can be enabled/disabled only for buck[2346] */
208df33799cSKrzysztof Kozlowski if ((rdev_id >= S2MPS11_BUCK2 && rdev_id <= S2MPS11_BUCK4) ||
209df33799cSKrzysztof Kozlowski rdev_id == S2MPS11_BUCK6) {
210939c0277SYadwinder Singh Brar ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
211939c0277SYadwinder Singh Brar 1 << enable_shift, 1 << enable_shift);
212939c0277SYadwinder Singh Brar if (ret) {
213939c0277SYadwinder Singh Brar dev_err(&rdev->dev, "failed to enable ramp rate\n");
214939c0277SYadwinder Singh Brar return ret;
215939c0277SYadwinder Singh Brar }
216b203e0dfSKrzysztof Kozlowski }
217939c0277SYadwinder Singh Brar
218939c0277SYadwinder Singh Brar ramp_val = get_ramp_delay(ramp_delay);
219939c0277SYadwinder Singh Brar
220f8f1d48bSAxel Lin return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
221f8f1d48bSAxel Lin ramp_val << ramp_shift);
222939c0277SYadwinder Singh Brar
223939c0277SYadwinder Singh Brar ramp_disable:
22480853304SAxel Lin return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
22580853304SAxel Lin 1 << enable_shift, 0);
226939c0277SYadwinder Singh Brar }
227939c0277SYadwinder Singh Brar
s2mps11_regulator_enable(struct regulator_dev * rdev)22865d80db2SKrzysztof Kozlowski static int s2mps11_regulator_enable(struct regulator_dev *rdev)
22965d80db2SKrzysztof Kozlowski {
23065d80db2SKrzysztof Kozlowski struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
23165d80db2SKrzysztof Kozlowski int rdev_id = rdev_get_id(rdev);
23265d80db2SKrzysztof Kozlowski unsigned int val;
23365d80db2SKrzysztof Kozlowski
23465d80db2SKrzysztof Kozlowski switch (s2mps11->dev_type) {
23565d80db2SKrzysztof Kozlowski case S2MPS11X:
23665d80db2SKrzysztof Kozlowski if (test_bit(rdev_id, s2mps11->suspend_state))
23765d80db2SKrzysztof Kozlowski val = S2MPS14_ENABLE_SUSPEND;
23865d80db2SKrzysztof Kozlowski else
23965d80db2SKrzysztof Kozlowski val = rdev->desc->enable_mask;
24065d80db2SKrzysztof Kozlowski break;
24165d80db2SKrzysztof Kozlowski case S2MPS13X:
24265d80db2SKrzysztof Kozlowski case S2MPS14X:
24365d80db2SKrzysztof Kozlowski if (test_bit(rdev_id, s2mps11->suspend_state))
24465d80db2SKrzysztof Kozlowski val = S2MPS14_ENABLE_SUSPEND;
24565d80db2SKrzysztof Kozlowski else if (s2mps11->ext_control_gpiod[rdev_id])
24665d80db2SKrzysztof Kozlowski val = S2MPS14_ENABLE_EXT_CONTROL;
24765d80db2SKrzysztof Kozlowski else
24865d80db2SKrzysztof Kozlowski val = rdev->desc->enable_mask;
24965d80db2SKrzysztof Kozlowski break;
25065d80db2SKrzysztof Kozlowski case S2MPU02:
25165d80db2SKrzysztof Kozlowski if (test_bit(rdev_id, s2mps11->suspend_state))
25265d80db2SKrzysztof Kozlowski val = S2MPU02_ENABLE_SUSPEND;
25365d80db2SKrzysztof Kozlowski else
25465d80db2SKrzysztof Kozlowski val = rdev->desc->enable_mask;
25565d80db2SKrzysztof Kozlowski break;
25665d80db2SKrzysztof Kozlowski default:
25765d80db2SKrzysztof Kozlowski return -EINVAL;
25865d80db2SKrzysztof Kozlowski }
25965d80db2SKrzysztof Kozlowski
26065d80db2SKrzysztof Kozlowski return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
26165d80db2SKrzysztof Kozlowski rdev->desc->enable_mask, val);
26265d80db2SKrzysztof Kozlowski }
26365d80db2SKrzysztof Kozlowski
s2mps11_regulator_set_suspend_disable(struct regulator_dev * rdev)26465d80db2SKrzysztof Kozlowski static int s2mps11_regulator_set_suspend_disable(struct regulator_dev *rdev)
26565d80db2SKrzysztof Kozlowski {
26665d80db2SKrzysztof Kozlowski int ret;
26765d80db2SKrzysztof Kozlowski unsigned int val, state;
26865d80db2SKrzysztof Kozlowski struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
26965d80db2SKrzysztof Kozlowski int rdev_id = rdev_get_id(rdev);
27065d80db2SKrzysztof Kozlowski
27165d80db2SKrzysztof Kozlowski /* Below LDO should be always on or does not support suspend mode. */
27265d80db2SKrzysztof Kozlowski switch (s2mps11->dev_type) {
27365d80db2SKrzysztof Kozlowski case S2MPS11X:
27465d80db2SKrzysztof Kozlowski switch (rdev_id) {
27565d80db2SKrzysztof Kozlowski case S2MPS11_LDO2:
27665d80db2SKrzysztof Kozlowski case S2MPS11_LDO36:
27765d80db2SKrzysztof Kozlowski case S2MPS11_LDO37:
27865d80db2SKrzysztof Kozlowski case S2MPS11_LDO38:
27965d80db2SKrzysztof Kozlowski return 0;
28065d80db2SKrzysztof Kozlowski default:
28165d80db2SKrzysztof Kozlowski state = S2MPS14_ENABLE_SUSPEND;
28265d80db2SKrzysztof Kozlowski break;
28365d80db2SKrzysztof Kozlowski }
28465d80db2SKrzysztof Kozlowski break;
28565d80db2SKrzysztof Kozlowski case S2MPS13X:
28665d80db2SKrzysztof Kozlowski case S2MPS14X:
28765d80db2SKrzysztof Kozlowski switch (rdev_id) {
28865d80db2SKrzysztof Kozlowski case S2MPS14_LDO3:
28965d80db2SKrzysztof Kozlowski return 0;
29065d80db2SKrzysztof Kozlowski default:
29165d80db2SKrzysztof Kozlowski state = S2MPS14_ENABLE_SUSPEND;
29265d80db2SKrzysztof Kozlowski break;
29365d80db2SKrzysztof Kozlowski }
29465d80db2SKrzysztof Kozlowski break;
29565d80db2SKrzysztof Kozlowski case S2MPU02:
29665d80db2SKrzysztof Kozlowski switch (rdev_id) {
29765d80db2SKrzysztof Kozlowski case S2MPU02_LDO13:
29865d80db2SKrzysztof Kozlowski case S2MPU02_LDO14:
29965d80db2SKrzysztof Kozlowski case S2MPU02_LDO15:
30065d80db2SKrzysztof Kozlowski case S2MPU02_LDO17:
30165d80db2SKrzysztof Kozlowski case S2MPU02_BUCK7:
30265d80db2SKrzysztof Kozlowski state = S2MPU02_DISABLE_SUSPEND;
30365d80db2SKrzysztof Kozlowski break;
30465d80db2SKrzysztof Kozlowski default:
30565d80db2SKrzysztof Kozlowski state = S2MPU02_ENABLE_SUSPEND;
30665d80db2SKrzysztof Kozlowski break;
30765d80db2SKrzysztof Kozlowski }
30865d80db2SKrzysztof Kozlowski break;
30965d80db2SKrzysztof Kozlowski default:
31065d80db2SKrzysztof Kozlowski return -EINVAL;
31165d80db2SKrzysztof Kozlowski }
31265d80db2SKrzysztof Kozlowski
31365d80db2SKrzysztof Kozlowski ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
31465d80db2SKrzysztof Kozlowski if (ret < 0)
31565d80db2SKrzysztof Kozlowski return ret;
31665d80db2SKrzysztof Kozlowski
31765d80db2SKrzysztof Kozlowski set_bit(rdev_id, s2mps11->suspend_state);
31865d80db2SKrzysztof Kozlowski /*
31965d80db2SKrzysztof Kozlowski * Don't enable suspend mode if regulator is already disabled because
32065d80db2SKrzysztof Kozlowski * this would effectively for a short time turn on the regulator after
32165d80db2SKrzysztof Kozlowski * resuming.
32265d80db2SKrzysztof Kozlowski * However we still want to toggle the suspend_state bit for regulator
32365d80db2SKrzysztof Kozlowski * in case if it got enabled before suspending the system.
32465d80db2SKrzysztof Kozlowski */
32565d80db2SKrzysztof Kozlowski if (!(val & rdev->desc->enable_mask))
32665d80db2SKrzysztof Kozlowski return 0;
32765d80db2SKrzysztof Kozlowski
32865d80db2SKrzysztof Kozlowski return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
32965d80db2SKrzysztof Kozlowski rdev->desc->enable_mask, state);
33065d80db2SKrzysztof Kozlowski }
33165d80db2SKrzysztof Kozlowski
33271b4540fSKrzysztof Kozlowski static const struct regulator_ops s2mps11_ldo_ops = {
333cb74685eSSangbeom Kim .list_voltage = regulator_list_voltage_linear,
334cb74685eSSangbeom Kim .map_voltage = regulator_map_voltage_linear,
335cb74685eSSangbeom Kim .is_enabled = regulator_is_enabled_regmap,
33665d80db2SKrzysztof Kozlowski .enable = s2mps11_regulator_enable,
337cb74685eSSangbeom Kim .disable = regulator_disable_regmap,
338cb74685eSSangbeom Kim .get_voltage_sel = regulator_get_voltage_sel_regmap,
339cb74685eSSangbeom Kim .set_voltage_sel = regulator_set_voltage_sel_regmap,
340cb74685eSSangbeom Kim .set_voltage_time_sel = regulator_set_voltage_time_sel,
34165d80db2SKrzysztof Kozlowski .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
342cb74685eSSangbeom Kim };
343cb74685eSSangbeom Kim
34471b4540fSKrzysztof Kozlowski static const struct regulator_ops s2mps11_buck_ops = {
345cb74685eSSangbeom Kim .list_voltage = regulator_list_voltage_linear,
346cb74685eSSangbeom Kim .map_voltage = regulator_map_voltage_linear,
347cb74685eSSangbeom Kim .is_enabled = regulator_is_enabled_regmap,
34865d80db2SKrzysztof Kozlowski .enable = s2mps11_regulator_enable,
349cb74685eSSangbeom Kim .disable = regulator_disable_regmap,
350cb74685eSSangbeom Kim .get_voltage_sel = regulator_get_voltage_sel_regmap,
351cb74685eSSangbeom Kim .set_voltage_sel = regulator_set_voltage_sel_regmap,
3521e1598edSYadwinder Singh Brar .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
353939c0277SYadwinder Singh Brar .set_ramp_delay = s2mps11_set_ramp_delay,
35465d80db2SKrzysztof Kozlowski .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
355cb74685eSSangbeom Kim };
356cb74685eSSangbeom Kim
3575a867cf2SAmit Daniel Kachhap #define regulator_desc_s2mps11_ldo(num, step) { \
358cb74685eSSangbeom Kim .name = "LDO"#num, \
359cb74685eSSangbeom Kim .id = S2MPS11_LDO##num, \
360cb74685eSSangbeom Kim .ops = &s2mps11_ldo_ops, \
361cb74685eSSangbeom Kim .type = REGULATOR_VOLTAGE, \
362cb74685eSSangbeom Kim .owner = THIS_MODULE, \
36394be46b9SKrzysztof Kozlowski .ramp_delay = RAMP_DELAY_12_MVUS, \
3640e4f4178SAmit Daniel Kachhap .min_uV = MIN_800_MV, \
3655a867cf2SAmit Daniel Kachhap .uV_step = step, \
366cb74685eSSangbeom Kim .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
367cb74685eSSangbeom Kim .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
3682693fcabSAxel Lin .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
369cb74685eSSangbeom Kim .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
370cb74685eSSangbeom Kim .enable_mask = S2MPS11_ENABLE_MASK \
371cb74685eSSangbeom Kim }
372cb74685eSSangbeom Kim
37315f77300SKrzysztof Kozlowski #define regulator_desc_s2mps11_buck1_4(num) { \
374cb74685eSSangbeom Kim .name = "BUCK"#num, \
375cb74685eSSangbeom Kim .id = S2MPS11_BUCK##num, \
376cb74685eSSangbeom Kim .ops = &s2mps11_buck_ops, \
377cb74685eSSangbeom Kim .type = REGULATOR_VOLTAGE, \
378cb74685eSSangbeom Kim .owner = THIS_MODULE, \
3799d83dcb3SKrzysztof Kozlowski .min_uV = MIN_650_MV, \
3800e4f4178SAmit Daniel Kachhap .uV_step = STEP_6_25_MV, \
3819d83dcb3SKrzysztof Kozlowski .linear_min_sel = 8, \
3829d83dcb3SKrzysztof Kozlowski .n_voltages = S2MPS11_BUCK12346_N_VOLTAGES, \
38390068348SYadwinder Singh Brar .ramp_delay = S2MPS11_RAMP_DELAY, \
384cb74685eSSangbeom Kim .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
3852693fcabSAxel Lin .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
386cb74685eSSangbeom Kim .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
387cb74685eSSangbeom Kim .enable_mask = S2MPS11_ENABLE_MASK \
388cb74685eSSangbeom Kim }
389cb74685eSSangbeom Kim
39015f77300SKrzysztof Kozlowski #define regulator_desc_s2mps11_buck5 { \
391cb74685eSSangbeom Kim .name = "BUCK5", \
392cb74685eSSangbeom Kim .id = S2MPS11_BUCK5, \
393cb74685eSSangbeom Kim .ops = &s2mps11_buck_ops, \
394cb74685eSSangbeom Kim .type = REGULATOR_VOLTAGE, \
395cb74685eSSangbeom Kim .owner = THIS_MODULE, \
3969d83dcb3SKrzysztof Kozlowski .min_uV = MIN_650_MV, \
3970e4f4178SAmit Daniel Kachhap .uV_step = STEP_6_25_MV, \
3989d83dcb3SKrzysztof Kozlowski .linear_min_sel = 8, \
3999d83dcb3SKrzysztof Kozlowski .n_voltages = S2MPS11_BUCK5_N_VOLTAGES, \
40090068348SYadwinder Singh Brar .ramp_delay = S2MPS11_RAMP_DELAY, \
401cb74685eSSangbeom Kim .vsel_reg = S2MPS11_REG_B5CTRL2, \
4022693fcabSAxel Lin .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
403cb74685eSSangbeom Kim .enable_reg = S2MPS11_REG_B5CTRL1, \
404cb74685eSSangbeom Kim .enable_mask = S2MPS11_ENABLE_MASK \
405cb74685eSSangbeom Kim }
406cb74685eSSangbeom Kim
4079d83dcb3SKrzysztof Kozlowski #define regulator_desc_s2mps11_buck67810(num, min, step, min_sel, voltages) { \
408cb74685eSSangbeom Kim .name = "BUCK"#num, \
409cb74685eSSangbeom Kim .id = S2MPS11_BUCK##num, \
410cb74685eSSangbeom Kim .ops = &s2mps11_buck_ops, \
411cb74685eSSangbeom Kim .type = REGULATOR_VOLTAGE, \
412cb74685eSSangbeom Kim .owner = THIS_MODULE, \
4135a867cf2SAmit Daniel Kachhap .min_uV = min, \
4145a867cf2SAmit Daniel Kachhap .uV_step = step, \
4159d83dcb3SKrzysztof Kozlowski .linear_min_sel = min_sel, \
4169d83dcb3SKrzysztof Kozlowski .n_voltages = voltages, \
41790068348SYadwinder Singh Brar .ramp_delay = S2MPS11_RAMP_DELAY, \
418cb74685eSSangbeom Kim .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
4192693fcabSAxel Lin .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
420cb74685eSSangbeom Kim .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
421cb74685eSSangbeom Kim .enable_mask = S2MPS11_ENABLE_MASK \
422cb74685eSSangbeom Kim }
423cb74685eSSangbeom Kim
4243b672623SKrzysztof Kozlowski #define regulator_desc_s2mps11_buck9 { \
4253b672623SKrzysztof Kozlowski .name = "BUCK9", \
4263b672623SKrzysztof Kozlowski .id = S2MPS11_BUCK9, \
4273b672623SKrzysztof Kozlowski .ops = &s2mps11_buck_ops, \
4283b672623SKrzysztof Kozlowski .type = REGULATOR_VOLTAGE, \
4293b672623SKrzysztof Kozlowski .owner = THIS_MODULE, \
4303b672623SKrzysztof Kozlowski .min_uV = MIN_3000_MV, \
4313b672623SKrzysztof Kozlowski .uV_step = STEP_25_MV, \
4323b672623SKrzysztof Kozlowski .n_voltages = S2MPS11_BUCK9_N_VOLTAGES, \
4333b672623SKrzysztof Kozlowski .ramp_delay = S2MPS11_RAMP_DELAY, \
4343b672623SKrzysztof Kozlowski .vsel_reg = S2MPS11_REG_B9CTRL2, \
4353b672623SKrzysztof Kozlowski .vsel_mask = S2MPS11_BUCK9_VSEL_MASK, \
4363b672623SKrzysztof Kozlowski .enable_reg = S2MPS11_REG_B9CTRL1, \
4373b672623SKrzysztof Kozlowski .enable_mask = S2MPS11_ENABLE_MASK \
4383b672623SKrzysztof Kozlowski }
4393b672623SKrzysztof Kozlowski
4400f4cc282SKrzysztof Kozlowski static const struct regulator_desc s2mps11_regulators[] = {
4415a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(1, STEP_25_MV),
4425a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(2, STEP_50_MV),
4435a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(3, STEP_50_MV),
4445a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(4, STEP_50_MV),
4455a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(5, STEP_50_MV),
4465a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(6, STEP_25_MV),
4475a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(7, STEP_50_MV),
4485a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(8, STEP_50_MV),
4495a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(9, STEP_50_MV),
4505a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(10, STEP_50_MV),
4515a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(11, STEP_25_MV),
4525a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(12, STEP_50_MV),
4535a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(13, STEP_50_MV),
4545a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(14, STEP_50_MV),
4555a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(15, STEP_50_MV),
4565a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(16, STEP_50_MV),
4575a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(17, STEP_50_MV),
4585a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(18, STEP_50_MV),
4595a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(19, STEP_50_MV),
4605a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(20, STEP_50_MV),
4615a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(21, STEP_50_MV),
4625a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(22, STEP_25_MV),
4635a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(23, STEP_25_MV),
4645a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(24, STEP_50_MV),
4655a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(25, STEP_50_MV),
4665a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(26, STEP_50_MV),
4675a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(27, STEP_25_MV),
4685a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(28, STEP_50_MV),
4695a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(29, STEP_50_MV),
4705a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(30, STEP_50_MV),
4715a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(31, STEP_50_MV),
4725a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(32, STEP_50_MV),
4735a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(33, STEP_50_MV),
4745a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(34, STEP_50_MV),
47556b5d4eaSKrzysztof Kozlowski regulator_desc_s2mps11_ldo(35, STEP_25_MV),
4765a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(36, STEP_50_MV),
4775a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(37, STEP_50_MV),
4785a867cf2SAmit Daniel Kachhap regulator_desc_s2mps11_ldo(38, STEP_50_MV),
47915f77300SKrzysztof Kozlowski regulator_desc_s2mps11_buck1_4(1),
48015f77300SKrzysztof Kozlowski regulator_desc_s2mps11_buck1_4(2),
48115f77300SKrzysztof Kozlowski regulator_desc_s2mps11_buck1_4(3),
48215f77300SKrzysztof Kozlowski regulator_desc_s2mps11_buck1_4(4),
48315f77300SKrzysztof Kozlowski regulator_desc_s2mps11_buck5,
4849d83dcb3SKrzysztof Kozlowski regulator_desc_s2mps11_buck67810(6, MIN_650_MV, STEP_6_25_MV, 8,
4859d83dcb3SKrzysztof Kozlowski S2MPS11_BUCK12346_N_VOLTAGES),
4869d83dcb3SKrzysztof Kozlowski regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV, 0,
4879d83dcb3SKrzysztof Kozlowski S2MPS11_BUCK7810_N_VOLTAGES),
4889d83dcb3SKrzysztof Kozlowski regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV, 0,
4899d83dcb3SKrzysztof Kozlowski S2MPS11_BUCK7810_N_VOLTAGES),
4903b672623SKrzysztof Kozlowski regulator_desc_s2mps11_buck9,
4919d83dcb3SKrzysztof Kozlowski regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV, 0,
4929d83dcb3SKrzysztof Kozlowski S2MPS11_BUCK7810_N_VOLTAGES),
49315f77300SKrzysztof Kozlowski };
49415f77300SKrzysztof Kozlowski
49571b4540fSKrzysztof Kozlowski static const struct regulator_ops s2mps14_reg_ops;
49676b9840bSChanwoo Choi
49776b9840bSChanwoo Choi #define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
49876b9840bSChanwoo Choi .name = "LDO"#num, \
49976b9840bSChanwoo Choi .id = S2MPS13_LDO##num, \
50076b9840bSChanwoo Choi .ops = &s2mps14_reg_ops, \
50176b9840bSChanwoo Choi .type = REGULATOR_VOLTAGE, \
50276b9840bSChanwoo Choi .owner = THIS_MODULE, \
50376b9840bSChanwoo Choi .min_uV = min, \
50476b9840bSChanwoo Choi .uV_step = step, \
50576b9840bSChanwoo Choi .linear_min_sel = min_sel, \
50676b9840bSChanwoo Choi .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
50776b9840bSChanwoo Choi .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
50876b9840bSChanwoo Choi .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
50976b9840bSChanwoo Choi .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
51076b9840bSChanwoo Choi .enable_mask = S2MPS14_ENABLE_MASK \
51176b9840bSChanwoo Choi }
51276b9840bSChanwoo Choi
51376b9840bSChanwoo Choi #define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
51476b9840bSChanwoo Choi .name = "BUCK"#num, \
51576b9840bSChanwoo Choi .id = S2MPS13_BUCK##num, \
51676b9840bSChanwoo Choi .ops = &s2mps14_reg_ops, \
51776b9840bSChanwoo Choi .type = REGULATOR_VOLTAGE, \
51876b9840bSChanwoo Choi .owner = THIS_MODULE, \
51976b9840bSChanwoo Choi .min_uV = min, \
52076b9840bSChanwoo Choi .uV_step = step, \
52176b9840bSChanwoo Choi .linear_min_sel = min_sel, \
52276b9840bSChanwoo Choi .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
52376b9840bSChanwoo Choi .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
52476b9840bSChanwoo Choi .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
52576b9840bSChanwoo Choi .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
52676b9840bSChanwoo Choi .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
52776b9840bSChanwoo Choi .enable_mask = S2MPS14_ENABLE_MASK \
52876b9840bSChanwoo Choi }
52976b9840bSChanwoo Choi
530ad26aa6cSJonghwa Lee #define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
531ad26aa6cSJonghwa Lee .name = "BUCK"#num, \
532ad26aa6cSJonghwa Lee .id = S2MPS13_BUCK##num, \
533ad26aa6cSJonghwa Lee .ops = &s2mps14_reg_ops, \
534ad26aa6cSJonghwa Lee .type = REGULATOR_VOLTAGE, \
535ad26aa6cSJonghwa Lee .owner = THIS_MODULE, \
536ad26aa6cSJonghwa Lee .min_uV = min, \
537ad26aa6cSJonghwa Lee .uV_step = step, \
538ad26aa6cSJonghwa Lee .linear_min_sel = min_sel, \
539ad26aa6cSJonghwa Lee .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
540ad26aa6cSJonghwa Lee .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
541ad26aa6cSJonghwa Lee .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
542ad26aa6cSJonghwa Lee .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
543ad26aa6cSJonghwa Lee .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
544ad26aa6cSJonghwa Lee .enable_mask = S2MPS14_ENABLE_MASK \
545ad26aa6cSJonghwa Lee }
546ad26aa6cSJonghwa Lee
547ad26aa6cSJonghwa Lee #define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
548ad26aa6cSJonghwa Lee .name = "BUCK"#num, \
549ad26aa6cSJonghwa Lee .id = S2MPS13_BUCK##num, \
550ad26aa6cSJonghwa Lee .ops = &s2mps14_reg_ops, \
551ad26aa6cSJonghwa Lee .type = REGULATOR_VOLTAGE, \
552ad26aa6cSJonghwa Lee .owner = THIS_MODULE, \
553ad26aa6cSJonghwa Lee .min_uV = min, \
554ad26aa6cSJonghwa Lee .uV_step = step, \
555ad26aa6cSJonghwa Lee .linear_min_sel = min_sel, \
556ad26aa6cSJonghwa Lee .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
557ad26aa6cSJonghwa Lee .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
558ad26aa6cSJonghwa Lee .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
559ad26aa6cSJonghwa Lee .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
560ad26aa6cSJonghwa Lee .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
561ad26aa6cSJonghwa Lee .enable_mask = S2MPS14_ENABLE_MASK \
562ad26aa6cSJonghwa Lee }
563ad26aa6cSJonghwa Lee
56476b9840bSChanwoo Choi static const struct regulator_desc s2mps13_regulators[] = {
56576b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
56676b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
56776b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
56876b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
56976b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
57076b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
57176b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
57276b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
57376b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
57476b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
57576b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
57676b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
57776b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
57876b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
57976b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
58076b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
58176b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
58276b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
58376b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
58476b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
58576b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
58676b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
58776b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
58876b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
58976b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
59076b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
59176b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
59276b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
59376b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
59476b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
59576b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
59676b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
59776b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
59876b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
59976b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
60076b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
60176b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
60276b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
60376b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
60476b9840bSChanwoo Choi regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
60576b9840bSChanwoo Choi regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
60676b9840bSChanwoo Choi regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
60776b9840bSChanwoo Choi regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
60876b9840bSChanwoo Choi regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
60976b9840bSChanwoo Choi regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
61076b9840bSChanwoo Choi regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
611ad26aa6cSJonghwa Lee regulator_desc_s2mps13_buck7(7, MIN_500_MV, STEP_6_25_MV, 0x10),
612ad26aa6cSJonghwa Lee regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
613ad26aa6cSJonghwa Lee regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
614ad26aa6cSJonghwa Lee regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
61576b9840bSChanwoo Choi };
61676b9840bSChanwoo Choi
61771b4540fSKrzysztof Kozlowski static const struct regulator_ops s2mps14_reg_ops = {
61815f77300SKrzysztof Kozlowski .list_voltage = regulator_list_voltage_linear,
61915f77300SKrzysztof Kozlowski .map_voltage = regulator_map_voltage_linear,
62015f77300SKrzysztof Kozlowski .is_enabled = regulator_is_enabled_regmap,
62165d80db2SKrzysztof Kozlowski .enable = s2mps11_regulator_enable,
62215f77300SKrzysztof Kozlowski .disable = regulator_disable_regmap,
62315f77300SKrzysztof Kozlowski .get_voltage_sel = regulator_get_voltage_sel_regmap,
62415f77300SKrzysztof Kozlowski .set_voltage_sel = regulator_set_voltage_sel_regmap,
62515f77300SKrzysztof Kozlowski .set_voltage_time_sel = regulator_set_voltage_time_sel,
62665d80db2SKrzysztof Kozlowski .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
62715f77300SKrzysztof Kozlowski };
62815f77300SKrzysztof Kozlowski
6295a867cf2SAmit Daniel Kachhap #define regulator_desc_s2mps14_ldo(num, min, step) { \
63015f77300SKrzysztof Kozlowski .name = "LDO"#num, \
63115f77300SKrzysztof Kozlowski .id = S2MPS14_LDO##num, \
63215f77300SKrzysztof Kozlowski .ops = &s2mps14_reg_ops, \
63315f77300SKrzysztof Kozlowski .type = REGULATOR_VOLTAGE, \
63415f77300SKrzysztof Kozlowski .owner = THIS_MODULE, \
6355a867cf2SAmit Daniel Kachhap .min_uV = min, \
6365a867cf2SAmit Daniel Kachhap .uV_step = step, \
63715f77300SKrzysztof Kozlowski .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
63815f77300SKrzysztof Kozlowski .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
63915f77300SKrzysztof Kozlowski .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
64015f77300SKrzysztof Kozlowski .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
64115f77300SKrzysztof Kozlowski .enable_mask = S2MPS14_ENABLE_MASK \
64215f77300SKrzysztof Kozlowski }
6435a867cf2SAmit Daniel Kachhap
6441222d8feSKrzysztof Kozlowski #define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
64515f77300SKrzysztof Kozlowski .name = "BUCK"#num, \
64615f77300SKrzysztof Kozlowski .id = S2MPS14_BUCK##num, \
64715f77300SKrzysztof Kozlowski .ops = &s2mps14_reg_ops, \
64815f77300SKrzysztof Kozlowski .type = REGULATOR_VOLTAGE, \
64915f77300SKrzysztof Kozlowski .owner = THIS_MODULE, \
6505a867cf2SAmit Daniel Kachhap .min_uV = min, \
6515a867cf2SAmit Daniel Kachhap .uV_step = step, \
65215f77300SKrzysztof Kozlowski .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
6531222d8feSKrzysztof Kozlowski .linear_min_sel = min_sel, \
65415f77300SKrzysztof Kozlowski .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
65515f77300SKrzysztof Kozlowski .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
65615f77300SKrzysztof Kozlowski .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
65715f77300SKrzysztof Kozlowski .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
65815f77300SKrzysztof Kozlowski .enable_mask = S2MPS14_ENABLE_MASK \
65915f77300SKrzysztof Kozlowski }
66015f77300SKrzysztof Kozlowski
66115f77300SKrzysztof Kozlowski static const struct regulator_desc s2mps14_regulators[] = {
6625a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
6635a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
6645a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
6655a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
6665a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
6675a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
6685a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
6695a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
6705a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
6715a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
6725a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
6735a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
6745a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
6755a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
6765a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
6775a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
6785a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
6795a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
6805a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
6815a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
6825a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
6835a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
6845a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
6855a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
6865a867cf2SAmit Daniel Kachhap regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
6871222d8feSKrzysztof Kozlowski regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
6881222d8feSKrzysztof Kozlowski S2MPS14_BUCK1235_START_SEL),
6891222d8feSKrzysztof Kozlowski regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
6901222d8feSKrzysztof Kozlowski S2MPS14_BUCK1235_START_SEL),
6911222d8feSKrzysztof Kozlowski regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
6921222d8feSKrzysztof Kozlowski S2MPS14_BUCK1235_START_SEL),
6931222d8feSKrzysztof Kozlowski regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
6941222d8feSKrzysztof Kozlowski S2MPS14_BUCK4_START_SEL),
6951222d8feSKrzysztof Kozlowski regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
6961222d8feSKrzysztof Kozlowski S2MPS14_BUCK1235_START_SEL),
697cb74685eSSangbeom Kim };
698cb74685eSSangbeom Kim
69971b4540fSKrzysztof Kozlowski static const struct regulator_ops s2mps15_reg_ldo_ops = {
70051af2067SThomas Abraham .list_voltage = regulator_list_voltage_linear_range,
70151af2067SThomas Abraham .map_voltage = regulator_map_voltage_linear_range,
70251af2067SThomas Abraham .is_enabled = regulator_is_enabled_regmap,
70351af2067SThomas Abraham .enable = regulator_enable_regmap,
70451af2067SThomas Abraham .disable = regulator_disable_regmap,
70551af2067SThomas Abraham .get_voltage_sel = regulator_get_voltage_sel_regmap,
70651af2067SThomas Abraham .set_voltage_sel = regulator_set_voltage_sel_regmap,
70751af2067SThomas Abraham };
70851af2067SThomas Abraham
70971b4540fSKrzysztof Kozlowski static const struct regulator_ops s2mps15_reg_buck_ops = {
71051af2067SThomas Abraham .list_voltage = regulator_list_voltage_linear_range,
71151af2067SThomas Abraham .map_voltage = regulator_map_voltage_linear_range,
71251af2067SThomas Abraham .is_enabled = regulator_is_enabled_regmap,
71351af2067SThomas Abraham .enable = regulator_enable_regmap,
71451af2067SThomas Abraham .disable = regulator_disable_regmap,
71551af2067SThomas Abraham .get_voltage_sel = regulator_get_voltage_sel_regmap,
71651af2067SThomas Abraham .set_voltage_sel = regulator_set_voltage_sel_regmap,
71751af2067SThomas Abraham .set_voltage_time_sel = regulator_set_voltage_time_sel,
71851af2067SThomas Abraham };
71951af2067SThomas Abraham
72051af2067SThomas Abraham #define regulator_desc_s2mps15_ldo(num, range) { \
72151af2067SThomas Abraham .name = "LDO"#num, \
72251af2067SThomas Abraham .id = S2MPS15_LDO##num, \
72351af2067SThomas Abraham .ops = &s2mps15_reg_ldo_ops, \
72451af2067SThomas Abraham .type = REGULATOR_VOLTAGE, \
72551af2067SThomas Abraham .owner = THIS_MODULE, \
72651af2067SThomas Abraham .linear_ranges = range, \
72751af2067SThomas Abraham .n_linear_ranges = ARRAY_SIZE(range), \
72851af2067SThomas Abraham .n_voltages = S2MPS15_LDO_N_VOLTAGES, \
72951af2067SThomas Abraham .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
73051af2067SThomas Abraham .vsel_mask = S2MPS15_LDO_VSEL_MASK, \
73151af2067SThomas Abraham .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
73251af2067SThomas Abraham .enable_mask = S2MPS15_ENABLE_MASK \
73351af2067SThomas Abraham }
73451af2067SThomas Abraham
73551af2067SThomas Abraham #define regulator_desc_s2mps15_buck(num, range) { \
73651af2067SThomas Abraham .name = "BUCK"#num, \
73751af2067SThomas Abraham .id = S2MPS15_BUCK##num, \
73851af2067SThomas Abraham .ops = &s2mps15_reg_buck_ops, \
73951af2067SThomas Abraham .type = REGULATOR_VOLTAGE, \
74051af2067SThomas Abraham .owner = THIS_MODULE, \
74151af2067SThomas Abraham .linear_ranges = range, \
74251af2067SThomas Abraham .n_linear_ranges = ARRAY_SIZE(range), \
74351af2067SThomas Abraham .ramp_delay = 12500, \
74451af2067SThomas Abraham .n_voltages = S2MPS15_BUCK_N_VOLTAGES, \
74551af2067SThomas Abraham .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
74651af2067SThomas Abraham .vsel_mask = S2MPS15_BUCK_VSEL_MASK, \
74751af2067SThomas Abraham .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
74851af2067SThomas Abraham .enable_mask = S2MPS15_ENABLE_MASK \
74951af2067SThomas Abraham }
75051af2067SThomas Abraham
75151af2067SThomas Abraham /* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
75260ab7f41SMatti Vaittinen static const struct linear_range s2mps15_ldo_voltage_ranges1[] = {
75351af2067SThomas Abraham REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
75451af2067SThomas Abraham };
75551af2067SThomas Abraham
75651af2067SThomas Abraham /* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
75760ab7f41SMatti Vaittinen static const struct linear_range s2mps15_ldo_voltage_ranges2[] = {
75851af2067SThomas Abraham REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
75951af2067SThomas Abraham };
76051af2067SThomas Abraham
76151af2067SThomas Abraham /* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
76260ab7f41SMatti Vaittinen static const struct linear_range s2mps15_ldo_voltage_ranges3[] = {
76351af2067SThomas Abraham REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
76451af2067SThomas Abraham };
76551af2067SThomas Abraham
76651af2067SThomas Abraham /* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
76760ab7f41SMatti Vaittinen static const struct linear_range s2mps15_ldo_voltage_ranges4[] = {
76804c16b84SAlim Akhtar REGULATOR_LINEAR_RANGE(700000, 0x10, 0x20, 25000),
76951af2067SThomas Abraham };
77051af2067SThomas Abraham
77151af2067SThomas Abraham /* voltage range for s2mps15 LDO 1 */
77260ab7f41SMatti Vaittinen static const struct linear_range s2mps15_ldo_voltage_ranges5[] = {
77351af2067SThomas Abraham REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
77451af2067SThomas Abraham };
77551af2067SThomas Abraham
77651af2067SThomas Abraham /* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
77760ab7f41SMatti Vaittinen static const struct linear_range s2mps15_buck_voltage_ranges1[] = {
77804c16b84SAlim Akhtar REGULATOR_LINEAR_RANGE(500000, 0x20, 0xc0, 6250),
77951af2067SThomas Abraham };
78051af2067SThomas Abraham
78151af2067SThomas Abraham /* voltage range for s2mps15 BUCK 8, 9 and 10 */
78260ab7f41SMatti Vaittinen static const struct linear_range s2mps15_buck_voltage_ranges2[] = {
78304c16b84SAlim Akhtar REGULATOR_LINEAR_RANGE(1000000, 0x20, 0x78, 12500),
78451af2067SThomas Abraham };
78551af2067SThomas Abraham
78651af2067SThomas Abraham static const struct regulator_desc s2mps15_regulators[] = {
78751af2067SThomas Abraham regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5),
78851af2067SThomas Abraham regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2),
78951af2067SThomas Abraham regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1),
79051af2067SThomas Abraham regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3),
79151af2067SThomas Abraham regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1),
79251af2067SThomas Abraham regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2),
79351af2067SThomas Abraham regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4),
79451af2067SThomas Abraham regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4),
79551af2067SThomas Abraham regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4),
79651af2067SThomas Abraham regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4),
79751af2067SThomas Abraham regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3),
79851af2067SThomas Abraham regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3),
79951af2067SThomas Abraham regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3),
80051af2067SThomas Abraham regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2),
80151af2067SThomas Abraham regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1),
80251af2067SThomas Abraham regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1),
80351af2067SThomas Abraham regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2),
80451af2067SThomas Abraham regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1),
80551af2067SThomas Abraham regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2),
80651af2067SThomas Abraham regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1),
80751af2067SThomas Abraham regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2),
80851af2067SThomas Abraham regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3),
80951af2067SThomas Abraham regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1),
81051af2067SThomas Abraham regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2),
81151af2067SThomas Abraham regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2),
81251af2067SThomas Abraham regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3),
81351af2067SThomas Abraham regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1),
81451af2067SThomas Abraham regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1),
81551af2067SThomas Abraham regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1),
81651af2067SThomas Abraham regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1),
81751af2067SThomas Abraham regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1),
81851af2067SThomas Abraham regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1),
81951af2067SThomas Abraham regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1),
82051af2067SThomas Abraham regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1),
82151af2067SThomas Abraham regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2),
82251af2067SThomas Abraham regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2),
82351af2067SThomas Abraham regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2),
82451af2067SThomas Abraham };
82551af2067SThomas Abraham
s2mps14_pmic_enable_ext_control(struct s2mps11_info * s2mps11,struct regulator_dev * rdev)82697f53d71SKrzysztof Kozlowski static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
82797f53d71SKrzysztof Kozlowski struct regulator_dev *rdev)
82897f53d71SKrzysztof Kozlowski {
82997f53d71SKrzysztof Kozlowski return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
83097f53d71SKrzysztof Kozlowski rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
83197f53d71SKrzysztof Kozlowski }
83297f53d71SKrzysztof Kozlowski
s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device * pdev,struct of_regulator_match * rdata,struct s2mps11_info * s2mps11)83397f53d71SKrzysztof Kozlowski static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
83401170383SKrzysztof Kozlowski struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
83501170383SKrzysztof Kozlowski {
8361c984942SLinus Walleij struct gpio_desc **gpio = s2mps11->ext_control_gpiod;
83797f53d71SKrzysztof Kozlowski unsigned int i;
83897f53d71SKrzysztof Kozlowski unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
83997f53d71SKrzysztof Kozlowski S2MPS14_LDO12 };
84097f53d71SKrzysztof Kozlowski
84197f53d71SKrzysztof Kozlowski for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
84297f53d71SKrzysztof Kozlowski unsigned int reg = valid_regulators[i];
84397f53d71SKrzysztof Kozlowski
84497f53d71SKrzysztof Kozlowski if (!rdata[reg].init_data || !rdata[reg].of_node)
84597f53d71SKrzysztof Kozlowski continue;
84697f53d71SKrzysztof Kozlowski
847de2792b5SDmitry Torokhov gpio[reg] = devm_fwnode_gpiod_get(&pdev->dev,
848de2792b5SDmitry Torokhov of_fwnode_handle(rdata[reg].of_node),
849de2792b5SDmitry Torokhov "samsung,ext-control",
8501c984942SLinus Walleij GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
8511c984942SLinus Walleij "s2mps11-regulator");
852025bf377SWaibel Georg if (PTR_ERR(gpio[reg]) == -ENOENT)
853025bf377SWaibel Georg gpio[reg] = NULL;
854025bf377SWaibel Georg else if (IS_ERR(gpio[reg])) {
8551c984942SLinus Walleij dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n",
8561c984942SLinus Walleij reg, rdata[reg].name);
85770ca117bSKrzysztof Kozlowski gpio[reg] = NULL;
8581c984942SLinus Walleij continue;
8591c984942SLinus Walleij }
8601c984942SLinus Walleij if (gpio[reg])
8611c984942SLinus Walleij dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n",
8621c984942SLinus Walleij reg, rdata[reg].name);
86397f53d71SKrzysztof Kozlowski }
86497f53d71SKrzysztof Kozlowski }
86597f53d71SKrzysztof Kozlowski
s2mps11_pmic_dt_parse(struct platform_device * pdev,struct of_regulator_match * rdata,struct s2mps11_info * s2mps11,unsigned int rdev_num)86697f53d71SKrzysztof Kozlowski static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
8677ddec641SKrzysztof Kozlowski struct of_regulator_match *rdata, struct s2mps11_info *s2mps11,
8687ddec641SKrzysztof Kozlowski unsigned int rdev_num)
86997f53d71SKrzysztof Kozlowski {
87001170383SKrzysztof Kozlowski struct device_node *reg_np;
87101170383SKrzysztof Kozlowski
87201170383SKrzysztof Kozlowski reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
87301170383SKrzysztof Kozlowski if (!reg_np) {
87401170383SKrzysztof Kozlowski dev_err(&pdev->dev, "could not find regulators sub-node\n");
87501170383SKrzysztof Kozlowski return -EINVAL;
87601170383SKrzysztof Kozlowski }
87701170383SKrzysztof Kozlowski
8787ddec641SKrzysztof Kozlowski of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num);
87900e2573dSChanwoo Choi if (s2mps11->dev_type == S2MPS14X)
88097f53d71SKrzysztof Kozlowski s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
88197f53d71SKrzysztof Kozlowski
88201170383SKrzysztof Kozlowski of_node_put(reg_np);
88301170383SKrzysztof Kozlowski
88401170383SKrzysztof Kozlowski return 0;
88501170383SKrzysztof Kozlowski }
88601170383SKrzysztof Kozlowski
s2mpu02_set_ramp_delay(struct regulator_dev * rdev,int ramp_delay)88700e2573dSChanwoo Choi static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
88800e2573dSChanwoo Choi {
88900e2573dSChanwoo Choi unsigned int ramp_val, ramp_shift, ramp_reg;
890df33799cSKrzysztof Kozlowski int rdev_id = rdev_get_id(rdev);
89100e2573dSChanwoo Choi
892df33799cSKrzysztof Kozlowski switch (rdev_id) {
89300e2573dSChanwoo Choi case S2MPU02_BUCK1:
89400e2573dSChanwoo Choi ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
89500e2573dSChanwoo Choi break;
89600e2573dSChanwoo Choi case S2MPU02_BUCK2:
89700e2573dSChanwoo Choi ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
89800e2573dSChanwoo Choi break;
89900e2573dSChanwoo Choi case S2MPU02_BUCK3:
90000e2573dSChanwoo Choi ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
90100e2573dSChanwoo Choi break;
90200e2573dSChanwoo Choi case S2MPU02_BUCK4:
90300e2573dSChanwoo Choi ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
90400e2573dSChanwoo Choi break;
90500e2573dSChanwoo Choi default:
90600e2573dSChanwoo Choi return 0;
90700e2573dSChanwoo Choi }
90800e2573dSChanwoo Choi ramp_reg = S2MPU02_REG_RAMP1;
90900e2573dSChanwoo Choi ramp_val = get_ramp_delay(ramp_delay);
91000e2573dSChanwoo Choi
91100e2573dSChanwoo Choi return regmap_update_bits(rdev->regmap, ramp_reg,
91200e2573dSChanwoo Choi S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
91300e2573dSChanwoo Choi ramp_val << ramp_shift);
91400e2573dSChanwoo Choi }
91500e2573dSChanwoo Choi
91671b4540fSKrzysztof Kozlowski static const struct regulator_ops s2mpu02_ldo_ops = {
91700e2573dSChanwoo Choi .list_voltage = regulator_list_voltage_linear,
91800e2573dSChanwoo Choi .map_voltage = regulator_map_voltage_linear,
91900e2573dSChanwoo Choi .is_enabled = regulator_is_enabled_regmap,
92065d80db2SKrzysztof Kozlowski .enable = s2mps11_regulator_enable,
92100e2573dSChanwoo Choi .disable = regulator_disable_regmap,
92200e2573dSChanwoo Choi .get_voltage_sel = regulator_get_voltage_sel_regmap,
92300e2573dSChanwoo Choi .set_voltage_sel = regulator_set_voltage_sel_regmap,
92400e2573dSChanwoo Choi .set_voltage_time_sel = regulator_set_voltage_time_sel,
92565d80db2SKrzysztof Kozlowski .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
92600e2573dSChanwoo Choi };
92700e2573dSChanwoo Choi
92871b4540fSKrzysztof Kozlowski static const struct regulator_ops s2mpu02_buck_ops = {
92900e2573dSChanwoo Choi .list_voltage = regulator_list_voltage_linear,
93000e2573dSChanwoo Choi .map_voltage = regulator_map_voltage_linear,
93100e2573dSChanwoo Choi .is_enabled = regulator_is_enabled_regmap,
93265d80db2SKrzysztof Kozlowski .enable = s2mps11_regulator_enable,
93300e2573dSChanwoo Choi .disable = regulator_disable_regmap,
93400e2573dSChanwoo Choi .get_voltage_sel = regulator_get_voltage_sel_regmap,
93500e2573dSChanwoo Choi .set_voltage_sel = regulator_set_voltage_sel_regmap,
93600e2573dSChanwoo Choi .set_voltage_time_sel = regulator_set_voltage_time_sel,
93765d80db2SKrzysztof Kozlowski .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
93800e2573dSChanwoo Choi .set_ramp_delay = s2mpu02_set_ramp_delay,
93900e2573dSChanwoo Choi };
94000e2573dSChanwoo Choi
94100e2573dSChanwoo Choi #define regulator_desc_s2mpu02_ldo1(num) { \
94200e2573dSChanwoo Choi .name = "LDO"#num, \
94300e2573dSChanwoo Choi .id = S2MPU02_LDO##num, \
94400e2573dSChanwoo Choi .ops = &s2mpu02_ldo_ops, \
94500e2573dSChanwoo Choi .type = REGULATOR_VOLTAGE, \
94600e2573dSChanwoo Choi .owner = THIS_MODULE, \
94700e2573dSChanwoo Choi .min_uV = S2MPU02_LDO_MIN_900MV, \
94800e2573dSChanwoo Choi .uV_step = S2MPU02_LDO_STEP_12_5MV, \
94900e2573dSChanwoo Choi .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
95000e2573dSChanwoo Choi .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
95100e2573dSChanwoo Choi .vsel_reg = S2MPU02_REG_L1CTRL, \
95200e2573dSChanwoo Choi .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
95300e2573dSChanwoo Choi .enable_reg = S2MPU02_REG_L1CTRL, \
95400e2573dSChanwoo Choi .enable_mask = S2MPU02_ENABLE_MASK \
95500e2573dSChanwoo Choi }
95600e2573dSChanwoo Choi #define regulator_desc_s2mpu02_ldo2(num) { \
95700e2573dSChanwoo Choi .name = "LDO"#num, \
95800e2573dSChanwoo Choi .id = S2MPU02_LDO##num, \
95900e2573dSChanwoo Choi .ops = &s2mpu02_ldo_ops, \
96000e2573dSChanwoo Choi .type = REGULATOR_VOLTAGE, \
96100e2573dSChanwoo Choi .owner = THIS_MODULE, \
96200e2573dSChanwoo Choi .min_uV = S2MPU02_LDO_MIN_1050MV, \
96300e2573dSChanwoo Choi .uV_step = S2MPU02_LDO_STEP_25MV, \
96400e2573dSChanwoo Choi .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
96500e2573dSChanwoo Choi .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
96600e2573dSChanwoo Choi .vsel_reg = S2MPU02_REG_L2CTRL1, \
96700e2573dSChanwoo Choi .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
96800e2573dSChanwoo Choi .enable_reg = S2MPU02_REG_L2CTRL1, \
96900e2573dSChanwoo Choi .enable_mask = S2MPU02_ENABLE_MASK \
97000e2573dSChanwoo Choi }
97100e2573dSChanwoo Choi #define regulator_desc_s2mpu02_ldo3(num) { \
97200e2573dSChanwoo Choi .name = "LDO"#num, \
97300e2573dSChanwoo Choi .id = S2MPU02_LDO##num, \
97400e2573dSChanwoo Choi .ops = &s2mpu02_ldo_ops, \
97500e2573dSChanwoo Choi .type = REGULATOR_VOLTAGE, \
97600e2573dSChanwoo Choi .owner = THIS_MODULE, \
97700e2573dSChanwoo Choi .min_uV = S2MPU02_LDO_MIN_900MV, \
97800e2573dSChanwoo Choi .uV_step = S2MPU02_LDO_STEP_12_5MV, \
97900e2573dSChanwoo Choi .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
98000e2573dSChanwoo Choi .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
98100e2573dSChanwoo Choi .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
98200e2573dSChanwoo Choi .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
98300e2573dSChanwoo Choi .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
98400e2573dSChanwoo Choi .enable_mask = S2MPU02_ENABLE_MASK \
98500e2573dSChanwoo Choi }
98600e2573dSChanwoo Choi #define regulator_desc_s2mpu02_ldo4(num) { \
98700e2573dSChanwoo Choi .name = "LDO"#num, \
98800e2573dSChanwoo Choi .id = S2MPU02_LDO##num, \
98900e2573dSChanwoo Choi .ops = &s2mpu02_ldo_ops, \
99000e2573dSChanwoo Choi .type = REGULATOR_VOLTAGE, \
99100e2573dSChanwoo Choi .owner = THIS_MODULE, \
99200e2573dSChanwoo Choi .min_uV = S2MPU02_LDO_MIN_1050MV, \
99300e2573dSChanwoo Choi .uV_step = S2MPU02_LDO_STEP_25MV, \
99400e2573dSChanwoo Choi .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
99500e2573dSChanwoo Choi .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
99600e2573dSChanwoo Choi .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
99700e2573dSChanwoo Choi .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
99800e2573dSChanwoo Choi .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
99900e2573dSChanwoo Choi .enable_mask = S2MPU02_ENABLE_MASK \
100000e2573dSChanwoo Choi }
100100e2573dSChanwoo Choi #define regulator_desc_s2mpu02_ldo5(num) { \
100200e2573dSChanwoo Choi .name = "LDO"#num, \
100300e2573dSChanwoo Choi .id = S2MPU02_LDO##num, \
100400e2573dSChanwoo Choi .ops = &s2mpu02_ldo_ops, \
100500e2573dSChanwoo Choi .type = REGULATOR_VOLTAGE, \
100600e2573dSChanwoo Choi .owner = THIS_MODULE, \
100700e2573dSChanwoo Choi .min_uV = S2MPU02_LDO_MIN_1600MV, \
100800e2573dSChanwoo Choi .uV_step = S2MPU02_LDO_STEP_50MV, \
100900e2573dSChanwoo Choi .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
101000e2573dSChanwoo Choi .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
101100e2573dSChanwoo Choi .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
101200e2573dSChanwoo Choi .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
101300e2573dSChanwoo Choi .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
101400e2573dSChanwoo Choi .enable_mask = S2MPU02_ENABLE_MASK \
101500e2573dSChanwoo Choi }
101600e2573dSChanwoo Choi
101700e2573dSChanwoo Choi #define regulator_desc_s2mpu02_buck1234(num) { \
101800e2573dSChanwoo Choi .name = "BUCK"#num, \
101900e2573dSChanwoo Choi .id = S2MPU02_BUCK##num, \
102000e2573dSChanwoo Choi .ops = &s2mpu02_buck_ops, \
102100e2573dSChanwoo Choi .type = REGULATOR_VOLTAGE, \
102200e2573dSChanwoo Choi .owner = THIS_MODULE, \
102300e2573dSChanwoo Choi .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
102400e2573dSChanwoo Choi .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
102500e2573dSChanwoo Choi .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
102600e2573dSChanwoo Choi .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
102700e2573dSChanwoo Choi .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
102800e2573dSChanwoo Choi .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
102900e2573dSChanwoo Choi .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
103000e2573dSChanwoo Choi .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
103100e2573dSChanwoo Choi .enable_mask = S2MPU02_ENABLE_MASK \
103200e2573dSChanwoo Choi }
103300e2573dSChanwoo Choi #define regulator_desc_s2mpu02_buck5(num) { \
103400e2573dSChanwoo Choi .name = "BUCK"#num, \
103500e2573dSChanwoo Choi .id = S2MPU02_BUCK##num, \
103600e2573dSChanwoo Choi .ops = &s2mpu02_ldo_ops, \
103700e2573dSChanwoo Choi .type = REGULATOR_VOLTAGE, \
103800e2573dSChanwoo Choi .owner = THIS_MODULE, \
103900e2573dSChanwoo Choi .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
104000e2573dSChanwoo Choi .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
104100e2573dSChanwoo Choi .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
104200e2573dSChanwoo Choi .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
104300e2573dSChanwoo Choi .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
104400e2573dSChanwoo Choi .vsel_reg = S2MPU02_REG_B5CTRL2, \
104500e2573dSChanwoo Choi .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
104600e2573dSChanwoo Choi .enable_reg = S2MPU02_REG_B5CTRL1, \
104700e2573dSChanwoo Choi .enable_mask = S2MPU02_ENABLE_MASK \
104800e2573dSChanwoo Choi }
104900e2573dSChanwoo Choi #define regulator_desc_s2mpu02_buck6(num) { \
105000e2573dSChanwoo Choi .name = "BUCK"#num, \
105100e2573dSChanwoo Choi .id = S2MPU02_BUCK##num, \
105200e2573dSChanwoo Choi .ops = &s2mpu02_ldo_ops, \
105300e2573dSChanwoo Choi .type = REGULATOR_VOLTAGE, \
105400e2573dSChanwoo Choi .owner = THIS_MODULE, \
105500e2573dSChanwoo Choi .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
105600e2573dSChanwoo Choi .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
105700e2573dSChanwoo Choi .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
105800e2573dSChanwoo Choi .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
105900e2573dSChanwoo Choi .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
106000e2573dSChanwoo Choi .vsel_reg = S2MPU02_REG_B6CTRL2, \
106100e2573dSChanwoo Choi .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
106200e2573dSChanwoo Choi .enable_reg = S2MPU02_REG_B6CTRL1, \
106300e2573dSChanwoo Choi .enable_mask = S2MPU02_ENABLE_MASK \
106400e2573dSChanwoo Choi }
106500e2573dSChanwoo Choi #define regulator_desc_s2mpu02_buck7(num) { \
106600e2573dSChanwoo Choi .name = "BUCK"#num, \
106700e2573dSChanwoo Choi .id = S2MPU02_BUCK##num, \
106800e2573dSChanwoo Choi .ops = &s2mpu02_ldo_ops, \
106900e2573dSChanwoo Choi .type = REGULATOR_VOLTAGE, \
107000e2573dSChanwoo Choi .owner = THIS_MODULE, \
107100e2573dSChanwoo Choi .min_uV = S2MPU02_BUCK7_MIN_900MV, \
107200e2573dSChanwoo Choi .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
107300e2573dSChanwoo Choi .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
107400e2573dSChanwoo Choi .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
107500e2573dSChanwoo Choi .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
107600e2573dSChanwoo Choi .vsel_reg = S2MPU02_REG_B7CTRL2, \
107700e2573dSChanwoo Choi .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
107800e2573dSChanwoo Choi .enable_reg = S2MPU02_REG_B7CTRL1, \
107900e2573dSChanwoo Choi .enable_mask = S2MPU02_ENABLE_MASK \
108000e2573dSChanwoo Choi }
108100e2573dSChanwoo Choi
108200e2573dSChanwoo Choi static const struct regulator_desc s2mpu02_regulators[] = {
108300e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo1(1),
108400e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo2(2),
108500e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo4(3),
108600e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(4),
108700e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo4(5),
108800e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo3(6),
108900e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo3(7),
109000e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo4(8),
109100e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(9),
109200e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo3(10),
109300e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo4(11),
109400e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(12),
109500e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(13),
109600e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(14),
109700e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(15),
109800e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(16),
109900e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo4(17),
110000e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(18),
110100e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo3(19),
110200e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo4(20),
110300e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(21),
110400e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(22),
110500e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(23),
110600e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo4(24),
110700e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(25),
110800e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo4(26),
110900e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(27),
111000e2573dSChanwoo Choi regulator_desc_s2mpu02_ldo5(28),
111100e2573dSChanwoo Choi regulator_desc_s2mpu02_buck1234(1),
111200e2573dSChanwoo Choi regulator_desc_s2mpu02_buck1234(2),
111300e2573dSChanwoo Choi regulator_desc_s2mpu02_buck1234(3),
111400e2573dSChanwoo Choi regulator_desc_s2mpu02_buck1234(4),
111500e2573dSChanwoo Choi regulator_desc_s2mpu02_buck5(5),
111600e2573dSChanwoo Choi regulator_desc_s2mpu02_buck6(6),
111700e2573dSChanwoo Choi regulator_desc_s2mpu02_buck7(7),
111800e2573dSChanwoo Choi };
111900e2573dSChanwoo Choi
s2mps11_pmic_probe(struct platform_device * pdev)1120a5023574SBill Pemberton static int s2mps11_pmic_probe(struct platform_device *pdev)
1121cb74685eSSangbeom Kim {
1122cb74685eSSangbeom Kim struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
11233e80f95bSKrzysztof Kozlowski struct of_regulator_match *rdata = NULL;
1124cb74685eSSangbeom Kim struct regulator_config config = { };
1125cb74685eSSangbeom Kim struct s2mps11_info *s2mps11;
11267ddec641SKrzysztof Kozlowski unsigned int rdev_num = 0;
11273e80f95bSKrzysztof Kozlowski int i, ret = 0;
11280f4cc282SKrzysztof Kozlowski const struct regulator_desc *regulators;
1129cb74685eSSangbeom Kim
1130cb74685eSSangbeom Kim s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
1131cb74685eSSangbeom Kim GFP_KERNEL);
1132cb74685eSSangbeom Kim if (!s2mps11)
1133cb74685eSSangbeom Kim return -ENOMEM;
1134cb74685eSSangbeom Kim
113500e2573dSChanwoo Choi s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
113600e2573dSChanwoo Choi switch (s2mps11->dev_type) {
11370f4cc282SKrzysztof Kozlowski case S2MPS11X:
11387ddec641SKrzysztof Kozlowski rdev_num = ARRAY_SIZE(s2mps11_regulators);
11390f4cc282SKrzysztof Kozlowski regulators = s2mps11_regulators;
1140297eaaa6SKrzysztof Kozlowski BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators));
11410f4cc282SKrzysztof Kozlowski break;
114276b9840bSChanwoo Choi case S2MPS13X:
11437ddec641SKrzysztof Kozlowski rdev_num = ARRAY_SIZE(s2mps13_regulators);
114476b9840bSChanwoo Choi regulators = s2mps13_regulators;
1145297eaaa6SKrzysztof Kozlowski BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators));
114676b9840bSChanwoo Choi break;
114715f77300SKrzysztof Kozlowski case S2MPS14X:
11487ddec641SKrzysztof Kozlowski rdev_num = ARRAY_SIZE(s2mps14_regulators);
114915f77300SKrzysztof Kozlowski regulators = s2mps14_regulators;
1150297eaaa6SKrzysztof Kozlowski BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators));
115115f77300SKrzysztof Kozlowski break;
115251af2067SThomas Abraham case S2MPS15X:
11537ddec641SKrzysztof Kozlowski rdev_num = ARRAY_SIZE(s2mps15_regulators);
115451af2067SThomas Abraham regulators = s2mps15_regulators;
1155297eaaa6SKrzysztof Kozlowski BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators));
115651af2067SThomas Abraham break;
115700e2573dSChanwoo Choi case S2MPU02:
11587ddec641SKrzysztof Kozlowski rdev_num = ARRAY_SIZE(s2mpu02_regulators);
115900e2573dSChanwoo Choi regulators = s2mpu02_regulators;
1160297eaaa6SKrzysztof Kozlowski BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators));
116100e2573dSChanwoo Choi break;
11620f4cc282SKrzysztof Kozlowski default:
116300e2573dSChanwoo Choi dev_err(&pdev->dev, "Invalid device type: %u\n",
116400e2573dSChanwoo Choi s2mps11->dev_type);
11650f4cc282SKrzysztof Kozlowski return -EINVAL;
11667cf225b9SKrzysztof Kozlowski }
11673e80f95bSKrzysztof Kozlowski
1168d7c7fc44SMarek Szyprowski s2mps11->ext_control_gpiod = devm_kcalloc(&pdev->dev, rdev_num,
1169d7c7fc44SMarek Szyprowski sizeof(*s2mps11->ext_control_gpiod), GFP_KERNEL);
11701c984942SLinus Walleij if (!s2mps11->ext_control_gpiod)
117197f53d71SKrzysztof Kozlowski return -ENOMEM;
117297f53d71SKrzysztof Kozlowski
11736396bb22SKees Cook rdata = kcalloc(rdev_num, sizeof(*rdata), GFP_KERNEL);
11743e80f95bSKrzysztof Kozlowski if (!rdata)
11753e80f95bSKrzysztof Kozlowski return -ENOMEM;
11763e80f95bSKrzysztof Kozlowski
11777ddec641SKrzysztof Kozlowski for (i = 0; i < rdev_num; i++)
1178a50c6b32SYadwinder Singh Brar rdata[i].name = regulators[i].name;
1179a50c6b32SYadwinder Singh Brar
11807ddec641SKrzysztof Kozlowski ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num);
118101170383SKrzysztof Kozlowski if (ret)
11823e80f95bSKrzysztof Kozlowski goto out;
1183a50c6b32SYadwinder Singh Brar
1184a50c6b32SYadwinder Singh Brar platform_set_drvdata(pdev, s2mps11);
1185cb74685eSSangbeom Kim
1186232b2504SAxel Lin config.dev = &pdev->dev;
11871b1ccee1SKrzysztof Kozlowski config.regmap = iodev->regmap_pmic;
1188cb74685eSSangbeom Kim config.driver_data = s2mps11;
11897ddec641SKrzysztof Kozlowski for (i = 0; i < rdev_num; i++) {
119031195252SKrzysztof Kozlowski struct regulator_dev *regulator;
119131195252SKrzysztof Kozlowski
1192a50c6b32SYadwinder Singh Brar config.init_data = rdata[i].init_data;
1193a50c6b32SYadwinder Singh Brar config.of_node = rdata[i].of_node;
11941c984942SLinus Walleij config.ena_gpiod = s2mps11->ext_control_gpiod[i];
11952b96edb5SLinus Walleij /*
11962b96edb5SLinus Walleij * Hand the GPIO descriptor management over to the regulator
11972b96edb5SLinus Walleij * core, remove it from devres management.
11982b96edb5SLinus Walleij */
11992b96edb5SLinus Walleij if (config.ena_gpiod)
12002b96edb5SLinus Walleij devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod);
120131195252SKrzysztof Kozlowski regulator = devm_regulator_register(&pdev->dev,
1202d55cd794SSachin Kamat ®ulators[i], &config);
120331195252SKrzysztof Kozlowski if (IS_ERR(regulator)) {
120431195252SKrzysztof Kozlowski ret = PTR_ERR(regulator);
1205232b2504SAxel Lin dev_err(&pdev->dev, "regulator init failed for %d\n",
1206cb74685eSSangbeom Kim i);
12073e80f95bSKrzysztof Kozlowski goto out;
1208cb74685eSSangbeom Kim }
120997f53d71SKrzysztof Kozlowski
1210d57d90f4SKrzysztof Kozlowski if (config.ena_gpiod) {
121197f53d71SKrzysztof Kozlowski ret = s2mps14_pmic_enable_ext_control(s2mps11,
121297f53d71SKrzysztof Kozlowski regulator);
121397f53d71SKrzysztof Kozlowski if (ret < 0) {
121497f53d71SKrzysztof Kozlowski dev_err(&pdev->dev,
121597f53d71SKrzysztof Kozlowski "failed to enable GPIO control over %s: %d\n",
121697f53d71SKrzysztof Kozlowski regulator->desc->name, ret);
121797f53d71SKrzysztof Kozlowski goto out;
121897f53d71SKrzysztof Kozlowski }
121997f53d71SKrzysztof Kozlowski }
1220b707a274SMark Brown }
1221cb74685eSSangbeom Kim
12223e80f95bSKrzysztof Kozlowski out:
12233e80f95bSKrzysztof Kozlowski kfree(rdata);
12243e80f95bSKrzysztof Kozlowski
12253e80f95bSKrzysztof Kozlowski return ret;
1226cb74685eSSangbeom Kim }
1227cb74685eSSangbeom Kim
1228cb74685eSSangbeom Kim static const struct platform_device_id s2mps11_pmic_id[] = {
12292fadbbf0SAlim Akhtar { "s2mps11-regulator", S2MPS11X},
12302fadbbf0SAlim Akhtar { "s2mps13-regulator", S2MPS13X},
12312fadbbf0SAlim Akhtar { "s2mps14-regulator", S2MPS14X},
123251af2067SThomas Abraham { "s2mps15-regulator", S2MPS15X},
12332fadbbf0SAlim Akhtar { "s2mpu02-regulator", S2MPU02},
1234cb74685eSSangbeom Kim { },
1235cb74685eSSangbeom Kim };
1236cb74685eSSangbeom Kim MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
1237cb74685eSSangbeom Kim
1238cb74685eSSangbeom Kim static struct platform_driver s2mps11_pmic_driver = {
1239cb74685eSSangbeom Kim .driver = {
1240cb74685eSSangbeom Kim .name = "s2mps11-pmic",
1241*259b93b2SDouglas Anderson .probe_type = PROBE_PREFER_ASYNCHRONOUS,
1242cb74685eSSangbeom Kim },
1243cb74685eSSangbeom Kim .probe = s2mps11_pmic_probe,
1244cb74685eSSangbeom Kim .id_table = s2mps11_pmic_id,
1245cb74685eSSangbeom Kim };
1246cb74685eSSangbeom Kim
12475ab3c494SJavier Martinez Canillas module_platform_driver(s2mps11_pmic_driver);
1248cb74685eSSangbeom Kim
1249cb74685eSSangbeom Kim /* Module information */
1250cb74685eSSangbeom Kim MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
1251fc2b10d1SKrzysztof Kozlowski MODULE_DESCRIPTION("Samsung S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
1252cb74685eSSangbeom Kim MODULE_LICENSE("GPL");
1253