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; |
| 39 | |
| 40 | bool buck6_ramp; |
| 41 | bool buck2_ramp; |
| 42 | bool buck3_ramp; |
| 43 | bool buck4_ramp; |
| 44 | }; |
| 45 | |
| 46 | static int get_ramp_delay(int ramp_delay) |
| 47 | { |
| 48 | unsigned char cnt = 0; |
| 49 | |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 50 | ramp_delay /= 6250; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 51 | |
| 52 | while (true) { |
| 53 | ramp_delay = ramp_delay >> 1; |
| 54 | if (ramp_delay == 0) |
| 55 | break; |
| 56 | cnt++; |
| 57 | } |
| 58 | return cnt; |
| 59 | } |
| 60 | |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 61 | static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
| 62 | unsigned int old_selector, |
| 63 | unsigned int new_selector) |
| 64 | { |
| 65 | struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); |
| 66 | unsigned int ramp_delay = 0; |
| 67 | int old_volt, new_volt; |
| 68 | |
| 69 | switch (rdev->desc->id) { |
| 70 | case S2MPS11_BUCK2: |
| 71 | if (!s2mps11->buck2_ramp) |
| 72 | return 0; |
| 73 | ramp_delay = s2mps11->ramp_delay2; |
| 74 | break; |
| 75 | case S2MPS11_BUCK3: |
| 76 | if (!s2mps11->buck3_ramp) |
| 77 | return 0; |
| 78 | ramp_delay = s2mps11->ramp_delay34; |
| 79 | break; |
| 80 | case S2MPS11_BUCK4: |
| 81 | if (!s2mps11->buck4_ramp) |
| 82 | return 0; |
| 83 | ramp_delay = s2mps11->ramp_delay34; |
| 84 | break; |
| 85 | case S2MPS11_BUCK5: |
| 86 | ramp_delay = s2mps11->ramp_delay5; |
| 87 | break; |
| 88 | case S2MPS11_BUCK6: |
| 89 | if (!s2mps11->buck6_ramp) |
| 90 | return 0; |
| 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 | |
| 119 | switch (rdev->desc->id) { |
| 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 | |
| 208 | if (enable_shift) { |
| 209 | ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, |
| 210 | 1 << enable_shift, 1 << enable_shift); |
| 211 | if (ret) { |
| 212 | dev_err(&rdev->dev, "failed to enable ramp rate\n"); |
| 213 | return ret; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | ramp_val = get_ramp_delay(ramp_delay); |
| 218 | |
| 219 | return regmap_update_bits(rdev->regmap, ramp_reg, |
| 220 | ramp_val << ramp_shift, 1 << ramp_shift); |
| 221 | |
| 222 | ramp_disable: |
| 223 | return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, 0, |
| 224 | 1 << enable_shift); |
| 225 | } |
| 226 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 227 | static struct regulator_ops s2mps11_ldo_ops = { |
| 228 | .list_voltage = regulator_list_voltage_linear, |
| 229 | .map_voltage = regulator_map_voltage_linear, |
| 230 | .is_enabled = regulator_is_enabled_regmap, |
| 231 | .enable = regulator_enable_regmap, |
| 232 | .disable = regulator_disable_regmap, |
| 233 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 234 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 235 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 236 | }; |
| 237 | |
| 238 | static struct regulator_ops s2mps11_buck_ops = { |
| 239 | .list_voltage = regulator_list_voltage_linear, |
| 240 | .map_voltage = regulator_map_voltage_linear, |
| 241 | .is_enabled = regulator_is_enabled_regmap, |
| 242 | .enable = regulator_enable_regmap, |
| 243 | .disable = regulator_disable_regmap, |
| 244 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 245 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Yadwinder Singh Brar | 1e1598e | 2013-06-24 16:50:56 +0530 | [diff] [blame] | 246 | .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel, |
Yadwinder Singh Brar | 939c027 | 2013-06-29 18:21:16 +0530 | [diff] [blame] | 247 | .set_ramp_delay = s2mps11_set_ramp_delay, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | #define regulator_desc_ldo1(num) { \ |
| 251 | .name = "LDO"#num, \ |
| 252 | .id = S2MPS11_LDO##num, \ |
| 253 | .ops = &s2mps11_ldo_ops, \ |
| 254 | .type = REGULATOR_VOLTAGE, \ |
| 255 | .owner = THIS_MODULE, \ |
| 256 | .min_uV = S2MPS11_LDO_MIN, \ |
| 257 | .uV_step = S2MPS11_LDO_STEP1, \ |
| 258 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ |
| 259 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 260 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 261 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
| 262 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 263 | } |
| 264 | #define regulator_desc_ldo2(num) { \ |
| 265 | .name = "LDO"#num, \ |
| 266 | .id = S2MPS11_LDO##num, \ |
| 267 | .ops = &s2mps11_ldo_ops, \ |
| 268 | .type = REGULATOR_VOLTAGE, \ |
| 269 | .owner = THIS_MODULE, \ |
| 270 | .min_uV = S2MPS11_LDO_MIN, \ |
| 271 | .uV_step = S2MPS11_LDO_STEP2, \ |
| 272 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ |
| 273 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 274 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 275 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
| 276 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 277 | } |
| 278 | |
| 279 | #define regulator_desc_buck1_4(num) { \ |
| 280 | .name = "BUCK"#num, \ |
| 281 | .id = S2MPS11_BUCK##num, \ |
| 282 | .ops = &s2mps11_buck_ops, \ |
| 283 | .type = REGULATOR_VOLTAGE, \ |
| 284 | .owner = THIS_MODULE, \ |
| 285 | .min_uV = S2MPS11_BUCK_MIN1, \ |
| 286 | .uV_step = S2MPS11_BUCK_STEP1, \ |
| 287 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 288 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 289 | .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 290 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 291 | .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \ |
| 292 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 293 | } |
| 294 | |
| 295 | #define regulator_desc_buck5 { \ |
| 296 | .name = "BUCK5", \ |
| 297 | .id = S2MPS11_BUCK5, \ |
| 298 | .ops = &s2mps11_buck_ops, \ |
| 299 | .type = REGULATOR_VOLTAGE, \ |
| 300 | .owner = THIS_MODULE, \ |
| 301 | .min_uV = S2MPS11_BUCK_MIN1, \ |
| 302 | .uV_step = S2MPS11_BUCK_STEP1, \ |
| 303 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 304 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 305 | .vsel_reg = S2MPS11_REG_B5CTRL2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 306 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 307 | .enable_reg = S2MPS11_REG_B5CTRL1, \ |
| 308 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 309 | } |
| 310 | |
| 311 | #define regulator_desc_buck6_8(num) { \ |
| 312 | .name = "BUCK"#num, \ |
| 313 | .id = S2MPS11_BUCK##num, \ |
| 314 | .ops = &s2mps11_buck_ops, \ |
| 315 | .type = REGULATOR_VOLTAGE, \ |
| 316 | .owner = THIS_MODULE, \ |
| 317 | .min_uV = S2MPS11_BUCK_MIN1, \ |
| 318 | .uV_step = S2MPS11_BUCK_STEP1, \ |
| 319 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 320 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 321 | .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 322 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 323 | .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \ |
| 324 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 325 | } |
| 326 | |
| 327 | #define regulator_desc_buck9 { \ |
| 328 | .name = "BUCK9", \ |
| 329 | .id = S2MPS11_BUCK9, \ |
| 330 | .ops = &s2mps11_buck_ops, \ |
| 331 | .type = REGULATOR_VOLTAGE, \ |
| 332 | .owner = THIS_MODULE, \ |
| 333 | .min_uV = S2MPS11_BUCK_MIN3, \ |
| 334 | .uV_step = S2MPS11_BUCK_STEP3, \ |
| 335 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 336 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 337 | .vsel_reg = S2MPS11_REG_B9CTRL2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 338 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 339 | .enable_reg = S2MPS11_REG_B9CTRL1, \ |
| 340 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 341 | } |
| 342 | |
| 343 | #define regulator_desc_buck10 { \ |
| 344 | .name = "BUCK10", \ |
| 345 | .id = S2MPS11_BUCK10, \ |
| 346 | .ops = &s2mps11_buck_ops, \ |
| 347 | .type = REGULATOR_VOLTAGE, \ |
| 348 | .owner = THIS_MODULE, \ |
| 349 | .min_uV = S2MPS11_BUCK_MIN2, \ |
| 350 | .uV_step = S2MPS11_BUCK_STEP2, \ |
| 351 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ |
Yadwinder Singh Brar | 9006834 | 2013-06-24 16:50:55 +0530 | [diff] [blame] | 352 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
Alim Akhtar | c76edd5 | 2013-01-30 08:02:27 -0500 | [diff] [blame] | 353 | .vsel_reg = S2MPS11_REG_B10CTRL2, \ |
Axel Lin | 2693fca | 2012-07-12 09:35:50 +0800 | [diff] [blame] | 354 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
Alim Akhtar | c76edd5 | 2013-01-30 08:02:27 -0500 | [diff] [blame] | 355 | .enable_reg = S2MPS11_REG_B10CTRL1, \ |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 356 | .enable_mask = S2MPS11_ENABLE_MASK \ |
| 357 | } |
| 358 | |
| 359 | static struct regulator_desc regulators[] = { |
| 360 | regulator_desc_ldo2(1), |
| 361 | regulator_desc_ldo1(2), |
| 362 | regulator_desc_ldo1(3), |
| 363 | regulator_desc_ldo1(4), |
| 364 | regulator_desc_ldo1(5), |
| 365 | regulator_desc_ldo2(6), |
| 366 | regulator_desc_ldo1(7), |
| 367 | regulator_desc_ldo1(8), |
| 368 | regulator_desc_ldo1(9), |
| 369 | regulator_desc_ldo1(10), |
| 370 | regulator_desc_ldo2(11), |
| 371 | regulator_desc_ldo1(12), |
| 372 | regulator_desc_ldo1(13), |
| 373 | regulator_desc_ldo1(14), |
| 374 | regulator_desc_ldo1(15), |
| 375 | regulator_desc_ldo1(16), |
| 376 | regulator_desc_ldo1(17), |
| 377 | regulator_desc_ldo1(18), |
| 378 | regulator_desc_ldo1(19), |
| 379 | regulator_desc_ldo1(20), |
| 380 | regulator_desc_ldo1(21), |
| 381 | regulator_desc_ldo2(22), |
| 382 | regulator_desc_ldo2(23), |
| 383 | regulator_desc_ldo1(24), |
| 384 | regulator_desc_ldo1(25), |
| 385 | regulator_desc_ldo1(26), |
| 386 | regulator_desc_ldo2(27), |
| 387 | regulator_desc_ldo1(28), |
| 388 | regulator_desc_ldo1(29), |
| 389 | regulator_desc_ldo1(30), |
| 390 | regulator_desc_ldo1(31), |
| 391 | regulator_desc_ldo1(32), |
| 392 | regulator_desc_ldo1(33), |
| 393 | regulator_desc_ldo1(34), |
| 394 | regulator_desc_ldo1(35), |
| 395 | regulator_desc_ldo1(36), |
| 396 | regulator_desc_ldo1(37), |
| 397 | regulator_desc_ldo1(38), |
| 398 | regulator_desc_buck1_4(1), |
| 399 | regulator_desc_buck1_4(2), |
| 400 | regulator_desc_buck1_4(3), |
| 401 | regulator_desc_buck1_4(4), |
| 402 | regulator_desc_buck5, |
| 403 | regulator_desc_buck6_8(6), |
| 404 | regulator_desc_buck6_8(7), |
| 405 | regulator_desc_buck6_8(8), |
| 406 | regulator_desc_buck9, |
| 407 | regulator_desc_buck10, |
| 408 | }; |
| 409 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 410 | static int s2mps11_pmic_probe(struct platform_device *pdev) |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 411 | { |
| 412 | struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
| 413 | struct sec_platform_data *pdata = dev_get_platdata(iodev->dev); |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame^] | 414 | struct of_regulator_match rdata[S2MPS11_REGULATOR_MAX]; |
| 415 | struct device_node *reg_np = NULL; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 416 | struct regulator_config config = { }; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 417 | struct s2mps11_info *s2mps11; |
Axel Lin | ad46ed1 | 2012-07-13 10:12:40 +0800 | [diff] [blame] | 418 | int i, ret; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 419 | unsigned char ramp_enable, ramp_reg = 0; |
| 420 | |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 421 | s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), |
| 422 | GFP_KERNEL); |
| 423 | if (!s2mps11) |
| 424 | return -ENOMEM; |
| 425 | |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame^] | 426 | if (!iodev->dev->of_node) |
| 427 | goto p_data; |
| 428 | |
| 429 | for (i = 0; i < S2MPS11_REGULATOR_CNT; i++) |
| 430 | rdata[i].name = regulators[i].name; |
| 431 | |
| 432 | reg_np = of_find_node_by_name(iodev->dev->of_node, "regulators"); |
| 433 | if (!reg_np) { |
| 434 | dev_err(&pdev->dev, "could not find regulators sub-node\n"); |
| 435 | return -EINVAL; |
| 436 | } |
| 437 | |
| 438 | of_regulator_match(&pdev->dev, reg_np, rdata, S2MPS11_REGULATOR_MAX); |
| 439 | |
| 440 | goto common_reg; |
| 441 | p_data: |
| 442 | if (!pdata) { |
| 443 | dev_err(pdev->dev.parent, "Platform data not supplied\n"); |
| 444 | return -ENODEV; |
| 445 | } |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 446 | |
| 447 | s2mps11->ramp_delay2 = pdata->buck2_ramp_delay; |
| 448 | s2mps11->ramp_delay34 = pdata->buck34_ramp_delay; |
| 449 | s2mps11->ramp_delay5 = pdata->buck5_ramp_delay; |
| 450 | s2mps11->ramp_delay16 = pdata->buck16_ramp_delay; |
| 451 | s2mps11->ramp_delay7810 = pdata->buck7810_ramp_delay; |
| 452 | s2mps11->ramp_delay9 = pdata->buck9_ramp_delay; |
| 453 | |
| 454 | s2mps11->buck6_ramp = pdata->buck6_ramp_enable; |
| 455 | s2mps11->buck2_ramp = pdata->buck2_ramp_enable; |
| 456 | s2mps11->buck3_ramp = pdata->buck3_ramp_enable; |
| 457 | s2mps11->buck4_ramp = pdata->buck4_ramp_enable; |
| 458 | |
| 459 | ramp_enable = (s2mps11->buck2_ramp << 3) | (s2mps11->buck3_ramp << 2) | |
| 460 | (s2mps11->buck4_ramp << 1) | s2mps11->buck6_ramp ; |
| 461 | |
| 462 | if (ramp_enable) { |
| 463 | if (s2mps11->buck2_ramp) |
Sangbeom Kim | f7ebaae | 2012-11-24 11:13:28 +0900 | [diff] [blame] | 464 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay2) << 6; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 465 | if (s2mps11->buck3_ramp || s2mps11->buck4_ramp) |
Sangbeom Kim | f7ebaae | 2012-11-24 11:13:28 +0900 | [diff] [blame] | 466 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay34) << 4; |
Axel Lin | c06eed3 | 2012-07-12 09:39:10 +0800 | [diff] [blame] | 467 | sec_reg_write(iodev, S2MPS11_REG_RAMP, ramp_reg | ramp_enable); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | ramp_reg &= 0x00; |
Sangbeom Kim | f7ebaae | 2012-11-24 11:13:28 +0900 | [diff] [blame] | 471 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay5) << 6; |
| 472 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay16) << 4; |
| 473 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay7810) << 2; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 474 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay9); |
Axel Lin | c06eed3 | 2012-07-12 09:39:10 +0800 | [diff] [blame] | 475 | sec_reg_write(iodev, S2MPS11_REG_RAMP_BUCK, ramp_reg); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 476 | |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame^] | 477 | common_reg: |
| 478 | platform_set_drvdata(pdev, s2mps11); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 479 | |
Yadwinder Singh Brar | a50c6b3 | 2013-06-29 18:21:17 +0530 | [diff] [blame^] | 480 | config.dev = &pdev->dev; |
| 481 | config.regmap = iodev->regmap; |
| 482 | config.driver_data = s2mps11; |
| 483 | for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) { |
| 484 | if (!reg_np) { |
| 485 | config.init_data = pdata->regulators[i].initdata; |
| 486 | } else { |
| 487 | config.init_data = rdata[i].init_data; |
| 488 | config.of_node = rdata[i].of_node; |
| 489 | } |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 490 | |
Axel Lin | ad46ed1 | 2012-07-13 10:12:40 +0800 | [diff] [blame] | 491 | s2mps11->rdev[i] = regulator_register(®ulators[i], &config); |
| 492 | if (IS_ERR(s2mps11->rdev[i])) { |
| 493 | ret = PTR_ERR(s2mps11->rdev[i]); |
Axel Lin | 232b250 | 2012-07-12 09:37:37 +0800 | [diff] [blame] | 494 | dev_err(&pdev->dev, "regulator init failed for %d\n", |
| 495 | i); |
Axel Lin | ad46ed1 | 2012-07-13 10:12:40 +0800 | [diff] [blame] | 496 | s2mps11->rdev[i] = NULL; |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 497 | goto err; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | return 0; |
| 502 | err: |
| 503 | for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) |
Axel Lin | ad46ed1 | 2012-07-13 10:12:40 +0800 | [diff] [blame] | 504 | regulator_unregister(s2mps11->rdev[i]); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 505 | |
| 506 | return ret; |
| 507 | } |
| 508 | |
Bill Pemberton | 8dc995f | 2012-11-19 13:26:10 -0500 | [diff] [blame] | 509 | static int s2mps11_pmic_remove(struct platform_device *pdev) |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 510 | { |
| 511 | struct s2mps11_info *s2mps11 = platform_get_drvdata(pdev); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 512 | int i; |
| 513 | |
| 514 | for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) |
Axel Lin | ad46ed1 | 2012-07-13 10:12:40 +0800 | [diff] [blame] | 515 | regulator_unregister(s2mps11->rdev[i]); |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | static const struct platform_device_id s2mps11_pmic_id[] = { |
| 521 | { "s2mps11-pmic", 0}, |
| 522 | { }, |
| 523 | }; |
| 524 | MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id); |
| 525 | |
| 526 | static struct platform_driver s2mps11_pmic_driver = { |
| 527 | .driver = { |
| 528 | .name = "s2mps11-pmic", |
| 529 | .owner = THIS_MODULE, |
| 530 | }, |
| 531 | .probe = s2mps11_pmic_probe, |
Bill Pemberton | 5eb9f2b | 2012-11-19 13:20:42 -0500 | [diff] [blame] | 532 | .remove = s2mps11_pmic_remove, |
Sangbeom Kim | cb74685 | 2012-07-11 21:08:17 +0900 | [diff] [blame] | 533 | .id_table = s2mps11_pmic_id, |
| 534 | }; |
| 535 | |
| 536 | static int __init s2mps11_pmic_init(void) |
| 537 | { |
| 538 | return platform_driver_register(&s2mps11_pmic_driver); |
| 539 | } |
| 540 | subsys_initcall(s2mps11_pmic_init); |
| 541 | |
| 542 | static void __exit s2mps11_pmic_exit(void) |
| 543 | { |
| 544 | platform_driver_unregister(&s2mps11_pmic_driver); |
| 545 | } |
| 546 | module_exit(s2mps11_pmic_exit); |
| 547 | |
| 548 | /* Module information */ |
| 549 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
| 550 | MODULE_DESCRIPTION("SAMSUNG S2MPS11 Regulator Driver"); |
| 551 | MODULE_LICENSE("GPL"); |