ARM: tegra: use soctherm on Loki
[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         struct board_info bi;
474
475         tegra_get_pmu_board_info(&bi);
476
477         switch (bi.board_id) {
478         case BOARD_E1733:
479                 /* Host cable is detected through USB ID */
480                 tegra_udc_pdata.id_det_type = TEGRA_USB_ID;
481                 tegra_ehci1_utmi_pdata.id_det_type = TEGRA_USB_ID;
482                 break;
483         case BOARD_E1735:
484                 /* Host cable is detected through PMU Interrupt */
485                 tegra_udc_pdata.id_det_type = TEGRA_USB_PMU_ID;
486                 tegra_ehci1_utmi_pdata.id_det_type = TEGRA_USB_PMU_ID;
487                 tegra_otg_pdata.id_extcon_dev_name = "palmas-extcon";
488         }
489
490         if (!(usb_port_owner_info & UTMI1_PORT_OWNER_XUSB)) {
491                 tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
492                 platform_device_register(&tegra_otg_device);
493                 /* Setup the udc platform data */
494                 tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
495         }
496         if (!(usb_port_owner_info & UTMI2_PORT_OWNER_XUSB)) {
497                 if (!modem_id) {
498                         tegra_ehci2_device.dev.platform_data =
499                                 &tegra_ehci2_utmi_pdata;
500                         platform_device_register(&tegra_ehci2_device);
501                 }
502         }
503         if (!(usb_port_owner_info & UTMI3_PORT_OWNER_XUSB)) {
504                 tegra_ehci3_device.dev.platform_data = &tegra_ehci3_utmi_pdata;
505                 platform_device_register(&tegra_ehci3_device);
506         }
507 }
508
509 static struct tegra_xusb_board_data xusb_bdata = {
510         .portmap = TEGRA_XUSB_SS_P0 | TEGRA_XUSB_USB2_P0 | TEGRA_XUSB_SS_P1 |
511                         TEGRA_XUSB_USB2_P1 | TEGRA_XUSB_USB2_P2,
512         .supply = {
513                 .s5p0v = "usb_vbus0",
514                 .s5p0v1 = "usb_vbus1",
515                 .s5p0v2 = "usb_vbus2",
516                 .s3p3v = "hvdd_usb",
517                 .s1p8v = "avdd_pll_utmip",
518                 .vddio_hsic = "vddio_hsic",
519                 .s1p05v = "avddio_usb",
520         },
521         .uses_external_pmic = false,
522         .uses_different_vbus_per_port = true,
523 };
524
525 static void loki_xusb_init(void)
526 {
527         int usb_port_owner_info = tegra_get_usb_port_owner_info();
528
529         xusb_bdata.lane_owner = (u8) tegra_get_lane_owner_info();
530
531         if (board_info.board_id == BOARD_PM359 ||
532                         board_info.board_id == BOARD_PM358 ||
533                         board_info.board_id == BOARD_PM363) {
534                 /* Laguna */
535                 xusb_bdata.gpio_controls_muxed_ss_lanes = true;
536                 /* D[0:15] = gpio number and D[16:31] = output value*/
537                 xusb_bdata.gpio_ss1_sata = PMU_TCA6416_GPIO(11) | (0 << 16);
538                 xusb_bdata.ss_portmap = (TEGRA_XUSB_SS_PORT_MAP_USB2_P0 << 0) |
539                         (TEGRA_XUSB_SS_PORT_MAP_USB2_P1 << 4);
540
541                 if (!(usb_port_owner_info & UTMI1_PORT_OWNER_XUSB))
542                         xusb_bdata.portmap &= ~(TEGRA_XUSB_USB2_P0 |
543                                 TEGRA_XUSB_SS_P0);
544
545                 if (!(usb_port_owner_info & UTMI2_PORT_OWNER_XUSB))
546                         xusb_bdata.portmap &= ~(TEGRA_XUSB_USB2_P1 |
547                                 TEGRA_XUSB_SS_P1);
548
549                 /* FIXME Add for UTMIP2 when have odmdata assigend */
550         } else {
551                 /* Loki */
552                 xusb_bdata.gpio_controls_muxed_ss_lanes = false;
553
554                 if (board_info.board_id == BOARD_E1781) {
555                         pr_info("Shield ERS-S. 0x%x\n", board_info.board_id);
556                         /* Shield ERS-S */
557                         xusb_bdata.ss_portmap =
558                                 (TEGRA_XUSB_SS_PORT_MAP_USB2_P1 << 0) |
559                                 (TEGRA_XUSB_SS_PORT_MAP_USB2_P2 << 4);
560
561                         if (!(usb_port_owner_info & UTMI1_PORT_OWNER_XUSB))
562                                 xusb_bdata.portmap &= ~(TEGRA_XUSB_USB2_P0);
563
564                         if (!(usb_port_owner_info & UTMI2_PORT_OWNER_XUSB))
565                                 xusb_bdata.portmap &= ~(
566                                         TEGRA_XUSB_USB2_P1 | TEGRA_XUSB_SS_P0 |
567                                         TEGRA_XUSB_USB2_P2 | TEGRA_XUSB_SS_P1);
568                 } else {
569                         pr_info("Shield ERS 0x%x\n", board_info.board_id);
570                         /* Shield ERS */
571                         xusb_bdata.ss_portmap =
572                                 (TEGRA_XUSB_SS_PORT_MAP_USB2_P0 << 0) |
573                                 (TEGRA_XUSB_SS_PORT_MAP_USB2_P2 << 4);
574
575                         if (!(usb_port_owner_info & UTMI1_PORT_OWNER_XUSB))
576                                 xusb_bdata.portmap &= ~(TEGRA_XUSB_USB2_P0 |
577                                         TEGRA_XUSB_SS_P0);
578
579                         if (!(usb_port_owner_info & UTMI2_PORT_OWNER_XUSB))
580                                 xusb_bdata.portmap &= ~(TEGRA_XUSB_USB2_P1 |
581                                         TEGRA_XUSB_USB2_P2 | TEGRA_XUSB_SS_P1);
582                 }
583                 /* FIXME Add for UTMIP2 when have odmdata assigend */
584         }
585         if (xusb_bdata.portmap)
586                 tegra_xusb_init(&xusb_bdata);
587 }
588
589 static int baseband_init(void)
590 {
591         int ret;
592
593         ret = gpio_request_array(modem_gpios, ARRAY_SIZE(modem_gpios));
594         if (ret) {
595                 pr_warn("%s:gpio request failed\n", __func__);
596                 return ret;
597         }
598
599         /* enable pull-down for MDM_COLD_BOOT */
600         tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_ULPI_DATA4,
601                                     TEGRA_PUPD_PULL_DOWN);
602
603         /* export GPIO for user space access through sysfs */
604         gpio_export(MDM_RST, false);
605
606         return 0;
607 }
608
609 static const struct tegra_modem_operations baseband_operations = {
610         .init = baseband_init,
611 };
612
613 static struct tegra_usb_modem_power_platform_data baseband_pdata = {
614         .ops = &baseband_operations,
615         .regulator_name = "vdd_wwan_mdm",
616         .wake_gpio = -1,
617         .boot_gpio = MDM_COLDBOOT,
618         .boot_irq_flags = IRQF_TRIGGER_RISING |
619                                     IRQF_TRIGGER_FALLING |
620                                     IRQF_ONESHOT,
621         .autosuspend_delay = 2000,
622         .short_autosuspend_delay = 50,
623         .tegra_ehci_device = &tegra_ehci2_device,
624         .tegra_ehci_pdata = &tegra_ehci2_hsic_baseband_pdata,
625 };
626
627 static struct platform_device icera_bruce_device = {
628         .name = "tegra_usb_modem_power",
629         .id = -1,
630         .dev = {
631                 .platform_data = &baseband_pdata,
632         },
633 };
634
635 static void loki_modem_init(void)
636 {
637         int modem_id = tegra_get_modem_id();
638         struct board_info board_info;
639         int usb_port_owner_info = tegra_get_usb_port_owner_info();
640
641         tegra_get_board_info(&board_info);
642         pr_info("%s: modem_id = %d\n", __func__, modem_id);
643
644         switch (modem_id) {
645         case TEGRA_BB_BRUCE:
646                 if (!(usb_port_owner_info & HSIC1_PORT_OWNER_XUSB))
647                         platform_device_register(&icera_bruce_device);
648                 break;
649         case TEGRA_BB_HSIC_HUB: /* HSIC hub */
650                 if (!(usb_port_owner_info & HSIC1_PORT_OWNER_XUSB)) {
651                         tegra_ehci2_device.dev.platform_data =
652                                 &tegra_ehci2_hsic_smsc_hub_pdata;
653                         platform_device_register(&tegra_ehci2_device);
654                 }
655                 break;
656         default:
657                 return;
658         }
659 }
660
661 #ifndef CONFIG_USE_OF
662 static struct platform_device *loki_spi_devices[] __initdata = {
663         &tegra11_spi_device1,
664         &tegra11_spi_device4,
665 };
666
667 static struct tegra_spi_platform_data loki_spi1_pdata = {
668         .dma_req_sel            = 15,
669         .spi_max_frequency      = 25000000,
670         .clock_always_on        = false,
671 };
672
673 static struct tegra_spi_platform_data loki_spi4_pdata = {
674         .dma_req_sel            = 18,
675         .spi_max_frequency      = 25000000,
676         .clock_always_on        = false,
677 };
678
679 static void __init loki_spi_init(void)
680 {
681         tegra11_spi_device1.dev.platform_data = &loki_spi1_pdata;
682         tegra11_spi_device4.dev.platform_data = &loki_spi4_pdata;
683         platform_add_devices(loki_spi_devices,
684                         ARRAY_SIZE(loki_spi_devices));
685 }
686 #else
687 static void __init loki_spi_init(void)
688 {
689 }
690 #endif
691
692 #ifdef CONFIG_USE_OF
693 struct of_dev_auxdata loki_auxdata_lookup[] __initdata = {
694         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000d400, "spi-tegra114.0",
695                                 NULL),
696         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000d600, "spi-tegra114.1",
697                                 NULL),
698         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000d800, "spi-tegra114.2",
699                                 NULL),
700         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000da00, "spi-tegra114.3",
701                                 NULL),
702         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000dc00, "spi-tegra114.4",
703                                 NULL),
704         OF_DEV_AUXDATA("nvidia,tegra114-spi", 0x7000de00, "spi-tegra114.5",
705                                 NULL),
706         OF_DEV_AUXDATA("nvidia,tegra124-apbdma", 0x60020000, "tegra-apbdma",
707                                 NULL),
708         OF_DEV_AUXDATA("nvidia,tegra124-host1x", TEGRA_HOST1X_BASE, "host1x",
709                 NULL),
710         OF_DEV_AUXDATA("nvidia,tegra124-gk20a", 0x538F0000, "gk20a", NULL),
711         OF_DEV_AUXDATA("nvidia,tegra124-vic", TEGRA_VIC_BASE, "vic03", NULL),
712         OF_DEV_AUXDATA("nvidia,tegra124-msenc", TEGRA_MSENC_BASE, "msenc",
713                 NULL),
714         OF_DEV_AUXDATA("nvidia,tegra124-vi", TEGRA_VI_BASE, "vi", NULL),
715         OF_DEV_AUXDATA("nvidia,tegra124-isp", TEGRA_ISP_BASE, "isp", NULL),
716         OF_DEV_AUXDATA("nvidia,tegra124-tsec", TEGRA_TSEC_BASE, "tsec", NULL),
717         OF_DEV_AUXDATA("nvidia,tegra114-hsuart", 0x70006000, "serial-tegra.0",
718                                 NULL),
719         OF_DEV_AUXDATA("nvidia,tegra114-hsuart", 0x70006040, "serial-tegra.1",
720                                 NULL),
721         OF_DEV_AUXDATA("nvidia,tegra114-hsuart", 0x70006200, "serial-tegra.2",
722                                 NULL),
723         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000c000, "tegra12-i2c.0",
724                                 NULL),
725         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000c400, "tegra12-i2c.1",
726                                 NULL),
727         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000c500, "tegra12-i2c.2",
728                                 NULL),
729         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000c700, "tegra12-i2c.3",
730                                 NULL),
731         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000d000, "tegra12-i2c.4",
732                                 NULL),
733         OF_DEV_AUXDATA("nvidia,tegra124-i2c", 0x7000d100, "tegra12-i2c.5",
734                                 NULL),
735         {}
736 };
737 #endif
738
739 static __initdata struct tegra_clk_init_table touch_clk_init_table[] = {
740         /* name         parent          rate            enabled */
741         { "extern2",    "pll_p",        41000000,       false},
742         { "clk_out_2",  "extern2",      40800000,       false},
743         { NULL,         NULL,           0,              0},
744 };
745
746 struct rm_spi_ts_platform_data rm31080ts_loki_data = {
747         .gpio_reset = TOUCH_GPIO_RST_RAYDIUM_SPI,
748         .config = 0,
749         .platform_id = RM_PLATFORM_R005,
750         .name_of_clock = "clk_out_2",
751         .name_of_clock_con = "extern2",
752 };
753
754 static struct tegra_spi_device_controller_data dev_cdata = {
755         .rx_clk_tap_delay = 16,
756         .tx_clk_tap_delay = 16,
757 };
758
759 struct spi_board_info rm31080a_loki_spi_board[1] = {
760         {
761                 .modalias = "rm_ts_spidev",
762                 .bus_num = TOUCH_SPI_ID,
763                 .chip_select = TOUCH_SPI_CS,
764                 .max_speed_hz = 12 * 1000 * 1000,
765                 .mode = SPI_MODE_0,
766                 .controller_data = &dev_cdata,
767                 .platform_data = &rm31080ts_loki_data,
768         },
769 };
770
771 static int __init loki_touch_init(void)
772 {
773         tegra_clk_init_from_table(touch_clk_init_table);
774         rm31080a_loki_spi_board[0].irq =
775                 gpio_to_irq(TOUCH_GPIO_IRQ_RAYDIUM_SPI);
776         touch_init_raydium(TOUCH_GPIO_IRQ_RAYDIUM_SPI,
777                                 TOUCH_GPIO_RST_RAYDIUM_SPI,
778                                 &rm31080ts_loki_data,
779                                 &rm31080a_loki_spi_board[0],
780                                 ARRAY_SIZE(rm31080a_loki_spi_board));
781         return 0;
782 }
783
784 static void __init tegra_loki_early_init(void)
785 {
786         tegra_clk_init_from_table(loki_clk_init_table);
787         tegra_clk_verify_parents();
788         tegra_soc_device_init("loki");
789 }
790
791 static void __init tegra_loki_late_init(void)
792 {
793         struct board_info board_info;
794         tegra_get_board_info(&board_info);
795         pr_info("board_info: id:sku:fab:major:minor = 0x%04x:0x%04x:0x%02x:0x%02x:0x%02x\n",
796                 board_info.board_id, board_info.sku,
797                 board_info.fab, board_info.major_revision,
798                 board_info.minor_revision);
799         platform_device_register(&tegra_pinmux_device);
800         loki_pinmux_init();
801         loki_usb_init();
802         loki_modem_init();
803         loki_xusb_init();
804         loki_i2c_init();
805         loki_spi_init();
806         loki_uart_init();
807         loki_audio_init();
808         platform_add_devices(loki_devices, ARRAY_SIZE(loki_devices));
809         //tegra_ram_console_debug_init();
810         tegra_io_dpd_init();
811         loki_sdhci_init();
812         loki_regulator_init();
813         loki_suspend_init();
814 #if 0
815         loki_emc_init();
816 #endif
817         loki_edp_init();
818         isomgr_init();
819         loki_touch_init();
820         loki_panel_init();
821         loki_kbc_init();
822         loki_pmon_init();
823 #ifdef CONFIG_TEGRA_WDT_RECOVERY
824         tegra_wdt_recovery_init();
825 #endif
826         tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
827
828         loki_sensors_init();
829         loki_fan_init();
830         loki_soctherm_init();
831         loki_setup_bluedroid_pm();
832         tegra_register_fuse();
833         tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
834 }
835
836 static void __init loki_ramconsole_reserve(unsigned long size)
837 {
838         tegra_ram_console_debug_reserve(SZ_1M);
839 }
840
841 static void __init tegra_loki_dt_init(void)
842 {
843         tegra_get_board_info(&board_info);
844         tegra_get_display_board_info(&display_board_info);
845
846         tegra_loki_early_init();
847 #ifdef CONFIG_USE_OF
848         of_platform_populate(NULL,
849                 of_default_bus_match_table, loki_auxdata_lookup,
850                 &platform_bus);
851 #endif
852
853         tegra_loki_late_init();
854 }
855
856 static void __init tegra_loki_reserve(void)
857 {
858 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM) || \
859                 defined(CONFIG_TEGRA_NO_CARVEOUT)
860         /* 1920*1200*4*2 = 18432000 bytes */
861         tegra_reserve(0, SZ_16M + SZ_2M, SZ_16M);
862 #else
863         tegra_reserve(SZ_1G, SZ_16M + SZ_2M, SZ_4M);
864 #endif
865         loki_ramconsole_reserve(SZ_1M);
866 }
867
868 static const char * const loki_dt_board_compat[] = {
869         "nvidia,loki",
870         NULL
871 };
872
873 static void __init tegra_loki_init_early(void)
874 {
875         loki_rail_alignment_init();
876         tegra12x_init_early();
877 }
878
879 DT_MACHINE_START(LOKI, "loki")
880         .atag_offset    = 0x100,
881         .smp            = smp_ops(tegra_smp_ops),
882         .map_io         = tegra_map_common_io,
883         .reserve        = tegra_loki_reserve,
884         .init_early     = tegra_loki_init_early,
885         .init_irq       = tegra_dt_init_irq,
886         .init_time      = tegra_init_timer,
887         .init_machine   = tegra_loki_dt_init,
888         .restart        = tegra_assert_system_reset,
889         .dt_compat      = loki_dt_board_compat,
890 MACHINE_END