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