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