PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / usb / host / ohci-platform.c
blob68f674cd095fa227cf06ade8eded93364184861b
1 /*
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.
17 #include <linux/hrtimer.h>
18 #include <linux/io.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/err.h>
22 #include <linux/platform_device.h>
23 #include <linux/usb/ohci_pdriver.h>
24 #include <linux/usb.h>
25 #include <linux/usb/hcd.h>
27 #include "ohci.h"
29 #define DRIVER_DESC "OHCI generic platform driver"
31 static const char hcd_name[] = "ohci-platform";
33 static int ohci_platform_reset(struct usb_hcd *hcd)
35 struct platform_device *pdev = to_platform_device(hcd->self.controller);
36 struct usb_ohci_pdata *pdata = dev_get_platdata(&pdev->dev);
37 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
39 if (pdata->big_endian_desc)
40 ohci->flags |= OHCI_QUIRK_BE_DESC;
41 if (pdata->big_endian_mmio)
42 ohci->flags |= OHCI_QUIRK_BE_MMIO;
43 if (pdata->no_big_frame_no)
44 ohci->flags |= OHCI_QUIRK_FRAME_NO;
45 if (pdata->num_ports)
46 ohci->num_ports = pdata->num_ports;
48 return ohci_setup(hcd);
51 static struct hc_driver __read_mostly ohci_platform_hc_driver;
53 static const struct ohci_driver_overrides platform_overrides __initconst = {
54 .product_desc = "Generic Platform OHCI controller",
55 .reset = ohci_platform_reset,
58 static int ohci_platform_probe(struct platform_device *dev)
60 struct usb_hcd *hcd;
61 struct resource *res_mem;
62 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
63 int irq;
64 int err = -ENOMEM;
66 if (!pdata) {
67 WARN_ON(1);
68 return -ENODEV;
71 if (usb_disabled())
72 return -ENODEV;
74 irq = platform_get_irq(dev, 0);
75 if (irq < 0) {
76 dev_err(&dev->dev, "no irq provided");
77 return irq;
80 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
81 if (!res_mem) {
82 dev_err(&dev->dev, "no memory resource provided");
83 return -ENXIO;
86 if (pdata->power_on) {
87 err = pdata->power_on(dev);
88 if (err < 0)
89 return err;
92 hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
93 dev_name(&dev->dev));
94 if (!hcd) {
95 err = -ENOMEM;
96 goto err_power;
99 hcd->rsrc_start = res_mem->start;
100 hcd->rsrc_len = resource_size(res_mem);
102 hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
103 if (IS_ERR(hcd->regs)) {
104 err = PTR_ERR(hcd->regs);
105 goto err_put_hcd;
107 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
108 if (err)
109 goto err_put_hcd;
111 device_wakeup_enable(hcd->self.controller);
113 platform_set_drvdata(dev, hcd);
115 return err;
117 err_put_hcd:
118 usb_put_hcd(hcd);
119 err_power:
120 if (pdata->power_off)
121 pdata->power_off(dev);
123 return err;
126 static int ohci_platform_remove(struct platform_device *dev)
128 struct usb_hcd *hcd = platform_get_drvdata(dev);
129 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
131 usb_remove_hcd(hcd);
132 usb_put_hcd(hcd);
134 if (pdata->power_off)
135 pdata->power_off(dev);
137 return 0;
140 #ifdef CONFIG_PM
142 static int ohci_platform_suspend(struct device *dev)
144 struct usb_hcd *hcd = dev_get_drvdata(dev);
145 struct usb_ohci_pdata *pdata = dev->platform_data;
146 struct platform_device *pdev =
147 container_of(dev, struct platform_device, dev);
148 bool do_wakeup = device_may_wakeup(dev);
149 int ret;
151 ret = ohci_suspend(hcd, do_wakeup);
152 if (ret)
153 return ret;
155 if (pdata->power_suspend)
156 pdata->power_suspend(pdev);
158 return ret;
161 static int ohci_platform_resume(struct device *dev)
163 struct usb_hcd *hcd = dev_get_drvdata(dev);
164 struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
165 struct platform_device *pdev =
166 container_of(dev, struct platform_device, dev);
168 if (pdata->power_on) {
169 int err = pdata->power_on(pdev);
170 if (err < 0)
171 return err;
174 ohci_resume(hcd, false);
175 return 0;
178 #else /* !CONFIG_PM */
179 #define ohci_platform_suspend NULL
180 #define ohci_platform_resume NULL
181 #endif /* CONFIG_PM */
183 static const struct platform_device_id ohci_platform_table[] = {
184 { "ohci-platform", 0 },
187 MODULE_DEVICE_TABLE(platform, ohci_platform_table);
189 static const struct dev_pm_ops ohci_platform_pm_ops = {
190 .suspend = ohci_platform_suspend,
191 .resume = ohci_platform_resume,
194 static struct platform_driver ohci_platform_driver = {
195 .id_table = ohci_platform_table,
196 .probe = ohci_platform_probe,
197 .remove = ohci_platform_remove,
198 .shutdown = usb_hcd_platform_shutdown,
199 .driver = {
200 .owner = THIS_MODULE,
201 .name = "ohci-platform",
202 .pm = &ohci_platform_pm_ops,
206 static int __init ohci_platform_init(void)
208 if (usb_disabled())
209 return -ENODEV;
211 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
213 ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides);
214 return platform_driver_register(&ohci_platform_driver);
216 module_init(ohci_platform_init);
218 static void __exit ohci_platform_cleanup(void)
220 platform_driver_unregister(&ohci_platform_driver);
222 module_exit(ohci_platform_cleanup);
224 MODULE_DESCRIPTION(DRIVER_DESC);
225 MODULE_AUTHOR("Hauke Mehrtens");
226 MODULE_AUTHOR("Alan Stern");
227 MODULE_LICENSE("GPL");