xhci: Fix invalid loop check in xhci_free_tt_info()
[pandora-kernel.git] / drivers / usb / host / ohci-au1xxx.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 AMD Alchemy Au1xxx
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  * Modified for AMD Alchemy Au1xxx
16  *  by Matt Porter <mporter@kernel.crashing.org>
17  *
18  * This file is licenced under the GPL.
19  */
20
21 #include <linux/platform_device.h>
22 #include <linux/signal.h>
23
24 #include <asm/mach-au1x00/au1000.h>
25
26
27 extern int usb_disabled(void);
28
29 static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd)
30 {
31         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
32         int ret;
33
34         ohci_dbg(ohci, "ohci_au1xxx_start, ohci:%p", ohci);
35
36         if ((ret = ohci_init(ohci)) < 0)
37                 return ret;
38
39         if ((ret = ohci_run(ohci)) < 0) {
40                 err ("can't start %s", hcd->self.bus_name);
41                 ohci_stop(hcd);
42                 return ret;
43         }
44
45         return 0;
46 }
47
48 static const struct hc_driver ohci_au1xxx_hc_driver = {
49         .description =          hcd_name,
50         .product_desc =         "Au1xxx OHCI",
51         .hcd_priv_size =        sizeof(struct ohci_hcd),
52
53         /*
54          * generic hardware linkage
55          */
56         .irq =                  ohci_irq,
57         .flags =                HCD_USB11 | HCD_MEMORY,
58
59         /*
60          * basic lifecycle operations
61          */
62         .start =                ohci_au1xxx_start,
63         .stop =                 ohci_stop,
64         .shutdown =             ohci_shutdown,
65
66         /*
67          * managing i/o requests and associated device resources
68          */
69         .urb_enqueue =          ohci_urb_enqueue,
70         .urb_dequeue =          ohci_urb_dequeue,
71         .endpoint_disable =     ohci_endpoint_disable,
72
73         /*
74          * scheduling support
75          */
76         .get_frame_number =     ohci_get_frame,
77
78         /*
79          * root hub support
80          */
81         .hub_status_data =      ohci_hub_status_data,
82         .hub_control =          ohci_hub_control,
83 #ifdef  CONFIG_PM
84         .bus_suspend =          ohci_bus_suspend,
85         .bus_resume =           ohci_bus_resume,
86 #endif
87         .start_port_reset =     ohci_start_port_reset,
88 };
89
90 static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
91 {
92         int ret;
93         struct usb_hcd *hcd;
94
95         if (usb_disabled())
96                 return -ENODEV;
97
98         if (pdev->resource[1].flags != IORESOURCE_IRQ) {
99                 pr_debug("resource[1] is not IORESOURCE_IRQ\n");
100                 return -ENOMEM;
101         }
102
103         hcd = usb_create_hcd(&ohci_au1xxx_hc_driver, &pdev->dev, "au1xxx");
104         if (!hcd)
105                 return -ENOMEM;
106
107         hcd->rsrc_start = pdev->resource[0].start;
108         hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
109
110         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
111                 pr_debug("request_mem_region failed\n");
112                 ret = -EBUSY;
113                 goto err1;
114         }
115
116         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
117         if (!hcd->regs) {
118                 pr_debug("ioremap failed\n");
119                 ret = -ENOMEM;
120                 goto err2;
121         }
122
123         if (alchemy_usb_control(ALCHEMY_USB_OHCI0, 1)) {
124                 printk(KERN_INFO "%s: controller init failed!\n", pdev->name);
125                 ret = -ENODEV;
126                 goto err3;
127         }
128
129         ohci_hcd_init(hcd_to_ohci(hcd));
130
131         ret = usb_add_hcd(hcd, pdev->resource[1].start,
132                           IRQF_SHARED);
133         if (ret == 0) {
134                 platform_set_drvdata(pdev, hcd);
135                 return ret;
136         }
137
138         alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
139 err3:
140         iounmap(hcd->regs);
141 err2:
142         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
143 err1:
144         usb_put_hcd(hcd);
145         return ret;
146 }
147
148 static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
149 {
150         struct usb_hcd *hcd = platform_get_drvdata(pdev);
151
152         usb_remove_hcd(hcd);
153         alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
154         iounmap(hcd->regs);
155         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
156         usb_put_hcd(hcd);
157         platform_set_drvdata(pdev, NULL);
158
159         return 0;
160 }
161
162 #ifdef CONFIG_PM
163 static int ohci_hcd_au1xxx_drv_suspend(struct device *dev)
164 {
165         struct usb_hcd *hcd = dev_get_drvdata(dev);
166         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
167         unsigned long flags;
168         int rc;
169
170         rc = 0;
171
172         /* Root hub was already suspended. Disable irq emission and
173          * mark HW unaccessible, bail out if RH has been resumed. Use
174          * the spinlock to properly synchronize with possible pending
175          * RH suspend or resume activity.
176          *
177          * This is still racy as hcd->state is manipulated outside of
178          * any locks =P But that will be a different fix.
179          */
180         spin_lock_irqsave(&ohci->lock, flags);
181         if (hcd->state != HC_STATE_SUSPENDED) {
182                 rc = -EINVAL;
183                 goto bail;
184         }
185         ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
186         (void)ohci_readl(ohci, &ohci->regs->intrdisable);
187
188         clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
189
190         alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
191 bail:
192         spin_unlock_irqrestore(&ohci->lock, flags);
193
194         return rc;
195 }
196
197 static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
198 {
199         struct usb_hcd *hcd = dev_get_drvdata(dev);
200
201         alchemy_usb_control(ALCHEMY_USB_OHCI0, 1);
202
203         set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
204         ohci_finish_controller_resume(hcd);
205
206         return 0;
207 }
208
209 static const struct dev_pm_ops au1xxx_ohci_pmops = {
210         .suspend        = ohci_hcd_au1xxx_drv_suspend,
211         .resume         = ohci_hcd_au1xxx_drv_resume,
212 };
213
214 #define AU1XXX_OHCI_PMOPS &au1xxx_ohci_pmops
215
216 #else
217 #define AU1XXX_OHCI_PMOPS NULL
218 #endif
219
220 static struct platform_driver ohci_hcd_au1xxx_driver = {
221         .probe          = ohci_hcd_au1xxx_drv_probe,
222         .remove         = ohci_hcd_au1xxx_drv_remove,
223         .shutdown       = usb_hcd_platform_shutdown,
224         .driver         = {
225                 .name   = "au1xxx-ohci",
226                 .owner  = THIS_MODULE,
227                 .pm     = AU1XXX_OHCI_PMOPS,
228         },
229 };
230
231 MODULE_ALIAS("platform:au1xxx-ohci");