ARM: tegra: whistler: remove baseband init when there is no modem
[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 = "clk_dev2",
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 };
305
306 static const struct tegra_pingroup_config i2c2_ddc = {
307         .pingroup       = TEGRA_PINGROUP_DDC,
308         .func           = TEGRA_MUX_I2C2,
309 };
310
311 static const struct tegra_pingroup_config i2c2_gen2 = {
312         .pingroup       = TEGRA_PINGROUP_PTA,
313         .func           = TEGRA_MUX_I2C2,
314 };
315
316 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
317         .adapter_nr     = 1,
318         .bus_count      = 2,
319         .bus_clk_rate   = { 100000, 100000 },
320         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
321         .bus_mux_len    = { 1, 1 },
322 };
323
324 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
325         .adapter_nr     = 3,
326         .bus_count      = 1,
327         .bus_clk_rate   = { 400000, 0 },
328 };
329
330 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
331         .adapter_nr     = 4,
332         .bus_count      = 1,
333         .bus_clk_rate   = { 400000, 0 },
334         .is_dvc         = true,
335 };
336
337 static struct aic326x_pdata whistler_aic3262_pdata = {
338         /* debounce time */
339         .debounce_time_ms = 512,
340 };
341
342 static struct i2c_board_info __initdata wm8753_board_info[] = {
343         {
344                 I2C_BOARD_INFO("wm8753", 0x1a),
345                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_HP_DET),
346         },
347         {
348                 I2C_BOARD_INFO("tlv320aic3262", 0x18),
349                 .platform_data = &whistler_aic3262_pdata,
350                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_HP_DET),
351         },
352 };
353
354 static void whistler_i2c_init(void)
355 {
356         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
357         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
358         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
359         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
360
361         platform_device_register(&tegra_i2c_device4);
362         platform_device_register(&tegra_i2c_device3);
363         platform_device_register(&tegra_i2c_device2);
364         platform_device_register(&tegra_i2c_device1);
365
366         i2c_register_board_info(4, wm8753_board_info,
367                 ARRAY_SIZE(wm8753_board_info));
368 }
369
370 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
371 {       \
372         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
373         .gpio = TEGRA_GPIO_##_gpio,     \
374         .desc = _desc,  \
375         .active_low = 1,        \
376         .debounce_interval = 2, \
377 }
378
379 static struct gpio_scrollwheel_button scroll_keys[] = {
380         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
381         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
382         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
383         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
384 };
385
386 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
387         .buttons = scroll_keys,
388         .nbuttons = ARRAY_SIZE(scroll_keys),
389 };
390
391 static struct platform_device whistler_scroll_device = {
392         .name   = "alps-gpio-scrollwheel",
393         .id     = 0,
394         .dev    = {
395                 .platform_data  = &whistler_scroll_platform_data,
396         },
397 };
398
399 static struct platform_device tegra_camera = {
400         .name = "tegra_camera",
401         .id = -1,
402 };
403
404 static struct tegra_wm8753_platform_data whistler_audio_pdata = {
405         .gpio_spkr_en = -1,
406         .gpio_hp_det = TEGRA_GPIO_HP_DET,
407         .gpio_hp_mute = -1,
408         .gpio_int_mic_en = -1,
409         .gpio_ext_mic_en = -1,
410         .debounce_time_hp = 200,
411 };
412
413 static struct platform_device whistler_audio_device1 = {
414         .name   = "tegra-snd-aic326x",
415         .id     = 0,
416         .dev    = {
417                 .platform_data  = &whistler_audio_pdata,
418         },
419 };
420
421 static struct platform_device whistler_audio_device2 = {
422         .name   = "tegra-snd-wm8753",
423         .id     = 0,
424         .dev    = {
425                 .platform_data  = &whistler_audio_pdata,
426         },
427 };
428
429 static struct platform_device *whistler_devices[] __initdata = {
430         &tegra_pmu_device,
431         &tegra_udc_device,
432         &tegra_gart_device,
433         &tegra_wdt_device,
434         &tegra_avp_device,
435         &whistler_scroll_device,
436         &tegra_camera,
437         &tegra_i2s_device1,
438         &tegra_i2s_device2,
439         &tegra_spdif_device,
440         &tegra_das_device,
441         &spdif_dit_device,
442         &bluetooth_dit_device,
443         &baseband_dit_device,
444         &whistler_bcm4329_rfkill_device,
445         &tegra_pcm_device,
446         &whistler_audio_device1,
447         &whistler_audio_device2,
448 };
449
450 static struct synaptics_i2c_rmi_platform_data synaptics_pdata = {
451         .flags          = SYNAPTICS_FLIP_X | SYNAPTICS_FLIP_Y | SYNAPTICS_SWAP_XY,
452         .irqflags       = IRQF_TRIGGER_LOW,
453 };
454
455 static const struct i2c_board_info whistler_i2c_touch_info[] = {
456         {
457                 I2C_BOARD_INFO("synaptics-rmi-ts", 0x20),
458                 .irq            = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PC6),
459                 .platform_data  = &synaptics_pdata,
460         },
461 };
462
463 static int __init whistler_touch_init(void)
464 {
465         tegra_gpio_enable(TEGRA_GPIO_PC6);
466         i2c_register_board_info(0, whistler_i2c_touch_info, 1);
467
468         return 0;
469 }
470
471 static int __init whistler_scroll_init(void)
472 {
473         int i;
474         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
475                 tegra_gpio_enable(scroll_keys[i].gpio);
476
477         return 0;
478 }
479
480 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
481         [0] = {
482                         .instance = 0,
483                         .vbus_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
484                         .vbus_gpio = USB1_VBUS_GPIO,
485         },
486         [1] = {
487                         .instance = 1,
488                         .vbus_gpio = -1,
489         },
490         [2] = {
491                         .instance = 2,
492                         .vbus_gpio = -1,
493         },
494 };
495
496 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
497         [0] = {
498                         .phy_config = &utmi_phy_config[0],
499                         .operating_mode = TEGRA_USB_HOST,
500                         .power_down_on_bus_suspend = 1,
501                 },
502         [1] = {
503                         .phy_config = &ulpi_phy_config,
504                         .operating_mode = TEGRA_USB_HOST,
505                         .power_down_on_bus_suspend = 1,
506                 },
507         [2] = {
508                         .phy_config = &utmi_phy_config[1],
509                         .operating_mode = TEGRA_USB_HOST,
510                         .power_down_on_bus_suspend = 1,
511         },
512 };
513
514 static struct tegra_otg_platform_data tegra_otg_pdata = {
515         .ehci_device = &tegra_ehci1_device,
516         .ehci_pdata = &tegra_ehci_pdata[0],
517 };
518
519 static int __init whistler_gps_init(void)
520 {
521         tegra_gpio_enable(TEGRA_GPIO_PU4);
522         return 0;
523 }
524
525 static void whistler_power_off(void)
526 {
527         int ret;
528
529         ret = max8907c_power_off();
530         if (ret)
531                 pr_err("whistler: failed to power off\n");
532
533         while (1);
534 }
535
536 static void __init whistler_power_off_init(void)
537 {
538         pm_power_off = whistler_power_off;
539 }
540
541 static void whistler_usb_init(void)
542 {
543         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
544
545         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
546         platform_device_register(&tegra_otg_device);
547
548         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
549         platform_device_register(&tegra_ehci3_device);
550 }
551
552 static void __init tegra_whistler_init(void)
553 {
554         int modem_id = tegra_get_modem_id();
555         tegra_clk_init_from_table(whistler_clk_init_table);
556         whistler_pinmux_init();
557         whistler_i2c_init();
558         whistler_uart_init();
559         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
560
561         whistler_sdhci_init();
562         whistler_regulator_init();
563         whistler_panel_init();
564         whistler_sensors_init();
565         whistler_touch_init();
566         whistler_kbc_init();
567         whistler_gps_init();
568         whistler_usb_init();
569         whistler_scroll_init();
570         whistler_power_off_init();
571         whistler_emc_init();
572         if (modem_id == 0x1)
573                 whistler_baseband_init();
574         whistler_setup_bluesleep();
575         tegra_release_bootloader_fb();
576 }
577
578 int __init tegra_whistler_protected_aperture_init(void)
579 {
580         tegra_protected_aperture_init(tegra_grhost_aperture);
581         return 0;
582 }
583
584 void __init tegra_whistler_reserve(void)
585 {
586         if (memblock_reserve(0x0, 4096) < 0)
587                 pr_warn("Cannot reserve first 4K of memory for safety\n");
588
589         tegra_reserve(SZ_128M, SZ_8M, SZ_16M);
590 }
591
592 MACHINE_START(WHISTLER, "whistler")
593         .boot_params    = 0x00000100,
594         .map_io         = tegra_map_common_io,
595         .reserve        = tegra_whistler_reserve,
596         .init_early     = tegra_init_early,
597         .init_irq       = tegra_init_irq,
598         .timer          = &tegra_timer,
599         .init_machine   = tegra_whistler_init,
600 MACHINE_END