blob: f351ff5b171f752f121119cdc1e51d5846d4d6f0 [file] [log] [blame]
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +01001/*
2 * Generic platform ohci driver
3 *
4 * Copyright 2007 Michael Buesch <m@bues.ch>
5 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
6 *
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
13 *
14 * Licensed under the GNU/GPL. See COPYING for details.
15 */
Manjunath Goudar928fb682013-06-03 20:46:08 +053016
17#include <linux/hrtimer.h>
18#include <linux/io.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
Thierry Reding148e1132013-01-21 11:09:22 +010021#include <linux/err.h>
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010022#include <linux/platform_device.h>
23#include <linux/usb/ohci_pdriver.h>
Manjunath Goudar928fb682013-06-03 20:46:08 +053024#include <linux/usb.h>
25#include <linux/usb/hcd.h>
26
27#include "ohci.h"
28
29#define DRIVER_DESC "OHCI generic platform driver"
30
31static const char hcd_name[] = "ohci-platform";
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010032
33static int ohci_platform_reset(struct usb_hcd *hcd)
34{
35 struct platform_device *pdev = to_platform_device(hcd->self.controller);
Jingoo Hand4f09e22013-07-30 19:59:40 +090036 struct usb_ohci_pdata *pdata = dev_get_platdata(&pdev->dev);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010037 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010038
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;
Florian Fainelli2b16e392012-10-08 15:11:26 +020045 if (pdata->num_ports)
46 ohci->num_ports = pdata->num_ports;
47
Manjunath Goudar928fb682013-06-03 20:46:08 +053048 return ohci_setup(hcd);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010049}
50
Manjunath Goudar928fb682013-06-03 20:46:08 +053051static struct hc_driver __read_mostly ohci_platform_hc_driver;
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010052
Manjunath Goudar928fb682013-06-03 20:46:08 +053053static const struct ohci_driver_overrides platform_overrides __initconst = {
54 .product_desc = "Generic Platform OHCI controller",
55 .reset = ohci_platform_reset,
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010056};
57
Bill Pemberton41ac7b32012-11-19 13:21:48 -050058static int ohci_platform_probe(struct platform_device *dev)
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010059{
60 struct usb_hcd *hcd;
61 struct resource *res_mem;
Jingoo Hand4f09e22013-07-30 19:59:40 +090062 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010063 int irq;
64 int err = -ENOMEM;
65
Kuninori Morimotob6dd2452012-08-06 18:07:30 -070066 if (!pdata) {
67 WARN_ON(1);
68 return -ENODEV;
69 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010070
71 if (usb_disabled())
72 return -ENODEV;
73
74 irq = platform_get_irq(dev, 0);
75 if (irq < 0) {
Florian Fainelli976baf6e2012-10-08 15:11:42 +020076 dev_err(&dev->dev, "no irq provided");
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010077 return irq;
78 }
79
80 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
81 if (!res_mem) {
Florian Fainelliac0e3c02012-10-08 15:11:44 +020082 dev_err(&dev->dev, "no memory resource provided");
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010083 return -ENXIO;
84 }
85
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -070086 if (pdata->power_on) {
87 err = pdata->power_on(dev);
88 if (err < 0)
89 return err;
90 }
91
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010092 hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
93 dev_name(&dev->dev));
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -070094 if (!hcd) {
95 err = -ENOMEM;
96 goto err_power;
97 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +010098
99 hcd->rsrc_start = res_mem->start;
100 hcd->rsrc_len = resource_size(res_mem);
101
Thierry Reding148e1132013-01-21 11:09:22 +0100102 hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
103 if (IS_ERR(hcd->regs)) {
104 err = PTR_ERR(hcd->regs);
Florian Fainellibe7ac702012-10-08 15:11:46 +0200105 goto err_put_hcd;
Julia Lawallaece3892012-08-14 08:47:37 +0200106 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100107 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
108 if (err)
Florian Fainellibe7ac702012-10-08 15:11:46 +0200109 goto err_put_hcd;
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100110
111 platform_set_drvdata(dev, hcd);
112
113 return err;
114
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100115err_put_hcd:
116 usb_put_hcd(hcd);
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700117err_power:
118 if (pdata->power_off)
119 pdata->power_off(dev);
120
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100121 return err;
122}
123
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500124static int ohci_platform_remove(struct platform_device *dev)
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100125{
126 struct usb_hcd *hcd = platform_get_drvdata(dev);
Jingoo Hand4f09e22013-07-30 19:59:40 +0900127 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100128
129 usb_remove_hcd(hcd);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100130 usb_put_hcd(hcd);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100131
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700132 if (pdata->power_off)
133 pdata->power_off(dev);
134
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100135 return 0;
136}
137
138#ifdef CONFIG_PM
139
140static int ohci_platform_suspend(struct device *dev)
141{
Manjunath Goudar39dbd7d2013-10-04 09:58:14 +0530142 struct usb_hcd *hcd = dev_get_drvdata(dev);
143 struct usb_ohci_pdata *pdata = dev->platform_data;
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700144 struct platform_device *pdev =
145 container_of(dev, struct platform_device, dev);
Manjunath Goudar39dbd7d2013-10-04 09:58:14 +0530146 bool do_wakeup = device_may_wakeup(dev);
147 int ret;
148
149 ret = ohci_suspend(hcd, do_wakeup);
150 if (ret)
151 return ret;
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700152
153 if (pdata->power_suspend)
154 pdata->power_suspend(pdev);
155
Manjunath Goudar39dbd7d2013-10-04 09:58:14 +0530156 return ret;
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100157}
158
159static int ohci_platform_resume(struct device *dev)
160{
161 struct usb_hcd *hcd = dev_get_drvdata(dev);
Jingoo Hand4f09e22013-07-30 19:59:40 +0900162 struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
Kuninori Morimotoe4d37ae2012-08-06 18:09:10 -0700163 struct platform_device *pdev =
164 container_of(dev, struct platform_device, dev);
165
166 if (pdata->power_on) {
167 int err = pdata->power_on(pdev);
168 if (err < 0)
169 return err;
170 }
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100171
Florian Fainellicfa49b42012-10-08 15:11:29 +0200172 ohci_resume(hcd, false);
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100173 return 0;
174}
175
176#else /* !CONFIG_PM */
177#define ohci_platform_suspend NULL
178#define ohci_platform_resume NULL
179#endif /* CONFIG_PM */
180
181static const struct platform_device_id ohci_platform_table[] = {
182 { "ohci-platform", 0 },
183 { }
184};
185MODULE_DEVICE_TABLE(platform, ohci_platform_table);
186
187static const struct dev_pm_ops ohci_platform_pm_ops = {
188 .suspend = ohci_platform_suspend,
189 .resume = ohci_platform_resume,
190};
191
192static struct platform_driver ohci_platform_driver = {
193 .id_table = ohci_platform_table,
194 .probe = ohci_platform_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500195 .remove = ohci_platform_remove,
Hauke Mehrtensfa3364b2012-03-13 01:04:47 +0100196 .shutdown = usb_hcd_platform_shutdown,
197 .driver = {
198 .owner = THIS_MODULE,
199 .name = "ohci-platform",
200 .pm = &ohci_platform_pm_ops,
201 }
202};
Manjunath Goudar928fb682013-06-03 20:46:08 +0530203
204static int __init ohci_platform_init(void)
205{
206 if (usb_disabled())
207 return -ENODEV;
208
209 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
210
211 ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides);
212 return platform_driver_register(&ohci_platform_driver);
213}
214module_init(ohci_platform_init);
215
216static void __exit ohci_platform_cleanup(void)
217{
218 platform_driver_unregister(&ohci_platform_driver);
219}
220module_exit(ohci_platform_cleanup);
221
222MODULE_DESCRIPTION(DRIVER_DESC);
223MODULE_AUTHOR("Hauke Mehrtens");
224MODULE_AUTHOR("Alan Stern");
225MODULE_LICENSE("GPL");