gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / media / usb / dvb-usb / dvb-usb-urb.c
blob2aabf90d869769144184465414d9da1cb3925352
1 // SPDX-License-Identifier: GPL-2.0
2 /* dvb-usb-urb.c is part of the DVB USB library.
4 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
5 * see dvb-usb-init.c for copyright information.
7 * This file keeps functions for initializing and handling the
8 * USB and URB stuff.
9 */
10 #include "dvb-usb-common.h"
12 int dvb_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
13 u16 rlen, int delay_ms)
15 int actlen = 0, ret = -ENOMEM;
17 if (!d || wbuf == NULL || wlen == 0)
18 return -EINVAL;
20 if (d->props.generic_bulk_ctrl_endpoint == 0) {
21 err("endpoint for generic control not specified.");
22 return -EINVAL;
25 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
26 return ret;
28 deb_xfer(">>> ");
29 debug_dump(wbuf,wlen,deb_xfer);
31 ret = usb_bulk_msg(d->udev,usb_sndbulkpipe(d->udev,
32 d->props.generic_bulk_ctrl_endpoint), wbuf,wlen,&actlen,
33 2000);
35 if (ret)
36 err("bulk message failed: %d (%d/%d)",ret,wlen,actlen);
37 else
38 ret = actlen != wlen ? -1 : 0;
40 /* an answer is expected, and no error before */
41 if (!ret && rbuf && rlen) {
42 if (delay_ms)
43 msleep(delay_ms);
45 ret = usb_bulk_msg(d->udev,usb_rcvbulkpipe(d->udev,
46 d->props.generic_bulk_ctrl_endpoint_response ?
47 d->props.generic_bulk_ctrl_endpoint_response :
48 d->props.generic_bulk_ctrl_endpoint),rbuf,rlen,&actlen,
49 2000);
51 if (ret)
52 err("recv bulk message failed: %d",ret);
53 else {
54 deb_xfer("<<< ");
55 debug_dump(rbuf,actlen,deb_xfer);
59 mutex_unlock(&d->usb_mutex);
60 return ret;
62 EXPORT_SYMBOL(dvb_usb_generic_rw);
64 int dvb_usb_generic_write(struct dvb_usb_device *d, u8 *buf, u16 len)
66 return dvb_usb_generic_rw(d,buf,len,NULL,0,0);
68 EXPORT_SYMBOL(dvb_usb_generic_write);
70 static void dvb_usb_data_complete(struct usb_data_stream *stream, u8 *buffer, size_t length)
72 struct dvb_usb_adapter *adap = stream->user_priv;
73 if (adap->feedcount > 0 && adap->state & DVB_USB_ADAP_STATE_DVB)
74 dvb_dmx_swfilter(&adap->demux, buffer, length);
77 static void dvb_usb_data_complete_204(struct usb_data_stream *stream, u8 *buffer, size_t length)
79 struct dvb_usb_adapter *adap = stream->user_priv;
80 if (adap->feedcount > 0 && adap->state & DVB_USB_ADAP_STATE_DVB)
81 dvb_dmx_swfilter_204(&adap->demux, buffer, length);
84 static void dvb_usb_data_complete_raw(struct usb_data_stream *stream,
85 u8 *buffer, size_t length)
87 struct dvb_usb_adapter *adap = stream->user_priv;
88 if (adap->feedcount > 0 && adap->state & DVB_USB_ADAP_STATE_DVB)
89 dvb_dmx_swfilter_raw(&adap->demux, buffer, length);
92 int dvb_usb_adapter_stream_init(struct dvb_usb_adapter *adap)
94 int i, ret = 0;
95 for (i = 0; i < adap->props.num_frontends; i++) {
97 adap->fe_adap[i].stream.udev = adap->dev->udev;
98 if (adap->props.fe[i].caps & DVB_USB_ADAP_RECEIVES_204_BYTE_TS)
99 adap->fe_adap[i].stream.complete =
100 dvb_usb_data_complete_204;
101 else
102 if (adap->props.fe[i].caps & DVB_USB_ADAP_RECEIVES_RAW_PAYLOAD)
103 adap->fe_adap[i].stream.complete =
104 dvb_usb_data_complete_raw;
105 else
106 adap->fe_adap[i].stream.complete = dvb_usb_data_complete;
107 adap->fe_adap[i].stream.user_priv = adap;
108 ret = usb_urb_init(&adap->fe_adap[i].stream,
109 &adap->props.fe[i].stream);
110 if (ret < 0)
111 break;
113 return ret;
116 int dvb_usb_adapter_stream_exit(struct dvb_usb_adapter *adap)
118 int i;
119 for (i = 0; i < adap->props.num_frontends; i++)
120 usb_urb_exit(&adap->fe_adap[i].stream);
121 return 0;