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