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