arm: tegra: whistler: Remove wrong spkr_en gpio entry
[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 #ifdef CONFIG_BT_BLUESLEEP
189 static noinline void __init tegra_setup_bluesleep(void)
190 {
191         struct platform_device *pdev = NULL;
192         struct resource *res;
193
194         pdev = platform_device_alloc("bluesleep", 0);
195         if (!pdev) {
196                 pr_err("unable to allocate platform device for bluesleep");
197                 return;
198         }
199
200         res = kzalloc(sizeof(struct resource) * 3, GFP_KERNEL);
201         if (!res) {
202                 pr_err("unable to allocate resource for bluesleep\n");
203                 goto err_free_dev;
204         }
205
206         res[0].name   = "gpio_host_wake";
207         res[0].start  = TEGRA_GPIO_PU6;
208         res[0].end    = TEGRA_GPIO_PU6;
209         res[0].flags  = IORESOURCE_IO;
210
211         res[1].name   = "gpio_ext_wake";
212         res[1].start  = TEGRA_GPIO_PU1;
213         res[1].end    = TEGRA_GPIO_PU1;
214         res[1].flags  = IORESOURCE_IO;
215
216         res[2].name   = "host_wake";
217         res[2].start  = gpio_to_irq(TEGRA_GPIO_PU6);
218         res[2].end    = gpio_to_irq(TEGRA_GPIO_PU6);
219         res[2].flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE;
220
221         if (platform_device_add_resources(pdev, res, 3)) {
222                 pr_err("unable to add resources to bluesleep device\n");
223                 goto err_free_res;
224         }
225
226         if (platform_device_add(pdev)) {
227                 pr_err("unable to add bluesleep device\n");
228                 goto err_free_res;
229         }
230
231         tegra_gpio_enable(TEGRA_GPIO_PU6);
232         tegra_gpio_enable(TEGRA_GPIO_PU1);
233
234         return;
235
236 err_free_res:
237         kfree(res);
238 err_free_dev:
239         platform_device_put(pdev);
240         return;
241 }
242 #else
243 static inline void tegra_setup_bluesleep(void) { }
244 #endif
245
246 static struct tegra_utmip_config utmi_phy_config[] = {
247         [0] = {
248                         .hssync_start_delay = 9,
249                         .idle_wait_delay = 17,
250                         .elastic_limit = 16,
251                         .term_range_adj = 6,
252                         .xcvr_setup = 15,
253                         .xcvr_lsfslew = 2,
254                         .xcvr_lsrslew = 2,
255                 },
256         [1] = {
257                         .hssync_start_delay = 9,
258                         .idle_wait_delay = 17,
259                         .elastic_limit = 16,
260                         .term_range_adj = 6,
261                         .xcvr_setup = 8,
262                         .xcvr_lsfslew = 2,
263                         .xcvr_lsrslew = 2,
264                 },
265 };
266
267 static struct tegra_ulpi_config ulpi_phy_config = {
268         .reset_gpio = TEGRA_GPIO_PG2,
269         .clk = "clk_dev2",
270 };
271
272 static __initdata struct tegra_clk_init_table whistler_clk_init_table[] = {
273         /* name         parent          rate            enabled */
274         { "pwm",        "clk_32k",      32768,          false},
275         { "kbc",        "clk_32k",      32768,          true},
276         { "sdmmc2",     "pll_p",        25000000,       false},
277         { "i2s1",       "pll_a_out0",   0,              false},
278         { "i2s2",       "pll_a_out0",   0,              false},
279         { "spdif_out",  "pll_a_out0",   0,              false},
280         { NULL,         NULL,           0,              0},
281 };
282
283 static struct tegra_i2c_platform_data whistler_i2c1_platform_data = {
284         .adapter_nr     = 0,
285         .bus_count      = 1,
286         .bus_clk_rate   = { 400000, 0 },
287 };
288
289 static const struct tegra_pingroup_config i2c2_ddc = {
290         .pingroup       = TEGRA_PINGROUP_DDC,
291         .func           = TEGRA_MUX_I2C2,
292 };
293
294 static const struct tegra_pingroup_config i2c2_gen2 = {
295         .pingroup       = TEGRA_PINGROUP_PTA,
296         .func           = TEGRA_MUX_I2C2,
297 };
298
299 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
300         .adapter_nr     = 1,
301         .bus_count      = 2,
302         .bus_clk_rate   = { 100000, 100000 },
303         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
304         .bus_mux_len    = { 1, 1 },
305 };
306
307 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
308         .adapter_nr     = 3,
309         .bus_count      = 1,
310         .bus_clk_rate   = { 400000, 0 },
311 };
312
313 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
314         .adapter_nr     = 4,
315         .bus_count      = 1,
316         .bus_clk_rate   = { 400000, 0 },
317         .is_dvc         = true,
318 };
319
320 static struct i2c_board_info __initdata wm8753_board_info = {
321         I2C_BOARD_INFO("wm8753", 0x1a),
322         .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_HP_DET),
323 };
324
325 static void whistler_i2c_init(void)
326 {
327         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
328         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
329         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
330         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
331
332         platform_device_register(&tegra_i2c_device4);
333         platform_device_register(&tegra_i2c_device3);
334         platform_device_register(&tegra_i2c_device2);
335         platform_device_register(&tegra_i2c_device1);
336
337         i2c_register_board_info(4, &wm8753_board_info, 1);
338 }
339
340 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
341 {       \
342         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
343         .gpio = TEGRA_GPIO_##_gpio,     \
344         .desc = _desc,  \
345         .active_low = 1,        \
346         .debounce_interval = 2, \
347 }
348
349 static struct gpio_scrollwheel_button scroll_keys[] = {
350         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
351         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
352         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
353         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
354 };
355
356 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
357         .buttons = scroll_keys,
358         .nbuttons = ARRAY_SIZE(scroll_keys),
359 };
360
361 static struct platform_device whistler_scroll_device = {
362         .name   = "alps-gpio-scrollwheel",
363         .id     = 0,
364         .dev    = {
365                 .platform_data  = &whistler_scroll_platform_data,
366         },
367 };
368
369 static struct platform_device tegra_camera = {
370         .name = "tegra_camera",
371         .id = -1,
372 };
373
374 static struct tegra_wm8753_platform_data whistler_audio_pdata = {
375         .gpio_spkr_en = -1,
376         .gpio_hp_det = TEGRA_GPIO_HP_DET,
377         .gpio_hp_mute = -1,
378         .gpio_int_mic_en = -1,
379         .gpio_ext_mic_en = -1,
380         .debounce_time_hp = 200,
381 };
382
383 static struct platform_device whistler_audio_device = {
384         .name   = "tegra-snd-wm8753",
385         .id     = 0,
386         .dev    = {
387                 .platform_data  = &whistler_audio_pdata,
388         },
389 };
390
391 static struct platform_device *whistler_devices[] __initdata = {
392         &tegra_pmu_device,
393         &tegra_udc_device,
394         &tegra_gart_device,
395         &tegra_wdt_device,
396         &tegra_avp_device,
397         &whistler_scroll_device,
398         &tegra_camera,
399         &tegra_i2s_device1,
400         &tegra_i2s_device2,
401         &tegra_spdif_device,
402         &tegra_das_device,
403         &spdif_dit_device,
404         &bluetooth_dit_device,
405         &tegra_pcm_device,
406         &whistler_audio_device,
407 };
408
409 static int __init whistler_scroll_init(void)
410 {
411         int i;
412         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
413                 tegra_gpio_enable(scroll_keys[i].gpio);
414
415         return 0;
416 }
417
418 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
419         [0] = {
420                         .instance = 0,
421                         .vbus_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
422                         .vbus_gpio = TEGRA_GPIO_PN6,
423         },
424         [1] = {
425                         .instance = 1,
426                         .vbus_gpio = -1,
427         },
428         [2] = {
429                         .instance = 2,
430                         .vbus_gpio = -1,
431         },
432 };
433
434 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
435         [0] = {
436                         .phy_config = &utmi_phy_config[0],
437                         .operating_mode = TEGRA_USB_HOST,
438                         .power_down_on_bus_suspend = 1,
439                 },
440         [1] = {
441                         .phy_config = &ulpi_phy_config,
442                         .operating_mode = TEGRA_USB_HOST,
443                         .power_down_on_bus_suspend = 1,
444                 },
445         [2] = {
446                         .phy_config = &utmi_phy_config[1],
447                         .operating_mode = TEGRA_USB_HOST,
448                         .power_down_on_bus_suspend = 1,
449         },
450 };
451
452 static struct tegra_otg_platform_data tegra_otg_pdata = {
453         .ehci_device = &tegra_ehci1_device,
454         .ehci_pdata = &tegra_ehci_pdata[0],
455 };
456
457 static int __init whistler_gps_init(void)
458 {
459         tegra_gpio_enable(TEGRA_GPIO_PU4);
460         return 0;
461 }
462
463 static void whistler_power_off(void)
464 {
465         int ret;
466
467         ret = max8907c_power_off();
468         if (ret)
469                 pr_err("whistler: failed to power off\n");
470
471         while (1);
472 }
473
474 static void __init whistler_power_off_init(void)
475 {
476         pm_power_off = whistler_power_off;
477 }
478
479 static void whistler_usb_init(void)
480 {
481         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
482
483         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
484         platform_device_register(&tegra_otg_device);
485
486         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
487         platform_device_register(&tegra_ehci3_device);
488 }
489
490 static void __init tegra_whistler_init(void)
491 {
492         char serial[20];
493
494         tegra_clk_init_from_table(whistler_clk_init_table);
495         whistler_pinmux_init();
496         whistler_i2c_init();
497         whistler_uart_init();
498         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
499
500         whistler_sdhci_init();
501         whistler_regulator_init();
502         whistler_panel_init();
503         whistler_sensors_init();
504         whistler_kbc_init();
505         whistler_bt_rfkill();
506         whistler_gps_init();
507         whistler_usb_init();
508         whistler_scroll_init();
509         whistler_power_off_init();
510         whistler_emc_init();
511         whistler_baseband_init();
512 #ifdef CONFIG_BT_BLUESLEEP
513         tegra_setup_bluesleep();
514 #endif
515         tegra_release_bootloader_fb();
516 }
517
518 int __init tegra_whistler_protected_aperture_init(void)
519 {
520         tegra_protected_aperture_init(tegra_grhost_aperture);
521         return 0;
522 }
523
524 void __init tegra_whistler_reserve(void)
525 {
526         if (memblock_reserve(0x0, 4096) < 0)
527                 pr_warn("Cannot reserve first 4K of memory for safety\n");
528
529         tegra_reserve(SZ_128M, SZ_8M, SZ_16M);
530 }
531
532 MACHINE_START(WHISTLER, "whistler")
533         .boot_params    = 0x00000100,
534         .map_io         = tegra_map_common_io,
535         .reserve        = tegra_whistler_reserve,
536         .init_early     = tegra_init_early,
537         .init_irq       = tegra_init_irq,
538         .timer          = &tegra_timer,
539         .init_machine   = tegra_whistler_init,
540 MACHINE_END