17 #include <linux/kernel.h>
18 #include <linux/slab.h>
21 #include <linux/module.h>
24 #define MC13892_REVISION 7
26 #define MC13892_POWERCTL0 13
27 #define MC13892_POWERCTL0_USEROFFSPI 3
28 #define MC13892_POWERCTL0_VCOINCELLVSEL 20
29 #define MC13892_POWERCTL0_VCOINCELLVSEL_M (7<<20)
30 #define MC13892_POWERCTL0_VCOINCELLEN (1<<23)
32 #define MC13892_SWITCHERS0_SWxHI (1<<23)
34 #define MC13892_SWITCHERS0 24
35 #define MC13892_SWITCHERS0_SW1VSEL 0
36 #define MC13892_SWITCHERS0_SW1VSEL_M (0x1f<<0)
37 #define MC13892_SWITCHERS0_SW1HI (1<<23)
38 #define MC13892_SWITCHERS0_SW1EN 0
40 #define MC13892_SWITCHERS1 25
41 #define MC13892_SWITCHERS1_SW2VSEL 0
42 #define MC13892_SWITCHERS1_SW2VSEL_M (0x1f<<0)
43 #define MC13892_SWITCHERS1_SW2HI (1<<23)
44 #define MC13892_SWITCHERS1_SW2EN 0
46 #define MC13892_SWITCHERS2 26
47 #define MC13892_SWITCHERS2_SW3VSEL 0
48 #define MC13892_SWITCHERS2_SW3VSEL_M (0x1f<<0)
49 #define MC13892_SWITCHERS2_SW3HI (1<<23)
50 #define MC13892_SWITCHERS2_SW3EN 0
52 #define MC13892_SWITCHERS3 27
53 #define MC13892_SWITCHERS3_SW4VSEL 0
54 #define MC13892_SWITCHERS3_SW4VSEL_M (0x1f<<0)
55 #define MC13892_SWITCHERS3_SW4HI (1<<23)
56 #define MC13892_SWITCHERS3_SW4EN 0
58 #define MC13892_SWITCHERS4 28
59 #define MC13892_SWITCHERS4_SW1MODE 0
60 #define MC13892_SWITCHERS4_SW1MODE_AUTO (8<<0)
61 #define MC13892_SWITCHERS4_SW1MODE_M (0xf<<0)
62 #define MC13892_SWITCHERS4_SW2MODE 10
63 #define MC13892_SWITCHERS4_SW2MODE_AUTO (8<<10)
64 #define MC13892_SWITCHERS4_SW2MODE_M (0xf<<10)
66 #define MC13892_SWITCHERS5 29
67 #define MC13892_SWITCHERS5_SW3MODE 0
68 #define MC13892_SWITCHERS5_SW3MODE_AUTO (8<<0)
69 #define MC13892_SWITCHERS5_SW3MODE_M (0xf<<0)
70 #define MC13892_SWITCHERS5_SW4MODE 8
71 #define MC13892_SWITCHERS5_SW4MODE_AUTO (8<<8)
72 #define MC13892_SWITCHERS5_SW4MODE_M (0xf<<8)
73 #define MC13892_SWITCHERS5_SWBSTEN (1<<20)
75 #define MC13892_REGULATORSETTING0 30
76 #define MC13892_REGULATORSETTING0_VGEN1VSEL 0
77 #define MC13892_REGULATORSETTING0_VDIGVSEL 4
78 #define MC13892_REGULATORSETTING0_VGEN2VSEL 6
79 #define MC13892_REGULATORSETTING0_VPLLVSEL 9
80 #define MC13892_REGULATORSETTING0_VUSB2VSEL 11
81 #define MC13892_REGULATORSETTING0_VGEN3VSEL 14
82 #define MC13892_REGULATORSETTING0_VCAMVSEL 16
84 #define MC13892_REGULATORSETTING0_VGEN1VSEL_M (3<<0)
85 #define MC13892_REGULATORSETTING0_VDIGVSEL_M (3<<4)
86 #define MC13892_REGULATORSETTING0_VGEN2VSEL_M (7<<6)
87 #define MC13892_REGULATORSETTING0_VPLLVSEL_M (3<<9)
88 #define MC13892_REGULATORSETTING0_VUSB2VSEL_M (3<<11)
89 #define MC13892_REGULATORSETTING0_VGEN3VSEL_M (1<<14)
90 #define MC13892_REGULATORSETTING0_VCAMVSEL_M (3<<16)
92 #define MC13892_REGULATORSETTING1 31
93 #define MC13892_REGULATORSETTING1_VVIDEOVSEL 2
94 #define MC13892_REGULATORSETTING1_VAUDIOVSEL 4
95 #define MC13892_REGULATORSETTING1_VSDVSEL 6
97 #define MC13892_REGULATORSETTING1_VVIDEOVSEL_M (3<<2)
98 #define MC13892_REGULATORSETTING1_VAUDIOVSEL_M (3<<4)
99 #define MC13892_REGULATORSETTING1_VSDVSEL_M (7<<6)
101 #define MC13892_REGULATORMODE0 32
102 #define MC13892_REGULATORMODE0_VGEN1EN (1<<0)
103 #define MC13892_REGULATORMODE0_VGEN1STDBY (1<<1)
104 #define MC13892_REGULATORMODE0_VGEN1MODE (1<<2)
105 #define MC13892_REGULATORMODE0_VIOHIEN (1<<3)
106 #define MC13892_REGULATORMODE0_VIOHISTDBY (1<<4)
107 #define MC13892_REGULATORMODE0_VIOHIMODE (1<<5)
108 #define MC13892_REGULATORMODE0_VDIGEN (1<<9)
109 #define MC13892_REGULATORMODE0_VDIGSTDBY (1<<10)
110 #define MC13892_REGULATORMODE0_VDIGMODE (1<<11)
111 #define MC13892_REGULATORMODE0_VGEN2EN (1<<12)
112 #define MC13892_REGULATORMODE0_VGEN2STDBY (1<<13)
113 #define MC13892_REGULATORMODE0_VGEN2MODE (1<<14)
114 #define MC13892_REGULATORMODE0_VPLLEN (1<<15)
115 #define MC13892_REGULATORMODE0_VPLLSTDBY (1<<16)
116 #define MC13892_REGULATORMODE0_VPLLMODE (1<<17)
117 #define MC13892_REGULATORMODE0_VUSB2EN (1<<18)
118 #define MC13892_REGULATORMODE0_VUSB2STDBY (1<<19)
119 #define MC13892_REGULATORMODE0_VUSB2MODE (1<<20)
121 #define MC13892_REGULATORMODE1 33
122 #define MC13892_REGULATORMODE1_VGEN3EN (1<<0)
123 #define MC13892_REGULATORMODE1_VGEN3STDBY (1<<1)
124 #define MC13892_REGULATORMODE1_VGEN3MODE (1<<2)
125 #define MC13892_REGULATORMODE1_VCAMEN (1<<6)
126 #define MC13892_REGULATORMODE1_VCAMSTDBY (1<<7)
127 #define MC13892_REGULATORMODE1_VCAMMODE (1<<8)
128 #define MC13892_REGULATORMODE1_VCAMCONFIGEN (1<<9)
129 #define MC13892_REGULATORMODE1_VVIDEOEN (1<<12)
130 #define MC13892_REGULATORMODE1_VVIDEOSTDBY (1<<13)
131 #define MC13892_REGULATORMODE1_VVIDEOMODE (1<<14)
132 #define MC13892_REGULATORMODE1_VAUDIOEN (1<<15)
133 #define MC13892_REGULATORMODE1_VAUDIOSTDBY (1<<16)
134 #define MC13892_REGULATORMODE1_VAUDIOMODE (1<<17)
135 #define MC13892_REGULATORMODE1_VSDEN (1<<18)
136 #define MC13892_REGULATORMODE1_VSDSTDBY (1<<19)
137 #define MC13892_REGULATORMODE1_VSDMODE (1<<20)
139 #define MC13892_POWERMISC 34
140 #define MC13892_POWERMISC_GPO1EN (1<<6)
141 #define MC13892_POWERMISC_GPO2EN (1<<8)
142 #define MC13892_POWERMISC_GPO3EN (1<<10)
143 #define MC13892_POWERMISC_GPO4EN (1<<12)
144 #define MC13892_POWERMISC_PWGT1SPIEN (1<<15)
145 #define MC13892_POWERMISC_PWGT2SPIEN (1<<16)
146 #define MC13892_POWERMISC_GPO4ADINEN (1<<21)
148 #define MC13892_POWERMISC_PWGTSPI_M (3 << 15)
150 #define MC13892_USB1 50
151 #define MC13892_USB1_VUSBEN (1<<3)
153 static const unsigned int mc13892_vcoincell[] = {
154 2500000, 2700000, 2800000, 2900000, 3000000, 3100000,
158 static const unsigned int mc13892_sw1[] = {
159 600000, 625000, 650000, 675000, 700000, 725000,
160 750000, 775000, 800000, 825000, 850000, 875000,
161 900000, 925000, 950000, 975000, 1000000, 1025000,
162 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
163 1200000, 1225000, 1250000, 1275000, 1300000, 1325000,
167 static const unsigned int mc13892_sw[] = {
168 600000, 625000, 650000, 675000, 700000, 725000,
169 750000, 775000, 800000, 825000, 850000, 875000,
170 900000, 925000, 950000, 975000, 1000000, 1025000,
171 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
172 1200000, 1225000, 1250000, 1275000, 1300000, 1325000,
173 1350000, 1375000, 1400000, 1425000, 1450000, 1475000,
174 1500000, 1525000, 1550000, 1575000, 1600000, 1625000,
175 1650000, 1675000, 1700000, 1725000, 1750000, 1775000,
176 1800000, 1825000, 1850000, 1875000
179 static const unsigned int mc13892_swbst[] = {
183 static const unsigned int mc13892_viohi[] = {
187 static const unsigned int mc13892_vpll[] = {
188 1050000, 1250000, 1650000, 1800000,
191 static const unsigned int mc13892_vdig[] = {
192 1050000, 1250000, 1650000, 1800000,
195 static const unsigned int mc13892_vsd[] = {
196 1800000, 2000000, 2600000, 2700000,
197 2800000, 2900000, 3000000, 3150000,
200 static const unsigned int mc13892_vusb2[] = {
201 2400000, 2600000, 2700000, 2775000,
204 static const unsigned int mc13892_vvideo[] = {
205 2700000, 2775000, 2500000, 2600000,
208 static const unsigned int mc13892_vaudio[] = {
209 2300000, 2500000, 2775000, 3000000,
212 static const unsigned int mc13892_vcam[] = {
213 2500000, 2600000, 2750000, 3000000,
216 static const unsigned int mc13892_vgen1[] = {
217 1200000, 1500000, 2775000, 3150000,
220 static const unsigned int mc13892_vgen2[] = {
221 1200000, 1500000, 1600000, 1800000,
222 2700000, 2800000, 3000000, 3150000,
225 static const unsigned int mc13892_vgen3[] = {
229 static const unsigned int mc13892_vusb[] = {
233 static const unsigned int mc13892_gpo[] = {
237 static const unsigned int mc13892_pwgtdrv[] = {
246 #define MC13892_FIXED_DEFINE(name, reg, voltages) \
247 MC13xxx_FIXED_DEFINE(MC13892_, name, reg, voltages, \
248 mc13xxx_fixed_regulator_ops)
250 #define MC13892_GPO_DEFINE(name, reg, voltages) \
251 MC13xxx_GPO_DEFINE(MC13892_, name, reg, voltages, \
252 mc13892_gpo_regulator_ops)
254 #define MC13892_SW_DEFINE(name, reg, vsel_reg, voltages) \
255 MC13xxx_DEFINE(MC13892_, name, reg, vsel_reg, voltages, \
256 mc13892_sw_regulator_ops)
258 #define MC13892_DEFINE_REGU(name, reg, vsel_reg, voltages) \
259 MC13xxx_DEFINE(MC13892_, name, reg, vsel_reg, voltages, \
260 mc13xxx_regulator_ops)
319 valread = (valread & ~mask) | val;
346 return mc13892_powermisc_rmw(priv, mask, en_val);
349 static int mc13892_gpo_regulator_disable(
struct regulator_dev *rdev)
361 return mc13892_powermisc_rmw(priv, mc13892_regulators[
id].enable_bit,
365 static int mc13892_gpo_regulator_is_enabled(
struct regulator_dev *rdev)
383 return (val & mc13892_regulators[
id].enable_bit) != 0;
388 .enable = mc13892_gpo_regulator_enable,
389 .disable = mc13892_gpo_regulator_disable,
390 .is_enabled = mc13892_gpo_regulator_is_enabled,
395 static int mc13892_sw_regulator_get_voltage_sel(
struct regulator_dev *rdev)
405 mc13892_regulators[
id].
vsel_reg, &val);
411 >> mc13892_regulators[
id].vsel_shift;
418 static int mc13892_sw_regulator_set_voltage_sel(
struct regulator_dev *rdev,
426 volt = rdev->
desc->volt_table[selector];
428 reg_value = selector << mc13892_regulators[
id].
vsel_shift;
430 if (volt > 1375000) {
433 }
else if (volt < 1100000) {
448 .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel,
449 .get_voltage_sel = mc13892_sw_regulator_get_voltage_sel,
454 unsigned int en_val = 0;
469 static unsigned int mc13892_vcam_get_mode(
struct regulator_dev *rdev)
494 dev_get_platdata(&pdev->
dev);
498 int num_regulators = 0;
501 num_regulators = mc13xxx_get_num_regulators_dt(pdev);
502 if (num_regulators <= 0 && pdata)
504 if (num_regulators <= 0)
516 platform_set_drvdata(pdev, priv);
524 if ((val & 0x0000FFFF) == 0x45d0) {
544 = mc13892_vcam_set_mode;
546 = mc13892_vcam_get_mode;
548 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
550 for (i = 0; i < num_regulators; i++) {
557 id = mc13xxx_data[
i].
id;
559 node = mc13xxx_data[
i].
node;
564 desc = &mc13892_regulators[
id].
desc;
573 dev_err(&pdev->
dev,
"failed to register regulator %s\n",
574 mc13892_regulators[i].
desc.name);
596 platform_set_drvdata(pdev,
NULL);
606 .name =
"mc13892-regulator",
610 .probe = mc13892_regulator_probe,
613 static int __init mc13892_regulator_init(
void)
619 static void __exit mc13892_regulator_exit(
void)