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> |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 15 | #include <linux/err.h> |
| 16 | #include <linux/gpio.h> |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame^] | 17 | #include <linux/of_gpio.h> |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 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> |
Sangbeom Kim | 54227bc | 2012-07-11 21:07:16 +0900 | [diff] [blame] | 23 | #include <linux/mfd/samsung/core.h> |
| 24 | #include <linux/mfd/samsung/s5m8767.h> |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame^] | 25 | #include <linux/regulator/of_regulator.h> |
| 26 | |
| 27 | #define S5M8767_OPMODE_NORMAL_MODE 0x1 |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 28 | |
| 29 | struct s5m8767_info { |
| 30 | struct device *dev; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 31 | struct sec_pmic_dev *iodev; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 32 | int num_regulators; |
| 33 | struct regulator_dev **rdev; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 34 | struct sec_opmode_data *opmode; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 35 | |
| 36 | int ramp_delay; |
| 37 | bool buck2_ramp; |
| 38 | bool buck3_ramp; |
| 39 | bool buck4_ramp; |
| 40 | |
| 41 | bool buck2_gpiodvs; |
| 42 | bool buck3_gpiodvs; |
| 43 | bool buck4_gpiodvs; |
| 44 | u8 buck2_vol[8]; |
| 45 | u8 buck3_vol[8]; |
| 46 | u8 buck4_vol[8]; |
| 47 | int buck_gpios[3]; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 48 | int buck_ds[3]; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 49 | int buck_gpioindex; |
| 50 | }; |
| 51 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 52 | struct sec_voltage_desc { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 53 | int max; |
| 54 | int min; |
| 55 | int step; |
| 56 | }; |
| 57 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 58 | static const struct sec_voltage_desc buck_voltage_val1 = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 59 | .max = 2225000, |
| 60 | .min = 650000, |
| 61 | .step = 6250, |
| 62 | }; |
| 63 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 64 | static const struct sec_voltage_desc buck_voltage_val2 = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 65 | .max = 1600000, |
| 66 | .min = 600000, |
| 67 | .step = 6250, |
| 68 | }; |
| 69 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 70 | static const struct sec_voltage_desc buck_voltage_val3 = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 71 | .max = 3000000, |
| 72 | .min = 750000, |
| 73 | .step = 12500, |
| 74 | }; |
| 75 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 76 | static const struct sec_voltage_desc ldo_voltage_val1 = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 77 | .max = 3950000, |
| 78 | .min = 800000, |
| 79 | .step = 50000, |
| 80 | }; |
| 81 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 82 | static const struct sec_voltage_desc ldo_voltage_val2 = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 83 | .max = 2375000, |
| 84 | .min = 800000, |
| 85 | .step = 25000, |
| 86 | }; |
| 87 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 88 | static const struct sec_voltage_desc *reg_voltage_map[] = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 89 | [S5M8767_LDO1] = &ldo_voltage_val2, |
| 90 | [S5M8767_LDO2] = &ldo_voltage_val2, |
| 91 | [S5M8767_LDO3] = &ldo_voltage_val1, |
| 92 | [S5M8767_LDO4] = &ldo_voltage_val1, |
| 93 | [S5M8767_LDO5] = &ldo_voltage_val1, |
| 94 | [S5M8767_LDO6] = &ldo_voltage_val2, |
| 95 | [S5M8767_LDO7] = &ldo_voltage_val2, |
| 96 | [S5M8767_LDO8] = &ldo_voltage_val2, |
| 97 | [S5M8767_LDO9] = &ldo_voltage_val1, |
| 98 | [S5M8767_LDO10] = &ldo_voltage_val1, |
| 99 | [S5M8767_LDO11] = &ldo_voltage_val1, |
| 100 | [S5M8767_LDO12] = &ldo_voltage_val1, |
| 101 | [S5M8767_LDO13] = &ldo_voltage_val1, |
| 102 | [S5M8767_LDO14] = &ldo_voltage_val1, |
| 103 | [S5M8767_LDO15] = &ldo_voltage_val2, |
| 104 | [S5M8767_LDO16] = &ldo_voltage_val1, |
| 105 | [S5M8767_LDO17] = &ldo_voltage_val1, |
| 106 | [S5M8767_LDO18] = &ldo_voltage_val1, |
| 107 | [S5M8767_LDO19] = &ldo_voltage_val1, |
| 108 | [S5M8767_LDO20] = &ldo_voltage_val1, |
| 109 | [S5M8767_LDO21] = &ldo_voltage_val1, |
| 110 | [S5M8767_LDO22] = &ldo_voltage_val1, |
| 111 | [S5M8767_LDO23] = &ldo_voltage_val1, |
| 112 | [S5M8767_LDO24] = &ldo_voltage_val1, |
| 113 | [S5M8767_LDO25] = &ldo_voltage_val1, |
| 114 | [S5M8767_LDO26] = &ldo_voltage_val1, |
| 115 | [S5M8767_LDO27] = &ldo_voltage_val1, |
| 116 | [S5M8767_LDO28] = &ldo_voltage_val1, |
| 117 | [S5M8767_BUCK1] = &buck_voltage_val1, |
| 118 | [S5M8767_BUCK2] = &buck_voltage_val2, |
| 119 | [S5M8767_BUCK3] = &buck_voltage_val2, |
| 120 | [S5M8767_BUCK4] = &buck_voltage_val2, |
| 121 | [S5M8767_BUCK5] = &buck_voltage_val1, |
| 122 | [S5M8767_BUCK6] = &buck_voltage_val1, |
| 123 | [S5M8767_BUCK7] = NULL, |
| 124 | [S5M8767_BUCK8] = NULL, |
| 125 | [S5M8767_BUCK9] = &buck_voltage_val3, |
| 126 | }; |
| 127 | |
Mark Brown | 5ceba7b | 2012-05-09 20:37:51 +0100 | [diff] [blame] | 128 | static unsigned int s5m8767_opmode_reg[][4] = { |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 129 | /* {OFF, ON, LOWPOWER, SUSPEND} */ |
| 130 | /* LDO1 ... LDO28 */ |
| 131 | {0x0, 0x3, 0x2, 0x1}, /* LDO1 */ |
| 132 | {0x0, 0x3, 0x2, 0x1}, |
| 133 | {0x0, 0x3, 0x2, 0x1}, |
| 134 | {0x0, 0x0, 0x0, 0x0}, |
| 135 | {0x0, 0x3, 0x2, 0x1}, /* LDO5 */ |
| 136 | {0x0, 0x3, 0x2, 0x1}, |
| 137 | {0x0, 0x3, 0x2, 0x1}, |
| 138 | {0x0, 0x3, 0x2, 0x1}, |
| 139 | {0x0, 0x3, 0x2, 0x1}, |
| 140 | {0x0, 0x3, 0x2, 0x1}, /* LDO10 */ |
| 141 | {0x0, 0x3, 0x2, 0x1}, |
| 142 | {0x0, 0x3, 0x2, 0x1}, |
| 143 | {0x0, 0x3, 0x2, 0x1}, |
| 144 | {0x0, 0x3, 0x2, 0x1}, |
| 145 | {0x0, 0x3, 0x2, 0x1}, /* LDO15 */ |
| 146 | {0x0, 0x3, 0x2, 0x1}, |
| 147 | {0x0, 0x3, 0x2, 0x1}, |
| 148 | {0x0, 0x0, 0x0, 0x0}, |
| 149 | {0x0, 0x3, 0x2, 0x1}, |
| 150 | {0x0, 0x3, 0x2, 0x1}, /* LDO20 */ |
| 151 | {0x0, 0x3, 0x2, 0x1}, |
| 152 | {0x0, 0x3, 0x2, 0x1}, |
| 153 | {0x0, 0x0, 0x0, 0x0}, |
| 154 | {0x0, 0x3, 0x2, 0x1}, |
| 155 | {0x0, 0x3, 0x2, 0x1}, /* LDO25 */ |
| 156 | {0x0, 0x3, 0x2, 0x1}, |
| 157 | {0x0, 0x3, 0x2, 0x1}, |
| 158 | {0x0, 0x3, 0x2, 0x1}, /* LDO28 */ |
| 159 | |
| 160 | /* BUCK1 ... BUCK9 */ |
| 161 | {0x0, 0x3, 0x1, 0x1}, /* BUCK1 */ |
| 162 | {0x0, 0x3, 0x1, 0x1}, |
| 163 | {0x0, 0x3, 0x1, 0x1}, |
| 164 | {0x0, 0x3, 0x1, 0x1}, |
| 165 | {0x0, 0x3, 0x2, 0x1}, /* BUCK5 */ |
| 166 | {0x0, 0x3, 0x1, 0x1}, |
| 167 | {0x0, 0x3, 0x1, 0x1}, |
| 168 | {0x0, 0x3, 0x1, 0x1}, |
| 169 | {0x0, 0x3, 0x1, 0x1}, /* BUCK9 */ |
| 170 | }; |
| 171 | |
| 172 | static int s5m8767_get_register(struct regulator_dev *rdev, int *reg, |
| 173 | int *enable_ctrl) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 174 | { |
Amit Daniel Kachhap | 9bb096f | 2012-12-10 18:19:39 +0530 | [diff] [blame] | 175 | int i, reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 176 | unsigned int mode; |
| 177 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 178 | |
| 179 | switch (reg_id) { |
| 180 | case S5M8767_LDO1 ... S5M8767_LDO2: |
| 181 | *reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1); |
| 182 | break; |
| 183 | case S5M8767_LDO3 ... S5M8767_LDO28: |
| 184 | *reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3); |
| 185 | break; |
| 186 | case S5M8767_BUCK1: |
| 187 | *reg = S5M8767_REG_BUCK1CTRL1; |
| 188 | break; |
| 189 | case S5M8767_BUCK2 ... S5M8767_BUCK4: |
| 190 | *reg = S5M8767_REG_BUCK2CTRL + (reg_id - S5M8767_BUCK2) * 9; |
| 191 | break; |
| 192 | case S5M8767_BUCK5: |
| 193 | *reg = S5M8767_REG_BUCK5CTRL1; |
| 194 | break; |
| 195 | case S5M8767_BUCK6 ... S5M8767_BUCK9: |
| 196 | *reg = S5M8767_REG_BUCK6CTRL1 + (reg_id - S5M8767_BUCK6) * 2; |
| 197 | break; |
| 198 | default: |
| 199 | return -EINVAL; |
| 200 | } |
| 201 | |
Amit Daniel Kachhap | 9bb096f | 2012-12-10 18:19:39 +0530 | [diff] [blame] | 202 | for (i = 0; i < s5m8767->num_regulators; i++) { |
| 203 | if (s5m8767->opmode[i].id == reg_id) { |
| 204 | mode = s5m8767->opmode[i].mode; |
| 205 | break; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | if (i < s5m8767->num_regulators) |
| 210 | *enable_ctrl = |
| 211 | s5m8767_opmode_reg[reg_id][mode] << S5M8767_ENCTRL_SHIFT; |
| 212 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | static int s5m8767_reg_is_enabled(struct regulator_dev *rdev) |
| 217 | { |
| 218 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 219 | int ret, reg; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 220 | int mask = 0xc0, enable_ctrl; |
Inderpal Singh | 3ef3039 | 2012-12-12 08:57:00 +0530 | [diff] [blame] | 221 | unsigned int val; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 222 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 223 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 224 | if (ret == -EINVAL) |
| 225 | return 1; |
| 226 | else if (ret) |
| 227 | return ret; |
| 228 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 229 | ret = sec_reg_read(s5m8767->iodev, reg, &val); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 230 | if (ret) |
| 231 | return ret; |
| 232 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 233 | return (val & mask) == enable_ctrl; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static int s5m8767_reg_enable(struct regulator_dev *rdev) |
| 237 | { |
| 238 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 239 | int ret, reg; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 240 | int mask = 0xc0, enable_ctrl; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 241 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 242 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 243 | if (ret) |
| 244 | return ret; |
| 245 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 246 | return sec_reg_update(s5m8767->iodev, reg, enable_ctrl, mask); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static int s5m8767_reg_disable(struct regulator_dev *rdev) |
| 250 | { |
| 251 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 252 | int ret, reg; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 253 | int mask = 0xc0, enable_ctrl; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 254 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 255 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 256 | if (ret) |
| 257 | return ret; |
| 258 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 259 | return sec_reg_update(s5m8767->iodev, reg, ~mask, mask); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 260 | } |
| 261 | |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame] | 262 | static int s5m8767_get_vsel_reg(int reg_id, struct s5m8767_info *s5m8767) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 263 | { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 264 | int reg; |
| 265 | |
| 266 | switch (reg_id) { |
| 267 | case S5M8767_LDO1 ... S5M8767_LDO2: |
| 268 | reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1); |
| 269 | break; |
| 270 | case S5M8767_LDO3 ... S5M8767_LDO28: |
| 271 | reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3); |
| 272 | break; |
| 273 | case S5M8767_BUCK1: |
| 274 | reg = S5M8767_REG_BUCK1CTRL2; |
| 275 | break; |
| 276 | case S5M8767_BUCK2: |
Amit Daniel Kachhap | da130ab | 2012-12-10 18:19:40 +0530 | [diff] [blame] | 277 | reg = S5M8767_REG_BUCK2DVS1; |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 278 | if (s5m8767->buck2_gpiodvs) |
| 279 | reg += s5m8767->buck_gpioindex; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 280 | break; |
| 281 | case S5M8767_BUCK3: |
Amit Daniel Kachhap | da130ab | 2012-12-10 18:19:40 +0530 | [diff] [blame] | 282 | reg = S5M8767_REG_BUCK3DVS1; |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 283 | if (s5m8767->buck3_gpiodvs) |
| 284 | reg += s5m8767->buck_gpioindex; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 285 | break; |
| 286 | case S5M8767_BUCK4: |
Amit Daniel Kachhap | da130ab | 2012-12-10 18:19:40 +0530 | [diff] [blame] | 287 | reg = S5M8767_REG_BUCK4DVS1; |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 288 | if (s5m8767->buck4_gpiodvs) |
| 289 | reg += s5m8767->buck_gpioindex; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 290 | break; |
| 291 | case S5M8767_BUCK5: |
| 292 | reg = S5M8767_REG_BUCK5CTRL2; |
| 293 | break; |
| 294 | case S5M8767_BUCK6 ... S5M8767_BUCK9: |
| 295 | reg = S5M8767_REG_BUCK6CTRL2 + (reg_id - S5M8767_BUCK6) * 2; |
| 296 | break; |
| 297 | default: |
| 298 | return -EINVAL; |
| 299 | } |
| 300 | |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame] | 301 | return reg; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 302 | } |
| 303 | |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 304 | static int s5m8767_convert_voltage_to_sel(const struct sec_voltage_desc *desc, |
| 305 | int min_vol) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 306 | { |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 307 | int selector = 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 308 | |
| 309 | if (desc == NULL) |
| 310 | return -EINVAL; |
| 311 | |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 312 | if (min_vol > desc->max) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 313 | return -EINVAL; |
| 314 | |
Axel Lin | 94e85a3 | 2012-04-13 09:30:05 +0800 | [diff] [blame] | 315 | if (min_vol < desc->min) |
| 316 | min_vol = desc->min; |
| 317 | |
| 318 | selector = DIV_ROUND_UP(min_vol - desc->min, desc->step); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 319 | |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 320 | if (desc->min + desc->step * selector > desc->max) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 321 | return -EINVAL; |
| 322 | |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 323 | return selector; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 324 | } |
| 325 | |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 326 | static inline int s5m8767_set_high(struct s5m8767_info *s5m8767) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 327 | { |
| 328 | int temp_index = s5m8767->buck_gpioindex; |
| 329 | |
| 330 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); |
| 331 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); |
| 332 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 333 | |
| 334 | return 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 335 | } |
| 336 | |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 337 | static inline int s5m8767_set_low(struct s5m8767_info *s5m8767) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 338 | { |
| 339 | int temp_index = s5m8767->buck_gpioindex; |
| 340 | |
| 341 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); |
| 342 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); |
| 343 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 344 | |
| 345 | return 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 346 | } |
| 347 | |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 348 | static int s5m8767_set_voltage_sel(struct regulator_dev *rdev, |
| 349 | unsigned selector) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 350 | { |
| 351 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 352 | int reg_id = rdev_get_id(rdev); |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame] | 353 | int old_index, index = 0; |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 354 | u8 *buck234_vol = NULL; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 355 | |
| 356 | switch (reg_id) { |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 357 | case S5M8767_LDO1 ... S5M8767_LDO28: |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 358 | break; |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 359 | case S5M8767_BUCK1 ... S5M8767_BUCK6: |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 360 | if (reg_id == S5M8767_BUCK2 && s5m8767->buck2_gpiodvs) |
| 361 | buck234_vol = &s5m8767->buck2_vol[0]; |
| 362 | else if (reg_id == S5M8767_BUCK3 && s5m8767->buck3_gpiodvs) |
| 363 | buck234_vol = &s5m8767->buck3_vol[0]; |
| 364 | else if (reg_id == S5M8767_BUCK4 && s5m8767->buck4_gpiodvs) |
| 365 | buck234_vol = &s5m8767->buck4_vol[0]; |
| 366 | break; |
| 367 | case S5M8767_BUCK7 ... S5M8767_BUCK8: |
| 368 | return -EINVAL; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 369 | case S5M8767_BUCK9: |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 370 | break; |
| 371 | default: |
| 372 | return -EINVAL; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 373 | } |
| 374 | |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 375 | /* buck234_vol != NULL means to control buck234 voltage via DVS GPIO */ |
| 376 | if (buck234_vol) { |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 377 | while (*buck234_vol != selector) { |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 378 | buck234_vol++; |
| 379 | index++; |
| 380 | } |
| 381 | old_index = s5m8767->buck_gpioindex; |
| 382 | s5m8767->buck_gpioindex = index; |
| 383 | |
| 384 | if (index > old_index) |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 385 | return s5m8767_set_high(s5m8767); |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 386 | else |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 387 | return s5m8767_set_low(s5m8767); |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 388 | } else { |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame] | 389 | return regulator_set_voltage_sel_regmap(rdev, selector); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 390 | } |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, |
| 394 | unsigned int old_sel, |
| 395 | unsigned int new_sel) |
| 396 | { |
| 397 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 398 | const struct sec_voltage_desc *desc; |
Axel Lin | 20a14b8 | 2012-01-31 15:13:31 +0800 | [diff] [blame] | 399 | int reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 400 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 401 | desc = reg_voltage_map[reg_id]; |
| 402 | |
Sangbeom Kim | 9d88fc0 | 2012-06-13 17:27:16 +0900 | [diff] [blame] | 403 | if ((old_sel < new_sel) && s5m8767->ramp_delay) |
Axel Lin | 89e0f0e | 2012-02-24 14:52:45 +0800 | [diff] [blame] | 404 | return DIV_ROUND_UP(desc->step * (new_sel - old_sel), |
Sangbeom Kim | 0f8b9c7 | 2012-03-09 16:28:10 +0900 | [diff] [blame] | 405 | s5m8767->ramp_delay * 1000); |
Axel Lin | 89e0f0e | 2012-02-24 14:52:45 +0800 | [diff] [blame] | 406 | return 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 407 | } |
| 408 | |
Axel Lin | d35aad0 | 2012-04-10 14:07:15 +0800 | [diff] [blame] | 409 | static struct regulator_ops s5m8767_ops = { |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 410 | .list_voltage = regulator_list_voltage_linear, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 411 | .is_enabled = s5m8767_reg_is_enabled, |
| 412 | .enable = s5m8767_reg_enable, |
| 413 | .disable = s5m8767_reg_disable, |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame] | 414 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 415 | .set_voltage_sel = s5m8767_set_voltage_sel, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 416 | .set_voltage_time_sel = s5m8767_set_voltage_time_sel, |
| 417 | }; |
| 418 | |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 419 | static struct regulator_ops s5m8767_buck78_ops = { |
| 420 | .is_enabled = s5m8767_reg_is_enabled, |
| 421 | .enable = s5m8767_reg_enable, |
| 422 | .disable = s5m8767_reg_disable, |
| 423 | }; |
| 424 | |
Axel Lin | 65896e7 | 2012-04-10 14:08:19 +0800 | [diff] [blame] | 425 | #define s5m8767_regulator_desc(_name) { \ |
| 426 | .name = #_name, \ |
| 427 | .id = S5M8767_##_name, \ |
| 428 | .ops = &s5m8767_ops, \ |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 429 | .type = REGULATOR_VOLTAGE, \ |
| 430 | .owner = THIS_MODULE, \ |
| 431 | } |
| 432 | |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 433 | #define s5m8767_regulator_buck78_desc(_name) { \ |
| 434 | .name = #_name, \ |
| 435 | .id = S5M8767_##_name, \ |
| 436 | .ops = &s5m8767_buck78_ops, \ |
| 437 | .type = REGULATOR_VOLTAGE, \ |
| 438 | .owner = THIS_MODULE, \ |
| 439 | } |
| 440 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 441 | static struct regulator_desc regulators[] = { |
Axel Lin | 65896e7 | 2012-04-10 14:08:19 +0800 | [diff] [blame] | 442 | s5m8767_regulator_desc(LDO1), |
| 443 | s5m8767_regulator_desc(LDO2), |
| 444 | s5m8767_regulator_desc(LDO3), |
| 445 | s5m8767_regulator_desc(LDO4), |
| 446 | s5m8767_regulator_desc(LDO5), |
| 447 | s5m8767_regulator_desc(LDO6), |
| 448 | s5m8767_regulator_desc(LDO7), |
| 449 | s5m8767_regulator_desc(LDO8), |
| 450 | s5m8767_regulator_desc(LDO9), |
| 451 | s5m8767_regulator_desc(LDO10), |
| 452 | s5m8767_regulator_desc(LDO11), |
| 453 | s5m8767_regulator_desc(LDO12), |
| 454 | s5m8767_regulator_desc(LDO13), |
| 455 | s5m8767_regulator_desc(LDO14), |
| 456 | s5m8767_regulator_desc(LDO15), |
| 457 | s5m8767_regulator_desc(LDO16), |
| 458 | s5m8767_regulator_desc(LDO17), |
| 459 | s5m8767_regulator_desc(LDO18), |
| 460 | s5m8767_regulator_desc(LDO19), |
| 461 | s5m8767_regulator_desc(LDO20), |
| 462 | s5m8767_regulator_desc(LDO21), |
| 463 | s5m8767_regulator_desc(LDO22), |
| 464 | s5m8767_regulator_desc(LDO23), |
| 465 | s5m8767_regulator_desc(LDO24), |
| 466 | s5m8767_regulator_desc(LDO25), |
| 467 | s5m8767_regulator_desc(LDO26), |
| 468 | s5m8767_regulator_desc(LDO27), |
| 469 | s5m8767_regulator_desc(LDO28), |
| 470 | s5m8767_regulator_desc(BUCK1), |
| 471 | s5m8767_regulator_desc(BUCK2), |
| 472 | s5m8767_regulator_desc(BUCK3), |
| 473 | s5m8767_regulator_desc(BUCK4), |
| 474 | s5m8767_regulator_desc(BUCK5), |
| 475 | s5m8767_regulator_desc(BUCK6), |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 476 | s5m8767_regulator_buck78_desc(BUCK7), |
| 477 | s5m8767_regulator_buck78_desc(BUCK8), |
Axel Lin | 65896e7 | 2012-04-10 14:08:19 +0800 | [diff] [blame] | 478 | s5m8767_regulator_desc(BUCK9), |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 479 | }; |
| 480 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame^] | 481 | #ifdef CONFIG_OF |
| 482 | static int s5m8767_pmic_dt_parse_dvs_gpio(struct sec_pmic_dev *iodev, |
| 483 | struct sec_platform_data *pdata, |
| 484 | struct device_node *pmic_np) |
| 485 | { |
| 486 | int i, gpio; |
| 487 | |
| 488 | for (i = 0; i < 3; i++) { |
| 489 | gpio = of_get_named_gpio(pmic_np, |
| 490 | "s5m8767,pmic-buck-dvs-gpios", i); |
| 491 | if (!gpio_is_valid(gpio)) { |
| 492 | dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio); |
| 493 | return -EINVAL; |
| 494 | } |
| 495 | pdata->buck_gpios[i] = gpio; |
| 496 | } |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static int s5m8767_pmic_dt_parse_ds_gpio(struct sec_pmic_dev *iodev, |
| 501 | struct sec_platform_data *pdata, |
| 502 | struct device_node *pmic_np) |
| 503 | { |
| 504 | int i, gpio; |
| 505 | |
| 506 | for (i = 0; i < 3; i++) { |
| 507 | gpio = of_get_named_gpio(pmic_np, |
| 508 | "s5m8767,pmic-buck-ds-gpios", i); |
| 509 | if (!gpio_is_valid(gpio)) { |
| 510 | dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio); |
| 511 | return -EINVAL; |
| 512 | } |
| 513 | pdata->buck_ds[i] = gpio; |
| 514 | } |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static int s5m8767_pmic_dt_parse_pdata(struct sec_pmic_dev *iodev, |
| 519 | struct sec_platform_data *pdata) |
| 520 | { |
| 521 | struct device_node *pmic_np, *regulators_np, *reg_np; |
| 522 | struct sec_regulator_data *rdata; |
| 523 | struct sec_opmode_data *rmode; |
| 524 | unsigned int i, dvs_voltage_nr = 1, ret; |
| 525 | |
| 526 | pmic_np = iodev->dev->of_node; |
| 527 | if (!pmic_np) { |
| 528 | dev_err(iodev->dev, "could not find pmic sub-node\n"); |
| 529 | return -ENODEV; |
| 530 | } |
| 531 | |
| 532 | regulators_np = of_find_node_by_name(pmic_np, "regulators"); |
| 533 | if (!regulators_np) { |
| 534 | dev_err(iodev->dev, "could not find regulators sub-node\n"); |
| 535 | return -EINVAL; |
| 536 | } |
| 537 | |
| 538 | /* count the number of regulators to be supported in pmic */ |
| 539 | pdata->num_regulators = 0; |
| 540 | for_each_child_of_node(regulators_np, reg_np) |
| 541 | pdata->num_regulators++; |
| 542 | |
| 543 | rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) * |
| 544 | pdata->num_regulators, GFP_KERNEL); |
| 545 | if (!rdata) { |
| 546 | dev_err(iodev->dev, |
| 547 | "could not allocate memory for regulator data\n"); |
| 548 | return -ENOMEM; |
| 549 | } |
| 550 | |
| 551 | rmode = devm_kzalloc(iodev->dev, sizeof(*rmode) * |
| 552 | pdata->num_regulators, GFP_KERNEL); |
| 553 | if (!rdata) { |
| 554 | dev_err(iodev->dev, |
| 555 | "could not allocate memory for regulator mode\n"); |
| 556 | return -ENOMEM; |
| 557 | } |
| 558 | |
| 559 | pdata->regulators = rdata; |
| 560 | pdata->opmode = rmode; |
| 561 | for_each_child_of_node(regulators_np, reg_np) { |
| 562 | for (i = 0; i < ARRAY_SIZE(regulators); i++) |
| 563 | if (!of_node_cmp(reg_np->name, regulators[i].name)) |
| 564 | break; |
| 565 | |
| 566 | if (i == ARRAY_SIZE(regulators)) { |
| 567 | dev_warn(iodev->dev, |
| 568 | "don't know how to configure regulator %s\n", |
| 569 | reg_np->name); |
| 570 | continue; |
| 571 | } |
| 572 | |
| 573 | rdata->id = i; |
| 574 | rdata->initdata = of_get_regulator_init_data( |
| 575 | iodev->dev, reg_np); |
| 576 | rdata->reg_node = reg_np; |
| 577 | rdata++; |
| 578 | rmode->id = i; |
| 579 | if (of_property_read_u32(reg_np, "op_mode", |
| 580 | &rmode->mode)) { |
| 581 | dev_warn(iodev->dev, |
| 582 | "no op_mode property property at %s\n", |
| 583 | reg_np->full_name); |
| 584 | |
| 585 | rmode->mode = S5M8767_OPMODE_NORMAL_MODE; |
| 586 | } |
| 587 | rmode++; |
| 588 | } |
| 589 | |
| 590 | if (of_get_property(pmic_np, "s5m8767,pmic-buck2-uses-gpio-dvs", NULL)) |
| 591 | pdata->buck2_gpiodvs = true; |
| 592 | |
| 593 | if (of_get_property(pmic_np, "s5m8767,pmic-buck3-uses-gpio-dvs", NULL)) |
| 594 | pdata->buck3_gpiodvs = true; |
| 595 | |
| 596 | if (of_get_property(pmic_np, "s5m8767,pmic-buck4-uses-gpio-dvs", NULL)) |
| 597 | pdata->buck4_gpiodvs = true; |
| 598 | |
| 599 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || |
| 600 | pdata->buck4_gpiodvs) { |
| 601 | ret = s5m8767_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np); |
| 602 | if (ret) |
| 603 | return -EINVAL; |
| 604 | |
| 605 | if (of_property_read_u32(pmic_np, |
| 606 | "s5m8767,pmic-buck-default-dvs-idx", |
| 607 | &pdata->buck_default_idx)) { |
| 608 | pdata->buck_default_idx = 0; |
| 609 | } else { |
| 610 | if (pdata->buck_default_idx >= 8) { |
| 611 | pdata->buck_default_idx = 0; |
| 612 | dev_info(iodev->dev, |
| 613 | "invalid value for default dvs index, use 0\n"); |
| 614 | } |
| 615 | } |
| 616 | dvs_voltage_nr = 8; |
| 617 | } |
| 618 | |
| 619 | ret = s5m8767_pmic_dt_parse_ds_gpio(iodev, pdata, pmic_np); |
| 620 | if (ret) |
| 621 | return -EINVAL; |
| 622 | |
| 623 | if (of_property_read_u32_array(pmic_np, |
| 624 | "s5m8767,pmic-buck2-dvs-voltage", |
| 625 | pdata->buck2_voltage, dvs_voltage_nr)) { |
| 626 | dev_err(iodev->dev, "buck2 voltages not specified\n"); |
| 627 | return -EINVAL; |
| 628 | } |
| 629 | |
| 630 | if (of_property_read_u32_array(pmic_np, |
| 631 | "s5m8767,pmic-buck3-dvs-voltage", |
| 632 | pdata->buck3_voltage, dvs_voltage_nr)) { |
| 633 | dev_err(iodev->dev, "buck3 voltages not specified\n"); |
| 634 | return -EINVAL; |
| 635 | } |
| 636 | |
| 637 | if (of_property_read_u32_array(pmic_np, |
| 638 | "s5m8767,pmic-buck4-dvs-voltage", |
| 639 | pdata->buck4_voltage, dvs_voltage_nr)) { |
| 640 | dev_err(iodev->dev, "buck4 voltages not specified\n"); |
| 641 | return -EINVAL; |
| 642 | } |
| 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | #else |
| 647 | static int s5m8767_pmic_dt_parse_pdata(struct sec_pmic_dev *iodev, |
| 648 | struct sec_platform_data *pdata) |
| 649 | { |
| 650 | return 0; |
| 651 | } |
| 652 | #endif /* CONFIG_OF */ |
| 653 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 654 | static int s5m8767_pmic_probe(struct platform_device *pdev) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 655 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 656 | struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame^] | 657 | struct sec_platform_data *pdata = iodev->pdata; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 658 | struct regulator_config config = { }; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 659 | struct regulator_dev **rdev; |
| 660 | struct s5m8767_info *s5m8767; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 661 | int i, ret, size, buck_init; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 662 | |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame^] | 663 | if (iodev->dev->of_node) { |
| 664 | ret = s5m8767_pmic_dt_parse_pdata(iodev, pdata); |
| 665 | if (ret) |
| 666 | return ret; |
| 667 | } |
| 668 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 669 | if (!pdata) { |
| 670 | dev_err(pdev->dev.parent, "Platform data not supplied\n"); |
| 671 | return -ENODEV; |
| 672 | } |
| 673 | |
Axel Lin | 6c4efe2 | 2012-03-10 08:43:02 +0800 | [diff] [blame] | 674 | if (pdata->buck2_gpiodvs) { |
| 675 | if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) { |
| 676 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 677 | return -EINVAL; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | if (pdata->buck3_gpiodvs) { |
| 682 | if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) { |
| 683 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 684 | return -EINVAL; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | if (pdata->buck4_gpiodvs) { |
| 689 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) { |
| 690 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 691 | return -EINVAL; |
| 692 | } |
| 693 | } |
| 694 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 695 | s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info), |
| 696 | GFP_KERNEL); |
| 697 | if (!s5m8767) |
| 698 | return -ENOMEM; |
| 699 | |
| 700 | size = sizeof(struct regulator_dev *) * (S5M8767_REG_MAX - 2); |
| 701 | s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
| 702 | if (!s5m8767->rdev) |
| 703 | return -ENOMEM; |
| 704 | |
| 705 | rdev = s5m8767->rdev; |
| 706 | s5m8767->dev = &pdev->dev; |
| 707 | s5m8767->iodev = iodev; |
Amit Daniel Kachhap | 9bb096f | 2012-12-10 18:19:39 +0530 | [diff] [blame] | 708 | s5m8767->num_regulators = pdata->num_regulators; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 709 | platform_set_drvdata(pdev, s5m8767); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 710 | |
| 711 | s5m8767->buck_gpioindex = pdata->buck_default_idx; |
| 712 | s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs; |
| 713 | s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs; |
| 714 | s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs; |
| 715 | s5m8767->buck_gpios[0] = pdata->buck_gpios[0]; |
| 716 | s5m8767->buck_gpios[1] = pdata->buck_gpios[1]; |
| 717 | s5m8767->buck_gpios[2] = pdata->buck_gpios[2]; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 718 | s5m8767->buck_ds[0] = pdata->buck_ds[0]; |
| 719 | s5m8767->buck_ds[1] = pdata->buck_ds[1]; |
| 720 | s5m8767->buck_ds[2] = pdata->buck_ds[2]; |
| 721 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 722 | s5m8767->ramp_delay = pdata->buck_ramp_delay; |
| 723 | s5m8767->buck2_ramp = pdata->buck2_ramp_enable; |
| 724 | s5m8767->buck3_ramp = pdata->buck3_ramp_enable; |
| 725 | s5m8767->buck4_ramp = pdata->buck4_ramp_enable; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 726 | s5m8767->opmode = pdata->opmode; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 727 | |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 728 | buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 729 | pdata->buck2_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 730 | |
Samuel Ortiz | 938e05b | 2012-07-31 00:36:16 +0200 | [diff] [blame] | 731 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS2, buck_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 732 | |
| 733 | buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 734 | pdata->buck3_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 735 | |
Samuel Ortiz | 938e05b | 2012-07-31 00:36:16 +0200 | [diff] [blame] | 736 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS2, buck_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 737 | |
| 738 | buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 739 | pdata->buck4_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 740 | |
Samuel Ortiz | 938e05b | 2012-07-31 00:36:16 +0200 | [diff] [blame] | 741 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS2, buck_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 742 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 743 | for (i = 0; i < 8; i++) { |
| 744 | if (s5m8767->buck2_gpiodvs) { |
| 745 | s5m8767->buck2_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 746 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 747 | &buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 748 | pdata->buck2_voltage[i]); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | if (s5m8767->buck3_gpiodvs) { |
| 752 | s5m8767->buck3_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 753 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 754 | &buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 755 | pdata->buck3_voltage[i]); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | if (s5m8767->buck4_gpiodvs) { |
| 759 | s5m8767->buck4_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 760 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 761 | &buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 762 | pdata->buck4_voltage[i]); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
Amit Daniel Kachhap | 76c854d | 2012-12-10 18:19:41 +0530 | [diff] [blame] | 766 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || |
| 767 | pdata->buck4_gpiodvs) { |
| 768 | |
| 769 | if (!gpio_is_valid(pdata->buck_gpios[0]) || |
| 770 | !gpio_is_valid(pdata->buck_gpios[1]) || |
| 771 | !gpio_is_valid(pdata->buck_gpios[2])) { |
| 772 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); |
| 773 | return -EINVAL; |
| 774 | } |
| 775 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 776 | ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[0], |
| 777 | "S5M8767 SET1"); |
| 778 | if (ret) |
| 779 | return ret; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 780 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 781 | ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[1], |
| 782 | "S5M8767 SET2"); |
| 783 | if (ret) |
| 784 | return ret; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 785 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 786 | ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[2], |
| 787 | "S5M8767 SET3"); |
| 788 | if (ret) |
| 789 | return ret; |
| 790 | |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 791 | /* SET1 GPIO */ |
| 792 | gpio_direction_output(pdata->buck_gpios[0], |
| 793 | (s5m8767->buck_gpioindex >> 2) & 0x1); |
| 794 | /* SET2 GPIO */ |
| 795 | gpio_direction_output(pdata->buck_gpios[1], |
| 796 | (s5m8767->buck_gpioindex >> 1) & 0x1); |
| 797 | /* SET3 GPIO */ |
| 798 | gpio_direction_output(pdata->buck_gpios[2], |
| 799 | (s5m8767->buck_gpioindex >> 0) & 0x1); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 800 | } |
| 801 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 802 | ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[0], "S5M8767 DS2"); |
| 803 | if (ret) |
| 804 | return ret; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 805 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 806 | ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[1], "S5M8767 DS3"); |
| 807 | if (ret) |
| 808 | return ret; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 809 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 810 | ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[2], "S5M8767 DS4"); |
| 811 | if (ret) |
| 812 | return ret; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 813 | |
| 814 | /* DS2 GPIO */ |
| 815 | gpio_direction_output(pdata->buck_ds[0], 0x0); |
| 816 | /* DS3 GPIO */ |
| 817 | gpio_direction_output(pdata->buck_ds[1], 0x0); |
| 818 | /* DS4 GPIO */ |
| 819 | gpio_direction_output(pdata->buck_ds[2], 0x0); |
| 820 | |
| 821 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || |
| 822 | pdata->buck4_gpiodvs) { |
Linus Torvalds | 3e701cd | 2012-07-30 12:41:17 -0700 | [diff] [blame] | 823 | sec_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 824 | (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), |
| 825 | 1 << 1); |
Linus Torvalds | 3e701cd | 2012-07-30 12:41:17 -0700 | [diff] [blame] | 826 | sec_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 827 | (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), |
| 828 | 1 << 1); |
Linus Torvalds | 3e701cd | 2012-07-30 12:41:17 -0700 | [diff] [blame] | 829 | sec_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 830 | (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), |
| 831 | 1 << 1); |
| 832 | } |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 833 | |
| 834 | /* Initialize GPIO DVS registers */ |
| 835 | for (i = 0; i < 8; i++) { |
| 836 | if (s5m8767->buck2_gpiodvs) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 837 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS1 + i, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 838 | s5m8767->buck2_vol[i]); |
| 839 | } |
| 840 | |
| 841 | if (s5m8767->buck3_gpiodvs) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 842 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS1 + i, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 843 | s5m8767->buck3_vol[i]); |
| 844 | } |
| 845 | |
| 846 | if (s5m8767->buck4_gpiodvs) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 847 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS1 + i, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 848 | s5m8767->buck4_vol[i]); |
| 849 | } |
| 850 | } |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 851 | |
| 852 | if (s5m8767->buck2_ramp) |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 853 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 854 | |
| 855 | if (s5m8767->buck3_ramp) |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 856 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x04, 0x04); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 857 | |
| 858 | if (s5m8767->buck4_ramp) |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 859 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x02, 0x02); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 860 | |
| 861 | if (s5m8767->buck2_ramp || s5m8767->buck3_ramp |
| 862 | || s5m8767->buck4_ramp) { |
| 863 | switch (s5m8767->ramp_delay) { |
Sangbeom Kim | 1af142c | 2012-06-13 17:27:54 +0900 | [diff] [blame] | 864 | case 5: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 865 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 1af142c | 2012-06-13 17:27:54 +0900 | [diff] [blame] | 866 | 0x40, 0xf0); |
| 867 | break; |
| 868 | case 10: |
Linus Torvalds | 3e701cd | 2012-07-30 12:41:17 -0700 | [diff] [blame] | 869 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 1af142c | 2012-06-13 17:27:54 +0900 | [diff] [blame] | 870 | 0x90, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 871 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 872 | case 25: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 873 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 874 | 0xd0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 875 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 876 | case 50: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 877 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 878 | 0xe0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 879 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 880 | case 100: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 881 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 882 | 0xf0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 883 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 884 | default: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 885 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 886 | 0x90, 0xf0); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | for (i = 0; i < pdata->num_regulators; i++) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 891 | const struct sec_voltage_desc *desc; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 892 | int id = pdata->regulators[i].id; |
| 893 | |
| 894 | desc = reg_voltage_map[id]; |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 895 | if (desc) { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 896 | regulators[id].n_voltages = |
| 897 | (desc->max - desc->min) / desc->step + 1; |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 898 | regulators[id].min_uV = desc->min; |
| 899 | regulators[id].uV_step = desc->step; |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame] | 900 | regulators[id].vsel_reg = |
| 901 | s5m8767_get_vsel_reg(id, s5m8767); |
| 902 | if (id < S5M8767_BUCK1) |
| 903 | regulators[id].vsel_mask = 0x3f; |
| 904 | else |
| 905 | regulators[id].vsel_mask = 0xff; |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 906 | } |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 907 | |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 908 | config.dev = s5m8767->dev; |
| 909 | config.init_data = pdata->regulators[i].initdata; |
| 910 | config.driver_data = s5m8767; |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame] | 911 | config.regmap = iodev->regmap; |
Amit Daniel Kachhap | 26aec009 | 2013-02-03 15:49:47 -0800 | [diff] [blame^] | 912 | config.of_node = pdata->regulators[i].reg_node; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 913 | |
| 914 | rdev[i] = regulator_register(®ulators[id], &config); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 915 | if (IS_ERR(rdev[i])) { |
| 916 | ret = PTR_ERR(rdev[i]); |
| 917 | dev_err(s5m8767->dev, "regulator init failed for %d\n", |
| 918 | id); |
| 919 | rdev[i] = NULL; |
| 920 | goto err; |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | return 0; |
| 925 | err: |
| 926 | for (i = 0; i < s5m8767->num_regulators; i++) |
| 927 | if (rdev[i]) |
| 928 | regulator_unregister(rdev[i]); |
| 929 | |
| 930 | return ret; |
| 931 | } |
| 932 | |
Bill Pemberton | 8dc995f | 2012-11-19 13:26:10 -0500 | [diff] [blame] | 933 | static int s5m8767_pmic_remove(struct platform_device *pdev) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 934 | { |
| 935 | struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev); |
| 936 | struct regulator_dev **rdev = s5m8767->rdev; |
| 937 | int i; |
| 938 | |
| 939 | for (i = 0; i < s5m8767->num_regulators; i++) |
| 940 | if (rdev[i]) |
| 941 | regulator_unregister(rdev[i]); |
| 942 | |
| 943 | return 0; |
| 944 | } |
| 945 | |
| 946 | static const struct platform_device_id s5m8767_pmic_id[] = { |
| 947 | { "s5m8767-pmic", 0}, |
| 948 | { }, |
| 949 | }; |
| 950 | MODULE_DEVICE_TABLE(platform, s5m8767_pmic_id); |
| 951 | |
| 952 | static struct platform_driver s5m8767_pmic_driver = { |
| 953 | .driver = { |
| 954 | .name = "s5m8767-pmic", |
| 955 | .owner = THIS_MODULE, |
| 956 | }, |
| 957 | .probe = s5m8767_pmic_probe, |
Bill Pemberton | 5eb9f2b | 2012-11-19 13:20:42 -0500 | [diff] [blame] | 958 | .remove = s5m8767_pmic_remove, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 959 | .id_table = s5m8767_pmic_id, |
| 960 | }; |
| 961 | |
| 962 | static int __init s5m8767_pmic_init(void) |
| 963 | { |
| 964 | return platform_driver_register(&s5m8767_pmic_driver); |
| 965 | } |
| 966 | subsys_initcall(s5m8767_pmic_init); |
| 967 | |
| 968 | static void __exit s5m8767_pmic_exit(void) |
| 969 | { |
| 970 | platform_driver_unregister(&s5m8767_pmic_driver); |
| 971 | } |
| 972 | module_exit(s5m8767_pmic_exit); |
| 973 | |
| 974 | /* Module information */ |
| 975 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
| 976 | MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver"); |
| 977 | MODULE_LICENSE("GPL"); |