[ar71xx] OHCI driver cleanup
[openwrt.git] / target / linux / ar71xx / files / drivers / usb / host / ohci-ar71xx.c
1 /*
2  *  OHCI HCD (Host Controller Driver) for USB.
3  *
4  *  Bus Glue for Atheros AR71xx built-in OHCI controller.
5  *
6  *  Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
7  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
8  *
9  *  Parts of this file are based on Atheros' 2.6.15 BSP
10  *      Copyright (C) 2007 Atheros Communications, Inc.
11  *
12  *  This program is free software; you can redistribute it and/or modify it
13  *  under the terms of the GNU General Public License version 2 as published
14  *  by the Free Software Foundation.
15  */
16
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19
20 extern int usb_disabled(void);
21
22 static int usb_hcd_ar71xx_probe(const struct hc_driver *driver,
23                                 struct platform_device *pdev)
24 {
25         struct usb_hcd *hcd;
26         struct resource *res;
27         int irq;
28         int ret;
29
30         res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
31         if (!res) {
32                 dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
33                         pdev->dev.bus_id);
34                 return -ENODEV;
35         }
36         irq = res->start;
37
38         hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
39         if (!hcd)
40                 return -ENOMEM;
41
42         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
43         if (!res) {
44                 dev_dbg(&pdev->dev, "no base address specified for %s\n",
45                         pdev->dev.bus_id);
46                 ret = -ENODEV;
47                 goto err_put_hcd;
48         }
49         hcd->rsrc_start = res->start;
50         hcd->rsrc_len   = res->end - res->start + 1;
51
52         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
53                 dev_dbg(&pdev->dev, "controller already in use\n");
54                 ret = -EBUSY;
55                 goto err_put_hcd;
56         }
57
58         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
59         if (!hcd->regs) {
60                 dev_dbg(&pdev->dev, "error mapping memory\n");
61                 ret = -EFAULT;
62                 goto err_release_region;
63         }
64
65         ohci_hcd_init(hcd_to_ohci(hcd));
66
67         ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
68         if (ret)
69                 goto err_stop_hcd;
70
71         return 0;
72
73  err_stop_hcd:
74         iounmap(hcd->regs);
75  err_release_region:
76         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
77  err_put_hcd:
78         usb_put_hcd(hcd);
79         return ret;
80 }
81
82 void usb_hcd_ar71xx_remove(struct usb_hcd *hcd, struct platform_device *pdev)
83 {
84         usb_remove_hcd(hcd);
85         iounmap(hcd->regs);
86         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
87         usb_put_hcd(hcd);
88 }
89
90 static int __devinit ohci_ar71xx_start(struct usb_hcd *hcd)
91 {
92         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
93         int ret;
94
95         ret = ohci_init(ohci);
96         if (ret < 0)
97                 return ret;
98
99         ret = ohci_run(ohci);
100         if (ret < 0)
101                 goto err;
102
103         return 0;
104
105  err:
106         ohci_stop(hcd);
107         return ret;
108 }
109
110 static const struct hc_driver ohci_ar71xx_hc_driver = {
111         .description            = hcd_name,
112         .product_desc           = "Atheros AR71xx built-in OHCI controller",
113         .hcd_priv_size          = sizeof(struct ohci_hcd),
114
115         .irq                    = ohci_irq,
116         .flags                  = HCD_USB11 | HCD_MEMORY,
117
118         .start                  = ohci_ar71xx_start,
119         .stop                   = ohci_stop,
120         .shutdown               = ohci_shutdown,
121
122         .urb_enqueue            = ohci_urb_enqueue,
123         .urb_dequeue            = ohci_urb_dequeue,
124         .endpoint_disable       = ohci_endpoint_disable,
125
126         /*
127          * scheduling support
128          */
129         .get_frame_number       = ohci_get_frame,
130
131         /*
132          * root hub support
133          */
134         .hub_status_data        = ohci_hub_status_data,
135         .hub_control            = ohci_hub_control,
136         .start_port_reset       = ohci_start_port_reset,
137 };
138
139 static int ohci_hcd_ar71xx_drv_probe(struct platform_device *pdev)
140 {
141         if (usb_disabled())
142                 return -ENODEV;
143
144         return usb_hcd_ar71xx_probe(&ohci_ar71xx_hc_driver, pdev);
145 }
146
147 static int ohci_hcd_ar71xx_drv_remove(struct platform_device *pdev)
148 {
149         struct usb_hcd *hcd = platform_get_drvdata(pdev);
150
151         usb_hcd_ar71xx_remove(hcd, pdev);
152         return 0;
153 }
154
155 MODULE_ALIAS("platform:ar71xx-ohci");
156
157 static struct platform_driver ohci_hcd_ar71xx_driver = {
158         .probe          = ohci_hcd_ar71xx_drv_probe,
159         .remove         = ohci_hcd_ar71xx_drv_remove,
160         .shutdown       = usb_hcd_platform_shutdown,
161         .driver         = {
162                 .name   = "ar71xx-ohci",
163                 .owner  = THIS_MODULE,
164         },
165 };