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