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