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