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