arm: tegra: Enable Host mode on USB3 port
[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_nreset_gpio",
113                 .start  = TEGRA_GPIO_PU0,
114                 .end    = TEGRA_GPIO_PU0,
115                 .flags  = IORESOURCE_IO,
116         },
117         {
118                 .name   = "bcm4329_nshutdown_gpio",
119                 .start  = TEGRA_GPIO_PK2,
120                 .end    = TEGRA_GPIO_PK2,
121                 .flags  = IORESOURCE_IO,
122         },
123 };
124
125 static struct platform_device cardhu_bcm4329_rfkill_device = {
126         .name = "bcm4329_rfkill",
127         .id             = -1,
128         .num_resources  = ARRAY_SIZE(cardhu_bcm4329_rfkill_resources),
129         .resource       = cardhu_bcm4329_rfkill_resources,
130 };
131
132 static noinline void __init cardhu_bt_rfkill(void)
133 {
134         /*Add Clock Resource*/
135         clk_add_alias("bcm4329_32k_clk", cardhu_bcm4329_rfkill_device.name, \
136                                 "blink", NULL);
137
138         platform_device_register(&cardhu_bcm4329_rfkill_device);
139
140         return;
141 }
142 #else
143 static inline void cardhu_bt_rfkill(void) { }
144 #endif
145
146 static __initdata struct tegra_clk_init_table cardhu_clk_init_table[] = {
147         /* name         parent          rate            enabled */
148         { "uarta",      "pll_p",        216000000,      true},
149         { "uartb",      "clk_m",        13000000,       true},
150         { "uartc",      "clk_m",        13000000,       true},
151         { "uartd",      "clk_m",        13000000,       true},
152         { "uarte",      "clk_m",        13000000,       true},
153         { "pll_m",      NULL,           0,              true},
154         { "pll_p_out4", "pll_p",        24000000,       true },
155         { "pwm",        "clk_32k",      32768,          false},
156         { "blink",      "clk_32k",      32768,          true},
157         { "pll_a",      NULL,           56448000,       true},
158         { "pll_a_out0", NULL,           11289600,       true},
159         { "i2s1",       "pll_a_out0",   11289600,       true},
160         { "i2s2",       "pll_a_out0",   11289600,       true},
161         { "audio",      "pll_a_out0",   11289600,       true},
162         { "audio_2x",   "audio",        22579200,       true},
163         { "sdmmc3",     "clk_m",        12000000,       true},
164         { "sdmmc1",     "clk_m",        12000000,       true},
165         { NULL,         NULL,           0,              0},
166 };
167
168 static struct tegra_ulpi_config cardhu_ehci2_ulpi_phy_config = {
169         .reset_gpio = TEGRA_GPIO_PV1,
170         .clk = "clk_dev2",
171 };
172
173 static struct tegra_ehci_platform_data cardhu_ehci2_ulpi_platform_data = {
174         .operating_mode = TEGRA_USB_HOST,
175         .power_down_on_bus_suspend = 0,
176         .phy_config = &cardhu_ehci2_ulpi_phy_config,
177 };
178
179 static struct tegra_i2c_platform_data cardhu_i2c1_platform_data = {
180         .adapter_nr     = 0,
181         .bus_count      = 1,
182         .bus_clk_rate   = { 100000, 0 },
183 };
184
185 static struct tegra_i2c_platform_data cardhu_i2c2_platform_data = {
186         .adapter_nr     = 1,
187         .bus_count      = 1,
188         .bus_clk_rate   = { 100000, 0 },
189 };
190
191 static struct tegra_i2c_platform_data cardhu_i2c3_platform_data = {
192         .adapter_nr     = 2,
193         .bus_count      = 1,
194         .bus_clk_rate   = { 100000, 0 },
195 };
196
197 static struct tegra_i2c_platform_data cardhu_i2c4_platform_data = {
198         .adapter_nr     = 3,
199         .bus_count      = 1,
200         .bus_clk_rate   = { 100000, 0 },
201 };
202
203 static struct tegra_i2c_platform_data cardhu_i2c5_platform_data = {
204         .adapter_nr     = 4,
205         .bus_count      = 1,
206         .bus_clk_rate   = { 100000, 0 },
207 };
208
209
210 static void cardhu_i2c_init(void)
211 {
212         tegra_i2c_device1.dev.platform_data = &cardhu_i2c1_platform_data;
213         tegra_i2c_device2.dev.platform_data = &cardhu_i2c2_platform_data;
214         tegra_i2c_device3.dev.platform_data = &cardhu_i2c3_platform_data;
215         tegra_i2c_device4.dev.platform_data = &cardhu_i2c4_platform_data;
216         tegra_i2c_device5.dev.platform_data = &cardhu_i2c5_platform_data;
217
218         platform_device_register(&tegra_i2c_device5);
219         platform_device_register(&tegra_i2c_device4);
220         platform_device_register(&tegra_i2c_device3);
221         platform_device_register(&tegra_i2c_device2);
222         platform_device_register(&tegra_i2c_device1);
223 }
224
225 static struct resource tegra_rtc_resources[] = {
226         [0] = {
227                 .start = TEGRA_RTC_BASE,
228                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
229                 .flags = IORESOURCE_MEM,
230         },
231         [1] = {
232                 .start = INT_RTC,
233                 .end = INT_RTC,
234                 .flags = IORESOURCE_IRQ,
235         },
236 };
237
238 static struct platform_device tegra_rtc_device = {
239         .name = "tegra_rtc",
240         .id   = -1,
241         .resource = tegra_rtc_resources,
242         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
243 };
244
245 static struct platform_device *cardhu_devices[] __initdata = {
246         &tegra_otg_device,
247         &debug_uart,
248         &tegra_uartb_device,
249         &tegra_uartc_device,
250         &tegra_uartd_device,
251         &tegra_uarte_device,
252         &pmu_device,
253         &tegra_rtc_device,
254         &tegra_udc_device,
255 #if ENABLE_USB_HOST
256         &tegra_ehci2_device,
257 #endif
258 #if defined(CONFIG_TEGRA_IOVMM_SMMU)
259         &tegra_smmu_device,
260 #endif
261         &tegra_wdt_device,
262         &tegra_avp_device,
263 };
264
265 static int __init cardhu_touch_init(void)
266 {
267         return 0;
268 }
269
270
271 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
272         [0] = {
273                         .phy_config = &utmi_phy_config[0],
274                         .operating_mode = TEGRA_USB_HOST,
275                         .power_down_on_bus_suspend = 0,
276         },
277         [1] = {
278                         .phy_config = &ulpi_phy_config,
279                         .operating_mode = TEGRA_USB_HOST,
280                         .power_down_on_bus_suspend = 1,
281         },
282         [2] = {
283                         .phy_config = &utmi_phy_config[1],
284                         .operating_mode = TEGRA_USB_HOST,
285                         .power_down_on_bus_suspend = 0,
286         },
287 };
288
289 static void cardhu_usb_init(void)
290 {
291         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
292         platform_device_register(&tegra_ehci3_device);
293 }
294
295 struct platform_device *tegra_usb_otg_host_register(void)
296 {
297         struct platform_device *pdev;
298         void *platform_data;
299         int val;
300
301         pdev = platform_device_alloc(tegra_ehci1_device.name,
302                 tegra_ehci1_device.id);
303         if (!pdev)
304                 return NULL;
305
306         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
307                 tegra_ehci1_device.num_resources);
308         if (val)
309                 goto error;
310
311         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
312         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
313
314         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
315                 GFP_KERNEL);
316         if (!platform_data)
317                 goto error;
318
319         memcpy(platform_data, &tegra_ehci_pdata[0],
320                                 sizeof(struct tegra_ehci_platform_data));
321         pdev->dev.platform_data = platform_data;
322
323         val = platform_device_add(pdev);
324         if (val)
325                 goto error_add;
326
327         return pdev;
328
329 error_add:
330         kfree(platform_data);
331 error:
332         pr_err("%s: failed to add the host contoller device\n", __func__);
333         platform_device_put(pdev);
334         return NULL;
335 }
336
337 void tegra_usb_otg_host_unregister(struct platform_device *pdev)
338 {
339         platform_device_unregister(pdev);
340 }
341
342
343 #ifdef CONFIG_SATA_AHCI_TEGRA
344 static void cardhu_sata_init(void)
345 {
346         platform_device_register(&tegra_sata_device);
347 }
348 #else
349 static void cardhu_sata_init(void) { }
350 #endif
351
352 static void __init tegra_cardhu_init(void)
353 {
354         tegra_common_init();
355         tegra_clk_init_from_table(cardhu_clk_init_table);
356         cardhu_pinmux_init();
357
358         tegra_ehci2_device.dev.platform_data
359                 = &cardhu_ehci2_ulpi_platform_data;
360         platform_add_devices(cardhu_devices, ARRAY_SIZE(cardhu_devices));
361
362         cardhu_sdhci_init();
363         cardhu_i2c_init();
364         cardhu_regulator_init();
365         cardhu_gpio_switch_regulator_init();
366         cardhu_suspend_init();
367         cardhu_touch_init();
368         cardhu_usb_init();
369
370 #ifdef CONFIG_KEYBOARD_TEGRA
371         cardhu_kbc_init();
372 #endif
373
374 #ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
375         cardhu_scroll_init();
376 #endif
377
378 #ifdef CONFIG_KEYBOARD_GPIO
379         cardhu_keys_init();
380 #endif
381
382         cardhu_panel_init();
383         cardhu_sensors_init();
384         cardhu_bt_rfkill();
385         cardhu_sata_init();
386 }
387
388 static void __init tegra_cardhu_reserve(void)
389 {
390         tegra_reserve(SZ_128M, SZ_4M, SZ_8M);
391 }
392
393 MACHINE_START(CARDHU, "cardhu")
394         .boot_params    = 0x80000100,
395         .phys_io        = IO_APB_PHYS,
396         .io_pg_offst    = ((IO_APB_VIRT) >> 18) & 0xfffc,
397         .init_irq       = tegra_init_irq,
398         .init_machine   = tegra_cardhu_init,
399         .map_io         = tegra_map_common_io,
400         .reserve        = tegra_cardhu_reserve,
401         .timer          = &tegra_timer,
402 MACHINE_END