ar71xx: add AR934X_RESET_REG_PCIE_WMAC_INT_STATUS defines
[openwrt.git] / target / linux / ar71xx / files / drivers / usb / host / ehci-ar71xx.c
1 /*
2 * Bus Glue for Atheros AR71xx built-in EHCI controller.
3 *
4 * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * Parts of this file are based on Atheros' 2.6.15 BSP
8 * Copyright (C) 2007 Atheros Communications, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 */
14
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17
18 #include <asm/mach-ar71xx/platform.h>
19
20 extern int usb_disabled(void);
21
22 static int ehci_ar71xx_init(struct usb_hcd *hcd)
23 {
24 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
25 int ret;
26
27 ehci->caps = hcd->regs;
28 ehci->regs = hcd->regs +
29 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
30 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
31
32 ehci->sbrn = 0x20;
33 ehci->has_synopsys_hc_bug = 1;
34
35 ehci_reset(ehci);
36
37 ret = ehci_init(hcd);
38 if (ret)
39 return ret;
40
41 ehci_port_power(ehci, 0);
42
43 return 0;
44 }
45
46 static int ehci_ar91xx_init(struct usb_hcd *hcd)
47 {
48 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
49 int ret;
50
51 ehci->caps = hcd->regs + 0x100;
52 ehci->regs = hcd->regs + 0x100 +
53 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
54 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
55
56 hcd->has_tt = 1;
57 ehci->sbrn = 0x20;
58
59 ehci_reset(ehci);
60
61 ret = ehci_init(hcd);
62 if (ret)
63 return ret;
64
65 ehci_port_power(ehci, 0);
66
67 return 0;
68 }
69
70 static int ehci_ar71xx_probe(const struct hc_driver *driver,
71 struct usb_hcd **hcd_out,
72 struct platform_device *pdev)
73 {
74 struct usb_hcd *hcd;
75 struct resource *res;
76 int irq;
77 int ret;
78
79 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
80 if (!res) {
81 dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
82 dev_name(&pdev->dev));
83 return -ENODEV;
84 }
85 irq = res->start;
86
87 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88 if (!res) {
89 dev_dbg(&pdev->dev, "no base address specified for %s\n",
90 dev_name(&pdev->dev));
91 return -ENODEV;
92 }
93
94 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
95 if (!hcd)
96 return -ENOMEM;
97
98 hcd->rsrc_start = res->start;
99 hcd->rsrc_len = res->end - res->start + 1;
100
101 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
102 dev_dbg(&pdev->dev, "controller already in use\n");
103 ret = -EBUSY;
104 goto err_put_hcd;
105 }
106
107 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
108 if (!hcd->regs) {
109 dev_dbg(&pdev->dev, "error mapping memory\n");
110 ret = -EFAULT;
111 goto err_release_region;
112 }
113
114 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
115 if (ret)
116 goto err_iounmap;
117
118 return 0;
119
120 err_iounmap:
121 iounmap(hcd->regs);
122
123 err_release_region:
124 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
125 err_put_hcd:
126 usb_put_hcd(hcd);
127 return ret;
128 }
129
130 static void ehci_ar71xx_remove(struct usb_hcd *hcd,
131 struct platform_device *pdev)
132 {
133 usb_remove_hcd(hcd);
134 iounmap(hcd->regs);
135 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
136 usb_put_hcd(hcd);
137 }
138
139 static const struct hc_driver ehci_ar71xx_hc_driver = {
140 .description = hcd_name,
141 .product_desc = "Atheros AR71xx built-in EHCI controller",
142 .hcd_priv_size = sizeof(struct ehci_hcd),
143
144 .irq = ehci_irq,
145 .flags = HCD_MEMORY | HCD_USB2,
146
147 .reset = ehci_ar71xx_init,
148 .start = ehci_run,
149 .stop = ehci_stop,
150 .shutdown = ehci_shutdown,
151
152 .urb_enqueue = ehci_urb_enqueue,
153 .urb_dequeue = ehci_urb_dequeue,
154 .endpoint_disable = ehci_endpoint_disable,
155 .endpoint_reset = ehci_endpoint_reset,
156
157 .get_frame_number = ehci_get_frame,
158
159 .hub_status_data = ehci_hub_status_data,
160 .hub_control = ehci_hub_control,
161 #ifdef CONFIG_PM
162 .hub_suspend = ehci_hub_suspend,
163 .hub_resume = ehci_hub_resume,
164 #endif
165 .relinquish_port = ehci_relinquish_port,
166 .port_handed_over = ehci_port_handed_over,
167
168 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
169 };
170
171 static const struct hc_driver ehci_ar91xx_hc_driver = {
172 .description = hcd_name,
173 .product_desc = "Atheros AR91xx built-in EHCI controller",
174 .hcd_priv_size = sizeof(struct ehci_hcd),
175 .irq = ehci_irq,
176 .flags = HCD_MEMORY | HCD_USB2,
177
178 .reset = ehci_ar91xx_init,
179 .start = ehci_run,
180 .stop = ehci_stop,
181 .shutdown = ehci_shutdown,
182
183 .urb_enqueue = ehci_urb_enqueue,
184 .urb_dequeue = ehci_urb_dequeue,
185 .endpoint_disable = ehci_endpoint_disable,
186 .endpoint_reset = ehci_endpoint_reset,
187
188 .get_frame_number = ehci_get_frame,
189
190 .hub_status_data = ehci_hub_status_data,
191 .hub_control = ehci_hub_control,
192 #ifdef CONFIG_PM
193 .hub_suspend = ehci_hub_suspend,
194 .hub_resume = ehci_hub_resume,
195 #endif
196 .relinquish_port = ehci_relinquish_port,
197 .port_handed_over = ehci_port_handed_over,
198
199 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
200 };
201
202 static int ehci_ar71xx_driver_probe(struct platform_device *pdev)
203 {
204 struct ar71xx_ehci_platform_data *pdata;
205 struct usb_hcd *hcd = NULL;
206 int ret;
207
208 if (usb_disabled())
209 return -ENODEV;
210
211 pdata = pdev->dev.platform_data;
212 if (!pdata) {
213 dev_err(&pdev->dev, "no platform data specified for %s\n",
214 dev_name(&pdev->dev));
215 return -ENODEV;
216 }
217
218 if (pdata->is_ar91xx)
219 ret = ehci_ar71xx_probe(&ehci_ar91xx_hc_driver, &hcd, pdev);
220 else
221 ret = ehci_ar71xx_probe(&ehci_ar71xx_hc_driver, &hcd, pdev);
222
223 return ret;
224 }
225
226 static int ehci_ar71xx_driver_remove(struct platform_device *pdev)
227 {
228 struct usb_hcd *hcd = platform_get_drvdata(pdev);
229
230 ehci_ar71xx_remove(hcd, pdev);
231 return 0;
232 }
233
234 MODULE_ALIAS("platform:ar71xx-ehci");
235
236 static struct platform_driver ehci_ar71xx_driver = {
237 .probe = ehci_ar71xx_driver_probe,
238 .remove = ehci_ar71xx_driver_remove,
239 .driver = {
240 .name = "ar71xx-ehci",
241 }
242 };
This page took 0.058994 seconds and 5 git commands to generate.