[ar71xx] EHCI driver: add AR913x support
[openwrt/svn-archive/archive.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 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
34 ehci_reset(ehci);
35
36 ret = ehci_init(hcd);
37 if (ret)
38 return ret;
39
40 ehci_port_power(ehci, 0);
41
42 return 0;
43 }
44
45 static int ehci_ar91xx_init(struct usb_hcd *hcd)
46 {
47 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
48 int ret;
49
50 ehci->caps = hcd->regs + 0x100;
51 ehci->regs = hcd->regs + 0x100 +
52 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
53 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
54
55 hcd->has_tt = 1;
56 ehci->sbrn = 0x20;
57
58 ehci_reset(ehci);
59
60 ret = ehci_init(hcd);
61 if (ret)
62 return ret;
63
64 ehci_port_power(ehci, 0);
65
66 return 0;
67 }
68
69 static int ehci_ar71xx_probe(const struct hc_driver *driver,
70 struct usb_hcd **hcd_out,
71 struct platform_device *pdev)
72 {
73 struct usb_hcd *hcd;
74 struct resource *res;
75 int irq;
76 int ret;
77
78 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
79 if (!res) {
80 dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
81 pdev->dev.bus_id);
82 return -ENODEV;
83 }
84 irq = res->start;
85
86 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
87 if (!res) {
88 dev_dbg(&pdev->dev, "no base address specified for %s\n",
89 pdev->dev.bus_id);
90 return -ENODEV;
91 }
92
93 hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
94 if (!hcd)
95 return -ENOMEM;
96
97 hcd->rsrc_start = res->start;
98 hcd->rsrc_len = res->end - res->start + 1;
99
100 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
101 dev_dbg(&pdev->dev, "controller already in use\n");
102 ret = -EBUSY;
103 goto err_put_hcd;
104 }
105
106 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
107 if (!hcd->regs) {
108 dev_dbg(&pdev->dev, "error mapping memory\n");
109 ret = -EFAULT;
110 goto err_release_region;
111 }
112
113 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
114 if (ret)
115 goto err_iounmap;
116
117 return 0;
118
119 err_iounmap:
120 iounmap(hcd->regs);
121
122 err_release_region:
123 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
124 err_put_hcd:
125 usb_put_hcd(hcd);
126 return ret;
127 }
128
129 static void ehci_ar71xx_remove(struct usb_hcd *hcd,
130 struct platform_device *pdev)
131 {
132 usb_remove_hcd(hcd);
133 iounmap(hcd->regs);
134 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
135 usb_put_hcd(hcd);
136 }
137
138 static const struct hc_driver ehci_ar71xx_hc_driver = {
139 .description = hcd_name,
140 .product_desc = "Atheros AR71xx built-in EHCI controller",
141 .hcd_priv_size = sizeof(struct ehci_hcd),
142
143 .irq = ehci_irq,
144 .flags = HCD_MEMORY | HCD_USB2,
145
146 .reset = ehci_ar71xx_init,
147 .start = ehci_run,
148 .stop = ehci_stop,
149 .shutdown = ehci_shutdown,
150
151 .urb_enqueue = ehci_urb_enqueue,
152 .urb_dequeue = ehci_urb_dequeue,
153 .endpoint_disable = ehci_endpoint_disable,
154
155 .get_frame_number = ehci_get_frame,
156
157 .hub_status_data = ehci_hub_status_data,
158 .hub_control = ehci_hub_control,
159 #ifdef CONFIG_PM
160 .hub_suspend = ehci_hub_suspend,
161 .hub_resume = ehci_hub_resume,
162 #endif
163 .relinquish_port = ehci_relinquish_port,
164 .port_handed_over = ehci_port_handed_over,
165 };
166
167 static const struct hc_driver ehci_ar91xx_hc_driver = {
168 .description = hcd_name,
169 .product_desc = "Atheros AR91xx built-in EHCI controller",
170 .hcd_priv_size = sizeof(struct ehci_hcd),
171 .irq = ehci_irq,
172 .flags = HCD_MEMORY | HCD_USB2,
173
174 .reset = ehci_ar91xx_init,
175 .start = ehci_run,
176 .stop = ehci_stop,
177 .shutdown = ehci_shutdown,
178
179 .urb_enqueue = ehci_urb_enqueue,
180 .urb_dequeue = ehci_urb_dequeue,
181 .endpoint_disable = ehci_endpoint_disable,
182
183 .get_frame_number = ehci_get_frame,
184
185 .hub_status_data = ehci_hub_status_data,
186 .hub_control = ehci_hub_control,
187 #ifdef CONFIG_PM
188 .hub_suspend = ehci_hub_suspend,
189 .hub_resume = ehci_hub_resume,
190 #endif
191 .relinquish_port = ehci_relinquish_port,
192 .port_handed_over = ehci_port_handed_over,
193 };
194
195 static int ehci_ar71xx_driver_probe(struct platform_device *pdev)
196 {
197 struct ar71xx_ehci_platform_data *pdata;
198 struct usb_hcd *hcd = NULL;
199 int ret;
200
201 if (usb_disabled())
202 return -ENODEV;
203
204 pdata = pdev->dev.platform_data;
205 if (!pdata) {
206 dev_err(&pdev->dev, "no platform data specified for %s\n",
207 pdev->dev.bus_id);
208 return -ENODEV;
209 }
210
211 if (pdata->is_ar91xx)
212 ret = ehci_ar71xx_probe(&ehci_ar91xx_hc_driver, &hcd, pdev);
213 else
214 ret = ehci_ar71xx_probe(&ehci_ar71xx_hc_driver, &hcd, pdev);
215
216 return ret;
217 }
218
219 static int ehci_ar71xx_driver_remove(struct platform_device *pdev)
220 {
221 struct usb_hcd *hcd = platform_get_drvdata(pdev);
222
223 ehci_ar71xx_remove(hcd, pdev);
224 return 0;
225 }
226
227 MODULE_ALIAS("platform:ar71xx-ehci");
228
229 static struct platform_driver ehci_ar71xx_driver = {
230 .probe = ehci_ar71xx_driver_probe,
231 .remove = ehci_ar71xx_driver_remove,
232 .driver = {
233 .name = "ar71xx-ehci",
234 }
235 };