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