1/* 2 * EHCI HCD (Host Controller Driver) for USB. 3 * 4 * Bus Glue for MIPS CI13320A 5 * 6 * Based on "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com> 7 * 8 * This file is licenced under the GPL. 9 */ 10 11#include <linux/platform_device.h> 12 13extern int usb_disabled(void); 14 15#ifdef CONFIG_PM 16static void mips_start_ehc(void) 17{ 18 pr_debug("mips_start_ehc\n"); 19} 20#endif 21 22static void mips_stop_ehc(void) 23{ 24 pr_debug("mips_start_ehc\n"); 25} 26 27static const struct hc_driver ehci_mips_hc_driver = { 28 .description = hcd_name, 29 .product_desc = "MIPS EHCI", 30 .hcd_priv_size = sizeof(struct ehci_hcd), 31 32 /* 33 * generic hardware linkage 34 */ 35 .irq = ehci_irq, 36 .flags = HCD_MEMORY | HCD_USB2, 37 38 /* 39 * basic lifecycle operations 40 * 41 */ 42 .reset = ehci_init, 43 .start = ehci_run, 44 .stop = ehci_stop, 45 .shutdown = ehci_shutdown, 46 47 /* 48 * managing i/o requests and associated device resources 49 */ 50 .urb_enqueue = ehci_urb_enqueue, 51 .urb_dequeue = ehci_urb_dequeue, 52 .endpoint_disable = ehci_endpoint_disable, 53 54 /* 55 * scheduling support 56 */ 57 .get_frame_number = ehci_get_frame, 58 59 /* 60 * root hub support 61 */ 62 .hub_status_data = ehci_hub_status_data, 63 .hub_control = ehci_hub_control, 64 .bus_suspend = ehci_bus_suspend, 65 .bus_resume = ehci_bus_resume, 66 .relinquish_port = ehci_relinquish_port, 67 .port_handed_over = ehci_port_handed_over, 68}; 69 70static int ehci_hcd_mips_drv_probe(struct platform_device *pdev) 71{ 72 struct usb_hcd *hcd; 73 struct ehci_hcd *ehci; 74 int ret; 75 76 if (usb_disabled()) 77 return -ENODEV; 78 79 if (pdev->resource[1].flags != IORESOURCE_IRQ) { 80 pr_debug("resource[1] is not IORESOURCE_IRQ"); 81 return -ENOMEM; 82 } 83 hcd = usb_create_hcd(&ehci_mips_hc_driver, &pdev->dev, "MIPS"); 84 if (!hcd) 85 return -ENOMEM; 86 87 hcd->rsrc_start = pdev->resource[0].start; 88 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; 89 90 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 91 pr_debug("request_mem_region failed"); 92 ret = -EBUSY; 93 goto err1; 94 } 95 96 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 97 if (!hcd->regs) { 98 pr_debug("ioremap failed"); 99 ret = -ENOMEM; 100 goto err2; 101 } 102 103 hcd->has_tt = 1; 104 105 ehci = hcd_to_ehci(hcd); 106 ehci->caps = hcd->regs + 0x100; 107 ehci->regs = hcd->regs + 0x100 + HC_LENGTH(readl(&ehci->caps->hc_capbase)); 108 /* cache this readonly data; minimize chip reads */ 109 ehci->hcs_params = readl(&ehci->caps->hcs_params); 110 111#if defined(CONFIG_MIPS) 112#if defined(CONFIG_CPU_BIG_ENDIAN) 113 ehci->big_endian_desc = 1; 114#endif 115#if defined(CONFIG_CPU_LITTLE_ENDIAN) 116 ehci->big_endian_desc = 0; 117#endif 118#endif 119 /* Set burst length to 16 words */ 120 ehci_writel(ehci, 0x1010, &ehci->regs->reserved[1]); 121 122 ret = usb_add_hcd(hcd, pdev->resource[1].start, 123 IRQF_DISABLED | IRQF_SHARED); 124 if (ret == 0) { 125 platform_set_drvdata(pdev, hcd); 126 return ret; 127 } 128 129 mips_stop_ehc(); 130 iounmap(hcd->regs); 131err2: 132 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 133err1: 134 usb_put_hcd(hcd); 135 return ret; 136} 137 138static int ehci_hcd_mips_drv_remove(struct platform_device *pdev) 139{ 140 struct usb_hcd *hcd = platform_get_drvdata(pdev); 141 142 usb_remove_hcd(hcd); 143 iounmap(hcd->regs); 144 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 145 usb_put_hcd(hcd); 146 mips_stop_ehc(); 147 platform_set_drvdata(pdev, NULL); 148 149 return 0; 150} 151 152#ifdef CONFIG_PM 153static int ehci_hcd_mips_drv_suspend(struct platform_device *pdev, 154 pm_message_t message) 155{ 156 struct usb_hcd *hcd = platform_get_drvdata(pdev); 157 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 158 unsigned long flags; 159 int rc; 160 161 return 0; 162 rc = 0; 163 164 if (time_before(jiffies, ehci->next_statechange)) 165 msleep(10); 166 167 /* Root hub was already suspended. Disable irq emission and 168 * mark HW unaccessible, bail out if RH has been resumed. Use 169 * the spinlock to properly synchronize with possible pending 170 * RH suspend or resume activity. 171 * 172 * This is still racy as hcd->state is manipulated outside of 173 * any locks =P But that will be a different fix. 174 */ 175 spin_lock_irqsave(&ehci->lock, flags); 176 if (hcd->state != HC_STATE_SUSPENDED) { 177 rc = -EINVAL; 178 goto bail; 179 } 180 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 181 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 182 183 /* make sure snapshot being resumed re-enumerates everything */ 184 if (message.event == PM_EVENT_PRETHAW) { 185 ehci_halt(ehci); 186 ehci_reset(ehci); 187 } 188 189 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 190 191 mips_stop_ehc(); 192 193bail: 194 spin_unlock_irqrestore(&ehci->lock, flags); 195 196 /* could save FLADJ in case of Vaux power loss */ 197 /* ... we'd only use it to handle clock skew */ 198 199 return rc; 200} 201 202 203static int ehci_hcd_mips_drv_resume(struct platform_device *pdev) 204{ 205 struct usb_hcd *hcd = platform_get_drvdata(pdev); 206 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 207 208 mips_start_ehc(); 209 210 /* maybe restore FLADJ */ 211 212 if (time_before(jiffies, ehci->next_statechange)) 213 msleep(100); 214 215 /* Mark hardware accessible again as we are out of D3 state by now */ 216 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 217 218 /* If CF is still set, we maintained PCI Vaux power. 219 * Just undo the effect of ehci_pci_suspend(). 220 */ 221 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) { 222 int mask = INTR_MASK; 223 224 if (!hcd->self.root_hub->do_remote_wakeup) 225 mask &= ~STS_PCD; 226 ehci_writel(ehci, mask, &ehci->regs->intr_enable); 227 ehci_readl(ehci, &ehci->regs->intr_enable); 228 return 0; 229 } 230 231 ehci_dbg(ehci, "lost power, restarting\n"); 232 usb_root_hub_lost_power(hcd->self.root_hub); 233 234 /* Else reset, to cope with power loss or flush-to-storage 235 * style "resume" having let BIOS kick in during reboot. 236 */ 237 (void) ehci_halt(ehci); 238 (void) ehci_reset(ehci); 239 240 /* emptying the schedule aborts any urbs */ 241 spin_lock_irq(&ehci->lock); 242 if (ehci->reclaim) 243 end_unlink_async(ehci); 244 ehci_work(ehci); 245 spin_unlock_irq(&ehci->lock); 246 247 ehci_writel(ehci, ehci->command, &ehci->regs->command); 248 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); 249 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ 250 251 /* here we "know" root ports should always stay powered */ 252 ehci_port_power(ehci, 1); 253 254 hcd->state = HC_STATE_SUSPENDED; 255 256 return 0; 257} 258 259#else 260#define ehci_hcd_mips_drv_suspend NULL 261#define ehci_hcd_mips_drv_resume NULL 262#endif 263 264static struct platform_driver ehci_hcd_mips_driver = { 265 .probe = ehci_hcd_mips_drv_probe, 266 .remove = ehci_hcd_mips_drv_remove, 267 .shutdown = usb_hcd_platform_shutdown, 268 .suspend = ehci_hcd_mips_drv_suspend, 269 .resume = ehci_hcd_mips_drv_resume, 270 .driver = { 271 .name = "ci13xxx-ehci", 272 .owner = THIS_MODULE, 273 } 274}; 275 276MODULE_ALIAS("platform:ci13xxx-ehci"); 277