blob: 3fcdaea21e24ad937e6e6f5e6933f8f6d5a408b3 [file] [log] [blame]
Sebastian Andrzej Siewior3429e912012-03-13 16:57:41 +02001/*
2 * xhci-plat.c - xHCI host controller driver platform Bus Glue.
3 *
4 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com
5 * Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
6 *
7 * A lot of code borrowed from the Linux xHCI driver.
8 *
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.
12 */
13
14#include <linux/platform_device.h>
15#include <linux/module.h>
16#include <linux/slab.h>
Al Cooper1fe6c452013-07-25 19:04:44 -040017#include <linux/of.h>
Sebastian Andrzej Siewior3429e912012-03-13 16:57:41 +020018
19#include "xhci.h"
20
21static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
22{
23 /*
24 * As of now platform drivers don't provide MSI support so we ensure
25 * here that the generic code does not try to make a pci_dev from our
26 * dev struct in order to setup MSI
27 */
28 xhci->quirks |= XHCI_BROKEN_MSI;
29}
30
31/* called during probe() after chip reset completes */
32static int xhci_plat_setup(struct usb_hcd *hcd)
33{
34 return xhci_gen_setup(hcd, xhci_plat_quirks);
35}
36
37static const struct hc_driver xhci_plat_xhci_driver = {
38 .description = "xhci-hcd",
39 .product_desc = "xHCI Host Controller",
40 .hcd_priv_size = sizeof(struct xhci_hcd *),
41
42 /*
43 * generic hardware linkage
44 */
45 .irq = xhci_irq,
46 .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
47
48 /*
49 * basic lifecycle operations
50 */
51 .reset = xhci_plat_setup,
52 .start = xhci_run,
53 .stop = xhci_stop,
54 .shutdown = xhci_shutdown,
55
56 /*
57 * managing i/o requests and associated device resources
58 */
59 .urb_enqueue = xhci_urb_enqueue,
60 .urb_dequeue = xhci_urb_dequeue,
61 .alloc_dev = xhci_alloc_dev,
62 .free_dev = xhci_free_dev,
63 .alloc_streams = xhci_alloc_streams,
64 .free_streams = xhci_free_streams,
65 .add_endpoint = xhci_add_endpoint,
66 .drop_endpoint = xhci_drop_endpoint,
67 .endpoint_reset = xhci_endpoint_reset,
68 .check_bandwidth = xhci_check_bandwidth,
69 .reset_bandwidth = xhci_reset_bandwidth,
70 .address_device = xhci_address_device,
71 .update_hub_device = xhci_update_hub_device,
72 .reset_device = xhci_discover_or_reset_device,
73
74 /*
75 * scheduling support
76 */
77 .get_frame_number = xhci_get_frame,
78
79 /* Root hub support */
80 .hub_control = xhci_hub_control,
81 .hub_status_data = xhci_hub_status_data,
82 .bus_suspend = xhci_bus_suspend,
83 .bus_resume = xhci_bus_resume,
84};
85
86static int xhci_plat_probe(struct platform_device *pdev)
87{
88 const struct hc_driver *driver;
89 struct xhci_hcd *xhci;
90 struct resource *res;
91 struct usb_hcd *hcd;
92 int ret;
93 int irq;
94
95 if (usb_disabled())
96 return -ENODEV;
97
98 driver = &xhci_plat_xhci_driver;
99
100 irq = platform_get_irq(pdev, 0);
101 if (irq < 0)
102 return -ENODEV;
103
104 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
105 if (!res)
106 return -ENODEV;
107
108 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
109 if (!hcd)
110 return -ENOMEM;
111
112 hcd->rsrc_start = res->start;
113 hcd->rsrc_len = resource_size(res);
114
115 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
116 driver->description)) {
117 dev_dbg(&pdev->dev, "controller already in use\n");
118 ret = -EBUSY;
119 goto put_hcd;
120 }
121
Ruchika Kharwar319acdf2012-08-10 09:58:30 +0300122 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
Sebastian Andrzej Siewior3429e912012-03-13 16:57:41 +0200123 if (!hcd->regs) {
124 dev_dbg(&pdev->dev, "error mapping memory\n");
125 ret = -EFAULT;
126 goto release_mem_region;
127 }
128
129 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
130 if (ret)
131 goto unmap_registers;
132
133 /* USB 2.0 roothub is stored in the platform_device now. */
Jingoo Han477527b2013-05-23 19:18:39 +0900134 hcd = platform_get_drvdata(pdev);
Sebastian Andrzej Siewior3429e912012-03-13 16:57:41 +0200135 xhci = hcd_to_xhci(hcd);
136 xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
137 dev_name(&pdev->dev), hcd);
138 if (!xhci->shared_hcd) {
139 ret = -ENOMEM;
140 goto dealloc_usb2_hcd;
141 }
142
143 /*
144 * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset)
145 * is called by usb_add_hcd().
146 */
147 *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
148
149 ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
150 if (ret)
151 goto put_usb3_hcd;
152
153 return 0;
154
155put_usb3_hcd:
156 usb_put_hcd(xhci->shared_hcd);
157
158dealloc_usb2_hcd:
159 usb_remove_hcd(hcd);
160
161unmap_registers:
162 iounmap(hcd->regs);
163
164release_mem_region:
165 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
166
167put_hcd:
168 usb_put_hcd(hcd);
169
170 return ret;
171}
172
173static int xhci_plat_remove(struct platform_device *dev)
174{
175 struct usb_hcd *hcd = platform_get_drvdata(dev);
176 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
177
178 usb_remove_hcd(xhci->shared_hcd);
179 usb_put_hcd(xhci->shared_hcd);
180
181 usb_remove_hcd(hcd);
182 iounmap(hcd->regs);
George Cherian5388a3a2013-06-21 13:59:08 +0530183 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
Sebastian Andrzej Siewior3429e912012-03-13 16:57:41 +0200184 usb_put_hcd(hcd);
185 kfree(xhci);
186
187 return 0;
188}
189
Vikas Sajjan57d04eb2013-02-11 12:58:00 +0200190#ifdef CONFIG_PM
191static int xhci_plat_suspend(struct device *dev)
192{
193 struct usb_hcd *hcd = dev_get_drvdata(dev);
194 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
195
196 return xhci_suspend(xhci);
197}
198
199static int xhci_plat_resume(struct device *dev)
200{
201 struct usb_hcd *hcd = dev_get_drvdata(dev);
202 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
203
204 return xhci_resume(xhci, 0);
205}
206
207static const struct dev_pm_ops xhci_plat_pm_ops = {
208 SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
209};
210#define DEV_PM_OPS (&xhci_plat_pm_ops)
211#else
212#define DEV_PM_OPS NULL
213#endif /* CONFIG_PM */
214
Al Cooper1fe6c452013-07-25 19:04:44 -0400215#ifdef CONFIG_OF
216static const struct of_device_id usb_xhci_of_match[] = {
217 { .compatible = "xhci-platform" },
218 { },
219};
220MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
221#endif
222
Sebastian Andrzej Siewior3429e912012-03-13 16:57:41 +0200223static struct platform_driver usb_xhci_driver = {
224 .probe = xhci_plat_probe,
225 .remove = xhci_plat_remove,
226 .driver = {
227 .name = "xhci-hcd",
Vikas Sajjan57d04eb2013-02-11 12:58:00 +0200228 .pm = DEV_PM_OPS,
Al Cooper1fe6c452013-07-25 19:04:44 -0400229 .of_match_table = of_match_ptr(usb_xhci_of_match),
Sebastian Andrzej Siewior3429e912012-03-13 16:57:41 +0200230 },
231};
232MODULE_ALIAS("platform:xhci-hcd");
233
234int xhci_register_plat(void)
235{
236 return platform_driver_register(&usb_xhci_driver);
237}
238
239void xhci_unregister_plat(void)
240{
241 platform_driver_unregister(&usb_xhci_driver);
242}