Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 1 | /* |
| 2 | * max77686.c - Regulator driver for the Maxim 77686 |
| 3 | * |
| 4 | * Copyright (C) 2012 Samsung Electronics |
| 5 | * Chiwoong Byun <woong.byun@smasung.com> |
| 6 | * Jonghwa Lee <jonghwa3.lee@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | * This driver is based on max8997.c |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/bug.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/err.h> |
| 29 | #include <linux/gpio.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/platform_device.h> |
| 32 | #include <linux/regulator/driver.h> |
| 33 | #include <linux/regulator/machine.h> |
Yadwinder Singh Brar | 4706fca | 2012-07-05 09:28:25 +0530 | [diff] [blame] | 34 | #include <linux/regulator/of_regulator.h> |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 35 | #include <linux/mfd/max77686.h> |
| 36 | #include <linux/mfd/max77686-private.h> |
| 37 | |
| 38 | #define MAX77686_LDO_MINUV 800000 |
| 39 | #define MAX77686_LDO_UVSTEP 50000 |
| 40 | #define MAX77686_LDO_LOW_MINUV 800000 |
| 41 | #define MAX77686_LDO_LOW_UVSTEP 25000 |
| 42 | #define MAX77686_BUCK_MINUV 750000 |
| 43 | #define MAX77686_BUCK_UVSTEP 50000 |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 44 | #define MAX77686_RAMP_DELAY 100000 /* uV/us */ |
| 45 | #define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 46 | #define MAX77686_DVS_MINUV 600000 |
| 47 | #define MAX77686_DVS_UVSTEP 12500 |
| 48 | |
| 49 | #define MAX77686_OPMODE_SHIFT 6 |
| 50 | #define MAX77686_OPMODE_BUCK234_SHIFT 4 |
| 51 | #define MAX77686_OPMODE_MASK 0x3 |
| 52 | |
| 53 | #define MAX77686_VSEL_MASK 0x3F |
| 54 | #define MAX77686_DVS_VSEL_MASK 0xFF |
| 55 | |
| 56 | #define MAX77686_RAMP_RATE_MASK 0xC0 |
| 57 | |
| 58 | #define MAX77686_REGULATORS MAX77686_REG_MAX |
| 59 | #define MAX77686_LDOS 26 |
| 60 | |
| 61 | enum max77686_ramp_rate { |
| 62 | RAMP_RATE_13P75MV, |
| 63 | RAMP_RATE_27P5MV, |
| 64 | RAMP_RATE_55MV, |
| 65 | RAMP_RATE_NO_CTRL, /* 100mV/us */ |
| 66 | }; |
| 67 | |
| 68 | struct max77686_data { |
Axel Lin | cb44cde | 2012-08-05 10:11:16 +0800 | [diff] [blame] | 69 | struct regulator_dev *rdev[MAX77686_REGULATORS]; |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame^] | 70 | unsigned int opmode[MAX77686_REGULATORS]; |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 71 | }; |
| 72 | |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame^] | 73 | int max77686_enable(struct regulator_dev *rdev) |
| 74 | { |
| 75 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); |
| 76 | |
| 77 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 78 | rdev->desc->enable_mask, |
| 79 | max77686->opmode[rdev->desc->id]); |
| 80 | } |
| 81 | |
Yadwinder Singh Brar | f503071 | 2012-06-20 10:50:51 +0530 | [diff] [blame] | 82 | static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
| 83 | { |
| 84 | unsigned int ramp_value = RAMP_RATE_NO_CTRL; |
| 85 | |
| 86 | switch (ramp_delay) { |
| 87 | case 1 ... 13750: |
| 88 | ramp_value = RAMP_RATE_13P75MV; |
| 89 | break; |
| 90 | case 13751 ... 27500: |
| 91 | ramp_value = RAMP_RATE_27P5MV; |
| 92 | break; |
| 93 | case 27501 ... 55000: |
| 94 | ramp_value = RAMP_RATE_55MV; |
| 95 | break; |
| 96 | case 55001 ... 100000: |
| 97 | break; |
| 98 | default: |
| 99 | pr_warn("%s: ramp_delay: %d not supported, setting 100000\n", |
| 100 | rdev->desc->name, ramp_delay); |
| 101 | } |
| 102 | |
| 103 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 104 | MAX77686_RAMP_RATE_MASK, ramp_value << 6); |
| 105 | } |
| 106 | |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 107 | static struct regulator_ops max77686_ops = { |
| 108 | .list_voltage = regulator_list_voltage_linear, |
Axel Lin | 2e3f7f2 | 2012-06-03 22:46:14 +0800 | [diff] [blame] | 109 | .map_voltage = regulator_map_voltage_linear, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 110 | .is_enabled = regulator_is_enabled_regmap, |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame^] | 111 | .enable = max77686_enable, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 112 | .disable = regulator_disable_regmap, |
| 113 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 114 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 115 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | static struct regulator_ops max77686_buck_dvs_ops = { |
| 119 | .list_voltage = regulator_list_voltage_linear, |
Axel Lin | 2e3f7f2 | 2012-06-03 22:46:14 +0800 | [diff] [blame] | 120 | .map_voltage = regulator_map_voltage_linear, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 121 | .is_enabled = regulator_is_enabled_regmap, |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame^] | 122 | .enable = max77686_enable, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 123 | .disable = regulator_disable_regmap, |
| 124 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 125 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 126 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Yadwinder Singh Brar | f503071 | 2012-06-20 10:50:51 +0530 | [diff] [blame] | 127 | .set_ramp_delay = max77686_set_ramp_delay, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | #define regulator_desc_ldo(num) { \ |
| 131 | .name = "LDO"#num, \ |
| 132 | .id = MAX77686_LDO##num, \ |
| 133 | .ops = &max77686_ops, \ |
| 134 | .type = REGULATOR_VOLTAGE, \ |
| 135 | .owner = THIS_MODULE, \ |
| 136 | .min_uV = MAX77686_LDO_MINUV, \ |
| 137 | .uV_step = MAX77686_LDO_UVSTEP, \ |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 138 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 139 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
| 140 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 141 | .vsel_mask = MAX77686_VSEL_MASK, \ |
| 142 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 143 | .enable_mask = MAX77686_OPMODE_MASK \ |
| 144 | << MAX77686_OPMODE_SHIFT, \ |
| 145 | } |
| 146 | #define regulator_desc_ldo_low(num) { \ |
| 147 | .name = "LDO"#num, \ |
| 148 | .id = MAX77686_LDO##num, \ |
| 149 | .ops = &max77686_ops, \ |
| 150 | .type = REGULATOR_VOLTAGE, \ |
| 151 | .owner = THIS_MODULE, \ |
| 152 | .min_uV = MAX77686_LDO_LOW_MINUV, \ |
| 153 | .uV_step = MAX77686_LDO_LOW_UVSTEP, \ |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 154 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 155 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
| 156 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 157 | .vsel_mask = MAX77686_VSEL_MASK, \ |
| 158 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 159 | .enable_mask = MAX77686_OPMODE_MASK \ |
| 160 | << MAX77686_OPMODE_SHIFT, \ |
| 161 | } |
| 162 | #define regulator_desc_buck(num) { \ |
| 163 | .name = "BUCK"#num, \ |
| 164 | .id = MAX77686_BUCK##num, \ |
| 165 | .ops = &max77686_ops, \ |
| 166 | .type = REGULATOR_VOLTAGE, \ |
| 167 | .owner = THIS_MODULE, \ |
| 168 | .min_uV = MAX77686_BUCK_MINUV, \ |
| 169 | .uV_step = MAX77686_BUCK_UVSTEP, \ |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 170 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 171 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
| 172 | .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \ |
| 173 | .vsel_mask = MAX77686_VSEL_MASK, \ |
| 174 | .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \ |
| 175 | .enable_mask = MAX77686_OPMODE_MASK, \ |
| 176 | } |
| 177 | #define regulator_desc_buck1(num) { \ |
| 178 | .name = "BUCK"#num, \ |
| 179 | .id = MAX77686_BUCK##num, \ |
| 180 | .ops = &max77686_ops, \ |
| 181 | .type = REGULATOR_VOLTAGE, \ |
| 182 | .owner = THIS_MODULE, \ |
| 183 | .min_uV = MAX77686_BUCK_MINUV, \ |
| 184 | .uV_step = MAX77686_BUCK_UVSTEP, \ |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 185 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 186 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
| 187 | .vsel_reg = MAX77686_REG_BUCK1OUT, \ |
| 188 | .vsel_mask = MAX77686_VSEL_MASK, \ |
| 189 | .enable_reg = MAX77686_REG_BUCK1CTRL, \ |
| 190 | .enable_mask = MAX77686_OPMODE_MASK, \ |
| 191 | } |
| 192 | #define regulator_desc_buck_dvs(num) { \ |
| 193 | .name = "BUCK"#num, \ |
| 194 | .id = MAX77686_BUCK##num, \ |
Axel Lin | 74adfee5 | 2012-06-04 10:19:18 +0800 | [diff] [blame] | 195 | .ops = &max77686_buck_dvs_ops, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 196 | .type = REGULATOR_VOLTAGE, \ |
| 197 | .owner = THIS_MODULE, \ |
| 198 | .min_uV = MAX77686_DVS_MINUV, \ |
| 199 | .uV_step = MAX77686_DVS_UVSTEP, \ |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 200 | .ramp_delay = MAX77686_DVS_RAMP_DELAY, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 201 | .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \ |
| 202 | .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \ |
| 203 | .vsel_mask = MAX77686_DVS_VSEL_MASK, \ |
| 204 | .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \ |
| 205 | .enable_mask = MAX77686_OPMODE_MASK \ |
| 206 | << MAX77686_OPMODE_BUCK234_SHIFT, \ |
| 207 | } |
| 208 | |
| 209 | static struct regulator_desc regulators[] = { |
| 210 | regulator_desc_ldo_low(1), |
| 211 | regulator_desc_ldo_low(2), |
| 212 | regulator_desc_ldo(3), |
| 213 | regulator_desc_ldo(4), |
| 214 | regulator_desc_ldo(5), |
| 215 | regulator_desc_ldo_low(6), |
| 216 | regulator_desc_ldo_low(7), |
| 217 | regulator_desc_ldo_low(8), |
| 218 | regulator_desc_ldo(9), |
| 219 | regulator_desc_ldo(10), |
| 220 | regulator_desc_ldo(11), |
| 221 | regulator_desc_ldo(12), |
| 222 | regulator_desc_ldo(13), |
| 223 | regulator_desc_ldo(14), |
| 224 | regulator_desc_ldo_low(15), |
| 225 | regulator_desc_ldo(16), |
| 226 | regulator_desc_ldo(17), |
| 227 | regulator_desc_ldo(18), |
| 228 | regulator_desc_ldo(19), |
| 229 | regulator_desc_ldo(20), |
| 230 | regulator_desc_ldo(21), |
| 231 | regulator_desc_ldo(22), |
| 232 | regulator_desc_ldo(23), |
| 233 | regulator_desc_ldo(24), |
| 234 | regulator_desc_ldo(25), |
| 235 | regulator_desc_ldo(26), |
| 236 | regulator_desc_buck1(1), |
| 237 | regulator_desc_buck_dvs(2), |
| 238 | regulator_desc_buck_dvs(3), |
| 239 | regulator_desc_buck_dvs(4), |
| 240 | regulator_desc_buck(5), |
| 241 | regulator_desc_buck(6), |
| 242 | regulator_desc_buck(7), |
| 243 | regulator_desc_buck(8), |
| 244 | regulator_desc_buck(9), |
| 245 | }; |
| 246 | |
Yadwinder Singh Brar | 4706fca | 2012-07-05 09:28:25 +0530 | [diff] [blame] | 247 | #ifdef CONFIG_OF |
| 248 | static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev, |
| 249 | struct max77686_platform_data *pdata) |
| 250 | { |
| 251 | struct device_node *pmic_np, *regulators_np; |
| 252 | struct max77686_regulator_data *rdata; |
| 253 | struct of_regulator_match rmatch; |
| 254 | unsigned int i; |
| 255 | |
| 256 | pmic_np = iodev->dev->of_node; |
| 257 | regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators"); |
| 258 | if (!regulators_np) { |
| 259 | dev_err(iodev->dev, "could not find regulators sub-node\n"); |
| 260 | return -EINVAL; |
| 261 | } |
| 262 | |
| 263 | pdata->num_regulators = ARRAY_SIZE(regulators); |
| 264 | rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) * |
| 265 | pdata->num_regulators, GFP_KERNEL); |
| 266 | if (!rdata) { |
| 267 | dev_err(iodev->dev, |
| 268 | "could not allocate memory for regulator data\n"); |
| 269 | return -ENOMEM; |
| 270 | } |
| 271 | |
| 272 | for (i = 0; i < pdata->num_regulators; i++) { |
| 273 | rmatch.name = regulators[i].name; |
| 274 | rmatch.init_data = NULL; |
Yadwinder Singh Brar | d1ef065 | 2012-07-06 14:50:08 +0530 | [diff] [blame] | 275 | rmatch.of_node = NULL; |
Yadwinder Singh Brar | 4706fca | 2012-07-05 09:28:25 +0530 | [diff] [blame] | 276 | of_regulator_match(iodev->dev, regulators_np, &rmatch, 1); |
| 277 | rdata[i].initdata = rmatch.init_data; |
Axel Lin | 2c58e26 | 2012-08-05 10:09:57 +0800 | [diff] [blame] | 278 | rdata[i].of_node = rmatch.of_node; |
Yadwinder Singh Brar | 4706fca | 2012-07-05 09:28:25 +0530 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | pdata->regulators = rdata; |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | #else |
| 286 | static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev, |
| 287 | struct max77686_platform_data *pdata) |
| 288 | { |
| 289 | return 0; |
| 290 | } |
| 291 | #endif /* CONFIG_OF */ |
| 292 | |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 293 | static __devinit int max77686_pmic_probe(struct platform_device *pdev) |
| 294 | { |
| 295 | struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
| 296 | struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev); |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 297 | struct max77686_data *max77686; |
Axel Lin | cb44cde | 2012-08-05 10:11:16 +0800 | [diff] [blame] | 298 | int i, ret = 0; |
Axel Lin | c59d2a6 | 2012-06-20 15:01:25 +0800 | [diff] [blame] | 299 | struct regulator_config config = { }; |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 300 | |
| 301 | dev_dbg(&pdev->dev, "%s\n", __func__); |
| 302 | |
Yadwinder Singh Brar | 4706fca | 2012-07-05 09:28:25 +0530 | [diff] [blame] | 303 | if (!pdata) { |
| 304 | dev_err(&pdev->dev, "no platform data found for regulator\n"); |
| 305 | return -ENODEV; |
| 306 | } |
| 307 | |
| 308 | if (iodev->dev->of_node) { |
| 309 | ret = max77686_pmic_dt_parse_pdata(iodev, pdata); |
| 310 | if (ret) |
| 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | if (pdata->num_regulators != MAX77686_REGULATORS) { |
Axel Lin | ab0d1cb | 2012-06-08 12:03:04 +0800 | [diff] [blame] | 315 | dev_err(&pdev->dev, |
| 316 | "Invalid initial data for regulator's initialiation\n"); |
| 317 | return -EINVAL; |
| 318 | } |
| 319 | |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 320 | max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data), |
| 321 | GFP_KERNEL); |
| 322 | if (!max77686) |
| 323 | return -ENOMEM; |
| 324 | |
Yadwinder Singh Brar | f503071 | 2012-06-20 10:50:51 +0530 | [diff] [blame] | 325 | config.dev = &pdev->dev; |
| 326 | config.regmap = iodev->regmap; |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame^] | 327 | config.driver_data = max77686; |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 328 | platform_set_drvdata(pdev, max77686); |
| 329 | |
Axel Lin | ab0d1cb | 2012-06-08 12:03:04 +0800 | [diff] [blame] | 330 | for (i = 0; i < MAX77686_REGULATORS; i++) { |
Axel Lin | ab0d1cb | 2012-06-08 12:03:04 +0800 | [diff] [blame] | 331 | config.init_data = pdata->regulators[i].initdata; |
Axel Lin | 2c58e26 | 2012-08-05 10:09:57 +0800 | [diff] [blame] | 332 | config.of_node = pdata->regulators[i].of_node; |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 333 | |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame^] | 334 | max77686->opmode[i] = regulators[i].enable_mask; |
Axel Lin | cb44cde | 2012-08-05 10:11:16 +0800 | [diff] [blame] | 335 | max77686->rdev[i] = regulator_register(®ulators[i], &config); |
| 336 | if (IS_ERR(max77686->rdev[i])) { |
| 337 | ret = PTR_ERR(max77686->rdev[i]); |
Yadwinder Singh Brar | f503071 | 2012-06-20 10:50:51 +0530 | [diff] [blame] | 338 | dev_err(&pdev->dev, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 339 | "regulator init failed for %d\n", i); |
Axel Lin | cb44cde | 2012-08-05 10:11:16 +0800 | [diff] [blame] | 340 | max77686->rdev[i] = NULL; |
| 341 | goto err; |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 342 | } |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 343 | } |
Axel Lin | ab0d1cb | 2012-06-08 12:03:04 +0800 | [diff] [blame] | 344 | |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 345 | return 0; |
| 346 | err: |
Axel Lin | ab0d1cb | 2012-06-08 12:03:04 +0800 | [diff] [blame] | 347 | while (--i >= 0) |
Axel Lin | cb44cde | 2012-08-05 10:11:16 +0800 | [diff] [blame] | 348 | regulator_unregister(max77686->rdev[i]); |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 349 | return ret; |
| 350 | } |
| 351 | |
| 352 | static int __devexit max77686_pmic_remove(struct platform_device *pdev) |
| 353 | { |
| 354 | struct max77686_data *max77686 = platform_get_drvdata(pdev); |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 355 | int i; |
| 356 | |
| 357 | for (i = 0; i < MAX77686_REGULATORS; i++) |
Axel Lin | cb44cde | 2012-08-05 10:11:16 +0800 | [diff] [blame] | 358 | regulator_unregister(max77686->rdev[i]); |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | static const struct platform_device_id max77686_pmic_id[] = { |
| 364 | {"max77686-pmic", 0}, |
| 365 | { }, |
| 366 | }; |
| 367 | MODULE_DEVICE_TABLE(platform, max77686_pmic_id); |
| 368 | |
| 369 | static struct platform_driver max77686_pmic_driver = { |
| 370 | .driver = { |
| 371 | .name = "max77686-pmic", |
| 372 | .owner = THIS_MODULE, |
| 373 | }, |
| 374 | .probe = max77686_pmic_probe, |
| 375 | .remove = __devexit_p(max77686_pmic_remove), |
| 376 | .id_table = max77686_pmic_id, |
| 377 | }; |
| 378 | |
| 379 | static int __init max77686_pmic_init(void) |
| 380 | { |
| 381 | return platform_driver_register(&max77686_pmic_driver); |
| 382 | } |
| 383 | subsys_initcall(max77686_pmic_init); |
| 384 | |
| 385 | static void __exit max77686_pmic_cleanup(void) |
| 386 | { |
| 387 | platform_driver_unregister(&max77686_pmic_driver); |
| 388 | } |
| 389 | module_exit(max77686_pmic_cleanup); |
| 390 | |
| 391 | MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver"); |
| 392 | MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>"); |
| 393 | MODULE_LICENSE("GPL"); |