wusb: remove unused #include <version.h>
[linux-2.6.git] / drivers / usb / host / whci / hcd.c
1 /*
2  * Wireless Host Controller (WHC) driver.
3  *
4  * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License version
8  * 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/uwb/umc.h>
21
22 #include "../../wusbcore/wusbhc.h"
23
24 #include "whcd.h"
25
26 /*
27  * One time initialization.
28  *
29  * Nothing to do here.
30  */
31 static int whc_reset(struct usb_hcd *usb_hcd)
32 {
33         return 0;
34 }
35
36 /*
37  * Start the wireless host controller.
38  *
39  * Start device notification.
40  *
41  * Put hc into run state, set DNTS parameters.
42  */
43 static int whc_start(struct usb_hcd *usb_hcd)
44 {
45         struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
46         struct whc *whc = wusbhc_to_whc(wusbhc);
47         u8 bcid;
48         int ret;
49
50         mutex_lock(&wusbhc->mutex);
51
52         le_writel(WUSBINTR_GEN_CMD_DONE
53                   | WUSBINTR_HOST_ERR
54                   | WUSBINTR_ASYNC_SCHED_SYNCED
55                   | WUSBINTR_DNTS_INT
56                   | WUSBINTR_ERR_INT
57                   | WUSBINTR_INT,
58                   whc->base + WUSBINTR);
59
60         /* set cluster ID */
61         bcid = wusb_cluster_id_get();
62         ret = whc_set_cluster_id(whc, bcid);
63         if (ret < 0)
64                 goto out;
65         wusbhc->cluster_id = bcid;
66
67         /* start HC */
68         whc_write_wusbcmd(whc, WUSBCMD_RUN, WUSBCMD_RUN);
69
70         usb_hcd->uses_new_polling = 1;
71         usb_hcd->poll_rh = 1;
72         usb_hcd->state = HC_STATE_RUNNING;
73
74 out:
75         mutex_unlock(&wusbhc->mutex);
76         return ret;
77 }
78
79
80 /*
81  * Stop the wireless host controller.
82  *
83  * Stop device notification.
84  *
85  * Wait for pending transfer to stop? Put hc into stop state?
86  */
87 static void whc_stop(struct usb_hcd *usb_hcd)
88 {
89         struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
90         struct whc *whc = wusbhc_to_whc(wusbhc);
91
92         mutex_lock(&wusbhc->mutex);
93
94         wusbhc_stop(wusbhc);
95
96         /* stop HC */
97         le_writel(0, whc->base + WUSBINTR);
98         whc_write_wusbcmd(whc, WUSBCMD_RUN, 0);
99         whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS,
100                       WUSBSTS_HCHALTED, WUSBSTS_HCHALTED,
101                       100, "HC to halt");
102
103         wusb_cluster_id_put(wusbhc->cluster_id);
104
105         mutex_unlock(&wusbhc->mutex);
106 }
107
108 static int whc_get_frame_number(struct usb_hcd *usb_hcd)
109 {
110         /* Frame numbers are not applicable to WUSB. */
111         return -ENOSYS;
112 }
113
114
115 /*
116  * Queue an URB to the ASL or PZL
117  */
118 static int whc_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb,
119                            gfp_t mem_flags)
120 {
121         struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
122         struct whc *whc = wusbhc_to_whc(wusbhc);
123         int ret;
124
125         switch (usb_pipetype(urb->pipe)) {
126         case PIPE_INTERRUPT:
127                 ret = pzl_urb_enqueue(whc, urb, mem_flags);
128                 break;
129         case PIPE_ISOCHRONOUS:
130                 dev_err(&whc->umc->dev, "isochronous transfers unsupported\n");
131                 ret = -ENOTSUPP;
132                 break;
133         case PIPE_CONTROL:
134         case PIPE_BULK:
135         default:
136                 ret = asl_urb_enqueue(whc, urb, mem_flags);
137                 break;
138         };
139
140         return ret;
141 }
142
143 /*
144  * Remove a queued URB from the ASL or PZL.
145  */
146 static int whc_urb_dequeue(struct usb_hcd *usb_hcd, struct urb *urb, int status)
147 {
148         struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
149         struct whc *whc = wusbhc_to_whc(wusbhc);
150         int ret;
151
152         switch (usb_pipetype(urb->pipe)) {
153         case PIPE_INTERRUPT:
154                 ret = pzl_urb_dequeue(whc, urb, status);
155                 break;
156         case PIPE_ISOCHRONOUS:
157                 ret = -ENOTSUPP;
158                 break;
159         case PIPE_CONTROL:
160         case PIPE_BULK:
161         default:
162                 ret = asl_urb_dequeue(whc, urb, status);
163                 break;
164         };
165
166         return ret;
167 }
168
169 /*
170  * Wait for all URBs to the endpoint to be completed, then delete the
171  * qset.
172  */
173 static void whc_endpoint_disable(struct usb_hcd *usb_hcd,
174                                  struct usb_host_endpoint *ep)
175 {
176         struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
177         struct whc *whc = wusbhc_to_whc(wusbhc);
178         struct whc_qset *qset;
179
180         qset = ep->hcpriv;
181         if (qset) {
182                 ep->hcpriv = NULL;
183                 if (usb_endpoint_xfer_bulk(&ep->desc)
184                     || usb_endpoint_xfer_control(&ep->desc))
185                         asl_qset_delete(whc, qset);
186                 else
187                         pzl_qset_delete(whc, qset);
188         }
189 }
190
191 static struct hc_driver whc_hc_driver = {
192         .description = "whci-hcd",
193         .product_desc = "Wireless host controller",
194         .hcd_priv_size = sizeof(struct whc) - sizeof(struct usb_hcd),
195         .irq = whc_int_handler,
196         .flags = HCD_USB2,
197
198         .reset = whc_reset,
199         .start = whc_start,
200         .stop = whc_stop,
201         .get_frame_number = whc_get_frame_number,
202         .urb_enqueue = whc_urb_enqueue,
203         .urb_dequeue = whc_urb_dequeue,
204         .endpoint_disable = whc_endpoint_disable,
205
206         .hub_status_data = wusbhc_rh_status_data,
207         .hub_control = wusbhc_rh_control,
208         .bus_suspend = wusbhc_rh_suspend,
209         .bus_resume = wusbhc_rh_resume,
210         .start_port_reset = wusbhc_rh_start_port_reset,
211 };
212
213 static int whc_probe(struct umc_dev *umc)
214 {
215         int ret = -ENOMEM;
216         struct usb_hcd *usb_hcd;
217         struct wusbhc *wusbhc = NULL;
218         struct whc *whc = NULL;
219         struct device *dev = &umc->dev;
220
221         usb_hcd = usb_create_hcd(&whc_hc_driver, dev, "whci");
222         if (usb_hcd == NULL) {
223                 dev_err(dev, "unable to create hcd\n");
224                 goto error;
225         }
226
227         usb_hcd->wireless = 1;
228
229         wusbhc = usb_hcd_to_wusbhc(usb_hcd);
230         whc = wusbhc_to_whc(wusbhc);
231         whc->umc = umc;
232
233         ret = whc_init(whc);
234         if (ret)
235                 goto error;
236
237         wusbhc->dev = dev;
238         wusbhc->uwb_rc = uwb_rc_get_by_grandpa(umc->dev.parent);
239         if (!wusbhc->uwb_rc) {
240                 ret = -ENODEV;
241                 dev_err(dev, "cannot get radio controller\n");
242                 goto error;
243         }
244
245         if (whc->n_devices > USB_MAXCHILDREN) {
246                 dev_warn(dev, "USB_MAXCHILDREN too low for WUSB adapter (%u ports)\n",
247                          whc->n_devices);
248                 wusbhc->ports_max = USB_MAXCHILDREN;
249         } else
250                 wusbhc->ports_max = whc->n_devices;
251         wusbhc->mmcies_max      = whc->n_mmc_ies;
252         wusbhc->start           = whc_wusbhc_start;
253         wusbhc->stop            = whc_wusbhc_stop;
254         wusbhc->mmcie_add       = whc_mmcie_add;
255         wusbhc->mmcie_rm        = whc_mmcie_rm;
256         wusbhc->dev_info_set    = whc_dev_info_set;
257         wusbhc->bwa_set         = whc_bwa_set;
258         wusbhc->set_num_dnts    = whc_set_num_dnts;
259         wusbhc->set_ptk         = whc_set_ptk;
260         wusbhc->set_gtk         = whc_set_gtk;
261
262         ret = wusbhc_create(wusbhc);
263         if (ret)
264                 goto error_wusbhc_create;
265
266         ret = usb_add_hcd(usb_hcd, whc->umc->irq, IRQF_SHARED);
267         if (ret) {
268                 dev_err(dev, "cannot add HCD: %d\n", ret);
269                 goto error_usb_add_hcd;
270         }
271
272         ret = wusbhc_b_create(wusbhc);
273         if (ret) {
274                 dev_err(dev, "WUSBHC phase B setup failed: %d\n", ret);
275                 goto error_wusbhc_b_create;
276         }
277
278         return 0;
279
280 error_wusbhc_b_create:
281         usb_remove_hcd(usb_hcd);
282 error_usb_add_hcd:
283         wusbhc_destroy(wusbhc);
284 error_wusbhc_create:
285         uwb_rc_put(wusbhc->uwb_rc);
286 error:
287         whc_clean_up(whc);
288         if (usb_hcd)
289                 usb_put_hcd(usb_hcd);
290         return ret;
291 }
292
293
294 static void whc_remove(struct umc_dev *umc)
295 {
296         struct usb_hcd *usb_hcd = dev_get_drvdata(&umc->dev);
297         struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
298         struct whc *whc = wusbhc_to_whc(wusbhc);
299
300         if (usb_hcd) {
301                 wusbhc_b_destroy(wusbhc);
302                 usb_remove_hcd(usb_hcd);
303                 wusbhc_destroy(wusbhc);
304                 uwb_rc_put(wusbhc->uwb_rc);
305                 whc_clean_up(whc);
306                 usb_put_hcd(usb_hcd);
307         }
308 }
309
310 static struct umc_driver whci_hc_driver = {
311         .name =         "whci-hcd",
312         .cap_id =       UMC_CAP_ID_WHCI_WUSB_HC,
313         .probe =        whc_probe,
314         .remove =       whc_remove,
315 };
316
317 static int __init whci_hc_driver_init(void)
318 {
319         return umc_driver_register(&whci_hc_driver);
320 }
321 module_init(whci_hc_driver_init);
322
323 static void __exit whci_hc_driver_exit(void)
324 {
325         umc_driver_unregister(&whci_hc_driver);
326 }
327 module_exit(whci_hc_driver_exit);
328
329 /* PCI device ID's that we handle (so it gets loaded) */
330 static struct pci_device_id whci_hcd_id_table[] = {
331         { PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI, ~0) },
332         { /* empty last entry */ }
333 };
334 MODULE_DEVICE_TABLE(pci, whci_hcd_id_table);
335
336 MODULE_DESCRIPTION("WHCI Wireless USB host controller driver");
337 MODULE_AUTHOR("Cambridge Silicon Radio Ltd.");
338 MODULE_LICENSE("GPL");