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>
20 #include <linux/usb/xhci_pdriver.h>
23 #include "xhci-mvebu.h"
25 static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
28 * As of now platform drivers don't provide MSI support so we ensure
29 * here that the generic code does not try to make a pci_dev from our
30 * dev struct in order to setup MSI
32 xhci->quirks |= XHCI_PLAT;
35 /* called during probe() after chip reset completes */
36 static int xhci_plat_setup(struct usb_hcd *hcd)
38 return xhci_gen_setup(hcd, xhci_plat_quirks);
41 static int xhci_plat_start(struct usb_hcd *hcd)
46 static const struct hc_driver xhci_plat_xhci_driver = {
47 .description = "xhci-hcd",
48 .product_desc = "xHCI Host Controller",
49 .hcd_priv_size = sizeof(struct xhci_hcd *),
52 * generic hardware linkage
55 .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
58 * basic lifecycle operations
60 .reset = xhci_plat_setup,
61 .start = xhci_plat_start,
63 .shutdown = xhci_shutdown,
66 * managing i/o requests and associated device resources
68 .urb_enqueue = xhci_urb_enqueue,
69 .urb_dequeue = xhci_urb_dequeue,
70 .alloc_dev = xhci_alloc_dev,
71 .free_dev = xhci_free_dev,
72 .alloc_streams = xhci_alloc_streams,
73 .free_streams = xhci_free_streams,
74 .add_endpoint = xhci_add_endpoint,
75 .drop_endpoint = xhci_drop_endpoint,
76 .endpoint_reset = xhci_endpoint_reset,
77 .check_bandwidth = xhci_check_bandwidth,
78 .reset_bandwidth = xhci_reset_bandwidth,
79 .address_device = xhci_address_device,
80 .enable_device = xhci_enable_device,
81 .update_hub_device = xhci_update_hub_device,
82 .reset_device = xhci_discover_or_reset_device,
87 .get_frame_number = xhci_get_frame,
89 /* Root hub support */
90 .hub_control = xhci_hub_control,
91 .hub_status_data = xhci_hub_status_data,
92 .bus_suspend = xhci_bus_suspend,
93 .bus_resume = xhci_bus_resume,
95 .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout,
96 .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout,
99 static int xhci_plat_probe(struct platform_device *pdev)
101 struct device_node *node = pdev->dev.of_node;
102 struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
103 const struct hc_driver *driver;
104 struct xhci_hcd *xhci;
105 struct resource *res;
114 driver = &xhci_plat_xhci_driver;
116 irq = platform_get_irq(pdev, 0);
120 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
124 if (of_device_is_compatible(pdev->dev.of_node,
125 "marvell,armada-375-xhci") ||
126 of_device_is_compatible(pdev->dev.of_node,
127 "marvell,armada-380-xhci")) {
128 ret = xhci_mvebu_mbus_init_quirk(pdev);
133 /* Initialize dma_mask and coherent_dma_mask to 32-bits */
134 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
137 if (!pdev->dev.dma_mask)
138 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
140 dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
142 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
146 hcd->rsrc_start = res->start;
147 hcd->rsrc_len = resource_size(res);
149 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
150 driver->description)) {
151 dev_dbg(&pdev->dev, "controller already in use\n");
156 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
158 dev_dbg(&pdev->dev, "error mapping memory\n");
160 goto release_mem_region;
164 * Not all platforms have a clk so it is not an error if the
165 * clock does not exists.
167 clk = devm_clk_get(&pdev->dev, NULL);
169 ret = clk_prepare_enable(clk);
171 goto unmap_registers;
174 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
178 device_wakeup_enable(hcd->self.controller);
180 /* USB 2.0 roothub is stored in the platform_device now. */
181 hcd = platform_get_drvdata(pdev);
182 xhci = hcd_to_xhci(hcd);
184 xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
185 dev_name(&pdev->dev), hcd);
186 if (!xhci->shared_hcd) {
188 goto dealloc_usb2_hcd;
191 if ((node && of_property_read_bool(node, "usb3-lpm-capable")) ||
192 (pdata && pdata->usb3_lpm_capable))
193 xhci->quirks |= XHCI_LPM_SUPPORT;
195 * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset)
196 * is called by usb_add_hcd().
198 *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
200 ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
207 usb_put_hcd(xhci->shared_hcd);
214 clk_disable_unprepare(clk);
220 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
228 static int xhci_plat_remove(struct platform_device *dev)
230 struct usb_hcd *hcd = platform_get_drvdata(dev);
231 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
232 struct clk *clk = xhci->clk;
234 usb_remove_hcd(xhci->shared_hcd);
235 usb_put_hcd(xhci->shared_hcd);
239 clk_disable_unprepare(clk);
241 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
248 #ifdef CONFIG_PM_SLEEP
249 static int xhci_plat_suspend(struct device *dev)
251 struct usb_hcd *hcd = dev_get_drvdata(dev);
252 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
255 * xhci_suspend() needs `do_wakeup` to know whether host is allowed
256 * to do wakeup during suspend. Since xhci_plat_suspend is currently
257 * only designed for system suspend, device_may_wakeup() is enough
258 * to dertermine whether host is allowed to do wakeup. Need to
259 * reconsider this when xhci_plat_suspend enlarges its scope, e.g.,
260 * also applies to runtime suspend.
262 return xhci_suspend(xhci, device_may_wakeup(dev));
265 static int xhci_plat_resume(struct device *dev)
267 struct usb_hcd *hcd = dev_get_drvdata(dev);
268 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
270 return xhci_resume(xhci, 0);
273 static const struct dev_pm_ops xhci_plat_pm_ops = {
274 SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
276 #define DEV_PM_OPS (&xhci_plat_pm_ops)
278 #define DEV_PM_OPS NULL
279 #endif /* CONFIG_PM */
282 static const struct of_device_id usb_xhci_of_match[] = {
283 { .compatible = "generic-xhci" },
284 { .compatible = "xhci-platform" },
285 { .compatible = "marvell,armada-375-xhci"},
286 { .compatible = "marvell,armada-380-xhci"},
289 MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
292 static struct platform_driver usb_xhci_driver = {
293 .probe = xhci_plat_probe,
294 .remove = xhci_plat_remove,
298 .of_match_table = of_match_ptr(usb_xhci_of_match),
301 MODULE_ALIAS("platform:xhci-hcd");
303 int xhci_register_plat(void)
305 return platform_driver_register(&usb_xhci_driver);
308 void xhci_unregister_plat(void)
310 platform_driver_unregister(&usb_xhci_driver);