2 * Generic platform ohci driver
4 * Copyright 2007 Michael Buesch <m@bues.ch>
5 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
7 * Derived from the OCHI-SSB driver
8 * Derived from the OHCI-PCI driver
9 * Copyright 1999 Roman Weissgaerber
10 * Copyright 2000-2002 David Brownell
11 * Copyright 1999 Linus Torvalds
12 * Copyright 1999 Gregory P. Smith
14 * Licensed under the GNU/GPL. See COPYING for details.
16 #include <linux/err.h>
17 #include <linux/platform_device.h>
18 #include <linux/usb/ohci_pdriver.h>
20 static int ohci_platform_reset(struct usb_hcd *hcd)
22 struct platform_device *pdev = to_platform_device(hcd->self.controller);
23 struct usb_ohci_pdata *pdata = pdev->dev.platform_data;
24 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
27 if (pdata->big_endian_desc)
28 ohci->flags |= OHCI_QUIRK_BE_DESC;
29 if (pdata->big_endian_mmio)
30 ohci->flags |= OHCI_QUIRK_BE_MMIO;
31 if (pdata->no_big_frame_no)
32 ohci->flags |= OHCI_QUIRK_FRAME_NO;
37 ohci->num_ports = pdata->num_ports;
39 err = ohci_init(ohci);
44 static int ohci_platform_start(struct usb_hcd *hcd)
46 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
51 ohci_err(ohci, "can't start\n");
58 static const struct hc_driver ohci_platform_hc_driver = {
59 .description = hcd_name,
60 .product_desc = "Generic Platform OHCI Controller",
61 .hcd_priv_size = sizeof(struct ohci_hcd),
64 .flags = HCD_MEMORY | HCD_USB11,
66 .reset = ohci_platform_reset,
67 .start = ohci_platform_start,
69 .shutdown = ohci_shutdown,
71 .urb_enqueue = ohci_urb_enqueue,
72 .urb_dequeue = ohci_urb_dequeue,
73 .endpoint_disable = ohci_endpoint_disable,
75 .get_frame_number = ohci_get_frame,
77 .hub_status_data = ohci_hub_status_data,
78 .hub_control = ohci_hub_control,
80 .bus_suspend = ohci_bus_suspend,
81 .bus_resume = ohci_bus_resume,
84 .start_port_reset = ohci_start_port_reset,
87 static int ohci_platform_probe(struct platform_device *dev)
90 struct resource *res_mem;
91 struct usb_ohci_pdata *pdata = dev->dev.platform_data;
103 irq = platform_get_irq(dev, 0);
105 dev_err(&dev->dev, "no irq provided");
109 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
111 dev_err(&dev->dev, "no memory resource provided");
115 if (pdata->power_on) {
116 err = pdata->power_on(dev);
121 hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
122 dev_name(&dev->dev));
128 hcd->rsrc_start = res_mem->start;
129 hcd->rsrc_len = resource_size(res_mem);
131 hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
132 if (IS_ERR(hcd->regs)) {
133 err = PTR_ERR(hcd->regs);
136 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
140 platform_set_drvdata(dev, hcd);
147 if (pdata->power_off)
148 pdata->power_off(dev);
153 static int ohci_platform_remove(struct platform_device *dev)
155 struct usb_hcd *hcd = platform_get_drvdata(dev);
156 struct usb_ohci_pdata *pdata = dev->dev.platform_data;
160 platform_set_drvdata(dev, NULL);
162 if (pdata->power_off)
163 pdata->power_off(dev);
170 static int ohci_platform_suspend(struct device *dev)
172 struct usb_ohci_pdata *pdata = dev->platform_data;
173 struct platform_device *pdev =
174 container_of(dev, struct platform_device, dev);
176 if (pdata->power_suspend)
177 pdata->power_suspend(pdev);
182 static int ohci_platform_resume(struct device *dev)
184 struct usb_hcd *hcd = dev_get_drvdata(dev);
185 struct usb_ohci_pdata *pdata = dev->platform_data;
186 struct platform_device *pdev =
187 container_of(dev, struct platform_device, dev);
189 if (pdata->power_on) {
190 int err = pdata->power_on(pdev);
195 ohci_resume(hcd, false);
199 #else /* !CONFIG_PM */
200 #define ohci_platform_suspend NULL
201 #define ohci_platform_resume NULL
202 #endif /* CONFIG_PM */
204 static const struct platform_device_id ohci_platform_table[] = {
205 { "ohci-platform", 0 },
208 MODULE_DEVICE_TABLE(platform, ohci_platform_table);
210 static const struct dev_pm_ops ohci_platform_pm_ops = {
211 .suspend = ohci_platform_suspend,
212 .resume = ohci_platform_resume,
215 static struct platform_driver ohci_platform_driver = {
216 .id_table = ohci_platform_table,
217 .probe = ohci_platform_probe,
218 .remove = ohci_platform_remove,
219 .shutdown = usb_hcd_platform_shutdown,
221 .owner = THIS_MODULE,
222 .name = "ohci-platform",
223 .pm = &ohci_platform_pm_ops,