ARM: tegra: loki: Enable VBUS detection via PMIC
[linux-3.10.git] / arch / arm / mach-tegra / board-loki.c
1 /*
2  * arch/arm/mach-tegra/board-loki.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, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * 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/kernel.h>
21 #include <linux/init.h>
22 #include <linux/slab.h>
23 #include <linux/ctype.h>
24 #include <linux/platform_device.h>
25 #include <linux/clk.h>
26 #include <linux/serial_8250.h>
27 #include <linux/i2c.h>
28 #include <linux/i2c/i2c-hid.h>
29 #include <linux/dma-mapping.h>
30 #include <linux/delay.h>
31 #include <linux/i2c-tegra.h>
32 #include <linux/gpio.h>
33 #include <linux/input.h>
34 #include <linux/platform_data/tegra_usb.h>
35 #include <linux/spi/spi.h>
36 #include <linux/spi/rm31080a_ts.h>
37 #include <linux/memblock.h>
38 #include <linux/spi/spi-tegra.h>
39 #include <linux/nfc/pn544.h>
40 #include <linux/rfkill-gpio.h>
41 #include <linux/skbuff.h>
42 #include <linux/ti_wilink_st.h>
43 #include <linux/regulator/consumer.h>
44 #include <linux/smb349-charger.h>
45 #include <linux/max17048_battery.h>
46 #include <linux/leds.h>
47 #include <linux/i2c/at24.h>
48 #include <linux/of_platform.h>
49 #include <linux/i2c.h>
50 #include <linux/i2c-tegra.h>
51 #include <linux/platform_data/serial-tegra.h>
52 #include <linux/edp.h>
53 #include <linux/mfd/palmas.h>
54 #include <linux/usb/tegra_usb_phy.h>
55 #include <linux/clk/tegra.h>
56
57 #include <mach/irqs.h>
58 #include <mach/pci.h>
59 #include <mach/tegra_fiq_debugger.h>
60
61 #include <mach/pinmux.h>
62 #include <mach/pinmux-t12.h>
63 #include <mach/io_dpd.h>
64 #include <mach/i2s.h>
65 #include <mach/isomgr.h>
66 #include <mach/tegra_asoc_pdata.h>
67 #include <asm/mach-types.h>
68 #include <asm/mach/arch.h>
69 #include <mach/gpio-tegra.h>
70 #include <mach/tegra_fiq_debugger.h>
71 #include <mach/xusb.h>
72 #include <linux/platform_data/tegra_usb_modem_power.h>
73
74 #include "board-touch-raydium.h"
75 #include "board.h"
76 #include "board-common.h"
77 #include "clock.h"
78 #include "board-loki.h"
79 #include "devices.h"
80 #include "gpio-names.h"
81 #include "fuse.h"
82 #include "pm.h"
83 #include "pm-irq.h"
84 #include "common.h"
85 #include "tegra-board-id.h"
86 #include "iomap.h"
87
88 static struct board_info board_info, display_board_info;
89
90 static struct resource loki_bluedroid_pm_resources[] = {
91         [0] = {
92                 .name   = "shutdown_gpio",
93                 .start  = TEGRA_GPIO_PR1,
94                 .end    = TEGRA_GPIO_PR1,
95                 .flags  = IORESOURCE_IO,
96         },
97         [1] = {
98                 .name = "host_wake",
99                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
100         },
101         [2] = {
102                 .name = "gpio_ext_wake",
103                 .start  = TEGRA_GPIO_PEE1,
104                 .end    = TEGRA_GPIO_PEE1,
105                 .flags  = IORESOURCE_IO,
106         },
107         [3] = {
108                 .name = "gpio_host_wake",
109                 .start  = TEGRA_GPIO_PU0,
110                 .end    = TEGRA_GPIO_PU0,
111                 .flags  = IORESOURCE_IO,
112         },
113         [4] = {
114                 .name = "reset_gpio",
115                 .start  = TEGRA_GPIO_PQ6,
116                 .end    = TEGRA_GPIO_PQ6,
117                 .flags  = IORESOURCE_IO,
118         },
119 };
120
121 static struct platform_device loki_bluedroid_pm_device = {
122         .name = "bluedroid_pm",
123         .id             = 0,
124         .num_resources  = ARRAY_SIZE(loki_bluedroid_pm_resources),
125         .resource       = loki_bluedroid_pm_resources,
126 };
127
128 static noinline void __init loki_setup_bluedroid_pm(void)
129 {
130         loki_bluedroid_pm_resources[1].start =
131                 loki_bluedroid_pm_resources[1].end =
132                                 gpio_to_irq(TEGRA_GPIO_PU0);
133         platform_device_register(&loki_bluedroid_pm_device);
134 }
135
136 static struct i2c_board_info __initdata rt5639_board_info = {
137         I2C_BOARD_INFO("rt5639", 0x1c),
138 };
139
140 static __initdata struct tegra_clk_init_table loki_clk_init_table[] = {
141         /* name         parent          rate            enabled */
142         { "pll_m",      NULL,           0,              false},
143         { "hda",        "pll_p",        108000000,      false},
144         { "hda2codec_2x", "pll_p",      48000000,       false},
145         { "pwm",        "pll_p",        3187500,        false},
146         { "i2s1",       "pll_a_out0",   0,              false},
147         { "i2s3",       "pll_a_out0",   0,              false},
148         { "i2s4",       "pll_a_out0",   0,              false},
149         { "spdif_out",  "pll_a_out0",   0,              false},
150         { "d_audio",    "clk_m",        12000000,       false},
151         { "dam0",       "clk_m",        12000000,       false},
152         { "dam1",       "clk_m",        12000000,       false},
153         { "dam2",       "clk_m",        12000000,       false},
154         { "audio1",     "i2s1_sync",    0,              false},
155         { "audio3",     "i2s3_sync",    0,              false},
156         { "vi_sensor",  "pll_p",        150000000,      false},
157         { "vi_sensor2", "pll_p",        150000000,      false},
158         { "cilab",      "pll_p",        150000000,      false},
159         { "cilcd",      "pll_p",        150000000,      false},
160         { "cile",       "pll_p",        150000000,      false},
161         { "i2c1",       "pll_p",        3200000,        false},
162         { "i2c2",       "pll_p",        3200000,        false},
163         { "i2c3",       "pll_p",        3200000,        false},
164         { "i2c4",       "pll_p",        3200000,        false},
165         { "i2c5",       "pll_p",        3200000,        false},
166         { "sbc1",       "pll_p",        25000000,       false},
167         { "sbc2",       "pll_p",        25000000,       false},
168         { "sbc3",       "pll_p",        25000000,       false},
169         { "sbc4",       "pll_p",        25000000,       false},
170         { "sbc5",       "pll_p",        25000000,       false},
171         { "sbc6",       "pll_p",        25000000,       false},
172         { "uarta",      "pll_p",        408000000,      false},
173         { "uartb",      "pll_p",        408000000,      false},
174         { "uartc",      "pll_p",        408000000,      false},
175         { "uartd",      "pll_p",        408000000,      false},
176         { NULL,         NULL,           0,              0},
177 };
178
179 static void loki_i2c_init(void)
180 {
181         i2c_register_board_info(0, &rt5639_board_info, 1);
182 }
183
184 #ifndef CONFIG_USE_OF
185 static struct platform_device *loki_uart_devices[] __initdata = {
186         &tegra_uarta_device,
187         &tegra_uartb_device,
188         &tegra_uartc_device,
189 };
190
191 static struct tegra_serial_platform_data loki_uarta_pdata = {
192         .dma_req_selector = 8,
193         .modem_interrupt = false,
194 };
195
196 static struct tegra_serial_platform_data loki_uartb_pdata = {
197         .dma_req_selector = 9,
198         .modem_interrupt = false,
199 };
200
201 static struct tegra_serial_platform_data loki_uartc_pdata = {
202         .dma_req_selector = 10,
203         .modem_interrupt = false,
204 };
205 #endif
206
207 static struct tegra_serial_platform_data loki_uartd_pdata = {
208         .dma_req_selector = 19,
209         .modem_interrupt = false,
210 };
211
212 static struct tegra_asoc_platform_data loki_audio_pdata_rt5639 = {
213         .gpio_hp_det = TEGRA_GPIO_HP_DET,
214         .gpio_ldo1_en = TEGRA_GPIO_LDO_EN,
215         .gpio_spkr_en = -1,
216         .gpio_int_mic_en = -1,
217         .gpio_ext_mic_en = -1,
218         .gpio_hp_mute = -1,
219         .gpio_codec1 = -1,
220         .gpio_codec2 = -1,
221         .gpio_codec3 = -1,
222         .i2s_param[HIFI_CODEC]       = {
223                 .audio_port_id = 1,
224                 .is_i2s_master = 0,
225                 .i2s_mode = TEGRA_DAIFMT_I2S,
226         },
227         .i2s_param[BT_SCO] = {
228                 .audio_port_id = 3,
229                 .is_i2s_master = 1,
230                 .i2s_mode = TEGRA_DAIFMT_DSP_A,
231         },
232 };
233
234 static void loki_audio_init(void)
235 {
236         loki_audio_pdata_rt5639.gpio_hp_det =
237                         TEGRA_GPIO_HP_DET;
238
239         loki_audio_pdata_rt5639.gpio_hp_det_active_high = 0;
240
241         loki_audio_pdata_rt5639.gpio_ldo1_en =
242                         TEGRA_GPIO_LDO_EN;
243
244         loki_audio_pdata_rt5639.codec_name = "rt5639.0-001c";
245         loki_audio_pdata_rt5639.codec_dai_name = "rt5639-aif1";
246 }
247
248 static struct platform_device loki_audio_device_rt5639 = {
249         .name = "tegra-snd-rt5639",
250         .id = 0,
251         .dev = {
252                 .platform_data = &loki_audio_pdata_rt5639,
253         },
254 };
255
256 static void __init loki_uart_init(void)
257 {
258         int debug_port_id;
259
260 #ifndef CONFIG_USE_OF
261         tegra_uarta_device.dev.platform_data = &loki_uarta_pdata;
262         tegra_uartb_device.dev.platform_data = &loki_uartb_pdata;
263         tegra_uartc_device.dev.platform_data = &loki_uartc_pdata;
264         platform_add_devices(loki_uart_devices,
265                         ARRAY_SIZE(loki_uart_devices));
266 #endif
267         tegra_uartd_device.dev.platform_data = &loki_uartd_pdata;
268         if (!is_tegra_debug_uartport_hs()) {
269                 debug_port_id = uart_console_debug_init(3);
270                 if (debug_port_id < 0)
271                         return;
272
273                 platform_device_register(uart_console_debug_device);
274         } else {
275                 tegra_uartd_device.dev.platform_data = &loki_uartd_pdata;
276                 platform_device_register(&tegra_uartd_device);
277         }
278
279 }
280
281 static struct resource tegra_rtc_resources[] = {
282         [0] = {
283                 .start = TEGRA_RTC_BASE,
284                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
285                 .flags = IORESOURCE_MEM,
286         },
287         [1] = {
288                 .start = INT_RTC,
289                 .end = INT_RTC,
290                 .flags = IORESOURCE_IRQ,
291         },
292 };
293
294 static struct platform_device tegra_rtc_device = {
295         .name = "tegra_rtc",
296         .id   = -1,
297         .resource = tegra_rtc_resources,
298         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
299 };
300
301 static struct platform_device *loki_devices[] __initdata = {
302         &tegra_pmu_device,
303         &tegra_rtc_device,
304         &tegra_udc_device,
305 #if defined(CONFIG_TEGRA_AVP)
306         &tegra_avp_device,
307 #endif
308 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
309         &tegra12_se_device,
310 #endif
311         &tegra_ahub_device,
312         &tegra_dam_device0,
313         &tegra_dam_device1,
314         &tegra_dam_device2,
315         &tegra_i2s_device1,
316         &tegra_i2s_device3,
317         &tegra_i2s_device4,
318         &loki_audio_device_rt5639,
319         &tegra_spdif_device,
320         &spdif_dit_device,
321         &bluetooth_dit_device,
322         &tegra_hda_device,
323 #if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
324         &tegra_aes_device,
325 #endif
326 };
327
328 static struct tegra_usb_platform_data tegra_udc_pdata = {
329         .port_otg = true,
330         .has_hostpc = true,
331         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
332         .op_mode = TEGRA_USB_OPMODE_DEVICE,
333         .u_data.dev = {
334                 .vbus_pmu_irq = 0,
335                 .vbus_gpio = -1,
336                 .charging_supported = false,
337                 .remote_wakeup_supported = false,
338         },
339         .u_cfg.utmi = {
340                 .hssync_start_delay = 0,
341                 .elastic_limit = 16,
342                 .idle_wait_delay = 17,
343                 .term_range_adj = 6,
344                 .xcvr_setup = 8,
345                 .xcvr_lsfslew = 2,
346                 .xcvr_lsrslew = 2,
347                 .xcvr_setup_offset = 0,
348                 .xcvr_use_fuses = 1,
349         },
350 };
351
352 static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
353         .port_otg = true,
354         .has_hostpc = true,
355         .unaligned_dma_buf_supported = true,
356         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
357         .op_mode = TEGRA_USB_OPMODE_HOST,
358         .u_data.host = {
359                 .vbus_gpio = -1,
360                 .hot_plug = false,
361                 .remote_wakeup_supported = true,
362                 .power_off_on_suspend = true,
363         },
364         .u_cfg.utmi = {
365                 .hssync_start_delay = 0,
366                 .elastic_limit = 16,
367                 .idle_wait_delay = 17,
368                 .term_range_adj = 6,
369                 .xcvr_setup = 15,
370                 .xcvr_lsfslew = 0,
371                 .xcvr_lsrslew = 3,
372                 .xcvr_setup_offset = 0,
373                 .xcvr_use_fuses = 0,
374                 .vbus_oc_map = 0x4,
375                 .xcvr_hsslew_lsb = 2,
376         },
377 };
378
379 static struct tegra_usb_platform_data tegra_ehci2_utmi_pdata = {
380         .port_otg = false,
381         .has_hostpc = true,
382         .unaligned_dma_buf_supported = true,
383         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
384         .op_mode = TEGRA_USB_OPMODE_HOST,
385         .u_data.host = {
386                 .vbus_gpio = -1,
387                 .hot_plug = false,
388                 .remote_wakeup_supported = true,
389                 .power_off_on_suspend = true,
390         },
391         .u_cfg.utmi = {
392                 .hssync_start_delay = 0,
393                 .elastic_limit = 16,
394                 .idle_wait_delay = 17,
395                 .term_range_adj = 6,
396                 .xcvr_setup = 8,
397                 .xcvr_lsfslew = 2,
398                 .xcvr_lsrslew = 2,
399                 .xcvr_setup_offset = 0,
400                 .xcvr_use_fuses = 1,
401                 .vbus_oc_map = 0x5,
402         },
403 };
404
405 static struct tegra_usb_platform_data tegra_ehci3_utmi_pdata = {
406         .port_otg = false,
407         .has_hostpc = true,
408         .unaligned_dma_buf_supported = true,
409         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
410         .op_mode = TEGRA_USB_OPMODE_HOST,
411         .u_data.host = {
412                 .vbus_gpio = -1,
413                 .hot_plug = false,
414                 .remote_wakeup_supported = true,
415                 .power_off_on_suspend = true,
416         },
417         .u_cfg.utmi = {
418         .hssync_start_delay = 0,
419                 .elastic_limit = 16,
420                 .idle_wait_delay = 17,
421                 .term_range_adj = 6,
422                 .xcvr_setup = 8,
423                 .xcvr_lsfslew = 2,
424                 .xcvr_lsrslew = 2,
425                 .xcvr_setup_offset = 0,
426                 .xcvr_use_fuses = 1,
427                 .vbus_oc_map = 0x5,
428         },
429 };
430
431 static struct gpio modem_gpios[] = { /* Bruce modem */
432         {MDM_RST, GPIOF_OUT_INIT_LOW, "MODEM RESET"},
433 };
434
435 static struct tegra_usb_platform_data tegra_ehci2_hsic_baseband_pdata = {
436         .port_otg = false,
437         .has_hostpc = true,
438         .unaligned_dma_buf_supported = true,
439         .phy_intf = TEGRA_USB_PHY_INTF_HSIC,
440         .op_mode = TEGRA_USB_OPMODE_HOST,
441         .u_data.host = {
442                 .vbus_gpio = -1,
443                 .hot_plug = false,
444                 .remote_wakeup_supported = true,
445                 .power_off_on_suspend = true,
446         },
447 };
448
449 static struct tegra_usb_platform_data tegra_ehci2_hsic_smsc_hub_pdata = {
450         .port_otg = false,
451         .has_hostpc = true,
452         .unaligned_dma_buf_supported = true,
453         .phy_intf = TEGRA_USB_PHY_INTF_HSIC,
454         .op_mode        = TEGRA_USB_OPMODE_HOST,
455         .u_data.host = {
456                 .vbus_gpio = -1,
457                 .hot_plug = false,
458                 .remote_wakeup_supported = true,
459                 .power_off_on_suspend = true,
460         },
461 };
462
463
464 static struct tegra_usb_otg_data tegra_otg_pdata = {
465         .ehci_device = &tegra_ehci1_device,
466         .ehci_pdata = &tegra_ehci1_utmi_pdata,
467 };
468
469 static void loki_usb_init(void)
470 {
471         int usb_port_owner_info = tegra_get_usb_port_owner_info();
472         int modem_id = tegra_get_modem_id();
473
474         /* Device cable is detected through PMU Interrupt */
475         tegra_udc_pdata.support_pmu_vbus = true;
476         tegra_ehci1_utmi_pdata.support_pmu_vbus = true;
477         tegra_otg_pdata.vbus_extcon_dev_name = "palmas-extcon";
478
479         if (!(usb_port_owner_info & UTMI1_PORT_OWNER_XUSB)) {
480                 tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
481                 platform_device_register(&tegra_otg_device);
482                 /* Setup the udc platform data */
483                 tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
484         }
485         if (!(usb_port_owner_info & UTMI2_PORT_OWNER_XUSB)) {
486                 if (!modem_id) {
487                         tegra_ehci2_device.dev.platform_data =
488                                 &tegra_ehci2_utmi_pdata;
489                         platform_device_register(&tegra_ehci2_device);
490                 }
491         }
492         if (!(usb_port_owner_info & UTMI3_PORT_OWNER_XUSB)) {
493                 tegra_ehci3_device.dev.platform_data = &tegra_ehci3_utmi_pdata;
494                 platform_device_register(&tegra_ehci3_device);
495         }
496 }
497
498 static struct tegra_xusb_board_data xusb_bdata = {
499         .portmap = TEGRA_XUSB_SS_P0 | TEGRA_XUSB_USB2_P0 | TEGRA_XUSB_SS_P1 |
500                         TEGRA_XUSB_USB2_P1 | TEGRA_XUSB_USB2_P2,
501         .supply = {
502                 .s5p0v = "usb_vbus0",
503                 .s5p0v1 = "usb_vbus1",
504                 .s5p0v2 = "usb_vbus2",
505                 .s3p3v = "hvdd_usb",
506                 .s1p8v = "avdd_pll_utmip",
507                 .vddio_hsic = "vddio_hsic",
508                 .s1p05v = "avddio_usb",
509         },
510         .uses_external_pmic = false,
511         .uses_different_vbus_per_port = true,
512 };
513
514 static void loki_xusb_init(void)
515 {
516         int usb_port_owner_info = tegra_get_usb_port_owner_info();
517
518         xusb_bdata.lane_owner = (u8) tegra_get_lane_owner_info();
519
520         if (board_info.board_id == BOARD_PM359 ||
521                         board_info.board_id == BOARD_PM358 ||
522                         board_info.board_id == BOARD_PM363) {
523                 /* Laguna */
524                 xusb_bdata.gpio_controls_muxed_ss_lanes = true;
525                 /* D[0:15] = gpio number and D[16:31] = output value*/
526                 xusb_bdata.gpio_ss1_sata = PMU_TCA6416_GPIO(11) | (0 << 16);
527                 xusb_bdata.ss_portmap = (TEGRA_XUSB_SS_PORT_MAP_USB2_P0 << 0) |
528                         (TEGRA_XUSB_SS_PORT_MAP_USB2_P1 << 4);
529
530                 if (!(usb_port_owner_info & UTMI1_PORT_OWNER_XUSB))
531                         xusb_bdata.portmap &= ~(TEGRA_XUSB_USB2_P0 |
532                                 TEGRA_XUSB_SS_P0);
533
534                 if (!(usb_port_owner_info & UTMI2_PORT_OWNER_XUSB))
535                         xusb_bdata.portmap &= ~(TEGRA_XUSB_USB2_P1 |
536                                 TEGRA_XUSB_SS_P1);
537
538                 /* FIXME Add for UTMIP2 when have odmdata assigend */
539         } else {
540                 /* Loki */
541                 xusb_bdata.gpio_controls_muxed_ss_lanes = false;
542
543                 if (board_info.board_id == BOARD_E1781) {
544                         pr_info("Shield ERS-S. 0x%x\n", board_info.board_id);
545                         /* Shield ERS-S */
546                         xusb_bdata.ss_portmap =
547                                 (TEGRA_XUSB_SS_PORT_MAP_USB2_P1 << 0) |
548                                 (TEGRA_XUSB_SS_PORT_MAP_USB2_P2 << 4);
549
550                         if (!(usb_port_owner_info & UTMI1_PORT_OWNER_XUSB))
551                                 xusb_bdata.portmap &= ~(TEGRA_XUSB_USB2_P0);
552
553                         if (!(usb_port_owner_info & UTMI2_PORT_OWNER_XUSB))
554                                 xusb_bdata.portmap &= ~(
555                                         TEGRA_XUSB_USB2_P1 | TEGRA_XUSB_SS_P0 |
556                                         TEGRA_XUSB_USB2_P2 | TEGRA_XUSB_SS_P1);
557                 } else {
558                         pr_info("Shield ERS 0x%x\n", board_info.board_id);
559                         /* Shield ERS */
560                         xusb_bdata.ss_portmap =
561                                 (TEGRA_XUSB_SS_PORT_MAP_USB2_P0 << 0) |
562                                 (TEGRA_XUSB_SS_PORT_MAP_USB2_P2 << 4);
563
564                         if (!(usb_port_owner_info & UTMI1_PORT_OWNER_XUSB))
565                                 xusb_bdata.portmap &= ~(TEGRA_XUSB_USB2_P0 |
566                                         TEGRA_XUSB_SS_P0);
567
568                         if (!(usb_port_owner_info & UTMI2_PORT_OWNER_XUSB))
569                                 xusb_bdata.portmap &= ~(TEGRA_XUSB_USB2_P1 |
570                                         TEGRA_XUSB_USB2_P2 | TEGRA_XUSB_SS_P1);
571                 }
572                 /* FIXME Add for UTMIP2 when have odmdata assigend */
573         }
574         if (xusb_bdata.portmap)
575                 tegra_xusb_init(&xusb_bdata);
576 }
577
578 static int baseband_init(void)
579 {
580         int ret;
581
582         ret = gpio_request_array(modem_gpios, ARRAY_SIZE(modem_gpios));
583         if (ret) {
584                 pr_warn("%s:gpio request failed\n", __func__);
585                 return ret;
586         }
587
588         /* enable pull-down for MDM_COLD_BOOT */
589         tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_ULPI_DATA4,
590                                     TEGRA_PUPD_PULL_DOWN);
591
592         /* export GPIO for user space access through sysfs */
593         gpio_export(MDM_RST, false);
594
595         return 0;
596 }
597
598 static const struct tegra_modem_operations baseband_operations = {
599         .init = baseband_init,
600 };
601
602 static struct tegra_usb_modem_power_platform_data baseband_pdata = {
603         .ops = &baseband_operations,
604         .regulator_name = "vdd_wwan_mdm",
605         .wake_gpio = -1,
606         .boot_gpio = MDM_COLDBOOT,
607         .boot_irq_flags = IRQF_TRIGGER_RISING |
608                                     IRQF_TRIGGER_FALLING |
609                                     IRQF_ONESHOT,
610         .autosuspend_delay = 2000,
611         .short_autosuspend_delay = 50,
612         .tegra_ehci_device = &tegra_ehci2_device,
613         .tegra_ehci_pdata = &tegra_ehci2_hsic_baseband_pdata,
614 };
615
616 static struct platform_device icera_bruce_device = {
617         .name = "tegra_usb_modem_power",
618         .id = -1,
619         .dev = {
620                 .platform_data = &baseband_pdata,
621         },
622 };
623
624 static void loki_modem_init(void)
625 {
626         int modem_id = tegra_get_modem_id();
627         struct board_info board_info;
628         int usb_port_owner_info = tegra_get_usb_port_owner_info();
629
630         tegra_get_board_info(&board_info);
631         pr_info("%s: modem_id = %d\n", __func__, modem_id);
632
633         switch (modem_id) {
634         case TEGRA_BB_BRUCE:
635                 if (!(usb_port_owner_info & HSIC1_PORT_OWNER_XUSB))
636                         platform_device_register(&icera_bruce_device);
637                 break;
638         case TEGRA_BB_HSIC_HUB: /* HSIC hub */
639                 if (!(usb_port_owner_info & HSIC1_PORT_OWNER_XUSB)) {
640                         tegra_ehci2_device.dev.platform_data =
641                                 &tegra_ehci2_hsic_smsc_hub_pdata;
642                         platform_device_register(&tegra_ehci2_device);
643                 }
644                 break;
645         default:
646                 return;
647         }
648 }
649
650 #ifndef CONFIG_USE_OF
651 static struct platform_device *loki_spi_devices[] __initdata = {
652         &tegra11_spi_device1,
653         &tegra11_spi_device4,
654 };
655
656 static struct tegra_spi_platform_data loki_spi1_pdata = {
657         .dma_req_sel            = 15,
658         .spi_max_frequency      = 25000000,
659         .clock_always_on        = false,
660 };
661
662 static struct tegra_spi_platform_data loki_spi4_pdata = {
663         .dma_req_sel            = 18,
664         .spi_max_frequency      = 25000000,
665         .clock_always_on        = false,
666 };
667
668 static void __init loki_spi_init(void)
669 {
670         tegra11_spi_device1.dev.platform_data = &loki_spi1_pdata;
671         tegra11_spi_device4.dev.platform_data = &loki_spi4_pdata;
672         platform_add_devices(loki_spi_devices,
673                         ARRAY_SIZE(loki_spi_devices));
674 }
675 #else
676 static void __init loki_spi_init(void)
677 {
678 }
679 #endif
680
681 #ifdef CONFIG_USE_OF
682 struct of_dev_auxdata loki_auxdata_lookup[] __initdata = {
683         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000d400, "spi-tegra114.0",
684                                 NULL),
685         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000d600, "spi-tegra114.1",
686                                 NULL),
687         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000d800, "spi-tegra114.2",
688                                 NULL),
689         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000da00, "spi-tegra114.3",
690                                 NULL),
691         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000dc00, "spi-tegra114.4",
692                                 NULL),
693         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000de00, "spi-tegra114.5",
694                                 NULL),
695         OF_DEV_AUXDATA("nvidia,tegra124-apbdma", 0x60020000, "tegra-apbdma",
696                                 NULL),
697         OF_DEV_AUXDATA("nvidia,tegra124-host1x", TEGRA_HOST1X_BASE, "host1x",
698                 NULL),
699         OF_DEV_AUXDATA("nvidia,tegra124-gk20a", 0x538F0000, "gk20a", NULL),
700         OF_DEV_AUXDATA("nvidia,tegra124-vic", TEGRA_VIC_BASE, "vic03", NULL),
701         OF_DEV_AUXDATA("nvidia,tegra124-msenc", TEGRA_MSENC_BASE, "msenc",
702                 NULL),
703         OF_DEV_AUXDATA("nvidia,tegra124-vi", TEGRA_VI_BASE, "vi", NULL),
704         OF_DEV_AUXDATA("nvidia,tegra124-isp", TEGRA_ISP_BASE, "isp", NULL),
705         OF_DEV_AUXDATA("nvidia,tegra124-tsec", TEGRA_TSEC_BASE, "tsec", NULL),
706         OF_DEV_AUXDATA("nvidia,tegra114-hsuart", 0x70006000, "serial-tegra.0",
707                                 NULL),
708         OF_DEV_AUXDATA("nvidia,tegra114-hsuart", 0x70006040, "serial-tegra.1",
709                                 NULL),
710         OF_DEV_AUXDATA("nvidia,tegra114-hsuart", 0x70006200, "serial-tegra.2",
711                                 NULL),
712         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000c000, "tegra12-i2c.0",
713                                 NULL),
714         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000c400, "tegra12-i2c.1",
715                                 NULL),
716         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000c500, "tegra12-i2c.2",
717                                 NULL),
718         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000c700, "tegra12-i2c.3",
719                                 NULL),
720         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000d000, "tegra12-i2c.4",
721                                 NULL),
722         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000d100, "tegra12-i2c.5",
723                                 NULL),
724         {}
725 };
726 #endif
727
728 static __initdata struct tegra_clk_init_table touch_clk_init_table[] = {
729         /* name         parent          rate            enabled */
730         { "extern2",    "pll_p",        41000000,       false},
731         { "clk_out_2",  "extern2",      40800000,       false},
732         { NULL,         NULL,           0,              0},
733 };
734
735 struct rm_spi_ts_platform_data rm31080ts_loki_data = {
736         .gpio_reset = TOUCH_GPIO_RST_RAYDIUM_SPI,
737         .config = 0,
738         .platform_id = RM_PLATFORM_R005,
739         .name_of_clock = "clk_out_2",
740         .name_of_clock_con = "extern2",
741 };
742
743 static struct tegra_spi_device_controller_data dev_cdata = {
744         .rx_clk_tap_delay = 16,
745         .tx_clk_tap_delay = 16,
746 };
747
748 struct spi_board_info rm31080a_loki_spi_board[1] = {
749         {
750                 .modalias = "rm_ts_spidev",
751                 .bus_num = TOUCH_SPI_ID,
752                 .chip_select = TOUCH_SPI_CS,
753                 .max_speed_hz = 12 * 1000 * 1000,
754                 .mode = SPI_MODE_0,
755                 .controller_data = &dev_cdata,
756                 .platform_data = &rm31080ts_loki_data,
757         },
758 };
759
760 static int __init loki_touch_init(void)
761 {
762         tegra_clk_init_from_table(touch_clk_init_table);
763         rm31080a_loki_spi_board[0].irq =
764                 gpio_to_irq(TOUCH_GPIO_IRQ_RAYDIUM_SPI);
765         touch_init_raydium(TOUCH_GPIO_IRQ_RAYDIUM_SPI,
766                                 TOUCH_GPIO_RST_RAYDIUM_SPI,
767                                 &rm31080ts_loki_data,
768                                 &rm31080a_loki_spi_board[0],
769                                 ARRAY_SIZE(rm31080a_loki_spi_board));
770         return 0;
771 }
772
773 static void __init tegra_loki_early_init(void)
774 {
775         tegra_clk_init_from_table(loki_clk_init_table);
776         tegra_clk_verify_parents();
777         tegra_soc_device_init("loki");
778 }
779
780 static void __init tegra_loki_late_init(void)
781 {
782         struct board_info board_info;
783         tegra_get_board_info(&board_info);
784         pr_info("board_info: id:sku:fab:major:minor = 0x%04x:0x%04x:0x%02x:0x%02x:0x%02x\n",
785                 board_info.board_id, board_info.sku,
786                 board_info.fab, board_info.major_revision,
787                 board_info.minor_revision);
788         platform_device_register(&tegra_pinmux_device);
789         loki_pinmux_init();
790         loki_usb_init();
791         loki_modem_init();
792         loki_xusb_init();
793         loki_i2c_init();
794         loki_spi_init();
795         loki_uart_init();
796         loki_audio_init();
797         platform_add_devices(loki_devices, ARRAY_SIZE(loki_devices));
798         //tegra_ram_console_debug_init();
799         tegra_io_dpd_init();
800         loki_sdhci_init();
801         loki_regulator_init();
802         loki_suspend_init();
803 #if 0
804         loki_emc_init();
805 #endif
806         loki_edp_init();
807         isomgr_init();
808         loki_touch_init();
809         loki_panel_init();
810         loki_kbc_init();
811         loki_pmon_init();
812 #ifdef CONFIG_TEGRA_WDT_RECOVERY
813         tegra_wdt_recovery_init();
814 #endif
815         tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
816
817         loki_sensors_init();
818         loki_fan_init();
819         loki_soctherm_init();
820         loki_setup_bluedroid_pm();
821         tegra_register_fuse();
822         tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
823 }
824
825 static void __init loki_ramconsole_reserve(unsigned long size)
826 {
827         tegra_ram_console_debug_reserve(SZ_1M);
828 }
829
830 static void __init tegra_loki_dt_init(void)
831 {
832         tegra_get_board_info(&board_info);
833         tegra_get_display_board_info(&display_board_info);
834
835         tegra_loki_early_init();
836 #ifdef CONFIG_USE_OF
837         of_platform_populate(NULL,
838                 of_default_bus_match_table, loki_auxdata_lookup,
839                 &platform_bus);
840 #endif
841
842         tegra_loki_late_init();
843 }
844
845 static void __init tegra_loki_reserve(void)
846 {
847 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM) || \
848                 defined(CONFIG_TEGRA_NO_CARVEOUT)
849         /* 1920*1200*4*2 = 18432000 bytes */
850         tegra_reserve(0, SZ_16M + SZ_2M, SZ_16M);
851 #else
852         tegra_reserve(SZ_1G, SZ_16M + SZ_2M, SZ_4M);
853 #endif
854         loki_ramconsole_reserve(SZ_1M);
855 }
856
857 static const char * const loki_dt_board_compat[] = {
858         "nvidia,loki",
859         NULL
860 };
861
862 static void __init tegra_loki_init_early(void)
863 {
864         loki_rail_alignment_init();
865         tegra12x_init_early();
866 }
867
868 DT_MACHINE_START(LOKI, "loki")
869         .atag_offset    = 0x100,
870         .smp            = smp_ops(tegra_smp_ops),
871         .map_io         = tegra_map_common_io,
872         .reserve        = tegra_loki_reserve,
873         .init_early     = tegra_loki_init_early,
874         .init_irq       = tegra_dt_init_irq,
875         .init_time      = tegra_init_timer,
876         .init_machine   = tegra_loki_dt_init,
877         .restart        = tegra_assert_system_reset,
878         .dt_compat      = loki_dt_board_compat,
879 MACHINE_END