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