b7fd3654f1da5b47f98ce31cf21891d026c00bca
[linux-2.6.git] / arch / arm / mach-tegra / board-enterprise-power.c
1 /*
2  * arch/arm/mach-tegra/board-enterprise-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/regulator/fixed.h>
26 #include <linux/mfd/tps80031.h>
27 #include <linux/regulator/tps80031-regulator.h>
28 #include <linux/tps80031-charger.h>
29 #include <linux/gpio.h>
30 #include <linux/io.h>
31 #include <linux/cpumask.h>
32 #include <linux/platform_data/tegra_bpc_mgmt.h>
33 #include <linux/regulator/driver.h>
34 #include <linux/regulator/gpio-regulator.h>
35
36 #include <asm/mach-types.h>
37
38 #include <mach/edp.h>
39 #include <mach/iomap.h>
40 #include <mach/irqs.h>
41 #include <mach/pinmux.h>
42
43 #include "gpio-names.h"
44 #include "board.h"
45 #include "board-enterprise.h"
46 #include "pm.h"
47 #include "tegra3_tsensor.h"
48
49 #define PMC_CTRL                0x0
50 #define PMC_CTRL_INTR_LOW       (1 << 17)
51
52 #define PMC_DPD_PADS_ORIDE              0x01c
53 #define PMC_DPD_PADS_ORIDE_BLINK        (1 << 20)
54
55 /************************ TPS80031 based regulator ****************/
56 static struct regulator_consumer_supply tps80031_vio_supply_a02[] = {
57         REGULATOR_SUPPLY("vio_1v8", NULL),
58         REGULATOR_SUPPLY("avdd_osc", NULL),
59         REGULATOR_SUPPLY("vddio_sys", NULL),
60         REGULATOR_SUPPLY("vddio_uart", NULL),
61         REGULATOR_SUPPLY("pwrdet_uart", NULL),
62         REGULATOR_SUPPLY("vddio_lcd", NULL),
63         REGULATOR_SUPPLY("pwrdet_lcd", NULL),
64         REGULATOR_SUPPLY("vddio_audio", NULL),
65         REGULATOR_SUPPLY("pwrdet_audio", NULL),
66         REGULATOR_SUPPLY("vddio_bb", NULL),
67         REGULATOR_SUPPLY("pwrdet_bb", NULL),
68         REGULATOR_SUPPLY("vddio_gmi", NULL),
69         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
70         REGULATOR_SUPPLY("vddio_cam", NULL),
71         REGULATOR_SUPPLY("pwrdet_cam", NULL),
72         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
73         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
74         REGULATOR_SUPPLY("vddio_sdmmc4", NULL),
75         REGULATOR_SUPPLY("pwrdet_sdmmc4", NULL),
76         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
77         REGULATOR_SUPPLY("vddio_gps", NULL),
78         REGULATOR_SUPPLY("vdd_lcd_buffered", NULL),
79         REGULATOR_SUPPLY("vddio_nand", NULL),
80         REGULATOR_SUPPLY("pwrdet_nand", NULL),
81         REGULATOR_SUPPLY("vddio_sd", NULL),
82         REGULATOR_SUPPLY("vdd_bat", NULL),
83         REGULATOR_SUPPLY("vdd_io", NULL),
84         REGULATOR_SUPPLY("pwrdet_pex_ctl", NULL),
85 };
86
87 static struct regulator_consumer_supply tps80031_vio_supply_a03[] = {
88         REGULATOR_SUPPLY("vio_1v8", NULL),
89         REGULATOR_SUPPLY("vddio_sys", NULL),
90         REGULATOR_SUPPLY("vddio_uart", NULL),
91         REGULATOR_SUPPLY("pwrdet_uart", NULL),
92         REGULATOR_SUPPLY("vddio_lcd", NULL),
93         REGULATOR_SUPPLY("pwrdet_lcd", NULL),
94         REGULATOR_SUPPLY("vddio_audio", NULL),
95         REGULATOR_SUPPLY("pwrdet_audio", NULL),
96         REGULATOR_SUPPLY("vddio_bb", NULL),
97         REGULATOR_SUPPLY("pwrdet_bb", NULL),
98         REGULATOR_SUPPLY("vddio_gmi", NULL),
99         REGULATOR_SUPPLY("vddio_cam", NULL),
100         REGULATOR_SUPPLY("pwrdet_cam", NULL),
101         REGULATOR_SUPPLY("vddio_sdmmc1", NULL),
102         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
103         REGULATOR_SUPPLY("vddio_sdmmc4", NULL),
104         REGULATOR_SUPPLY("pwrdet_sdmmc4", NULL),
105         REGULATOR_SUPPLY("avdd_hdmi_pll", NULL),
106         REGULATOR_SUPPLY("vddio_gps", NULL),
107         REGULATOR_SUPPLY("vdd_lcd_buffered", NULL),
108         REGULATOR_SUPPLY("vddio_nand", NULL),
109         REGULATOR_SUPPLY("pwrdet_nand", NULL),
110         REGULATOR_SUPPLY("vddio_sd", NULL),
111         REGULATOR_SUPPLY("vdd_bat", NULL),
112         REGULATOR_SUPPLY("vdd_io", NULL),
113         REGULATOR_SUPPLY("pwrdet_pex_ctl", NULL),
114 };
115
116 static struct regulator_consumer_supply tps80031_smps1_supply_common[] = {
117         REGULATOR_SUPPLY("vdd_cpu", NULL),
118 };
119
120 static struct regulator_consumer_supply tps80031_smps2_supply_common[] = {
121         REGULATOR_SUPPLY("vdd_core", NULL),
122 };
123
124 static struct regulator_consumer_supply tps80031_smps3_supply_common[] = {
125         REGULATOR_SUPPLY("en_vddio_ddr_1v2", NULL),
126         REGULATOR_SUPPLY("vddio_ddr", NULL),
127         REGULATOR_SUPPLY("vdd_lpddr", NULL),
128         REGULATOR_SUPPLY("ddr_comp_pu", NULL),
129 };
130
131 static struct regulator_consumer_supply tps80031_smps4_supply_a02[] = {
132         REGULATOR_SUPPLY("vddio_sdmmc_2v85", NULL),
133         REGULATOR_SUPPLY("pwrdet_sdmmc3", NULL),
134 };
135
136 static struct regulator_consumer_supply tps80031_smps4_supply_a03[] = {
137         REGULATOR_SUPPLY("vddio_sdmmc_2v85", NULL),
138         REGULATOR_SUPPLY("pwrdet_sdmmc3", NULL),
139         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
140         REGULATOR_SUPPLY("vddf_core_emmc", NULL),
141 };
142
143 static struct regulator_consumer_supply tps80031_vana_supply_a02[] = {
144         REGULATOR_SUPPLY("unused_vana", NULL),
145 };
146 #define tps80031_vana_supply_a03 tps80031_vana_supply_a02
147
148 static struct regulator_consumer_supply tps80031_ldo1_supply_a02[] = {
149         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
150         REGULATOR_SUPPLY("avdd_hsic", NULL),
151         REGULATOR_SUPPLY("pwrdet_mipi", NULL),
152 };
153
154 static struct regulator_consumer_supply tps80031_ldo1_supply_a03[] = {
155         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
156 };
157
158 static struct regulator_consumer_supply tps80031_ldo2_supply_common[] = {
159         REGULATOR_SUPPLY("vdd_rtc", NULL),
160 };
161
162 static struct regulator_consumer_supply tps80031_ldo3_supply_common[] = {
163         REGULATOR_SUPPLY("vdd_vbrtr", NULL),
164 };
165
166 static struct regulator_consumer_supply tps80031_ldo4_supply_a02[] = {
167         REGULATOR_SUPPLY("avdd_lcd", NULL),
168 };
169
170 static struct regulator_consumer_supply tps80031_ldo4_supply_a03[] = {
171         REGULATOR_SUPPLY("avdd_dsi_csi", NULL),
172         REGULATOR_SUPPLY("avdd_hsic", NULL),
173         REGULATOR_SUPPLY("pwrdet_mipi", NULL),
174 };
175
176 static struct regulator_consumer_supply tps80031_ldo5_supply_common[] = {
177         REGULATOR_SUPPLY("vdd_sensor", NULL),
178         REGULATOR_SUPPLY("vdd_compass", NULL),
179         REGULATOR_SUPPLY("vdd_als", NULL),
180         REGULATOR_SUPPLY("vdd_gyro", NULL),
181         REGULATOR_SUPPLY("vdd_touch", NULL),
182         REGULATOR_SUPPLY("vdd_proxim_diode", NULL),
183 };
184
185 static struct regulator_consumer_supply tps80031_ldo6_supply_a02[] = {
186         REGULATOR_SUPPLY("vdd_ddr_rx", NULL),
187         REGULATOR_SUPPLY("vddf_core_emmc", NULL),
188 };
189
190 static struct regulator_consumer_supply tps80031_ldo6_supply_a03[] = {
191         REGULATOR_SUPPLY("avdd_osc", NULL),
192         REGULATOR_SUPPLY("avdd_usb_pll", NULL),
193 };
194
195 static struct regulator_consumer_supply tps80031_ldo7_supply_a02[] = {
196         REGULATOR_SUPPLY("vdd_plla_p_c_s", NULL),
197         REGULATOR_SUPPLY("vdd_pllm", NULL),
198         REGULATOR_SUPPLY("vdd_pllu_d", NULL),
199         REGULATOR_SUPPLY("vdd_pllx", NULL),
200 };
201
202 static struct regulator_consumer_supply tps80031_ldo7_supply_a03[] = {
203         REGULATOR_SUPPLY("avdd_lcd", NULL),
204 };
205
206 static struct regulator_consumer_supply tps80031_ldoln_supply_a02[] = {
207         REGULATOR_SUPPLY("vdd_ddr_hs", NULL),
208 };
209
210 static struct regulator_consumer_supply tps80031_ldoln_supply_a03[] = {
211         REGULATOR_SUPPLY("vdd_plla_p_c_s", NULL),
212         REGULATOR_SUPPLY("vdd_pllm", NULL),
213         REGULATOR_SUPPLY("vdd_pllu_d", NULL),
214         REGULATOR_SUPPLY("vdd_pllx", NULL),
215 };
216
217 static struct regulator_consumer_supply tps80031_ldousb_supply_a02[] = {
218         REGULATOR_SUPPLY("unused_ldousb", NULL),
219 };
220
221 static struct regulator_consumer_supply tps80031_ldousb_supply_a03[] = {
222         REGULATOR_SUPPLY("avdd_usb_hdmi_3v3", NULL),
223         REGULATOR_SUPPLY("avdd_usb", NULL),
224         REGULATOR_SUPPLY("avdd_hdmi", NULL),
225         REGULATOR_SUPPLY("vdd", "4-004c"),
226 };
227
228 static struct regulator_consumer_supply tps80031_vbus_supply_common[] = {
229         REGULATOR_SUPPLY("usb_vbus", NULL),
230 };
231
232 static struct regulator_consumer_supply tps80031_battery_charge_supply[] = {
233         REGULATOR_SUPPLY("usb_bat_chg", NULL),
234 };
235
236 #define TPS_PDATA_INIT(_reg_id, _id, _sname, _minmv, _maxmv, _supply_reg, _always_on,   \
237         _boot_on, _apply_uv, _init_uV, _init_enable, _init_apply,                       \
238         _flags, _ectrl, _delay)                                                         \
239         static struct regulator_init_data reg_idata_##_id##_##_sname = {                \
240                 .constraints = {                                                        \
241                         .name = tps80031_rails(_id),                                    \
242                         .min_uV = (_minmv)*1000,                                        \
243                         .max_uV = (_maxmv)*1000,                                        \
244                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |                    \
245                                         REGULATOR_MODE_STANDBY),                        \
246                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |                      \
247                                         REGULATOR_CHANGE_STATUS |                       \
248                                         REGULATOR_CHANGE_VOLTAGE),                      \
249                         .always_on = _always_on,                                        \
250                         .boot_on = _boot_on,                                            \
251                         .apply_uV = _apply_uv,                                          \
252                 },                                                                      \
253                 .num_consumer_supplies =                                                \
254                         ARRAY_SIZE(tps80031_##_id##_supply_##_sname),                   \
255                 .consumer_supplies = tps80031_##_id##_supply_##_sname,                  \
256         };                                                                              \
257         static struct tps80031_regulator_platform_data pdata_##_id##_##_sname = {       \
258                 .reg_init_data = &reg_idata_##_id##_##_sname,                           \
259                 .regulator_id = TPS80031_REGULATOR_##_reg_id,                           \
260                 .init_uV =  _init_uV * 1000,                                            \
261                 .init_enable = _init_enable,                                            \
262                 .init_apply = _init_apply,                                              \
263                 .flags = _flags,                                                        \
264                 .ext_ctrl_flag = _ectrl,                                                \
265                 .delay_us = _delay,                                                     \
266         }
267
268 TPS_PDATA_INIT(VIO, vio, a02,   600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
269 TPS_PDATA_INIT(VIO, vio, a03,   600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
270 TPS_PDATA_INIT(SMPS1, smps1, common, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ2 | PWR_OFF_ON_SLEEP, 0);
271 TPS_PDATA_INIT(SMPS2, smps2, common, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
272 TPS_PDATA_INIT(SMPS3, smps3, common, 600, 2100, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0);
273 TPS_PDATA_INIT(SMPS4, smps4, a02, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
274 TPS_PDATA_INIT(SMPS4, smps4, a03, 600, 2100, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
275 TPS_PDATA_INIT(LDO1, ldo1, a02, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, 0, 0);
276 TPS_PDATA_INIT(LDO1, ldo1, a03, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
277 TPS_PDATA_INIT(LDO2, ldo2, common, 1000, 1000, 0, 1, 1, 1, -1, 0, 0, 0, 0, 0);
278 TPS_PDATA_INIT(LDO3, ldo3, common, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_OFF_ON_SLEEP, 0);
279 TPS_PDATA_INIT(LDO4, ldo4, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
280 TPS_PDATA_INIT(LDO4, ldo4, a03, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
281 TPS_PDATA_INIT(LDO5, ldo5, common, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
282 TPS_PDATA_INIT(LDO6, ldo6, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
283 TPS_PDATA_INIT(LDO6, ldo6, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
284 TPS_PDATA_INIT(LDO7, ldo7, a02, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
285 TPS_PDATA_INIT(LDO7, ldo7, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
286 TPS_PDATA_INIT(LDOLN, ldoln, a02, 1000, 3300, tps80031_rails(smps3), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
287 TPS_PDATA_INIT(LDOLN, ldoln, a03, 1000, 3300, tps80031_rails(vio), 0, 0, 0, -1, 0, 0, 0, PWR_REQ_INPUT_PREQ1, 0);
288 TPS_PDATA_INIT(LDOUSB, ldousb, a02, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, USBLDO_INPUT_VSYS, PWR_OFF_ON_SLEEP, 0);
289 TPS_PDATA_INIT(LDOUSB, ldousb, a03, 1000, 3300, 0, 0, 0, 0, -1, 0, 0, USBLDO_INPUT_VSYS, PWR_REQ_INPUT_PREQ1, 0);
290 TPS_PDATA_INIT(VANA, vana, a02,  1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0);
291 TPS_PDATA_INIT(VANA, vana, a03,  1000, 3300, 0, 0, 0, 0, -1, 0, 0, 0, PWR_OFF_ON_SLEEP, 0);
292 TPS_PDATA_INIT(VBUS, vbus, common,  0, 5000, 0, 0, 0, 0, -1, 0, 0, (VBUS_SW_ONLY | VBUS_DISCHRG_EN_PDN), 0, 100000);
293
294 static struct tps80031_rtc_platform_data rtc_data = {
295         .irq = ENT_TPS80031_IRQ_BASE + TPS80031_INT_RTC_ALARM,
296         .time = {
297                 .tm_year = 2011,
298                 .tm_mon = 0,
299                 .tm_mday = 1,
300                 .tm_hour = 1,
301                 .tm_min = 2,
302                 .tm_sec = 3,
303         },
304         .msecure_gpio = TEGRA_GPIO_PF7,
305 };
306
307 int battery_charger_init(void *board_data)
308 {
309         int ret;
310         ret = gpio_request(TEGRA_GPIO_PF6, "lcd_d14-bat_charge");
311         if (ret < 0) {
312                 pr_err("%s() The gpio_request for battery"
313                                 " charger fails\n", __func__);
314         }
315         gpio_direction_output(TEGRA_GPIO_PF6, 1);
316         return 0;
317 }
318
319 static struct tps80031_charger_platform_data bcharger_pdata = {
320         .max_charge_volt_mV = 4100,
321         .max_charge_current_mA = 1000,
322         .charging_term_current_mA = 100,
323         .watch_time_sec = 100,
324         .irq_base = ENT_TPS80031_IRQ_BASE,
325         .consumer_supplies = tps80031_battery_charge_supply,
326         .num_consumer_supplies = ARRAY_SIZE(tps80031_battery_charge_supply),
327         .board_init = battery_charger_init,
328         .board_data = NULL,
329 };
330
331 static struct tps80031_bg_platform_data battery_gauge_data = {
332         .irq_base = ENT_TPS80031_IRQ_BASE,
333         .battery_present = 1,
334 };
335
336 #define TPS_REG_PDATA(_id, _sname) &pdata_##_id##_##_sname
337 static struct tps80031_regulator_platform_data *tps80031_reg_pdata_a02[] = {
338         TPS_REG_PDATA(vio, a02),
339         TPS_REG_PDATA(smps1, common),
340         TPS_REG_PDATA(smps2, common),
341         TPS_REG_PDATA(smps3, common),
342         TPS_REG_PDATA(ldo2, common),
343         TPS_REG_PDATA(ldo3, common),
344         TPS_REG_PDATA(ldo5, common),
345         TPS_REG_PDATA(vbus, common),
346         TPS_REG_PDATA(smps4, a02),
347         TPS_REG_PDATA(ldo1, a02),
348         TPS_REG_PDATA(ldo4, a02),
349         TPS_REG_PDATA(ldo6, a02),
350         TPS_REG_PDATA(ldo7, a02),
351         TPS_REG_PDATA(ldoln, a02),
352         TPS_REG_PDATA(ldousb, a02),
353         TPS_REG_PDATA(vana, a02),
354 };
355
356 static struct tps80031_regulator_platform_data *tps80031_reg_pdata_a03[] = {
357         TPS_REG_PDATA(vio, a03),
358         TPS_REG_PDATA(smps1, common),
359         TPS_REG_PDATA(smps2, common),
360         TPS_REG_PDATA(smps3, common),
361         TPS_REG_PDATA(ldo2, common),
362         TPS_REG_PDATA(ldo3, common),
363         TPS_REG_PDATA(ldo5, common),
364         TPS_REG_PDATA(vbus, common),
365         TPS_REG_PDATA(smps4, a03),
366         TPS_REG_PDATA(ldo1, a03),
367         TPS_REG_PDATA(ldo4, a03),
368         TPS_REG_PDATA(ldo6, a03),
369         TPS_REG_PDATA(ldo7, a03),
370         TPS_REG_PDATA(ldoln, a03),
371         TPS_REG_PDATA(ldousb, a03),
372         TPS_REG_PDATA(vana, a03),
373 };
374
375 static struct tps80031_clk32k_init_data clk32k_idata[] = {
376         {
377                 .clk32k_nr = TPS80031_CLOCK32K_G,
378                 .enable = true,
379                 .ext_ctrl_flag = 0,
380         },
381         {
382                 .clk32k_nr = TPS80031_CLOCK32K_AUDIO,
383                 .enable = true,
384                 .ext_ctrl_flag = 0,
385         },
386
387
388 };
389
390 static struct tps80031_gpio_init_data gpio_idata_a03[] = {
391         {
392                 .gpio_nr = TPS80031_GPIO_REGEN1,
393                 .ext_ctrl_flag = PWR_REQ_INPUT_PREQ1,
394         },
395         {
396                 .gpio_nr = TPS80031_GPIO_REGEN2,
397                 .ext_ctrl_flag = PWR_REQ_INPUT_PREQ1,
398         },
399         {
400                 .gpio_nr = TPS80031_GPIO_SYSEN,
401                 .ext_ctrl_flag = PWR_REQ_INPUT_PREQ1,
402         },
403 };
404
405 static struct tps80031_pupd_init_data pupd_idata[] = {
406         {
407                 .input_pin = TPS80031_PREQ1,
408                 .setting = TPS80031_PUPD_PULLUP,
409         },
410 };
411
412 static struct tps80031_platform_data tps_platform = {
413         .irq_base       = ENT_TPS80031_IRQ_BASE,
414         .gpio_base      = ENT_TPS80031_GPIO_BASE,
415         .clk32k_init_data       = clk32k_idata,
416         .clk32k_init_data_size  = ARRAY_SIZE(clk32k_idata),
417         .use_power_off  = true,
418         .rtc_pdata = &rtc_data,
419         .bg_pdata = &battery_gauge_data,
420         .battery_charger_pdata = &bcharger_pdata,
421 };
422
423 static struct i2c_board_info __initdata enterprise_regulators[] = {
424         {
425                 I2C_BOARD_INFO("tps80031", 0x4A),
426                 .irq            = INT_EXTERNAL_PMU,
427                 .platform_data  = &tps_platform,
428         },
429 };
430
431 /************************ GPIO based fixed regulator ****************/
432 /* REGEN1 from PMU*/
433 static struct regulator_consumer_supply fixed_reg_pmu_5v15_en_supply[] = {
434         REGULATOR_SUPPLY("vdd_5v15", NULL),
435 };
436
437 /* REGEN2 from PMU*/
438 static struct regulator_consumer_supply fixed_reg_pmu_3v3_en_supply[] = {
439         REGULATOR_SUPPLY("avdd_usb_hdmi_3v3", NULL),
440         REGULATOR_SUPPLY("avdd_usb", NULL),
441         REGULATOR_SUPPLY("avdd_hdmi", NULL),
442         REGULATOR_SUPPLY("vdd", "4-004c"),
443 };
444
445 /* SYSEN from PMU*/
446 static struct regulator_consumer_supply fixed_reg_pmu_hdmi_5v0_en_supply[] = {
447         REGULATOR_SUPPLY("hdmi_5v0", NULL),
448 };
449 static struct regulator_consumer_supply
450 fixed_reg_pmu_hdmi_5v0_en_tai_supply[] = {
451         REGULATOR_SUPPLY("hdmi_5v0", NULL),
452 };
453
454 /* LCD-D16 (GPIO M0) from T30*/
455 static struct regulator_consumer_supply fixed_reg_vdd_fuse_en_supply[] = {
456         REGULATOR_SUPPLY("vdd_fuse", NULL),
457 };
458
459 /* LCD-D17 (GPIO M1) from T30*/
460 static struct regulator_consumer_supply gpio_reg_sdmmc3_vdd_sel_supply[] = {
461         REGULATOR_SUPPLY("vddio_sdmmc3_2v85_1v8", NULL),
462         REGULATOR_SUPPLY("sdmmc3_compu_pu", NULL),
463         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.2"),
464         REGULATOR_SUPPLY("vsys_3v7", NULL),
465 };
466
467 /* LCD-D23 (GPIO M7) from T30*/
468 /* 2-0036 is dev_name of ar0832 in Enterprise A01*/
469 /* 2-0032 is alternative dev_name of ar0832 Enterprise A01*/
470 /* 2-0010 is dev_name of ov9726 */
471 /* 2-0070 is dev_name of PCA9546 in Enterprise A02*/
472 /* 6-0036 is dev_name of ar0832 in Enterprise A02 */
473 /* 7-0036 is dev_name of ar0832 in Enterprise A02 */
474 static struct regulator_consumer_supply fixed_reg_cam_ldo_2v8_en_supply[] = {
475         REGULATOR_SUPPLY("vaa", "2-0036"),
476         REGULATOR_SUPPLY("vaa", "2-0032"),
477         REGULATOR_SUPPLY("avdd", "2-0010"),
478         REGULATOR_SUPPLY("vdd_2v8_cam", NULL),
479         REGULATOR_SUPPLY("vcc", "2-0070"),
480         REGULATOR_SUPPLY("vaa", "6-0036"),
481         REGULATOR_SUPPLY("vaa", "7-0036"),
482 };
483
484 /* LCD-D9 (GPIO F1) from T30*/
485 /* 2-0036 is dev_name of ar0832 in Enterprise A01*/
486 /* 2-0032 is alternative dev_name of ar0832 Enterprise A01*/
487 /* 2-0010 is dev_name of ov9726 */
488 /* 2-0033 is dev_name of tps61050 */
489 /* 2-0070 is dev_name of PCA9546 in Enterprise A02*/
490 /* 6-0036 is dev_name of ar0832 in Enterprise A02 */
491 /* 7-0036 is dev_name of ar0832 in Enterprise A02 */
492 static struct regulator_consumer_supply fixed_reg_cam_ldo_1v8_en_supply[] = {
493         REGULATOR_SUPPLY("vdd", "2-0036"),
494         REGULATOR_SUPPLY("vdd", "2-0032"),
495         REGULATOR_SUPPLY("dovdd", "2-0010"),
496         REGULATOR_SUPPLY("vdd_1v8_cam", NULL),
497         REGULATOR_SUPPLY("vdd_i2c", "2-0033"),
498         REGULATOR_SUPPLY("vcc_i2c", "2-0070"),
499         REGULATOR_SUPPLY("vdd", "6-0036"),
500         REGULATOR_SUPPLY("vdd", "7-0036"),
501 };
502
503 /* LCD-D10 (GPIO F2) from T30*/
504 static struct regulator_consumer_supply fixed_reg_vdd_sdmmc3_2v85_en_supply[] = {
505         REGULATOR_SUPPLY("en_vdd_sdmmc3", NULL),
506         REGULATOR_SUPPLY("vddio_sd_slot", "sdhci-tegra.2"),
507 };
508
509 /* LCD_PWR0 (GPIO B2) from T30*/
510 static struct regulator_consumer_supply fixed_reg_lcd_1v8_en_supply[] = {
511         REGULATOR_SUPPLY("lcd_vddio_en", NULL),
512 };
513
514 static struct gpio_regulator_state gpio_reg_sdmmc3_vdd_sel_states[] = {
515         {
516                 .gpios = 0,
517                 .value = 2850000,
518         },
519         {
520                 .gpios = 1,
521                 .value = 1800000,
522         },
523 };
524
525 static struct gpio gpio_reg_sdmmc3_vdd_sel_gpios[] = {
526         {
527                 .gpio = TEGRA_GPIO_PM1,
528                 .flags = 0,
529                 .label = "sdmmc3_vdd_sel",
530         },
531 };
532
533 /* Macro for defining gpio regulator device data */
534 #define GPIO_REG(_id, _name, _input_supply, _active_high,               \
535         _boot_state, _delay_us, _minmv, _maxmv)                         \
536         static struct regulator_init_data ri_data_##_name =             \
537         {                                                               \
538                 .supply_regulator = _input_supply,                      \
539                 .num_consumer_supplies =                                \
540                         ARRAY_SIZE(gpio_reg_##_name##_supply),          \
541                 .consumer_supplies = gpio_reg_##_name##_supply,         \
542                 .constraints = {                                        \
543                         .name = "gpio_reg_"#_name,                      \
544                         .min_uV = (_minmv)*1000,                        \
545                         .max_uV = (_maxmv)*1000,                        \
546                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
547                                         REGULATOR_MODE_STANDBY),        \
548                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
549                                         REGULATOR_CHANGE_STATUS |       \
550                                         REGULATOR_CHANGE_VOLTAGE),      \
551                 },                                                      \
552         };                                                              \
553         static struct gpio_regulator_config gpio_reg_##_name##_pdata =  \
554         {                                                               \
555                 .supply_name = _input_supply,                           \
556                 .enable_gpio = -EINVAL,                                 \
557                 .enable_high = _active_high,                            \
558                 .enabled_at_boot = _boot_state,                         \
559                 .startup_delay = _delay_us,                             \
560                 .gpios = gpio_reg_##_name##_gpios,                      \
561                 .nr_gpios = ARRAY_SIZE(gpio_reg_##_name##_gpios),       \
562                 .states = gpio_reg_##_name##_states,                    \
563                 .nr_states = ARRAY_SIZE(gpio_reg_##_name##_states),     \
564                 .type = REGULATOR_VOLTAGE,                              \
565                 .init_data = &ri_data_##_name,                          \
566         };                                                              \
567         static struct platform_device gpio_reg_##_name##_dev = {        \
568                 .name   = "gpio-regulator",                             \
569                 .id = _id,                                              \
570                 .dev    = {                                             \
571                         .platform_data = &gpio_reg_##_name##_pdata,     \
572                 },                                                      \
573         }
574
575 GPIO_REG(4, sdmmc3_vdd_sel,  tps80031_rails(smps4),
576                 true, false, 0, 1000, 3300);
577
578 /* Macro for defining fixed regulator sub device data */
579 #define FIXED_REG(_id, _name, _input_supply, _gpio_nr, _active_high,    \
580                         _millivolts, _boot_state, _sdelay)              \
581         static struct regulator_init_data ri_data_##_name =             \
582         {                                                               \
583                 .supply_regulator = _input_supply,                      \
584                 .num_consumer_supplies =                                \
585                         ARRAY_SIZE(fixed_reg_##_name##_supply),         \
586                 .consumer_supplies = fixed_reg_##_name##_supply,        \
587                 .constraints = {                                        \
588                         .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
589                                         REGULATOR_MODE_STANDBY),        \
590                         .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
591                                         REGULATOR_CHANGE_STATUS |       \
592                                         REGULATOR_CHANGE_VOLTAGE),      \
593                 },                                                      \
594         };                                                              \
595         static struct fixed_voltage_config fixed_reg_##_name##_pdata =  \
596         {                                                               \
597                 .supply_name = "fixed_reg_"#_name,                      \
598                 .microvolts = _millivolts * 1000,                       \
599                 .gpio = _gpio_nr,                                       \
600                 .enable_high = _active_high,                            \
601                 .enabled_at_boot = _boot_state,                         \
602                 .init_data = &ri_data_##_name,                          \
603                 .startup_delay = _sdelay,                               \
604         };                                                              \
605         static struct platform_device fixed_reg_##_name##_dev = {       \
606                 .name   = "reg-fixed-voltage",                          \
607                 .id     = _id,                                          \
608                 .dev    = {                                             \
609                         .platform_data = &fixed_reg_##_name##_pdata,    \
610                 },                                                      \
611         }
612
613 FIXED_REG(0, pmu_5v15_en,     NULL,
614                 ENT_TPS80031_GPIO_REGEN1, true, 5000, 0 , 0);
615 FIXED_REG(2, pmu_hdmi_5v0_en, "fixed_reg_pmu_5v15_en",
616                 ENT_TPS80031_GPIO_SYSEN, true, 5000, 0, 0);
617 FIXED_REG(3, vdd_fuse_en,     "fixed_reg_pmu_3v3_en",
618                 TEGRA_GPIO_PM0, true, 3300, 0, 0);
619 FIXED_REG(5, cam_ldo_2v8_en,  NULL,
620                 TEGRA_GPIO_PM7, true, 2800, 0, 0);
621 FIXED_REG(6, cam_ldo_1v8_en,  NULL,
622                 TEGRA_GPIO_PF1, true, 1800, 0, 0);
623
624 /* Enterprise A02- specific */
625 FIXED_REG(1, pmu_3v3_en,      "fixed_reg_pmu_5v15_en",
626                 ENT_TPS80031_GPIO_REGEN2, true, 3300, 0, 500);
627
628 /* Enterprise A03+ specific */
629 FIXED_REG(7, vdd_sdmmc3_2v85_en,  NULL,
630                 TEGRA_GPIO_PF2, true, 2850, 0, 0);
631 FIXED_REG(8, lcd_1v8_en,  NULL,
632                 TEGRA_GPIO_PB2, true, 1800, 0, 0);
633
634 FIXED_REG(9, pmu_hdmi_5v0_en_tai, NULL,
635                 ENT_TPS80031_GPIO_SYSEN, true, 5000, 0, 0);
636
637 #define ADD_FIXED_REG(_name)    (&fixed_reg_##_name##_dev)
638 static struct platform_device *fixed_regs_devices_a02[] = {
639         ADD_FIXED_REG(pmu_5v15_en),
640         ADD_FIXED_REG(pmu_3v3_en),
641         ADD_FIXED_REG(pmu_hdmi_5v0_en),
642         ADD_FIXED_REG(vdd_fuse_en),
643         ADD_FIXED_REG(cam_ldo_2v8_en),
644         ADD_FIXED_REG(cam_ldo_1v8_en)
645 };
646
647 static struct platform_device *fixed_regs_devices_a03[] = {
648         ADD_FIXED_REG(pmu_5v15_en),
649         ADD_FIXED_REG(pmu_hdmi_5v0_en),
650         ADD_FIXED_REG(vdd_fuse_en),
651         ADD_FIXED_REG(cam_ldo_2v8_en),
652         ADD_FIXED_REG(cam_ldo_1v8_en),
653         ADD_FIXED_REG(vdd_sdmmc3_2v85_en),
654         ADD_FIXED_REG(lcd_1v8_en),
655 };
656
657 static struct platform_device *fixed_regs_devices_tai[] = {
658         ADD_FIXED_REG(pmu_hdmi_5v0_en_tai),
659         ADD_FIXED_REG(cam_ldo_2v8_en),
660         ADD_FIXED_REG(cam_ldo_1v8_en),
661         ADD_FIXED_REG(vdd_sdmmc3_2v85_en),
662         ADD_FIXED_REG(lcd_1v8_en),
663 };
664
665 #define ADD_GPIO_REG(_name) (&gpio_reg_##_name##_dev)
666 static struct platform_device *gpio_regs_devices[] = {
667         ADD_GPIO_REG(sdmmc3_vdd_sel),
668 };
669
670 static int __init enterprise_fixed_regulator_init(void)
671 {
672         struct board_info board_info;
673         struct platform_device **fixed_regs_devices;
674         int nfixreg_devs;
675
676         tegra_get_board_info(&board_info);
677
678         if (board_info.board_id == BOARD_E1239) {
679                 fixed_regs_devices = fixed_regs_devices_tai;
680                 nfixreg_devs = ARRAY_SIZE(fixed_regs_devices_tai);
681         } else {
682                 if (board_info.fab < BOARD_FAB_A03) {
683                         fixed_regs_devices = fixed_regs_devices_a02;
684                         nfixreg_devs = ARRAY_SIZE(fixed_regs_devices_a02);
685                 } else {
686                         fixed_regs_devices = fixed_regs_devices_a03;
687                         nfixreg_devs = ARRAY_SIZE(fixed_regs_devices_a03);
688                 }
689         }
690         return platform_add_devices(fixed_regs_devices, nfixreg_devs);
691 }
692
693 static int __init enterprise_gpio_regulator_init(void)
694 {
695         return platform_add_devices(gpio_regs_devices,
696                                     ARRAY_SIZE(gpio_regs_devices));
697 }
698
699 static int __init enterprise_regulators_fixed_gpio_init(void)
700 {
701         int ret;
702
703         if (!machine_is_tegra_enterprise())
704                 return 0;
705
706         ret = enterprise_fixed_regulator_init();
707         if (ret)
708                 return ret;
709
710         ret = enterprise_gpio_regulator_init();
711         return ret;
712 }
713 subsys_initcall_sync(enterprise_regulators_fixed_gpio_init);
714
715 int __init enterprise_regulator_init(void)
716 {
717         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
718         u32 pmc_ctrl;
719         u32 pmc_dpd_pads;
720         struct board_info board_info;
721
722         tegra_get_board_info(&board_info);
723
724         /* configure the power management controller to trigger PMU
725          * interrupts when low */
726
727         pmc_ctrl = readl(pmc + PMC_CTRL);
728         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
729
730         pmc_dpd_pads = readl(pmc + PMC_DPD_PADS_ORIDE);
731         writel(pmc_dpd_pads & ~PMC_DPD_PADS_ORIDE_BLINK , pmc + PMC_DPD_PADS_ORIDE);
732
733         /* Setting CPU voltage tolerance in lower side for 3000uV */
734         pdata_smps1_common.tolerance_uv = 3000;
735
736         /* Disable battery charging if power adapter is connected. */
737         if (get_power_supply_type() == POWER_SUPPLY_TYPE_MAINS) {
738                 bcharger_pdata.num_consumer_supplies = 0;
739                 bcharger_pdata.consumer_supplies = NULL;
740                 battery_gauge_data.battery_present = 0;
741         }
742
743         if ((board_info.fab < BOARD_FAB_A03) &&
744                         (board_info.board_id != BOARD_E1239)) {
745                 tps_platform.num_regulator_pdata = ARRAY_SIZE(tps80031_reg_pdata_a02);
746                 tps_platform.regulator_pdata = tps80031_reg_pdata_a02;
747         } else {
748                 tps_platform.num_regulator_pdata = ARRAY_SIZE(tps80031_reg_pdata_a03);
749                 tps_platform.regulator_pdata = tps80031_reg_pdata_a03;
750                 tps_platform.pupd_init_data = pupd_idata;
751                 tps_platform.pupd_init_data_size = ARRAY_SIZE(pupd_idata);
752                 tps_platform.gpio_init_data = gpio_idata_a03;
753                 tps_platform.gpio_init_data_size = ARRAY_SIZE(gpio_idata_a03);
754         }
755
756         i2c_register_board_info(4, enterprise_regulators, 1);
757         return 0;
758 }
759
760 static void enterprise_board_suspend(int lp_state, enum suspend_stage stg)
761 {
762         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_SUSPEND_BEFORE_CPU))
763                 tegra_console_uart_suspend();
764 }
765
766 static void enterprise_board_resume(int lp_state, enum resume_stage stg)
767 {
768         if ((lp_state == TEGRA_SUSPEND_LP1) && (stg == TEGRA_RESUME_AFTER_CPU))
769                 tegra_console_uart_resume();
770 }
771
772 static struct tegra_suspend_platform_data enterprise_suspend_data = {
773         .cpu_timer      = 2000,
774         .cpu_off_timer  = 200,
775         .suspend_mode   = TEGRA_SUSPEND_LP0,
776         .core_timer     = 0x7e7e,
777         .core_off_timer = 0,
778         .corereq_high   = true,
779         .sysclkreq_high = true,
780         .board_suspend = enterprise_board_suspend,
781         .board_resume = enterprise_board_resume,
782 #ifdef CONFIG_TEGRA_LP1_950
783         .lp1_lowvolt_support = true,
784         .i2c_base_addr = TEGRA_I2C5_BASE,
785         .pmuslave_addr = 0x24,
786         .core_reg_addr = 0x5B,
787         .lp1_core_volt_low = 0x1D,
788         .lp1_core_volt_high = 0x33,
789 #endif
790 };
791
792 static void enterprise_init_deep_sleep_mode(void)
793 {
794         struct board_info bi;
795         tegra_get_board_info(&bi);
796
797         if (bi.board_id == BOARD_E1205 && bi.fab == BOARD_FAB_A01)
798                 enterprise_suspend_data.suspend_mode = TEGRA_SUSPEND_LP1;
799
800         if ((bi.board_id == BOARD_E1205 && (bi.sku & BOARD_SKU_VF_BIT) == 0) ||
801             (bi.board_id == BOARD_E1239 && (bi.sku & BOARD_SKU_VF_BIT) == 0) ||
802             (bi.board_id == BOARD_E1197 && (bi.sku & BOARD_SKU_VF_BIT)))
803                 enterprise_suspend_data.cpu_timer = 8000;
804 }
805
806 int __init enterprise_suspend_init(void)
807 {
808         enterprise_init_deep_sleep_mode();
809         tegra_init_suspend(&enterprise_suspend_data);
810         return 0;
811 }
812
813 #ifdef CONFIG_TEGRA_EDP_LIMITS
814
815 int __init enterprise_edp_init(void)
816 {
817         unsigned int regulator_mA;
818
819         regulator_mA = get_maximum_cpu_current_supported();
820         if (!regulator_mA) {
821                 regulator_mA = 2500; /* regular AP30 */
822         }
823         pr_info("%s: CPU regulator %d mA\n", __func__, regulator_mA);
824
825         tegra_init_cpu_edp_limits(regulator_mA);
826         tegra_init_system_edp_limits(TEGRA_BPC_CPU_PWR_LIMIT);
827         return 0;
828 }
829 #endif
830
831 static struct tegra_bpc_mgmt_platform_data bpc_mgmt_platform_data = {
832         .gpio_trigger = TEGRA_BPC_TRIGGER,
833         .bpc_mgmt_timeout = TEGRA_BPC_TIMEOUT,
834 };
835
836 static struct platform_device enterprise_bpc_mgmt_device = {
837         .name           = "tegra-bpc-mgmt",
838         .id             = -1,
839         .dev            = {
840                 .platform_data = &bpc_mgmt_platform_data,
841         },
842 };
843
844 void __init enterprise_bpc_mgmt_init(void)
845 {
846 #ifdef CONFIG_SMP
847         int int_gpio = TEGRA_GPIO_TO_IRQ(TEGRA_BPC_TRIGGER);
848
849         cpumask_setall(&(bpc_mgmt_platform_data.affinity_mask));
850         irq_set_affinity_hint(int_gpio,
851                                 &(bpc_mgmt_platform_data.affinity_mask));
852         irq_set_affinity(int_gpio, &(bpc_mgmt_platform_data.affinity_mask));
853 #endif
854         platform_device_register(&enterprise_bpc_mgmt_device);
855
856         return;
857 }