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) |
| 22 | #define USB_MCFG_EHCCLKEN (1<<17) |
| 23 | #define USB_MCFG_UCAM (1<<7) |
| 24 | #define USB_MCFG_EBMEN (1<<3) |
| 25 | #define USB_MCFG_EMEMEN (1<<2) |
| 26 | |
| 27 | #define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN) |
| 28 | |
| 29 | #ifdef CONFIG_DMA_COHERENT |
| 30 | #define USBH_ENABLE_INIT (USBH_ENABLE_CE \ |
| 31 | | USB_MCFG_PFEN | USB_MCFG_RDCOMB \ |
| 32 | | USB_MCFG_SSDEN | USB_MCFG_UCAM \ |
| 33 | | USB_MCFG_EBMEN | USB_MCFG_EMEMEN) |
| 34 | #else |
| 35 | #define USBH_ENABLE_INIT (USBH_ENABLE_CE \ |
| 36 | | USB_MCFG_PFEN | USB_MCFG_RDCOMB \ |
| 37 | | USB_MCFG_SSDEN \ |
| 38 | | USB_MCFG_EBMEN | USB_MCFG_EMEMEN) |
| 39 | #endif |
| 40 | #define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN) |
| 41 | |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 42 | extern int usb_disabled(void); |
| 43 | |
| 44 | /*-------------------------------------------------------------------------*/ |
| 45 | |
| 46 | static void au1xxx_start_ehc(struct platform_device *dev) |
| 47 | { |
| 48 | pr_debug(__FILE__ ": starting Au1xxx EHCI USB Controller\n"); |
| 49 | |
| 50 | /* write HW defaults again in case Yamon cleared them */ |
| 51 | if (au_readl(USB_HOST_CONFIG) == 0) { |
| 52 | au_writel(0x00d02000, USB_HOST_CONFIG); |
| 53 | au_readl(USB_HOST_CONFIG); |
| 54 | udelay(1000); |
| 55 | } |
| 56 | /* enable host controller */ |
| 57 | au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG); |
| 58 | au_readl(USB_HOST_CONFIG); |
| 59 | udelay(1000); |
| 60 | au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG), |
| 61 | USB_HOST_CONFIG); |
| 62 | au_readl(USB_HOST_CONFIG); |
| 63 | udelay(1000); |
| 64 | |
| 65 | pr_debug(__FILE__ ": Clock to USB host has been enabled\n"); |
| 66 | } |
| 67 | |
| 68 | static void au1xxx_stop_ehc(struct platform_device *dev) |
| 69 | { |
| 70 | pr_debug(__FILE__ ": stopping Au1xxx EHCI USB Controller\n"); |
| 71 | |
| 72 | /* Disable mem */ |
| 73 | au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG); |
| 74 | udelay(1000); |
| 75 | /* Disable clock */ |
| 76 | au_writel(~USB_MCFG_EHCCLKEN & au_readl(USB_HOST_CONFIG), |
| 77 | USB_HOST_CONFIG); |
| 78 | au_readl(USB_HOST_CONFIG); |
| 79 | } |
| 80 | |
| 81 | /*-------------------------------------------------------------------------*/ |
| 82 | |
| 83 | /* configure so an HC device and id are always provided */ |
| 84 | /* always called with process context; sleeping is OK */ |
| 85 | |
| 86 | /** |
| 87 | * usb_ehci_au1xxx_probe - initialize Au1xxx-based HCDs |
| 88 | * Context: !in_interrupt() |
| 89 | * |
| 90 | * Allocates basic resources for this USB host controller, and |
| 91 | * then invokes the start() method for the HCD associated with it |
| 92 | * through the hotplug entry's driver_data. |
| 93 | * |
| 94 | */ |
| 95 | int usb_ehci_au1xxx_probe(const struct hc_driver *driver, |
| 96 | struct usb_hcd **hcd_out, struct platform_device *dev) |
| 97 | { |
| 98 | int retval; |
| 99 | struct usb_hcd *hcd; |
| 100 | struct ehci_hcd *ehci; |
| 101 | |
| 102 | #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT) |
| 103 | |
| 104 | /* Au1200 AB USB does not support coherent memory */ |
| 105 | if (!(read_c0_prid() & 0xff)) { |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 106 | pr_info("%s: this is chip revision AB!\n", dev->name); |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 107 | pr_info("%s: update your board or re-configure the kernel\n", |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 108 | dev->name); |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 109 | return -ENODEV; |
| 110 | } |
| 111 | #endif |
| 112 | |
| 113 | au1xxx_start_ehc(dev); |
| 114 | |
| 115 | if (dev->resource[1].flags != IORESOURCE_IRQ) { |
| 116 | pr_debug("resource[1] is not IORESOURCE_IRQ"); |
| 117 | retval = -ENOMEM; |
| 118 | } |
| 119 | hcd = usb_create_hcd(driver, &dev->dev, "Au1xxx"); |
| 120 | if (!hcd) |
| 121 | return -ENOMEM; |
| 122 | hcd->rsrc_start = dev->resource[0].start; |
| 123 | hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1; |
| 124 | |
| 125 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 126 | pr_debug("request_mem_region failed"); |
| 127 | retval = -EBUSY; |
| 128 | goto err1; |
| 129 | } |
| 130 | |
| 131 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 132 | if (!hcd->regs) { |
| 133 | pr_debug("ioremap failed"); |
| 134 | retval = -ENOMEM; |
| 135 | goto err2; |
| 136 | } |
| 137 | |
| 138 | ehci = hcd_to_ehci(hcd); |
| 139 | ehci->caps = hcd->regs; |
| 140 | ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase)); |
| 141 | /* cache this readonly data; minimize chip reads */ |
| 142 | ehci->hcs_params = readl(&ehci->caps->hcs_params); |
| 143 | |
| 144 | /* ehci_hcd_init(hcd_to_ehci(hcd)); */ |
| 145 | |
| 146 | retval = |
Thomas Gleixner | d54b5ca | 2006-07-01 19:29:44 -0700 | [diff] [blame] | 147 | usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED | IRQF_SHARED); |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 148 | if (retval == 0) |
| 149 | return retval; |
| 150 | |
| 151 | au1xxx_stop_ehc(dev); |
| 152 | iounmap(hcd->regs); |
| 153 | err2: |
| 154 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 155 | err1: |
| 156 | usb_put_hcd(hcd); |
| 157 | return retval; |
| 158 | } |
| 159 | |
| 160 | /* may be called without controller electrically present */ |
| 161 | /* may be called with controller, bus, and devices active */ |
| 162 | |
| 163 | /** |
| 164 | * usb_ehci_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs |
| 165 | * @dev: USB Host Controller being removed |
| 166 | * Context: !in_interrupt() |
| 167 | * |
| 168 | * Reverses the effect of usb_ehci_hcd_au1xxx_probe(), first invoking |
| 169 | * the HCD's stop() method. It is always called from a thread |
| 170 | * context, normally "rmmod", "apmd", or something similar. |
| 171 | * |
| 172 | */ |
| 173 | void usb_ehci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev) |
| 174 | { |
| 175 | usb_remove_hcd(hcd); |
| 176 | iounmap(hcd->regs); |
| 177 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 178 | usb_put_hcd(hcd); |
| 179 | au1xxx_stop_ehc(dev); |
| 180 | } |
| 181 | |
| 182 | /*-------------------------------------------------------------------------*/ |
| 183 | |
| 184 | static const struct hc_driver ehci_au1xxx_hc_driver = { |
| 185 | .description = hcd_name, |
| 186 | .product_desc = "Au1xxx EHCI", |
| 187 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 188 | |
| 189 | /* |
| 190 | * generic hardware linkage |
| 191 | */ |
| 192 | .irq = ehci_irq, |
| 193 | .flags = HCD_MEMORY | HCD_USB2, |
| 194 | |
| 195 | /* |
| 196 | * basic lifecycle operations |
Mike Nuss | c907d3b | 2007-08-20 18:21:15 -0700 | [diff] [blame] | 197 | * |
| 198 | * FIXME -- ehci_init() doesn't do enough here. |
| 199 | * See ehci-ppc-soc for a complete implementation. |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 200 | */ |
| 201 | .reset = ehci_init, |
| 202 | .start = ehci_run, |
| 203 | .stop = ehci_stop, |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 204 | .shutdown = ehci_shutdown, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 205 | |
| 206 | /* |
| 207 | * managing i/o requests and associated device resources |
| 208 | */ |
| 209 | .urb_enqueue = ehci_urb_enqueue, |
| 210 | .urb_dequeue = ehci_urb_dequeue, |
| 211 | .endpoint_disable = ehci_endpoint_disable, |
| 212 | |
| 213 | /* |
| 214 | * scheduling support |
| 215 | */ |
| 216 | .get_frame_number = ehci_get_frame, |
| 217 | |
| 218 | /* |
| 219 | * root hub support |
| 220 | */ |
| 221 | .hub_status_data = ehci_hub_status_data, |
| 222 | .hub_control = ehci_hub_control, |
David Brownell | b24896c | 2007-10-09 22:04:16 -0700 | [diff] [blame] | 223 | .bus_suspend = ehci_bus_suspend, |
| 224 | .bus_resume = ehci_bus_resume, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | /*-------------------------------------------------------------------------*/ |
| 228 | |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 229 | static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev) |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 230 | { |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 231 | struct usb_hcd *hcd = NULL; |
| 232 | int ret; |
| 233 | |
| 234 | pr_debug("In ehci_hcd_au1xxx_drv_probe\n"); |
| 235 | |
| 236 | if (usb_disabled()) |
| 237 | return -ENODEV; |
| 238 | |
| 239 | ret = usb_ehci_au1xxx_probe(&ehci_au1xxx_hc_driver, &hcd, pdev); |
| 240 | return ret; |
| 241 | } |
| 242 | |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 243 | static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev) |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 244 | { |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 245 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 246 | |
| 247 | usb_ehci_au1xxx_remove(hcd, pdev); |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | /*TBD*/ |
| 252 | /*static int ehci_hcd_au1xxx_drv_suspend(struct device *dev) |
| 253 | { |
| 254 | struct platform_device *pdev = to_platform_device(dev); |
| 255 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | static int ehci_hcd_au1xxx_drv_resume(struct device *dev) |
| 260 | { |
| 261 | struct platform_device *pdev = to_platform_device(dev); |
| 262 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 263 | |
| 264 | return 0; |
| 265 | } |
| 266 | */ |
Kumar Gala | 01cced2 | 2006-04-11 10:07:16 -0500 | [diff] [blame] | 267 | MODULE_ALIAS("au1xxx-ehci"); |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 268 | static struct platform_driver ehci_hcd_au1xxx_driver = { |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 269 | .probe = ehci_hcd_au1xxx_drv_probe, |
| 270 | .remove = ehci_hcd_au1xxx_drv_remove, |
Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 271 | .shutdown = usb_hcd_platform_shutdown, |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 272 | /*.suspend = ehci_hcd_au1xxx_drv_suspend, */ |
| 273 | /*.resume = ehci_hcd_au1xxx_drv_resume, */ |
Daniel Mack | d14feb5 | 2006-06-23 21:36:07 +0100 | [diff] [blame] | 274 | .driver = { |
| 275 | .name = "au1xxx-ehci", |
| 276 | .bus = &platform_bus_type |
| 277 | } |
Jordan Crouse | 76fa9a2 | 2006-01-20 14:06:09 -0800 | [diff] [blame] | 278 | }; |