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