]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - drivers/regulator/twl6030-regulator.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
[mirror_ubuntu-kernels.git] / drivers / regulator / twl6030-regulator.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
cac28ae6
NR
2/*
3 * Split TWL6030 logic from twl-regulator.c:
4 * Copyright (C) 2008 David Brownell
5 *
6 * Copyright (C) 2016 Nicolae Rosia <nicolae.rosia@gmail.com>
cac28ae6
NR
7 */
8
9#include <linux/module.h>
10#include <linux/string.h>
11#include <linux/slab.h>
12#include <linux/init.h>
13#include <linux/err.h>
14#include <linux/platform_device.h>
15#include <linux/of.h>
16#include <linux/of_device.h>
17#include <linux/regulator/driver.h>
18#include <linux/regulator/machine.h>
19#include <linux/regulator/of_regulator.h>
a2054256 20#include <linux/mfd/twl.h>
cac28ae6
NR
21#include <linux/delay.h>
22
23struct twlreg_info {
24 /* start of regulator's PM_RECEIVER control register bank */
25 u8 base;
26
27 /* twl resource ID, for resource control state machine */
28 u8 id;
29
cac28ae6
NR
30 u8 flags;
31
32 /* used by regulator core */
33 struct regulator_desc desc;
34
35 /* chip specific features */
36 unsigned long features;
37
38 /* data passed from board for external get/set voltage */
39 void *data;
40};
41
42
43/* LDO control registers ... offset is from the base of its register bank.
44 * The first three registers of all power resource banks help hardware to
45 * manage the various resource groups.
46 */
47/* Common offset in TWL4030/6030 */
48#define VREG_GRP 0
49/* TWL6030 register offsets */
50#define VREG_TRANS 1
51#define VREG_STATE 2
52#define VREG_VOLTAGE 3
53#define VREG_VOLTAGE_SMPS 4
54/* TWL6030 Misc register offsets */
55#define VREG_BC_ALL 1
56#define VREG_BC_REF 2
57#define VREG_BC_PROC 3
58#define VREG_BC_CLK_RST 4
59
60/* TWL6030 LDO register values for CFG_STATE */
61#define TWL6030_CFG_STATE_OFF 0x00
62#define TWL6030_CFG_STATE_ON 0x01
63#define TWL6030_CFG_STATE_OFF2 0x02
64#define TWL6030_CFG_STATE_SLEEP 0x03
65#define TWL6030_CFG_STATE_GRP_SHIFT 5
66#define TWL6030_CFG_STATE_APP_SHIFT 2
67#define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
68#define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
69 TWL6030_CFG_STATE_APP_SHIFT)
70
71/* Flags for SMPS Voltage reading */
72#define SMPS_OFFSET_EN BIT(0)
73#define SMPS_EXTENDED_EN BIT(1)
74
75/* twl6032 SMPS EPROM values */
76#define TWL6030_SMPS_OFFSET 0xB0
77#define TWL6030_SMPS_MULT 0xB3
78#define SMPS_MULTOFFSET_SMPS4 BIT(0)
79#define SMPS_MULTOFFSET_VIO BIT(1)
80#define SMPS_MULTOFFSET_SMPS3 BIT(6)
81
82static inline int
83twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
84{
85 u8 value;
86 int status;
87
88 status = twl_i2c_read_u8(slave_subgp,
89 &value, info->base + offset);
90 return (status < 0) ? status : value;
91}
92
93static inline int
94twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
95 u8 value)
96{
97 return twl_i2c_write_u8(slave_subgp,
98 value, info->base + offset);
99}
100
101/* generic power resource operations, which work on all regulators */
102static int twlreg_grp(struct regulator_dev *rdev)
103{
104 return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
105 VREG_GRP);
106}
107
108/*
109 * Enable/disable regulators by joining/leaving the P1 (processor) group.
110 * We assume nobody else is updating the DEV_GRP registers.
111 */
112/* definition for 6030 family */
113#define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */
114#define P2_GRP_6030 BIT(1) /* "peripherals" */
115#define P1_GRP_6030 BIT(0) /* CPU/Linux */
116
117static int twl6030reg_is_enabled(struct regulator_dev *rdev)
118{
119 struct twlreg_info *info = rdev_get_drvdata(rdev);
120 int grp = 0, val;
121
122 if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) {
123 grp = twlreg_grp(rdev);
124 if (grp < 0)
125 return grp;
126 grp &= P1_GRP_6030;
127 } else {
128 grp = 1;
129 }
130
131 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
132 val = TWL6030_CFG_STATE_APP(val);
133
134 return grp && (val == TWL6030_CFG_STATE_ON);
135}
136
137#define PB_I2C_BUSY BIT(0)
138#define PB_I2C_BWEN BIT(1)
139
140
141static int twl6030reg_enable(struct regulator_dev *rdev)
142{
143 struct twlreg_info *info = rdev_get_drvdata(rdev);
144 int grp = 0;
145 int ret;
146
147 if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS)))
148 grp = twlreg_grp(rdev);
149 if (grp < 0)
150 return grp;
151
152 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
153 grp << TWL6030_CFG_STATE_GRP_SHIFT |
154 TWL6030_CFG_STATE_ON);
155 return ret;
156}
157
158static int twl6030reg_disable(struct regulator_dev *rdev)
159{
160 struct twlreg_info *info = rdev_get_drvdata(rdev);
161 int grp = 0;
162 int ret;
163
164 if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS)))
165 grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030;
166
167 /* For 6030, set the off state for all grps enabled */
168 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
169 (grp) << TWL6030_CFG_STATE_GRP_SHIFT |
170 TWL6030_CFG_STATE_OFF);
171
172 return ret;
173}
174
175static int twl6030reg_get_status(struct regulator_dev *rdev)
176{
177 struct twlreg_info *info = rdev_get_drvdata(rdev);
178 int val;
179
180 val = twlreg_grp(rdev);
181 if (val < 0)
182 return val;
183
184 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
185
186 switch (TWL6030_CFG_STATE_APP(val)) {
187 case TWL6030_CFG_STATE_ON:
188 return REGULATOR_STATUS_NORMAL;
189
190 case TWL6030_CFG_STATE_SLEEP:
191 return REGULATOR_STATUS_STANDBY;
192
193 case TWL6030_CFG_STATE_OFF:
194 case TWL6030_CFG_STATE_OFF2:
195 default:
196 break;
197 }
198
199 return REGULATOR_STATUS_OFF;
200}
201
202static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
203{
204 struct twlreg_info *info = rdev_get_drvdata(rdev);
205 int grp = 0;
206 int val;
207
208 if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS)))
209 grp = twlreg_grp(rdev);
210
211 if (grp < 0)
212 return grp;
213
214 /* Compose the state register settings */
215 val = grp << TWL6030_CFG_STATE_GRP_SHIFT;
216 /* We can only set the mode through state machine commands... */
217 switch (mode) {
218 case REGULATOR_MODE_NORMAL:
219 val |= TWL6030_CFG_STATE_ON;
220 break;
221 case REGULATOR_MODE_STANDBY:
222 val |= TWL6030_CFG_STATE_SLEEP;
223 break;
224
225 default:
226 return -EINVAL;
227 }
228
229 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val);
230}
231
232static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV,
233 int max_uV, unsigned *selector)
234{
235 return -ENODEV;
236}
237
238static int twl6030coresmps_get_voltage(struct regulator_dev *rdev)
239{
240 return -ENODEV;
241}
242
606640bb 243static const struct regulator_ops twl6030coresmps_ops = {
cac28ae6
NR
244 .set_voltage = twl6030coresmps_set_voltage,
245 .get_voltage = twl6030coresmps_get_voltage,
246};
247
cac28ae6
NR
248static int
249twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
250{
251 struct twlreg_info *info = rdev_get_drvdata(rdev);
252
253 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE,
254 selector);
255}
256
257static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev)
258{
259 struct twlreg_info *info = rdev_get_drvdata(rdev);
260 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE);
261
262 return vsel;
263}
264
606640bb 265static const struct regulator_ops twl6030ldo_ops = {
4a43870a 266 .list_voltage = regulator_list_voltage_linear_range,
cac28ae6
NR
267
268 .set_voltage_sel = twl6030ldo_set_voltage_sel,
269 .get_voltage_sel = twl6030ldo_get_voltage_sel,
270
271 .enable = twl6030reg_enable,
272 .disable = twl6030reg_disable,
273 .is_enabled = twl6030reg_is_enabled,
274
275 .set_mode = twl6030reg_set_mode,
276
277 .get_status = twl6030reg_get_status,
278};
279
606640bb 280static const struct regulator_ops twl6030fixed_ops = {
cac28ae6
NR
281 .list_voltage = regulator_list_voltage_linear,
282
283 .enable = twl6030reg_enable,
284 .disable = twl6030reg_disable,
285 .is_enabled = twl6030reg_is_enabled,
286
287 .set_mode = twl6030reg_set_mode,
288
289 .get_status = twl6030reg_get_status,
290};
291
292/*
293 * SMPS status and control
294 */
295
296static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
297{
298 struct twlreg_info *info = rdev_get_drvdata(rdev);
299
300 int voltage = 0;
301
302 switch (info->flags) {
303 case SMPS_OFFSET_EN:
304 voltage = 100000;
305 /* fall through */
306 case 0:
307 switch (index) {
308 case 0:
309 voltage = 0;
310 break;
311 case 58:
312 voltage = 1350 * 1000;
313 break;
314 case 59:
315 voltage = 1500 * 1000;
316 break;
317 case 60:
318 voltage = 1800 * 1000;
319 break;
320 case 61:
321 voltage = 1900 * 1000;
322 break;
323 case 62:
324 voltage = 2100 * 1000;
325 break;
326 default:
327 voltage += (600000 + (12500 * (index - 1)));
328 }
329 break;
330 case SMPS_EXTENDED_EN:
331 switch (index) {
332 case 0:
333 voltage = 0;
334 break;
335 case 58:
336 voltage = 2084 * 1000;
337 break;
338 case 59:
339 voltage = 2315 * 1000;
340 break;
341 case 60:
342 voltage = 2778 * 1000;
343 break;
344 case 61:
345 voltage = 2932 * 1000;
346 break;
347 case 62:
348 voltage = 3241 * 1000;
349 break;
350 default:
351 voltage = (1852000 + (38600 * (index - 1)));
352 }
353 break;
354 case SMPS_OFFSET_EN | SMPS_EXTENDED_EN:
355 switch (index) {
356 case 0:
357 voltage = 0;
358 break;
359 case 58:
360 voltage = 4167 * 1000;
361 break;
362 case 59:
363 voltage = 2315 * 1000;
364 break;
365 case 60:
366 voltage = 2778 * 1000;
367 break;
368 case 61:
369 voltage = 2932 * 1000;
370 break;
371 case 62:
372 voltage = 3241 * 1000;
373 break;
374 default:
375 voltage = (2161000 + (38600 * (index - 1)));
376 }
377 break;
378 }
379
380 return voltage;
381}
382
383static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV,
384 int max_uV)
385{
386 struct twlreg_info *info = rdev_get_drvdata(rdev);
387 int vsel = 0;
388
389 switch (info->flags) {
390 case 0:
391 if (min_uV == 0)
392 vsel = 0;
393 else if ((min_uV >= 600000) && (min_uV <= 1300000)) {
394 vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
395 vsel++;
396 }
397 /* Values 1..57 for vsel are linear and can be calculated
398 * values 58..62 are non linear.
399 */
400 else if ((min_uV > 1900000) && (min_uV <= 2100000))
401 vsel = 62;
402 else if ((min_uV > 1800000) && (min_uV <= 1900000))
403 vsel = 61;
404 else if ((min_uV > 1500000) && (min_uV <= 1800000))
405 vsel = 60;
406 else if ((min_uV > 1350000) && (min_uV <= 1500000))
407 vsel = 59;
408 else if ((min_uV > 1300000) && (min_uV <= 1350000))
409 vsel = 58;
410 else
411 return -EINVAL;
412 break;
413 case SMPS_OFFSET_EN:
414 if (min_uV == 0)
415 vsel = 0;
416 else if ((min_uV >= 700000) && (min_uV <= 1420000)) {
417 vsel = DIV_ROUND_UP(min_uV - 700000, 12500);
418 vsel++;
419 }
420 /* Values 1..57 for vsel are linear and can be calculated
421 * values 58..62 are non linear.
422 */
423 else if ((min_uV > 1900000) && (min_uV <= 2100000))
424 vsel = 62;
425 else if ((min_uV > 1800000) && (min_uV <= 1900000))
426 vsel = 61;
b98acbff 427 else if ((min_uV > 1500000) && (min_uV <= 1800000))
cac28ae6
NR
428 vsel = 60;
429 else if ((min_uV > 1350000) && (min_uV <= 1500000))
430 vsel = 59;
cac28ae6
NR
431 else
432 return -EINVAL;
433 break;
434 case SMPS_EXTENDED_EN:
435 if (min_uV == 0) {
436 vsel = 0;
437 } else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
438 vsel = DIV_ROUND_UP(min_uV - 1852000, 38600);
439 vsel++;
440 }
441 break;
442 case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
443 if (min_uV == 0) {
444 vsel = 0;
445 } else if ((min_uV >= 2161000) && (min_uV <= 4321000)) {
446 vsel = DIV_ROUND_UP(min_uV - 2161000, 38600);
447 vsel++;
448 }
449 break;
450 }
451
452 return vsel;
453}
454
455static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev,
456 unsigned int selector)
457{
458 struct twlreg_info *info = rdev_get_drvdata(rdev);
459
460 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
461 selector);
462}
463
464static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
465{
466 struct twlreg_info *info = rdev_get_drvdata(rdev);
467
468 return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS);
469}
470
606640bb 471static const struct regulator_ops twlsmps_ops = {
cac28ae6
NR
472 .list_voltage = twl6030smps_list_voltage,
473 .map_voltage = twl6030smps_map_voltage,
474
475 .set_voltage_sel = twl6030smps_set_voltage_sel,
476 .get_voltage_sel = twl6030smps_get_voltage_sel,
477
478 .enable = twl6030reg_enable,
479 .disable = twl6030reg_disable,
480 .is_enabled = twl6030reg_is_enabled,
481
482 .set_mode = twl6030reg_set_mode,
483
484 .get_status = twl6030reg_get_status,
485};
486
487/*----------------------------------------------------------------------*/
4a43870a
AL
488static const struct regulator_linear_range twl6030ldo_linear_range[] = {
489 REGULATOR_LINEAR_RANGE(0, 0, 0, 0),
490 REGULATOR_LINEAR_RANGE(1000000, 1, 24, 100000),
491 REGULATOR_LINEAR_RANGE(2750000, 31, 31, 0),
492};
cac28ae6
NR
493
494#define TWL6030_ADJUSTABLE_SMPS(label) \
495static const struct twlreg_info TWL6030_INFO_##label = { \
496 .desc = { \
497 .name = #label, \
498 .id = TWL6030_REG_##label, \
499 .ops = &twl6030coresmps_ops, \
500 .type = REGULATOR_VOLTAGE, \
501 .owner = THIS_MODULE, \
502 }, \
503 }
504
4a43870a 505#define TWL6030_ADJUSTABLE_LDO(label, offset) \
cac28ae6
NR
506static const struct twlreg_info TWL6030_INFO_##label = { \
507 .base = offset, \
cac28ae6
NR
508 .desc = { \
509 .name = #label, \
510 .id = TWL6030_REG_##label, \
511 .n_voltages = 32, \
4a43870a
AL
512 .linear_ranges = twl6030ldo_linear_range, \
513 .n_linear_ranges = ARRAY_SIZE(twl6030ldo_linear_range), \
cac28ae6
NR
514 .ops = &twl6030ldo_ops, \
515 .type = REGULATOR_VOLTAGE, \
516 .owner = THIS_MODULE, \
517 }, \
518 }
519
4a43870a 520#define TWL6032_ADJUSTABLE_LDO(label, offset) \
cac28ae6
NR
521static const struct twlreg_info TWL6032_INFO_##label = { \
522 .base = offset, \
cac28ae6
NR
523 .desc = { \
524 .name = #label, \
525 .id = TWL6032_REG_##label, \
526 .n_voltages = 32, \
4a43870a
AL
527 .linear_ranges = twl6030ldo_linear_range, \
528 .n_linear_ranges = ARRAY_SIZE(twl6030ldo_linear_range), \
cac28ae6
NR
529 .ops = &twl6030ldo_ops, \
530 .type = REGULATOR_VOLTAGE, \
531 .owner = THIS_MODULE, \
532 }, \
533 }
534
535#define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
536static const struct twlreg_info TWLFIXED_INFO_##label = { \
537 .base = offset, \
538 .id = 0, \
cac28ae6
NR
539 .desc = { \
540 .name = #label, \
541 .id = TWL6030##_REG_##label, \
542 .n_voltages = 1, \
543 .ops = &twl6030fixed_ops, \
544 .type = REGULATOR_VOLTAGE, \
545 .owner = THIS_MODULE, \
546 .min_uV = mVolts * 1000, \
547 .enable_time = turnon_delay, \
548 .of_map_mode = NULL, \
549 }, \
550 }
551
552#define TWL6032_ADJUSTABLE_SMPS(label, offset) \
553static const struct twlreg_info TWLSMPS_INFO_##label = { \
554 .base = offset, \
cac28ae6
NR
555 .desc = { \
556 .name = #label, \
557 .id = TWL6032_REG_##label, \
558 .n_voltages = 63, \
559 .ops = &twlsmps_ops, \
560 .type = REGULATOR_VOLTAGE, \
561 .owner = THIS_MODULE, \
562 }, \
563 }
564
565/* VUSBCP is managed *only* by the USB subchip */
566/* 6030 REG with base as PMC Slave Misc : 0x0030 */
567/* Turnon-delay and remap configuration values for 6030 are not
568 verified since the specification is not public */
569TWL6030_ADJUSTABLE_SMPS(VDD1);
570TWL6030_ADJUSTABLE_SMPS(VDD2);
571TWL6030_ADJUSTABLE_SMPS(VDD3);
4a43870a
AL
572TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54);
573TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58);
574TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c);
575TWL6030_ADJUSTABLE_LDO(VMMC, 0x68);
576TWL6030_ADJUSTABLE_LDO(VPP, 0x6c);
577TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74);
cac28ae6 578/* 6025 are renamed compared to 6030 versions */
4a43870a
AL
579TWL6032_ADJUSTABLE_LDO(LDO2, 0x54);
580TWL6032_ADJUSTABLE_LDO(LDO4, 0x58);
581TWL6032_ADJUSTABLE_LDO(LDO3, 0x5c);
582TWL6032_ADJUSTABLE_LDO(LDO5, 0x68);
583TWL6032_ADJUSTABLE_LDO(LDO1, 0x6c);
584TWL6032_ADJUSTABLE_LDO(LDO7, 0x74);
585TWL6032_ADJUSTABLE_LDO(LDO6, 0x60);
586TWL6032_ADJUSTABLE_LDO(LDOLN, 0x64);
587TWL6032_ADJUSTABLE_LDO(LDOUSB, 0x70);
cac28ae6
NR
588TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0);
589TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0);
590TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0);
591TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0);
592TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0);
593TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0);
594TWL6032_ADJUSTABLE_SMPS(SMPS3, 0x34);
595TWL6032_ADJUSTABLE_SMPS(SMPS4, 0x10);
596TWL6032_ADJUSTABLE_SMPS(VIO, 0x16);
597
598static u8 twl_get_smps_offset(void)
599{
600 u8 value;
601
602 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
603 TWL6030_SMPS_OFFSET);
604 return value;
605}
606
607static u8 twl_get_smps_mult(void)
608{
609 u8 value;
610
611 twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
612 TWL6030_SMPS_MULT);
613 return value;
614}
615
616#define TWL_OF_MATCH(comp, family, label) \
617 { \
618 .compatible = comp, \
619 .data = &family##_INFO_##label, \
620 }
621
622#define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label)
623#define TWL6032_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6032, label)
624#define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
625#define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
626
627static const struct of_device_id twl_of_match[] = {
628 TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1),
629 TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2),
630 TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3),
631 TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030),
632 TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030),
633 TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030),
634 TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC),
635 TWL6030_OF_MATCH("ti,twl6030-vpp", VPP),
636 TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM),
637 TWL6032_OF_MATCH("ti,twl6032-ldo2", LDO2),
638 TWL6032_OF_MATCH("ti,twl6032-ldo4", LDO4),
639 TWL6032_OF_MATCH("ti,twl6032-ldo3", LDO3),
640 TWL6032_OF_MATCH("ti,twl6032-ldo5", LDO5),
641 TWL6032_OF_MATCH("ti,twl6032-ldo1", LDO1),
642 TWL6032_OF_MATCH("ti,twl6032-ldo7", LDO7),
643 TWL6032_OF_MATCH("ti,twl6032-ldo6", LDO6),
644 TWL6032_OF_MATCH("ti,twl6032-ldoln", LDOLN),
645 TWL6032_OF_MATCH("ti,twl6032-ldousb", LDOUSB),
646 TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA),
647 TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO),
648 TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC),
649 TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB),
650 TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8),
651 TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1),
652 TWLSMPS_OF_MATCH("ti,twl6032-smps3", SMPS3),
653 TWLSMPS_OF_MATCH("ti,twl6032-smps4", SMPS4),
654 TWLSMPS_OF_MATCH("ti,twl6032-vio", VIO),
655 {},
656};
657MODULE_DEVICE_TABLE(of, twl_of_match);
658
659static int twlreg_probe(struct platform_device *pdev)
660{
661 int id;
662 struct twlreg_info *info;
663 const struct twlreg_info *template;
664 struct regulator_init_data *initdata;
665 struct regulation_constraints *c;
666 struct regulator_dev *rdev;
cac28ae6
NR
667 struct regulator_config config = { };
668
7085180d 669 template = of_device_get_match_data(&pdev->dev);
cac28ae6
NR
670 if (!template)
671 return -ENODEV;
672
673 id = template->desc.id;
674 initdata = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node,
675 &template->desc);
676 if (!initdata)
677 return -EINVAL;
678
679 info = devm_kmemdup(&pdev->dev, template, sizeof(*info), GFP_KERNEL);
680 if (!info)
681 return -ENOMEM;
682
683 /* Constrain board-specific capabilities according to what
684 * this driver and the chip itself can actually do.
685 */
686 c = &initdata->constraints;
687 c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
688 c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
689 | REGULATOR_CHANGE_MODE
690 | REGULATOR_CHANGE_STATUS;
691
692 switch (id) {
693 case TWL6032_REG_SMPS3:
694 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3)
695 info->flags |= SMPS_EXTENDED_EN;
696 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3)
697 info->flags |= SMPS_OFFSET_EN;
698 break;
699 case TWL6032_REG_SMPS4:
700 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4)
701 info->flags |= SMPS_EXTENDED_EN;
702 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4)
703 info->flags |= SMPS_OFFSET_EN;
704 break;
705 case TWL6032_REG_VIO:
706 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO)
707 info->flags |= SMPS_EXTENDED_EN;
708 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO)
709 info->flags |= SMPS_OFFSET_EN;
710 break;
711 }
712
713 config.dev = &pdev->dev;
714 config.init_data = initdata;
715 config.driver_data = info;
716 config.of_node = pdev->dev.of_node;
717
718 rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
719 if (IS_ERR(rdev)) {
720 dev_err(&pdev->dev, "can't register %s, %ld\n",
721 info->desc.name, PTR_ERR(rdev));
722 return PTR_ERR(rdev);
723 }
724 platform_set_drvdata(pdev, rdev);
725
726 /* NOTE: many regulators support short-circuit IRQs (presentable
727 * as REGULATOR_OVER_CURRENT notifications?) configured via:
728 * - SC_CONFIG
729 * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
730 * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
731 * - IT_CONFIG
732 */
733
734 return 0;
735}
736
737MODULE_ALIAS("platform:twl6030_reg");
738
739static struct platform_driver twlreg_driver = {
740 .probe = twlreg_probe,
741 /* NOTE: short name, to work around driver model truncation of
742 * "twl_regulator.12" (and friends) to "twl_regulator.1".
743 */
744 .driver = {
745 .name = "twl6030_reg",
746 .of_match_table = of_match_ptr(twl_of_match),
747 },
748};
749
750static int __init twlreg_init(void)
751{
752 return platform_driver_register(&twlreg_driver);
753}
754subsys_initcall(twlreg_init);
755
756static void __exit twlreg_exit(void)
757{
758 platform_driver_unregister(&twlreg_driver);
759}
760module_exit(twlreg_exit)
761
762MODULE_DESCRIPTION("TWL6030 regulator driver");
763MODULE_LICENSE("GPL");