Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Aeroflex Gaisler GRLIB GRUSBHC EHCI host controller |
| 3 | * |
| 4 | * GRUSBHC is typically found on LEON/GRLIB SoCs |
| 5 | * |
| 6 | * (c) Jan Andersson <jan@gaisler.com> |
| 7 | * |
| 8 | * Based on ehci-ppc-of.c which is: |
| 9 | * (c) Valentine Barshak <vbarshak@ru.mvista.com> |
| 10 | * and in turn based on "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de> |
| 11 | * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com> |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License as published by the |
| 15 | * Free Software Foundation; either version 2 of the License, or (at your |
| 16 | * option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, but |
| 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 20 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 21 | * for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software Foundation, |
| 25 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | */ |
| 27 | |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 28 | #include <linux/err.h> |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 29 | #include <linux/signal.h> |
| 30 | |
| 31 | #include <linux/of_irq.h> |
| 32 | #include <linux/of_address.h> |
| 33 | #include <linux/of_platform.h> |
| 34 | |
| 35 | #define GRUSBHC_HCIVERSION 0x0100 /* Known value of cap. reg. HCIVERSION */ |
| 36 | |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 37 | static const struct hc_driver ehci_grlib_hc_driver = { |
| 38 | .description = hcd_name, |
| 39 | .product_desc = "GRLIB GRUSBHC EHCI", |
| 40 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 41 | |
| 42 | /* |
| 43 | * generic hardware linkage |
| 44 | */ |
| 45 | .irq = ehci_irq, |
Greg Kroah-Hartman | c04ee4b | 2013-09-23 13:32:51 -0700 | [diff] [blame] | 46 | .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 47 | |
| 48 | /* |
| 49 | * basic lifecycle operations |
| 50 | */ |
Alan Stern | c73cee7 | 2012-10-31 13:21:06 -0400 | [diff] [blame] | 51 | .reset = ehci_setup, |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [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 | #ifdef CONFIG_PM |
| 75 | .bus_suspend = ehci_bus_suspend, |
| 76 | .bus_resume = ehci_bus_resume, |
| 77 | #endif |
| 78 | .relinquish_port = ehci_relinquish_port, |
| 79 | .port_handed_over = ehci_port_handed_over, |
| 80 | |
| 81 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 82 | }; |
| 83 | |
| 84 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 85 | static int ehci_hcd_grlib_probe(struct platform_device *op) |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 86 | { |
| 87 | struct device_node *dn = op->dev.of_node; |
| 88 | struct usb_hcd *hcd; |
| 89 | struct ehci_hcd *ehci = NULL; |
| 90 | struct resource res; |
| 91 | u32 hc_capbase; |
| 92 | int irq; |
| 93 | int rv; |
| 94 | |
| 95 | if (usb_disabled()) |
| 96 | return -ENODEV; |
| 97 | |
| 98 | dev_dbg(&op->dev, "initializing GRUSBHC EHCI USB Controller\n"); |
| 99 | |
| 100 | rv = of_address_to_resource(dn, 0, &res); |
| 101 | if (rv) |
| 102 | return rv; |
| 103 | |
| 104 | /* usb_create_hcd requires dma_mask != NULL */ |
| 105 | op->dev.dma_mask = &op->dev.coherent_dma_mask; |
| 106 | hcd = usb_create_hcd(&ehci_grlib_hc_driver, &op->dev, |
| 107 | "GRUSBHC EHCI USB"); |
| 108 | if (!hcd) |
| 109 | return -ENOMEM; |
| 110 | |
| 111 | hcd->rsrc_start = res.start; |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 112 | hcd->rsrc_len = resource_size(&res); |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 113 | |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 114 | irq = irq_of_parse_and_map(dn, 0); |
| 115 | if (irq == NO_IRQ) { |
Jingoo Han | fc32f11 | 2013-12-10 21:19:18 +0900 | [diff] [blame] | 116 | dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n", |
| 117 | __FILE__); |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 118 | rv = -EBUSY; |
| 119 | goto err_irq; |
| 120 | } |
| 121 | |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 122 | hcd->regs = devm_ioremap_resource(&op->dev, &res); |
| 123 | if (IS_ERR(hcd->regs)) { |
| 124 | rv = PTR_ERR(hcd->regs); |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 125 | goto err_ioremap; |
| 126 | } |
| 127 | |
| 128 | ehci = hcd_to_ehci(hcd); |
| 129 | |
| 130 | ehci->caps = hcd->regs; |
| 131 | |
| 132 | /* determine endianness of this implementation */ |
| 133 | hc_capbase = ehci_readl(ehci, &ehci->caps->hc_capbase); |
| 134 | if (HC_VERSION(ehci, hc_capbase) != GRUSBHC_HCIVERSION) { |
| 135 | ehci->big_endian_mmio = 1; |
| 136 | ehci->big_endian_desc = 1; |
| 137 | ehci->big_endian_capbase = 1; |
| 138 | } |
| 139 | |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 140 | rv = usb_add_hcd(hcd, irq, 0); |
| 141 | if (rv) |
Julia Lawall | 436f271 | 2012-07-29 21:46:08 +0200 | [diff] [blame] | 142 | goto err_ioremap; |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 143 | |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 144 | device_wakeup_enable(hcd->self.controller); |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 145 | return 0; |
| 146 | |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 147 | err_ioremap: |
| 148 | irq_dispose_mapping(irq); |
| 149 | err_irq: |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 150 | usb_put_hcd(hcd); |
| 151 | |
| 152 | return rv; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | static int ehci_hcd_grlib_remove(struct platform_device *op) |
| 157 | { |
Jingoo Han | 477527b | 2013-05-23 19:18:39 +0900 | [diff] [blame] | 158 | struct usb_hcd *hcd = platform_get_drvdata(op); |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 159 | |
| 160 | dev_dbg(&op->dev, "stopping GRLIB GRUSBHC EHCI USB Controller\n"); |
| 161 | |
| 162 | usb_remove_hcd(hcd); |
| 163 | |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 164 | irq_dispose_mapping(hcd->irq); |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 165 | |
| 166 | usb_put_hcd(hcd); |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 172 | static const struct of_device_id ehci_hcd_grlib_of_match[] = { |
| 173 | { |
| 174 | .name = "GAISLER_EHCI", |
| 175 | }, |
| 176 | { |
| 177 | .name = "01_026", |
| 178 | }, |
| 179 | {}, |
| 180 | }; |
| 181 | MODULE_DEVICE_TABLE(of, ehci_hcd_grlib_of_match); |
| 182 | |
| 183 | |
| 184 | static struct platform_driver ehci_grlib_driver = { |
| 185 | .probe = ehci_hcd_grlib_probe, |
| 186 | .remove = ehci_hcd_grlib_remove, |
Roger Quadros | aaf6b52 | 2013-07-22 15:04:50 +0300 | [diff] [blame] | 187 | .shutdown = usb_hcd_platform_shutdown, |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 188 | .driver = { |
| 189 | .name = "grlib-ehci", |
Jan Andersson | 9be0392 | 2011-05-03 20:11:58 +0200 | [diff] [blame] | 190 | .of_match_table = ehci_hcd_grlib_of_match, |
| 191 | }, |
| 192 | }; |