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