1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for Aeroflex Gaisler GRLIB GRUSBHC EHCI host controller
5 * GRUSBHC is typically found on LEON/GRLIB SoCs
9 * Based on ehci-ppc-of.c which is:
15 #include <linux/err.h>
16 #include <linux/signal.h>
18 #include <linux/of_irq.h>
19 #include <linux/of_address.h>
20 #include <linux/of_platform.h>
22 #define GRUSBHC_HCIVERSION 0x0100 /* Known value of cap. reg. HCIVERSION */
24 static const struct hc_driver ehci_grlib_hc_driver = {
25 .description = hcd_name,
26 .product_desc = "GRLIB GRUSBHC EHCI",
27 .hcd_priv_size = sizeof(struct ehci_hcd),
30 * generic hardware linkage
33 .flags = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH,
36 * basic lifecycle operations
41 .shutdown = ehci_shutdown,
44 * managing i/o requests and associated device resources
46 .urb_enqueue = ehci_urb_enqueue,
47 .urb_dequeue = ehci_urb_dequeue,
48 .endpoint_disable = ehci_endpoint_disable,
49 .endpoint_reset = ehci_endpoint_reset,
54 .get_frame_number = ehci_get_frame,
59 .hub_status_data = ehci_hub_status_data,
60 .hub_control = ehci_hub_control,
62 .bus_suspend = ehci_bus_suspend,
63 .bus_resume = ehci_bus_resume,
65 .relinquish_port = ehci_relinquish_port,
66 .port_handed_over = ehci_port_handed_over,
68 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
72 static int ehci_hcd_grlib_probe(struct platform_device *op)
74 struct device_node *dn = op->dev.of_node;
76 struct ehci_hcd *ehci = NULL;
85 dev_dbg(&op->dev, "initializing GRUSBHC EHCI USB Controller\n");
87 rv = of_address_to_resource(dn, 0, &res);
91 /* usb_create_hcd requires dma_mask != NULL */
92 op->dev.dma_mask = &op->dev.coherent_dma_mask;
93 hcd = usb_create_hcd(&ehci_grlib_hc_driver, &op->dev,
98 hcd->rsrc_start = res.start;
99 hcd->rsrc_len = resource_size(&res);
101 irq = irq_of_parse_and_map(dn, 0);
103 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
109 hcd->regs = devm_ioremap_resource(&op->dev, &res);
110 if (IS_ERR(hcd->regs)) {
111 rv = PTR_ERR(hcd->regs);
115 ehci = hcd_to_ehci(hcd);
117 ehci->caps = hcd->regs;
119 /* determine endianness of this implementation */
120 hc_capbase = ehci_readl(ehci, &ehci->caps->hc_capbase);
121 if (HC_VERSION(ehci, hc_capbase) != GRUSBHC_HCIVERSION) {
122 ehci->big_endian_mmio = 1;
123 ehci->big_endian_desc = 1;
124 ehci->big_endian_capbase = 1;
127 rv = usb_add_hcd(hcd, irq, 0);
131 device_wakeup_enable(hcd->self.controller);
135 irq_dispose_mapping(irq);
143 static void ehci_hcd_grlib_remove(struct platform_device *op)
145 struct usb_hcd *hcd = platform_get_drvdata(op);
147 dev_dbg(&op->dev, "stopping GRLIB GRUSBHC EHCI USB Controller\n");
151 irq_dispose_mapping(hcd->irq);
157 static const struct of_device_id ehci_hcd_grlib_of_match[] = {
159 .name = "GAISLER_EHCI",
166 MODULE_DEVICE_TABLE(of, ehci_hcd_grlib_of_match);
169 static struct platform_driver ehci_grlib_driver = {
170 .probe = ehci_hcd_grlib_probe,
171 .remove = ehci_hcd_grlib_remove,
172 .shutdown = usb_hcd_platform_shutdown,
174 .name = "grlib-ehci",
175 .of_match_table = ehci_hcd_grlib_of_match,