1 /*
2 * twl-common.c
3 *
4 * Copyright (C) 2011 Texas Instruments, Inc..
5 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23 #include <linux/i2c.h>
24 #include <linux/i2c/twl.h>
25 #include <linux/gpio.h>
26 #include <linux/regulator/machine.h>
27 #include <linux/regulator/fixed.h>
28
29 #include <plat/i2c.h>
30 #include <plat/usb.h>
31
32 #include "twl-common.h"
33 #include "pm.h"
34
35 static struct i2c_board_info __initdata pmic_i2c_board_info = {
36 .addr = 0x48,
37 .flags = I2C_CLIENT_WAKE,
38 };
39
omap_pmic_init(int bus,u32 clkrate,const char * pmic_type,int pmic_irq,struct twl4030_platform_data * pmic_data)40 void __init omap_pmic_init(int bus, u32 clkrate,
41 const char *pmic_type, int pmic_irq,
42 struct twl4030_platform_data *pmic_data)
43 {
44 strncpy(pmic_i2c_board_info.type, pmic_type,
45 sizeof(pmic_i2c_board_info.type));
46 pmic_i2c_board_info.irq = pmic_irq;
47 pmic_i2c_board_info.platform_data = pmic_data;
48
49 omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
50 }
51
omap_pmic_late_init(void)52 void __init omap_pmic_late_init(void)
53 {
54 /* Init the OMAP TWL parameters (if PMIC has been registerd) */
55 if (!pmic_i2c_board_info.irq)
56 return;
57
58 omap3_twl_init();
59 omap4_twl_init();
60 }
61
62 #if defined(CONFIG_ARCH_OMAP3)
63 static struct twl4030_usb_data omap3_usb_pdata = {
64 .usb_mode = T2_USB_MODE_ULPI,
65 };
66
67 static int omap3_batt_table[] = {
68 /* 0 C */
69 30800, 29500, 28300, 27100,
70 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
71 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
72 11600, 11200, 10800, 10400, 10000, 9630, 9280, 8950, 8620, 8310,
73 8020, 7730, 7460, 7200, 6950, 6710, 6470, 6250, 6040, 5830,
74 5640, 5450, 5260, 5090, 4920, 4760, 4600, 4450, 4310, 4170,
75 4040, 3910, 3790, 3670, 3550
76 };
77
78 static struct twl4030_bci_platform_data omap3_bci_pdata = {
79 .battery_tmp_tbl = omap3_batt_table,
80 .tblsize = ARRAY_SIZE(omap3_batt_table),
81 };
82
83 static struct twl4030_madc_platform_data omap3_madc_pdata = {
84 .irq_line = 1,
85 };
86
87 static struct twl4030_codec_data omap3_codec;
88
89 static struct twl4030_audio_data omap3_audio_pdata = {
90 .audio_mclk = 26000000,
91 .codec = &omap3_codec,
92 };
93
94 static struct regulator_consumer_supply omap3_vdda_dac_supplies[] = {
95 REGULATOR_SUPPLY("vdda_dac", "omapdss_venc"),
96 };
97
98 static struct regulator_init_data omap3_vdac_idata = {
99 .constraints = {
100 .min_uV = 1800000,
101 .max_uV = 1800000,
102 .valid_modes_mask = REGULATOR_MODE_NORMAL
103 | REGULATOR_MODE_STANDBY,
104 .valid_ops_mask = REGULATOR_CHANGE_MODE
105 | REGULATOR_CHANGE_STATUS,
106 },
107 .num_consumer_supplies = ARRAY_SIZE(omap3_vdda_dac_supplies),
108 .consumer_supplies = omap3_vdda_dac_supplies,
109 };
110
111 static struct regulator_consumer_supply omap3_vpll2_supplies[] = {
112 REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
113 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
114 };
115
116 static struct regulator_init_data omap3_vpll2_idata = {
117 .constraints = {
118 .min_uV = 1800000,
119 .max_uV = 1800000,
120 .valid_modes_mask = REGULATOR_MODE_NORMAL
121 | REGULATOR_MODE_STANDBY,
122 .valid_ops_mask = REGULATOR_CHANGE_MODE
123 | REGULATOR_CHANGE_STATUS,
124 },
125 .num_consumer_supplies = ARRAY_SIZE(omap3_vpll2_supplies),
126 .consumer_supplies = omap3_vpll2_supplies,
127 };
128
omap3_pmic_get_config(struct twl4030_platform_data * pmic_data,u32 pdata_flags,u32 regulators_flags)129 void __init omap3_pmic_get_config(struct twl4030_platform_data *pmic_data,
130 u32 pdata_flags, u32 regulators_flags)
131 {
132 if (!pmic_data->irq_base)
133 pmic_data->irq_base = TWL4030_IRQ_BASE;
134 if (!pmic_data->irq_end)
135 pmic_data->irq_end = TWL4030_IRQ_END;
136
137 /* Common platform data configurations */
138 if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
139 pmic_data->usb = &omap3_usb_pdata;
140
141 if (pdata_flags & TWL_COMMON_PDATA_BCI && !pmic_data->bci)
142 pmic_data->bci = &omap3_bci_pdata;
143
144 if (pdata_flags & TWL_COMMON_PDATA_MADC && !pmic_data->madc)
145 pmic_data->madc = &omap3_madc_pdata;
146
147 if (pdata_flags & TWL_COMMON_PDATA_AUDIO && !pmic_data->audio)
148 pmic_data->audio = &omap3_audio_pdata;
149
150 /* Common regulator configurations */
151 if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
152 pmic_data->vdac = &omap3_vdac_idata;
153
154 if (regulators_flags & TWL_COMMON_REGULATOR_VPLL2 && !pmic_data->vpll2)
155 pmic_data->vpll2 = &omap3_vpll2_idata;
156 }
157 #endif /* CONFIG_ARCH_OMAP3 */
158
159 #if defined(CONFIG_ARCH_OMAP4)
160 static struct twl4030_usb_data omap4_usb_pdata = {
161 .phy_init = omap4430_phy_init,
162 .phy_exit = omap4430_phy_exit,
163 .phy_power = omap4430_phy_power,
164 .phy_set_clock = omap4430_phy_set_clk,
165 .phy_suspend = omap4430_phy_suspend,
166 };
167
168 static struct regulator_init_data omap4_vdac_idata = {
169 .constraints = {
170 .min_uV = 1800000,
171 .max_uV = 1800000,
172 .valid_modes_mask = REGULATOR_MODE_NORMAL
173 | REGULATOR_MODE_STANDBY,
174 .valid_ops_mask = REGULATOR_CHANGE_MODE
175 | REGULATOR_CHANGE_STATUS,
176 },
177 };
178
179 static struct regulator_init_data omap4_vaux2_idata = {
180 .constraints = {
181 .min_uV = 1200000,
182 .max_uV = 2800000,
183 .apply_uV = true,
184 .valid_modes_mask = REGULATOR_MODE_NORMAL
185 | REGULATOR_MODE_STANDBY,
186 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
187 | REGULATOR_CHANGE_MODE
188 | REGULATOR_CHANGE_STATUS,
189 },
190 };
191
192 static struct regulator_init_data omap4_vaux3_idata = {
193 .constraints = {
194 .min_uV = 1000000,
195 .max_uV = 3000000,
196 .apply_uV = true,
197 .valid_modes_mask = REGULATOR_MODE_NORMAL
198 | REGULATOR_MODE_STANDBY,
199 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
200 | REGULATOR_CHANGE_MODE
201 | REGULATOR_CHANGE_STATUS,
202 },
203 };
204
205 static struct regulator_consumer_supply omap4_vmmc_supply[] = {
206 REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
207 };
208
209 /* VMMC1 for MMC1 card */
210 static struct regulator_init_data omap4_vmmc_idata = {
211 .constraints = {
212 .min_uV = 1200000,
213 .max_uV = 3000000,
214 .apply_uV = true,
215 .valid_modes_mask = REGULATOR_MODE_NORMAL
216 | REGULATOR_MODE_STANDBY,
217 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
218 | REGULATOR_CHANGE_MODE
219 | REGULATOR_CHANGE_STATUS,
220 },
221 .num_consumer_supplies = ARRAY_SIZE(omap4_vmmc_supply),
222 .consumer_supplies = omap4_vmmc_supply,
223 };
224
225 static struct regulator_init_data omap4_vpp_idata = {
226 .constraints = {
227 .min_uV = 1800000,
228 .max_uV = 2500000,
229 .apply_uV = true,
230 .valid_modes_mask = REGULATOR_MODE_NORMAL
231 | REGULATOR_MODE_STANDBY,
232 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
233 | REGULATOR_CHANGE_MODE
234 | REGULATOR_CHANGE_STATUS,
235 },
236 };
237
238 static struct regulator_init_data omap4_vana_idata = {
239 .constraints = {
240 .min_uV = 2100000,
241 .max_uV = 2100000,
242 .valid_modes_mask = REGULATOR_MODE_NORMAL
243 | REGULATOR_MODE_STANDBY,
244 .valid_ops_mask = REGULATOR_CHANGE_MODE
245 | REGULATOR_CHANGE_STATUS,
246 },
247 };
248
249 static struct regulator_consumer_supply omap4_vcxio_supply[] = {
250 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dss"),
251 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
252 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.1"),
253 };
254
255 static struct regulator_init_data omap4_vcxio_idata = {
256 .constraints = {
257 .min_uV = 1800000,
258 .max_uV = 1800000,
259 .valid_modes_mask = REGULATOR_MODE_NORMAL
260 | REGULATOR_MODE_STANDBY,
261 .valid_ops_mask = REGULATOR_CHANGE_MODE
262 | REGULATOR_CHANGE_STATUS,
263 .always_on = true,
264 },
265 .num_consumer_supplies = ARRAY_SIZE(omap4_vcxio_supply),
266 .consumer_supplies = omap4_vcxio_supply,
267 };
268
269 static struct regulator_init_data omap4_vusb_idata = {
270 .constraints = {
271 .min_uV = 3300000,
272 .max_uV = 3300000,
273 .valid_modes_mask = REGULATOR_MODE_NORMAL
274 | REGULATOR_MODE_STANDBY,
275 .valid_ops_mask = REGULATOR_CHANGE_MODE
276 | REGULATOR_CHANGE_STATUS,
277 },
278 };
279
280 static struct regulator_init_data omap4_clk32kg_idata = {
281 .constraints = {
282 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
283 },
284 };
285
omap4_pmic_get_config(struct twl4030_platform_data * pmic_data,u32 pdata_flags,u32 regulators_flags)286 void __init omap4_pmic_get_config(struct twl4030_platform_data *pmic_data,
287 u32 pdata_flags, u32 regulators_flags)
288 {
289 if (!pmic_data->irq_base)
290 pmic_data->irq_base = TWL6030_IRQ_BASE;
291 if (!pmic_data->irq_end)
292 pmic_data->irq_end = TWL6030_IRQ_END;
293
294 /* Common platform data configurations */
295 if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
296 pmic_data->usb = &omap4_usb_pdata;
297
298 /* Common regulator configurations */
299 if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
300 pmic_data->vdac = &omap4_vdac_idata;
301
302 if (regulators_flags & TWL_COMMON_REGULATOR_VAUX2 && !pmic_data->vaux2)
303 pmic_data->vaux2 = &omap4_vaux2_idata;
304
305 if (regulators_flags & TWL_COMMON_REGULATOR_VAUX3 && !pmic_data->vaux3)
306 pmic_data->vaux3 = &omap4_vaux3_idata;
307
308 if (regulators_flags & TWL_COMMON_REGULATOR_VMMC && !pmic_data->vmmc)
309 pmic_data->vmmc = &omap4_vmmc_idata;
310
311 if (regulators_flags & TWL_COMMON_REGULATOR_VPP && !pmic_data->vpp)
312 pmic_data->vpp = &omap4_vpp_idata;
313
314 if (regulators_flags & TWL_COMMON_REGULATOR_VANA && !pmic_data->vana)
315 pmic_data->vana = &omap4_vana_idata;
316
317 if (regulators_flags & TWL_COMMON_REGULATOR_VCXIO && !pmic_data->vcxio)
318 pmic_data->vcxio = &omap4_vcxio_idata;
319
320 if (regulators_flags & TWL_COMMON_REGULATOR_VUSB && !pmic_data->vusb)
321 pmic_data->vusb = &omap4_vusb_idata;
322
323 if (regulators_flags & TWL_COMMON_REGULATOR_CLK32KG &&
324 !pmic_data->clk32kg)
325 pmic_data->clk32kg = &omap4_clk32kg_idata;
326 }
327 #endif /* CONFIG_ARCH_OMAP4 */
328