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