ARM: tegra: whistler: uart: Add PORT_TEGRA port type
[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
40 #include <mach/clk.h>
41 #include <mach/iomap.h>
42 #include <mach/irqs.h>
43 #include <mach/pinmux.h>
44 #include <mach/iomap.h>
45 #include <mach/io.h>
46
47 #include <asm/mach-types.h>
48 #include <asm/mach/arch.h>
49 #include <mach/usb_phy.h>
50
51 #include "board.h"
52 #include "clock.h"
53 #include "board-whistler.h"
54 #include "devices.h"
55 #include "gpio-names.h"
56 #include "fuse.h"
57
58 static struct plat_serial8250_port debug_uart_platform_data[] = {
59         {
60                 .membase        = IO_ADDRESS(TEGRA_UARTA_BASE),
61                 .mapbase        = TEGRA_UARTA_BASE,
62                 .irq            = INT_UARTA,
63                 .flags          = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
64                 .type           = PORT_TEGRA,
65                 .iotype         = UPIO_MEM,
66                 .regshift       = 2,
67                 .uartclk        = 216000000,
68         }, {
69                 .flags          = 0,
70         }
71 };
72
73 static struct platform_device debug_uart = {
74         .name = "serial8250",
75         .id = PLAT8250_DEV_PLATFORM,
76         .dev = {
77                 .platform_data = debug_uart_platform_data,
78         },
79 };
80
81 #ifdef CONFIG_BCM4329_RFKILL
82
83 static struct resource whistler_bcm4329_rfkill_resources[] = {
84         {
85                 .name   = "bcm4329_nshutdown_gpio",
86                 .start  = TEGRA_GPIO_PU0,
87                 .end    = TEGRA_GPIO_PU0,
88                 .flags  = IORESOURCE_IO,
89         },
90 };
91
92 static struct platform_device whistler_bcm4329_rfkill_device = {
93         .name           = "bcm4329_rfkill",
94         .id             = -1,
95         .num_resources  = ARRAY_SIZE(whistler_bcm4329_rfkill_resources),
96         .resource       = whistler_bcm4329_rfkill_resources,
97 };
98
99 static noinline void __init whistler_bt_rfkill(void)
100 {
101         platform_device_register(&whistler_bcm4329_rfkill_device);
102         return;
103 }
104 #else
105 static inline void whistler_bt_rfkill(void) { }
106 #endif
107
108 static struct tegra_utmip_config utmi_phy_config[] = {
109         [0] = {
110                         .hssync_start_delay = 0,
111                         .idle_wait_delay = 17,
112                         .elastic_limit = 16,
113                         .term_range_adj = 6,
114                         .xcvr_setup = 15,
115                         .xcvr_lsfslew = 2,
116                         .xcvr_lsrslew = 2,
117                 },
118         [1] = {
119                         .hssync_start_delay = 0,
120                         .idle_wait_delay = 17,
121                         .elastic_limit = 16,
122                         .term_range_adj = 6,
123                         .xcvr_setup = 8,
124                         .xcvr_lsfslew = 2,
125                         .xcvr_lsrslew = 2,
126                 },
127 };
128
129 static struct tegra_ulpi_config ulpi_phy_config = {
130         .reset_gpio = TEGRA_GPIO_PG2,
131         .clk = "clk_dev2",
132         .inf_type = TEGRA_USB_LINK_ULPI,
133 };
134
135 static __initdata struct tegra_clk_init_table whistler_clk_init_table[] = {
136         /* name         parent          rate            enabled */
137         { "uarta",      "pll_p",        216000000,      true},
138         { "uartc",      "pll_m",        600000000,      false},
139         { "pwm",        "clk_32k",      32768,          false},
140         { "kbc",        "clk_32k",      32768,          true},
141         { "sdmmc2",     "pll_p",        25000000,       false},
142         { NULL,         NULL,           0,              0},
143 };
144
145 static struct tegra_i2c_platform_data whistler_i2c1_platform_data = {
146         .adapter_nr     = 0,
147         .bus_count      = 1,
148         .bus_clk_rate   = { 400000, 0 },
149 };
150
151 static const struct tegra_pingroup_config i2c2_ddc = {
152         .pingroup       = TEGRA_PINGROUP_DDC,
153         .func           = TEGRA_MUX_I2C2,
154 };
155
156 static const struct tegra_pingroup_config i2c2_gen2 = {
157         .pingroup       = TEGRA_PINGROUP_PTA,
158         .func           = TEGRA_MUX_I2C2,
159 };
160
161 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
162         .adapter_nr     = 1,
163         .bus_count      = 2,
164         .bus_clk_rate   = { 400000, 100000 },
165         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
166         .bus_mux_len    = { 1, 1 },
167 };
168
169 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
170         .adapter_nr     = 3,
171         .bus_count      = 1,
172         .bus_clk_rate   = { 400000, 0 },
173 };
174
175 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
176         .adapter_nr     = 4,
177         .bus_count      = 1,
178         .bus_clk_rate   = { 400000, 0 },
179         .is_dvc         = true,
180 };
181
182 static void whistler_i2c_init(void)
183 {
184         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
185         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
186         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
187         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
188
189         platform_device_register(&tegra_i2c_device4);
190         platform_device_register(&tegra_i2c_device3);
191         platform_device_register(&tegra_i2c_device2);
192         platform_device_register(&tegra_i2c_device1);
193 }
194
195 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
196 {       \
197         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
198         .gpio = TEGRA_GPIO_##_gpio,     \
199         .desc = _desc,  \
200         .active_low = 1,        \
201         .debounce_interval = 2, \
202 }
203
204 static struct gpio_scrollwheel_button scroll_keys[] = {
205         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
206         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
207         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
208         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
209 };
210
211 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
212         .buttons = scroll_keys,
213         .nbuttons = ARRAY_SIZE(scroll_keys),
214 };
215
216 static struct platform_device whistler_scroll_device = {
217         .name   = "alps-gpio-scrollwheel",
218         .id     = 0,
219         .dev    = {
220                 .platform_data  = &whistler_scroll_platform_data,
221         },
222 };
223
224 static struct platform_device tegra_camera = {
225         .name = "tegra_camera",
226         .id = -1,
227 };
228
229 static struct platform_device *whistler_devices[] __initdata = {
230         &tegra_uartb_device,
231         &tegra_uartc_device,
232         &pmu_device,
233         &tegra_udc_device,
234         &tegra_gart_device,
235         &tegra_wdt_device,
236         &tegra_avp_device,
237         &whistler_scroll_device,
238         &tegra_camera,
239 };
240
241 static int __init whistler_scroll_init(void)
242 {
243         int i;
244         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
245                 tegra_gpio_enable(scroll_keys[i].gpio);
246
247         return 0;
248 }
249
250 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
251         [0] = {
252                         .instance = 0,
253                         .vbus_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
254                         .vbus_gpio = TEGRA_GPIO_PN6,
255         },
256         [1] = {
257                         .instance = 1,
258                         .vbus_gpio = -1,
259         },
260         [2] = {
261                         .instance = 2,
262                         .vbus_gpio = -1,
263         },
264 };
265
266 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
267         [0] = {
268                         .phy_config = &utmi_phy_config[0],
269                         .operating_mode = TEGRA_USB_HOST,
270                         .power_down_on_bus_suspend = 1,
271                 },
272         [1] = {
273                         .phy_config = &ulpi_phy_config,
274                         .operating_mode = TEGRA_USB_HOST,
275                         .power_down_on_bus_suspend = 1,
276                 },
277         [2] = {
278                         .phy_config = &utmi_phy_config[1],
279                         .operating_mode = TEGRA_USB_HOST,
280                         .power_down_on_bus_suspend = 1,
281         },
282 };
283
284 static struct platform_device *tegra_usb_otg_host_register(void)
285 {
286         struct platform_device *pdev;
287         void *platform_data;
288         int val;
289
290         pdev = platform_device_alloc(tegra_ehci1_device.name,
291                         tegra_ehci1_device.id);
292         if (!pdev)
293                 return NULL;
294
295         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
296                 tegra_ehci1_device.num_resources);
297         if (val)
298                 goto error;
299
300         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
301         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
302
303         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
304                                 GFP_KERNEL);
305         if (!platform_data)
306                 goto error;
307
308         memcpy(platform_data, &tegra_ehci_pdata[0],
309                                 sizeof(struct tegra_ehci_platform_data));
310         pdev->dev.platform_data = platform_data;
311
312         val = platform_device_add(pdev);
313         if (val)
314                 goto error_add;
315
316         return pdev;
317
318 error_add:
319         kfree(platform_data);
320 error:
321         pr_err("%s: failed to add the host contoller device\n", __func__);
322         platform_device_put(pdev);
323         return NULL;
324 }
325
326 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
327 {
328         kfree(pdev->dev.platform_data);
329         platform_device_unregister(pdev);
330 }
331
332 static struct tegra_otg_platform_data tegra_otg_pdata = {
333         .host_register = &tegra_usb_otg_host_register,
334         .host_unregister = &tegra_usb_otg_host_unregister,
335 };
336
337 static int __init whistler_gps_init(void)
338 {
339         tegra_gpio_enable(TEGRA_GPIO_PU4);
340         return 0;
341 }
342
343 static void whistler_power_off(void)
344 {
345         int ret;
346
347         ret = max8907c_power_off();
348         if (ret)
349                 pr_err("whistler: failed to power off\n");
350
351         while (1);
352 }
353
354 static void __init whistler_power_off_init(void)
355 {
356         pm_power_off = whistler_power_off;
357 }
358
359 static void whistler_usb_init(void)
360 {
361         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
362
363         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
364         platform_device_register(&tegra_otg_device);
365
366         tegra_ehci3_device.dev.platform_data=&tegra_ehci_pdata[2];
367         platform_device_register(&tegra_ehci3_device);
368 }
369
370 static void __init tegra_whistler_init(void)
371 {
372         char serial[20];
373
374         tegra_common_init();
375         tegra_clk_init_from_table(whistler_clk_init_table);
376         whistler_pinmux_init();
377         whistler_i2c_init();
378         if (is_tegra_debug_uartport_hs() == true)
379                 platform_device_register(&tegra_uarta_device);
380         else
381                 platform_device_register(&debug_uart);
382         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
383
384         whistler_sdhci_init();
385         whistler_regulator_init();
386         whistler_panel_init();
387         whistler_sensors_init();
388         whistler_kbc_init();
389         whistler_bt_rfkill();
390         whistler_gps_init();
391         whistler_usb_init();
392         whistler_scroll_init();
393         whistler_power_off_init();
394         whistler_emc_init();
395 }
396
397 int __init tegra_whistler_protected_aperture_init(void)
398 {
399         tegra_protected_aperture_init(tegra_grhost_aperture);
400         return 0;
401 }
402
403 void __init tegra_whistler_reserve(void)
404 {
405         if (memblock_reserve(0x0, 4096) < 0)
406                 pr_warn("Cannot reserve first 4K of memory for safety\n");
407
408         tegra_reserve(SZ_128M, SZ_8M, SZ_16M);
409 }
410
411 MACHINE_START(WHISTLER, "whistler")
412         .boot_params    = 0x00000100,
413         .phys_io        = IO_APB_PHYS,
414         .io_pg_offst    = ((IO_APB_VIRT) >> 18) & 0xfffc,
415         .init_irq       = tegra_init_irq,
416         .init_machine   = tegra_whistler_init,
417         .map_io         = tegra_map_common_io,
418         .reserve        = tegra_whistler_reserve,
419         .timer          = &tegra_timer,
420 MACHINE_END