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