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