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, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 100 | |
| 101 | /* |
| 102 | * scheduling support |
| 103 | */ |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame^] | 104 | .get_frame_number = ehci_get_frame, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * root hub support |
| 108 | */ |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame^] | 109 | .hub_status_data = ehci_hub_status_data, |
| 110 | .hub_control = ehci_hub_control, |
| 111 | .bus_suspend = ehci_bus_suspend, |
| 112 | .bus_resume = ehci_bus_resume, |
| 113 | .relinquish_port = ehci_relinquish_port, |
| 114 | .port_handed_over = ehci_port_handed_over, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 117 | static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev) |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 118 | { |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame^] | 119 | struct usb_hcd *hcd; |
| 120 | struct ehci_hcd *ehci; |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 121 | int ret; |
| 122 | |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 123 | if (usb_disabled()) |
| 124 | return -ENODEV; |
| 125 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame^] | 126 | #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT) |
| 127 | /* Au1200 AB USB does not support coherent memory */ |
| 128 | if (!(read_c0_prid() & 0xff)) { |
| 129 | printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name); |
| 130 | printk(KERN_INFO "%s: update your board or re-configure" |
| 131 | " the kernel\n", pdev->name); |
| 132 | return -ENODEV; |
| 133 | } |
| 134 | #endif |
| 135 | |
| 136 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
| 137 | pr_debug("resource[1] is not IORESOURCE_IRQ"); |
| 138 | return -ENOMEM; |
| 139 | } |
| 140 | hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx"); |
| 141 | if (!hcd) |
| 142 | return -ENOMEM; |
| 143 | |
| 144 | hcd->rsrc_start = pdev->resource[0].start; |
| 145 | hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; |
| 146 | |
| 147 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 148 | pr_debug("request_mem_region failed"); |
| 149 | ret = -EBUSY; |
| 150 | goto err1; |
| 151 | } |
| 152 | |
| 153 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 154 | if (!hcd->regs) { |
| 155 | pr_debug("ioremap failed"); |
| 156 | ret = -ENOMEM; |
| 157 | goto err2; |
| 158 | } |
| 159 | |
| 160 | au1xxx_start_ehc(); |
| 161 | |
| 162 | ehci = hcd_to_ehci(hcd); |
| 163 | ehci->caps = hcd->regs; |
| 164 | ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase)); |
| 165 | /* cache this readonly data; minimize chip reads */ |
| 166 | ehci->hcs_params = readl(&ehci->caps->hcs_params); |
| 167 | |
| 168 | ret = usb_add_hcd(hcd, pdev->resource[1].start, |
| 169 | IRQF_DISABLED | IRQF_SHARED); |
| 170 | if (ret == 0) { |
| 171 | platform_set_drvdata(pdev, hcd); |
| 172 | return ret; |
| 173 | } |
| 174 | |
| 175 | au1xxx_stop_ehc(); |
| 176 | iounmap(hcd->regs); |
| 177 | err2: |
| 178 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 179 | err1: |
| 180 | usb_put_hcd(hcd); |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 181 | return ret; |
| 182 | } |
| 183 | |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 184 | static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev) |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 185 | { |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 186 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 187 | |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame^] | 188 | usb_remove_hcd(hcd); |
| 189 | iounmap(hcd->regs); |
| 190 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 191 | usb_put_hcd(hcd); |
| 192 | au1xxx_stop_ehc(); |
| 193 | platform_set_drvdata(pdev, NULL); |
| 194 | |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | /*TBD*/ |
| 199 | /*static int ehci_hcd_au1xxx_drv_suspend(struct device *dev) |
| 200 | { |
| 201 | struct platform_device *pdev = to_platform_device(dev); |
| 202 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | static int ehci_hcd_au1xxx_drv_resume(struct device *dev) |
| 207 | { |
| 208 | struct platform_device *pdev = to_platform_device(dev); |
| 209 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | */ |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame^] | 214 | |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 215 | static struct platform_driver ehci_hcd_au1xxx_driver = { |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame^] | 216 | .probe = ehci_hcd_au1xxx_drv_probe, |
| 217 | .remove = ehci_hcd_au1xxx_drv_remove, |
| 218 | .shutdown = usb_hcd_platform_shutdown, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 219 | /*.suspend = ehci_hcd_au1xxx_drv_suspend, */ |
| 220 | /*.resume = ehci_hcd_au1xxx_drv_resume, */ |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 221 | .driver = { |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame^] | 222 | .name = "au1xxx-ehci", |
| 223 | .owner = THIS_MODULE, |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 224 | } |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 225 | }; |
Manuel Lauss | 53c81a3 | 2008-06-23 09:08:29 +0200 | [diff] [blame^] | 226 | |
| 227 | MODULE_ALIAS("platform:au1xxx-ehci"); |