sfc: Don't use enums as a bitmask.
[zen-stable.git] / drivers / usb / host / ohci-ep93xx.c
blob4e681613e7ae1fc846b42c40b8db5f4b8ffa97eb
1 /*
2 * OHCI HCD (Host Controller Driver) for USB.
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
8 * Bus Glue for ep93xx.
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
13 * Modified for LH7A404 from ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
16 * Modified for pxa27x from ohci-lh7a404.c
17 * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
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
23 * This file is licenced under the GPL.
26 #include <linux/clk.h>
27 #include <linux/device.h>
28 #include <linux/signal.h>
29 #include <linux/platform_device.h>
31 static struct clk *usb_host_clock;
33 static void ep93xx_start_hc(struct device *dev)
35 clk_enable(usb_host_clock);
38 static void ep93xx_stop_hc(struct device *dev)
40 clk_disable(usb_host_clock);
43 static int usb_hcd_ep93xx_probe(const struct hc_driver *driver,
44 struct platform_device *pdev)
46 int retval;
47 struct usb_hcd *hcd;
49 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
50 dbg("resource[1] is not IORESOURCE_IRQ");
51 return -ENOMEM;
54 hcd = usb_create_hcd(driver, &pdev->dev, "ep93xx");
55 if (hcd == NULL)
56 return -ENOMEM;
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;
66 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
67 if (hcd->regs == NULL) {
68 dbg("ioremap failed");
69 retval = -ENOMEM;
70 goto err2;
73 usb_host_clock = clk_get(&pdev->dev, NULL);
74 if (IS_ERR(usb_host_clock)) {
75 dbg("clk_get failed");
76 retval = PTR_ERR(usb_host_clock);
77 goto err3;
80 ep93xx_start_hc(&pdev->dev);
82 ohci_hcd_init(hcd_to_ohci(hcd));
84 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED);
85 if (retval == 0)
86 return retval;
88 ep93xx_stop_hc(&pdev->dev);
89 err3:
90 iounmap(hcd->regs);
91 err2:
92 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
93 err1:
94 usb_put_hcd(hcd);
96 return retval;
99 static void usb_hcd_ep93xx_remove(struct usb_hcd *hcd,
100 struct platform_device *pdev)
102 usb_remove_hcd(hcd);
103 ep93xx_stop_hc(&pdev->dev);
104 clk_put(usb_host_clock);
105 iounmap(hcd->regs);
106 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
107 usb_put_hcd(hcd);
110 static int __devinit ohci_ep93xx_start(struct usb_hcd *hcd)
112 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
113 int ret;
115 if ((ret = ohci_init(ohci)) < 0)
116 return ret;
118 if ((ret = ohci_run(ohci)) < 0) {
119 err("can't start %s", hcd->self.bus_name);
120 ohci_stop(hcd);
121 return ret;
124 return 0;
127 static struct hc_driver ohci_ep93xx_hc_driver = {
128 .description = hcd_name,
129 .product_desc = "EP93xx OHCI",
130 .hcd_priv_size = sizeof(struct ohci_hcd),
131 .irq = ohci_irq,
132 .flags = HCD_USB11 | HCD_MEMORY,
133 .start = ohci_ep93xx_start,
134 .stop = ohci_stop,
135 .shutdown = ohci_shutdown,
136 .urb_enqueue = ohci_urb_enqueue,
137 .urb_dequeue = ohci_urb_dequeue,
138 .endpoint_disable = ohci_endpoint_disable,
139 .get_frame_number = ohci_get_frame,
140 .hub_status_data = ohci_hub_status_data,
141 .hub_control = ohci_hub_control,
142 #ifdef CONFIG_PM
143 .bus_suspend = ohci_bus_suspend,
144 .bus_resume = ohci_bus_resume,
145 #endif
146 .start_port_reset = ohci_start_port_reset,
149 extern int usb_disabled(void);
151 static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
153 int ret;
155 ret = -ENODEV;
156 if (!usb_disabled())
157 ret = usb_hcd_ep93xx_probe(&ohci_ep93xx_hc_driver, pdev);
159 return ret;
162 static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
164 struct usb_hcd *hcd = platform_get_drvdata(pdev);
166 usb_hcd_ep93xx_remove(hcd, pdev);
168 return 0;
171 #ifdef CONFIG_PM
172 static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
174 struct usb_hcd *hcd = platform_get_drvdata(pdev);
175 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
177 if (time_before(jiffies, ohci->next_statechange))
178 msleep(5);
179 ohci->next_statechange = jiffies;
181 ep93xx_stop_hc(&pdev->dev);
182 hcd->state = HC_STATE_SUSPENDED;
184 return 0;
187 static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
189 struct usb_hcd *hcd = platform_get_drvdata(pdev);
190 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
192 if (time_before(jiffies, ohci->next_statechange))
193 msleep(5);
194 ohci->next_statechange = jiffies;
196 ep93xx_start_hc(&pdev->dev);
198 ohci_finish_controller_resume(hcd);
199 return 0;
201 #endif
204 static struct platform_driver ohci_hcd_ep93xx_driver = {
205 .probe = ohci_hcd_ep93xx_drv_probe,
206 .remove = ohci_hcd_ep93xx_drv_remove,
207 .shutdown = usb_hcd_platform_shutdown,
208 #ifdef CONFIG_PM
209 .suspend = ohci_hcd_ep93xx_drv_suspend,
210 .resume = ohci_hcd_ep93xx_drv_resume,
211 #endif
212 .driver = {
213 .name = "ep93xx-ohci",
214 .owner = THIS_MODULE,
218 MODULE_ALIAS("platform:ep93xx-ohci");