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