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