arm: tegra: ventana/whistler: Enable i2s2 and BT device
[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/i2c/panjit_ts.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
50 #include <asm/mach-types.h>
51 #include <asm/mach/arch.h>
52 #include <mach/usb_phy.h>
53
54 #include "board.h"
55 #include "clock.h"
56 #include "board-whistler.h"
57 #include "devices.h"
58 #include "gpio-names.h"
59 #include "fuse.h"
60 #include "pm.h"
61 #include "board-whistler-baseband.h"
62
63 static struct plat_serial8250_port debug_uart_platform_data[] = {
64         {
65                 .membase        = IO_ADDRESS(TEGRA_UARTA_BASE),
66                 .mapbase        = TEGRA_UARTA_BASE,
67                 .irq            = INT_UARTA,
68                 .flags          = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
69                 .type           = PORT_TEGRA,
70                 .iotype         = UPIO_MEM,
71                 .regshift       = 2,
72                 .uartclk        = 216000000,
73         }, {
74                 .flags          = 0,
75         }
76 };
77
78 static struct platform_device debug_uart = {
79         .name = "serial8250",
80         .id = PLAT8250_DEV_PLATFORM,
81         .dev = {
82                 .platform_data = debug_uart_platform_data,
83         },
84 };
85 static struct platform_device *whistler_uart_devices[] __initdata = {
86         &tegra_uarta_device,
87         &tegra_uartb_device,
88         &tegra_uartc_device,
89 };
90
91 struct uart_clk_parent uart_parent_clk[] = {
92         [0] = {.name = "pll_p"},
93         [1] = {.name = "pll_m"},
94         [2] = {.name = "clk_m"},
95 };
96
97 static struct tegra_uart_platform_data whistler_uart_pdata;
98
99 static void __init uart_debug_init(void)
100 {
101         unsigned long rate;
102         struct clk *debug_uart_clk;
103         struct clk *c;
104
105         /* UARTA is the debug port. */
106         pr_info("Selecting UARTA as the debug console\n");
107         whistler_uart_devices[0] = &debug_uart;
108         debug_uart_port_base = ((struct plat_serial8250_port *)(
109                                 debug_uarta_device.dev.platform_data))->mapbase;
110         debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
111
112         /* Clock enable for the debug channel */
113         if (!IS_ERR_OR_NULL(debug_uart_clk)) {
114                 rate = debug_uart_platform_data[0].uartclk;
115                 pr_info("The debug console clock name is %s\n",
116                                                 debug_uart_clk->name);
117                 c = tegra_get_clock_by_name("pll_p");
118                 if (IS_ERR_OR_NULL(c))
119                         pr_err("Not getting the parent clock pll_p\n");
120                 else
121                         clk_set_parent(debug_uart_clk, c);
122
123                 clk_enable(debug_uart_clk);
124                 clk_set_rate(debug_uart_clk, rate);
125         } else {
126                 pr_err("Not getting the clock %s for debug console\n",
127                                         debug_uart_clk->name);
128         }
129 }
130
131 static void __init whistler_uart_init(void)
132 {
133         int i;
134         struct clk *c;
135
136         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
137                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
138                 if (IS_ERR_OR_NULL(c)) {
139                         pr_err("Not able to get the clock for %s\n",
140                                                 uart_parent_clk[i].name);
141                         continue;
142                 }
143                 uart_parent_clk[i].parent_clk = c;
144                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
145         }
146         whistler_uart_pdata.parent_clk_list = uart_parent_clk;
147         whistler_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
148
149         tegra_uarta_device.dev.platform_data = &whistler_uart_pdata;
150         tegra_uartb_device.dev.platform_data = &whistler_uart_pdata;
151         tegra_uartc_device.dev.platform_data = &whistler_uart_pdata;
152
153         /* Register low speed only if it is selected */
154         if (!is_tegra_debug_uartport_hs())
155                 uart_debug_init();
156
157         platform_add_devices(whistler_uart_devices,
158                                 ARRAY_SIZE(whistler_uart_devices));
159 }
160
161 #ifdef CONFIG_BCM4329_RFKILL
162
163 static struct resource whistler_bcm4329_rfkill_resources[] = {
164         {
165                 .name   = "bcm4329_nshutdown_gpio",
166                 .start  = TEGRA_GPIO_PU0,
167                 .end    = TEGRA_GPIO_PU0,
168                 .flags  = IORESOURCE_IO,
169         },
170 };
171
172 static struct platform_device whistler_bcm4329_rfkill_device = {
173         .name           = "bcm4329_rfkill",
174         .id             = -1,
175         .num_resources  = ARRAY_SIZE(whistler_bcm4329_rfkill_resources),
176         .resource       = whistler_bcm4329_rfkill_resources,
177 };
178
179 static noinline void __init whistler_bt_rfkill(void)
180 {
181         platform_device_register(&whistler_bcm4329_rfkill_device);
182         return;
183 }
184 #else
185 static inline void whistler_bt_rfkill(void) { }
186 #endif
187
188 static struct tegra_utmip_config utmi_phy_config[] = {
189         [0] = {
190                         .hssync_start_delay = 9,
191                         .idle_wait_delay = 17,
192                         .elastic_limit = 16,
193                         .term_range_adj = 6,
194                         .xcvr_setup = 15,
195                         .xcvr_lsfslew = 2,
196                         .xcvr_lsrslew = 2,
197                 },
198         [1] = {
199                         .hssync_start_delay = 9,
200                         .idle_wait_delay = 17,
201                         .elastic_limit = 16,
202                         .term_range_adj = 6,
203                         .xcvr_setup = 8,
204                         .xcvr_lsfslew = 2,
205                         .xcvr_lsrslew = 2,
206                 },
207 };
208
209 static struct tegra_ulpi_config ulpi_phy_config = {
210         .reset_gpio = TEGRA_GPIO_PG2,
211         .clk = "clk_dev2",
212 };
213
214 static __initdata struct tegra_clk_init_table whistler_clk_init_table[] = {
215         /* name         parent          rate            enabled */
216         { "pwm",        "clk_32k",      32768,          false},
217         { "kbc",        "clk_32k",      32768,          true},
218         { "sdmmc2",     "pll_p",        25000000,       false},
219         { "i2s1",       "pll_a_out0",   0,              false},
220         { "i2s2",       "pll_a_out0",   0,              false},
221         { "spdif_out",  "pll_a_out0",   0,              false},
222         { NULL,         NULL,           0,              0},
223 };
224
225 static struct tegra_i2c_platform_data whistler_i2c1_platform_data = {
226         .adapter_nr     = 0,
227         .bus_count      = 1,
228         .bus_clk_rate   = { 400000, 0 },
229 };
230
231 static const struct tegra_pingroup_config i2c2_ddc = {
232         .pingroup       = TEGRA_PINGROUP_DDC,
233         .func           = TEGRA_MUX_I2C2,
234 };
235
236 static const struct tegra_pingroup_config i2c2_gen2 = {
237         .pingroup       = TEGRA_PINGROUP_PTA,
238         .func           = TEGRA_MUX_I2C2,
239 };
240
241 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
242         .adapter_nr     = 1,
243         .bus_count      = 2,
244         .bus_clk_rate   = { 100000, 100000 },
245         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
246         .bus_mux_len    = { 1, 1 },
247 };
248
249 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
250         .adapter_nr     = 3,
251         .bus_count      = 1,
252         .bus_clk_rate   = { 400000, 0 },
253 };
254
255 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
256         .adapter_nr     = 4,
257         .bus_count      = 1,
258         .bus_clk_rate   = { 400000, 0 },
259         .is_dvc         = true,
260 };
261
262 static struct i2c_board_info __initdata wm8753_board_info = {
263         I2C_BOARD_INFO("wm8753", 0x1a),
264         .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_HP_DET),
265 };
266
267 static void whistler_i2c_init(void)
268 {
269         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
270         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
271         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
272         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
273
274         platform_device_register(&tegra_i2c_device4);
275         platform_device_register(&tegra_i2c_device3);
276         platform_device_register(&tegra_i2c_device2);
277         platform_device_register(&tegra_i2c_device1);
278
279         i2c_register_board_info(4, &wm8753_board_info, 1);
280 }
281
282 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
283 {       \
284         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
285         .gpio = TEGRA_GPIO_##_gpio,     \
286         .desc = _desc,  \
287         .active_low = 1,        \
288         .debounce_interval = 2, \
289 }
290
291 static struct gpio_scrollwheel_button scroll_keys[] = {
292         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
293         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
294         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
295         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
296 };
297
298 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
299         .buttons = scroll_keys,
300         .nbuttons = ARRAY_SIZE(scroll_keys),
301 };
302
303 static struct platform_device whistler_scroll_device = {
304         .name   = "alps-gpio-scrollwheel",
305         .id     = 0,
306         .dev    = {
307                 .platform_data  = &whistler_scroll_platform_data,
308         },
309 };
310
311 static struct platform_device tegra_camera = {
312         .name = "tegra_camera",
313         .id = -1,
314 };
315
316 static struct tegra_wm8753_platform_data whistler_audio_pdata = {
317         .gpio_spkr_en = TEGRA_GPIO_SPKR_EN,
318         .gpio_hp_det = TEGRA_GPIO_HP_DET,
319         .gpio_hp_mute = -1,
320         .gpio_int_mic_en = -1,
321         .gpio_ext_mic_en = -1,
322         .debounce_time_hp = 200,
323 };
324
325 static struct platform_device whistler_audio_device = {
326         .name   = "tegra-snd-wm8753",
327         .id     = 0,
328         .dev    = {
329                 .platform_data  = &whistler_audio_pdata,
330         },
331 };
332
333 static struct platform_device *whistler_devices[] __initdata = {
334         &tegra_pmu_device,
335         &tegra_udc_device,
336         &tegra_gart_device,
337         &tegra_wdt_device,
338         &tegra_avp_device,
339         &whistler_scroll_device,
340         &tegra_camera,
341         &tegra_i2s_device1,
342         &tegra_i2s_device2,
343         &tegra_spdif_device,
344         &tegra_das_device,
345         &spdif_dit_device,
346         &bluetooth_dit_device,
347         &tegra_pcm_device,
348         &whistler_audio_device,
349 };
350
351 static int __init whistler_scroll_init(void)
352 {
353         int i;
354         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
355                 tegra_gpio_enable(scroll_keys[i].gpio);
356
357         return 0;
358 }
359
360 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
361         [0] = {
362                         .instance = 0,
363                         .vbus_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
364                         .vbus_gpio = TEGRA_GPIO_PN6,
365         },
366         [1] = {
367                         .instance = 1,
368                         .vbus_gpio = -1,
369         },
370         [2] = {
371                         .instance = 2,
372                         .vbus_gpio = -1,
373         },
374 };
375
376 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
377         [0] = {
378                         .phy_config = &utmi_phy_config[0],
379                         .operating_mode = TEGRA_USB_HOST,
380                         .power_down_on_bus_suspend = 1,
381                 },
382         [1] = {
383                         .phy_config = &ulpi_phy_config,
384                         .operating_mode = TEGRA_USB_HOST,
385                         .power_down_on_bus_suspend = 1,
386                 },
387         [2] = {
388                         .phy_config = &utmi_phy_config[1],
389                         .operating_mode = TEGRA_USB_HOST,
390                         .power_down_on_bus_suspend = 1,
391         },
392 };
393
394 static struct platform_device *tegra_usb_otg_host_register(void)
395 {
396         struct platform_device *pdev;
397         void *platform_data;
398         int val;
399
400         pdev = platform_device_alloc(tegra_ehci1_device.name,
401                         tegra_ehci1_device.id);
402         if (!pdev)
403                 return NULL;
404
405         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
406                 tegra_ehci1_device.num_resources);
407         if (val)
408                 goto error;
409
410         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
411         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
412
413         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
414                                 GFP_KERNEL);
415         if (!platform_data)
416                 goto error;
417
418         memcpy(platform_data, &tegra_ehci_pdata[0],
419                                 sizeof(struct tegra_ehci_platform_data));
420         pdev->dev.platform_data = platform_data;
421
422         val = platform_device_add(pdev);
423         if (val)
424                 goto error_add;
425
426         return pdev;
427
428 error_add:
429         kfree(platform_data);
430 error:
431         pr_err("%s: failed to add the host contoller device\n", __func__);
432         platform_device_put(pdev);
433         return NULL;
434 }
435
436 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
437 {
438         kfree(pdev->dev.platform_data);
439         platform_device_unregister(pdev);
440 }
441
442 static struct tegra_otg_platform_data tegra_otg_pdata = {
443         .host_register = &tegra_usb_otg_host_register,
444         .host_unregister = &tegra_usb_otg_host_unregister,
445 };
446
447 static int __init whistler_gps_init(void)
448 {
449         tegra_gpio_enable(TEGRA_GPIO_PU4);
450         return 0;
451 }
452
453 static void whistler_power_off(void)
454 {
455         int ret;
456
457         ret = max8907c_power_off();
458         if (ret)
459                 pr_err("whistler: failed to power off\n");
460
461         while (1);
462 }
463
464 static void __init whistler_power_off_init(void)
465 {
466         pm_power_off = whistler_power_off;
467 }
468
469 static void whistler_usb_init(void)
470 {
471         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
472
473         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
474         platform_device_register(&tegra_otg_device);
475
476         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
477         platform_device_register(&tegra_ehci3_device);
478 }
479
480 static void __init tegra_whistler_init(void)
481 {
482         char serial[20];
483
484         tegra_clk_init_from_table(whistler_clk_init_table);
485         whistler_pinmux_init();
486         whistler_i2c_init();
487         whistler_uart_init();
488         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
489
490         whistler_sdhci_init();
491         whistler_regulator_init();
492         whistler_panel_init();
493         whistler_sensors_init();
494         whistler_kbc_init();
495         whistler_bt_rfkill();
496         whistler_gps_init();
497         whistler_usb_init();
498         whistler_scroll_init();
499         whistler_power_off_init();
500         whistler_emc_init();
501         whistler_baseband_init();
502         tegra_release_bootloader_fb();
503 }
504
505 int __init tegra_whistler_protected_aperture_init(void)
506 {
507         tegra_protected_aperture_init(tegra_grhost_aperture);
508         return 0;
509 }
510
511 void __init tegra_whistler_reserve(void)
512 {
513         if (memblock_reserve(0x0, 4096) < 0)
514                 pr_warn("Cannot reserve first 4K of memory for safety\n");
515
516         tegra_reserve(SZ_128M, SZ_8M, SZ_16M);
517 }
518
519 MACHINE_START(WHISTLER, "whistler")
520         .boot_params    = 0x00000100,
521         .map_io         = tegra_map_common_io,
522         .reserve        = tegra_whistler_reserve,
523         .init_early     = tegra_init_early,
524         .init_irq       = tegra_init_irq,
525         .timer          = &tegra_timer,
526         .init_machine   = tegra_whistler_init,
527 MACHINE_END