]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/usb/host/ohci-ep93xx.c
Merge branch 'pm-cpufreq'
[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/signal.h>
29 #include <linux/platform_device.h>
30
31 static struct clk *usb_host_clock;
32
33 static int ohci_ep93xx_start(struct usb_hcd *hcd)
34 {
35         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
36         int ret;
37
38         if ((ret = ohci_init(ohci)) < 0)
39                 return ret;
40
41         if ((ret = ohci_run(ohci)) < 0) {
42                 dev_err(hcd->self.controller, "can't start %s\n",
43                         hcd->self.bus_name);
44                 ohci_stop(hcd);
45                 return ret;
46         }
47
48         return 0;
49 }
50
51 static struct hc_driver ohci_ep93xx_hc_driver = {
52         .description            = hcd_name,
53         .product_desc           = "EP93xx OHCI",
54         .hcd_priv_size          = sizeof(struct ohci_hcd),
55         .irq                    = ohci_irq,
56         .flags                  = HCD_USB11 | HCD_MEMORY,
57         .start                  = ohci_ep93xx_start,
58         .stop                   = ohci_stop,
59         .shutdown               = ohci_shutdown,
60         .urb_enqueue            = ohci_urb_enqueue,
61         .urb_dequeue            = ohci_urb_dequeue,
62         .endpoint_disable       = ohci_endpoint_disable,
63         .get_frame_number       = ohci_get_frame,
64         .hub_status_data        = ohci_hub_status_data,
65         .hub_control            = ohci_hub_control,
66 #ifdef CONFIG_PM
67         .bus_suspend            = ohci_bus_suspend,
68         .bus_resume             = ohci_bus_resume,
69 #endif
70         .start_port_reset       = ohci_start_port_reset,
71 };
72
73 static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
74 {
75         struct usb_hcd *hcd;
76         struct resource *res;
77         int irq;
78         int ret;
79
80         if (usb_disabled())
81                 return -ENODEV;
82
83         irq = platform_get_irq(pdev, 0);
84         if (irq < 0)
85                 return irq;
86
87         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88         if (!res)
89                 return -ENXIO;
90
91         hcd = usb_create_hcd(&ohci_ep93xx_hc_driver, &pdev->dev, "ep93xx");
92         if (!hcd)
93                 return -ENOMEM;
94
95         hcd->rsrc_start = res->start;
96         hcd->rsrc_len = resource_size(res);
97
98         hcd->regs = devm_ioremap_resource(&pdev->dev, res);
99         if (IS_ERR(hcd->regs)) {
100                 ret = PTR_ERR(hcd->regs);
101                 goto err_put_hcd;
102         }
103
104         usb_host_clock = devm_clk_get(&pdev->dev, NULL);
105         if (IS_ERR(usb_host_clock)) {
106                 ret = PTR_ERR(usb_host_clock);
107                 goto err_put_hcd;
108         }
109
110         clk_enable(usb_host_clock);
111
112         ohci_hcd_init(hcd_to_ohci(hcd));
113
114         ret = usb_add_hcd(hcd, irq, 0);
115         if (ret)
116                 goto err_clk_disable;
117
118         return 0;
119
120 err_clk_disable:
121         clk_disable(usb_host_clock);
122 err_put_hcd:
123         usb_put_hcd(hcd);
124
125         return ret;
126 }
127
128 static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
129 {
130         struct usb_hcd *hcd = platform_get_drvdata(pdev);
131
132         usb_remove_hcd(hcd);
133         clk_disable(usb_host_clock);
134         usb_put_hcd(hcd);
135
136         return 0;
137 }
138
139 #ifdef CONFIG_PM
140 static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
141 {
142         struct usb_hcd *hcd = platform_get_drvdata(pdev);
143         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
144
145         if (time_before(jiffies, ohci->next_statechange))
146                 msleep(5);
147         ohci->next_statechange = jiffies;
148
149         clk_disable(usb_host_clock);
150         return 0;
151 }
152
153 static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
154 {
155         struct usb_hcd *hcd = platform_get_drvdata(pdev);
156         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
157
158         if (time_before(jiffies, ohci->next_statechange))
159                 msleep(5);
160         ohci->next_statechange = jiffies;
161
162         clk_enable(usb_host_clock);
163
164         ohci_resume(hcd, false);
165         return 0;
166 }
167 #endif
168
169
170 static struct platform_driver ohci_hcd_ep93xx_driver = {
171         .probe          = ohci_hcd_ep93xx_drv_probe,
172         .remove         = ohci_hcd_ep93xx_drv_remove,
173         .shutdown       = usb_hcd_platform_shutdown,
174 #ifdef CONFIG_PM
175         .suspend        = ohci_hcd_ep93xx_drv_suspend,
176         .resume         = ohci_hcd_ep93xx_drv_resume,
177 #endif
178         .driver         = {
179                 .name   = "ep93xx-ohci",
180                 .owner  = THIS_MODULE,
181         },
182 };
183
184 MODULE_ALIAS("platform:ep93xx-ohci");