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