arm: tegra: whistler: add headphone debouncetime and irq
[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         { "spdif_out",  "pll_a_out0",   0,              false},
221         { NULL,         NULL,           0,              0},
222 };
223
224 static struct tegra_i2c_platform_data whistler_i2c1_platform_data = {
225         .adapter_nr     = 0,
226         .bus_count      = 1,
227         .bus_clk_rate   = { 400000, 0 },
228 };
229
230 static const struct tegra_pingroup_config i2c2_ddc = {
231         .pingroup       = TEGRA_PINGROUP_DDC,
232         .func           = TEGRA_MUX_I2C2,
233 };
234
235 static const struct tegra_pingroup_config i2c2_gen2 = {
236         .pingroup       = TEGRA_PINGROUP_PTA,
237         .func           = TEGRA_MUX_I2C2,
238 };
239
240 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
241         .adapter_nr     = 1,
242         .bus_count      = 2,
243         .bus_clk_rate   = { 100000, 100000 },
244         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
245         .bus_mux_len    = { 1, 1 },
246 };
247
248 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
249         .adapter_nr     = 3,
250         .bus_count      = 1,
251         .bus_clk_rate   = { 400000, 0 },
252 };
253
254 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
255         .adapter_nr     = 4,
256         .bus_count      = 1,
257         .bus_clk_rate   = { 400000, 0 },
258         .is_dvc         = true,
259 };
260
261 static struct i2c_board_info __initdata wm8753_board_info = {
262         I2C_BOARD_INFO("wm8753", 0x1a),
263         .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_HP_DET),
264 };
265
266 static void whistler_i2c_init(void)
267 {
268         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
269         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
270         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
271         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
272
273         platform_device_register(&tegra_i2c_device4);
274         platform_device_register(&tegra_i2c_device3);
275         platform_device_register(&tegra_i2c_device2);
276         platform_device_register(&tegra_i2c_device1);
277
278         i2c_register_board_info(4, &wm8753_board_info, 1);
279 }
280
281 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
282 {       \
283         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
284         .gpio = TEGRA_GPIO_##_gpio,     \
285         .desc = _desc,  \
286         .active_low = 1,        \
287         .debounce_interval = 2, \
288 }
289
290 static struct gpio_scrollwheel_button scroll_keys[] = {
291         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
292         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
293         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
294         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
295 };
296
297 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
298         .buttons = scroll_keys,
299         .nbuttons = ARRAY_SIZE(scroll_keys),
300 };
301
302 static struct platform_device whistler_scroll_device = {
303         .name   = "alps-gpio-scrollwheel",
304         .id     = 0,
305         .dev    = {
306                 .platform_data  = &whistler_scroll_platform_data,
307         },
308 };
309
310 static struct platform_device tegra_camera = {
311         .name = "tegra_camera",
312         .id = -1,
313 };
314
315 static struct tegra_wm8753_platform_data whistler_audio_pdata = {
316         .gpio_spkr_en = TEGRA_GPIO_SPKR_EN,
317         .gpio_hp_det = TEGRA_GPIO_HP_DET,
318         .gpio_hp_mute = -1,
319         .gpio_int_mic_en = -1,
320         .gpio_ext_mic_en = -1,
321         .debounce_time_hp = 200,
322 };
323
324 static struct platform_device whistler_audio_device = {
325         .name   = "tegra-snd-wm8753",
326         .id     = 0,
327         .dev    = {
328                 .platform_data  = &whistler_audio_pdata,
329         },
330 };
331
332 static struct platform_device *whistler_devices[] __initdata = {
333         &tegra_pmu_device,
334         &tegra_udc_device,
335         &tegra_gart_device,
336         &tegra_wdt_device,
337         &tegra_avp_device,
338         &whistler_scroll_device,
339         &tegra_camera,
340         &tegra_i2s_device1,
341         &tegra_spdif_device,
342         &tegra_das_device,
343         &spdif_dit_device,
344         &tegra_pcm_device,
345         &whistler_audio_device,
346 };
347
348 static int __init whistler_scroll_init(void)
349 {
350         int i;
351         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
352                 tegra_gpio_enable(scroll_keys[i].gpio);
353
354         return 0;
355 }
356
357 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
358         [0] = {
359                         .instance = 0,
360                         .vbus_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
361                         .vbus_gpio = TEGRA_GPIO_PN6,
362         },
363         [1] = {
364                         .instance = 1,
365                         .vbus_gpio = -1,
366         },
367         [2] = {
368                         .instance = 2,
369                         .vbus_gpio = -1,
370         },
371 };
372
373 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
374         [0] = {
375                         .phy_config = &utmi_phy_config[0],
376                         .operating_mode = TEGRA_USB_HOST,
377                         .power_down_on_bus_suspend = 1,
378                 },
379         [1] = {
380                         .phy_config = &ulpi_phy_config,
381                         .operating_mode = TEGRA_USB_HOST,
382                         .power_down_on_bus_suspend = 1,
383                 },
384         [2] = {
385                         .phy_config = &utmi_phy_config[1],
386                         .operating_mode = TEGRA_USB_HOST,
387                         .power_down_on_bus_suspend = 1,
388         },
389 };
390
391 static struct platform_device *tegra_usb_otg_host_register(void)
392 {
393         struct platform_device *pdev;
394         void *platform_data;
395         int val;
396
397         pdev = platform_device_alloc(tegra_ehci1_device.name,
398                         tegra_ehci1_device.id);
399         if (!pdev)
400                 return NULL;
401
402         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
403                 tegra_ehci1_device.num_resources);
404         if (val)
405                 goto error;
406
407         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
408         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
409
410         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
411                                 GFP_KERNEL);
412         if (!platform_data)
413                 goto error;
414
415         memcpy(platform_data, &tegra_ehci_pdata[0],
416                                 sizeof(struct tegra_ehci_platform_data));
417         pdev->dev.platform_data = platform_data;
418
419         val = platform_device_add(pdev);
420         if (val)
421                 goto error_add;
422
423         return pdev;
424
425 error_add:
426         kfree(platform_data);
427 error:
428         pr_err("%s: failed to add the host contoller device\n", __func__);
429         platform_device_put(pdev);
430         return NULL;
431 }
432
433 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
434 {
435         kfree(pdev->dev.platform_data);
436         platform_device_unregister(pdev);
437 }
438
439 static struct tegra_otg_platform_data tegra_otg_pdata = {
440         .host_register = &tegra_usb_otg_host_register,
441         .host_unregister = &tegra_usb_otg_host_unregister,
442 };
443
444 static int __init whistler_gps_init(void)
445 {
446         tegra_gpio_enable(TEGRA_GPIO_PU4);
447         return 0;
448 }
449
450 static void whistler_power_off(void)
451 {
452         int ret;
453
454         ret = max8907c_power_off();
455         if (ret)
456                 pr_err("whistler: failed to power off\n");
457
458         while (1);
459 }
460
461 static void __init whistler_power_off_init(void)
462 {
463         pm_power_off = whistler_power_off;
464 }
465
466 static void whistler_usb_init(void)
467 {
468         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
469
470         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
471         platform_device_register(&tegra_otg_device);
472
473         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
474         platform_device_register(&tegra_ehci3_device);
475 }
476
477 static void __init tegra_whistler_init(void)
478 {
479         char serial[20];
480
481         tegra_clk_init_from_table(whistler_clk_init_table);
482         whistler_pinmux_init();
483         whistler_i2c_init();
484         whistler_uart_init();
485         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
486
487         whistler_sdhci_init();
488         whistler_regulator_init();
489         whistler_panel_init();
490         whistler_sensors_init();
491         whistler_kbc_init();
492         whistler_bt_rfkill();
493         whistler_gps_init();
494         whistler_usb_init();
495         whistler_scroll_init();
496         whistler_power_off_init();
497         whistler_emc_init();
498         whistler_baseband_init();
499         tegra_release_bootloader_fb();
500 }
501
502 int __init tegra_whistler_protected_aperture_init(void)
503 {
504         tegra_protected_aperture_init(tegra_grhost_aperture);
505         return 0;
506 }
507
508 void __init tegra_whistler_reserve(void)
509 {
510         if (memblock_reserve(0x0, 4096) < 0)
511                 pr_warn("Cannot reserve first 4K of memory for safety\n");
512
513         tegra_reserve(SZ_128M, SZ_8M, SZ_16M);
514 }
515
516 MACHINE_START(WHISTLER, "whistler")
517         .boot_params    = 0x00000100,
518         .map_io         = tegra_map_common_io,
519         .reserve        = tegra_whistler_reserve,
520         .init_early     = tegra_init_early,
521         .init_irq       = tegra_init_irq,
522         .timer          = &tegra_timer,
523         .init_machine   = tegra_whistler_init,
524 MACHINE_END