]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-n800-usb.c
Merge omap-drivers
[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/delay.h>
14 #include <linux/platform_device.h>
15 #include <linux/clk.h>
16 #include <linux/err.h>
17 #include <linux/usb/musb.h>
18 #include <asm/arch/gpmc.h>
19 #include <asm/arch/gpio.h>
20 #include <asm/arch/pm.h>
21
22 #define TUSB_ASYNC_CS           1
23 #define TUSB_SYNC_CS            4
24 #define GPIO_TUSB_INT           58
25 #define GPIO_TUSB_ENABLE        0
26
27 static int tusb_set_power(int state);
28 static int tusb_set_clock(struct clk *osc_ck, int state);
29
30 #if     defined(CONFIG_USB_MUSB_OTG)
31 #       define BOARD_MODE       MUSB_OTG
32 #elif   defined(CONFIG_USB_MUSB_PERIPHERAL)
33 #       define BOARD_MODE       MUSB_PERIPHERAL
34 #else   /* defined(CONFIG_USB_MUSB_HOST) */
35 #       define BOARD_MODE       MUSB_HOST
36 #endif
37
38 static struct musb_hdrc_platform_data tusb_data = {
39         .mode           = BOARD_MODE,
40         .multipoint     = 1,
41         .set_power      = tusb_set_power,
42         .set_clock      = tusb_set_clock,
43         .min_power      = 25,   /* x2 = 50 mA drawn from VBUS as peripheral */
44         .clock          = "osc_ck",
45 };
46
47 /*
48  * Enable or disable power to TUSB6010. When enabling, turn on 3.3 V and
49  * 1.5 V voltage regulators of PM companion chip. Companion chip will then
50  * provide then PGOOD signal to TUSB6010 which will release it from reset.
51  */
52 static int tusb_set_power(int state)
53 {
54         int i, retval = 0;
55
56         if (state) {
57                 omap_set_gpio_dataout(GPIO_TUSB_ENABLE, 1);
58                 msleep(1);
59
60                 /* Wait until TUSB6010 pulls INT pin down */
61                 i = 100;
62                 while (i && omap_get_gpio_datain(GPIO_TUSB_INT)) {
63                         msleep(1);
64                         i--;
65                 }
66
67                 if (!i) {
68                         printk(KERN_ERR "tusb: powerup failed\n");
69                         retval = -ENODEV;
70                 }
71         } else {
72                 omap_set_gpio_dataout(GPIO_TUSB_ENABLE, 0);
73                 msleep(10);
74         }
75
76         return retval;
77 }
78
79 static int              osc_ck_on;
80
81 static int tusb_set_clock(struct clk *osc_ck, int state)
82 {
83         if (state) {
84                 if (osc_ck_on > 0)
85                         return -ENODEV;
86
87                 omap2_block_sleep();
88                 clk_enable(osc_ck);
89                 osc_ck_on = 1;
90         } else {
91                 if (osc_ck_on == 0)
92                         return -ENODEV;
93
94                 clk_disable(osc_ck);
95                 osc_ck_on = 0;
96                 omap2_allow_sleep();
97         }
98
99         return 0;
100 }
101
102 void __init n800_usb_init(void)
103 {
104         int ret = 0;
105         static char     announce[] __initdata = KERN_INFO "TUSB 6010\n";
106
107         /* PM companion chip power control pin */
108         ret = omap_request_gpio(GPIO_TUSB_ENABLE);
109         if (ret != 0) {
110                 printk(KERN_ERR "Could not get TUSB power GPIO%i\n",
111                        GPIO_TUSB_ENABLE);
112                 return;
113         }
114         omap_set_gpio_direction(GPIO_TUSB_ENABLE, 0);
115
116         tusb_set_power(0);
117
118         ret = tusb6010_setup_interface(&tusb_data, TUSB6010_REFCLK_19, 2,
119                                         TUSB_ASYNC_CS, TUSB_SYNC_CS,
120                                         GPIO_TUSB_INT, 0x3f);
121         if (ret != 0)
122                 goto err;
123
124         printk(announce);
125
126         return;
127
128 err:
129         omap_free_gpio(GPIO_TUSB_ENABLE);
130 }