xref: /openbmc/u-boot/drivers/power/palmas.c (revision f0df2546)
1 /*
2  * (C) Copyright 2012-2013
3  * Texas Instruments, <www.ti.com>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23 #include <config.h>
24 #include <palmas.h>
25 
26 void palmas_init_settings(void)
27 {
28 #ifdef CONFIG_PALMAS_SMPS7_FPWM
29 	int err;
30 	/*
31 	 * Set SMPS7 (1.8 V I/O supply on platforms with TWL6035/37) to
32 	 * forced PWM mode. This reduces noise (but affects efficiency).
33 	 */
34 	u8 val = SMPS_MODE_SLP_FPWM | SMPS_MODE_ACT_FPWM;
35 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS7_CTRL, val);
36 	if (err)
37 		printf("palmas: could not force PWM for SMPS7: err = %d\n",
38 		       err);
39 #endif
40 }
41 
42 int palmas_mmc1_poweron_ldo(void)
43 {
44 	u8 val = 0;
45 
46 #if defined(CONFIG_DRA7XX)
47 	/*
48 	 * Currently valid for the dra7xx_evm board:
49 	 * Set TPS659038 LDO1 to 3.0 V
50 	 */
51 	val = LDO_VOLT_3V0;
52 	if (palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_VOLTAGE, val)) {
53 		printf("tps65903x: could not set LDO1 voltage.\n");
54 		return 1;
55 	}
56 	/* TURN ON LDO1 */
57 	val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
58 	if (palmas_i2c_write_u8(TPS65903X_CHIP_P1, LDO1_CTRL, val)) {
59 		printf("tps65903x: could not turn on LDO1.\n");
60 		return 1;
61 	}
62 	return 0;
63 #else
64 	/*
65 	 * We assume that this is a OMAP543X + TWL603X board:
66 	 * Set TWL6035/37 LDO9 to 3.0 V
67 	 */
68 	val = LDO_VOLT_3V0;
69 	return twl603x_mmc1_set_ldo9(val);
70 #endif
71 }
72 
73 /*
74  * On some OMAP5 + TWL603X hardware the SD card socket and LDO9_IN are
75  * powered by an external 3.3 V regulator, while the output of LDO9
76  * supplies VDDS_SDCARD for the OMAP5 interface only. This implies that
77  * LDO9 could be set to 'bypass' mode when required (e.g. for 3.3 V cards).
78  */
79 int twl603x_mmc1_set_ldo9(u8 vsel)
80 {
81 	u8 cval = 0, vval = 0;	/* Off by default */
82 	int err;
83 
84 	if (vsel) {
85 		/* Turn on */
86 		if (vsel > LDO_VOLT_3V3) {
87 			/* Put LDO9 in bypass */
88 			cval = LDO9_BYP_EN | RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
89 			vval = LDO_VOLT_3V3;
90 		} else {
91 			cval = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
92 			vval = vsel & 0x3f;
93 		}
94 	}
95 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_VOLTAGE, vval);
96 	if (err) {
97 		printf("twl603x: could not set LDO9 %s: err = %d\n",
98 		       vsel > LDO_VOLT_3V3 ? "bypass" : "voltage", err);
99 		return err;
100 	}
101 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_CTRL, cval);
102 	if (err)
103 		printf("twl603x: could not turn %s LDO9: err = %d\n",
104 		       cval ? "on" : "off", err);
105 	return err;
106 }
107 
108 #ifdef CONFIG_PALMAS_AUDPWR
109 /*
110  * Turn audio codec power and 32 kHz clock on/off. Use for
111  * testing OMAP543X + TWL603X + TWL604X boards only.
112  */
113 int twl603x_audio_power(u8 on)
114 {
115 	u8 cval = 0, vval = 0, c32k = 0;
116 	int err;
117 
118 	if (on) {
119 		vval = SMPS_VOLT_2V1;
120 		cval = SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO;
121 		c32k = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
122 	}
123 	/* Set SMPS9 to 2.1 V (for TWL604x), or to 0 (off) */
124 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_VOLTAGE, vval);
125 	if (err) {
126 		printf("twl603x: could not set SMPS9 voltage: err = %d\n",
127 		       err);
128 		return err;
129 	}
130 	/* Turn on or off SMPS9 */
131 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_CTRL, cval);
132 	if (err) {
133 		printf("twl603x: could not turn SMPS9 %s: err = %d\n",
134 		       cval ? "on" : "off", err);
135 		return err;
136 	}
137 	/* Output 32 kHz clock on or off */
138 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, CLK32KGAUDIO_CTRL, c32k);
139 	if (err)
140 		printf("twl603x: could not turn CLK32KGAUDIO %s: err = %d\n",
141 		       c32k ? "on" : "off", err);
142 	return err;
143 }
144 #endif
145 
146 /*
147  * Enable/disable back-up battery (or super cap) charging on TWL6035/37.
148  * Please use defined BB_xxx values.
149  */
150 int twl603x_enable_bb_charge(u8 bb_fields)
151 {
152 	u8 val = bb_fields & 0x0f;
153 	int err;
154 
155 	val |= (VRTC_EN_SLP | VRTC_EN_OFF | VRTC_PWEN);
156 	err = palmas_i2c_write_u8(TWL603X_CHIP_P1, BB_VRTC_CTRL, val);
157 	if (err)
158 		printf("twl603x: could not set BB_VRTC_CTRL to 0x%02x: err = %d\n",
159 		       val, err);
160 	return err;
161 }
162