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