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