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