xref: /OK3568_Linux_fs/kernel/drivers/regulator/cpcap-regulator.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Motorola CPCAP PMIC regulator driver
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Based on cpcap-regulator.c from Motorola Linux kernel tree
5*4882a593Smuzhiyun  * Copyright (C) 2009-2011 Motorola, Inc.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Rewritten for mainline kernel to use device tree and regmap
8*4882a593Smuzhiyun  * Copyright (C) 2017 Tony Lindgren <tony@atomide.com>
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or
11*4882a593Smuzhiyun  * modify it under the terms of the GNU General Public License as
12*4882a593Smuzhiyun  * published by the Free Software Foundation version 2.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
15*4882a593Smuzhiyun  * kind, whether express or implied; without even the implied warranty
16*4882a593Smuzhiyun  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17*4882a593Smuzhiyun  * GNU General Public License for more details.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include <linux/err.h>
21*4882a593Smuzhiyun #include <linux/module.h>
22*4882a593Smuzhiyun #include <linux/of.h>
23*4882a593Smuzhiyun #include <linux/of_platform.h>
24*4882a593Smuzhiyun #include <linux/regmap.h>
25*4882a593Smuzhiyun #include <linux/regulator/driver.h>
26*4882a593Smuzhiyun #include <linux/regulator/machine.h>
27*4882a593Smuzhiyun #include <linux/regulator/of_regulator.h>
28*4882a593Smuzhiyun #include <linux/mfd/motorola-cpcap.h>
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /*
31*4882a593Smuzhiyun  * Resource assignment register bits. These seem to control the state
32*4882a593Smuzhiyun  * idle modes adn are used at least for omap4.
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /* CPCAP_REG_ASSIGN2 bits - Resource Assignment 2 */
36*4882a593Smuzhiyun #define CPCAP_BIT_VSDIO_SEL		BIT(15)
37*4882a593Smuzhiyun #define CPCAP_BIT_VDIG_SEL		BIT(14)
38*4882a593Smuzhiyun #define CPCAP_BIT_VCAM_SEL		BIT(13)
39*4882a593Smuzhiyun #define CPCAP_BIT_SW6_SEL		BIT(12)
40*4882a593Smuzhiyun #define CPCAP_BIT_SW5_SEL		BIT(11)
41*4882a593Smuzhiyun #define CPCAP_BIT_SW4_SEL		BIT(10)
42*4882a593Smuzhiyun #define CPCAP_BIT_SW3_SEL		BIT(9)
43*4882a593Smuzhiyun #define CPCAP_BIT_SW2_SEL		BIT(8)
44*4882a593Smuzhiyun #define CPCAP_BIT_SW1_SEL		BIT(7)
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /* CPCAP_REG_ASSIGN3 bits - Resource Assignment 3 */
47*4882a593Smuzhiyun #define CPCAP_BIT_VUSBINT2_SEL		BIT(15)
48*4882a593Smuzhiyun #define CPCAP_BIT_VUSBINT1_SEL		BIT(14)
49*4882a593Smuzhiyun #define CPCAP_BIT_VVIB_SEL		BIT(13)
50*4882a593Smuzhiyun #define CPCAP_BIT_VWLAN1_SEL		BIT(12)
51*4882a593Smuzhiyun #define CPCAP_BIT_VRF1_SEL		BIT(11)
52*4882a593Smuzhiyun #define CPCAP_BIT_VHVIO_SEL		BIT(10)
53*4882a593Smuzhiyun #define CPCAP_BIT_VDAC_SEL		BIT(9)
54*4882a593Smuzhiyun #define CPCAP_BIT_VUSB_SEL		BIT(8)
55*4882a593Smuzhiyun #define CPCAP_BIT_VSIM_SEL		BIT(7)
56*4882a593Smuzhiyun #define CPCAP_BIT_VRFREF_SEL		BIT(6)
57*4882a593Smuzhiyun #define CPCAP_BIT_VPLL_SEL		BIT(5)
58*4882a593Smuzhiyun #define CPCAP_BIT_VFUSE_SEL		BIT(4)
59*4882a593Smuzhiyun #define CPCAP_BIT_VCSI_SEL		BIT(3)
60*4882a593Smuzhiyun #define CPCAP_BIT_SPARE_14_2		BIT(2)
61*4882a593Smuzhiyun #define CPCAP_BIT_VWLAN2_SEL		BIT(1)
62*4882a593Smuzhiyun #define CPCAP_BIT_VRF2_SEL		BIT(0)
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun /* CPCAP_REG_ASSIGN4 bits - Resource Assignment 4 */
65*4882a593Smuzhiyun #define CPCAP_BIT_VAUDIO_SEL		BIT(0)
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun /*
68*4882a593Smuzhiyun  * Enable register bits. At least CPCAP_BIT_AUDIO_LOW_PWR is generic,
69*4882a593Smuzhiyun  * and not limited to audio regulator. Let's use the Motorola kernel
70*4882a593Smuzhiyun  * naming for now until we have a better understanding of the other
71*4882a593Smuzhiyun  * enable register bits. No idea why BIT(3) is not defined.
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun #define CPCAP_BIT_AUDIO_LOW_PWR		BIT(6)
74*4882a593Smuzhiyun #define CPCAP_BIT_AUD_LOWPWR_SPEED	BIT(5)
75*4882a593Smuzhiyun #define CPCAP_BIT_VAUDIOPRISTBY		BIT(4)
76*4882a593Smuzhiyun #define CPCAP_BIT_VAUDIO_MODE1		BIT(2)
77*4882a593Smuzhiyun #define CPCAP_BIT_VAUDIO_MODE0		BIT(1)
78*4882a593Smuzhiyun #define CPCAP_BIT_V_AUDIO_EN		BIT(0)
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun #define CPCAP_BIT_AUDIO_NORMAL_MODE	0x00
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun /*
83*4882a593Smuzhiyun  * Off mode configuration bit. Used currently only by SW5 on omap4. There's
84*4882a593Smuzhiyun  * the following comment in Motorola Linux kernel tree for it:
85*4882a593Smuzhiyun  *
86*4882a593Smuzhiyun  * When set in the regulator mode, the regulator assignment will be changed
87*4882a593Smuzhiyun  * to secondary when the regulator is disabled. The mode will be set back to
88*4882a593Smuzhiyun  * primary when the regulator is turned on.
89*4882a593Smuzhiyun  */
90*4882a593Smuzhiyun #define CPCAP_REG_OFF_MODE_SEC		BIT(15)
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /*
93*4882a593Smuzhiyun  * SoC specific configuration for CPCAP regulator. There are at least three
94*4882a593Smuzhiyun  * different SoCs each with their own parameters: omap3, omap4 and tegra2.
95*4882a593Smuzhiyun  *
96*4882a593Smuzhiyun  * The assign_reg and assign_mask seem to allow toggling between primary
97*4882a593Smuzhiyun  * and secondary mode that at least omap4 uses for off mode.
98*4882a593Smuzhiyun  */
99*4882a593Smuzhiyun struct cpcap_regulator {
100*4882a593Smuzhiyun 	struct regulator_desc rdesc;
101*4882a593Smuzhiyun 	const u16 assign_reg;
102*4882a593Smuzhiyun 	const u16 assign_mask;
103*4882a593Smuzhiyun };
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun #define CPCAP_REG(_ID, reg, assignment_reg, assignment_mask, val_tbl,	\
106*4882a593Smuzhiyun 		mode_mask, volt_mask, mode_val, off_val,		\
107*4882a593Smuzhiyun 		volt_trans_time) {					\
108*4882a593Smuzhiyun 	.rdesc = {							\
109*4882a593Smuzhiyun 		.name = #_ID,						\
110*4882a593Smuzhiyun 		.of_match = of_match_ptr(#_ID),				\
111*4882a593Smuzhiyun 		.ops = &cpcap_regulator_ops,				\
112*4882a593Smuzhiyun 		.regulators_node = of_match_ptr("regulators"),		\
113*4882a593Smuzhiyun 		.type = REGULATOR_VOLTAGE,				\
114*4882a593Smuzhiyun 		.id = CPCAP_##_ID,					\
115*4882a593Smuzhiyun 		.owner = THIS_MODULE,					\
116*4882a593Smuzhiyun 		.n_voltages = ARRAY_SIZE(val_tbl),			\
117*4882a593Smuzhiyun 		.volt_table = (val_tbl),				\
118*4882a593Smuzhiyun 		.vsel_reg = (reg),					\
119*4882a593Smuzhiyun 		.vsel_mask = (volt_mask),				\
120*4882a593Smuzhiyun 		.enable_reg = (reg),					\
121*4882a593Smuzhiyun 		.enable_mask = (mode_mask),				\
122*4882a593Smuzhiyun 		.enable_val = (mode_val),				\
123*4882a593Smuzhiyun 		.disable_val = (off_val),				\
124*4882a593Smuzhiyun 		.ramp_delay = (volt_trans_time),			\
125*4882a593Smuzhiyun 		.of_map_mode = cpcap_map_mode,				\
126*4882a593Smuzhiyun 	},								\
127*4882a593Smuzhiyun 	.assign_reg = (assignment_reg),					\
128*4882a593Smuzhiyun 	.assign_mask = (assignment_mask),				\
129*4882a593Smuzhiyun }
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun struct cpcap_ddata {
132*4882a593Smuzhiyun 	struct regmap *reg;
133*4882a593Smuzhiyun 	struct device *dev;
134*4882a593Smuzhiyun 	const struct cpcap_regulator *soc;
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun enum cpcap_regulator_id {
138*4882a593Smuzhiyun 	CPCAP_SW1,
139*4882a593Smuzhiyun 	CPCAP_SW2,
140*4882a593Smuzhiyun 	CPCAP_SW3,
141*4882a593Smuzhiyun 	CPCAP_SW4,
142*4882a593Smuzhiyun 	CPCAP_SW5,
143*4882a593Smuzhiyun 	CPCAP_SW6,
144*4882a593Smuzhiyun 	CPCAP_VCAM,
145*4882a593Smuzhiyun 	CPCAP_VCSI,
146*4882a593Smuzhiyun 	CPCAP_VDAC,
147*4882a593Smuzhiyun 	CPCAP_VDIG,
148*4882a593Smuzhiyun 	CPCAP_VFUSE,
149*4882a593Smuzhiyun 	CPCAP_VHVIO,
150*4882a593Smuzhiyun 	CPCAP_VSDIO,
151*4882a593Smuzhiyun 	CPCAP_VPLL,
152*4882a593Smuzhiyun 	CPCAP_VRF1,
153*4882a593Smuzhiyun 	CPCAP_VRF2,
154*4882a593Smuzhiyun 	CPCAP_VRFREF,
155*4882a593Smuzhiyun 	CPCAP_VWLAN1,
156*4882a593Smuzhiyun 	CPCAP_VWLAN2,
157*4882a593Smuzhiyun 	CPCAP_VSIM,
158*4882a593Smuzhiyun 	CPCAP_VSIMCARD,
159*4882a593Smuzhiyun 	CPCAP_VVIB,
160*4882a593Smuzhiyun 	CPCAP_VUSB,
161*4882a593Smuzhiyun 	CPCAP_VAUDIO,
162*4882a593Smuzhiyun 	CPCAP_NR_REGULATORS,
163*4882a593Smuzhiyun };
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun /*
166*4882a593Smuzhiyun  * We need to also configure regulator idle mode for SoC off mode if
167*4882a593Smuzhiyun  * CPCAP_REG_OFF_MODE_SEC is set.
168*4882a593Smuzhiyun  */
cpcap_regulator_enable(struct regulator_dev * rdev)169*4882a593Smuzhiyun static int cpcap_regulator_enable(struct regulator_dev *rdev)
170*4882a593Smuzhiyun {
171*4882a593Smuzhiyun 	struct cpcap_regulator *regulator = rdev_get_drvdata(rdev);
172*4882a593Smuzhiyun 	int error;
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun 	error = regulator_enable_regmap(rdev);
175*4882a593Smuzhiyun 	if (error)
176*4882a593Smuzhiyun 		return error;
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun 	if (rdev->desc->enable_val & CPCAP_REG_OFF_MODE_SEC) {
179*4882a593Smuzhiyun 		error = regmap_update_bits(rdev->regmap, regulator->assign_reg,
180*4882a593Smuzhiyun 					   regulator->assign_mask,
181*4882a593Smuzhiyun 					   regulator->assign_mask);
182*4882a593Smuzhiyun 		if (error)
183*4882a593Smuzhiyun 			regulator_disable_regmap(rdev);
184*4882a593Smuzhiyun 	}
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	return error;
187*4882a593Smuzhiyun }
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun /*
190*4882a593Smuzhiyun  * We need to also configure regulator idle mode for SoC off mode if
191*4882a593Smuzhiyun  * CPCAP_REG_OFF_MODE_SEC is set.
192*4882a593Smuzhiyun  */
cpcap_regulator_disable(struct regulator_dev * rdev)193*4882a593Smuzhiyun static int cpcap_regulator_disable(struct regulator_dev *rdev)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun 	struct cpcap_regulator *regulator = rdev_get_drvdata(rdev);
196*4882a593Smuzhiyun 	int error;
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun 	if (rdev->desc->enable_val & CPCAP_REG_OFF_MODE_SEC) {
199*4882a593Smuzhiyun 		error = regmap_update_bits(rdev->regmap, regulator->assign_reg,
200*4882a593Smuzhiyun 					   regulator->assign_mask, 0);
201*4882a593Smuzhiyun 		if (error)
202*4882a593Smuzhiyun 			return error;
203*4882a593Smuzhiyun 	}
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	error = regulator_disable_regmap(rdev);
206*4882a593Smuzhiyun 	if (error && (rdev->desc->enable_val & CPCAP_REG_OFF_MODE_SEC)) {
207*4882a593Smuzhiyun 		regmap_update_bits(rdev->regmap, regulator->assign_reg,
208*4882a593Smuzhiyun 				   regulator->assign_mask,
209*4882a593Smuzhiyun 				   regulator->assign_mask);
210*4882a593Smuzhiyun 	}
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun 	return error;
213*4882a593Smuzhiyun }
214*4882a593Smuzhiyun 
cpcap_map_mode(unsigned int mode)215*4882a593Smuzhiyun static unsigned int cpcap_map_mode(unsigned int mode)
216*4882a593Smuzhiyun {
217*4882a593Smuzhiyun 	switch (mode) {
218*4882a593Smuzhiyun 	case CPCAP_BIT_AUDIO_NORMAL_MODE:
219*4882a593Smuzhiyun 		return REGULATOR_MODE_NORMAL;
220*4882a593Smuzhiyun 	case CPCAP_BIT_AUDIO_LOW_PWR:
221*4882a593Smuzhiyun 		return REGULATOR_MODE_STANDBY;
222*4882a593Smuzhiyun 	default:
223*4882a593Smuzhiyun 		return REGULATOR_MODE_INVALID;
224*4882a593Smuzhiyun 	}
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun 
cpcap_regulator_get_mode(struct regulator_dev * rdev)227*4882a593Smuzhiyun static unsigned int cpcap_regulator_get_mode(struct regulator_dev *rdev)
228*4882a593Smuzhiyun {
229*4882a593Smuzhiyun 	int value;
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun 	regmap_read(rdev->regmap, rdev->desc->enable_reg, &value);
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun 	if (value & CPCAP_BIT_AUDIO_LOW_PWR)
234*4882a593Smuzhiyun 		return REGULATOR_MODE_STANDBY;
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun 	return REGULATOR_MODE_NORMAL;
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun 
cpcap_regulator_set_mode(struct regulator_dev * rdev,unsigned int mode)239*4882a593Smuzhiyun static int cpcap_regulator_set_mode(struct regulator_dev *rdev,
240*4882a593Smuzhiyun 				    unsigned int mode)
241*4882a593Smuzhiyun {
242*4882a593Smuzhiyun 	int value;
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun 	switch (mode) {
245*4882a593Smuzhiyun 	case REGULATOR_MODE_NORMAL:
246*4882a593Smuzhiyun 		value = CPCAP_BIT_AUDIO_NORMAL_MODE;
247*4882a593Smuzhiyun 		break;
248*4882a593Smuzhiyun 	case REGULATOR_MODE_STANDBY:
249*4882a593Smuzhiyun 		value = CPCAP_BIT_AUDIO_LOW_PWR;
250*4882a593Smuzhiyun 		break;
251*4882a593Smuzhiyun 	default:
252*4882a593Smuzhiyun 		return -EINVAL;
253*4882a593Smuzhiyun 	}
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun 	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
256*4882a593Smuzhiyun 				  CPCAP_BIT_AUDIO_LOW_PWR, value);
257*4882a593Smuzhiyun }
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun static const struct regulator_ops cpcap_regulator_ops = {
260*4882a593Smuzhiyun 	.enable = cpcap_regulator_enable,
261*4882a593Smuzhiyun 	.disable = cpcap_regulator_disable,
262*4882a593Smuzhiyun 	.is_enabled = regulator_is_enabled_regmap,
263*4882a593Smuzhiyun 	.list_voltage = regulator_list_voltage_table,
264*4882a593Smuzhiyun 	.map_voltage = regulator_map_voltage_iterate,
265*4882a593Smuzhiyun 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
266*4882a593Smuzhiyun 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
267*4882a593Smuzhiyun 	.get_mode = cpcap_regulator_get_mode,
268*4882a593Smuzhiyun 	.set_mode = cpcap_regulator_set_mode,
269*4882a593Smuzhiyun };
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun static const unsigned int unknown_val_tbl[] = { 0, };
272*4882a593Smuzhiyun static const unsigned int sw2_sw4_val_tbl[] = { 612500, 625000, 637500,
273*4882a593Smuzhiyun 						650000, 662500, 675000,
274*4882a593Smuzhiyun 						687500, 700000, 712500,
275*4882a593Smuzhiyun 						725000, 737500, 750000,
276*4882a593Smuzhiyun 						762500, 775000, 787500,
277*4882a593Smuzhiyun 						800000, 812500, 825000,
278*4882a593Smuzhiyun 						837500, 850000, 862500,
279*4882a593Smuzhiyun 						875000, 887500, 900000,
280*4882a593Smuzhiyun 						912500, 925000, 937500,
281*4882a593Smuzhiyun 						950000, 962500, 975000,
282*4882a593Smuzhiyun 						987500, 1000000, 1012500,
283*4882a593Smuzhiyun 						1025000, 1037500, 1050000,
284*4882a593Smuzhiyun 						1062500, 1075000, 1087500,
285*4882a593Smuzhiyun 						1100000, 1112500, 1125000,
286*4882a593Smuzhiyun 						1137500, 1150000, 1162500,
287*4882a593Smuzhiyun 						1175000, 1187500, 1200000,
288*4882a593Smuzhiyun 						1212500, 1225000, 1237500,
289*4882a593Smuzhiyun 						1250000, 1262500, 1275000,
290*4882a593Smuzhiyun 						1287500, 1300000, 1312500,
291*4882a593Smuzhiyun 						1325000, 1337500, 1350000,
292*4882a593Smuzhiyun 						1362500, 1375000, 1387500,
293*4882a593Smuzhiyun 						1400000, 1412500, 1425000,
294*4882a593Smuzhiyun 						1437500, 1450000, 1462500, };
295*4882a593Smuzhiyun static const unsigned int sw5_val_tbl[] = { 0, 5050000, };
296*4882a593Smuzhiyun static const unsigned int vcam_val_tbl[] = { 2600000, 2700000, 2800000,
297*4882a593Smuzhiyun 					     2900000, };
298*4882a593Smuzhiyun static const unsigned int vcsi_val_tbl[] = { 1200000, 1800000, };
299*4882a593Smuzhiyun static const unsigned int vdac_val_tbl[] = { 1200000, 1500000, 1800000,
300*4882a593Smuzhiyun 					     2500000,};
301*4882a593Smuzhiyun static const unsigned int vdig_val_tbl[] = { 1200000, 1350000, 1500000,
302*4882a593Smuzhiyun 					     1875000, };
303*4882a593Smuzhiyun static const unsigned int vfuse_val_tbl[] = { 1500000, 1600000, 1700000,
304*4882a593Smuzhiyun 					      1800000, 1900000, 2000000,
305*4882a593Smuzhiyun 					      2100000, 2200000, 2300000,
306*4882a593Smuzhiyun 					      2400000, 2500000, 2600000,
307*4882a593Smuzhiyun 					      2700000, 3150000, };
308*4882a593Smuzhiyun static const unsigned int vhvio_val_tbl[] = { 2775000, };
309*4882a593Smuzhiyun static const unsigned int vsdio_val_tbl[] = { 1500000, 1600000, 1800000,
310*4882a593Smuzhiyun 					      2600000, 2700000, 2800000,
311*4882a593Smuzhiyun 					      2900000, 3000000, };
312*4882a593Smuzhiyun static const unsigned int vpll_val_tbl[] = { 1200000, 1300000, 1400000,
313*4882a593Smuzhiyun 					     1800000, };
314*4882a593Smuzhiyun /* Quirk: 2775000 is before 2500000 for vrf1 regulator */
315*4882a593Smuzhiyun static const unsigned int vrf1_val_tbl[] = { 2775000, 2500000, };
316*4882a593Smuzhiyun static const unsigned int vrf2_val_tbl[] = { 0, 2775000, };
317*4882a593Smuzhiyun static const unsigned int vrfref_val_tbl[] = { 2500000, 2775000, };
318*4882a593Smuzhiyun static const unsigned int vwlan1_val_tbl[] = { 1800000, 1900000, };
319*4882a593Smuzhiyun static const unsigned int vwlan2_val_tbl[] = { 2775000, 3000000, 3300000,
320*4882a593Smuzhiyun 					       3300000, };
321*4882a593Smuzhiyun static const unsigned int vsim_val_tbl[] = { 1800000, 2900000, };
322*4882a593Smuzhiyun static const unsigned int vsimcard_val_tbl[] = { 1800000, 2900000, };
323*4882a593Smuzhiyun static const unsigned int vvib_val_tbl[] = { 1300000, 1800000, 2000000,
324*4882a593Smuzhiyun 					     3000000, };
325*4882a593Smuzhiyun static const unsigned int vusb_val_tbl[] = { 0, 3300000, };
326*4882a593Smuzhiyun static const unsigned int vaudio_val_tbl[] = { 0, 2775000, };
327*4882a593Smuzhiyun 
328*4882a593Smuzhiyun /*
329*4882a593Smuzhiyun  * SoC specific configuration for omap4. The data below is comes from Motorola
330*4882a593Smuzhiyun  * Linux kernel tree. It's basically the values of cpcap_regltr_data,
331*4882a593Smuzhiyun  * cpcap_regulator_mode_values and cpcap_regulator_off_mode_values, see
332*4882a593Smuzhiyun  * CPCAP_REG macro above.
333*4882a593Smuzhiyun  *
334*4882a593Smuzhiyun  * SW1 to SW4 and SW6 seems to be unused for mapphone. Note that VSIM and
335*4882a593Smuzhiyun  * VSIMCARD have a shared resource assignment bit.
336*4882a593Smuzhiyun  */
337*4882a593Smuzhiyun static const struct cpcap_regulator omap4_regulators[] = {
338*4882a593Smuzhiyun 	CPCAP_REG(SW1, CPCAP_REG_S1C1, CPCAP_REG_ASSIGN2,
339*4882a593Smuzhiyun 		  CPCAP_BIT_SW1_SEL, unknown_val_tbl,
340*4882a593Smuzhiyun 		  0, 0, 0, 0, 0),
341*4882a593Smuzhiyun 	CPCAP_REG(SW2, CPCAP_REG_S2C1, CPCAP_REG_ASSIGN2,
342*4882a593Smuzhiyun 		  CPCAP_BIT_SW2_SEL, unknown_val_tbl,
343*4882a593Smuzhiyun 		  0, 0, 0, 0, 0),
344*4882a593Smuzhiyun 	CPCAP_REG(SW3, CPCAP_REG_S3C, CPCAP_REG_ASSIGN2,
345*4882a593Smuzhiyun 		  CPCAP_BIT_SW3_SEL, unknown_val_tbl,
346*4882a593Smuzhiyun 		  0, 0, 0, 0, 0),
347*4882a593Smuzhiyun 	CPCAP_REG(SW4, CPCAP_REG_S4C1, CPCAP_REG_ASSIGN2,
348*4882a593Smuzhiyun 		  CPCAP_BIT_SW4_SEL, unknown_val_tbl,
349*4882a593Smuzhiyun 		  0, 0, 0, 0, 0),
350*4882a593Smuzhiyun 	CPCAP_REG(SW5, CPCAP_REG_S5C, CPCAP_REG_ASSIGN2,
351*4882a593Smuzhiyun 		  CPCAP_BIT_SW5_SEL, sw5_val_tbl,
352*4882a593Smuzhiyun 		  0x28, 0, 0x20 | CPCAP_REG_OFF_MODE_SEC, 0, 0),
353*4882a593Smuzhiyun 	CPCAP_REG(SW6, CPCAP_REG_S6C, CPCAP_REG_ASSIGN2,
354*4882a593Smuzhiyun 		  CPCAP_BIT_SW6_SEL, unknown_val_tbl,
355*4882a593Smuzhiyun 		  0, 0, 0, 0, 0),
356*4882a593Smuzhiyun 	CPCAP_REG(VCAM, CPCAP_REG_VCAMC, CPCAP_REG_ASSIGN2,
357*4882a593Smuzhiyun 		  CPCAP_BIT_VCAM_SEL, vcam_val_tbl,
358*4882a593Smuzhiyun 		  0x87, 0x30, 0x3, 0, 420),
359*4882a593Smuzhiyun 	CPCAP_REG(VCSI, CPCAP_REG_VCSIC, CPCAP_REG_ASSIGN3,
360*4882a593Smuzhiyun 		  CPCAP_BIT_VCSI_SEL, vcsi_val_tbl,
361*4882a593Smuzhiyun 		  0x47, 0x10, 0x43, 0x41, 350),
362*4882a593Smuzhiyun 	CPCAP_REG(VDAC, CPCAP_REG_VDACC, CPCAP_REG_ASSIGN3,
363*4882a593Smuzhiyun 		  CPCAP_BIT_VDAC_SEL, vdac_val_tbl,
364*4882a593Smuzhiyun 		  0x87, 0x30, 0x3, 0, 420),
365*4882a593Smuzhiyun 	CPCAP_REG(VDIG, CPCAP_REG_VDIGC, CPCAP_REG_ASSIGN2,
366*4882a593Smuzhiyun 		  CPCAP_BIT_VDIG_SEL, vdig_val_tbl,
367*4882a593Smuzhiyun 		  0x87, 0x30, 0x82, 0, 420),
368*4882a593Smuzhiyun 	CPCAP_REG(VFUSE, CPCAP_REG_VFUSEC, CPCAP_REG_ASSIGN3,
369*4882a593Smuzhiyun 		  CPCAP_BIT_VFUSE_SEL, vfuse_val_tbl,
370*4882a593Smuzhiyun 		  0x80, 0xf, 0x80, 0, 420),
371*4882a593Smuzhiyun 	CPCAP_REG(VHVIO, CPCAP_REG_VHVIOC, CPCAP_REG_ASSIGN3,
372*4882a593Smuzhiyun 		  CPCAP_BIT_VHVIO_SEL, vhvio_val_tbl,
373*4882a593Smuzhiyun 		  0x17, 0, 0, 0x12, 0),
374*4882a593Smuzhiyun 	CPCAP_REG(VSDIO, CPCAP_REG_VSDIOC, CPCAP_REG_ASSIGN2,
375*4882a593Smuzhiyun 		  CPCAP_BIT_VSDIO_SEL, vsdio_val_tbl,
376*4882a593Smuzhiyun 		  0x87, 0x38, 0x82, 0, 420),
377*4882a593Smuzhiyun 	CPCAP_REG(VPLL, CPCAP_REG_VPLLC, CPCAP_REG_ASSIGN3,
378*4882a593Smuzhiyun 		  CPCAP_BIT_VPLL_SEL, vpll_val_tbl,
379*4882a593Smuzhiyun 		  0x43, 0x18, 0x2, 0, 420),
380*4882a593Smuzhiyun 	CPCAP_REG(VRF1, CPCAP_REG_VRF1C, CPCAP_REG_ASSIGN3,
381*4882a593Smuzhiyun 		  CPCAP_BIT_VRF1_SEL, vrf1_val_tbl,
382*4882a593Smuzhiyun 		  0xac, 0x2, 0x4, 0, 10),
383*4882a593Smuzhiyun 	CPCAP_REG(VRF2, CPCAP_REG_VRF2C, CPCAP_REG_ASSIGN3,
384*4882a593Smuzhiyun 		  CPCAP_BIT_VRF2_SEL, vrf2_val_tbl,
385*4882a593Smuzhiyun 		  0x23, 0x8, 0, 0, 10),
386*4882a593Smuzhiyun 	CPCAP_REG(VRFREF, CPCAP_REG_VRFREFC, CPCAP_REG_ASSIGN3,
387*4882a593Smuzhiyun 		  CPCAP_BIT_VRFREF_SEL, vrfref_val_tbl,
388*4882a593Smuzhiyun 		  0x23, 0x8, 0, 0, 420),
389*4882a593Smuzhiyun 	CPCAP_REG(VWLAN1, CPCAP_REG_VWLAN1C, CPCAP_REG_ASSIGN3,
390*4882a593Smuzhiyun 		  CPCAP_BIT_VWLAN1_SEL, vwlan1_val_tbl,
391*4882a593Smuzhiyun 		  0x47, 0x10, 0, 0, 420),
392*4882a593Smuzhiyun 	CPCAP_REG(VWLAN2, CPCAP_REG_VWLAN2C, CPCAP_REG_ASSIGN3,
393*4882a593Smuzhiyun 		  CPCAP_BIT_VWLAN2_SEL, vwlan2_val_tbl,
394*4882a593Smuzhiyun 		  0x20c, 0xc0, 0x20c, 0, 420),
395*4882a593Smuzhiyun 	CPCAP_REG(VSIM, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
396*4882a593Smuzhiyun 		  0xffff, vsim_val_tbl,
397*4882a593Smuzhiyun 		  0x23, 0x8, 0x3, 0, 420),
398*4882a593Smuzhiyun 	CPCAP_REG(VSIMCARD, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
399*4882a593Smuzhiyun 		  0xffff, vsimcard_val_tbl,
400*4882a593Smuzhiyun 		  0x1e80, 0x8, 0x1e00, 0, 420),
401*4882a593Smuzhiyun 	CPCAP_REG(VVIB, CPCAP_REG_VVIBC, CPCAP_REG_ASSIGN3,
402*4882a593Smuzhiyun 		  CPCAP_BIT_VVIB_SEL, vvib_val_tbl,
403*4882a593Smuzhiyun 		  0x1, 0xc, 0x1, 0, 500),
404*4882a593Smuzhiyun 	CPCAP_REG(VUSB, CPCAP_REG_VUSBC, CPCAP_REG_ASSIGN3,
405*4882a593Smuzhiyun 		  CPCAP_BIT_VUSB_SEL, vusb_val_tbl,
406*4882a593Smuzhiyun 		  0x11c, 0x40, 0xc, 0, 0),
407*4882a593Smuzhiyun 	CPCAP_REG(VAUDIO, CPCAP_REG_VAUDIOC, CPCAP_REG_ASSIGN4,
408*4882a593Smuzhiyun 		  CPCAP_BIT_VAUDIO_SEL, vaudio_val_tbl,
409*4882a593Smuzhiyun 		  0x16, 0x1, 0x4, 0, 0),
410*4882a593Smuzhiyun 	{ /* sentinel */ },
411*4882a593Smuzhiyun };
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun static const struct cpcap_regulator xoom_regulators[] = {
414*4882a593Smuzhiyun 	CPCAP_REG(SW1, CPCAP_REG_S1C1, CPCAP_REG_ASSIGN2,
415*4882a593Smuzhiyun 		  CPCAP_BIT_SW1_SEL, unknown_val_tbl,
416*4882a593Smuzhiyun 		  0, 0, 0, 0, 0),
417*4882a593Smuzhiyun 	CPCAP_REG(SW2, CPCAP_REG_S2C1, CPCAP_REG_ASSIGN2,
418*4882a593Smuzhiyun 		  CPCAP_BIT_SW2_SEL, sw2_sw4_val_tbl,
419*4882a593Smuzhiyun 		  0xf00, 0x7f, 0x800, 0, 120),
420*4882a593Smuzhiyun 	CPCAP_REG(SW3, CPCAP_REG_S3C, CPCAP_REG_ASSIGN2,
421*4882a593Smuzhiyun 		  CPCAP_BIT_SW3_SEL, unknown_val_tbl,
422*4882a593Smuzhiyun 		  0, 0, 0, 0, 0),
423*4882a593Smuzhiyun 	CPCAP_REG(SW4, CPCAP_REG_S4C1, CPCAP_REG_ASSIGN2,
424*4882a593Smuzhiyun 		  CPCAP_BIT_SW4_SEL, sw2_sw4_val_tbl,
425*4882a593Smuzhiyun 		  0xf00, 0x7f, 0x900, 0, 100),
426*4882a593Smuzhiyun 	CPCAP_REG(SW5, CPCAP_REG_S5C, CPCAP_REG_ASSIGN2,
427*4882a593Smuzhiyun 		  CPCAP_BIT_SW5_SEL, sw5_val_tbl,
428*4882a593Smuzhiyun 		  0x2a, 0, 0x22, 0, 0),
429*4882a593Smuzhiyun 	CPCAP_REG(SW6, CPCAP_REG_S6C, CPCAP_REG_ASSIGN2,
430*4882a593Smuzhiyun 		  CPCAP_BIT_SW6_SEL, unknown_val_tbl,
431*4882a593Smuzhiyun 		  0, 0, 0, 0, 0),
432*4882a593Smuzhiyun 	CPCAP_REG(VCAM, CPCAP_REG_VCAMC, CPCAP_REG_ASSIGN2,
433*4882a593Smuzhiyun 		  CPCAP_BIT_VCAM_SEL, vcam_val_tbl,
434*4882a593Smuzhiyun 		  0x87, 0x30, 0x7, 0, 420),
435*4882a593Smuzhiyun 	CPCAP_REG(VCSI, CPCAP_REG_VCSIC, CPCAP_REG_ASSIGN3,
436*4882a593Smuzhiyun 		  CPCAP_BIT_VCSI_SEL, vcsi_val_tbl,
437*4882a593Smuzhiyun 		  0x47, 0x10, 0x7, 0, 350),
438*4882a593Smuzhiyun 	CPCAP_REG(VDAC, CPCAP_REG_VDACC, CPCAP_REG_ASSIGN3,
439*4882a593Smuzhiyun 		  CPCAP_BIT_VDAC_SEL, vdac_val_tbl,
440*4882a593Smuzhiyun 		  0x87, 0x30, 0x3, 0, 420),
441*4882a593Smuzhiyun 	CPCAP_REG(VDIG, CPCAP_REG_VDIGC, CPCAP_REG_ASSIGN2,
442*4882a593Smuzhiyun 		  CPCAP_BIT_VDIG_SEL, vdig_val_tbl,
443*4882a593Smuzhiyun 		  0x87, 0x30, 0x5, 0, 420),
444*4882a593Smuzhiyun 	CPCAP_REG(VFUSE, CPCAP_REG_VFUSEC, CPCAP_REG_ASSIGN3,
445*4882a593Smuzhiyun 		  CPCAP_BIT_VFUSE_SEL, vfuse_val_tbl,
446*4882a593Smuzhiyun 		  0x80, 0xf, 0x80, 0, 420),
447*4882a593Smuzhiyun 	CPCAP_REG(VHVIO, CPCAP_REG_VHVIOC, CPCAP_REG_ASSIGN3,
448*4882a593Smuzhiyun 		  CPCAP_BIT_VHVIO_SEL, vhvio_val_tbl,
449*4882a593Smuzhiyun 		  0x17, 0, 0x2, 0, 0),
450*4882a593Smuzhiyun 	CPCAP_REG(VSDIO, CPCAP_REG_VSDIOC, CPCAP_REG_ASSIGN2,
451*4882a593Smuzhiyun 		  CPCAP_BIT_VSDIO_SEL, vsdio_val_tbl,
452*4882a593Smuzhiyun 		  0x87, 0x38, 0x2, 0, 420),
453*4882a593Smuzhiyun 	CPCAP_REG(VPLL, CPCAP_REG_VPLLC, CPCAP_REG_ASSIGN3,
454*4882a593Smuzhiyun 		  CPCAP_BIT_VPLL_SEL, vpll_val_tbl,
455*4882a593Smuzhiyun 		  0x43, 0x18, 0x1, 0, 420),
456*4882a593Smuzhiyun 	CPCAP_REG(VRF1, CPCAP_REG_VRF1C, CPCAP_REG_ASSIGN3,
457*4882a593Smuzhiyun 		  CPCAP_BIT_VRF1_SEL, vrf1_val_tbl,
458*4882a593Smuzhiyun 		  0xac, 0x2, 0xc, 0, 10),
459*4882a593Smuzhiyun 	CPCAP_REG(VRF2, CPCAP_REG_VRF2C, CPCAP_REG_ASSIGN3,
460*4882a593Smuzhiyun 		  CPCAP_BIT_VRF2_SEL, vrf2_val_tbl,
461*4882a593Smuzhiyun 		  0x23, 0x8, 0x3, 0, 10),
462*4882a593Smuzhiyun 	CPCAP_REG(VRFREF, CPCAP_REG_VRFREFC, CPCAP_REG_ASSIGN3,
463*4882a593Smuzhiyun 		  CPCAP_BIT_VRFREF_SEL, vrfref_val_tbl,
464*4882a593Smuzhiyun 		  0x23, 0x8, 0x3, 0, 420),
465*4882a593Smuzhiyun 	CPCAP_REG(VWLAN1, CPCAP_REG_VWLAN1C, CPCAP_REG_ASSIGN3,
466*4882a593Smuzhiyun 		  CPCAP_BIT_VWLAN1_SEL, vwlan1_val_tbl,
467*4882a593Smuzhiyun 		  0x47, 0x10, 0x5, 0, 420),
468*4882a593Smuzhiyun 	CPCAP_REG(VWLAN2, CPCAP_REG_VWLAN2C, CPCAP_REG_ASSIGN3,
469*4882a593Smuzhiyun 		  CPCAP_BIT_VWLAN2_SEL, vwlan2_val_tbl,
470*4882a593Smuzhiyun 		  0x20c, 0xc0, 0x8, 0, 420),
471*4882a593Smuzhiyun 	CPCAP_REG(VSIM, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
472*4882a593Smuzhiyun 		  0xffff, vsim_val_tbl,
473*4882a593Smuzhiyun 		  0x23, 0x8, 0x3, 0, 420),
474*4882a593Smuzhiyun 	CPCAP_REG(VSIMCARD, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
475*4882a593Smuzhiyun 		  0xffff, vsimcard_val_tbl,
476*4882a593Smuzhiyun 		  0x1e80, 0x8, 0x1e00, 0, 420),
477*4882a593Smuzhiyun 	CPCAP_REG(VVIB, CPCAP_REG_VVIBC, CPCAP_REG_ASSIGN3,
478*4882a593Smuzhiyun 		  CPCAP_BIT_VVIB_SEL, vvib_val_tbl,
479*4882a593Smuzhiyun 		  0x1, 0xc, 0, 0x1, 500),
480*4882a593Smuzhiyun 	CPCAP_REG(VUSB, CPCAP_REG_VUSBC, CPCAP_REG_ASSIGN3,
481*4882a593Smuzhiyun 		  CPCAP_BIT_VUSB_SEL, vusb_val_tbl,
482*4882a593Smuzhiyun 		  0x11c, 0x40, 0xc, 0, 0),
483*4882a593Smuzhiyun 	CPCAP_REG(VAUDIO, CPCAP_REG_VAUDIOC, CPCAP_REG_ASSIGN4,
484*4882a593Smuzhiyun 		  CPCAP_BIT_VAUDIO_SEL, vaudio_val_tbl,
485*4882a593Smuzhiyun 		  0x16, 0x1, 0x4, 0, 0),
486*4882a593Smuzhiyun 	{ /* sentinel */ },
487*4882a593Smuzhiyun };
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun static const struct of_device_id cpcap_regulator_id_table[] = {
490*4882a593Smuzhiyun 	{
491*4882a593Smuzhiyun 		.compatible = "motorola,cpcap-regulator",
492*4882a593Smuzhiyun 	},
493*4882a593Smuzhiyun 	{
494*4882a593Smuzhiyun 		.compatible = "motorola,mapphone-cpcap-regulator",
495*4882a593Smuzhiyun 		.data = omap4_regulators,
496*4882a593Smuzhiyun 	},
497*4882a593Smuzhiyun 	{
498*4882a593Smuzhiyun 		.compatible = "motorola,xoom-cpcap-regulator",
499*4882a593Smuzhiyun 		.data = xoom_regulators,
500*4882a593Smuzhiyun 	},
501*4882a593Smuzhiyun 	{},
502*4882a593Smuzhiyun };
503*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, cpcap_regulator_id_table);
504*4882a593Smuzhiyun 
cpcap_regulator_probe(struct platform_device * pdev)505*4882a593Smuzhiyun static int cpcap_regulator_probe(struct platform_device *pdev)
506*4882a593Smuzhiyun {
507*4882a593Smuzhiyun 	struct cpcap_ddata *ddata;
508*4882a593Smuzhiyun 	const struct cpcap_regulator *match_data;
509*4882a593Smuzhiyun 	struct regulator_config config;
510*4882a593Smuzhiyun 	int i;
511*4882a593Smuzhiyun 
512*4882a593Smuzhiyun 	match_data = of_device_get_match_data(&pdev->dev);
513*4882a593Smuzhiyun 	if (!match_data) {
514*4882a593Smuzhiyun 		dev_err(&pdev->dev, "no configuration data found\n");
515*4882a593Smuzhiyun 
516*4882a593Smuzhiyun 		return -ENODEV;
517*4882a593Smuzhiyun 	}
518*4882a593Smuzhiyun 
519*4882a593Smuzhiyun 	ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
520*4882a593Smuzhiyun 	if (!ddata)
521*4882a593Smuzhiyun 		return -ENOMEM;
522*4882a593Smuzhiyun 
523*4882a593Smuzhiyun 	ddata->reg = dev_get_regmap(pdev->dev.parent, NULL);
524*4882a593Smuzhiyun 	if (!ddata->reg)
525*4882a593Smuzhiyun 		return -ENODEV;
526*4882a593Smuzhiyun 
527*4882a593Smuzhiyun 	ddata->dev = &pdev->dev;
528*4882a593Smuzhiyun 	ddata->soc = match_data;
529*4882a593Smuzhiyun 	platform_set_drvdata(pdev, ddata);
530*4882a593Smuzhiyun 
531*4882a593Smuzhiyun 	memset(&config, 0, sizeof(config));
532*4882a593Smuzhiyun 	config.dev = &pdev->dev;
533*4882a593Smuzhiyun 	config.regmap = ddata->reg;
534*4882a593Smuzhiyun 
535*4882a593Smuzhiyun 	for (i = 0; i < CPCAP_NR_REGULATORS; i++) {
536*4882a593Smuzhiyun 		const struct cpcap_regulator *regulator = &ddata->soc[i];
537*4882a593Smuzhiyun 		struct regulator_dev *rdev;
538*4882a593Smuzhiyun 
539*4882a593Smuzhiyun 		if (!regulator->rdesc.name)
540*4882a593Smuzhiyun 			break;
541*4882a593Smuzhiyun 
542*4882a593Smuzhiyun 		if (regulator->rdesc.volt_table == unknown_val_tbl)
543*4882a593Smuzhiyun 			continue;
544*4882a593Smuzhiyun 
545*4882a593Smuzhiyun 		config.driver_data = (void *)regulator;
546*4882a593Smuzhiyun 		rdev = devm_regulator_register(&pdev->dev,
547*4882a593Smuzhiyun 					       &regulator->rdesc,
548*4882a593Smuzhiyun 					       &config);
549*4882a593Smuzhiyun 		if (IS_ERR(rdev)) {
550*4882a593Smuzhiyun 			dev_err(&pdev->dev, "failed to register regulator %s\n",
551*4882a593Smuzhiyun 				regulator->rdesc.name);
552*4882a593Smuzhiyun 
553*4882a593Smuzhiyun 			return PTR_ERR(rdev);
554*4882a593Smuzhiyun 		}
555*4882a593Smuzhiyun 	}
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun 	return 0;
558*4882a593Smuzhiyun }
559*4882a593Smuzhiyun 
560*4882a593Smuzhiyun static struct platform_driver cpcap_regulator_driver = {
561*4882a593Smuzhiyun 	.probe		= cpcap_regulator_probe,
562*4882a593Smuzhiyun 	.driver		= {
563*4882a593Smuzhiyun 		.name	= "cpcap-regulator",
564*4882a593Smuzhiyun 		.of_match_table = of_match_ptr(cpcap_regulator_id_table),
565*4882a593Smuzhiyun 	},
566*4882a593Smuzhiyun };
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun module_platform_driver(cpcap_regulator_driver);
569*4882a593Smuzhiyun 
570*4882a593Smuzhiyun MODULE_ALIAS("platform:cpcap-regulator");
571*4882a593Smuzhiyun MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>");
572*4882a593Smuzhiyun MODULE_DESCRIPTION("CPCAP regulator driver");
573*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
574