1
2
3
4
5
6#include <config.h>
7#include <palmas.h>
8
9void palmas_init_settings(void)
10{
11#ifdef CONFIG_PALMAS_SMPS7_FPWM
12 int err;
13
14
15
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
23}
24
25#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
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
44int palmas_mmc1_poweron_ldo(uint ldo_volt, uint ldo_ctrl, uint voltage)
45{
46 u8 val = 0;
47
48#if defined(CONFIG_DRA7XX)
49 int ret;
50
51 ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, ldo_volt, voltage);
52 if (ret) {
53 printf("tps65903x: could not set LDO1 voltage.\n");
54 return ret;
55 }
56
57 val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
58 ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, ldo_ctrl, val);
59 if (ret) {
60 printf("tps65903x: could not turn on LDO1.\n");
61 return ret;
62 }
63 return 0;
64#else
65
66
67
68
69 val = LDO_VOLT_3V0;
70 return twl603x_mmc1_set_ldo9(val);
71#endif
72}
73
74
75
76
77
78
79
80int twl603x_mmc1_set_ldo9(u8 vsel)
81{
82 u8 cval = 0, vval = 0;
83 int err;
84
85 if (vsel) {
86
87 if (vsel > LDO_VOLT_3V3) {
88
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
112
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
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
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
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
147#ifdef CONFIG_PALMAS_USB_SS_PWR
148
149
150
151
152
153
154int palmas_enable_ss_ldo(void)
155{
156
157 return palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS10_CTRL,
158 SMPS10_MODE_ACTIVE_D);
159}
160#endif
161
162
163
164
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;
177}
178
179#ifdef CONFIG_DM_I2C
180int 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
217