diff options
author | Kyungmin Park <kyungmin.park@samsung.com> | 2010-06-16 03:04:16 -0400 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2010-08-11 06:38:00 -0400 |
commit | 156f252857dfd81f03d77d09e33b5f7d2b113e2b (patch) | |
tree | 1614c00b1996ae5a805d9d27661026796d1403fa /drivers/regulator | |
parent | 51bd6943cd760a55f655830b3f7dca8a06b54c73 (diff) |
drivers: regulator: add Maxim 8998 driver
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This patch adds voltage regulator driver for Maxim 8998 chip. This chip
is used on Samsung Aquila and GONI boards and provides following
functionalities:
- 4 BUCK voltage converters, 17 LDO power regulators and 5 other power
controllers
- battery charger
This patch adds basic driver for voltage regulators and MAX 8998 MFD core.
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Samuel Ortiz <sameo@linux.intel.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/Kconfig | 9 | ||||
-rw-r--r-- | drivers/regulator/Makefile | 1 | ||||
-rw-r--r-- | drivers/regulator/max8998.c | 610 |
3 files changed, 620 insertions, 0 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 6bf56c93a336..671b81a39482 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
@@ -100,6 +100,15 @@ config REGULATOR_MAX8925 | |||
100 | help | 100 | help |
101 | Say y here to support the voltage regulaltor of Maxim MAX8925 PMIC. | 101 | Say y here to support the voltage regulaltor of Maxim MAX8925 PMIC. |
102 | 102 | ||
103 | config REGULATOR_MAX8998 | ||
104 | tristate "Maxim 8998 voltage regulator" | ||
105 | depends on I2C | ||
106 | default n | ||
107 | help | ||
108 | This driver controls a Maxim 8998 voltage output regulator | ||
109 | via I2C bus. The provided regulator is suitable for S3C6410 | ||
110 | and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages. | ||
111 | |||
103 | config REGULATOR_TWL4030 | 112 | config REGULATOR_TWL4030 |
104 | bool "TI TWL4030/TWL5030/TWL6030/TPS695x0 PMIC" | 113 | bool "TI TWL4030/TWL5030/TWL6030/TPS695x0 PMIC" |
105 | depends on TWL4030_CORE | 114 | depends on TWL4030_CORE |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 451a14a873f6..74a4638bd9a6 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -17,6 +17,7 @@ obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o | |||
17 | obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o | 17 | obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o |
18 | obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o | 18 | obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o |
19 | obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o | 19 | obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o |
20 | obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o | ||
20 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o | 21 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o |
21 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o | 22 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o |
22 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o | 23 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o |
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c new file mode 100644 index 000000000000..174fd1957ae4 --- /dev/null +++ b/drivers/regulator/max8998.c | |||
@@ -0,0 +1,610 @@ | |||
1 | /* | ||
2 | * max8998.c - Voltage regulator driver for the Maxim 8998 | ||
3 | * | ||
4 | * Copyright (C) 2009-2010 Samsung Electronics | ||
5 | * Kyungmin Park <kyungmin.park@samsung.com> | ||
6 | * Marek Szyprowski <m.szyprowski@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 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/i2c.h> | ||
26 | #include <linux/err.h> | ||
27 | #include <linux/gpio.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/interrupt.h> | ||
30 | #include <linux/mutex.h> | ||
31 | #include <linux/platform_device.h> | ||
32 | #include <linux/regulator/driver.h> | ||
33 | #include <linux/mfd/max8998.h> | ||
34 | #include <linux/mfd/max8998-private.h> | ||
35 | |||
36 | struct max8998_data { | ||
37 | struct device *dev; | ||
38 | struct max8998_dev *iodev; | ||
39 | int num_regulators; | ||
40 | struct regulator_dev **rdev; | ||
41 | }; | ||
42 | |||
43 | struct voltage_map_desc { | ||
44 | int min; | ||
45 | int max; | ||
46 | int step; | ||
47 | }; | ||
48 | |||
49 | /* Voltage maps */ | ||
50 | static const struct voltage_map_desc ldo23_voltage_map_desc = { | ||
51 | .min = 800, .step = 50, .max = 1300, | ||
52 | }; | ||
53 | static const struct voltage_map_desc ldo456711_voltage_map_desc = { | ||
54 | .min = 1600, .step = 100, .max = 3600, | ||
55 | }; | ||
56 | static const struct voltage_map_desc ldo8_voltage_map_desc = { | ||
57 | .min = 3000, .step = 100, .max = 3600, | ||
58 | }; | ||
59 | static const struct voltage_map_desc ldo9_voltage_map_desc = { | ||
60 | .min = 2800, .step = 100, .max = 3100, | ||
61 | }; | ||
62 | static const struct voltage_map_desc ldo10_voltage_map_desc = { | ||
63 | .min = 950, .step = 50, .max = 1300, | ||
64 | }; | ||
65 | static const struct voltage_map_desc ldo1213_voltage_map_desc = { | ||
66 | .min = 800, .step = 100, .max = 3300, | ||
67 | }; | ||
68 | static const struct voltage_map_desc ldo1415_voltage_map_desc = { | ||
69 | .min = 1200, .step = 100, .max = 3300, | ||
70 | }; | ||
71 | static const struct voltage_map_desc ldo1617_voltage_map_desc = { | ||
72 | .min = 1600, .step = 100, .max = 3600, | ||
73 | }; | ||
74 | static const struct voltage_map_desc buck12_voltage_map_desc = { | ||
75 | .min = 750, .step = 25, .max = 1525, | ||
76 | }; | ||
77 | static const struct voltage_map_desc buck3_voltage_map_desc = { | ||
78 | .min = 1600, .step = 100, .max = 3600, | ||
79 | }; | ||
80 | static const struct voltage_map_desc buck4_voltage_map_desc = { | ||
81 | .min = 800, .step = 100, .max = 2300, | ||
82 | }; | ||
83 | |||
84 | static const struct voltage_map_desc *ldo_voltage_map[] = { | ||
85 | NULL, | ||
86 | NULL, | ||
87 | &ldo23_voltage_map_desc, /* LDO2 */ | ||
88 | &ldo23_voltage_map_desc, /* LDO3 */ | ||
89 | &ldo456711_voltage_map_desc, /* LDO4 */ | ||
90 | &ldo456711_voltage_map_desc, /* LDO5 */ | ||
91 | &ldo456711_voltage_map_desc, /* LDO6 */ | ||
92 | &ldo456711_voltage_map_desc, /* LDO7 */ | ||
93 | &ldo8_voltage_map_desc, /* LDO8 */ | ||
94 | &ldo9_voltage_map_desc, /* LDO9 */ | ||
95 | &ldo10_voltage_map_desc, /* LDO10 */ | ||
96 | &ldo456711_voltage_map_desc, /* LDO11 */ | ||
97 | &ldo1213_voltage_map_desc, /* LDO12 */ | ||
98 | &ldo1213_voltage_map_desc, /* LDO13 */ | ||
99 | &ldo1415_voltage_map_desc, /* LDO14 */ | ||
100 | &ldo1415_voltage_map_desc, /* LDO15 */ | ||
101 | &ldo1617_voltage_map_desc, /* LDO16 */ | ||
102 | &ldo1617_voltage_map_desc, /* LDO17 */ | ||
103 | &buck12_voltage_map_desc, /* BUCK1 */ | ||
104 | &buck12_voltage_map_desc, /* BUCK2 */ | ||
105 | &buck3_voltage_map_desc, /* BUCK3 */ | ||
106 | &buck4_voltage_map_desc, /* BUCK4 */ | ||
107 | }; | ||
108 | |||
109 | static inline int max8998_get_ldo(struct regulator_dev *rdev) | ||
110 | { | ||
111 | return rdev_get_id(rdev); | ||
112 | } | ||
113 | |||
114 | static int max8998_list_voltage(struct regulator_dev *rdev, | ||
115 | unsigned int selector) | ||
116 | { | ||
117 | const struct voltage_map_desc *desc; | ||
118 | int ldo = max8998_get_ldo(rdev); | ||
119 | int val; | ||
120 | |||
121 | if (ldo > ARRAY_SIZE(ldo_voltage_map)) | ||
122 | return -EINVAL; | ||
123 | |||
124 | desc = ldo_voltage_map[ldo]; | ||
125 | if (desc == NULL) | ||
126 | return -EINVAL; | ||
127 | |||
128 | val = desc->min + desc->step * selector; | ||
129 | if (val > desc->max) | ||
130 | return -EINVAL; | ||
131 | |||
132 | return val * 1000; | ||
133 | } | ||
134 | |||
135 | static int max8998_get_enable_register(struct regulator_dev *rdev, | ||
136 | int *reg, int *shift) | ||
137 | { | ||
138 | int ldo = max8998_get_ldo(rdev); | ||
139 | |||
140 | switch (ldo) { | ||
141 | case MAX8998_LDO2 ... MAX8998_LDO5: | ||
142 | *reg = MAX8998_REG_ONOFF1; | ||
143 | *shift = 3 - (ldo - MAX8998_LDO2); | ||
144 | break; | ||
145 | case MAX8998_LDO6 ... MAX8998_LDO13: | ||
146 | *reg = MAX8998_REG_ONOFF2; | ||
147 | *shift = 7 - (ldo - MAX8998_LDO6); | ||
148 | break; | ||
149 | case MAX8998_LDO14 ... MAX8998_LDO17: | ||
150 | *reg = MAX8998_REG_ONOFF3; | ||
151 | *shift = 7 - (ldo - MAX8998_LDO14); | ||
152 | break; | ||
153 | case MAX8998_BUCK1 ... MAX8998_BUCK4: | ||
154 | *reg = MAX8998_REG_ONOFF1; | ||
155 | *shift = 7 - (ldo - MAX8998_BUCK1); | ||
156 | break; | ||
157 | case MAX8998_EN32KHZ_AP ... MAX8998_ENVICHG: | ||
158 | *reg = MAX8998_REG_ONOFF4; | ||
159 | *shift = 7 - (ldo - MAX8998_EN32KHZ_AP); | ||
160 | break; | ||
161 | case MAX8998_ESAFEOUT1 ... MAX8998_ESAFEOUT2: | ||
162 | *reg = MAX8998_REG_CHGR2; | ||
163 | *shift = 7 - (ldo - MAX8998_ESAFEOUT1); | ||
164 | break; | ||
165 | default: | ||
166 | return -EINVAL; | ||
167 | } | ||
168 | |||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | static int max8998_ldo_is_enabled(struct regulator_dev *rdev) | ||
173 | { | ||
174 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | ||
175 | int ret, reg, shift = 8; | ||
176 | u8 val; | ||
177 | |||
178 | ret = max8998_get_enable_register(rdev, ®, &shift); | ||
179 | if (ret) | ||
180 | return ret; | ||
181 | |||
182 | ret = max8998_read_reg(max8998->iodev, reg, &val); | ||
183 | if (ret) | ||
184 | return ret; | ||
185 | |||
186 | return val & (1 << shift); | ||
187 | } | ||
188 | |||
189 | static int max8998_ldo_enable(struct regulator_dev *rdev) | ||
190 | { | ||
191 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | ||
192 | int reg, shift = 8, ret; | ||
193 | |||
194 | ret = max8998_get_enable_register(rdev, ®, &shift); | ||
195 | if (ret) | ||
196 | return ret; | ||
197 | |||
198 | return max8998_update_reg(max8998->iodev, reg, 1<<shift, 1<<shift); | ||
199 | } | ||
200 | |||
201 | static int max8998_ldo_disable(struct regulator_dev *rdev) | ||
202 | { | ||
203 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | ||
204 | int reg, shift = 8, ret; | ||
205 | |||
206 | ret = max8998_get_enable_register(rdev, ®, &shift); | ||
207 | if (ret) | ||
208 | return ret; | ||
209 | |||
210 | return max8998_update_reg(max8998->iodev, reg, 0, 1<<shift); | ||
211 | } | ||
212 | |||
213 | static int max8998_get_voltage_register(struct regulator_dev *rdev, | ||
214 | int *_reg, int *_shift, int *_mask) | ||
215 | { | ||
216 | int ldo = max8998_get_ldo(rdev); | ||
217 | int reg, shift = 0, mask = 0xff; | ||
218 | |||
219 | switch (ldo) { | ||
220 | case MAX8998_LDO2 ... MAX8998_LDO3: | ||
221 | reg = MAX8998_REG_LDO2_LDO3; | ||
222 | mask = 0xf; | ||
223 | if (ldo == MAX8998_LDO2) | ||
224 | shift = 4; | ||
225 | else | ||
226 | shift = 0; | ||
227 | break; | ||
228 | case MAX8998_LDO4 ... MAX8998_LDO7: | ||
229 | reg = MAX8998_REG_LDO4 + (ldo - MAX8998_LDO4); | ||
230 | break; | ||
231 | case MAX8998_LDO8 ... MAX8998_LDO9: | ||
232 | reg = MAX8998_REG_LDO8_LDO9; | ||
233 | mask = 0xf; | ||
234 | if (ldo == MAX8998_LDO8) | ||
235 | shift = 4; | ||
236 | else | ||
237 | shift = 0; | ||
238 | break; | ||
239 | case MAX8998_LDO10 ... MAX8998_LDO11: | ||
240 | reg = MAX8998_REG_LDO10_LDO11; | ||
241 | if (ldo == MAX8998_LDO10) { | ||
242 | shift = 5; | ||
243 | mask = 0x7; | ||
244 | } else { | ||
245 | shift = 0; | ||
246 | mask = 0x1f; | ||
247 | } | ||
248 | break; | ||
249 | case MAX8998_LDO12 ... MAX8998_LDO17: | ||
250 | reg = MAX8998_REG_LDO12 + (ldo - MAX8998_LDO12); | ||
251 | break; | ||
252 | case MAX8998_BUCK1: | ||
253 | reg = MAX8998_REG_BUCK1_DVSARM1; | ||
254 | break; | ||
255 | case MAX8998_BUCK2: | ||
256 | reg = MAX8998_REG_BUCK2_DVSINT1; | ||
257 | break; | ||
258 | case MAX8998_BUCK3: | ||
259 | reg = MAX8998_REG_BUCK3; | ||
260 | break; | ||
261 | case MAX8998_BUCK4: | ||
262 | reg = MAX8998_REG_BUCK4; | ||
263 | break; | ||
264 | default: | ||
265 | return -EINVAL; | ||
266 | } | ||
267 | |||
268 | *_reg = reg; | ||
269 | *_shift = shift; | ||
270 | *_mask = mask; | ||
271 | |||
272 | return 0; | ||
273 | } | ||
274 | |||
275 | static int max8998_get_voltage(struct regulator_dev *rdev) | ||
276 | { | ||
277 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | ||
278 | int reg, shift = 0, mask, ret; | ||
279 | u8 val; | ||
280 | |||
281 | ret = max8998_get_voltage_register(rdev, ®, &shift, &mask); | ||
282 | if (ret) | ||
283 | return ret; | ||
284 | |||
285 | ret = max8998_read_reg(max8998->iodev, reg, &val); | ||
286 | if (ret) | ||
287 | return ret; | ||
288 | |||
289 | val >>= shift; | ||
290 | val &= mask; | ||
291 | |||
292 | return max8998_list_voltage(rdev, val); | ||
293 | } | ||
294 | |||
295 | static int max8998_set_voltage(struct regulator_dev *rdev, | ||
296 | int min_uV, int max_uV) | ||
297 | { | ||
298 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | ||
299 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | ||
300 | const struct voltage_map_desc *desc; | ||
301 | int ldo = max8998_get_ldo(rdev); | ||
302 | int reg, shift = 0, mask, ret; | ||
303 | int i = 0; | ||
304 | |||
305 | if (ldo > ARRAY_SIZE(ldo_voltage_map)) | ||
306 | return -EINVAL; | ||
307 | |||
308 | desc = ldo_voltage_map[ldo]; | ||
309 | if (desc == NULL) | ||
310 | return -EINVAL; | ||
311 | |||
312 | if (max_vol < desc->min || min_vol > desc->max) | ||
313 | return -EINVAL; | ||
314 | |||
315 | while (desc->min + desc->step*i < max_vol && | ||
316 | desc->min + desc->step*i < desc->max) | ||
317 | i++; | ||
318 | |||
319 | ret = max8998_get_voltage_register(rdev, ®, &shift, &mask); | ||
320 | if (ret) | ||
321 | return ret; | ||
322 | |||
323 | return max8998_update_reg(max8998->iodev, reg, i<<shift, mask<<shift); | ||
324 | } | ||
325 | |||
326 | static struct regulator_ops max8998_ldo_ops = { | ||
327 | .list_voltage = max8998_list_voltage, | ||
328 | .is_enabled = max8998_ldo_is_enabled, | ||
329 | .enable = max8998_ldo_enable, | ||
330 | .disable = max8998_ldo_disable, | ||
331 | .get_voltage = max8998_get_voltage, | ||
332 | .set_voltage = max8998_set_voltage, | ||
333 | .set_suspend_enable = max8998_ldo_enable, | ||
334 | .set_suspend_disable = max8998_ldo_disable, | ||
335 | }; | ||
336 | |||
337 | static struct regulator_ops max8998_buck_ops = { | ||
338 | .list_voltage = max8998_list_voltage, | ||
339 | .is_enabled = max8998_ldo_is_enabled, | ||
340 | .enable = max8998_ldo_enable, | ||
341 | .disable = max8998_ldo_disable, | ||
342 | .get_voltage = max8998_get_voltage, | ||
343 | .set_voltage = max8998_set_voltage, | ||
344 | .set_suspend_enable = max8998_ldo_enable, | ||
345 | .set_suspend_disable = max8998_ldo_disable, | ||
346 | }; | ||
347 | |||
348 | static struct regulator_ops max8998_others_ops = { | ||
349 | .is_enabled = max8998_ldo_is_enabled, | ||
350 | .enable = max8998_ldo_enable, | ||
351 | .disable = max8998_ldo_disable, | ||
352 | .set_suspend_enable = max8998_ldo_enable, | ||
353 | .set_suspend_disable = max8998_ldo_disable, | ||
354 | }; | ||
355 | |||
356 | static struct regulator_desc regulators[] = { | ||
357 | { | ||
358 | .name = "LDO2", | ||
359 | .id = MAX8998_LDO2, | ||
360 | .ops = &max8998_ldo_ops, | ||
361 | .type = REGULATOR_VOLTAGE, | ||
362 | .owner = THIS_MODULE, | ||
363 | }, { | ||
364 | .name = "LDO3", | ||
365 | .id = MAX8998_LDO3, | ||
366 | .ops = &max8998_ldo_ops, | ||
367 | .type = REGULATOR_VOLTAGE, | ||
368 | .owner = THIS_MODULE, | ||
369 | }, { | ||
370 | .name = "LDO4", | ||
371 | .id = MAX8998_LDO4, | ||
372 | .ops = &max8998_ldo_ops, | ||
373 | .type = REGULATOR_VOLTAGE, | ||
374 | .owner = THIS_MODULE, | ||
375 | }, { | ||
376 | .name = "LDO5", | ||
377 | .id = MAX8998_LDO5, | ||
378 | .ops = &max8998_ldo_ops, | ||
379 | .type = REGULATOR_VOLTAGE, | ||
380 | .owner = THIS_MODULE, | ||
381 | }, { | ||
382 | .name = "LDO6", | ||
383 | .id = MAX8998_LDO6, | ||
384 | .ops = &max8998_ldo_ops, | ||
385 | .type = REGULATOR_VOLTAGE, | ||
386 | .owner = THIS_MODULE, | ||
387 | }, { | ||
388 | .name = "LDO7", | ||
389 | .id = MAX8998_LDO7, | ||
390 | .ops = &max8998_ldo_ops, | ||
391 | .type = REGULATOR_VOLTAGE, | ||
392 | .owner = THIS_MODULE, | ||
393 | }, { | ||
394 | .name = "LDO8", | ||
395 | .id = MAX8998_LDO8, | ||
396 | .ops = &max8998_ldo_ops, | ||
397 | .type = REGULATOR_VOLTAGE, | ||
398 | .owner = THIS_MODULE, | ||
399 | }, { | ||
400 | .name = "LDO9", | ||
401 | .id = MAX8998_LDO9, | ||
402 | .ops = &max8998_ldo_ops, | ||
403 | .type = REGULATOR_VOLTAGE, | ||
404 | .owner = THIS_MODULE, | ||
405 | }, { | ||
406 | .name = "LDO10", | ||
407 | .id = MAX8998_LDO10, | ||
408 | .ops = &max8998_ldo_ops, | ||
409 | .type = REGULATOR_VOLTAGE, | ||
410 | .owner = THIS_MODULE, | ||
411 | }, { | ||
412 | .name = "LDO11", | ||
413 | .id = MAX8998_LDO11, | ||
414 | .ops = &max8998_ldo_ops, | ||
415 | .type = REGULATOR_VOLTAGE, | ||
416 | .owner = THIS_MODULE, | ||
417 | }, { | ||
418 | .name = "LDO12", | ||
419 | .id = MAX8998_LDO12, | ||
420 | .ops = &max8998_ldo_ops, | ||
421 | .type = REGULATOR_VOLTAGE, | ||
422 | .owner = THIS_MODULE, | ||
423 | }, { | ||
424 | .name = "LDO13", | ||
425 | .id = MAX8998_LDO13, | ||
426 | .ops = &max8998_ldo_ops, | ||
427 | .type = REGULATOR_VOLTAGE, | ||
428 | .owner = THIS_MODULE, | ||
429 | }, { | ||
430 | .name = "LDO14", | ||
431 | .id = MAX8998_LDO14, | ||
432 | .ops = &max8998_ldo_ops, | ||
433 | .type = REGULATOR_VOLTAGE, | ||
434 | .owner = THIS_MODULE, | ||
435 | }, { | ||
436 | .name = "LDO15", | ||
437 | .id = MAX8998_LDO15, | ||
438 | .ops = &max8998_ldo_ops, | ||
439 | .type = REGULATOR_VOLTAGE, | ||
440 | .owner = THIS_MODULE, | ||
441 | }, { | ||
442 | .name = "LDO16", | ||
443 | .id = MAX8998_LDO16, | ||
444 | .ops = &max8998_ldo_ops, | ||
445 | .type = REGULATOR_VOLTAGE, | ||
446 | .owner = THIS_MODULE, | ||
447 | }, { | ||
448 | .name = "LDO17", | ||
449 | .id = MAX8998_LDO17, | ||
450 | .ops = &max8998_ldo_ops, | ||
451 | .type = REGULATOR_VOLTAGE, | ||
452 | .owner = THIS_MODULE, | ||
453 | }, { | ||
454 | .name = "BUCK1", | ||
455 | .id = MAX8998_BUCK1, | ||
456 | .ops = &max8998_buck_ops, | ||
457 | .type = REGULATOR_VOLTAGE, | ||
458 | .owner = THIS_MODULE, | ||
459 | }, { | ||
460 | .name = "BUCK2", | ||
461 | .id = MAX8998_BUCK2, | ||
462 | .ops = &max8998_buck_ops, | ||
463 | .type = REGULATOR_VOLTAGE, | ||
464 | .owner = THIS_MODULE, | ||
465 | }, { | ||
466 | .name = "BUCK3", | ||
467 | .id = MAX8998_BUCK3, | ||
468 | .ops = &max8998_buck_ops, | ||
469 | .type = REGULATOR_VOLTAGE, | ||
470 | .owner = THIS_MODULE, | ||
471 | }, { | ||
472 | .name = "BUCK4", | ||
473 | .id = MAX8998_BUCK4, | ||
474 | .ops = &max8998_buck_ops, | ||
475 | .type = REGULATOR_VOLTAGE, | ||
476 | .owner = THIS_MODULE, | ||
477 | }, { | ||
478 | .name = "EN32KHz AP", | ||
479 | .id = MAX8998_EN32KHZ_AP, | ||
480 | .ops = &max8998_others_ops, | ||
481 | .type = REGULATOR_VOLTAGE, | ||
482 | .owner = THIS_MODULE, | ||
483 | }, { | ||
484 | .name = "EN32KHz CP", | ||
485 | .id = MAX8998_EN32KHZ_CP, | ||
486 | .ops = &max8998_others_ops, | ||
487 | .type = REGULATOR_VOLTAGE, | ||
488 | .owner = THIS_MODULE, | ||
489 | }, { | ||
490 | .name = "ENVICHG", | ||
491 | .id = MAX8998_ENVICHG, | ||
492 | .ops = &max8998_others_ops, | ||
493 | .type = REGULATOR_VOLTAGE, | ||
494 | .owner = THIS_MODULE, | ||
495 | }, { | ||
496 | .name = "ESAFEOUT1", | ||
497 | .id = MAX8998_ESAFEOUT1, | ||
498 | .ops = &max8998_others_ops, | ||
499 | .type = REGULATOR_VOLTAGE, | ||
500 | .owner = THIS_MODULE, | ||
501 | }, { | ||
502 | .name = "ESAFEOUT2", | ||
503 | .id = MAX8998_ESAFEOUT2, | ||
504 | .ops = &max8998_others_ops, | ||
505 | .type = REGULATOR_VOLTAGE, | ||
506 | .owner = THIS_MODULE, | ||
507 | } | ||
508 | }; | ||
509 | |||
510 | static __devinit int max8998_pmic_probe(struct platform_device *pdev) | ||
511 | { | ||
512 | struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent); | ||
513 | struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev); | ||
514 | struct regulator_dev **rdev; | ||
515 | struct max8998_data *max8998; | ||
516 | int i, ret, size; | ||
517 | |||
518 | if (!pdata) { | ||
519 | dev_err(pdev->dev.parent, "No platform init data supplied\n"); | ||
520 | return -ENODEV; | ||
521 | } | ||
522 | |||
523 | max8998 = kzalloc(sizeof(struct max8998_data), GFP_KERNEL); | ||
524 | if (!max8998) | ||
525 | return -ENOMEM; | ||
526 | |||
527 | size = sizeof(struct regulator_dev *) * (pdata->num_regulators + 1); | ||
528 | max8998->rdev = kzalloc(size, GFP_KERNEL); | ||
529 | if (!max8998->rdev) { | ||
530 | kfree(max8998); | ||
531 | return -ENOMEM; | ||
532 | } | ||
533 | |||
534 | rdev = max8998->rdev; | ||
535 | max8998->iodev = iodev; | ||
536 | platform_set_drvdata(pdev, max8998); | ||
537 | |||
538 | for (i = 0; i < pdata->num_regulators; i++) { | ||
539 | const struct voltage_map_desc *desc; | ||
540 | int id = pdata->regulators[i].id; | ||
541 | int index = id - MAX8998_LDO2; | ||
542 | |||
543 | desc = ldo_voltage_map[id]; | ||
544 | if (desc && regulators[index].ops != &max8998_others_ops) { | ||
545 | int count = (desc->max - desc->min) / desc->step + 1; | ||
546 | regulators[index].n_voltages = count; | ||
547 | } | ||
548 | rdev[i] = regulator_register(®ulators[index], max8998->dev, | ||
549 | pdata->regulators[i].initdata, max8998); | ||
550 | if (IS_ERR(rdev[i])) { | ||
551 | ret = PTR_ERR(rdev[i]); | ||
552 | dev_err(max8998->dev, "regulator init failed\n"); | ||
553 | rdev[i] = NULL; | ||
554 | goto err; | ||
555 | } | ||
556 | } | ||
557 | |||
558 | |||
559 | return 0; | ||
560 | err: | ||
561 | for (i = 0; i <= max8998->num_regulators; i++) | ||
562 | if (rdev[i]) | ||
563 | regulator_unregister(rdev[i]); | ||
564 | |||
565 | kfree(max8998->rdev); | ||
566 | kfree(max8998); | ||
567 | |||
568 | return ret; | ||
569 | } | ||
570 | |||
571 | static int __devexit max8998_pmic_remove(struct platform_device *pdev) | ||
572 | { | ||
573 | struct max8998_data *max8998 = platform_get_drvdata(pdev); | ||
574 | struct regulator_dev **rdev = max8998->rdev; | ||
575 | int i; | ||
576 | |||
577 | for (i = 0; i <= max8998->num_regulators; i++) | ||
578 | if (rdev[i]) | ||
579 | regulator_unregister(rdev[i]); | ||
580 | |||
581 | kfree(max8998->rdev); | ||
582 | kfree(max8998); | ||
583 | |||
584 | return 0; | ||
585 | } | ||
586 | |||
587 | static struct platform_driver max8998_pmic_driver = { | ||
588 | .driver = { | ||
589 | .name = "max8998-pmic", | ||
590 | .owner = THIS_MODULE, | ||
591 | }, | ||
592 | .probe = max8998_pmic_probe, | ||
593 | .remove = __devexit_p(max8998_pmic_remove), | ||
594 | }; | ||
595 | |||
596 | static int __init max8998_pmic_init(void) | ||
597 | { | ||
598 | return platform_driver_register(&max8998_pmic_driver); | ||
599 | } | ||
600 | subsys_initcall(max8998_pmic_init); | ||
601 | |||
602 | static void __exit max8998_pmic_cleanup(void) | ||
603 | { | ||
604 | platform_driver_unregister(&max8998_pmic_driver); | ||
605 | } | ||
606 | module_exit(max8998_pmic_cleanup); | ||
607 | |||
608 | MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver"); | ||
609 | MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>"); | ||
610 | MODULE_LICENSE("GPL"); | ||