]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/usb/host/ohci-ep93xx.c
Merge 3.12-rc3 into usb-next
[karo-tx-linux.git] / drivers / usb / host / ohci-ep93xx.c
1 /*
2  * OHCI HCD (Host Controller Driver) for USB.
3  *
4  * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5  * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6  * (C) Copyright 2002 Hewlett-Packard Company
7  *
8  * Bus Glue for ep93xx.
9  *
10  * Written by Christopher Hoover <ch@hpl.hp.com>
11  * Based on fragments of previous driver by Russell King et al.
12  *
13  * Modified for LH7A404 from ohci-sa1111.c
14  *  by Durgesh Pattamatta <pattamattad@sharpsec.com>
15  *
16  * Modified for pxa27x from ohci-lh7a404.c
17  *  by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
18  *
19  * Modified for ep93xx from ohci-pxa27x.c
20  *  by Lennert Buytenhek <buytenh@wantstofly.org> 28-2-2006
21  *  Based on an earlier driver by Ray Lehtiniemi
22  *
23  * This file is licenced under the GPL.
24  */
25
26 #include <linux/clk.h>
27 #include <linux/device.h>
28 #include <linux/io.h>
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/platform_device.h>
32 #include <linux/signal.h>
33 #include <linux/usb.h>
34 #include <linux/usb/hcd.h>
35
36 #include "ohci.h"
37
38 #define DRIVER_DESC "OHCI EP93xx driver"
39
40 static const char hcd_name[] = "ohci-ep93xx";
41
42 static struct hc_driver __read_mostly ohci_ep93xx_hc_driver;
43
44 static struct clk *usb_host_clock;
45
46 static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
47 {
48         struct usb_hcd *hcd;
49         struct resource *res;
50         int irq;
51         int ret;
52
53         if (usb_disabled())
54                 return -ENODEV;
55
56         irq = platform_get_irq(pdev, 0);
57         if (irq < 0)
58                 return irq;
59
60         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
61         if (!res)
62                 return -ENXIO;
63
64         hcd = usb_create_hcd(&ohci_ep93xx_hc_driver, &pdev->dev, "ep93xx");
65         if (!hcd)
66                 return -ENOMEM;
67
68         hcd->rsrc_start = res->start;
69         hcd->rsrc_len = resource_size(res);
70
71         hcd->regs = devm_ioremap_resource(&pdev->dev, res);
72         if (IS_ERR(hcd->regs)) {
73                 ret = PTR_ERR(hcd->regs);
74                 goto err_put_hcd;
75         }
76
77         usb_host_clock = devm_clk_get(&pdev->dev, NULL);
78         if (IS_ERR(usb_host_clock)) {
79                 ret = PTR_ERR(usb_host_clock);
80                 goto err_put_hcd;
81         }
82
83         clk_enable(usb_host_clock);
84
85         ret = usb_add_hcd(hcd, irq, 0);
86         if (ret)
87                 goto err_clk_disable;
88
89         return 0;
90
91 err_clk_disable:
92         clk_disable(usb_host_clock);
93 err_put_hcd:
94         usb_put_hcd(hcd);
95
96         return ret;
97 }
98
99 static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
100 {
101         struct usb_hcd *hcd = platform_get_drvdata(pdev);
102
103         usb_remove_hcd(hcd);
104         clk_disable(usb_host_clock);
105         usb_put_hcd(hcd);
106
107         return 0;
108 }
109
110 #ifdef CONFIG_PM
111 static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
112 {
113         struct usb_hcd *hcd = platform_get_drvdata(pdev);
114         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
115
116         if (time_before(jiffies, ohci->next_statechange))
117                 msleep(5);
118         ohci->next_statechange = jiffies;
119
120         clk_disable(usb_host_clock);
121         return 0;
122 }
123
124 static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
125 {
126         struct usb_hcd *hcd = platform_get_drvdata(pdev);
127         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
128
129         if (time_before(jiffies, ohci->next_statechange))
130                 msleep(5);
131         ohci->next_statechange = jiffies;
132
133         clk_enable(usb_host_clock);
134
135         ohci_resume(hcd, false);
136         return 0;
137 }
138 #endif
139
140 static struct platform_driver ohci_hcd_ep93xx_driver = {
141         .probe          = ohci_hcd_ep93xx_drv_probe,
142         .remove         = ohci_hcd_ep93xx_drv_remove,
143         .shutdown       = usb_hcd_platform_shutdown,
144 #ifdef CONFIG_PM
145         .suspend        = ohci_hcd_ep93xx_drv_suspend,
146         .resume         = ohci_hcd_ep93xx_drv_resume,
147 #endif
148         .driver         = {
149                 .name   = "ep93xx-ohci",
150                 .owner  = THIS_MODULE,
151         },
152 };
153
154 static int __init ohci_ep93xx_init(void)
155 {
156         if (usb_disabled())
157                 return -ENODEV;
158
159         pr_info("%s: " DRIVER_DESC "\n", hcd_name);
160
161         ohci_init_driver(&ohci_ep93xx_hc_driver, NULL);
162         return platform_driver_register(&ohci_hcd_ep93xx_driver);
163 }
164 module_init(ohci_ep93xx_init);
165
166 static void __exit ohci_ep93xx_cleanup(void)
167 {
168         platform_driver_unregister(&ohci_hcd_ep93xx_driver);
169 }
170 module_exit(ohci_ep93xx_cleanup);
171
172 MODULE_DESCRIPTION(DRIVER_DESC);
173 MODULE_LICENSE("GPL");
174 MODULE_ALIAS("platform:ep93xx-ohci");