fixup f21110d7 arm: tegra: whistler: Add KBC support for whistler
[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 #include <linux/tegra_uart.h>
40
41 #include <mach/clk.h>
42 #include <mach/iomap.h>
43 #include <mach/irqs.h>
44 #include <mach/pinmux.h>
45 #include <mach/iomap.h>
46 #include <mach/io.h>
47 #include <mach/i2s.h>
48 #include <mach/tegra_wm8753_pdata.h>
49
50 #include <asm/mach-types.h>
51 #include <asm/mach/arch.h>
52 #include <mach/usb_phy.h>
53
54 #include "board.h"
55 #include "clock.h"
56 #include "board-whistler.h"
57 #include "devices.h"
58 #include "gpio-names.h"
59 #include "fuse.h"
60 #include "pm.h"
61 #include "board-whistler-baseband.h"
62
63 static struct plat_serial8250_port debug_uart_platform_data[] = {
64         {
65                 .membase        = IO_ADDRESS(TEGRA_UARTA_BASE),
66                 .mapbase        = TEGRA_UARTA_BASE,
67                 .irq            = INT_UARTA,
68                 .flags          = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
69                 .type           = PORT_TEGRA,
70                 .iotype         = UPIO_MEM,
71                 .regshift       = 2,
72                 .uartclk        = 216000000,
73         }, {
74                 .flags          = 0,
75         }
76 };
77
78 static struct platform_device debug_uart = {
79         .name = "serial8250",
80         .id = PLAT8250_DEV_PLATFORM,
81         .dev = {
82                 .platform_data = debug_uart_platform_data,
83         },
84 };
85 static struct platform_device *whistler_uart_devices[] __initdata = {
86         &tegra_uarta_device,
87         &tegra_uartb_device,
88         &tegra_uartc_device,
89 };
90
91 struct uart_clk_parent uart_parent_clk[] = {
92         [0] = {.name = "pll_p"},
93         [1] = {.name = "pll_m"},
94         [2] = {.name = "clk_m"},
95 };
96
97 static struct tegra_uart_platform_data whistler_uart_pdata;
98
99 static void __init uart_debug_init(void)
100 {
101         unsigned long rate;
102         struct clk *debug_uart_clk;
103         struct clk *c;
104
105         /* UARTA is the debug port. */
106         pr_info("Selecting UARTA as the debug console\n");
107         whistler_uart_devices[0] = &debug_uart;
108         debug_uart_port_base = ((struct plat_serial8250_port *)(
109                                 debug_uarta_device.dev.platform_data))->mapbase;
110         debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
111
112         /* Clock enable for the debug channel */
113         if (!IS_ERR_OR_NULL(debug_uart_clk)) {
114                 rate = debug_uart_platform_data[0].uartclk;
115                 pr_info("The debug console clock name is %s\n",
116                                                 debug_uart_clk->name);
117                 c = tegra_get_clock_by_name("pll_p");
118                 if (IS_ERR_OR_NULL(c))
119                         pr_err("Not getting the parent clock pll_p\n");
120                 else
121                         clk_set_parent(debug_uart_clk, c);
122
123                 clk_enable(debug_uart_clk);
124                 clk_set_rate(debug_uart_clk, rate);
125         } else {
126                 pr_err("Not getting the clock %s for debug console\n",
127                                         debug_uart_clk->name);
128         }
129 }
130
131 static void __init whistler_uart_init(void)
132 {
133         int i;
134         struct clk *c;
135
136         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
137                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
138                 if (IS_ERR_OR_NULL(c)) {
139                         pr_err("Not able to get the clock for %s\n",
140                                                 uart_parent_clk[i].name);
141                         continue;
142                 }
143                 uart_parent_clk[i].parent_clk = c;
144                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
145         }
146         whistler_uart_pdata.parent_clk_list = uart_parent_clk;
147         whistler_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
148
149         tegra_uarta_device.dev.platform_data = &whistler_uart_pdata;
150         tegra_uartb_device.dev.platform_data = &whistler_uart_pdata;
151         tegra_uartc_device.dev.platform_data = &whistler_uart_pdata;
152
153         /* Register low speed only if it is selected */
154         if (!is_tegra_debug_uartport_hs())
155                 uart_debug_init();
156
157         platform_add_devices(whistler_uart_devices,
158                                 ARRAY_SIZE(whistler_uart_devices));
159 }
160
161 #ifdef CONFIG_BCM4329_RFKILL
162
163 static struct resource whistler_bcm4329_rfkill_resources[] = {
164         {
165                 .name   = "bcm4329_nshutdown_gpio",
166                 .start  = TEGRA_GPIO_PU0,
167                 .end    = TEGRA_GPIO_PU0,
168                 .flags  = IORESOURCE_IO,
169         },
170 };
171
172 static struct platform_device whistler_bcm4329_rfkill_device = {
173         .name           = "bcm4329_rfkill",
174         .id             = -1,
175         .num_resources  = ARRAY_SIZE(whistler_bcm4329_rfkill_resources),
176         .resource       = whistler_bcm4329_rfkill_resources,
177 };
178
179 static noinline void __init whistler_bt_rfkill(void)
180 {
181         platform_device_register(&whistler_bcm4329_rfkill_device);
182         return;
183 }
184 #else
185 static inline void whistler_bt_rfkill(void) { }
186 #endif
187
188 static struct tegra_utmip_config utmi_phy_config[] = {
189         [0] = {
190                         .hssync_start_delay = 9,
191                         .idle_wait_delay = 17,
192                         .elastic_limit = 16,
193                         .term_range_adj = 6,
194                         .xcvr_setup = 15,
195                         .xcvr_lsfslew = 2,
196                         .xcvr_lsrslew = 2,
197                 },
198         [1] = {
199                         .hssync_start_delay = 9,
200                         .idle_wait_delay = 17,
201                         .elastic_limit = 16,
202                         .term_range_adj = 6,
203                         .xcvr_setup = 8,
204                         .xcvr_lsfslew = 2,
205                         .xcvr_lsrslew = 2,
206                 },
207 };
208
209 static struct tegra_ulpi_config ulpi_phy_config = {
210         .reset_gpio = TEGRA_GPIO_PG2,
211         .clk = "clk_dev2",
212 };
213
214 static __initdata struct tegra_clk_init_table whistler_clk_init_table[] = {
215         /* name         parent          rate            enabled */
216         { "pwm",        "clk_32k",      32768,          false},
217         { "kbc",        "clk_32k",      32768,          true},
218         { "sdmmc2",     "pll_p",        25000000,       false},
219         { "i2s1",       "pll_a_out0",   0,              false},
220         { NULL,         NULL,           0,              0},
221 };
222
223 static struct tegra_i2c_platform_data whistler_i2c1_platform_data = {
224         .adapter_nr     = 0,
225         .bus_count      = 1,
226         .bus_clk_rate   = { 400000, 0 },
227 };
228
229 static const struct tegra_pingroup_config i2c2_ddc = {
230         .pingroup       = TEGRA_PINGROUP_DDC,
231         .func           = TEGRA_MUX_I2C2,
232 };
233
234 static const struct tegra_pingroup_config i2c2_gen2 = {
235         .pingroup       = TEGRA_PINGROUP_PTA,
236         .func           = TEGRA_MUX_I2C2,
237 };
238
239 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
240         .adapter_nr     = 1,
241         .bus_count      = 2,
242         .bus_clk_rate   = { 100000, 100000 },
243         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
244         .bus_mux_len    = { 1, 1 },
245 };
246
247 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
248         .adapter_nr     = 3,
249         .bus_count      = 1,
250         .bus_clk_rate   = { 400000, 0 },
251 };
252
253 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
254         .adapter_nr     = 4,
255         .bus_count      = 1,
256         .bus_clk_rate   = { 400000, 0 },
257         .is_dvc         = true,
258 };
259
260 static struct i2c_board_info __initdata wm8753_board_info = {
261         I2C_BOARD_INFO("wm8753", 0x1a),
262 };
263
264 static void whistler_i2c_init(void)
265 {
266         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
267         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
268         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
269         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
270
271         platform_device_register(&tegra_i2c_device4);
272         platform_device_register(&tegra_i2c_device3);
273         platform_device_register(&tegra_i2c_device2);
274         platform_device_register(&tegra_i2c_device1);
275
276         i2c_register_board_info(4, &wm8753_board_info, 1);
277 }
278
279 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
280 {       \
281         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
282         .gpio = TEGRA_GPIO_##_gpio,     \
283         .desc = _desc,  \
284         .active_low = 1,        \
285         .debounce_interval = 2, \
286 }
287
288 static struct gpio_scrollwheel_button scroll_keys[] = {
289         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
290         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
291         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
292         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
293 };
294
295 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
296         .buttons = scroll_keys,
297         .nbuttons = ARRAY_SIZE(scroll_keys),
298 };
299
300 static struct platform_device whistler_scroll_device = {
301         .name   = "alps-gpio-scrollwheel",
302         .id     = 0,
303         .dev    = {
304                 .platform_data  = &whistler_scroll_platform_data,
305         },
306 };
307
308 static struct platform_device tegra_camera = {
309         .name = "tegra_camera",
310         .id = -1,
311 };
312
313 static struct tegra_wm8753_platform_data whistler_audio_pdata = {
314         .gpio_spkr_en = TEGRA_GPIO_SPKR_EN,
315         .gpio_hp_det = TEGRA_GPIO_HP_DET,
316         .gpio_hp_mute = -1,
317         .gpio_int_mic_en = -1,
318         .gpio_ext_mic_en = -1,
319 };
320
321 static struct platform_device whistler_audio_device = {
322         .name   = "tegra-snd-wm8753",
323         .id     = 0,
324         .dev    = {
325                 .platform_data  = &whistler_audio_pdata,
326         },
327 };
328
329 static struct platform_device *whistler_devices[] __initdata = {
330         &tegra_pmu_device,
331         &tegra_udc_device,
332         &tegra_gart_device,
333         &tegra_wdt_device,
334         &tegra_avp_device,
335         &whistler_scroll_device,
336         &tegra_camera,
337         &tegra_i2s_device1,
338         &tegra_das_device,
339         &tegra_pcm_device,
340         &whistler_audio_device,
341 };
342
343 static int __init whistler_scroll_init(void)
344 {
345         int i;
346         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
347                 tegra_gpio_enable(scroll_keys[i].gpio);
348
349         return 0;
350 }
351
352 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
353         [0] = {
354                         .instance = 0,
355                         .vbus_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
356                         .vbus_gpio = TEGRA_GPIO_PN6,
357         },
358         [1] = {
359                         .instance = 1,
360                         .vbus_gpio = -1,
361         },
362         [2] = {
363                         .instance = 2,
364                         .vbus_gpio = -1,
365         },
366 };
367
368 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
369         [0] = {
370                         .phy_config = &utmi_phy_config[0],
371                         .operating_mode = TEGRA_USB_HOST,
372                         .power_down_on_bus_suspend = 1,
373                 },
374         [1] = {
375                         .phy_config = &ulpi_phy_config,
376                         .operating_mode = TEGRA_USB_HOST,
377                         .power_down_on_bus_suspend = 1,
378                 },
379         [2] = {
380                         .phy_config = &utmi_phy_config[1],
381                         .operating_mode = TEGRA_USB_HOST,
382                         .power_down_on_bus_suspend = 1,
383         },
384 };
385
386 static struct platform_device *tegra_usb_otg_host_register(void)
387 {
388         struct platform_device *pdev;
389         void *platform_data;
390         int val;
391
392         pdev = platform_device_alloc(tegra_ehci1_device.name,
393                         tegra_ehci1_device.id);
394         if (!pdev)
395                 return NULL;
396
397         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
398                 tegra_ehci1_device.num_resources);
399         if (val)
400                 goto error;
401
402         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
403         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
404
405         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
406                                 GFP_KERNEL);
407         if (!platform_data)
408                 goto error;
409
410         memcpy(platform_data, &tegra_ehci_pdata[0],
411                                 sizeof(struct tegra_ehci_platform_data));
412         pdev->dev.platform_data = platform_data;
413
414         val = platform_device_add(pdev);
415         if (val)
416                 goto error_add;
417
418         return pdev;
419
420 error_add:
421         kfree(platform_data);
422 error:
423         pr_err("%s: failed to add the host contoller device\n", __func__);
424         platform_device_put(pdev);
425         return NULL;
426 }
427
428 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
429 {
430         kfree(pdev->dev.platform_data);
431         platform_device_unregister(pdev);
432 }
433
434 static struct tegra_otg_platform_data tegra_otg_pdata = {
435         .host_register = &tegra_usb_otg_host_register,
436         .host_unregister = &tegra_usb_otg_host_unregister,
437 };
438
439 static int __init whistler_gps_init(void)
440 {
441         tegra_gpio_enable(TEGRA_GPIO_PU4);
442         return 0;
443 }
444
445 static void whistler_power_off(void)
446 {
447         int ret;
448
449         ret = max8907c_power_off();
450         if (ret)
451                 pr_err("whistler: failed to power off\n");
452
453         while (1);
454 }
455
456 static void __init whistler_power_off_init(void)
457 {
458         pm_power_off = whistler_power_off;
459 }
460
461 static void whistler_usb_init(void)
462 {
463         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
464
465         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
466         platform_device_register(&tegra_otg_device);
467
468         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
469         platform_device_register(&tegra_ehci3_device);
470 }
471
472 static void __init tegra_whistler_init(void)
473 {
474         char serial[20];
475
476         tegra_clk_init_from_table(whistler_clk_init_table);
477         whistler_pinmux_init();
478         whistler_i2c_init();
479         whistler_uart_init();
480         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
481
482         whistler_sdhci_init();
483         whistler_regulator_init();
484         whistler_panel_init();
485         whistler_sensors_init();
486         whistler_kbc_init();
487         whistler_bt_rfkill();
488         whistler_gps_init();
489         whistler_usb_init();
490         whistler_scroll_init();
491         whistler_power_off_init();
492         whistler_emc_init();
493         whistler_baseband_init();
494         tegra_release_bootloader_fb();
495 }
496
497 int __init tegra_whistler_protected_aperture_init(void)
498 {
499         tegra_protected_aperture_init(tegra_grhost_aperture);
500         return 0;
501 }
502
503 void __init tegra_whistler_reserve(void)
504 {
505         if (memblock_reserve(0x0, 4096) < 0)
506                 pr_warn("Cannot reserve first 4K of memory for safety\n");
507
508         tegra_reserve(SZ_128M, SZ_8M, SZ_16M);
509 }
510
511 MACHINE_START(WHISTLER, "whistler")
512         .boot_params    = 0x00000100,
513         .map_io         = tegra_map_common_io,
514         .reserve        = tegra_whistler_reserve,
515         .init_early     = tegra_init_early,
516         .init_irq       = tegra_init_irq,
517         .timer          = &tegra_timer,
518         .init_machine   = tegra_whistler_init,
519 MACHINE_END