arm: tegra: cardhu: Use fixed regulator
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-pm299-power-rails.c
1 /*
2  * arch/arm/mach-tegra/board-cardhu-pm299-power-rails.c
3  *
4  * Copyright (C) 2011 NVIDIA, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  * 02111-1307, USA
19  */
20 #include <linux/i2c.h>
21 #include <linux/pda_power.h>
22 #include <linux/platform_device.h>
23 #include <linux/resource.h>
24 #include <linux/regulator/machine.h>
25 #include <linux/mfd/ricoh583.h>
26 #include <linux/gpio.h>
27 #include <linux/io.h>
28 #include <linux/regulator/gpio-switch-regulator.h>
29 #include <linux/regulator/fixed.h>
30 #include <linux/regulator/ricoh583-regulator.h>
31 #include <linux/regulator/tps6236x-regulator.h>
32
33 #include <mach/iomap.h>
34 #include <mach/irqs.h>
35 #include <mach/pinmux.h>
36 #include <mach/edp.h>
37
38 #include "gpio-names.h"
39 #include "board.h"
40 #include "board-cardhu.h"
41 #include "wakeups-t3.h"
42
43 #define PMC_CTRL                0x0
44 #define PMC_CTRL_INTR_LOW       (1 << 17)
45
46 static struct regulator_consumer_supply ricoh583_dc1_supply_skubit0_0[] = {
47         REGULATOR_SUPPLY("vdd_core", NULL),
48         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
49 };
50
51 static struct regulator_consumer_supply ricoh583_dc1_supply_skubit0_1[] = {
52         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
53 };
54
55 static struct regulator_consumer_supply ricoh583_dc3_supply_0[] = {
56         REGULATOR_SUPPLY("vdd_gen1v5", NULL),
57         REGULATOR_SUPPLY("vcore_lcd", NULL),
58         REGULATOR_SUPPLY("track_ldo1", NULL),
59         REGULATOR_SUPPLY("external_ldo_1v2", NULL),
60         REGULATOR_SUPPLY("vcore_cam1", NULL),
61         REGULATOR_SUPPLY("vcore_cam2", NULL),
62 };
63
64 static struct regulator_consumer_supply ricoh583_dc0_supply_0[] = {
65         REGULATOR_SUPPLY("vdd_cpu_pmu", NULL),
66         REGULATOR_SUPPLY("vdd_cpu", NULL),
67         REGULATOR_SUPPLY("vdd_sys", NULL),
68 };
69
70 static struct regulator_consumer_supply ricoh583_dc2_supply_0[] = {
71         REGULATOR_SUPPLY("vdd_gen1v8", NULL),
72         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
73         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
74         REGULATOR_SUPPLY("avdd_osc", NULL),
75         REGULATOR_SUPPLY("vddio_sys", NULL),
76         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.3"),
77         REGULATOR_SUPPLY("pwrdet_sdmmc4", NULL),
78         REGULATOR_SUPPLY("vdd1v8_satelite", NULL),
79         REGULATOR_SUPPLY("vddio_uart", NULL),
80         REGULATOR_SUPPLY("pwrdet_uart", NULL),
81         REGULATOR_SUPPLY("vddio_audio", NULL),
82         REGULATOR_SUPPLY("pwrdet_audio", NULL),
83         REGULATOR_SUPPLY("vddio_bb", NULL),
84         REGULATOR_SUPPLY("pwrdet_bb", NULL),
85         REGULATOR_SUPPLY("vddio_lcd_pmu", NULL),
86         REGULATOR_SUPPLY("pwrdet_lcd", NULL),
87         REGULATOR_SUPPLY("vddio_cam", NULL),
88         REGULATOR_SUPPLY("pwrdet_cam", NULL),
89         REGULATOR_SUPPLY("vddio_vi", NULL),
90         REGULATOR_SUPPLY("pwrdet_vi", NULL),
91         REGULATOR_SUPPLY("ldo6", NULL),
92         REGULATOR_SUPPLY("ldo7", NULL),
93         REGULATOR_SUPPLY("ldo8", NULL),
94         REGULATOR_SUPPLY("vcore_audio", NULL),
95         REGULATOR_SUPPLY("avcore_audio", NULL),
96         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.2"),
97         REGULATOR_SUPPLY("pwrdet_sdmmc3", NULL),
98         REGULATOR_SUPPLY("vcore1_lpddr2", NULL),
99         REGULATOR_SUPPLY("vcom_1v8", NULL),
100         REGULATOR_SUPPLY("pmuio_1v8", NULL),
101         REGULATOR_SUPPLY("avdd_ic_usb", NULL),
102 };
103
104 static struct regulator_consumer_supply ricoh583_ldo0_supply_0[] = {
105         REGULATOR_SUPPLY("unused_ldo0", NULL),
106 };
107
108 static struct regulator_consumer_supply ricoh583_ldo1_supply_0[] = {
109         REGULATOR_SUPPLY("avdd_pexb", NULL),
110         REGULATOR_SUPPLY("vdd_pexb", NULL),
111         REGULATOR_SUPPLY("avdd_pex_pll", NULL),
112         REGULATOR_SUPPLY("avdd_pexa", NULL),
113         REGULATOR_SUPPLY("vdd_pexa", NULL),
114 };
115
116 static struct regulator_consumer_supply ricoh583_ldo2_supply_0[] = {
117         REGULATOR_SUPPLY("avdd_sata", NULL),
118         REGULATOR_SUPPLY("vdd_sata", NULL),
119         REGULATOR_SUPPLY("avdd_sata_pll", NULL),
120         REGULATOR_SUPPLY("avdd_plle", NULL),
121 };
122
123 static struct regulator_consumer_supply ricoh583_ldo3_supply_0[] = {
124         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.0"),
125         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
126 };
127
128 static struct regulator_consumer_supply ricoh583_ldo4_supply_0[] = {
129         REGULATOR_SUPPLY("vdd_rtc", NULL),
130 };
131
132 static struct regulator_consumer_supply ricoh583_ldo5_supply_0[] = {
133         REGULATOR_SUPPLY("avdd_vdac", NULL),
134 };
135
136 static struct regulator_consumer_supply ricoh583_ldo6_supply_0[] = {
137         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
138         REGULATOR_SUPPLY("pwrdet_mipi", NULL),
139 };
140 static struct regulator_consumer_supply ricoh583_ldo7_supply_0[] = {
141         REGULATOR_SUPPLY("avdd_plla_p_c_s", NULL),
142         REGULATOR_SUPPLY("avdd_pllm", NULL),
143         REGULATOR_SUPPLY("avdd_pllu_d", NULL),
144         REGULATOR_SUPPLY("avdd_pllu_d2", NULL),
145         REGULATOR_SUPPLY("avdd_pllx", NULL),
146 };
147
148 static struct regulator_consumer_supply ricoh583_ldo8_supply_0[] = {
149         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
150 };
151
152 #define RICOH_PDATA_INIT(_name, _sname, _minmv, _maxmv, _supply_reg, _always_on, \
153         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply, _flags,      \
154         _ext_contol, _ds_slots) \
155         static struct ricoh583_regulator_platform_data pdata_##_name##_##_sname = \
156         {                                                               \
157                 .regulator = {                                          \
158                         .constraints = {                                \
159                                 .min_uV = (_minmv)*1000,                \
160                                 .max_uV = (_maxmv)*1000,                \
161                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
162                                                      REGULATOR_MODE_STANDBY), \
163                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
164                                                    REGULATOR_CHANGE_STATUS |  \
165                                                    REGULATOR_CHANGE_VOLTAGE), \
166                                 .always_on = _always_on,                \
167                                 .boot_on = _boot_on,                    \
168                                 .apply_uV = _apply_uv,                  \
169                         },                                              \
170                         .num_consumer_supplies =                        \
171                                 ARRAY_SIZE(ricoh583_##_name##_supply_##_sname), \
172                         .consumer_supplies = ricoh583_##_name##_supply_##_sname, \
173                         .supply_regulator = _supply_reg,                \
174                 },                                                      \
175                 .init_uV =  _init_uV * 1000,                            \
176                 .init_enable = _init_enable,                            \
177                 .init_apply = _init_apply,                              \
178                 .deepsleep_slots = _ds_slots,                           \
179                 .flags = _flags,                                        \
180                 .ext_pwr_req = _ext_contol,                             \
181         }
182
183 RICOH_PDATA_INIT(dc0, 0,         700,  1500, 0, 1, 1, 0, -1, 0, 0, 0,
184                                 RICOH583_EXT_PWRREQ2_CONTROL, 0);
185 RICOH_PDATA_INIT(dc1, skubit0_0, 700,  1500, 0, 1, 1, 0, -1, 0, 0, 0, 0, 0);
186 RICOH_PDATA_INIT(dc2, 0,         900,  2400, 0, 1, 1, 0, -1, 0, 0, 0, 0, 0);
187 RICOH_PDATA_INIT(dc3, 0,         900,  2400, 0, 1, 1, 0, -1, 0, 0, 0, 0, 0);
188
189 RICOH_PDATA_INIT(ldo0, 0,         1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
190 RICOH_PDATA_INIT(ldo1, 0,         1000, 3300, ricoh583_rails(DC1), 0, 0, 0, -1, 0, 0, 0, 0, 0);
191 RICOH_PDATA_INIT(ldo2, 0,         1050, 1050, ricoh583_rails(DC1), 0, 0, 1, -1, 0, 0, 0, 0, 0);
192
193 RICOH_PDATA_INIT(ldo3, 0,         1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
194 RICOH_PDATA_INIT(ldo4, 0,         750,  1500, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
195 RICOH_PDATA_INIT(ldo5, 0,         1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
196
197 RICOH_PDATA_INIT(ldo6, 0,         1200, 1200, ricoh583_rails(DC2), 0, 0, 1, -1, 0, 0, 0, 0, 0);
198 RICOH_PDATA_INIT(ldo7, 0,         1200, 1200, ricoh583_rails(DC2), 1, 1, 1, -1, 0, 0, 0, 0, 0);
199 RICOH_PDATA_INIT(ldo8, 0,         900, 3400, ricoh583_rails(DC2), 1, 0, 0, -1, 0, 0, 0, 0, 0);
200
201 static struct ricoh583_rtc_platform_data rtc_data = {
202         .irq = TEGRA_NR_IRQS + RICOH583_IRQ_YALE,
203         .time = {
204                 .tm_year = 2011,
205                 .tm_mon = 0,
206                 .tm_mday = 1,
207                 .tm_hour = 0,
208                 .tm_min = 0,
209                 .tm_sec = 0,
210         },
211 };
212
213 #define RICOH_RTC_REG()                         \
214 {                                               \
215         .id     = 0,                            \
216         .name   = "rtc_ricoh583",               \
217         .platform_data = &rtc_data,             \
218 }
219
220 #define RICOH_REG(_id, _name, _sname)                   \
221 {                                                       \
222         .id     = RICOH583_ID_##_id,                    \
223         .name   = "ricoh583-regulator",                 \
224         .platform_data  = &pdata_##_name##_##_sname,    \
225 }
226
227 #define RICOH583_DEV_COMMON_E118X               \
228         RICOH_REG(DC0, dc0, 0),                 \
229         RICOH_REG(DC1, dc1, skubit0_0),         \
230         RICOH_REG(DC2, dc2, 0),         \
231         RICOH_REG(DC3, dc3, 0),         \
232         RICOH_REG(LDO0, ldo8, 0),               \
233         RICOH_REG(LDO1, ldo7, 0),               \
234         RICOH_REG(LDO2, ldo6, 0),               \
235         RICOH_REG(LDO3, ldo5, 0),               \
236         RICOH_REG(LDO4, ldo4, 0),               \
237         RICOH_REG(LDO5, ldo3, 0),               \
238         RICOH_REG(LDO6, ldo0, 0),               \
239         RICOH_REG(LDO7, ldo1, 0),               \
240         RICOH_REG(LDO8, ldo2, 0),               \
241         RICOH_RTC_REG()
242
243 static struct ricoh583_subdev_info ricoh_devs_e118x_dcdc[] = {
244         RICOH583_DEV_COMMON_E118X,
245 };
246
247 #define RICOH_GPIO_INIT(_init_apply, _pulldn, _output_mode, _output_val) \
248         {                                       \
249                 .pulldn_en = _pulldn,           \
250                 .output_mode_en = _output_mode, \
251                 .output_val = _output_val,      \
252                 .init_apply = _init_apply,      \
253         }
254 struct ricoh583_gpio_init_data ricoh_gpio_data[] = {
255         RICOH_GPIO_INIT(false, false, false, 0),
256         RICOH_GPIO_INIT(false, false, false, 0),
257         RICOH_GPIO_INIT(false, false, false, 0),
258         RICOH_GPIO_INIT(true,  false,  true, 1),
259         RICOH_GPIO_INIT(true,  false, true, 1),
260         RICOH_GPIO_INIT(false, false, false, 0),
261         RICOH_GPIO_INIT(false, false, false, 0),
262         RICOH_GPIO_INIT(false, false, false, 0),
263 };
264
265 static struct ricoh583_platform_data ricoh_platform = {
266         .irq_base       = RICOH583_IRQ_BASE,
267         .gpio_base      = RICOH583_GPIO_BASE,
268         .gpio_init_data = ricoh_gpio_data,
269         .num_gpioinit_data = ARRAY_SIZE(ricoh_gpio_data),
270         .enable_shutdown_pin = true,
271 };
272
273 static struct i2c_board_info __initdata ricoh583_regulators[] = {
274         {
275                 I2C_BOARD_INFO("ricoh583", 0x34),
276                 .irq            = INT_EXTERNAL_PMU,
277                 .platform_data  = &ricoh_platform,
278         },
279 };
280
281 /* TPS62361B DC-DC converter */
282 static struct regulator_consumer_supply tps6236x_dcdc_supply[] = {
283         REGULATOR_SUPPLY("vdd_core", NULL),
284 };
285
286 static struct tps6236x_regulator_platform_data tps6236x_pdata = {
287         .reg_init_data = {                                      \
288                 .constraints = {                                \
289                         .min_uV = 500000,                       \
290                         .max_uV = 1770000,                      \
291                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
292                                              REGULATOR_MODE_STANDBY), \
293                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
294                                            REGULATOR_CHANGE_STATUS |  \
295                                            REGULATOR_CHANGE_VOLTAGE), \
296                         .always_on = 1,                         \
297                         .boot_on =  1,                          \
298                         .apply_uV = 0,                          \
299                 },                                              \
300                 .num_consumer_supplies = ARRAY_SIZE(tps6236x_dcdc_supply), \
301                 .consumer_supplies = tps6236x_dcdc_supply,              \
302                 },                                                      \
303         .internal_pd_enable = 0,                                        \
304         .vsel = 3,                                                      \
305         .init_uV = -1,                                                  \
306         .init_apply = 0,                                                \
307 };
308
309 static struct i2c_board_info __initdata tps6236x_boardinfo[] = {
310         {
311                 I2C_BOARD_INFO("tps62361B", 0x60),
312                 .platform_data  = &tps6236x_pdata,
313         },
314 };
315
316 int __init cardhu_pm299_regulator_init(void)
317 {
318         struct board_info board_info;
319         struct board_info pmu_board_info;
320         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
321         u32 pmc_ctrl;
322
323         /* configure the power management controller to trigger PMU
324          * interrupts when low */
325         pmc_ctrl = readl(pmc + PMC_CTRL);
326         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
327
328         /* The regulator details have complete constraints */
329         tegra_get_board_info(&board_info);
330         tegra_get_pmu_board_info(&pmu_board_info);
331         if (pmu_board_info.board_id != BOARD_PMU_PM299) {
332                 pr_err("%s(): Board ID is not proper\n", __func__);
333                 return -ENODEV;
334         }
335
336         /* If TPS6236x DCDC is there then consumer for dc1 should
337          * not have vdd_core */
338         if ((board_info.sku & SKU_DCDC_TPS62361_SUPPORT) ||
339                         (pmu_board_info.sku & SKU_DCDC_TPS62361_SUPPORT)) {
340                 pdata_dc1_skubit0_0.regulator.consumer_supplies =
341                                         ricoh583_dc1_supply_skubit0_1;
342                 pdata_dc1_skubit0_0.regulator.num_consumer_supplies =
343                                 ARRAY_SIZE(ricoh583_dc1_supply_skubit0_1);
344         }
345
346         ricoh_platform.num_subdevs = ARRAY_SIZE(ricoh_devs_e118x_dcdc);
347         ricoh_platform.subdevs = ricoh_devs_e118x_dcdc;
348
349         i2c_register_board_info(4, ricoh583_regulators, 1);
350
351         /* Register the TPS6236x for all boards whose sku bit 0 is set. */
352         if ((board_info.sku & SKU_DCDC_TPS62361_SUPPORT) ||
353                         (pmu_board_info.sku & SKU_DCDC_TPS62361_SUPPORT)) {
354                 pr_info("Registering the device TPS62361B\n");
355                 i2c_register_board_info(4, tps6236x_boardinfo, 1);
356         }
357         return 0;
358 }
359
360 /* EN_5V_CP from PMU GP0 */
361 static struct regulator_consumer_supply fixed_reg_en_5v_cp_supply[] = {
362         REGULATOR_SUPPLY("vdd_5v0_sby", NULL),
363         REGULATOR_SUPPLY("vdd_hall", NULL),
364         REGULATOR_SUPPLY("vterm_ddr", NULL),
365         REGULATOR_SUPPLY("v2ref_ddr", NULL),
366 };
367
368 /* EN_5V0 From PMU GP2 */
369 static struct regulator_consumer_supply fixed_reg_en_5v0_supply[] = {
370         REGULATOR_SUPPLY("vdd_5v0_sys", NULL),
371 };
372
373 /* EN_DDR From PMU GP6 */
374 static struct regulator_consumer_supply fixed_reg_en_ddr_supply[] = {
375         REGULATOR_SUPPLY("mem_vddio_ddr", NULL),
376         REGULATOR_SUPPLY("t30_vddio_ddr", NULL),
377 };
378
379 /* EN_3V3_SYS From PMU GP7 */
380 static struct regulator_consumer_supply fixed_reg_en_3v3_sys_supply[] = {
381         REGULATOR_SUPPLY("vdd_lvds", NULL),
382         REGULATOR_SUPPLY("vdd_pnl", NULL),
383         REGULATOR_SUPPLY("vcom_3v3", NULL),
384         REGULATOR_SUPPLY("vdd_3v3", NULL),
385         REGULATOR_SUPPLY("vcore_mmc", NULL),
386         REGULATOR_SUPPLY("vddio_pex_ctl", NULL),
387         REGULATOR_SUPPLY("pwrdet_pex_ctl", NULL),
388         REGULATOR_SUPPLY("hvdd_pex_pmu", NULL),
389         REGULATOR_SUPPLY("avdd_hdmi", NULL),
390         REGULATOR_SUPPLY("vpp_fuse", NULL),
391         REGULATOR_SUPPLY("avdd_usb", NULL),
392         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
393         REGULATOR_SUPPLY("vcore_nand", NULL),
394         REGULATOR_SUPPLY("hvdd_sata", NULL),
395         REGULATOR_SUPPLY("vddio_gmi_pmu", NULL),
396         REGULATOR_SUPPLY("pwrdet_nand", NULL),
397         REGULATOR_SUPPLY("avdd_cam1", NULL),
398         REGULATOR_SUPPLY("vdd_af", NULL),
399         REGULATOR_SUPPLY("avdd_cam2", NULL),
400         REGULATOR_SUPPLY("vdd_acc", NULL),
401         REGULATOR_SUPPLY("vdd_phtl", NULL),
402         REGULATOR_SUPPLY("vddio_tp", NULL),
403         REGULATOR_SUPPLY("vdd_led", NULL),
404         REGULATOR_SUPPLY("vddio_cec", NULL),
405         REGULATOR_SUPPLY("vdd_cmps", NULL),
406         REGULATOR_SUPPLY("vdd_temp", NULL),
407         REGULATOR_SUPPLY("vpp_kfuse", NULL),
408         REGULATOR_SUPPLY("vddio_ts", NULL),
409         REGULATOR_SUPPLY("vdd_ir_led", NULL),
410         REGULATOR_SUPPLY("vddio_1wire", NULL),
411         REGULATOR_SUPPLY("avddio_audio", NULL),
412         REGULATOR_SUPPLY("vdd_ec", NULL),
413         REGULATOR_SUPPLY("vcom_pa", NULL),
414         REGULATOR_SUPPLY("vdd_3v3_devices", NULL),
415         REGULATOR_SUPPLY("vdd_3v3_dock", NULL),
416         REGULATOR_SUPPLY("vdd_3v3_edid", NULL),
417         REGULATOR_SUPPLY("vdd_3v3_hdmi_cec", NULL),
418         REGULATOR_SUPPLY("vdd_3v3_gmi", NULL),
419         REGULATOR_SUPPLY("vdd_3v3_spk_amp", NULL),
420         REGULATOR_SUPPLY("vdd_3v3_sensor", NULL),
421         REGULATOR_SUPPLY("vdd_3v3_cam", NULL),
422         REGULATOR_SUPPLY("vdd_3v3_als", NULL),
423         REGULATOR_SUPPLY("debug_cons", NULL),
424 };
425
426 /* DIS_5V_SWITCH from AP SPI2_SCK X02 */
427 static struct regulator_consumer_supply fixed_reg_dis_5v_switch_supply[] = {
428         REGULATOR_SUPPLY("master_5v_switch", NULL),
429 };
430
431 /* EN_VDD_BL */
432 static struct regulator_consumer_supply fixed_reg_en_vdd_bl_supply[] = {
433         REGULATOR_SUPPLY("vdd_backlight", NULL),
434         REGULATOR_SUPPLY("vdd_backlight1", NULL),
435 };
436
437 /* EN_3V3_MODEM from AP GPIO VI_VSYNCH D06*/
438 static struct regulator_consumer_supply fixed_reg_en_3v3_modem_supply[] = {
439         REGULATOR_SUPPLY("vdd_3v3_mini_card", NULL),
440         REGULATOR_SUPPLY("vdd_mini_card", NULL),
441 };
442
443 /* EN_VDD_PNL1 from AP GPIO VI_D6 L04*/
444 static struct regulator_consumer_supply fixed_reg_en_vdd_pnl1_supply[] = {
445         REGULATOR_SUPPLY("vdd_lcd_panel", NULL),
446 };
447
448 /* CAM1_LDO_EN from AP GPIO KB_ROW6 R06*/
449 static struct regulator_consumer_supply fixed_reg_cam1_ldo_en_supply[] = {
450         REGULATOR_SUPPLY("vdd_2v8_cam1", NULL),
451         REGULATOR_SUPPLY("vdd", "6-0072"),
452 };
453
454 /* CAM2_LDO_EN from AP GPIO KB_ROW7 R07*/
455 static struct regulator_consumer_supply fixed_reg_cam2_ldo_en_supply[] = {
456         REGULATOR_SUPPLY("vdd_2v8_cam2", NULL),
457         REGULATOR_SUPPLY("vdd", "7-0072"),
458 };
459
460 /* CAM3_LDO_EN from AP GPIO KB_ROW8 S00*/
461 static struct regulator_consumer_supply fixed_reg_cam3_ldo_en_supply[] = {
462         REGULATOR_SUPPLY("vdd_cam3", NULL),
463 };
464
465 /* EN_VDD_COM from AP GPIO SDMMC3_DAT5 D00*/
466 static struct regulator_consumer_supply fixed_reg_en_vdd_com_supply[] = {
467         REGULATOR_SUPPLY("vdd_com_bd", NULL),
468 };
469
470 /* EN_VDD_SDMMC1 from AP GPIO VI_HSYNC D07*/
471 static struct regulator_consumer_supply fixed_reg_en_vdd_sdmmc1_supply[] = {
472         REGULATOR_SUPPLY("vddio_sd_slot", "sdhci-tegra.0"),
473 };
474
475 /* EN_3V3_EMMC from AP GPIO SDMMC3_DAT4 D01*/
476 static struct regulator_consumer_supply fixed_reg_en_3v3_emmc_supply[] = {
477         REGULATOR_SUPPLY("vdd_emmc_core", NULL),
478 };
479
480 /* EN_3V3_PEX_HVDD from AP GPIO VI_D09 L07*/
481 static struct regulator_consumer_supply fixed_reg_en_3v3_pex_hvdd_supply[] = {
482         REGULATOR_SUPPLY("hvdd_pex", NULL),
483 };
484
485 /* EN_3v3_FUSE from AP GPIO VI_D08 L06*/
486 static struct regulator_consumer_supply fixed_reg_en_3v3_fuse_supply[] = {
487         REGULATOR_SUPPLY("vdd_fuse", NULL),
488 };
489
490 /* EN_1V8_CAM from AP GPIO GPIO_PBB4 PBB04*/
491 static struct regulator_consumer_supply fixed_reg_en_1v8_cam_supply[] = {
492         REGULATOR_SUPPLY("vdd_1v8_cam1", NULL),
493         REGULATOR_SUPPLY("vdd_1v8_cam2", NULL),
494         REGULATOR_SUPPLY("vdd_1v8_cam3", NULL),
495         REGULATOR_SUPPLY("vdd_i2c", "6-0072"),
496         REGULATOR_SUPPLY("vdd_i2c", "7-0072"),
497         REGULATOR_SUPPLY("vdd_i2c", "2-0033"),
498 };
499
500 static struct regulator_consumer_supply fixed_reg_en_vbrtr_supply[] = {
501         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
502 };
503
504
505 /* EN_USB1_VBUS_OC*/
506 static struct regulator_consumer_supply gpio_switch_en_usb1_vbus_oc_supply[] = {
507         REGULATOR_SUPPLY("vdd_vbus_micro_usb", NULL),
508 };
509 static int gpio_switch_en_usb1_vbus_oc_voltages[] = { 5000};
510
511 /*EN_USB3_VBUS_OC*/
512 static struct regulator_consumer_supply gpio_switch_en_usb3_vbus_oc_supply[] = {
513         REGULATOR_SUPPLY("vdd_vbus_typea_usb", NULL),
514 };
515 static int gpio_switch_en_usb3_vbus_oc_voltages[] = { 5000};
516
517 /* EN_VDDIO_VID_OC from AP GPIO VI_PCLK T00*/
518 static struct regulator_consumer_supply gpio_switch_en_vddio_vid_oc_supply[] = {
519         REGULATOR_SUPPLY("vdd_hdmi_con", NULL),
520 };
521 static int gpio_switch_en_vddio_vid_oc_voltages[] = { 5000};
522
523 static int enable_load_switch_rail(
524                 struct gpio_switch_regulator_subdev_data *psubdev_data)
525 {
526         int ret;
527
528         if (psubdev_data->pin_group <= 0)
529                 return -EINVAL;
530
531         /* Tristate and make pin as input*/
532         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
533                                                 TEGRA_TRI_TRISTATE);
534         if (ret < 0)
535                 return ret;
536         return gpio_direction_input(psubdev_data->gpio_nr);
537 }
538
539 static int disable_load_switch_rail(
540                 struct gpio_switch_regulator_subdev_data *psubdev_data)
541 {
542         int ret;
543
544         if (psubdev_data->pin_group <= 0)
545                 return -EINVAL;
546
547         /* Un-tristate and driver low */
548         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
549                                                 TEGRA_TRI_NORMAL);
550         if (ret < 0)
551                 return ret;
552         return gpio_direction_output(psubdev_data->gpio_nr, 0);
553 }
554
555 /* Macro for defining gpio switch regulator sub device data */
556 #define GREG_INIT(_id, _var, _name, _input_supply, _always_on, _boot_on, \
557         _gpio_nr, _active_low, _init_state, _pg, _enable, _disable)      \
558         static struct gpio_switch_regulator_subdev_data gpio_pdata_##_var =  \
559         {                                                               \
560                 .regulator_name = "gpio-switch-"#_name,                 \
561                 .input_supply   = _input_supply,                        \
562                 .id             = _id,                                  \
563                 .gpio_nr        = _gpio_nr,                             \
564                 .pin_group      = _pg,                                  \
565                 .active_low     = _active_low,                          \
566                 .init_state     = _init_state,                          \
567                 .voltages       = gpio_switch_##_name##_voltages,       \
568                 .n_voltages     = ARRAY_SIZE(gpio_switch_##_name##_voltages), \
569                 .num_consumer_supplies =                                \
570                                 ARRAY_SIZE(gpio_switch_##_name##_supply), \
571                 .consumer_supplies = gpio_switch_##_name##_supply,      \
572                 .constraints = {                                        \
573                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
574                                              REGULATOR_MODE_STANDBY),   \
575                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
576                                            REGULATOR_CHANGE_STATUS |    \
577                                            REGULATOR_CHANGE_VOLTAGE),   \
578                         .always_on = _always_on,                        \
579                         .boot_on = _boot_on,                            \
580                 },                                                      \
581                 .enable_rail = _enable,                                 \
582                 .disable_rail = _disable,                               \
583         };                                                              \
584         static struct gpio_switch_regulator_subdev_data                 \
585                                 *gpio_pdata_##_var##_list[] = { \
586                 &gpio_pdata_##_var,                                     \
587         };                                                              \
588         static struct gpio_switch_regulator_platform_data gs_##_var##_pdata = \
589         {                                                               \
590                 .num_subdevs = 1,                                       \
591                 .subdevs = gpio_pdata_##_var##_list,                    \
592         };                                                              \
593         static struct platform_device gswitch_reg_##_var##_dev = {      \
594                 .name = "gpio-switch-regulator",                        \
595                 .id   = _id,                                            \
596                 .dev  = {                                               \
597                      .platform_data = &gs_##_var##_pdata,               \
598                 },                                                      \
599         }
600
601 /* Macro for defining fixed regulator sub device data */
602 #define FIXED_SUPPLY(_name) "fixed_reg_"#_name
603 #define FIXED_REG(_id, _var, _name, _in_supply, _always_on, _boot_on,   \
604                  _gpio_nr, _active_high, _boot_state, _millivolts)      \
605         static struct regulator_init_data ri_data_##_var =              \
606         {                                                               \
607                 .supply_regulator = _in_supply,                         \
608                 .num_consumer_supplies =                                \
609                         ARRAY_SIZE(fixed_reg_##_name##_supply),         \
610                 .consumer_supplies = fixed_reg_##_name##_supply,        \
611                 .constraints = {                                        \
612                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
613                                         REGULATOR_MODE_STANDBY),        \
614                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
615                                         REGULATOR_CHANGE_STATUS |       \
616                                         REGULATOR_CHANGE_VOLTAGE),      \
617                         .always_on = _always_on,                        \
618                         .boot_on = _boot_on,                            \
619                 },                                                      \
620         };                                                              \
621         static struct fixed_voltage_config fixed_reg_##_var##_pdata =   \
622         {                                                               \
623                 .supply_name = FIXED_SUPPLY(_name),                     \
624                 .microvolts = _millivolts * 1000,                       \
625                 .gpio = _gpio_nr,                                       \
626                 .enable_high = _active_high,                            \
627                 .enabled_at_boot = _boot_state,                         \
628                 .init_data = &ri_data_##_var,                           \
629         };                                                              \
630         static struct platform_device fixed_reg_##_var##_dev = {        \
631                 .name   = "reg-fixed-voltage",                          \
632                 .id     = _id,                                          \
633                 .dev    = {                                             \
634                         .platform_data = &fixed_reg_##_var##_pdata,     \
635                 },                                                      \
636         }
637
638 /* common to most of boards*/
639 FIXED_REG(0, en_5v_cp,          en_5v_cp,       NULL,                   1,      0,      TPS6591X_GPIO_0,        true,   1, 5000);
640 FIXED_REG(1, en_5v0,            en_5v0,         NULL,                   0,      0,      TPS6591X_GPIO_4,        true,   0, 5000);
641 FIXED_REG(2, en_ddr,            en_ddr,         NULL,                   0,      0,      TPS6591X_GPIO_3,        true,   1, 1500);
642 FIXED_REG(3, en_3v3_sys,        en_3v3_sys,     NULL,                   0,      0,      TPS6591X_GPIO_1,        true,   0, 3300);
643 FIXED_REG(4, en_vdd_bl,         en_vdd_bl,      NULL,                   0,      0,      TEGRA_GPIO_PK3,         true,   1, 5000);
644 FIXED_REG(5, en_3v3_modem,      en_3v3_modem,   NULL,                   1,      0,      TEGRA_GPIO_PD6,         true,   1, 3300);
645 FIXED_REG(6, en_vdd_pnl1,       en_vdd_pnl1,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PL4,         true,   1, 3300);
646 FIXED_REG(7, cam3_ldo_en,       cam3_ldo_en,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PS0,         true,   0, 3300);
647 FIXED_REG(8, en_vdd_com,        en_vdd_com,     FIXED_SUPPLY(en_3v3_sys),       1,      0,      TEGRA_GPIO_PD0,         true,   1, 3300);
648 FIXED_REG(9, en_3v3_fuse,       en_3v3_fuse,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PL6,         true,   0, 3300);
649 FIXED_REG(10, en_3v3_emmc,      en_3v3_emmc,    FIXED_SUPPLY(en_3v3_sys),       1,      0,      TEGRA_GPIO_PD1,         true,   1, 3300);
650 FIXED_REG(11, en_vdd_sdmmc1,    en_vdd_sdmmc1,  FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PD7,         true,   1, 3300);
651 FIXED_REG(12, en_3v3_pex_hvdd,  en_3v3_pex_hvdd, FIXED_SUPPLY(en_3v3_sys),      0,      0,      TEGRA_GPIO_PL7,         true,   0, 3300);
652 FIXED_REG(13, en_1v8_cam,       en_1v8_cam,     ricoh583_rails(DC2),            0,      0,      TEGRA_GPIO_PBB4,        true,   0, 1800);
653
654 /* E1198/E1291 specific*/
655 FIXED_REG(18, cam1_ldo_en,      cam1_ldo_en,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PR6,         true,   0, 2800);
656 FIXED_REG(19, cam2_ldo_en,      cam2_ldo_en,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PR7,         true,   0, 2800);
657 FIXED_REG(22, en_vbrtr,         en_vbrtr,       FIXED_SUPPLY(en_3v3_sys),       0,      0,      PMU_TCA6416_GPIO_PORT12,true,   0, 3300);
658
659 /*Specific to pm269*/
660 FIXED_REG(4, en_vdd_bl_pm269,           en_vdd_bl,              NULL,                           0,      0,      TEGRA_GPIO_PH3, true,   1, 5000);
661 FIXED_REG(6, en_vdd_pnl1_pm269,         en_vdd_pnl1,            FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PW1, true,   1, 3300);
662 FIXED_REG(9, en_3v3_fuse_pm269,         en_3v3_fuse,            FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PC1, true,   0, 3300);
663 FIXED_REG(11, en_vdd_sdmmc1_pm269,      en_vdd_sdmmc1,          FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PP1, true,   1, 3300);
664 FIXED_REG(12, en_3v3_pex_hvdd_pm269,    en_3v3_pex_hvdd,        FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PC6, true,   0, 3300);
665
666 /* Specific to E1187/E1186/E1256 */
667 FIXED_REG(14, dis_5v_switch_e118x,      dis_5v_switch,          FIXED_SUPPLY(en_5v0),           0,      0,      TEGRA_GPIO_PX2, false,  0, 5000);
668
669 /*** Open collector load switches ************/
670 /*Specific to pm269*/
671 GREG_INIT(17, en_vddio_vid_oc_pm269,    en_vddio_vid_oc,        "master_5v_switch",
672         0,      0,      TEGRA_GPIO_PP2, false,  0,      TEGRA_PINGROUP_DAP3_DOUT,
673         enable_load_switch_rail, disable_load_switch_rail);
674
675 /* Specific to E1187/E1186/E1256 */
676 GREG_INIT(15, en_usb1_vbus_oc_e118x,    en_usb1_vbus_oc,        "master_5v_switch",
677                 0,      0,      TEGRA_GPIO_PI4,         false,  0,      TEGRA_PINGROUP_GMI_RST_N,
678                 enable_load_switch_rail, disable_load_switch_rail);
679 GREG_INIT(16, en_usb3_vbus_oc_e118x,    en_usb3_vbus_oc,        "master_5v_switch",
680                 0,      0,      TEGRA_GPIO_PH7,         false,  0,      TEGRA_PINGROUP_GMI_AD15,
681                 enable_load_switch_rail, disable_load_switch_rail);
682 GREG_INIT(17, en_vddio_vid_oc_e118x,    en_vddio_vid_oc,        "master_5v_switch",
683                 0,      0,      TEGRA_GPIO_PT0,         false,  0,      TEGRA_PINGROUP_VI_PCLK,
684                 enable_load_switch_rail, disable_load_switch_rail);
685
686 /*
687  * Creating the fixed/gpio-switch regulator device tables for different boards
688  */
689 #define ADD_FIXED_REG(_name)    (&fixed_reg_##_name##_dev)
690 #define ADD_GPIO_REG(_name)     (&gswitch_reg_##_name##_dev)
691
692 #define COMMON_FIXED_REG                        \
693         ADD_FIXED_REG(en_5v_cp),                \
694         ADD_FIXED_REG(en_5v0),                  \
695         ADD_FIXED_REG(en_ddr),                  \
696         ADD_FIXED_REG(en_3v3_sys),              \
697         ADD_FIXED_REG(en_3v3_modem),            \
698         ADD_FIXED_REG(en_vdd_pnl1),             \
699         ADD_FIXED_REG(cam1_ldo_en),             \
700         ADD_FIXED_REG(cam2_ldo_en),             \
701         ADD_FIXED_REG(cam3_ldo_en),             \
702         ADD_FIXED_REG(en_vdd_com),              \
703         ADD_FIXED_REG(en_3v3_fuse),             \
704         ADD_FIXED_REG(en_3v3_emmc),             \
705         ADD_FIXED_REG(en_vdd_sdmmc1),           \
706         ADD_FIXED_REG(en_3v3_pex_hvdd),         \
707         ADD_FIXED_REG(en_1v8_cam),
708
709 #define PM269_FIXED_REG                         \
710         ADD_FIXED_REG(en_5v_cp),                \
711         ADD_FIXED_REG(en_5v0),                  \
712         ADD_FIXED_REG(en_ddr),                  \
713         ADD_FIXED_REG(en_vdd_bl_pm269),         \
714         ADD_FIXED_REG(en_3v3_sys),              \
715         ADD_FIXED_REG(en_3v3_modem),            \
716         ADD_FIXED_REG(en_vdd_pnl1_pm269),       \
717         ADD_FIXED_REG(cam1_ldo_en),             \
718         ADD_FIXED_REG(cam2_ldo_en),             \
719         ADD_FIXED_REG(cam3_ldo_en),             \
720         ADD_FIXED_REG(en_vdd_com),              \
721         ADD_FIXED_REG(en_3v3_fuse_pm269),       \
722         ADD_FIXED_REG(en_3v3_emmc),             \
723         ADD_FIXED_REG(en_vdd_sdmmc1_pm269),     \
724         ADD_FIXED_REG(en_3v3_pex_hvdd_pm269),   \
725         ADD_FIXED_REG(en_1v8_cam),              \
726         ADD_FIXED_REG(dis_5v_switch_e118x),     \
727         ADD_GPIO_REG(en_usb1_vbus_oc_e118x),    \
728         ADD_GPIO_REG(en_usb3_vbus_oc_e118x),    \
729         ADD_GPIO_REG(en_vddio_vid_oc_pm269),
730
731 #define E118x_FIXED_REG                         \
732         ADD_FIXED_REG(en_vdd_bl),               \
733         ADD_FIXED_REG(dis_5v_switch_e118x),     \
734         ADD_FIXED_REG(en_vbrtr),                \
735         ADD_GPIO_REG(en_usb1_vbus_oc_e118x),    \
736         ADD_GPIO_REG(en_usb3_vbus_oc_e118x),    \
737         ADD_GPIO_REG(en_vddio_vid_oc_e118x),    \
738
739 /* Gpio switch regulator platform data  for E1186/E1187/E1256*/
740 static struct platform_device *fixed_reg_devs_e118x[] = {
741         COMMON_FIXED_REG
742         E118x_FIXED_REG
743 };
744
745 /* Gpio switch regulator platform data for PM269*/
746 static struct platform_device *fixed_reg_devs_pm269[] = {
747         PM269_FIXED_REG
748 };
749
750 int __init cardhu_pm299_gpio_switch_regulator_init(void)
751 {
752         int i;
753         struct board_info board_info;
754         struct platform_device **fixed_reg_devs;
755         int    nfixreg_devs;
756
757         tegra_get_board_info(&board_info);
758
759         switch (board_info.board_id) {
760         case BOARD_PM269:
761         case BOARD_PM305:
762         case BOARD_PM311:
763         case BOARD_E1257:
764                 nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm269);
765                 fixed_reg_devs = fixed_reg_devs_pm269;
766                 break;
767
768         default:
769                 nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e118x);
770                 fixed_reg_devs = fixed_reg_devs_e118x;
771                 break;
772         }
773
774         for (i = 0; i < nfixreg_devs; ++i) {
775                 int gpio_nr;
776                 if (!strncmp(fixed_reg_devs[i]->name, "gpio", 4)) {
777                         struct gpio_switch_regulator_platform_data *gs_pdata =
778                                 fixed_reg_devs[i]->dev.platform_data;
779                         gpio_nr = gs_pdata->subdevs[0]->gpio_nr;
780                 } else {
781                         struct fixed_voltage_config *fixed_reg_pdata =
782                                 fixed_reg_devs[i]->dev.platform_data;
783                         gpio_nr = fixed_reg_pdata->gpio;
784                 }
785
786                 if (gpio_nr < TEGRA_NR_GPIOS)
787                         tegra_gpio_enable(gpio_nr);
788         }
789         return platform_add_devices(fixed_reg_devs, nfixreg_devs);
790 }