arm: tegra: fix audio in hdmi
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu.c
1 /*
2  * arch/arm/mach-tegra/board-cardhu.c
3  *
4  * Copyright (c) 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/input.h>
35 #include <linux/platform_data/tegra_usb.h>
36 #include <mach/clk.h>
37 #include <mach/iomap.h>
38 #include <mach/irqs.h>
39 #include <mach/pinmux.h>
40 #include <mach/iomap.h>
41 #include <mach/io.h>
42 #include <mach/i2s.h>
43 #include <mach/audio.h>
44 #include <asm/mach-types.h>
45 #include <asm/mach/arch.h>
46 #include <mach/usb_phy.h>
47
48 #include "board.h"
49 #include "clock.h"
50 #include "board-cardhu.h"
51 #include "devices.h"
52 #include "gpio-names.h"
53 #include "fuse.h"
54
55 #define ENABLE_USB_HOST 0
56
57 static struct plat_serial8250_port debug_uart_platform_data[] = {
58         {
59                 .membase        = IO_ADDRESS(TEGRA_UARTA_BASE),
60                 .mapbase        = TEGRA_UARTA_BASE,
61                 .irq            = INT_UARTA,
62                 .flags          = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
63                 .type           = PORT_TEGRA,
64                 .iotype         = UPIO_MEM,
65                 .regshift       = 2,
66                 .uartclk        = 216000000,
67         }, {
68                 .flags          = 0,
69         }
70 };
71
72 static struct platform_device debug_uart = {
73         .name = "serial8250",
74         .id = PLAT8250_DEV_PLATFORM,
75         .dev = {
76                 .platform_data = debug_uart_platform_data,
77         },
78 };
79
80 /* !!!TODO: Change for cardhu (Taken from Ventana) */
81 static struct tegra_utmip_config utmi_phy_config[] = {
82         [0] = {
83                         .hssync_start_delay = 0,
84                         .idle_wait_delay = 17,
85                         .elastic_limit = 16,
86                         .term_range_adj = 6,
87                         .xcvr_setup = 15,
88                         .xcvr_lsfslew = 2,
89                         .xcvr_lsrslew = 2,
90         },
91         [1] = {
92                         .hssync_start_delay = 0,
93                         .idle_wait_delay = 17,
94                         .elastic_limit = 16,
95                         .term_range_adj = 6,
96                         .xcvr_setup = 8,
97                         .xcvr_lsfslew = 2,
98                         .xcvr_lsrslew = 2,
99         },
100 };
101
102 /* !!!TODO: Change for cardhu (Taken from Ventana) */
103 static struct tegra_ulpi_config ulpi_phy_config = {
104         /* !!!TODO!!! CABLE DETECT? if so GPIO_PC7 on cardhu */
105         .reset_gpio = TEGRA_GPIO_PG2,
106         .clk = "clk_dev2",
107 };
108
109 #ifdef CONFIG_BCM4329_RFKILL
110 static struct resource cardhu_bcm4329_rfkill_resources[] = {
111         {
112                 .name   = "bcm4329_nshutdown_gpio",
113                 .start  = TEGRA_GPIO_PU0,
114                 .end    = TEGRA_GPIO_PU0,
115                 .flags  = IORESOURCE_IO,
116         },
117 };
118
119 static struct platform_device cardhu_bcm4329_rfkill_device = {
120         .name = "bcm4329_rfkill",
121         .id             = -1,
122         .num_resources  = ARRAY_SIZE(cardhu_bcm4329_rfkill_resources),
123         .resource       = cardhu_bcm4329_rfkill_resources,
124 };
125
126 static noinline void __init cardhu_bt_rfkill(void)
127 {
128         platform_device_register(&cardhu_bcm4329_rfkill_device);
129
130         return;
131 }
132 #else
133 static inline void cardhu_bt_rfkill(void) { }
134 #endif
135
136 static __initdata struct tegra_clk_init_table cardhu_clk_init_table[] = {
137         /* name         parent          rate            enabled */
138         { "uarta",      "pll_p",        216000000,      true},
139         { "uartb",      "pll_p",        216000000,      false},
140         { "uartc",      "pll_p",        216000000,      false},
141         { "uartd",      "pll_p",        216000000,      false},
142         { "uarte",      "pll_p",        216000000,      false},
143         { "pll_m",      NULL,           0,              true},
144         { "hda2codec_2x", "pll_p",      48000000,       false },
145         { "pll_p_out4", "pll_p",        24000000,       true },
146         { "pwm",        "clk_32k",      32768,          false},
147         { "blink",      "clk_32k",      32768,          true},
148         { "pll_a",      NULL,           56448000,       true},
149         { "pll_a_out0", NULL,           11289600,       true},
150         { "i2s1",       "pll_a_out0",   11289600,       true},
151         { "i2s2",       "pll_a_out0",   11289600,       true},
152         { "audio",      "pll_a_out0",   11289600,       true},
153         { "audio_2x",   "audio",        22579200,       true},
154         { "sdmmc3",     "clk_m",        12000000,       true},
155         { "sdmmc1",     "clk_m",        12000000,       true},
156         { NULL,         NULL,           0,              0},
157 };
158
159 static struct tegra_ulpi_config cardhu_ehci2_ulpi_phy_config = {
160         .reset_gpio = TEGRA_GPIO_PV1,
161         .clk = "clk_dev2",
162 };
163
164 static struct tegra_ehci_platform_data cardhu_ehci2_ulpi_platform_data = {
165         .operating_mode = TEGRA_USB_HOST,
166         .power_down_on_bus_suspend = 0,
167         .phy_config = &cardhu_ehci2_ulpi_phy_config,
168 };
169
170 static struct tegra_i2c_platform_data cardhu_i2c1_platform_data = {
171         .adapter_nr     = 0,
172         .bus_count      = 1,
173         .bus_clk_rate   = { 100000, 0 },
174 };
175
176 static struct tegra_i2c_platform_data cardhu_i2c2_platform_data = {
177         .adapter_nr     = 1,
178         .bus_count      = 1,
179         .bus_clk_rate   = { 100000, 0 },
180 };
181
182 static struct tegra_i2c_platform_data cardhu_i2c3_platform_data = {
183         .adapter_nr     = 2,
184         .bus_count      = 1,
185         .bus_clk_rate   = { 100000, 0 },
186 };
187
188 static struct tegra_i2c_platform_data cardhu_i2c4_platform_data = {
189         .adapter_nr     = 3,
190         .bus_count      = 1,
191         .bus_clk_rate   = { 100000, 0 },
192 };
193
194 static struct tegra_i2c_platform_data cardhu_i2c5_platform_data = {
195         .adapter_nr     = 4,
196         .bus_count      = 1,
197         .bus_clk_rate   = { 100000, 0 },
198 };
199
200
201 static void cardhu_i2c_init(void)
202 {
203         tegra_i2c_device1.dev.platform_data = &cardhu_i2c1_platform_data;
204         tegra_i2c_device2.dev.platform_data = &cardhu_i2c2_platform_data;
205         tegra_i2c_device3.dev.platform_data = &cardhu_i2c3_platform_data;
206         tegra_i2c_device4.dev.platform_data = &cardhu_i2c4_platform_data;
207         tegra_i2c_device5.dev.platform_data = &cardhu_i2c5_platform_data;
208
209         platform_device_register(&tegra_i2c_device5);
210         platform_device_register(&tegra_i2c_device4);
211         platform_device_register(&tegra_i2c_device3);
212         platform_device_register(&tegra_i2c_device2);
213         platform_device_register(&tegra_i2c_device1);
214 }
215
216 static struct resource tegra_rtc_resources[] = {
217         [0] = {
218                 .start = TEGRA_RTC_BASE,
219                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
220                 .flags = IORESOURCE_MEM,
221         },
222         [1] = {
223                 .start = INT_RTC,
224                 .end = INT_RTC,
225                 .flags = IORESOURCE_IRQ,
226         },
227 };
228
229 static struct platform_device tegra_rtc_device = {
230         .name = "tegra_rtc",
231         .id   = -1,
232         .resource = tegra_rtc_resources,
233         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
234 };
235
236 static struct platform_device *cardhu_devices[] __initdata = {
237         &debug_uart,
238         &tegra_uartb_device,
239         &tegra_uartc_device,
240         &tegra_uartd_device,
241         &tegra_uarte_device,
242         &pmu_device,
243         &tegra_rtc_device,
244         &tegra_udc_device,
245 #if ENABLE_USB_HOST
246         &tegra_ehci2_device,
247 #endif
248 #if defined(CONFIG_TEGRA_IOVMM_SMMU)
249         &tegra_smmu_device,
250 #endif
251         &tegra_wdt_device,
252         &tegra_avp_device,
253 };
254
255 static int __init cardhu_touch_init(void)
256 {
257         return 0;
258 }
259
260
261 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
262         [0] = {
263                         .phy_config = &utmi_phy_config[0],
264                         .operating_mode = TEGRA_USB_HOST,
265                         .power_down_on_bus_suspend = 0,
266         },
267         [1] = {
268                         .phy_config = &ulpi_phy_config,
269                         .operating_mode = TEGRA_USB_HOST,
270                         .power_down_on_bus_suspend = 1,
271         },
272         [2] = {
273                         .phy_config = &utmi_phy_config[1],
274                         .operating_mode = TEGRA_USB_HOST,
275                         .power_down_on_bus_suspend = 0,
276         },
277 };
278
279 struct platform_device *tegra_usb_otg_host_register(void)
280 {
281         struct platform_device *pdev;
282         void *platform_data;
283         int val;
284
285         pdev = platform_device_alloc(tegra_ehci1_device.name,
286                 tegra_ehci1_device.id);
287         if (!pdev)
288                 return NULL;
289
290         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
291                 tegra_ehci1_device.num_resources);
292         if (val)
293                 goto error;
294
295         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
296         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
297
298         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
299                 GFP_KERNEL);
300         if (!platform_data)
301                 goto error;
302
303         memcpy(platform_data, &tegra_ehci_pdata[0],
304                                 sizeof(struct tegra_ehci_platform_data));
305         pdev->dev.platform_data = platform_data;
306
307         val = platform_device_add(pdev);
308         if (val)
309                 goto error_add;
310
311         return pdev;
312
313 error_add:
314         kfree(platform_data);
315 error:
316         pr_err("%s: failed to add the host contoller device\n", __func__);
317         platform_device_put(pdev);
318         return NULL;
319 }
320
321 void tegra_usb_otg_host_unregister(struct platform_device *pdev)
322 {
323         platform_device_unregister(pdev);
324 }
325
326 static struct tegra_otg_platform_data tegra_otg_pdata = {
327         .host_register = &tegra_usb_otg_host_register,
328         .host_unregister = &tegra_usb_otg_host_unregister,
329 };
330
331 static void cardhu_usb_init(void)
332 {
333         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
334         platform_device_register(&tegra_otg_device);
335
336         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
337         platform_device_register(&tegra_ehci3_device);
338 }
339
340
341 #ifdef CONFIG_SATA_AHCI_TEGRA
342 static void cardhu_sata_init(void)
343 {
344         platform_device_register(&tegra_sata_device);
345 }
346 #else
347 static void cardhu_sata_init(void) { }
348 #endif
349
350 static void __init tegra_cardhu_init(void)
351 {
352         tegra_common_init();
353         tegra_clk_init_from_table(cardhu_clk_init_table);
354         cardhu_pinmux_init();
355
356         tegra_ehci2_device.dev.platform_data
357                 = &cardhu_ehci2_ulpi_platform_data;
358         platform_add_devices(cardhu_devices, ARRAY_SIZE(cardhu_devices));
359
360         cardhu_sdhci_init();
361         cardhu_i2c_init();
362         cardhu_regulator_init();
363         cardhu_gpio_switch_regulator_init();
364         cardhu_suspend_init();
365         cardhu_touch_init();
366         cardhu_usb_init();
367
368 #ifdef CONFIG_KEYBOARD_TEGRA
369         cardhu_kbc_init();
370 #endif
371
372 #ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
373         cardhu_scroll_init();
374 #endif
375
376 #ifdef CONFIG_KEYBOARD_GPIO
377         cardhu_keys_init();
378 #endif
379
380         cardhu_panel_init();
381         cardhu_sensors_init();
382         cardhu_bt_rfkill();
383         cardhu_sata_init();
384 }
385
386 static void __init tegra_cardhu_reserve(void)
387 {
388         tegra_reserve(SZ_128M, SZ_4M, SZ_8M);
389 }
390
391 MACHINE_START(CARDHU, "cardhu")
392         .boot_params    = 0x80000100,
393         .phys_io        = IO_APB_PHYS,
394         .io_pg_offst    = ((IO_APB_VIRT) >> 18) & 0xfffc,
395         .init_irq       = tegra_init_irq,
396         .init_machine   = tegra_cardhu_init,
397         .map_io         = tegra_map_common_io,
398         .reserve        = tegra_cardhu_reserve,
399         .timer          = &tegra_timer,
400 MACHINE_END