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/regulator/machine.h>
28 #include <linux/regulator/fixed.h>
31 #include "twl-common.h"
36 static struct i2c_board_info __initdata pmic_i2c_board_info
= {
38 .flags
= I2C_CLIENT_WAKE
,
41 #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
42 static int twl_set_voltage(void *data
, int target_uV
)
44 struct voltagedomain
*voltdm
= (struct voltagedomain
*)data
;
45 return voltdm_scale(voltdm
, target_uV
);
48 static int twl_get_voltage(void *data
)
50 struct voltagedomain
*voltdm
= (struct voltagedomain
*)data
;
51 return voltdm_get_voltage(voltdm
);
55 void __init
omap_pmic_init(int bus
, u32 clkrate
,
56 const char *pmic_type
, int pmic_irq
,
57 struct twl4030_platform_data
*pmic_data
)
59 omap_mux_init_signal("sys_nirq", OMAP_PIN_INPUT_PULLUP
| OMAP_PIN_OFF_WAKEUPENABLE
);
60 strlcpy(pmic_i2c_board_info
.type
, pmic_type
,
61 sizeof(pmic_i2c_board_info
.type
));
62 pmic_i2c_board_info
.irq
= pmic_irq
;
63 pmic_i2c_board_info
.platform_data
= pmic_data
;
65 omap_register_i2c_bus(bus
, clkrate
, &pmic_i2c_board_info
, 1);
68 void __init
omap4_pmic_init(const char *pmic_type
,
69 struct twl4030_platform_data
*pmic_data
,
70 struct i2c_board_info
*devices
, int nr_devices
)
73 omap_mux_init_signal("sys_nirq1", OMAP_PIN_INPUT_PULLUP
| OMAP_PIN_OFF_WAKEUPENABLE
);
74 omap_mux_init_signal("fref_clk0_out.sys_drm_msecure", OMAP_PIN_OUTPUT
);
75 omap_pmic_init(1, 400, pmic_type
, 7 + OMAP44XX_IRQ_GIC_START
, pmic_data
);
77 /* Register additional devices on i2c1 bus if needed */
79 i2c_register_board_info(1, devices
, nr_devices
);
82 void __init
omap_pmic_late_init(void)
84 /* Init the OMAP TWL parameters (if PMIC has been registerd) */
85 if (!pmic_i2c_board_info
.irq
)
92 #if defined(CONFIG_ARCH_OMAP3)
93 static struct twl4030_usb_data omap3_usb_pdata
= {
94 .usb_mode
= T2_USB_MODE_ULPI
,
97 static int omap3_batt_table
[] = {
99 30800, 29500, 28300, 27100,
100 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
101 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
102 11600, 11200, 10800, 10400, 10000, 9630, 9280, 8950, 8620, 8310,
103 8020, 7730, 7460, 7200, 6950, 6710, 6470, 6250, 6040, 5830,
104 5640, 5450, 5260, 5090, 4920, 4760, 4600, 4450, 4310, 4170,
105 4040, 3910, 3790, 3670, 3550
108 static struct twl4030_bci_platform_data omap3_bci_pdata
= {
109 .battery_tmp_tbl
= omap3_batt_table
,
110 .tblsize
= ARRAY_SIZE(omap3_batt_table
),
113 static struct twl4030_madc_platform_data omap3_madc_pdata
= {
117 static struct twl4030_codec_data omap3_codec
;
119 static struct twl4030_audio_data omap3_audio_pdata
= {
120 .audio_mclk
= 26000000,
121 .codec
= &omap3_codec
,
124 static struct regulator_consumer_supply omap3_vdda_dac_supplies
[] = {
125 REGULATOR_SUPPLY("vdda_dac", "omapdss_venc"),
128 static struct regulator_init_data omap3_vdac_idata
= {
132 .valid_modes_mask
= REGULATOR_MODE_NORMAL
133 | REGULATOR_MODE_STANDBY
,
134 .valid_ops_mask
= REGULATOR_CHANGE_MODE
135 | REGULATOR_CHANGE_STATUS
,
137 .num_consumer_supplies
= ARRAY_SIZE(omap3_vdda_dac_supplies
),
138 .consumer_supplies
= omap3_vdda_dac_supplies
,
141 static struct regulator_consumer_supply omap3_vpll2_supplies
[] = {
142 REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
143 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
146 static struct regulator_init_data omap3_vpll2_idata
= {
150 .valid_modes_mask
= REGULATOR_MODE_NORMAL
151 | REGULATOR_MODE_STANDBY
,
152 .valid_ops_mask
= REGULATOR_CHANGE_MODE
153 | REGULATOR_CHANGE_STATUS
,
155 .num_consumer_supplies
= ARRAY_SIZE(omap3_vpll2_supplies
),
156 .consumer_supplies
= omap3_vpll2_supplies
,
159 static struct regulator_consumer_supply omap3_vdd1_supply
[] = {
160 REGULATOR_SUPPLY("vcc", "cpu0"),
163 static struct regulator_consumer_supply omap3_vdd2_supply
[] = {
164 REGULATOR_SUPPLY("vcc", "l3_main.0"),
167 static struct regulator_init_data omap3_vdd1
= {
169 .name
= "vdd_mpu_iva",
172 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
173 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
175 .num_consumer_supplies
= ARRAY_SIZE(omap3_vdd1_supply
),
176 .consumer_supplies
= omap3_vdd1_supply
,
179 static struct regulator_init_data omap3_vdd2
= {
184 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
185 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
187 .num_consumer_supplies
= ARRAY_SIZE(omap3_vdd2_supply
),
188 .consumer_supplies
= omap3_vdd2_supply
,
191 static struct twl_regulator_driver_data omap3_vdd1_drvdata
= {
192 .get_voltage
= twl_get_voltage
,
193 .set_voltage
= twl_set_voltage
,
196 static struct twl_regulator_driver_data omap3_vdd2_drvdata
= {
197 .get_voltage
= twl_get_voltage
,
198 .set_voltage
= twl_set_voltage
,
201 void __init
omap3_pmic_get_config(struct twl4030_platform_data
*pmic_data
,
202 u32 pdata_flags
, u32 regulators_flags
)
204 if (!pmic_data
->vdd1
) {
205 omap3_vdd1
.driver_data
= &omap3_vdd1_drvdata
;
206 omap3_vdd1_drvdata
.data
= voltdm_lookup("mpu_iva");
207 pmic_data
->vdd1
= &omap3_vdd1
;
209 if (!pmic_data
->vdd2
) {
210 omap3_vdd2
.driver_data
= &omap3_vdd2_drvdata
;
211 omap3_vdd2_drvdata
.data
= voltdm_lookup("core");
212 pmic_data
->vdd2
= &omap3_vdd2
;
215 /* Common platform data configurations */
216 if (pdata_flags
& TWL_COMMON_PDATA_USB
&& !pmic_data
->usb
)
217 pmic_data
->usb
= &omap3_usb_pdata
;
219 if (pdata_flags
& TWL_COMMON_PDATA_BCI
&& !pmic_data
->bci
)
220 pmic_data
->bci
= &omap3_bci_pdata
;
222 if (pdata_flags
& TWL_COMMON_PDATA_MADC
&& !pmic_data
->madc
)
223 pmic_data
->madc
= &omap3_madc_pdata
;
225 if (pdata_flags
& TWL_COMMON_PDATA_AUDIO
&& !pmic_data
->audio
)
226 pmic_data
->audio
= &omap3_audio_pdata
;
228 /* Common regulator configurations */
229 if (regulators_flags
& TWL_COMMON_REGULATOR_VDAC
&& !pmic_data
->vdac
)
230 pmic_data
->vdac
= &omap3_vdac_idata
;
232 if (regulators_flags
& TWL_COMMON_REGULATOR_VPLL2
&& !pmic_data
->vpll2
)
233 pmic_data
->vpll2
= &omap3_vpll2_idata
;
235 #endif /* CONFIG_ARCH_OMAP3 */
237 #if defined(CONFIG_ARCH_OMAP4)
238 static struct twl4030_usb_data omap4_usb_pdata
= {
241 static struct regulator_consumer_supply omap4_vdda_hdmi_dac_supplies
[] = {
242 REGULATOR_SUPPLY("vdda_hdmi_dac", "omapdss_hdmi"),
245 static struct regulator_init_data omap4_vdac_idata
= {
249 .valid_modes_mask
= REGULATOR_MODE_NORMAL
250 | REGULATOR_MODE_STANDBY
,
251 .valid_ops_mask
= REGULATOR_CHANGE_MODE
252 | REGULATOR_CHANGE_STATUS
,
254 .num_consumer_supplies
= ARRAY_SIZE(omap4_vdda_hdmi_dac_supplies
),
255 .consumer_supplies
= omap4_vdda_hdmi_dac_supplies
,
256 .supply_regulator
= "V2V1",
259 static struct regulator_init_data omap4_vaux2_idata
= {
264 .valid_modes_mask
= REGULATOR_MODE_NORMAL
265 | REGULATOR_MODE_STANDBY
,
266 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
267 | REGULATOR_CHANGE_MODE
268 | REGULATOR_CHANGE_STATUS
,
272 static struct regulator_init_data omap4_vaux3_idata
= {
277 .valid_modes_mask
= REGULATOR_MODE_NORMAL
278 | REGULATOR_MODE_STANDBY
,
279 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
280 | REGULATOR_CHANGE_MODE
281 | REGULATOR_CHANGE_STATUS
,
285 static struct regulator_consumer_supply omap4_vmmc_supply
[] = {
286 REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
289 /* VMMC1 for MMC1 card */
290 static struct regulator_init_data omap4_vmmc_idata
= {
295 .valid_modes_mask
= REGULATOR_MODE_NORMAL
296 | REGULATOR_MODE_STANDBY
,
297 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
298 | REGULATOR_CHANGE_MODE
299 | REGULATOR_CHANGE_STATUS
,
301 .num_consumer_supplies
= ARRAY_SIZE(omap4_vmmc_supply
),
302 .consumer_supplies
= omap4_vmmc_supply
,
305 static struct regulator_init_data omap4_vpp_idata
= {
310 .valid_modes_mask
= REGULATOR_MODE_NORMAL
311 | REGULATOR_MODE_STANDBY
,
312 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
313 | REGULATOR_CHANGE_MODE
314 | REGULATOR_CHANGE_STATUS
,
318 static struct regulator_init_data omap4_vana_idata
= {
322 .valid_modes_mask
= REGULATOR_MODE_NORMAL
323 | REGULATOR_MODE_STANDBY
,
324 .valid_ops_mask
= REGULATOR_CHANGE_MODE
325 | REGULATOR_CHANGE_STATUS
,
329 static struct regulator_consumer_supply omap4_vcxio_supply
[] = {
330 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dss"),
331 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
332 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.1"),
335 static struct regulator_init_data omap4_vcxio_idata
= {
339 .valid_modes_mask
= REGULATOR_MODE_NORMAL
340 | REGULATOR_MODE_STANDBY
,
341 .valid_ops_mask
= REGULATOR_CHANGE_MODE
342 | REGULATOR_CHANGE_STATUS
,
345 .num_consumer_supplies
= ARRAY_SIZE(omap4_vcxio_supply
),
346 .consumer_supplies
= omap4_vcxio_supply
,
347 .supply_regulator
= "V2V1",
350 static struct regulator_init_data omap4_vusb_idata
= {
354 .valid_modes_mask
= REGULATOR_MODE_NORMAL
355 | REGULATOR_MODE_STANDBY
,
356 .valid_ops_mask
= REGULATOR_CHANGE_MODE
357 | REGULATOR_CHANGE_STATUS
,
361 static struct regulator_init_data omap4_clk32kg_idata
= {
363 .valid_ops_mask
= REGULATOR_CHANGE_STATUS
,
367 static struct regulator_consumer_supply omap4_vdd1_supply
[] = {
368 REGULATOR_SUPPLY("vcc", "cpu0"),
371 static struct regulator_consumer_supply omap4_vdd2_supply
[] = {
372 REGULATOR_SUPPLY("vcc", "iva.0"),
375 static struct regulator_consumer_supply omap4_vdd3_supply
[] = {
376 REGULATOR_SUPPLY("vcc", "l3_main.0"),
379 static struct regulator_init_data omap4_vdd1
= {
384 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
385 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
387 .num_consumer_supplies
= ARRAY_SIZE(omap4_vdd1_supply
),
388 .consumer_supplies
= omap4_vdd1_supply
,
391 static struct regulator_init_data omap4_vdd2
= {
396 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
397 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
399 .num_consumer_supplies
= ARRAY_SIZE(omap4_vdd2_supply
),
400 .consumer_supplies
= omap4_vdd2_supply
,
403 static struct regulator_init_data omap4_vdd3
= {
408 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
409 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
411 .num_consumer_supplies
= ARRAY_SIZE(omap4_vdd3_supply
),
412 .consumer_supplies
= omap4_vdd3_supply
,
416 static struct twl_regulator_driver_data omap4_vdd1_drvdata
= {
417 .get_voltage
= twl_get_voltage
,
418 .set_voltage
= twl_set_voltage
,
421 static struct twl_regulator_driver_data omap4_vdd2_drvdata
= {
422 .get_voltage
= twl_get_voltage
,
423 .set_voltage
= twl_set_voltage
,
426 static struct twl_regulator_driver_data omap4_vdd3_drvdata
= {
427 .get_voltage
= twl_get_voltage
,
428 .set_voltage
= twl_set_voltage
,
431 static struct regulator_consumer_supply omap4_v1v8_supply
[] = {
432 REGULATOR_SUPPLY("vio", "1-004b"),
435 static struct regulator_init_data omap4_v1v8_idata
= {
439 .valid_modes_mask
= REGULATOR_MODE_NORMAL
440 | REGULATOR_MODE_STANDBY
,
441 .valid_ops_mask
= REGULATOR_CHANGE_MODE
442 | REGULATOR_CHANGE_STATUS
,
445 .num_consumer_supplies
= ARRAY_SIZE(omap4_v1v8_supply
),
446 .consumer_supplies
= omap4_v1v8_supply
,
449 static struct regulator_consumer_supply omap4_v2v1_supply
[] = {
450 REGULATOR_SUPPLY("v2v1", "1-004b"),
453 static struct regulator_init_data omap4_v2v1_idata
= {
457 .valid_modes_mask
= REGULATOR_MODE_NORMAL
458 | REGULATOR_MODE_STANDBY
,
459 .valid_ops_mask
= REGULATOR_CHANGE_MODE
460 | REGULATOR_CHANGE_STATUS
,
462 .num_consumer_supplies
= ARRAY_SIZE(omap4_v2v1_supply
),
463 .consumer_supplies
= omap4_v2v1_supply
,
466 void __init
omap4_pmic_get_config(struct twl4030_platform_data
*pmic_data
,
467 u32 pdata_flags
, u32 regulators_flags
)
469 if (!pmic_data
->vdd1
) {
470 omap4_vdd1
.driver_data
= &omap4_vdd1_drvdata
;
471 omap4_vdd1_drvdata
.data
= voltdm_lookup("mpu");
472 pmic_data
->vdd1
= &omap4_vdd1
;
475 if (!pmic_data
->vdd2
) {
476 omap4_vdd2
.driver_data
= &omap4_vdd2_drvdata
;
477 omap4_vdd2_drvdata
.data
= voltdm_lookup("iva");
478 pmic_data
->vdd2
= &omap4_vdd2
;
481 if (!pmic_data
->vdd3
) {
482 omap4_vdd3
.driver_data
= &omap4_vdd3_drvdata
;
483 omap4_vdd3_drvdata
.data
= voltdm_lookup("core");
484 pmic_data
->vdd3
= &omap4_vdd3
;
487 /* Common platform data configurations */
488 if (pdata_flags
& TWL_COMMON_PDATA_USB
&& !pmic_data
->usb
)
489 pmic_data
->usb
= &omap4_usb_pdata
;
491 /* Common regulator configurations */
492 if (regulators_flags
& TWL_COMMON_REGULATOR_VDAC
&& !pmic_data
->vdac
)
493 pmic_data
->vdac
= &omap4_vdac_idata
;
495 if (regulators_flags
& TWL_COMMON_REGULATOR_VAUX2
&& !pmic_data
->vaux2
)
496 pmic_data
->vaux2
= &omap4_vaux2_idata
;
498 if (regulators_flags
& TWL_COMMON_REGULATOR_VAUX3
&& !pmic_data
->vaux3
)
499 pmic_data
->vaux3
= &omap4_vaux3_idata
;
501 if (regulators_flags
& TWL_COMMON_REGULATOR_VMMC
&& !pmic_data
->vmmc
)
502 pmic_data
->vmmc
= &omap4_vmmc_idata
;
504 if (regulators_flags
& TWL_COMMON_REGULATOR_VPP
&& !pmic_data
->vpp
)
505 pmic_data
->vpp
= &omap4_vpp_idata
;
507 if (regulators_flags
& TWL_COMMON_REGULATOR_VANA
&& !pmic_data
->vana
)
508 pmic_data
->vana
= &omap4_vana_idata
;
510 if (regulators_flags
& TWL_COMMON_REGULATOR_VCXIO
&& !pmic_data
->vcxio
)
511 pmic_data
->vcxio
= &omap4_vcxio_idata
;
513 if (regulators_flags
& TWL_COMMON_REGULATOR_VUSB
&& !pmic_data
->vusb
)
514 pmic_data
->vusb
= &omap4_vusb_idata
;
516 if (regulators_flags
& TWL_COMMON_REGULATOR_CLK32KG
&&
518 pmic_data
->clk32kg
= &omap4_clk32kg_idata
;
520 if (regulators_flags
& TWL_COMMON_REGULATOR_V1V8
&& !pmic_data
->v1v8
)
521 pmic_data
->v1v8
= &omap4_v1v8_idata
;
523 if (regulators_flags
& TWL_COMMON_REGULATOR_V2V1
&& !pmic_data
->v2v1
)
524 pmic_data
->v2v1
= &omap4_v2v1_idata
;
526 #endif /* CONFIG_ARCH_OMAP4 */
528 #if defined(CONFIG_SND_OMAP_SOC_OMAP_TWL4030) || \
529 defined(CONFIG_SND_OMAP_SOC_OMAP_TWL4030_MODULE)
530 #include <linux/platform_data/omap-twl4030.h>
532 /* Commonly used configuration */
533 static struct omap_tw4030_pdata omap_twl4030_audio_data
;
535 static struct platform_device audio_device
= {
536 .name
= "omap-twl4030",
540 void omap_twl4030_audio_init(char *card_name
,
541 struct omap_tw4030_pdata
*pdata
)
544 pdata
= &omap_twl4030_audio_data
;
546 pdata
->card_name
= card_name
;
548 audio_device
.dev
.platform_data
= pdata
;
549 platform_device_register(&audio_device
);
552 #else /* SOC_OMAP_TWL4030 */
553 void omap_twl4030_audio_init(char *card_name
,
554 struct omap_tw4030_pdata
*pdata
)
558 #endif /* SOC_OMAP_TWL4030 */