xref: /openbmc/u-boot/drivers/power/palmas.c (revision 679590eb)
1 /*
2  * (C) Copyright 2012-2013
3  * Texas Instruments, <www.ti.com>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 #include <config.h>
8 #include <palmas.h>
9 
10 void palmas_init_settings(void)
11 {
12 #ifdef CONFIG_PALMAS_SMPS7_FPWM
13 	int err;
14 	/*
15 	 * Set SMPS7 (1.8 V I/O supply on platforms with TWL6035/37) to
16 	 * forced PWM mode. This reduces noise (but affects efficiency).
17 	 */
18 	u8 val = SMPS_MODE_SLP_FPWM | SMPS_MODE_ACT_FPWM;
19 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS7_CTRL, val);
20 	if (err)
21 		printf("palmas: could not force PWM for SMPS7: err = %d\n",
22 		       err);
23 #endif
24 }
25 
26 #if defined(CONFIG_OMAP54XX)
27 int lp873x_mmc1_poweron_ldo(uint voltage)
28 {
29 	if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_VOLTAGE,
30 				voltage)) {
31 		printf("lp873x: could not set LDO1 voltage.\n");
32 		return 1;
33 	}
34 	/* TURN ON LDO1 */
35 	if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_CTRL,
36 				LP873X_LDO_CTRL_EN | LP873X_LDO_CTRL_RDIS_EN)) {
37 		printf("lp873x: could not turn on LDO1.\n");
38 		return 1;
39 	}
40 	return 0;
41 
42 }
43 #endif
44 
45 int palmas_mmc1_poweron_ldo(uint voltage)
46 {
47 	u8 val = 0;
48 
49 #if defined(CONFIG_DRA7XX)
50 	int ret;
51 	/*
52 	 * Currently valid for the dra7xx_evm board:
53 	 * Set TPS659038 LDO1 to 3.0 V or 1.8V
54 	 */
55 	ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_VOLTAGE, voltage);
56 	if (ret) {
57 		printf("tps65903x: could not set LDO1 voltage.\n");
58 		return ret;
59 	}
60 	/* TURN ON LDO1 */
61 	val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
62 	ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_CTRL, val);
63 	if (ret) {
64 		printf("tps65903x: could not turn on LDO1.\n");
65 		return ret;
66 	}
67 	return 0;
68 #else
69 	/*
70 	 * We assume that this is a OMAP543X + TWL603X board:
71 	 * Set TWL6035/37 LDO9 to 3.0 V
72 	 */
73 	val = LDO_VOLT_3V0;
74 	return twl603x_mmc1_set_ldo9(val);
75 #endif
76 }
77 
78 /*
79  * On some OMAP5 + TWL603X hardware the SD card socket and LDO9_IN are
80  * powered by an external 3.3 V regulator, while the output of LDO9
81  * supplies VDDS_SDCARD for the OMAP5 interface only. This implies that
82  * LDO9 could be set to 'bypass' mode when required (e.g. for 3.3 V cards).
83  */
84 int twl603x_mmc1_set_ldo9(u8 vsel)
85 {
86 	u8 cval = 0, vval = 0;	/* Off by default */
87 	int err;
88 
89 	if (vsel) {
90 		/* Turn on */
91 		if (vsel > LDO_VOLT_3V3) {
92 			/* Put LDO9 in bypass */
93 			cval = LDO9_BYP_EN | RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
94 			vval = LDO_VOLT_3V3;
95 		} else {
96 			cval = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
97 			vval = vsel & 0x3f;
98 		}
99 	}
100 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_VOLTAGE, vval);
101 	if (err) {
102 		printf("twl603x: could not set LDO9 %s: err = %d\n",
103 		       vsel > LDO_VOLT_3V3 ? "bypass" : "voltage", err);
104 		return err;
105 	}
106 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_CTRL, cval);
107 	if (err)
108 		printf("twl603x: could not turn %s LDO9: err = %d\n",
109 		       cval ? "on" : "off", err);
110 	return err;
111 }
112 
113 #ifdef CONFIG_PALMAS_AUDPWR
114 /*
115  * Turn audio codec power and 32 kHz clock on/off. Use for
116  * testing OMAP543X + TWL603X + TWL604X boards only.
117  */
118 int twl603x_audio_power(u8 on)
119 {
120 	u8 cval = 0, vval = 0, c32k = 0;
121 	int err;
122 
123 	if (on) {
124 		vval = SMPS_VOLT_2V1;
125 		cval = SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO;
126 		c32k = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
127 	}
128 	/* Set SMPS9 to 2.1 V (for TWL604x), or to 0 (off) */
129 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_VOLTAGE, vval);
130 	if (err) {
131 		printf("twl603x: could not set SMPS9 voltage: err = %d\n",
132 		       err);
133 		return err;
134 	}
135 	/* Turn on or off SMPS9 */
136 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_CTRL, cval);
137 	if (err) {
138 		printf("twl603x: could not turn SMPS9 %s: err = %d\n",
139 		       cval ? "on" : "off", err);
140 		return err;
141 	}
142 	/* Output 32 kHz clock on or off */
143 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, CLK32KGAUDIO_CTRL, c32k);
144 	if (err)
145 		printf("twl603x: could not turn CLK32KGAUDIO %s: err = %d\n",
146 		       c32k ? "on" : "off", err);
147 	return err;
148 }
149 #endif
150 
151 #ifdef CONFIG_PALMAS_USB_SS_PWR
152 /**
153  * @brief palmas_enable_ss_ldo - Configure EVM board specific configurations
154  * for the USB Super speed SMPS10 regulator.
155  *
156  * @return 0
157  */
158 int palmas_enable_ss_ldo(void)
159 {
160 	/* Enable smps10 regulator  */
161 	return palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS10_CTRL,
162 				SMPS10_MODE_ACTIVE_D);
163 }
164 #endif
165 
166 /*
167  * Enable/disable back-up battery (or super cap) charging on TWL6035/37.
168  * Please use defined BB_xxx values.
169  */
170 int twl603x_enable_bb_charge(u8 bb_fields)
171 {
172 	u8 val = bb_fields & 0x0f;
173 	int err;
174 
175 	val |= (VRTC_EN_SLP | VRTC_EN_OFF | VRTC_PWEN);
176 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, BB_VRTC_CTRL, val);
177 	if (err)
178 		printf("twl603x: could not set BB_VRTC_CTRL to 0x%02x: err = %d\n",
179 		       val, err);
180 	return err;
181 }
182