surprise :p
[openwrt-10.03/.git] / target / linux / ar71xx / files / drivers / usb / host / ohci-ar71xx.c
1 /*
2  * OHCI HCD (Host Controller Driver) for USB.
3  *
4  * Copyright (C) 2007 Atheros Communications, Inc.
5  * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
6  * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7  *
8  * Bus Glue for Atheros AR71xx built-in OHCI controller
9  *
10  */
11
12 #include <linux/platform_device.h>
13 #include <linux/delay.h>
14
15 extern int usb_disabled(void);
16
17 static void ar71xx_start_ohci(struct platform_device *pdev)
18 {
19 }
20
21 static void ar71xx_stop_ohci(struct platform_device *pdev)
22 {
23         /*
24          * TODO: implement
25          */
26 }
27
28 int usb_hcd_ar71xx_probe(const struct hc_driver *driver,
29                          struct platform_device *pdev)
30 {
31         struct usb_hcd *hcd;
32         struct resource *res;
33         int irq;
34         int ret;
35
36         res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
37         if (!res) {
38                 dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
39                         pdev->dev.bus_id);
40                 return -ENODEV;
41         }
42         irq = res->start;
43
44         hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
45         if (!hcd)
46                 return -ENOMEM;
47
48         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
49         if (!res) {
50                 dev_dbg(&pdev->dev, "no base address specified for %s\n",
51                         pdev->dev.bus_id);
52                 ret = -ENODEV;
53                 goto err_put_hcd;
54         }
55         hcd->rsrc_start = res->start;
56         hcd->rsrc_len   = res->end - res->start + 1;
57
58         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
59                 dev_dbg(&pdev->dev, "controller already in use\n");
60                 ret = -EBUSY;
61                 goto err_put_hcd;
62         }
63
64         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
65         if (!hcd->regs) {
66                 dev_dbg(&pdev->dev, "error mapping memory\n");
67                 ret = -EFAULT;
68                 goto err_release_region;
69         }
70
71         ar71xx_start_ohci(pdev);
72         ohci_hcd_init(hcd_to_ohci(hcd));
73
74         ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
75         if (ret)
76                 goto err_stop_hcd;
77
78         return 0;
79
80 err_stop_hcd:
81         ar71xx_stop_ohci(pdev);
82         iounmap(hcd->regs);
83 err_release_region:
84         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
85 err_put_hcd:
86         usb_put_hcd(hcd);
87         return ret;
88 }
89
90
91 /* may be called without controller electrically present */
92 /* may be called with controller, bus, and devices active */
93
94 /**
95  * usb_hcd_ar71xx_remove - shutdown processing for AR71xx HCDs
96  * @dev: USB Host Controller being removed
97  * Context: !in_interrupt()
98  *
99  * Reverses the effect of usb_hcd_ar71xx_probe(), first invoking
100  * the HCD's stop() method.  It is always called from a thread
101  * context, normally "rmmod", "apmd", or something similar.
102  *
103  */
104 void usb_hcd_ar71xx_remove(struct usb_hcd *hcd, struct platform_device *pdev)
105 {
106         usb_remove_hcd(hcd);
107         ar71xx_stop_ohci(pdev);
108         iounmap(hcd->regs);
109         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
110         usb_put_hcd(hcd);
111 }
112
113 static int __devinit ohci_ar71xx_start(struct usb_hcd *hcd)
114 {
115         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
116         int ret;
117
118         ret = ohci_init(ohci);
119         if (ret < 0)
120                 return ret;
121
122         ret = ohci_run(ohci);
123         if (ret < 0)
124                 goto err;
125
126         return 0;
127
128 err:
129         ohci_stop(hcd);
130         return ret;
131 }
132
133 static const struct hc_driver ohci_ar71xx_hc_driver = {
134         .description    = hcd_name,
135         .product_desc   = "Atheros AR71xx built-in OHCI controller",
136         .hcd_priv_size  = sizeof(struct ohci_hcd),
137
138         /*
139          * generic hardware linkage
140          */
141         .irq            = ohci_irq,
142         .flags          = HCD_USB11 | HCD_MEMORY,
143
144         /*
145          * basic lifecycle operations
146          */
147         .start          = ohci_ar71xx_start,
148         .stop           = ohci_stop,
149         .shutdown       = ohci_shutdown,
150
151         /*
152          * managing i/o requests and associated device resources
153          */
154         .urb_enqueue            = ohci_urb_enqueue,
155         .urb_dequeue            = ohci_urb_dequeue,
156         .endpoint_disable       = ohci_endpoint_disable,
157
158         /*
159          * scheduling support
160          */
161         .get_frame_number       = ohci_get_frame,
162
163         /*
164          * root hub support
165          */
166         .hub_status_data        = ohci_hub_status_data,
167         .hub_control            = ohci_hub_control,
168         .start_port_reset       = ohci_start_port_reset,
169 };
170
171 static int ohci_hcd_ar71xx_drv_probe(struct platform_device *pdev)
172 {
173         int ret;
174
175         ret = -ENODEV;
176         if (!usb_disabled())
177                 ret = usb_hcd_ar71xx_probe(&ohci_ar71xx_hc_driver, pdev);
178
179         return ret;
180 }
181
182 static int ohci_hcd_ar71xx_drv_remove(struct platform_device *pdev)
183 {
184         struct usb_hcd *hcd = platform_get_drvdata(pdev);
185
186         usb_hcd_ar71xx_remove(hcd, pdev);
187         return 0;
188 }
189
190 static struct platform_driver ohci_hcd_ar71xx_driver = {
191         .probe          = ohci_hcd_ar71xx_drv_probe,
192         .remove         = ohci_hcd_ar71xx_drv_remove,
193         .shutdown       = usb_hcd_platform_shutdown,
194         .driver         = {
195                 .name   = "ar71xx-ohci",
196                 .owner  = THIS_MODULE,
197         },
198 };
199
200 MODULE_ALIAS("ar71xx-ohci");