Inaky Perez-Gonzalez | df36542 | 2008-09-17 16:34:29 +0100 | [diff] [blame] | 1 | /* |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Paul Gortmaker | 6eb0de8 | 2011-07-03 16:09:31 -0400 | [diff] [blame] | 26 | #include <linux/module.h> |
Inaky Perez-Gonzalez | df36542 | 2008-09-17 16:34:29 +0100 | [diff] [blame] | 27 | #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 Pugliese | f07ddb9 | 2013-10-23 14:44:28 -0500 | [diff] [blame] | 36 | int wa_create(struct wahc *wa, struct usb_interface *iface, |
| 37 | kernel_ulong_t quirks) |
Inaky Perez-Gonzalez | df36542 | 2008-09-17 16:34:29 +0100 | [diff] [blame] | 38 | { |
| 39 | int result; |
| 40 | struct device *dev = &iface->dev; |
| 41 | |
Johan Hovold | 46aeeb2 | 2017-03-13 13:47:51 +0100 | [diff] [blame] | 42 | if (iface->cur_altsetting->desc.bNumEndpoints < 3) |
| 43 | return -ENODEV; |
| 44 | |
Inaky Perez-Gonzalez | df36542 | 2008-09-17 16:34:29 +0100 | [diff] [blame] | 45 | result = wa_rpipes_create(wa); |
| 46 | if (result < 0) |
| 47 | goto error_rpipes_create; |
Thomas Pugliese | f07ddb9 | 2013-10-23 14:44:28 -0500 | [diff] [blame] | 48 | wa->quirks = quirks; |
Inaky Perez-Gonzalez | df36542 | 2008-09-17 16:34:29 +0100 | [diff] [blame] | 49 | /* Fill up Data Transfer EP pointers */ |
| 50 | wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc; |
| 51 | wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc; |
Thomas Pugliese | 0367eef | 2013-09-26 10:49:41 -0500 | [diff] [blame] | 52 | wa->dti_buf_size = usb_endpoint_maxp(wa->dti_epd); |
| 53 | wa->dti_buf = kmalloc(wa->dti_buf_size, GFP_KERNEL); |
| 54 | if (wa->dti_buf == NULL) { |
Julia Lawall | fd4d72c | 2012-08-14 08:47:36 +0200 | [diff] [blame] | 55 | result = -ENOMEM; |
Thomas Pugliese | 0367eef | 2013-09-26 10:49:41 -0500 | [diff] [blame] | 56 | goto error_dti_buf_alloc; |
Julia Lawall | fd4d72c | 2012-08-14 08:47:36 +0200 | [diff] [blame] | 57 | } |
Inaky Perez-Gonzalez | df36542 | 2008-09-17 16:34:29 +0100 | [diff] [blame] | 58 | result = wa_nep_create(wa, iface); |
| 59 | if (result < 0) { |
| 60 | dev_err(dev, "WA-CDS: can't initialize notif endpoint: %d\n", |
| 61 | result); |
| 62 | goto error_nep_create; |
| 63 | } |
| 64 | return 0; |
| 65 | |
| 66 | error_nep_create: |
Thomas Pugliese | 0367eef | 2013-09-26 10:49:41 -0500 | [diff] [blame] | 67 | kfree(wa->dti_buf); |
| 68 | error_dti_buf_alloc: |
Inaky Perez-Gonzalez | df36542 | 2008-09-17 16:34:29 +0100 | [diff] [blame] | 69 | wa_rpipes_destroy(wa); |
| 70 | error_rpipes_create: |
| 71 | return result; |
| 72 | } |
| 73 | EXPORT_SYMBOL_GPL(wa_create); |
| 74 | |
| 75 | |
| 76 | void __wa_destroy(struct wahc *wa) |
| 77 | { |
| 78 | if (wa->dti_urb) { |
| 79 | usb_kill_urb(wa->dti_urb); |
| 80 | usb_put_urb(wa->dti_urb); |
Inaky Perez-Gonzalez | df36542 | 2008-09-17 16:34:29 +0100 | [diff] [blame] | 81 | } |
Thomas Pugliese | 0367eef | 2013-09-26 10:49:41 -0500 | [diff] [blame] | 82 | kfree(wa->dti_buf); |
Inaky Perez-Gonzalez | df36542 | 2008-09-17 16:34:29 +0100 | [diff] [blame] | 83 | wa_nep_destroy(wa); |
| 84 | wa_rpipes_destroy(wa); |
| 85 | } |
| 86 | EXPORT_SYMBOL_GPL(__wa_destroy); |
| 87 | |
| 88 | /** |
| 89 | * wa_reset_all - reset the WA device |
| 90 | * @wa: the WA to be reset |
| 91 | * |
| 92 | * For HWAs the radio controller and all other PALs are also reset. |
| 93 | */ |
| 94 | void wa_reset_all(struct wahc *wa) |
| 95 | { |
| 96 | /* FIXME: assuming HWA. */ |
| 97 | wusbhc_reset_all(wa->wusb); |
| 98 | } |
| 99 | |
| 100 | MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); |
| 101 | MODULE_DESCRIPTION("Wireless USB Wire Adapter core"); |
| 102 | MODULE_LICENSE("GPL"); |