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