]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-n800-usb.c
ARM: OMAP: Merge board specific files from N800 tree
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-n800-usb.c
1 /*
2  * linux/arch/arm/mach-omap2/board-n800-usb.c
3  *
4  * Copyright (C) 2006 Nokia Corporation
5  * Author: Juha Yrjola
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/types.h>
13 #include <linux/errno.h>
14 #include <linux/delay.h>
15 #include <linux/platform_device.h>
16 #include <linux/usb/musb.h>
17 #include <asm/arch/gpmc.h>
18 #include <asm/arch/gpio.h>
19
20 #define TUSB_ASYNC_CS           1
21 #define TUSB_SYNC_CS            4
22 #define GPIO_TUSB_INT           58
23 #define GPIO_TUSB_ENABLE        0
24
25 static int tusb_set_power(int state);
26
27 #if     defined(CONFIG_USB_MUSB_OTG)
28 #       define BOARD_MODE       MUSB_OTG
29 #elif   defined(CONFIG_USB_MUSB_PERIPHERAL)
30 #       define BOARD_MODE       MUSB_PERIPHERAL
31 #else   /* defined(CONFIG_USB_MUSB_HOST) */
32 #       define BOARD_MODE       MUSB_HOST
33 #endif
34
35 static struct musb_hdrc_platform_data tusb_data = {
36         .mode           = BOARD_MODE,
37         .multipoint     = 1,
38         .set_power      = tusb_set_power,
39         .min_power      = 25,   /* x2 = 50 mA drawn from VBUS as peripheral */
40 };
41
42 /*
43  * Enable or disable power to TUSB6010. When enabling, turn on 3.3 V and
44  * 1.5 V voltage regulators of PM companion chip. Companion chip will then
45  * provide then PGOOD signal to TUSB6010 which will release it from reset.
46  */
47 static int tusb_set_power(int state)
48 {
49         int i, retval = 0;
50
51         if (state) {
52                 omap_set_gpio_dataout(GPIO_TUSB_ENABLE, 1);
53                 msleep(1);
54
55                 /* Wait until TUSB6010 pulls INT pin down */
56                 i = 100;
57                 while (i && omap_get_gpio_datain(GPIO_TUSB_INT)) {
58                         msleep(1);
59                         i--;
60                 }
61
62                 if (!i) {
63                         printk(KERN_ERR "tusb: powerup failed\n");
64                         retval = -ENODEV;
65                 }
66         } else {
67                 omap_set_gpio_dataout(GPIO_TUSB_ENABLE, 0);
68                 msleep(10);
69         }
70
71         return retval;
72 }
73
74 void __init n800_usb_init(void)
75 {
76         int ret = 0;
77         static char     announce[] __initdata = KERN_INFO "TUSB 6010\n";
78
79         /* PM companion chip power control pin */
80         ret = omap_request_gpio(GPIO_TUSB_ENABLE);
81         if (ret != 0) {
82                 printk(KERN_ERR "Could not get TUSB power GPIO%i\n",
83                        GPIO_TUSB_ENABLE);
84                 return;
85         }
86         omap_set_gpio_direction(GPIO_TUSB_ENABLE, 0);
87
88         tusb_set_power(0);
89
90         ret = tusb6010_setup_interface(&tusb_data, TUSB6010_REFCLK_19, 2,
91                                         TUSB_ASYNC_CS, TUSB_SYNC_CS,
92                                         GPIO_TUSB_INT, 0x3f);
93         if (ret != 0)
94                 goto err;
95
96         printk(announce);
97
98         return;
99
100 err:
101         omap_free_gpio(GPIO_TUSB_ENABLE);
102 }