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