Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 1 | /* |
| 2 | * drivers/usb/host/ehci-vt8500.c |
| 3 | * |
| 4 | * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com> |
| 5 | * |
| 6 | * Based on ehci-au1xxx.c |
| 7 | * |
| 8 | * This software is licensed under the terms of the GNU General Public |
| 9 | * License version 2, as published by the Free Software Foundation, and |
| 10 | * may be copied, distributed, and modified under those terms. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <linux/platform_device.h> |
| 20 | |
| 21 | static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev) |
| 22 | { |
| 23 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 24 | int rc = 0; |
| 25 | |
| 26 | if (!udev->parent) /* udev is root hub itself, impossible */ |
| 27 | rc = -1; |
| 28 | /* we only support lpm device connected to root hub yet */ |
| 29 | if (ehci->has_lpm && !udev->parent->parent) { |
| 30 | rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum); |
| 31 | if (!rc) |
| 32 | rc = ehci_lpm_check(ehci, udev->portnum); |
| 33 | } |
| 34 | return rc; |
| 35 | } |
| 36 | |
| 37 | static const struct hc_driver vt8500_ehci_hc_driver = { |
| 38 | .description = hcd_name, |
| 39 | .product_desc = "VT8500 EHCI", |
| 40 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 41 | |
| 42 | /* |
| 43 | * generic hardware linkage |
| 44 | */ |
| 45 | .irq = ehci_irq, |
| 46 | .flags = HCD_MEMORY | HCD_USB2, |
| 47 | |
| 48 | /* |
| 49 | * basic lifecycle operations |
| 50 | */ |
Alan Stern | 1a49e2a | 2012-07-09 15:55:14 -0400 | [diff] [blame] | 51 | .reset = ehci_setup, |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 52 | .start = ehci_run, |
| 53 | .stop = ehci_stop, |
| 54 | .shutdown = ehci_shutdown, |
| 55 | |
| 56 | /* |
| 57 | * managing i/o requests and associated device resources |
| 58 | */ |
| 59 | .urb_enqueue = ehci_urb_enqueue, |
| 60 | .urb_dequeue = ehci_urb_dequeue, |
| 61 | .endpoint_disable = ehci_endpoint_disable, |
| 62 | .endpoint_reset = ehci_endpoint_reset, |
| 63 | |
| 64 | /* |
| 65 | * scheduling support |
| 66 | */ |
| 67 | .get_frame_number = ehci_get_frame, |
| 68 | |
| 69 | /* |
| 70 | * root hub support |
| 71 | */ |
| 72 | .hub_status_data = ehci_hub_status_data, |
| 73 | .hub_control = ehci_hub_control, |
| 74 | .bus_suspend = ehci_bus_suspend, |
| 75 | .bus_resume = ehci_bus_resume, |
| 76 | .relinquish_port = ehci_relinquish_port, |
| 77 | .port_handed_over = ehci_port_handed_over, |
| 78 | |
| 79 | /* |
| 80 | * call back when device connected and addressed |
| 81 | */ |
| 82 | .update_device = ehci_update_device, |
| 83 | |
| 84 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 85 | }; |
| 86 | |
| 87 | static int vt8500_ehci_drv_probe(struct platform_device *pdev) |
| 88 | { |
| 89 | struct usb_hcd *hcd; |
| 90 | struct ehci_hcd *ehci; |
| 91 | struct resource *res; |
| 92 | int ret; |
| 93 | |
| 94 | if (usb_disabled()) |
| 95 | return -ENODEV; |
| 96 | |
| 97 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
| 98 | pr_debug("resource[1] is not IORESOURCE_IRQ"); |
| 99 | return -ENOMEM; |
| 100 | } |
| 101 | hcd = usb_create_hcd(&vt8500_ehci_hc_driver, &pdev->dev, "VT8500"); |
| 102 | if (!hcd) |
| 103 | return -ENOMEM; |
| 104 | |
| 105 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 106 | hcd->rsrc_start = res->start; |
| 107 | hcd->rsrc_len = resource_size(res); |
| 108 | |
| 109 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 110 | pr_debug("request_mem_region failed"); |
| 111 | ret = -EBUSY; |
| 112 | goto err1; |
| 113 | } |
| 114 | |
| 115 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 116 | if (!hcd->regs) { |
| 117 | pr_debug("ioremap failed"); |
| 118 | ret = -ENOMEM; |
| 119 | goto err2; |
| 120 | } |
| 121 | |
| 122 | ehci = hcd_to_ehci(hcd); |
| 123 | ehci->caps = hcd->regs; |
Geoff Levand | 876e0df | 2011-11-22 18:04:45 -0800 | [diff] [blame] | 124 | |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 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); |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 127 | if (ret == 0) { |
| 128 | platform_set_drvdata(pdev, hcd); |
| 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | iounmap(hcd->regs); |
| 133 | err2: |
| 134 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 135 | err1: |
| 136 | usb_put_hcd(hcd); |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | static int vt8500_ehci_drv_remove(struct platform_device *pdev) |
| 141 | { |
| 142 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 143 | |
| 144 | usb_remove_hcd(hcd); |
| 145 | iounmap(hcd->regs); |
| 146 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 147 | usb_put_hcd(hcd); |
| 148 | platform_set_drvdata(pdev, NULL); |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static struct platform_driver vt8500_ehci_driver = { |
| 154 | .probe = vt8500_ehci_drv_probe, |
| 155 | .remove = vt8500_ehci_drv_remove, |
| 156 | .shutdown = usb_hcd_platform_shutdown, |
| 157 | .driver = { |
| 158 | .name = "vt8500-ehci", |
| 159 | .owner = THIS_MODULE, |
| 160 | } |
| 161 | }; |
| 162 | |
| 163 | MODULE_ALIAS("platform:vt8500-ehci"); |