arm: tegra: Specify correct dev name for audio regulators
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-power.c
1 /*
2  * arch/arm/mach-tegra/board-cardhu-power.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/tps6591x.h>
26 #include <linux/mfd/max77663-core.h>
27 #include <linux/gpio.h>
28 #include <linux/io.h>
29 #include <linux/regulator/gpio-switch-regulator.h>
30 #include <linux/regulator/fixed.h>
31 #include <linux/regulator/tps6591x-regulator.h>
32 #include <linux/regulator/tps62360.h>
33 #include <linux/power/gpio-charger.h>
34
35 #include <asm/mach-types.h>
36
37 #include <mach/iomap.h>
38 #include <mach/irqs.h>
39 #include <mach/pinmux.h>
40 #include <mach/edp.h>
41
42 #include "gpio-names.h"
43 #include "board.h"
44 #include "board-cardhu.h"
45 #include "pm.h"
46 #include "wakeups-t3.h"
47 #include "tegra3_tsensor.h"
48
49 #define PMC_CTRL                0x0
50 #define PMC_CTRL_INTR_LOW       (1 << 17)
51
52 static struct regulator_consumer_supply tps6591x_vdd1_supply_skubit0_0[] = {
53         REGULATOR_SUPPLY("vdd_core", NULL),
54         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
55 };
56
57 static struct regulator_consumer_supply tps6591x_vdd1_supply_skubit0_1[] = {
58         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
59 };
60
61 static struct regulator_consumer_supply tps6591x_vdd2_supply_0[] = {
62         REGULATOR_SUPPLY("vdd_gen1v5", NULL),
63         REGULATOR_SUPPLY("vcore_lcd", NULL),
64         REGULATOR_SUPPLY("track_ldo1", NULL),
65         REGULATOR_SUPPLY("external_ldo_1v2", NULL),
66         REGULATOR_SUPPLY("vcore_cam1", NULL),
67         REGULATOR_SUPPLY("vcore_cam2", NULL),
68 };
69
70 static struct regulator_consumer_supply tps6591x_vddctrl_supply_0[] = {
71         REGULATOR_SUPPLY("vdd_cpu_pmu", NULL),
72         REGULATOR_SUPPLY("vdd_cpu", NULL),
73         REGULATOR_SUPPLY("vdd_sys", NULL),
74 };
75
76 static struct regulator_consumer_supply tps6591x_vio_supply_0[] = {
77         REGULATOR_SUPPLY("vdd_gen1v8", NULL),
78         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
79         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
80         REGULATOR_SUPPLY("avdd_osc", NULL),
81         REGULATOR_SUPPLY("vddio_sys", NULL),
82         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.3"),
83         REGULATOR_SUPPLY("pwrdet_sdmmc4", NULL),
84         REGULATOR_SUPPLY("vdd1v8_satelite", NULL),
85         REGULATOR_SUPPLY("vddio_uart", NULL),
86         REGULATOR_SUPPLY("pwrdet_uart", NULL),
87         REGULATOR_SUPPLY("vddio_audio", NULL),
88         REGULATOR_SUPPLY("pwrdet_audio", NULL),
89         REGULATOR_SUPPLY("vddio_bb", NULL),
90         REGULATOR_SUPPLY("pwrdet_bb", NULL),
91         REGULATOR_SUPPLY("vddio_lcd_pmu", NULL),
92         REGULATOR_SUPPLY("pwrdet_lcd", NULL),
93         REGULATOR_SUPPLY("vddio_cam", NULL),
94         REGULATOR_SUPPLY("pwrdet_cam", NULL),
95         REGULATOR_SUPPLY("vddio_vi", NULL),
96         REGULATOR_SUPPLY("pwrdet_vi", NULL),
97         REGULATOR_SUPPLY("ldo6", NULL),
98         REGULATOR_SUPPLY("ldo7", NULL),
99         REGULATOR_SUPPLY("ldo8", NULL),
100         REGULATOR_SUPPLY("vcore_audio", NULL),
101         REGULATOR_SUPPLY("avcore_audio", NULL),
102         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.2"),
103         REGULATOR_SUPPLY("pwrdet_sdmmc3", NULL),
104         REGULATOR_SUPPLY("vcore1_lpddr2", NULL),
105         REGULATOR_SUPPLY("vcom_1v8", NULL),
106         REGULATOR_SUPPLY("pmuio_1v8", NULL),
107         REGULATOR_SUPPLY("avdd_ic_usb", NULL),
108 };
109
110 static struct regulator_consumer_supply tps6591x_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 tps6591x_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 tps6591x_ldo3_supply_e118x[] = {
126         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.0"),
127         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
128 };
129
130 static struct regulator_consumer_supply tps6591x_ldo3_supply_e1198[] = {
131         REGULATOR_SUPPLY("unused_rail_ldo3", NULL),
132 };
133
134 static struct regulator_consumer_supply tps6591x_ldo4_supply_0[] = {
135         REGULATOR_SUPPLY("vdd_rtc", NULL),
136 };
137
138 static struct regulator_consumer_supply tps6591x_ldo5_supply_e118x[] = {
139         REGULATOR_SUPPLY("avdd_vdac", NULL),
140 };
141
142 static struct regulator_consumer_supply tps6591x_ldo5_supply_e1198[] = {
143         REGULATOR_SUPPLY("avdd_vdac", NULL),
144         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.0"),
145         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
146 };
147
148 static struct regulator_consumer_supply tps6591x_ldo6_supply_0[] = {
149         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
150         REGULATOR_SUPPLY("pwrdet_mipi", NULL),
151 };
152 static struct regulator_consumer_supply tps6591x_ldo7_supply_0[] = {
153         REGULATOR_SUPPLY("avdd_plla_p_c_s", NULL),
154         REGULATOR_SUPPLY("avdd_pllm", NULL),
155         REGULATOR_SUPPLY("avdd_pllu_d", NULL),
156         REGULATOR_SUPPLY("avdd_pllu_d2", NULL),
157         REGULATOR_SUPPLY("avdd_pllx", NULL),
158 };
159
160 static struct regulator_consumer_supply tps6591x_ldo8_supply_0[] = {
161         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
162 };
163
164 #define TPS_PDATA_INIT(_name, _sname, _minmv, _maxmv, _supply_reg, _always_on, \
165         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply, _ectrl, _flags) \
166         static struct tps6591x_regulator_platform_data pdata_##_name##_##_sname = \
167         {                                                               \
168                 .regulator = {                                          \
169                         .constraints = {                                \
170                                 .min_uV = (_minmv)*1000,                \
171                                 .max_uV = (_maxmv)*1000,                \
172                                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
173                                                      REGULATOR_MODE_STANDBY), \
174                                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
175                                                    REGULATOR_CHANGE_STATUS |  \
176                                                    REGULATOR_CHANGE_VOLTAGE), \
177                                 .always_on = _always_on,                \
178                                 .boot_on = _boot_on,                    \
179                                 .apply_uV = _apply_uv,                  \
180                         },                                              \
181                         .num_consumer_supplies =                        \
182                                 ARRAY_SIZE(tps6591x_##_name##_supply_##_sname), \
183                         .consumer_supplies = tps6591x_##_name##_supply_##_sname,        \
184                         .supply_regulator = _supply_reg,                \
185                 },                                                      \
186                 .init_uV =  _init_uV * 1000,                            \
187                 .init_enable = _init_enable,                            \
188                 .init_apply = _init_apply,                              \
189                 .ectrl = _ectrl,                                        \
190                 .flags = _flags,                                        \
191         }
192
193 TPS_PDATA_INIT(vdd1, skubit0_0, 600,  1500, 0, 1, 1, 0, -1, 0, 0, EXT_CTRL_SLEEP_OFF, 0);
194 TPS_PDATA_INIT(vdd1, skubit0_1, 600,  1500, 0, 1, 1, 0, -1, 0, 0, EXT_CTRL_SLEEP_OFF, 0);
195 TPS_PDATA_INIT(vdd2, 0,         600,  1500, 0, 1, 1, 0, -1, 0, 0, 0, 0);
196 TPS_PDATA_INIT(vddctrl, 0,      600,  1400, 0, 1, 1, 0, -1, 0, 0, EXT_CTRL_EN1, 0);
197 TPS_PDATA_INIT(vio,  0,         1500, 3300, 0, 1, 1, 0, -1, 0, 0, 0, 0);
198
199 TPS_PDATA_INIT(ldo1, 0,         1000, 3300, tps6591x_rails(VDD_2), 0, 0, 0, -1, 0, 1, 0, 0);
200 TPS_PDATA_INIT(ldo2, 0,         1050, 1050, tps6591x_rails(VDD_2), 0, 0, 1, -1, 0, 1, 0, 0);
201
202 TPS_PDATA_INIT(ldo3, e118x,     1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0);
203 TPS_PDATA_INIT(ldo3, e1198,     1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0);
204 TPS_PDATA_INIT(ldo4, 0,         1000, 3300, 0, 1, 0, 0, -1, 0, 0, 0, 0);
205 TPS_PDATA_INIT(ldo5, e118x,     1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0);
206 TPS_PDATA_INIT(ldo5, e1198,     1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0);
207
208 TPS_PDATA_INIT(ldo6, 0,         1200, 1200, tps6591x_rails(VIO), 0, 0, 1, -1, 0, 0, 0, 0);
209 TPS_PDATA_INIT(ldo7, 0,         1200, 1200, tps6591x_rails(VIO), 1, 1, 1, -1, 0, 0, EXT_CTRL_SLEEP_OFF, LDO_LOW_POWER_ON_SUSPEND);
210 TPS_PDATA_INIT(ldo8, 0,         1000, 3300, tps6591x_rails(VIO), 1, 0, 0, -1, 0, 0, EXT_CTRL_SLEEP_OFF, LDO_LOW_POWER_ON_SUSPEND);
211
212 #if defined(CONFIG_RTC_DRV_TPS6591x)
213 static struct tps6591x_rtc_platform_data rtc_data = {
214         .irq = TEGRA_NR_IRQS + TPS6591X_INT_RTC_ALARM,
215         .time = {
216                 .tm_year = 2000,
217                 .tm_mon = 0,
218                 .tm_mday = 1,
219                 .tm_hour = 0,
220                 .tm_min = 0,
221                 .tm_sec = 0,
222         },
223 };
224
225 #define TPS_RTC_REG()                                   \
226         {                                               \
227                 .id     = 0,                            \
228                 .name   = "rtc_tps6591x",               \
229                 .platform_data = &rtc_data,             \
230         }
231 #endif
232
233 #define TPS_REG(_id, _name, _sname)                             \
234         {                                                       \
235                 .id     = TPS6591X_ID_##_id,                    \
236                 .name   = "tps6591x-regulator",                 \
237                 .platform_data  = &pdata_##_name##_##_sname,    \
238         }
239
240 #define TPS6591X_DEV_COMMON_E118X               \
241         TPS_REG(VDD_2, vdd2, 0),                \
242         TPS_REG(VDDCTRL, vddctrl, 0),           \
243         TPS_REG(LDO_1, ldo1, 0),                \
244         TPS_REG(LDO_2, ldo2, 0),                \
245         TPS_REG(LDO_3, ldo3, e118x),            \
246         TPS_REG(LDO_4, ldo4, 0),                \
247         TPS_REG(LDO_5, ldo5, e118x),            \
248         TPS_REG(LDO_6, ldo6, 0),                \
249         TPS_REG(LDO_7, ldo7, 0),                \
250         TPS_REG(LDO_8, ldo8, 0)
251
252 static struct tps6591x_subdev_info tps_devs_e118x_skubit0_0[] = {
253         TPS_REG(VIO, vio, 0),
254         TPS_REG(VDD_1, vdd1, skubit0_0),
255         TPS6591X_DEV_COMMON_E118X,
256 #if defined(CONFIG_RTC_DRV_TPS6591x)
257         TPS_RTC_REG(),
258 #endif
259 };
260
261 static struct tps6591x_subdev_info tps_devs_e118x_skubit0_1[] = {
262         TPS_REG(VIO, vio, 0),
263         TPS_REG(VDD_1, vdd1, skubit0_1),
264         TPS6591X_DEV_COMMON_E118X,
265 #if defined(CONFIG_RTC_DRV_TPS6591x)
266         TPS_RTC_REG(),
267 #endif
268 };
269
270 #define TPS6591X_DEV_COMMON_CARDHU              \
271         TPS_REG(VDD_2, vdd2, 0),                \
272         TPS_REG(VDDCTRL, vddctrl, 0),           \
273         TPS_REG(LDO_1, ldo1, 0),                \
274         TPS_REG(LDO_2, ldo2, 0),                \
275         TPS_REG(LDO_3, ldo3, e1198),            \
276         TPS_REG(LDO_4, ldo4, 0),                \
277         TPS_REG(LDO_5, ldo5, e1198),            \
278         TPS_REG(LDO_6, ldo6, 0),                \
279         TPS_REG(LDO_7, ldo7, 0),                \
280         TPS_REG(LDO_8, ldo8, 0)
281
282 static struct tps6591x_subdev_info tps_devs_e1198_skubit0_0[] = {
283         TPS_REG(VIO, vio, 0),
284         TPS_REG(VDD_1, vdd1, skubit0_0),
285         TPS6591X_DEV_COMMON_CARDHU,
286 #if defined(CONFIG_RTC_DRV_TPS6591x)
287         TPS_RTC_REG(),
288 #endif
289 };
290
291 static struct tps6591x_subdev_info tps_devs_e1198_skubit0_1[] = {
292         TPS_REG(VIO, vio, 0),
293         TPS_REG(VDD_1, vdd1, skubit0_1),
294         TPS6591X_DEV_COMMON_CARDHU,
295 #if defined(CONFIG_RTC_DRV_TPS6591x)
296         TPS_RTC_REG(),
297 #endif
298 };
299
300 #define TPS_GPIO_INIT_PDATA(gpio_nr, _init_apply, _sleep_en, _pulldn_en, _output_en, _output_val)       \
301         [gpio_nr] = {                                   \
302                         .sleep_en       = _sleep_en,    \
303                         .pulldn_en      = _pulldn_en,   \
304                         .output_mode_en = _output_en,   \
305                         .output_val     = _output_val,  \
306                         .init_apply     = _init_apply,  \
307                      }
308 static struct tps6591x_gpio_init_data tps_gpio_pdata_e1291_a04[] =  {
309         TPS_GPIO_INIT_PDATA(0, 0, 0, 0, 0, 0),
310         TPS_GPIO_INIT_PDATA(1, 0, 0, 0, 0, 0),
311         TPS_GPIO_INIT_PDATA(2, 1, 1, 0, 1, 1),
312         TPS_GPIO_INIT_PDATA(3, 0, 0, 0, 0, 0),
313         TPS_GPIO_INIT_PDATA(4, 0, 0, 0, 0, 0),
314         TPS_GPIO_INIT_PDATA(5, 0, 0, 0, 0, 0),
315         TPS_GPIO_INIT_PDATA(6, 0, 0, 0, 0, 0),
316         TPS_GPIO_INIT_PDATA(7, 0, 0, 0, 0, 0),
317         TPS_GPIO_INIT_PDATA(8, 0, 0, 0, 0, 0),
318 };
319
320 static struct tps6591x_sleep_keepon_data tps_slp_keepon = {
321         .clkout32k_keepon = 1,
322 };
323
324 static struct tps6591x_platform_data tps_platform = {
325         .irq_base       = TPS6591X_IRQ_BASE,
326         .gpio_base      = TPS6591X_GPIO_BASE,
327         .dev_slp_en     = true,
328         .slp_keepon     = &tps_slp_keepon,
329         .use_power_off  = true,
330 };
331
332 static struct i2c_board_info __initdata cardhu_regulators[] = {
333         {
334                 I2C_BOARD_INFO("tps6591x", 0x2D),
335                 .irq            = INT_EXTERNAL_PMU,
336                 .platform_data  = &tps_platform,
337         },
338 };
339
340 /* TPS62361B DC-DC converter */
341 static struct regulator_consumer_supply tps62361_dcdc_supply[] = {
342         REGULATOR_SUPPLY("vdd_core", NULL),
343 };
344
345 static struct tps62360_regulator_platform_data tps62361_pdata = {
346         .reg_init_data = {                                      \
347                 .constraints = {                                \
348                         .min_uV = 500000,                       \
349                         .max_uV = 1770000,                      \
350                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |  \
351                                              REGULATOR_MODE_STANDBY), \
352                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |    \
353                                            REGULATOR_CHANGE_STATUS |  \
354                                            REGULATOR_CHANGE_VOLTAGE), \
355                         .always_on = 1,                         \
356                         .boot_on =  1,                          \
357                         .apply_uV = 0,                          \
358                 },                                              \
359                 .num_consumer_supplies = ARRAY_SIZE(tps62361_dcdc_supply), \
360                 .consumer_supplies = tps62361_dcdc_supply,      \
361                 },                                              \
362         .en_discharge = true,                                   \
363         .vsel0_gpio = -1,                                       \
364         .vsel1_gpio = -1,                                       \
365         .vsel0_def_state = 1,                                   \
366         .vsel1_def_state = 1,                                   \
367 };
368
369 static struct i2c_board_info __initdata tps62361_boardinfo[] = {
370         {
371                 I2C_BOARD_INFO("tps62361", 0x60),
372                 .platform_data  = &tps62361_pdata,
373         },
374 };
375
376 int __init cardhu_regulator_init(void)
377 {
378         struct board_info board_info;
379         struct board_info pmu_board_info;
380         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
381         u32 pmc_ctrl;
382
383         /* configure the power management controller to trigger PMU
384          * interrupts when low */
385
386         pmc_ctrl = readl(pmc + PMC_CTRL);
387         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
388
389         tegra_get_board_info(&board_info);
390         tegra_get_pmu_board_info(&pmu_board_info);
391
392         if (pmu_board_info.board_id == BOARD_PMU_PM298)
393                 return cardhu_pm298_regulator_init();
394
395         if (pmu_board_info.board_id == BOARD_PMU_PM299)
396                 return cardhu_pm299_regulator_init();
397
398         /* The regulator details have complete constraints */
399         regulator_has_full_constraints();
400
401         /* PMU-E1208, the ldo2 should be set to 1200mV */
402         if (pmu_board_info.board_id == BOARD_E1208) {
403                 pdata_ldo2_0.regulator.constraints.min_uV = 1200000;
404                 pdata_ldo2_0.regulator.constraints.max_uV = 1200000;
405         }
406
407         if ((board_info.board_id == BOARD_E1198) ||
408                 (board_info.board_id == BOARD_E1291)) {
409                 if (board_info.sku & SKU_DCDC_TPS62361_SUPPORT) {
410                         tps_platform.num_subdevs =
411                                         ARRAY_SIZE(tps_devs_e1198_skubit0_1);
412                         tps_platform.subdevs = tps_devs_e1198_skubit0_1;
413                 } else {
414                         tps_platform.num_subdevs =
415                                         ARRAY_SIZE(tps_devs_e1198_skubit0_0);
416                         tps_platform.subdevs = tps_devs_e1198_skubit0_0;
417                 }
418         } else {
419                 if (board_info.board_id == BOARD_PM269)
420                         pdata_ldo3_e118x.slew_rate_uV_per_us = 250;
421
422                 if (pmu_board_info.sku & SKU_DCDC_TPS62361_SUPPORT) {
423                         tps_platform.num_subdevs = ARRAY_SIZE(tps_devs_e118x_skubit0_1);
424                         tps_platform.subdevs = tps_devs_e118x_skubit0_1;
425                 } else {
426                         tps_platform.num_subdevs = ARRAY_SIZE(tps_devs_e118x_skubit0_0);
427                         tps_platform.subdevs = tps_devs_e118x_skubit0_0;
428                 }
429         }
430
431         /* E1291-A04/A05: Enable DEV_SLP and enable sleep on GPIO2 */
432         if ((board_info.board_id == BOARD_E1291) &&
433                         ((board_info.fab == BOARD_FAB_A04) ||
434                          (board_info.fab == BOARD_FAB_A05))) {
435                 tps_platform.dev_slp_en = true;
436                 tps_platform.gpio_init_data = tps_gpio_pdata_e1291_a04;
437                 tps_platform.num_gpioinit_data =
438                                         ARRAY_SIZE(tps_gpio_pdata_e1291_a04);
439         }
440
441         i2c_register_board_info(4, cardhu_regulators, 1);
442
443         /* Resgister the TPS6236x for all boards whose sku bit 0 is set. */
444         if ((board_info.sku & SKU_DCDC_TPS62361_SUPPORT) ||
445                         (pmu_board_info.sku & SKU_DCDC_TPS62361_SUPPORT)) {
446                 pr_info("Registering the device TPS62361\n");
447                 i2c_register_board_info(4, tps62361_boardinfo, 1);
448         }
449         return 0;
450 }
451
452
453 /**************** GPIO based fixed regulator *****************/
454 /* EN_5V_CP from PMU GP0 */
455 static struct regulator_consumer_supply fixed_reg_en_5v_cp_supply[] = {
456         REGULATOR_SUPPLY("vdd_5v0_sby", NULL),
457         REGULATOR_SUPPLY("vdd_hall", NULL),
458         REGULATOR_SUPPLY("vterm_ddr", NULL),
459         REGULATOR_SUPPLY("v2ref_ddr", NULL),
460 };
461
462 /* EN_5V0 From PMU GP2 */
463 static struct regulator_consumer_supply fixed_reg_en_5v0_supply[] = {
464         REGULATOR_SUPPLY("vdd_5v0_sys", NULL),
465 };
466
467 /* EN_DDR From PMU GP6 */
468 static struct regulator_consumer_supply fixed_reg_en_ddr_supply[] = {
469         REGULATOR_SUPPLY("mem_vddio_ddr", NULL),
470         REGULATOR_SUPPLY("t30_vddio_ddr", NULL),
471 };
472
473 /* EN_3V3_SYS From PMU GP7 */
474 static struct regulator_consumer_supply fixed_reg_en_3v3_sys_supply[] = {
475         REGULATOR_SUPPLY("vdd_lvds", NULL),
476         REGULATOR_SUPPLY("vdd_pnl", NULL),
477         REGULATOR_SUPPLY("vcom_3v3", NULL),
478         REGULATOR_SUPPLY("vdd_3v3", NULL),
479         REGULATOR_SUPPLY("vcore_mmc", NULL),
480         REGULATOR_SUPPLY("vddio_pex_ctl", NULL),
481         REGULATOR_SUPPLY("pwrdet_pex_ctl", NULL),
482         REGULATOR_SUPPLY("hvdd_pex_pmu", NULL),
483         REGULATOR_SUPPLY("avdd_hdmi", NULL),
484         REGULATOR_SUPPLY("vpp_fuse", NULL),
485         REGULATOR_SUPPLY("avdd_usb", NULL),
486         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
487         REGULATOR_SUPPLY("vcore_nand", NULL),
488         REGULATOR_SUPPLY("hvdd_sata", NULL),
489         REGULATOR_SUPPLY("vddio_gmi_pmu", NULL),
490         REGULATOR_SUPPLY("pwrdet_nand", NULL),
491         REGULATOR_SUPPLY("avdd_cam1", NULL),
492         REGULATOR_SUPPLY("vdd_af", NULL),
493         REGULATOR_SUPPLY("avdd_cam2", NULL),
494         REGULATOR_SUPPLY("vdd_acc", NULL),
495         REGULATOR_SUPPLY("vdd_phtl", NULL),
496         REGULATOR_SUPPLY("vddio_tp", NULL),
497         REGULATOR_SUPPLY("vdd_led", NULL),
498         REGULATOR_SUPPLY("vddio_cec", NULL),
499         REGULATOR_SUPPLY("vdd_cmps", NULL),
500         REGULATOR_SUPPLY("vdd_temp", NULL),
501         REGULATOR_SUPPLY("vpp_kfuse", NULL),
502         REGULATOR_SUPPLY("vddio_ts", NULL),
503         REGULATOR_SUPPLY("vdd_ir_led", NULL),
504         REGULATOR_SUPPLY("vddio_1wire", NULL),
505         REGULATOR_SUPPLY("avddio_audio", NULL),
506         REGULATOR_SUPPLY("vdd_ec", NULL),
507         REGULATOR_SUPPLY("vcom_pa", NULL),
508         REGULATOR_SUPPLY("vdd_3v3_devices", NULL),
509         REGULATOR_SUPPLY("vdd_3v3_dock", NULL),
510         REGULATOR_SUPPLY("vdd_3v3_edid", NULL),
511         REGULATOR_SUPPLY("vdd_3v3_hdmi_cec", NULL),
512         REGULATOR_SUPPLY("vdd_3v3_gmi", NULL),
513         REGULATOR_SUPPLY("vdd_spk_amp", "tegra-snd-wm8903.0"),
514         REGULATOR_SUPPLY("vdd_3v3_sensor", NULL),
515         REGULATOR_SUPPLY("vdd_3v3_cam", NULL),
516         REGULATOR_SUPPLY("vdd_3v3_als", NULL),
517         REGULATOR_SUPPLY("debug_cons", NULL),
518         REGULATOR_SUPPLY("vdd", "4-004c"),
519 };
520
521 /* DIS_5V_SWITCH from AP SPI2_SCK X02 */
522 static struct regulator_consumer_supply fixed_reg_dis_5v_switch_supply[] = {
523         REGULATOR_SUPPLY("master_5v_switch", NULL),
524 };
525
526 /* EN_VDD_BL */
527 static struct regulator_consumer_supply fixed_reg_en_vdd_bl_supply[] = {
528         REGULATOR_SUPPLY("vdd_backlight", NULL),
529         REGULATOR_SUPPLY("vdd_backlight1", NULL),
530 };
531
532 /* EN_VDD_BL2 (E1291-A03) from AP PEX_L0_PRSNT_N DD.00 */
533 static struct regulator_consumer_supply fixed_reg_en_vdd_bl2_supply[] = {
534         REGULATOR_SUPPLY("vdd_backlight2", NULL),
535 };
536
537 /* EN_3V3_MODEM from AP GPIO VI_VSYNCH D06*/
538 static struct regulator_consumer_supply fixed_reg_en_3v3_modem_supply[] = {
539         REGULATOR_SUPPLY("vdd_3v3_mini_card", NULL),
540         REGULATOR_SUPPLY("vdd_mini_card", NULL),
541 };
542
543 /* EN_VDD_PNL1 from AP GPIO VI_D6 L04*/
544 static struct regulator_consumer_supply fixed_reg_en_vdd_pnl1_supply[] = {
545         REGULATOR_SUPPLY("vdd_lcd_panel", NULL),
546 };
547
548 /* CAM1_LDO_EN from AP GPIO KB_ROW6 R06*/
549 static struct regulator_consumer_supply fixed_reg_cam1_ldo_en_supply[] = {
550         REGULATOR_SUPPLY("vdd_2v8_cam1", NULL),
551         REGULATOR_SUPPLY("vdd", "6-0072"),
552 };
553
554 /* CAM2_LDO_EN from AP GPIO KB_ROW7 R07*/
555 static struct regulator_consumer_supply fixed_reg_cam2_ldo_en_supply[] = {
556         REGULATOR_SUPPLY("vdd_2v8_cam2", NULL),
557         REGULATOR_SUPPLY("vdd", "7-0072"),
558 };
559
560 /* CAM3_LDO_EN from AP GPIO KB_ROW8 S00*/
561 static struct regulator_consumer_supply fixed_reg_cam3_ldo_en_supply[] = {
562         REGULATOR_SUPPLY("vdd_cam3", NULL),
563 };
564
565 /* EN_VDD_COM from AP GPIO SDMMC3_DAT5 D00*/
566 static struct regulator_consumer_supply fixed_reg_en_vdd_com_supply[] = {
567         REGULATOR_SUPPLY("vdd_com_bd", NULL),
568 };
569
570 /* EN_VDD_SDMMC1 from AP GPIO VI_HSYNC D07*/
571 static struct regulator_consumer_supply fixed_reg_en_vdd_sdmmc1_supply[] = {
572         REGULATOR_SUPPLY("vddio_sd_slot", "sdhci-tegra.0"),
573 };
574
575 /* EN_3V3_EMMC from AP GPIO SDMMC3_DAT4 D01*/
576 static struct regulator_consumer_supply fixed_reg_en_3v3_emmc_supply[] = {
577         REGULATOR_SUPPLY("vdd_emmc_core", NULL),
578 };
579
580 /* EN_3V3_PEX_HVDD from AP GPIO VI_D09 L07*/
581 static struct regulator_consumer_supply fixed_reg_en_3v3_pex_hvdd_supply[] = {
582         REGULATOR_SUPPLY("hvdd_pex", NULL),
583 };
584
585 /* EN_3v3_FUSE from AP GPIO VI_D08 L06*/
586 static struct regulator_consumer_supply fixed_reg_en_3v3_fuse_supply[] = {
587         REGULATOR_SUPPLY("vdd_fuse", NULL),
588 };
589
590 /* EN_1V8_CAM from AP GPIO GPIO_PBB4 PBB04*/
591 static struct regulator_consumer_supply fixed_reg_en_1v8_cam_supply[] = {
592         REGULATOR_SUPPLY("vdd_1v8_cam1", NULL),
593         REGULATOR_SUPPLY("vdd_1v8_cam2", NULL),
594         REGULATOR_SUPPLY("vdd_1v8_cam3", NULL),
595         REGULATOR_SUPPLY("vdd_i2c", "6-0072"),
596         REGULATOR_SUPPLY("vdd_i2c", "7-0072"),
597         REGULATOR_SUPPLY("vdd_i2c", "2-0033"),
598 };
599
600 static struct regulator_consumer_supply fixed_reg_en_vbrtr_supply[] = {
601         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
602 };
603
604 /* EN_USB1_VBUS_OC*/
605 static struct regulator_consumer_supply gpio_switch_en_usb1_vbus_oc_supply[] = {
606         REGULATOR_SUPPLY("vdd_vbus_micro_usb", NULL),
607 };
608 static int gpio_switch_en_usb1_vbus_oc_voltages[] = { 5000};
609
610 /*EN_USB3_VBUS_OC*/
611 static struct regulator_consumer_supply gpio_switch_en_usb3_vbus_oc_supply[] = {
612         REGULATOR_SUPPLY("vdd_vbus_typea_usb", NULL),
613 };
614 static int gpio_switch_en_usb3_vbus_oc_voltages[] = { 5000};
615
616 /* EN_VDDIO_VID_OC from AP GPIO VI_PCLK T00*/
617 static struct regulator_consumer_supply gpio_switch_en_vddio_vid_oc_supply[] = {
618         REGULATOR_SUPPLY("vdd_hdmi_con", NULL),
619 };
620 static int gpio_switch_en_vddio_vid_oc_voltages[] = { 5000};
621
622 static int enable_load_switch_rail(
623                 struct gpio_switch_regulator_subdev_data *psubdev_data)
624 {
625         int ret;
626
627         if (psubdev_data->pin_group <= 0)
628                 return -EINVAL;
629
630         /* Tristate and make pin as input*/
631         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
632                                                 TEGRA_TRI_TRISTATE);
633         if (ret < 0)
634                 return ret;
635         return gpio_direction_input(psubdev_data->gpio_nr);
636 }
637
638 static int disable_load_switch_rail(
639                 struct gpio_switch_regulator_subdev_data *psubdev_data)
640 {
641         int ret;
642
643         if (psubdev_data->pin_group <= 0)
644                 return -EINVAL;
645
646         /* Un-tristate and driver low */
647         ret = tegra_pinmux_set_tristate(psubdev_data->pin_group,
648                                                 TEGRA_TRI_NORMAL);
649         if (ret < 0)
650                 return ret;
651         return gpio_direction_output(psubdev_data->gpio_nr, 0);
652 }
653
654 /* Macro for defining gpio switch regulator sub device data */
655 #define GREG_INIT(_id, _var, _name, _input_supply, _always_on, _boot_on, \
656         _gpio_nr, _active_low, _init_state, _pg, _enable, _disable)      \
657         static struct gpio_switch_regulator_subdev_data gpio_pdata_##_var =  \
658         {                                                               \
659                 .regulator_name = "gpio-switch-"#_name,                 \
660                 .input_supply   = _input_supply,                        \
661                 .id             = _id,                                  \
662                 .gpio_nr        = _gpio_nr,                             \
663                 .pin_group      = _pg,                                  \
664                 .active_low     = _active_low,                          \
665                 .init_state     = _init_state,                          \
666                 .voltages       = gpio_switch_##_name##_voltages,       \
667                 .n_voltages     = ARRAY_SIZE(gpio_switch_##_name##_voltages), \
668                 .num_consumer_supplies =                                \
669                                 ARRAY_SIZE(gpio_switch_##_name##_supply), \
670                 .consumer_supplies = gpio_switch_##_name##_supply,      \
671                 .constraints = {                                        \
672                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
673                                              REGULATOR_MODE_STANDBY),   \
674                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
675                                            REGULATOR_CHANGE_STATUS |    \
676                                            REGULATOR_CHANGE_VOLTAGE),   \
677                         .always_on = _always_on,                        \
678                         .boot_on = _boot_on,                            \
679                 },                                                      \
680                 .enable_rail = _enable,                                 \
681                 .disable_rail = _disable,                               \
682         };                                                              \
683         static struct gpio_switch_regulator_subdev_data                 \
684                                 *gpio_pdata_##_var##_list[] = { \
685                 &gpio_pdata_##_var,                                     \
686         };                                                              \
687         static struct gpio_switch_regulator_platform_data gs_##_var##_pdata = \
688         {                                                               \
689                 .num_subdevs = 1,                                       \
690                 .subdevs = gpio_pdata_##_var##_list,                    \
691         };                                                              \
692         static struct platform_device gswitch_reg_##_var##_dev = {      \
693                 .name = "gpio-switch-regulator",                        \
694                 .id   = _id,                                            \
695                 .dev  = {                                               \
696                      .platform_data = &gs_##_var##_pdata,               \
697                 },                                                      \
698         }
699
700 /* Macro for defining fixed regulator sub device data */
701 #define FIXED_SUPPLY(_name) "fixed_reg_"#_name
702 #define FIXED_REG(_id, _var, _name, _in_supply, _always_on, _boot_on,   \
703                  _gpio_nr, _active_high, _boot_state, _millivolts)      \
704         static struct regulator_init_data ri_data_##_var =              \
705         {                                                               \
706                 .supply_regulator = _in_supply,                         \
707                 .num_consumer_supplies =                                \
708                         ARRAY_SIZE(fixed_reg_##_name##_supply),         \
709                 .consumer_supplies = fixed_reg_##_name##_supply,        \
710                 .constraints = {                                        \
711                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
712                                         REGULATOR_MODE_STANDBY),        \
713                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
714                                         REGULATOR_CHANGE_STATUS |       \
715                                         REGULATOR_CHANGE_VOLTAGE),      \
716                         .always_on = _always_on,                        \
717                         .boot_on = _boot_on,                            \
718                 },                                                      \
719         };                                                              \
720         static struct fixed_voltage_config fixed_reg_##_var##_pdata =   \
721         {                                                               \
722                 .supply_name = FIXED_SUPPLY(_name),                     \
723                 .microvolts = _millivolts * 1000,                       \
724                 .gpio = _gpio_nr,                                       \
725                 .enable_high = _active_high,                            \
726                 .enabled_at_boot = _boot_state,                         \
727                 .init_data = &ri_data_##_var,                           \
728         };                                                              \
729         static struct platform_device fixed_reg_##_var##_dev = {        \
730                 .name   = "reg-fixed-voltage",                          \
731                 .id     = _id,                                          \
732                 .dev    = {                                             \
733                         .platform_data = &fixed_reg_##_var##_pdata,     \
734                 },                                                      \
735         }
736
737 /* common to most of boards*/
738 FIXED_REG(0, en_5v_cp,          en_5v_cp,       NULL,                           1,      0,      TPS6591X_GPIO_0,        true,   1, 5000);
739 FIXED_REG(1, en_5v0,            en_5v0,         NULL,                           0,      0,      TPS6591X_GPIO_2,        true,   0, 5000);
740 FIXED_REG(2, en_ddr,            en_ddr,         NULL,                           1,      0,      TPS6591X_GPIO_6,        true,   1, 1500);
741 FIXED_REG(3, en_3v3_sys,        en_3v3_sys,     NULL,                           0,      0,      TPS6591X_GPIO_7,        true,   1, 3300);
742 FIXED_REG(4, en_vdd_bl,         en_vdd_bl,      NULL,                           0,      0,      TEGRA_GPIO_PK3,         true,   1, 5000);
743 FIXED_REG(5, en_3v3_modem,      en_3v3_modem,   NULL,                           1,      0,      TEGRA_GPIO_PD6,         true,   1, 3300);
744 FIXED_REG(6, en_vdd_pnl1,       en_vdd_pnl1,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PL4,         true,   1, 3300);
745 FIXED_REG(7, cam3_ldo_en,       cam3_ldo_en,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PS0,         true,   0, 3300);
746 FIXED_REG(8, en_vdd_com,        en_vdd_com,     FIXED_SUPPLY(en_3v3_sys),       1,      0,      TEGRA_GPIO_PD0,         true,   1, 3300);
747 FIXED_REG(9, en_3v3_fuse,       en_3v3_fuse,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PL6,         true,   0, 3300);
748 FIXED_REG(10, en_3v3_emmc,      en_3v3_emmc,    FIXED_SUPPLY(en_3v3_sys),       1,      0,      TEGRA_GPIO_PD1,         true,   1, 3300);
749 FIXED_REG(11, en_vdd_sdmmc1,    en_vdd_sdmmc1,  FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PD7,         true,   1, 3300);
750 FIXED_REG(12, en_3v3_pex_hvdd,  en_3v3_pex_hvdd, FIXED_SUPPLY(en_3v3_sys),      0,      0,      TEGRA_GPIO_PL7,         true,   0, 3300);
751 FIXED_REG(13, en_1v8_cam,       en_1v8_cam,     tps6591x_rails(VIO),            0,      0,      TEGRA_GPIO_PBB4,        true,   0, 1800);
752
753 /* Specific to E1187/E1186/E1256 */
754 FIXED_REG(14, dis_5v_switch_e118x,      dis_5v_switch,  FIXED_SUPPLY(en_5v0),   0,      0,      TEGRA_GPIO_PX2,         false,  0, 5000);
755
756 /* E1291-A04/A05 specific */
757 FIXED_REG(1, en_5v0_a04,        en_5v0,         NULL,                           0,      0,      TPS6591X_GPIO_8,        true,   0, 5000);
758 FIXED_REG(2, en_ddr_a04,        en_ddr,         NULL,                           1,      0,      TPS6591X_GPIO_7,        true,   1, 1500);
759 FIXED_REG(3, en_3v3_sys_a04,    en_3v3_sys,     NULL,                           0,      0,      TPS6591X_GPIO_6,        true,   1, 3300);
760
761 /* Specific to pm269 */
762 FIXED_REG(4, en_vdd_bl_pm269,           en_vdd_bl,              NULL,                           0,      0,      TEGRA_GPIO_PH3, true,   1, 5000);
763 FIXED_REG(6, en_vdd_pnl1_pm269,         en_vdd_pnl1,            FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PW1, true,   1, 3300);
764 FIXED_REG(9, en_3v3_fuse_pm269,         en_3v3_fuse,            FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PC1, true,   0, 3300);
765 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);
766
767 /* E1198/E1291 specific*/
768 FIXED_REG(18, cam1_ldo_en,      cam1_ldo_en,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PR6,         true,   0, 2800);
769 FIXED_REG(19, cam2_ldo_en,      cam2_ldo_en,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PR7,         true,   0, 2800);
770
771 /* E1291 A03 specific */
772 FIXED_REG(20, en_vdd_bl1_a03,   en_vdd_bl,      NULL,                           0,      0,      TEGRA_GPIO_PDD2,        true,   1, 5000);
773 FIXED_REG(21, en_vdd_bl2_a03,   en_vdd_bl2,     NULL,                           0,      0,      TEGRA_GPIO_PDD0,        true,   1, 5000);
774 FIXED_REG(22, en_vbrtr,         en_vbrtr,       FIXED_SUPPLY(en_3v3_sys),       0,      0,      PMU_TCA6416_GPIO_PORT12,true,   0, 3300);
775
776 /* PM313 display board specific */
777 FIXED_REG(4, en_vdd_bl_pm313,   en_vdd_bl,      NULL,                           0,      0,      TEGRA_GPIO_PK3,         true,  1, 5000);
778 FIXED_REG(6, en_vdd_pnl1_pm313, en_vdd_pnl1,    FIXED_SUPPLY(en_3v3_sys),       0,      0,      TEGRA_GPIO_PH3,         true,  1, 3300);
779
780
781 /****************** Open collector Load switches *******/
782 /*Specific to pm269*/
783 GREG_INIT(17, en_vddio_vid_oc_pm269,    en_vddio_vid_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PP2,     false,  0,      TEGRA_PINGROUP_DAP3_DOUT,
784         enable_load_switch_rail, disable_load_switch_rail);
785
786 /* Specific to pm311 */
787 GREG_INIT(15, en_usb1_vbus_oc_pm311,    en_usb1_vbus_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PCC7,            false,  0,      TEGRA_PINGROUP_GMI_RST_N,
788                 enable_load_switch_rail, disable_load_switch_rail);
789 GREG_INIT(16, en_usb3_vbus_oc_pm311,    en_usb3_vbus_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PCC6,            false,  0,      TEGRA_PINGROUP_GMI_AD15,
790                 enable_load_switch_rail, disable_load_switch_rail);
791
792 /* Specific to E1187/E1186/E1256 */
793 GREG_INIT(15, en_usb1_vbus_oc_e118x,    en_usb1_vbus_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PI4,             false,  0,      TEGRA_PINGROUP_GMI_RST_N,
794                 enable_load_switch_rail, disable_load_switch_rail);
795 GREG_INIT(16, en_usb3_vbus_oc_e118x,    en_usb3_vbus_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PH7,             false,  0,      TEGRA_PINGROUP_GMI_AD15,
796                 enable_load_switch_rail, disable_load_switch_rail);
797 GREG_INIT(17, en_vddio_vid_oc_e118x,    en_vddio_vid_oc,        "master_5v_switch", 0,      0,      TEGRA_GPIO_PT0,             false,  0,      TEGRA_PINGROUP_VI_PCLK,
798                 enable_load_switch_rail, disable_load_switch_rail);
799
800 /* E1198/E1291 specific  fab < A03 */
801 GREG_INIT(15, en_usb1_vbus_oc,          en_usb1_vbus_oc,        "vdd_5v0_sys", 0,      0,      TEGRA_GPIO_PI4,          false,  0,      TEGRA_PINGROUP_GMI_RST_N,
802                 enable_load_switch_rail, disable_load_switch_rail);
803 GREG_INIT(16, en_usb3_vbus_oc,          en_usb3_vbus_oc,        "vdd_5v0_sys", 0,      0,      TEGRA_GPIO_PH7,          false,  0,      TEGRA_PINGROUP_GMI_AD15,
804                 enable_load_switch_rail, disable_load_switch_rail);
805
806 /* E1198/E1291 specific  fab >= A03 */
807 GREG_INIT(15, en_usb1_vbus_oc_a03,      en_usb1_vbus_oc,        "vdd_5v0_sys", 0,      0,      TEGRA_GPIO_PDD6,         false,  0,      TEGRA_PINGROUP_PEX_L1_CLKREQ_N,
808                 enable_load_switch_rail, disable_load_switch_rail);
809 GREG_INIT(16, en_usb3_vbus_oc_a03,      en_usb3_vbus_oc,        "vdd_5v0_sys", 0,      0,      TEGRA_GPIO_PDD4,         false,  0,      TEGRA_PINGROUP_PEX_L1_PRSNT_N,
810                 enable_load_switch_rail, disable_load_switch_rail);
811
812 /* E1198/E1291 specific */
813 GREG_INIT(17, en_vddio_vid_oc,          en_vddio_vid_oc,        "vdd_5v0_sys", 0,      0,      TEGRA_GPIO_PT0,          false,  0,      TEGRA_PINGROUP_VI_PCLK,
814                 enable_load_switch_rail, disable_load_switch_rail);
815
816 /*
817  * Creating the fixed/gpio-switch regulator device tables for different boards
818  */
819 #define ADD_FIXED_REG(_name)    (&fixed_reg_##_name##_dev)
820 #define ADD_GPIO_REG(_name)     (&gswitch_reg_##_name##_dev)
821
822 #define COMMON_FIXED_REG                        \
823         ADD_FIXED_REG(en_5v_cp),                \
824         ADD_FIXED_REG(en_5v0),                  \
825         ADD_FIXED_REG(en_ddr),                  \
826         ADD_FIXED_REG(en_3v3_sys),              \
827         ADD_FIXED_REG(en_3v3_modem),            \
828         ADD_FIXED_REG(en_vdd_pnl1),             \
829         ADD_FIXED_REG(cam3_ldo_en),             \
830         ADD_FIXED_REG(en_vdd_com),              \
831         ADD_FIXED_REG(en_3v3_fuse),             \
832         ADD_FIXED_REG(en_3v3_emmc),             \
833         ADD_FIXED_REG(en_vdd_sdmmc1),           \
834         ADD_FIXED_REG(en_3v3_pex_hvdd),         \
835         ADD_FIXED_REG(en_1v8_cam),
836
837 #define COMMON_FIXED_REG_E1291_A04              \
838         ADD_FIXED_REG(en_5v_cp),                \
839         ADD_FIXED_REG(en_5v0_a04),              \
840         ADD_FIXED_REG(en_ddr_a04),              \
841         ADD_FIXED_REG(en_3v3_sys_a04),          \
842         ADD_FIXED_REG(en_3v3_modem),            \
843         ADD_FIXED_REG(en_vdd_pnl1),             \
844         ADD_FIXED_REG(cam3_ldo_en),             \
845         ADD_FIXED_REG(en_vdd_com),              \
846         ADD_FIXED_REG(en_3v3_fuse),             \
847         ADD_FIXED_REG(en_3v3_emmc),             \
848         ADD_FIXED_REG(en_vdd_sdmmc1),           \
849         ADD_FIXED_REG(en_3v3_pex_hvdd),         \
850         ADD_FIXED_REG(en_1v8_cam),
851
852 #define PM269_FIXED_REG                         \
853         ADD_FIXED_REG(en_5v_cp),                \
854         ADD_FIXED_REG(en_5v0),                  \
855         ADD_FIXED_REG(en_ddr),                  \
856         ADD_FIXED_REG(en_3v3_sys),              \
857         ADD_FIXED_REG(en_3v3_modem),            \
858         ADD_FIXED_REG(cam1_ldo_en),             \
859         ADD_FIXED_REG(cam2_ldo_en),             \
860         ADD_FIXED_REG(cam3_ldo_en),             \
861         ADD_FIXED_REG(en_vdd_com),              \
862         ADD_FIXED_REG(en_3v3_fuse_pm269),       \
863         ADD_FIXED_REG(en_3v3_emmc),             \
864         ADD_FIXED_REG(en_3v3_pex_hvdd_pm269),   \
865         ADD_FIXED_REG(en_1v8_cam),              \
866         ADD_FIXED_REG(dis_5v_switch_e118x),     \
867         ADD_GPIO_REG(en_usb1_vbus_oc_e118x),    \
868         ADD_GPIO_REG(en_usb3_vbus_oc_e118x),    \
869         ADD_GPIO_REG(en_vddio_vid_oc_pm269),
870
871 #define PM311_FIXED_REG                         \
872         ADD_FIXED_REG(en_5v_cp),                \
873         ADD_FIXED_REG(en_5v0),                  \
874         ADD_FIXED_REG(en_ddr),                  \
875         ADD_FIXED_REG(en_3v3_sys),              \
876         ADD_FIXED_REG(en_3v3_modem),            \
877         ADD_FIXED_REG(cam1_ldo_en),             \
878         ADD_FIXED_REG(cam2_ldo_en),             \
879         ADD_FIXED_REG(cam3_ldo_en),             \
880         ADD_FIXED_REG(en_vdd_com),              \
881         ADD_FIXED_REG(en_3v3_fuse_pm269),       \
882         ADD_FIXED_REG(en_3v3_emmc),             \
883         ADD_FIXED_REG(en_3v3_pex_hvdd_pm269),   \
884         ADD_FIXED_REG(en_1v8_cam),              \
885         ADD_FIXED_REG(dis_5v_switch_e118x),     \
886         ADD_GPIO_REG(en_usb1_vbus_oc_pm311),    \
887         ADD_GPIO_REG(en_usb3_vbus_oc_pm311),    \
888         ADD_GPIO_REG(en_vddio_vid_oc_pm269),
889
890
891 #define E1247_DISPLAY_FIXED_REG                 \
892         ADD_FIXED_REG(en_vdd_bl_pm269),         \
893         ADD_FIXED_REG(en_vdd_pnl1_pm269),
894
895 #define PM313_DISPLAY_FIXED_REG                 \
896         ADD_FIXED_REG(en_vdd_bl_pm313),         \
897         ADD_FIXED_REG(en_vdd_pnl1_pm313),
898
899 #define E118x_FIXED_REG                         \
900         ADD_FIXED_REG(en_5v_cp),                \
901         ADD_FIXED_REG(en_5v0),                  \
902         ADD_FIXED_REG(en_ddr),                  \
903         ADD_FIXED_REG(en_3v3_sys),              \
904         ADD_FIXED_REG(en_3v3_modem),            \
905         ADD_FIXED_REG(cam3_ldo_en),             \
906         ADD_FIXED_REG(en_vdd_com),              \
907         ADD_FIXED_REG(en_3v3_fuse),             \
908         ADD_FIXED_REG(en_3v3_emmc),             \
909         ADD_FIXED_REG(en_vdd_sdmmc1),           \
910         ADD_FIXED_REG(en_3v3_pex_hvdd),         \
911         ADD_FIXED_REG(en_1v8_cam),              \
912         ADD_FIXED_REG(dis_5v_switch_e118x),     \
913         ADD_FIXED_REG(en_vbrtr),                \
914         ADD_GPIO_REG(en_usb1_vbus_oc_e118x),    \
915         ADD_GPIO_REG(en_usb3_vbus_oc_e118x),    \
916         ADD_GPIO_REG(en_vddio_vid_oc_e118x),
917
918 #define E1198_FIXED_REG                         \
919         ADD_FIXED_REG(cam1_ldo_en),             \
920         ADD_FIXED_REG(cam2_ldo_en),             \
921         ADD_GPIO_REG(en_vddio_vid_oc),
922
923 #define E1291_1198_A00_FIXED_REG                \
924         ADD_FIXED_REG(en_vdd_bl),               \
925         ADD_GPIO_REG(en_usb1_vbus_oc),          \
926         ADD_GPIO_REG(en_usb3_vbus_oc),
927
928 #define E1291_A03_FIXED_REG                     \
929         ADD_FIXED_REG(en_vdd_bl1_a03),          \
930         ADD_FIXED_REG(en_vdd_bl2_a03),          \
931         ADD_GPIO_REG(en_usb1_vbus_oc_a03),      \
932         ADD_GPIO_REG(en_usb3_vbus_oc_a03),
933
934 /* Fixed regulator devices for E1186/E1187/E1256 */
935 static struct platform_device *fixed_reg_devs_e118x[] = {
936         E118x_FIXED_REG
937         E1247_DISPLAY_FIXED_REG
938 };
939
940 /* Fixed regulator devices for E1186/E1187/E1256 */
941 static struct platform_device *fixed_reg_devs_e118x_pm313[] = {
942         E118x_FIXED_REG
943         PM313_DISPLAY_FIXED_REG
944 };
945
946 /* Fixed regulator devices for E1198 and E1291 */
947 static struct platform_device *fixed_reg_devs_e1198_base[] = {
948         COMMON_FIXED_REG
949         E1291_1198_A00_FIXED_REG
950         E1198_FIXED_REG
951 };
952
953 static struct platform_device *fixed_reg_devs_e1198_a02[] = {
954         ADD_FIXED_REG(en_5v_cp),
955         ADD_FIXED_REG(en_5v0),
956         ADD_FIXED_REG(en_ddr_a04),
957         ADD_FIXED_REG(en_3v3_sys_a04),
958         ADD_FIXED_REG(en_3v3_modem),
959         ADD_FIXED_REG(en_vdd_pnl1),
960         ADD_FIXED_REG(cam3_ldo_en),
961         ADD_FIXED_REG(en_vdd_com),
962         ADD_FIXED_REG(en_3v3_fuse),
963         ADD_FIXED_REG(en_3v3_emmc),
964         ADD_FIXED_REG(en_vdd_sdmmc1),
965         ADD_FIXED_REG(en_3v3_pex_hvdd),
966         ADD_FIXED_REG(en_1v8_cam),
967         ADD_FIXED_REG(en_vdd_bl1_a03),
968         ADD_FIXED_REG(en_vdd_bl2_a03),
969         ADD_FIXED_REG(cam1_ldo_en),
970         ADD_FIXED_REG(cam2_ldo_en),
971         ADD_GPIO_REG(en_usb1_vbus_oc_a03),
972         ADD_GPIO_REG(en_usb3_vbus_oc_a03),
973         ADD_GPIO_REG(en_vddio_vid_oc),
974 };
975
976 /* Fixed regulator devices for PM269 */
977 static struct platform_device *fixed_reg_devs_pm269[] = {
978         PM269_FIXED_REG
979         E1247_DISPLAY_FIXED_REG
980 };
981
982 /* Fixed regulator devices for PM269 */
983 static struct platform_device *fixed_reg_devs_pm269_pm313[] = {
984         PM269_FIXED_REG
985         PM313_DISPLAY_FIXED_REG
986 };
987
988 /* Fixed regulator devices for PM311 */
989 static struct platform_device *fixed_reg_devs_pm311[] = {
990         PM311_FIXED_REG
991         E1247_DISPLAY_FIXED_REG
992 };
993
994 /* Fixed regulator devices for PM11 */
995 static struct platform_device *fixed_reg_devs_pm311_pm313[] = {
996         PM311_FIXED_REG
997         PM313_DISPLAY_FIXED_REG
998 };
999
1000 /* Fixed regulator devices for E1291 A03 */
1001 static struct platform_device *fixed_reg_devs_e1291_a03[] = {
1002         COMMON_FIXED_REG
1003         E1291_A03_FIXED_REG
1004         E1198_FIXED_REG
1005 };
1006
1007 /* Fixed regulator devices for E1291 A04/A05 */
1008 static struct platform_device *fixed_reg_devs_e1291_a04[] = {
1009         COMMON_FIXED_REG_E1291_A04
1010         E1291_A03_FIXED_REG
1011         E1198_FIXED_REG
1012 };
1013
1014 int __init cardhu_fixed_regulator_init(void)
1015 {
1016         int i;
1017         struct board_info board_info;
1018         struct board_info pmu_board_info;
1019         struct board_info display_board_info;
1020         struct platform_device **fixed_reg_devs;
1021         int    nfixreg_devs;
1022
1023         if (!machine_is_cardhu())
1024                 return 0;
1025
1026         tegra_get_board_info(&board_info);
1027         tegra_get_pmu_board_info(&pmu_board_info);
1028         tegra_get_display_board_info(&display_board_info);
1029
1030         if (pmu_board_info.board_id == BOARD_PMU_PM298)
1031                 return cardhu_pm298_gpio_switch_regulator_init();
1032
1033         if (pmu_board_info.board_id == BOARD_PMU_PM299)
1034                 return cardhu_pm299_gpio_switch_regulator_init();
1035
1036         switch (board_info.board_id) {
1037         case BOARD_E1198:
1038                 if (board_info.fab <= BOARD_FAB_A01) {
1039                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e1198_base);
1040                         fixed_reg_devs = fixed_reg_devs_e1198_base;
1041                 } else {
1042                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e1198_a02);
1043                         fixed_reg_devs = fixed_reg_devs_e1198_a02;
1044                 }
1045                 break;
1046
1047         case BOARD_E1291:
1048                 if (board_info.fab == BOARD_FAB_A03) {
1049                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e1291_a03);
1050                         fixed_reg_devs = fixed_reg_devs_e1291_a03;
1051                 } else if ((board_info.fab == BOARD_FAB_A04) ||
1052                                 (board_info.fab == BOARD_FAB_A05)) {
1053                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e1291_a04);
1054                         fixed_reg_devs = fixed_reg_devs_e1291_a04;
1055                 } else {
1056                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e1198_base);
1057                         fixed_reg_devs = fixed_reg_devs_e1198_base;
1058                 }
1059                 break;
1060
1061         case BOARD_PM311:
1062         case BOARD_PM305:
1063                 nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm311);
1064                 fixed_reg_devs = fixed_reg_devs_pm311;
1065                 if (display_board_info.board_id == BOARD_DISPLAY_PM313) {
1066                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm311_pm313);
1067                         fixed_reg_devs = fixed_reg_devs_pm311_pm313;
1068                 }
1069                 break;
1070
1071         case BOARD_PM269:
1072         case BOARD_E1257:
1073                 nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm269);
1074                 fixed_reg_devs = fixed_reg_devs_pm269;
1075                 if (display_board_info.board_id == BOARD_DISPLAY_PM313) {
1076                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm269_pm313);
1077                         fixed_reg_devs = fixed_reg_devs_pm269_pm313;
1078                 } else {
1079                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_pm269);
1080                         fixed_reg_devs = fixed_reg_devs_pm269;
1081                 }
1082                 break;
1083
1084         default:
1085                 if (display_board_info.board_id == BOARD_DISPLAY_PM313) {
1086                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e118x_pm313);
1087                         fixed_reg_devs = fixed_reg_devs_e118x_pm313;
1088                 } else {
1089                         nfixreg_devs = ARRAY_SIZE(fixed_reg_devs_e118x);
1090                         fixed_reg_devs = fixed_reg_devs_e118x;
1091                 }
1092                 break;
1093         }
1094
1095         for (i = 0; i < nfixreg_devs; ++i) {
1096                 int gpio_nr;
1097                 if (!strncmp(fixed_reg_devs[i]->name, "gpio", 4)) {
1098                         struct gpio_switch_regulator_platform_data *gs_pdata =
1099                                 fixed_reg_devs[i]->dev.platform_data;
1100                         gpio_nr = gs_pdata->subdevs[0]->gpio_nr;
1101                 } else {
1102                         struct fixed_voltage_config *fixed_reg_pdata =
1103                                 fixed_reg_devs[i]->dev.platform_data;
1104                         gpio_nr = fixed_reg_pdata->gpio;
1105                 }
1106
1107                 if (gpio_nr < TEGRA_NR_GPIOS)
1108                         tegra_gpio_enable(gpio_nr);
1109         }
1110         return platform_add_devices(fixed_reg_devs, nfixreg_devs);
1111 }
1112 subsys_initcall_sync(cardhu_fixed_regulator_init);
1113
1114 static void cardhu_board_suspend(int lp_state, enum suspend_stage stg)
1115 {
1116         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_SUSPEND_BEFORE_CPU))
1117                 tegra_console_uart_suspend();
1118 }
1119
1120 static void cardhu_board_resume(int lp_state, enum resume_stage stg)
1121 {
1122         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_RESUME_AFTER_CPU))
1123                 tegra_console_uart_resume();
1124 }
1125
1126 static struct tegra_suspend_platform_data cardhu_suspend_data = {
1127         .cpu_timer      = 2000,
1128         .cpu_off_timer  = 200,
1129         .suspend_mode   = TEGRA_SUSPEND_LP0,
1130         .core_timer     = 0x7e7e,
1131         .core_off_timer = 0,
1132         .corereq_high   = true,
1133         .sysclkreq_high = true,
1134         .cpu_lp2_min_residency = 2000,
1135         .board_suspend = cardhu_board_suspend,
1136         .board_resume = cardhu_board_resume,
1137 };
1138
1139 int __init cardhu_suspend_init(void)
1140 {
1141         struct board_info board_info;
1142         struct board_info pmu_board_info;
1143
1144         tegra_get_board_info(&board_info);
1145         tegra_get_pmu_board_info(&pmu_board_info);
1146
1147         /* For PMU Fab A03, A04 and A05 make core_pwr_req to high */
1148         if ((pmu_board_info.fab == BOARD_FAB_A03) ||
1149                 (pmu_board_info.fab == BOARD_FAB_A04) ||
1150                  (pmu_board_info.fab == BOARD_FAB_A05))
1151                 cardhu_suspend_data.corereq_high = true;
1152
1153         /* CORE_PWR_REQ to be high for all processor/pmu board whose sku bit 0
1154          * is set. This is require to enable the dc-dc converter tps62361x */
1155         if ((board_info.sku & SKU_DCDC_TPS62361_SUPPORT) || (pmu_board_info.sku & SKU_DCDC_TPS62361_SUPPORT))
1156                 cardhu_suspend_data.corereq_high = true;
1157
1158         switch (board_info.board_id) {
1159         case BOARD_E1291:
1160                 /* CORE_PWR_REQ to be high for E1291-A03 */
1161                 if (board_info.fab == BOARD_FAB_A03)
1162                         cardhu_suspend_data.corereq_high = true;
1163                 break;
1164         case BOARD_E1198:
1165         case BOARD_PM269:
1166         case BOARD_PM305:
1167         case BOARD_PM311:
1168                 break;
1169         case BOARD_E1187:
1170         case BOARD_E1186:
1171         case BOARD_E1256:
1172         case BOARD_E1257:
1173                 cardhu_suspend_data.cpu_timer = 5000;
1174                 cardhu_suspend_data.cpu_off_timer = 5000;
1175                 break;
1176         default:
1177                 break;
1178         }
1179
1180         tegra_init_suspend(&cardhu_suspend_data);
1181         return 0;
1182 }
1183
1184 static struct tegra_tsensor_pmu_data  tpdata = {
1185         .poweroff_reg_addr = 0x3F,
1186         .poweroff_reg_data = 0x80,
1187         .reset_tegra = 1,
1188         .controller_type = 0,
1189         .i2c_controller_id = 4,
1190         .pinmux = 0,
1191         .pmu_16bit_ops = 0,
1192         .pmu_i2c_addr = 0x2D,
1193 };
1194
1195 #ifdef CONFIG_TEGRA_EDP_LIMITS
1196
1197 int __init cardhu_edp_init(void)
1198 {
1199         unsigned int regulator_mA;
1200
1201         regulator_mA = get_maximum_cpu_current_supported();
1202         if (!regulator_mA) {
1203                 regulator_mA = 6000; /* regular T30/s */
1204         }
1205         pr_info("%s: CPU regulator %d mA\n", __func__, regulator_mA);
1206
1207         tegra_init_cpu_edp_limits(regulator_mA);
1208         return 0;
1209 }
1210 #endif
1211
1212 static char *cardhu_battery[] = {
1213         "bq27510-0",
1214 };
1215
1216 static struct gpio_charger_platform_data cardhu_charger_pdata = {
1217         .name = "ac",
1218         .type = POWER_SUPPLY_TYPE_MAINS,
1219         .gpio = AC_PRESENT_GPIO,
1220         .gpio_active_low = 0,
1221         .supplied_to = cardhu_battery,
1222         .num_supplicants = ARRAY_SIZE(cardhu_battery),
1223 };
1224
1225 static struct platform_device cardhu_charger_device = {
1226         .name = "gpio-charger",
1227         .dev = {
1228                 .platform_data = &cardhu_charger_pdata,
1229         },
1230 };
1231
1232 static int __init cardhu_charger_late_init(void)
1233 {
1234         if (!machine_is_cardhu())
1235                 return 0;
1236
1237         platform_device_register(&cardhu_charger_device);
1238         return 0;
1239 }
1240
1241 late_initcall(cardhu_charger_late_init);