]> Git Repo - linux.git/blob - drivers/usb/host/ehci-platform.c
Merge tag 'fixes-non-critical-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux.git] / drivers / usb / host / ehci-platform.c
1 /*
2  * Generic platform ehci driver
3  *
4  * Copyright 2007 Steven Brown <[email protected]>
5  * Copyright 2010-2012 Hauke Mehrtens <[email protected]>
6  *
7  * Derived from the ohci-ssb driver
8  * Copyright 2007 Michael Buesch <[email protected]>
9  *
10  * Derived from the EHCI-PCI driver
11  * Copyright (c) 2000-2004 by David Brownell
12  *
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
18  *
19  * Licensed under the GNU/GPL. See COPYING for details.
20  */
21 #include <linux/dma-mapping.h>
22 #include <linux/err.h>
23 #include <linux/kernel.h>
24 #include <linux/hrtimer.h>
25 #include <linux/io.h>
26 #include <linux/module.h>
27 #include <linux/of.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>
32
33 #include "ehci.h"
34
35 #define DRIVER_DESC "EHCI generic platform driver"
36
37 static const char hcd_name[] = "ehci-platform";
38
39 static int ehci_platform_reset(struct usb_hcd *hcd)
40 {
41         struct platform_device *pdev = to_platform_device(hcd->self.controller);
42         struct usb_ehci_pdata *pdata = pdev->dev.platform_data;
43         struct ehci_hcd *ehci = hcd_to_ehci(hcd);
44         int retval;
45
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;
50
51         ehci->caps = hcd->regs + pdata->caps_offset;
52         retval = ehci_setup(hcd);
53         if (retval)
54                 return retval;
55
56         if (pdata->no_io_watchdog)
57                 ehci->need_io_watchdog = 0;
58         return 0;
59 }
60
61 static struct hc_driver __read_mostly ehci_platform_hc_driver;
62
63 static const struct ehci_driver_overrides platform_overrides __initconst = {
64         .reset =        ehci_platform_reset,
65 };
66
67 static struct usb_ehci_pdata ehci_platform_defaults;
68
69 static int ehci_platform_probe(struct platform_device *dev)
70 {
71         struct usb_hcd *hcd;
72         struct resource *res_mem;
73         struct usb_ehci_pdata *pdata;
74         int irq;
75         int err = -ENOMEM;
76
77         if (usb_disabled())
78                 return -ENODEV;
79
80         /*
81          * use reasonable defaults so platforms don't have to provide these.
82          * with DT probing on ARM, none of these are set.
83          */
84         if (!dev->dev.platform_data)
85                 dev->dev.platform_data = &ehci_platform_defaults;
86         if (!dev->dev.dma_mask)
87                 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
88         if (!dev->dev.coherent_dma_mask)
89                 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
90
91         pdata = dev->dev.platform_data;
92
93         irq = platform_get_irq(dev, 0);
94         if (irq < 0) {
95                 dev_err(&dev->dev, "no irq provided");
96                 return irq;
97         }
98         res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
99         if (!res_mem) {
100                 dev_err(&dev->dev, "no memory resource provided");
101                 return -ENXIO;
102         }
103
104         if (pdata->power_on) {
105                 err = pdata->power_on(dev);
106                 if (err < 0)
107                         return err;
108         }
109
110         hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
111                              dev_name(&dev->dev));
112         if (!hcd) {
113                 err = -ENOMEM;
114                 goto err_power;
115         }
116
117         hcd->rsrc_start = res_mem->start;
118         hcd->rsrc_len = resource_size(res_mem);
119
120         hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
121         if (IS_ERR(hcd->regs)) {
122                 err = PTR_ERR(hcd->regs);
123                 goto err_put_hcd;
124         }
125         err = usb_add_hcd(hcd, irq, IRQF_SHARED);
126         if (err)
127                 goto err_put_hcd;
128
129         platform_set_drvdata(dev, hcd);
130
131         return err;
132
133 err_put_hcd:
134         usb_put_hcd(hcd);
135 err_power:
136         if (pdata->power_off)
137                 pdata->power_off(dev);
138
139         return err;
140 }
141
142 static int ehci_platform_remove(struct platform_device *dev)
143 {
144         struct usb_hcd *hcd = platform_get_drvdata(dev);
145         struct usb_ehci_pdata *pdata = dev->dev.platform_data;
146
147         usb_remove_hcd(hcd);
148         usb_put_hcd(hcd);
149
150         if (pdata->power_off)
151                 pdata->power_off(dev);
152
153         if (pdata == &ehci_platform_defaults)
154                 dev->dev.platform_data = NULL;
155
156         return 0;
157 }
158
159 #ifdef CONFIG_PM
160
161 static int ehci_platform_suspend(struct device *dev)
162 {
163         struct usb_hcd *hcd = dev_get_drvdata(dev);
164         struct usb_ehci_pdata *pdata = dev->platform_data;
165         struct platform_device *pdev =
166                 container_of(dev, struct platform_device, dev);
167         bool do_wakeup = device_may_wakeup(dev);
168         int ret;
169
170         ret = ehci_suspend(hcd, do_wakeup);
171
172         if (pdata->power_suspend)
173                 pdata->power_suspend(pdev);
174
175         return ret;
176 }
177
178 static int ehci_platform_resume(struct device *dev)
179 {
180         struct usb_hcd *hcd = dev_get_drvdata(dev);
181         struct usb_ehci_pdata *pdata = dev->platform_data;
182         struct platform_device *pdev =
183                 container_of(dev, struct platform_device, dev);
184
185         if (pdata->power_on) {
186                 int err = pdata->power_on(pdev);
187                 if (err < 0)
188                         return err;
189         }
190
191         ehci_resume(hcd, false);
192         return 0;
193 }
194
195 #else /* !CONFIG_PM */
196 #define ehci_platform_suspend   NULL
197 #define ehci_platform_resume    NULL
198 #endif /* CONFIG_PM */
199
200 static const struct of_device_id vt8500_ehci_ids[] = {
201         { .compatible = "via,vt8500-ehci", },
202         { .compatible = "wm,prizm-ehci", },
203         {}
204 };
205
206 static const struct platform_device_id ehci_platform_table[] = {
207         { "ehci-platform", 0 },
208         { }
209 };
210 MODULE_DEVICE_TABLE(platform, ehci_platform_table);
211
212 static const struct dev_pm_ops ehci_platform_pm_ops = {
213         .suspend        = ehci_platform_suspend,
214         .resume         = ehci_platform_resume,
215 };
216
217 static struct platform_driver ehci_platform_driver = {
218         .id_table       = ehci_platform_table,
219         .probe          = ehci_platform_probe,
220         .remove         = ehci_platform_remove,
221         .shutdown       = usb_hcd_platform_shutdown,
222         .driver         = {
223                 .owner  = THIS_MODULE,
224                 .name   = "ehci-platform",
225                 .pm     = &ehci_platform_pm_ops,
226                 .of_match_table = vt8500_ehci_ids,
227         }
228 };
229
230 static int __init ehci_platform_init(void)
231 {
232         if (usb_disabled())
233                 return -ENODEV;
234
235         pr_info("%s: " DRIVER_DESC "\n", hcd_name);
236
237         ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides);
238         return platform_driver_register(&ehci_platform_driver);
239 }
240 module_init(ehci_platform_init);
241
242 static void __exit ehci_platform_cleanup(void)
243 {
244         platform_driver_unregister(&ehci_platform_driver);
245 }
246 module_exit(ehci_platform_cleanup);
247
248 MODULE_DESCRIPTION(DRIVER_DESC);
249 MODULE_AUTHOR("Hauke Mehrtens");
250 MODULE_AUTHOR("Alan Stern");
251 MODULE_LICENSE("GPL");
This page took 0.049134 seconds and 4 git commands to generate.