blob: e3a74e75e8225585c5c85e089f82fe046e7b4796 [file] [log] [blame]
Jordan Crouse76fa9a22006-01-20 14:06:09 -08001/*
2 * EHCI HCD (Host Controller Driver) for USB.
3 *
Jordan Crouse76fa9a22006-01-20 14:06:09 -08004 * 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
Jordan Crouse76fa9a22006-01-20 14:06:09 -080017#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)
Manuel Lauss53c81a32008-06-23 09:08:29 +020022#define USB_MCFG_UCECLKEN (1<<18)
Jordan Crouse76fa9a22006-01-20 14:06:09 -080023#define USB_MCFG_EHCCLKEN (1<<17)
Manuel Lauss53c81a32008-06-23 09:08:29 +020024#ifdef CONFIG_DMA_COHERENT
Jordan Crouse76fa9a22006-01-20 14:06:09 -080025#define USB_MCFG_UCAM (1<<7)
Manuel Lauss53c81a32008-06-23 09:08:29 +020026#else
27#define USB_MCFG_UCAM (0)
28#endif
Jordan Crouse76fa9a22006-01-20 14:06:09 -080029#define USB_MCFG_EBMEN (1<<3)
30#define USB_MCFG_EMEMEN (1<<2)
31
Manuel Lauss53c81a32008-06-23 09:08:29 +020032#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)
Jordan Crouse76fa9a22006-01-20 14:06:09 -080037
Jordan Crouse76fa9a22006-01-20 14:06:09 -080038#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
39
Jordan Crouse76fa9a22006-01-20 14:06:09 -080040extern int usb_disabled(void);
41
Manuel Lauss53c81a32008-06-23 09:08:29 +020042static void au1xxx_start_ehc(void)
Jordan Crouse76fa9a22006-01-20 14:06:09 -080043{
Manuel Lauss53c81a32008-06-23 09:08:29 +020044 /* 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();
Jordan Crouse76fa9a22006-01-20 14:06:09 -080047 udelay(1000);
48
Manuel Lauss53c81a32008-06-23 09:08:29 +020049 /* enable EHCI mmio */
50 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
51 au_sync();
52 udelay(1000);
Jordan Crouse76fa9a22006-01-20 14:06:09 -080053}
54
Manuel Lauss53c81a32008-06-23 09:08:29 +020055static void au1xxx_stop_ehc(void)
Jordan Crouse76fa9a22006-01-20 14:06:09 -080056{
Manuel Lauss53c81a32008-06-23 09:08:29 +020057 unsigned long c;
Jordan Crouse76fa9a22006-01-20 14:06:09 -080058
59 /* Disable mem */
Manuel Lauss53c81a32008-06-23 09:08:29 +020060 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
61 au_sync();
Jordan Crouse76fa9a22006-01-20 14:06:09 -080062 udelay(1000);
Manuel Lauss53c81a32008-06-23 09:08:29 +020063
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();
Jordan Crouse76fa9a22006-01-20 14:06:09 -080070}
71
Jordan Crouse76fa9a22006-01-20 14:06:09 -080072static const struct hc_driver ehci_au1xxx_hc_driver = {
Manuel Lauss53c81a32008-06-23 09:08:29 +020073 .description = hcd_name,
74 .product_desc = "Au1xxx EHCI",
75 .hcd_priv_size = sizeof(struct ehci_hcd),
Jordan Crouse76fa9a22006-01-20 14:06:09 -080076
77 /*
78 * generic hardware linkage
79 */
Manuel Lauss53c81a32008-06-23 09:08:29 +020080 .irq = ehci_irq,
81 .flags = HCD_MEMORY | HCD_USB2,
Jordan Crouse76fa9a22006-01-20 14:06:09 -080082
83 /*
84 * basic lifecycle operations
Mike Nussc907d3b2007-08-20 18:21:15 -070085 *
86 * FIXME -- ehci_init() doesn't do enough here.
87 * See ehci-ppc-soc for a complete implementation.
Jordan Crouse76fa9a22006-01-20 14:06:09 -080088 */
Manuel Lauss53c81a32008-06-23 09:08:29 +020089 .reset = ehci_init,
90 .start = ehci_run,
91 .stop = ehci_stop,
92 .shutdown = ehci_shutdown,
Jordan Crouse76fa9a22006-01-20 14:06:09 -080093
94 /*
95 * managing i/o requests and associated device resources
96 */
Manuel Lauss53c81a32008-06-23 09:08:29 +020097 .urb_enqueue = ehci_urb_enqueue,
98 .urb_dequeue = ehci_urb_dequeue,
99 .endpoint_disable = ehci_endpoint_disable,
Alan Sternb18ffd42009-05-27 18:21:56 -0400100 .endpoint_reset = ehci_endpoint_reset,
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800101
102 /*
103 * scheduling support
104 */
Manuel Lauss53c81a32008-06-23 09:08:29 +0200105 .get_frame_number = ehci_get_frame,
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800106
107 /*
108 * root hub support
109 */
Manuel Lauss53c81a32008-06-23 09:08:29 +0200110 .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,
Alan Stern914b7012009-06-29 10:47:30 -0400116
117 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800118};
119
Daniel Mackd14feb52006-06-23 21:36:07 +0100120static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800121{
Manuel Lauss53c81a32008-06-23 09:08:29 +0200122 struct usb_hcd *hcd;
123 struct ehci_hcd *ehci;
H Hartley Sweeten1f141ca2009-12-14 18:22:42 -0500124 struct resource *res;
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800125 int ret;
126
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800127 if (usb_disabled())
128 return -ENODEV;
129
Manuel Lauss53c81a32008-06-23 09:08:29 +0200130#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
131 /* Au1200 AB USB does not support coherent memory */
132 if (!(read_c0_prid() & 0xff)) {
133 printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
134 printk(KERN_INFO "%s: update your board or re-configure"
135 " the kernel\n", pdev->name);
136 return -ENODEV;
137 }
138#endif
139
140 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
141 pr_debug("resource[1] is not IORESOURCE_IRQ");
142 return -ENOMEM;
143 }
144 hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
145 if (!hcd)
146 return -ENOMEM;
147
H Hartley Sweeten1f141ca2009-12-14 18:22:42 -0500148 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
149 hcd->rsrc_start = res->start;
150 hcd->rsrc_len = resource_size(res);
Manuel Lauss53c81a32008-06-23 09:08:29 +0200151
152 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
153 pr_debug("request_mem_region failed");
154 ret = -EBUSY;
155 goto err1;
156 }
157
158 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
159 if (!hcd->regs) {
160 pr_debug("ioremap failed");
161 ret = -ENOMEM;
162 goto err2;
163 }
164
165 au1xxx_start_ehc();
166
167 ehci = hcd_to_ehci(hcd);
168 ehci->caps = hcd->regs;
169 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
170 /* cache this readonly data; minimize chip reads */
171 ehci->hcs_params = readl(&ehci->caps->hcs_params);
172
173 ret = usb_add_hcd(hcd, pdev->resource[1].start,
174 IRQF_DISABLED | IRQF_SHARED);
175 if (ret == 0) {
176 platform_set_drvdata(pdev, hcd);
177 return ret;
178 }
179
180 au1xxx_stop_ehc();
181 iounmap(hcd->regs);
182err2:
183 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
184err1:
185 usb_put_hcd(hcd);
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800186 return ret;
187}
188
Daniel Mackd14feb52006-06-23 21:36:07 +0100189static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800190{
Daniel Mackd14feb52006-06-23 21:36:07 +0100191 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800192
Manuel Lauss53c81a32008-06-23 09:08:29 +0200193 usb_remove_hcd(hcd);
194 iounmap(hcd->regs);
195 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
196 usb_put_hcd(hcd);
197 au1xxx_stop_ehc();
198 platform_set_drvdata(pdev, NULL);
199
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800200 return 0;
201}
202
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200203#ifdef CONFIG_PM
Manuel Lauss807fcb52009-07-29 19:13:13 +0200204static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800205{
Manuel Lauss807fcb52009-07-29 19:13:13 +0200206 struct usb_hcd *hcd = dev_get_drvdata(dev);
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200207 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
208 unsigned long flags;
209 int rc;
210
211 return 0;
212 rc = 0;
213
214 if (time_before(jiffies, ehci->next_statechange))
215 msleep(10);
216
217 /* Root hub was already suspended. Disable irq emission and
218 * mark HW unaccessible, bail out if RH has been resumed. Use
219 * the spinlock to properly synchronize with possible pending
220 * RH suspend or resume activity.
221 *
222 * This is still racy as hcd->state is manipulated outside of
223 * any locks =P But that will be a different fix.
224 */
225 spin_lock_irqsave(&ehci->lock, flags);
226 if (hcd->state != HC_STATE_SUSPENDED) {
227 rc = -EINVAL;
228 goto bail;
229 }
230 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
231 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
232
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200233 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
234
235 au1xxx_stop_ehc();
236
237bail:
238 spin_unlock_irqrestore(&ehci->lock, flags);
239
240 // could save FLADJ in case of Vaux power loss
241 // ... we'd only use it to handle clock skew
242
243 return rc;
244}
245
Manuel Lauss807fcb52009-07-29 19:13:13 +0200246static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200247{
Manuel Lauss807fcb52009-07-29 19:13:13 +0200248 struct usb_hcd *hcd = dev_get_drvdata(dev);
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200249 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
250
251 au1xxx_start_ehc();
252
253 // maybe restore FLADJ
254
255 if (time_before(jiffies, ehci->next_statechange))
256 msleep(100);
257
258 /* Mark hardware accessible again as we are out of D3 state by now */
259 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
260
261 /* If CF is still set, we maintained PCI Vaux power.
262 * Just undo the effect of ehci_pci_suspend().
263 */
264 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
265 int mask = INTR_MASK;
266
267 if (!hcd->self.root_hub->do_remote_wakeup)
268 mask &= ~STS_PCD;
269 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
270 ehci_readl(ehci, &ehci->regs->intr_enable);
271 return 0;
272 }
273
274 ehci_dbg(ehci, "lost power, restarting\n");
275 usb_root_hub_lost_power(hcd->self.root_hub);
276
277 /* Else reset, to cope with power loss or flush-to-storage
278 * style "resume" having let BIOS kick in during reboot.
279 */
280 (void) ehci_halt(ehci);
281 (void) ehci_reset(ehci);
282
283 /* emptying the schedule aborts any urbs */
284 spin_lock_irq(&ehci->lock);
285 if (ehci->reclaim)
286 end_unlink_async(ehci);
287 ehci_work(ehci);
288 spin_unlock_irq(&ehci->lock);
289
290 ehci_writel(ehci, ehci->command, &ehci->regs->command);
291 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
292 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
293
294 /* here we "know" root ports should always stay powered */
295 ehci_port_power(ehci, 1);
296
297 hcd->state = HC_STATE_SUSPENDED;
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800298
299 return 0;
300}
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800301
Alexey Dobriyan47145212009-12-14 18:00:08 -0800302static const struct dev_pm_ops au1xxx_ehci_pmops = {
Manuel Lauss807fcb52009-07-29 19:13:13 +0200303 .suspend = ehci_hcd_au1xxx_drv_suspend,
304 .resume = ehci_hcd_au1xxx_drv_resume,
305};
306
307#define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
308
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200309#else
Manuel Lauss807fcb52009-07-29 19:13:13 +0200310#define AU1XXX_EHCI_PMOPS NULL
Manuel Lauss42bfc7b2008-06-23 09:09:37 +0200311#endif
Manuel Lauss53c81a32008-06-23 09:08:29 +0200312
Daniel Mackd14feb52006-06-23 21:36:07 +0100313static struct platform_driver ehci_hcd_au1xxx_driver = {
Manuel Lauss53c81a32008-06-23 09:08:29 +0200314 .probe = ehci_hcd_au1xxx_drv_probe,
315 .remove = ehci_hcd_au1xxx_drv_remove,
316 .shutdown = usb_hcd_platform_shutdown,
Daniel Mackd14feb52006-06-23 21:36:07 +0100317 .driver = {
Manuel Lauss53c81a32008-06-23 09:08:29 +0200318 .name = "au1xxx-ehci",
319 .owner = THIS_MODULE,
Manuel Lauss807fcb52009-07-29 19:13:13 +0200320 .pm = AU1XXX_EHCI_PMOPS,
Daniel Mackd14feb52006-06-23 21:36:07 +0100321 }
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800322};
Manuel Lauss53c81a32008-06-23 09:08:29 +0200323
324MODULE_ALIAS("platform:au1xxx-ehci");