]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/usb/host/xhci-plat.c
xhci: Platform: Add (en/dis)able_usb3_lpm_timeout
[mirror_ubuntu-zesty-kernel.git] / drivers / usb / host / xhci-plat.c
CommitLineData
3429e91a
SAS
1/*
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
4718c177 14#include <linux/clk.h>
48157bb9 15#include <linux/dma-mapping.h>
3429e91a 16#include <linux/module.h>
1fe6c452 17#include <linux/of.h>
48157bb9
GC
18#include <linux/platform_device.h>
19#include <linux/slab.h>
3429e91a
SAS
20
21#include "xhci.h"
97374792 22#include "xhci-mvebu.h"
3429e91a
SAS
23
24static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
25{
26 /*
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
30 */
52fb6125 31 xhci->quirks |= XHCI_PLAT;
3429e91a
SAS
32}
33
34/* called during probe() after chip reset completes */
35static int xhci_plat_setup(struct usb_hcd *hcd)
36{
37 return xhci_gen_setup(hcd, xhci_plat_quirks);
38}
39
94adcdce
YS
40static int xhci_plat_start(struct usb_hcd *hcd)
41{
42 return xhci_run(hcd);
43}
44
3429e91a
SAS
45static 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 *),
49
50 /*
51 * generic hardware linkage
52 */
53 .irq = xhci_irq,
54 .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
55
56 /*
57 * basic lifecycle operations
58 */
59 .reset = xhci_plat_setup,
94adcdce 60 .start = xhci_plat_start,
3429e91a
SAS
61 .stop = xhci_stop,
62 .shutdown = xhci_shutdown,
63
64 /*
65 * managing i/o requests and associated device resources
66 */
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,
48fc7dbd 79 .enable_device = xhci_enable_device,
3429e91a
SAS
80 .update_hub_device = xhci_update_hub_device,
81 .reset_device = xhci_discover_or_reset_device,
82
83 /*
84 * scheduling support
85 */
86 .get_frame_number = xhci_get_frame,
87
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,
94ef3d50
PA
93
94 .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout,
95 .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout,
3429e91a
SAS
96};
97
98static int xhci_plat_probe(struct platform_device *pdev)
99{
100 const struct hc_driver *driver;
101 struct xhci_hcd *xhci;
102 struct resource *res;
103 struct usb_hcd *hcd;
4718c177 104 struct clk *clk;
3429e91a
SAS
105 int ret;
106 int irq;
107
108 if (usb_disabled())
109 return -ENODEV;
110
111 driver = &xhci_plat_xhci_driver;
112
113 irq = platform_get_irq(pdev, 0);
114 if (irq < 0)
115 return -ENODEV;
116
117 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
118 if (!res)
119 return -ENODEV;
120
97374792
GC
121 if (of_device_is_compatible(pdev->dev.of_node,
122 "marvell,armada-375-xhci") ||
123 of_device_is_compatible(pdev->dev.of_node,
124 "marvell,armada-380-xhci")) {
125 ret = xhci_mvebu_mbus_init_quirk(pdev);
126 if (ret)
127 return ret;
128 }
129
c10cf118
XR
130 /* Initialize dma_mask and coherent_dma_mask to 32-bits */
131 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
132 if (ret)
133 return ret;
134 if (!pdev->dev.dma_mask)
135 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
136 else
137 dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
138
3429e91a
SAS
139 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
140 if (!hcd)
141 return -ENOMEM;
142
143 hcd->rsrc_start = res->start;
144 hcd->rsrc_len = resource_size(res);
145
146 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
147 driver->description)) {
148 dev_dbg(&pdev->dev, "controller already in use\n");
149 ret = -EBUSY;
150 goto put_hcd;
151 }
152
319acdfc 153 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
3429e91a
SAS
154 if (!hcd->regs) {
155 dev_dbg(&pdev->dev, "error mapping memory\n");
156 ret = -EFAULT;
157 goto release_mem_region;
158 }
159
4718c177
GC
160 /*
161 * Not all platforms have a clk so it is not an error if the
162 * clock does not exists.
163 */
164 clk = devm_clk_get(&pdev->dev, NULL);
165 if (!IS_ERR(clk)) {
166 ret = clk_prepare_enable(clk);
167 if (ret)
168 goto unmap_registers;
169 }
170
3429e91a
SAS
171 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
172 if (ret)
4718c177
GC
173 goto disable_clk;
174
3c9740a1 175 device_wakeup_enable(hcd->self.controller);
3429e91a
SAS
176
177 /* USB 2.0 roothub is stored in the platform_device now. */
477527ba 178 hcd = platform_get_drvdata(pdev);
3429e91a 179 xhci = hcd_to_xhci(hcd);
4718c177 180 xhci->clk = clk;
3429e91a
SAS
181 xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
182 dev_name(&pdev->dev), hcd);
183 if (!xhci->shared_hcd) {
184 ret = -ENOMEM;
185 goto dealloc_usb2_hcd;
186 }
187
188 /*
189 * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset)
190 * is called by usb_add_hcd().
191 */
192 *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
193
14aec589
ON
194 if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
195 xhci->shared_hcd->can_do_streams = 1;
196
3429e91a
SAS
197 ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
198 if (ret)
199 goto put_usb3_hcd;
200
201 return 0;
202
203put_usb3_hcd:
204 usb_put_hcd(xhci->shared_hcd);
205
206dealloc_usb2_hcd:
207 usb_remove_hcd(hcd);
208
4718c177
GC
209disable_clk:
210 if (!IS_ERR(clk))
211 clk_disable_unprepare(clk);
212
3429e91a
SAS
213unmap_registers:
214 iounmap(hcd->regs);
215
216release_mem_region:
217 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
218
219put_hcd:
220 usb_put_hcd(hcd);
221
222 return ret;
223}
224
225static int xhci_plat_remove(struct platform_device *dev)
226{
227 struct usb_hcd *hcd = platform_get_drvdata(dev);
228 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
4718c177 229 struct clk *clk = xhci->clk;
3429e91a
SAS
230
231 usb_remove_hcd(xhci->shared_hcd);
232 usb_put_hcd(xhci->shared_hcd);
233
234 usb_remove_hcd(hcd);
4718c177
GC
235 if (!IS_ERR(clk))
236 clk_disable_unprepare(clk);
3429e91a 237 iounmap(hcd->regs);
5388a3a5 238 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
3429e91a
SAS
239 usb_put_hcd(hcd);
240 kfree(xhci);
241
242 return 0;
243}
244
274f6afa 245#ifdef CONFIG_PM_SLEEP
57d04eb1
VS
246static int xhci_plat_suspend(struct device *dev)
247{
248 struct usb_hcd *hcd = dev_get_drvdata(dev);
249 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
250
251 return xhci_suspend(xhci);
252}
253
254static int xhci_plat_resume(struct device *dev)
255{
256 struct usb_hcd *hcd = dev_get_drvdata(dev);
257 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
258
259 return xhci_resume(xhci, 0);
260}
261
262static const struct dev_pm_ops xhci_plat_pm_ops = {
263 SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
264};
265#define DEV_PM_OPS (&xhci_plat_pm_ops)
266#else
267#define DEV_PM_OPS NULL
268#endif /* CONFIG_PM */
269
1fe6c452
AC
270#ifdef CONFIG_OF
271static const struct of_device_id usb_xhci_of_match[] = {
0f94388b 272 { .compatible = "generic-xhci" },
1fe6c452 273 { .compatible = "xhci-platform" },
97374792
GC
274 { .compatible = "marvell,armada-375-xhci"},
275 { .compatible = "marvell,armada-380-xhci"},
1fe6c452
AC
276 { },
277};
278MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
279#endif
280
3429e91a
SAS
281static struct platform_driver usb_xhci_driver = {
282 .probe = xhci_plat_probe,
283 .remove = xhci_plat_remove,
284 .driver = {
285 .name = "xhci-hcd",
57d04eb1 286 .pm = DEV_PM_OPS,
1fe6c452 287 .of_match_table = of_match_ptr(usb_xhci_of_match),
3429e91a
SAS
288 },
289};
290MODULE_ALIAS("platform:xhci-hcd");
291
292int xhci_register_plat(void)
293{
294 return platform_driver_register(&usb_xhci_driver);
295}
296
297void xhci_unregister_plat(void)
298{
299 platform_driver_unregister(&usb_xhci_driver);
300}