blob: e5d22234215706f4b055bececb0137266152e4db [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>
Juha Keski-Saari53b8a9d2009-12-16 14:55:26 +020015#include <linux/delay.h>
David Brownellfa16a5c2009-02-08 10:37:06 -080016#include <linux/platform_device.h>
17#include <linux/regulator/driver.h>
18#include <linux/regulator/machine.h>
Santosh Shilimkarb07682b2009-12-13 20:05:51 +010019#include <linux/i2c/twl.h>
David Brownellfa16a5c2009-02-08 10:37:06 -080020
21
22/*
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010023 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
David Brownellfa16a5c2009-02-08 10:37:06 -080024 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions
25 * include an audio codec, battery charger, and more voltage regulators.
26 * These chips are often used in OMAP-based systems.
27 *
28 * This driver implements software-based resource control for various
29 * voltage regulators. This is usually augmented with state machine
30 * based control.
31 */
32
33struct twlreg_info {
34 /* start of regulator's PM_RECEIVER control register bank */
35 u8 base;
36
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010037 /* twl resource ID, for resource control state machine */
David Brownellfa16a5c2009-02-08 10:37:06 -080038 u8 id;
39
40 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
41 u8 table_len;
42 const u16 *table;
43
Juha Keski-Saari045f9722009-12-16 14:49:52 +020044 /* regulator specific turn-on delay */
45 u16 delay;
46
47 /* State REMAP default configuration */
48 u8 remap;
49
David Brownellfa16a5c2009-02-08 10:37:06 -080050 /* chip constraints on regulator behavior */
51 u16 min_mV;
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +053052 u16 max_mV;
David Brownellfa16a5c2009-02-08 10:37:06 -080053
Graeme Gregory4d94aee2011-05-22 21:21:23 +010054 u8 flags;
55
David Brownellfa16a5c2009-02-08 10:37:06 -080056 /* used by regulator core */
57 struct regulator_desc desc;
Graeme Gregory4d94aee2011-05-22 21:21:23 +010058
59 /* chip specific features */
60 unsigned long features;
David Brownellfa16a5c2009-02-08 10:37:06 -080061};
62
63
64/* LDO control registers ... offset is from the base of its register bank.
65 * The first three registers of all power resource banks help hardware to
66 * manage the various resource groups.
67 */
Rajendra Nayak441a4502009-12-13 22:19:23 +010068/* Common offset in TWL4030/6030 */
David Brownellfa16a5c2009-02-08 10:37:06 -080069#define VREG_GRP 0
Rajendra Nayak441a4502009-12-13 22:19:23 +010070/* TWL4030 register offsets */
David Brownellfa16a5c2009-02-08 10:37:06 -080071#define VREG_TYPE 1
72#define VREG_REMAP 2
73#define VREG_DEDICATED 3 /* LDO control */
Tero Kristoba305e32011-11-28 16:53:19 +020074#define VREG_VOLTAGE_SMPS_4030 9
Rajendra Nayak441a4502009-12-13 22:19:23 +010075/* TWL6030 register offsets */
76#define VREG_TRANS 1
77#define VREG_STATE 2
78#define VREG_VOLTAGE 3
Graeme Gregory4d94aee2011-05-22 21:21:23 +010079#define VREG_VOLTAGE_SMPS 4
Rajendra Nayak441a4502009-12-13 22:19:23 +010080/* TWL6030 Misc register offsets */
81#define VREG_BC_ALL 1
82#define VREG_BC_REF 2
83#define VREG_BC_PROC 3
84#define VREG_BC_CLK_RST 4
David Brownellfa16a5c2009-02-08 10:37:06 -080085
Saquib Herman21657ebf2011-04-01 10:22:42 +053086/* TWL6030 LDO register values for CFG_STATE */
87#define TWL6030_CFG_STATE_OFF 0x00
88#define TWL6030_CFG_STATE_ON 0x01
Saquib Herman9a0244a2011-04-01 10:22:45 +053089#define TWL6030_CFG_STATE_OFF2 0x02
90#define TWL6030_CFG_STATE_SLEEP 0x03
Saquib Herman21657ebf2011-04-01 10:22:42 +053091#define TWL6030_CFG_STATE_GRP_SHIFT 5
Saquib Hermanb2456772011-04-01 10:22:44 +053092#define TWL6030_CFG_STATE_APP_SHIFT 2
93#define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
94#define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
95 TWL6030_CFG_STATE_APP_SHIFT)
Saquib Herman21657ebf2011-04-01 10:22:42 +053096
Graeme Gregory4d94aee2011-05-22 21:21:23 +010097/* Flags for SMPS Voltage reading */
98#define SMPS_OFFSET_EN BIT(0)
99#define SMPS_EXTENDED_EN BIT(1)
100
101/* twl6025 SMPS EPROM values */
102#define TWL6030_SMPS_OFFSET 0xB0
103#define TWL6030_SMPS_MULT 0xB3
104#define SMPS_MULTOFFSET_SMPS4 BIT(0)
105#define SMPS_MULTOFFSET_VIO BIT(1)
106#define SMPS_MULTOFFSET_SMPS3 BIT(6)
107
David Brownellfa16a5c2009-02-08 10:37:06 -0800108static inline int
Rajendra Nayak441a4502009-12-13 22:19:23 +0100109twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
David Brownellfa16a5c2009-02-08 10:37:06 -0800110{
111 u8 value;
112 int status;
113
Rajendra Nayak441a4502009-12-13 22:19:23 +0100114 status = twl_i2c_read_u8(slave_subgp,
David Brownellfa16a5c2009-02-08 10:37:06 -0800115 &value, info->base + offset);
116 return (status < 0) ? status : value;
117}
118
119static inline int
Rajendra Nayak441a4502009-12-13 22:19:23 +0100120twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
121 u8 value)
David Brownellfa16a5c2009-02-08 10:37:06 -0800122{
Rajendra Nayak441a4502009-12-13 22:19:23 +0100123 return twl_i2c_write_u8(slave_subgp,
David Brownellfa16a5c2009-02-08 10:37:06 -0800124 value, info->base + offset);
125}
126
127/*----------------------------------------------------------------------*/
128
129/* generic power resource operations, which work on all regulators */
130
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100131static int twlreg_grp(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800132{
Rajendra Nayak441a4502009-12-13 22:19:23 +0100133 return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
134 VREG_GRP);
David Brownellfa16a5c2009-02-08 10:37:06 -0800135}
136
137/*
138 * Enable/disable regulators by joining/leaving the P1 (processor) group.
139 * We assume nobody else is updating the DEV_GRP registers.
140 */
Rajendra Nayak441a4502009-12-13 22:19:23 +0100141/* definition for 4030 family */
142#define P3_GRP_4030 BIT(7) /* "peripherals" */
143#define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
144#define P1_GRP_4030 BIT(5) /* CPU/Linux */
145/* definition for 6030 family */
146#define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
147#define P2_GRP_6030 BIT(1) /* "peripherals" */
148#define P1_GRP_6030 BIT(0) /* CPU/Linux */
David Brownellfa16a5c2009-02-08 10:37:06 -0800149
Saquib Hermanb2456772011-04-01 10:22:44 +0530150static int twl4030reg_is_enabled(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800151{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100152 int state = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800153
154 if (state < 0)
155 return state;
156
Saquib Hermanb2456772011-04-01 10:22:44 +0530157 return state & P1_GRP_4030;
158}
159
160static int twl6030reg_is_enabled(struct regulator_dev *rdev)
161{
162 struct twlreg_info *info = rdev_get_drvdata(rdev);
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100163 int grp = 0, val;
Saquib Hermanb2456772011-04-01 10:22:44 +0530164
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100165 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
166 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
Saquib Hermanb2456772011-04-01 10:22:44 +0530167 if (grp < 0)
168 return grp;
169
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100170 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
171 grp &= P1_GRP_6030;
172 else
173 grp = 1;
Saquib Hermanb2456772011-04-01 10:22:44 +0530174
175 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
176 val = TWL6030_CFG_STATE_APP(val);
177
178 return grp && (val == TWL6030_CFG_STATE_ON);
David Brownellfa16a5c2009-02-08 10:37:06 -0800179}
180
Balaji T Kf8c29402011-05-20 19:03:51 +0530181static int twl4030reg_enable(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800182{
183 struct twlreg_info *info = rdev_get_drvdata(rdev);
184 int grp;
Juha Keski-Saari53b8a9d2009-12-16 14:55:26 +0200185 int ret;
David Brownellfa16a5c2009-02-08 10:37:06 -0800186
Rajendra Nayak441a4502009-12-13 22:19:23 +0100187 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
David Brownellfa16a5c2009-02-08 10:37:06 -0800188 if (grp < 0)
189 return grp;
190
Balaji T Kf8c29402011-05-20 19:03:51 +0530191 grp |= P1_GRP_4030;
Rajendra Nayak441a4502009-12-13 22:19:23 +0100192
Juha Keski-Saari53b8a9d2009-12-16 14:55:26 +0200193 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
194
Balaji T Kf8c29402011-05-20 19:03:51 +0530195 udelay(info->delay);
196
197 return ret;
198}
199
200static int twl6030reg_enable(struct regulator_dev *rdev)
201{
202 struct twlreg_info *info = rdev_get_drvdata(rdev);
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100203 int grp = 0;
Balaji T Kf8c29402011-05-20 19:03:51 +0530204 int ret;
205
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100206 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
207 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
Balaji T Kf8c29402011-05-20 19:03:51 +0530208 if (grp < 0)
209 return grp;
210
211 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
212 grp << TWL6030_CFG_STATE_GRP_SHIFT |
213 TWL6030_CFG_STATE_ON);
Saquib Herman21657ebf2011-04-01 10:22:42 +0530214
Juha Keski-Saari53b8a9d2009-12-16 14:55:26 +0200215 udelay(info->delay);
216
217 return ret;
David Brownellfa16a5c2009-02-08 10:37:06 -0800218}
219
Balaji T K0ff38972011-05-20 19:03:52 +0530220static int twl4030reg_disable(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800221{
222 struct twlreg_info *info = rdev_get_drvdata(rdev);
223 int grp;
Saquib Herman21657ebf2011-04-01 10:22:42 +0530224 int ret;
David Brownellfa16a5c2009-02-08 10:37:06 -0800225
Rajendra Nayak441a4502009-12-13 22:19:23 +0100226 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
David Brownellfa16a5c2009-02-08 10:37:06 -0800227 if (grp < 0)
228 return grp;
229
Balaji T K0ff38972011-05-20 19:03:52 +0530230 grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
Rajendra Nayak441a4502009-12-13 22:19:23 +0100231
Saquib Herman21657ebf2011-04-01 10:22:42 +0530232 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
233
Balaji T K0ff38972011-05-20 19:03:52 +0530234 return ret;
235}
236
237static int twl6030reg_disable(struct regulator_dev *rdev)
238{
239 struct twlreg_info *info = rdev_get_drvdata(rdev);
240 int grp = 0;
241 int ret;
242
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100243 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
244 grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030;
Balaji T K0ff38972011-05-20 19:03:52 +0530245
246 /* For 6030, set the off state for all grps enabled */
247 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
248 (grp) << TWL6030_CFG_STATE_GRP_SHIFT |
249 TWL6030_CFG_STATE_OFF);
Saquib Herman21657ebf2011-04-01 10:22:42 +0530250
251 return ret;
David Brownellfa16a5c2009-02-08 10:37:06 -0800252}
253
Saquib Herman9a0244a2011-04-01 10:22:45 +0530254static int twl4030reg_get_status(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800255{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100256 int state = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800257
258 if (state < 0)
259 return state;
260 state &= 0x0f;
261
262 /* assume state != WARM_RESET; we'd not be running... */
263 if (!state)
264 return REGULATOR_STATUS_OFF;
265 return (state & BIT(3))
266 ? REGULATOR_STATUS_NORMAL
267 : REGULATOR_STATUS_STANDBY;
268}
269
Saquib Herman9a0244a2011-04-01 10:22:45 +0530270static int twl6030reg_get_status(struct regulator_dev *rdev)
271{
272 struct twlreg_info *info = rdev_get_drvdata(rdev);
273 int val;
274
275 val = twlreg_grp(rdev);
276 if (val < 0)
277 return val;
278
279 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
280
281 switch (TWL6030_CFG_STATE_APP(val)) {
282 case TWL6030_CFG_STATE_ON:
283 return REGULATOR_STATUS_NORMAL;
284
285 case TWL6030_CFG_STATE_SLEEP:
286 return REGULATOR_STATUS_STANDBY;
287
288 case TWL6030_CFG_STATE_OFF:
289 case TWL6030_CFG_STATE_OFF2:
290 default:
291 break;
292 }
293
294 return REGULATOR_STATUS_OFF;
295}
296
Saquib Herman1a399622011-04-01 10:22:46 +0530297static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
David Brownellfa16a5c2009-02-08 10:37:06 -0800298{
299 struct twlreg_info *info = rdev_get_drvdata(rdev);
300 unsigned message;
301 int status;
302
303 /* We can only set the mode through state machine commands... */
304 switch (mode) {
305 case REGULATOR_MODE_NORMAL:
306 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
307 break;
308 case REGULATOR_MODE_STANDBY:
309 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
310 break;
311 default:
312 return -EINVAL;
313 }
314
315 /* Ensure the resource is associated with some group */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100316 status = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800317 if (status < 0)
318 return status;
Rajendra Nayak441a4502009-12-13 22:19:23 +0100319 if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
David Brownellfa16a5c2009-02-08 10:37:06 -0800320 return -EACCES;
321
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100322 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
Axel Linb9e26bc2010-10-22 16:38:22 +0800323 message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
324 if (status < 0)
David Brownellfa16a5c2009-02-08 10:37:06 -0800325 return status;
326
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100327 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
Axel Linb9e26bc2010-10-22 16:38:22 +0800328 message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
David Brownellfa16a5c2009-02-08 10:37:06 -0800329}
330
Saquib Herman1a399622011-04-01 10:22:46 +0530331static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
332{
333 struct twlreg_info *info = rdev_get_drvdata(rdev);
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100334 int grp = 0;
Saquib Herman1a399622011-04-01 10:22:46 +0530335 int val;
336
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100337 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
338 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
Saquib Herman1a399622011-04-01 10:22:46 +0530339
340 if (grp < 0)
341 return grp;
342
343 /* Compose the state register settings */
344 val = grp << TWL6030_CFG_STATE_GRP_SHIFT;
345 /* We can only set the mode through state machine commands... */
346 switch (mode) {
347 case REGULATOR_MODE_NORMAL:
348 val |= TWL6030_CFG_STATE_ON;
349 break;
350 case REGULATOR_MODE_STANDBY:
351 val |= TWL6030_CFG_STATE_SLEEP;
352 break;
353
354 default:
355 return -EINVAL;
356 }
357
358 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val);
359}
360
David Brownellfa16a5c2009-02-08 10:37:06 -0800361/*----------------------------------------------------------------------*/
362
363/*
364 * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
365 * select field in its control register. We use tables indexed by VSEL
366 * to record voltages in milliVolts. (Accuracy is about three percent.)
367 *
368 * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
369 * currently handled by listing two slightly different VAUX2 regulators,
370 * only one of which will be configured.
371 *
372 * VSEL values documented as "TI cannot support these values" are flagged
373 * in these tables as UNSUP() values; we normally won't assign them.
Adrian Hunterd6bb69c2009-03-06 14:51:30 +0200374 *
375 * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
376 * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
David Brownellfa16a5c2009-02-08 10:37:06 -0800377 */
378#ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED
379#define UNSUP_MASK 0x0000
380#else
381#define UNSUP_MASK 0x8000
382#endif
383
384#define UNSUP(x) (UNSUP_MASK | (x))
385#define IS_UNSUP(x) (UNSUP_MASK & (x))
386#define LDO_MV(x) (~UNSUP_MASK & (x))
387
388
389static const u16 VAUX1_VSEL_table[] = {
390 UNSUP(1500), UNSUP(1800), 2500, 2800,
391 3000, 3000, 3000, 3000,
392};
393static const u16 VAUX2_4030_VSEL_table[] = {
394 UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
395 1500, 1800, UNSUP(1850), 2500,
396 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
397 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
398};
399static const u16 VAUX2_VSEL_table[] = {
400 1700, 1700, 1900, 1300,
401 1500, 1800, 2000, 2500,
402 2100, 2800, 2200, 2300,
403 2400, 2400, 2400, 2400,
404};
405static const u16 VAUX3_VSEL_table[] = {
406 1500, 1800, 2500, 2800,
Adrian Hunterd6bb69c2009-03-06 14:51:30 +0200407 3000, 3000, 3000, 3000,
David Brownellfa16a5c2009-02-08 10:37:06 -0800408};
409static const u16 VAUX4_VSEL_table[] = {
410 700, 1000, 1200, UNSUP(1300),
411 1500, 1800, UNSUP(1850), 2500,
David Brownell1897e742009-03-10 11:51:15 -0800412 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
413 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
David Brownellfa16a5c2009-02-08 10:37:06 -0800414};
415static const u16 VMMC1_VSEL_table[] = {
416 1850, 2850, 3000, 3150,
417};
418static const u16 VMMC2_VSEL_table[] = {
419 UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
420 UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
421 2600, 2800, 2850, 3000,
422 3150, 3150, 3150, 3150,
423};
424static const u16 VPLL1_VSEL_table[] = {
425 1000, 1200, 1300, 1800,
426 UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
427};
428static const u16 VPLL2_VSEL_table[] = {
429 700, 1000, 1200, 1300,
430 UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
431 UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
432 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
433};
434static const u16 VSIM_VSEL_table[] = {
435 UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
436 2800, 3000, 3000, 3000,
437};
438static const u16 VDAC_VSEL_table[] = {
439 1200, 1300, 1800, 1800,
440};
Juha Keski-Saari07fc4932009-12-16 15:27:55 +0200441static const u16 VDD1_VSEL_table[] = {
442 800, 1450,
443};
444static const u16 VDD2_VSEL_table[] = {
445 800, 1450, 1500,
446};
447static const u16 VIO_VSEL_table[] = {
448 1800, 1850,
449};
450static const u16 VINTANA2_VSEL_table[] = {
451 2500, 2750,
452};
David Brownellfa16a5c2009-02-08 10:37:06 -0800453
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530454static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
David Brownell66b659e2009-02-26 11:50:14 -0800455{
456 struct twlreg_info *info = rdev_get_drvdata(rdev);
457 int mV = info->table[index];
458
459 return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000);
460}
461
David Brownellfa16a5c2009-02-08 10:37:06 -0800462static int
Mark Brown3a93f2a2010-11-10 14:38:29 +0000463twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
464 unsigned *selector)
David Brownellfa16a5c2009-02-08 10:37:06 -0800465{
466 struct twlreg_info *info = rdev_get_drvdata(rdev);
467 int vsel;
468
469 for (vsel = 0; vsel < info->table_len; vsel++) {
470 int mV = info->table[vsel];
471 int uV;
472
473 if (IS_UNSUP(mV))
474 continue;
475 uV = LDO_MV(mV) * 1000;
476
David Brownell66b659e2009-02-26 11:50:14 -0800477 /* REVISIT for VAUX2, first match may not be best/lowest */
478
David Brownellfa16a5c2009-02-08 10:37:06 -0800479 /* use the first in-range value */
Mark Brown3a93f2a2010-11-10 14:38:29 +0000480 if (min_uV <= uV && uV <= max_uV) {
481 *selector = vsel;
Rajendra Nayak441a4502009-12-13 22:19:23 +0100482 return twlreg_write(info, TWL_MODULE_PM_RECEIVER,
483 VREG_VOLTAGE, vsel);
Mark Brown3a93f2a2010-11-10 14:38:29 +0000484 }
David Brownellfa16a5c2009-02-08 10:37:06 -0800485 }
486
487 return -EDOM;
488}
489
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530490static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800491{
492 struct twlreg_info *info = rdev_get_drvdata(rdev);
Rajendra Nayak441a4502009-12-13 22:19:23 +0100493 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
494 VREG_VOLTAGE);
David Brownellfa16a5c2009-02-08 10:37:06 -0800495
496 if (vsel < 0)
497 return vsel;
498
499 vsel &= info->table_len - 1;
500 return LDO_MV(info->table[vsel]) * 1000;
501}
502
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530503static struct regulator_ops twl4030ldo_ops = {
504 .list_voltage = twl4030ldo_list_voltage,
David Brownell66b659e2009-02-26 11:50:14 -0800505
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530506 .set_voltage = twl4030ldo_set_voltage,
507 .get_voltage = twl4030ldo_get_voltage,
508
Balaji T Kf8c29402011-05-20 19:03:51 +0530509 .enable = twl4030reg_enable,
Balaji T K0ff38972011-05-20 19:03:52 +0530510 .disable = twl4030reg_disable,
Saquib Hermanb2456772011-04-01 10:22:44 +0530511 .is_enabled = twl4030reg_is_enabled,
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530512
Saquib Herman1a399622011-04-01 10:22:46 +0530513 .set_mode = twl4030reg_set_mode,
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530514
Saquib Herman9a0244a2011-04-01 10:22:45 +0530515 .get_status = twl4030reg_get_status,
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530516};
517
Tero Kristoba305e32011-11-28 16:53:19 +0200518static int
519twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
520 unsigned *selector)
521{
522 struct twlreg_info *info = rdev_get_drvdata(rdev);
523 int vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
524
525 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS_4030,
526 vsel);
527 return 0;
528}
529
530static int twl4030smps_get_voltage(struct regulator_dev *rdev)
531{
532 struct twlreg_info *info = rdev_get_drvdata(rdev);
533 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
534 VREG_VOLTAGE_SMPS_4030);
535
536 return vsel * 12500 + 600000;
537}
538
539static struct regulator_ops twl4030smps_ops = {
540 .set_voltage = twl4030smps_set_voltage,
541 .get_voltage = twl4030smps_get_voltage,
542};
543
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530544static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
545{
546 struct twlreg_info *info = rdev_get_drvdata(rdev);
547
548 return ((info->min_mV + (index * 100)) * 1000);
549}
550
551static int
Mark Brown3a93f2a2010-11-10 14:38:29 +0000552twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
553 unsigned *selector)
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530554{
555 struct twlreg_info *info = rdev_get_drvdata(rdev);
556 int vsel;
557
558 if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV))
559 return -EDOM;
560
561 /*
562 * Use the below formula to calculate vsel
563 * mV = 1000mv + 100mv * (vsel - 1)
564 */
565 vsel = (min_uV/1000 - 1000)/100 + 1;
Mark Brown3a93f2a2010-11-10 14:38:29 +0000566 *selector = vsel;
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530567 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
568
569}
570
571static int twl6030ldo_get_voltage(struct regulator_dev *rdev)
572{
573 struct twlreg_info *info = rdev_get_drvdata(rdev);
574 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
575 VREG_VOLTAGE);
576
577 if (vsel < 0)
578 return vsel;
579
580 /*
581 * Use the below formula to calculate vsel
582 * mV = 1000mv + 100mv * (vsel - 1)
583 */
584 return (1000 + (100 * (vsel - 1))) * 1000;
585}
586
587static struct regulator_ops twl6030ldo_ops = {
588 .list_voltage = twl6030ldo_list_voltage,
589
590 .set_voltage = twl6030ldo_set_voltage,
591 .get_voltage = twl6030ldo_get_voltage,
David Brownellfa16a5c2009-02-08 10:37:06 -0800592
Balaji T Kf8c29402011-05-20 19:03:51 +0530593 .enable = twl6030reg_enable,
Balaji T K0ff38972011-05-20 19:03:52 +0530594 .disable = twl6030reg_disable,
Saquib Hermanb2456772011-04-01 10:22:44 +0530595 .is_enabled = twl6030reg_is_enabled,
David Brownellfa16a5c2009-02-08 10:37:06 -0800596
Saquib Herman1a399622011-04-01 10:22:46 +0530597 .set_mode = twl6030reg_set_mode,
David Brownellfa16a5c2009-02-08 10:37:06 -0800598
Saquib Herman9a0244a2011-04-01 10:22:45 +0530599 .get_status = twl6030reg_get_status,
David Brownellfa16a5c2009-02-08 10:37:06 -0800600};
601
602/*----------------------------------------------------------------------*/
603
604/*
605 * Fixed voltage LDOs don't have a VSEL field to update.
606 */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100607static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
David Brownell66b659e2009-02-26 11:50:14 -0800608{
609 struct twlreg_info *info = rdev_get_drvdata(rdev);
610
611 return info->min_mV * 1000;
612}
613
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100614static int twlfixed_get_voltage(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800615{
616 struct twlreg_info *info = rdev_get_drvdata(rdev);
617
618 return info->min_mV * 1000;
619}
620
Saquib Hermanb2456772011-04-01 10:22:44 +0530621static struct regulator_ops twl4030fixed_ops = {
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100622 .list_voltage = twlfixed_list_voltage,
David Brownell66b659e2009-02-26 11:50:14 -0800623
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100624 .get_voltage = twlfixed_get_voltage,
David Brownellfa16a5c2009-02-08 10:37:06 -0800625
Balaji T Kf8c29402011-05-20 19:03:51 +0530626 .enable = twl4030reg_enable,
Balaji T K0ff38972011-05-20 19:03:52 +0530627 .disable = twl4030reg_disable,
Saquib Hermanb2456772011-04-01 10:22:44 +0530628 .is_enabled = twl4030reg_is_enabled,
629
Saquib Herman1a399622011-04-01 10:22:46 +0530630 .set_mode = twl4030reg_set_mode,
Saquib Hermanb2456772011-04-01 10:22:44 +0530631
Saquib Herman9a0244a2011-04-01 10:22:45 +0530632 .get_status = twl4030reg_get_status,
Saquib Hermanb2456772011-04-01 10:22:44 +0530633};
634
635static struct regulator_ops twl6030fixed_ops = {
636 .list_voltage = twlfixed_list_voltage,
637
638 .get_voltage = twlfixed_get_voltage,
639
Balaji T Kf8c29402011-05-20 19:03:51 +0530640 .enable = twl6030reg_enable,
Balaji T K0ff38972011-05-20 19:03:52 +0530641 .disable = twl6030reg_disable,
Saquib Hermanb2456772011-04-01 10:22:44 +0530642 .is_enabled = twl6030reg_is_enabled,
David Brownellfa16a5c2009-02-08 10:37:06 -0800643
Saquib Herman1a399622011-04-01 10:22:46 +0530644 .set_mode = twl6030reg_set_mode,
David Brownellfa16a5c2009-02-08 10:37:06 -0800645
Saquib Herman9a0244a2011-04-01 10:22:45 +0530646 .get_status = twl6030reg_get_status,
David Brownellfa16a5c2009-02-08 10:37:06 -0800647};
648
Balaji T K8e6de4a2011-02-10 18:44:50 +0530649static struct regulator_ops twl6030_fixed_resource = {
Balaji T Kf8c29402011-05-20 19:03:51 +0530650 .enable = twl6030reg_enable,
Balaji T K0ff38972011-05-20 19:03:52 +0530651 .disable = twl6030reg_disable,
Saquib Hermanb2456772011-04-01 10:22:44 +0530652 .is_enabled = twl6030reg_is_enabled,
Saquib Herman9a0244a2011-04-01 10:22:45 +0530653 .get_status = twl6030reg_get_status,
Balaji T K8e6de4a2011-02-10 18:44:50 +0530654};
655
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100656/*
657 * SMPS status and control
658 */
659
660static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
661{
662 struct twlreg_info *info = rdev_get_drvdata(rdev);
663
664 int voltage = 0;
665
666 switch (info->flags) {
667 case SMPS_OFFSET_EN:
668 voltage = 100000;
669 /* fall through */
670 case 0:
671 switch (index) {
672 case 0:
673 voltage = 0;
674 break;
675 case 58:
676 voltage = 1350 * 1000;
677 break;
678 case 59:
679 voltage = 1500 * 1000;
680 break;
681 case 60:
682 voltage = 1800 * 1000;
683 break;
684 case 61:
685 voltage = 1900 * 1000;
686 break;
687 case 62:
688 voltage = 2100 * 1000;
689 break;
690 default:
691 voltage += (600000 + (12500 * (index - 1)));
692 }
693 break;
694 case SMPS_EXTENDED_EN:
695 switch (index) {
696 case 0:
697 voltage = 0;
698 break;
699 case 58:
700 voltage = 2084 * 1000;
701 break;
702 case 59:
703 voltage = 2315 * 1000;
704 break;
705 case 60:
706 voltage = 2778 * 1000;
707 break;
708 case 61:
709 voltage = 2932 * 1000;
710 break;
711 case 62:
712 voltage = 3241 * 1000;
713 break;
714 default:
715 voltage = (1852000 + (38600 * (index - 1)));
716 }
717 break;
718 case SMPS_OFFSET_EN | SMPS_EXTENDED_EN:
719 switch (index) {
720 case 0:
721 voltage = 0;
722 break;
723 case 58:
724 voltage = 4167 * 1000;
725 break;
726 case 59:
727 voltage = 2315 * 1000;
728 break;
729 case 60:
730 voltage = 2778 * 1000;
731 break;
732 case 61:
733 voltage = 2932 * 1000;
734 break;
735 case 62:
736 voltage = 3241 * 1000;
737 break;
738 default:
739 voltage = (2161000 + (38600 * (index - 1)));
740 }
741 break;
742 }
743
744 return voltage;
745}
746
747static int
748twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
749 unsigned int *selector)
750{
751 struct twlreg_info *info = rdev_get_drvdata(rdev);
752 int vsel = 0;
753
754 switch (info->flags) {
755 case 0:
756 if (min_uV == 0)
757 vsel = 0;
Laxman Dewangana33b6e52012-02-03 12:54:38 +0530758 else if ((min_uV >= 600000) && (min_uV <= 1300000)) {
759 int calc_uV;
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100760 vsel = (min_uV - 600000) / 125;
761 if (vsel % 100)
762 vsel += 100;
763 vsel /= 100;
764 vsel++;
Laxman Dewangana33b6e52012-02-03 12:54:38 +0530765 calc_uV = twl6030smps_list_voltage(rdev, vsel);
766 if (calc_uV > max_uV)
767 return -EINVAL;
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100768 }
769 /* Values 1..57 for vsel are linear and can be calculated
770 * values 58..62 are non linear.
771 */
772 else if ((min_uV > 1900000) && (max_uV >= 2100000))
773 vsel = 62;
774 else if ((min_uV > 1800000) && (max_uV >= 1900000))
775 vsel = 61;
776 else if ((min_uV > 1500000) && (max_uV >= 1800000))
777 vsel = 60;
778 else if ((min_uV > 1350000) && (max_uV >= 1500000))
779 vsel = 59;
780 else if ((min_uV > 1300000) && (max_uV >= 1350000))
781 vsel = 58;
782 else
783 return -EINVAL;
784 break;
785 case SMPS_OFFSET_EN:
786 if (min_uV == 0)
787 vsel = 0;
Laxman Dewangana33b6e52012-02-03 12:54:38 +0530788 else if ((min_uV >= 700000) && (min_uV <= 1420000)) {
789 int calc_uV;
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100790 vsel = (min_uV - 700000) / 125;
791 if (vsel % 100)
792 vsel += 100;
793 vsel /= 100;
794 vsel++;
Laxman Dewangana33b6e52012-02-03 12:54:38 +0530795 calc_uV = twl6030smps_list_voltage(rdev, vsel);
796 if (calc_uV > max_uV)
797 return -EINVAL;
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100798 }
799 /* Values 1..57 for vsel are linear and can be calculated
800 * values 58..62 are non linear.
801 */
802 else if ((min_uV > 1900000) && (max_uV >= 2100000))
803 vsel = 62;
804 else if ((min_uV > 1800000) && (max_uV >= 1900000))
805 vsel = 61;
806 else if ((min_uV > 1350000) && (max_uV >= 1800000))
807 vsel = 60;
808 else if ((min_uV > 1350000) && (max_uV >= 1500000))
809 vsel = 59;
810 else if ((min_uV > 1300000) && (max_uV >= 1350000))
811 vsel = 58;
812 else
813 return -EINVAL;
814 break;
815 case SMPS_EXTENDED_EN:
816 if (min_uV == 0)
817 vsel = 0;
818 else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
819 vsel = (min_uV - 1852000) / 386;
820 if (vsel % 100)
821 vsel += 100;
822 vsel /= 100;
823 vsel++;
824 }
825 break;
826 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
827 if (min_uV == 0)
828 vsel = 0;
829 else if ((min_uV >= 2161000) && (max_uV <= 4321000)) {
Laxman Dewangana33b6e52012-02-03 12:54:38 +0530830 vsel = (min_uV - 2161000) / 386;
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100831 if (vsel % 100)
832 vsel += 100;
833 vsel /= 100;
834 vsel++;
835 }
836 break;
837 }
838
839 *selector = vsel;
840
841 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
842 vsel);
843}
844
845static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
846{
847 struct twlreg_info *info = rdev_get_drvdata(rdev);
848
849 return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS);
850}
851
852static struct regulator_ops twlsmps_ops = {
853 .list_voltage = twl6030smps_list_voltage,
854
855 .set_voltage = twl6030smps_set_voltage,
856 .get_voltage_sel = twl6030smps_get_voltage_sel,
857
858 .enable = twl6030reg_enable,
859 .disable = twl6030reg_disable,
860 .is_enabled = twl6030reg_is_enabled,
861
862 .set_mode = twl6030reg_set_mode,
863
864 .get_status = twl6030reg_get_status,
865};
866
David Brownellfa16a5c2009-02-08 10:37:06 -0800867/*----------------------------------------------------------------------*/
868
Juha Keski-Saari045f9722009-12-16 14:49:52 +0200869#define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
870 remap_conf) \
871 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
Saquib Hermanb2456772011-04-01 10:22:44 +0530872 remap_conf, TWL4030, twl4030fixed_ops)
Ambresh Kaf8b2442011-07-09 19:02:21 -0700873#define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
874 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
Saquib Hermanb2456772011-04-01 10:22:44 +0530875 0x0, TWL6030, twl6030fixed_ops)
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100876
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530877#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) { \
David Brownellfa16a5c2009-02-08 10:37:06 -0800878 .base = offset, \
879 .id = num, \
880 .table_len = ARRAY_SIZE(label##_VSEL_table), \
881 .table = label##_VSEL_table, \
Juha Keski-Saari045f9722009-12-16 14:49:52 +0200882 .delay = turnon_delay, \
883 .remap = remap_conf, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800884 .desc = { \
885 .name = #label, \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530886 .id = TWL4030_REG_##label, \
David Brownell66b659e2009-02-26 11:50:14 -0800887 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530888 .ops = &twl4030ldo_ops, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800889 .type = REGULATOR_VOLTAGE, \
890 .owner = THIS_MODULE, \
891 }, \
892 }
893
Tero Kristoba305e32011-11-28 16:53:19 +0200894#define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
895 { \
896 .base = offset, \
897 .id = num, \
898 .delay = turnon_delay, \
899 .remap = remap_conf, \
900 .desc = { \
901 .name = #label, \
902 .id = TWL4030_REG_##label, \
903 .ops = &twl4030smps_ops, \
904 .type = REGULATOR_VOLTAGE, \
905 .owner = THIS_MODULE, \
906 }, \
907 }
908
Ambresh Kaf8b2442011-07-09 19:02:21 -0700909#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530910 .base = offset, \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530911 .min_mV = min_mVolts, \
912 .max_mV = max_mVolts, \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530913 .desc = { \
914 .name = #label, \
915 .id = TWL6030_REG_##label, \
Colin Cross7736f112011-05-27 12:25:27 -0700916 .n_voltages = (max_mVolts - min_mVolts)/100 + 1, \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530917 .ops = &twl6030ldo_ops, \
918 .type = REGULATOR_VOLTAGE, \
919 .owner = THIS_MODULE, \
920 }, \
921 }
922
Ambresh Kaf8b2442011-07-09 19:02:21 -0700923#define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100924 .base = offset, \
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100925 .min_mV = min_mVolts, \
926 .max_mV = max_mVolts, \
927 .desc = { \
928 .name = #label, \
929 .id = TWL6025_REG_##label, \
930 .n_voltages = ((max_mVolts - min_mVolts)/100) + 1, \
931 .ops = &twl6030ldo_ops, \
932 .type = REGULATOR_VOLTAGE, \
933 .owner = THIS_MODULE, \
934 }, \
935 }
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530936
Juha Keski-Saari045f9722009-12-16 14:49:52 +0200937#define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
Saquib Hermanb2456772011-04-01 10:22:44 +0530938 family, operations) { \
David Brownellfa16a5c2009-02-08 10:37:06 -0800939 .base = offset, \
940 .id = num, \
941 .min_mV = mVolts, \
Juha Keski-Saari045f9722009-12-16 14:49:52 +0200942 .delay = turnon_delay, \
943 .remap = remap_conf, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800944 .desc = { \
945 .name = #label, \
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100946 .id = family##_REG_##label, \
David Brownell66b659e2009-02-26 11:50:14 -0800947 .n_voltages = 1, \
Saquib Hermanb2456772011-04-01 10:22:44 +0530948 .ops = &operations, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800949 .type = REGULATOR_VOLTAGE, \
950 .owner = THIS_MODULE, \
951 }, \
952 }
953
Ambresh Kaf8b2442011-07-09 19:02:21 -0700954#define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) { \
Balaji T K8e6de4a2011-02-10 18:44:50 +0530955 .base = offset, \
Balaji T K8e6de4a2011-02-10 18:44:50 +0530956 .delay = turnon_delay, \
Balaji T K8e6de4a2011-02-10 18:44:50 +0530957 .desc = { \
958 .name = #label, \
959 .id = TWL6030_REG_##label, \
960 .ops = &twl6030_fixed_resource, \
961 .type = REGULATOR_VOLTAGE, \
962 .owner = THIS_MODULE, \
963 }, \
964 }
965
Ambresh Kaf8b2442011-07-09 19:02:21 -0700966#define TWL6025_ADJUSTABLE_SMPS(label, offset) { \
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100967 .base = offset, \
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100968 .min_mV = 600, \
969 .max_mV = 2100, \
970 .desc = { \
971 .name = #label, \
972 .id = TWL6025_REG_##label, \
973 .n_voltages = 63, \
974 .ops = &twlsmps_ops, \
975 .type = REGULATOR_VOLTAGE, \
976 .owner = THIS_MODULE, \
977 }, \
978 }
979
David Brownellfa16a5c2009-02-08 10:37:06 -0800980/*
981 * We list regulators here if systems need some level of
982 * software control over them after boot.
983 */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100984static struct twlreg_info twl_regs[] = {
Juha Keski-Saari045f9722009-12-16 14:49:52 +0200985 TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08),
986 TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08),
987 TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08),
988 TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08),
989 TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08),
990 TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08),
991 TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08),
992 TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00),
993 TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08),
994 TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00),
995 TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08),
996 TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08),
997 TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08),
998 TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08),
999 TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08),
Tero Kristoba305e32011-11-28 16:53:19 +02001000 TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08),
1001 TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08),
Juha Keski-Saari045f9722009-12-16 14:49:52 +02001002 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08),
1003 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08),
1004 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08),
David Brownellfa16a5c2009-02-08 10:37:06 -08001005 /* VUSBCP is managed *only* by the USB subchip */
Rajendra Nayak441a4502009-12-13 22:19:23 +01001006
1007 /* 6030 REG with base as PMC Slave Misc : 0x0030 */
Juha Keski-Saari045f9722009-12-16 14:49:52 +02001008 /* Turnon-delay and remap configuration values for 6030 are not
1009 verified since the specification is not public */
Ambresh Kaf8b2442011-07-09 19:02:21 -07001010 TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300),
1011 TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300),
1012 TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300),
1013 TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300),
1014 TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300),
1015 TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300),
1016 TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0),
1017 TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0),
1018 TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0),
1019 TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0),
1020 TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0),
Graeme Gregory4d94aee2011-05-22 21:21:23 +01001021
1022 /* 6025 are renamed compared to 6030 versions */
Ambresh Kaf8b2442011-07-09 19:02:21 -07001023 TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300),
1024 TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300),
1025 TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300),
1026 TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300),
1027 TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300),
1028 TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300),
1029 TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300),
1030 TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300),
1031 TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300),
Graeme Gregory4d94aee2011-05-22 21:21:23 +01001032
Ambresh Kaf8b2442011-07-09 19:02:21 -07001033 TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34),
1034 TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10),
1035 TWL6025_ADJUSTABLE_SMPS(VIO, 0x16),
David Brownellfa16a5c2009-02-08 10:37:06 -08001036};
1037
Graeme Gregory4d94aee2011-05-22 21:21:23 +01001038static u8 twl_get_smps_offset(void)
1039{
1040 u8 value;
1041
1042 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1043 TWL6030_SMPS_OFFSET);
1044 return value;
1045}
1046
1047static u8 twl_get_smps_mult(void)
1048{
1049 u8 value;
1050
1051 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1052 TWL6030_SMPS_MULT);
1053 return value;
1054}
1055
Dmitry Torokhov24c29022010-02-23 23:38:01 -08001056static int __devinit twlreg_probe(struct platform_device *pdev)
David Brownellfa16a5c2009-02-08 10:37:06 -08001057{
1058 int i;
1059 struct twlreg_info *info;
1060 struct regulator_init_data *initdata;
1061 struct regulation_constraints *c;
1062 struct regulator_dev *rdev;
David Brownellfa16a5c2009-02-08 10:37:06 -08001063
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001064 for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
1065 if (twl_regs[i].desc.id != pdev->id)
David Brownellfa16a5c2009-02-08 10:37:06 -08001066 continue;
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001067 info = twl_regs + i;
David Brownellfa16a5c2009-02-08 10:37:06 -08001068 break;
1069 }
1070 if (!info)
1071 return -ENODEV;
1072
1073 initdata = pdev->dev.platform_data;
1074 if (!initdata)
1075 return -EINVAL;
1076
Graeme Gregory4d94aee2011-05-22 21:21:23 +01001077 /* copy the features into regulator data */
1078 info->features = (unsigned long)initdata->driver_data;
1079
David Brownellfa16a5c2009-02-08 10:37:06 -08001080 /* Constrain board-specific capabilities according to what
1081 * this driver and the chip itself can actually do.
1082 */
1083 c = &initdata->constraints;
David Brownellfa16a5c2009-02-08 10:37:06 -08001084 c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
1085 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
1086 | REGULATOR_CHANGE_MODE
1087 | REGULATOR_CHANGE_STATUS;
Juha Keski-Saari205e5cd2009-12-16 15:27:56 +02001088 switch (pdev->id) {
1089 case TWL4030_REG_VIO:
1090 case TWL4030_REG_VDD1:
1091 case TWL4030_REG_VDD2:
1092 case TWL4030_REG_VPLL1:
1093 case TWL4030_REG_VINTANA1:
1094 case TWL4030_REG_VINTANA2:
1095 case TWL4030_REG_VINTDIG:
1096 c->always_on = true;
1097 break;
1098 default:
1099 break;
1100 }
David Brownellfa16a5c2009-02-08 10:37:06 -08001101
Graeme Gregory4d94aee2011-05-22 21:21:23 +01001102 switch (pdev->id) {
1103 case TWL6025_REG_SMPS3:
1104 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3)
1105 info->flags |= SMPS_EXTENDED_EN;
1106 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3)
1107 info->flags |= SMPS_OFFSET_EN;
1108 break;
1109 case TWL6025_REG_SMPS4:
1110 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4)
1111 info->flags |= SMPS_EXTENDED_EN;
1112 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4)
1113 info->flags |= SMPS_OFFSET_EN;
1114 break;
1115 case TWL6025_REG_VIO:
1116 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO)
1117 info->flags |= SMPS_EXTENDED_EN;
1118 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO)
1119 info->flags |= SMPS_OFFSET_EN;
1120 break;
1121 }
1122
Rajendra Nayak2c043bc2011-11-18 16:47:19 +05301123 rdev = regulator_register(&info->desc, &pdev->dev, initdata, info, NULL);
David Brownellfa16a5c2009-02-08 10:37:06 -08001124 if (IS_ERR(rdev)) {
1125 dev_err(&pdev->dev, "can't register %s, %ld\n",
1126 info->desc.name, PTR_ERR(rdev));
1127 return PTR_ERR(rdev);
1128 }
1129 platform_set_drvdata(pdev, rdev);
1130
Saquib Herman776dc922011-04-01 10:22:43 +05301131 if (twl_class_is_4030())
1132 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
Juha Keski-Saari30010fa2009-12-16 15:27:58 +02001133 info->remap);
1134
David Brownellfa16a5c2009-02-08 10:37:06 -08001135 /* NOTE: many regulators support short-circuit IRQs (presentable
1136 * as REGULATOR_OVER_CURRENT notifications?) configured via:
1137 * - SC_CONFIG
1138 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
1139 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
1140 * - IT_CONFIG
1141 */
1142
1143 return 0;
1144}
1145
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001146static int __devexit twlreg_remove(struct platform_device *pdev)
David Brownellfa16a5c2009-02-08 10:37:06 -08001147{
1148 regulator_unregister(platform_get_drvdata(pdev));
1149 return 0;
1150}
1151
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001152MODULE_ALIAS("platform:twl_reg");
David Brownellfa16a5c2009-02-08 10:37:06 -08001153
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001154static struct platform_driver twlreg_driver = {
1155 .probe = twlreg_probe,
1156 .remove = __devexit_p(twlreg_remove),
David Brownellfa16a5c2009-02-08 10:37:06 -08001157 /* NOTE: short name, to work around driver model truncation of
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001158 * "twl_regulator.12" (and friends) to "twl_regulator.1".
David Brownellfa16a5c2009-02-08 10:37:06 -08001159 */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001160 .driver.name = "twl_reg",
David Brownellfa16a5c2009-02-08 10:37:06 -08001161 .driver.owner = THIS_MODULE,
1162};
1163
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001164static int __init twlreg_init(void)
David Brownellfa16a5c2009-02-08 10:37:06 -08001165{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001166 return platform_driver_register(&twlreg_driver);
David Brownellfa16a5c2009-02-08 10:37:06 -08001167}
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001168subsys_initcall(twlreg_init);
David Brownellfa16a5c2009-02-08 10:37:06 -08001169
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001170static void __exit twlreg_exit(void)
David Brownellfa16a5c2009-02-08 10:37:06 -08001171{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001172 platform_driver_unregister(&twlreg_driver);
David Brownellfa16a5c2009-02-08 10:37:06 -08001173}
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001174module_exit(twlreg_exit)
David Brownellfa16a5c2009-02-08 10:37:06 -08001175
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001176MODULE_DESCRIPTION("TWL regulator driver");
David Brownellfa16a5c2009-02-08 10:37:06 -08001177MODULE_LICENSE("GPL");