blob: 564acae3eae8eabd3de00f15d140ba53177396a7 [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>
Stephen Rothwell8f52a582012-08-16 15:16:05 +100013#include <linux/string.h>
14#include <linux/slab.h>
David Brownellfa16a5c2009-02-08 10:37:06 -080015#include <linux/init.h>
16#include <linux/err.h>
17#include <linux/platform_device.h>
Rajendra Nayak2098e952012-02-28 15:09:11 +053018#include <linux/of.h>
19#include <linux/of_device.h>
David Brownellfa16a5c2009-02-08 10:37:06 -080020#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h>
Rajendra Nayak2098e952012-02-28 15:09:11 +053022#include <linux/regulator/of_regulator.h>
Santosh Shilimkarb07682b2009-12-13 20:05:51 +010023#include <linux/i2c/twl.h>
David Brownellfa16a5c2009-02-08 10:37:06 -080024
25
26/*
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010027 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
David Brownellfa16a5c2009-02-08 10:37:06 -080028 * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions
29 * include an audio codec, battery charger, and more voltage regulators.
30 * These chips are often used in OMAP-based systems.
31 *
32 * This driver implements software-based resource control for various
33 * voltage regulators. This is usually augmented with state machine
34 * based control.
35 */
36
37struct twlreg_info {
38 /* start of regulator's PM_RECEIVER control register bank */
39 u8 base;
40
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +010041 /* twl resource ID, for resource control state machine */
David Brownellfa16a5c2009-02-08 10:37:06 -080042 u8 id;
43
44 /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
45 u8 table_len;
46 const u16 *table;
47
Juha Keski-Saari045f9722009-12-16 14:49:52 +020048 /* State REMAP default configuration */
49 u8 remap;
50
David Brownellfa16a5c2009-02-08 10:37:06 -080051 /* chip constraints on regulator behavior */
52 u16 min_mV;
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +053053 u16 max_mV;
David Brownellfa16a5c2009-02-08 10:37:06 -080054
Graeme Gregory4d94aee2011-05-22 21:21:23 +010055 u8 flags;
56
David Brownellfa16a5c2009-02-08 10:37:06 -080057 /* used by regulator core */
58 struct regulator_desc desc;
Graeme Gregory4d94aee2011-05-22 21:21:23 +010059
60 /* chip specific features */
61 unsigned long features;
Tero Kristo63bfff42012-02-16 12:27:52 +020062
63 /*
64 * optional override functions for voltage set/get
65 * these are currently only used for SMPS regulators
66 */
67 int (*get_voltage)(void *data);
68 int (*set_voltage)(void *data, int target_uV);
69
70 /* data passed from board for external get/set voltage */
71 void *data;
David Brownellfa16a5c2009-02-08 10:37:06 -080072};
73
74
75/* LDO control registers ... offset is from the base of its register bank.
76 * The first three registers of all power resource banks help hardware to
77 * manage the various resource groups.
78 */
Rajendra Nayak441a4502009-12-13 22:19:23 +010079/* Common offset in TWL4030/6030 */
David Brownellfa16a5c2009-02-08 10:37:06 -080080#define VREG_GRP 0
Rajendra Nayak441a4502009-12-13 22:19:23 +010081/* TWL4030 register offsets */
David Brownellfa16a5c2009-02-08 10:37:06 -080082#define VREG_TYPE 1
83#define VREG_REMAP 2
84#define VREG_DEDICATED 3 /* LDO control */
Tero Kristoba305e32011-11-28 16:53:19 +020085#define VREG_VOLTAGE_SMPS_4030 9
Rajendra Nayak441a4502009-12-13 22:19:23 +010086/* TWL6030 register offsets */
87#define VREG_TRANS 1
88#define VREG_STATE 2
89#define VREG_VOLTAGE 3
Graeme Gregory4d94aee2011-05-22 21:21:23 +010090#define VREG_VOLTAGE_SMPS 4
Rajendra Nayak441a4502009-12-13 22:19:23 +010091/* TWL6030 Misc register offsets */
92#define VREG_BC_ALL 1
93#define VREG_BC_REF 2
94#define VREG_BC_PROC 3
95#define VREG_BC_CLK_RST 4
David Brownellfa16a5c2009-02-08 10:37:06 -080096
Saquib Herman21657ebf2011-04-01 10:22:42 +053097/* TWL6030 LDO register values for CFG_STATE */
98#define TWL6030_CFG_STATE_OFF 0x00
99#define TWL6030_CFG_STATE_ON 0x01
Saquib Herman9a0244a2011-04-01 10:22:45 +0530100#define TWL6030_CFG_STATE_OFF2 0x02
101#define TWL6030_CFG_STATE_SLEEP 0x03
Saquib Herman21657ebf2011-04-01 10:22:42 +0530102#define TWL6030_CFG_STATE_GRP_SHIFT 5
Saquib Hermanb2456772011-04-01 10:22:44 +0530103#define TWL6030_CFG_STATE_APP_SHIFT 2
104#define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
105#define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
106 TWL6030_CFG_STATE_APP_SHIFT)
Saquib Herman21657ebf2011-04-01 10:22:42 +0530107
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100108/* Flags for SMPS Voltage reading */
109#define SMPS_OFFSET_EN BIT(0)
110#define SMPS_EXTENDED_EN BIT(1)
111
112/* twl6025 SMPS EPROM values */
113#define TWL6030_SMPS_OFFSET 0xB0
114#define TWL6030_SMPS_MULT 0xB3
115#define SMPS_MULTOFFSET_SMPS4 BIT(0)
116#define SMPS_MULTOFFSET_VIO BIT(1)
117#define SMPS_MULTOFFSET_SMPS3 BIT(6)
118
David Brownellfa16a5c2009-02-08 10:37:06 -0800119static inline int
Rajendra Nayak441a4502009-12-13 22:19:23 +0100120twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
David Brownellfa16a5c2009-02-08 10:37:06 -0800121{
122 u8 value;
123 int status;
124
Rajendra Nayak441a4502009-12-13 22:19:23 +0100125 status = twl_i2c_read_u8(slave_subgp,
David Brownellfa16a5c2009-02-08 10:37:06 -0800126 &value, info->base + offset);
127 return (status < 0) ? status : value;
128}
129
130static inline int
Rajendra Nayak441a4502009-12-13 22:19:23 +0100131twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
132 u8 value)
David Brownellfa16a5c2009-02-08 10:37:06 -0800133{
Rajendra Nayak441a4502009-12-13 22:19:23 +0100134 return twl_i2c_write_u8(slave_subgp,
David Brownellfa16a5c2009-02-08 10:37:06 -0800135 value, info->base + offset);
136}
137
138/*----------------------------------------------------------------------*/
139
140/* generic power resource operations, which work on all regulators */
141
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100142static int twlreg_grp(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800143{
Rajendra Nayak441a4502009-12-13 22:19:23 +0100144 return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
145 VREG_GRP);
David Brownellfa16a5c2009-02-08 10:37:06 -0800146}
147
148/*
149 * Enable/disable regulators by joining/leaving the P1 (processor) group.
150 * We assume nobody else is updating the DEV_GRP registers.
151 */
Rajendra Nayak441a4502009-12-13 22:19:23 +0100152/* definition for 4030 family */
153#define P3_GRP_4030 BIT(7) /* "peripherals" */
154#define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */
155#define P1_GRP_4030 BIT(5) /* CPU/Linux */
156/* definition for 6030 family */
157#define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
158#define P2_GRP_6030 BIT(1) /* "peripherals" */
159#define P1_GRP_6030 BIT(0) /* CPU/Linux */
David Brownellfa16a5c2009-02-08 10:37:06 -0800160
Saquib Hermanb2456772011-04-01 10:22:44 +0530161static int twl4030reg_is_enabled(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800162{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100163 int state = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800164
165 if (state < 0)
166 return state;
167
Saquib Hermanb2456772011-04-01 10:22:44 +0530168 return state & P1_GRP_4030;
169}
170
171static int twl6030reg_is_enabled(struct regulator_dev *rdev)
172{
173 struct twlreg_info *info = rdev_get_drvdata(rdev);
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100174 int grp = 0, val;
Saquib Hermanb2456772011-04-01 10:22:44 +0530175
Axel Linb6f476c2012-04-11 11:07:17 +0800176 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) {
177 grp = twlreg_grp(rdev);
178 if (grp < 0)
179 return grp;
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100180 grp &= P1_GRP_6030;
Axel Linb6f476c2012-04-11 11:07:17 +0800181 } else {
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100182 grp = 1;
Axel Linb6f476c2012-04-11 11:07:17 +0800183 }
Saquib Hermanb2456772011-04-01 10:22:44 +0530184
185 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
186 val = TWL6030_CFG_STATE_APP(val);
187
188 return grp && (val == TWL6030_CFG_STATE_ON);
David Brownellfa16a5c2009-02-08 10:37:06 -0800189}
190
Balaji T Kf8c29402011-05-20 19:03:51 +0530191static int twl4030reg_enable(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800192{
193 struct twlreg_info *info = rdev_get_drvdata(rdev);
194 int grp;
Juha Keski-Saari53b8a9d2009-12-16 14:55:26 +0200195 int ret;
David Brownellfa16a5c2009-02-08 10:37:06 -0800196
Axel Linb6f476c2012-04-11 11:07:17 +0800197 grp = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800198 if (grp < 0)
199 return grp;
200
Balaji T Kf8c29402011-05-20 19:03:51 +0530201 grp |= P1_GRP_4030;
Rajendra Nayak441a4502009-12-13 22:19:23 +0100202
Juha Keski-Saari53b8a9d2009-12-16 14:55:26 +0200203 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
204
Balaji T Kf8c29402011-05-20 19:03:51 +0530205 return ret;
206}
207
208static int twl6030reg_enable(struct regulator_dev *rdev)
209{
210 struct twlreg_info *info = rdev_get_drvdata(rdev);
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100211 int grp = 0;
Balaji T Kf8c29402011-05-20 19:03:51 +0530212 int ret;
213
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100214 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
Axel Linb6f476c2012-04-11 11:07:17 +0800215 grp = twlreg_grp(rdev);
Balaji T Kf8c29402011-05-20 19:03:51 +0530216 if (grp < 0)
217 return grp;
218
219 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
220 grp << TWL6030_CFG_STATE_GRP_SHIFT |
221 TWL6030_CFG_STATE_ON);
Juha Keski-Saari53b8a9d2009-12-16 14:55:26 +0200222 return ret;
David Brownellfa16a5c2009-02-08 10:37:06 -0800223}
224
Balaji T K0ff38972011-05-20 19:03:52 +0530225static int twl4030reg_disable(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800226{
227 struct twlreg_info *info = rdev_get_drvdata(rdev);
228 int grp;
Saquib Herman21657ebf2011-04-01 10:22:42 +0530229 int ret;
David Brownellfa16a5c2009-02-08 10:37:06 -0800230
Axel Linb6f476c2012-04-11 11:07:17 +0800231 grp = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800232 if (grp < 0)
233 return grp;
234
Balaji T K0ff38972011-05-20 19:03:52 +0530235 grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
Rajendra Nayak441a4502009-12-13 22:19:23 +0100236
Saquib Herman21657ebf2011-04-01 10:22:42 +0530237 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
238
Balaji T K0ff38972011-05-20 19:03:52 +0530239 return ret;
240}
241
242static int twl6030reg_disable(struct regulator_dev *rdev)
243{
244 struct twlreg_info *info = rdev_get_drvdata(rdev);
245 int grp = 0;
246 int ret;
247
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100248 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
249 grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030;
Balaji T K0ff38972011-05-20 19:03:52 +0530250
251 /* For 6030, set the off state for all grps enabled */
252 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
253 (grp) << TWL6030_CFG_STATE_GRP_SHIFT |
254 TWL6030_CFG_STATE_OFF);
Saquib Herman21657ebf2011-04-01 10:22:42 +0530255
256 return ret;
David Brownellfa16a5c2009-02-08 10:37:06 -0800257}
258
Saquib Herman9a0244a2011-04-01 10:22:45 +0530259static int twl4030reg_get_status(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800260{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100261 int state = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800262
263 if (state < 0)
264 return state;
265 state &= 0x0f;
266
267 /* assume state != WARM_RESET; we'd not be running... */
268 if (!state)
269 return REGULATOR_STATUS_OFF;
270 return (state & BIT(3))
271 ? REGULATOR_STATUS_NORMAL
272 : REGULATOR_STATUS_STANDBY;
273}
274
Saquib Herman9a0244a2011-04-01 10:22:45 +0530275static int twl6030reg_get_status(struct regulator_dev *rdev)
276{
277 struct twlreg_info *info = rdev_get_drvdata(rdev);
278 int val;
279
280 val = twlreg_grp(rdev);
281 if (val < 0)
282 return val;
283
284 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
285
286 switch (TWL6030_CFG_STATE_APP(val)) {
287 case TWL6030_CFG_STATE_ON:
288 return REGULATOR_STATUS_NORMAL;
289
290 case TWL6030_CFG_STATE_SLEEP:
291 return REGULATOR_STATUS_STANDBY;
292
293 case TWL6030_CFG_STATE_OFF:
294 case TWL6030_CFG_STATE_OFF2:
295 default:
296 break;
297 }
298
299 return REGULATOR_STATUS_OFF;
300}
301
Saquib Herman1a399622011-04-01 10:22:46 +0530302static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
David Brownellfa16a5c2009-02-08 10:37:06 -0800303{
304 struct twlreg_info *info = rdev_get_drvdata(rdev);
305 unsigned message;
306 int status;
307
308 /* We can only set the mode through state machine commands... */
309 switch (mode) {
310 case REGULATOR_MODE_NORMAL:
311 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
312 break;
313 case REGULATOR_MODE_STANDBY:
314 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
315 break;
316 default:
317 return -EINVAL;
318 }
319
320 /* Ensure the resource is associated with some group */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100321 status = twlreg_grp(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800322 if (status < 0)
323 return status;
Rajendra Nayak441a4502009-12-13 22:19:23 +0100324 if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
David Brownellfa16a5c2009-02-08 10:37:06 -0800325 return -EACCES;
326
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100327 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
Axel Linb9e26bc2010-10-22 16:38:22 +0800328 message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
329 if (status < 0)
David Brownellfa16a5c2009-02-08 10:37:06 -0800330 return status;
331
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100332 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
Axel Linb9e26bc2010-10-22 16:38:22 +0800333 message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
David Brownellfa16a5c2009-02-08 10:37:06 -0800334}
335
Saquib Herman1a399622011-04-01 10:22:46 +0530336static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
337{
338 struct twlreg_info *info = rdev_get_drvdata(rdev);
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100339 int grp = 0;
Saquib Herman1a399622011-04-01 10:22:46 +0530340 int val;
341
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100342 if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS)))
Axel Linb6f476c2012-04-11 11:07:17 +0800343 grp = twlreg_grp(rdev);
Saquib Herman1a399622011-04-01 10:22:46 +0530344
345 if (grp < 0)
346 return grp;
347
348 /* Compose the state register settings */
349 val = grp << TWL6030_CFG_STATE_GRP_SHIFT;
350 /* We can only set the mode through state machine commands... */
351 switch (mode) {
352 case REGULATOR_MODE_NORMAL:
353 val |= TWL6030_CFG_STATE_ON;
354 break;
355 case REGULATOR_MODE_STANDBY:
356 val |= TWL6030_CFG_STATE_SLEEP;
357 break;
358
359 default:
360 return -EINVAL;
361 }
362
363 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val);
364}
365
David Brownellfa16a5c2009-02-08 10:37:06 -0800366/*----------------------------------------------------------------------*/
367
368/*
369 * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
370 * select field in its control register. We use tables indexed by VSEL
371 * to record voltages in milliVolts. (Accuracy is about three percent.)
372 *
373 * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
374 * currently handled by listing two slightly different VAUX2 regulators,
375 * only one of which will be configured.
376 *
377 * VSEL values documented as "TI cannot support these values" are flagged
378 * in these tables as UNSUP() values; we normally won't assign them.
Adrian Hunterd6bb69c2009-03-06 14:51:30 +0200379 *
380 * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
381 * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
David Brownellfa16a5c2009-02-08 10:37:06 -0800382 */
David Brownellfa16a5c2009-02-08 10:37:06 -0800383#define UNSUP_MASK 0x8000
David Brownellfa16a5c2009-02-08 10:37:06 -0800384
385#define UNSUP(x) (UNSUP_MASK | (x))
NeilBrown411a2df2012-05-09 05:44:00 +1000386#define IS_UNSUP(info, x) \
387 ((UNSUP_MASK & (x)) && \
388 !((info)->features & TWL4030_ALLOW_UNSUPPORTED))
David Brownellfa16a5c2009-02-08 10:37:06 -0800389#define LDO_MV(x) (~UNSUP_MASK & (x))
390
391
392static const u16 VAUX1_VSEL_table[] = {
393 UNSUP(1500), UNSUP(1800), 2500, 2800,
394 3000, 3000, 3000, 3000,
395};
396static const u16 VAUX2_4030_VSEL_table[] = {
397 UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
398 1500, 1800, UNSUP(1850), 2500,
399 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
400 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
401};
402static const u16 VAUX2_VSEL_table[] = {
403 1700, 1700, 1900, 1300,
404 1500, 1800, 2000, 2500,
405 2100, 2800, 2200, 2300,
406 2400, 2400, 2400, 2400,
407};
408static const u16 VAUX3_VSEL_table[] = {
409 1500, 1800, 2500, 2800,
Adrian Hunterd6bb69c2009-03-06 14:51:30 +0200410 3000, 3000, 3000, 3000,
David Brownellfa16a5c2009-02-08 10:37:06 -0800411};
412static const u16 VAUX4_VSEL_table[] = {
413 700, 1000, 1200, UNSUP(1300),
414 1500, 1800, UNSUP(1850), 2500,
David Brownell1897e742009-03-10 11:51:15 -0800415 UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
416 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
David Brownellfa16a5c2009-02-08 10:37:06 -0800417};
418static const u16 VMMC1_VSEL_table[] = {
419 1850, 2850, 3000, 3150,
420};
421static const u16 VMMC2_VSEL_table[] = {
422 UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
423 UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
424 2600, 2800, 2850, 3000,
425 3150, 3150, 3150, 3150,
426};
427static const u16 VPLL1_VSEL_table[] = {
428 1000, 1200, 1300, 1800,
429 UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
430};
431static const u16 VPLL2_VSEL_table[] = {
432 700, 1000, 1200, 1300,
433 UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
434 UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
435 UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
436};
437static const u16 VSIM_VSEL_table[] = {
438 UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
439 2800, 3000, 3000, 3000,
440};
441static const u16 VDAC_VSEL_table[] = {
442 1200, 1300, 1800, 1800,
443};
Juha Keski-Saari07fc4932009-12-16 15:27:55 +0200444static const u16 VDD1_VSEL_table[] = {
445 800, 1450,
446};
447static const u16 VDD2_VSEL_table[] = {
448 800, 1450, 1500,
449};
450static const u16 VIO_VSEL_table[] = {
451 1800, 1850,
452};
453static const u16 VINTANA2_VSEL_table[] = {
454 2500, 2750,
455};
David Brownellfa16a5c2009-02-08 10:37:06 -0800456
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530457static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
David Brownell66b659e2009-02-26 11:50:14 -0800458{
459 struct twlreg_info *info = rdev_get_drvdata(rdev);
460 int mV = info->table[index];
461
NeilBrown411a2df2012-05-09 05:44:00 +1000462 return IS_UNSUP(info, mV) ? 0 : (LDO_MV(mV) * 1000);
David Brownell66b659e2009-02-26 11:50:14 -0800463}
464
David Brownellfa16a5c2009-02-08 10:37:06 -0800465static int
Axel Lindd16b1f2012-03-26 09:30:06 +0800466twl4030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
David Brownellfa16a5c2009-02-08 10:37:06 -0800467{
468 struct twlreg_info *info = rdev_get_drvdata(rdev);
David Brownellfa16a5c2009-02-08 10:37:06 -0800469
Axel Lindd16b1f2012-03-26 09:30:06 +0800470 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE,
471 selector);
David Brownellfa16a5c2009-02-08 10:37:06 -0800472}
473
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530474static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
David Brownellfa16a5c2009-02-08 10:37:06 -0800475{
476 struct twlreg_info *info = rdev_get_drvdata(rdev);
Rajendra Nayak441a4502009-12-13 22:19:23 +0100477 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
478 VREG_VOLTAGE);
David Brownellfa16a5c2009-02-08 10:37:06 -0800479
480 if (vsel < 0)
481 return vsel;
482
483 vsel &= info->table_len - 1;
484 return LDO_MV(info->table[vsel]) * 1000;
485}
486
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530487static struct regulator_ops twl4030ldo_ops = {
488 .list_voltage = twl4030ldo_list_voltage,
David Brownell66b659e2009-02-26 11:50:14 -0800489
Axel Lindd16b1f2012-03-26 09:30:06 +0800490 .set_voltage_sel = twl4030ldo_set_voltage_sel,
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530491 .get_voltage = twl4030ldo_get_voltage,
492
Balaji T Kf8c29402011-05-20 19:03:51 +0530493 .enable = twl4030reg_enable,
Balaji T K0ff38972011-05-20 19:03:52 +0530494 .disable = twl4030reg_disable,
Saquib Hermanb2456772011-04-01 10:22:44 +0530495 .is_enabled = twl4030reg_is_enabled,
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530496
Saquib Herman1a399622011-04-01 10:22:46 +0530497 .set_mode = twl4030reg_set_mode,
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530498
Saquib Herman9a0244a2011-04-01 10:22:45 +0530499 .get_status = twl4030reg_get_status,
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530500};
501
Tero Kristoba305e32011-11-28 16:53:19 +0200502static int
503twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
504 unsigned *selector)
505{
506 struct twlreg_info *info = rdev_get_drvdata(rdev);
507 int vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
508
Tero Kristo63bfff42012-02-16 12:27:52 +0200509 if (info->set_voltage) {
510 return info->set_voltage(info->data, min_uV);
511 } else {
512 twlreg_write(info, TWL_MODULE_PM_RECEIVER,
513 VREG_VOLTAGE_SMPS_4030, vsel);
514 }
515
Tero Kristoba305e32011-11-28 16:53:19 +0200516 return 0;
517}
518
519static int twl4030smps_get_voltage(struct regulator_dev *rdev)
520{
521 struct twlreg_info *info = rdev_get_drvdata(rdev);
Tero Kristo63bfff42012-02-16 12:27:52 +0200522 int vsel;
523
524 if (info->get_voltage)
525 return info->get_voltage(info->data);
526
527 vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
Tero Kristoba305e32011-11-28 16:53:19 +0200528 VREG_VOLTAGE_SMPS_4030);
529
530 return vsel * 12500 + 600000;
531}
532
533static struct regulator_ops twl4030smps_ops = {
534 .set_voltage = twl4030smps_set_voltage,
535 .get_voltage = twl4030smps_get_voltage,
536};
537
Tero Kristo34a38442012-02-28 15:09:10 +0530538static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV,
539 int max_uV, unsigned *selector)
540{
541 struct twlreg_info *info = rdev_get_drvdata(rdev);
542
543 if (info->set_voltage)
544 return info->set_voltage(info->data, min_uV);
545
546 return -ENODEV;
547}
548
549static int twl6030coresmps_get_voltage(struct regulator_dev *rdev)
550{
551 struct twlreg_info *info = rdev_get_drvdata(rdev);
552
553 if (info->get_voltage)
554 return info->get_voltage(info->data);
555
556 return -ENODEV;
557}
558
559static struct regulator_ops twl6030coresmps_ops = {
560 .set_voltage = twl6030coresmps_set_voltage,
561 .get_voltage = twl6030coresmps_get_voltage,
562};
563
Axel Linc6a717c2012-07-16 18:31:10 +0800564static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel)
565{
566 struct twlreg_info *info = rdev_get_drvdata(rdev);
567
568 switch (sel) {
569 case 0:
570 return 0;
571 case 1 ... 24:
572 /* Linear mapping from 00000001 to 00011000:
573 * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001)
574 */
575 return (info->min_mV + 100 * (sel - 1)) * 1000;
576 case 25 ... 30:
577 return -EINVAL;
578 case 31:
579 return 2750000;
580 default:
581 return -EINVAL;
582 }
583}
584
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530585static int
Axel Lin4bcb9f42012-07-09 11:26:28 +0800586twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530587{
588 struct twlreg_info *info = rdev_get_drvdata(rdev);
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530589
Axel Lin4bcb9f42012-07-09 11:26:28 +0800590 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE,
591 selector);
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530592}
593
Axel Lin4bcb9f42012-07-09 11:26:28 +0800594static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev)
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530595{
596 struct twlreg_info *info = rdev_get_drvdata(rdev);
Axel Lina3cb80f2012-07-09 11:22:31 +0800597 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE);
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530598
Axel Lin4bcb9f42012-07-09 11:26:28 +0800599 return vsel;
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530600}
601
602static struct regulator_ops twl6030ldo_ops = {
Axel Linc6a717c2012-07-16 18:31:10 +0800603 .list_voltage = twl6030ldo_list_voltage,
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530604
Axel Lin4bcb9f42012-07-09 11:26:28 +0800605 .set_voltage_sel = twl6030ldo_set_voltage_sel,
606 .get_voltage_sel = twl6030ldo_get_voltage_sel,
David Brownellfa16a5c2009-02-08 10:37:06 -0800607
Balaji T Kf8c29402011-05-20 19:03:51 +0530608 .enable = twl6030reg_enable,
Balaji T K0ff38972011-05-20 19:03:52 +0530609 .disable = twl6030reg_disable,
Saquib Hermanb2456772011-04-01 10:22:44 +0530610 .is_enabled = twl6030reg_is_enabled,
David Brownellfa16a5c2009-02-08 10:37:06 -0800611
Saquib Herman1a399622011-04-01 10:22:46 +0530612 .set_mode = twl6030reg_set_mode,
David Brownellfa16a5c2009-02-08 10:37:06 -0800613
Saquib Herman9a0244a2011-04-01 10:22:45 +0530614 .get_status = twl6030reg_get_status,
David Brownellfa16a5c2009-02-08 10:37:06 -0800615};
616
617/*----------------------------------------------------------------------*/
618
619/*
620 * Fixed voltage LDOs don't have a VSEL field to update.
621 */
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100622static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
David Brownell66b659e2009-02-26 11:50:14 -0800623{
624 struct twlreg_info *info = rdev_get_drvdata(rdev);
625
626 return info->min_mV * 1000;
627}
628
Saquib Hermanb2456772011-04-01 10:22:44 +0530629static struct regulator_ops twl4030fixed_ops = {
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100630 .list_voltage = twlfixed_list_voltage,
David Brownell66b659e2009-02-26 11:50:14 -0800631
Balaji T Kf8c29402011-05-20 19:03:51 +0530632 .enable = twl4030reg_enable,
Balaji T K0ff38972011-05-20 19:03:52 +0530633 .disable = twl4030reg_disable,
Saquib Hermanb2456772011-04-01 10:22:44 +0530634 .is_enabled = twl4030reg_is_enabled,
635
Saquib Herman1a399622011-04-01 10:22:46 +0530636 .set_mode = twl4030reg_set_mode,
Saquib Hermanb2456772011-04-01 10:22:44 +0530637
Saquib Herman9a0244a2011-04-01 10:22:45 +0530638 .get_status = twl4030reg_get_status,
Saquib Hermanb2456772011-04-01 10:22:44 +0530639};
640
641static struct regulator_ops twl6030fixed_ops = {
642 .list_voltage = twlfixed_list_voltage,
643
Balaji T Kf8c29402011-05-20 19:03:51 +0530644 .enable = twl6030reg_enable,
Balaji T K0ff38972011-05-20 19:03:52 +0530645 .disable = twl6030reg_disable,
Saquib Hermanb2456772011-04-01 10:22:44 +0530646 .is_enabled = twl6030reg_is_enabled,
David Brownellfa16a5c2009-02-08 10:37:06 -0800647
Saquib Herman1a399622011-04-01 10:22:46 +0530648 .set_mode = twl6030reg_set_mode,
David Brownellfa16a5c2009-02-08 10:37:06 -0800649
Saquib Herman9a0244a2011-04-01 10:22:45 +0530650 .get_status = twl6030reg_get_status,
David Brownellfa16a5c2009-02-08 10:37:06 -0800651};
652
Balaji T K8e6de4a2011-02-10 18:44:50 +0530653static struct regulator_ops twl6030_fixed_resource = {
Balaji T Kf8c29402011-05-20 19:03:51 +0530654 .enable = twl6030reg_enable,
Balaji T K0ff38972011-05-20 19:03:52 +0530655 .disable = twl6030reg_disable,
Saquib Hermanb2456772011-04-01 10:22:44 +0530656 .is_enabled = twl6030reg_is_enabled,
Saquib Herman9a0244a2011-04-01 10:22:45 +0530657 .get_status = twl6030reg_get_status,
Balaji T K8e6de4a2011-02-10 18:44:50 +0530658};
659
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100660/*
661 * SMPS status and control
662 */
663
664static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
665{
666 struct twlreg_info *info = rdev_get_drvdata(rdev);
667
668 int voltage = 0;
669
670 switch (info->flags) {
671 case SMPS_OFFSET_EN:
672 voltage = 100000;
673 /* fall through */
674 case 0:
675 switch (index) {
676 case 0:
677 voltage = 0;
678 break;
679 case 58:
680 voltage = 1350 * 1000;
681 break;
682 case 59:
683 voltage = 1500 * 1000;
684 break;
685 case 60:
686 voltage = 1800 * 1000;
687 break;
688 case 61:
689 voltage = 1900 * 1000;
690 break;
691 case 62:
692 voltage = 2100 * 1000;
693 break;
694 default:
695 voltage += (600000 + (12500 * (index - 1)));
696 }
697 break;
698 case SMPS_EXTENDED_EN:
699 switch (index) {
700 case 0:
701 voltage = 0;
702 break;
703 case 58:
704 voltage = 2084 * 1000;
705 break;
706 case 59:
707 voltage = 2315 * 1000;
708 break;
709 case 60:
710 voltage = 2778 * 1000;
711 break;
712 case 61:
713 voltage = 2932 * 1000;
714 break;
715 case 62:
716 voltage = 3241 * 1000;
717 break;
718 default:
719 voltage = (1852000 + (38600 * (index - 1)));
720 }
721 break;
722 case SMPS_OFFSET_EN | SMPS_EXTENDED_EN:
723 switch (index) {
724 case 0:
725 voltage = 0;
726 break;
727 case 58:
728 voltage = 4167 * 1000;
729 break;
730 case 59:
731 voltage = 2315 * 1000;
732 break;
733 case 60:
734 voltage = 2778 * 1000;
735 break;
736 case 61:
737 voltage = 2932 * 1000;
738 break;
739 case 62:
740 voltage = 3241 * 1000;
741 break;
742 default:
743 voltage = (2161000 + (38600 * (index - 1)));
744 }
745 break;
746 }
747
748 return voltage;
749}
750
Axel Lin38f8f432012-07-14 13:41:23 +0800751static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV,
752 int max_uV)
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100753{
Axel Lin38f8f432012-07-14 13:41:23 +0800754 struct twlreg_info *info = rdev_get_drvdata(rdev);
755 int vsel = 0;
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100756
757 switch (info->flags) {
758 case 0:
759 if (min_uV == 0)
760 vsel = 0;
Laxman Dewangana33b6e52012-02-03 12:54:38 +0530761 else if ((min_uV >= 600000) && (min_uV <= 1300000)) {
Axel Lin268a1642012-04-09 23:35:10 +0800762 vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
Axel Lin0cb2f122012-04-10 23:07:52 +0800763 vsel++;
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100764 }
765 /* Values 1..57 for vsel are linear and can be calculated
766 * values 58..62 are non linear.
767 */
Axel Lin78292f42012-07-14 13:37:13 +0800768 else if ((min_uV > 1900000) && (min_uV <= 2100000))
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100769 vsel = 62;
Axel Lin78292f42012-07-14 13:37:13 +0800770 else if ((min_uV > 1800000) && (min_uV <= 1900000))
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100771 vsel = 61;
Axel Lin78292f42012-07-14 13:37:13 +0800772 else if ((min_uV > 1500000) && (min_uV <= 1800000))
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100773 vsel = 60;
Axel Lin78292f42012-07-14 13:37:13 +0800774 else if ((min_uV > 1350000) && (min_uV <= 1500000))
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100775 vsel = 59;
Axel Lin78292f42012-07-14 13:37:13 +0800776 else if ((min_uV > 1300000) && (min_uV <= 1350000))
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100777 vsel = 58;
778 else
779 return -EINVAL;
780 break;
781 case SMPS_OFFSET_EN:
782 if (min_uV == 0)
783 vsel = 0;
Laxman Dewangana33b6e52012-02-03 12:54:38 +0530784 else if ((min_uV >= 700000) && (min_uV <= 1420000)) {
Axel Lin268a1642012-04-09 23:35:10 +0800785 vsel = DIV_ROUND_UP(min_uV - 700000, 12500);
Axel Lin0cb2f122012-04-10 23:07:52 +0800786 vsel++;
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100787 }
788 /* Values 1..57 for vsel are linear and can be calculated
789 * values 58..62 are non linear.
790 */
Axel Lin78292f42012-07-14 13:37:13 +0800791 else if ((min_uV > 1900000) && (min_uV <= 2100000))
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100792 vsel = 62;
Axel Lin78292f42012-07-14 13:37:13 +0800793 else if ((min_uV > 1800000) && (min_uV <= 1900000))
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100794 vsel = 61;
Axel Lin78292f42012-07-14 13:37:13 +0800795 else if ((min_uV > 1350000) && (min_uV <= 1800000))
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100796 vsel = 60;
Axel Lin78292f42012-07-14 13:37:13 +0800797 else if ((min_uV > 1350000) && (min_uV <= 1500000))
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100798 vsel = 59;
Axel Lin78292f42012-07-14 13:37:13 +0800799 else if ((min_uV > 1300000) && (min_uV <= 1350000))
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100800 vsel = 58;
801 else
802 return -EINVAL;
803 break;
804 case SMPS_EXTENDED_EN:
Axel Lin0cb2f122012-04-10 23:07:52 +0800805 if (min_uV == 0) {
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100806 vsel = 0;
Axel Lin0cb2f122012-04-10 23:07:52 +0800807 } else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
Axel Lin268a1642012-04-09 23:35:10 +0800808 vsel = DIV_ROUND_UP(min_uV - 1852000, 38600);
Axel Lin0cb2f122012-04-10 23:07:52 +0800809 vsel++;
810 }
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100811 break;
812 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
Axel Lin0cb2f122012-04-10 23:07:52 +0800813 if (min_uV == 0) {
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100814 vsel = 0;
Axel Lin78292f42012-07-14 13:37:13 +0800815 } else if ((min_uV >= 2161000) && (min_uV <= 4321000)) {
Axel Lin268a1642012-04-09 23:35:10 +0800816 vsel = DIV_ROUND_UP(min_uV - 2161000, 38600);
Axel Lin0cb2f122012-04-10 23:07:52 +0800817 vsel++;
818 }
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100819 break;
820 }
821
Axel Lin38f8f432012-07-14 13:41:23 +0800822 return vsel;
823}
Axel Lin78292f42012-07-14 13:37:13 +0800824
Axel Lin38f8f432012-07-14 13:41:23 +0800825static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev,
826 unsigned int selector)
827{
828 struct twlreg_info *info = rdev_get_drvdata(rdev);
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100829
830 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
Axel Lin38f8f432012-07-14 13:41:23 +0800831 selector);
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100832}
833
834static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
835{
836 struct twlreg_info *info = rdev_get_drvdata(rdev);
837
838 return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS);
839}
840
841static struct regulator_ops twlsmps_ops = {
842 .list_voltage = twl6030smps_list_voltage,
Axel Lin38f8f432012-07-14 13:41:23 +0800843 .map_voltage = twl6030smps_map_voltage,
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100844
Axel Lin38f8f432012-07-14 13:41:23 +0800845 .set_voltage_sel = twl6030smps_set_voltage_sel,
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100846 .get_voltage_sel = twl6030smps_get_voltage_sel,
847
848 .enable = twl6030reg_enable,
849 .disable = twl6030reg_disable,
850 .is_enabled = twl6030reg_is_enabled,
851
852 .set_mode = twl6030reg_set_mode,
853
854 .get_status = twl6030reg_get_status,
855};
856
David Brownellfa16a5c2009-02-08 10:37:06 -0800857/*----------------------------------------------------------------------*/
858
Juha Keski-Saari045f9722009-12-16 14:49:52 +0200859#define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
860 remap_conf) \
861 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
Saquib Hermanb2456772011-04-01 10:22:44 +0530862 remap_conf, TWL4030, twl4030fixed_ops)
Ambresh Kaf8b2442011-07-09 19:02:21 -0700863#define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
864 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
Saquib Hermanb2456772011-04-01 10:22:44 +0530865 0x0, TWL6030, twl6030fixed_ops)
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100866
Rajendra Nayak2098e952012-02-28 15:09:11 +0530867#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +0000868static const struct twlreg_info TWL4030_INFO_##label = { \
David Brownellfa16a5c2009-02-08 10:37:06 -0800869 .base = offset, \
870 .id = num, \
871 .table_len = ARRAY_SIZE(label##_VSEL_table), \
872 .table = label##_VSEL_table, \
Juha Keski-Saari045f9722009-12-16 14:49:52 +0200873 .remap = remap_conf, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800874 .desc = { \
875 .name = #label, \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530876 .id = TWL4030_REG_##label, \
David Brownell66b659e2009-02-26 11:50:14 -0800877 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530878 .ops = &twl4030ldo_ops, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800879 .type = REGULATOR_VOLTAGE, \
880 .owner = THIS_MODULE, \
Axel Linfca53d82012-07-04 10:46:34 +0800881 .enable_time = turnon_delay, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800882 }, \
883 }
884
Tero Kristoba305e32011-11-28 16:53:19 +0200885#define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +0000886static const struct twlreg_info TWL4030_INFO_##label = { \
Tero Kristoba305e32011-11-28 16:53:19 +0200887 .base = offset, \
888 .id = num, \
Tero Kristoba305e32011-11-28 16:53:19 +0200889 .remap = remap_conf, \
890 .desc = { \
891 .name = #label, \
892 .id = TWL4030_REG_##label, \
893 .ops = &twl4030smps_ops, \
894 .type = REGULATOR_VOLTAGE, \
895 .owner = THIS_MODULE, \
Axel Linfca53d82012-07-04 10:46:34 +0800896 .enable_time = turnon_delay, \
Tero Kristoba305e32011-11-28 16:53:19 +0200897 }, \
898 }
899
Rajendra Nayak2098e952012-02-28 15:09:11 +0530900#define TWL6030_ADJUSTABLE_SMPS(label) \
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +0000901static const struct twlreg_info TWL6030_INFO_##label = { \
Tero Kristo34a38442012-02-28 15:09:10 +0530902 .desc = { \
903 .name = #label, \
904 .id = TWL6030_REG_##label, \
905 .ops = &twl6030coresmps_ops, \
906 .type = REGULATOR_VOLTAGE, \
907 .owner = THIS_MODULE, \
908 }, \
909 }
910
Rajendra Nayak2098e952012-02-28 15:09:11 +0530911#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +0000912static const struct twlreg_info TWL6030_INFO_##label = { \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530913 .base = offset, \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530914 .min_mV = min_mVolts, \
915 .max_mV = max_mVolts, \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530916 .desc = { \
917 .name = #label, \
918 .id = TWL6030_REG_##label, \
Axel Linc6a717c2012-07-16 18:31:10 +0800919 .n_voltages = 32, \
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530920 .ops = &twl6030ldo_ops, \
921 .type = REGULATOR_VOLTAGE, \
922 .owner = THIS_MODULE, \
923 }, \
924 }
925
Rajendra Nayak2098e952012-02-28 15:09:11 +0530926#define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +0000927static const struct twlreg_info TWL6025_INFO_##label = { \
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100928 .base = offset, \
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100929 .min_mV = min_mVolts, \
930 .max_mV = max_mVolts, \
931 .desc = { \
932 .name = #label, \
933 .id = TWL6025_REG_##label, \
Axel Linc6a717c2012-07-16 18:31:10 +0800934 .n_voltages = 32, \
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100935 .ops = &twl6030ldo_ops, \
936 .type = REGULATOR_VOLTAGE, \
937 .owner = THIS_MODULE, \
938 }, \
939 }
Rajendra Nayak3e3d3be2010-04-22 14:18:32 +0530940
Juha Keski-Saari045f9722009-12-16 14:49:52 +0200941#define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
Rajendra Nayak2098e952012-02-28 15:09:11 +0530942 family, operations) \
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +0000943static const struct twlreg_info TWLFIXED_INFO_##label = { \
David Brownellfa16a5c2009-02-08 10:37:06 -0800944 .base = offset, \
945 .id = num, \
946 .min_mV = mVolts, \
Juha Keski-Saari045f9722009-12-16 14:49:52 +0200947 .remap = remap_conf, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800948 .desc = { \
949 .name = #label, \
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +0100950 .id = family##_REG_##label, \
David Brownell66b659e2009-02-26 11:50:14 -0800951 .n_voltages = 1, \
Saquib Hermanb2456772011-04-01 10:22:44 +0530952 .ops = &operations, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800953 .type = REGULATOR_VOLTAGE, \
954 .owner = THIS_MODULE, \
Axel Linfca53d82012-07-04 10:46:34 +0800955 .enable_time = turnon_delay, \
David Brownellfa16a5c2009-02-08 10:37:06 -0800956 }, \
957 }
958
Rajendra Nayak2098e952012-02-28 15:09:11 +0530959#define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \
960static struct twlreg_info TWLRES_INFO_##label = { \
Balaji T K8e6de4a2011-02-10 18:44:50 +0530961 .base = offset, \
Balaji T K8e6de4a2011-02-10 18:44:50 +0530962 .desc = { \
963 .name = #label, \
964 .id = TWL6030_REG_##label, \
965 .ops = &twl6030_fixed_resource, \
966 .type = REGULATOR_VOLTAGE, \
967 .owner = THIS_MODULE, \
Axel Linfca53d82012-07-04 10:46:34 +0800968 .enable_time = turnon_delay, \
Balaji T K8e6de4a2011-02-10 18:44:50 +0530969 }, \
970 }
971
Rajendra Nayak2098e952012-02-28 15:09:11 +0530972#define TWL6025_ADJUSTABLE_SMPS(label, offset) \
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +0000973static const struct twlreg_info TWLSMPS_INFO_##label = { \
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100974 .base = offset, \
Graeme Gregory4d94aee2011-05-22 21:21:23 +0100975 .min_mV = 600, \
976 .max_mV = 2100, \
977 .desc = { \
978 .name = #label, \
979 .id = TWL6025_REG_##label, \
980 .n_voltages = 63, \
981 .ops = &twlsmps_ops, \
982 .type = REGULATOR_VOLTAGE, \
983 .owner = THIS_MODULE, \
984 }, \
985 }
986
David Brownellfa16a5c2009-02-08 10:37:06 -0800987/*
988 * We list regulators here if systems need some level of
989 * software control over them after boot.
990 */
Rajendra Nayak2098e952012-02-28 15:09:11 +0530991TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08);
992TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08);
993TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08);
994TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08);
995TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08);
996TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08);
997TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08);
998TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00);
999TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08);
1000TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00);
1001TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08);
1002TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08);
1003TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08);
1004TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08);
1005TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08);
1006/* VUSBCP is managed *only* by the USB subchip */
1007/* 6030 REG with base as PMC Slave Misc : 0x0030 */
1008/* Turnon-delay and remap configuration values for 6030 are not
1009 verified since the specification is not public */
1010TWL6030_ADJUSTABLE_SMPS(VDD1);
1011TWL6030_ADJUSTABLE_SMPS(VDD2);
1012TWL6030_ADJUSTABLE_SMPS(VDD3);
1013TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300);
1014TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300);
1015TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300);
1016TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300);
1017TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300);
1018TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300);
1019/* 6025 are renamed compared to 6030 versions */
1020TWL6025_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300);
1021TWL6025_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300);
1022TWL6025_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300);
1023TWL6025_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300);
1024TWL6025_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300);
1025TWL6025_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300);
1026TWL6025_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300);
1027TWL6025_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300);
1028TWL6025_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300);
Aaro Koskinen908d6d52012-08-15 01:10:04 +03001029TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08);
Rajendra Nayak2098e952012-02-28 15:09:11 +05301030TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08);
1031TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08);
1032TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08);
1033TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08);
1034TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0);
1035TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0);
1036TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0);
1037TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0);
Peter Ujfalusie9d47fa2012-02-28 15:09:12 +05301038TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0);
1039TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0);
Rajendra Nayak2098e952012-02-28 15:09:11 +05301040TWL6025_ADJUSTABLE_SMPS(SMPS3, 0x34);
1041TWL6025_ADJUSTABLE_SMPS(SMPS4, 0x10);
1042TWL6025_ADJUSTABLE_SMPS(VIO, 0x16);
David Brownellfa16a5c2009-02-08 10:37:06 -08001043
Graeme Gregory4d94aee2011-05-22 21:21:23 +01001044static u8 twl_get_smps_offset(void)
1045{
1046 u8 value;
1047
1048 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1049 TWL6030_SMPS_OFFSET);
1050 return value;
1051}
1052
1053static u8 twl_get_smps_mult(void)
1054{
1055 u8 value;
1056
1057 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1058 TWL6030_SMPS_MULT);
1059 return value;
1060}
1061
Rajendra Nayak2098e952012-02-28 15:09:11 +05301062#define TWL_OF_MATCH(comp, family, label) \
1063 { \
1064 .compatible = comp, \
1065 .data = &family##_INFO_##label, \
1066 }
1067
1068#define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label)
1069#define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label)
1070#define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label)
1071#define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
Rajendra Nayak2098e952012-02-28 15:09:11 +05301072#define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
1073
1074static const struct of_device_id twl_of_match[] __devinitconst = {
1075 TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1),
1076 TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030),
1077 TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2),
1078 TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3),
1079 TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4),
1080 TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1),
1081 TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2),
1082 TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1),
1083 TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2),
1084 TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM),
1085 TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC),
1086 TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2),
1087 TWL4030_OF_MATCH("ti,twl4030-vio", VIO),
1088 TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1),
1089 TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2),
1090 TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1),
1091 TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2),
1092 TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3),
1093 TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030),
1094 TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030),
1095 TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030),
1096 TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC),
1097 TWL6030_OF_MATCH("ti,twl6030-vpp", VPP),
1098 TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM),
1099 TWL6025_OF_MATCH("ti,twl6025-ldo2", LDO2),
1100 TWL6025_OF_MATCH("ti,twl6025-ldo4", LDO4),
1101 TWL6025_OF_MATCH("ti,twl6025-ldo3", LDO3),
1102 TWL6025_OF_MATCH("ti,twl6025-ldo5", LDO5),
1103 TWL6025_OF_MATCH("ti,twl6025-ldo1", LDO1),
1104 TWL6025_OF_MATCH("ti,twl6025-ldo7", LDO7),
1105 TWL6025_OF_MATCH("ti,twl6025-ldo6", LDO6),
1106 TWL6025_OF_MATCH("ti,twl6025-ldoln", LDOLN),
1107 TWL6025_OF_MATCH("ti,twl6025-ldousb", LDOUSB),
Aaro Koskinen908d6d52012-08-15 01:10:04 +03001108 TWLFIXED_OF_MATCH("ti,twl4030-vintana1", VINTANA1),
Rajendra Nayak2098e952012-02-28 15:09:11 +05301109 TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG),
1110 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5),
1111 TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8),
1112 TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1),
1113 TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA),
1114 TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO),
1115 TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC),
1116 TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB),
Peter Ujfalusie9d47fa2012-02-28 15:09:12 +05301117 TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8),
1118 TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1),
Rajendra Nayak2098e952012-02-28 15:09:11 +05301119 TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3),
1120 TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4),
1121 TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO),
1122 {},
1123};
1124MODULE_DEVICE_TABLE(of, twl_of_match);
1125
Dmitry Torokhov24c29022010-02-23 23:38:01 -08001126static int __devinit twlreg_probe(struct platform_device *pdev)
David Brownellfa16a5c2009-02-08 10:37:06 -08001127{
Rajendra Nayak2098e952012-02-28 15:09:11 +05301128 int i, id;
David Brownellfa16a5c2009-02-08 10:37:06 -08001129 struct twlreg_info *info;
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +00001130 const struct twlreg_info *template;
David Brownellfa16a5c2009-02-08 10:37:06 -08001131 struct regulator_init_data *initdata;
1132 struct regulation_constraints *c;
1133 struct regulator_dev *rdev;
Tero Kristo63bfff42012-02-16 12:27:52 +02001134 struct twl_regulator_driver_data *drvdata;
Rajendra Nayak2098e952012-02-28 15:09:11 +05301135 const struct of_device_id *match;
Mark Brownc1727082012-04-04 00:50:22 +01001136 struct regulator_config config = { };
David Brownellfa16a5c2009-02-08 10:37:06 -08001137
Rajendra Nayak2098e952012-02-28 15:09:11 +05301138 match = of_match_device(twl_of_match, &pdev->dev);
1139 if (match) {
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +00001140 template = match->data;
1141 id = template->desc.id;
Rajendra Nayak2098e952012-02-28 15:09:11 +05301142 initdata = of_get_regulator_init_data(&pdev->dev,
1143 pdev->dev.of_node);
1144 drvdata = NULL;
1145 } else {
1146 id = pdev->id;
1147 initdata = pdev->dev.platform_data;
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +00001148 for (i = 0, template = NULL; i < ARRAY_SIZE(twl_of_match); i++) {
1149 template = twl_of_match[i].data;
1150 if (template && template->desc.id == id)
Axel Lin5ade3932012-04-09 22:32:49 +08001151 break;
Rajendra Nayak2098e952012-02-28 15:09:11 +05301152 }
Axel Lin5ade3932012-04-09 22:32:49 +08001153 if (i == ARRAY_SIZE(twl_of_match))
1154 return -ENODEV;
1155
Rajendra Nayak2098e952012-02-28 15:09:11 +05301156 drvdata = initdata->driver_data;
1157 if (!drvdata)
1158 return -EINVAL;
David Brownellfa16a5c2009-02-08 10:37:06 -08001159 }
Rajendra Nayak2098e952012-02-28 15:09:11 +05301160
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +00001161 if (!template)
David Brownellfa16a5c2009-02-08 10:37:06 -08001162 return -ENODEV;
1163
David Brownellfa16a5c2009-02-08 10:37:06 -08001164 if (!initdata)
1165 return -EINVAL;
1166
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +00001167 info = kmemdup(template, sizeof (*info), GFP_KERNEL);
1168 if (!info)
1169 return -ENOMEM;
1170
Rajendra Nayak2098e952012-02-28 15:09:11 +05301171 if (drvdata) {
1172 /* copy the driver data into regulator data */
1173 info->features = drvdata->features;
1174 info->data = drvdata->data;
1175 info->set_voltage = drvdata->set_voltage;
1176 info->get_voltage = drvdata->get_voltage;
1177 }
Graeme Gregory4d94aee2011-05-22 21:21:23 +01001178
David Brownellfa16a5c2009-02-08 10:37:06 -08001179 /* Constrain board-specific capabilities according to what
1180 * this driver and the chip itself can actually do.
1181 */
1182 c = &initdata->constraints;
David Brownellfa16a5c2009-02-08 10:37:06 -08001183 c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
1184 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
1185 | REGULATOR_CHANGE_MODE
1186 | REGULATOR_CHANGE_STATUS;
Rajendra Nayak2098e952012-02-28 15:09:11 +05301187 switch (id) {
Juha Keski-Saari205e5cd2009-12-16 15:27:56 +02001188 case TWL4030_REG_VIO:
1189 case TWL4030_REG_VDD1:
1190 case TWL4030_REG_VDD2:
1191 case TWL4030_REG_VPLL1:
1192 case TWL4030_REG_VINTANA1:
1193 case TWL4030_REG_VINTANA2:
1194 case TWL4030_REG_VINTDIG:
1195 c->always_on = true;
1196 break;
1197 default:
1198 break;
1199 }
David Brownellfa16a5c2009-02-08 10:37:06 -08001200
Rajendra Nayak2098e952012-02-28 15:09:11 +05301201 switch (id) {
Graeme Gregory4d94aee2011-05-22 21:21:23 +01001202 case TWL6025_REG_SMPS3:
1203 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3)
1204 info->flags |= SMPS_EXTENDED_EN;
1205 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3)
1206 info->flags |= SMPS_OFFSET_EN;
1207 break;
1208 case TWL6025_REG_SMPS4:
1209 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4)
1210 info->flags |= SMPS_EXTENDED_EN;
1211 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4)
1212 info->flags |= SMPS_OFFSET_EN;
1213 break;
1214 case TWL6025_REG_VIO:
1215 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO)
1216 info->flags |= SMPS_EXTENDED_EN;
1217 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO)
1218 info->flags |= SMPS_OFFSET_EN;
1219 break;
1220 }
1221
Mark Brownc1727082012-04-04 00:50:22 +01001222 config.dev = &pdev->dev;
1223 config.init_data = initdata;
1224 config.driver_data = info;
1225 config.of_node = pdev->dev.of_node;
1226
1227 rdev = regulator_register(&info->desc, &config);
David Brownellfa16a5c2009-02-08 10:37:06 -08001228 if (IS_ERR(rdev)) {
1229 dev_err(&pdev->dev, "can't register %s, %ld\n",
1230 info->desc.name, PTR_ERR(rdev));
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +00001231 kfree(info);
David Brownellfa16a5c2009-02-08 10:37:06 -08001232 return PTR_ERR(rdev);
1233 }
1234 platform_set_drvdata(pdev, rdev);
1235
Saquib Herman776dc922011-04-01 10:22:43 +05301236 if (twl_class_is_4030())
1237 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
Juha Keski-Saari30010fa2009-12-16 15:27:58 +02001238 info->remap);
1239
David Brownellfa16a5c2009-02-08 10:37:06 -08001240 /* NOTE: many regulators support short-circuit IRQs (presentable
1241 * as REGULATOR_OVER_CURRENT notifications?) configured via:
1242 * - SC_CONFIG
1243 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
1244 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
1245 * - IT_CONFIG
1246 */
1247
1248 return 0;
1249}
1250
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001251static int __devexit twlreg_remove(struct platform_device *pdev)
David Brownellfa16a5c2009-02-08 10:37:06 -08001252{
Arnd Bergmann0ffff5a2012-08-14 12:41:50 +00001253 struct regulator_dev *rdev = platform_get_drvdata(pdev);
1254 struct twlreg_info *info = rdev->reg_data;
1255
1256 regulator_unregister(rdev);
1257 kfree(info);
David Brownellfa16a5c2009-02-08 10:37:06 -08001258 return 0;
1259}
1260
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001261MODULE_ALIAS("platform:twl_reg");
David Brownellfa16a5c2009-02-08 10:37:06 -08001262
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001263static struct platform_driver twlreg_driver = {
1264 .probe = twlreg_probe,
1265 .remove = __devexit_p(twlreg_remove),
David Brownellfa16a5c2009-02-08 10:37:06 -08001266 /* NOTE: short name, to work around driver model truncation of
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001267 * "twl_regulator.12" (and friends) to "twl_regulator.1".
David Brownellfa16a5c2009-02-08 10:37:06 -08001268 */
Rajendra Nayak2098e952012-02-28 15:09:11 +05301269 .driver = {
1270 .name = "twl_reg",
1271 .owner = THIS_MODULE,
1272 .of_match_table = of_match_ptr(twl_of_match),
1273 },
David Brownellfa16a5c2009-02-08 10:37:06 -08001274};
1275
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001276static int __init twlreg_init(void)
David Brownellfa16a5c2009-02-08 10:37:06 -08001277{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001278 return platform_driver_register(&twlreg_driver);
David Brownellfa16a5c2009-02-08 10:37:06 -08001279}
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001280subsys_initcall(twlreg_init);
David Brownellfa16a5c2009-02-08 10:37:06 -08001281
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001282static void __exit twlreg_exit(void)
David Brownellfa16a5c2009-02-08 10:37:06 -08001283{
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001284 platform_driver_unregister(&twlreg_driver);
David Brownellfa16a5c2009-02-08 10:37:06 -08001285}
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001286module_exit(twlreg_exit)
David Brownellfa16a5c2009-02-08 10:37:06 -08001287
Rajendra Nayakc4aa6f32009-12-13 21:36:49 +01001288MODULE_DESCRIPTION("TWL regulator driver");
David Brownellfa16a5c2009-02-08 10:37:06 -08001289MODULE_LICENSE("GPL");