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