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/dma-mapping.h>
22 #include <linux/err.h>
23 #include <linux/kernel.h>
24 #include <linux/hrtimer.h>
26 #include <linux/module.h>
28 #include <linux/platform_device.h>
29 #include <linux/usb.h>
30 #include <linux/usb/hcd.h>
31 #include <linux/usb/ehci_pdriver.h>
35 #define DRIVER_DESC "EHCI generic platform driver"
37 static const char hcd_name
[] = "ehci-platform";
39 static int ehci_platform_reset(struct usb_hcd
*hcd
)
41 struct platform_device
*pdev
= to_platform_device(hcd
->self
.controller
);
42 struct usb_ehci_pdata
*pdata
= dev_get_platdata(&pdev
->dev
);
43 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
46 hcd
->has_tt
= pdata
->has_tt
;
47 ehci
->has_synopsys_hc_bug
= pdata
->has_synopsys_hc_bug
;
48 ehci
->big_endian_desc
= pdata
->big_endian_desc
;
49 ehci
->big_endian_mmio
= pdata
->big_endian_mmio
;
51 if (pdata
->pre_setup
) {
52 retval
= pdata
->pre_setup(hcd
);
57 ehci
->caps
= hcd
->regs
+ pdata
->caps_offset
;
58 retval
= ehci_setup(hcd
);
62 if (pdata
->no_io_watchdog
)
63 ehci
->need_io_watchdog
= 0;
67 static struct hc_driver __read_mostly ehci_platform_hc_driver
;
69 static const struct ehci_driver_overrides platform_overrides __initconst
= {
70 .reset
= ehci_platform_reset
,
73 static struct usb_ehci_pdata ehci_platform_defaults
;
75 static int ehci_platform_probe(struct platform_device
*dev
)
78 struct resource
*res_mem
;
79 struct usb_ehci_pdata
*pdata
;
87 * use reasonable defaults so platforms don't have to provide these.
88 * with DT probing on ARM, none of these are set.
90 if (!dev_get_platdata(&dev
->dev
))
91 dev
->dev
.platform_data
= &ehci_platform_defaults
;
92 if (!dev
->dev
.dma_mask
)
93 dev
->dev
.dma_mask
= &dev
->dev
.coherent_dma_mask
;
94 if (!dev
->dev
.coherent_dma_mask
)
95 dev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
97 pdata
= dev_get_platdata(&dev
->dev
);
99 irq
= platform_get_irq(dev
, 0);
101 dev_err(&dev
->dev
, "no irq provided");
104 res_mem
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
106 dev_err(&dev
->dev
, "no memory resource provided");
110 if (pdata
->power_on
) {
111 err
= pdata
->power_on(dev
);
116 hcd
= usb_create_hcd(&ehci_platform_hc_driver
, &dev
->dev
,
117 dev_name(&dev
->dev
));
123 hcd
->rsrc_start
= res_mem
->start
;
124 hcd
->rsrc_len
= resource_size(res_mem
);
126 hcd
->regs
= devm_ioremap_resource(&dev
->dev
, res_mem
);
127 if (IS_ERR(hcd
->regs
)) {
128 err
= PTR_ERR(hcd
->regs
);
131 err
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
135 platform_set_drvdata(dev
, hcd
);
142 if (pdata
->power_off
)
143 pdata
->power_off(dev
);
148 static int ehci_platform_remove(struct platform_device
*dev
)
150 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
151 struct usb_ehci_pdata
*pdata
= dev_get_platdata(&dev
->dev
);
156 if (pdata
->power_off
)
157 pdata
->power_off(dev
);
159 if (pdata
== &ehci_platform_defaults
)
160 dev
->dev
.platform_data
= NULL
;
167 static int ehci_platform_suspend(struct device
*dev
)
169 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
170 struct usb_ehci_pdata
*pdata
= dev_get_platdata(dev
);
171 struct platform_device
*pdev
=
172 container_of(dev
, struct platform_device
, dev
);
173 bool do_wakeup
= device_may_wakeup(dev
);
176 ret
= ehci_suspend(hcd
, do_wakeup
);
178 if (pdata
->power_suspend
)
179 pdata
->power_suspend(pdev
);
184 static int ehci_platform_resume(struct device
*dev
)
186 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
187 struct usb_ehci_pdata
*pdata
= dev_get_platdata(dev
);
188 struct platform_device
*pdev
=
189 container_of(dev
, struct platform_device
, dev
);
191 if (pdata
->power_on
) {
192 int err
= pdata
->power_on(pdev
);
197 ehci_resume(hcd
, false);
201 #else /* !CONFIG_PM */
202 #define ehci_platform_suspend NULL
203 #define ehci_platform_resume NULL
204 #endif /* CONFIG_PM */
206 static const struct of_device_id vt8500_ehci_ids
[] = {
207 { .compatible
= "via,vt8500-ehci", },
208 { .compatible
= "wm,prizm-ehci", },
212 static const struct platform_device_id ehci_platform_table
[] = {
213 { "ehci-platform", 0 },
216 MODULE_DEVICE_TABLE(platform
, ehci_platform_table
);
218 static const struct dev_pm_ops ehci_platform_pm_ops
= {
219 .suspend
= ehci_platform_suspend
,
220 .resume
= ehci_platform_resume
,
223 static struct platform_driver ehci_platform_driver
= {
224 .id_table
= ehci_platform_table
,
225 .probe
= ehci_platform_probe
,
226 .remove
= ehci_platform_remove
,
227 .shutdown
= usb_hcd_platform_shutdown
,
229 .owner
= THIS_MODULE
,
230 .name
= "ehci-platform",
231 .pm
= &ehci_platform_pm_ops
,
232 .of_match_table
= vt8500_ehci_ids
,
236 static int __init
ehci_platform_init(void)
241 pr_info("%s: " DRIVER_DESC
"\n", hcd_name
);
243 ehci_init_driver(&ehci_platform_hc_driver
, &platform_overrides
);
244 return platform_driver_register(&ehci_platform_driver
);
246 module_init(ehci_platform_init
);
248 static void __exit
ehci_platform_cleanup(void)
250 platform_driver_unregister(&ehci_platform_driver
);
252 module_exit(ehci_platform_cleanup
);
254 MODULE_DESCRIPTION(DRIVER_DESC
);
255 MODULE_AUTHOR("Hauke Mehrtens");
256 MODULE_AUTHOR("Alan Stern");
257 MODULE_LICENSE("GPL");