6bb5373ac4e5cd73cff92b4119ec9ab872b7980c
[linux-2.6.git] / arch / arm / mach-tegra / board-kai.c
1 /*
2  * arch/arm/mach-tegra/board-kai.c
3  *
4  * Copyright (c) 2012-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/dma-mapping.h>
29 #include <linux/delay.h>
30 #include <linux/i2c-tegra.h>
31 #include <linux/gpio.h>
32 #include <linux/input.h>
33 #include <linux/platform_data/tegra_usb.h>
34 #include <linux/spi/spi.h>
35 #include <linux/spi/rm31080a_ts.h>
36 #include <linux/tegra_uart.h>
37 #include <linux/memblock.h>
38 #include <linux/spi-tegra.h>
39 #include <linux/nfc/pn544.h>
40 #include <linux/skbuff.h>
41 #include <linux/ti_wilink_st.h>
42 #include <linux/regulator/consumer.h>
43 #include <linux/smb349-charger.h>
44 #include <linux/max17048_battery.h>
45 #include <linux/leds.h>
46 #include <linux/i2c/at24.h>
47 #include <linux/of_platform.h>
48
49 #include <asm/hardware/gic.h>
50
51 #include <mach/clk.h>
52 #include <mach/iomap.h>
53 #include <mach/irqs.h>
54 #include <mach/pinmux.h>
55 #include <mach/pinmux-tegra30.h>
56 #include <mach/iomap.h>
57 #include <mach/io.h>
58 #include <mach/io_dpd.h>
59 #include <mach/i2s.h>
60 #include <mach/tegra_asoc_pdata.h>
61 #include <asm/mach-types.h>
62 #include <asm/mach/arch.h>
63 #include <mach/usb_phy.h>
64 #include <mach/gpio-tegra.h>
65 #include <mach/tegra_fiq_debugger.h>
66 #include <mach/tegra_wakeup_monitor.h>
67
68 #include "board.h"
69 #include "board-common.h"
70 #include "clock.h"
71 #include "board-kai.h"
72 #include "board-touch-raydium.h"
73 #include "devices.h"
74 #include "gpio-names.h"
75 #include "fuse.h"
76 #include "pm.h"
77 #include "wdt-recovery.h"
78 #include "common.h"
79
80 /* wl128x BT, FM, GPS connectivity chip */
81 struct ti_st_plat_data kai_wilink_pdata = {
82         .nshutdown_gpio = TEGRA_GPIO_PU0,
83         .dev_name = BLUETOOTH_UART_DEV_NAME,
84         .flow_cntrl = 1,
85         .baud_rate = 3000000,
86 };
87
88 static struct platform_device wl128x_device = {
89         .name           = "kim",
90         .id             = -1,
91         .dev.platform_data = &kai_wilink_pdata,
92 };
93
94 static struct platform_device btwilink_device = {
95         .name = "btwilink",
96         .id = -1,
97 };
98
99 static noinline void __init kai_bt_st(void)
100 {
101         pr_info("kai_bt_st");
102
103         platform_device_register(&wl128x_device);
104         platform_device_register(&btwilink_device);
105 }
106
107 static struct resource kai_bluesleep_resources[] = {
108         [0] = {
109                 .name = "gpio_host_wake",
110                         .start  = TEGRA_GPIO_PU6,
111                         .end    = TEGRA_GPIO_PU6,
112                         .flags  = IORESOURCE_IO,
113         },
114         [1] = {
115                 .name = "host_wake",
116                         .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
117         },
118 };
119
120 static struct platform_device kai_bluesleep_device = {
121         .name           = "bluesleep",
122         .id             = 0,
123         .num_resources  = ARRAY_SIZE(kai_bluesleep_resources),
124         .resource       = kai_bluesleep_resources,
125 };
126
127 static noinline void __init kai_tegra_setup_tibluesleep(void)
128 {
129         kai_bluesleep_device.resource[1].start =
130                 kai_bluesleep_device.resource[1].end =
131                         gpio_to_irq(TEGRA_GPIO_PU6);
132         platform_device_register(&kai_bluesleep_device);
133 }
134
135 static __initdata struct tegra_clk_init_table kai_clk_init_table[] = {
136         /* name         parent          rate            enabled */
137         { "pll_m",      NULL,           0,              false},
138         { "hda",        "pll_p",        108000000,      false},
139         { "hda2codec_2x", "pll_p",      48000000,       false},
140         { "pwm",        "pll_p",        3187500,        false},
141         { "blink",      "clk_32k",      32768,          true},
142         { "i2s1",       "pll_a_out0",   0,              false},
143         { "i2s3",       "pll_a_out0",   0,              false},
144         { "i2s4",       "pll_a_out0",   0,              false},
145         { "spdif_out",  "pll_a_out0",   0,              false},
146         { "d_audio",    "clk_m",        12000000,       false},
147         { "dam0",       "clk_m",        12000000,       false},
148         { "dam1",       "clk_m",        12000000,       false},
149         { "dam2",       "clk_m",        12000000,       false},
150         { "audio1",     "i2s1_sync",    0,              false},
151         { "audio3",     "i2s3_sync",    0,              false},
152         { "vi_sensor",  "pll_p",        150000000,      false},
153         { "i2c1",       "pll_p",        3200000,        false},
154         { "i2c2",       "pll_p",        3200000,        false},
155         { "i2c3",       "pll_p",        3200000,        false},
156         { "i2c4",       "pll_p",        3200000,        false},
157         { "i2c5",       "pll_p",        3200000,        false},
158         { NULL,         NULL,           0,              0},
159 };
160
161 static struct pn544_i2c_platform_data nfc_pdata = {
162         .irq_gpio = TEGRA_GPIO_PX0,
163         .ven_gpio = TEGRA_GPIO_PS7,
164         .firm_gpio = TEGRA_GPIO_PR3,
165 };
166
167 static struct i2c_board_info __initdata kai_nfc_board_info[] = {
168         {
169                 I2C_BOARD_INFO("pn544", 0x28),
170                 .platform_data = &nfc_pdata,
171         },
172 };
173
174 static struct tegra_i2c_platform_data kai_i2c1_platform_data = {
175         .adapter_nr     = 0,
176         .bus_count      = 1,
177         .bus_clk_rate   = { 100000, 0 },
178         .scl_gpio               = {TEGRA_GPIO_PC4, 0},
179         .sda_gpio               = {TEGRA_GPIO_PC5, 0},
180         .arb_recovery = arb_lost_recovery,
181 };
182
183 static struct tegra_i2c_platform_data kai_i2c2_platform_data = {
184         .adapter_nr     = 1,
185         .bus_count      = 1,
186         .bus_clk_rate   = { 100000, 0 },
187         .is_clkon_always = true,
188         .scl_gpio               = {TEGRA_GPIO_PT5, 0},
189         .sda_gpio               = {TEGRA_GPIO_PT6, 0},
190         .arb_recovery = arb_lost_recovery,
191 };
192
193 static struct tegra_i2c_platform_data kai_i2c3_platform_data = {
194         .adapter_nr     = 2,
195         .bus_count      = 1,
196         .bus_clk_rate   = { 100000, 0 },
197         .scl_gpio               = {TEGRA_GPIO_PBB1, 0},
198         .sda_gpio               = {TEGRA_GPIO_PBB2, 0},
199         .arb_recovery = arb_lost_recovery,
200 };
201
202 static struct tegra_i2c_platform_data kai_i2c4_platform_data = {
203         .adapter_nr     = 3,
204         .bus_count      = 1,
205         .bus_clk_rate   = { 10000, 0 },
206         .scl_gpio               = {TEGRA_GPIO_PV4, 0},
207         .sda_gpio               = {TEGRA_GPIO_PV5, 0},
208         .arb_recovery = arb_lost_recovery,
209 };
210
211 static struct tegra_i2c_platform_data kai_i2c5_platform_data = {
212         .adapter_nr     = 4,
213         .bus_count      = 1,
214         .bus_clk_rate   = { 400000, 0 },
215         .scl_gpio               = {TEGRA_GPIO_PZ6, 0},
216         .sda_gpio               = {TEGRA_GPIO_PZ7, 0},
217         .arb_recovery = arb_lost_recovery,
218 };
219
220 struct max17048_battery_model max17048_mdata = {
221         .rcomp          = 170,
222         .soccheck_A     = 252,
223         .soccheck_B     = 254,
224         .bits           = 19,
225         .alert_threshold = 0x00,
226         .one_percent_alerts = 0x40,
227         .alert_on_reset = 0x40,
228         .rcomp_seg      = 0x0800,
229         .hibernate      = 0x3080,
230         .vreset         = 0x9696,
231         .valert         = 0xD4AA,
232         .ocvtest        = 55600,
233 };
234
235
236 static struct at24_platform_data eeprom_info = {
237         .byte_len       = (256*1024)/8,
238         .page_size      = 64,
239         .flags          = AT24_FLAG_ADDR16,
240         .setup          = get_mac_addr,
241 };
242
243 static struct i2c_board_info kai_i2c4_max17048_board_info[] = {
244         {
245                 I2C_BOARD_INFO("max17048", 0x36),
246                 .platform_data = &max17048_mdata,
247         },
248 };
249
250 static struct i2c_board_info kai_eeprom_mac_add = {
251         I2C_BOARD_INFO("at24", 0x56),
252         .platform_data = &eeprom_info,
253 };
254
255 static struct regulator_consumer_supply smb349_vbus_supply[] = {
256         REGULATOR_SUPPLY("usb_bat_chg", "tegra-udc.0"),
257 };
258
259 static struct regulator_consumer_supply smb349_otg_vbus_supply[] = {
260         REGULATOR_SUPPLY("usb_vbus", "tegra-ehci.0"),
261         REGULATOR_SUPPLY("usb_vbus", "tegra-otg"),
262 };
263
264 static struct smb349_charger_platform_data smb349_charger_pdata = {
265         .max_charge_current_mA = 1000,
266         .charging_term_current_mA = 100,
267         .consumer_supplies = smb349_vbus_supply,
268         .num_consumer_supplies = ARRAY_SIZE(smb349_vbus_supply),
269         .otg_consumer_supplies = smb349_otg_vbus_supply,
270         .num_otg_consumer_supplies = ARRAY_SIZE(smb349_otg_vbus_supply),
271 };
272
273 static struct i2c_board_info kai_i2c4_smb349_board_info[] = {
274         {
275                 I2C_BOARD_INFO("smb349", 0x1B),
276                 .platform_data = &smb349_charger_pdata,
277         },
278 };
279
280 static struct i2c_board_info __initdata rt5640_board_info = {
281         I2C_BOARD_INFO("rt5640", 0x1c),
282 };
283
284 static struct i2c_board_info __initdata rt5639_board_info = {
285         I2C_BOARD_INFO("rt5639", 0x1c),
286 };
287
288 static void kai_i2c_init(void)
289 {
290         struct board_info board_info;
291
292         tegra_get_board_info(&board_info);
293
294         tegra_i2c_device1.dev.platform_data = &kai_i2c1_platform_data;
295         tegra_i2c_device2.dev.platform_data = &kai_i2c2_platform_data;
296         tegra_i2c_device3.dev.platform_data = &kai_i2c3_platform_data;
297         tegra_i2c_device4.dev.platform_data = &kai_i2c4_platform_data;
298         tegra_i2c_device5.dev.platform_data = &kai_i2c5_platform_data;
299
300         platform_device_register(&tegra_i2c_device5);
301         platform_device_register(&tegra_i2c_device4);
302         platform_device_register(&tegra_i2c_device3);
303         platform_device_register(&tegra_i2c_device2);
304         platform_device_register(&tegra_i2c_device1);
305
306         i2c_register_board_info(4, kai_i2c4_smb349_board_info,
307                 ARRAY_SIZE(kai_i2c4_smb349_board_info));
308
309         rt5639_board_info.irq = rt5640_board_info.irq =
310                 gpio_to_irq(TEGRA_GPIO_CDC_IRQ);
311         if (board_info.fab == BOARD_FAB_A00)
312                 i2c_register_board_info(4, &rt5640_board_info, 1);
313         else
314                 i2c_register_board_info(4, &rt5639_board_info, 1);
315
316         i2c_register_board_info(4, &kai_eeprom_mac_add, 1);
317
318         i2c_register_board_info(4, kai_i2c4_max17048_board_info,
319                 ARRAY_SIZE(kai_i2c4_max17048_board_info));
320
321         kai_nfc_board_info[0].irq = gpio_to_irq(TEGRA_GPIO_PX0);
322         i2c_register_board_info(0, kai_nfc_board_info, 1);
323 }
324
325 static struct platform_device *kai_uart_devices[] __initdata = {
326         &tegra_uarta_device,
327         &tegra_uartb_device,
328         &tegra_uartc_device,
329         &tegra_uartd_device,
330         &tegra_uarte_device,
331 };
332 static struct uart_clk_parent uart_parent_clk[] = {
333         [0] = {.name = "clk_m"},
334         [1] = {.name = "pll_p"},
335 #ifndef CONFIG_TEGRA_PLLM_RESTRICTED
336         [2] = {.name = "pll_m"},
337 #endif
338 };
339
340 static struct tegra_uart_platform_data kai_uart_pdata;
341 static struct tegra_uart_platform_data kai_loopback_uart_pdata;
342
343 static void __init uart_debug_init(void)
344 {
345         int debug_port_id;
346
347         debug_port_id = uart_console_debug_init(3);
348         if (debug_port_id < 0)
349                 return;
350         kai_uart_devices[debug_port_id] = uart_console_debug_device;
351
352         return;
353 }
354
355 static void __init kai_uart_init(void)
356 {
357         struct clk *c;
358         int i;
359
360         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
361                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
362                 if (IS_ERR_OR_NULL(c)) {
363                         pr_err("Not able to get the clock for %s\n",
364                                                 uart_parent_clk[i].name);
365                         continue;
366                 }
367                 uart_parent_clk[i].parent_clk = c;
368                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
369         }
370         kai_uart_pdata.parent_clk_list = uart_parent_clk;
371         kai_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
372         kai_loopback_uart_pdata.parent_clk_list = uart_parent_clk;
373         kai_loopback_uart_pdata.parent_clk_count =
374                                                 ARRAY_SIZE(uart_parent_clk);
375         kai_loopback_uart_pdata.is_loopback = true;
376         tegra_uarta_device.dev.platform_data = &kai_uart_pdata;
377         tegra_uartb_device.dev.platform_data = &kai_uart_pdata;
378         tegra_uartc_device.dev.platform_data = &kai_uart_pdata;
379         tegra_uartd_device.dev.platform_data = &kai_uart_pdata;
380         /* UARTE is used for loopback test purpose */
381         tegra_uarte_device.dev.platform_data = &kai_loopback_uart_pdata;
382
383         /* Register low speed only if it is selected */
384         if (!is_tegra_debug_uartport_hs())
385                 uart_debug_init();
386
387         platform_add_devices(kai_uart_devices,
388                                 ARRAY_SIZE(kai_uart_devices));
389 }
390
391 static struct platform_device tegra_camera = {
392         .name = "tegra_camera",
393         .id = -1,
394 };
395
396 static struct platform_device *kai_spi_devices[] __initdata = {
397         &tegra_spi_device1,
398 };
399
400 static struct spi_clk_parent spi_parent_clk[] = {
401         [0] = {.name = "pll_p"},
402 #ifndef CONFIG_TEGRA_PLLM_RESTRICTED
403         [1] = {.name = "pll_m"},
404         [2] = {.name = "clk_m"},
405 #else
406         [1] = {.name = "clk_m"},
407 #endif
408 };
409
410 static struct tegra_spi_platform_data kai_spi1_pdata = {
411                 .is_dma_based           = true,
412                 .max_dma_buffer         = (128),
413                 .is_clkon_always        = false,
414                 .max_rate               = 100000000,
415 };
416
417 static void __init kai_spi_init(void)
418 {
419         int i;
420         struct clk *c;
421
422         for (i = 0; i < ARRAY_SIZE(spi_parent_clk); ++i) {
423                 c = tegra_get_clock_by_name(spi_parent_clk[i].name);
424                 if (IS_ERR_OR_NULL(c)) {
425                         pr_err("Not able to get the clock for %s\n",
426                                                 spi_parent_clk[i].name);
427                         continue;
428                 }
429                 spi_parent_clk[i].parent_clk = c;
430                 spi_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
431         }
432
433         kai_spi1_pdata.parent_clk_list = spi_parent_clk;
434         kai_spi1_pdata.parent_clk_count = ARRAY_SIZE(spi_parent_clk);
435         tegra_spi_device1.dev.platform_data = &kai_spi1_pdata;
436         platform_add_devices(kai_spi_devices,
437                                 ARRAY_SIZE(kai_spi_devices));
438
439 }
440
441 static struct resource tegra_rtc_resources[] = {
442         [0] = {
443                 .start = TEGRA_RTC_BASE,
444                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
445                 .flags = IORESOURCE_MEM,
446         },
447         [1] = {
448                 .start = INT_RTC,
449                 .end = INT_RTC,
450                 .flags = IORESOURCE_IRQ,
451         },
452 };
453
454 static struct platform_device tegra_rtc_device = {
455         .name = "tegra_rtc",
456         .id   = -1,
457         .resource = tegra_rtc_resources,
458         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
459 };
460
461 static struct tegra_wakeup_monitor_platform_data
462                                         kai_tegra_wakeup_monitor_pdata = {
463         .wifi_wakeup_source     = 1,  /* kai's wifi wakeup source */
464 };
465
466 static struct platform_device kai_tegra_wakeup_monitor_device = {
467         .name = "tegra_wakeup_monitor",
468         .id   = -1,
469         .dev  = {
470                 .platform_data = &kai_tegra_wakeup_monitor_pdata,
471         },
472 };
473
474 static struct tegra_asoc_platform_data kai_audio_pdata = {
475         .gpio_spkr_en           = TEGRA_GPIO_SPKR_EN,
476         .gpio_hp_det            = TEGRA_GPIO_HP_DET,
477         .gpio_hp_mute           = -1,
478         .gpio_int_mic_en        = TEGRA_GPIO_INT_MIC_EN,
479         .gpio_ext_mic_en        = TEGRA_GPIO_EXT_MIC_EN,
480         .gpio_ldo1_en           = TEGRA_GPIO_PX2,
481         .i2s_param[HIFI_CODEC]  = {
482                 .audio_port_id  = 0,
483                 .is_i2s_master  = 1,
484                 .i2s_mode       = TEGRA_DAIFMT_I2S,
485         },
486         .i2s_param[BASEBAND]    = {
487                 .audio_port_id  = -1,
488         },
489         .i2s_param[BT_SCO]      = {
490                 .audio_port_id  = 3,
491                 .is_i2s_master  = 1,
492                 .i2s_mode       = TEGRA_DAIFMT_DSP_A,
493         },
494 };
495
496 static struct platform_device kai_audio_device = {
497         .name   = "tegra-snd-rt5640",
498         .id     = 0,
499         .dev    = {
500                 .platform_data = &kai_audio_pdata,
501         },
502 };
503
504 static struct gpio_led kai_led_info[] = {
505         {
506                 .name                   = "statled",
507                 .default_trigger        = "default-on",
508                 .gpio                   = TEGRA_GPIO_STAT_LED,
509                 .active_low             = 1,
510                 .retain_state_suspended = 0,
511                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
512         },
513 };
514
515 static struct gpio_led_platform_data kai_leds_pdata = {
516         .leds           = kai_led_info,
517         .num_leds       = ARRAY_SIZE(kai_led_info),
518 };
519
520 static struct platform_device kai_leds_gpio_device = {
521         .name   = "leds-gpio",
522         .id     = -1,
523         .dev    = {
524                 .platform_data = &kai_leds_pdata,
525         },
526 };
527
528 static struct platform_device *kai_devices[] __initdata = {
529         &tegra_pmu_device,
530         &tegra_rtc_device,
531         &tegra_udc_device,
532         &tegra_wdt0_device,
533 #if defined(CONFIG_TEGRA_AVP)
534         &tegra_avp_device,
535 #endif
536         &tegra_camera,
537 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
538         &tegra_se_device,
539 #endif
540         &tegra_ahub_device,
541         &tegra_dam_device0,
542         &tegra_dam_device1,
543         &tegra_dam_device2,
544         &tegra_i2s_device1,
545         &tegra_i2s_device3,
546         &tegra_i2s_device4,
547         &tegra_spdif_device,
548         &spdif_dit_device,
549         &bluetooth_dit_device,
550         &tegra_pcm_device,
551 #if defined(CONFIG_TEGRA_WAKEUP_MONITOR)
552         &kai_tegra_wakeup_monitor_device,
553 #endif
554         &kai_audio_device,
555         &kai_leds_gpio_device,
556         &tegra_hda_device,
557 #if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
558         &tegra_aes_device,
559 #endif
560 };
561
562 static __initdata struct tegra_clk_init_table spi_clk_init_table[] = {
563         /* name         parent          rate            enabled */
564         { "sbc1",       "pll_p",        52000000,       true},
565         { NULL,         NULL,           0,              0},
566 };
567
568 static __initdata struct tegra_clk_init_table touch_clk_init_table[] = {
569         /* name         parent          rate            enabled */
570         { "extern3",    "pll_p",        41000000,       true},
571         { "clk_out_3",  "extern3",      40800000,       true},
572         { NULL,         NULL,           0,              0},
573 };
574
575
576 struct rm_spi_ts_platform_data rm31080ts_kai_007_data = {
577         .gpio_reset = 0,
578         .config = 0,
579         .platform_id = RM_PLATFORM_K007,
580         .name_of_clock = NULL,
581         .name_of_clock_con = NULL,
582 };
583
584 struct rm_spi_ts_platform_data rm31080ts_kai_107_data = {
585         .gpio_reset = 0,
586         .config = 0,
587         .platform_id = RM_PLATFORM_K107,
588         .name_of_clock = "clk_out_3",
589         .name_of_clock_con = "extern3",
590 };
591
592 struct spi_board_info rm31080a_kai_spi_board[1] = {
593         {
594          .modalias = "rm_ts_spidev",
595          .bus_num = 0,
596          .chip_select = 0,
597          .max_speed_hz = 13 * 1000 * 1000,
598          .mode = SPI_MODE_0,
599          .platform_data = &rm31080ts_kai_107_data,
600          },
601 };
602
603 static int __init kai_touch_init(void)
604 {
605         int touch_id;
606
607         touch_id = gpio_request(KAI_TS_ID1, "touch-id1");
608         if (touch_id < 0) {
609                 pr_err("%s: gpio_request failed %d\n",
610                         __func__, touch_id);
611                 return touch_id;
612         }
613         touch_id = gpio_direction_input(KAI_TS_ID1);
614         if (touch_id < 0) {
615                 pr_err("%s: gpio_direction_input failed %d\n",
616                         __func__, touch_id);
617                 gpio_free(KAI_TS_ID1);
618         }
619
620         touch_id = gpio_request(KAI_TS_ID2, "touch-id2");
621         if (touch_id < 0) {
622                 pr_err("%s: gpio_request failed %d\n",
623                         __func__, touch_id);
624                 return touch_id;
625         }
626         touch_id = gpio_direction_input(KAI_TS_ID2);
627         if (touch_id < 0) {
628                 pr_err("%s: gpio_direction_input failed %d\n",
629                         __func__, touch_id);
630                 gpio_free(KAI_TS_ID2);
631         }
632
633         touch_id = gpio_get_value(KAI_TS_ID1) << 1;
634         touch_id |= gpio_get_value(KAI_TS_ID2);
635
636         pr_info("touch-id %d\n", touch_id);
637
638         /* Disable TS_ID GPIO to save power */
639         gpio_direction_output(KAI_TS_ID1, 0);
640         tegra_pinmux_set_pullupdown(KAI_TS_ID1_PG, TEGRA_PUPD_NORMAL);
641         tegra_pinmux_set_tristate(KAI_TS_ID1_PG, TEGRA_TRI_TRISTATE);
642         gpio_direction_output(KAI_TS_ID2, 0);
643         tegra_pinmux_set_pullupdown(KAI_TS_ID2_PG, TEGRA_PUPD_NORMAL);
644         tegra_pinmux_set_tristate(KAI_TS_ID2_PG, TEGRA_TRI_TRISTATE);
645
646         switch (touch_id) {
647         case 0:
648                 pr_info("Raydium PCB based touch init\n");
649                 tegra_clk_init_from_table(spi_clk_init_table);
650                 rm31080a_kai_spi_board[0].platform_data =
651                         &rm31080ts_kai_007_data;
652                 rm31080a_kai_spi_board[0].irq =
653                         gpio_to_irq(TOUCH_GPIO_IRQ_RAYDIUM_SPI);
654                 touch_init_raydium(TOUCH_GPIO_IRQ_RAYDIUM_SPI,
655                                         TOUCH_GPIO_RST_RAYDIUM_SPI,
656                                         &rm31080ts_kai_007_data,
657                                         &rm31080a_kai_spi_board[0],
658                                         ARRAY_SIZE(rm31080a_kai_spi_board));
659                 break;
660         case 1:
661                 pr_info("Raydium On-Board touch init\n");
662                 tegra_clk_init_from_table(spi_clk_init_table);
663                 tegra_clk_init_from_table(touch_clk_init_table);
664                 rm31080a_kai_spi_board[0].platform_data =
665                         &rm31080ts_kai_107_data;
666                 rm31080a_kai_spi_board[0].irq =
667                         gpio_to_irq(TOUCH_GPIO_IRQ_RAYDIUM_SPI);
668                 touch_init_raydium(TOUCH_GPIO_IRQ_RAYDIUM_SPI,
669                                         TOUCH_GPIO_RST_RAYDIUM_SPI,
670                                         &rm31080ts_kai_107_data,
671                                         &rm31080a_kai_spi_board[0],
672                                         ARRAY_SIZE(rm31080a_kai_spi_board));
673                 break;
674         case 3:
675                 pr_info("Synaptics PCB based touch init\n");
676                 touch_init_synaptics_kai();
677                 break;
678         default:
679                 pr_err("touch_id error, no touch %d\n", touch_id);
680         }
681         return 0;
682 }
683
684 static struct tegra_usb_platform_data tegra_udc_pdata = {
685         .port_otg = true,
686         .has_hostpc = true,
687         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
688         .op_mode = TEGRA_USB_OPMODE_DEVICE,
689         .u_data.dev = {
690                 .vbus_pmu_irq = 0,
691                 .vbus_gpio = -1,
692                 .charging_supported = false,
693                 .remote_wakeup_supported = false,
694         },
695         .u_cfg.utmi = {
696                 .hssync_start_delay = 0,
697                 .elastic_limit = 16,
698                 .idle_wait_delay = 17,
699                 .term_range_adj = 6,
700                 .xcvr_setup = 8,
701                 .xcvr_lsfslew = 2,
702                 .xcvr_lsrslew = 2,
703                 .xcvr_setup_offset = 0,
704                 .xcvr_use_fuses = 1,
705         },
706 };
707
708 static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
709         .port_otg = true,
710         .has_hostpc = true,
711         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
712         .op_mode = TEGRA_USB_OPMODE_HOST,
713         .u_data.host = {
714                 .vbus_gpio = -1,
715                 .hot_plug = true,
716                 .remote_wakeup_supported = true,
717                 .power_off_on_suspend = true,
718         },
719         .u_cfg.utmi = {
720                 .hssync_start_delay = 0,
721                 .elastic_limit = 16,
722                 .idle_wait_delay = 17,
723                 .term_range_adj = 6,
724                 .xcvr_setup = 15,
725                 .xcvr_lsfslew = 2,
726                 .xcvr_lsrslew = 2,
727                 .xcvr_setup_offset = 0,
728                 .xcvr_use_fuses = 1,
729         },
730 };
731
732
733 static struct tegra_usb_platform_data tegra_ehci2_utmi_pdata = {
734         .port_otg = false,
735         .has_hostpc = true,
736         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
737         .op_mode        = TEGRA_USB_OPMODE_HOST,
738         .u_data.host = {
739                 .vbus_gpio = -1,
740                 .hot_plug = true,
741                 .remote_wakeup_supported = true,
742                 .power_off_on_suspend = true,
743
744         },
745         .u_cfg.utmi = {
746                 .hssync_start_delay = 0,
747                 .elastic_limit = 16,
748                 .idle_wait_delay = 17,
749                 .term_range_adj = 6,
750                 .xcvr_setup = 8,
751                 .xcvr_lsfslew = 2,
752                 .xcvr_lsrslew = 2,
753                 .xcvr_setup_offset = 0,
754                 .xcvr_use_fuses = 1,
755         },
756 };
757
758 static struct tegra_usb_otg_data tegra_otg_pdata = {
759         .ehci_device = &tegra_ehci1_device,
760         .ehci_pdata = &tegra_ehci1_utmi_pdata,
761 };
762
763 #if CONFIG_USB_SUPPORT
764 static void kai_usb_init(void)
765 {
766         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
767         platform_device_register(&tegra_otg_device);
768
769         /* Setup the udc platform data */
770         tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
771 }
772
773 static void kai_modem_init(void)
774 {
775         int ret;
776         int modem_id = tegra_get_modem_id();
777
778         if (modem_id == TEGRA_BB_TANGO) {
779                 tegra_ehci2_device.dev.platform_data = &tegra_ehci2_utmi_pdata;
780                 platform_device_register(&tegra_ehci2_device);
781         }
782
783
784         ret = gpio_request(TEGRA_GPIO_W_DISABLE, "w_disable_gpio");
785         if (ret < 0)
786                 pr_err("%s: gpio_request failed for gpio %d\n",
787                         __func__, TEGRA_GPIO_W_DISABLE);
788         else {
789                 ret = gpio_direction_output(TEGRA_GPIO_W_DISABLE, 1);
790                 if (ret < 0) {
791                         pr_err("%s: gpio_direction_output failed %d\n",
792                                 __func__, ret);
793                         gpio_free(TEGRA_GPIO_W_DISABLE);
794                 }
795         }
796
797         ret = gpio_request(TEGRA_GPIO_MODEM_RSVD1, "Port_V_PIN_0");
798         if (ret < 0)
799                 pr_err("%s: gpio_request failed for gpio %d\n",
800                         __func__, TEGRA_GPIO_MODEM_RSVD1);
801         else {
802                 ret = gpio_direction_input(TEGRA_GPIO_MODEM_RSVD1);
803                 if (ret < 0) {
804                         pr_err("%s: gpio_direction_output failed %d\n",
805                                 __func__, ret);
806                         gpio_free(TEGRA_GPIO_MODEM_RSVD1);
807                 }
808         }
809
810
811         ret = gpio_request(TEGRA_GPIO_MODEM_RSVD2, "Port_H_PIN_7");
812         if (ret < 0)
813                 pr_err("%s: gpio_request failed for gpio %d\n",
814                         __func__, TEGRA_GPIO_MODEM_RSVD2);
815         else {
816                 ret = gpio_direction_output(TEGRA_GPIO_MODEM_RSVD2, 1);
817                 if (ret < 0) {
818                         pr_err("%s: gpio_direction_output failed %d\n",
819                                 __func__, ret);
820                         gpio_free(TEGRA_GPIO_MODEM_RSVD2);
821                 }
822         }
823
824 }
825
826 #else
827 static void kai_usb_init(void) { }
828 static void kai_modem_init(void) { }
829 #endif
830
831 static void kai_audio_init(void)
832 {
833         struct board_info board_info;
834
835         tegra_get_board_info(&board_info);
836
837         if (board_info.fab == BOARD_FAB_A01) {
838                 kai_audio_pdata.codec_name = "rt5639.4-001c";
839                 kai_audio_pdata.codec_dai_name = "rt5639-aif1";
840         } else if (board_info.fab == BOARD_FAB_A00) {
841                 kai_audio_pdata.codec_name = "rt5640.4-001c";
842                 kai_audio_pdata.codec_dai_name = "rt5640-aif1";
843         }
844 }
845
846 static void __init tegra_kai_init(void)
847 {
848         tegra_clk_init_from_table(kai_clk_init_table);
849         tegra_enable_pinmux();
850         tegra_smmu_init();
851         tegra_soc_device_init("kai");
852         kai_pinmux_init();
853         kai_i2c_init();
854         kai_spi_init();
855         kai_usb_init();
856 #ifdef CONFIG_TEGRA_EDP_LIMITS
857         kai_edp_init();
858 #endif
859         kai_uart_init();
860         kai_audio_init();
861         platform_add_devices(kai_devices, ARRAY_SIZE(kai_devices));
862         tegra_ram_console_debug_init();
863         tegra_io_dpd_init();
864         kai_sdhci_init();
865         kai_regulator_init();
866         kai_suspend_init();
867         kai_touch_init();
868         kai_keys_init();
869         kai_panel_init();
870         kai_tegra_setup_tibluesleep();
871         kai_bt_st();
872         kai_sensors_init();
873         kai_pins_state_init();
874         kai_emc_init();
875         tegra_release_bootloader_fb();
876         kai_modem_init();
877 #ifdef CONFIG_TEGRA_WDT_RECOVERY
878         tegra_wdt_recovery_init();
879 #endif
880         tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
881         tegra_register_fuse();
882 }
883
884 static void __init kai_ramconsole_reserve(unsigned long size)
885 {
886         tegra_ram_console_debug_reserve(SZ_1M);
887 }
888
889 static void __init tegra_kai_dt_init(void)
890 {
891         tegra_kai_init();
892
893 #ifdef CONFIG_USE_OF
894         of_platform_populate(NULL,
895                 of_default_bus_match_table, NULL, NULL);
896 #endif
897 }
898
899 static void __init tegra_kai_reserve(void)
900 {
901 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
902         /* support 1920X1200 with 24bpp */
903         tegra_reserve(0, SZ_8M + SZ_1M, SZ_8M + SZ_1M);
904 #else
905         tegra_reserve(SZ_128M, SZ_8M, SZ_8M);
906 #endif
907         kai_ramconsole_reserve(SZ_1M);
908 }
909
910 static const char * const kai_dt_board_compat[] = {
911         "nvidia,kai",
912         NULL
913 };
914
915 MACHINE_START(KAI, "kai")
916         .atag_offset    = 0x100,
917         .soc            = &tegra_soc_desc,
918         .map_io         = tegra_map_common_io,
919         .reserve        = tegra_kai_reserve,
920         .init_early     = tegra30_init_early,
921         .init_irq       = tegra_init_irq,
922         .handle_irq     = gic_handle_irq,
923         .timer          = &tegra_timer,
924         .init_machine   = tegra_kai_dt_init,
925         .restart        = tegra_assert_system_reset,
926         .dt_compat      = kai_dt_board_compat,
927 MACHINE_END