Merge branch 'next/dt-samsung-2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.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 "soc.h"
30 #include "twl-common.h"
31 #include "pm.h"
32 #include "voltage.h"
33 #include "mux.h"
34
35 static struct i2c_board_info __initdata pmic_i2c_board_info = {
36         .addr           = 0x48,
37         .flags          = I2C_CLIENT_WAKE,
38 };
39
40 #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
41 static int twl_set_voltage(void *data, int target_uV)
42 {
43         struct voltagedomain *voltdm = (struct voltagedomain *)data;
44         return voltdm_scale(voltdm, target_uV);
45 }
46
47 static int twl_get_voltage(void *data)
48 {
49         struct voltagedomain *voltdm = (struct voltagedomain *)data;
50         return voltdm_get_voltage(voltdm);
51 }
52 #endif
53
54 void __init omap_pmic_init(int bus, u32 clkrate,
55                            const char *pmic_type, int pmic_irq,
56                            struct twl4030_platform_data *pmic_data)
57 {
58         omap_mux_init_signal("sys_nirq", OMAP_PIN_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE);
59         strncpy(pmic_i2c_board_info.type, pmic_type,
60                 sizeof(pmic_i2c_board_info.type));
61         pmic_i2c_board_info.irq = pmic_irq;
62         pmic_i2c_board_info.platform_data = pmic_data;
63
64         omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
65 }
66
67 void __init omap4_pmic_init(const char *pmic_type,
68                     struct twl4030_platform_data *pmic_data,
69                     struct i2c_board_info *devices, int nr_devices)
70 {
71         /* PMIC part*/
72         omap_mux_init_signal("sys_nirq1", OMAP_PIN_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE);
73         omap_pmic_init(1, 400, pmic_type, 7 + OMAP44XX_IRQ_GIC_START, pmic_data);
74
75         /* Register additional devices on i2c1 bus if needed */
76         if (devices)
77                 i2c_register_board_info(1, devices, nr_devices);
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                 return;
85
86         omap3_twl_init();
87         omap4_twl_init();
88 }
89
90 #if defined(CONFIG_ARCH_OMAP3)
91 static struct twl4030_usb_data omap3_usb_pdata = {
92         .usb_mode       = T2_USB_MODE_ULPI,
93 };
94
95 static int omap3_batt_table[] = {
96 /* 0 C */
97 30800, 29500, 28300, 27100,
98 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
99 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
100 11600, 11200, 10800, 10400, 10000, 9630,  9280,  8950,  8620,  8310,
101 8020,  7730,  7460,  7200,  6950,  6710,  6470,  6250,  6040,  5830,
102 5640,  5450,  5260,  5090,  4920,  4760,  4600,  4450,  4310,  4170,
103 4040,  3910,  3790,  3670,  3550
104 };
105
106 static struct twl4030_bci_platform_data omap3_bci_pdata = {
107         .battery_tmp_tbl        = omap3_batt_table,
108         .tblsize                = ARRAY_SIZE(omap3_batt_table),
109 };
110
111 static struct twl4030_madc_platform_data omap3_madc_pdata = {
112         .irq_line       = 1,
113 };
114
115 static struct twl4030_codec_data omap3_codec;
116
117 static struct twl4030_audio_data omap3_audio_pdata = {
118         .audio_mclk = 26000000,
119         .codec = &omap3_codec,
120 };
121
122 static struct regulator_consumer_supply omap3_vdda_dac_supplies[] = {
123         REGULATOR_SUPPLY("vdda_dac", "omapdss_venc"),
124 };
125
126 static struct regulator_init_data omap3_vdac_idata = {
127         .constraints = {
128                 .min_uV                 = 1800000,
129                 .max_uV                 = 1800000,
130                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
131                                         | REGULATOR_MODE_STANDBY,
132                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
133                                         | REGULATOR_CHANGE_STATUS,
134         },
135         .num_consumer_supplies  = ARRAY_SIZE(omap3_vdda_dac_supplies),
136         .consumer_supplies      = omap3_vdda_dac_supplies,
137 };
138
139 static struct regulator_consumer_supply omap3_vpll2_supplies[] = {
140         REGULATOR_SUPPLY("vdds_dsi", "omapdss"),
141         REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
142 };
143
144 static struct regulator_init_data omap3_vpll2_idata = {
145         .constraints = {
146                 .min_uV                 = 1800000,
147                 .max_uV                 = 1800000,
148                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
149                                         | REGULATOR_MODE_STANDBY,
150                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
151                                         | REGULATOR_CHANGE_STATUS,
152         },
153         .num_consumer_supplies          = ARRAY_SIZE(omap3_vpll2_supplies),
154         .consumer_supplies              = omap3_vpll2_supplies,
155 };
156
157 static struct regulator_consumer_supply omap3_vdd1_supply[] = {
158         REGULATOR_SUPPLY("vcc", "cpu0"),
159 };
160
161 static struct regulator_consumer_supply omap3_vdd2_supply[] = {
162         REGULATOR_SUPPLY("vcc", "l3_main.0"),
163 };
164
165 static struct regulator_init_data omap3_vdd1 = {
166         .constraints = {
167                 .name                   = "vdd_mpu_iva",
168                 .min_uV                 = 600000,
169                 .max_uV                 = 1450000,
170                 .valid_modes_mask       = REGULATOR_MODE_NORMAL,
171                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE,
172         },
173         .num_consumer_supplies          = ARRAY_SIZE(omap3_vdd1_supply),
174         .consumer_supplies              = omap3_vdd1_supply,
175 };
176
177 static struct regulator_init_data omap3_vdd2 = {
178         .constraints = {
179                 .name                   = "vdd_core",
180                 .min_uV                 = 600000,
181                 .max_uV                 = 1450000,
182                 .valid_modes_mask       = REGULATOR_MODE_NORMAL,
183                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE,
184         },
185         .num_consumer_supplies          = ARRAY_SIZE(omap3_vdd2_supply),
186         .consumer_supplies              = omap3_vdd2_supply,
187 };
188
189 static struct twl_regulator_driver_data omap3_vdd1_drvdata = {
190         .get_voltage = twl_get_voltage,
191         .set_voltage = twl_set_voltage,
192 };
193
194 static struct twl_regulator_driver_data omap3_vdd2_drvdata = {
195         .get_voltage = twl_get_voltage,
196         .set_voltage = twl_set_voltage,
197 };
198
199 void __init omap3_pmic_get_config(struct twl4030_platform_data *pmic_data,
200                                   u32 pdata_flags, u32 regulators_flags)
201 {
202         if (!pmic_data->vdd1) {
203                 omap3_vdd1.driver_data = &omap3_vdd1_drvdata;
204                 omap3_vdd1_drvdata.data = voltdm_lookup("mpu_iva");
205                 pmic_data->vdd1 = &omap3_vdd1;
206         }
207         if (!pmic_data->vdd2) {
208                 omap3_vdd2.driver_data = &omap3_vdd2_drvdata;
209                 omap3_vdd2_drvdata.data = voltdm_lookup("core");
210                 pmic_data->vdd2 = &omap3_vdd2;
211         }
212
213         /* Common platform data configurations */
214         if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
215                 pmic_data->usb = &omap3_usb_pdata;
216
217         if (pdata_flags & TWL_COMMON_PDATA_BCI && !pmic_data->bci)
218                 pmic_data->bci = &omap3_bci_pdata;
219
220         if (pdata_flags & TWL_COMMON_PDATA_MADC && !pmic_data->madc)
221                 pmic_data->madc = &omap3_madc_pdata;
222
223         if (pdata_flags & TWL_COMMON_PDATA_AUDIO && !pmic_data->audio)
224                 pmic_data->audio = &omap3_audio_pdata;
225
226         /* Common regulator configurations */
227         if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
228                 pmic_data->vdac = &omap3_vdac_idata;
229
230         if (regulators_flags & TWL_COMMON_REGULATOR_VPLL2 && !pmic_data->vpll2)
231                 pmic_data->vpll2 = &omap3_vpll2_idata;
232 }
233 #endif /* CONFIG_ARCH_OMAP3 */
234
235 #if defined(CONFIG_ARCH_OMAP4)
236 static struct twl4030_usb_data omap4_usb_pdata = {
237 };
238
239 static struct regulator_consumer_supply omap4_vdda_hdmi_dac_supplies[] = {
240         REGULATOR_SUPPLY("vdda_hdmi_dac", "omapdss_hdmi"),
241 };
242
243 static struct regulator_init_data omap4_vdac_idata = {
244         .constraints = {
245                 .min_uV                 = 1800000,
246                 .max_uV                 = 1800000,
247                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
248                                         | REGULATOR_MODE_STANDBY,
249                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
250                                         | REGULATOR_CHANGE_STATUS,
251         },
252         .num_consumer_supplies  = ARRAY_SIZE(omap4_vdda_hdmi_dac_supplies),
253         .consumer_supplies      = omap4_vdda_hdmi_dac_supplies,
254         .supply_regulator       = "V2V1",
255 };
256
257 static struct regulator_init_data omap4_vaux2_idata = {
258         .constraints = {
259                 .min_uV                 = 1200000,
260                 .max_uV                 = 2800000,
261                 .apply_uV               = true,
262                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
263                                         | REGULATOR_MODE_STANDBY,
264                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
265                                         | REGULATOR_CHANGE_MODE
266                                         | REGULATOR_CHANGE_STATUS,
267         },
268 };
269
270 static struct regulator_init_data omap4_vaux3_idata = {
271         .constraints = {
272                 .min_uV                 = 1000000,
273                 .max_uV                 = 3000000,
274                 .apply_uV               = true,
275                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
276                                         | REGULATOR_MODE_STANDBY,
277                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
278                                         | REGULATOR_CHANGE_MODE
279                                         | REGULATOR_CHANGE_STATUS,
280         },
281 };
282
283 static struct regulator_consumer_supply omap4_vmmc_supply[] = {
284         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
285 };
286
287 /* VMMC1 for MMC1 card */
288 static struct regulator_init_data omap4_vmmc_idata = {
289         .constraints = {
290                 .min_uV                 = 1200000,
291                 .max_uV                 = 3000000,
292                 .apply_uV               = true,
293                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
294                                         | REGULATOR_MODE_STANDBY,
295                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
296                                         | REGULATOR_CHANGE_MODE
297                                         | REGULATOR_CHANGE_STATUS,
298         },
299         .num_consumer_supplies  = ARRAY_SIZE(omap4_vmmc_supply),
300         .consumer_supplies      = omap4_vmmc_supply,
301 };
302
303 static struct regulator_init_data omap4_vpp_idata = {
304         .constraints = {
305                 .min_uV                 = 1800000,
306                 .max_uV                 = 2500000,
307                 .apply_uV               = true,
308                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
309                                         | REGULATOR_MODE_STANDBY,
310                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
311                                         | REGULATOR_CHANGE_MODE
312                                         | REGULATOR_CHANGE_STATUS,
313         },
314 };
315
316 static struct regulator_init_data omap4_vana_idata = {
317         .constraints = {
318                 .min_uV                 = 2100000,
319                 .max_uV                 = 2100000,
320                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
321                                         | REGULATOR_MODE_STANDBY,
322                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
323                                         | REGULATOR_CHANGE_STATUS,
324         },
325 };
326
327 static struct regulator_consumer_supply omap4_vcxio_supply[] = {
328         REGULATOR_SUPPLY("vdds_dsi", "omapdss_dss"),
329         REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.0"),
330         REGULATOR_SUPPLY("vdds_dsi", "omapdss_dsi.1"),
331 };
332
333 static struct regulator_init_data omap4_vcxio_idata = {
334         .constraints = {
335                 .min_uV                 = 1800000,
336                 .max_uV                 = 1800000,
337                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
338                                         | REGULATOR_MODE_STANDBY,
339                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
340                                         | REGULATOR_CHANGE_STATUS,
341                 .always_on              = true,
342         },
343         .num_consumer_supplies  = ARRAY_SIZE(omap4_vcxio_supply),
344         .consumer_supplies      = omap4_vcxio_supply,
345         .supply_regulator       = "V2V1",
346 };
347
348 static struct regulator_init_data omap4_vusb_idata = {
349         .constraints = {
350                 .min_uV                 = 3300000,
351                 .max_uV                 = 3300000,
352                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
353                                         | REGULATOR_MODE_STANDBY,
354                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
355                                         | REGULATOR_CHANGE_STATUS,
356         },
357 };
358
359 static struct regulator_init_data omap4_clk32kg_idata = {
360         .constraints = {
361                 .valid_ops_mask         = REGULATOR_CHANGE_STATUS,
362         },
363 };
364
365 static struct regulator_consumer_supply omap4_vdd1_supply[] = {
366         REGULATOR_SUPPLY("vcc", "mpu.0"),
367 };
368
369 static struct regulator_consumer_supply omap4_vdd2_supply[] = {
370         REGULATOR_SUPPLY("vcc", "iva.0"),
371 };
372
373 static struct regulator_consumer_supply omap4_vdd3_supply[] = {
374         REGULATOR_SUPPLY("vcc", "l3_main.0"),
375 };
376
377 static struct regulator_init_data omap4_vdd1 = {
378         .constraints = {
379                 .name                   = "vdd_mpu",
380                 .min_uV                 = 500000,
381                 .max_uV                 = 1500000,
382                 .valid_modes_mask       = REGULATOR_MODE_NORMAL,
383                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE,
384         },
385         .num_consumer_supplies          = ARRAY_SIZE(omap4_vdd1_supply),
386         .consumer_supplies              = omap4_vdd1_supply,
387 };
388
389 static struct regulator_init_data omap4_vdd2 = {
390         .constraints = {
391                 .name                   = "vdd_iva",
392                 .min_uV                 = 500000,
393                 .max_uV                 = 1500000,
394                 .valid_modes_mask       = REGULATOR_MODE_NORMAL,
395                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE,
396         },
397         .num_consumer_supplies          = ARRAY_SIZE(omap4_vdd2_supply),
398         .consumer_supplies              = omap4_vdd2_supply,
399 };
400
401 static struct regulator_init_data omap4_vdd3 = {
402         .constraints = {
403                 .name                   = "vdd_core",
404                 .min_uV                 = 500000,
405                 .max_uV                 = 1500000,
406                 .valid_modes_mask       = REGULATOR_MODE_NORMAL,
407                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE,
408         },
409         .num_consumer_supplies          = ARRAY_SIZE(omap4_vdd3_supply),
410         .consumer_supplies              = omap4_vdd3_supply,
411 };
412
413
414 static struct twl_regulator_driver_data omap4_vdd1_drvdata = {
415         .get_voltage = twl_get_voltage,
416         .set_voltage = twl_set_voltage,
417 };
418
419 static struct twl_regulator_driver_data omap4_vdd2_drvdata = {
420         .get_voltage = twl_get_voltage,
421         .set_voltage = twl_set_voltage,
422 };
423
424 static struct twl_regulator_driver_data omap4_vdd3_drvdata = {
425         .get_voltage = twl_get_voltage,
426         .set_voltage = twl_set_voltage,
427 };
428
429 static struct regulator_consumer_supply omap4_v1v8_supply[] = {
430         REGULATOR_SUPPLY("vio", "1-004b"),
431 };
432
433 static struct regulator_init_data omap4_v1v8_idata = {
434         .constraints = {
435                 .min_uV                 = 1800000,
436                 .max_uV                 = 1800000,
437                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
438                                         | REGULATOR_MODE_STANDBY,
439                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
440                                         | REGULATOR_CHANGE_STATUS,
441                 .always_on              = true,
442         },
443         .num_consumer_supplies  = ARRAY_SIZE(omap4_v1v8_supply),
444         .consumer_supplies      = omap4_v1v8_supply,
445 };
446
447 static struct regulator_consumer_supply omap4_v2v1_supply[] = {
448         REGULATOR_SUPPLY("v2v1", "1-004b"),
449 };
450
451 static struct regulator_init_data omap4_v2v1_idata = {
452         .constraints = {
453                 .min_uV                 = 2100000,
454                 .max_uV                 = 2100000,
455                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
456                                         | REGULATOR_MODE_STANDBY,
457                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
458                                         | REGULATOR_CHANGE_STATUS,
459         },
460         .num_consumer_supplies  = ARRAY_SIZE(omap4_v2v1_supply),
461         .consumer_supplies      = omap4_v2v1_supply,
462 };
463
464 void __init omap4_pmic_get_config(struct twl4030_platform_data *pmic_data,
465                                   u32 pdata_flags, u32 regulators_flags)
466 {
467         if (!pmic_data->vdd1) {
468                 omap4_vdd1.driver_data = &omap4_vdd1_drvdata;
469                 omap4_vdd1_drvdata.data = voltdm_lookup("mpu");
470                 pmic_data->vdd1 = &omap4_vdd1;
471         }
472
473         if (!pmic_data->vdd2) {
474                 omap4_vdd2.driver_data = &omap4_vdd2_drvdata;
475                 omap4_vdd2_drvdata.data = voltdm_lookup("iva");
476                 pmic_data->vdd2 = &omap4_vdd2;
477         }
478
479         if (!pmic_data->vdd3) {
480                 omap4_vdd3.driver_data = &omap4_vdd3_drvdata;
481                 omap4_vdd3_drvdata.data = voltdm_lookup("core");
482                 pmic_data->vdd3 = &omap4_vdd3;
483         }
484
485         /* Common platform data configurations */
486         if (pdata_flags & TWL_COMMON_PDATA_USB && !pmic_data->usb)
487                 pmic_data->usb = &omap4_usb_pdata;
488
489         /* Common regulator configurations */
490         if (regulators_flags & TWL_COMMON_REGULATOR_VDAC && !pmic_data->vdac)
491                 pmic_data->vdac = &omap4_vdac_idata;
492
493         if (regulators_flags & TWL_COMMON_REGULATOR_VAUX2 && !pmic_data->vaux2)
494                 pmic_data->vaux2 = &omap4_vaux2_idata;
495
496         if (regulators_flags & TWL_COMMON_REGULATOR_VAUX3 && !pmic_data->vaux3)
497                 pmic_data->vaux3 = &omap4_vaux3_idata;
498
499         if (regulators_flags & TWL_COMMON_REGULATOR_VMMC && !pmic_data->vmmc)
500                 pmic_data->vmmc = &omap4_vmmc_idata;
501
502         if (regulators_flags & TWL_COMMON_REGULATOR_VPP && !pmic_data->vpp)
503                 pmic_data->vpp = &omap4_vpp_idata;
504
505         if (regulators_flags & TWL_COMMON_REGULATOR_VANA && !pmic_data->vana)
506                 pmic_data->vana = &omap4_vana_idata;
507
508         if (regulators_flags & TWL_COMMON_REGULATOR_VCXIO && !pmic_data->vcxio)
509                 pmic_data->vcxio = &omap4_vcxio_idata;
510
511         if (regulators_flags & TWL_COMMON_REGULATOR_VUSB && !pmic_data->vusb)
512                 pmic_data->vusb = &omap4_vusb_idata;
513
514         if (regulators_flags & TWL_COMMON_REGULATOR_CLK32KG &&
515             !pmic_data->clk32kg)
516                 pmic_data->clk32kg = &omap4_clk32kg_idata;
517
518         if (regulators_flags & TWL_COMMON_REGULATOR_V1V8 && !pmic_data->v1v8)
519                 pmic_data->v1v8 = &omap4_v1v8_idata;
520
521         if (regulators_flags & TWL_COMMON_REGULATOR_V2V1 && !pmic_data->v2v1)
522                 pmic_data->v2v1 = &omap4_v2v1_idata;
523 }
524 #endif /* CONFIG_ARCH_OMAP4 */
525
526 #if defined(CONFIG_SND_OMAP_SOC_OMAP_TWL4030) || \
527         defined(CONFIG_SND_OMAP_SOC_OMAP_TWL4030_MODULE)
528 #include <linux/platform_data/omap-twl4030.h>
529
530 static struct omap_tw4030_pdata omap_twl4030_audio_data;
531
532 static struct platform_device audio_device = {
533         .name           = "omap-twl4030",
534         .id             = -1,
535         .dev = {
536                 .platform_data = &omap_twl4030_audio_data,
537         },
538 };
539
540 void __init omap_twl4030_audio_init(char *card_name)
541 {
542         omap_twl4030_audio_data.card_name = card_name;
543         platform_device_register(&audio_device);
544 }
545
546 #else /* SOC_OMAP_TWL4030 */
547 void __init omap_twl4030_audio_init(char *card_name)
548 {
549         return;
550 }
551 #endif /* SOC_OMAP_TWL4030 */