Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 1 | /* |
| 2 | * s2mps11.c |
| 3 | * |
| 4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd |
| 5 | * http://www.samsung.com |
| 6 | * |
| 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 | */ |
| 13 | |
| 14 | #include <linux/bug.h> |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 15 | #include <linux/err.h> |
| 16 | #include <linux/gpio.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/module.h> |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 19 | #include <linux/of.h> |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 20 | #include <linux/regmap.h> |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/regulator/driver.h> |
| 23 | #include <linux/regulator/machine.h> |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 24 | #include <linux/regulator/of_regulator.h> |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 25 | #include <linux/mfd/samsung/core.h> |
| 26 | #include <linux/mfd/samsung/s2mps11.h> |
| 27 | |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 28 | #define S2MPS11_REGULATOR_CNT ARRAY_SIZE(regulators) |
| 29 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 30 | struct s2mps11_info { |
Axel Lin | ad46ed1 | 2012-07-13 10:12:40 +0800 | [diff] [blame] | 31 | struct regulator_dev *rdev[S2MPS11_REGULATOR_MAX]; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 32 | |
| 33 | int ramp_delay2; |
| 34 | int ramp_delay34; |
| 35 | int ramp_delay5; |
| 36 | int ramp_delay16; |
| 37 | int ramp_delay7810; |
| 38 | int ramp_delay9; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | static int get_ramp_delay(int ramp_delay) |
| 42 | { |
| 43 | unsigned char cnt = 0; |
| 44 | |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 45 | ramp_delay /= 6250; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 46 | |
| 47 | while (true) { |
| 48 | ramp_delay = ramp_delay >> 1; |
| 49 | if (ramp_delay == 0) |
| 50 | break; |
| 51 | cnt++; |
| 52 | } |
Axel Lin | f8f1d48 | 2013-08-05 14:08:37 +0800 | [diff] [blame] | 53 | |
| 54 | if (cnt > 3) |
| 55 | cnt = 3; |
| 56 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 57 | return cnt; |
| 58 | } |
| 59 | |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 60 | static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
| 61 | unsigned int old_selector, |
| 62 | unsigned int new_selector) |
| 63 | { |
| 64 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
| 65 | unsigned int ramp_delay = 0; |
| 66 | int old_volt, new_volt; |
| 67 | |
| 68 | switch (rdev->desc->id) { |
| 69 | case S2MPS11_BUCK2: |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 70 | ramp_delay = s2mps11->ramp_delay2; |
| 71 | break; |
| 72 | case S2MPS11_BUCK3: |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 73 | ramp_delay = s2mps11->ramp_delay34; |
| 74 | break; |
| 75 | case S2MPS11_BUCK4: |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 76 | ramp_delay = s2mps11->ramp_delay34; |
| 77 | break; |
| 78 | case S2MPS11_BUCK5: |
| 79 | ramp_delay = s2mps11->ramp_delay5; |
| 80 | break; |
| 81 | case S2MPS11_BUCK6: |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 82 | case S2MPS11_BUCK1: |
| 83 | ramp_delay = s2mps11->ramp_delay16; |
| 84 | break; |
| 85 | case S2MPS11_BUCK7: |
| 86 | case S2MPS11_BUCK8: |
| 87 | case S2MPS11_BUCK10: |
| 88 | ramp_delay = s2mps11->ramp_delay7810; |
| 89 | break; |
| 90 | case S2MPS11_BUCK9: |
| 91 | ramp_delay = s2mps11->ramp_delay9; |
| 92 | } |
| 93 | |
| 94 | if (ramp_delay == 0) |
| 95 | ramp_delay = rdev->desc->ramp_delay; |
| 96 | |
| 97 | old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector); |
| 98 | new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector); |
| 99 | |
| 100 | return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay); |
| 101 | } |
| 102 | |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 103 | static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
| 104 | { |
| 105 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
| 106 | unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK; |
| 107 | unsigned int ramp_enable = 1, enable_shift = 0; |
| 108 | int ret; |
| 109 | |
| 110 | switch (rdev->desc->id) { |
| 111 | case S2MPS11_BUCK1: |
| 112 | if (ramp_delay > s2mps11->ramp_delay16) |
| 113 | s2mps11->ramp_delay16 = ramp_delay; |
| 114 | else |
| 115 | ramp_delay = s2mps11->ramp_delay16; |
| 116 | |
| 117 | ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT; |
| 118 | break; |
| 119 | case S2MPS11_BUCK2: |
| 120 | enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT; |
| 121 | if (!ramp_delay) { |
| 122 | ramp_enable = 0; |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | s2mps11->ramp_delay2 = ramp_delay; |
| 127 | ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT; |
| 128 | ramp_reg = S2MPS11_REG_RAMP; |
| 129 | break; |
| 130 | case S2MPS11_BUCK3: |
| 131 | enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT; |
| 132 | if (!ramp_delay) { |
| 133 | ramp_enable = 0; |
| 134 | break; |
| 135 | } |
| 136 | |
| 137 | if (ramp_delay > s2mps11->ramp_delay34) |
| 138 | s2mps11->ramp_delay34 = ramp_delay; |
| 139 | else |
| 140 | ramp_delay = s2mps11->ramp_delay34; |
| 141 | |
| 142 | ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT; |
| 143 | ramp_reg = S2MPS11_REG_RAMP; |
| 144 | break; |
| 145 | case S2MPS11_BUCK4: |
| 146 | enable_shift = S2MPS11_BUCK4_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_BUCK5: |
| 161 | s2mps11->ramp_delay5 = ramp_delay; |
| 162 | ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT; |
| 163 | break; |
| 164 | case S2MPS11_BUCK6: |
| 165 | enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT; |
| 166 | if (!ramp_delay) { |
| 167 | ramp_enable = 0; |
| 168 | break; |
| 169 | } |
| 170 | |
| 171 | if (ramp_delay > s2mps11->ramp_delay16) |
| 172 | s2mps11->ramp_delay16 = ramp_delay; |
| 173 | else |
| 174 | ramp_delay = s2mps11->ramp_delay16; |
| 175 | |
| 176 | ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT; |
| 177 | break; |
| 178 | case S2MPS11_BUCK7: |
| 179 | case S2MPS11_BUCK8: |
| 180 | case S2MPS11_BUCK10: |
| 181 | if (ramp_delay > s2mps11->ramp_delay7810) |
| 182 | s2mps11->ramp_delay7810 = ramp_delay; |
| 183 | else |
| 184 | ramp_delay = s2mps11->ramp_delay7810; |
| 185 | |
| 186 | ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT; |
| 187 | break; |
| 188 | case S2MPS11_BUCK9: |
| 189 | s2mps11->ramp_delay9 = ramp_delay; |
| 190 | ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT; |
| 191 | break; |
| 192 | default: |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | if (!ramp_enable) |
| 197 | goto ramp_disable; |
| 198 | |
| 199 | if (enable_shift) { |
| 200 | ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, |
| 201 | 1 << enable_shift, 1 << enable_shift); |
| 202 | if (ret) { |
| 203 | dev_err(&rdev->dev, "failed to enable ramp rate\n"); |
| 204 | return ret; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | ramp_val = get_ramp_delay(ramp_delay); |
| 209 | |
Axel Lin | f8f1d48 | 2013-08-05 14:08:37 +0800 | [diff] [blame] | 210 | return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift, |
| 211 | ramp_val << ramp_shift); |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 212 | |
| 213 | ramp_disable: |
Axel Lin | 8085330 | 2013-08-03 17:10:42 +0800 | [diff] [blame] | 214 | return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, |
| 215 | 1 << enable_shift, 0); |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 216 | } |
| 217 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 218 | static struct regulator_ops s2mps11_ldo_ops = { |
| 219 | .list_voltage = regulator_list_voltage_linear, |
| 220 | .map_voltage = regulator_map_voltage_linear, |
| 221 | .is_enabled = regulator_is_enabled_regmap, |
| 222 | .enable = regulator_enable_regmap, |
| 223 | .disable = regulator_disable_regmap, |
| 224 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 225 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 226 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 227 | }; |
| 228 | |
| 229 | static struct regulator_ops s2mps11_buck_ops = { |
| 230 | .list_voltage = regulator_list_voltage_linear, |
| 231 | .map_voltage = regulator_map_voltage_linear, |
| 232 | .is_enabled = regulator_is_enabled_regmap, |
| 233 | .enable = regulator_enable_regmap, |
| 234 | .disable = regulator_disable_regmap, |
| 235 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 236 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 237 | .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel, |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 238 | .set_ramp_delay = s2mps11_set_ramp_delay, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | #define regulator_desc_ldo1(num) { \ |
| 242 | .name = "LDO"#num, \ |
| 243 | .id = S2MPS11_LDO##num, \ |
| 244 | .ops = &s2mps11_ldo_ops, \ |
| 245 | .type = REGULATOR_VOLTAGE, \ |
| 246 | .owner = THIS_MODULE, \ |
| 247 | .min_uV = S2MPS11_LDO_MIN, \ |
| 248 | .uV_step = S2MPS11_LDO_STEP1, \ |
| 249 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ |
| 250 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 251 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 252 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
| 253 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 254 | } |
| 255 | #define regulator_desc_ldo2(num) { \ |
| 256 | .name = "LDO"#num, \ |
| 257 | .id = S2MPS11_LDO##num, \ |
| 258 | .ops = &s2mps11_ldo_ops, \ |
| 259 | .type = REGULATOR_VOLTAGE, \ |
| 260 | .owner = THIS_MODULE, \ |
| 261 | .min_uV = S2MPS11_LDO_MIN, \ |
| 262 | .uV_step = S2MPS11_LDO_STEP2, \ |
| 263 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ |
| 264 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 265 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 266 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
| 267 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 268 | } |
| 269 | |
| 270 | #define regulator_desc_buck1_4(num) { \ |
| 271 | .name = "BUCK"#num, \ |
| 272 | .id = S2MPS11_BUCK##num, \ |
| 273 | .ops = &s2mps11_buck_ops, \ |
| 274 | .type = REGULATOR_VOLTAGE, \ |
| 275 | .owner = THIS_MODULE, \ |
| 276 | .min_uV = S2MPS11_BUCK_MIN1, \ |
| 277 | .uV_step = S2MPS11_BUCK_STEP1, \ |
| 278 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 279 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 280 | .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 281 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 282 | .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \ |
| 283 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 284 | } |
| 285 | |
| 286 | #define regulator_desc_buck5 { \ |
| 287 | .name = "BUCK5", \ |
| 288 | .id = S2MPS11_BUCK5, \ |
| 289 | .ops = &s2mps11_buck_ops, \ |
| 290 | .type = REGULATOR_VOLTAGE, \ |
| 291 | .owner = THIS_MODULE, \ |
| 292 | .min_uV = S2MPS11_BUCK_MIN1, \ |
| 293 | .uV_step = S2MPS11_BUCK_STEP1, \ |
| 294 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 295 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 296 | .vsel_reg = S2MPS11_REG_B5CTRL2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 297 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 298 | .enable_reg = S2MPS11_REG_B5CTRL1, \ |
| 299 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 300 | } |
| 301 | |
| 302 | #define regulator_desc_buck6_8(num) { \ |
| 303 | .name = "BUCK"#num, \ |
| 304 | .id = S2MPS11_BUCK##num, \ |
| 305 | .ops = &s2mps11_buck_ops, \ |
| 306 | .type = REGULATOR_VOLTAGE, \ |
| 307 | .owner = THIS_MODULE, \ |
| 308 | .min_uV = S2MPS11_BUCK_MIN1, \ |
| 309 | .uV_step = S2MPS11_BUCK_STEP1, \ |
| 310 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 311 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 312 | .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 313 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 314 | .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \ |
| 315 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 316 | } |
| 317 | |
| 318 | #define regulator_desc_buck9 { \ |
| 319 | .name = "BUCK9", \ |
| 320 | .id = S2MPS11_BUCK9, \ |
| 321 | .ops = &s2mps11_buck_ops, \ |
| 322 | .type = REGULATOR_VOLTAGE, \ |
| 323 | .owner = THIS_MODULE, \ |
| 324 | .min_uV = S2MPS11_BUCK_MIN3, \ |
| 325 | .uV_step = S2MPS11_BUCK_STEP3, \ |
| 326 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 327 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 328 | .vsel_reg = S2MPS11_REG_B9CTRL2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 329 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 330 | .enable_reg = S2MPS11_REG_B9CTRL1, \ |
| 331 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 332 | } |
| 333 | |
| 334 | #define regulator_desc_buck10 { \ |
| 335 | .name = "BUCK10", \ |
| 336 | .id = S2MPS11_BUCK10, \ |
| 337 | .ops = &s2mps11_buck_ops, \ |
| 338 | .type = REGULATOR_VOLTAGE, \ |
| 339 | .owner = THIS_MODULE, \ |
| 340 | .min_uV = S2MPS11_BUCK_MIN2, \ |
| 341 | .uV_step = S2MPS11_BUCK_STEP2, \ |
| 342 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 343 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Alim Akhtar | c76edd5 | 2013-01-30 08:02:27 -0500 | [diff] [blame] | 344 | .vsel_reg = S2MPS11_REG_B10CTRL2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 345 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Alim Akhtar | c76edd5 | 2013-01-30 08:02:27 -0500 | [diff] [blame] | 346 | .enable_reg = S2MPS11_REG_B10CTRL1, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 347 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 348 | } |
| 349 | |
| 350 | static struct regulator_desc regulators[] = { |
| 351 | regulator_desc_ldo2(1), |
| 352 | regulator_desc_ldo1(2), |
| 353 | regulator_desc_ldo1(3), |
| 354 | regulator_desc_ldo1(4), |
| 355 | regulator_desc_ldo1(5), |
| 356 | regulator_desc_ldo2(6), |
| 357 | regulator_desc_ldo1(7), |
| 358 | regulator_desc_ldo1(8), |
| 359 | regulator_desc_ldo1(9), |
| 360 | regulator_desc_ldo1(10), |
| 361 | regulator_desc_ldo2(11), |
| 362 | regulator_desc_ldo1(12), |
| 363 | regulator_desc_ldo1(13), |
| 364 | regulator_desc_ldo1(14), |
| 365 | regulator_desc_ldo1(15), |
| 366 | regulator_desc_ldo1(16), |
| 367 | regulator_desc_ldo1(17), |
| 368 | regulator_desc_ldo1(18), |
| 369 | regulator_desc_ldo1(19), |
| 370 | regulator_desc_ldo1(20), |
| 371 | regulator_desc_ldo1(21), |
| 372 | regulator_desc_ldo2(22), |
| 373 | regulator_desc_ldo2(23), |
| 374 | regulator_desc_ldo1(24), |
| 375 | regulator_desc_ldo1(25), |
| 376 | regulator_desc_ldo1(26), |
| 377 | regulator_desc_ldo2(27), |
| 378 | regulator_desc_ldo1(28), |
| 379 | regulator_desc_ldo1(29), |
| 380 | regulator_desc_ldo1(30), |
| 381 | regulator_desc_ldo1(31), |
| 382 | regulator_desc_ldo1(32), |
| 383 | regulator_desc_ldo1(33), |
| 384 | regulator_desc_ldo1(34), |
| 385 | regulator_desc_ldo1(35), |
| 386 | regulator_desc_ldo1(36), |
| 387 | regulator_desc_ldo1(37), |
| 388 | regulator_desc_ldo1(38), |
| 389 | regulator_desc_buck1_4(1), |
| 390 | regulator_desc_buck1_4(2), |
| 391 | regulator_desc_buck1_4(3), |
| 392 | regulator_desc_buck1_4(4), |
| 393 | regulator_desc_buck5, |
| 394 | regulator_desc_buck6_8(6), |
| 395 | regulator_desc_buck6_8(7), |
| 396 | regulator_desc_buck6_8(8), |
| 397 | regulator_desc_buck9, |
| 398 | regulator_desc_buck10, |
| 399 | }; |
| 400 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 401 | static int s2mps11_pmic_probe(struct platform_device *pdev) |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 402 | { |
| 403 | struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
| 404 | struct sec_platform_data *pdata = dev_get_platdata(iodev->dev); |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 405 | struct of_regulator_match rdata[S2MPS11_REGULATOR_MAX]; |
| 406 | struct device_node *reg_np = NULL; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 407 | struct regulator_config config = { }; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 408 | struct s2mps11_info *s2mps11; |
Axel Lin | ad46ed1 | 2012-07-13 10:12:40 +0800 | [diff] [blame] | 409 | int i, ret; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 410 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 411 | s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), |
| 412 | GFP_KERNEL); |
| 413 | if (!s2mps11) |
| 414 | return -ENOMEM; |
| 415 | |
Yadwinder Singh Brar | 6c683c9 | 2013-06-29 18:21:18 +0530 | [diff] [blame] | 416 | if (!iodev->dev->of_node) { |
| 417 | if (pdata) { |
| 418 | goto common_reg; |
| 419 | } else { |
| 420 | dev_err(pdev->dev.parent, |
| 421 | "Platform data or DT node not supplied\n"); |
| 422 | return -ENODEV; |
| 423 | } |
| 424 | } |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 425 | |
| 426 | for (i = 0; i < S2MPS11_REGULATOR_CNT; i++) |
| 427 | rdata[i].name = regulators[i].name; |
| 428 | |
| 429 | reg_np = of_find_node_by_name(iodev->dev->of_node, "regulators"); |
| 430 | if (!reg_np) { |
| 431 | dev_err(&pdev->dev, "could not find regulators sub-node\n"); |
| 432 | return -EINVAL; |
| 433 | } |
| 434 | |
| 435 | of_regulator_match(&pdev->dev, reg_np, rdata, S2MPS11_REGULATOR_MAX); |
| 436 | |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 437 | common_reg: |
| 438 | platform_set_drvdata(pdev, s2mps11); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 439 | |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame] | 440 | config.dev = &pdev->dev; |
| 441 | config.regmap = iodev->regmap; |
| 442 | config.driver_data = s2mps11; |
| 443 | for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) { |
| 444 | if (!reg_np) { |
| 445 | config.init_data = pdata->regulators[i].initdata; |
| 446 | } else { |
| 447 | config.init_data = rdata[i].init_data; |
| 448 | config.of_node = rdata[i].of_node; |
| 449 | } |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 450 | |
Axel Lin | ad46ed1 | 2012-07-13 10:12:40 +0800 | [diff] [blame] | 451 | s2mps11->rdev[i] = regulator_register(®ulators[i], &config); |
| 452 | if (IS_ERR(s2mps11->rdev[i])) { |
| 453 | ret = PTR_ERR(s2mps11->rdev[i]); |
Axel Lin | 232b250 | 2012-07-12 09:37:37 +0800 | [diff] [blame] | 454 | dev_err(&pdev->dev, "regulator init failed for %d\n", |
| 455 | i); |
Mark Brown | b707a27 | 2013-08-31 11:57:16 +0100 | [diff] [blame] | 456 | return ret; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
| 460 | return 0; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | static const struct platform_device_id s2mps11_pmic_id[] = { |
| 464 | { "s2mps11-pmic", 0}, |
| 465 | { }, |
| 466 | }; |
| 467 | MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id); |
| 468 | |
| 469 | static struct platform_driver s2mps11_pmic_driver = { |
| 470 | .driver = { |
| 471 | .name = "s2mps11-pmic", |
| 472 | .owner = THIS_MODULE, |
| 473 | }, |
| 474 | .probe = s2mps11_pmic_probe, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 475 | .id_table = s2mps11_pmic_id, |
| 476 | }; |
| 477 | |
| 478 | static int __init s2mps11_pmic_init(void) |
| 479 | { |
| 480 | return platform_driver_register(&s2mps11_pmic_driver); |
| 481 | } |
| 482 | subsys_initcall(s2mps11_pmic_init); |
| 483 | |
| 484 | static void __exit s2mps11_pmic_exit(void) |
| 485 | { |
| 486 | platform_driver_unregister(&s2mps11_pmic_driver); |
| 487 | } |
| 488 | module_exit(s2mps11_pmic_exit); |
| 489 | |
| 490 | /* Module information */ |
| 491 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
| 492 | MODULE_DESCRIPTION("SAMSUNG S2MPS11 Regulator Driver"); |
| 493 | MODULE_LICENSE("GPL"); |