Merge branch 'for-linus' of git://neil.brown.name/md
[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 static struct clk *usb_host_clock;
32
33 static void ep93xx_start_hc(struct device *dev)
34 {
35         clk_enable(usb_host_clock);
36 }
37
38 static void ep93xx_stop_hc(struct device *dev)
39 {
40         clk_disable(usb_host_clock);
41 }
42
43 static int usb_hcd_ep93xx_probe(const struct hc_driver *driver,
44                          struct platform_device *pdev)
45 {
46         int retval;
47         struct usb_hcd *hcd;
48
49         if (pdev->resource[1].flags != IORESOURCE_IRQ) {
50                 pr_debug("resource[1] is not IORESOURCE_IRQ");
51                 return -ENOMEM;
52         }
53
54         hcd = usb_create_hcd(driver, &pdev->dev, "ep93xx");
55         if (hcd == NULL)
56                 return -ENOMEM;
57
58         hcd->rsrc_start = pdev->resource[0].start;
59         hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
60         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
61                 usb_put_hcd(hcd);
62                 retval = -EBUSY;
63                 goto err1;
64         }
65
66         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
67         if (hcd->regs == NULL) {
68                 pr_debug("ioremap failed");
69                 retval = -ENOMEM;
70                 goto err2;
71         }
72
73         usb_host_clock = clk_get(&pdev->dev, "usb_host");
74         ep93xx_start_hc(&pdev->dev);
75
76         ohci_hcd_init(hcd_to_ohci(hcd));
77
78         retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
79         if (retval == 0)
80                 return retval;
81
82         ep93xx_stop_hc(&pdev->dev);
83         iounmap(hcd->regs);
84 err2:
85         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
86 err1:
87         usb_put_hcd(hcd);
88
89         return retval;
90 }
91
92 static void usb_hcd_ep93xx_remove(struct usb_hcd *hcd,
93                         struct platform_device *pdev)
94 {
95         usb_remove_hcd(hcd);
96         ep93xx_stop_hc(&pdev->dev);
97         clk_put(usb_host_clock);
98         iounmap(hcd->regs);
99         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
100         usb_put_hcd(hcd);
101 }
102
103 static int __devinit ohci_ep93xx_start(struct usb_hcd *hcd)
104 {
105         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
106         int ret;
107
108         if ((ret = ohci_init(ohci)) < 0)
109                 return ret;
110
111         if ((ret = ohci_run(ohci)) < 0) {
112                 err("can't start %s", hcd->self.bus_name);
113                 ohci_stop(hcd);
114                 return ret;
115         }
116
117         return 0;
118 }
119
120 static struct hc_driver ohci_ep93xx_hc_driver = {
121         .description            = hcd_name,
122         .product_desc           = "EP93xx OHCI",
123         .hcd_priv_size          = sizeof(struct ohci_hcd),
124         .irq                    = ohci_irq,
125         .flags                  = HCD_USB11 | HCD_MEMORY,
126         .start                  = ohci_ep93xx_start,
127         .stop                   = ohci_stop,
128         .shutdown               = ohci_shutdown,
129         .urb_enqueue            = ohci_urb_enqueue,
130         .urb_dequeue            = ohci_urb_dequeue,
131         .endpoint_disable       = ohci_endpoint_disable,
132         .get_frame_number       = ohci_get_frame,
133         .hub_status_data        = ohci_hub_status_data,
134         .hub_control            = ohci_hub_control,
135 #ifdef CONFIG_PM
136         .bus_suspend            = ohci_bus_suspend,
137         .bus_resume             = ohci_bus_resume,
138 #endif
139         .start_port_reset       = ohci_start_port_reset,
140 };
141
142 extern int usb_disabled(void);
143
144 static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
145 {
146         int ret;
147
148         ret = -ENODEV;
149         if (!usb_disabled())
150                 ret = usb_hcd_ep93xx_probe(&ohci_ep93xx_hc_driver, pdev);
151
152         return ret;
153 }
154
155 static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
156 {
157         struct usb_hcd *hcd = platform_get_drvdata(pdev);
158
159         usb_hcd_ep93xx_remove(hcd, pdev);
160
161         return 0;
162 }
163
164 #ifdef CONFIG_PM
165 static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
166 {
167         struct usb_hcd *hcd = platform_get_drvdata(pdev);
168         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
169
170         if (time_before(jiffies, ohci->next_statechange))
171                 msleep(5);
172         ohci->next_statechange = jiffies;
173
174         ep93xx_stop_hc(&pdev->dev);
175         hcd->state = HC_STATE_SUSPENDED;
176
177         return 0;
178 }
179
180 static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
181 {
182         struct usb_hcd *hcd = platform_get_drvdata(pdev);
183         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
184         int status;
185
186         if (time_before(jiffies, ohci->next_statechange))
187                 msleep(5);
188         ohci->next_statechange = jiffies;
189
190         ep93xx_start_hc(&pdev->dev);
191
192         ohci_finish_controller_resume(hcd);
193         return 0;
194 }
195 #endif
196
197
198 static struct platform_driver ohci_hcd_ep93xx_driver = {
199         .probe          = ohci_hcd_ep93xx_drv_probe,
200         .remove         = ohci_hcd_ep93xx_drv_remove,
201         .shutdown       = usb_hcd_platform_shutdown,
202 #ifdef CONFIG_PM
203         .suspend        = ohci_hcd_ep93xx_drv_suspend,
204         .resume         = ohci_hcd_ep93xx_drv_resume,
205 #endif
206         .driver         = {
207                 .name   = "ep93xx-ohci",
208                 .owner  = THIS_MODULE,
209         },
210 };
211
212 MODULE_ALIAS("platform:ep93xx-ohci");