blob: bf9173949cfa0486e7b9f52d152b171a25b49df8 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
SRICHARAN R21144292012-03-12 02:25:48 +00002/*
Nishanth Menoncb199102013-03-26 05:20:54 +00003 * (C) Copyright 2012-2013
SRICHARAN R21144292012-03-12 02:25:48 +00004 * Texas Instruments, <www.ti.com>
SRICHARAN R21144292012-03-12 02:25:48 +00005 */
6#include <config.h>
Nishanth Menoncb199102013-03-26 05:20:54 +00007#include <palmas.h>
SRICHARAN R21144292012-03-12 02:25:48 +00008
Nishanth Menon12733882013-03-26 05:20:55 +00009void palmas_init_settings(void)
SRICHARAN R21144292012-03-12 02:25:48 +000010{
Lubomir Popove9090fa2013-06-06 04:16:40 +000011#ifdef CONFIG_PALMAS_SMPS7_FPWM
12 int err;
13 /*
14 * Set SMPS7 (1.8 V I/O supply on platforms with TWL6035/37) to
15 * forced PWM mode. This reduces noise (but affects efficiency).
16 */
17 u8 val = SMPS_MODE_SLP_FPWM | SMPS_MODE_ACT_FPWM;
18 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS7_CTRL, val);
19 if (err)
20 printf("palmas: could not force PWM for SMPS7: err = %d\n",
21 err);
22#endif
SRICHARAN R21144292012-03-12 02:25:48 +000023}
Balaji T Kdd23e592012-03-12 02:25:49 +000024
Lokesh Vutlab4b06002016-11-23 13:25:28 +053025#if defined(CONFIG_OMAP54XX)
26int lp873x_mmc1_poweron_ldo(uint voltage)
27{
28 if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_VOLTAGE,
29 voltage)) {
30 printf("lp873x: could not set LDO1 voltage.\n");
31 return 1;
32 }
33 /* TURN ON LDO1 */
34 if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_CTRL,
35 LP873X_LDO_CTRL_EN | LP873X_LDO_CTRL_RDIS_EN)) {
36 printf("lp873x: could not turn on LDO1.\n");
37 return 1;
38 }
39 return 0;
40
41}
42#endif
43
Lokesh Vutladb4fce82017-08-21 12:50:50 +053044int palmas_mmc1_poweron_ldo(uint ldo_volt, uint ldo_ctrl, uint voltage)
Balaji T Kdd23e592012-03-12 02:25:49 +000045{
46 u8 val = 0;
47
Nishanth Menon3891a542016-11-29 15:22:00 +053048#if defined(CONFIG_DRA7XX)
Jaehoon Chung505cf472016-12-15 20:49:50 +090049 int ret;
Lokesh Vutladb4fce82017-08-21 12:50:50 +053050
51 ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, ldo_volt, voltage);
Jaehoon Chung505cf472016-12-15 20:49:50 +090052 if (ret) {
Lubomir Popove9090fa2013-06-06 04:16:40 +000053 printf("tps65903x: could not set LDO1 voltage.\n");
Jaehoon Chung505cf472016-12-15 20:49:50 +090054 return ret;
Vincent Stehléce851c82012-12-03 05:23:17 +000055 }
Lubomir Popove9090fa2013-06-06 04:16:40 +000056 /* TURN ON LDO1 */
57 val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
Lokesh Vutladb4fce82017-08-21 12:50:50 +053058 ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, ldo_ctrl, val);
Jaehoon Chung505cf472016-12-15 20:49:50 +090059 if (ret) {
Lubomir Popove9090fa2013-06-06 04:16:40 +000060 printf("tps65903x: could not turn on LDO1.\n");
Jaehoon Chung505cf472016-12-15 20:49:50 +090061 return ret;
Vincent Stehléce851c82012-12-03 05:23:17 +000062 }
Vincent Stehléce851c82012-12-03 05:23:17 +000063 return 0;
Lubomir Popove9090fa2013-06-06 04:16:40 +000064#else
65 /*
66 * We assume that this is a OMAP543X + TWL603X board:
67 * Set TWL6035/37 LDO9 to 3.0 V
68 */
69 val = LDO_VOLT_3V0;
70 return twl603x_mmc1_set_ldo9(val);
71#endif
72}
73
74/*
75 * On some OMAP5 + TWL603X hardware the SD card socket and LDO9_IN are
76 * powered by an external 3.3 V regulator, while the output of LDO9
77 * supplies VDDS_SDCARD for the OMAP5 interface only. This implies that
78 * LDO9 could be set to 'bypass' mode when required (e.g. for 3.3 V cards).
79 */
80int twl603x_mmc1_set_ldo9(u8 vsel)
81{
82 u8 cval = 0, vval = 0; /* Off by default */
83 int err;
84
85 if (vsel) {
86 /* Turn on */
87 if (vsel > LDO_VOLT_3V3) {
88 /* Put LDO9 in bypass */
89 cval = LDO9_BYP_EN | RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
90 vval = LDO_VOLT_3V3;
91 } else {
92 cval = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
93 vval = vsel & 0x3f;
94 }
95 }
96 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_VOLTAGE, vval);
97 if (err) {
98 printf("twl603x: could not set LDO9 %s: err = %d\n",
99 vsel > LDO_VOLT_3V3 ? "bypass" : "voltage", err);
100 return err;
101 }
102 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_CTRL, cval);
103 if (err)
104 printf("twl603x: could not turn %s LDO9: err = %d\n",
105 cval ? "on" : "off", err);
106 return err;
107}
108
109#ifdef CONFIG_PALMAS_AUDPWR
110/*
111 * Turn audio codec power and 32 kHz clock on/off. Use for
112 * testing OMAP543X + TWL603X + TWL604X boards only.
113 */
114int twl603x_audio_power(u8 on)
115{
116 u8 cval = 0, vval = 0, c32k = 0;
117 int err;
118
119 if (on) {
120 vval = SMPS_VOLT_2V1;
121 cval = SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO;
122 c32k = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
123 }
124 /* Set SMPS9 to 2.1 V (for TWL604x), or to 0 (off) */
125 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_VOLTAGE, vval);
126 if (err) {
127 printf("twl603x: could not set SMPS9 voltage: err = %d\n",
128 err);
129 return err;
130 }
131 /* Turn on or off SMPS9 */
132 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_CTRL, cval);
133 if (err) {
134 printf("twl603x: could not turn SMPS9 %s: err = %d\n",
135 cval ? "on" : "off", err);
136 return err;
137 }
138 /* Output 32 kHz clock on or off */
139 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, CLK32KGAUDIO_CTRL, c32k);
140 if (err)
141 printf("twl603x: could not turn CLK32KGAUDIO %s: err = %d\n",
142 c32k ? "on" : "off", err);
143 return err;
144}
145#endif
146
Dan Murphy1bd435b2013-08-26 08:54:49 -0500147#ifdef CONFIG_PALMAS_USB_SS_PWR
148/**
149 * @brief palmas_enable_ss_ldo - Configure EVM board specific configurations
150 * for the USB Super speed SMPS10 regulator.
151 *
152 * @return 0
153 */
154int palmas_enable_ss_ldo(void)
155{
156 /* Enable smps10 regulator */
157 return palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS10_CTRL,
158 SMPS10_MODE_ACTIVE_D);
159}
160#endif
161
Lubomir Popove9090fa2013-06-06 04:16:40 +0000162/*
163 * Enable/disable back-up battery (or super cap) charging on TWL6035/37.
164 * Please use defined BB_xxx values.
165 */
166int twl603x_enable_bb_charge(u8 bb_fields)
167{
168 u8 val = bb_fields & 0x0f;
169 int err;
170
171 val |= (VRTC_EN_SLP | VRTC_EN_OFF | VRTC_PWEN);
172 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, BB_VRTC_CTRL, val);
173 if (err)
174 printf("twl603x: could not set BB_VRTC_CTRL to 0x%02x: err = %d\n",
175 val, err);
176 return err;
Balaji T Kdd23e592012-03-12 02:25:49 +0000177}
Jean-Jacques Hiblotfb1b7712018-12-07 14:50:46 +0100178
Igor Opaniuk2147a162021-02-09 13:52:45 +0200179#if CONFIG_IS_ENABLED(DM_I2C)
Jean-Jacques Hiblotfb1b7712018-12-07 14:50:46 +0100180int palmas_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
181{
182 struct udevice *dev;
183 int ret;
184
185 ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
186 if (ret) {
187 pr_err("unable to get I2C bus. ret %d\n", ret);
188 return ret;
189 }
190 ret = dm_i2c_reg_write(dev, reg, val);
191 if (ret) {
192 pr_err("writing to palmas failed. ret %d\n", ret);
193 return ret;
194 }
195 return 0;
196}
197
198int palmas_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
199{
200 struct udevice *dev;
201 int ret;
202
203 ret = i2c_get_chip_for_busnum(0, chip_no, 1, &dev);
204 if (ret) {
205 pr_err("unable to get I2C bus. ret %d\n", ret);
206 return ret;
207 }
208 ret = dm_i2c_reg_read(dev, reg);
209 if (ret < 0) {
210 pr_err("reading from palmas failed. ret %d\n", ret);
211 return ret;
212 }
213 *valp = (u8)ret;
214 return 0;
215}
216#endif