blob: 8e1b68a20ef04fb38b462ebaf890d0b448382c2a [file] [log] [blame]
David Brownellfa16a5c2009-02-08 10:37:06 -08001/*
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01002 * twl-regulator.c -- support regulators in twl4030/twl6030 family chips
David Brownellfa16a5c2009-02-08 10:37:06 -08003 *
4 * Copyright (C) 2008 David Brownell
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/err.h>
15#include <linux/platform_device.h>
16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h>
Santosh Shilimkarb07682b2009-12-13 20:05:51 +010018#include <linux/i2c/twl.h>
David Brownellfa16a5c2009-02-08 10:37:06 -080019
20
21/*
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010022 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
David Brownellfa16a5c2009-02-08 10:37:06 -080023 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions
24 * include an audio codec, battery charger, and more voltage regulators.
25 * These chips are often used in OMAP-based systems.
26 *
27 * This driver implements software-based resource control for various
28 * voltage regulators. This is usually augmented with state machine
29 * based control.
30 */
31
32struct twlreg_info {
33 /* start of regulator's PM_RECEIVER control register bank */
34 u8 base;
35
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010036 /* twl resource ID, for resource control state machine */
David Brownellfa16a5c2009-02-08 10:37:06 -080037 u8 id;
38
39 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
40 u8 table_len;
41 const u16 *table;
42
43 /* chip constraints on regulator behavior */
44 u16 min_mV;
David Brownellfa16a5c2009-02-08 10:37:06 -080045
46 /* used by regulator core */
47 struct regulator_desc desc;
48};
49
50
51/* LDO control registers ... offset is from the base of its register bank.
52 * The first three registers of all power resource banks help hardware to
53 * manage the various resource groups.
54 */
55#define VREG_GRP 0
56#define VREG_TYPE 1
57#define VREG_REMAP 2
58#define VREG_DEDICATED 3 /* LDO control */
59
60
61static inline int
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010062twlreg_read(struct twlreg_info *info, unsigned offset)
David Brownellfa16a5c2009-02-08 10:37:06 -080063{
64 u8 value;
65 int status;
66
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010067 status = twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER,
David Brownellfa16a5c2009-02-08 10:37:06 -080068 &value, info->base + offset);
69 return (status < 0) ? status : value;
70}
71
72static inline int
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010073twlreg_write(struct twlreg_info *info, unsigned offset, u8 value)
David Brownellfa16a5c2009-02-08 10:37:06 -080074{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010075 return twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER,
David Brownellfa16a5c2009-02-08 10:37:06 -080076 value, info->base + offset);
77}
78
79/*----------------------------------------------------------------------*/
80
81/* generic power resource operations, which work on all regulators */
82
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010083static int twlreg_grp(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -080084{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010085 return twlreg_read(rdev_get_drvdata(rdev), VREG_GRP);
David Brownellfa16a5c2009-02-08 10:37:06 -080086}
87
88/*
89 * Enable/disable regulators by joining/leaving the P1 (processor) group.
90 * We assume nobody else is updating the DEV_GRP registers.
91 */
92
93#define P3_GRP BIT(7) /* "peripherals" */
94#define P2_GRP BIT(6) /* secondary processor, modem, etc */
95#define P1_GRP BIT(5) /* CPU/Linux */
96
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010097static int twlreg_is_enabled(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -080098{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010099 int state = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800100
101 if (state < 0)
102 return state;
103
104 return (state & P1_GRP) != 0;
105}
106
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100107static int twlreg_enable(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800108{
109 struct twlreg_info *info = rdev_get_drvdata(rdev);
110 int grp;
111
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100112 grp = twlreg_read(info, VREG_GRP);
David Brownellfa16a5c2009-02-08 10:37:06 -0800113 if (grp < 0)
114 return grp;
115
116 grp |= P1_GRP;
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100117 return twlreg_write(info, VREG_GRP, grp);
David Brownellfa16a5c2009-02-08 10:37:06 -0800118}
119
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100120static int twlreg_disable(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800121{
122 struct twlreg_info *info = rdev_get_drvdata(rdev);
123 int grp;
124
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100125 grp = twlreg_read(info, VREG_GRP);
David Brownellfa16a5c2009-02-08 10:37:06 -0800126 if (grp < 0)
127 return grp;
128
129 grp &= ~P1_GRP;
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100130 return twlreg_write(info, VREG_GRP, grp);
David Brownellfa16a5c2009-02-08 10:37:06 -0800131}
132
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100133static int twlreg_get_status(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800134{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100135 int state = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800136
137 if (state < 0)
138 return state;
139 state &= 0x0f;
140
141 /* assume state != WARM_RESET; we'd not be running... */
142 if (!state)
143 return REGULATOR_STATUS_OFF;
144 return (state & BIT(3))
145 ? REGULATOR_STATUS_NORMAL
146 : REGULATOR_STATUS_STANDBY;
147}
148
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100149static int twlreg_set_mode(struct regulator_dev *rdev, unsigned mode)
David Brownellfa16a5c2009-02-08 10:37:06 -0800150{
151 struct twlreg_info *info = rdev_get_drvdata(rdev);
152 unsigned message;
153 int status;
154
155 /* We can only set the mode through state machine commands... */
156 switch (mode) {
157 case REGULATOR_MODE_NORMAL:
158 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
159 break;
160 case REGULATOR_MODE_STANDBY:
161 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
162 break;
163 default:
164 return -EINVAL;
165 }
166
167 /* Ensure the resource is associated with some group */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100168 status = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800169 if (status < 0)
170 return status;
171 if (!(status & (P3_GRP | P2_GRP | P1_GRP)))
172 return -EACCES;
173
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100174 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
David Brownellfa16a5c2009-02-08 10:37:06 -0800175 message >> 8, 0x15 /* PB_WORD_MSB */ );
176 if (status >= 0)
177 return status;
178
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100179 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
David Brownellfa16a5c2009-02-08 10:37:06 -0800180 message, 0x16 /* PB_WORD_LSB */ );
181}
182
183/*----------------------------------------------------------------------*/
184
185/*
186 * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
187 * select field in its control register. We use tables indexed by VSEL
188 * to record voltages in milliVolts. (Accuracy is about three percent.)
189 *
190 * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
191 * currently handled by listing two slightly different VAUX2 regulators,
192 * only one of which will be configured.
193 *
194 * VSEL values documented as "TI cannot support these values" are flagged
195 * in these tables as UNSUP() values; we normally won't assign them.
Adrian Hunterd6bb69c2009-03-06 14:51:30 +0200196 *
197 * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
198 * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
David Brownellfa16a5c2009-02-08 10:37:06 -0800199 */
200#ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED
201#define UNSUP_MASK 0x0000
202#else
203#define UNSUP_MASK 0x8000
204#endif
205
206#define UNSUP(x) (UNSUP_MASK | (x))
207#define IS_UNSUP(x) (UNSUP_MASK & (x))
208#define LDO_MV(x) (~UNSUP_MASK & (x))
209
210
211static const u16 VAUX1_VSEL_table[] = {
212 UNSUP(1500), UNSUP(1800), 2500, 2800,
213 3000, 3000, 3000, 3000,
214};
215static const u16 VAUX2_4030_VSEL_table[] = {
216 UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
217 1500, 1800, UNSUP(1850), 2500,
218 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
219 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
220};
221static const u16 VAUX2_VSEL_table[] = {
222 1700, 1700, 1900, 1300,
223 1500, 1800, 2000, 2500,
224 2100, 2800, 2200, 2300,
225 2400, 2400, 2400, 2400,
226};
227static const u16 VAUX3_VSEL_table[] = {
228 1500, 1800, 2500, 2800,
Adrian Hunterd6bb69c2009-03-06 14:51:30 +0200229 3000, 3000, 3000, 3000,
David Brownellfa16a5c2009-02-08 10:37:06 -0800230};
231static const u16 VAUX4_VSEL_table[] = {
232 700, 1000, 1200, UNSUP(1300),
233 1500, 1800, UNSUP(1850), 2500,
David Brownell1897e742009-03-10 11:51:15 -0800234 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
235 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
David Brownellfa16a5c2009-02-08 10:37:06 -0800236};
237static const u16 VMMC1_VSEL_table[] = {
238 1850, 2850, 3000, 3150,
239};
240static const u16 VMMC2_VSEL_table[] = {
241 UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
242 UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
243 2600, 2800, 2850, 3000,
244 3150, 3150, 3150, 3150,
245};
246static const u16 VPLL1_VSEL_table[] = {
247 1000, 1200, 1300, 1800,
248 UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
249};
250static const u16 VPLL2_VSEL_table[] = {
251 700, 1000, 1200, 1300,
252 UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
253 UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
254 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
255};
256static const u16 VSIM_VSEL_table[] = {
257 UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
258 2800, 3000, 3000, 3000,
259};
260static const u16 VDAC_VSEL_table[] = {
261 1200, 1300, 1800, 1800,
262};
263
264
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100265static int twlldo_list_voltage(struct regulator_dev *rdev, unsigned index)
David Brownell66b659e2009-02-26 11:50:14 -0800266{
267 struct twlreg_info *info = rdev_get_drvdata(rdev);
268 int mV = info->table[index];
269
270 return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000);
271}
272
David Brownellfa16a5c2009-02-08 10:37:06 -0800273static int
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100274twlldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
David Brownellfa16a5c2009-02-08 10:37:06 -0800275{
276 struct twlreg_info *info = rdev_get_drvdata(rdev);
277 int vsel;
278
279 for (vsel = 0; vsel < info->table_len; vsel++) {
280 int mV = info->table[vsel];
281 int uV;
282
283 if (IS_UNSUP(mV))
284 continue;
285 uV = LDO_MV(mV) * 1000;
286
David Brownell66b659e2009-02-26 11:50:14 -0800287 /* REVISIT for VAUX2, first match may not be best/lowest */
288
David Brownellfa16a5c2009-02-08 10:37:06 -0800289 /* use the first in-range value */
290 if (min_uV <= uV && uV <= max_uV)
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100291 return twlreg_write(info, VREG_DEDICATED, vsel);
David Brownellfa16a5c2009-02-08 10:37:06 -0800292 }
293
294 return -EDOM;
295}
296
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100297static int twlldo_get_voltage(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800298{
299 struct twlreg_info *info = rdev_get_drvdata(rdev);
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100300 int vsel = twlreg_read(info, VREG_DEDICATED);
David Brownellfa16a5c2009-02-08 10:37:06 -0800301
302 if (vsel < 0)
303 return vsel;
304
305 vsel &= info->table_len - 1;
306 return LDO_MV(info->table[vsel]) * 1000;
307}
308
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100309static struct regulator_ops twlldo_ops = {
310 .list_voltage = twlldo_list_voltage,
David Brownell66b659e2009-02-26 11:50:14 -0800311
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100312 .set_voltage = twlldo_set_voltage,
313 .get_voltage = twlldo_get_voltage,
David Brownellfa16a5c2009-02-08 10:37:06 -0800314
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100315 .enable = twlreg_enable,
316 .disable = twlreg_disable,
317 .is_enabled = twlreg_is_enabled,
David Brownellfa16a5c2009-02-08 10:37:06 -0800318
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100319 .set_mode = twlreg_set_mode,
David Brownellfa16a5c2009-02-08 10:37:06 -0800320
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100321 .get_status = twlreg_get_status,
David Brownellfa16a5c2009-02-08 10:37:06 -0800322};
323
324/*----------------------------------------------------------------------*/
325
326/*
327 * Fixed voltage LDOs don't have a VSEL field to update.
328 */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100329static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
David Brownell66b659e2009-02-26 11:50:14 -0800330{
331 struct twlreg_info *info = rdev_get_drvdata(rdev);
332
333 return info->min_mV * 1000;
334}
335
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100336static int twlfixed_get_voltage(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800337{
338 struct twlreg_info *info = rdev_get_drvdata(rdev);
339
340 return info->min_mV * 1000;
341}
342
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100343static struct regulator_ops twlfixed_ops = {
344 .list_voltage = twlfixed_list_voltage,
David Brownell66b659e2009-02-26 11:50:14 -0800345
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100346 .get_voltage = twlfixed_get_voltage,
David Brownellfa16a5c2009-02-08 10:37:06 -0800347
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100348 .enable = twlreg_enable,
349 .disable = twlreg_disable,
350 .is_enabled = twlreg_is_enabled,
David Brownellfa16a5c2009-02-08 10:37:06 -0800351
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100352 .set_mode = twlreg_set_mode,
David Brownellfa16a5c2009-02-08 10:37:06 -0800353
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100354 .get_status = twlreg_get_status,
David Brownellfa16a5c2009-02-08 10:37:06 -0800355};
356
357/*----------------------------------------------------------------------*/
358
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100359#define TWL4030_ADJUSTABLE_LDO(label, offset, num) \
360 TWL_ADJUSTABLE_LDO(label, offset, num, TWL4030)
361#define TWL4030_FIXED_LDO(label, offset, mVolts, num) \
362 TWL_FIXED_LDO(label, offset, mVolts, num, TWL4030)
363
364#define TWL_ADJUSTABLE_LDO(label, offset, num, family) { \
David Brownellfa16a5c2009-02-08 10:37:06 -0800365 .base = offset, \
366 .id = num, \
367 .table_len = ARRAY_SIZE(label##_VSEL_table), \
368 .table = label##_VSEL_table, \
369 .desc = { \
370 .name = #label, \
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100371 .id = family##_REG_##label, \
David Brownell66b659e2009-02-26 11:50:14 -0800372 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100373 .ops = &twlldo_ops, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800374 .type = REGULATOR_VOLTAGE, \
375 .owner = THIS_MODULE, \
376 }, \
377 }
378
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100379#define TWL_FIXED_LDO(label, offset, mVolts, num, family) { \
David Brownellfa16a5c2009-02-08 10:37:06 -0800380 .base = offset, \
381 .id = num, \
382 .min_mV = mVolts, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800383 .desc = { \
384 .name = #label, \
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100385 .id = family##_REG_##label, \
David Brownell66b659e2009-02-26 11:50:14 -0800386 .n_voltages = 1, \
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100387 .ops = &twlfixed_ops, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800388 .type = REGULATOR_VOLTAGE, \
389 .owner = THIS_MODULE, \
390 }, \
391 }
392
393/*
394 * We list regulators here if systems need some level of
395 * software control over them after boot.
396 */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100397static struct twlreg_info twl_regs[] = {
398 TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1),
399 TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2),
400 TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2),
401 TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3),
402 TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4),
403 TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5),
404 TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6),
David Brownellfa16a5c2009-02-08 10:37:06 -0800405 /*
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100406 TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7),
David Brownellfa16a5c2009-02-08 10:37:06 -0800407 */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100408 TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8),
409 TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9),
410 TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10),
David Brownellfa16a5c2009-02-08 10:37:06 -0800411 /*
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100412 TWL4030_ADJUSTABLE_LDO(VINTANA1, 0x3f, 11),
413 TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12),
414 TWL4030_ADJUSTABLE_LDO(VINTDIG, 0x47, 13),
415 TWL4030_SMPS(VIO, 0x4b, 14),
416 TWL4030_SMPS(VDD1, 0x55, 15),
417 TWL4030_SMPS(VDD2, 0x63, 16),
David Brownellfa16a5c2009-02-08 10:37:06 -0800418 */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100419 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17),
420 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18),
421 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19),
David Brownellfa16a5c2009-02-08 10:37:06 -0800422 /* VUSBCP is managed *only* by the USB subchip */
423};
424
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100425static int twlreg_probe(struct platform_device *pdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800426{
427 int i;
428 struct twlreg_info *info;
429 struct regulator_init_data *initdata;
430 struct regulation_constraints *c;
431 struct regulator_dev *rdev;
David Brownellfa16a5c2009-02-08 10:37:06 -0800432
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100433 for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
434 if (twl_regs[i].desc.id != pdev->id)
David Brownellfa16a5c2009-02-08 10:37:06 -0800435 continue;
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100436 info = twl_regs + i;
David Brownellfa16a5c2009-02-08 10:37:06 -0800437 break;
438 }
439 if (!info)
440 return -ENODEV;
441
442 initdata = pdev->dev.platform_data;
443 if (!initdata)
444 return -EINVAL;
445
446 /* Constrain board-specific capabilities according to what
447 * this driver and the chip itself can actually do.
448 */
449 c = &initdata->constraints;
David Brownellfa16a5c2009-02-08 10:37:06 -0800450 c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
451 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
452 | REGULATOR_CHANGE_MODE
453 | REGULATOR_CHANGE_STATUS;
454
455 rdev = regulator_register(&info->desc, &pdev->dev, initdata, info);
456 if (IS_ERR(rdev)) {
457 dev_err(&pdev->dev, "can't register %s, %ld\n",
458 info->desc.name, PTR_ERR(rdev));
459 return PTR_ERR(rdev);
460 }
461 platform_set_drvdata(pdev, rdev);
462
463 /* NOTE: many regulators support short-circuit IRQs (presentable
464 * as REGULATOR_OVER_CURRENT notifications?) configured via:
465 * - SC_CONFIG
466 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
467 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
468 * - IT_CONFIG
469 */
470
471 return 0;
472}
473
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100474static int __devexit twlreg_remove(struct platform_device *pdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800475{
476 regulator_unregister(platform_get_drvdata(pdev));
477 return 0;
478}
479
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100480MODULE_ALIAS("platform:twl_reg");
David Brownellfa16a5c2009-02-08 10:37:06 -0800481
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100482static struct platform_driver twlreg_driver = {
483 .probe = twlreg_probe,
484 .remove = __devexit_p(twlreg_remove),
David Brownellfa16a5c2009-02-08 10:37:06 -0800485 /* NOTE: short name, to work around driver model truncation of
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100486 * "twl_regulator.12" (and friends) to "twl_regulator.1".
David Brownellfa16a5c2009-02-08 10:37:06 -0800487 */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100488 .driver.name = "twl_reg",
David Brownellfa16a5c2009-02-08 10:37:06 -0800489 .driver.owner = THIS_MODULE,
490};
491
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100492static int __init twlreg_init(void)
David Brownellfa16a5c2009-02-08 10:37:06 -0800493{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100494 return platform_driver_register(&twlreg_driver);
David Brownellfa16a5c2009-02-08 10:37:06 -0800495}
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100496subsys_initcall(twlreg_init);
David Brownellfa16a5c2009-02-08 10:37:06 -0800497
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100498static void __exit twlreg_exit(void)
David Brownellfa16a5c2009-02-08 10:37:06 -0800499{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100500 platform_driver_unregister(&twlreg_driver);
David Brownellfa16a5c2009-02-08 10:37:06 -0800501}
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100502module_exit(twlreg_exit)
David Brownellfa16a5c2009-02-08 10:37:06 -0800503
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100504MODULE_DESCRIPTION("TWL regulator driver");
David Brownellfa16a5c2009-02-08 10:37:06 -0800505MODULE_LICENSE("GPL");