Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 1 | /* |
| 2 | * s5m8767.c |
| 3 | * |
| 4 | * Copyright (c) 2011 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> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/gpio.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/regulator/driver.h> |
| 22 | #include <linux/regulator/machine.h> |
| 23 | #include <linux/mfd/s5m87xx/s5m-core.h> |
| 24 | #include <linux/mfd/s5m87xx/s5m-pmic.h> |
| 25 | |
| 26 | struct s5m8767_info { |
| 27 | struct device *dev; |
| 28 | struct s5m87xx_dev *iodev; |
| 29 | int num_regulators; |
| 30 | struct regulator_dev **rdev; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 31 | struct s5m_opmode_data *opmode; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 32 | |
| 33 | int ramp_delay; |
| 34 | bool buck2_ramp; |
| 35 | bool buck3_ramp; |
| 36 | bool buck4_ramp; |
| 37 | |
| 38 | bool buck2_gpiodvs; |
| 39 | bool buck3_gpiodvs; |
| 40 | bool buck4_gpiodvs; |
| 41 | u8 buck2_vol[8]; |
| 42 | u8 buck3_vol[8]; |
| 43 | u8 buck4_vol[8]; |
| 44 | int buck_gpios[3]; |
| 45 | int buck_gpioindex; |
| 46 | }; |
| 47 | |
| 48 | struct s5m_voltage_desc { |
| 49 | int max; |
| 50 | int min; |
| 51 | int step; |
| 52 | }; |
| 53 | |
| 54 | static const struct s5m_voltage_desc buck_voltage_val1 = { |
| 55 | .max = 2225000, |
| 56 | .min = 650000, |
| 57 | .step = 6250, |
| 58 | }; |
| 59 | |
| 60 | static const struct s5m_voltage_desc buck_voltage_val2 = { |
| 61 | .max = 1600000, |
| 62 | .min = 600000, |
| 63 | .step = 6250, |
| 64 | }; |
| 65 | |
| 66 | static const struct s5m_voltage_desc buck_voltage_val3 = { |
| 67 | .max = 3000000, |
| 68 | .min = 750000, |
| 69 | .step = 12500, |
| 70 | }; |
| 71 | |
| 72 | static const struct s5m_voltage_desc ldo_voltage_val1 = { |
| 73 | .max = 3950000, |
| 74 | .min = 800000, |
| 75 | .step = 50000, |
| 76 | }; |
| 77 | |
| 78 | static const struct s5m_voltage_desc ldo_voltage_val2 = { |
| 79 | .max = 2375000, |
| 80 | .min = 800000, |
| 81 | .step = 25000, |
| 82 | }; |
| 83 | |
| 84 | static const struct s5m_voltage_desc *reg_voltage_map[] = { |
| 85 | [S5M8767_LDO1] = &ldo_voltage_val2, |
| 86 | [S5M8767_LDO2] = &ldo_voltage_val2, |
| 87 | [S5M8767_LDO3] = &ldo_voltage_val1, |
| 88 | [S5M8767_LDO4] = &ldo_voltage_val1, |
| 89 | [S5M8767_LDO5] = &ldo_voltage_val1, |
| 90 | [S5M8767_LDO6] = &ldo_voltage_val2, |
| 91 | [S5M8767_LDO7] = &ldo_voltage_val2, |
| 92 | [S5M8767_LDO8] = &ldo_voltage_val2, |
| 93 | [S5M8767_LDO9] = &ldo_voltage_val1, |
| 94 | [S5M8767_LDO10] = &ldo_voltage_val1, |
| 95 | [S5M8767_LDO11] = &ldo_voltage_val1, |
| 96 | [S5M8767_LDO12] = &ldo_voltage_val1, |
| 97 | [S5M8767_LDO13] = &ldo_voltage_val1, |
| 98 | [S5M8767_LDO14] = &ldo_voltage_val1, |
| 99 | [S5M8767_LDO15] = &ldo_voltage_val2, |
| 100 | [S5M8767_LDO16] = &ldo_voltage_val1, |
| 101 | [S5M8767_LDO17] = &ldo_voltage_val1, |
| 102 | [S5M8767_LDO18] = &ldo_voltage_val1, |
| 103 | [S5M8767_LDO19] = &ldo_voltage_val1, |
| 104 | [S5M8767_LDO20] = &ldo_voltage_val1, |
| 105 | [S5M8767_LDO21] = &ldo_voltage_val1, |
| 106 | [S5M8767_LDO22] = &ldo_voltage_val1, |
| 107 | [S5M8767_LDO23] = &ldo_voltage_val1, |
| 108 | [S5M8767_LDO24] = &ldo_voltage_val1, |
| 109 | [S5M8767_LDO25] = &ldo_voltage_val1, |
| 110 | [S5M8767_LDO26] = &ldo_voltage_val1, |
| 111 | [S5M8767_LDO27] = &ldo_voltage_val1, |
| 112 | [S5M8767_LDO28] = &ldo_voltage_val1, |
| 113 | [S5M8767_BUCK1] = &buck_voltage_val1, |
| 114 | [S5M8767_BUCK2] = &buck_voltage_val2, |
| 115 | [S5M8767_BUCK3] = &buck_voltage_val2, |
| 116 | [S5M8767_BUCK4] = &buck_voltage_val2, |
| 117 | [S5M8767_BUCK5] = &buck_voltage_val1, |
| 118 | [S5M8767_BUCK6] = &buck_voltage_val1, |
| 119 | [S5M8767_BUCK7] = NULL, |
| 120 | [S5M8767_BUCK8] = NULL, |
| 121 | [S5M8767_BUCK9] = &buck_voltage_val3, |
| 122 | }; |
| 123 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 124 | static int s5m8767_list_voltage(struct regulator_dev *rdev, |
| 125 | unsigned int selector) |
| 126 | { |
| 127 | const struct s5m_voltage_desc *desc; |
Axel Lin | 20a14b8 | 2012-01-31 15:13:31 +0800 | [diff] [blame] | 128 | int reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 129 | int val; |
| 130 | |
| 131 | if (reg_id >= ARRAY_SIZE(reg_voltage_map) || reg_id < 0) |
| 132 | return -EINVAL; |
| 133 | |
| 134 | desc = reg_voltage_map[reg_id]; |
| 135 | if (desc == NULL) |
| 136 | return -EINVAL; |
| 137 | |
| 138 | val = desc->min + desc->step * selector; |
| 139 | if (val > desc->max) |
| 140 | return -EINVAL; |
| 141 | |
| 142 | return val; |
| 143 | } |
| 144 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 145 | unsigned int s5m8767_opmode_reg[][4] = { |
| 146 | /* {OFF, ON, LOWPOWER, SUSPEND} */ |
| 147 | /* LDO1 ... LDO28 */ |
| 148 | {0x0, 0x3, 0x2, 0x1}, /* LDO1 */ |
| 149 | {0x0, 0x3, 0x2, 0x1}, |
| 150 | {0x0, 0x3, 0x2, 0x1}, |
| 151 | {0x0, 0x0, 0x0, 0x0}, |
| 152 | {0x0, 0x3, 0x2, 0x1}, /* LDO5 */ |
| 153 | {0x0, 0x3, 0x2, 0x1}, |
| 154 | {0x0, 0x3, 0x2, 0x1}, |
| 155 | {0x0, 0x3, 0x2, 0x1}, |
| 156 | {0x0, 0x3, 0x2, 0x1}, |
| 157 | {0x0, 0x3, 0x2, 0x1}, /* LDO10 */ |
| 158 | {0x0, 0x3, 0x2, 0x1}, |
| 159 | {0x0, 0x3, 0x2, 0x1}, |
| 160 | {0x0, 0x3, 0x2, 0x1}, |
| 161 | {0x0, 0x3, 0x2, 0x1}, |
| 162 | {0x0, 0x3, 0x2, 0x1}, /* LDO15 */ |
| 163 | {0x0, 0x3, 0x2, 0x1}, |
| 164 | {0x0, 0x3, 0x2, 0x1}, |
| 165 | {0x0, 0x0, 0x0, 0x0}, |
| 166 | {0x0, 0x3, 0x2, 0x1}, |
| 167 | {0x0, 0x3, 0x2, 0x1}, /* LDO20 */ |
| 168 | {0x0, 0x3, 0x2, 0x1}, |
| 169 | {0x0, 0x3, 0x2, 0x1}, |
| 170 | {0x0, 0x0, 0x0, 0x0}, |
| 171 | {0x0, 0x3, 0x2, 0x1}, |
| 172 | {0x0, 0x3, 0x2, 0x1}, /* LDO25 */ |
| 173 | {0x0, 0x3, 0x2, 0x1}, |
| 174 | {0x0, 0x3, 0x2, 0x1}, |
| 175 | {0x0, 0x3, 0x2, 0x1}, /* LDO28 */ |
| 176 | |
| 177 | /* BUCK1 ... BUCK9 */ |
| 178 | {0x0, 0x3, 0x1, 0x1}, /* BUCK1 */ |
| 179 | {0x0, 0x3, 0x1, 0x1}, |
| 180 | {0x0, 0x3, 0x1, 0x1}, |
| 181 | {0x0, 0x3, 0x1, 0x1}, |
| 182 | {0x0, 0x3, 0x2, 0x1}, /* BUCK5 */ |
| 183 | {0x0, 0x3, 0x1, 0x1}, |
| 184 | {0x0, 0x3, 0x1, 0x1}, |
| 185 | {0x0, 0x3, 0x1, 0x1}, |
| 186 | {0x0, 0x3, 0x1, 0x1}, /* BUCK9 */ |
| 187 | }; |
| 188 | |
| 189 | static int s5m8767_get_register(struct regulator_dev *rdev, int *reg, |
| 190 | int *enable_ctrl) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 191 | { |
Axel Lin | 20a14b8 | 2012-01-31 15:13:31 +0800 | [diff] [blame] | 192 | int reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 193 | unsigned int mode; |
| 194 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 195 | |
| 196 | switch (reg_id) { |
| 197 | case S5M8767_LDO1 ... S5M8767_LDO2: |
| 198 | *reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1); |
| 199 | break; |
| 200 | case S5M8767_LDO3 ... S5M8767_LDO28: |
| 201 | *reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3); |
| 202 | break; |
| 203 | case S5M8767_BUCK1: |
| 204 | *reg = S5M8767_REG_BUCK1CTRL1; |
| 205 | break; |
| 206 | case S5M8767_BUCK2 ... S5M8767_BUCK4: |
| 207 | *reg = S5M8767_REG_BUCK2CTRL + (reg_id - S5M8767_BUCK2) * 9; |
| 208 | break; |
| 209 | case S5M8767_BUCK5: |
| 210 | *reg = S5M8767_REG_BUCK5CTRL1; |
| 211 | break; |
| 212 | case S5M8767_BUCK6 ... S5M8767_BUCK9: |
| 213 | *reg = S5M8767_REG_BUCK6CTRL1 + (reg_id - S5M8767_BUCK6) * 2; |
| 214 | break; |
| 215 | default: |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 219 | mode = s5m8767->opmode[reg_id].mode; |
| 220 | *enable_ctrl = s5m8767_opmode_reg[reg_id][mode] << S5M8767_ENCTRL_SHIFT; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | static int s5m8767_reg_is_enabled(struct regulator_dev *rdev) |
| 225 | { |
| 226 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 227 | int ret, reg; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 228 | int mask = 0xc0, enable_ctrl; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 229 | u8 val; |
| 230 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 231 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 232 | if (ret == -EINVAL) |
| 233 | return 1; |
| 234 | else if (ret) |
| 235 | return ret; |
| 236 | |
| 237 | ret = s5m_reg_read(s5m8767->iodev, reg, &val); |
| 238 | if (ret) |
| 239 | return ret; |
| 240 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 241 | return (val & mask) == enable_ctrl; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | static int s5m8767_reg_enable(struct regulator_dev *rdev) |
| 245 | { |
| 246 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 247 | int ret, reg; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 248 | int mask = 0xc0, enable_ctrl; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 249 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 250 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 251 | if (ret) |
| 252 | return ret; |
| 253 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 254 | return s5m_reg_update(s5m8767->iodev, reg, enable_ctrl, mask); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | static int s5m8767_reg_disable(struct regulator_dev *rdev) |
| 258 | { |
| 259 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 260 | int ret, reg; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 261 | int mask = 0xc0, enable_ctrl; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 262 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 263 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 264 | if (ret) |
| 265 | return ret; |
| 266 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 267 | return s5m_reg_update(s5m8767->iodev, reg, ~mask, mask); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg) |
| 271 | { |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 272 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Axel Lin | 20a14b8 | 2012-01-31 15:13:31 +0800 | [diff] [blame] | 273 | int reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 274 | int reg; |
| 275 | |
| 276 | switch (reg_id) { |
| 277 | case S5M8767_LDO1 ... S5M8767_LDO2: |
| 278 | reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1); |
| 279 | break; |
| 280 | case S5M8767_LDO3 ... S5M8767_LDO28: |
| 281 | reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3); |
| 282 | break; |
| 283 | case S5M8767_BUCK1: |
| 284 | reg = S5M8767_REG_BUCK1CTRL2; |
| 285 | break; |
| 286 | case S5M8767_BUCK2: |
| 287 | reg = S5M8767_REG_BUCK2DVS1; |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 288 | if (s5m8767->buck2_gpiodvs) |
| 289 | reg += s5m8767->buck_gpioindex; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 290 | break; |
| 291 | case S5M8767_BUCK3: |
| 292 | reg = S5M8767_REG_BUCK3DVS1; |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 293 | if (s5m8767->buck3_gpiodvs) |
| 294 | reg += s5m8767->buck_gpioindex; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 295 | break; |
| 296 | case S5M8767_BUCK4: |
| 297 | reg = S5M8767_REG_BUCK4DVS1; |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 298 | if (s5m8767->buck4_gpiodvs) |
| 299 | reg += s5m8767->buck_gpioindex; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 300 | break; |
| 301 | case S5M8767_BUCK5: |
| 302 | reg = S5M8767_REG_BUCK5CTRL2; |
| 303 | break; |
| 304 | case S5M8767_BUCK6 ... S5M8767_BUCK9: |
| 305 | reg = S5M8767_REG_BUCK6CTRL2 + (reg_id - S5M8767_BUCK6) * 2; |
| 306 | break; |
| 307 | default: |
| 308 | return -EINVAL; |
| 309 | } |
| 310 | |
| 311 | *_reg = reg; |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int s5m8767_get_voltage_sel(struct regulator_dev *rdev) |
| 317 | { |
| 318 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 319 | int reg, mask, ret; |
Axel Lin | 20a14b8 | 2012-01-31 15:13:31 +0800 | [diff] [blame] | 320 | int reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 321 | u8 val; |
| 322 | |
| 323 | ret = s5m8767_get_voltage_register(rdev, ®); |
| 324 | if (ret) |
| 325 | return ret; |
| 326 | |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 327 | mask = (reg_id < S5M8767_BUCK1) ? 0x3f : 0xff; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 328 | |
| 329 | ret = s5m_reg_read(s5m8767->iodev, reg, &val); |
| 330 | if (ret) |
| 331 | return ret; |
| 332 | |
| 333 | val &= mask; |
| 334 | |
| 335 | return val; |
| 336 | } |
| 337 | |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 338 | static int s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 339 | const struct s5m_voltage_desc *desc, |
| 340 | int min_vol, int max_vol) |
| 341 | { |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 342 | int selector = 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 343 | |
| 344 | if (desc == NULL) |
| 345 | return -EINVAL; |
| 346 | |
| 347 | if (max_vol < desc->min || min_vol > desc->max) |
| 348 | return -EINVAL; |
| 349 | |
Axel Lin | 94e85a3 | 2012-04-13 09:30:05 +0800 | [diff] [blame^] | 350 | if (min_vol < desc->min) |
| 351 | min_vol = desc->min; |
| 352 | |
| 353 | selector = DIV_ROUND_UP(min_vol - desc->min, desc->step); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 354 | |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 355 | if (desc->min + desc->step * selector > max_vol) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 356 | return -EINVAL; |
| 357 | |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 358 | return selector; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 359 | } |
| 360 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 361 | static inline void s5m8767_set_high(struct s5m8767_info *s5m8767) |
| 362 | { |
| 363 | int temp_index = s5m8767->buck_gpioindex; |
| 364 | |
| 365 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); |
| 366 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); |
| 367 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); |
| 368 | } |
| 369 | |
| 370 | static inline void s5m8767_set_low(struct s5m8767_info *s5m8767) |
| 371 | { |
| 372 | int temp_index = s5m8767->buck_gpioindex; |
| 373 | |
| 374 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); |
| 375 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); |
| 376 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); |
| 377 | } |
| 378 | |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 379 | static int s5m8767_set_voltage(struct regulator_dev *rdev, |
| 380 | int min_uV, int max_uV, unsigned *selector) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 381 | { |
| 382 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 383 | const struct s5m_voltage_desc *desc; |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 384 | int reg_id = rdev_get_id(rdev); |
| 385 | int sel, reg, mask, ret = 0, old_index, index = 0; |
| 386 | u8 val; |
| 387 | u8 *buck234_vol = NULL; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 388 | |
| 389 | switch (reg_id) { |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 390 | case S5M8767_LDO1 ... S5M8767_LDO28: |
| 391 | mask = 0x3f; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 392 | break; |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 393 | case S5M8767_BUCK1 ... S5M8767_BUCK6: |
| 394 | mask = 0xff; |
| 395 | if (reg_id == S5M8767_BUCK2 && s5m8767->buck2_gpiodvs) |
| 396 | buck234_vol = &s5m8767->buck2_vol[0]; |
| 397 | else if (reg_id == S5M8767_BUCK3 && s5m8767->buck3_gpiodvs) |
| 398 | buck234_vol = &s5m8767->buck3_vol[0]; |
| 399 | else if (reg_id == S5M8767_BUCK4 && s5m8767->buck4_gpiodvs) |
| 400 | buck234_vol = &s5m8767->buck4_vol[0]; |
| 401 | break; |
| 402 | case S5M8767_BUCK7 ... S5M8767_BUCK8: |
| 403 | return -EINVAL; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 404 | case S5M8767_BUCK9: |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 405 | mask = 0xff; |
| 406 | break; |
| 407 | default: |
| 408 | return -EINVAL; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | desc = reg_voltage_map[reg_id]; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 412 | |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 413 | sel = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV); |
| 414 | if (sel < 0) |
| 415 | return sel; |
| 416 | |
| 417 | /* buck234_vol != NULL means to control buck234 voltage via DVS GPIO */ |
| 418 | if (buck234_vol) { |
| 419 | while (*buck234_vol != sel) { |
| 420 | buck234_vol++; |
| 421 | index++; |
| 422 | } |
| 423 | old_index = s5m8767->buck_gpioindex; |
| 424 | s5m8767->buck_gpioindex = index; |
| 425 | |
| 426 | if (index > old_index) |
| 427 | s5m8767_set_high(s5m8767); |
| 428 | else |
| 429 | s5m8767_set_low(s5m8767); |
| 430 | } else { |
| 431 | ret = s5m8767_get_voltage_register(rdev, ®); |
| 432 | if (ret) |
| 433 | return ret; |
| 434 | |
| 435 | s5m_reg_read(s5m8767->iodev, reg, &val); |
| 436 | val = (val & ~mask) | sel; |
| 437 | |
| 438 | ret = s5m_reg_write(s5m8767->iodev, reg, val); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 439 | } |
| 440 | |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 441 | *selector = sel; |
| 442 | return ret; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, |
| 446 | unsigned int old_sel, |
| 447 | unsigned int new_sel) |
| 448 | { |
| 449 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 450 | const struct s5m_voltage_desc *desc; |
Axel Lin | 20a14b8 | 2012-01-31 15:13:31 +0800 | [diff] [blame] | 451 | int reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 452 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 453 | desc = reg_voltage_map[reg_id]; |
| 454 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 455 | if (old_sel < new_sel) |
Axel Lin | 89e0f0e | 2012-02-24 14:52:45 +0800 | [diff] [blame] | 456 | return DIV_ROUND_UP(desc->step * (new_sel - old_sel), |
Sangbeom Kim | 0f8b9c7 | 2012-03-09 16:28:10 +0900 | [diff] [blame] | 457 | s5m8767->ramp_delay * 1000); |
Axel Lin | 89e0f0e | 2012-02-24 14:52:45 +0800 | [diff] [blame] | 458 | return 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 459 | } |
| 460 | |
Axel Lin | d35aad0 | 2012-04-10 14:07:15 +0800 | [diff] [blame] | 461 | static struct regulator_ops s5m8767_ops = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 462 | .list_voltage = s5m8767_list_voltage, |
| 463 | .is_enabled = s5m8767_reg_is_enabled, |
| 464 | .enable = s5m8767_reg_enable, |
| 465 | .disable = s5m8767_reg_disable, |
| 466 | .get_voltage_sel = s5m8767_get_voltage_sel, |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 467 | .set_voltage = s5m8767_set_voltage, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 468 | .set_voltage_time_sel = s5m8767_set_voltage_time_sel, |
| 469 | }; |
| 470 | |
Axel Lin | 65896e7 | 2012-04-10 14:08:19 +0800 | [diff] [blame] | 471 | #define s5m8767_regulator_desc(_name) { \ |
| 472 | .name = #_name, \ |
| 473 | .id = S5M8767_##_name, \ |
| 474 | .ops = &s5m8767_ops, \ |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 475 | .type = REGULATOR_VOLTAGE, \ |
| 476 | .owner = THIS_MODULE, \ |
| 477 | } |
| 478 | |
| 479 | static struct regulator_desc regulators[] = { |
Axel Lin | 65896e7 | 2012-04-10 14:08:19 +0800 | [diff] [blame] | 480 | s5m8767_regulator_desc(LDO1), |
| 481 | s5m8767_regulator_desc(LDO2), |
| 482 | s5m8767_regulator_desc(LDO3), |
| 483 | s5m8767_regulator_desc(LDO4), |
| 484 | s5m8767_regulator_desc(LDO5), |
| 485 | s5m8767_regulator_desc(LDO6), |
| 486 | s5m8767_regulator_desc(LDO7), |
| 487 | s5m8767_regulator_desc(LDO8), |
| 488 | s5m8767_regulator_desc(LDO9), |
| 489 | s5m8767_regulator_desc(LDO10), |
| 490 | s5m8767_regulator_desc(LDO11), |
| 491 | s5m8767_regulator_desc(LDO12), |
| 492 | s5m8767_regulator_desc(LDO13), |
| 493 | s5m8767_regulator_desc(LDO14), |
| 494 | s5m8767_regulator_desc(LDO15), |
| 495 | s5m8767_regulator_desc(LDO16), |
| 496 | s5m8767_regulator_desc(LDO17), |
| 497 | s5m8767_regulator_desc(LDO18), |
| 498 | s5m8767_regulator_desc(LDO19), |
| 499 | s5m8767_regulator_desc(LDO20), |
| 500 | s5m8767_regulator_desc(LDO21), |
| 501 | s5m8767_regulator_desc(LDO22), |
| 502 | s5m8767_regulator_desc(LDO23), |
| 503 | s5m8767_regulator_desc(LDO24), |
| 504 | s5m8767_regulator_desc(LDO25), |
| 505 | s5m8767_regulator_desc(LDO26), |
| 506 | s5m8767_regulator_desc(LDO27), |
| 507 | s5m8767_regulator_desc(LDO28), |
| 508 | s5m8767_regulator_desc(BUCK1), |
| 509 | s5m8767_regulator_desc(BUCK2), |
| 510 | s5m8767_regulator_desc(BUCK3), |
| 511 | s5m8767_regulator_desc(BUCK4), |
| 512 | s5m8767_regulator_desc(BUCK5), |
| 513 | s5m8767_regulator_desc(BUCK6), |
| 514 | s5m8767_regulator_desc(BUCK7), |
| 515 | s5m8767_regulator_desc(BUCK8), |
| 516 | s5m8767_regulator_desc(BUCK9), |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 517 | }; |
| 518 | |
| 519 | static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) |
| 520 | { |
| 521 | struct s5m87xx_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
| 522 | struct s5m_platform_data *pdata = dev_get_platdata(iodev->dev); |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 523 | struct regulator_config config = { }; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 524 | struct regulator_dev **rdev; |
| 525 | struct s5m8767_info *s5m8767; |
Mark Brown | 22cd2fef | 2012-02-06 11:34:36 +0000 | [diff] [blame] | 526 | int i, ret, size; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 527 | |
| 528 | if (!pdata) { |
| 529 | dev_err(pdev->dev.parent, "Platform data not supplied\n"); |
| 530 | return -ENODEV; |
| 531 | } |
| 532 | |
Axel Lin | 6c4efe2 | 2012-03-10 08:43:02 +0800 | [diff] [blame] | 533 | if (pdata->buck2_gpiodvs) { |
| 534 | if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) { |
| 535 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 536 | return -EINVAL; |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | if (pdata->buck3_gpiodvs) { |
| 541 | if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) { |
| 542 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 543 | return -EINVAL; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | if (pdata->buck4_gpiodvs) { |
| 548 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) { |
| 549 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 550 | return -EINVAL; |
| 551 | } |
| 552 | } |
| 553 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 554 | s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info), |
| 555 | GFP_KERNEL); |
| 556 | if (!s5m8767) |
| 557 | return -ENOMEM; |
| 558 | |
| 559 | size = sizeof(struct regulator_dev *) * (S5M8767_REG_MAX - 2); |
| 560 | s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
| 561 | if (!s5m8767->rdev) |
| 562 | return -ENOMEM; |
| 563 | |
| 564 | rdev = s5m8767->rdev; |
| 565 | s5m8767->dev = &pdev->dev; |
| 566 | s5m8767->iodev = iodev; |
| 567 | s5m8767->num_regulators = S5M8767_REG_MAX - 2; |
| 568 | platform_set_drvdata(pdev, s5m8767); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 569 | |
| 570 | s5m8767->buck_gpioindex = pdata->buck_default_idx; |
| 571 | s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs; |
| 572 | s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs; |
| 573 | s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs; |
| 574 | s5m8767->buck_gpios[0] = pdata->buck_gpios[0]; |
| 575 | s5m8767->buck_gpios[1] = pdata->buck_gpios[1]; |
| 576 | s5m8767->buck_gpios[2] = pdata->buck_gpios[2]; |
| 577 | s5m8767->ramp_delay = pdata->buck_ramp_delay; |
| 578 | s5m8767->buck2_ramp = pdata->buck2_ramp_enable; |
| 579 | s5m8767->buck3_ramp = pdata->buck3_ramp_enable; |
| 580 | s5m8767->buck4_ramp = pdata->buck4_ramp_enable; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 581 | s5m8767->opmode = pdata->opmode; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 582 | |
| 583 | for (i = 0; i < 8; i++) { |
| 584 | if (s5m8767->buck2_gpiodvs) { |
| 585 | s5m8767->buck2_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 586 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 587 | &buck_voltage_val2, |
| 588 | pdata->buck2_voltage[i], |
| 589 | pdata->buck2_voltage[i] + |
| 590 | buck_voltage_val2.step); |
| 591 | } |
| 592 | |
| 593 | if (s5m8767->buck3_gpiodvs) { |
| 594 | s5m8767->buck3_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 595 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 596 | &buck_voltage_val2, |
| 597 | pdata->buck3_voltage[i], |
| 598 | pdata->buck3_voltage[i] + |
| 599 | buck_voltage_val2.step); |
| 600 | } |
| 601 | |
| 602 | if (s5m8767->buck4_gpiodvs) { |
| 603 | s5m8767->buck4_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 604 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 605 | &buck_voltage_val2, |
| 606 | pdata->buck4_voltage[i], |
| 607 | pdata->buck4_voltage[i] + |
| 608 | buck_voltage_val2.step); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || |
| 613 | pdata->buck4_gpiodvs) { |
| 614 | if (gpio_is_valid(pdata->buck_gpios[0]) && |
| 615 | gpio_is_valid(pdata->buck_gpios[1]) && |
| 616 | gpio_is_valid(pdata->buck_gpios[2])) { |
| 617 | ret = gpio_request(pdata->buck_gpios[0], |
| 618 | "S5M8767 SET1"); |
| 619 | if (ret == -EBUSY) |
| 620 | dev_warn(&pdev->dev, "Duplicated gpio request for SET1\n"); |
| 621 | |
| 622 | ret = gpio_request(pdata->buck_gpios[1], |
| 623 | "S5M8767 SET2"); |
| 624 | if (ret == -EBUSY) |
| 625 | dev_warn(&pdev->dev, "Duplicated gpio request for SET2\n"); |
| 626 | |
| 627 | ret = gpio_request(pdata->buck_gpios[2], |
| 628 | "S5M8767 SET3"); |
| 629 | if (ret == -EBUSY) |
| 630 | dev_warn(&pdev->dev, "Duplicated gpio request for SET3\n"); |
| 631 | /* SET1 GPIO */ |
| 632 | gpio_direction_output(pdata->buck_gpios[0], |
| 633 | (s5m8767->buck_gpioindex >> 2) & 0x1); |
| 634 | /* SET2 GPIO */ |
| 635 | gpio_direction_output(pdata->buck_gpios[1], |
| 636 | (s5m8767->buck_gpioindex >> 1) & 0x1); |
| 637 | /* SET3 GPIO */ |
| 638 | gpio_direction_output(pdata->buck_gpios[2], |
| 639 | (s5m8767->buck_gpioindex >> 0) & 0x1); |
| 640 | ret = 0; |
| 641 | } else { |
| 642 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); |
| 643 | ret = -EINVAL; |
| 644 | return ret; |
| 645 | } |
| 646 | } |
| 647 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 648 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, |
| 649 | (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); |
| 650 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, |
| 651 | (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); |
| 652 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, |
| 653 | (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); |
| 654 | |
| 655 | /* Initialize GPIO DVS registers */ |
| 656 | for (i = 0; i < 8; i++) { |
| 657 | if (s5m8767->buck2_gpiodvs) { |
| 658 | s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS1 + i, |
| 659 | s5m8767->buck2_vol[i]); |
| 660 | } |
| 661 | |
| 662 | if (s5m8767->buck3_gpiodvs) { |
| 663 | s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS1 + i, |
| 664 | s5m8767->buck3_vol[i]); |
| 665 | } |
| 666 | |
| 667 | if (s5m8767->buck4_gpiodvs) { |
| 668 | s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS1 + i, |
| 669 | s5m8767->buck4_vol[i]); |
| 670 | } |
| 671 | } |
| 672 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 0x78, 0xff); |
| 673 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 0x58, 0xff); |
| 674 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 0x78, 0xff); |
| 675 | |
| 676 | if (s5m8767->buck2_ramp) |
| 677 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08); |
| 678 | |
| 679 | if (s5m8767->buck3_ramp) |
| 680 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x04, 0x04); |
| 681 | |
| 682 | if (s5m8767->buck4_ramp) |
| 683 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x02, 0x02); |
| 684 | |
| 685 | if (s5m8767->buck2_ramp || s5m8767->buck3_ramp |
| 686 | || s5m8767->buck4_ramp) { |
| 687 | switch (s5m8767->ramp_delay) { |
| 688 | case 15: |
| 689 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
| 690 | 0xc0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 691 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 692 | case 25: |
| 693 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
| 694 | 0xd0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 695 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 696 | case 50: |
| 697 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
| 698 | 0xe0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 699 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 700 | case 100: |
| 701 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
| 702 | 0xf0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 703 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 704 | default: |
| 705 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
| 706 | 0x90, 0xf0); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | for (i = 0; i < pdata->num_regulators; i++) { |
| 711 | const struct s5m_voltage_desc *desc; |
| 712 | int id = pdata->regulators[i].id; |
| 713 | |
| 714 | desc = reg_voltage_map[id]; |
| 715 | if (desc) |
| 716 | regulators[id].n_voltages = |
| 717 | (desc->max - desc->min) / desc->step + 1; |
| 718 | |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 719 | config.dev = s5m8767->dev; |
| 720 | config.init_data = pdata->regulators[i].initdata; |
| 721 | config.driver_data = s5m8767; |
| 722 | |
| 723 | rdev[i] = regulator_register(®ulators[id], &config); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 724 | if (IS_ERR(rdev[i])) { |
| 725 | ret = PTR_ERR(rdev[i]); |
| 726 | dev_err(s5m8767->dev, "regulator init failed for %d\n", |
| 727 | id); |
| 728 | rdev[i] = NULL; |
| 729 | goto err; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | return 0; |
| 734 | err: |
| 735 | for (i = 0; i < s5m8767->num_regulators; i++) |
| 736 | if (rdev[i]) |
| 737 | regulator_unregister(rdev[i]); |
| 738 | |
| 739 | return ret; |
| 740 | } |
| 741 | |
| 742 | static int __devexit s5m8767_pmic_remove(struct platform_device *pdev) |
| 743 | { |
| 744 | struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev); |
| 745 | struct regulator_dev **rdev = s5m8767->rdev; |
| 746 | int i; |
| 747 | |
| 748 | for (i = 0; i < s5m8767->num_regulators; i++) |
| 749 | if (rdev[i]) |
| 750 | regulator_unregister(rdev[i]); |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | static const struct platform_device_id s5m8767_pmic_id[] = { |
| 756 | { "s5m8767-pmic", 0}, |
| 757 | { }, |
| 758 | }; |
| 759 | MODULE_DEVICE_TABLE(platform, s5m8767_pmic_id); |
| 760 | |
| 761 | static struct platform_driver s5m8767_pmic_driver = { |
| 762 | .driver = { |
| 763 | .name = "s5m8767-pmic", |
| 764 | .owner = THIS_MODULE, |
| 765 | }, |
| 766 | .probe = s5m8767_pmic_probe, |
| 767 | .remove = __devexit_p(s5m8767_pmic_remove), |
| 768 | .id_table = s5m8767_pmic_id, |
| 769 | }; |
| 770 | |
| 771 | static int __init s5m8767_pmic_init(void) |
| 772 | { |
| 773 | return platform_driver_register(&s5m8767_pmic_driver); |
| 774 | } |
| 775 | subsys_initcall(s5m8767_pmic_init); |
| 776 | |
| 777 | static void __exit s5m8767_pmic_exit(void) |
| 778 | { |
| 779 | platform_driver_unregister(&s5m8767_pmic_driver); |
| 780 | } |
| 781 | module_exit(s5m8767_pmic_exit); |
| 782 | |
| 783 | /* Module information */ |
| 784 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
| 785 | MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver"); |
| 786 | MODULE_LICENSE("GPL"); |