Merge branch 'x86/header-guards' into x86-v28-for-linus-phase1
[linux-2.6] / drivers / usb / host / ohci-ep93xx.c
1 /*
2  * OHCI HCD (Host Controller Driver) for USB.
3  *
4  * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5  * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6  * (C) Copyright 2002 Hewlett-Packard Company
7  *
8  * Bus Glue for ep93xx.
9  *
10  * Written by Christopher Hoover <ch@hpl.hp.com>
11  * Based on fragments of previous driver by Russell King et al.
12  *
13  * Modified for LH7A404 from ohci-sa1111.c
14  *  by Durgesh Pattamatta <pattamattad@sharpsec.com>
15  *
16  * Modified for pxa27x from ohci-lh7a404.c
17  *  by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
18  *
19  * Modified for ep93xx from ohci-pxa27x.c
20  *  by Lennert Buytenhek <buytenh@wantstofly.org> 28-2-2006
21  *  Based on an earlier driver by Ray Lehtiniemi
22  *
23  * This file is licenced under the GPL.
24  */
25
26 #include <linux/clk.h>
27 #include <linux/device.h>
28 #include <linux/signal.h>
29 #include <linux/platform_device.h>
30
31 #include <mach/hardware.h>
32
33 static struct clk *usb_host_clock;
34
35 static void ep93xx_start_hc(struct device *dev)
36 {
37         clk_enable(usb_host_clock);
38 }
39
40 static void ep93xx_stop_hc(struct device *dev)
41 {
42         clk_disable(usb_host_clock);
43 }
44
45 static int usb_hcd_ep93xx_probe(const struct hc_driver *driver,
46                          struct platform_device *pdev)
47 {
48         int retval;
49         struct usb_hcd *hcd;
50
51         if (pdev->resource[1].flags != IORESOURCE_IRQ) {
52                 pr_debug("resource[1] is not IORESOURCE_IRQ");
53                 return -ENOMEM;
54         }
55
56         hcd = usb_create_hcd(driver, &pdev->dev, "ep93xx");
57         if (hcd == NULL)
58                 return -ENOMEM;
59
60         hcd->rsrc_start = pdev->resource[0].start;
61         hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
62         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
63                 usb_put_hcd(hcd);
64                 retval = -EBUSY;
65                 goto err1;
66         }
67
68         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
69         if (hcd->regs == NULL) {
70                 pr_debug("ioremap failed");
71                 retval = -ENOMEM;
72                 goto err2;
73         }
74
75         usb_host_clock = clk_get(&pdev->dev, "usb_host");
76         ep93xx_start_hc(&pdev->dev);
77
78         ohci_hcd_init(hcd_to_ohci(hcd));
79
80         retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
81         if (retval == 0)
82                 return retval;
83
84         ep93xx_stop_hc(&pdev->dev);
85         iounmap(hcd->regs);
86 err2:
87         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
88 err1:
89         usb_put_hcd(hcd);
90
91         return retval;
92 }
93
94 static void usb_hcd_ep93xx_remove(struct usb_hcd *hcd,
95                         struct platform_device *pdev)
96 {
97         usb_remove_hcd(hcd);
98         ep93xx_stop_hc(&pdev->dev);
99         clk_put(usb_host_clock);
100         iounmap(hcd->regs);
101         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
102         usb_put_hcd(hcd);
103 }
104
105 static int __devinit ohci_ep93xx_start(struct usb_hcd *hcd)
106 {
107         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
108         int ret;
109
110         if ((ret = ohci_init(ohci)) < 0)
111                 return ret;
112
113         if ((ret = ohci_run(ohci)) < 0) {
114                 err("can't start %s", hcd->self.bus_name);
115                 ohci_stop(hcd);
116                 return ret;
117         }
118
119         return 0;
120 }
121
122 static struct hc_driver ohci_ep93xx_hc_driver = {
123         .description            = hcd_name,
124         .product_desc           = "EP93xx OHCI",
125         .hcd_priv_size          = sizeof(struct ohci_hcd),
126         .irq                    = ohci_irq,
127         .flags                  = HCD_USB11 | HCD_MEMORY,
128         .start                  = ohci_ep93xx_start,
129         .stop                   = ohci_stop,
130         .shutdown               = ohci_shutdown,
131         .urb_enqueue            = ohci_urb_enqueue,
132         .urb_dequeue            = ohci_urb_dequeue,
133         .endpoint_disable       = ohci_endpoint_disable,
134         .get_frame_number       = ohci_get_frame,
135         .hub_status_data        = ohci_hub_status_data,
136         .hub_control            = ohci_hub_control,
137 #ifdef CONFIG_PM
138         .bus_suspend            = ohci_bus_suspend,
139         .bus_resume             = ohci_bus_resume,
140 #endif
141         .start_port_reset       = ohci_start_port_reset,
142 };
143
144 extern int usb_disabled(void);
145
146 static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
147 {
148         int ret;
149
150         ret = -ENODEV;
151         if (!usb_disabled())
152                 ret = usb_hcd_ep93xx_probe(&ohci_ep93xx_hc_driver, pdev);
153
154         return ret;
155 }
156
157 static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
158 {
159         struct usb_hcd *hcd = platform_get_drvdata(pdev);
160
161         usb_hcd_ep93xx_remove(hcd, pdev);
162
163         return 0;
164 }
165
166 #ifdef CONFIG_PM
167 static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
168 {
169         struct usb_hcd *hcd = platform_get_drvdata(pdev);
170         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
171
172         if (time_before(jiffies, ohci->next_statechange))
173                 msleep(5);
174         ohci->next_statechange = jiffies;
175
176         ep93xx_stop_hc(&pdev->dev);
177         hcd->state = HC_STATE_SUSPENDED;
178
179         return 0;
180 }
181
182 static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
183 {
184         struct usb_hcd *hcd = platform_get_drvdata(pdev);
185         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
186         int status;
187
188         if (time_before(jiffies, ohci->next_statechange))
189                 msleep(5);
190         ohci->next_statechange = jiffies;
191
192         ep93xx_start_hc(&pdev->dev);
193
194         ohci_finish_controller_resume(hcd);
195         return 0;
196 }
197 #endif
198
199
200 static struct platform_driver ohci_hcd_ep93xx_driver = {
201         .probe          = ohci_hcd_ep93xx_drv_probe,
202         .remove         = ohci_hcd_ep93xx_drv_remove,
203         .shutdown       = usb_hcd_platform_shutdown,
204 #ifdef CONFIG_PM
205         .suspend        = ohci_hcd_ep93xx_drv_suspend,
206         .resume         = ohci_hcd_ep93xx_drv_resume,
207 #endif
208         .driver         = {
209                 .name   = "ep93xx-ohci",
210                 .owner  = THIS_MODULE,
211         },
212 };
213
214 MODULE_ALIAS("platform:ep93xx-ohci");