Revert "USB: OHCI: Properly handle ohci-exynos suspend"
[firefly-linux-kernel-4.4.55.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         bool do_wakeup = device_may_wakeup(&pdev->dev);
116         int ret;
117
118         if (time_before(jiffies, ohci->next_statechange))
119                 msleep(5);
120         ohci->next_statechange = jiffies;
121
122         ret = ohci_suspend(hcd, do_wakeup);
123         if (ret)
124                 return ret;
125
126         ep93xx_stop_hc(&pdev->dev);
127
128         return ret;
129 }
130
131 static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
132 {
133         struct usb_hcd *hcd = platform_get_drvdata(pdev);
134         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
135
136         if (time_before(jiffies, ohci->next_statechange))
137                 msleep(5);
138         ohci->next_statechange = jiffies;
139
140         clk_enable(usb_host_clock);
141
142         ohci_resume(hcd, false);
143         return 0;
144 }
145 #endif
146
147 static struct platform_driver ohci_hcd_ep93xx_driver = {
148         .probe          = ohci_hcd_ep93xx_drv_probe,
149         .remove         = ohci_hcd_ep93xx_drv_remove,
150         .shutdown       = usb_hcd_platform_shutdown,
151 #ifdef CONFIG_PM
152         .suspend        = ohci_hcd_ep93xx_drv_suspend,
153         .resume         = ohci_hcd_ep93xx_drv_resume,
154 #endif
155         .driver         = {
156                 .name   = "ep93xx-ohci",
157                 .owner  = THIS_MODULE,
158         },
159 };
160
161 static int __init ohci_ep93xx_init(void)
162 {
163         if (usb_disabled())
164                 return -ENODEV;
165
166         pr_info("%s: " DRIVER_DESC "\n", hcd_name);
167
168         ohci_init_driver(&ohci_ep93xx_hc_driver, NULL);
169         return platform_driver_register(&ohci_hcd_ep93xx_driver);
170 }
171 module_init(ohci_ep93xx_init);
172
173 static void __exit ohci_ep93xx_cleanup(void)
174 {
175         platform_driver_unregister(&ohci_hcd_ep93xx_driver);
176 }
177 module_exit(ohci_ep93xx_cleanup);
178
179 MODULE_DESCRIPTION(DRIVER_DESC);
180 MODULE_LICENSE("GPL");
181 MODULE_ALIAS("platform:ep93xx-ohci");