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
23 #include <linux/i2c.h>
24 #include <linux/i2c/twl.h>
25 #include <linux/gpio.h>
26 #include <linux/string.h>
27 #include <linux/phy/phy.h>
28 #include <linux/regulator/machine.h>
29 #include <linux/regulator/fixed.h>
32 #include "twl-common.h"
37 static struct i2c_board_info __initdata pmic_i2c_board_info = {
39 .flags = I2C_CLIENT_WAKE,
42 #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
43 static int twl_set_voltage(void *data, int target_uV)
45 struct voltagedomain *voltdm = (struct voltagedomain *)data;
46 return voltdm_scale(voltdm, target_uV);
49 static int twl_get_voltage(void *data)
51 struct voltagedomain *voltdm = (struct voltagedomain *)data;
52 return voltdm_get_voltage(voltdm);
56 void __init omap_pmic_init(int bus, u32 clkrate,
57 const char *pmic_type, int pmic_irq,
58 struct twl4030_platform_data *pmic_data)
60 omap_mux_init_signal("sys_nirq", OMAP_PIN_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE);
61 strlcpy(pmic_i2c_board_info.type, pmic_type,
62 sizeof(pmic_i2c_board_info.type));
63 pmic_i2c_board_info.irq = pmic_irq;
64 pmic_i2c_board_info.platform_data = pmic_data;
66 omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
69 void __init omap4_pmic_init(const char *pmic_type,
70 struct twl4030_platform_data *pmic_data,
71 struct i2c_board_info *devices, int nr_devices)
74 omap_mux_init_signal("sys_nirq1", OMAP_PIN_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE);
75 omap_mux_init_signal("fref_clk0_out.sys_drm_msecure", OMAP_PIN_OUTPUT);
76 omap_pmic_init(1, 400, pmic_type, 7 + OMAP44XX_IRQ_GIC_START, pmic_data);
78 /* Register additional devices on i2c1 bus if needed */
80 i2c_register_board_info(1, devices, nr_devices);
83 void __init omap_pmic_late_init(void)
85 /* Init the OMAP TWL parameters (if PMIC has been registerd) */
86 if (!pmic_i2c_board_info.irq)
93 #if defined(CONFIG_ARCH_OMAP3)
94 static struct twl4030_usb_data omap3_usb_pdata = {
95 .usb_mode = T2_USB_MODE_ULPI,
98 static int omap3_batt_table[] = {
100 30800, 29500, 28300, 27100,
101 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
102 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
103 11600, 11200, 10800, 10400, 10000, 9630, 9280, 8950, 8620, 8310,
104 8020, 7730, 7460, 7200, 6950, 6710, 6470, 6250, 6040, 5830,
105 5640, 5450, 5260, 5090, 4920, 4760, 4600, 4450, 4310, 4170,
106 4040, 3910, 3790, 3670, 3550
109 static struct twl4030_bci_platform_data omap3_bci_pdata = {
110 .battery_tmp_tbl = omap3_batt_table,
111 .tblsize = ARRAY_SIZE(omap3_batt_table),
114 static struct twl4030_madc_platform_data omap3_madc_pdata = {
118 static struct twl4030_codec_data omap3_codec;
120 static struct twl4030_audio_data omap3_audio_pdata = {
121 .audio_mclk = 26000000,
122 .codec = &omap3_codec,
125 static struct regulator_consumer_supply omap3_vdda_dac_supplies[] = {
126 REGULATOR_SUPPLY("vdda_dac", "omapdss_venc"),
129 static struct regulator_init_data omap3_vdac_idata = {
133 .valid_modes_mask = REGULATOR_MODE_NORMAL
134 | REGULATOR_MODE_STANDBY,
135 .valid_ops_mask = REGULATOR_CHANGE_MODE
136 | REGULATOR_CHANGE_STATUS,
138 .num_consumer_supplies = ARRAY_SIZE(omap3_vdda_dac_supplies),
139 .consumer_supplies = omap3_vdda_dac_supplies,
142 static struct regulator_consumer_supply omap3_vpll2_supplies[] = {
143 REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
144 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dpi.0"),
145 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
148 static struct regulator_init_data omap3_vpll2_idata = {
152 .valid_modes_mask = REGULATOR_MODE_NORMAL
153 | REGULATOR_MODE_STANDBY,
154 .valid_ops_mask = REGULATOR_CHANGE_MODE
155 | REGULATOR_CHANGE_STATUS,
157 .num_consumer_supplies = ARRAY_SIZE(omap3_vpll2_supplies),
158 .consumer_supplies = omap3_vpll2_supplies,
161 static struct regulator_consumer_supply omap3_vdd1_supply[] = {
162 REGULATOR_SUPPLY("vcc", "cpu0"),
165 static struct regulator_consumer_supply omap3_vdd2_supply[] = {
166 REGULATOR_SUPPLY("vcc", "l3_main.0"),
169 static struct regulator_init_data omap3_vdd1 = {
171 .name = "vdd_mpu_iva",
174 .valid_modes_mask = REGULATOR_MODE_NORMAL,
175 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
177 .num_consumer_supplies = ARRAY_SIZE(omap3_vdd1_supply),
178 .consumer_supplies = omap3_vdd1_supply,
181 static struct regulator_init_data omap3_vdd2 = {
186 .valid_modes_mask = REGULATOR_MODE_NORMAL,
187 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
189 .num_consumer_supplies = ARRAY_SIZE(omap3_vdd2_supply),
190 .consumer_supplies = omap3_vdd2_supply,
193 static struct twl_regulator_driver_data omap3_vdd1_drvdata = {
194 .get_voltage = twl_get_voltage,
195 .set_voltage = twl_set_voltage,
198 static struct twl_regulator_driver_data omap3_vdd2_drvdata = {
199 .get_voltage = twl_get_voltage,
200 .set_voltage = twl_set_voltage,
203 void __init omap3_pmic_get_config(struct twl4030_platform_data *pmic_data,
204 u32 pdata_flags, u32 regulators_flags)
206 if (!pmic_data->vdd1) {
207 omap3_vdd1.driver_data = &omap3_vdd1_drvdata;
208 omap3_vdd1_drvdata.data = voltdm_lookup("mpu_iva");
209 pmic_data->vdd1 = &omap3_vdd1;
211 if (!pmic_data->vdd2) {
212 omap3_vdd2.driver_data = &omap3_vdd2_drvdata;
213 omap3_vdd2_drvdata.data = voltdm_lookup("core");
214 pmic_data->vdd2 = &omap3_vdd2;
217 /* Common platform data configurations */
218 if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
219 pmic_data->usb = &omap3_usb_pdata;
221 if (pdata_flags & TWL_COMMON_PDATA_BCI && !pmic_data->bci)
222 pmic_data->bci = &omap3_bci_pdata;
224 if (pdata_flags & TWL_COMMON_PDATA_MADC && !pmic_data->madc)
225 pmic_data->madc = &omap3_madc_pdata;
227 if (pdata_flags & TWL_COMMON_PDATA_AUDIO && !pmic_data->audio)
228 pmic_data->audio = &omap3_audio_pdata;
230 /* Common regulator configurations */
231 if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
232 pmic_data->vdac = &omap3_vdac_idata;
234 if (regulators_flags & TWL_COMMON_REGULATOR_VPLL2 && !pmic_data->vpll2)
235 pmic_data->vpll2 = &omap3_vpll2_idata;
237 #endif /* CONFIG_ARCH_OMAP3 */
239 #if defined(CONFIG_ARCH_OMAP4)
240 static struct twl4030_usb_data omap4_usb_pdata = {
243 static struct regulator_consumer_supply omap4_vdda_hdmi_dac_supplies[] = {
244 REGULATOR_SUPPLY("vdda_hdmi_dac", "omapdss_hdmi"),
247 static struct regulator_init_data omap4_vdac_idata = {
251 .valid_modes_mask = REGULATOR_MODE_NORMAL
252 | REGULATOR_MODE_STANDBY,
253 .valid_ops_mask = REGULATOR_CHANGE_MODE
254 | REGULATOR_CHANGE_STATUS,
256 .num_consumer_supplies = ARRAY_SIZE(omap4_vdda_hdmi_dac_supplies),
257 .consumer_supplies = omap4_vdda_hdmi_dac_supplies,
258 .supply_regulator = "V2V1",
261 static struct regulator_init_data omap4_vaux2_idata = {
266 .valid_modes_mask = REGULATOR_MODE_NORMAL
267 | REGULATOR_MODE_STANDBY,
268 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
269 | REGULATOR_CHANGE_MODE
270 | REGULATOR_CHANGE_STATUS,
274 static struct regulator_init_data omap4_vaux3_idata = {
279 .valid_modes_mask = REGULATOR_MODE_NORMAL
280 | REGULATOR_MODE_STANDBY,
281 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
282 | REGULATOR_CHANGE_MODE
283 | REGULATOR_CHANGE_STATUS,
287 static struct regulator_consumer_supply omap4_vmmc_supply[] = {
288 REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
291 /* VMMC1 for MMC1 card */
292 static struct regulator_init_data omap4_vmmc_idata = {
297 .valid_modes_mask = REGULATOR_MODE_NORMAL
298 | REGULATOR_MODE_STANDBY,
299 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
300 | REGULATOR_CHANGE_MODE
301 | REGULATOR_CHANGE_STATUS,
303 .num_consumer_supplies = ARRAY_SIZE(omap4_vmmc_supply),
304 .consumer_supplies = omap4_vmmc_supply,
307 static struct regulator_init_data omap4_vpp_idata = {
312 .valid_modes_mask = REGULATOR_MODE_NORMAL
313 | REGULATOR_MODE_STANDBY,
314 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
315 | REGULATOR_CHANGE_MODE
316 | REGULATOR_CHANGE_STATUS,
320 static struct regulator_init_data omap4_vana_idata = {
324 .valid_modes_mask = REGULATOR_MODE_NORMAL
325 | REGULATOR_MODE_STANDBY,
326 .valid_ops_mask = REGULATOR_CHANGE_MODE
327 | REGULATOR_CHANGE_STATUS,
331 static struct regulator_consumer_supply omap4_vcxio_supply[] = {
332 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dss"),
333 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
334 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.1"),
337 static struct regulator_init_data omap4_vcxio_idata = {
341 .valid_modes_mask = REGULATOR_MODE_NORMAL
342 | REGULATOR_MODE_STANDBY,
343 .valid_ops_mask = REGULATOR_CHANGE_MODE
344 | REGULATOR_CHANGE_STATUS,
347 .num_consumer_supplies = ARRAY_SIZE(omap4_vcxio_supply),
348 .consumer_supplies = omap4_vcxio_supply,
349 .supply_regulator = "V2V1",
352 static struct regulator_init_data omap4_vusb_idata = {
356 .valid_modes_mask = REGULATOR_MODE_NORMAL
357 | REGULATOR_MODE_STANDBY,
358 .valid_ops_mask = REGULATOR_CHANGE_MODE
359 | REGULATOR_CHANGE_STATUS,
363 static struct regulator_init_data omap4_clk32kg_idata = {
365 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
369 static struct regulator_consumer_supply omap4_vdd1_supply[] = {
370 REGULATOR_SUPPLY("vcc", "cpu0"),
373 static struct regulator_consumer_supply omap4_vdd2_supply[] = {
374 REGULATOR_SUPPLY("vcc", "iva.0"),
377 static struct regulator_consumer_supply omap4_vdd3_supply[] = {
378 REGULATOR_SUPPLY("vcc", "l3_main.0"),
381 static struct regulator_init_data omap4_vdd1 = {
386 .valid_modes_mask = REGULATOR_MODE_NORMAL,
387 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
389 .num_consumer_supplies = ARRAY_SIZE(omap4_vdd1_supply),
390 .consumer_supplies = omap4_vdd1_supply,
393 static struct regulator_init_data omap4_vdd2 = {
398 .valid_modes_mask = REGULATOR_MODE_NORMAL,
399 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
401 .num_consumer_supplies = ARRAY_SIZE(omap4_vdd2_supply),
402 .consumer_supplies = omap4_vdd2_supply,
405 static struct regulator_init_data omap4_vdd3 = {
410 .valid_modes_mask = REGULATOR_MODE_NORMAL,
411 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
413 .num_consumer_supplies = ARRAY_SIZE(omap4_vdd3_supply),
414 .consumer_supplies = omap4_vdd3_supply,
418 static struct twl_regulator_driver_data omap4_vdd1_drvdata = {
419 .get_voltage = twl_get_voltage,
420 .set_voltage = twl_set_voltage,
423 static struct twl_regulator_driver_data omap4_vdd2_drvdata = {
424 .get_voltage = twl_get_voltage,
425 .set_voltage = twl_set_voltage,
428 static struct twl_regulator_driver_data omap4_vdd3_drvdata = {
429 .get_voltage = twl_get_voltage,
430 .set_voltage = twl_set_voltage,
433 static struct regulator_consumer_supply omap4_v1v8_supply[] = {
434 REGULATOR_SUPPLY("vio", "1-004b"),
437 static struct regulator_init_data omap4_v1v8_idata = {
441 .valid_modes_mask = REGULATOR_MODE_NORMAL
442 | REGULATOR_MODE_STANDBY,
443 .valid_ops_mask = REGULATOR_CHANGE_MODE
444 | REGULATOR_CHANGE_STATUS,
447 .num_consumer_supplies = ARRAY_SIZE(omap4_v1v8_supply),
448 .consumer_supplies = omap4_v1v8_supply,
451 static struct regulator_consumer_supply omap4_v2v1_supply[] = {
452 REGULATOR_SUPPLY("v2v1", "1-004b"),
455 static struct regulator_init_data omap4_v2v1_idata = {
459 .valid_modes_mask = REGULATOR_MODE_NORMAL
460 | REGULATOR_MODE_STANDBY,
461 .valid_ops_mask = REGULATOR_CHANGE_MODE
462 | REGULATOR_CHANGE_STATUS,
464 .num_consumer_supplies = ARRAY_SIZE(omap4_v2v1_supply),
465 .consumer_supplies = omap4_v2v1_supply,
468 void __init omap4_pmic_get_config(struct twl4030_platform_data *pmic_data,
469 u32 pdata_flags, u32 regulators_flags)
471 if (!pmic_data->vdd1) {
472 omap4_vdd1.driver_data = &omap4_vdd1_drvdata;
473 omap4_vdd1_drvdata.data = voltdm_lookup("mpu");
474 pmic_data->vdd1 = &omap4_vdd1;
477 if (!pmic_data->vdd2) {
478 omap4_vdd2.driver_data = &omap4_vdd2_drvdata;
479 omap4_vdd2_drvdata.data = voltdm_lookup("iva");
480 pmic_data->vdd2 = &omap4_vdd2;
483 if (!pmic_data->vdd3) {
484 omap4_vdd3.driver_data = &omap4_vdd3_drvdata;
485 omap4_vdd3_drvdata.data = voltdm_lookup("core");
486 pmic_data->vdd3 = &omap4_vdd3;
489 /* Common platform data configurations */
490 if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
491 pmic_data->usb = &omap4_usb_pdata;
493 /* Common regulator configurations */
494 if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
495 pmic_data->vdac = &omap4_vdac_idata;
497 if (regulators_flags & TWL_COMMON_REGULATOR_VAUX2 && !pmic_data->vaux2)
498 pmic_data->vaux2 = &omap4_vaux2_idata;
500 if (regulators_flags & TWL_COMMON_REGULATOR_VAUX3 && !pmic_data->vaux3)
501 pmic_data->vaux3 = &omap4_vaux3_idata;
503 if (regulators_flags & TWL_COMMON_REGULATOR_VMMC && !pmic_data->vmmc)
504 pmic_data->vmmc = &omap4_vmmc_idata;
506 if (regulators_flags & TWL_COMMON_REGULATOR_VPP && !pmic_data->vpp)
507 pmic_data->vpp = &omap4_vpp_idata;
509 if (regulators_flags & TWL_COMMON_REGULATOR_VANA && !pmic_data->vana)
510 pmic_data->vana = &omap4_vana_idata;
512 if (regulators_flags & TWL_COMMON_REGULATOR_VCXIO && !pmic_data->vcxio)
513 pmic_data->vcxio = &omap4_vcxio_idata;
515 if (regulators_flags & TWL_COMMON_REGULATOR_VUSB && !pmic_data->vusb)
516 pmic_data->vusb = &omap4_vusb_idata;
518 if (regulators_flags & TWL_COMMON_REGULATOR_CLK32KG &&
520 pmic_data->clk32kg = &omap4_clk32kg_idata;
522 if (regulators_flags & TWL_COMMON_REGULATOR_V1V8 && !pmic_data->v1v8)
523 pmic_data->v1v8 = &omap4_v1v8_idata;
525 if (regulators_flags & TWL_COMMON_REGULATOR_V2V1 && !pmic_data->v2v1)
526 pmic_data->v2v1 = &omap4_v2v1_idata;
528 #endif /* CONFIG_ARCH_OMAP4 */
530 #if defined(CONFIG_SND_OMAP_SOC_OMAP_TWL4030) || \
531 defined(CONFIG_SND_OMAP_SOC_OMAP_TWL4030_MODULE)
532 #include <linux/platform_data/omap-twl4030.h>
534 /* Commonly used configuration */
535 static struct omap_tw4030_pdata omap_twl4030_audio_data;
537 static struct platform_device audio_device = {
538 .name = "omap-twl4030",
542 void omap_twl4030_audio_init(char *card_name,
543 struct omap_tw4030_pdata *pdata)
546 pdata = &omap_twl4030_audio_data;
548 pdata->card_name = card_name;
550 audio_device.dev.platform_data = pdata;
551 platform_device_register(&audio_device);
554 #else /* SOC_OMAP_TWL4030 */
555 void omap_twl4030_audio_init(char *card_name,
556 struct omap_tw4030_pdata *pdata)
560 #endif /* SOC_OMAP_TWL4030 */