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 | |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 18 | extern int usb_disabled(void); |
| 19 | |
Manuel Lauss | 9757de3 | 2010-03-08 20:43:32 +0100 | [diff] [blame] | 20 | static int au1xxx_ehci_setup(struct usb_hcd *hcd) |
| 21 | { |
| 22 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 23 | int ret = ehci_init(hcd); |
| 24 | |
| 25 | ehci->need_io_watchdog = 0; |
Geoff Levand | 876e0df | 2011-11-22 18:04:45 -0800 | [diff] [blame] | 26 | ehci_reset(ehci); |
Manuel Lauss | 9757de3 | 2010-03-08 20:43:32 +0100 | [diff] [blame] | 27 | return ret; |
| 28 | } |
| 29 | |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 30 | static const struct hc_driver ehci_au1xxx_hc_driver = { |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 31 | .description = hcd_name, |
| 32 | .product_desc = "Au1xxx EHCI", |
| 33 | .hcd_priv_size = sizeof(struct ehci_hcd), |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * generic hardware linkage |
| 37 | */ |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 38 | .irq = ehci_irq, |
| 39 | .flags = HCD_MEMORY | HCD_USB2, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * basic lifecycle operations |
Mike Nuss | c907d3b | 2007-08-20 18:21:15 -0700 | [diff] [blame] | 43 | * |
| 44 | * FIXME -- ehci_init() doesn't do enough here. |
| 45 | * See ehci-ppc-soc for a complete implementation. |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 46 | */ |
Manuel Lauss | 9757de3 | 2010-03-08 20:43:32 +0100 | [diff] [blame] | 47 | .reset = au1xxx_ehci_setup, |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 48 | .start = ehci_run, |
| 49 | .stop = ehci_stop, |
| 50 | .shutdown = ehci_shutdown, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * managing i/o requests and associated device resources |
| 54 | */ |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 55 | .urb_enqueue = ehci_urb_enqueue, |
| 56 | .urb_dequeue = ehci_urb_dequeue, |
| 57 | .endpoint_disable = ehci_endpoint_disable, |
Alan Stern | b18ffd4 | 2009-05-27 18:21:56 -0400 | [diff] [blame] | 58 | .endpoint_reset = ehci_endpoint_reset, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * scheduling support |
| 62 | */ |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 63 | .get_frame_number = ehci_get_frame, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * root hub support |
| 67 | */ |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 68 | .hub_status_data = ehci_hub_status_data, |
| 69 | .hub_control = ehci_hub_control, |
| 70 | .bus_suspend = ehci_bus_suspend, |
| 71 | .bus_resume = ehci_bus_resume, |
| 72 | .relinquish_port = ehci_relinquish_port, |
| 73 | .port_handed_over = ehci_port_handed_over, |
Alan Stern | 914b701 | 2009-06-29 10:47:30 -0400 | [diff] [blame] | 74 | |
| 75 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 78 | static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev) |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 79 | { |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 80 | struct usb_hcd *hcd; |
| 81 | struct ehci_hcd *ehci; |
H Hartley Sweeten | 1f141ca | 2009-12-14 18:22:42 -0500 | [diff] [blame] | 82 | struct resource *res; |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 83 | int ret; |
| 84 | |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 85 | if (usb_disabled()) |
| 86 | return -ENODEV; |
| 87 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 88 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
| 89 | pr_debug("resource[1] is not IORESOURCE_IRQ"); |
| 90 | return -ENOMEM; |
| 91 | } |
| 92 | hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx"); |
| 93 | if (!hcd) |
| 94 | return -ENOMEM; |
| 95 | |
H Hartley Sweeten | 1f141ca | 2009-12-14 18:22:42 -0500 | [diff] [blame] | 96 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 97 | hcd->rsrc_start = res->start; |
| 98 | hcd->rsrc_len = resource_size(res); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 99 | |
| 100 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 101 | pr_debug("request_mem_region failed"); |
| 102 | ret = -EBUSY; |
| 103 | goto err1; |
| 104 | } |
| 105 | |
| 106 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 107 | if (!hcd->regs) { |
| 108 | pr_debug("ioremap failed"); |
| 109 | ret = -ENOMEM; |
| 110 | goto err2; |
| 111 | } |
| 112 | |
Manuel Lauss | ce6bc92 | 2011-08-12 20:12:33 +0200 | [diff] [blame] | 113 | if (alchemy_usb_control(ALCHEMY_USB_EHCI0, 1)) { |
| 114 | printk(KERN_INFO "%s: controller init failed!\n", pdev->name); |
| 115 | ret = -ENODEV; |
| 116 | goto err3; |
| 117 | } |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 118 | |
| 119 | ehci = hcd_to_ehci(hcd); |
| 120 | ehci->caps = hcd->regs; |
Jan Andersson | c430131 | 2011-05-03 20:11:57 +0200 | [diff] [blame] | 121 | ehci->regs = hcd->regs + |
| 122 | HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase)); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 123 | /* cache this readonly data; minimize chip reads */ |
| 124 | ehci->hcs_params = readl(&ehci->caps->hcs_params); |
| 125 | |
| 126 | ret = usb_add_hcd(hcd, pdev->resource[1].start, |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 127 | IRQF_SHARED); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 128 | if (ret == 0) { |
| 129 | platform_set_drvdata(pdev, hcd); |
| 130 | return ret; |
| 131 | } |
| 132 | |
Manuel Lauss | ce6bc92 | 2011-08-12 20:12:33 +0200 | [diff] [blame] | 133 | alchemy_usb_control(ALCHEMY_USB_EHCI0, 0); |
| 134 | err3: |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 135 | iounmap(hcd->regs); |
| 136 | err2: |
| 137 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 138 | err1: |
| 139 | usb_put_hcd(hcd); |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 140 | return ret; |
| 141 | } |
| 142 | |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 143 | static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev) |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 144 | { |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 145 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 146 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 147 | usb_remove_hcd(hcd); |
Manuel Lauss | ce6bc92 | 2011-08-12 20:12:33 +0200 | [diff] [blame] | 148 | alchemy_usb_control(ALCHEMY_USB_EHCI0, 0); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 149 | iounmap(hcd->regs); |
| 150 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 151 | usb_put_hcd(hcd); |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 152 | platform_set_drvdata(pdev, NULL); |
| 153 | |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 157 | #ifdef CONFIG_PM |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 158 | static int ehci_hcd_au1xxx_drv_suspend(struct device *dev) |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 159 | { |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 160 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 161 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 162 | unsigned long flags; |
Manuel Lauss | a7535ac | 2011-05-05 16:35:24 +0200 | [diff] [blame] | 163 | int rc = 0; |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 164 | |
| 165 | if (time_before(jiffies, ehci->next_statechange)) |
| 166 | msleep(10); |
| 167 | |
| 168 | /* Root hub was already suspended. Disable irq emission and |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 169 | * mark HW unaccessible. The PM and USB cores make sure that |
| 170 | * the root hub is either suspended or stopped. |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 171 | */ |
Alan Stern | 4147200 | 2010-06-25 14:02:14 -0400 | [diff] [blame] | 172 | ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev)); |
Yin Kangkai | 148fc55 | 2011-01-28 12:04:35 +0800 | [diff] [blame] | 173 | spin_lock_irqsave(&ehci->lock, flags); |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 174 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); |
| 175 | (void)ehci_readl(ehci, &ehci->regs->intr_enable); |
| 176 | |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 177 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 178 | spin_unlock_irqrestore(&ehci->lock, flags); |
| 179 | |
| 180 | // could save FLADJ in case of Vaux power loss |
| 181 | // ... we'd only use it to handle clock skew |
| 182 | |
Manuel Lauss | ce6bc92 | 2011-08-12 20:12:33 +0200 | [diff] [blame] | 183 | alchemy_usb_control(ALCHEMY_USB_EHCI0, 0); |
Manuel Lauss | a7535ac | 2011-05-05 16:35:24 +0200 | [diff] [blame] | 184 | |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 185 | return rc; |
| 186 | } |
| 187 | |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 188 | static int ehci_hcd_au1xxx_drv_resume(struct device *dev) |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 189 | { |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 190 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 191 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 192 | |
Manuel Lauss | ce6bc92 | 2011-08-12 20:12:33 +0200 | [diff] [blame] | 193 | alchemy_usb_control(ALCHEMY_USB_EHCI0, 1); |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 194 | |
| 195 | // maybe restore FLADJ |
| 196 | |
| 197 | if (time_before(jiffies, ehci->next_statechange)) |
| 198 | msleep(100); |
| 199 | |
| 200 | /* Mark hardware accessible again as we are out of D3 state by now */ |
| 201 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 202 | |
| 203 | /* If CF is still set, we maintained PCI Vaux power. |
| 204 | * Just undo the effect of ehci_pci_suspend(). |
| 205 | */ |
| 206 | if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) { |
| 207 | int mask = INTR_MASK; |
| 208 | |
Alan Stern | 16032c4 | 2010-05-12 18:21:35 -0400 | [diff] [blame] | 209 | ehci_prepare_ports_for_controller_resume(ehci); |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 210 | if (!hcd->self.root_hub->do_remote_wakeup) |
| 211 | mask &= ~STS_PCD; |
| 212 | ehci_writel(ehci, mask, &ehci->regs->intr_enable); |
| 213 | ehci_readl(ehci, &ehci->regs->intr_enable); |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | ehci_dbg(ehci, "lost power, restarting\n"); |
| 218 | usb_root_hub_lost_power(hcd->self.root_hub); |
| 219 | |
| 220 | /* Else reset, to cope with power loss or flush-to-storage |
| 221 | * style "resume" having let BIOS kick in during reboot. |
| 222 | */ |
| 223 | (void) ehci_halt(ehci); |
| 224 | (void) ehci_reset(ehci); |
| 225 | |
| 226 | /* emptying the schedule aborts any urbs */ |
| 227 | spin_lock_irq(&ehci->lock); |
| 228 | if (ehci->reclaim) |
| 229 | end_unlink_async(ehci); |
| 230 | ehci_work(ehci); |
| 231 | spin_unlock_irq(&ehci->lock); |
| 232 | |
| 233 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
| 234 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); |
| 235 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ |
| 236 | |
| 237 | /* here we "know" root ports should always stay powered */ |
| 238 | ehci_port_power(ehci, 1); |
| 239 | |
Alan Stern | e879990 | 2011-08-18 16:31:30 -0400 | [diff] [blame] | 240 | ehci->rh_state = EHCI_RH_SUSPENDED; |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 241 | |
| 242 | return 0; |
| 243 | } |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 244 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 245 | static const struct dev_pm_ops au1xxx_ehci_pmops = { |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 246 | .suspend = ehci_hcd_au1xxx_drv_suspend, |
| 247 | .resume = ehci_hcd_au1xxx_drv_resume, |
| 248 | }; |
| 249 | |
| 250 | #define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops |
| 251 | |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 252 | #else |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 253 | #define AU1XXX_EHCI_PMOPS NULL |
Manuel Lauss | 42bfc7b | 2008-06-23 09:09:37 +0200 | [diff] [blame] | 254 | #endif |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 255 | |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 256 | static struct platform_driver ehci_hcd_au1xxx_driver = { |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 257 | .probe = ehci_hcd_au1xxx_drv_probe, |
| 258 | .remove = ehci_hcd_au1xxx_drv_remove, |
| 259 | .shutdown = usb_hcd_platform_shutdown, |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 260 | .driver = { |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 261 | .name = "au1xxx-ehci", |
| 262 | .owner = THIS_MODULE, |
Manuel Lauss | 807fcb5 | 2009-07-29 19:13:13 +0200 | [diff] [blame] | 263 | .pm = AU1XXX_EHCI_PMOPS, |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 264 | } |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 265 | }; |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame] | 266 | |
| 267 | MODULE_ALIAS("platform:au1xxx-ehci"); |