2 * Generic platform ehci driver
4 * Copyright 2007 Steven Brown <sbrown@cortland.com>
5 * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
7 * Derived from the ohci-ssb driver
8 * Copyright 2007 Michael Buesch <m@bues.ch>
10 * Derived from the EHCI-PCI driver
11 * Copyright (c) 2000-2004 by David Brownell
13 * Derived from the ohci-pci driver
14 * Copyright 1999 Roman Weissgaerber
15 * Copyright 2000-2002 David Brownell
16 * Copyright 1999 Linus Torvalds
17 * Copyright 1999 Gregory P. Smith
19 * Licensed under the GNU/GPL. See COPYING for details.
21 #include <linux/err.h>
22 #include <linux/kernel.h>
23 #include <linux/hrtimer.h>
25 #include <linux/module.h>
26 #include <linux/platform_device.h>
27 #include <linux/usb.h>
28 #include <linux/usb/hcd.h>
29 #include <linux/usb/ehci_pdriver.h>
33 #define DRIVER_DESC "EHCI generic platform driver"
35 static const char hcd_name
[] = "ehci-platform";
37 static int ehci_platform_reset(struct usb_hcd
*hcd
)
39 struct platform_device
*pdev
= to_platform_device(hcd
->self
.controller
);
40 struct usb_ehci_pdata
*pdata
= pdev
->dev
.platform_data
;
41 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
44 hcd
->has_tt
= pdata
->has_tt
;
45 ehci
->has_synopsys_hc_bug
= pdata
->has_synopsys_hc_bug
;
46 ehci
->big_endian_desc
= pdata
->big_endian_desc
;
47 ehci
->big_endian_mmio
= pdata
->big_endian_mmio
;
49 ehci
->caps
= hcd
->regs
+ pdata
->caps_offset
;
50 retval
= ehci_setup(hcd
);
54 if (pdata
->no_io_watchdog
)
55 ehci
->need_io_watchdog
= 0;
59 static struct hc_driver __read_mostly ehci_platform_hc_driver
;
61 static const struct ehci_driver_overrides platform_overrides __initdata
= {
62 .reset
= ehci_platform_reset
,
65 static int ehci_platform_probe(struct platform_device
*dev
)
68 struct resource
*res_mem
;
69 struct usb_ehci_pdata
*pdata
= dev
->dev
.platform_data
;
81 irq
= platform_get_irq(dev
, 0);
83 dev_err(&dev
->dev
, "no irq provided");
86 res_mem
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
88 dev_err(&dev
->dev
, "no memory resource provided");
92 if (pdata
->power_on
) {
93 err
= pdata
->power_on(dev
);
98 hcd
= usb_create_hcd(&ehci_platform_hc_driver
, &dev
->dev
,
105 hcd
->rsrc_start
= res_mem
->start
;
106 hcd
->rsrc_len
= resource_size(res_mem
);
108 hcd
->regs
= devm_ioremap_resource(&dev
->dev
, res_mem
);
109 if (IS_ERR(hcd
->regs
)) {
110 err
= PTR_ERR(hcd
->regs
);
113 err
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
117 platform_set_drvdata(dev
, hcd
);
124 if (pdata
->power_off
)
125 pdata
->power_off(dev
);
130 static int ehci_platform_remove(struct platform_device
*dev
)
132 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
133 struct usb_ehci_pdata
*pdata
= dev
->dev
.platform_data
;
137 platform_set_drvdata(dev
, NULL
);
139 if (pdata
->power_off
)
140 pdata
->power_off(dev
);
147 static int ehci_platform_suspend(struct device
*dev
)
149 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
150 struct usb_ehci_pdata
*pdata
= dev
->platform_data
;
151 struct platform_device
*pdev
=
152 container_of(dev
, struct platform_device
, dev
);
153 bool do_wakeup
= device_may_wakeup(dev
);
156 ret
= ehci_suspend(hcd
, do_wakeup
);
158 if (pdata
->power_suspend
)
159 pdata
->power_suspend(pdev
);
164 static int ehci_platform_resume(struct device
*dev
)
166 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
167 struct usb_ehci_pdata
*pdata
= dev
->platform_data
;
168 struct platform_device
*pdev
=
169 container_of(dev
, struct platform_device
, dev
);
171 if (pdata
->power_on
) {
172 int err
= pdata
->power_on(pdev
);
177 ehci_resume(hcd
, false);
181 #else /* !CONFIG_PM */
182 #define ehci_platform_suspend NULL
183 #define ehci_platform_resume NULL
184 #endif /* CONFIG_PM */
186 static const struct platform_device_id ehci_platform_table
[] = {
187 { "ehci-platform", 0 },
190 MODULE_DEVICE_TABLE(platform
, ehci_platform_table
);
192 static const struct dev_pm_ops ehci_platform_pm_ops
= {
193 .suspend
= ehci_platform_suspend
,
194 .resume
= ehci_platform_resume
,
197 static struct platform_driver ehci_platform_driver
= {
198 .id_table
= ehci_platform_table
,
199 .probe
= ehci_platform_probe
,
200 .remove
= ehci_platform_remove
,
201 .shutdown
= usb_hcd_platform_shutdown
,
203 .owner
= THIS_MODULE
,
204 .name
= "ehci-platform",
205 .pm
= &ehci_platform_pm_ops
,
209 static int __init
ehci_platform_init(void)
214 pr_info("%s: " DRIVER_DESC
"\n", hcd_name
);
216 ehci_init_driver(&ehci_platform_hc_driver
, &platform_overrides
);
217 return platform_driver_register(&ehci_platform_driver
);
219 module_init(ehci_platform_init
);
221 static void __exit
ehci_platform_cleanup(void)
223 platform_driver_unregister(&ehci_platform_driver
);
225 module_exit(ehci_platform_cleanup
);
227 MODULE_DESCRIPTION(DRIVER_DESC
);
228 MODULE_AUTHOR("Hauke Mehrtens");
229 MODULE_AUTHOR("Alan Stern");
230 MODULE_LICENSE("GPL");