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