2 * xhci-plat.c - xHCI host controller driver platform Bus Glue.
4 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com
5 * Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
7 * A lot of code borrowed from the Linux xHCI driver.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
14 #include <linux/clk.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <linux/slab.h>
22 #include "xhci-mvebu.h"
24 static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
27 * As of now platform drivers don't provide MSI support so we ensure
28 * here that the generic code does not try to make a pci_dev from our
29 * dev struct in order to setup MSI
31 xhci->quirks |= XHCI_PLAT;
34 /* called during probe() after chip reset completes */
35 static int xhci_plat_setup(struct usb_hcd *hcd)
37 return xhci_gen_setup(hcd, xhci_plat_quirks);
40 static int xhci_plat_start(struct usb_hcd *hcd)
45 static const struct hc_driver xhci_plat_xhci_driver = {
46 .description = "xhci-hcd",
47 .product_desc = "xHCI Host Controller",
48 .hcd_priv_size = sizeof(struct xhci_hcd *),
51 * generic hardware linkage
54 .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
57 * basic lifecycle operations
59 .reset = xhci_plat_setup,
60 .start = xhci_plat_start,
62 .shutdown = xhci_shutdown,
65 * managing i/o requests and associated device resources
67 .urb_enqueue = xhci_urb_enqueue,
68 .urb_dequeue = xhci_urb_dequeue,
69 .alloc_dev = xhci_alloc_dev,
70 .free_dev = xhci_free_dev,
71 .alloc_streams = xhci_alloc_streams,
72 .free_streams = xhci_free_streams,
73 .add_endpoint = xhci_add_endpoint,
74 .drop_endpoint = xhci_drop_endpoint,
75 .endpoint_reset = xhci_endpoint_reset,
76 .check_bandwidth = xhci_check_bandwidth,
77 .reset_bandwidth = xhci_reset_bandwidth,
78 .address_device = xhci_address_device,
79 .enable_device = xhci_enable_device,
80 .update_hub_device = xhci_update_hub_device,
81 .reset_device = xhci_discover_or_reset_device,
86 .get_frame_number = xhci_get_frame,
88 /* Root hub support */
89 .hub_control = xhci_hub_control,
90 .hub_status_data = xhci_hub_status_data,
91 .bus_suspend = xhci_bus_suspend,
92 .bus_resume = xhci_bus_resume,
95 static int xhci_plat_probe(struct platform_device *pdev)
97 const struct hc_driver *driver;
98 struct xhci_hcd *xhci;
108 driver = &xhci_plat_xhci_driver;
110 irq = platform_get_irq(pdev, 0);
114 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
118 if (of_device_is_compatible(pdev->dev.of_node,
119 "marvell,armada-375-xhci") ||
120 of_device_is_compatible(pdev->dev.of_node,
121 "marvell,armada-380-xhci")) {
122 ret = xhci_mvebu_mbus_init_quirk(pdev);
127 /* Initialize dma_mask and coherent_dma_mask to 32-bits */
128 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
131 if (!pdev->dev.dma_mask)
132 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
134 dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
136 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
140 hcd->rsrc_start = res->start;
141 hcd->rsrc_len = resource_size(res);
143 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
144 driver->description)) {
145 dev_dbg(&pdev->dev, "controller already in use\n");
150 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
152 dev_dbg(&pdev->dev, "error mapping memory\n");
154 goto release_mem_region;
158 * Not all platforms have a clk so it is not an error if the
159 * clock does not exists.
161 clk = devm_clk_get(&pdev->dev, NULL);
163 ret = clk_prepare_enable(clk);
165 goto unmap_registers;
168 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
172 device_wakeup_enable(hcd->self.controller);
174 /* USB 2.0 roothub is stored in the platform_device now. */
175 hcd = platform_get_drvdata(pdev);
176 xhci = hcd_to_xhci(hcd);
178 xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
179 dev_name(&pdev->dev), hcd);
180 if (!xhci->shared_hcd) {
182 goto dealloc_usb2_hcd;
186 * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset)
187 * is called by usb_add_hcd().
189 *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
191 ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
198 usb_put_hcd(xhci->shared_hcd);
205 clk_disable_unprepare(clk);
211 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
219 static int xhci_plat_remove(struct platform_device *dev)
221 struct usb_hcd *hcd = platform_get_drvdata(dev);
222 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
223 struct clk *clk = xhci->clk;
225 usb_remove_hcd(xhci->shared_hcd);
226 usb_put_hcd(xhci->shared_hcd);
230 clk_disable_unprepare(clk);
232 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
239 #ifdef CONFIG_PM_SLEEP
240 static int xhci_plat_suspend(struct device *dev)
242 struct usb_hcd *hcd = dev_get_drvdata(dev);
243 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
245 return xhci_suspend(xhci);
248 static int xhci_plat_resume(struct device *dev)
250 struct usb_hcd *hcd = dev_get_drvdata(dev);
251 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
253 return xhci_resume(xhci, 0);
256 static const struct dev_pm_ops xhci_plat_pm_ops = {
257 SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
259 #define DEV_PM_OPS (&xhci_plat_pm_ops)
261 #define DEV_PM_OPS NULL
262 #endif /* CONFIG_PM */
265 static const struct of_device_id usb_xhci_of_match[] = {
266 { .compatible = "generic-xhci" },
267 { .compatible = "xhci-platform" },
268 { .compatible = "marvell,armada-375-xhci"},
269 { .compatible = "marvell,armada-380-xhci"},
272 MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
275 static struct platform_driver usb_xhci_driver = {
276 .probe = xhci_plat_probe,
277 .remove = xhci_plat_remove,
281 .of_match_table = of_match_ptr(usb_xhci_of_match),
284 MODULE_ALIAS("platform:xhci-hcd");
286 int xhci_register_plat(void)
288 return platform_driver_register(&usb_xhci_driver);
291 void xhci_unregister_plat(void)
293 platform_driver_unregister(&usb_xhci_driver);