Commit | Line | Data |
---|---|---|
a5b7474a LB |
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 | ||
a5b7474a LB |
31 | static struct clk *usb_host_clock; |
32 | ||
33 | static void ep93xx_start_hc(struct device *dev) | |
34 | { | |
35 | clk_enable(usb_host_clock); | |
36 | } | |
37 | ||
38 | static void ep93xx_stop_hc(struct device *dev) | |
39 | { | |
40 | clk_disable(usb_host_clock); | |
41 | } | |
42 | ||
43 | static int usb_hcd_ep93xx_probe(const struct hc_driver *driver, | |
44 | struct platform_device *pdev) | |
45 | { | |
a5b7474a | 46 | struct usb_hcd *hcd; |
8bd3902d HS |
47 | struct resource *res; |
48 | int retval; | |
a5b7474a LB |
49 | |
50 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { | |
1f550c1a | 51 | dev_dbg(&pdev->dev, "resource[1] is not IORESOURCE_IRQ\n"); |
a5b7474a LB |
52 | return -ENOMEM; |
53 | } | |
54 | ||
8bd3902d HS |
55 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
56 | if (!res) | |
57 | return -ENXIO; | |
58 | ||
a5b7474a LB |
59 | hcd = usb_create_hcd(driver, &pdev->dev, "ep93xx"); |
60 | if (hcd == NULL) | |
61 | return -ENOMEM; | |
62 | ||
8bd3902d HS |
63 | hcd->rsrc_start = res->start; |
64 | hcd->rsrc_len = resource_size(res); | |
a5b7474a | 65 | |
8bd3902d HS |
66 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
67 | if (IS_ERR(hcd->regs)) { | |
68 | retval = PTR_ERR(hcd->regs); | |
69 | goto err_put_hcd; | |
a5b7474a LB |
70 | } |
71 | ||
e3a6d019 HS |
72 | usb_host_clock = clk_get(&pdev->dev, NULL); |
73 | if (IS_ERR(usb_host_clock)) { | |
1f550c1a | 74 | dev_dbg(&pdev->dev, "clk_get failed\n"); |
e3a6d019 | 75 | retval = PTR_ERR(usb_host_clock); |
8bd3902d | 76 | goto err_put_hcd; |
e3a6d019 HS |
77 | } |
78 | ||
a5b7474a LB |
79 | ep93xx_start_hc(&pdev->dev); |
80 | ||
81 | ohci_hcd_init(hcd_to_ohci(hcd)); | |
82 | ||
b5dd18d8 | 83 | retval = usb_add_hcd(hcd, pdev->resource[1].start, 0); |
a5b7474a LB |
84 | if (retval == 0) |
85 | return retval; | |
86 | ||
87 | ep93xx_stop_hc(&pdev->dev); | |
8bd3902d | 88 | err_put_hcd: |
a5b7474a LB |
89 | usb_put_hcd(hcd); |
90 | ||
91 | return retval; | |
92 | } | |
93 | ||
94 | static void usb_hcd_ep93xx_remove(struct usb_hcd *hcd, | |
95 | struct platform_device *pdev) | |
96 | { | |
97 | usb_remove_hcd(hcd); | |
98 | ep93xx_stop_hc(&pdev->dev); | |
99 | clk_put(usb_host_clock); | |
a5b7474a LB |
100 | usb_put_hcd(hcd); |
101 | } | |
102 | ||
41ac7b3a | 103 | static int ohci_ep93xx_start(struct usb_hcd *hcd) |
a5b7474a LB |
104 | { |
105 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | |
106 | int ret; | |
107 | ||
108 | if ((ret = ohci_init(ohci)) < 0) | |
109 | return ret; | |
110 | ||
111 | if ((ret = ohci_run(ohci)) < 0) { | |
8d6c85e4 GKH |
112 | dev_err(hcd->self.controller, "can't start %s\n", |
113 | hcd->self.bus_name); | |
a5b7474a LB |
114 | ohci_stop(hcd); |
115 | return ret; | |
116 | } | |
117 | ||
118 | return 0; | |
119 | } | |
120 | ||
121 | static struct hc_driver ohci_ep93xx_hc_driver = { | |
122 | .description = hcd_name, | |
123 | .product_desc = "EP93xx OHCI", | |
124 | .hcd_priv_size = sizeof(struct ohci_hcd), | |
125 | .irq = ohci_irq, | |
126 | .flags = HCD_USB11 | HCD_MEMORY, | |
127 | .start = ohci_ep93xx_start, | |
128 | .stop = ohci_stop, | |
64a21d02 | 129 | .shutdown = ohci_shutdown, |
a5b7474a LB |
130 | .urb_enqueue = ohci_urb_enqueue, |
131 | .urb_dequeue = ohci_urb_dequeue, | |
132 | .endpoint_disable = ohci_endpoint_disable, | |
133 | .get_frame_number = ohci_get_frame, | |
134 | .hub_status_data = ohci_hub_status_data, | |
135 | .hub_control = ohci_hub_control, | |
136 | #ifdef CONFIG_PM | |
137 | .bus_suspend = ohci_bus_suspend, | |
138 | .bus_resume = ohci_bus_resume, | |
139 | #endif | |
140 | .start_port_reset = ohci_start_port_reset, | |
141 | }; | |
142 | ||
143 | extern int usb_disabled(void); | |
144 | ||
145 | static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev) | |
146 | { | |
147 | int ret; | |
148 | ||
149 | ret = -ENODEV; | |
150 | if (!usb_disabled()) | |
151 | ret = usb_hcd_ep93xx_probe(&ohci_ep93xx_hc_driver, pdev); | |
152 | ||
153 | return ret; | |
154 | } | |
155 | ||
156 | static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev) | |
157 | { | |
158 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | |
159 | ||
160 | usb_hcd_ep93xx_remove(hcd, pdev); | |
161 | ||
162 | return 0; | |
163 | } | |
164 | ||
165 | #ifdef CONFIG_PM | |
166 | static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state) | |
167 | { | |
168 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | |
caaf2632 | 169 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
a5b7474a LB |
170 | |
171 | if (time_before(jiffies, ohci->next_statechange)) | |
172 | msleep(5); | |
173 | ohci->next_statechange = jiffies; | |
174 | ||
175 | ep93xx_stop_hc(&pdev->dev); | |
a5b7474a LB |
176 | return 0; |
177 | } | |
178 | ||
179 | static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev) | |
180 | { | |
181 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | |
182 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | |
a5b7474a LB |
183 | |
184 | if (time_before(jiffies, ohci->next_statechange)) | |
185 | msleep(5); | |
186 | ohci->next_statechange = jiffies; | |
187 | ||
188 | ep93xx_start_hc(&pdev->dev); | |
a5b7474a | 189 | |
cfa49b4b | 190 | ohci_resume(hcd, false); |
a5b7474a LB |
191 | return 0; |
192 | } | |
193 | #endif | |
194 | ||
195 | ||
196 | static struct platform_driver ohci_hcd_ep93xx_driver = { | |
197 | .probe = ohci_hcd_ep93xx_drv_probe, | |
198 | .remove = ohci_hcd_ep93xx_drv_remove, | |
dd9048af | 199 | .shutdown = usb_hcd_platform_shutdown, |
a5b7474a LB |
200 | #ifdef CONFIG_PM |
201 | .suspend = ohci_hcd_ep93xx_drv_suspend, | |
202 | .resume = ohci_hcd_ep93xx_drv_resume, | |
203 | #endif | |
204 | .driver = { | |
205 | .name = "ep93xx-ohci", | |
f4fce61d | 206 | .owner = THIS_MODULE, |
a5b7474a LB |
207 | }, |
208 | }; | |
209 | ||
f4fce61d | 210 | MODULE_ALIAS("platform:ep93xx-ohci"); |