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