blob: b85040caaea318b13154927bc1beb0e13aef6ad4 [file] [log] [blame]
Jonghwa Lee133d4012012-06-01 13:17:14 +09001/*
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 Brar4706fca2012-07-05 09:28:25 +053034#include <linux/regulator/of_regulator.h>
Jonghwa Lee133d4012012-06-01 13:17:14 +090035#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 Brar852abad2012-06-19 13:23:42 +053044#define MAX77686_RAMP_DELAY 100000 /* uV/us */
45#define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */
Jonghwa Lee133d4012012-06-01 13:17:14 +090046#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
61enum max77686_ramp_rate {
62 RAMP_RATE_13P75MV,
63 RAMP_RATE_27P5MV,
64 RAMP_RATE_55MV,
65 RAMP_RATE_NO_CTRL, /* 100mV/us */
66};
67
68struct max77686_data {
Axel Lincb44cde2012-08-05 10:11:16 +080069 struct regulator_dev *rdev[MAX77686_REGULATORS];
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +053070 unsigned int opmode[MAX77686_REGULATORS];
Jonghwa Lee133d4012012-06-01 13:17:14 +090071};
72
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +053073/* Some BUCKS supports Normal[ON/OFF] mode during suspend */
74static int max77686_buck_set_suspend_disable(struct regulator_dev *rdev)
75{
76 unsigned int val;
77 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
78
79 if (rdev->desc->id == MAX77686_BUCK1)
80 val = 0x1;
81 else
82 val = 0x1 << MAX77686_OPMODE_BUCK234_SHIFT;
83
84 max77686->opmode[rdev->desc->id] = val;
85 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
86 rdev->desc->enable_mask,
87 val);
88}
89
90/* Some LDOs supports [LPM/Normal]ON mode during suspend state */
91static int max77686_set_suspend_mode(struct regulator_dev *rdev,
92 unsigned int mode)
93{
94 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
95 unsigned int val;
96
97 /* BUCK[5-9] doesn't support this feature */
98 if (rdev->desc->id >= MAX77686_BUCK5)
99 return 0;
100
101 switch (mode) {
102 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
103 val = 0x2 << MAX77686_OPMODE_SHIFT;
104 break;
105 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
106 val = 0x3 << MAX77686_OPMODE_SHIFT;
107 break;
108 default:
109 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
110 rdev->desc->name, mode);
111 return -EINVAL;
112 }
113
114 max77686->opmode[rdev->desc->id] = val;
115 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
116 rdev->desc->enable_mask,
117 val);
118}
119
120/* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */
121static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
122 unsigned int mode)
123{
124 unsigned int val;
125 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
126
127 switch (mode) {
128 case REGULATOR_MODE_STANDBY: /* switch off */
129 val = 0x1 << MAX77686_OPMODE_SHIFT;
130 break;
131 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
132 val = 0x2 << MAX77686_OPMODE_SHIFT;
133 break;
134 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
135 val = 0x3 << MAX77686_OPMODE_SHIFT;
136 break;
137 default:
138 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
139 rdev->desc->name, mode);
140 return -EINVAL;
141 }
142
143 max77686->opmode[rdev->desc->id] = val;
144 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
145 rdev->desc->enable_mask,
146 val);
147}
148
Yadwinder Singh Brar38d34032012-10-22 09:39:28 +0530149static int max77686_enable(struct regulator_dev *rdev)
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530150{
151 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
152
153 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
154 rdev->desc->enable_mask,
155 max77686->opmode[rdev->desc->id]);
156}
157
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530158static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
159{
160 unsigned int ramp_value = RAMP_RATE_NO_CTRL;
161
162 switch (ramp_delay) {
163 case 1 ... 13750:
164 ramp_value = RAMP_RATE_13P75MV;
165 break;
166 case 13751 ... 27500:
167 ramp_value = RAMP_RATE_27P5MV;
168 break;
169 case 27501 ... 55000:
170 ramp_value = RAMP_RATE_55MV;
171 break;
172 case 55001 ... 100000:
173 break;
174 default:
175 pr_warn("%s: ramp_delay: %d not supported, setting 100000\n",
176 rdev->desc->name, ramp_delay);
177 }
178
179 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
180 MAX77686_RAMP_RATE_MASK, ramp_value << 6);
181}
182
Jonghwa Lee133d4012012-06-01 13:17:14 +0900183static struct regulator_ops max77686_ops = {
184 .list_voltage = regulator_list_voltage_linear,
Axel Lin2e3f7f22012-06-03 22:46:14 +0800185 .map_voltage = regulator_map_voltage_linear,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900186 .is_enabled = regulator_is_enabled_regmap,
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530187 .enable = max77686_enable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900188 .disable = regulator_disable_regmap,
189 .get_voltage_sel = regulator_get_voltage_sel_regmap,
190 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530191 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530192 .set_suspend_mode = max77686_set_suspend_mode,
193};
194
195static struct regulator_ops max77686_ldo_ops = {
196 .list_voltage = regulator_list_voltage_linear,
197 .map_voltage = regulator_map_voltage_linear,
198 .is_enabled = regulator_is_enabled_regmap,
199 .enable = max77686_enable,
200 .disable = regulator_disable_regmap,
201 .get_voltage_sel = regulator_get_voltage_sel_regmap,
202 .set_voltage_sel = regulator_set_voltage_sel_regmap,
203 .set_voltage_time_sel = regulator_set_voltage_time_sel,
204 .set_suspend_mode = max77686_ldo_set_suspend_mode,
205};
206
207static struct regulator_ops max77686_buck1_ops = {
208 .list_voltage = regulator_list_voltage_linear,
209 .map_voltage = regulator_map_voltage_linear,
210 .is_enabled = regulator_is_enabled_regmap,
211 .enable = max77686_enable,
212 .disable = regulator_disable_regmap,
213 .get_voltage_sel = regulator_get_voltage_sel_regmap,
214 .set_voltage_sel = regulator_set_voltage_sel_regmap,
215 .set_voltage_time_sel = regulator_set_voltage_time_sel,
216 .set_suspend_disable = max77686_buck_set_suspend_disable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900217};
218
219static struct regulator_ops max77686_buck_dvs_ops = {
220 .list_voltage = regulator_list_voltage_linear,
Axel Lin2e3f7f22012-06-03 22:46:14 +0800221 .map_voltage = regulator_map_voltage_linear,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900222 .is_enabled = regulator_is_enabled_regmap,
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530223 .enable = max77686_enable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900224 .disable = regulator_disable_regmap,
225 .get_voltage_sel = regulator_get_voltage_sel_regmap,
226 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530227 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530228 .set_ramp_delay = max77686_set_ramp_delay,
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530229 .set_suspend_disable = max77686_buck_set_suspend_disable,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900230};
231
232#define regulator_desc_ldo(num) { \
233 .name = "LDO"#num, \
234 .id = MAX77686_LDO##num, \
235 .ops = &max77686_ops, \
236 .type = REGULATOR_VOLTAGE, \
237 .owner = THIS_MODULE, \
238 .min_uV = MAX77686_LDO_MINUV, \
239 .uV_step = MAX77686_LDO_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530240 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900241 .n_voltages = MAX77686_VSEL_MASK + 1, \
242 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
243 .vsel_mask = MAX77686_VSEL_MASK, \
244 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
245 .enable_mask = MAX77686_OPMODE_MASK \
246 << MAX77686_OPMODE_SHIFT, \
247}
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530248#define regulator_desc_lpm_ldo(num) { \
249 .name = "LDO"#num, \
250 .id = MAX77686_LDO##num, \
251 .ops = &max77686_ldo_ops, \
252 .type = REGULATOR_VOLTAGE, \
253 .owner = THIS_MODULE, \
254 .min_uV = MAX77686_LDO_MINUV, \
255 .uV_step = MAX77686_LDO_UVSTEP, \
256 .ramp_delay = MAX77686_RAMP_DELAY, \
257 .n_voltages = MAX77686_VSEL_MASK + 1, \
258 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
259 .vsel_mask = MAX77686_VSEL_MASK, \
260 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
261 .enable_mask = MAX77686_OPMODE_MASK \
262 << MAX77686_OPMODE_SHIFT, \
263}
Jonghwa Lee133d4012012-06-01 13:17:14 +0900264#define regulator_desc_ldo_low(num) { \
265 .name = "LDO"#num, \
266 .id = MAX77686_LDO##num, \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530267 .ops = &max77686_ldo_ops, \
268 .type = REGULATOR_VOLTAGE, \
269 .owner = THIS_MODULE, \
270 .min_uV = MAX77686_LDO_LOW_MINUV, \
271 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
272 .ramp_delay = MAX77686_RAMP_DELAY, \
273 .n_voltages = MAX77686_VSEL_MASK + 1, \
274 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
275 .vsel_mask = MAX77686_VSEL_MASK, \
276 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
277 .enable_mask = MAX77686_OPMODE_MASK \
278 << MAX77686_OPMODE_SHIFT, \
279}
280#define regulator_desc_ldo1_low(num) { \
281 .name = "LDO"#num, \
282 .id = MAX77686_LDO##num, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900283 .ops = &max77686_ops, \
284 .type = REGULATOR_VOLTAGE, \
285 .owner = THIS_MODULE, \
286 .min_uV = MAX77686_LDO_LOW_MINUV, \
287 .uV_step = MAX77686_LDO_LOW_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530288 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900289 .n_voltages = MAX77686_VSEL_MASK + 1, \
290 .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
291 .vsel_mask = MAX77686_VSEL_MASK, \
292 .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
293 .enable_mask = MAX77686_OPMODE_MASK \
294 << MAX77686_OPMODE_SHIFT, \
295}
296#define regulator_desc_buck(num) { \
297 .name = "BUCK"#num, \
298 .id = MAX77686_BUCK##num, \
299 .ops = &max77686_ops, \
300 .type = REGULATOR_VOLTAGE, \
301 .owner = THIS_MODULE, \
302 .min_uV = MAX77686_BUCK_MINUV, \
303 .uV_step = MAX77686_BUCK_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530304 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900305 .n_voltages = MAX77686_VSEL_MASK + 1, \
306 .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \
307 .vsel_mask = MAX77686_VSEL_MASK, \
308 .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \
309 .enable_mask = MAX77686_OPMODE_MASK, \
310}
311#define regulator_desc_buck1(num) { \
312 .name = "BUCK"#num, \
313 .id = MAX77686_BUCK##num, \
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530314 .ops = &max77686_buck1_ops, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900315 .type = REGULATOR_VOLTAGE, \
316 .owner = THIS_MODULE, \
317 .min_uV = MAX77686_BUCK_MINUV, \
318 .uV_step = MAX77686_BUCK_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530319 .ramp_delay = MAX77686_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900320 .n_voltages = MAX77686_VSEL_MASK + 1, \
321 .vsel_reg = MAX77686_REG_BUCK1OUT, \
322 .vsel_mask = MAX77686_VSEL_MASK, \
323 .enable_reg = MAX77686_REG_BUCK1CTRL, \
324 .enable_mask = MAX77686_OPMODE_MASK, \
325}
326#define regulator_desc_buck_dvs(num) { \
327 .name = "BUCK"#num, \
328 .id = MAX77686_BUCK##num, \
Axel Lin74adfee52012-06-04 10:19:18 +0800329 .ops = &max77686_buck_dvs_ops, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900330 .type = REGULATOR_VOLTAGE, \
331 .owner = THIS_MODULE, \
332 .min_uV = MAX77686_DVS_MINUV, \
333 .uV_step = MAX77686_DVS_UVSTEP, \
Yadwinder Singh Brar852abad2012-06-19 13:23:42 +0530334 .ramp_delay = MAX77686_DVS_RAMP_DELAY, \
Jonghwa Lee133d4012012-06-01 13:17:14 +0900335 .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \
336 .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \
337 .vsel_mask = MAX77686_DVS_VSEL_MASK, \
338 .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \
339 .enable_mask = MAX77686_OPMODE_MASK \
340 << MAX77686_OPMODE_BUCK234_SHIFT, \
341}
342
343static struct regulator_desc regulators[] = {
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530344 regulator_desc_ldo1_low(1),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900345 regulator_desc_ldo_low(2),
346 regulator_desc_ldo(3),
347 regulator_desc_ldo(4),
348 regulator_desc_ldo(5),
349 regulator_desc_ldo_low(6),
350 regulator_desc_ldo_low(7),
351 regulator_desc_ldo_low(8),
352 regulator_desc_ldo(9),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530353 regulator_desc_lpm_ldo(10),
354 regulator_desc_lpm_ldo(11),
355 regulator_desc_lpm_ldo(12),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900356 regulator_desc_ldo(13),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530357 regulator_desc_lpm_ldo(14),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900358 regulator_desc_ldo_low(15),
Yadwinder Singh Brar15282ba2012-10-16 17:24:19 +0530359 regulator_desc_lpm_ldo(16),
Jonghwa Lee133d4012012-06-01 13:17:14 +0900360 regulator_desc_ldo(17),
361 regulator_desc_ldo(18),
362 regulator_desc_ldo(19),
363 regulator_desc_ldo(20),
364 regulator_desc_ldo(21),
365 regulator_desc_ldo(22),
366 regulator_desc_ldo(23),
367 regulator_desc_ldo(24),
368 regulator_desc_ldo(25),
369 regulator_desc_ldo(26),
370 regulator_desc_buck1(1),
371 regulator_desc_buck_dvs(2),
372 regulator_desc_buck_dvs(3),
373 regulator_desc_buck_dvs(4),
374 regulator_desc_buck(5),
375 regulator_desc_buck(6),
376 regulator_desc_buck(7),
377 regulator_desc_buck(8),
378 regulator_desc_buck(9),
379};
380
Yadwinder Singh Brar4706fca2012-07-05 09:28:25 +0530381#ifdef CONFIG_OF
382static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev,
383 struct max77686_platform_data *pdata)
384{
385 struct device_node *pmic_np, *regulators_np;
386 struct max77686_regulator_data *rdata;
387 struct of_regulator_match rmatch;
388 unsigned int i;
389
390 pmic_np = iodev->dev->of_node;
391 regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators");
392 if (!regulators_np) {
393 dev_err(iodev->dev, "could not find regulators sub-node\n");
394 return -EINVAL;
395 }
396
397 pdata->num_regulators = ARRAY_SIZE(regulators);
398 rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *
399 pdata->num_regulators, GFP_KERNEL);
400 if (!rdata) {
401 dev_err(iodev->dev,
402 "could not allocate memory for regulator data\n");
403 return -ENOMEM;
404 }
405
406 for (i = 0; i < pdata->num_regulators; i++) {
407 rmatch.name = regulators[i].name;
408 rmatch.init_data = NULL;
Yadwinder Singh Brard1ef0652012-07-06 14:50:08 +0530409 rmatch.of_node = NULL;
Yadwinder Singh Brar4706fca2012-07-05 09:28:25 +0530410 of_regulator_match(iodev->dev, regulators_np, &rmatch, 1);
411 rdata[i].initdata = rmatch.init_data;
Axel Lin2c58e262012-08-05 10:09:57 +0800412 rdata[i].of_node = rmatch.of_node;
Yadwinder Singh Brar4706fca2012-07-05 09:28:25 +0530413 }
414
415 pdata->regulators = rdata;
416
417 return 0;
418}
419#else
420static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev,
421 struct max77686_platform_data *pdata)
422{
423 return 0;
424}
425#endif /* CONFIG_OF */
426
Bill Pembertona5023572012-11-19 13:22:22 -0500427static int max77686_pmic_probe(struct platform_device *pdev)
Jonghwa Lee133d4012012-06-01 13:17:14 +0900428{
429 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
430 struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev);
Jonghwa Lee133d4012012-06-01 13:17:14 +0900431 struct max77686_data *max77686;
Axel Lincb44cde2012-08-05 10:11:16 +0800432 int i, ret = 0;
Axel Linc59d2a62012-06-20 15:01:25 +0800433 struct regulator_config config = { };
Jonghwa Lee133d4012012-06-01 13:17:14 +0900434
435 dev_dbg(&pdev->dev, "%s\n", __func__);
436
Yadwinder Singh Brar4706fca2012-07-05 09:28:25 +0530437 if (!pdata) {
438 dev_err(&pdev->dev, "no platform data found for regulator\n");
439 return -ENODEV;
440 }
441
442 if (iodev->dev->of_node) {
443 ret = max77686_pmic_dt_parse_pdata(iodev, pdata);
444 if (ret)
445 return ret;
446 }
447
448 if (pdata->num_regulators != MAX77686_REGULATORS) {
Axel Linab0d1cb2012-06-08 12:03:04 +0800449 dev_err(&pdev->dev,
450 "Invalid initial data for regulator's initialiation\n");
451 return -EINVAL;
452 }
453
Jonghwa Lee133d4012012-06-01 13:17:14 +0900454 max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
455 GFP_KERNEL);
456 if (!max77686)
457 return -ENOMEM;
458
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530459 config.dev = &pdev->dev;
460 config.regmap = iodev->regmap;
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530461 config.driver_data = max77686;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900462 platform_set_drvdata(pdev, max77686);
463
Axel Linab0d1cb2012-06-08 12:03:04 +0800464 for (i = 0; i < MAX77686_REGULATORS; i++) {
Axel Linab0d1cb2012-06-08 12:03:04 +0800465 config.init_data = pdata->regulators[i].initdata;
Axel Lin2c58e262012-08-05 10:09:57 +0800466 config.of_node = pdata->regulators[i].of_node;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900467
Yadwinder Singh Brar6d2c8962012-10-16 17:24:18 +0530468 max77686->opmode[i] = regulators[i].enable_mask;
Axel Lincb44cde2012-08-05 10:11:16 +0800469 max77686->rdev[i] = regulator_register(&regulators[i], &config);
470 if (IS_ERR(max77686->rdev[i])) {
471 ret = PTR_ERR(max77686->rdev[i]);
Yadwinder Singh Brarf5030712012-06-20 10:50:51 +0530472 dev_err(&pdev->dev,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900473 "regulator init failed for %d\n", i);
Axel Lincb44cde2012-08-05 10:11:16 +0800474 max77686->rdev[i] = NULL;
475 goto err;
Jonghwa Lee133d4012012-06-01 13:17:14 +0900476 }
Jonghwa Lee133d4012012-06-01 13:17:14 +0900477 }
Axel Linab0d1cb2012-06-08 12:03:04 +0800478
Jonghwa Lee133d4012012-06-01 13:17:14 +0900479 return 0;
480err:
Axel Linab0d1cb2012-06-08 12:03:04 +0800481 while (--i >= 0)
Axel Lincb44cde2012-08-05 10:11:16 +0800482 regulator_unregister(max77686->rdev[i]);
Jonghwa Lee133d4012012-06-01 13:17:14 +0900483 return ret;
484}
485
Bill Pemberton8dc995f2012-11-19 13:26:10 -0500486static int max77686_pmic_remove(struct platform_device *pdev)
Jonghwa Lee133d4012012-06-01 13:17:14 +0900487{
488 struct max77686_data *max77686 = platform_get_drvdata(pdev);
Jonghwa Lee133d4012012-06-01 13:17:14 +0900489 int i;
490
491 for (i = 0; i < MAX77686_REGULATORS; i++)
Axel Lincb44cde2012-08-05 10:11:16 +0800492 regulator_unregister(max77686->rdev[i]);
Jonghwa Lee133d4012012-06-01 13:17:14 +0900493
494 return 0;
495}
496
497static const struct platform_device_id max77686_pmic_id[] = {
498 {"max77686-pmic", 0},
499 { },
500};
501MODULE_DEVICE_TABLE(platform, max77686_pmic_id);
502
503static struct platform_driver max77686_pmic_driver = {
504 .driver = {
505 .name = "max77686-pmic",
506 .owner = THIS_MODULE,
507 },
508 .probe = max77686_pmic_probe,
Bill Pemberton5eb9f2b2012-11-19 13:20:42 -0500509 .remove = max77686_pmic_remove,
Jonghwa Lee133d4012012-06-01 13:17:14 +0900510 .id_table = max77686_pmic_id,
511};
512
513static int __init max77686_pmic_init(void)
514{
515 return platform_driver_register(&max77686_pmic_driver);
516}
517subsys_initcall(max77686_pmic_init);
518
519static void __exit max77686_pmic_cleanup(void)
520{
521 platform_driver_unregister(&max77686_pmic_driver);
522}
523module_exit(max77686_pmic_cleanup);
524
525MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver");
526MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
527MODULE_LICENSE("GPL");