Antti Palosaari | 12042b0 | 2012-06-20 23:09:41 -0300 | [diff] [blame] | 1 | /* |
| 2 | * DVB USB framework |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 3 | * |
Antti Palosaari | 12042b0 | 2012-06-20 23:09:41 -0300 | [diff] [blame] | 4 | * Copyright (C) 2004-6 Patrick Boettcher <patrick.boettcher@desy.de> |
| 5 | * Copyright (C) 2012 Antti Palosaari <crope@iki.fi> |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 6 | * |
Antti Palosaari | 12042b0 | 2012-06-20 23:09:41 -0300 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 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 along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 20 | */ |
Antti Palosaari | 12042b0 | 2012-06-20 23:09:41 -0300 | [diff] [blame] | 21 | |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 22 | #include "dvb_usb_common.h" |
| 23 | |
| 24 | int dvb_usbv2_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf, |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 25 | u16 rlen) |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 26 | { |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 27 | int ret, actual_length; |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 28 | |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 29 | if (!d || !wbuf || !wlen || !d->props->generic_bulk_ctrl_endpoint || |
| 30 | !d->props->generic_bulk_ctrl_endpoint_response) { |
Antti Palosaari | d10d1b9 | 2012-06-26 22:44:00 -0300 | [diff] [blame] | 31 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, -EINVAL); |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 32 | return -EINVAL; |
| 33 | } |
| 34 | |
Antti Palosaari | 4e60d95 | 2012-05-24 14:44:21 -0300 | [diff] [blame] | 35 | ret = mutex_lock_interruptible(&d->usb_mutex); |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 36 | if (ret < 0) |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 37 | return ret; |
| 38 | |
Antti Palosaari | 65d9bc9 | 2012-08-07 18:56:36 -0300 | [diff] [blame] | 39 | dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, wlen, wbuf); |
| 40 | |
Antti Palosaari | 4e60d95 | 2012-05-24 14:44:21 -0300 | [diff] [blame] | 41 | ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev, |
Antti Palosaari | f093c38 | 2012-06-12 16:25:01 -0300 | [diff] [blame] | 42 | d->props->generic_bulk_ctrl_endpoint), wbuf, wlen, |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 43 | &actual_length, 2000); |
| 44 | if (ret < 0) |
Antti Palosaari | d10d1b9 | 2012-06-26 22:44:00 -0300 | [diff] [blame] | 45 | dev_err(&d->udev->dev, "%s: usb_bulk_msg() failed=%d\n", |
| 46 | KBUILD_MODNAME, ret); |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 47 | else |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 48 | ret = actual_length != wlen ? -EIO : 0; |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 49 | |
| 50 | /* an answer is expected, and no error before */ |
| 51 | if (!ret && rbuf && rlen) { |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 52 | if (d->props->generic_bulk_ctrl_delay) |
| 53 | usleep_range(d->props->generic_bulk_ctrl_delay, |
| 54 | d->props->generic_bulk_ctrl_delay |
| 55 | + 20000); |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 56 | |
Antti Palosaari | 4e60d95 | 2012-05-24 14:44:21 -0300 | [diff] [blame] | 57 | ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev, |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 58 | d->props->generic_bulk_ctrl_endpoint_response), |
| 59 | rbuf, rlen, &actual_length, 2000); |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 60 | if (ret) |
Antti Palosaari | d10d1b9 | 2012-06-26 22:44:00 -0300 | [diff] [blame] | 61 | dev_err(&d->udev->dev, "%s: 2nd usb_bulk_msg() " \ |
| 62 | "failed=%d\n", KBUILD_MODNAME, ret); |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 63 | |
Antti Palosaari | 65d9bc9 | 2012-08-07 18:56:36 -0300 | [diff] [blame] | 64 | dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__, |
| 65 | actual_length, rbuf); |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | mutex_unlock(&d->usb_mutex); |
| 69 | return ret; |
| 70 | } |
| 71 | EXPORT_SYMBOL(dvb_usbv2_generic_rw); |
| 72 | |
| 73 | int dvb_usbv2_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len) |
| 74 | { |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 75 | return dvb_usbv2_generic_rw(d, buf, len, NULL, 0); |
Antti Palosaari | c79b339 | 2012-05-23 10:06:09 -0300 | [diff] [blame] | 76 | } |
| 77 | EXPORT_SYMBOL(dvb_usbv2_generic_write); |