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