blob: 368360f9a93ae1283780c3b30e230c6efd630b38 [file] [log] [blame]
Inaky Perez-Gonzalezdf365422008-09-17 16:34:29 +01001/*
2 * Wire Adapter Host Controller Driver
3 * Common items to HWA and DWA based HCDs
4 *
5 * Copyright (C) 2005-2006 Intel Corporation
6 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 *
22 *
23 * FIXME: docs
24 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Paul Gortmaker6eb0de82011-07-03 16:09:31 -040026#include <linux/module.h>
Inaky Perez-Gonzalezdf365422008-09-17 16:34:29 +010027#include "wusbhc.h"
28#include "wa-hc.h"
29
30/**
31 * Assumes
32 *
33 * wa->usb_dev and wa->usb_iface initialized and refcounted,
34 * wa->wa_descr initialized.
35 */
Thomas Pugliesef07ddb92013-10-23 14:44:28 -050036int wa_create(struct wahc *wa, struct usb_interface *iface,
37 kernel_ulong_t quirks)
Inaky Perez-Gonzalezdf365422008-09-17 16:34:29 +010038{
39 int result;
40 struct device *dev = &iface->dev;
41
42 result = wa_rpipes_create(wa);
43 if (result < 0)
44 goto error_rpipes_create;
Thomas Pugliesef07ddb92013-10-23 14:44:28 -050045 wa->quirks = quirks;
Inaky Perez-Gonzalezdf365422008-09-17 16:34:29 +010046 /* Fill up Data Transfer EP pointers */
47 wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc;
48 wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc;
Thomas Pugliese0367eef2013-09-26 10:49:41 -050049 wa->dti_buf_size = usb_endpoint_maxp(wa->dti_epd);
50 wa->dti_buf = kmalloc(wa->dti_buf_size, GFP_KERNEL);
51 if (wa->dti_buf == NULL) {
Julia Lawallfd4d72c2012-08-14 08:47:36 +020052 result = -ENOMEM;
Thomas Pugliese0367eef2013-09-26 10:49:41 -050053 goto error_dti_buf_alloc;
Julia Lawallfd4d72c2012-08-14 08:47:36 +020054 }
Inaky Perez-Gonzalezdf365422008-09-17 16:34:29 +010055 result = wa_nep_create(wa, iface);
56 if (result < 0) {
57 dev_err(dev, "WA-CDS: can't initialize notif endpoint: %d\n",
58 result);
59 goto error_nep_create;
60 }
61 return 0;
62
63error_nep_create:
Thomas Pugliese0367eef2013-09-26 10:49:41 -050064 kfree(wa->dti_buf);
65error_dti_buf_alloc:
Inaky Perez-Gonzalezdf365422008-09-17 16:34:29 +010066 wa_rpipes_destroy(wa);
67error_rpipes_create:
68 return result;
69}
70EXPORT_SYMBOL_GPL(wa_create);
71
72
73void __wa_destroy(struct wahc *wa)
74{
75 if (wa->dti_urb) {
76 usb_kill_urb(wa->dti_urb);
77 usb_put_urb(wa->dti_urb);
78 usb_kill_urb(wa->buf_in_urb);
79 usb_put_urb(wa->buf_in_urb);
80 }
Thomas Pugliese0367eef2013-09-26 10:49:41 -050081 kfree(wa->dti_buf);
Inaky Perez-Gonzalezdf365422008-09-17 16:34:29 +010082 wa_nep_destroy(wa);
83 wa_rpipes_destroy(wa);
84}
85EXPORT_SYMBOL_GPL(__wa_destroy);
86
87/**
88 * wa_reset_all - reset the WA device
89 * @wa: the WA to be reset
90 *
91 * For HWAs the radio controller and all other PALs are also reset.
92 */
93void wa_reset_all(struct wahc *wa)
94{
95 /* FIXME: assuming HWA. */
96 wusbhc_reset_all(wa->wusb);
97}
98
99MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>");
100MODULE_DESCRIPTION("Wireless USB Wire Adapter core");
101MODULE_LICENSE("GPL");