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