| 1 | --- /dev/null |
| 2 | +++ b/drivers/usb/host/ehci-cns21xx.c |
| 3 | @@ -0,0 +1,186 @@ |
| 4 | +/* |
| 5 | + * Copyright (c) 2008 Cavium Networks |
| 6 | + * Copyright (c) 2010-2012 Gabor Juhos <juhosg@openwrt.org> |
| 7 | + * |
| 8 | + * This file is free software; you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License, Version 2, as |
| 10 | + * published by the Free Software Foundation. |
| 11 | + */ |
| 12 | + |
| 13 | +#include <linux/platform_device.h> |
| 14 | +#include <linux/irq.h> |
| 15 | + |
| 16 | +#include <mach/cns21xx.h> |
| 17 | + |
| 18 | +#define DRIVER_NAME "cns21xx-ehci" |
| 19 | + |
| 20 | +static int cns21xx_ehci_reset(struct usb_hcd *hcd) |
| 21 | +{ |
| 22 | + struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 23 | + int ret; |
| 24 | + |
| 25 | + ret = ehci_halt(ehci); |
| 26 | + if (ret) |
| 27 | + return ret; |
| 28 | + |
| 29 | + ret = ehci_init(hcd); |
| 30 | + if (ret) |
| 31 | + return ret; |
| 32 | + |
| 33 | + ehci_reset(ehci); |
| 34 | + ehci_port_power(ehci, 0); |
| 35 | + |
| 36 | + return 0; |
| 37 | +} |
| 38 | + |
| 39 | +static const struct hc_driver ehci_cns21xx_hc_driver = { |
| 40 | + .description = hcd_name, |
| 41 | + .product_desc = DRIVER_NAME, |
| 42 | + .hcd_priv_size = sizeof(struct ehci_hcd), |
| 43 | + |
| 44 | + /* |
| 45 | + * generic hardware linkage |
| 46 | + */ |
| 47 | + .irq = ehci_irq, |
| 48 | + .flags = HCD_MEMORY | HCD_USB2, |
| 49 | + |
| 50 | + /* |
| 51 | + * basic lifecycle operations |
| 52 | + */ |
| 53 | + .reset = cns21xx_ehci_reset, |
| 54 | + .start = ehci_run, |
| 55 | + .stop = ehci_stop, |
| 56 | + .shutdown = ehci_shutdown, |
| 57 | + |
| 58 | + /* |
| 59 | + * managing i/o requests and associated device resources |
| 60 | + */ |
| 61 | + .urb_enqueue = ehci_urb_enqueue, |
| 62 | + .urb_dequeue = ehci_urb_dequeue, |
| 63 | + .endpoint_disable = ehci_endpoint_disable, |
| 64 | + .endpoint_reset = ehci_endpoint_reset, |
| 65 | + |
| 66 | + /* |
| 67 | + * scheduling support |
| 68 | + */ |
| 69 | + .get_frame_number = ehci_get_frame, |
| 70 | + |
| 71 | + /* |
| 72 | + * root hub support |
| 73 | + */ |
| 74 | + .hub_status_data = ehci_hub_status_data, |
| 75 | + .hub_control = ehci_hub_control, |
| 76 | + .relinquish_port = ehci_relinquish_port, |
| 77 | + .port_handed_over = ehci_port_handed_over, |
| 78 | + |
| 79 | + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 80 | +}; |
| 81 | + |
| 82 | +static void cns21xx_ehci_init_hc(void) |
| 83 | +{ |
| 84 | + __raw_writel(0x106, CNS21XX_EHCI_CONFIG_BASE_VIRT + 0x04); |
| 85 | + __raw_writel((3 << 5) | 0x2000, CNS21XX_EHCI_CONFIG_BASE_VIRT + 0x40); |
| 86 | + msleep(100); |
| 87 | +} |
| 88 | + |
| 89 | +static int ehci_cns21xx_probe(struct platform_device *pdev) |
| 90 | +{ |
| 91 | + struct usb_hcd *hcd; |
| 92 | + struct ehci_hcd *ehci; |
| 93 | + struct resource *res; |
| 94 | + int irq; |
| 95 | + int ret; |
| 96 | + |
| 97 | + if (usb_disabled()) |
| 98 | + return -ENODEV; |
| 99 | + |
| 100 | + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 101 | + if (!res) { |
| 102 | + dev_dbg(&pdev->dev, "no IRQ specified for %s\n", |
| 103 | + dev_name(&pdev->dev)); |
| 104 | + return -ENODEV; |
| 105 | + } |
| 106 | + irq = res->start; |
| 107 | + |
| 108 | + hcd = usb_create_hcd(&ehci_cns21xx_hc_driver, &pdev->dev, |
| 109 | + dev_name(&pdev->dev)); |
| 110 | + if (!hcd) |
| 111 | + return -ENOMEM; |
| 112 | + |
| 113 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 114 | + if (!res) { |
| 115 | + dev_dbg(&pdev->dev, "no base address specified for %s\n", |
| 116 | + dev_name(&pdev->dev)); |
| 117 | + ret = -ENODEV; |
| 118 | + goto err_put_hcd; |
| 119 | + } |
| 120 | + hcd->rsrc_start = res->start; |
| 121 | + hcd->rsrc_len = res->end - res->start + 1; |
| 122 | + |
| 123 | + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 124 | + dev_dbg(&pdev->dev, "controller already in use\n"); |
| 125 | + ret = -EBUSY; |
| 126 | + goto err_put_hcd; |
| 127 | + } |
| 128 | + |
| 129 | + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 130 | + if (!hcd->regs) { |
| 131 | + dev_dbg(&pdev->dev, "error mapping memory\n"); |
| 132 | + ret = -EFAULT; |
| 133 | + goto err_release_region; |
| 134 | + } |
| 135 | + |
| 136 | + cns21xx_ehci_init_hc(); |
| 137 | + |
| 138 | + ehci = hcd_to_ehci(hcd); |
| 139 | + |
| 140 | + ehci->caps = hcd->regs; |
| 141 | + ehci->regs = hcd->regs + |
| 142 | + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
| 143 | + dbg_hcs_params(ehci, "reset"); |
| 144 | + dbg_hcc_params(ehci, "reset"); |
| 145 | + |
| 146 | + /* cache this readonly data; minimize chip reads */ |
| 147 | + ehci->hcs_params = readl(&ehci->caps->hcs_params); |
| 148 | + ehci->sbrn = 0x20; |
| 149 | + |
| 150 | + ret = usb_add_hcd(hcd, CNS21XX_IRQ_EHCI, IRQF_DISABLED); |
| 151 | + if (ret) |
| 152 | + goto err_unmap; |
| 153 | + |
| 154 | + platform_set_drvdata(pdev, hcd); |
| 155 | + return 0; |
| 156 | + |
| 157 | +err_unmap: |
| 158 | + iounmap(hcd->regs); |
| 159 | +err_release_region: |
| 160 | + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 161 | +err_put_hcd: |
| 162 | + usb_put_hcd(hcd); |
| 163 | + return ret; |
| 164 | +} |
| 165 | + |
| 166 | +static int ehci_cns21xx_remove(struct platform_device *pdev) |
| 167 | +{ |
| 168 | + struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 169 | + |
| 170 | + usb_remove_hcd(hcd); |
| 171 | + iounmap(hcd->regs); |
| 172 | + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 173 | + usb_put_hcd(hcd); |
| 174 | + platform_set_drvdata(pdev, NULL); |
| 175 | + |
| 176 | + return 0; |
| 177 | +} |
| 178 | + |
| 179 | +static struct platform_driver ehci_cns21xx_driver = { |
| 180 | + .probe = ehci_cns21xx_probe, |
| 181 | + .remove = ehci_cns21xx_remove, |
| 182 | + .shutdown = usb_hcd_platform_shutdown, |
| 183 | + .driver = { |
| 184 | + .owner = THIS_MODULE, |
| 185 | + .name = DRIVER_NAME, |
| 186 | + }, |
| 187 | +}; |
| 188 | + |
| 189 | +MODULE_ALIAS("platform:" DRIVER_NAME); |
| 190 | --- a/drivers/usb/host/ehci-hcd.c |
| 191 | +++ b/drivers/usb/host/ehci-hcd.c |
| 192 | @@ -1376,6 +1376,11 @@ MODULE_LICENSE ("GPL"); |
| 193 | #define PLATFORM_DRIVER ehci_mv_driver |
| 194 | #endif |
| 195 | |
| 196 | +#ifdef CONFIG_ARCH_CNS21XX |
| 197 | +#include "ehci-cns21xx.c" |
| 198 | +#define PLATFORM_DRIVER ehci_cns21xx_driver |
| 199 | +#endif |
| 200 | + |
| 201 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ |
| 202 | !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ |
| 203 | !defined(XILINX_OF_PLATFORM_DRIVER) |
| 204 | --- a/arch/arm/Kconfig |
| 205 | +++ b/arch/arm/Kconfig |
| 206 | @@ -369,6 +369,7 @@ config ARCH_CNS21XX |
| 207 | select ARCH_REQUIRE_GPIOLIB |
| 208 | select ARM_L1_CACHE_SHIFT_4 |
| 209 | select USB_ARCH_HAS_OHCI |
| 210 | + select USB_ARCH_HAS_EHCI |
| 211 | help |
| 212 | Support for Cavium Networks CNS21xx family. |
| 213 | |
| 214 | |