ARM: tegra: loki: fix build error due to warning
[linux-3.10.git] / arch / arm / mach-tegra / board-tn8-power.c
1 /*
2  * arch/arm/mach-tegra/board-tn8-power.c
3  *
4  * Copyright (c) 2013 NVIDIA Corporation. All rights reserved.
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #include <linux/i2c.h>
21 #include <linux/platform_device.h>
22 #include <linux/resource.h>
23 #include <linux/io.h>
24 #include <linux/regulator/fixed.h>
25 #include <linux/mfd/palmas.h>
26 #include <linux/regulator/machine.h>
27 #include <linux/irq.h>
28
29 #include <linux/gpio.h>
30 #include <linux/power/bq2419x-charger.h>
31 #include <linux/power/power_supply_extcon.h>
32 #include <linux/max17048_battery.h>
33 #include <linux/tegra-soc.h>
34 #include <linux/generic_adc_thermal.h>
35
36 #include <mach/irqs.h>
37
38 #include <asm/mach-types.h>
39
40 #include "pm.h"
41 #include "board.h"
42 #include "tegra-board-id.h"
43 #include "board-common.h"
44 #include "board-ardbeg.h"
45 #include "board-pmu-defines.h"
46 #include "devices.h"
47 #include "iomap.h"
48 #include "tegra-board-id.h"
49 #include "battery-ini-model-data.h"
50
51 #define PMC_CTRL                0x0
52 #define PMC_CTRL_INTR_LOW       (1 << 17)
53
54 /* -40 to 125 degC */
55 static int tn8_batt_temperature_table[] = {
56         259, 266, 272, 279, 286, 293, 301, 308,
57         316, 324, 332, 340, 349, 358, 367, 376,
58         386, 395, 405, 416, 426, 437, 448, 459,
59         471, 483, 495, 508, 520, 533, 547, 561,
60         575, 589, 604, 619, 634, 650, 666, 682,
61         699, 716, 733, 751, 769, 787, 806, 825,
62         845, 865, 885, 905, 926, 947, 969, 990,
63         1013, 1035, 1058, 1081, 1104, 1127, 1151, 1175,
64         1199, 1224, 1249, 1273, 1298, 1324, 1349, 1374,
65         1400, 1426, 1451, 1477, 1503, 1529, 1554, 1580,
66         1606, 1631, 1657, 1682, 1707, 1732, 1757, 1782,
67         1807, 1831, 1855, 1878, 1902, 1925, 1948, 1970,
68         1992, 2014, 2036, 2057, 2077, 2097, 2117, 2136,
69         2155, 2174, 2192, 2209, 2227, 2243, 2259, 2275,
70         2291, 2305, 2320, 2334, 2347, 2361, 2373, 2386,
71         2397, 2409, 2420, 2430, 2441, 2450, 2460, 2469,
72         2478, 2486, 2494, 2502, 2509, 2516, 2523, 2529,
73         2535, 2541, 2547, 2552, 2557, 2562, 2567, 2571,
74         2575, 2579, 2583, 2587, 2590, 2593, 2596, 2599,
75         2602, 2605, 2607, 2609, 2611, 2614, 2615, 2617,
76         2619, 2621, 2622, 2624, 2625, 2626,
77 };
78
79 /* BQ2419X VBUS regulator */
80 static struct regulator_consumer_supply bq2419x_vbus_supply[] = {
81         REGULATOR_SUPPLY("usb_vbus", "tegra-ehci.0"),
82         REGULATOR_SUPPLY("usb_vbus", "tegra-otg"),
83 };
84
85 static struct regulator_consumer_supply bq2419x_batt_supply[] = {
86         REGULATOR_SUPPLY("usb_bat_chg", "tegra-udc.0"),
87 };
88
89 static struct bq2419x_vbus_platform_data bq2419x_vbus_pdata = {
90         .gpio_otg_iusb = TEGRA_GPIO_PI4,
91         .num_consumer_supplies = ARRAY_SIZE(bq2419x_vbus_supply),
92         .consumer_supplies = bq2419x_vbus_supply,
93 };
94
95 static struct bq2419x_charger_platform_data bq2419x_charger_pdata = {
96         .max_charge_current_mA = 3000,
97         .charging_term_current_mA = 100,
98         .consumer_supplies = bq2419x_batt_supply,
99         .num_consumer_supplies = ARRAY_SIZE(bq2419x_batt_supply),
100         .wdt_timeout    = 40,
101         .rtc_alarm_time = 3600,
102         .chg_restart_time = 1800,
103 };
104
105 struct bq2419x_platform_data tn8_bq2419x_pdata = {
106         .vbus_pdata = &bq2419x_vbus_pdata,
107 };
108
109 static struct i2c_board_info __initdata bq2419x_boardinfo[] = {
110         {
111                 I2C_BOARD_INFO("bq2419x", 0x6b),
112                 .platform_data = &tn8_bq2419x_pdata,
113         },
114 };
115
116
117 static struct regulator_consumer_supply palmas_smps123_supply[] = {
118         REGULATOR_SUPPLY("vdd_cpu", NULL),
119 };
120
121 static struct regulator_consumer_supply palmas_smps45_supply[] = {
122         REGULATOR_SUPPLY("vdd_gpu", NULL),
123 };
124
125 static struct regulator_consumer_supply palmas_smps6_supply[] = {
126         REGULATOR_SUPPLY("vddio_ddr", NULL),
127         REGULATOR_SUPPLY("vddio_ddr_mclk", NULL),
128         REGULATOR_SUPPLY("vddio_ddr3", NULL),
129         REGULATOR_SUPPLY("vcore1_ddr3", NULL),
130 };
131
132 static struct regulator_consumer_supply palmas_smps7_supply[] = {
133         REGULATOR_SUPPLY("vdd_core", NULL),
134 };
135
136 static struct regulator_consumer_supply palmas_smps8_supply[] = {
137         REGULATOR_SUPPLY("dbvdd", "tegra-snd-rt5639.0"),
138         REGULATOR_SUPPLY("dbvdd", "tegra-snd-rt5645.0"),
139         REGULATOR_SUPPLY("avdd", "tegra-snd-rt5639.0"),
140         REGULATOR_SUPPLY("avdd", "tegra-snd-rt5645.0"),
141         REGULATOR_SUPPLY("dmicvdd", "tegra-snd-rt5639.0"),
142         REGULATOR_SUPPLY("dmicvdd", "tegra-snd-rt5645.0"),
143         REGULATOR_SUPPLY("avdd_osc", NULL),
144         REGULATOR_SUPPLY("vddio_sys", NULL),
145         REGULATOR_SUPPLY("vddio_sys_2", NULL),
146         REGULATOR_SUPPLY("vddio_gmi", NULL),
147         REGULATOR_SUPPLY("pwrdet_nand", NULL),
148         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.0"),
149         REGULATOR_SUPPLY("pwrdet_sdmmc1", NULL),
150         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.3"),
151         REGULATOR_SUPPLY("pwrdet_sdmmc4", NULL),
152         REGULATOR_SUPPLY("avdd_pll_utmip", "tegra-udc.0"),
153         REGULATOR_SUPPLY("avdd_pll_utmip", "tegra-ehci.0"),
154         REGULATOR_SUPPLY("avdd_pll_utmip", "tegra-ehci.1"),
155         REGULATOR_SUPPLY("avdd_pll_utmip", "tegra-ehci.2"),
156         REGULATOR_SUPPLY("avdd_pll_utmip", "tegra-xhci"),
157         REGULATOR_SUPPLY("vddio_audio", NULL),
158         REGULATOR_SUPPLY("pwrdet_audio", NULL),
159         REGULATOR_SUPPLY("vddio_uart", NULL),
160         REGULATOR_SUPPLY("pwrdet_uart", NULL),
161         REGULATOR_SUPPLY("vddio_bb", NULL),
162         REGULATOR_SUPPLY("pwrdet_bb", NULL),
163         REGULATOR_SUPPLY("vdd_dtv", NULL),
164         REGULATOR_SUPPLY("vdd_1v8_eeprom", NULL),
165         REGULATOR_SUPPLY("vddio_cam", "tegra_camera"),
166         REGULATOR_SUPPLY("vddio_cam", "vi"),
167         REGULATOR_SUPPLY("pwrdet_cam", NULL),
168         REGULATOR_SUPPLY("dvdd", "spi0.0"),
169         REGULATOR_SUPPLY("vlogic", "0-0069"),
170         REGULATOR_SUPPLY("vid", "0-000d"),
171         REGULATOR_SUPPLY("vddio", "0-0077"),
172         REGULATOR_SUPPLY("dvdd_lcd", NULL),
173         REGULATOR_SUPPLY("vdd_lcd_1v8_s", NULL),
174 };
175
176 static struct regulator_consumer_supply palmas_smps9_supply[] = {
177         REGULATOR_SUPPLY("vdd_snsr", NULL),
178         REGULATOR_SUPPLY("vddio_sd_slot", "sdhci-tegra.3"),
179         REGULATOR_SUPPLY("vddio_sd_slot", "sdhci-tegra.2"),
180         REGULATOR_SUPPLY("vdd_3v3_gps", NULL),
181         REGULATOR_SUPPLY("vdd_3v3_nfc", NULL),
182         REGULATOR_SUPPLY("vdd", "0-0069"),
183         REGULATOR_SUPPLY("vdd", "0-000d"),
184         REGULATOR_SUPPLY("vdd", "0-0077"),
185         REGULATOR_SUPPLY("vdd", "1-004c"),
186         REGULATOR_SUPPLY("vdd", "1-004d"),
187 };
188
189 static struct regulator_consumer_supply palmas_smps10_out1_supply[] = {
190 };
191
192 static struct regulator_consumer_supply palmas_smps10_out2_supply[] = {
193         REGULATOR_SUPPLY("vdd_5v0_mdm", NULL),
194         REGULATOR_SUPPLY("vdd_5v0_snsr", NULL),
195         REGULATOR_SUPPLY("vdd_5v0_dis", NULL),
196         REGULATOR_SUPPLY("spkvdd", "tegra-snd-rt5639.0"),
197         REGULATOR_SUPPLY("spkvdd", "tegra-snd-rt5645.0"),
198         REGULATOR_SUPPLY("avddio_pex", "tegra-pcie"),
199         REGULATOR_SUPPLY("dvddio_pex", "tegra-pcie"),
200         REGULATOR_SUPPLY("avddio_usb", "tegra-xhci"),
201 };
202
203 static struct regulator_consumer_supply palmas_ldo1_supply[] = {
204         REGULATOR_SUPPLY("avdd_pll_m", NULL),
205         REGULATOR_SUPPLY("avdd_pll_ap_c2_c3", NULL),
206         REGULATOR_SUPPLY("avdd_pll_cud2dpd", NULL),
207         REGULATOR_SUPPLY("avdd_pll_c4", NULL),
208         REGULATOR_SUPPLY("avdd_lvds0_io", NULL),
209         REGULATOR_SUPPLY("vddio_ddr_hs", NULL),
210         REGULATOR_SUPPLY("avdd_pll_erefe", NULL),
211         REGULATOR_SUPPLY("avdd_pll_x", NULL),
212         REGULATOR_SUPPLY("avdd_pll_cg", NULL),
213         REGULATOR_SUPPLY("avdd_pex_pll", "tegra-pcie"),
214         REGULATOR_SUPPLY("avdd_hdmi_pll", "tegradc.1"),
215 };
216
217 static struct regulator_consumer_supply palmas_ldo2_supply[] = {
218         REGULATOR_SUPPLY("vdd_cam_1v1_cam", NULL),
219         REGULATOR_SUPPLY("imx135_reg2", NULL),
220         REGULATOR_SUPPLY("vdd_1v2_cam", NULL),
221         REGULATOR_SUPPLY("vdig", "2-0010"),
222         REGULATOR_SUPPLY("dvdd", "2-0010"),
223         REGULATOR_SUPPLY("vdig", "2-0036"),
224 };
225
226 static struct regulator_consumer_supply palmas_ldo3_supply[] = {
227         REGULATOR_SUPPLY("avdd", "spi0.0"),
228 };
229
230
231 static struct regulator_consumer_supply palmas_ldo4_supply[] = {
232         REGULATOR_SUPPLY("vdd_2v7_hv", NULL),
233         REGULATOR_SUPPLY("avdd_cam1_cam", NULL),
234         REGULATOR_SUPPLY("avdd_cam2_cam", NULL),
235         REGULATOR_SUPPLY("avdd_cam3_cam", NULL),
236         REGULATOR_SUPPLY("vana", "2-0010"),
237         REGULATOR_SUPPLY("avdd", "2-0010"),
238         REGULATOR_SUPPLY("vana", "2-0036"),
239 };
240
241 static struct regulator_consumer_supply palmas_ldo5_supply[] = {
242         REGULATOR_SUPPLY("vddio_hsic", "tegra-ehci.1"),
243         REGULATOR_SUPPLY("vddio_hsic", "tegra-ehci.2"),
244         REGULATOR_SUPPLY("vddio_hsic", "tegra-xhci"),
245         REGULATOR_SUPPLY("avdd_dsi_csi", "tegradc.0"),
246         REGULATOR_SUPPLY("avdd_dsi_csi", "tegradc.1"),
247         REGULATOR_SUPPLY("avdd_dsi_csi", "vi"),
248         REGULATOR_SUPPLY("pwrdet_mipi", NULL),
249         REGULATOR_SUPPLY("avdd_hsic_com", NULL),
250         REGULATOR_SUPPLY("avdd_hsic_mdm", NULL),
251         REGULATOR_SUPPLY("vdd_lcd_bl", NULL),
252 };
253
254 static struct regulator_consumer_supply palmas_ldo6_supply[] = {
255         REGULATOR_SUPPLY("vdd_cam1_1v8_cam", NULL),
256         REGULATOR_SUPPLY("vdd_cam2_1v8_cam", NULL),
257         REGULATOR_SUPPLY("vif", "2-0010"),
258         REGULATOR_SUPPLY("dovdd", "2-0010"),
259         REGULATOR_SUPPLY("vif2", "2-0021"),
260         REGULATOR_SUPPLY("vif", "2-0036"),
261         REGULATOR_SUPPLY("vdd_i2c", "2-000c"),
262         REGULATOR_SUPPLY("vi2c", "2-0030"),
263 };
264
265 static struct regulator_consumer_supply palmas_ldo7_supply[] = {
266         REGULATOR_SUPPLY("avdd_af1_cam", NULL),
267         REGULATOR_SUPPLY("imx135_reg1", NULL),
268         REGULATOR_SUPPLY("vana", "2-0021"),
269         REGULATOR_SUPPLY("vdd", "2-000c"),
270 };
271
272 static struct regulator_consumer_supply palmas_ldo8_supply[] = {
273         REGULATOR_SUPPLY("vdd_rtc", NULL),
274 };
275
276
277 static struct regulator_consumer_supply palmas_ldo9_supply[] = {
278         REGULATOR_SUPPLY("vddio_sdmmc", "sdhci-tegra.2"),
279         REGULATOR_SUPPLY("pwrdet_sdmmc3", NULL),
280 };
281
282 static struct regulator_consumer_supply palmas_ldousb_supply[] = {
283         REGULATOR_SUPPLY("pwrdet_pex_ctl", NULL),
284         REGULATOR_SUPPLY("avdd_usb", "tegra-udc.0"),
285         REGULATOR_SUPPLY("avdd_usb", "tegra-ehci.0"),
286         REGULATOR_SUPPLY("avdd_usb", "tegra-ehci.1"),
287         REGULATOR_SUPPLY("avdd_usb", "tegra-ehci.2"),
288         REGULATOR_SUPPLY("hvdd_usb", "tegra-xhci"),
289         REGULATOR_SUPPLY("hvdd_pex", "tegra-pcie"),
290         REGULATOR_SUPPLY("hvdd_pex_pll_e", "tegra-pcie"),
291 };
292
293 static struct regulator_consumer_supply palmas_ldoln_supply[] = {
294         REGULATOR_SUPPLY("vddio_hv", "tegradc.1"),
295         REGULATOR_SUPPLY("avdd_hdmi", "tegradc.1"),
296         REGULATOR_SUPPLY("pwrdet_hv", NULL),
297         REGULATOR_SUPPLY("vddio_pex_ctl", "tegra-pcie"),
298 };
299
300 PALMAS_REGS_PDATA(smps123, 900, 1400, NULL, 1, 1, 1, NORMAL,
301         0, PALMAS_EXT_CONTROL_ENABLE1, 0, 0, 0);
302 PALMAS_REGS_PDATA(smps45, 900, 1400, NULL, 1, 1, 1, NORMAL,
303         0, PALMAS_EXT_CONTROL_ENABLE2, 0, 0, 0);
304 PALMAS_REGS_PDATA(smps6, 1350, 1350, NULL, 1, 1, 1, NORMAL,
305         0, 0, 0, 0, 0);
306 PALMAS_REGS_PDATA(smps7, 900, 1400, NULL, 1, 1, 1, NORMAL,
307         0, PALMAS_EXT_CONTROL_NSLEEP, 0, 0, 0);
308 PALMAS_REGS_PDATA(smps8, 1800, 1800, NULL, 1, 1, 1, NORMAL,
309         0, 0, 0, 0, 0);
310 PALMAS_REGS_PDATA(smps9, 3300, 3300, NULL, 0, 0, 1, NORMAL,
311         0, 0, 0, 0, 0);
312 PALMAS_REGS_PDATA(smps10_out1, 5000, 5000, NULL, 0, 0, 1, 0,
313         0, 0, 0, 0, 0);
314 PALMAS_REGS_PDATA(smps10_out2, 5000, 5000, NULL, 0, 0, 1, 0,
315         0, 0, 0, 0, 0);
316 PALMAS_REGS_PDATA(ldo1, 1050, 1050, palmas_rails(smps6), 1, 1, 1, 0,
317         0, PALMAS_EXT_CONTROL_NSLEEP, 0, 0, 0);
318 PALMAS_REGS_PDATA(ldo2, 1050, 1200, palmas_rails(smps6), 0, 0, 1, 0,
319         0, 0, 0, 0, 0);
320 PALMAS_REGS_PDATA(ldo3, 3300, 3300, NULL, 0, 0, 1, 0,
321         0, 0, 0, 0, 0);
322 PALMAS_REGS_PDATA(ldo4, 2700, 2700, NULL, 0, 0, 1, 0,
323         0, 0, 0, 0, 0);
324 PALMAS_REGS_PDATA(ldo5, 1200, 1200, palmas_rails(smps8), 0, 0, 1, 0,
325         0, 0, 0, 0, 0);
326 PALMAS_REGS_PDATA(ldo6, 1800, 1800, palmas_rails(smps9), 0, 0, 1, 0,
327         0, 0, 0, 0, 0);
328 PALMAS_REGS_PDATA(ldo7, 2700, 2700, palmas_rails(smps9), 0, 0, 1, 0,
329         0, 0, 0, 0, 0);
330 PALMAS_REGS_PDATA(ldo8, 900, 900, NULL, 1, 1, 1, 0,
331         0, 0, 0, 0, 0);
332 PALMAS_REGS_PDATA(ldo9, 1800, 3300, palmas_rails(smps9), 0, 0, 1, 0,
333         0, 0, 0, 0, 0);
334 PALMAS_REGS_PDATA(ldoln, 3300, 3300, palmas_rails(smps10_out2), 1, 1, 1, 0,
335         0, 0, 0, 0, 0);
336 PALMAS_REGS_PDATA(ldousb, 3000, 3300, NULL, 1, 1, 1, 0,
337         0, 0, 0, 0, 0);
338
339 #define PALMAS_REG_PDATA(_sname) &reg_idata_##_sname
340 static struct regulator_init_data *tn8_reg_data[PALMAS_NUM_REGS] = {
341         NULL,
342         PALMAS_REG_PDATA(smps123),
343         NULL,
344         PALMAS_REG_PDATA(smps45),
345         NULL,
346         PALMAS_REG_PDATA(smps6),
347         PALMAS_REG_PDATA(smps7),
348         PALMAS_REG_PDATA(smps8),
349         PALMAS_REG_PDATA(smps9),
350         PALMAS_REG_PDATA(smps10_out2),
351         PALMAS_REG_PDATA(smps10_out1),
352         PALMAS_REG_PDATA(ldo1),
353         PALMAS_REG_PDATA(ldo2),
354         PALMAS_REG_PDATA(ldo3),
355         PALMAS_REG_PDATA(ldo4),
356         PALMAS_REG_PDATA(ldo5),
357         PALMAS_REG_PDATA(ldo6),
358         PALMAS_REG_PDATA(ldo7),
359         PALMAS_REG_PDATA(ldo8),
360         PALMAS_REG_PDATA(ldo9),
361         NULL,
362         NULL,
363         NULL,
364         NULL,
365         NULL,
366         PALMAS_REG_PDATA(ldoln),
367         PALMAS_REG_PDATA(ldousb),
368         NULL,
369         NULL,
370         NULL,
371         NULL,
372         NULL,
373 };
374
375 #define PALMAS_REG_INIT_DATA(_sname) &reg_init_data_##_sname
376 static struct palmas_reg_init *tn8_reg_init[PALMAS_NUM_REGS] = {
377         NULL,
378         PALMAS_REG_INIT_DATA(smps123),
379         NULL,
380         PALMAS_REG_INIT_DATA(smps45),
381         NULL,
382         PALMAS_REG_INIT_DATA(smps6),
383         PALMAS_REG_INIT_DATA(smps7),
384         PALMAS_REG_INIT_DATA(smps8),
385         PALMAS_REG_INIT_DATA(smps9),
386         PALMAS_REG_INIT_DATA(smps10_out2),
387         PALMAS_REG_INIT_DATA(smps10_out1),
388         PALMAS_REG_INIT_DATA(ldo1),
389         PALMAS_REG_INIT_DATA(ldo2),
390         PALMAS_REG_INIT_DATA(ldo3),
391         PALMAS_REG_INIT_DATA(ldo4),
392         PALMAS_REG_INIT_DATA(ldo5),
393         PALMAS_REG_INIT_DATA(ldo6),
394         PALMAS_REG_INIT_DATA(ldo7),
395         PALMAS_REG_INIT_DATA(ldo8),
396         PALMAS_REG_INIT_DATA(ldo9),
397         NULL,
398         NULL,
399         NULL,
400         NULL,
401         NULL,
402         PALMAS_REG_INIT_DATA(ldoln),
403         PALMAS_REG_INIT_DATA(ldousb),
404         NULL,
405         NULL,
406         NULL,
407         NULL,
408         NULL,
409 };
410
411 static struct palmas_pinctrl_config palmas_pincfg[] = {
412         PALMAS_PINMUX("powergood", "powergood", NULL, NULL),
413         PALMAS_PINMUX("vac", "vac", NULL, NULL),
414         PALMAS_PINMUX("gpio0", "id", "pull-up", NULL),
415         PALMAS_PINMUX("gpio1", "vbus_det", NULL, NULL),
416         PALMAS_PINMUX("gpio2", "gpio", NULL, NULL),
417         PALMAS_PINMUX("gpio3", "gpio", NULL, NULL),
418         PALMAS_PINMUX("gpio4", "gpio", NULL, NULL),
419         PALMAS_PINMUX("gpio5", "clk32kgaudio", NULL, NULL),
420         PALMAS_PINMUX("gpio6", "gpio", NULL, NULL),
421         PALMAS_PINMUX("gpio7", "gpio", NULL, NULL),
422 };
423
424 static struct palmas_pinctrl_platform_data palmas_pinctrl_pdata = {
425         .pincfg = palmas_pincfg,
426         .num_pinctrl = ARRAY_SIZE(palmas_pincfg),
427         .dvfs1_enable = true,
428         .dvfs2_enable = false,
429 };
430
431 static struct palmas_pmic_platform_data pmic_platform = {
432 };
433
434 static struct palmas_clk32k_init_data palmas_clk32k_idata[] = {
435         {
436                 .clk32k_id = PALMAS_CLOCK32KG,
437                 .enable = true,
438         }, {
439                 .clk32k_id = PALMAS_CLOCK32KG_AUDIO,
440                 .enable = true,
441         },
442 };
443
444 struct max17048_platform_data tn8_max17048_pdata = {
445         .model_data = &tn8_yoku_4100mA_max17048_battery,
446         .tz_name = "battery-temp",
447 };
448
449 static struct i2c_board_info __initdata tn8_max17048_boardinfo[] = {
450         {
451                 I2C_BOARD_INFO("max17048", 0x36),
452                 .platform_data = &tn8_max17048_pdata,
453         },
454 };
455
456 static struct gadc_thermal_platform_data gadc_thermal_battery_pdata = {
457         .iio_channel_name = "battery-temp-channel",
458         .tz_name = "battery-temp",
459         .temp_offset = 0,
460         .adc_to_temp = NULL,
461         .adc_temp_lookup = tn8_batt_temperature_table,
462         .lookup_table_size = ARRAY_SIZE(tn8_batt_temperature_table),
463         .first_index_temp = 125,
464         .last_index_temp = -40,
465 };
466
467 static struct platform_device gadc_thermal_battery = {
468         .name   = "generic-adc-thermal",
469         .id     = 0,
470         .dev    = {
471                 .platform_data = &gadc_thermal_battery_pdata,
472         },
473 };
474
475 static struct iio_map palmas_iio_map[] = {
476         PALMAS_GPADC_IIO_MAP(IN1, "generic-adc-thermal.0", "battery-temp-channel"),
477         PALMAS_GPADC_IIO_MAP(IN6, "palmas-battery", "vbat_channel"),
478         PALMAS_GPADC_IIO_MAP(NULL, NULL, NULL),
479 };
480
481 struct palmas_gpadc_platform_data gpadc_pdata = {
482         .ch0_current = 0,
483         .ch3_current = 0,
484         .iio_maps = palmas_iio_map,
485 };
486
487 static struct palmas_extcon_platform_data palmas_extcon_pdata = {
488         .connection_name = "palmas-extcon",
489         .enable_vbus_detection = true,
490         .enable_id_pin_detection = true,
491 };
492
493 static struct palmas_pm_platform_data palmas_pm_pdata = {
494         .use_power_off = true,
495         .use_power_reset = true,
496 };
497
498 static struct palmas_platform_data palmas_pdata = {
499         .gpio_base = PALMAS_TEGRA_GPIO_BASE,
500         .irq_base = PALMAS_TEGRA_IRQ_BASE,
501         .pmic_pdata = &pmic_platform,
502         .pinctrl_pdata = &palmas_pinctrl_pdata,
503         .clk32k_init_data =  palmas_clk32k_idata,
504         .clk32k_init_data_size = ARRAY_SIZE(palmas_clk32k_idata),
505         .extcon_pdata = &palmas_extcon_pdata,
506         .gpadc_pdata = &gpadc_pdata,
507         .pm_pdata = &palmas_pm_pdata,
508 };
509
510 static struct i2c_board_info palma_device[] = {
511         {
512                 I2C_BOARD_INFO("tps65913", 0x58),
513                 .irq            = INT_EXTERNAL_PMU,
514                 .platform_data  = &palmas_pdata,
515         },
516 };
517
518 static struct power_supply_extcon_plat_data extcon_pdata = {
519         .extcon_name = "tegra-udc",
520 };
521
522 static struct platform_device power_supply_extcon_device = {
523         .name   = "power-supply-extcon",
524         .id     = -1,
525         .dev    = {
526                 .platform_data = &extcon_pdata,
527         },
528 };
529
530 int __init tn8_regulator_init(void)
531 {
532         void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
533         u32 pmc_ctrl;
534         int i;
535
536         /* TPS65913: Normal state of INT request line is LOW.
537          * configure the power management controller to trigger PMU
538          * interrupts when HIGH.
539          */
540         pmc_ctrl = readl(pmc + PMC_CTRL);
541         writel(pmc_ctrl | PMC_CTRL_INTR_LOW, pmc + PMC_CTRL);
542         for (i = 0; i < PALMAS_NUM_REGS ; i++) {
543                 pmic_platform.reg_data[i] = tn8_reg_data[i];
544                 pmic_platform.reg_init[i] = tn8_reg_init[i];
545         }
546
547         /* Default PJ0 is connected to charger stat,
548          * HW rework is needed to connect to charger-int.
549          * Do not configure the charger int by default.
550          */
551         /* bq2419x_boardinfo[0].irq = gpio_to_irq(TEGRA_GPIO_PJ0); */
552         if (get_power_supply_type() == POWER_SUPPLY_TYPE_BATTERY) {
553                 tn8_bq2419x_pdata.bcharger_pdata = &bq2419x_charger_pdata;
554                 /* Only register fuel gauge when using battery. */
555                 i2c_register_board_info(0, tn8_max17048_boardinfo,
556                         ARRAY_SIZE(tn8_max17048_boardinfo));
557         } else
558                 tn8_bq2419x_pdata.bcharger_pdata = NULL;
559
560         i2c_register_board_info(0, bq2419x_boardinfo,
561                 ARRAY_SIZE(bq2419x_boardinfo));
562
563         /* Tracking configuration */
564         /* TODO
565         reg_init_data_ldo8.config_flags =
566                 PALMAS_REGULATOR_CONFIG_TRACKING_ENABLE |
567                 PALMAS_REGULATOR_CONFIG_SUSPEND_TRACKING_DISABLE;
568         */
569         reg_idata_smps45.constraints.init_uV = 1000000;
570
571         reg_init_data_smps45.enable_gpio = TEGRA_GPIO_PR5;
572
573         i2c_register_board_info(4, palma_device,
574                         ARRAY_SIZE(palma_device));
575
576         platform_device_register(&gadc_thermal_battery);
577         platform_device_register(&power_supply_extcon_device);
578         return 0;
579 }
580 /* Macro for defining fixed regulator sub device data */
581 #define FIXED_SUPPLY(_name) "fixed_reg_en_"#_name
582 #define FIXED_REG(_id, _var, _name, _in_supply,                 \
583         _always_on, _boot_on, _gpio_nr, _open_drain,            \
584         _active_high, _boot_state, _millivolts, _sdelay)        \
585 static struct regulator_init_data ri_data_##_var =              \
586 {                                                               \
587         .supply_regulator = _in_supply,                         \
588         .num_consumer_supplies =                                \
589         ARRAY_SIZE(fixed_reg_en_##_name##_supply),              \
590         .consumer_supplies = fixed_reg_en_##_name##_supply,     \
591         .constraints = {                                        \
592                 .valid_modes_mask = (REGULATOR_MODE_NORMAL |    \
593                                 REGULATOR_MODE_STANDBY),        \
594                 .valid_ops_mask = (REGULATOR_CHANGE_MODE |      \
595                                 REGULATOR_CHANGE_STATUS |       \
596                                 REGULATOR_CHANGE_VOLTAGE),      \
597                 .always_on = _always_on,                        \
598                 .boot_on = _boot_on,                            \
599         },                                                      \
600 };                                                              \
601 static struct fixed_voltage_config fixed_reg_en_##_var##_pdata =        \
602 {                                                               \
603         .supply_name = FIXED_SUPPLY(_name),                     \
604         .microvolts = _millivolts * 1000,                       \
605         .gpio = _gpio_nr,                                       \
606         .gpio_is_open_drain = _open_drain,                      \
607         .enable_high = _active_high,                            \
608         .enabled_at_boot = _boot_state,                         \
609         .init_data = &ri_data_##_var,                           \
610         .startup_delay = _sdelay                                \
611 };                                                              \
612 static struct platform_device fixed_reg_en_##_var##_dev = {     \
613         .name = "reg-fixed-voltage",                            \
614         .id = _id,                                              \
615         .dev = {                                                \
616                 .platform_data = &fixed_reg_en_##_var##_pdata,  \
617         },                                                      \
618 }
619
620 /* Always ON Battery regulator */
621 static struct regulator_consumer_supply fixed_reg_en_battery_supply[] = {
622                 REGULATOR_SUPPLY("vdd_sys_bl", NULL),
623 };
624
625 static struct regulator_consumer_supply fixed_reg_en_usb0_vbus_supply[] = {
626         REGULATOR_SUPPLY("usb_vbus0", "tegra-xhci"),
627 };
628
629 static struct regulator_consumer_supply fixed_reg_en_usb1_vbus_supply[] = {
630         REGULATOR_SUPPLY("usb_vbus", "tegra-ehci.1"),
631         REGULATOR_SUPPLY("usb_vbus1", "tegra-xhci"),
632 };
633
634 static struct regulator_consumer_supply fixed_reg_en_usb2_vbus_supply[] = {
635         REGULATOR_SUPPLY("usb_vbus", "tegra-ehci.2"),
636         REGULATOR_SUPPLY("usb_vbus2", "tegra-xhci"),
637 };
638
639 static struct regulator_consumer_supply fixed_reg_en_palmas_gpio3_supply[] = {
640         REGULATOR_SUPPLY("avdd_lcd", NULL),
641 };
642
643 static struct regulator_consumer_supply fixed_reg_en_palmas_gpio4_supply[] = {
644         REGULATOR_SUPPLY("vdd_lcd_1v2_s", NULL),
645 };
646
647 static struct regulator_consumer_supply fixed_reg_en_palmas_gpio6_supply[] = {
648         REGULATOR_SUPPLY("ldoen", "tegra-snd-rt5639"),
649 };
650
651 static struct regulator_consumer_supply fixed_reg_en_palmas_gpio7_supply[] = {
652         REGULATOR_SUPPLY("vpp_fuse", NULL),
653 };
654
655 static struct regulator_consumer_supply fixed_reg_en_lcd_bl_en_supply[] = {
656         REGULATOR_SUPPLY("vdd_lcd_bl_en", NULL),
657 };
658
659 static struct regulator_consumer_supply fixed_reg_en_vdd_hdmi_5v0_supply[] = {
660         REGULATOR_SUPPLY("vdd_hdmi_5v0", "tegradc.1"),
661 };
662
663 FIXED_REG(0,    battery,        battery,        NULL,
664         0,      0,      -1,
665         false,  true,   0,      3300, 0);
666
667 FIXED_SYNC_REG(1,       usb0_vbus,      usb0_vbus,      NULL,
668                 0,      0,      TEGRA_GPIO_PN4,
669                 true,   true,   0,      5000,   0);
670
671 FIXED_SYNC_REG(2,       usb1_vbus,      usb1_vbus,      palmas_rails(smps10_out2),
672                 0,      0,      TEGRA_GPIO_PN5,
673                 true,   true,   0,      5000,   0);
674
675 FIXED_SYNC_REG(3,       usb2_vbus,      usb2_vbus,      palmas_rails(smps10_out2),
676                 0,      0,      TEGRA_GPIO_PFF1,
677                 true,   true,   0,      5000,   0);
678
679 FIXED_SYNC_REG(4,       palmas_gpio3,   palmas_gpio3,   palmas_rails(smps9),
680                 0,      0,      PALMAS_TEGRA_GPIO_BASE + PALMAS_GPIO3,
681                 false,  true,   0,      3300,   0);
682
683 FIXED_SYNC_REG(5,       palmas_gpio4,   palmas_gpio4,   palmas_rails(smps8),
684                 0,      0,      PALMAS_TEGRA_GPIO_BASE + PALMAS_GPIO4,
685                 false,  true,   0,      1200,   0);
686
687 FIXED_SYNC_REG(6,       palmas_gpio6,   palmas_gpio6,   palmas_rails(smps8),
688                 0,      0,      PALMAS_TEGRA_GPIO_BASE + PALMAS_GPIO6,
689                 false,  true,   0,      1200,   0);
690
691 FIXED_SYNC_REG(7,       palmas_gpio7,   palmas_gpio7,   palmas_rails(smps8),
692                 0,      0,      PALMAS_TEGRA_GPIO_BASE + PALMAS_GPIO7,
693                 false,  true,   0,      1800,   0);
694
695 FIXED_SYNC_REG(8,       lcd_bl_en,      lcd_bl_en, NULL,
696                 0,      0, TEGRA_GPIO_PH2,
697                 false,  true,   0,      5000,   0);
698
699 FIXED_SYNC_REG(9,       vdd_hdmi_5v0,   vdd_hdmi_5v0, palmas_rails(smps10_out1),
700                 0,      0, TEGRA_GPIO_PK6,
701                 false,  true,   0,      5000,   0);
702
703 /*
704  * Creating fixed regulator device tables
705  */
706 #define ADD_FIXED_REG(_name)    (&fixed_reg_en_##_name##_dev)
707 #define TN8_E1736_FIXED_REG             \
708         ADD_FIXED_REG(battery),         \
709         ADD_FIXED_REG(usb0_vbus),       \
710         ADD_FIXED_REG(usb1_vbus),       \
711         ADD_FIXED_REG(usb2_vbus),       \
712         ADD_FIXED_REG(palmas_gpio3),    \
713         ADD_FIXED_REG(palmas_gpio4),    \
714         ADD_FIXED_REG(palmas_gpio6),    \
715         ADD_FIXED_REG(palmas_gpio7),    \
716         ADD_FIXED_REG(lcd_bl_en),       \
717         ADD_FIXED_REG(vdd_hdmi_5v0),
718
719
720 static struct platform_device *fixed_reg_devs_e1736[] = {
721         TN8_E1736_FIXED_REG
722 };
723
724 int __init tn8_fixed_regulator_init(void)
725 {
726         struct board_info pmu_board_info;
727
728         if (!of_machine_is_compatible("nvidia,tn8"))
729                 return 0;
730
731         tegra_get_pmu_board_info(&pmu_board_info);
732
733         if (pmu_board_info.board_id == BOARD_E1736)
734                 return platform_add_devices(fixed_reg_devs_e1736,
735                         ARRAY_SIZE(fixed_reg_devs_e1736));
736
737         return 0;
738 }