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 | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 350 | selector = (min_vol - desc->min) / desc->step; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 351 | |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 352 | if (desc->min + desc->step * selector > max_vol) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 353 | return -EINVAL; |
| 354 | |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 355 | return selector; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static int s5m8767_set_voltage(struct regulator_dev *rdev, |
| 359 | int min_uV, int max_uV, unsigned *selector) |
| 360 | { |
| 361 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 362 | const struct s5m_voltage_desc *desc; |
Axel Lin | 20a14b8 | 2012-01-31 15:13:31 +0800 | [diff] [blame] | 363 | int reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 364 | int reg, mask, ret; |
| 365 | int i; |
| 366 | u8 val; |
| 367 | |
| 368 | switch (reg_id) { |
| 369 | case S5M8767_LDO1 ... S5M8767_LDO28: |
| 370 | mask = 0x3f; |
| 371 | break; |
| 372 | case S5M8767_BUCK1 ... S5M8767_BUCK6: |
| 373 | mask = 0xff; |
| 374 | break; |
| 375 | case S5M8767_BUCK7 ... S5M8767_BUCK8: |
| 376 | return -EINVAL; |
| 377 | case S5M8767_BUCK9: |
| 378 | mask = 0xff; |
| 379 | break; |
| 380 | default: |
| 381 | return -EINVAL; |
| 382 | } |
| 383 | |
| 384 | desc = reg_voltage_map[reg_id]; |
| 385 | |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 386 | i = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 387 | if (i < 0) |
| 388 | return i; |
| 389 | |
| 390 | ret = s5m8767_get_voltage_register(rdev, ®); |
| 391 | if (ret) |
| 392 | return ret; |
| 393 | |
| 394 | s5m_reg_read(s5m8767->iodev, reg, &val); |
| 395 | val = val & mask; |
| 396 | |
| 397 | ret = s5m_reg_write(s5m8767->iodev, reg, val); |
| 398 | *selector = i; |
| 399 | |
| 400 | return ret; |
| 401 | } |
| 402 | |
| 403 | static inline void s5m8767_set_high(struct s5m8767_info *s5m8767) |
| 404 | { |
| 405 | int temp_index = s5m8767->buck_gpioindex; |
| 406 | |
| 407 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); |
| 408 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); |
| 409 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); |
| 410 | } |
| 411 | |
| 412 | static inline void s5m8767_set_low(struct s5m8767_info *s5m8767) |
| 413 | { |
| 414 | int temp_index = s5m8767->buck_gpioindex; |
| 415 | |
| 416 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); |
| 417 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); |
| 418 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); |
| 419 | } |
| 420 | |
| 421 | static int s5m8767_set_voltage_buck(struct regulator_dev *rdev, |
| 422 | int min_uV, int max_uV, unsigned *selector) |
| 423 | { |
| 424 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Axel Lin | 20a14b8 | 2012-01-31 15:13:31 +0800 | [diff] [blame] | 425 | int reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 426 | const struct s5m_voltage_desc *desc; |
| 427 | int new_val, old_val, i = 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 428 | |
| 429 | if (reg_id < S5M8767_BUCK1 || reg_id > S5M8767_BUCK6) |
| 430 | return -EINVAL; |
| 431 | |
| 432 | switch (reg_id) { |
| 433 | case S5M8767_BUCK1: |
| 434 | return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); |
| 435 | case S5M8767_BUCK2 ... S5M8767_BUCK4: |
| 436 | break; |
| 437 | case S5M8767_BUCK5 ... S5M8767_BUCK6: |
| 438 | return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); |
| 439 | case S5M8767_BUCK9: |
| 440 | return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); |
| 441 | } |
| 442 | |
| 443 | desc = reg_voltage_map[reg_id]; |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 444 | new_val = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 445 | if (new_val < 0) |
| 446 | return new_val; |
| 447 | |
| 448 | switch (reg_id) { |
| 449 | case S5M8767_BUCK2: |
| 450 | if (s5m8767->buck2_gpiodvs) { |
| 451 | while (s5m8767->buck2_vol[i] != new_val) |
| 452 | i++; |
| 453 | } else |
| 454 | return s5m8767_set_voltage(rdev, min_uV, |
| 455 | max_uV, selector); |
| 456 | break; |
| 457 | case S5M8767_BUCK3: |
| 458 | if (s5m8767->buck3_gpiodvs) { |
| 459 | while (s5m8767->buck3_vol[i] != new_val) |
| 460 | i++; |
| 461 | } else |
| 462 | return s5m8767_set_voltage(rdev, min_uV, |
| 463 | max_uV, selector); |
| 464 | break; |
| 465 | case S5M8767_BUCK4: |
| 466 | if (s5m8767->buck3_gpiodvs) { |
| 467 | while (s5m8767->buck4_vol[i] != new_val) |
| 468 | i++; |
| 469 | } else |
| 470 | return s5m8767_set_voltage(rdev, min_uV, |
| 471 | max_uV, selector); |
| 472 | break; |
| 473 | } |
| 474 | |
| 475 | old_val = s5m8767->buck_gpioindex; |
| 476 | s5m8767->buck_gpioindex = i; |
| 477 | |
| 478 | if (i > old_val) |
| 479 | s5m8767_set_high(s5m8767); |
| 480 | else |
| 481 | s5m8767_set_low(s5m8767); |
| 482 | |
| 483 | *selector = new_val; |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, |
| 488 | unsigned int old_sel, |
| 489 | unsigned int new_sel) |
| 490 | { |
| 491 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 492 | const struct s5m_voltage_desc *desc; |
Axel Lin | 20a14b8 | 2012-01-31 15:13:31 +0800 | [diff] [blame] | 493 | int reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 494 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 495 | desc = reg_voltage_map[reg_id]; |
| 496 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 497 | if (old_sel < new_sel) |
Axel Lin | 89e0f0e | 2012-02-24 14:52:45 +0800 | [diff] [blame] | 498 | return DIV_ROUND_UP(desc->step * (new_sel - old_sel), |
Sangbeom Kim | 0f8b9c7 | 2012-03-09 16:28:10 +0900 | [diff] [blame] | 499 | s5m8767->ramp_delay * 1000); |
Axel Lin | 89e0f0e | 2012-02-24 14:52:45 +0800 | [diff] [blame] | 500 | return 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | static struct regulator_ops s5m8767_ldo_ops = { |
| 504 | .list_voltage = s5m8767_list_voltage, |
| 505 | .is_enabled = s5m8767_reg_is_enabled, |
| 506 | .enable = s5m8767_reg_enable, |
| 507 | .disable = s5m8767_reg_disable, |
| 508 | .get_voltage_sel = s5m8767_get_voltage_sel, |
| 509 | .set_voltage = s5m8767_set_voltage, |
| 510 | .set_voltage_time_sel = s5m8767_set_voltage_time_sel, |
| 511 | }; |
| 512 | |
| 513 | static struct regulator_ops s5m8767_buck_ops = { |
| 514 | .list_voltage = s5m8767_list_voltage, |
| 515 | .is_enabled = s5m8767_reg_is_enabled, |
| 516 | .enable = s5m8767_reg_enable, |
| 517 | .disable = s5m8767_reg_disable, |
| 518 | .get_voltage_sel = s5m8767_get_voltage_sel, |
| 519 | .set_voltage = s5m8767_set_voltage_buck, |
| 520 | .set_voltage_time_sel = s5m8767_set_voltage_time_sel, |
| 521 | }; |
| 522 | |
| 523 | #define regulator_desc_ldo(num) { \ |
| 524 | .name = "LDO"#num, \ |
| 525 | .id = S5M8767_LDO##num, \ |
| 526 | .ops = &s5m8767_ldo_ops, \ |
| 527 | .type = REGULATOR_VOLTAGE, \ |
| 528 | .owner = THIS_MODULE, \ |
| 529 | } |
| 530 | #define regulator_desc_buck(num) { \ |
| 531 | .name = "BUCK"#num, \ |
| 532 | .id = S5M8767_BUCK##num, \ |
| 533 | .ops = &s5m8767_buck_ops, \ |
| 534 | .type = REGULATOR_VOLTAGE, \ |
| 535 | .owner = THIS_MODULE, \ |
| 536 | } |
| 537 | |
| 538 | static struct regulator_desc regulators[] = { |
| 539 | regulator_desc_ldo(1), |
| 540 | regulator_desc_ldo(2), |
| 541 | regulator_desc_ldo(3), |
| 542 | regulator_desc_ldo(4), |
| 543 | regulator_desc_ldo(5), |
| 544 | regulator_desc_ldo(6), |
| 545 | regulator_desc_ldo(7), |
| 546 | regulator_desc_ldo(8), |
| 547 | regulator_desc_ldo(9), |
| 548 | regulator_desc_ldo(10), |
| 549 | regulator_desc_ldo(11), |
| 550 | regulator_desc_ldo(12), |
| 551 | regulator_desc_ldo(13), |
| 552 | regulator_desc_ldo(14), |
| 553 | regulator_desc_ldo(15), |
| 554 | regulator_desc_ldo(16), |
| 555 | regulator_desc_ldo(17), |
| 556 | regulator_desc_ldo(18), |
| 557 | regulator_desc_ldo(19), |
| 558 | regulator_desc_ldo(20), |
| 559 | regulator_desc_ldo(21), |
| 560 | regulator_desc_ldo(22), |
| 561 | regulator_desc_ldo(23), |
| 562 | regulator_desc_ldo(24), |
| 563 | regulator_desc_ldo(25), |
| 564 | regulator_desc_ldo(26), |
| 565 | regulator_desc_ldo(27), |
| 566 | regulator_desc_ldo(28), |
| 567 | regulator_desc_buck(1), |
| 568 | regulator_desc_buck(2), |
| 569 | regulator_desc_buck(3), |
| 570 | regulator_desc_buck(4), |
| 571 | regulator_desc_buck(5), |
| 572 | regulator_desc_buck(6), |
| 573 | regulator_desc_buck(7), |
| 574 | regulator_desc_buck(8), |
| 575 | regulator_desc_buck(9), |
| 576 | }; |
| 577 | |
| 578 | static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) |
| 579 | { |
| 580 | struct s5m87xx_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
| 581 | struct s5m_platform_data *pdata = dev_get_platdata(iodev->dev); |
| 582 | struct regulator_dev **rdev; |
| 583 | struct s5m8767_info *s5m8767; |
Mark Brown | 22cd2fef | 2012-02-06 11:34:36 +0000 | [diff] [blame] | 584 | int i, ret, size; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 585 | |
| 586 | if (!pdata) { |
| 587 | dev_err(pdev->dev.parent, "Platform data not supplied\n"); |
| 588 | return -ENODEV; |
| 589 | } |
| 590 | |
Axel Lin | 6c4efe2 | 2012-03-10 08:43:02 +0800 | [diff] [blame] | 591 | if (pdata->buck2_gpiodvs) { |
| 592 | if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) { |
| 593 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 594 | return -EINVAL; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | if (pdata->buck3_gpiodvs) { |
| 599 | if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) { |
| 600 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 601 | return -EINVAL; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | if (pdata->buck4_gpiodvs) { |
| 606 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) { |
| 607 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | } |
| 611 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 612 | s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info), |
| 613 | GFP_KERNEL); |
| 614 | if (!s5m8767) |
| 615 | return -ENOMEM; |
| 616 | |
| 617 | size = sizeof(struct regulator_dev *) * (S5M8767_REG_MAX - 2); |
| 618 | s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
| 619 | if (!s5m8767->rdev) |
| 620 | return -ENOMEM; |
| 621 | |
| 622 | rdev = s5m8767->rdev; |
| 623 | s5m8767->dev = &pdev->dev; |
| 624 | s5m8767->iodev = iodev; |
| 625 | s5m8767->num_regulators = S5M8767_REG_MAX - 2; |
| 626 | platform_set_drvdata(pdev, s5m8767); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 627 | |
| 628 | s5m8767->buck_gpioindex = pdata->buck_default_idx; |
| 629 | s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs; |
| 630 | s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs; |
| 631 | s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs; |
| 632 | s5m8767->buck_gpios[0] = pdata->buck_gpios[0]; |
| 633 | s5m8767->buck_gpios[1] = pdata->buck_gpios[1]; |
| 634 | s5m8767->buck_gpios[2] = pdata->buck_gpios[2]; |
| 635 | s5m8767->ramp_delay = pdata->buck_ramp_delay; |
| 636 | s5m8767->buck2_ramp = pdata->buck2_ramp_enable; |
| 637 | s5m8767->buck3_ramp = pdata->buck3_ramp_enable; |
| 638 | s5m8767->buck4_ramp = pdata->buck4_ramp_enable; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame^] | 639 | s5m8767->opmode = pdata->opmode; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 640 | |
| 641 | for (i = 0; i < 8; i++) { |
| 642 | if (s5m8767->buck2_gpiodvs) { |
| 643 | s5m8767->buck2_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 644 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 645 | &buck_voltage_val2, |
| 646 | pdata->buck2_voltage[i], |
| 647 | pdata->buck2_voltage[i] + |
| 648 | buck_voltage_val2.step); |
| 649 | } |
| 650 | |
| 651 | if (s5m8767->buck3_gpiodvs) { |
| 652 | s5m8767->buck3_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 653 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 654 | &buck_voltage_val2, |
| 655 | pdata->buck3_voltage[i], |
| 656 | pdata->buck3_voltage[i] + |
| 657 | buck_voltage_val2.step); |
| 658 | } |
| 659 | |
| 660 | if (s5m8767->buck4_gpiodvs) { |
| 661 | s5m8767->buck4_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 662 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 663 | &buck_voltage_val2, |
| 664 | pdata->buck4_voltage[i], |
| 665 | pdata->buck4_voltage[i] + |
| 666 | buck_voltage_val2.step); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || |
| 671 | pdata->buck4_gpiodvs) { |
| 672 | if (gpio_is_valid(pdata->buck_gpios[0]) && |
| 673 | gpio_is_valid(pdata->buck_gpios[1]) && |
| 674 | gpio_is_valid(pdata->buck_gpios[2])) { |
| 675 | ret = gpio_request(pdata->buck_gpios[0], |
| 676 | "S5M8767 SET1"); |
| 677 | if (ret == -EBUSY) |
| 678 | dev_warn(&pdev->dev, "Duplicated gpio request for SET1\n"); |
| 679 | |
| 680 | ret = gpio_request(pdata->buck_gpios[1], |
| 681 | "S5M8767 SET2"); |
| 682 | if (ret == -EBUSY) |
| 683 | dev_warn(&pdev->dev, "Duplicated gpio request for SET2\n"); |
| 684 | |
| 685 | ret = gpio_request(pdata->buck_gpios[2], |
| 686 | "S5M8767 SET3"); |
| 687 | if (ret == -EBUSY) |
| 688 | dev_warn(&pdev->dev, "Duplicated gpio request for SET3\n"); |
| 689 | /* SET1 GPIO */ |
| 690 | gpio_direction_output(pdata->buck_gpios[0], |
| 691 | (s5m8767->buck_gpioindex >> 2) & 0x1); |
| 692 | /* SET2 GPIO */ |
| 693 | gpio_direction_output(pdata->buck_gpios[1], |
| 694 | (s5m8767->buck_gpioindex >> 1) & 0x1); |
| 695 | /* SET3 GPIO */ |
| 696 | gpio_direction_output(pdata->buck_gpios[2], |
| 697 | (s5m8767->buck_gpioindex >> 0) & 0x1); |
| 698 | ret = 0; |
| 699 | } else { |
| 700 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); |
| 701 | ret = -EINVAL; |
| 702 | return ret; |
| 703 | } |
| 704 | } |
| 705 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 706 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, |
| 707 | (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); |
| 708 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, |
| 709 | (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); |
| 710 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, |
| 711 | (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); |
| 712 | |
| 713 | /* Initialize GPIO DVS registers */ |
| 714 | for (i = 0; i < 8; i++) { |
| 715 | if (s5m8767->buck2_gpiodvs) { |
| 716 | s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS1 + i, |
| 717 | s5m8767->buck2_vol[i]); |
| 718 | } |
| 719 | |
| 720 | if (s5m8767->buck3_gpiodvs) { |
| 721 | s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS1 + i, |
| 722 | s5m8767->buck3_vol[i]); |
| 723 | } |
| 724 | |
| 725 | if (s5m8767->buck4_gpiodvs) { |
| 726 | s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS1 + i, |
| 727 | s5m8767->buck4_vol[i]); |
| 728 | } |
| 729 | } |
| 730 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 0x78, 0xff); |
| 731 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 0x58, 0xff); |
| 732 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 0x78, 0xff); |
| 733 | |
| 734 | if (s5m8767->buck2_ramp) |
| 735 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08); |
| 736 | |
| 737 | if (s5m8767->buck3_ramp) |
| 738 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x04, 0x04); |
| 739 | |
| 740 | if (s5m8767->buck4_ramp) |
| 741 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x02, 0x02); |
| 742 | |
| 743 | if (s5m8767->buck2_ramp || s5m8767->buck3_ramp |
| 744 | || s5m8767->buck4_ramp) { |
| 745 | switch (s5m8767->ramp_delay) { |
| 746 | case 15: |
| 747 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
| 748 | 0xc0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 749 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 750 | case 25: |
| 751 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
| 752 | 0xd0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 753 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 754 | case 50: |
| 755 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
| 756 | 0xe0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 757 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 758 | case 100: |
| 759 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
| 760 | 0xf0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 761 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 762 | default: |
| 763 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
| 764 | 0x90, 0xf0); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | for (i = 0; i < pdata->num_regulators; i++) { |
| 769 | const struct s5m_voltage_desc *desc; |
| 770 | int id = pdata->regulators[i].id; |
| 771 | |
| 772 | desc = reg_voltage_map[id]; |
| 773 | if (desc) |
| 774 | regulators[id].n_voltages = |
| 775 | (desc->max - desc->min) / desc->step + 1; |
| 776 | |
| 777 | rdev[i] = regulator_register(®ulators[id], s5m8767->dev, |
Mark Brown | 0ce6987 | 2012-01-17 11:25:45 +0000 | [diff] [blame] | 778 | pdata->regulators[i].initdata, s5m8767, NULL); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 779 | if (IS_ERR(rdev[i])) { |
| 780 | ret = PTR_ERR(rdev[i]); |
| 781 | dev_err(s5m8767->dev, "regulator init failed for %d\n", |
| 782 | id); |
| 783 | rdev[i] = NULL; |
| 784 | goto err; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | return 0; |
| 789 | err: |
| 790 | for (i = 0; i < s5m8767->num_regulators; i++) |
| 791 | if (rdev[i]) |
| 792 | regulator_unregister(rdev[i]); |
| 793 | |
| 794 | return ret; |
| 795 | } |
| 796 | |
| 797 | static int __devexit s5m8767_pmic_remove(struct platform_device *pdev) |
| 798 | { |
| 799 | struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev); |
| 800 | struct regulator_dev **rdev = s5m8767->rdev; |
| 801 | int i; |
| 802 | |
| 803 | for (i = 0; i < s5m8767->num_regulators; i++) |
| 804 | if (rdev[i]) |
| 805 | regulator_unregister(rdev[i]); |
| 806 | |
| 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | static const struct platform_device_id s5m8767_pmic_id[] = { |
| 811 | { "s5m8767-pmic", 0}, |
| 812 | { }, |
| 813 | }; |
| 814 | MODULE_DEVICE_TABLE(platform, s5m8767_pmic_id); |
| 815 | |
| 816 | static struct platform_driver s5m8767_pmic_driver = { |
| 817 | .driver = { |
| 818 | .name = "s5m8767-pmic", |
| 819 | .owner = THIS_MODULE, |
| 820 | }, |
| 821 | .probe = s5m8767_pmic_probe, |
| 822 | .remove = __devexit_p(s5m8767_pmic_remove), |
| 823 | .id_table = s5m8767_pmic_id, |
| 824 | }; |
| 825 | |
| 826 | static int __init s5m8767_pmic_init(void) |
| 827 | { |
| 828 | return platform_driver_register(&s5m8767_pmic_driver); |
| 829 | } |
| 830 | subsys_initcall(s5m8767_pmic_init); |
| 831 | |
| 832 | static void __exit s5m8767_pmic_exit(void) |
| 833 | { |
| 834 | platform_driver_unregister(&s5m8767_pmic_driver); |
| 835 | } |
| 836 | module_exit(s5m8767_pmic_exit); |
| 837 | |
| 838 | /* Module information */ |
| 839 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
| 840 | MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver"); |
| 841 | MODULE_LICENSE("GPL"); |