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> |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 33 | #include <linux/mfd/samsung/s2mps14.h> |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 34 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 35 | struct s2mps11_info { |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 36 | unsigned int rdev_num; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 37 | int ramp_delay2; |
| 38 | int ramp_delay34; |
| 39 | int ramp_delay5; |
| 40 | int ramp_delay16; |
| 41 | int ramp_delay7810; |
| 42 | int ramp_delay9; |
Krzysztof Kozlowski | 05be09b | 2014-03-07 11:10:51 +0100 | [diff] [blame] | 43 | /* |
| 44 | * One bit for each S2MPS14 regulator whether the suspend mode |
| 45 | * was enabled. |
| 46 | */ |
| 47 | unsigned int s2mps14_suspend_state:30; |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 48 | /* Array of size rdev_num with GPIO-s for external sleep control */ |
| 49 | int *ext_control_gpio; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | static int get_ramp_delay(int ramp_delay) |
| 53 | { |
| 54 | unsigned char cnt = 0; |
| 55 | |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 56 | ramp_delay /= 6250; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 57 | |
| 58 | while (true) { |
| 59 | ramp_delay = ramp_delay >> 1; |
| 60 | if (ramp_delay == 0) |
| 61 | break; |
| 62 | cnt++; |
| 63 | } |
Axel Lin | f8f1d48 | 2013-08-05 14:08:37 +0800 | [diff] [blame] | 64 | |
| 65 | if (cnt > 3) |
| 66 | cnt = 3; |
| 67 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 68 | return cnt; |
| 69 | } |
| 70 | |
Yadwinder Singh Brar | 1e1598ed | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 71 | static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
| 72 | unsigned int old_selector, |
| 73 | unsigned int new_selector) |
| 74 | { |
| 75 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
| 76 | unsigned int ramp_delay = 0; |
| 77 | int old_volt, new_volt; |
| 78 | |
Thiago Farina | d55efa4 | 2014-01-26 21:57:12 -0200 | [diff] [blame] | 79 | switch (rdev_get_id(rdev)) { |
Yadwinder Singh Brar | 1e1598ed | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 80 | case S2MPS11_BUCK2: |
Yadwinder Singh Brar | 1e1598ed | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 81 | ramp_delay = s2mps11->ramp_delay2; |
| 82 | break; |
| 83 | case S2MPS11_BUCK3: |
Yadwinder Singh Brar | 1e1598ed | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 84 | case S2MPS11_BUCK4: |
Yadwinder Singh Brar | 1e1598ed | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 85 | ramp_delay = s2mps11->ramp_delay34; |
| 86 | break; |
| 87 | case S2MPS11_BUCK5: |
| 88 | ramp_delay = s2mps11->ramp_delay5; |
| 89 | break; |
| 90 | case S2MPS11_BUCK6: |
Yadwinder Singh Brar | 1e1598ed | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 91 | case S2MPS11_BUCK1: |
| 92 | ramp_delay = s2mps11->ramp_delay16; |
| 93 | break; |
| 94 | case S2MPS11_BUCK7: |
| 95 | case S2MPS11_BUCK8: |
| 96 | case S2MPS11_BUCK10: |
| 97 | ramp_delay = s2mps11->ramp_delay7810; |
| 98 | break; |
| 99 | case S2MPS11_BUCK9: |
| 100 | ramp_delay = s2mps11->ramp_delay9; |
| 101 | } |
| 102 | |
| 103 | if (ramp_delay == 0) |
| 104 | ramp_delay = rdev->desc->ramp_delay; |
| 105 | |
| 106 | old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector); |
| 107 | new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector); |
| 108 | |
| 109 | return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay); |
| 110 | } |
| 111 | |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 112 | static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
| 113 | { |
| 114 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
| 115 | unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK; |
| 116 | unsigned int ramp_enable = 1, enable_shift = 0; |
| 117 | int ret; |
| 118 | |
Thiago Farina | d55efa4 | 2014-01-26 21:57:12 -0200 | [diff] [blame] | 119 | switch (rdev_get_id(rdev)) { |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 120 | case S2MPS11_BUCK1: |
| 121 | if (ramp_delay > s2mps11->ramp_delay16) |
| 122 | s2mps11->ramp_delay16 = ramp_delay; |
| 123 | else |
| 124 | ramp_delay = s2mps11->ramp_delay16; |
| 125 | |
| 126 | ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT; |
| 127 | break; |
| 128 | case S2MPS11_BUCK2: |
| 129 | enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT; |
| 130 | if (!ramp_delay) { |
| 131 | ramp_enable = 0; |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | s2mps11->ramp_delay2 = ramp_delay; |
| 136 | ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT; |
| 137 | ramp_reg = S2MPS11_REG_RAMP; |
| 138 | break; |
| 139 | case S2MPS11_BUCK3: |
| 140 | enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT; |
| 141 | if (!ramp_delay) { |
| 142 | ramp_enable = 0; |
| 143 | break; |
| 144 | } |
| 145 | |
| 146 | if (ramp_delay > s2mps11->ramp_delay34) |
| 147 | s2mps11->ramp_delay34 = ramp_delay; |
| 148 | else |
| 149 | ramp_delay = s2mps11->ramp_delay34; |
| 150 | |
| 151 | ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT; |
| 152 | ramp_reg = S2MPS11_REG_RAMP; |
| 153 | break; |
| 154 | case S2MPS11_BUCK4: |
| 155 | enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT; |
| 156 | if (!ramp_delay) { |
| 157 | ramp_enable = 0; |
| 158 | break; |
| 159 | } |
| 160 | |
| 161 | if (ramp_delay > s2mps11->ramp_delay34) |
| 162 | s2mps11->ramp_delay34 = ramp_delay; |
| 163 | else |
| 164 | ramp_delay = s2mps11->ramp_delay34; |
| 165 | |
| 166 | ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT; |
| 167 | ramp_reg = S2MPS11_REG_RAMP; |
| 168 | break; |
| 169 | case S2MPS11_BUCK5: |
| 170 | s2mps11->ramp_delay5 = ramp_delay; |
| 171 | ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT; |
| 172 | break; |
| 173 | case S2MPS11_BUCK6: |
| 174 | enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT; |
| 175 | if (!ramp_delay) { |
| 176 | ramp_enable = 0; |
| 177 | break; |
| 178 | } |
| 179 | |
| 180 | if (ramp_delay > s2mps11->ramp_delay16) |
| 181 | s2mps11->ramp_delay16 = ramp_delay; |
| 182 | else |
| 183 | ramp_delay = s2mps11->ramp_delay16; |
| 184 | |
| 185 | ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT; |
| 186 | break; |
| 187 | case S2MPS11_BUCK7: |
| 188 | case S2MPS11_BUCK8: |
| 189 | case S2MPS11_BUCK10: |
| 190 | if (ramp_delay > s2mps11->ramp_delay7810) |
| 191 | s2mps11->ramp_delay7810 = ramp_delay; |
| 192 | else |
| 193 | ramp_delay = s2mps11->ramp_delay7810; |
| 194 | |
| 195 | ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT; |
| 196 | break; |
| 197 | case S2MPS11_BUCK9: |
| 198 | s2mps11->ramp_delay9 = ramp_delay; |
| 199 | ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT; |
| 200 | break; |
| 201 | default: |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | if (!ramp_enable) |
| 206 | goto ramp_disable; |
| 207 | |
Krzysztof Kozlowski | b203e0d | 2014-05-06 08:37:36 +0200 | [diff] [blame] | 208 | /* Ramp delay can be enabled/disabled only for buck[2346] */ |
| 209 | if ((rdev_get_id(rdev) >= S2MPS11_BUCK2 && |
| 210 | rdev_get_id(rdev) <= S2MPS11_BUCK4) || |
| 211 | rdev_get_id(rdev) == S2MPS11_BUCK6) { |
| 212 | ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, |
| 213 | 1 << enable_shift, 1 << enable_shift); |
| 214 | if (ret) { |
| 215 | dev_err(&rdev->dev, "failed to enable ramp rate\n"); |
| 216 | return ret; |
| 217 | } |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | ramp_val = get_ramp_delay(ramp_delay); |
| 221 | |
Axel Lin | f8f1d48 | 2013-08-05 14:08:37 +0800 | [diff] [blame] | 222 | return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift, |
| 223 | ramp_val << ramp_shift); |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 224 | |
| 225 | ramp_disable: |
Axel Lin | 8085330 | 2013-08-03 17:10:42 +0800 | [diff] [blame] | 226 | return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, |
| 227 | 1 << enable_shift, 0); |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 228 | } |
| 229 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 230 | static struct regulator_ops s2mps11_ldo_ops = { |
| 231 | .list_voltage = regulator_list_voltage_linear, |
| 232 | .map_voltage = regulator_map_voltage_linear, |
| 233 | .is_enabled = regulator_is_enabled_regmap, |
| 234 | .enable = regulator_enable_regmap, |
| 235 | .disable = regulator_disable_regmap, |
| 236 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 237 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 238 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 239 | }; |
| 240 | |
| 241 | static struct regulator_ops s2mps11_buck_ops = { |
| 242 | .list_voltage = regulator_list_voltage_linear, |
| 243 | .map_voltage = regulator_map_voltage_linear, |
| 244 | .is_enabled = regulator_is_enabled_regmap, |
| 245 | .enable = regulator_enable_regmap, |
| 246 | .disable = regulator_disable_regmap, |
| 247 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 248 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Yadwinder Singh Brar | 1e1598ed | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 249 | .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel, |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 250 | .set_ramp_delay = s2mps11_set_ramp_delay, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 251 | }; |
| 252 | |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 253 | #define regulator_desc_s2mps11_ldo1(num) { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 254 | .name = "LDO"#num, \ |
| 255 | .id = S2MPS11_LDO##num, \ |
| 256 | .ops = &s2mps11_ldo_ops, \ |
| 257 | .type = REGULATOR_VOLTAGE, \ |
| 258 | .owner = THIS_MODULE, \ |
| 259 | .min_uV = S2MPS11_LDO_MIN, \ |
| 260 | .uV_step = S2MPS11_LDO_STEP1, \ |
| 261 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ |
| 262 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 263 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 264 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
| 265 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 266 | } |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 267 | #define regulator_desc_s2mps11_ldo2(num) { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 268 | .name = "LDO"#num, \ |
| 269 | .id = S2MPS11_LDO##num, \ |
| 270 | .ops = &s2mps11_ldo_ops, \ |
| 271 | .type = REGULATOR_VOLTAGE, \ |
| 272 | .owner = THIS_MODULE, \ |
| 273 | .min_uV = S2MPS11_LDO_MIN, \ |
| 274 | .uV_step = S2MPS11_LDO_STEP2, \ |
| 275 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ |
| 276 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 277 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 278 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
| 279 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 280 | } |
| 281 | |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 282 | #define regulator_desc_s2mps11_buck1_4(num) { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 283 | .name = "BUCK"#num, \ |
| 284 | .id = S2MPS11_BUCK##num, \ |
| 285 | .ops = &s2mps11_buck_ops, \ |
| 286 | .type = REGULATOR_VOLTAGE, \ |
| 287 | .owner = THIS_MODULE, \ |
| 288 | .min_uV = S2MPS11_BUCK_MIN1, \ |
| 289 | .uV_step = S2MPS11_BUCK_STEP1, \ |
| 290 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 291 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 292 | .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 293 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 294 | .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \ |
| 295 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 296 | } |
| 297 | |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 298 | #define regulator_desc_s2mps11_buck5 { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 299 | .name = "BUCK5", \ |
| 300 | .id = S2MPS11_BUCK5, \ |
| 301 | .ops = &s2mps11_buck_ops, \ |
| 302 | .type = REGULATOR_VOLTAGE, \ |
| 303 | .owner = THIS_MODULE, \ |
| 304 | .min_uV = S2MPS11_BUCK_MIN1, \ |
| 305 | .uV_step = S2MPS11_BUCK_STEP1, \ |
| 306 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 307 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 308 | .vsel_reg = S2MPS11_REG_B5CTRL2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 309 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 310 | .enable_reg = S2MPS11_REG_B5CTRL1, \ |
| 311 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 312 | } |
| 313 | |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 314 | #define regulator_desc_s2mps11_buck6_8(num) { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 315 | .name = "BUCK"#num, \ |
| 316 | .id = S2MPS11_BUCK##num, \ |
| 317 | .ops = &s2mps11_buck_ops, \ |
| 318 | .type = REGULATOR_VOLTAGE, \ |
| 319 | .owner = THIS_MODULE, \ |
| 320 | .min_uV = S2MPS11_BUCK_MIN1, \ |
| 321 | .uV_step = S2MPS11_BUCK_STEP1, \ |
| 322 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 323 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 324 | .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 325 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 326 | .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \ |
| 327 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 328 | } |
| 329 | |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 330 | #define regulator_desc_s2mps11_buck9 { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 331 | .name = "BUCK9", \ |
| 332 | .id = S2MPS11_BUCK9, \ |
| 333 | .ops = &s2mps11_buck_ops, \ |
| 334 | .type = REGULATOR_VOLTAGE, \ |
| 335 | .owner = THIS_MODULE, \ |
| 336 | .min_uV = S2MPS11_BUCK_MIN3, \ |
| 337 | .uV_step = S2MPS11_BUCK_STEP3, \ |
| 338 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 339 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 340 | .vsel_reg = S2MPS11_REG_B9CTRL2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 341 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 342 | .enable_reg = S2MPS11_REG_B9CTRL1, \ |
| 343 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 344 | } |
| 345 | |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 346 | #define regulator_desc_s2mps11_buck10 { \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 347 | .name = "BUCK10", \ |
| 348 | .id = S2MPS11_BUCK10, \ |
| 349 | .ops = &s2mps11_buck_ops, \ |
| 350 | .type = REGULATOR_VOLTAGE, \ |
| 351 | .owner = THIS_MODULE, \ |
| 352 | .min_uV = S2MPS11_BUCK_MIN2, \ |
| 353 | .uV_step = S2MPS11_BUCK_STEP2, \ |
| 354 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 355 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Alim Akhtar | c76edd5 | 2013-01-30 08:02:27 -0500 | [diff] [blame] | 356 | .vsel_reg = S2MPS11_REG_B10CTRL2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 357 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Alim Akhtar | c76edd5 | 2013-01-30 08:02:27 -0500 | [diff] [blame] | 358 | .enable_reg = S2MPS11_REG_B10CTRL1, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 359 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 360 | } |
| 361 | |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 362 | static const struct regulator_desc s2mps11_regulators[] = { |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 363 | regulator_desc_s2mps11_ldo2(1), |
| 364 | regulator_desc_s2mps11_ldo1(2), |
| 365 | regulator_desc_s2mps11_ldo1(3), |
| 366 | regulator_desc_s2mps11_ldo1(4), |
| 367 | regulator_desc_s2mps11_ldo1(5), |
| 368 | regulator_desc_s2mps11_ldo2(6), |
| 369 | regulator_desc_s2mps11_ldo1(7), |
| 370 | regulator_desc_s2mps11_ldo1(8), |
| 371 | regulator_desc_s2mps11_ldo1(9), |
| 372 | regulator_desc_s2mps11_ldo1(10), |
| 373 | regulator_desc_s2mps11_ldo2(11), |
| 374 | regulator_desc_s2mps11_ldo1(12), |
| 375 | regulator_desc_s2mps11_ldo1(13), |
| 376 | regulator_desc_s2mps11_ldo1(14), |
| 377 | regulator_desc_s2mps11_ldo1(15), |
| 378 | regulator_desc_s2mps11_ldo1(16), |
| 379 | regulator_desc_s2mps11_ldo1(17), |
| 380 | regulator_desc_s2mps11_ldo1(18), |
| 381 | regulator_desc_s2mps11_ldo1(19), |
| 382 | regulator_desc_s2mps11_ldo1(20), |
| 383 | regulator_desc_s2mps11_ldo1(21), |
| 384 | regulator_desc_s2mps11_ldo2(22), |
| 385 | regulator_desc_s2mps11_ldo2(23), |
| 386 | regulator_desc_s2mps11_ldo1(24), |
| 387 | regulator_desc_s2mps11_ldo1(25), |
| 388 | regulator_desc_s2mps11_ldo1(26), |
| 389 | regulator_desc_s2mps11_ldo2(27), |
| 390 | regulator_desc_s2mps11_ldo1(28), |
| 391 | regulator_desc_s2mps11_ldo1(29), |
| 392 | regulator_desc_s2mps11_ldo1(30), |
| 393 | regulator_desc_s2mps11_ldo1(31), |
| 394 | regulator_desc_s2mps11_ldo1(32), |
| 395 | regulator_desc_s2mps11_ldo1(33), |
| 396 | regulator_desc_s2mps11_ldo1(34), |
| 397 | regulator_desc_s2mps11_ldo1(35), |
| 398 | regulator_desc_s2mps11_ldo1(36), |
| 399 | regulator_desc_s2mps11_ldo1(37), |
| 400 | regulator_desc_s2mps11_ldo1(38), |
| 401 | regulator_desc_s2mps11_buck1_4(1), |
| 402 | regulator_desc_s2mps11_buck1_4(2), |
| 403 | regulator_desc_s2mps11_buck1_4(3), |
| 404 | regulator_desc_s2mps11_buck1_4(4), |
| 405 | regulator_desc_s2mps11_buck5, |
| 406 | regulator_desc_s2mps11_buck6_8(6), |
| 407 | regulator_desc_s2mps11_buck6_8(7), |
| 408 | regulator_desc_s2mps11_buck6_8(8), |
| 409 | regulator_desc_s2mps11_buck9, |
| 410 | regulator_desc_s2mps11_buck10, |
| 411 | }; |
| 412 | |
Krzysztof Kozlowski | 05be09b | 2014-03-07 11:10:51 +0100 | [diff] [blame] | 413 | static int s2mps14_regulator_enable(struct regulator_dev *rdev) |
| 414 | { |
| 415 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
| 416 | unsigned int val; |
| 417 | |
| 418 | if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev))) |
| 419 | val = S2MPS14_ENABLE_SUSPEND; |
Krzysztof Kozlowski | de5d056 | 2014-04-30 10:40:42 +0200 | [diff] [blame] | 420 | else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)])) |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 421 | val = S2MPS14_ENABLE_EXT_CONTROL; |
Krzysztof Kozlowski | 05be09b | 2014-03-07 11:10:51 +0100 | [diff] [blame] | 422 | else |
| 423 | val = rdev->desc->enable_mask; |
| 424 | |
| 425 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 426 | rdev->desc->enable_mask, val); |
| 427 | } |
| 428 | |
| 429 | static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev) |
| 430 | { |
| 431 | int ret; |
| 432 | unsigned int val; |
| 433 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
| 434 | |
| 435 | /* LDO3 should be always on and does not support suspend mode */ |
| 436 | if (rdev_get_id(rdev) == S2MPS14_LDO3) |
| 437 | return 0; |
| 438 | |
| 439 | ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); |
| 440 | if (ret < 0) |
| 441 | return ret; |
| 442 | |
| 443 | s2mps11->s2mps14_suspend_state |= (1 << rdev_get_id(rdev)); |
| 444 | /* |
| 445 | * Don't enable suspend mode if regulator is already disabled because |
| 446 | * this would effectively for a short time turn on the regulator after |
| 447 | * resuming. |
| 448 | * However we still want to toggle the suspend_state bit for regulator |
| 449 | * in case if it got enabled before suspending the system. |
| 450 | */ |
| 451 | if (!(val & rdev->desc->enable_mask)) |
| 452 | return 0; |
| 453 | |
| 454 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 455 | rdev->desc->enable_mask, S2MPS14_ENABLE_SUSPEND); |
| 456 | } |
| 457 | |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 458 | static struct regulator_ops s2mps14_reg_ops = { |
| 459 | .list_voltage = regulator_list_voltage_linear, |
| 460 | .map_voltage = regulator_map_voltage_linear, |
| 461 | .is_enabled = regulator_is_enabled_regmap, |
Krzysztof Kozlowski | 05be09b | 2014-03-07 11:10:51 +0100 | [diff] [blame] | 462 | .enable = s2mps14_regulator_enable, |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 463 | .disable = regulator_disable_regmap, |
| 464 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 465 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 466 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Krzysztof Kozlowski | 05be09b | 2014-03-07 11:10:51 +0100 | [diff] [blame] | 467 | .set_suspend_disable = s2mps14_regulator_set_suspend_disable, |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 468 | }; |
| 469 | |
| 470 | #define regulator_desc_s2mps14_ldo1(num) { \ |
| 471 | .name = "LDO"#num, \ |
| 472 | .id = S2MPS14_LDO##num, \ |
| 473 | .ops = &s2mps14_reg_ops, \ |
| 474 | .type = REGULATOR_VOLTAGE, \ |
| 475 | .owner = THIS_MODULE, \ |
| 476 | .min_uV = S2MPS14_LDO_MIN_800MV, \ |
| 477 | .uV_step = S2MPS14_LDO_STEP_25MV, \ |
| 478 | .n_voltages = S2MPS14_LDO_N_VOLTAGES, \ |
| 479 | .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \ |
| 480 | .vsel_mask = S2MPS14_LDO_VSEL_MASK, \ |
| 481 | .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \ |
| 482 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 483 | } |
| 484 | #define regulator_desc_s2mps14_ldo2(num) { \ |
| 485 | .name = "LDO"#num, \ |
| 486 | .id = S2MPS14_LDO##num, \ |
| 487 | .ops = &s2mps14_reg_ops, \ |
| 488 | .type = REGULATOR_VOLTAGE, \ |
| 489 | .owner = THIS_MODULE, \ |
| 490 | .min_uV = S2MPS14_LDO_MIN_1800MV, \ |
| 491 | .uV_step = S2MPS14_LDO_STEP_25MV, \ |
| 492 | .n_voltages = S2MPS14_LDO_N_VOLTAGES, \ |
| 493 | .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \ |
| 494 | .vsel_mask = S2MPS14_LDO_VSEL_MASK, \ |
| 495 | .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \ |
| 496 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 497 | } |
| 498 | #define regulator_desc_s2mps14_ldo3(num) { \ |
| 499 | .name = "LDO"#num, \ |
| 500 | .id = S2MPS14_LDO##num, \ |
| 501 | .ops = &s2mps14_reg_ops, \ |
| 502 | .type = REGULATOR_VOLTAGE, \ |
| 503 | .owner = THIS_MODULE, \ |
| 504 | .min_uV = S2MPS14_LDO_MIN_800MV, \ |
| 505 | .uV_step = S2MPS14_LDO_STEP_12_5MV, \ |
| 506 | .n_voltages = S2MPS14_LDO_N_VOLTAGES, \ |
| 507 | .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \ |
| 508 | .vsel_mask = S2MPS14_LDO_VSEL_MASK, \ |
| 509 | .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \ |
| 510 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 511 | } |
| 512 | #define regulator_desc_s2mps14_buck1235(num) { \ |
| 513 | .name = "BUCK"#num, \ |
| 514 | .id = S2MPS14_BUCK##num, \ |
| 515 | .ops = &s2mps14_reg_ops, \ |
| 516 | .type = REGULATOR_VOLTAGE, \ |
| 517 | .owner = THIS_MODULE, \ |
| 518 | .min_uV = S2MPS14_BUCK1235_MIN_600MV, \ |
| 519 | .uV_step = S2MPS14_BUCK1235_STEP_6_25MV, \ |
| 520 | .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \ |
| 521 | .linear_min_sel = S2MPS14_BUCK1235_START_SEL, \ |
| 522 | .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \ |
| 523 | .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \ |
| 524 | .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \ |
| 525 | .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \ |
| 526 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 527 | } |
| 528 | #define regulator_desc_s2mps14_buck4(num) { \ |
| 529 | .name = "BUCK"#num, \ |
| 530 | .id = S2MPS14_BUCK##num, \ |
| 531 | .ops = &s2mps14_reg_ops, \ |
| 532 | .type = REGULATOR_VOLTAGE, \ |
| 533 | .owner = THIS_MODULE, \ |
| 534 | .min_uV = S2MPS14_BUCK4_MIN_1400MV, \ |
| 535 | .uV_step = S2MPS14_BUCK4_STEP_12_5MV, \ |
| 536 | .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \ |
| 537 | .linear_min_sel = S2MPS14_BUCK4_START_SEL, \ |
| 538 | .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \ |
| 539 | .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \ |
| 540 | .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \ |
| 541 | .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \ |
| 542 | .enable_mask = S2MPS14_ENABLE_MASK \ |
| 543 | } |
| 544 | |
| 545 | static const struct regulator_desc s2mps14_regulators[] = { |
| 546 | regulator_desc_s2mps14_ldo3(1), |
| 547 | regulator_desc_s2mps14_ldo3(2), |
| 548 | regulator_desc_s2mps14_ldo1(3), |
| 549 | regulator_desc_s2mps14_ldo1(4), |
| 550 | regulator_desc_s2mps14_ldo3(5), |
| 551 | regulator_desc_s2mps14_ldo3(6), |
| 552 | regulator_desc_s2mps14_ldo1(7), |
| 553 | regulator_desc_s2mps14_ldo2(8), |
| 554 | regulator_desc_s2mps14_ldo3(9), |
| 555 | regulator_desc_s2mps14_ldo3(10), |
| 556 | regulator_desc_s2mps14_ldo1(11), |
| 557 | regulator_desc_s2mps14_ldo2(12), |
| 558 | regulator_desc_s2mps14_ldo2(13), |
| 559 | regulator_desc_s2mps14_ldo2(14), |
| 560 | regulator_desc_s2mps14_ldo2(15), |
| 561 | regulator_desc_s2mps14_ldo2(16), |
| 562 | regulator_desc_s2mps14_ldo2(17), |
| 563 | regulator_desc_s2mps14_ldo2(18), |
| 564 | regulator_desc_s2mps14_ldo1(19), |
| 565 | regulator_desc_s2mps14_ldo1(20), |
| 566 | regulator_desc_s2mps14_ldo1(21), |
| 567 | regulator_desc_s2mps14_ldo3(22), |
| 568 | regulator_desc_s2mps14_ldo1(23), |
| 569 | regulator_desc_s2mps14_ldo2(24), |
| 570 | regulator_desc_s2mps14_ldo2(25), |
| 571 | regulator_desc_s2mps14_buck1235(1), |
| 572 | regulator_desc_s2mps14_buck1235(2), |
| 573 | regulator_desc_s2mps14_buck1235(3), |
| 574 | regulator_desc_s2mps14_buck4(4), |
| 575 | regulator_desc_s2mps14_buck1235(5), |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 576 | }; |
| 577 | |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 578 | static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11, |
| 579 | struct regulator_dev *rdev) |
| 580 | { |
| 581 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 582 | rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL); |
| 583 | } |
| 584 | |
| 585 | 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] | 586 | struct of_regulator_match *rdata, struct s2mps11_info *s2mps11) |
| 587 | { |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 588 | int *gpio = s2mps11->ext_control_gpio; |
| 589 | unsigned int i; |
| 590 | unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11, |
| 591 | S2MPS14_LDO12 }; |
| 592 | |
| 593 | for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) { |
| 594 | unsigned int reg = valid_regulators[i]; |
| 595 | |
| 596 | if (!rdata[reg].init_data || !rdata[reg].of_node) |
| 597 | continue; |
| 598 | |
| 599 | gpio[reg] = of_get_named_gpio(rdata[reg].of_node, |
| 600 | "samsung,ext-control-gpios", 0); |
Krzysztof Kozlowski | de5d056 | 2014-04-30 10:40:42 +0200 | [diff] [blame] | 601 | if (gpio_is_valid(gpio[reg])) |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 602 | dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n", |
| 603 | gpio[reg], reg, rdata[reg].name); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | static int s2mps11_pmic_dt_parse(struct platform_device *pdev, |
| 608 | struct of_regulator_match *rdata, struct s2mps11_info *s2mps11, |
| 609 | enum sec_device_type dev_type) |
| 610 | { |
Krzysztof Kozlowski | 0117038 | 2014-04-14 10:09:06 +0200 | [diff] [blame] | 611 | struct device_node *reg_np; |
| 612 | |
| 613 | reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); |
| 614 | if (!reg_np) { |
| 615 | dev_err(&pdev->dev, "could not find regulators sub-node\n"); |
| 616 | return -EINVAL; |
| 617 | } |
| 618 | |
| 619 | of_regulator_match(&pdev->dev, reg_np, rdata, s2mps11->rdev_num); |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 620 | if (dev_type == S2MPS14X) |
| 621 | s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11); |
| 622 | |
Krzysztof Kozlowski | 0117038 | 2014-04-14 10:09:06 +0200 | [diff] [blame] | 623 | of_node_put(reg_np); |
| 624 | |
| 625 | return 0; |
| 626 | } |
| 627 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 628 | static int s2mps11_pmic_probe(struct platform_device *pdev) |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 629 | { |
| 630 | struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
Krzysztof Kozlowski | 0117038 | 2014-04-14 10:09:06 +0200 | [diff] [blame] | 631 | struct sec_platform_data *pdata = NULL; |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 632 | struct of_regulator_match *rdata = NULL; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 633 | struct regulator_config config = { }; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 634 | struct s2mps11_info *s2mps11; |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 635 | int i, ret = 0; |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 636 | const struct regulator_desc *regulators; |
| 637 | enum sec_device_type dev_type; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 638 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 639 | s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), |
| 640 | GFP_KERNEL); |
| 641 | if (!s2mps11) |
| 642 | return -ENOMEM; |
| 643 | |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 644 | dev_type = platform_get_device_id(pdev)->driver_data; |
| 645 | switch (dev_type) { |
| 646 | case S2MPS11X: |
| 647 | s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators); |
| 648 | regulators = s2mps11_regulators; |
| 649 | break; |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 650 | case S2MPS14X: |
| 651 | s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators); |
| 652 | regulators = s2mps14_regulators; |
| 653 | break; |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 654 | default: |
| 655 | dev_err(&pdev->dev, "Invalid device type: %u\n", dev_type); |
| 656 | return -EINVAL; |
| 657 | }; |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 658 | |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 659 | s2mps11->ext_control_gpio = devm_kzalloc(&pdev->dev, |
| 660 | sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num, |
| 661 | GFP_KERNEL); |
| 662 | if (!s2mps11->ext_control_gpio) |
| 663 | return -ENOMEM; |
Krzysztof Kozlowski | de5d056 | 2014-04-30 10:40:42 +0200 | [diff] [blame] | 664 | /* |
| 665 | * 0 is a valid GPIO so initialize all GPIO-s to negative value |
| 666 | * to indicate that external control won't be used for this regulator. |
| 667 | */ |
| 668 | for (i = 0; i < s2mps11->rdev_num; i++) |
| 669 | s2mps11->ext_control_gpio[i] = -EINVAL; |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 670 | |
Yadwinder Singh Brar | 6c683c9 | 2013-06-29 18:21:18 +0530 | [diff] [blame] | 671 | if (!iodev->dev->of_node) { |
Krzysztof Kozlowski | 0117038 | 2014-04-14 10:09:06 +0200 | [diff] [blame] | 672 | if (iodev->pdata) { |
| 673 | pdata = iodev->pdata; |
Yadwinder Singh Brar | 6c683c9 | 2013-06-29 18:21:18 +0530 | [diff] [blame] | 674 | goto common_reg; |
| 675 | } else { |
| 676 | dev_err(pdev->dev.parent, |
| 677 | "Platform data or DT node not supplied\n"); |
| 678 | return -ENODEV; |
| 679 | } |
| 680 | } |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 681 | |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 682 | rdata = kzalloc(sizeof(*rdata) * s2mps11->rdev_num, GFP_KERNEL); |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 683 | if (!rdata) |
| 684 | return -ENOMEM; |
| 685 | |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 686 | for (i = 0; i < s2mps11->rdev_num; i++) |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 687 | rdata[i].name = regulators[i].name; |
| 688 | |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 689 | ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, dev_type); |
Krzysztof Kozlowski | 0117038 | 2014-04-14 10:09:06 +0200 | [diff] [blame] | 690 | if (ret) |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 691 | goto out; |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 692 | |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 693 | common_reg: |
| 694 | platform_set_drvdata(pdev, s2mps11); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 695 | |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 696 | config.dev = &pdev->dev; |
Krzysztof Kozlowski | 1b1ccee | 2013-12-11 15:07:43 +0100 | [diff] [blame] | 697 | config.regmap = iodev->regmap_pmic; |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 698 | config.driver_data = s2mps11; |
Krzysztof Kozlowski | de5d056 | 2014-04-30 10:40:42 +0200 | [diff] [blame] | 699 | config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH; |
Krzysztof Kozlowski | 0f4cc28 | 2014-03-03 16:53:51 +0100 | [diff] [blame] | 700 | for (i = 0; i < s2mps11->rdev_num; i++) { |
Krzysztof Kozlowski | 3119525 | 2014-02-28 11:01:48 +0100 | [diff] [blame] | 701 | struct regulator_dev *regulator; |
| 702 | |
Krzysztof Kozlowski | 0117038 | 2014-04-14 10:09:06 +0200 | [diff] [blame] | 703 | if (pdata) { |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 704 | config.init_data = pdata->regulators[i].initdata; |
Krzysztof Kozlowski | 54820f5 | 2014-01-30 14:51:19 +0100 | [diff] [blame] | 705 | config.of_node = pdata->regulators[i].reg_node; |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 706 | } else { |
| 707 | config.init_data = rdata[i].init_data; |
| 708 | config.of_node = rdata[i].of_node; |
| 709 | } |
Krzysztof Kozlowski | de5d056 | 2014-04-30 10:40:42 +0200 | [diff] [blame] | 710 | config.ena_gpio = s2mps11->ext_control_gpio[i]; |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 711 | |
Krzysztof Kozlowski | 3119525 | 2014-02-28 11:01:48 +0100 | [diff] [blame] | 712 | regulator = devm_regulator_register(&pdev->dev, |
Sachin Kamat | d55cd79 | 2013-09-04 12:12:15 +0530 | [diff] [blame] | 713 | ®ulators[i], &config); |
Krzysztof Kozlowski | 3119525 | 2014-02-28 11:01:48 +0100 | [diff] [blame] | 714 | if (IS_ERR(regulator)) { |
| 715 | ret = PTR_ERR(regulator); |
Axel Lin | 232b250 | 2012-07-12 09:37:37 +0800 | [diff] [blame] | 716 | dev_err(&pdev->dev, "regulator init failed for %d\n", |
| 717 | i); |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 718 | goto out; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 719 | } |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 720 | |
Krzysztof Kozlowski | de5d056 | 2014-04-30 10:40:42 +0200 | [diff] [blame] | 721 | if (gpio_is_valid(s2mps11->ext_control_gpio[i])) { |
Krzysztof Kozlowski | 97f53d7 | 2014-04-14 10:09:07 +0200 | [diff] [blame] | 722 | ret = s2mps14_pmic_enable_ext_control(s2mps11, |
| 723 | regulator); |
| 724 | if (ret < 0) { |
| 725 | dev_err(&pdev->dev, |
| 726 | "failed to enable GPIO control over %s: %d\n", |
| 727 | regulator->desc->name, ret); |
| 728 | goto out; |
| 729 | } |
| 730 | } |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 731 | } |
| 732 | |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 733 | out: |
| 734 | kfree(rdata); |
| 735 | |
| 736 | return ret; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | static const struct platform_device_id s2mps11_pmic_id[] = { |
Krzysztof Kozlowski | 3e80f95 | 2014-02-28 11:01:50 +0100 | [diff] [blame] | 740 | { "s2mps11-pmic", S2MPS11X}, |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 741 | { "s2mps14-pmic", S2MPS14X}, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 742 | { }, |
| 743 | }; |
| 744 | MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id); |
| 745 | |
| 746 | static struct platform_driver s2mps11_pmic_driver = { |
| 747 | .driver = { |
| 748 | .name = "s2mps11-pmic", |
| 749 | .owner = THIS_MODULE, |
| 750 | }, |
| 751 | .probe = s2mps11_pmic_probe, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 752 | .id_table = s2mps11_pmic_id, |
| 753 | }; |
| 754 | |
| 755 | static int __init s2mps11_pmic_init(void) |
| 756 | { |
| 757 | return platform_driver_register(&s2mps11_pmic_driver); |
| 758 | } |
| 759 | subsys_initcall(s2mps11_pmic_init); |
| 760 | |
| 761 | static void __exit s2mps11_pmic_exit(void) |
| 762 | { |
| 763 | platform_driver_unregister(&s2mps11_pmic_driver); |
| 764 | } |
| 765 | module_exit(s2mps11_pmic_exit); |
| 766 | |
| 767 | /* Module information */ |
| 768 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
Krzysztof Kozlowski | 15f7730 | 2014-03-07 11:10:50 +0100 | [diff] [blame] | 769 | MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14 Regulator Driver"); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 770 | MODULE_LICENSE("GPL"); |