Linux 3.4-rc5
[linux-2.6-block.git] / arch / arm / mach-omap2 / twl-common.c
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
40 static struct i2c_board_info __initdata omap4_i2c1_board_info[] = {
41         {
42                 .addr           = 0x48,
43                 .flags          = I2C_CLIENT_WAKE,
44         },
45         {
46                 I2C_BOARD_INFO("twl6040", 0x4b),
47         },
48 };
49
50 void __init omap_pmic_init(int bus, u32 clkrate,
51                            const char *pmic_type, int pmic_irq,
52                            struct twl4030_platform_data *pmic_data)
53 {
54         strncpy(pmic_i2c_board_info.type, pmic_type,
55                 sizeof(pmic_i2c_board_info.type));
56         pmic_i2c_board_info.irq = pmic_irq;
57         pmic_i2c_board_info.platform_data = pmic_data;
58
59         omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
60 }
61
62 void __init omap4_pmic_init(const char *pmic_type,
63                     struct twl4030_platform_data *pmic_data,
64                     struct twl6040_platform_data *twl6040_data, int twl6040_irq)
65 {
66         /* PMIC part*/
67         strncpy(omap4_i2c1_board_info[0].type, pmic_type,
68                 sizeof(omap4_i2c1_board_info[0].type));
69         omap4_i2c1_board_info[0].irq = OMAP44XX_IRQ_SYS_1N;
70         omap4_i2c1_board_info[0].platform_data = pmic_data;
71
72         /* TWL6040 audio IC part */
73         omap4_i2c1_board_info[1].irq = twl6040_irq;
74         omap4_i2c1_board_info[1].platform_data = twl6040_data;
75
76         omap_register_i2c_bus(1, 400, omap4_i2c1_board_info, 2);
77
78 }
79
80 void __init omap_pmic_late_init(void)
81 {
82         /* Init the OMAP TWL parameters (if PMIC has been registerd) */
83         if (pmic_i2c_board_info.irq)
84                 omap3_twl_init();
85         if (omap4_i2c1_board_info[0].irq)
86                 omap4_twl_init();
87 }
88
89 #if defined(CONFIG_ARCH_OMAP3)
90 static struct twl4030_usb_data omap3_usb_pdata = {
91         .usb_mode       = T2_USB_MODE_ULPI,
92 };
93
94 static int omap3_batt_table[] = {
95 /* 0 C */
96 30800, 29500, 28300, 27100,
97 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
98 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
99 11600, 11200, 10800, 10400, 10000, 9630,  9280,  8950,  8620,  8310,
100 8020,  7730,  7460,  7200,  6950,  6710,  6470,  6250,  6040,  5830,
101 5640,  5450,  5260,  5090,  4920,  4760,  4600,  4450,  4310,  4170,
102 4040,  3910,  3790,  3670,  3550
103 };
104
105 static struct twl4030_bci_platform_data omap3_bci_pdata = {
106         .battery_tmp_tbl        = omap3_batt_table,
107         .tblsize                = ARRAY_SIZE(omap3_batt_table),
108 };
109
110 static struct twl4030_madc_platform_data omap3_madc_pdata = {
111         .irq_line       = 1,
112 };
113
114 static struct twl4030_codec_data omap3_codec;
115
116 static struct twl4030_audio_data omap3_audio_pdata = {
117         .audio_mclk = 26000000,
118         .codec = &omap3_codec,
119 };
120
121 static struct regulator_consumer_supply omap3_vdda_dac_supplies[] = {
122         REGULATOR_SUPPLY("vdda_dac", "omapdss_venc"),
123 };
124
125 static struct regulator_init_data omap3_vdac_idata = {
126         .constraints = {
127                 .min_uV                 = 1800000,
128                 .max_uV                 = 1800000,
129                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
130                                         | REGULATOR_MODE_STANDBY,
131                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
132                                         | REGULATOR_CHANGE_STATUS,
133         },
134         .num_consumer_supplies  = ARRAY_SIZE(omap3_vdda_dac_supplies),
135         .consumer_supplies      = omap3_vdda_dac_supplies,
136 };
137
138 static struct regulator_consumer_supply omap3_vpll2_supplies[] = {
139         REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
140         REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
141 };
142
143 static struct regulator_init_data omap3_vpll2_idata = {
144         .constraints = {
145                 .min_uV                 = 1800000,
146                 .max_uV                 = 1800000,
147                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
148                                         | REGULATOR_MODE_STANDBY,
149                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
150                                         | REGULATOR_CHANGE_STATUS,
151         },
152         .num_consumer_supplies          = ARRAY_SIZE(omap3_vpll2_supplies),
153         .consumer_supplies              = omap3_vpll2_supplies,
154 };
155
156 void __init omap3_pmic_get_config(struct twl4030_platform_data *pmic_data,
157                                   u32 pdata_flags, u32 regulators_flags)
158 {
159         if (!pmic_data->irq_base)
160                 pmic_data->irq_base = TWL4030_IRQ_BASE;
161         if (!pmic_data->irq_end)
162                 pmic_data->irq_end = TWL4030_IRQ_END;
163
164         /* Common platform data configurations */
165         if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
166                 pmic_data->usb = &omap3_usb_pdata;
167
168         if (pdata_flags & TWL_COMMON_PDATA_BCI && !pmic_data->bci)
169                 pmic_data->bci = &omap3_bci_pdata;
170
171         if (pdata_flags & TWL_COMMON_PDATA_MADC && !pmic_data->madc)
172                 pmic_data->madc = &omap3_madc_pdata;
173
174         if (pdata_flags & TWL_COMMON_PDATA_AUDIO && !pmic_data->audio)
175                 pmic_data->audio = &omap3_audio_pdata;
176
177         /* Common regulator configurations */
178         if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
179                 pmic_data->vdac = &omap3_vdac_idata;
180
181         if (regulators_flags & TWL_COMMON_REGULATOR_VPLL2 && !pmic_data->vpll2)
182                 pmic_data->vpll2 = &omap3_vpll2_idata;
183 }
184 #endif /* CONFIG_ARCH_OMAP3 */
185
186 #if defined(CONFIG_ARCH_OMAP4)
187 static struct twl4030_usb_data omap4_usb_pdata = {
188         .phy_init       = omap4430_phy_init,
189         .phy_exit       = omap4430_phy_exit,
190         .phy_power      = omap4430_phy_power,
191         .phy_set_clock  = omap4430_phy_set_clk,
192         .phy_suspend    = omap4430_phy_suspend,
193 };
194
195 static struct regulator_init_data omap4_vdac_idata = {
196         .constraints = {
197                 .min_uV                 = 1800000,
198                 .max_uV                 = 1800000,
199                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
200                                         | REGULATOR_MODE_STANDBY,
201                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
202                                         | REGULATOR_CHANGE_STATUS,
203         },
204 };
205
206 static struct regulator_init_data omap4_vaux2_idata = {
207         .constraints = {
208                 .min_uV                 = 1200000,
209                 .max_uV                 = 2800000,
210                 .apply_uV               = true,
211                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
212                                         | REGULATOR_MODE_STANDBY,
213                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
214                                         | REGULATOR_CHANGE_MODE
215                                         | REGULATOR_CHANGE_STATUS,
216         },
217 };
218
219 static struct regulator_init_data omap4_vaux3_idata = {
220         .constraints = {
221                 .min_uV                 = 1000000,
222                 .max_uV                 = 3000000,
223                 .apply_uV               = true,
224                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
225                                         | REGULATOR_MODE_STANDBY,
226                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
227                                         | REGULATOR_CHANGE_MODE
228                                         | REGULATOR_CHANGE_STATUS,
229         },
230 };
231
232 static struct regulator_consumer_supply omap4_vmmc_supply[] = {
233         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
234 };
235
236 /* VMMC1 for MMC1 card */
237 static struct regulator_init_data omap4_vmmc_idata = {
238         .constraints = {
239                 .min_uV                 = 1200000,
240                 .max_uV                 = 3000000,
241                 .apply_uV               = true,
242                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
243                                         | REGULATOR_MODE_STANDBY,
244                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
245                                         | REGULATOR_CHANGE_MODE
246                                         | REGULATOR_CHANGE_STATUS,
247         },
248         .num_consumer_supplies  = ARRAY_SIZE(omap4_vmmc_supply),
249         .consumer_supplies      = omap4_vmmc_supply,
250 };
251
252 static struct regulator_init_data omap4_vpp_idata = {
253         .constraints = {
254                 .min_uV                 = 1800000,
255                 .max_uV                 = 2500000,
256                 .apply_uV               = true,
257                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
258                                         | REGULATOR_MODE_STANDBY,
259                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
260                                         | REGULATOR_CHANGE_MODE
261                                         | REGULATOR_CHANGE_STATUS,
262         },
263 };
264
265 static struct regulator_init_data omap4_vana_idata = {
266         .constraints = {
267                 .min_uV                 = 2100000,
268                 .max_uV                 = 2100000,
269                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
270                                         | REGULATOR_MODE_STANDBY,
271                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
272                                         | REGULATOR_CHANGE_STATUS,
273         },
274 };
275
276 static struct regulator_consumer_supply omap4_vcxio_supply[] = {
277         REGULATOR_SUPPLY("vdds_dsi", "omapdss_dss"),
278         REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
279         REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.1"),
280 };
281
282 static struct regulator_init_data omap4_vcxio_idata = {
283         .constraints = {
284                 .min_uV                 = 1800000,
285                 .max_uV                 = 1800000,
286                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
287                                         | REGULATOR_MODE_STANDBY,
288                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
289                                         | REGULATOR_CHANGE_STATUS,
290                 .always_on              = true,
291         },
292         .num_consumer_supplies  = ARRAY_SIZE(omap4_vcxio_supply),
293         .consumer_supplies      = omap4_vcxio_supply,
294 };
295
296 static struct regulator_init_data omap4_vusb_idata = {
297         .constraints = {
298                 .min_uV                 = 3300000,
299                 .max_uV                 = 3300000,
300                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
301                                         | REGULATOR_MODE_STANDBY,
302                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
303                                         | REGULATOR_CHANGE_STATUS,
304         },
305 };
306
307 static struct regulator_init_data omap4_clk32kg_idata = {
308         .constraints = {
309                 .valid_ops_mask         = REGULATOR_CHANGE_STATUS,
310         },
311 };
312
313 void __init omap4_pmic_get_config(struct twl4030_platform_data *pmic_data,
314                                   u32 pdata_flags, u32 regulators_flags)
315 {
316         if (!pmic_data->irq_base)
317                 pmic_data->irq_base = TWL6030_IRQ_BASE;
318         if (!pmic_data->irq_end)
319                 pmic_data->irq_end = TWL6030_IRQ_END;
320
321         /* Common platform data configurations */
322         if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
323                 pmic_data->usb = &omap4_usb_pdata;
324
325         /* Common regulator configurations */
326         if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
327                 pmic_data->vdac = &omap4_vdac_idata;
328
329         if (regulators_flags & TWL_COMMON_REGULATOR_VAUX2 && !pmic_data->vaux2)
330                 pmic_data->vaux2 = &omap4_vaux2_idata;
331
332         if (regulators_flags & TWL_COMMON_REGULATOR_VAUX3 && !pmic_data->vaux3)
333                 pmic_data->vaux3 = &omap4_vaux3_idata;
334
335         if (regulators_flags & TWL_COMMON_REGULATOR_VMMC && !pmic_data->vmmc)
336                 pmic_data->vmmc = &omap4_vmmc_idata;
337
338         if (regulators_flags & TWL_COMMON_REGULATOR_VPP && !pmic_data->vpp)
339                 pmic_data->vpp = &omap4_vpp_idata;
340
341         if (regulators_flags & TWL_COMMON_REGULATOR_VANA && !pmic_data->vana)
342                 pmic_data->vana = &omap4_vana_idata;
343
344         if (regulators_flags & TWL_COMMON_REGULATOR_VCXIO && !pmic_data->vcxio)
345                 pmic_data->vcxio = &omap4_vcxio_idata;
346
347         if (regulators_flags & TWL_COMMON_REGULATOR_VUSB && !pmic_data->vusb)
348                 pmic_data->vusb = &omap4_vusb_idata;
349
350         if (regulators_flags & TWL_COMMON_REGULATOR_CLK32KG &&
351             !pmic_data->clk32kg)
352                 pmic_data->clk32kg = &omap4_clk32kg_idata;
353 }
354 #endif /* CONFIG_ARCH_OMAP4 */