ARM: tegra: whistler: power down usb3 on suspend
[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
40 #include <mach/clk.h>
41 #include <mach/iomap.h>
42 #include <mach/irqs.h>
43 #include <mach/pinmux.h>
44 #include <mach/iomap.h>
45 #include <mach/io.h>
46
47 #include <asm/mach-types.h>
48 #include <asm/mach/arch.h>
49 #include <mach/usb_phy.h>
50
51 #include "board.h"
52 #include "clock.h"
53 #include "board-whistler.h"
54 #include "devices.h"
55 #include "gpio-names.h"
56 #include "fuse.h"
57
58 static struct plat_serial8250_port debug_uart_platform_data[] = {
59         {
60                 .membase        = IO_ADDRESS(TEGRA_UARTA_BASE),
61                 .mapbase        = TEGRA_UARTA_BASE,
62                 .irq            = INT_UARTA,
63                 .flags          = UPF_BOOT_AUTOCONF,
64                 .iotype         = UPIO_MEM,
65                 .regshift       = 2,
66                 .uartclk        = 216000000,
67         }, {
68                 .flags          = 0,
69         }
70 };
71
72 static struct platform_device debug_uart = {
73         .name = "serial8250",
74         .id = PLAT8250_DEV_PLATFORM,
75         .dev = {
76                 .platform_data = debug_uart_platform_data,
77         },
78 };
79
80 #ifdef CONFIG_BCM4329_RFKILL
81
82 static struct resource whistler_bcm4329_rfkill_resources[] = {
83         {
84                 .name   = "bcm4329_nshutdown_gpio",
85                 .start  = TEGRA_GPIO_PU0,
86                 .end    = TEGRA_GPIO_PU0,
87                 .flags  = IORESOURCE_IO,
88         },
89 };
90
91 static struct platform_device whistler_bcm4329_rfkill_device = {
92         .name           = "bcm4329_rfkill",
93         .id             = -1,
94         .num_resources  = ARRAY_SIZE(whistler_bcm4329_rfkill_resources),
95         .resource       = whistler_bcm4329_rfkill_resources,
96 };
97
98 static noinline void __init whistler_bt_rfkill(void)
99 {
100         platform_device_register(&whistler_bcm4329_rfkill_device);
101         return;
102 }
103 #else
104 static inline void whistler_bt_rfkill(void) { }
105 #endif
106
107 static struct tegra_utmip_config utmi_phy_config[] = {
108         [0] = {
109                         .hssync_start_delay = 0,
110                         .idle_wait_delay = 17,
111                         .elastic_limit = 16,
112                         .term_range_adj = 6,
113                         .xcvr_setup = 15,
114                         .xcvr_lsfslew = 2,
115                         .xcvr_lsrslew = 2,
116                 },
117         [1] = {
118                         .hssync_start_delay = 0,
119                         .idle_wait_delay = 17,
120                         .elastic_limit = 16,
121                         .term_range_adj = 6,
122                         .xcvr_setup = 8,
123                         .xcvr_lsfslew = 2,
124                         .xcvr_lsrslew = 2,
125                 },
126 };
127
128 static struct tegra_ulpi_config ulpi_phy_config = {
129         .reset_gpio = TEGRA_GPIO_PG2,
130         .clk = "clk_dev2",
131         .inf_type = TEGRA_USB_LINK_ULPI,
132 };
133
134 static __initdata struct tegra_clk_init_table whistler_clk_init_table[] = {
135         /* name         parent          rate            enabled */
136         { "uarta",      "pll_p",        216000000,      true},
137         { "uartc",      "pll_m",        600000000,      false},
138         { "pwm",        "clk_32k",      32768,          false},
139         { "kbc",        "clk_32k",      32768,          true},
140         { "sdmmc2",     "pll_p",        25000000,       false},
141         { NULL,         NULL,           0,              0},
142 };
143
144 static struct tegra_i2c_platform_data whistler_i2c1_platform_data = {
145         .adapter_nr     = 0,
146         .bus_count      = 1,
147         .bus_clk_rate   = { 400000, 0 },
148 };
149
150 static const struct tegra_pingroup_config i2c2_ddc = {
151         .pingroup       = TEGRA_PINGROUP_DDC,
152         .func           = TEGRA_MUX_I2C2,
153 };
154
155 static const struct tegra_pingroup_config i2c2_gen2 = {
156         .pingroup       = TEGRA_PINGROUP_PTA,
157         .func           = TEGRA_MUX_I2C2,
158 };
159
160 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
161         .adapter_nr     = 1,
162         .bus_count      = 2,
163         .bus_clk_rate   = { 400000, 100000 },
164         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
165         .bus_mux_len    = { 1, 1 },
166 };
167
168 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
169         .adapter_nr     = 3,
170         .bus_count      = 1,
171         .bus_clk_rate   = { 400000, 0 },
172 };
173
174 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
175         .adapter_nr     = 4,
176         .bus_count      = 1,
177         .bus_clk_rate   = { 400000, 0 },
178         .is_dvc         = true,
179 };
180
181 static void whistler_i2c_init(void)
182 {
183         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
184         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
185         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
186         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
187
188         platform_device_register(&tegra_i2c_device4);
189         platform_device_register(&tegra_i2c_device3);
190         platform_device_register(&tegra_i2c_device2);
191         platform_device_register(&tegra_i2c_device1);
192 }
193
194 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
195 {       \
196         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
197         .gpio = TEGRA_GPIO_##_gpio,     \
198         .desc = _desc,  \
199         .active_low = 1,        \
200         .debounce_interval = 2, \
201 }
202
203 static struct gpio_scrollwheel_button scroll_keys[] = {
204         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
205         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
206         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
207         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
208 };
209
210 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
211         .buttons = scroll_keys,
212         .nbuttons = ARRAY_SIZE(scroll_keys),
213 };
214
215 static struct platform_device whistler_scroll_device = {
216         .name   = "alps-gpio-scrollwheel",
217         .id     = 0,
218         .dev    = {
219                 .platform_data  = &whistler_scroll_platform_data,
220         },
221 };
222
223 static struct platform_device tegra_camera = {
224         .name = "tegra_camera",
225         .id = -1,
226 };
227
228 static struct platform_device *whistler_devices[] __initdata = {
229         &tegra_uartb_device,
230         &tegra_uartc_device,
231         &pmu_device,
232         &tegra_udc_device,
233         &tegra_gart_device,
234         &tegra_wdt_device,
235         &tegra_avp_device,
236         &whistler_scroll_device,
237         &tegra_camera,
238 };
239
240 static int __init whistler_scroll_init(void)
241 {
242         int i;
243         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
244                 tegra_gpio_enable(scroll_keys[i].gpio);
245
246         return 0;
247 }
248
249 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
250         [0] = {
251                         .instance = 0,
252                         .vbus_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
253                         .vbus_gpio = TEGRA_GPIO_PN6,
254         },
255         [1] = {
256                         .instance = 1,
257                         .vbus_gpio = -1,
258         },
259         [2] = {
260                         .instance = 2,
261                         .vbus_gpio = -1,
262         },
263 };
264
265 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
266         [0] = {
267                         .phy_config = &utmi_phy_config[0],
268                         .operating_mode = TEGRA_USB_HOST,
269                         .power_down_on_bus_suspend = 1,
270                 },
271         [1] = {
272                         .phy_config = &ulpi_phy_config,
273                         .operating_mode = TEGRA_USB_HOST,
274                         .power_down_on_bus_suspend = 1,
275                 },
276         [2] = {
277                         .phy_config = &utmi_phy_config[1],
278                         .operating_mode = TEGRA_USB_HOST,
279                         .power_down_on_bus_suspend = 1,
280         },
281 };
282
283 static struct platform_device *tegra_usb_otg_host_register(void)
284 {
285         struct platform_device *pdev;
286         void *platform_data;
287         int val;
288
289         pdev = platform_device_alloc(tegra_ehci1_device.name,
290                         tegra_ehci1_device.id);
291         if (!pdev)
292                 return NULL;
293
294         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
295                 tegra_ehci1_device.num_resources);
296         if (val)
297                 goto error;
298
299         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
300         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
301
302         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
303                                 GFP_KERNEL);
304         if (!platform_data)
305                 goto error;
306
307         memcpy(platform_data, &tegra_ehci_pdata[0],
308                                 sizeof(struct tegra_ehci_platform_data));
309         pdev->dev.platform_data = platform_data;
310
311         val = platform_device_add(pdev);
312         if (val)
313                 goto error_add;
314
315         return pdev;
316
317 error_add:
318         kfree(platform_data);
319 error:
320         pr_err("%s: failed to add the host contoller device\n", __func__);
321         platform_device_put(pdev);
322         return NULL;
323 }
324
325 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
326 {
327         kfree(pdev->dev.platform_data);
328         platform_device_unregister(pdev);
329 }
330
331 static struct tegra_otg_platform_data tegra_otg_pdata = {
332         .host_register = &tegra_usb_otg_host_register,
333         .host_unregister = &tegra_usb_otg_host_unregister,
334 };
335
336 static int __init whistler_gps_init(void)
337 {
338         tegra_gpio_enable(TEGRA_GPIO_PU4);
339         return 0;
340 }
341
342 static void whistler_power_off(void)
343 {
344         int ret;
345
346         ret = max8907c_power_off();
347         if (ret)
348                 pr_err("whistler: failed to power off\n");
349
350         while (1);
351 }
352
353 static void __init whistler_power_off_init(void)
354 {
355         pm_power_off = whistler_power_off;
356 }
357
358 static void whistler_usb_init(void)
359 {
360         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
361
362         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
363         platform_device_register(&tegra_otg_device);
364
365         tegra_ehci3_device.dev.platform_data=&tegra_ehci_pdata[2];
366         platform_device_register(&tegra_ehci3_device);
367 }
368
369 static void __init tegra_whistler_init(void)
370 {
371         char serial[20];
372
373         tegra_common_init();
374         tegra_clk_init_from_table(whistler_clk_init_table);
375         whistler_pinmux_init();
376         whistler_i2c_init();
377         if (is_tegra_debug_uartport_hs() == true)
378                 platform_device_register(&tegra_uarta_device);
379         else
380                 platform_device_register(&debug_uart);
381         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
382
383         whistler_sdhci_init();
384         whistler_regulator_init();
385         whistler_panel_init();
386         whistler_sensors_init();
387         whistler_kbc_init();
388         whistler_bt_rfkill();
389         whistler_gps_init();
390         whistler_usb_init();
391         whistler_scroll_init();
392         whistler_power_off_init();
393         whistler_emc_init();
394 }
395
396 int __init tegra_whistler_protected_aperture_init(void)
397 {
398         tegra_protected_aperture_init(tegra_grhost_aperture);
399         return 0;
400 }
401
402 void __init tegra_whistler_reserve(void)
403 {
404         if (memblock_reserve(0x0, 4096) < 0)
405                 pr_warn("Cannot reserve first 4K of memory for safety\n");
406
407         tegra_reserve(SZ_128M, SZ_8M, SZ_16M);
408 }
409
410 MACHINE_START(WHISTLER, "whistler")
411         .boot_params    = 0x00000100,
412         .phys_io        = IO_APB_PHYS,
413         .io_pg_offst    = ((IO_APB_VIRT) >> 18) & 0xfffc,
414         .init_irq       = tegra_init_irq,
415         .init_machine   = tegra_whistler_init,
416         .map_io         = tegra_map_common_io,
417         .reserve        = tegra_whistler_reserve,
418         .timer          = &tegra_timer,
419 MACHINE_END