Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 1 | /* |
| 2 | * MIPS CI13320A EHCI Host Controller driver |
| 3 | * Based on "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com> |
| 4 | * |
| 5 | * Copyright (C) 2012 MIPS Technologies, Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | * for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software Foundation, |
| 19 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 22 | #include <linux/err.h> |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
| 24 | |
| 25 | static int ehci_sead3_setup(struct usb_hcd *hcd) |
| 26 | { |
| 27 | int ret; |
| 28 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 29 | |
| 30 | ehci->caps = hcd->regs + 0x100; |
| 31 | |
Steven J. Hill | fdf6e63 | 2012-05-11 11:40:25 -0500 | [diff] [blame] | 32 | #ifdef __BIG_ENDIAN |
| 33 | ehci->big_endian_mmio = 1; |
| 34 | ehci->big_endian_desc = 1; |
| 35 | #endif |
| 36 | |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 37 | ret = ehci_setup(hcd); |
| 38 | if (ret) |
| 39 | return ret; |
| 40 | |
| 41 | ehci->need_io_watchdog = 0; |
| 42 | |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 43 | /* Set burst length to 16 words. */ |
Steven J. Hill | cc59c7a | 2012-08-06 17:29:31 -0500 | [diff] [blame] | 44 | ehci_writel(ehci, 0x1010, &ehci->regs->reserved1[1]); |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 45 | |
| 46 | return ret; |
| 47 | } |
| 48 | |
| 49 | const struct hc_driver ehci_sead3_hc_driver = { |
| 50 | .description = hcd_name, |
| 51 | .product_desc = "SEAD-3 EHCI", |
| 52 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 53 | |
| 54 | /* |
| 55 | * generic hardware linkage |
| 56 | */ |
| 57 | .irq = ehci_irq, |
Greg Kroah-Hartman | c04ee4b | 2013-09-23 13:32:51 -0700 | [diff] [blame] | 58 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * basic lifecycle operations |
| 62 | * |
| 63 | */ |
| 64 | .reset = ehci_sead3_setup, |
| 65 | .start = ehci_run, |
| 66 | .stop = ehci_stop, |
| 67 | .shutdown = ehci_shutdown, |
| 68 | |
| 69 | /* |
| 70 | * managing i/o requests and associated device resources |
| 71 | */ |
| 72 | .urb_enqueue = ehci_urb_enqueue, |
| 73 | .urb_dequeue = ehci_urb_dequeue, |
| 74 | .endpoint_disable = ehci_endpoint_disable, |
| 75 | .endpoint_reset = ehci_endpoint_reset, |
| 76 | |
| 77 | /* |
| 78 | * scheduling support |
| 79 | */ |
| 80 | .get_frame_number = ehci_get_frame, |
| 81 | |
| 82 | /* |
| 83 | * root hub support |
| 84 | */ |
| 85 | .hub_status_data = ehci_hub_status_data, |
| 86 | .hub_control = ehci_hub_control, |
| 87 | .bus_suspend = ehci_bus_suspend, |
| 88 | .bus_resume = ehci_bus_resume, |
| 89 | .relinquish_port = ehci_relinquish_port, |
| 90 | .port_handed_over = ehci_port_handed_over, |
| 91 | |
| 92 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 93 | }; |
| 94 | |
| 95 | static int ehci_hcd_sead3_drv_probe(struct platform_device *pdev) |
| 96 | { |
| 97 | struct usb_hcd *hcd; |
| 98 | struct resource *res; |
| 99 | int ret; |
| 100 | |
| 101 | if (usb_disabled()) |
| 102 | return -ENODEV; |
| 103 | |
| 104 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
| 105 | pr_debug("resource[1] is not IORESOURCE_IRQ"); |
| 106 | return -ENOMEM; |
| 107 | } |
| 108 | hcd = usb_create_hcd(&ehci_sead3_hc_driver, &pdev->dev, "SEAD-3"); |
| 109 | if (!hcd) |
| 110 | return -ENOMEM; |
| 111 | |
| 112 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 113 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
| 114 | if (IS_ERR(hcd->regs)) { |
| 115 | ret = PTR_ERR(hcd->regs); |
Julia Lawall | 6c40f5e | 2012-07-30 16:43:43 +0200 | [diff] [blame] | 116 | goto err1; |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 117 | } |
Varka Bhadram | 239ab7a | 2014-11-04 07:17:11 +0530 | [diff] [blame] | 118 | hcd->rsrc_start = res->start; |
| 119 | hcd->rsrc_len = resource_size(res); |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 120 | |
| 121 | /* Root hub has integrated TT. */ |
| 122 | hcd->has_tt = 1; |
| 123 | |
| 124 | ret = usb_add_hcd(hcd, pdev->resource[1].start, |
| 125 | IRQF_SHARED); |
| 126 | if (ret == 0) { |
| 127 | platform_set_drvdata(pdev, hcd); |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 128 | device_wakeup_enable(hcd->self.controller); |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 129 | return ret; |
| 130 | } |
| 131 | |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 132 | err1: |
| 133 | usb_put_hcd(hcd); |
| 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | static int ehci_hcd_sead3_drv_remove(struct platform_device *pdev) |
| 138 | { |
| 139 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 140 | |
| 141 | usb_remove_hcd(hcd); |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 142 | usb_put_hcd(hcd); |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | #ifdef CONFIG_PM |
| 148 | static int ehci_hcd_sead3_drv_suspend(struct device *dev) |
| 149 | { |
| 150 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 151 | bool do_wakeup = device_may_wakeup(dev); |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 152 | |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 153 | return ehci_suspend(hcd, do_wakeup); |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static int ehci_hcd_sead3_drv_resume(struct device *dev) |
| 157 | { |
| 158 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 159 | |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 160 | ehci_resume(hcd, false); |
Steven J. Hill | c256667 | 2012-04-19 12:57:31 -0500 | [diff] [blame] | 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | static const struct dev_pm_ops sead3_ehci_pmops = { |
| 165 | .suspend = ehci_hcd_sead3_drv_suspend, |
| 166 | .resume = ehci_hcd_sead3_drv_resume, |
| 167 | }; |
| 168 | |
| 169 | #define SEAD3_EHCI_PMOPS (&sead3_ehci_pmops) |
| 170 | |
| 171 | #else |
| 172 | #define SEAD3_EHCI_PMOPS NULL |
| 173 | #endif |
| 174 | |
| 175 | static struct platform_driver ehci_hcd_sead3_driver = { |
| 176 | .probe = ehci_hcd_sead3_drv_probe, |
| 177 | .remove = ehci_hcd_sead3_drv_remove, |
| 178 | .shutdown = usb_hcd_platform_shutdown, |
| 179 | .driver = { |
| 180 | .name = "sead3-ehci", |
| 181 | .owner = THIS_MODULE, |
| 182 | .pm = SEAD3_EHCI_PMOPS, |
| 183 | } |
| 184 | }; |
| 185 | |
| 186 | MODULE_ALIAS("platform:sead3-ehci"); |