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