1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2004-6 Patrick Boettcher <patrick.boettcher@posteo.de>
6 * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
9 #include "dvb_usb_common.h"
11 static int dvb_usb_v2_generic_io(struct dvb_usb_device
*d
,
12 u8
*wbuf
, u16 wlen
, u8
*rbuf
, u16 rlen
)
14 int ret
, actual_length
;
16 if (!wbuf
|| !wlen
|| !d
->props
->generic_bulk_ctrl_endpoint
||
17 !d
->props
->generic_bulk_ctrl_endpoint_response
) {
18 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, -EINVAL
);
22 dev_dbg(&d
->udev
->dev
, "%s: >>> %*ph\n", __func__
, wlen
, wbuf
);
24 ret
= usb_bulk_msg(d
->udev
, usb_sndbulkpipe(d
->udev
,
25 d
->props
->generic_bulk_ctrl_endpoint
), wbuf
, wlen
,
26 &actual_length
, 2000);
28 dev_err(&d
->udev
->dev
, "%s: usb_bulk_msg() failed=%d\n",
32 if (actual_length
!= wlen
) {
33 dev_err(&d
->udev
->dev
, "%s: usb_bulk_msg() write length=%d, actual=%d\n",
34 KBUILD_MODNAME
, wlen
, actual_length
);
38 /* an answer is expected */
40 if (d
->props
->generic_bulk_ctrl_delay
)
41 usleep_range(d
->props
->generic_bulk_ctrl_delay
,
42 d
->props
->generic_bulk_ctrl_delay
45 ret
= usb_bulk_msg(d
->udev
, usb_rcvbulkpipe(d
->udev
,
46 d
->props
->generic_bulk_ctrl_endpoint_response
),
47 rbuf
, rlen
, &actual_length
, 2000);
49 dev_err(&d
->udev
->dev
,
50 "%s: 2nd usb_bulk_msg() failed=%d\n",
53 dev_dbg(&d
->udev
->dev
, "%s: <<< %*ph\n", __func__
,
60 int dvb_usbv2_generic_rw(struct dvb_usb_device
*d
,
61 u8
*wbuf
, u16 wlen
, u8
*rbuf
, u16 rlen
)
65 mutex_lock(&d
->usb_mutex
);
66 ret
= dvb_usb_v2_generic_io(d
, wbuf
, wlen
, rbuf
, rlen
);
67 mutex_unlock(&d
->usb_mutex
);
71 EXPORT_SYMBOL(dvb_usbv2_generic_rw
);
73 int dvb_usbv2_generic_write(struct dvb_usb_device
*d
, u8
*buf
, u16 len
)
77 mutex_lock(&d
->usb_mutex
);
78 ret
= dvb_usb_v2_generic_io(d
, buf
, len
, NULL
, 0);
79 mutex_unlock(&d
->usb_mutex
);
83 EXPORT_SYMBOL(dvb_usbv2_generic_write
);
85 int dvb_usbv2_generic_rw_locked(struct dvb_usb_device
*d
,
86 u8
*wbuf
, u16 wlen
, u8
*rbuf
, u16 rlen
)
88 return dvb_usb_v2_generic_io(d
, wbuf
, wlen
, rbuf
, rlen
);
90 EXPORT_SYMBOL(dvb_usbv2_generic_rw_locked
);
92 int dvb_usbv2_generic_write_locked(struct dvb_usb_device
*d
, u8
*buf
, u16 len
)
94 return dvb_usb_v2_generic_io(d
, buf
, len
, NULL
, 0);
96 EXPORT_SYMBOL(dvb_usbv2_generic_write_locked
);