ramips_eth: pass sys_clk via platform_data
[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 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
156 .get_frame_number = ehci_get_frame,
157
158 .hub_status_data = ehci_hub_status_data,
159 .hub_control = ehci_hub_control,
160 #ifdef CONFIG_PM
161 .hub_suspend = ehci_hub_suspend,
162 .hub_resume = ehci_hub_resume,
163 #endif
164 .relinquish_port = ehci_relinquish_port,
165 .port_handed_over = ehci_port_handed_over,
166 };
167
168 static const struct hc_driver ehci_ar91xx_hc_driver = {
169 .description = hcd_name,
170 .product_desc = "Atheros AR91xx built-in EHCI controller",
171 .hcd_priv_size = sizeof(struct ehci_hcd),
172 .irq = ehci_irq,
173 .flags = HCD_MEMORY | HCD_USB2,
174
175 .reset = ehci_ar91xx_init,
176 .start = ehci_run,
177 .stop = ehci_stop,
178 .shutdown = ehci_shutdown,
179
180 .urb_enqueue = ehci_urb_enqueue,
181 .urb_dequeue = ehci_urb_dequeue,
182 .endpoint_disable = ehci_endpoint_disable,
183
184 .get_frame_number = ehci_get_frame,
185
186 .hub_status_data = ehci_hub_status_data,
187 .hub_control = ehci_hub_control,
188 #ifdef CONFIG_PM
189 .hub_suspend = ehci_hub_suspend,
190 .hub_resume = ehci_hub_resume,
191 #endif
192 .relinquish_port = ehci_relinquish_port,
193 .port_handed_over = ehci_port_handed_over,
194 };
195
196 static int ehci_ar71xx_driver_probe(struct platform_device *pdev)
197 {
198 struct ar71xx_ehci_platform_data *pdata;
199 struct usb_hcd *hcd = NULL;
200 int ret;
201
202 if (usb_disabled())
203 return -ENODEV;
204
205 pdata = pdev->dev.platform_data;
206 if (!pdata) {
207 dev_err(&pdev->dev, "no platform data specified for %s\n",
208 dev_name(&pdev->dev));
209 return -ENODEV;
210 }
211
212 if (pdata->is_ar91xx)
213 ret = ehci_ar71xx_probe(&ehci_ar91xx_hc_driver, &hcd, pdev);
214 else
215 ret = ehci_ar71xx_probe(&ehci_ar71xx_hc_driver, &hcd, pdev);
216
217 return ret;
218 }
219
220 static int ehci_ar71xx_driver_remove(struct platform_device *pdev)
221 {
222 struct usb_hcd *hcd = platform_get_drvdata(pdev);
223
224 ehci_ar71xx_remove(hcd, pdev);
225 return 0;
226 }
227
228 MODULE_ALIAS("platform:ar71xx-ehci");
229
230 static struct platform_driver ehci_ar71xx_driver = {
231 .probe = ehci_ar71xx_driver_probe,
232 .remove = ehci_ar71xx_driver_remove,
233 .driver = {
234 .name = "ar71xx-ehci",
235 }
236 };
This page took 0.062301 seconds and 5 git commands to generate.