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