Commit | Line | Data |
---|---|---|
76fa9a24 JC |
1 | /* |
2 | * EHCI HCD (Host Controller Driver) for USB. | |
3 | * | |
76fa9a24 JC |
4 | * Bus Glue for AMD Alchemy Au1xxx |
5 | * | |
6 | * Based on "ohci-au1xxx.c" by Matt Porter <mporter@kernel.crashing.org> | |
7 | * | |
8 | * Modified for AMD Alchemy Au1200 EHC | |
9 | * by K.Boge <karsten.boge@amd.com> | |
10 | * | |
11 | * This file is licenced under the GPL. | |
12 | */ | |
13 | ||
14 | #include <linux/platform_device.h> | |
15 | #include <asm/mach-au1x00/au1000.h> | |
16 | ||
76fa9a24 JC |
17 | #define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG) |
18 | #define USB_MCFG_PFEN (1<<31) | |
19 | #define USB_MCFG_RDCOMB (1<<30) | |
20 | #define USB_MCFG_SSDEN (1<<23) | |
21 | #define USB_MCFG_PHYPLLEN (1<<19) | |
53c81a34 | 22 | #define USB_MCFG_UCECLKEN (1<<18) |
76fa9a24 | 23 | #define USB_MCFG_EHCCLKEN (1<<17) |
53c81a34 | 24 | #ifdef CONFIG_DMA_COHERENT |
76fa9a24 | 25 | #define USB_MCFG_UCAM (1<<7) |
53c81a34 ML |
26 | #else |
27 | #define USB_MCFG_UCAM (0) | |
28 | #endif | |
76fa9a24 JC |
29 | #define USB_MCFG_EBMEN (1<<3) |
30 | #define USB_MCFG_EMEMEN (1<<2) | |
31 | ||
53c81a34 ML |
32 | #define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN) |
33 | #define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \ | |
34 | USBH_ENABLE_CE | USB_MCFG_SSDEN | \ | |
35 | USB_MCFG_UCAM | USB_MCFG_EBMEN | \ | |
36 | USB_MCFG_EMEMEN) | |
76fa9a24 | 37 | |
76fa9a24 JC |
38 | #define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN) |
39 | ||
76fa9a24 JC |
40 | extern int usb_disabled(void); |
41 | ||
53c81a34 | 42 | static void au1xxx_start_ehc(void) |
76fa9a24 | 43 | { |
53c81a34 ML |
44 | /* enable clock to EHCI block and HS PHY PLL*/ |
45 | au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG); | |
46 | au_sync(); | |
76fa9a24 JC |
47 | udelay(1000); |
48 | ||
53c81a34 ML |
49 | /* enable EHCI mmio */ |
50 | au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG); | |
51 | au_sync(); | |
52 | udelay(1000); | |
76fa9a24 JC |
53 | } |
54 | ||
53c81a34 | 55 | static void au1xxx_stop_ehc(void) |
76fa9a24 | 56 | { |
53c81a34 | 57 | unsigned long c; |
76fa9a24 JC |
58 | |
59 | /* Disable mem */ | |
53c81a34 ML |
60 | au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG); |
61 | au_sync(); | |
76fa9a24 | 62 | udelay(1000); |
53c81a34 ML |
63 | |
64 | /* Disable EHC clock. If the HS PHY is unused disable it too. */ | |
65 | c = au_readl(USB_HOST_CONFIG) & ~USB_MCFG_EHCCLKEN; | |
66 | if (!(c & USB_MCFG_UCECLKEN)) /* UDC disabled? */ | |
67 | c &= ~USB_MCFG_PHYPLLEN; /* yes: disable HS PHY PLL */ | |
68 | au_writel(c, USB_HOST_CONFIG); | |
69 | au_sync(); | |
76fa9a24 JC |
70 | } |
71 | ||
53c81a34 ML |
72 | static const struct hc_driver ehci_au1xxx_hc_driver = { |
73 | .description = hcd_name, | |
74 | .product_desc = "Au1xxx EHCI", | |
75 | .hcd_priv_size = sizeof(struct ehci_hcd), | |
76fa9a24 | 76 | |
53c81a34 ML |
77 | /* |
78 | * generic hardware linkage | |
79 | */ | |
80 | .irq = ehci_irq, | |
81 | .flags = HCD_MEMORY | HCD_USB2, | |
76fa9a24 | 82 | |
53c81a34 ML |
83 | /* |
84 | * basic lifecycle operations | |
85 | * | |
86 | * FIXME -- ehci_init() doesn't do enough here. | |
87 | * See ehci-ppc-soc for a complete implementation. | |
88 | */ | |
89 | .reset = ehci_init, | |
90 | .start = ehci_run, | |
91 | .stop = ehci_stop, | |
92 | .shutdown = ehci_shutdown, | |
93 | ||
94 | /* | |
95 | * managing i/o requests and associated device resources | |
96 | */ | |
97 | .urb_enqueue = ehci_urb_enqueue, | |
98 | .urb_dequeue = ehci_urb_dequeue, | |
99 | .endpoint_disable = ehci_endpoint_disable, | |
b18ffd49 | 100 | .endpoint_reset = ehci_endpoint_reset, |
53c81a34 ML |
101 | |
102 | /* | |
103 | * scheduling support | |
104 | */ | |
105 | .get_frame_number = ehci_get_frame, | |
106 | ||
107 | /* | |
108 | * root hub support | |
109 | */ | |
110 | .hub_status_data = ehci_hub_status_data, | |
111 | .hub_control = ehci_hub_control, | |
112 | .bus_suspend = ehci_bus_suspend, | |
113 | .bus_resume = ehci_bus_resume, | |
114 | .relinquish_port = ehci_relinquish_port, | |
115 | .port_handed_over = ehci_port_handed_over, | |
116 | }; | |
117 | ||
118 | static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev) | |
76fa9a24 | 119 | { |
76fa9a24 JC |
120 | struct usb_hcd *hcd; |
121 | struct ehci_hcd *ehci; | |
53c81a34 | 122 | int ret; |
76fa9a24 | 123 | |
53c81a34 ML |
124 | if (usb_disabled()) |
125 | return -ENODEV; | |
76fa9a24 | 126 | |
53c81a34 | 127 | #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT) |
76fa9a24 JC |
128 | /* Au1200 AB USB does not support coherent memory */ |
129 | if (!(read_c0_prid() & 0xff)) { | |
53c81a34 ML |
130 | printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name); |
131 | printk(KERN_INFO "%s: update your board or re-configure" | |
132 | " the kernel\n", pdev->name); | |
76fa9a24 JC |
133 | return -ENODEV; |
134 | } | |
135 | #endif | |
136 | ||
53c81a34 | 137 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
76fa9a24 | 138 | pr_debug("resource[1] is not IORESOURCE_IRQ"); |
53c81a34 | 139 | return -ENOMEM; |
76fa9a24 | 140 | } |
53c81a34 | 141 | hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx"); |
76fa9a24 JC |
142 | if (!hcd) |
143 | return -ENOMEM; | |
53c81a34 ML |
144 | |
145 | hcd->rsrc_start = pdev->resource[0].start; | |
146 | hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; | |
76fa9a24 JC |
147 | |
148 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | |
149 | pr_debug("request_mem_region failed"); | |
53c81a34 | 150 | ret = -EBUSY; |
76fa9a24 JC |
151 | goto err1; |
152 | } | |
153 | ||
154 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | |
155 | if (!hcd->regs) { | |
156 | pr_debug("ioremap failed"); | |
53c81a34 | 157 | ret = -ENOMEM; |
76fa9a24 JC |
158 | goto err2; |
159 | } | |
160 | ||
53c81a34 ML |
161 | au1xxx_start_ehc(); |
162 | ||
76fa9a24 JC |
163 | ehci = hcd_to_ehci(hcd); |
164 | ehci->caps = hcd->regs; | |
165 | ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase)); | |
166 | /* cache this readonly data; minimize chip reads */ | |
167 | ehci->hcs_params = readl(&ehci->caps->hcs_params); | |
168 | ||
53c81a34 ML |
169 | ret = usb_add_hcd(hcd, pdev->resource[1].start, |
170 | IRQF_DISABLED | IRQF_SHARED); | |
171 | if (ret == 0) { | |
172 | platform_set_drvdata(pdev, hcd); | |
173 | return ret; | |
174 | } | |
76fa9a24 | 175 | |
53c81a34 | 176 | au1xxx_stop_ehc(); |
76fa9a24 JC |
177 | iounmap(hcd->regs); |
178 | err2: | |
179 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | |
180 | err1: | |
181 | usb_put_hcd(hcd); | |
53c81a34 | 182 | return ret; |
76fa9a24 JC |
183 | } |
184 | ||
53c81a34 | 185 | static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev) |
76fa9a24 | 186 | { |
53c81a34 ML |
187 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
188 | ||
76fa9a24 JC |
189 | usb_remove_hcd(hcd); |
190 | iounmap(hcd->regs); | |
191 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | |
192 | usb_put_hcd(hcd); | |
53c81a34 ML |
193 | au1xxx_stop_ehc(); |
194 | platform_set_drvdata(pdev, NULL); | |
76fa9a24 | 195 | |
76fa9a24 JC |
196 | return 0; |
197 | } | |
198 | ||
42bfc7b4 ML |
199 | #ifdef CONFIG_PM |
200 | static int ehci_hcd_au1xxx_drv_suspend(struct platform_device *pdev, | |
201 | pm_message_t message) | |
76fa9a24 | 202 | { |
42bfc7b4 ML |
203 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
204 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | |
205 | unsigned long flags; | |
206 | int rc; | |
76fa9a24 JC |
207 | |
208 | return 0; | |
42bfc7b4 ML |
209 | rc = 0; |
210 | ||
211 | if (time_before(jiffies, ehci->next_statechange)) | |
212 | msleep(10); | |
213 | ||
214 | /* Root hub was already suspended. Disable irq emission and | |
215 | * mark HW unaccessible, bail out if RH has been resumed. Use | |
216 | * the spinlock to properly synchronize with possible pending | |
217 | * RH suspend or resume activity. | |
218 | * | |
219 | * This is still racy as hcd->state is manipulated outside of | |
220 | * any locks =P But that will be a different fix. | |
221 | */ | |
222 | spin_lock_irqsave(&ehci->lock, flags); | |
223 | if (hcd->state != HC_STATE_SUSPENDED) { | |
224 | rc = -EINVAL; | |
225 | goto bail; | |
226 | } | |
227 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); | |
228 | (void)ehci_readl(ehci, &ehci->regs->intr_enable); | |
229 | ||
230 | /* make sure snapshot being resumed re-enumerates everything */ | |
231 | if (message.event == PM_EVENT_PRETHAW) { | |
232 | ehci_halt(ehci); | |
233 | ehci_reset(ehci); | |
234 | } | |
235 | ||
236 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | |
237 | ||
238 | au1xxx_stop_ehc(); | |
239 | ||
240 | bail: | |
241 | spin_unlock_irqrestore(&ehci->lock, flags); | |
242 | ||
243 | // could save FLADJ in case of Vaux power loss | |
244 | // ... we'd only use it to handle clock skew | |
245 | ||
246 | return rc; | |
76fa9a24 | 247 | } |
42bfc7b4 ML |
248 | |
249 | ||
250 | static int ehci_hcd_au1xxx_drv_resume(struct platform_device *pdev) | |
76fa9a24 | 251 | { |
42bfc7b4 ML |
252 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
253 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | |
254 | ||
255 | au1xxx_start_ehc(); | |
256 | ||
257 | // maybe restore FLADJ | |
258 | ||
259 | if (time_before(jiffies, ehci->next_statechange)) | |
260 | msleep(100); | |
261 | ||
262 | /* Mark hardware accessible again as we are out of D3 state by now */ | |
263 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | |
264 | ||
265 | /* If CF is still set, we maintained PCI Vaux power. | |
266 | * Just undo the effect of ehci_pci_suspend(). | |
267 | */ | |
268 | if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) { | |
269 | int mask = INTR_MASK; | |
270 | ||
271 | if (!hcd->self.root_hub->do_remote_wakeup) | |
272 | mask &= ~STS_PCD; | |
273 | ehci_writel(ehci, mask, &ehci->regs->intr_enable); | |
274 | ehci_readl(ehci, &ehci->regs->intr_enable); | |
275 | return 0; | |
276 | } | |
277 | ||
278 | ehci_dbg(ehci, "lost power, restarting\n"); | |
279 | usb_root_hub_lost_power(hcd->self.root_hub); | |
280 | ||
281 | /* Else reset, to cope with power loss or flush-to-storage | |
282 | * style "resume" having let BIOS kick in during reboot. | |
283 | */ | |
284 | (void) ehci_halt(ehci); | |
285 | (void) ehci_reset(ehci); | |
286 | ||
287 | /* emptying the schedule aborts any urbs */ | |
288 | spin_lock_irq(&ehci->lock); | |
289 | if (ehci->reclaim) | |
290 | end_unlink_async(ehci); | |
291 | ehci_work(ehci); | |
292 | spin_unlock_irq(&ehci->lock); | |
293 | ||
294 | ehci_writel(ehci, ehci->command, &ehci->regs->command); | |
295 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); | |
296 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ | |
297 | ||
298 | /* here we "know" root ports should always stay powered */ | |
299 | ehci_port_power(ehci, 1); | |
300 | ||
301 | hcd->state = HC_STATE_SUSPENDED; | |
76fa9a24 JC |
302 | |
303 | return 0; | |
304 | } | |
42bfc7b4 ML |
305 | |
306 | #else | |
307 | #define ehci_hcd_au1xxx_drv_suspend NULL | |
308 | #define ehci_hcd_au1xxx_drv_resume NULL | |
309 | #endif | |
53c81a34 | 310 | |
d14feb5e | 311 | static struct platform_driver ehci_hcd_au1xxx_driver = { |
53c81a34 ML |
312 | .probe = ehci_hcd_au1xxx_drv_probe, |
313 | .remove = ehci_hcd_au1xxx_drv_remove, | |
314 | .shutdown = usb_hcd_platform_shutdown, | |
42bfc7b4 ML |
315 | .suspend = ehci_hcd_au1xxx_drv_suspend, |
316 | .resume = ehci_hcd_au1xxx_drv_resume, | |
d14feb5e | 317 | .driver = { |
53c81a34 ML |
318 | .name = "au1xxx-ehci", |
319 | .owner = THIS_MODULE, | |
d14feb5e | 320 | } |
76fa9a24 | 321 | }; |
53c81a34 ML |
322 | |
323 | MODULE_ALIAS("platform:au1xxx-ehci"); |