bc44bbaa6f913edacceb8618f1557bf1ec0787c7
[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_rt5640_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_rt5640_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 };
588
589 static struct platform_device kai_audio_device = {
590         .name   = "tegra-snd-rt5640",
591         .id     = 0,
592         .dev    = {
593                 .platform_data = &kai_audio_pdata,
594         },
595 };
596
597 static struct gpio_led kai_led_info[] = {
598         {
599                 .name                   = "statled",
600                 .default_trigger        = "default-on",
601                 .gpio                   = TEGRA_GPIO_STAT_LED,
602                 .active_low             = 1,
603                 .retain_state_suspended = 0,
604                 .default_state          = LEDS_GPIO_DEFSTATE_OFF,
605         },
606 };
607
608 static struct gpio_led_platform_data kai_leds_pdata = {
609         .leds           = kai_led_info,
610         .num_leds       = ARRAY_SIZE(kai_led_info),
611 };
612
613 static struct platform_device kai_leds_gpio_device = {
614         .name   = "leds-gpio",
615         .id     = -1,
616         .dev    = {
617                 .platform_data = &kai_leds_pdata,
618         },
619 };
620
621 static struct platform_device *kai_devices[] __initdata = {
622         &tegra_pmu_device,
623         &tegra_rtc_device,
624         &tegra_udc_device,
625 #if defined(CONFIG_TEGRA_IOVMM_SMMU) || defined(CONFIG_TEGRA_IOMMU_SMMU)
626         &tegra_smmu_device,
627 #endif
628         &tegra_wdt0_device,
629         &tegra_wdt1_device,
630         &tegra_wdt2_device,
631 #if defined(CONFIG_TEGRA_AVP)
632         &tegra_avp_device,
633 #endif
634         &tegra_camera,
635 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
636         &tegra_se_device,
637 #endif
638         &tegra_ahub_device,
639         &tegra_dam_device0,
640         &tegra_dam_device1,
641         &tegra_dam_device2,
642         &tegra_i2s_device1,
643         &tegra_i2s_device3,
644         &tegra_i2s_device4,
645         &tegra_spdif_device,
646         &spdif_dit_device,
647         &bluetooth_dit_device,
648         &tegra_pcm_device,
649         &kai_audio_device,
650         &kai_leds_gpio_device,
651         &tegra_hda_device,
652 #if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
653         &tegra_aes_device,
654 #endif
655 };
656
657 static __initdata struct tegra_clk_init_table spi_clk_init_table[] = {
658         /* name         parent          rate            enabled */
659         { "sbc1",       "pll_p",        52000000,       true},
660         { NULL,         NULL,           0,              0},
661 };
662
663 static __initdata struct tegra_clk_init_table touch_clk_init_table[] = {
664         /* name         parent          rate            enabled */
665         { "extern3",    "pll_p",        41000000,       true},
666         { "clk_out_3",  "extern3",      40800000,       true},
667         { NULL,         NULL,           0,              0},
668 };
669
670 static int __init kai_touch_init(void)
671 {
672         int touch_id;
673
674         gpio_request(KAI_TS_ID1, "touch-id1");
675         gpio_direction_input(KAI_TS_ID1);
676
677         gpio_request(KAI_TS_ID2, "touch-id2");
678         gpio_direction_input(KAI_TS_ID2);
679
680         touch_id = gpio_get_value(KAI_TS_ID1) << 1;
681         touch_id |= gpio_get_value(KAI_TS_ID2);
682
683         pr_info("touch-id %d\n", touch_id);
684
685         /* Disable TS_ID GPIO to save power */
686         gpio_direction_output(KAI_TS_ID1, 0);
687         tegra_pinmux_set_pullupdown(KAI_TS_ID1_PG, TEGRA_PUPD_NORMAL);
688         tegra_pinmux_set_tristate(KAI_TS_ID1_PG, TEGRA_TRI_TRISTATE);
689         gpio_direction_output(KAI_TS_ID2, 0);
690         tegra_pinmux_set_pullupdown(KAI_TS_ID2_PG, TEGRA_PUPD_NORMAL);
691         tegra_pinmux_set_tristate(KAI_TS_ID2_PG, TEGRA_TRI_TRISTATE);
692
693         switch (touch_id) {
694         case 0:
695                 pr_info("Raydium PCB based touch init\n");
696                 tegra_clk_init_from_table(spi_clk_init_table);
697                 touch_init_raydium(TEGRA_GPIO_PZ3, TEGRA_GPIO_PN5, 0);
698                 break;
699         case 1:
700                 pr_info("Raydium On-Board touch init\n");
701                 tegra_clk_init_from_table(spi_clk_init_table);
702                 tegra_clk_init_from_table(touch_clk_init_table);
703                 clk_enable(tegra_get_clock_by_name("clk_out_3"));
704
705                 touch_init_raydium(TEGRA_GPIO_PZ3, TEGRA_GPIO_PN5, 1);
706                 break;
707         case 3:
708                 pr_info("Synaptics PCB based touch init\n");
709                 touch_init_synaptics_kai();
710                 break;
711         default:
712                 pr_err("touch_id error, no touch %d\n", touch_id);
713         }
714         return 0;
715 }
716
717 static struct tegra_usb_platform_data tegra_udc_pdata = {
718         .port_otg = true,
719         .has_hostpc = true,
720         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
721         .op_mode = TEGRA_USB_OPMODE_DEVICE,
722         .u_data.dev = {
723                 .vbus_pmu_irq = 0,
724                 .vbus_gpio = -1,
725                 .charging_supported = false,
726                 .remote_wakeup_supported = false,
727         },
728         .u_cfg.utmi = {
729                 .hssync_start_delay = 0,
730                 .elastic_limit = 16,
731                 .idle_wait_delay = 17,
732                 .term_range_adj = 6,
733                 .xcvr_setup = 8,
734                 .xcvr_lsfslew = 2,
735                 .xcvr_lsrslew = 2,
736                 .xcvr_setup_offset = 0,
737                 .xcvr_use_fuses = 1,
738         },
739 };
740
741 static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
742         .port_otg = true,
743         .has_hostpc = true,
744         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
745         .op_mode = TEGRA_USB_OPMODE_HOST,
746         .u_data.host = {
747                 .vbus_gpio = -1,
748                 .vbus_reg = "usb_vbus_otg",
749                 .hot_plug = true,
750                 .remote_wakeup_supported = true,
751                 .power_off_on_suspend = true,
752         },
753         .u_cfg.utmi = {
754                 .hssync_start_delay = 0,
755                 .elastic_limit = 16,
756                 .idle_wait_delay = 17,
757                 .term_range_adj = 6,
758                 .xcvr_setup = 15,
759                 .xcvr_lsfslew = 2,
760                 .xcvr_lsrslew = 2,
761                 .xcvr_setup_offset = 0,
762                 .xcvr_use_fuses = 1,
763         },
764 };
765
766
767 static struct tegra_usb_platform_data tegra_ehci2_utmi_pdata = {
768         .port_otg = false,
769         .has_hostpc = true,
770         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
771         .op_mode        = TEGRA_USB_OPMODE_HOST,
772         .u_data.host = {
773                 .vbus_gpio = -1,
774                 .vbus_reg = NULL,
775                 .hot_plug = false,
776                 .remote_wakeup_supported = true,
777                 .power_off_on_suspend = true,
778
779         },
780         .u_cfg.utmi = {
781                 .hssync_start_delay = 0,
782                 .elastic_limit = 16,
783                 .idle_wait_delay = 17,
784                 .term_range_adj = 6,
785                 .xcvr_setup = 8,
786                 .xcvr_lsfslew = 2,
787                 .xcvr_lsrslew = 2,
788                 .xcvr_setup_offset = 0,
789                 .xcvr_use_fuses = 1,
790         },
791 };
792
793 static struct tegra_usb_otg_data tegra_otg_pdata = {
794         .ehci_device = &tegra_ehci1_device,
795         .ehci_pdata = &tegra_ehci1_utmi_pdata,
796 };
797
798 #if CONFIG_USB_SUPPORT
799 static void kai_usb_init(void)
800 {
801         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
802         platform_device_register(&tegra_otg_device);
803
804         /* Setup the udc platform data */
805         tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
806
807         tegra_ehci2_device.dev.platform_data = &tegra_ehci2_utmi_pdata;
808         platform_device_register(&tegra_ehci2_device);
809 }
810
811 static void kai_modem_init(void)
812 {
813         int ret;
814
815         ret = gpio_request(TEGRA_GPIO_W_DISABLE, "w_disable_gpio");
816         if (ret < 0)
817                 pr_err("%s: gpio_request failed for gpio %d\n",
818                         __func__, TEGRA_GPIO_W_DISABLE);
819         else
820                 gpio_direction_output(TEGRA_GPIO_W_DISABLE, 1);
821
822
823         ret = gpio_request(TEGRA_GPIO_MODEM_RSVD1, "Port_V_PIN_0");
824         if (ret < 0)
825                 pr_err("%s: gpio_request failed for gpio %d\n",
826                         __func__, TEGRA_GPIO_MODEM_RSVD1);
827         else
828                 gpio_direction_input(TEGRA_GPIO_MODEM_RSVD1);
829
830
831         ret = gpio_request(TEGRA_GPIO_MODEM_RSVD2, "Port_H_PIN_7");
832         if (ret < 0)
833                 pr_err("%s: gpio_request failed for gpio %d\n",
834                         __func__, TEGRA_GPIO_MODEM_RSVD2);
835         else
836                 gpio_direction_output(TEGRA_GPIO_MODEM_RSVD2, 1);
837
838 }
839
840 #else
841 static void kai_usb_init(void) { }
842 static void kai_modem_init(void) { }
843 #endif
844
845 static void kai_audio_init(void)
846 {
847         struct board_info board_info;
848
849         tegra_get_board_info(&board_info);
850
851         if (board_info.fab == BOARD_FAB_A01) {
852                 kai_audio_pdata.codec_name = "rt5639.4-001c";
853                 kai_audio_pdata.codec_dai_name = "rt5639-aif1";
854         } else if (board_info.fab == BOARD_FAB_A00) {
855                 kai_audio_pdata.codec_name = "rt5640.4-001c";
856                 kai_audio_pdata.codec_dai_name = "rt5640-aif1";
857         }
858 }
859
860 static void __init tegra_kai_init(void)
861 {
862         tegra_thermal_init(&thermal_data,
863                                 throttle_list,
864                                 ARRAY_SIZE(throttle_list));
865         tegra_clk_init_from_table(kai_clk_init_table);
866         tegra_enable_pinmux();
867         kai_pinmux_init();
868         kai_i2c_init();
869         kai_spi_init();
870         kai_usb_init();
871 #ifdef CONFIG_TEGRA_EDP_LIMITS
872         kai_edp_init();
873 #endif
874         kai_uart_init();
875         kai_audio_init();
876         platform_add_devices(kai_devices, ARRAY_SIZE(kai_devices));
877         tegra_ram_console_debug_init();
878         tegra_io_dpd_init();
879         kai_sdhci_init();
880         kai_regulator_init();
881         kai_suspend_init();
882         kai_touch_init();
883         kai_keys_init();
884         kai_panel_init();
885         kai_tegra_setup_tibluesleep();
886         kai_bt_st();
887         kai_sensors_init();
888         kai_pins_state_init();
889         kai_emc_init();
890         tegra_release_bootloader_fb();
891         kai_modem_init();
892 #ifdef CONFIG_TEGRA_WDT_RECOVERY
893         tegra_wdt_recovery_init();
894 #endif
895         tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
896 }
897
898 static void __init kai_ramconsole_reserve(unsigned long size)
899 {
900         tegra_ram_console_debug_reserve(SZ_1M);
901 }
902
903 static void __init tegra_kai_reserve(void)
904 {
905 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
906         /* support 1920X1200 with 24bpp */
907         tegra_reserve(0, SZ_8M + SZ_1M, SZ_8M + SZ_1M);
908 #else
909         tegra_reserve(SZ_128M, SZ_8M, SZ_8M);
910 #endif
911         kai_ramconsole_reserve(SZ_1M);
912 }
913
914 MACHINE_START(KAI, "kai")
915         .atag_offset    = 0x100,
916         .soc            = &tegra_soc_desc,
917         .map_io         = tegra_map_common_io,
918         .reserve        = tegra_kai_reserve,
919         .init_early     = tegra30_init_early,
920         .init_irq       = tegra_init_irq,
921         .handle_irq     = gic_handle_irq,
922         .timer          = &tegra_timer,
923         .init_machine   = tegra_kai_init,
924         .restart        = tegra_assert_system_reset,
925 MACHINE_END