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 | |
Tony Prisk | 8ad551d | 2012-07-21 22:58:52 +1200 | [diff] [blame] | 19 | #include <linux/of.h> |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
| 21 | |
| 22 | static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev) |
| 23 | { |
| 24 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 25 | int rc = 0; |
| 26 | |
| 27 | if (!udev->parent) /* udev is root hub itself, impossible */ |
| 28 | rc = -1; |
| 29 | /* we only support lpm device connected to root hub yet */ |
| 30 | if (ehci->has_lpm && !udev->parent->parent) { |
| 31 | rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum); |
| 32 | if (!rc) |
| 33 | rc = ehci_lpm_check(ehci, udev->portnum); |
| 34 | } |
| 35 | return rc; |
| 36 | } |
| 37 | |
| 38 | static const struct hc_driver vt8500_ehci_hc_driver = { |
| 39 | .description = hcd_name, |
| 40 | .product_desc = "VT8500 EHCI", |
| 41 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 42 | |
| 43 | /* |
| 44 | * generic hardware linkage |
| 45 | */ |
| 46 | .irq = ehci_irq, |
| 47 | .flags = HCD_MEMORY | HCD_USB2, |
| 48 | |
| 49 | /* |
| 50 | * basic lifecycle operations |
| 51 | */ |
Alan Stern | 1a49e2a | 2012-07-09 15:55:14 -0400 | [diff] [blame] | 52 | .reset = ehci_setup, |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 53 | .start = ehci_run, |
| 54 | .stop = ehci_stop, |
| 55 | .shutdown = ehci_shutdown, |
| 56 | |
| 57 | /* |
| 58 | * managing i/o requests and associated device resources |
| 59 | */ |
| 60 | .urb_enqueue = ehci_urb_enqueue, |
| 61 | .urb_dequeue = ehci_urb_dequeue, |
| 62 | .endpoint_disable = ehci_endpoint_disable, |
| 63 | .endpoint_reset = ehci_endpoint_reset, |
| 64 | |
| 65 | /* |
| 66 | * scheduling support |
| 67 | */ |
| 68 | .get_frame_number = ehci_get_frame, |
| 69 | |
| 70 | /* |
| 71 | * root hub support |
| 72 | */ |
| 73 | .hub_status_data = ehci_hub_status_data, |
| 74 | .hub_control = ehci_hub_control, |
| 75 | .bus_suspend = ehci_bus_suspend, |
| 76 | .bus_resume = ehci_bus_resume, |
| 77 | .relinquish_port = ehci_relinquish_port, |
| 78 | .port_handed_over = ehci_port_handed_over, |
| 79 | |
| 80 | /* |
| 81 | * call back when device connected and addressed |
| 82 | */ |
| 83 | .update_device = ehci_update_device, |
| 84 | |
| 85 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 86 | }; |
| 87 | |
| 88 | static int vt8500_ehci_drv_probe(struct platform_device *pdev) |
| 89 | { |
| 90 | struct usb_hcd *hcd; |
| 91 | struct ehci_hcd *ehci; |
| 92 | struct resource *res; |
| 93 | int ret; |
| 94 | |
| 95 | if (usb_disabled()) |
| 96 | return -ENODEV; |
| 97 | |
| 98 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
| 99 | pr_debug("resource[1] is not IORESOURCE_IRQ"); |
| 100 | return -ENOMEM; |
| 101 | } |
| 102 | hcd = usb_create_hcd(&vt8500_ehci_hc_driver, &pdev->dev, "VT8500"); |
| 103 | if (!hcd) |
| 104 | return -ENOMEM; |
| 105 | |
| 106 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 107 | hcd->rsrc_start = res->start; |
| 108 | hcd->rsrc_len = resource_size(res); |
| 109 | |
Julia Lawall | f1d4eb7 | 2012-07-30 16:43:40 +0200 | [diff] [blame] | 110 | hcd->regs = devm_request_and_ioremap(&pdev->dev, res); |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 111 | if (!hcd->regs) { |
| 112 | pr_debug("ioremap failed"); |
| 113 | ret = -ENOMEM; |
Julia Lawall | f1d4eb7 | 2012-07-30 16:43:40 +0200 | [diff] [blame] | 114 | goto err1; |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | ehci = hcd_to_ehci(hcd); |
| 118 | ehci->caps = hcd->regs; |
Geoff Levand | 876e0df | 2011-11-22 18:04:45 -0800 | [diff] [blame] | 119 | |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 120 | ret = usb_add_hcd(hcd, pdev->resource[1].start, |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 121 | IRQF_SHARED); |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 122 | if (ret == 0) { |
| 123 | platform_set_drvdata(pdev, hcd); |
| 124 | return ret; |
| 125 | } |
| 126 | |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 127 | err1: |
| 128 | usb_put_hcd(hcd); |
| 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | static int vt8500_ehci_drv_remove(struct platform_device *pdev) |
| 133 | { |
| 134 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 135 | |
| 136 | usb_remove_hcd(hcd); |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 137 | usb_put_hcd(hcd); |
| 138 | platform_set_drvdata(pdev, NULL); |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
Tony Prisk | 8ad551d | 2012-07-21 22:58:52 +1200 | [diff] [blame] | 143 | static const struct of_device_id vt8500_ehci_ids[] = { |
| 144 | { .compatible = "via,vt8500-ehci", }, |
| 145 | { .compatible = "wm,prizm-ehci", }, |
| 146 | {} |
| 147 | }; |
| 148 | |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 149 | static struct platform_driver vt8500_ehci_driver = { |
| 150 | .probe = vt8500_ehci_drv_probe, |
| 151 | .remove = vt8500_ehci_drv_remove, |
| 152 | .shutdown = usb_hcd_platform_shutdown, |
| 153 | .driver = { |
| 154 | .name = "vt8500-ehci", |
| 155 | .owner = THIS_MODULE, |
Tony Prisk | 8ad551d | 2012-07-21 22:58:52 +1200 | [diff] [blame] | 156 | .of_match_table = of_match_ptr(vt8500_ehci_ids), |
Alexey Charkov | ad78aca | 2010-11-07 19:28:55 +0300 | [diff] [blame] | 157 | } |
| 158 | }; |
| 159 | |
| 160 | MODULE_ALIAS("platform:vt8500-ehci"); |
Tony Prisk | 8ad551d | 2012-07-21 22:58:52 +1200 | [diff] [blame] | 161 | MODULE_DEVICE_TABLE(of, vt8500_ehci_ids); |