Linux Audio

Check our new training course

Loading...
v3.5.6
  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
 14#include <linux/platform_device.h>
 15#include <linux/module.h>
 16#include <linux/slab.h>
 
 
 17
 18#include "xhci.h"
 19
 20static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
 21{
 22	/*
 23	 * As of now platform drivers don't provide MSI support so we ensure
 24	 * here that the generic code does not try to make a pci_dev from our
 25	 * dev struct in order to setup MSI
 26	 */
 27	xhci->quirks |= XHCI_BROKEN_MSI;
 28}
 29
 30/* called during probe() after chip reset completes */
 31static int xhci_plat_setup(struct usb_hcd *hcd)
 32{
 33	return xhci_gen_setup(hcd, xhci_plat_quirks);
 34}
 35
 36static const struct hc_driver xhci_plat_xhci_driver = {
 37	.description =		"xhci-hcd",
 38	.product_desc =		"xHCI Host Controller",
 39	.hcd_priv_size =	sizeof(struct xhci_hcd *),
 40
 41	/*
 42	 * generic hardware linkage
 43	 */
 44	.irq =			xhci_irq,
 45	.flags =		HCD_MEMORY | HCD_USB3 | HCD_SHARED,
 46
 47	/*
 48	 * basic lifecycle operations
 49	 */
 50	.reset =		xhci_plat_setup,
 51	.start =		xhci_run,
 52	.stop =			xhci_stop,
 53	.shutdown =		xhci_shutdown,
 54
 55	/*
 56	 * managing i/o requests and associated device resources
 57	 */
 58	.urb_enqueue =		xhci_urb_enqueue,
 59	.urb_dequeue =		xhci_urb_dequeue,
 60	.alloc_dev =		xhci_alloc_dev,
 61	.free_dev =		xhci_free_dev,
 62	.alloc_streams =	xhci_alloc_streams,
 63	.free_streams =		xhci_free_streams,
 64	.add_endpoint =		xhci_add_endpoint,
 65	.drop_endpoint =	xhci_drop_endpoint,
 66	.endpoint_reset =	xhci_endpoint_reset,
 67	.check_bandwidth =	xhci_check_bandwidth,
 68	.reset_bandwidth =	xhci_reset_bandwidth,
 69	.address_device =	xhci_address_device,
 
 70	.update_hub_device =	xhci_update_hub_device,
 71	.reset_device =		xhci_discover_or_reset_device,
 72
 73	/*
 74	 * scheduling support
 75	 */
 76	.get_frame_number =	xhci_get_frame,
 77
 78	/* Root hub support */
 79	.hub_control =		xhci_hub_control,
 80	.hub_status_data =	xhci_hub_status_data,
 81	.bus_suspend =		xhci_bus_suspend,
 82	.bus_resume =		xhci_bus_resume,
 83};
 84
 85static int xhci_plat_probe(struct platform_device *pdev)
 86{
 87	const struct hc_driver	*driver;
 88	struct xhci_hcd		*xhci;
 89	struct resource         *res;
 90	struct usb_hcd		*hcd;
 91	int			ret;
 92	int			irq;
 93
 94	if (usb_disabled())
 95		return -ENODEV;
 96
 97	driver = &xhci_plat_xhci_driver;
 98
 99	irq = platform_get_irq(pdev, 0);
100	if (irq < 0)
101		return -ENODEV;
102
103	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
104	if (!res)
105		return -ENODEV;
106
 
 
 
 
 
 
 
 
 
107	hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
108	if (!hcd)
109		return -ENOMEM;
110
111	hcd->rsrc_start = res->start;
112	hcd->rsrc_len = resource_size(res);
113
114	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
115				driver->description)) {
116		dev_dbg(&pdev->dev, "controller already in use\n");
117		ret = -EBUSY;
118		goto put_hcd;
119	}
120
121	hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
122	if (!hcd->regs) {
123		dev_dbg(&pdev->dev, "error mapping memory\n");
124		ret = -EFAULT;
125		goto release_mem_region;
126	}
127
128	ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
129	if (ret)
130		goto unmap_registers;
 
131
132	/* USB 2.0 roothub is stored in the platform_device now. */
133	hcd = dev_get_drvdata(&pdev->dev);
134	xhci = hcd_to_xhci(hcd);
135	xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
136			dev_name(&pdev->dev), hcd);
137	if (!xhci->shared_hcd) {
138		ret = -ENOMEM;
139		goto dealloc_usb2_hcd;
140	}
141
142	/*
143	 * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset)
144	 * is called by usb_add_hcd().
145	 */
146	*((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
147
 
 
 
148	ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
149	if (ret)
150		goto put_usb3_hcd;
151
152	return 0;
153
154put_usb3_hcd:
155	usb_put_hcd(xhci->shared_hcd);
156
157dealloc_usb2_hcd:
158	usb_remove_hcd(hcd);
159
160unmap_registers:
161	iounmap(hcd->regs);
162
163release_mem_region:
164	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
165
166put_hcd:
167	usb_put_hcd(hcd);
168
169	return ret;
170}
171
172static int xhci_plat_remove(struct platform_device *dev)
173{
174	struct usb_hcd	*hcd = platform_get_drvdata(dev);
175	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
176
177	usb_remove_hcd(xhci->shared_hcd);
178	usb_put_hcd(xhci->shared_hcd);
179
180	usb_remove_hcd(hcd);
181	iounmap(hcd->regs);
 
182	usb_put_hcd(hcd);
183	kfree(xhci);
184
185	return 0;
186}
187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188static struct platform_driver usb_xhci_driver = {
189	.probe	= xhci_plat_probe,
190	.remove	= xhci_plat_remove,
191	.driver	= {
192		.name = "xhci-hcd",
 
 
193	},
194};
195MODULE_ALIAS("platform:xhci-hcd");
196
197int xhci_register_plat(void)
198{
199	return platform_driver_register(&usb_xhci_driver);
200}
201
202void xhci_unregister_plat(void)
203{
204	platform_driver_unregister(&usb_xhci_driver);
205}
v3.15
  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
 14#include <linux/platform_device.h>
 15#include <linux/module.h>
 16#include <linux/slab.h>
 17#include <linux/of.h>
 18#include <linux/dma-mapping.h>
 19
 20#include "xhci.h"
 21
 22static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
 23{
 24	/*
 25	 * As of now platform drivers don't provide MSI support so we ensure
 26	 * here that the generic code does not try to make a pci_dev from our
 27	 * dev struct in order to setup MSI
 28	 */
 29	xhci->quirks |= XHCI_PLAT;
 30}
 31
 32/* called during probe() after chip reset completes */
 33static int xhci_plat_setup(struct usb_hcd *hcd)
 34{
 35	return xhci_gen_setup(hcd, xhci_plat_quirks);
 36}
 37
 38static const struct hc_driver xhci_plat_xhci_driver = {
 39	.description =		"xhci-hcd",
 40	.product_desc =		"xHCI Host Controller",
 41	.hcd_priv_size =	sizeof(struct xhci_hcd *),
 42
 43	/*
 44	 * generic hardware linkage
 45	 */
 46	.irq =			xhci_irq,
 47	.flags =		HCD_MEMORY | HCD_USB3 | HCD_SHARED,
 48
 49	/*
 50	 * basic lifecycle operations
 51	 */
 52	.reset =		xhci_plat_setup,
 53	.start =		xhci_run,
 54	.stop =			xhci_stop,
 55	.shutdown =		xhci_shutdown,
 56
 57	/*
 58	 * managing i/o requests and associated device resources
 59	 */
 60	.urb_enqueue =		xhci_urb_enqueue,
 61	.urb_dequeue =		xhci_urb_dequeue,
 62	.alloc_dev =		xhci_alloc_dev,
 63	.free_dev =		xhci_free_dev,
 64	.alloc_streams =	xhci_alloc_streams,
 65	.free_streams =		xhci_free_streams,
 66	.add_endpoint =		xhci_add_endpoint,
 67	.drop_endpoint =	xhci_drop_endpoint,
 68	.endpoint_reset =	xhci_endpoint_reset,
 69	.check_bandwidth =	xhci_check_bandwidth,
 70	.reset_bandwidth =	xhci_reset_bandwidth,
 71	.address_device =	xhci_address_device,
 72	.enable_device =	xhci_enable_device,
 73	.update_hub_device =	xhci_update_hub_device,
 74	.reset_device =		xhci_discover_or_reset_device,
 75
 76	/*
 77	 * scheduling support
 78	 */
 79	.get_frame_number =	xhci_get_frame,
 80
 81	/* Root hub support */
 82	.hub_control =		xhci_hub_control,
 83	.hub_status_data =	xhci_hub_status_data,
 84	.bus_suspend =		xhci_bus_suspend,
 85	.bus_resume =		xhci_bus_resume,
 86};
 87
 88static int xhci_plat_probe(struct platform_device *pdev)
 89{
 90	const struct hc_driver	*driver;
 91	struct xhci_hcd		*xhci;
 92	struct resource         *res;
 93	struct usb_hcd		*hcd;
 94	int			ret;
 95	int			irq;
 96
 97	if (usb_disabled())
 98		return -ENODEV;
 99
100	driver = &xhci_plat_xhci_driver;
101
102	irq = platform_get_irq(pdev, 0);
103	if (irq < 0)
104		return -ENODEV;
105
106	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
107	if (!res)
108		return -ENODEV;
109
110	/* Initialize dma_mask and coherent_dma_mask to 32-bits */
111	ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
112	if (ret)
113		return ret;
114	if (!pdev->dev.dma_mask)
115		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
116	else
117		dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
118
119	hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
120	if (!hcd)
121		return -ENOMEM;
122
123	hcd->rsrc_start = res->start;
124	hcd->rsrc_len = resource_size(res);
125
126	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
127				driver->description)) {
128		dev_dbg(&pdev->dev, "controller already in use\n");
129		ret = -EBUSY;
130		goto put_hcd;
131	}
132
133	hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
134	if (!hcd->regs) {
135		dev_dbg(&pdev->dev, "error mapping memory\n");
136		ret = -EFAULT;
137		goto release_mem_region;
138	}
139
140	ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
141	if (ret)
142		goto unmap_registers;
143	device_wakeup_enable(hcd->self.controller);
144
145	/* USB 2.0 roothub is stored in the platform_device now. */
146	hcd = platform_get_drvdata(pdev);
147	xhci = hcd_to_xhci(hcd);
148	xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev,
149			dev_name(&pdev->dev), hcd);
150	if (!xhci->shared_hcd) {
151		ret = -ENOMEM;
152		goto dealloc_usb2_hcd;
153	}
154
155	/*
156	 * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset)
157	 * is called by usb_add_hcd().
158	 */
159	*((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
160
161	if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
162		xhci->shared_hcd->can_do_streams = 1;
163
164	ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
165	if (ret)
166		goto put_usb3_hcd;
167
168	return 0;
169
170put_usb3_hcd:
171	usb_put_hcd(xhci->shared_hcd);
172
173dealloc_usb2_hcd:
174	usb_remove_hcd(hcd);
175
176unmap_registers:
177	iounmap(hcd->regs);
178
179release_mem_region:
180	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
181
182put_hcd:
183	usb_put_hcd(hcd);
184
185	return ret;
186}
187
188static int xhci_plat_remove(struct platform_device *dev)
189{
190	struct usb_hcd	*hcd = platform_get_drvdata(dev);
191	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
192
193	usb_remove_hcd(xhci->shared_hcd);
194	usb_put_hcd(xhci->shared_hcd);
195
196	usb_remove_hcd(hcd);
197	iounmap(hcd->regs);
198	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
199	usb_put_hcd(hcd);
200	kfree(xhci);
201
202	return 0;
203}
204
205#ifdef CONFIG_PM
206static int xhci_plat_suspend(struct device *dev)
207{
208	struct usb_hcd	*hcd = dev_get_drvdata(dev);
209	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
210
211	return xhci_suspend(xhci);
212}
213
214static int xhci_plat_resume(struct device *dev)
215{
216	struct usb_hcd	*hcd = dev_get_drvdata(dev);
217	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
218
219	return xhci_resume(xhci, 0);
220}
221
222static const struct dev_pm_ops xhci_plat_pm_ops = {
223	SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
224};
225#define DEV_PM_OPS	(&xhci_plat_pm_ops)
226#else
227#define DEV_PM_OPS	NULL
228#endif /* CONFIG_PM */
229
230#ifdef CONFIG_OF
231static const struct of_device_id usb_xhci_of_match[] = {
232	{ .compatible = "generic-xhci" },
233	{ .compatible = "xhci-platform" },
234	{ },
235};
236MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
237#endif
238
239static struct platform_driver usb_xhci_driver = {
240	.probe	= xhci_plat_probe,
241	.remove	= xhci_plat_remove,
242	.driver	= {
243		.name = "xhci-hcd",
244		.pm = DEV_PM_OPS,
245		.of_match_table = of_match_ptr(usb_xhci_of_match),
246	},
247};
248MODULE_ALIAS("platform:xhci-hcd");
249
250int xhci_register_plat(void)
251{
252	return platform_driver_register(&usb_xhci_driver);
253}
254
255void xhci_unregister_plat(void)
256{
257	platform_driver_unregister(&usb_xhci_driver);
258}