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/regulator/machine.h>
27 #include <linux/regulator/fixed.h>
32 #include "twl-common.h"
36 static struct i2c_board_info __initdata pmic_i2c_board_info = {
38 .flags = I2C_CLIENT_WAKE,
41 static int twl_set_voltage(void *data, int target_uV)
43 struct voltagedomain *voltdm = (struct voltagedomain *)data;
44 return voltdm_scale(voltdm, target_uV);
47 static int twl_get_voltage(void *data)
49 struct voltagedomain *voltdm = (struct voltagedomain *)data;
50 return voltdm_get_voltage(voltdm);
53 void __init omap_pmic_init(int bus, u32 clkrate,
54 const char *pmic_type, int pmic_irq,
55 struct twl4030_platform_data *pmic_data)
57 strncpy(pmic_i2c_board_info.type, pmic_type,
58 sizeof(pmic_i2c_board_info.type));
59 pmic_i2c_board_info.irq = pmic_irq;
60 pmic_i2c_board_info.platform_data = pmic_data;
62 omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
65 void __init omap_pmic_late_init(void)
67 /* Init the OMAP TWL parameters (if PMIC has been registerd) */
68 if (!pmic_i2c_board_info.irq)
75 #if defined(CONFIG_ARCH_OMAP3)
76 static struct twl4030_usb_data omap3_usb_pdata = {
77 .usb_mode = T2_USB_MODE_ULPI,
80 static int omap3_batt_table[] = {
82 30800, 29500, 28300, 27100,
83 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
84 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
85 11600, 11200, 10800, 10400, 10000, 9630, 9280, 8950, 8620, 8310,
86 8020, 7730, 7460, 7200, 6950, 6710, 6470, 6250, 6040, 5830,
87 5640, 5450, 5260, 5090, 4920, 4760, 4600, 4450, 4310, 4170,
88 4040, 3910, 3790, 3670, 3550
91 static struct twl4030_bci_platform_data omap3_bci_pdata = {
92 .battery_tmp_tbl = omap3_batt_table,
93 .tblsize = ARRAY_SIZE(omap3_batt_table),
96 static struct twl4030_madc_platform_data omap3_madc_pdata = {
100 static struct twl4030_codec_data omap3_codec;
102 static struct twl4030_audio_data omap3_audio_pdata = {
103 .audio_mclk = 26000000,
104 .codec = &omap3_codec,
107 static struct regulator_consumer_supply omap3_vdda_dac_supplies[] = {
108 REGULATOR_SUPPLY("vdda_dac", "omapdss_venc"),
111 static struct regulator_init_data omap3_vdac_idata = {
115 .valid_modes_mask = REGULATOR_MODE_NORMAL
116 | REGULATOR_MODE_STANDBY,
117 .valid_ops_mask = REGULATOR_CHANGE_MODE
118 | REGULATOR_CHANGE_STATUS,
120 .num_consumer_supplies = ARRAY_SIZE(omap3_vdda_dac_supplies),
121 .consumer_supplies = omap3_vdda_dac_supplies,
124 static struct regulator_consumer_supply omap3_vpll2_supplies[] = {
125 REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
126 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
129 static struct regulator_init_data omap3_vpll2_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_vpll2_supplies),
139 .consumer_supplies = omap3_vpll2_supplies,
142 static struct regulator_consumer_supply omap3_vdd1_supply[] = {
143 REGULATOR_SUPPLY("vcc", "mpu.0"),
144 REGULATOR_SUPPLY("vcc", "iva.0"),
147 static struct regulator_consumer_supply omap3_vdd2_supply[] = {
148 REGULATOR_SUPPLY("vcc", "l3_main.0"),
151 static struct regulator_init_data omap3_vdd1 = {
153 .name = "vdd_mpu_iva",
156 .valid_modes_mask = REGULATOR_MODE_NORMAL,
157 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
159 .num_consumer_supplies = ARRAY_SIZE(omap3_vdd1_supply),
160 .consumer_supplies = omap3_vdd1_supply,
163 static struct regulator_init_data omap3_vdd2 = {
168 .valid_modes_mask = REGULATOR_MODE_NORMAL,
169 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
171 .num_consumer_supplies = ARRAY_SIZE(omap3_vdd2_supply),
172 .consumer_supplies = omap3_vdd2_supply,
175 static struct twl_regulator_driver_data omap3_vdd1_drvdata = {
176 .get_voltage = twl_get_voltage,
177 .set_voltage = twl_set_voltage,
180 static struct twl_regulator_driver_data omap3_vdd2_drvdata = {
181 .get_voltage = twl_get_voltage,
182 .set_voltage = twl_set_voltage,
185 void __init omap3_pmic_get_config(struct twl4030_platform_data *pmic_data,
186 u32 pdata_flags, u32 regulators_flags)
188 if (!pmic_data->irq_base)
189 pmic_data->irq_base = TWL4030_IRQ_BASE;
190 if (!pmic_data->irq_end)
191 pmic_data->irq_end = TWL4030_IRQ_END;
192 if (!pmic_data->vdd1) {
193 omap3_vdd1.driver_data = &omap3_vdd1_drvdata;
194 omap3_vdd1_drvdata.data = voltdm_lookup("mpu_iva");
195 pmic_data->vdd1 = &omap3_vdd1;
197 if (!pmic_data->vdd2) {
198 omap3_vdd2.driver_data = &omap3_vdd2_drvdata;
199 omap3_vdd2_drvdata.data = voltdm_lookup("core");
200 pmic_data->vdd2 = &omap3_vdd2;
203 /* Common platform data configurations */
204 if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
205 pmic_data->usb = &omap3_usb_pdata;
207 if (pdata_flags & TWL_COMMON_PDATA_BCI && !pmic_data->bci)
208 pmic_data->bci = &omap3_bci_pdata;
210 if (pdata_flags & TWL_COMMON_PDATA_MADC && !pmic_data->madc)
211 pmic_data->madc = &omap3_madc_pdata;
213 if (pdata_flags & TWL_COMMON_PDATA_AUDIO && !pmic_data->audio)
214 pmic_data->audio = &omap3_audio_pdata;
216 /* Common regulator configurations */
217 if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
218 pmic_data->vdac = &omap3_vdac_idata;
220 if (regulators_flags & TWL_COMMON_REGULATOR_VPLL2 && !pmic_data->vpll2)
221 pmic_data->vpll2 = &omap3_vpll2_idata;
223 #endif /* CONFIG_ARCH_OMAP3 */
225 #if defined(CONFIG_ARCH_OMAP4)
226 static struct twl4030_usb_data omap4_usb_pdata = {
227 .phy_init = omap4430_phy_init,
228 .phy_exit = omap4430_phy_exit,
229 .phy_power = omap4430_phy_power,
230 .phy_set_clock = omap4430_phy_set_clk,
231 .phy_suspend = omap4430_phy_suspend,
234 static struct regulator_init_data omap4_vdac_idata = {
238 .valid_modes_mask = REGULATOR_MODE_NORMAL
239 | REGULATOR_MODE_STANDBY,
240 .valid_ops_mask = REGULATOR_CHANGE_MODE
241 | REGULATOR_CHANGE_STATUS,
245 static struct regulator_init_data omap4_vaux2_idata = {
250 .valid_modes_mask = REGULATOR_MODE_NORMAL
251 | REGULATOR_MODE_STANDBY,
252 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
253 | REGULATOR_CHANGE_MODE
254 | REGULATOR_CHANGE_STATUS,
258 static struct regulator_init_data omap4_vaux3_idata = {
263 .valid_modes_mask = REGULATOR_MODE_NORMAL
264 | REGULATOR_MODE_STANDBY,
265 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
266 | REGULATOR_CHANGE_MODE
267 | REGULATOR_CHANGE_STATUS,
271 static struct regulator_consumer_supply omap4_vmmc_supply[] = {
272 REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
275 /* VMMC1 for MMC1 card */
276 static struct regulator_init_data omap4_vmmc_idata = {
281 .valid_modes_mask = REGULATOR_MODE_NORMAL
282 | REGULATOR_MODE_STANDBY,
283 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
284 | REGULATOR_CHANGE_MODE
285 | REGULATOR_CHANGE_STATUS,
287 .num_consumer_supplies = ARRAY_SIZE(omap4_vmmc_supply),
288 .consumer_supplies = omap4_vmmc_supply,
291 static struct regulator_init_data omap4_vpp_idata = {
296 .valid_modes_mask = REGULATOR_MODE_NORMAL
297 | REGULATOR_MODE_STANDBY,
298 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
299 | REGULATOR_CHANGE_MODE
300 | REGULATOR_CHANGE_STATUS,
304 static struct regulator_init_data omap4_vana_idata = {
308 .valid_modes_mask = REGULATOR_MODE_NORMAL
309 | REGULATOR_MODE_STANDBY,
310 .valid_ops_mask = REGULATOR_CHANGE_MODE
311 | REGULATOR_CHANGE_STATUS,
315 static struct regulator_consumer_supply omap4_vcxio_supply[] = {
316 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dss"),
317 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
318 REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.1"),
321 static struct regulator_init_data omap4_vcxio_idata = {
325 .valid_modes_mask = REGULATOR_MODE_NORMAL
326 | REGULATOR_MODE_STANDBY,
327 .valid_ops_mask = REGULATOR_CHANGE_MODE
328 | REGULATOR_CHANGE_STATUS,
331 .num_consumer_supplies = ARRAY_SIZE(omap4_vcxio_supply),
332 .consumer_supplies = omap4_vcxio_supply,
335 static struct regulator_init_data omap4_vusb_idata = {
340 .valid_modes_mask = REGULATOR_MODE_NORMAL
341 | REGULATOR_MODE_STANDBY,
342 .valid_ops_mask = REGULATOR_CHANGE_MODE
343 | REGULATOR_CHANGE_STATUS,
347 static struct regulator_init_data omap4_clk32kg_idata = {
349 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
353 void __init omap4_pmic_get_config(struct twl4030_platform_data *pmic_data,
354 u32 pdata_flags, u32 regulators_flags)
356 if (!pmic_data->irq_base)
357 pmic_data->irq_base = TWL6030_IRQ_BASE;
358 if (!pmic_data->irq_end)
359 pmic_data->irq_end = TWL6030_IRQ_END;
361 /* Common platform data configurations */
362 if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
363 pmic_data->usb = &omap4_usb_pdata;
365 /* Common regulator configurations */
366 if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
367 pmic_data->vdac = &omap4_vdac_idata;
369 if (regulators_flags & TWL_COMMON_REGULATOR_VAUX2 && !pmic_data->vaux2)
370 pmic_data->vaux2 = &omap4_vaux2_idata;
372 if (regulators_flags & TWL_COMMON_REGULATOR_VAUX3 && !pmic_data->vaux3)
373 pmic_data->vaux3 = &omap4_vaux3_idata;
375 if (regulators_flags & TWL_COMMON_REGULATOR_VMMC && !pmic_data->vmmc)
376 pmic_data->vmmc = &omap4_vmmc_idata;
378 if (regulators_flags & TWL_COMMON_REGULATOR_VPP && !pmic_data->vpp)
379 pmic_data->vpp = &omap4_vpp_idata;
381 if (regulators_flags & TWL_COMMON_REGULATOR_VANA && !pmic_data->vana)
382 pmic_data->vana = &omap4_vana_idata;
384 if (regulators_flags & TWL_COMMON_REGULATOR_VCXIO && !pmic_data->vcxio)
385 pmic_data->vcxio = &omap4_vcxio_idata;
387 if (regulators_flags & TWL_COMMON_REGULATOR_VUSB && !pmic_data->vusb)
388 pmic_data->vusb = &omap4_vusb_idata;
390 if (regulators_flags & TWL_COMMON_REGULATOR_CLK32KG &&
392 pmic_data->clk32kg = &omap4_clk32kg_idata;
394 #endif /* CONFIG_ARCH_OMAP4 */