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