arm: tegra: whistler: enable tegra-aes driver
[linux-2.6.git] / arch / arm / mach-tegra / board-whistler.c
1 /*
2  * arch/arm/mach-tegra/board-whistler.c
3  *
4  * Copyright (c) 2010 - 2011, NVIDIA Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/ctype.h>
25 #include <linux/platform_device.h>
26 #include <linux/clk.h>
27 #include <linux/serial_8250.h>
28 #include <linux/i2c.h>
29 #include <linux/synaptics_i2c_rmi.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/delay.h>
32 #include <linux/i2c-tegra.h>
33 #include <linux/gpio.h>
34 #include <linux/gpio_scrollwheel.h>
35 #include <linux/input.h>
36 #include <linux/platform_data/tegra_usb.h>
37 #include <linux/mfd/max8907c.h>
38 #include <linux/memblock.h>
39 #include <linux/tegra_uart.h>
40
41 #include <mach/clk.h>
42 #include <mach/iomap.h>
43 #include <mach/irqs.h>
44 #include <mach/pinmux.h>
45 #include <mach/iomap.h>
46 #include <mach/io.h>
47 #include <mach/i2s.h>
48 #include <mach/tegra_wm8753_pdata.h>
49 #include <sound/tlv320aic326x.h>
50
51 #include <asm/mach-types.h>
52 #include <asm/mach/arch.h>
53 #include <mach/usb_phy.h>
54
55 #include "board.h"
56 #include "clock.h"
57 #include "board-whistler.h"
58 #include "devices.h"
59 #include "gpio-names.h"
60 #include "fuse.h"
61 #include "pm.h"
62 #include "board-whistler-baseband.h"
63
64 #define USB1_VBUS_GPIO TCA6416_GPIO_BASE
65
66 static struct plat_serial8250_port debug_uartb_platform_data[] = {
67         {
68                 .membase        = IO_ADDRESS(TEGRA_UARTB_BASE),
69                 .mapbase        = TEGRA_UARTB_BASE,
70                 .irq            = INT_UARTB,
71                 .flags          = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
72                 .type           = PORT_TEGRA,
73                 .iotype         = UPIO_MEM,
74                 .regshift       = 2,
75                 .uartclk        = 216000000,
76         }, {
77                 .flags          = 0,
78         }
79 };
80
81 static struct platform_device debug_uartb = {
82         .name = "serial8250",
83         .id = PLAT8250_DEV_PLATFORM,
84         .dev = {
85                 .platform_data = debug_uartb_platform_data,
86         },
87 };
88
89 static struct plat_serial8250_port debug_uarta_platform_data[] = {
90         {
91                 .membase        = IO_ADDRESS(TEGRA_UARTA_BASE),
92                 .mapbase        = TEGRA_UARTA_BASE,
93                 .irq            = INT_UARTA,
94                 .flags          = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
95                 .type           = PORT_TEGRA,
96                 .iotype         = UPIO_MEM,
97                 .regshift       = 2,
98                 .uartclk        = 216000000,
99         }, {
100                 .flags          = 0,
101         }
102 };
103
104 static struct platform_device debug_uarta = {
105         .name = "serial8250",
106         .id = PLAT8250_DEV_PLATFORM,
107         .dev = {
108                 .platform_data = debug_uarta_platform_data,
109         },
110 };
111
112 static struct platform_device *whistler_uart_devices[] __initdata = {
113         &tegra_uarta_device,
114         &tegra_uartb_device,
115         &tegra_uartc_device,
116 };
117
118 struct uart_clk_parent uart_parent_clk[] = {
119         [0] = {.name = "pll_p"},
120         [1] = {.name = "pll_m"},
121         [2] = {.name = "clk_m"},
122 };
123
124 static struct tegra_uart_platform_data whistler_uart_pdata;
125
126 static void __init uart_debug_init(void)
127 {
128         unsigned long rate;
129         struct clk *debug_uart_clk;
130         struct clk *c;
131         int modem_id = tegra_get_modem_id();
132
133         if (modem_id == 0x1) {
134                 /* UARTB is the debug port. */
135                 pr_info("Selecting UARTB as the debug console\n");
136                 whistler_uart_devices[1] = &debug_uartb;
137                 debug_uart_clk = clk_get_sys("serial8250.0", "uartb");
138
139                 /* Clock enable for the debug channel */
140                 if (!IS_ERR_OR_NULL(debug_uart_clk)) {
141                         rate = debug_uartb_platform_data[0].uartclk;
142                         pr_info("The debug console clock name is %s\n",
143                                                 debug_uart_clk->name);
144                         c = tegra_get_clock_by_name("pll_p");
145                         if (IS_ERR_OR_NULL(c))
146                                 pr_err("Not getting the parent clock pll_p\n");
147                         else
148                                 clk_set_parent(debug_uart_clk, c);
149
150                         clk_enable(debug_uart_clk);
151                         clk_set_rate(debug_uart_clk, rate);
152                 } else {
153                         pr_err("Not getting the clock %s for debug console\n",
154                                                 debug_uart_clk->name);
155                 }
156         } else {
157                 /* UARTA is the debug port. */
158                 pr_info("Selecting UARTA as the debug console\n");
159                 whistler_uart_devices[0] = &debug_uarta;
160                 debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
161
162                 /* Clock enable for the debug channel */
163                 if (!IS_ERR_OR_NULL(debug_uart_clk)) {
164                         rate = debug_uarta_platform_data[0].uartclk;
165                         pr_info("The debug console clock name is %s\n",
166                                                 debug_uart_clk->name);
167                         c = tegra_get_clock_by_name("pll_p");
168                         if (IS_ERR_OR_NULL(c))
169                                 pr_err("Not getting the parent clock pll_p\n");
170                         else
171                                 clk_set_parent(debug_uart_clk, c);
172
173                         clk_enable(debug_uart_clk);
174                         clk_set_rate(debug_uart_clk, rate);
175                 } else {
176                         pr_err("Not getting the clock %s for debug console\n",
177                                                 debug_uart_clk->name);
178                 }
179         }
180 }
181
182 static void __init whistler_uart_init(void)
183 {
184         int i;
185         struct clk *c;
186
187         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
188                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
189                 if (IS_ERR_OR_NULL(c)) {
190                         pr_err("Not able to get the clock for %s\n",
191                                                 uart_parent_clk[i].name);
192                         continue;
193                 }
194                 uart_parent_clk[i].parent_clk = c;
195                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
196         }
197         whistler_uart_pdata.parent_clk_list = uart_parent_clk;
198         whistler_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
199
200         tegra_uarta_device.dev.platform_data = &whistler_uart_pdata;
201         tegra_uartb_device.dev.platform_data = &whistler_uart_pdata;
202         tegra_uartc_device.dev.platform_data = &whistler_uart_pdata;
203
204         if (!is_tegra_debug_uartport_hs())
205                 uart_debug_init();
206
207         platform_add_devices(whistler_uart_devices,
208                                 ARRAY_SIZE(whistler_uart_devices));
209 }
210
211 static struct resource whistler_bcm4329_rfkill_resources[] = {
212         {
213                 .name   = "bcm4329_nshutdown_gpio",
214                 .start  = TEGRA_GPIO_PU0,
215                 .end    = TEGRA_GPIO_PU0,
216                 .flags  = IORESOURCE_IO,
217         },
218 };
219
220 static struct platform_device whistler_bcm4329_rfkill_device = {
221         .name           = "bcm4329_rfkill",
222         .id             = -1,
223         .num_resources  = ARRAY_SIZE(whistler_bcm4329_rfkill_resources),
224         .resource       = whistler_bcm4329_rfkill_resources,
225 };
226
227 static struct resource whistler_bluesleep_resources[] = {
228         [0] = {
229                 .name = "gpio_host_wake",
230                         .start  = TEGRA_GPIO_PU6,
231                         .end    = TEGRA_GPIO_PU6,
232                         .flags  = IORESOURCE_IO,
233         },
234         [1] = {
235                 .name = "gpio_ext_wake",
236                         .start  = TEGRA_GPIO_PU1,
237                         .end    = TEGRA_GPIO_PU1,
238                         .flags  = IORESOURCE_IO,
239         },
240         [2] = {
241                 .name = "host_wake",
242                         .start  = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PU6),
243                         .end    = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PU6),
244                         .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
245         },
246 };
247
248 static struct platform_device whistler_bluesleep_device = {
249         .name           = "bluesleep",
250         .id             = -1,
251         .num_resources  = ARRAY_SIZE(whistler_bluesleep_resources),
252         .resource       = whistler_bluesleep_resources,
253 };
254
255 static void __init whistler_setup_bluesleep(void)
256 {
257         platform_device_register(&whistler_bluesleep_device);
258         tegra_gpio_enable(TEGRA_GPIO_PU6);
259         tegra_gpio_enable(TEGRA_GPIO_PU1);
260         return;
261 }
262
263 static struct tegra_utmip_config utmi_phy_config[] = {
264         [0] = {
265                         .hssync_start_delay = 9,
266                         .idle_wait_delay = 17,
267                         .elastic_limit = 16,
268                         .term_range_adj = 6,
269                         .xcvr_setup = 15,
270                         .xcvr_lsfslew = 2,
271                         .xcvr_lsrslew = 2,
272                 },
273         [1] = {
274                         .hssync_start_delay = 9,
275                         .idle_wait_delay = 17,
276                         .elastic_limit = 16,
277                         .term_range_adj = 6,
278                         .xcvr_setup = 8,
279                         .xcvr_lsfslew = 2,
280                         .xcvr_lsrslew = 2,
281                 },
282 };
283
284 static struct tegra_ulpi_config ulpi_phy_config = {
285         .reset_gpio = TEGRA_GPIO_PG2,
286         .clk = "cdev2",
287 };
288
289 static __initdata struct tegra_clk_init_table whistler_clk_init_table[] = {
290         /* name         parent          rate            enabled */
291         { "pwm",        "clk_32k",      32768,          false},
292         { "kbc",        "clk_32k",      32768,          true},
293         { "sdmmc2",     "pll_p",        25000000,       false},
294         { "i2s1",       "pll_a_out0",   0,              false},
295         { "i2s2",       "pll_a_out0",   0,              false},
296         { "spdif_out",  "pll_a_out0",   0,              false},
297         { NULL,         NULL,           0,              0},
298 };
299
300 static struct tegra_i2c_platform_data whistler_i2c1_platform_data = {
301         .adapter_nr     = 0,
302         .bus_count      = 1,
303         .bus_clk_rate   = { 400000, 0 },
304         .scl_gpio               = {TEGRA_GPIO_PC4, 0},
305         .sda_gpio               = {TEGRA_GPIO_PC5, 0},
306         .arb_recovery = arb_lost_recovery,
307 };
308
309 static const struct tegra_pingroup_config i2c2_ddc = {
310         .pingroup       = TEGRA_PINGROUP_DDC,
311         .func           = TEGRA_MUX_I2C2,
312 };
313
314 static const struct tegra_pingroup_config i2c2_gen2 = {
315         .pingroup       = TEGRA_PINGROUP_PTA,
316         .func           = TEGRA_MUX_I2C2,
317 };
318
319 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
320         .adapter_nr     = 1,
321         .bus_count      = 2,
322         .bus_clk_rate   = { 100000, 100000 },
323         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
324         .bus_mux_len    = { 1, 1 },
325         .scl_gpio               = {0, TEGRA_GPIO_PT5},
326         .sda_gpio               = {0, TEGRA_GPIO_PT6},
327         .arb_recovery = arb_lost_recovery,
328 };
329
330 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
331         .adapter_nr     = 3,
332         .bus_count      = 1,
333         .bus_clk_rate   = { 400000, 0 },
334         .scl_gpio               = {TEGRA_GPIO_PBB2, 0},
335         .sda_gpio               = {TEGRA_GPIO_PBB3, 0},
336         .arb_recovery = arb_lost_recovery,
337 };
338
339 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
340         .adapter_nr     = 4,
341         .bus_count      = 1,
342         .bus_clk_rate   = { 400000, 0 },
343         .is_dvc         = true,
344         .scl_gpio               = {TEGRA_GPIO_PZ6, 0},
345         .sda_gpio               = {TEGRA_GPIO_PZ7, 0},
346         .arb_recovery = arb_lost_recovery,
347 };
348
349 static struct aic326x_pdata whistler_aic3262_pdata = {
350         /* debounce time */
351         .debounce_time_ms = 512,
352 };
353
354 static struct i2c_board_info __initdata wm8753_board_info[] = {
355         {
356                 I2C_BOARD_INFO("wm8753", 0x1a),
357                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_HP_DET),
358         },
359         {
360                 I2C_BOARD_INFO("tlv320aic3262", 0x18),
361                 .platform_data = &whistler_aic3262_pdata,
362                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_HP_DET),
363         },
364 };
365
366 static void whistler_i2c_init(void)
367 {
368         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
369         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
370         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
371         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
372
373         platform_device_register(&tegra_i2c_device4);
374         platform_device_register(&tegra_i2c_device3);
375         platform_device_register(&tegra_i2c_device2);
376         platform_device_register(&tegra_i2c_device1);
377
378         i2c_register_board_info(4, wm8753_board_info,
379                 ARRAY_SIZE(wm8753_board_info));
380 }
381
382 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
383 {       \
384         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
385         .gpio = TEGRA_GPIO_##_gpio,     \
386         .desc = _desc,  \
387         .active_low = 1,        \
388         .debounce_interval = 2, \
389 }
390
391 static struct gpio_scrollwheel_button scroll_keys[] = {
392         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
393         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
394         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
395         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
396 };
397
398 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
399         .buttons = scroll_keys,
400         .nbuttons = ARRAY_SIZE(scroll_keys),
401 };
402
403 static struct platform_device whistler_scroll_device = {
404         .name   = "alps-gpio-scrollwheel",
405         .id     = 0,
406         .dev    = {
407                 .platform_data  = &whistler_scroll_platform_data,
408         },
409 };
410
411 static struct platform_device tegra_camera = {
412         .name = "tegra_camera",
413         .id = -1,
414 };
415
416 static struct tegra_wm8753_platform_data whistler_audio_pdata = {
417         .gpio_spkr_en = -1,
418         .gpio_hp_det = TEGRA_GPIO_HP_DET,
419         .gpio_hp_mute = -1,
420         .gpio_int_mic_en = -1,
421         .gpio_ext_mic_en = -1,
422         .debounce_time_hp = 200,
423 };
424
425 static struct platform_device whistler_audio_device1 = {
426         .name   = "tegra-snd-aic326x",
427         .id     = 0,
428         .dev    = {
429                 .platform_data  = &whistler_audio_pdata,
430         },
431 };
432
433 static struct platform_device whistler_audio_device2 = {
434         .name   = "tegra-snd-wm8753",
435         .id     = 0,
436         .dev    = {
437                 .platform_data  = &whistler_audio_pdata,
438         },
439 };
440
441 static struct platform_device *whistler_devices[] __initdata = {
442         &tegra_pmu_device,
443         &tegra_udc_device,
444         &tegra_gart_device,
445         &tegra_aes_device,
446         &tegra_wdt_device,
447         &tegra_avp_device,
448         &whistler_scroll_device,
449         &tegra_camera,
450         &tegra_i2s_device1,
451         &tegra_i2s_device2,
452         &tegra_spdif_device,
453         &tegra_das_device,
454         &spdif_dit_device,
455         &bluetooth_dit_device,
456         &baseband_dit_device,
457         &whistler_bcm4329_rfkill_device,
458         &tegra_pcm_device,
459         &whistler_audio_device1,
460         &whistler_audio_device2,
461 };
462
463 static struct synaptics_i2c_rmi_platform_data synaptics_pdata = {
464         .flags          = SYNAPTICS_FLIP_X | SYNAPTICS_FLIP_Y | SYNAPTICS_SWAP_XY,
465         .irqflags       = IRQF_TRIGGER_LOW,
466 };
467
468 static const struct i2c_board_info whistler_i2c_touch_info[] = {
469         {
470                 I2C_BOARD_INFO("synaptics-rmi-ts", 0x20),
471                 .irq            = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PC6),
472                 .platform_data  = &synaptics_pdata,
473         },
474 };
475
476 static int __init whistler_touch_init(void)
477 {
478         tegra_gpio_enable(TEGRA_GPIO_PC6);
479         i2c_register_board_info(0, whistler_i2c_touch_info, 1);
480
481         return 0;
482 }
483
484 static int __init whistler_scroll_init(void)
485 {
486         int i;
487         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
488                 tegra_gpio_enable(scroll_keys[i].gpio);
489
490         return 0;
491 }
492
493 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
494         [0] = {
495                         .instance = 0,
496                         .vbus_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
497                         .vbus_gpio = USB1_VBUS_GPIO,
498         },
499         [1] = {
500                         .instance = 1,
501                         .vbus_gpio = -1,
502         },
503         [2] = {
504                         .instance = 2,
505                         .vbus_gpio = -1,
506         },
507 };
508
509 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
510         [0] = {
511                         .phy_config = &utmi_phy_config[0],
512                         .operating_mode = TEGRA_USB_HOST,
513                         .power_down_on_bus_suspend = 1,
514                 },
515         [1] = {
516                         .phy_config = &ulpi_phy_config,
517                         .operating_mode = TEGRA_USB_HOST,
518                         .power_down_on_bus_suspend = 1,
519                 },
520         [2] = {
521                         .phy_config = &utmi_phy_config[1],
522                         .operating_mode = TEGRA_USB_HOST,
523                         .power_down_on_bus_suspend = 1,
524         },
525 };
526
527 static struct tegra_otg_platform_data tegra_otg_pdata = {
528         .ehci_device = &tegra_ehci1_device,
529         .ehci_pdata = &tegra_ehci_pdata[0],
530 };
531
532 static int __init whistler_gps_init(void)
533 {
534         tegra_gpio_enable(TEGRA_GPIO_PU4);
535         return 0;
536 }
537
538 static void whistler_power_off(void)
539 {
540         int ret;
541
542         ret = max8907c_power_off();
543         if (ret)
544                 pr_err("whistler: failed to power off\n");
545
546         while (1);
547 }
548
549 static void __init whistler_power_off_init(void)
550 {
551         pm_power_off = whistler_power_off;
552 }
553
554 static void whistler_usb_init(void)
555 {
556         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
557
558         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
559         platform_device_register(&tegra_otg_device);
560
561         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
562         platform_device_register(&tegra_ehci3_device);
563 }
564
565 static void __init tegra_whistler_init(void)
566 {
567         int modem_id = tegra_get_modem_id();
568         tegra_clk_init_from_table(whistler_clk_init_table);
569         whistler_pinmux_init();
570         whistler_i2c_init();
571         whistler_uart_init();
572         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
573
574         whistler_sdhci_init();
575         whistler_regulator_init();
576         whistler_panel_init();
577         whistler_sensors_init();
578         whistler_touch_init();
579         whistler_kbc_init();
580         whistler_gps_init();
581         whistler_usb_init();
582         whistler_scroll_init();
583         whistler_power_off_init();
584         whistler_emc_init();
585         if (modem_id == 0x1)
586                 whistler_baseband_init();
587         whistler_setup_bluesleep();
588         tegra_release_bootloader_fb();
589 }
590
591 int __init tegra_whistler_protected_aperture_init(void)
592 {
593         tegra_protected_aperture_init(tegra_grhost_aperture);
594         return 0;
595 }
596
597 void __init tegra_whistler_reserve(void)
598 {
599         if (memblock_reserve(0x0, 4096) < 0)
600                 pr_warn("Cannot reserve first 4K of memory for safety\n");
601
602         tegra_reserve(SZ_160M, SZ_8M, SZ_16M);
603 }
604
605 MACHINE_START(WHISTLER, "whistler")
606         .boot_params    = 0x00000100,
607         .map_io         = tegra_map_common_io,
608         .reserve        = tegra_whistler_reserve,
609         .init_early     = tegra_init_early,
610         .init_irq       = tegra_init_irq,
611         .timer          = &tegra_timer,
612         .init_machine   = tegra_whistler_init,
613 MACHINE_END