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