Krzysztof Kozlowski | 4f3fb28 | 2018-08-07 18:18:26 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // Copyright (c) 2012-2014 Samsung Electronics Co., Ltd |
| 4 | // http://www.samsung.com |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 5 | |
| 6 | #include <linux/bug.h> |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 7 | #include <linux/err.h> |
Linus Walleij | 1c98494 | 2018-11-15 09:01:17 +0100 | [diff] [blame] | 8 | #include <linux/gpio/consumer.h> |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
| 10 | #include <linux/module.h> |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 11 | #include <linux/of.h> |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 12 | #include <linux/regmap.h> |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/regulator/driver.h> |
| 15 | #include <linux/regulator/machine.h> |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 16 | #include <linux/regulator/of_regulator.h> |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 17 | #include <linux/mfd/samsung/core.h> |
| 18 | #include <linux/mfd/samsung/s2mps11.h> |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 19 | #include <linux/mfd/samsung/s2mps13.h> |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 20 | #include <linux/mfd/samsung/s2mps14.h> |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 21 | #include <linux/mfd/samsung/s2mps15.h> |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 22 | #include <linux/mfd/samsung/s2mpu02.h> |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 23 | |
Krzysztof Kozlowski | 32c848e | 2015-06-24 19:48:43 +0900 | [diff] [blame] | 24 | /* The highest number of possible regulators for supported devices. */ |
| 25 | #define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 26 | struct s2mps11_info { |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 27 | int ramp_delay2; |
| 28 | int ramp_delay34; |
| 29 | int ramp_delay5; |
| 30 | int ramp_delay16; |
| 31 | int ramp_delay7810; |
| 32 | int ramp_delay9; |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 33 | |
| 34 | enum sec_device_type dev_type; |
| 35 | |
Krzysztof Kozlowski | 05be09b | 2014-03-07 11:10:51 +0100 | [diff] [blame] | 36 | /* |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 37 | * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 38 | * the suspend mode was enabled. |
Krzysztof Kozlowski | 05be09b | 2014-03-07 11:10:51 +0100 | [diff] [blame] | 39 | */ |
Krzysztof Kozlowski | 32c848e | 2015-06-24 19:48:43 +0900 | [diff] [blame] | 40 | DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX); |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 41 | |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 42 | /* |
| 43 | * Array (size: number of regulators) with GPIO-s for external |
| 44 | * sleep control. |
| 45 | */ |
Linus Walleij | 1c98494 | 2018-11-15 09:01:17 +0100 | [diff] [blame] | 46 | struct gpio_desc **ext_control_gpiod; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | static int get_ramp_delay(int ramp_delay) |
| 50 | { |
| 51 | unsigned char cnt = 0; |
| 52 | |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 53 | ramp_delay /= 6250; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 54 | |
| 55 | while (true) { |
| 56 | ramp_delay = ramp_delay >> 1; |
| 57 | if (ramp_delay == 0) |
| 58 | break; |
| 59 | cnt++; |
| 60 | } |
Axel Lin | f8f1d48 | 2013-08-05 14:08:37 +0800 | [diff] [blame] | 61 | |
| 62 | if (cnt > 3) |
| 63 | cnt = 3; |
| 64 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 65 | return cnt; |
| 66 | } |
| 67 | |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 68 | static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
| 69 | unsigned int old_selector, |
| 70 | unsigned int new_selector) |
| 71 | { |
| 72 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
Krzysztof Kozlowski | df33799 | 2019-06-20 20:35:26 +0200 | [diff] [blame] | 73 | int rdev_id = rdev_get_id(rdev); |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 74 | unsigned int ramp_delay = 0; |
| 75 | int old_volt, new_volt; |
| 76 | |
Krzysztof Kozlowski | df33799 | 2019-06-20 20:35:26 +0200 | [diff] [blame] | 77 | switch (rdev_id) { |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 78 | case S2MPS11_BUCK2: |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 79 | ramp_delay = s2mps11->ramp_delay2; |
| 80 | break; |
| 81 | case S2MPS11_BUCK3: |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 82 | case S2MPS11_BUCK4: |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 83 | ramp_delay = s2mps11->ramp_delay34; |
| 84 | break; |
| 85 | case S2MPS11_BUCK5: |
| 86 | ramp_delay = s2mps11->ramp_delay5; |
| 87 | break; |
| 88 | case S2MPS11_BUCK6: |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 89 | case S2MPS11_BUCK1: |
| 90 | ramp_delay = s2mps11->ramp_delay16; |
| 91 | break; |
| 92 | case S2MPS11_BUCK7: |
| 93 | case S2MPS11_BUCK8: |
| 94 | case S2MPS11_BUCK10: |
| 95 | ramp_delay = s2mps11->ramp_delay7810; |
| 96 | break; |
| 97 | case S2MPS11_BUCK9: |
| 98 | ramp_delay = s2mps11->ramp_delay9; |
| 99 | } |
| 100 | |
| 101 | if (ramp_delay == 0) |
| 102 | ramp_delay = rdev->desc->ramp_delay; |
| 103 | |
| 104 | old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector); |
| 105 | new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector); |
| 106 | |
| 107 | return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay); |
| 108 | } |
| 109 | |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 110 | static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
| 111 | { |
| 112 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
| 113 | unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK; |
| 114 | unsigned int ramp_enable = 1, enable_shift = 0; |
Krzysztof Kozlowski | df33799 | 2019-06-20 20:35:26 +0200 | [diff] [blame] | 115 | int rdev_id = rdev_get_id(rdev); |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 116 | int ret; |
| 117 | |
Krzysztof Kozlowski | df33799 | 2019-06-20 20:35:26 +0200 | [diff] [blame] | 118 | switch (rdev_id) { |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 119 | case S2MPS11_BUCK1: |
| 120 | if (ramp_delay > s2mps11->ramp_delay16) |
| 121 | s2mps11->ramp_delay16 = ramp_delay; |
| 122 | else |
| 123 | ramp_delay = s2mps11->ramp_delay16; |
| 124 | |
| 125 | ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT; |
| 126 | break; |
| 127 | case S2MPS11_BUCK2: |
| 128 | enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT; |
| 129 | if (!ramp_delay) { |
| 130 | ramp_enable = 0; |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | s2mps11->ramp_delay2 = ramp_delay; |
| 135 | ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT; |
| 136 | ramp_reg = S2MPS11_REG_RAMP; |
| 137 | break; |
| 138 | case S2MPS11_BUCK3: |
| 139 | enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT; |
| 140 | if (!ramp_delay) { |
| 141 | ramp_enable = 0; |
| 142 | break; |
| 143 | } |
| 144 | |
| 145 | if (ramp_delay > s2mps11->ramp_delay34) |
| 146 | s2mps11->ramp_delay34 = ramp_delay; |
| 147 | else |
| 148 | ramp_delay = s2mps11->ramp_delay34; |
| 149 | |
| 150 | ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT; |
| 151 | ramp_reg = S2MPS11_REG_RAMP; |
| 152 | break; |
| 153 | case S2MPS11_BUCK4: |
| 154 | enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT; |
| 155 | if (!ramp_delay) { |
| 156 | ramp_enable = 0; |
| 157 | break; |
| 158 | } |
| 159 | |
| 160 | if (ramp_delay > s2mps11->ramp_delay34) |
| 161 | s2mps11->ramp_delay34 = ramp_delay; |
| 162 | else |
| 163 | ramp_delay = s2mps11->ramp_delay34; |
| 164 | |
| 165 | ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT; |
| 166 | ramp_reg = S2MPS11_REG_RAMP; |
| 167 | break; |
| 168 | case S2MPS11_BUCK5: |
| 169 | s2mps11->ramp_delay5 = ramp_delay; |
| 170 | ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT; |
| 171 | break; |
| 172 | case S2MPS11_BUCK6: |
| 173 | enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT; |
| 174 | if (!ramp_delay) { |
| 175 | ramp_enable = 0; |
| 176 | break; |
| 177 | } |
| 178 | |
| 179 | if (ramp_delay > s2mps11->ramp_delay16) |
| 180 | s2mps11->ramp_delay16 = ramp_delay; |
| 181 | else |
| 182 | ramp_delay = s2mps11->ramp_delay16; |
| 183 | |
| 184 | ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT; |
| 185 | break; |
| 186 | case S2MPS11_BUCK7: |
| 187 | case S2MPS11_BUCK8: |
| 188 | case S2MPS11_BUCK10: |
| 189 | if (ramp_delay > s2mps11->ramp_delay7810) |
| 190 | s2mps11->ramp_delay7810 = ramp_delay; |
| 191 | else |
| 192 | ramp_delay = s2mps11->ramp_delay7810; |
| 193 | |
| 194 | ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT; |
| 195 | break; |
| 196 | case S2MPS11_BUCK9: |
| 197 | s2mps11->ramp_delay9 = ramp_delay; |
| 198 | ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT; |
| 199 | break; |
| 200 | default: |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | if (!ramp_enable) |
| 205 | goto ramp_disable; |
| 206 | |
Krzysztof Kozlowski | b203e0d | 2014-05-06 08:37:36 +0200 | [diff] [blame] | 207 | /* Ramp delay can be enabled/disabled only for buck[2346] */ |
Krzysztof Kozlowski | df33799 | 2019-06-20 20:35:26 +0200 | [diff] [blame] | 208 | if ((rdev_id >= S2MPS11_BUCK2 && rdev_id <= S2MPS11_BUCK4) || |
| 209 | rdev_id == S2MPS11_BUCK6) { |
Krzysztof Kozlowski | b203e0d | 2014-05-06 08:37:36 +0200 | [diff] [blame] | 210 | ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, |
| 211 | 1 << enable_shift, 1 << enable_shift); |
| 212 | if (ret) { |
| 213 | dev_err(&rdev->dev, "failed to enable ramp rate\n"); |
| 214 | return ret; |
| 215 | } |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | ramp_val = get_ramp_delay(ramp_delay); |
| 219 | |
Axel Lin | f8f1d48 | 2013-08-05 14:08:37 +0800 | [diff] [blame] | 220 | return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift, |
| 221 | ramp_val << ramp_shift); |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 222 | |
| 223 | ramp_disable: |
Axel Lin | 8085330 | 2013-08-03 17:10:42 +0800 | [diff] [blame] | 224 | return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, |
| 225 | 1 << enable_shift, 0); |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 226 | } |
| 227 | |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 228 | static int s2mps11_regulator_enable(struct regulator_dev *rdev) |
| 229 | { |
| 230 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
| 231 | int rdev_id = rdev_get_id(rdev); |
| 232 | unsigned int val; |
| 233 | |
| 234 | switch (s2mps11->dev_type) { |
| 235 | case S2MPS11X: |
| 236 | if (test_bit(rdev_id, s2mps11->suspend_state)) |
| 237 | val = S2MPS14_ENABLE_SUSPEND; |
| 238 | else |
| 239 | val = rdev->desc->enable_mask; |
| 240 | break; |
| 241 | case S2MPS13X: |
| 242 | case S2MPS14X: |
| 243 | if (test_bit(rdev_id, s2mps11->suspend_state)) |
| 244 | val = S2MPS14_ENABLE_SUSPEND; |
| 245 | else if (s2mps11->ext_control_gpiod[rdev_id]) |
| 246 | val = S2MPS14_ENABLE_EXT_CONTROL; |
| 247 | else |
| 248 | val = rdev->desc->enable_mask; |
| 249 | break; |
| 250 | case S2MPU02: |
| 251 | if (test_bit(rdev_id, s2mps11->suspend_state)) |
| 252 | val = S2MPU02_ENABLE_SUSPEND; |
| 253 | else |
| 254 | val = rdev->desc->enable_mask; |
| 255 | break; |
| 256 | default: |
| 257 | return -EINVAL; |
| 258 | } |
| 259 | |
| 260 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 261 | rdev->desc->enable_mask, val); |
| 262 | } |
| 263 | |
| 264 | static int s2mps11_regulator_set_suspend_disable(struct regulator_dev *rdev) |
| 265 | { |
| 266 | int ret; |
| 267 | unsigned int val, state; |
| 268 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
| 269 | int rdev_id = rdev_get_id(rdev); |
| 270 | |
| 271 | /* Below LDO should be always on or does not support suspend mode. */ |
| 272 | switch (s2mps11->dev_type) { |
| 273 | case S2MPS11X: |
| 274 | switch (rdev_id) { |
| 275 | case S2MPS11_LDO2: |
| 276 | case S2MPS11_LDO36: |
| 277 | case S2MPS11_LDO37: |
| 278 | case S2MPS11_LDO38: |
| 279 | return 0; |
| 280 | default: |
| 281 | state = S2MPS14_ENABLE_SUSPEND; |
| 282 | break; |
| 283 | } |
| 284 | break; |
| 285 | case S2MPS13X: |
| 286 | case S2MPS14X: |
| 287 | switch (rdev_id) { |
| 288 | case S2MPS14_LDO3: |
| 289 | return 0; |
| 290 | default: |
| 291 | state = S2MPS14_ENABLE_SUSPEND; |
| 292 | break; |
| 293 | } |
| 294 | break; |
| 295 | case S2MPU02: |
| 296 | switch (rdev_id) { |
| 297 | case S2MPU02_LDO13: |
| 298 | case S2MPU02_LDO14: |
| 299 | case S2MPU02_LDO15: |
| 300 | case S2MPU02_LDO17: |
| 301 | case S2MPU02_BUCK7: |
| 302 | state = S2MPU02_DISABLE_SUSPEND; |
| 303 | break; |
| 304 | default: |
| 305 | state = S2MPU02_ENABLE_SUSPEND; |
| 306 | break; |
| 307 | } |
| 308 | break; |
| 309 | default: |
| 310 | return -EINVAL; |
| 311 | } |
| 312 | |
| 313 | ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); |
| 314 | if (ret < 0) |
| 315 | return ret; |
| 316 | |
| 317 | set_bit(rdev_id, s2mps11->suspend_state); |
| 318 | /* |
| 319 | * Don't enable suspend mode if regulator is already disabled because |
| 320 | * this would effectively for a short time turn on the regulator after |
| 321 | * resuming. |
| 322 | * However we still want to toggle the suspend_state bit for regulator |
| 323 | * in case if it got enabled before suspending the system. |
| 324 | */ |
| 325 | if (!(val & rdev->desc->enable_mask)) |
| 326 | return 0; |
| 327 | |
| 328 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 329 | rdev->desc->enable_mask, state); |
| 330 | } |
| 331 | |
Krzysztof Kozlowski | 71b4540 | 2017-03-11 21:01:22 +0200 | [diff] [blame] | 332 | static const struct regulator_ops s2mps11_ldo_ops = { |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 333 | .list_voltage = regulator_list_voltage_linear, |
| 334 | .map_voltage = regulator_map_voltage_linear, |
| 335 | .is_enabled = regulator_is_enabled_regmap, |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 336 | .enable = s2mps11_regulator_enable, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 337 | .disable = regulator_disable_regmap, |
| 338 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 339 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 340 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 341 | .set_suspend_disable = s2mps11_regulator_set_suspend_disable, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 342 | }; |
| 343 | |
Krzysztof Kozlowski | 71b4540 | 2017-03-11 21:01:22 +0200 | [diff] [blame] | 344 | static const struct regulator_ops s2mps11_buck_ops = { |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 345 | .list_voltage = regulator_list_voltage_linear, |
| 346 | .map_voltage = regulator_map_voltage_linear, |
| 347 | .is_enabled = regulator_is_enabled_regmap, |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 348 | .enable = s2mps11_regulator_enable, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 349 | .disable = regulator_disable_regmap, |
| 350 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 351 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 352 | .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel, |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 353 | .set_ramp_delay = s2mps11_set_ramp_delay, |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 354 | .set_suspend_disable = s2mps11_regulator_set_suspend_disable, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 355 | }; |
| 356 | |
Amit Daniel Kachhap | 5a867cf | 2014-07-15 16:32:53 +0530 | [diff] [blame] | 357 | #define regulator_desc_s2mps11_ldo(num, step) { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 358 | .name = "LDO"#num, \ |
| 359 | .id = S2MPS11_LDO##num, \ |
| 360 | .ops = &s2mps11_ldo_ops, \ |
| 361 | .type = REGULATOR_VOLTAGE, \ |
| 362 | .owner = THIS_MODULE, \ |
Krzysztof Kozlowski | 94be46b | 2016-04-18 15:33:10 +0200 | [diff] [blame] | 363 | .ramp_delay = RAMP_DELAY_12_MVUS, \ |
Amit Daniel Kachhap | 0e4f417 | 2014-07-15 16:32:51 +0530 | [diff] [blame] | 364 | .min_uV = MIN_800_MV, \ |
Amit Daniel Kachhap | 5a867cf | 2014-07-15 16:32:53 +0530 | [diff] [blame] | 365 | .uV_step = step, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 366 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ |
| 367 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 368 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 369 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
| 370 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 371 | } |
| 372 | |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 373 | #define regulator_desc_s2mps11_buck1_4(num) { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 374 | .name = "BUCK"#num, \ |
| 375 | .id = S2MPS11_BUCK##num, \ |
| 376 | .ops = &s2mps11_buck_ops, \ |
| 377 | .type = REGULATOR_VOLTAGE, \ |
| 378 | .owner = THIS_MODULE, \ |
Krzysztof Kozlowski | 9d83dcb | 2019-06-29 13:44:46 +0200 | [diff] [blame] | 379 | .min_uV = MIN_650_MV, \ |
Amit Daniel Kachhap | 0e4f417 | 2014-07-15 16:32:51 +0530 | [diff] [blame] | 380 | .uV_step = STEP_6_25_MV, \ |
Krzysztof Kozlowski | 9d83dcb | 2019-06-29 13:44:46 +0200 | [diff] [blame] | 381 | .linear_min_sel = 8, \ |
| 382 | .n_voltages = S2MPS11_BUCK12346_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 383 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 384 | .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 385 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 386 | .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \ |
| 387 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 388 | } |
| 389 | |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 390 | #define regulator_desc_s2mps11_buck5 { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 391 | .name = "BUCK5", \ |
| 392 | .id = S2MPS11_BUCK5, \ |
| 393 | .ops = &s2mps11_buck_ops, \ |
| 394 | .type = REGULATOR_VOLTAGE, \ |
| 395 | .owner = THIS_MODULE, \ |
Krzysztof Kozlowski | 9d83dcb | 2019-06-29 13:44:46 +0200 | [diff] [blame] | 396 | .min_uV = MIN_650_MV, \ |
Amit Daniel Kachhap | 0e4f417 | 2014-07-15 16:32:51 +0530 | [diff] [blame] | 397 | .uV_step = STEP_6_25_MV, \ |
Krzysztof Kozlowski | 9d83dcb | 2019-06-29 13:44:46 +0200 | [diff] [blame] | 398 | .linear_min_sel = 8, \ |
| 399 | .n_voltages = S2MPS11_BUCK5_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 400 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 401 | .vsel_reg = S2MPS11_REG_B5CTRL2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 402 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 403 | .enable_reg = S2MPS11_REG_B5CTRL1, \ |
| 404 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 405 | } |
| 406 | |
Krzysztof Kozlowski | 9d83dcb | 2019-06-29 13:44:46 +0200 | [diff] [blame] | 407 | #define regulator_desc_s2mps11_buck67810(num, min, step, min_sel, voltages) { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 408 | .name = "BUCK"#num, \ |
| 409 | .id = S2MPS11_BUCK##num, \ |
| 410 | .ops = &s2mps11_buck_ops, \ |
| 411 | .type = REGULATOR_VOLTAGE, \ |
| 412 | .owner = THIS_MODULE, \ |
Amit Daniel Kachhap | 5a867cf | 2014-07-15 16:32:53 +0530 | [diff] [blame] | 413 | .min_uV = min, \ |
| 414 | .uV_step = step, \ |
Krzysztof Kozlowski | 9d83dcb | 2019-06-29 13:44:46 +0200 | [diff] [blame] | 415 | .linear_min_sel = min_sel, \ |
| 416 | .n_voltages = voltages, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 417 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 418 | .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 419 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 420 | .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \ |
| 421 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 422 | } |
| 423 | |
Krzysztof Kozlowski | 3b67262 | 2016-03-28 13:09:56 +0900 | [diff] [blame] | 424 | #define regulator_desc_s2mps11_buck9 { \ |
| 425 | .name = "BUCK9", \ |
| 426 | .id = S2MPS11_BUCK9, \ |
| 427 | .ops = &s2mps11_buck_ops, \ |
| 428 | .type = REGULATOR_VOLTAGE, \ |
| 429 | .owner = THIS_MODULE, \ |
| 430 | .min_uV = MIN_3000_MV, \ |
| 431 | .uV_step = STEP_25_MV, \ |
| 432 | .n_voltages = S2MPS11_BUCK9_N_VOLTAGES, \ |
| 433 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
| 434 | .vsel_reg = S2MPS11_REG_B9CTRL2, \ |
| 435 | .vsel_mask = S2MPS11_BUCK9_VSEL_MASK, \ |
| 436 | .enable_reg = S2MPS11_REG_B9CTRL1, \ |
| 437 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 438 | } |
| 439 | |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 440 | static const struct regulator_desc s2mps11_regulators[] = { |
Amit Daniel Kachhap | 5a867cf | 2014-07-15 16:32:53 +0530 | [diff] [blame] | 441 | regulator_desc_s2mps11_ldo(1, STEP_25_MV), |
| 442 | regulator_desc_s2mps11_ldo(2, STEP_50_MV), |
| 443 | regulator_desc_s2mps11_ldo(3, STEP_50_MV), |
| 444 | regulator_desc_s2mps11_ldo(4, STEP_50_MV), |
| 445 | regulator_desc_s2mps11_ldo(5, STEP_50_MV), |
| 446 | regulator_desc_s2mps11_ldo(6, STEP_25_MV), |
| 447 | regulator_desc_s2mps11_ldo(7, STEP_50_MV), |
| 448 | regulator_desc_s2mps11_ldo(8, STEP_50_MV), |
| 449 | regulator_desc_s2mps11_ldo(9, STEP_50_MV), |
| 450 | regulator_desc_s2mps11_ldo(10, STEP_50_MV), |
| 451 | regulator_desc_s2mps11_ldo(11, STEP_25_MV), |
| 452 | regulator_desc_s2mps11_ldo(12, STEP_50_MV), |
| 453 | regulator_desc_s2mps11_ldo(13, STEP_50_MV), |
| 454 | regulator_desc_s2mps11_ldo(14, STEP_50_MV), |
| 455 | regulator_desc_s2mps11_ldo(15, STEP_50_MV), |
| 456 | regulator_desc_s2mps11_ldo(16, STEP_50_MV), |
| 457 | regulator_desc_s2mps11_ldo(17, STEP_50_MV), |
| 458 | regulator_desc_s2mps11_ldo(18, STEP_50_MV), |
| 459 | regulator_desc_s2mps11_ldo(19, STEP_50_MV), |
| 460 | regulator_desc_s2mps11_ldo(20, STEP_50_MV), |
| 461 | regulator_desc_s2mps11_ldo(21, STEP_50_MV), |
| 462 | regulator_desc_s2mps11_ldo(22, STEP_25_MV), |
| 463 | regulator_desc_s2mps11_ldo(23, STEP_25_MV), |
| 464 | regulator_desc_s2mps11_ldo(24, STEP_50_MV), |
| 465 | regulator_desc_s2mps11_ldo(25, STEP_50_MV), |
| 466 | regulator_desc_s2mps11_ldo(26, STEP_50_MV), |
| 467 | regulator_desc_s2mps11_ldo(27, STEP_25_MV), |
| 468 | regulator_desc_s2mps11_ldo(28, STEP_50_MV), |
| 469 | regulator_desc_s2mps11_ldo(29, STEP_50_MV), |
| 470 | regulator_desc_s2mps11_ldo(30, STEP_50_MV), |
| 471 | regulator_desc_s2mps11_ldo(31, STEP_50_MV), |
| 472 | regulator_desc_s2mps11_ldo(32, STEP_50_MV), |
| 473 | regulator_desc_s2mps11_ldo(33, STEP_50_MV), |
| 474 | regulator_desc_s2mps11_ldo(34, STEP_50_MV), |
Krzysztof Kozlowski | 56b5d4e | 2019-02-09 18:14:14 +0100 | [diff] [blame] | 475 | regulator_desc_s2mps11_ldo(35, STEP_25_MV), |
Amit Daniel Kachhap | 5a867cf | 2014-07-15 16:32:53 +0530 | [diff] [blame] | 476 | regulator_desc_s2mps11_ldo(36, STEP_50_MV), |
| 477 | regulator_desc_s2mps11_ldo(37, STEP_50_MV), |
| 478 | regulator_desc_s2mps11_ldo(38, STEP_50_MV), |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 479 | regulator_desc_s2mps11_buck1_4(1), |
| 480 | regulator_desc_s2mps11_buck1_4(2), |
| 481 | regulator_desc_s2mps11_buck1_4(3), |
| 482 | regulator_desc_s2mps11_buck1_4(4), |
| 483 | regulator_desc_s2mps11_buck5, |
Krzysztof Kozlowski | 9d83dcb | 2019-06-29 13:44:46 +0200 | [diff] [blame] | 484 | regulator_desc_s2mps11_buck67810(6, MIN_650_MV, STEP_6_25_MV, 8, |
| 485 | S2MPS11_BUCK12346_N_VOLTAGES), |
| 486 | regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV, 0, |
| 487 | S2MPS11_BUCK7810_N_VOLTAGES), |
| 488 | regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV, 0, |
| 489 | S2MPS11_BUCK7810_N_VOLTAGES), |
Krzysztof Kozlowski | 3b67262 | 2016-03-28 13:09:56 +0900 | [diff] [blame] | 490 | regulator_desc_s2mps11_buck9, |
Krzysztof Kozlowski | 9d83dcb | 2019-06-29 13:44:46 +0200 | [diff] [blame] | 491 | regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV, 0, |
| 492 | S2MPS11_BUCK7810_N_VOLTAGES), |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 493 | }; |
| 494 | |
Krzysztof Kozlowski | 71b4540 | 2017-03-11 21:01:22 +0200 | [diff] [blame] | 495 | static const struct regulator_ops s2mps14_reg_ops; |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 496 | |
| 497 | #define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \ |
| 498 | .name = "LDO"#num, \ |
| 499 | .id = S2MPS13_LDO##num, \ |
| 500 | .ops = &s2mps14_reg_ops, \ |
| 501 | .type = REGULATOR_VOLTAGE, \ |
| 502 | .owner = THIS_MODULE, \ |
| 503 | .min_uV = min, \ |
| 504 | .uV_step = step, \ |
| 505 | .linear_min_sel = min_sel, \ |
| 506 | .n_voltages = S2MPS14_LDO_N_VOLTAGES, \ |
| 507 | .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \ |
| 508 | .vsel_mask = S2MPS14_LDO_VSEL_MASK, \ |
| 509 | .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \ |
| 510 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 511 | } |
| 512 | |
| 513 | #define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \ |
| 514 | .name = "BUCK"#num, \ |
| 515 | .id = S2MPS13_BUCK##num, \ |
| 516 | .ops = &s2mps14_reg_ops, \ |
| 517 | .type = REGULATOR_VOLTAGE, \ |
| 518 | .owner = THIS_MODULE, \ |
| 519 | .min_uV = min, \ |
| 520 | .uV_step = step, \ |
| 521 | .linear_min_sel = min_sel, \ |
| 522 | .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \ |
| 523 | .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \ |
| 524 | .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \ |
| 525 | .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \ |
| 526 | .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \ |
| 527 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 528 | } |
| 529 | |
Jonghwa Lee | ad26aa6 | 2015-01-08 11:04:07 +0900 | [diff] [blame] | 530 | #define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \ |
| 531 | .name = "BUCK"#num, \ |
| 532 | .id = S2MPS13_BUCK##num, \ |
| 533 | .ops = &s2mps14_reg_ops, \ |
| 534 | .type = REGULATOR_VOLTAGE, \ |
| 535 | .owner = THIS_MODULE, \ |
| 536 | .min_uV = min, \ |
| 537 | .uV_step = step, \ |
| 538 | .linear_min_sel = min_sel, \ |
| 539 | .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \ |
| 540 | .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \ |
| 541 | .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \ |
| 542 | .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \ |
| 543 | .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \ |
| 544 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 545 | } |
| 546 | |
| 547 | #define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \ |
| 548 | .name = "BUCK"#num, \ |
| 549 | .id = S2MPS13_BUCK##num, \ |
| 550 | .ops = &s2mps14_reg_ops, \ |
| 551 | .type = REGULATOR_VOLTAGE, \ |
| 552 | .owner = THIS_MODULE, \ |
| 553 | .min_uV = min, \ |
| 554 | .uV_step = step, \ |
| 555 | .linear_min_sel = min_sel, \ |
| 556 | .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \ |
| 557 | .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \ |
| 558 | .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \ |
| 559 | .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \ |
| 560 | .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \ |
| 561 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 562 | } |
| 563 | |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 564 | static const struct regulator_desc s2mps13_regulators[] = { |
| 565 | regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00), |
| 566 | regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 567 | regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08), |
| 568 | regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00), |
| 569 | regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00), |
| 570 | regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00), |
| 571 | regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08), |
| 572 | regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08), |
| 573 | regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08), |
| 574 | regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 575 | regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10), |
| 576 | regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10), |
| 577 | regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10), |
| 578 | regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00), |
| 579 | regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00), |
| 580 | regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 581 | regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 582 | regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08), |
| 583 | regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08), |
| 584 | regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 585 | regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08), |
| 586 | regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08), |
| 587 | regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00), |
| 588 | regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00), |
| 589 | regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 590 | regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 591 | regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 592 | regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08), |
| 593 | regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 594 | regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 595 | regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08), |
| 596 | regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08), |
| 597 | regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 598 | regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08), |
| 599 | regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 600 | regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00), |
| 601 | regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08), |
| 602 | regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 603 | regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08), |
| 604 | regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C), |
| 605 | regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10), |
| 606 | regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10), |
| 607 | regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10), |
| 608 | regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10), |
| 609 | regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10), |
| 610 | regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10), |
Jonghwa Lee | ad26aa6 | 2015-01-08 11:04:07 +0900 | [diff] [blame] | 611 | regulator_desc_s2mps13_buck7(7, MIN_500_MV, STEP_6_25_MV, 0x10), |
| 612 | regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV, STEP_12_5_MV, 0x20), |
| 613 | regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV, STEP_12_5_MV, 0x20), |
| 614 | regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10), |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 615 | }; |
| 616 | |
Krzysztof Kozlowski | 71b4540 | 2017-03-11 21:01:22 +0200 | [diff] [blame] | 617 | static const struct regulator_ops s2mps14_reg_ops = { |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 618 | .list_voltage = regulator_list_voltage_linear, |
| 619 | .map_voltage = regulator_map_voltage_linear, |
| 620 | .is_enabled = regulator_is_enabled_regmap, |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 621 | .enable = s2mps11_regulator_enable, |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 622 | .disable = regulator_disable_regmap, |
| 623 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 624 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 625 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 626 | .set_suspend_disable = s2mps11_regulator_set_suspend_disable, |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 627 | }; |
| 628 | |
Amit Daniel Kachhap | 5a867cf | 2014-07-15 16:32:53 +0530 | [diff] [blame] | 629 | #define regulator_desc_s2mps14_ldo(num, min, step) { \ |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 630 | .name = "LDO"#num, \ |
| 631 | .id = S2MPS14_LDO##num, \ |
| 632 | .ops = &s2mps14_reg_ops, \ |
| 633 | .type = REGULATOR_VOLTAGE, \ |
| 634 | .owner = THIS_MODULE, \ |
Amit Daniel Kachhap | 5a867cf | 2014-07-15 16:32:53 +0530 | [diff] [blame] | 635 | .min_uV = min, \ |
| 636 | .uV_step = step, \ |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 637 | .n_voltages = S2MPS14_LDO_N_VOLTAGES, \ |
| 638 | .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \ |
| 639 | .vsel_mask = S2MPS14_LDO_VSEL_MASK, \ |
| 640 | .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \ |
| 641 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 642 | } |
Amit Daniel Kachhap | 5a867cf | 2014-07-15 16:32:53 +0530 | [diff] [blame] | 643 | |
Krzysztof Kozlowski | 1222d8f | 2014-12-11 14:40:21 +0100 | [diff] [blame] | 644 | #define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \ |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 645 | .name = "BUCK"#num, \ |
| 646 | .id = S2MPS14_BUCK##num, \ |
| 647 | .ops = &s2mps14_reg_ops, \ |
| 648 | .type = REGULATOR_VOLTAGE, \ |
| 649 | .owner = THIS_MODULE, \ |
Amit Daniel Kachhap | 5a867cf | 2014-07-15 16:32:53 +0530 | [diff] [blame] | 650 | .min_uV = min, \ |
| 651 | .uV_step = step, \ |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 652 | .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \ |
Krzysztof Kozlowski | 1222d8f | 2014-12-11 14:40:21 +0100 | [diff] [blame] | 653 | .linear_min_sel = min_sel, \ |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 654 | .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \ |
| 655 | .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \ |
| 656 | .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \ |
| 657 | .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \ |
| 658 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 659 | } |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 660 | |
| 661 | static const struct regulator_desc s2mps14_regulators[] = { |
Amit Daniel Kachhap | 5a867cf | 2014-07-15 16:32:53 +0530 | [diff] [blame] | 662 | regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV), |
| 663 | regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV), |
| 664 | regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV), |
| 665 | regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV), |
| 666 | regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV), |
| 667 | regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV), |
| 668 | regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV), |
| 669 | regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV), |
| 670 | regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV), |
| 671 | regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV), |
| 672 | regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV), |
| 673 | regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV), |
| 674 | regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV), |
| 675 | regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV), |
| 676 | regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV), |
| 677 | regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV), |
| 678 | regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV), |
| 679 | regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV), |
| 680 | regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV), |
| 681 | regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV), |
| 682 | regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV), |
| 683 | regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV), |
| 684 | regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV), |
| 685 | regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV), |
| 686 | regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV), |
Krzysztof Kozlowski | 1222d8f | 2014-12-11 14:40:21 +0100 | [diff] [blame] | 687 | regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV, |
| 688 | S2MPS14_BUCK1235_START_SEL), |
| 689 | regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV, |
| 690 | S2MPS14_BUCK1235_START_SEL), |
| 691 | regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV, |
| 692 | S2MPS14_BUCK1235_START_SEL), |
| 693 | regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV, |
| 694 | S2MPS14_BUCK4_START_SEL), |
| 695 | regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV, |
| 696 | S2MPS14_BUCK1235_START_SEL), |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 697 | }; |
| 698 | |
Krzysztof Kozlowski | 71b4540 | 2017-03-11 21:01:22 +0200 | [diff] [blame] | 699 | static const struct regulator_ops s2mps15_reg_ldo_ops = { |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 700 | .list_voltage = regulator_list_voltage_linear_range, |
| 701 | .map_voltage = regulator_map_voltage_linear_range, |
| 702 | .is_enabled = regulator_is_enabled_regmap, |
| 703 | .enable = regulator_enable_regmap, |
| 704 | .disable = regulator_disable_regmap, |
| 705 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 706 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 707 | }; |
| 708 | |
Krzysztof Kozlowski | 71b4540 | 2017-03-11 21:01:22 +0200 | [diff] [blame] | 709 | static const struct regulator_ops s2mps15_reg_buck_ops = { |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 710 | .list_voltage = regulator_list_voltage_linear_range, |
| 711 | .map_voltage = regulator_map_voltage_linear_range, |
| 712 | .is_enabled = regulator_is_enabled_regmap, |
| 713 | .enable = regulator_enable_regmap, |
| 714 | .disable = regulator_disable_regmap, |
| 715 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 716 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 717 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 718 | }; |
| 719 | |
| 720 | #define regulator_desc_s2mps15_ldo(num, range) { \ |
| 721 | .name = "LDO"#num, \ |
| 722 | .id = S2MPS15_LDO##num, \ |
| 723 | .ops = &s2mps15_reg_ldo_ops, \ |
| 724 | .type = REGULATOR_VOLTAGE, \ |
| 725 | .owner = THIS_MODULE, \ |
| 726 | .linear_ranges = range, \ |
| 727 | .n_linear_ranges = ARRAY_SIZE(range), \ |
| 728 | .n_voltages = S2MPS15_LDO_N_VOLTAGES, \ |
| 729 | .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \ |
| 730 | .vsel_mask = S2MPS15_LDO_VSEL_MASK, \ |
| 731 | .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \ |
| 732 | .enable_mask = S2MPS15_ENABLE_MASK \ |
| 733 | } |
| 734 | |
| 735 | #define regulator_desc_s2mps15_buck(num, range) { \ |
| 736 | .name = "BUCK"#num, \ |
| 737 | .id = S2MPS15_BUCK##num, \ |
| 738 | .ops = &s2mps15_reg_buck_ops, \ |
| 739 | .type = REGULATOR_VOLTAGE, \ |
| 740 | .owner = THIS_MODULE, \ |
| 741 | .linear_ranges = range, \ |
| 742 | .n_linear_ranges = ARRAY_SIZE(range), \ |
| 743 | .ramp_delay = 12500, \ |
| 744 | .n_voltages = S2MPS15_BUCK_N_VOLTAGES, \ |
| 745 | .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \ |
| 746 | .vsel_mask = S2MPS15_BUCK_VSEL_MASK, \ |
| 747 | .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \ |
| 748 | .enable_mask = S2MPS15_ENABLE_MASK \ |
| 749 | } |
| 750 | |
| 751 | /* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */ |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 752 | static const struct linear_range s2mps15_ldo_voltage_ranges1[] = { |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 753 | REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000), |
| 754 | }; |
| 755 | |
| 756 | /* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */ |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 757 | static const struct linear_range s2mps15_ldo_voltage_ranges2[] = { |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 758 | REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000), |
| 759 | }; |
| 760 | |
| 761 | /* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */ |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 762 | static const struct linear_range s2mps15_ldo_voltage_ranges3[] = { |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 763 | REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500), |
| 764 | }; |
| 765 | |
| 766 | /* voltage range for s2mps15 LDO 7, 8, 9 and 10 */ |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 767 | static const struct linear_range s2mps15_ldo_voltage_ranges4[] = { |
Alim Akhtar | 04c16b8 | 2016-07-12 11:26:43 +0530 | [diff] [blame] | 768 | REGULATOR_LINEAR_RANGE(700000, 0x10, 0x20, 25000), |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 769 | }; |
| 770 | |
| 771 | /* voltage range for s2mps15 LDO 1 */ |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 772 | static const struct linear_range s2mps15_ldo_voltage_ranges5[] = { |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 773 | REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500), |
| 774 | }; |
| 775 | |
| 776 | /* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */ |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 777 | static const struct linear_range s2mps15_buck_voltage_ranges1[] = { |
Alim Akhtar | 04c16b8 | 2016-07-12 11:26:43 +0530 | [diff] [blame] | 778 | REGULATOR_LINEAR_RANGE(500000, 0x20, 0xc0, 6250), |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 779 | }; |
| 780 | |
| 781 | /* voltage range for s2mps15 BUCK 8, 9 and 10 */ |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 782 | static const struct linear_range s2mps15_buck_voltage_ranges2[] = { |
Alim Akhtar | 04c16b8 | 2016-07-12 11:26:43 +0530 | [diff] [blame] | 783 | REGULATOR_LINEAR_RANGE(1000000, 0x20, 0x78, 12500), |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 784 | }; |
| 785 | |
| 786 | static const struct regulator_desc s2mps15_regulators[] = { |
| 787 | regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5), |
| 788 | regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2), |
| 789 | regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1), |
| 790 | regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3), |
| 791 | regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1), |
| 792 | regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2), |
| 793 | regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4), |
| 794 | regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4), |
| 795 | regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4), |
| 796 | regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4), |
| 797 | regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3), |
| 798 | regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3), |
| 799 | regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3), |
| 800 | regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2), |
| 801 | regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1), |
| 802 | regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1), |
| 803 | regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2), |
| 804 | regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1), |
| 805 | regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2), |
| 806 | regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1), |
| 807 | regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2), |
| 808 | regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3), |
| 809 | regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1), |
| 810 | regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2), |
| 811 | regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2), |
| 812 | regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3), |
| 813 | regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1), |
| 814 | regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1), |
| 815 | regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1), |
| 816 | regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1), |
| 817 | regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1), |
| 818 | regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1), |
| 819 | regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1), |
| 820 | regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1), |
| 821 | regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2), |
| 822 | regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2), |
| 823 | regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2), |
| 824 | }; |
| 825 | |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 826 | static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11, |
| 827 | struct regulator_dev *rdev) |
| 828 | { |
| 829 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 830 | rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL); |
| 831 | } |
| 832 | |
| 833 | static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev, |
Krzysztof Kozlowski | 0117038 | 2014-04-14 10:09:06 +0200 | [diff] [blame] | 834 | struct of_regulator_match *rdata, struct s2mps11_info *s2mps11) |
| 835 | { |
Linus Walleij | 1c98494 | 2018-11-15 09:01:17 +0100 | [diff] [blame] | 836 | struct gpio_desc **gpio = s2mps11->ext_control_gpiod; |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 837 | unsigned int i; |
| 838 | unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11, |
| 839 | S2MPS14_LDO12 }; |
| 840 | |
| 841 | for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) { |
| 842 | unsigned int reg = valid_regulators[i]; |
| 843 | |
| 844 | if (!rdata[reg].init_data || !rdata[reg].of_node) |
| 845 | continue; |
| 846 | |
Dmitry Torokhov | de2792b | 2019-10-04 16:10:14 -0700 | [diff] [blame] | 847 | gpio[reg] = devm_fwnode_gpiod_get(&pdev->dev, |
| 848 | of_fwnode_handle(rdata[reg].of_node), |
| 849 | "samsung,ext-control", |
Linus Walleij | 1c98494 | 2018-11-15 09:01:17 +0100 | [diff] [blame] | 850 | GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE, |
| 851 | "s2mps11-regulator"); |
Waibel Georg | 025bf377 | 2019-06-20 21:37:08 +0000 | [diff] [blame] | 852 | if (PTR_ERR(gpio[reg]) == -ENOENT) |
| 853 | gpio[reg] = NULL; |
| 854 | else if (IS_ERR(gpio[reg])) { |
Linus Walleij | 1c98494 | 2018-11-15 09:01:17 +0100 | [diff] [blame] | 855 | dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n", |
| 856 | reg, rdata[reg].name); |
Krzysztof Kozlowski | 70ca117 | 2019-06-19 14:42:39 +0200 | [diff] [blame] | 857 | gpio[reg] = NULL; |
Linus Walleij | 1c98494 | 2018-11-15 09:01:17 +0100 | [diff] [blame] | 858 | continue; |
| 859 | } |
| 860 | if (gpio[reg]) |
| 861 | dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n", |
| 862 | reg, rdata[reg].name); |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | |
| 866 | static int s2mps11_pmic_dt_parse(struct platform_device *pdev, |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 867 | struct of_regulator_match *rdata, struct s2mps11_info *s2mps11, |
| 868 | unsigned int rdev_num) |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 869 | { |
Krzysztof Kozlowski | 0117038 | 2014-04-14 10:09:06 +0200 | [diff] [blame] | 870 | struct device_node *reg_np; |
| 871 | |
| 872 | reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); |
| 873 | if (!reg_np) { |
| 874 | dev_err(&pdev->dev, "could not find regulators sub-node\n"); |
| 875 | return -EINVAL; |
| 876 | } |
| 877 | |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 878 | of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num); |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 879 | if (s2mps11->dev_type == S2MPS14X) |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 880 | s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11); |
| 881 | |
Krzysztof Kozlowski | 0117038 | 2014-04-14 10:09:06 +0200 | [diff] [blame] | 882 | of_node_put(reg_np); |
| 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 887 | static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
| 888 | { |
| 889 | unsigned int ramp_val, ramp_shift, ramp_reg; |
Krzysztof Kozlowski | df33799 | 2019-06-20 20:35:26 +0200 | [diff] [blame] | 890 | int rdev_id = rdev_get_id(rdev); |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 891 | |
Krzysztof Kozlowski | df33799 | 2019-06-20 20:35:26 +0200 | [diff] [blame] | 892 | switch (rdev_id) { |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 893 | case S2MPU02_BUCK1: |
| 894 | ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT; |
| 895 | break; |
| 896 | case S2MPU02_BUCK2: |
| 897 | ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT; |
| 898 | break; |
| 899 | case S2MPU02_BUCK3: |
| 900 | ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT; |
| 901 | break; |
| 902 | case S2MPU02_BUCK4: |
| 903 | ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT; |
| 904 | break; |
| 905 | default: |
| 906 | return 0; |
| 907 | } |
| 908 | ramp_reg = S2MPU02_REG_RAMP1; |
| 909 | ramp_val = get_ramp_delay(ramp_delay); |
| 910 | |
| 911 | return regmap_update_bits(rdev->regmap, ramp_reg, |
| 912 | S2MPU02_BUCK1234_RAMP_MASK << ramp_shift, |
| 913 | ramp_val << ramp_shift); |
| 914 | } |
| 915 | |
Krzysztof Kozlowski | 71b4540 | 2017-03-11 21:01:22 +0200 | [diff] [blame] | 916 | static const struct regulator_ops s2mpu02_ldo_ops = { |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 917 | .list_voltage = regulator_list_voltage_linear, |
| 918 | .map_voltage = regulator_map_voltage_linear, |
| 919 | .is_enabled = regulator_is_enabled_regmap, |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 920 | .enable = s2mps11_regulator_enable, |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 921 | .disable = regulator_disable_regmap, |
| 922 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 923 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 924 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 925 | .set_suspend_disable = s2mps11_regulator_set_suspend_disable, |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 926 | }; |
| 927 | |
Krzysztof Kozlowski | 71b4540 | 2017-03-11 21:01:22 +0200 | [diff] [blame] | 928 | static const struct regulator_ops s2mpu02_buck_ops = { |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 929 | .list_voltage = regulator_list_voltage_linear, |
| 930 | .map_voltage = regulator_map_voltage_linear, |
| 931 | .is_enabled = regulator_is_enabled_regmap, |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 932 | .enable = s2mps11_regulator_enable, |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 933 | .disable = regulator_disable_regmap, |
| 934 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 935 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 936 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Krzysztof Kozlowski | 65d80db | 2019-06-20 20:35:27 +0200 | [diff] [blame] | 937 | .set_suspend_disable = s2mps11_regulator_set_suspend_disable, |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 938 | .set_ramp_delay = s2mpu02_set_ramp_delay, |
| 939 | }; |
| 940 | |
| 941 | #define regulator_desc_s2mpu02_ldo1(num) { \ |
| 942 | .name = "LDO"#num, \ |
| 943 | .id = S2MPU02_LDO##num, \ |
| 944 | .ops = &s2mpu02_ldo_ops, \ |
| 945 | .type = REGULATOR_VOLTAGE, \ |
| 946 | .owner = THIS_MODULE, \ |
| 947 | .min_uV = S2MPU02_LDO_MIN_900MV, \ |
| 948 | .uV_step = S2MPU02_LDO_STEP_12_5MV, \ |
| 949 | .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \ |
| 950 | .n_voltages = S2MPU02_LDO_N_VOLTAGES, \ |
| 951 | .vsel_reg = S2MPU02_REG_L1CTRL, \ |
| 952 | .vsel_mask = S2MPU02_LDO_VSEL_MASK, \ |
| 953 | .enable_reg = S2MPU02_REG_L1CTRL, \ |
| 954 | .enable_mask = S2MPU02_ENABLE_MASK \ |
| 955 | } |
| 956 | #define regulator_desc_s2mpu02_ldo2(num) { \ |
| 957 | .name = "LDO"#num, \ |
| 958 | .id = S2MPU02_LDO##num, \ |
| 959 | .ops = &s2mpu02_ldo_ops, \ |
| 960 | .type = REGULATOR_VOLTAGE, \ |
| 961 | .owner = THIS_MODULE, \ |
| 962 | .min_uV = S2MPU02_LDO_MIN_1050MV, \ |
| 963 | .uV_step = S2MPU02_LDO_STEP_25MV, \ |
| 964 | .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \ |
| 965 | .n_voltages = S2MPU02_LDO_N_VOLTAGES, \ |
| 966 | .vsel_reg = S2MPU02_REG_L2CTRL1, \ |
| 967 | .vsel_mask = S2MPU02_LDO_VSEL_MASK, \ |
| 968 | .enable_reg = S2MPU02_REG_L2CTRL1, \ |
| 969 | .enable_mask = S2MPU02_ENABLE_MASK \ |
| 970 | } |
| 971 | #define regulator_desc_s2mpu02_ldo3(num) { \ |
| 972 | .name = "LDO"#num, \ |
| 973 | .id = S2MPU02_LDO##num, \ |
| 974 | .ops = &s2mpu02_ldo_ops, \ |
| 975 | .type = REGULATOR_VOLTAGE, \ |
| 976 | .owner = THIS_MODULE, \ |
| 977 | .min_uV = S2MPU02_LDO_MIN_900MV, \ |
| 978 | .uV_step = S2MPU02_LDO_STEP_12_5MV, \ |
| 979 | .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \ |
| 980 | .n_voltages = S2MPU02_LDO_N_VOLTAGES, \ |
| 981 | .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \ |
| 982 | .vsel_mask = S2MPU02_LDO_VSEL_MASK, \ |
| 983 | .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \ |
| 984 | .enable_mask = S2MPU02_ENABLE_MASK \ |
| 985 | } |
| 986 | #define regulator_desc_s2mpu02_ldo4(num) { \ |
| 987 | .name = "LDO"#num, \ |
| 988 | .id = S2MPU02_LDO##num, \ |
| 989 | .ops = &s2mpu02_ldo_ops, \ |
| 990 | .type = REGULATOR_VOLTAGE, \ |
| 991 | .owner = THIS_MODULE, \ |
| 992 | .min_uV = S2MPU02_LDO_MIN_1050MV, \ |
| 993 | .uV_step = S2MPU02_LDO_STEP_25MV, \ |
| 994 | .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \ |
| 995 | .n_voltages = S2MPU02_LDO_N_VOLTAGES, \ |
| 996 | .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \ |
| 997 | .vsel_mask = S2MPU02_LDO_VSEL_MASK, \ |
| 998 | .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \ |
| 999 | .enable_mask = S2MPU02_ENABLE_MASK \ |
| 1000 | } |
| 1001 | #define regulator_desc_s2mpu02_ldo5(num) { \ |
| 1002 | .name = "LDO"#num, \ |
| 1003 | .id = S2MPU02_LDO##num, \ |
| 1004 | .ops = &s2mpu02_ldo_ops, \ |
| 1005 | .type = REGULATOR_VOLTAGE, \ |
| 1006 | .owner = THIS_MODULE, \ |
| 1007 | .min_uV = S2MPU02_LDO_MIN_1600MV, \ |
| 1008 | .uV_step = S2MPU02_LDO_STEP_50MV, \ |
| 1009 | .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \ |
| 1010 | .n_voltages = S2MPU02_LDO_N_VOLTAGES, \ |
| 1011 | .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \ |
| 1012 | .vsel_mask = S2MPU02_LDO_VSEL_MASK, \ |
| 1013 | .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \ |
| 1014 | .enable_mask = S2MPU02_ENABLE_MASK \ |
| 1015 | } |
| 1016 | |
| 1017 | #define regulator_desc_s2mpu02_buck1234(num) { \ |
| 1018 | .name = "BUCK"#num, \ |
| 1019 | .id = S2MPU02_BUCK##num, \ |
| 1020 | .ops = &s2mpu02_buck_ops, \ |
| 1021 | .type = REGULATOR_VOLTAGE, \ |
| 1022 | .owner = THIS_MODULE, \ |
| 1023 | .min_uV = S2MPU02_BUCK1234_MIN_600MV, \ |
| 1024 | .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \ |
| 1025 | .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \ |
| 1026 | .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \ |
| 1027 | .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \ |
| 1028 | .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \ |
| 1029 | .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \ |
| 1030 | .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \ |
| 1031 | .enable_mask = S2MPU02_ENABLE_MASK \ |
| 1032 | } |
| 1033 | #define regulator_desc_s2mpu02_buck5(num) { \ |
| 1034 | .name = "BUCK"#num, \ |
| 1035 | .id = S2MPU02_BUCK##num, \ |
| 1036 | .ops = &s2mpu02_ldo_ops, \ |
| 1037 | .type = REGULATOR_VOLTAGE, \ |
| 1038 | .owner = THIS_MODULE, \ |
| 1039 | .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \ |
| 1040 | .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \ |
| 1041 | .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \ |
| 1042 | .linear_min_sel = S2MPU02_BUCK5_START_SEL, \ |
| 1043 | .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \ |
| 1044 | .vsel_reg = S2MPU02_REG_B5CTRL2, \ |
| 1045 | .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \ |
| 1046 | .enable_reg = S2MPU02_REG_B5CTRL1, \ |
| 1047 | .enable_mask = S2MPU02_ENABLE_MASK \ |
| 1048 | } |
| 1049 | #define regulator_desc_s2mpu02_buck6(num) { \ |
| 1050 | .name = "BUCK"#num, \ |
| 1051 | .id = S2MPU02_BUCK##num, \ |
| 1052 | .ops = &s2mpu02_ldo_ops, \ |
| 1053 | .type = REGULATOR_VOLTAGE, \ |
| 1054 | .owner = THIS_MODULE, \ |
| 1055 | .min_uV = S2MPU02_BUCK6_MIN_1700MV, \ |
| 1056 | .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \ |
| 1057 | .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \ |
| 1058 | .linear_min_sel = S2MPU02_BUCK6_START_SEL, \ |
| 1059 | .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \ |
| 1060 | .vsel_reg = S2MPU02_REG_B6CTRL2, \ |
| 1061 | .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \ |
| 1062 | .enable_reg = S2MPU02_REG_B6CTRL1, \ |
| 1063 | .enable_mask = S2MPU02_ENABLE_MASK \ |
| 1064 | } |
| 1065 | #define regulator_desc_s2mpu02_buck7(num) { \ |
| 1066 | .name = "BUCK"#num, \ |
| 1067 | .id = S2MPU02_BUCK##num, \ |
| 1068 | .ops = &s2mpu02_ldo_ops, \ |
| 1069 | .type = REGULATOR_VOLTAGE, \ |
| 1070 | .owner = THIS_MODULE, \ |
| 1071 | .min_uV = S2MPU02_BUCK7_MIN_900MV, \ |
| 1072 | .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \ |
| 1073 | .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \ |
| 1074 | .linear_min_sel = S2MPU02_BUCK7_START_SEL, \ |
| 1075 | .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \ |
| 1076 | .vsel_reg = S2MPU02_REG_B7CTRL2, \ |
| 1077 | .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \ |
| 1078 | .enable_reg = S2MPU02_REG_B7CTRL1, \ |
| 1079 | .enable_mask = S2MPU02_ENABLE_MASK \ |
| 1080 | } |
| 1081 | |
| 1082 | static const struct regulator_desc s2mpu02_regulators[] = { |
| 1083 | regulator_desc_s2mpu02_ldo1(1), |
| 1084 | regulator_desc_s2mpu02_ldo2(2), |
| 1085 | regulator_desc_s2mpu02_ldo4(3), |
| 1086 | regulator_desc_s2mpu02_ldo5(4), |
| 1087 | regulator_desc_s2mpu02_ldo4(5), |
| 1088 | regulator_desc_s2mpu02_ldo3(6), |
| 1089 | regulator_desc_s2mpu02_ldo3(7), |
| 1090 | regulator_desc_s2mpu02_ldo4(8), |
| 1091 | regulator_desc_s2mpu02_ldo5(9), |
| 1092 | regulator_desc_s2mpu02_ldo3(10), |
| 1093 | regulator_desc_s2mpu02_ldo4(11), |
| 1094 | regulator_desc_s2mpu02_ldo5(12), |
| 1095 | regulator_desc_s2mpu02_ldo5(13), |
| 1096 | regulator_desc_s2mpu02_ldo5(14), |
| 1097 | regulator_desc_s2mpu02_ldo5(15), |
| 1098 | regulator_desc_s2mpu02_ldo5(16), |
| 1099 | regulator_desc_s2mpu02_ldo4(17), |
| 1100 | regulator_desc_s2mpu02_ldo5(18), |
| 1101 | regulator_desc_s2mpu02_ldo3(19), |
| 1102 | regulator_desc_s2mpu02_ldo4(20), |
| 1103 | regulator_desc_s2mpu02_ldo5(21), |
| 1104 | regulator_desc_s2mpu02_ldo5(22), |
| 1105 | regulator_desc_s2mpu02_ldo5(23), |
| 1106 | regulator_desc_s2mpu02_ldo4(24), |
| 1107 | regulator_desc_s2mpu02_ldo5(25), |
| 1108 | regulator_desc_s2mpu02_ldo4(26), |
| 1109 | regulator_desc_s2mpu02_ldo5(27), |
| 1110 | regulator_desc_s2mpu02_ldo5(28), |
| 1111 | regulator_desc_s2mpu02_buck1234(1), |
| 1112 | regulator_desc_s2mpu02_buck1234(2), |
| 1113 | regulator_desc_s2mpu02_buck1234(3), |
| 1114 | regulator_desc_s2mpu02_buck1234(4), |
| 1115 | regulator_desc_s2mpu02_buck5(5), |
| 1116 | regulator_desc_s2mpu02_buck6(6), |
| 1117 | regulator_desc_s2mpu02_buck7(7), |
| 1118 | }; |
| 1119 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 1120 | static int s2mps11_pmic_probe(struct platform_device *pdev) |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1121 | { |
| 1122 | struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 1123 | struct of_regulator_match *rdata = NULL; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1124 | struct regulator_config config = { }; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1125 | struct s2mps11_info *s2mps11; |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 1126 | unsigned int rdev_num = 0; |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 1127 | int i, ret = 0; |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 1128 | const struct regulator_desc *regulators; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1129 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1130 | s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), |
| 1131 | GFP_KERNEL); |
| 1132 | if (!s2mps11) |
| 1133 | return -ENOMEM; |
| 1134 | |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 1135 | s2mps11->dev_type = platform_get_device_id(pdev)->driver_data; |
| 1136 | switch (s2mps11->dev_type) { |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 1137 | case S2MPS11X: |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 1138 | rdev_num = ARRAY_SIZE(s2mps11_regulators); |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 1139 | regulators = s2mps11_regulators; |
Krzysztof Kozlowski | 297eaaa | 2016-02-18 09:35:07 +0900 | [diff] [blame] | 1140 | BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators)); |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 1141 | break; |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 1142 | case S2MPS13X: |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 1143 | rdev_num = ARRAY_SIZE(s2mps13_regulators); |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 1144 | regulators = s2mps13_regulators; |
Krzysztof Kozlowski | 297eaaa | 2016-02-18 09:35:07 +0900 | [diff] [blame] | 1145 | BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators)); |
Chanwoo Choi | 76b9840 | 2014-11-18 17:59:40 +0900 | [diff] [blame] | 1146 | break; |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 1147 | case S2MPS14X: |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 1148 | rdev_num = ARRAY_SIZE(s2mps14_regulators); |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 1149 | regulators = s2mps14_regulators; |
Krzysztof Kozlowski | 297eaaa | 2016-02-18 09:35:07 +0900 | [diff] [blame] | 1150 | BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators)); |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 1151 | break; |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 1152 | case S2MPS15X: |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 1153 | rdev_num = ARRAY_SIZE(s2mps15_regulators); |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 1154 | regulators = s2mps15_regulators; |
Krzysztof Kozlowski | 297eaaa | 2016-02-18 09:35:07 +0900 | [diff] [blame] | 1155 | BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators)); |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 1156 | break; |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 1157 | case S2MPU02: |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 1158 | rdev_num = ARRAY_SIZE(s2mpu02_regulators); |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 1159 | regulators = s2mpu02_regulators; |
Krzysztof Kozlowski | 297eaaa | 2016-02-18 09:35:07 +0900 | [diff] [blame] | 1160 | BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators)); |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 1161 | break; |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 1162 | default: |
Chanwoo Choi | 00e2573 | 2014-06-25 16:14:45 +0900 | [diff] [blame] | 1163 | dev_err(&pdev->dev, "Invalid device type: %u\n", |
| 1164 | s2mps11->dev_type); |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 1165 | return -EINVAL; |
Krzysztof Kozlowski | 7cf225b | 2015-04-23 21:24:32 +0900 | [diff] [blame] | 1166 | } |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 1167 | |
Marek Szyprowski | d7c7fc4 | 2018-11-20 13:38:44 +0100 | [diff] [blame] | 1168 | s2mps11->ext_control_gpiod = devm_kcalloc(&pdev->dev, rdev_num, |
| 1169 | sizeof(*s2mps11->ext_control_gpiod), GFP_KERNEL); |
Linus Walleij | 1c98494 | 2018-11-15 09:01:17 +0100 | [diff] [blame] | 1170 | if (!s2mps11->ext_control_gpiod) |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 1171 | return -ENOMEM; |
| 1172 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1173 | rdata = kcalloc(rdev_num, sizeof(*rdata), GFP_KERNEL); |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 1174 | if (!rdata) |
| 1175 | return -ENOMEM; |
| 1176 | |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 1177 | for (i = 0; i < rdev_num; i++) |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 1178 | rdata[i].name = regulators[i].name; |
| 1179 | |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 1180 | ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num); |
Krzysztof Kozlowski | 0117038 | 2014-04-14 10:09:06 +0200 | [diff] [blame] | 1181 | if (ret) |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 1182 | goto out; |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 1183 | |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 1184 | platform_set_drvdata(pdev, s2mps11); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1185 | |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 1186 | config.dev = &pdev->dev; |
Krzysztof Kozlowski | 1b1ccee | 2013-12-11 15:07:43 +0100 | [diff] [blame] | 1187 | config.regmap = iodev->regmap_pmic; |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 1188 | config.driver_data = s2mps11; |
Krzysztof Kozlowski | 7ddec64 | 2016-02-18 14:57:03 +0900 | [diff] [blame] | 1189 | for (i = 0; i < rdev_num; i++) { |
Krzysztof Kozlowski | 3119525 | 2014-02-28 11:01:48 +0100 | [diff] [blame] | 1190 | struct regulator_dev *regulator; |
| 1191 | |
Krzysztof Kozlowski | beeab9b | 2021-04-20 19:02:44 +0200 | [diff] [blame] | 1192 | config.init_data = rdata[i].init_data; |
| 1193 | config.of_node = rdata[i].of_node; |
Linus Walleij | 1c98494 | 2018-11-15 09:01:17 +0100 | [diff] [blame] | 1194 | config.ena_gpiod = s2mps11->ext_control_gpiod[i]; |
Linus Walleij | 2b96edb | 2018-12-06 13:43:51 +0100 | [diff] [blame] | 1195 | /* |
| 1196 | * Hand the GPIO descriptor management over to the regulator |
| 1197 | * core, remove it from devres management. |
| 1198 | */ |
| 1199 | if (config.ena_gpiod) |
| 1200 | devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod); |
Krzysztof Kozlowski | 3119525 | 2014-02-28 11:01:48 +0100 | [diff] [blame] | 1201 | regulator = devm_regulator_register(&pdev->dev, |
Sachin Kamat | d55cd79 | 2013-09-04 12:12:15 +0530 | [diff] [blame] | 1202 | ®ulators[i], &config); |
Krzysztof Kozlowski | 3119525 | 2014-02-28 11:01:48 +0100 | [diff] [blame] | 1203 | if (IS_ERR(regulator)) { |
| 1204 | ret = PTR_ERR(regulator); |
Axel Lin | 232b250 | 2012-07-12 09:37:37 +0800 | [diff] [blame] | 1205 | dev_err(&pdev->dev, "regulator init failed for %d\n", |
| 1206 | i); |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 1207 | goto out; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1208 | } |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 1209 | |
Krzysztof Kozlowski | d57d90f | 2019-09-09 17:57:23 +0200 | [diff] [blame] | 1210 | if (config.ena_gpiod) { |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 1211 | ret = s2mps14_pmic_enable_ext_control(s2mps11, |
| 1212 | regulator); |
| 1213 | if (ret < 0) { |
| 1214 | dev_err(&pdev->dev, |
| 1215 | "failed to enable GPIO control over %s: %d\n", |
| 1216 | regulator->desc->name, ret); |
| 1217 | goto out; |
| 1218 | } |
| 1219 | } |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1220 | } |
| 1221 | |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 1222 | out: |
| 1223 | kfree(rdata); |
| 1224 | |
| 1225 | return ret; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | static const struct platform_device_id s2mps11_pmic_id[] = { |
Alim Akhtar | 2fadbbf | 2015-11-20 16:18:26 +0530 | [diff] [blame] | 1229 | { "s2mps11-regulator", S2MPS11X}, |
| 1230 | { "s2mps13-regulator", S2MPS13X}, |
| 1231 | { "s2mps14-regulator", S2MPS14X}, |
Thomas Abraham | 51af206 | 2015-11-20 16:07:52 +0530 | [diff] [blame] | 1232 | { "s2mps15-regulator", S2MPS15X}, |
Alim Akhtar | 2fadbbf | 2015-11-20 16:18:26 +0530 | [diff] [blame] | 1233 | { "s2mpu02-regulator", S2MPU02}, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1234 | { }, |
| 1235 | }; |
| 1236 | MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id); |
| 1237 | |
| 1238 | static struct platform_driver s2mps11_pmic_driver = { |
| 1239 | .driver = { |
| 1240 | .name = "s2mps11-pmic", |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1241 | }, |
| 1242 | .probe = s2mps11_pmic_probe, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1243 | .id_table = s2mps11_pmic_id, |
| 1244 | }; |
| 1245 | |
Javier Martinez Canillas | 5ab3c49 | 2016-04-06 09:49:46 -0400 | [diff] [blame] | 1246 | module_platform_driver(s2mps11_pmic_driver); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1247 | |
| 1248 | /* Module information */ |
| 1249 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
Krzysztof Kozlowski | fc2b10d | 2020-01-03 18:11:31 +0100 | [diff] [blame] | 1250 | MODULE_DESCRIPTION("Samsung S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver"); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1251 | MODULE_LICENSE("GPL"); |