blob: 5716662b483451f4d3a5fb6204091a6285f349e2 [file] [log] [blame]
Antti Palosaari12042b02012-06-20 23:09:41 -03001/*
2 * DVB USB framework
Antti Palosaaric79b3392012-05-23 10:06:09 -03003 *
Antti Palosaari12042b02012-06-20 23:09:41 -03004 * Copyright (C) 2004-6 Patrick Boettcher <patrick.boettcher@desy.de>
5 * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
Antti Palosaaric79b3392012-05-23 10:06:09 -03006 *
Antti Palosaari12042b02012-06-20 23:09:41 -03007 * 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 Palosaaric79b3392012-05-23 10:06:09 -030020 */
Antti Palosaari12042b02012-06-20 23:09:41 -030021
Antti Palosaaric79b3392012-05-23 10:06:09 -030022#include "dvb_usb_common.h"
23
24int dvb_usbv2_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
Antti Palosaari1162c7b2012-06-20 20:27:42 -030025 u16 rlen)
Antti Palosaaric79b3392012-05-23 10:06:09 -030026{
Antti Palosaari1162c7b2012-06-20 20:27:42 -030027 int ret, actual_length;
Antti Palosaaric79b3392012-05-23 10:06:09 -030028
Antti Palosaari1162c7b2012-06-20 20:27:42 -030029 if (!d || !wbuf || !wlen || !d->props->generic_bulk_ctrl_endpoint ||
30 !d->props->generic_bulk_ctrl_endpoint_response) {
Antti Palosaarid10d1b92012-06-26 22:44:00 -030031 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, -EINVAL);
Antti Palosaaric79b3392012-05-23 10:06:09 -030032 return -EINVAL;
33 }
34
Antti Palosaari41269382012-11-07 23:52:52 +010035 mutex_lock(&d->usb_mutex);
Antti Palosaaric79b3392012-05-23 10:06:09 -030036
Antti Palosaari65d9bc92012-08-07 18:56:36 -030037 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, wlen, wbuf);
38
Antti Palosaari4e60d952012-05-24 14:44:21 -030039 ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev,
Antti Palosaarif093c382012-06-12 16:25:01 -030040 d->props->generic_bulk_ctrl_endpoint), wbuf, wlen,
Antti Palosaari1162c7b2012-06-20 20:27:42 -030041 &actual_length, 2000);
42 if (ret < 0)
Antti Palosaarid10d1b92012-06-26 22:44:00 -030043 dev_err(&d->udev->dev, "%s: usb_bulk_msg() failed=%d\n",
44 KBUILD_MODNAME, ret);
Antti Palosaaric79b3392012-05-23 10:06:09 -030045 else
Antti Palosaari1162c7b2012-06-20 20:27:42 -030046 ret = actual_length != wlen ? -EIO : 0;
Antti Palosaaric79b3392012-05-23 10:06:09 -030047
48 /* an answer is expected, and no error before */
49 if (!ret && rbuf && rlen) {
Antti Palosaari1162c7b2012-06-20 20:27:42 -030050 if (d->props->generic_bulk_ctrl_delay)
51 usleep_range(d->props->generic_bulk_ctrl_delay,
52 d->props->generic_bulk_ctrl_delay
53 + 20000);
Antti Palosaaric79b3392012-05-23 10:06:09 -030054
Antti Palosaari4e60d952012-05-24 14:44:21 -030055 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
Antti Palosaari1162c7b2012-06-20 20:27:42 -030056 d->props->generic_bulk_ctrl_endpoint_response),
57 rbuf, rlen, &actual_length, 2000);
Antti Palosaaric79b3392012-05-23 10:06:09 -030058 if (ret)
Antti Palosaarid10d1b92012-06-26 22:44:00 -030059 dev_err(&d->udev->dev, "%s: 2nd usb_bulk_msg() " \
60 "failed=%d\n", KBUILD_MODNAME, ret);
Antti Palosaari1162c7b2012-06-20 20:27:42 -030061
Antti Palosaari65d9bc92012-08-07 18:56:36 -030062 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
63 actual_length, rbuf);
Antti Palosaaric79b3392012-05-23 10:06:09 -030064 }
65
66 mutex_unlock(&d->usb_mutex);
67 return ret;
68}
69EXPORT_SYMBOL(dvb_usbv2_generic_rw);
70
71int dvb_usbv2_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
72{
Antti Palosaari1162c7b2012-06-20 20:27:42 -030073 return dvb_usbv2_generic_rw(d, buf, len, NULL, 0);
Antti Palosaaric79b3392012-05-23 10:06:09 -030074}
75EXPORT_SYMBOL(dvb_usbv2_generic_write);