Adding support for MOXA ART SoC. Testing port of linux-2.6.32.60-moxart.
[linux-3.6.7-moxart.git] / arch / arm / mach-omap2 / twl-common.c
blobdb5ff664237517562766ffdbc34887c6416c272f
1 /*
2 * twl-common.c
4 * Copyright (C) 2011 Texas Instruments, Inc..
5 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
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.
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.
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
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>
29 #include <plat/i2c.h>
30 #include <plat/usb.h>
32 #include "twl-common.h"
33 #include "pm.h"
34 #include "voltage.h"
35 #include "mux.h"
37 static struct i2c_board_info __initdata pmic_i2c_board_info = {
38 .addr = 0x48,
39 .flags = I2C_CLIENT_WAKE,
42 static struct i2c_board_info __initdata omap4_i2c1_board_info[] = {
44 .addr = 0x48,
45 .flags = I2C_CLIENT_WAKE,
48 I2C_BOARD_INFO("twl6040", 0x4b),
52 #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
53 static int twl_set_voltage(void *data, int target_uV)
55 struct voltagedomain *voltdm = (struct voltagedomain *)data;
56 return voltdm_scale(voltdm, target_uV);
59 static int twl_get_voltage(void *data)
61 struct voltagedomain *voltdm = (struct voltagedomain *)data;
62 return voltdm_get_voltage(voltdm);
64 #endif
66 void __init omap_pmic_init(int bus, u32 clkrate,
67 const char *pmic_type, int pmic_irq,
68 struct twl4030_platform_data *pmic_data)
70 omap_mux_init_signal("sys_nirq", OMAP_PIN_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE);
71 strncpy(pmic_i2c_board_info.type, pmic_type,
72 sizeof(pmic_i2c_board_info.type));
73 pmic_i2c_board_info.irq = pmic_irq;
74 pmic_i2c_board_info.platform_data = pmic_data;
76 omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
79 void __init omap4_pmic_init(const char *pmic_type,
80 struct twl4030_platform_data *pmic_data,
81 struct twl6040_platform_data *twl6040_data, int twl6040_irq)
83 /* PMIC part*/
84 omap_mux_init_signal("sys_nirq1", OMAP_PIN_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE);
85 strncpy(omap4_i2c1_board_info[0].type, pmic_type,
86 sizeof(omap4_i2c1_board_info[0].type));
87 omap4_i2c1_board_info[0].irq = OMAP44XX_IRQ_SYS_1N;
88 omap4_i2c1_board_info[0].platform_data = pmic_data;
90 /* TWL6040 audio IC part */
91 omap4_i2c1_board_info[1].irq = twl6040_irq;
92 omap4_i2c1_board_info[1].platform_data = twl6040_data;
94 omap_register_i2c_bus(1, 400, omap4_i2c1_board_info, 2);
98 void __init omap_pmic_late_init(void)
100 /* Init the OMAP TWL parameters (if PMIC has been registered) */
101 if (pmic_i2c_board_info.irq)
102 omap3_twl_init();
103 if (omap4_i2c1_board_info[0].irq)
104 omap4_twl_init();
107 #if defined(CONFIG_ARCH_OMAP3)
108 static struct twl4030_usb_data omap3_usb_pdata = {
109 .usb_mode = T2_USB_MODE_ULPI,
112 static int omap3_batt_table[] = {
113 /* 0 C */
114 30800, 29500, 28300, 27100,
115 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
116 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
117 11600, 11200, 10800, 10400, 10000, 9630, 9280, 8950, 8620, 8310,
118 8020, 7730, 7460, 7200, 6950, 6710, 6470, 6250, 6040, 5830,
119 5640, 5450, 5260, 5090, 4920, 4760, 4600, 4450, 4310, 4170,
120 4040, 3910, 3790, 3670, 3550
123 static struct twl4030_bci_platform_data omap3_bci_pdata = {
124 .battery_tmp_tbl = omap3_batt_table,
125 .tblsize = ARRAY_SIZE(omap3_batt_table),
128 static struct twl4030_madc_platform_data omap3_madc_pdata = {
129 .irq_line = 1,
132 static struct twl4030_codec_data omap3_codec;
134 static struct twl4030_audio_data omap3_audio_pdata = {
135 .audio_mclk = 26000000,
136 .codec = &omap3_codec,
139 static struct regulator_consumer_supply omap3_vdda_dac_supplies[] = {
140 REGULATOR_SUPPLY("vdda_dac", "omapdss_venc"),
143 static struct regulator_init_data omap3_vdac_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,
152 .num_consumer_supplies = ARRAY_SIZE(omap3_vdda_dac_supplies),
153 .consumer_supplies = omap3_vdda_dac_supplies,
156 static struct regulator_consumer_supply omap3_vpll2_supplies[] = {
157 REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
158 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
161 static struct regulator_init_data omap3_vpll2_idata = {
162 .constraints = {
163 .min_uV = 1800000,
164 .max_uV = 1800000,
165 .valid_modes_mask = REGULATOR_MODE_NORMAL
166 | REGULATOR_MODE_STANDBY,
167 .valid_ops_mask = REGULATOR_CHANGE_MODE
168 | REGULATOR_CHANGE_STATUS,
170 .num_consumer_supplies = ARRAY_SIZE(omap3_vpll2_supplies),
171 .consumer_supplies = omap3_vpll2_supplies,
174 static struct regulator_consumer_supply omap3_vdd1_supply[] = {
175 REGULATOR_SUPPLY("vcc", "mpu.0"),
178 static struct regulator_consumer_supply omap3_vdd2_supply[] = {
179 REGULATOR_SUPPLY("vcc", "l3_main.0"),
182 static struct regulator_init_data omap3_vdd1 = {
183 .constraints = {
184 .name = "vdd_mpu_iva",
185 .min_uV = 600000,
186 .max_uV = 1450000,
187 .valid_modes_mask = REGULATOR_MODE_NORMAL,
188 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
190 .num_consumer_supplies = ARRAY_SIZE(omap3_vdd1_supply),
191 .consumer_supplies = omap3_vdd1_supply,
194 static struct regulator_init_data omap3_vdd2 = {
195 .constraints = {
196 .name = "vdd_core",
197 .min_uV = 600000,
198 .max_uV = 1450000,
199 .valid_modes_mask = REGULATOR_MODE_NORMAL,
200 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
202 .num_consumer_supplies = ARRAY_SIZE(omap3_vdd2_supply),
203 .consumer_supplies = omap3_vdd2_supply,
206 static struct twl_regulator_driver_data omap3_vdd1_drvdata = {
207 .get_voltage = twl_get_voltage,
208 .set_voltage = twl_set_voltage,
211 static struct twl_regulator_driver_data omap3_vdd2_drvdata = {
212 .get_voltage = twl_get_voltage,
213 .set_voltage = twl_set_voltage,
216 void __init omap3_pmic_get_config(struct twl4030_platform_data *pmic_data,
217 u32 pdata_flags, u32 regulators_flags)
219 if (!pmic_data->vdd1) {
220 omap3_vdd1.driver_data = &omap3_vdd1_drvdata;
221 omap3_vdd1_drvdata.data = voltdm_lookup("mpu_iva");
222 pmic_data->vdd1 = &omap3_vdd1;
224 if (!pmic_data->vdd2) {
225 omap3_vdd2.driver_data = &omap3_vdd2_drvdata;
226 omap3_vdd2_drvdata.data = voltdm_lookup("core");
227 pmic_data->vdd2 = &omap3_vdd2;
230 /* Common platform data configurations */
231 if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
232 pmic_data->usb = &omap3_usb_pdata;
234 if (pdata_flags & TWL_COMMON_PDATA_BCI && !pmic_data->bci)
235 pmic_data->bci = &omap3_bci_pdata;
237 if (pdata_flags & TWL_COMMON_PDATA_MADC && !pmic_data->madc)
238 pmic_data->madc = &omap3_madc_pdata;
240 if (pdata_flags & TWL_COMMON_PDATA_AUDIO && !pmic_data->audio)
241 pmic_data->audio = &omap3_audio_pdata;
243 /* Common regulator configurations */
244 if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
245 pmic_data->vdac = &omap3_vdac_idata;
247 if (regulators_flags & TWL_COMMON_REGULATOR_VPLL2 && !pmic_data->vpll2)
248 pmic_data->vpll2 = &omap3_vpll2_idata;
250 #endif /* CONFIG_ARCH_OMAP3 */
252 #if defined(CONFIG_ARCH_OMAP4)
253 static struct twl4030_usb_data omap4_usb_pdata = {
254 .phy_init = omap4430_phy_init,
255 .phy_exit = omap4430_phy_exit,
256 .phy_power = omap4430_phy_power,
257 .phy_set_clock = omap4430_phy_set_clk,
258 .phy_suspend = omap4430_phy_suspend,
261 static struct regulator_init_data omap4_vdac_idata = {
262 .constraints = {
263 .min_uV = 1800000,
264 .max_uV = 1800000,
265 .valid_modes_mask = REGULATOR_MODE_NORMAL
266 | REGULATOR_MODE_STANDBY,
267 .valid_ops_mask = REGULATOR_CHANGE_MODE
268 | REGULATOR_CHANGE_STATUS,
270 .supply_regulator = "V2V1",
273 static struct regulator_init_data omap4_vaux2_idata = {
274 .constraints = {
275 .min_uV = 1200000,
276 .max_uV = 2800000,
277 .apply_uV = true,
278 .valid_modes_mask = REGULATOR_MODE_NORMAL
279 | REGULATOR_MODE_STANDBY,
280 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
281 | REGULATOR_CHANGE_MODE
282 | REGULATOR_CHANGE_STATUS,
286 static struct regulator_init_data omap4_vaux3_idata = {
287 .constraints = {
288 .min_uV = 1000000,
289 .max_uV = 3000000,
290 .apply_uV = true,
291 .valid_modes_mask = REGULATOR_MODE_NORMAL
292 | REGULATOR_MODE_STANDBY,
293 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
294 | REGULATOR_CHANGE_MODE
295 | REGULATOR_CHANGE_STATUS,
299 static struct regulator_consumer_supply omap4_vmmc_supply[] = {
300 REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
303 /* VMMC1 for MMC1 card */
304 static struct regulator_init_data omap4_vmmc_idata = {
305 .constraints = {
306 .min_uV = 1200000,
307 .max_uV = 3000000,
308 .apply_uV = true,
309 .valid_modes_mask = REGULATOR_MODE_NORMAL
310 | REGULATOR_MODE_STANDBY,
311 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
312 | REGULATOR_CHANGE_MODE
313 | REGULATOR_CHANGE_STATUS,
315 .num_consumer_supplies = ARRAY_SIZE(omap4_vmmc_supply),
316 .consumer_supplies = omap4_vmmc_supply,
319 static struct regulator_init_data omap4_vpp_idata = {
320 .constraints = {
321 .min_uV = 1800000,
322 .max_uV = 2500000,
323 .apply_uV = true,
324 .valid_modes_mask = REGULATOR_MODE_NORMAL
325 | REGULATOR_MODE_STANDBY,
326 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
327 | REGULATOR_CHANGE_MODE
328 | REGULATOR_CHANGE_STATUS,
332 static struct regulator_init_data omap4_vana_idata = {
333 .constraints = {
334 .min_uV = 2100000,
335 .max_uV = 2100000,
336 .valid_modes_mask = REGULATOR_MODE_NORMAL
337 | REGULATOR_MODE_STANDBY,
338 .valid_ops_mask = REGULATOR_CHANGE_MODE
339 | REGULATOR_CHANGE_STATUS,
343 static struct regulator_consumer_supply omap4_vcxio_supply[] = {
344 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dss"),
345 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
346 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.1"),
349 static struct regulator_init_data omap4_vcxio_idata = {
350 .constraints = {
351 .min_uV = 1800000,
352 .max_uV = 1800000,
353 .valid_modes_mask = REGULATOR_MODE_NORMAL
354 | REGULATOR_MODE_STANDBY,
355 .valid_ops_mask = REGULATOR_CHANGE_MODE
356 | REGULATOR_CHANGE_STATUS,
357 .always_on = true,
359 .num_consumer_supplies = ARRAY_SIZE(omap4_vcxio_supply),
360 .consumer_supplies = omap4_vcxio_supply,
361 .supply_regulator = "V2V1",
364 static struct regulator_init_data omap4_vusb_idata = {
365 .constraints = {
366 .min_uV = 3300000,
367 .max_uV = 3300000,
368 .valid_modes_mask = REGULATOR_MODE_NORMAL
369 | REGULATOR_MODE_STANDBY,
370 .valid_ops_mask = REGULATOR_CHANGE_MODE
371 | REGULATOR_CHANGE_STATUS,
375 static struct regulator_init_data omap4_clk32kg_idata = {
376 .constraints = {
377 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
381 static struct regulator_consumer_supply omap4_vdd1_supply[] = {
382 REGULATOR_SUPPLY("vcc", "mpu.0"),
385 static struct regulator_consumer_supply omap4_vdd2_supply[] = {
386 REGULATOR_SUPPLY("vcc", "iva.0"),
389 static struct regulator_consumer_supply omap4_vdd3_supply[] = {
390 REGULATOR_SUPPLY("vcc", "l3_main.0"),
393 static struct regulator_init_data omap4_vdd1 = {
394 .constraints = {
395 .name = "vdd_mpu",
396 .min_uV = 500000,
397 .max_uV = 1500000,
398 .valid_modes_mask = REGULATOR_MODE_NORMAL,
399 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
401 .num_consumer_supplies = ARRAY_SIZE(omap4_vdd1_supply),
402 .consumer_supplies = omap4_vdd1_supply,
405 static struct regulator_init_data omap4_vdd2 = {
406 .constraints = {
407 .name = "vdd_iva",
408 .min_uV = 500000,
409 .max_uV = 1500000,
410 .valid_modes_mask = REGULATOR_MODE_NORMAL,
411 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
413 .num_consumer_supplies = ARRAY_SIZE(omap4_vdd2_supply),
414 .consumer_supplies = omap4_vdd2_supply,
417 static struct regulator_init_data omap4_vdd3 = {
418 .constraints = {
419 .name = "vdd_core",
420 .min_uV = 500000,
421 .max_uV = 1500000,
422 .valid_modes_mask = REGULATOR_MODE_NORMAL,
423 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
425 .num_consumer_supplies = ARRAY_SIZE(omap4_vdd3_supply),
426 .consumer_supplies = omap4_vdd3_supply,
430 static struct twl_regulator_driver_data omap4_vdd1_drvdata = {
431 .get_voltage = twl_get_voltage,
432 .set_voltage = twl_set_voltage,
435 static struct twl_regulator_driver_data omap4_vdd2_drvdata = {
436 .get_voltage = twl_get_voltage,
437 .set_voltage = twl_set_voltage,
440 static struct twl_regulator_driver_data omap4_vdd3_drvdata = {
441 .get_voltage = twl_get_voltage,
442 .set_voltage = twl_set_voltage,
445 static struct regulator_consumer_supply omap4_v1v8_supply[] = {
446 REGULATOR_SUPPLY("vio", "1-004b"),
449 static struct regulator_init_data omap4_v1v8_idata = {
450 .constraints = {
451 .min_uV = 1800000,
452 .max_uV = 1800000,
453 .valid_modes_mask = REGULATOR_MODE_NORMAL
454 | REGULATOR_MODE_STANDBY,
455 .valid_ops_mask = REGULATOR_CHANGE_MODE
456 | REGULATOR_CHANGE_STATUS,
457 .always_on = true,
459 .num_consumer_supplies = ARRAY_SIZE(omap4_v1v8_supply),
460 .consumer_supplies = omap4_v1v8_supply,
463 static struct regulator_consumer_supply omap4_v2v1_supply[] = {
464 REGULATOR_SUPPLY("v2v1", "1-004b"),
467 static struct regulator_init_data omap4_v2v1_idata = {
468 .constraints = {
469 .min_uV = 2100000,
470 .max_uV = 2100000,
471 .valid_modes_mask = REGULATOR_MODE_NORMAL
472 | REGULATOR_MODE_STANDBY,
473 .valid_ops_mask = REGULATOR_CHANGE_MODE
474 | REGULATOR_CHANGE_STATUS,
476 .num_consumer_supplies = ARRAY_SIZE(omap4_v2v1_supply),
477 .consumer_supplies = omap4_v2v1_supply,
480 void __init omap4_pmic_get_config(struct twl4030_platform_data *pmic_data,
481 u32 pdata_flags, u32 regulators_flags)
483 if (!pmic_data->vdd1) {
484 omap4_vdd1.driver_data = &omap4_vdd1_drvdata;
485 omap4_vdd1_drvdata.data = voltdm_lookup("mpu");
486 pmic_data->vdd1 = &omap4_vdd1;
489 if (!pmic_data->vdd2) {
490 omap4_vdd2.driver_data = &omap4_vdd2_drvdata;
491 omap4_vdd2_drvdata.data = voltdm_lookup("iva");
492 pmic_data->vdd2 = &omap4_vdd2;
495 if (!pmic_data->vdd3) {
496 omap4_vdd3.driver_data = &omap4_vdd3_drvdata;
497 omap4_vdd3_drvdata.data = voltdm_lookup("core");
498 pmic_data->vdd3 = &omap4_vdd3;
501 /* Common platform data configurations */
502 if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
503 pmic_data->usb = &omap4_usb_pdata;
505 /* Common regulator configurations */
506 if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
507 pmic_data->vdac = &omap4_vdac_idata;
509 if (regulators_flags & TWL_COMMON_REGULATOR_VAUX2 && !pmic_data->vaux2)
510 pmic_data->vaux2 = &omap4_vaux2_idata;
512 if (regulators_flags & TWL_COMMON_REGULATOR_VAUX3 && !pmic_data->vaux3)
513 pmic_data->vaux3 = &omap4_vaux3_idata;
515 if (regulators_flags & TWL_COMMON_REGULATOR_VMMC && !pmic_data->vmmc)
516 pmic_data->vmmc = &omap4_vmmc_idata;
518 if (regulators_flags & TWL_COMMON_REGULATOR_VPP && !pmic_data->vpp)
519 pmic_data->vpp = &omap4_vpp_idata;
521 if (regulators_flags & TWL_COMMON_REGULATOR_VANA && !pmic_data->vana)
522 pmic_data->vana = &omap4_vana_idata;
524 if (regulators_flags & TWL_COMMON_REGULATOR_VCXIO && !pmic_data->vcxio)
525 pmic_data->vcxio = &omap4_vcxio_idata;
527 if (regulators_flags & TWL_COMMON_REGULATOR_VUSB && !pmic_data->vusb)
528 pmic_data->vusb = &omap4_vusb_idata;
530 if (regulators_flags & TWL_COMMON_REGULATOR_CLK32KG &&
531 !pmic_data->clk32kg)
532 pmic_data->clk32kg = &omap4_clk32kg_idata;
534 if (regulators_flags & TWL_COMMON_REGULATOR_V1V8 && !pmic_data->v1v8)
535 pmic_data->v1v8 = &omap4_v1v8_idata;
537 if (regulators_flags & TWL_COMMON_REGULATOR_V2V1 && !pmic_data->v2v1)
538 pmic_data->v2v1 = &omap4_v2v1_idata;
540 #endif /* CONFIG_ARCH_OMAP4 */