xref: /openbmc/linux/drivers/media/usb/dvb-usb/dvb-usb-init.c (revision 1760371b277718062211fc7eb6f3042c5051c1a5)
1a10e763bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2786baecfSMauro Carvalho Chehab /*
3786baecfSMauro Carvalho Chehab  * DVB USB library - provides a generic interface for a DVB USB device driver.
4786baecfSMauro Carvalho Chehab  *
5786baecfSMauro Carvalho Chehab  * dvb-usb-init.c
6786baecfSMauro Carvalho Chehab  *
799e44da7SPatrick Boettcher  * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
8786baecfSMauro Carvalho Chehab  *
9577a7ad3SMauro Carvalho Chehab  * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
10786baecfSMauro Carvalho Chehab  */
11786baecfSMauro Carvalho Chehab #include "dvb-usb-common.h"
12786baecfSMauro Carvalho Chehab 
13786baecfSMauro Carvalho Chehab /* debug */
14786baecfSMauro Carvalho Chehab int dvb_usb_debug;
15786baecfSMauro Carvalho Chehab module_param_named(debug, dvb_usb_debug, int, 0644);
16786baecfSMauro Carvalho Chehab MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64,mem=128,uxfer=256  (or-able))." DVB_USB_DEBUG_STATUS);
17786baecfSMauro Carvalho Chehab 
18786baecfSMauro Carvalho Chehab int dvb_usb_disable_rc_polling;
19786baecfSMauro Carvalho Chehab module_param_named(disable_rc_polling, dvb_usb_disable_rc_polling, int, 0644);
20786baecfSMauro Carvalho Chehab MODULE_PARM_DESC(disable_rc_polling, "disable remote control polling (default: 0).");
21786baecfSMauro Carvalho Chehab 
22786baecfSMauro Carvalho Chehab static int dvb_usb_force_pid_filter_usage;
23786baecfSMauro Carvalho Chehab module_param_named(force_pid_filter_usage, dvb_usb_force_pid_filter_usage, int, 0444);
24786baecfSMauro Carvalho Chehab MODULE_PARM_DESC(force_pid_filter_usage, "force all dvb-usb-devices to use a PID filter, if any (default: 0).");
25786baecfSMauro Carvalho Chehab 
dvb_usb_adapter_init(struct dvb_usb_device * d,short * adapter_nrs)26786baecfSMauro Carvalho Chehab static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
27786baecfSMauro Carvalho Chehab {
28786baecfSMauro Carvalho Chehab 	struct dvb_usb_adapter *adap;
29786baecfSMauro Carvalho Chehab 	int ret, n, o;
30786baecfSMauro Carvalho Chehab 
31786baecfSMauro Carvalho Chehab 	for (n = 0; n < d->props.num_adapters; n++) {
32786baecfSMauro Carvalho Chehab 		adap = &d->adapter[n];
33786baecfSMauro Carvalho Chehab 		adap->dev = d;
34786baecfSMauro Carvalho Chehab 		adap->id  = n;
35786baecfSMauro Carvalho Chehab 
36786baecfSMauro Carvalho Chehab 		memcpy(&adap->props, &d->props.adapter[n], sizeof(struct dvb_usb_adapter_properties));
37786baecfSMauro Carvalho Chehab 
38786baecfSMauro Carvalho Chehab 		for (o = 0; o < adap->props.num_frontends; o++) {
39786baecfSMauro Carvalho Chehab 			struct dvb_usb_adapter_fe_properties *props = &adap->props.fe[o];
40786baecfSMauro Carvalho Chehab 			/* speed - when running at FULL speed we need a HW PID filter */
41786baecfSMauro Carvalho Chehab 			if (d->udev->speed == USB_SPEED_FULL && !(props->caps & DVB_USB_ADAP_HAS_PID_FILTER)) {
42786baecfSMauro Carvalho Chehab 				err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a hardware PID filter)");
43786baecfSMauro Carvalho Chehab 				return -ENODEV;
44786baecfSMauro Carvalho Chehab 			}
45786baecfSMauro Carvalho Chehab 
46786baecfSMauro Carvalho Chehab 			if ((d->udev->speed == USB_SPEED_FULL && props->caps & DVB_USB_ADAP_HAS_PID_FILTER) ||
47786baecfSMauro Carvalho Chehab 				(props->caps & DVB_USB_ADAP_NEED_PID_FILTERING)) {
48786baecfSMauro Carvalho Chehab 				info("will use the device's hardware PID filter (table count: %d).", props->pid_filter_count);
49786baecfSMauro Carvalho Chehab 				adap->fe_adap[o].pid_filtering  = 1;
50786baecfSMauro Carvalho Chehab 				adap->fe_adap[o].max_feed_count = props->pid_filter_count;
51786baecfSMauro Carvalho Chehab 			} else {
52786baecfSMauro Carvalho Chehab 				info("will pass the complete MPEG2 transport stream to the software demuxer.");
53786baecfSMauro Carvalho Chehab 				adap->fe_adap[o].pid_filtering  = 0;
54786baecfSMauro Carvalho Chehab 				adap->fe_adap[o].max_feed_count = 255;
55786baecfSMauro Carvalho Chehab 			}
56786baecfSMauro Carvalho Chehab 
57786baecfSMauro Carvalho Chehab 			if (!adap->fe_adap[o].pid_filtering &&
58786baecfSMauro Carvalho Chehab 				dvb_usb_force_pid_filter_usage &&
59786baecfSMauro Carvalho Chehab 				props->caps & DVB_USB_ADAP_HAS_PID_FILTER) {
60786baecfSMauro Carvalho Chehab 				info("pid filter enabled by module option.");
61786baecfSMauro Carvalho Chehab 				adap->fe_adap[o].pid_filtering  = 1;
62786baecfSMauro Carvalho Chehab 				adap->fe_adap[o].max_feed_count = props->pid_filter_count;
63786baecfSMauro Carvalho Chehab 			}
64786baecfSMauro Carvalho Chehab 
65786baecfSMauro Carvalho Chehab 			if (props->size_of_priv > 0) {
66786baecfSMauro Carvalho Chehab 				adap->fe_adap[o].priv = kzalloc(props->size_of_priv, GFP_KERNEL);
67786baecfSMauro Carvalho Chehab 				if (adap->fe_adap[o].priv == NULL) {
68786baecfSMauro Carvalho Chehab 					err("no memory for priv for adapter %d fe %d.", n, o);
69786baecfSMauro Carvalho Chehab 					return -ENOMEM;
70786baecfSMauro Carvalho Chehab 				}
71786baecfSMauro Carvalho Chehab 			}
72786baecfSMauro Carvalho Chehab 		}
73786baecfSMauro Carvalho Chehab 
74786baecfSMauro Carvalho Chehab 		if (adap->props.size_of_priv > 0) {
75786baecfSMauro Carvalho Chehab 			adap->priv = kzalloc(adap->props.size_of_priv, GFP_KERNEL);
76786baecfSMauro Carvalho Chehab 			if (adap->priv == NULL) {
77786baecfSMauro Carvalho Chehab 				err("no memory for priv for adapter %d.", n);
78786baecfSMauro Carvalho Chehab 				return -ENOMEM;
79786baecfSMauro Carvalho Chehab 			}
80786baecfSMauro Carvalho Chehab 		}
81786baecfSMauro Carvalho Chehab 
82b7cd0da9SPavel Skripkin 		ret = dvb_usb_adapter_stream_init(adap);
83b7cd0da9SPavel Skripkin 		if (ret)
8494d90fb0SMazin Al Haddad 			goto stream_init_err;
85b7cd0da9SPavel Skripkin 
86b7cd0da9SPavel Skripkin 		ret = dvb_usb_adapter_dvb_init(adap, adapter_nrs);
87b7cd0da9SPavel Skripkin 		if (ret)
88b7cd0da9SPavel Skripkin 			goto dvb_init_err;
89b7cd0da9SPavel Skripkin 
90b7cd0da9SPavel Skripkin 		ret = dvb_usb_adapter_frontend_init(adap);
91b7cd0da9SPavel Skripkin 		if (ret)
92b7cd0da9SPavel Skripkin 			goto frontend_init_err;
93786baecfSMauro Carvalho Chehab 
94786baecfSMauro Carvalho Chehab 		/* use exclusive FE lock if there is multiple shared FEs */
95e704b44bSRobert Schlabbach 		if (adap->fe_adap[1].fe && adap->dvb_adap.mfe_shared < 1)
96786baecfSMauro Carvalho Chehab 			adap->dvb_adap.mfe_shared = 1;
97786baecfSMauro Carvalho Chehab 
98786baecfSMauro Carvalho Chehab 		d->num_adapters_initialized++;
99786baecfSMauro Carvalho Chehab 		d->state |= DVB_USB_STATE_DVB;
100786baecfSMauro Carvalho Chehab 	}
101786baecfSMauro Carvalho Chehab 
102786baecfSMauro Carvalho Chehab 	/*
103786baecfSMauro Carvalho Chehab 	 * when reloading the driver w/o replugging the device
1043e4d8f48SMauro Carvalho Chehab 	 * sometimes a timeout occurs, this helps
105786baecfSMauro Carvalho Chehab 	 */
106*fb6f5624SSean Young 	if (d->props.generic_bulk_ctrl_endpoint != 0) {
107*fb6f5624SSean Young 		usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
108*fb6f5624SSean Young 		usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
109*fb6f5624SSean Young 	}
110786baecfSMauro Carvalho Chehab 
111786baecfSMauro Carvalho Chehab 	return 0;
112b7cd0da9SPavel Skripkin 
113b7cd0da9SPavel Skripkin frontend_init_err:
114b7cd0da9SPavel Skripkin 	dvb_usb_adapter_dvb_exit(adap);
115b7cd0da9SPavel Skripkin dvb_init_err:
116b7cd0da9SPavel Skripkin 	dvb_usb_adapter_stream_exit(adap);
11794d90fb0SMazin Al Haddad stream_init_err:
11894d90fb0SMazin Al Haddad 	kfree(adap->priv);
119b7cd0da9SPavel Skripkin 	return ret;
120786baecfSMauro Carvalho Chehab }
121786baecfSMauro Carvalho Chehab 
dvb_usb_adapter_exit(struct dvb_usb_device * d)122786baecfSMauro Carvalho Chehab static int dvb_usb_adapter_exit(struct dvb_usb_device *d)
123786baecfSMauro Carvalho Chehab {
124786baecfSMauro Carvalho Chehab 	int n;
125786baecfSMauro Carvalho Chehab 
126786baecfSMauro Carvalho Chehab 	for (n = 0; n < d->num_adapters_initialized; n++) {
127786baecfSMauro Carvalho Chehab 		dvb_usb_adapter_frontend_exit(&d->adapter[n]);
128786baecfSMauro Carvalho Chehab 		dvb_usb_adapter_dvb_exit(&d->adapter[n]);
129786baecfSMauro Carvalho Chehab 		dvb_usb_adapter_stream_exit(&d->adapter[n]);
130786baecfSMauro Carvalho Chehab 		kfree(d->adapter[n].priv);
131786baecfSMauro Carvalho Chehab 	}
132786baecfSMauro Carvalho Chehab 	d->num_adapters_initialized = 0;
133786baecfSMauro Carvalho Chehab 	d->state &= ~DVB_USB_STATE_DVB;
134786baecfSMauro Carvalho Chehab 	return 0;
135786baecfSMauro Carvalho Chehab }
136786baecfSMauro Carvalho Chehab 
137786baecfSMauro Carvalho Chehab 
138786baecfSMauro Carvalho Chehab /* general initialization functions */
dvb_usb_exit(struct dvb_usb_device * d)139786baecfSMauro Carvalho Chehab static int dvb_usb_exit(struct dvb_usb_device *d)
140786baecfSMauro Carvalho Chehab {
141786baecfSMauro Carvalho Chehab 	deb_info("state before exiting everything: %x\n", d->state);
142786baecfSMauro Carvalho Chehab 	dvb_usb_remote_exit(d);
143786baecfSMauro Carvalho Chehab 	dvb_usb_adapter_exit(d);
144786baecfSMauro Carvalho Chehab 	dvb_usb_i2c_exit(d);
145786baecfSMauro Carvalho Chehab 	deb_info("state should be zero now: %x\n", d->state);
146786baecfSMauro Carvalho Chehab 	d->state = DVB_USB_STATE_INIT;
147d525e5c2SMaciej S. Szmigiero 
148d525e5c2SMaciej S. Szmigiero 	if (d->priv != NULL && d->props.priv_destroy != NULL)
149d525e5c2SMaciej S. Szmigiero 		d->props.priv_destroy(d);
150d525e5c2SMaciej S. Szmigiero 
151786baecfSMauro Carvalho Chehab 	kfree(d->priv);
152786baecfSMauro Carvalho Chehab 	kfree(d);
153786baecfSMauro Carvalho Chehab 	return 0;
154786baecfSMauro Carvalho Chehab }
155786baecfSMauro Carvalho Chehab 
dvb_usb_init(struct dvb_usb_device * d,short * adapter_nums)156786baecfSMauro Carvalho Chehab static int dvb_usb_init(struct dvb_usb_device *d, short *adapter_nums)
157786baecfSMauro Carvalho Chehab {
158786baecfSMauro Carvalho Chehab 	int ret = 0;
159786baecfSMauro Carvalho Chehab 
1607724325aSMauro Carvalho Chehab 	mutex_init(&d->data_mutex);
161786baecfSMauro Carvalho Chehab 	mutex_init(&d->usb_mutex);
162786baecfSMauro Carvalho Chehab 	mutex_init(&d->i2c_mutex);
163786baecfSMauro Carvalho Chehab 
164786baecfSMauro Carvalho Chehab 	d->state = DVB_USB_STATE_INIT;
165786baecfSMauro Carvalho Chehab 
166786baecfSMauro Carvalho Chehab 	if (d->props.size_of_priv > 0) {
167786baecfSMauro Carvalho Chehab 		d->priv = kzalloc(d->props.size_of_priv, GFP_KERNEL);
168786baecfSMauro Carvalho Chehab 		if (d->priv == NULL) {
169786baecfSMauro Carvalho Chehab 			err("no memory for priv in 'struct dvb_usb_device'");
170786baecfSMauro Carvalho Chehab 			return -ENOMEM;
171786baecfSMauro Carvalho Chehab 		}
172d525e5c2SMaciej S. Szmigiero 
173d525e5c2SMaciej S. Szmigiero 		if (d->props.priv_init != NULL) {
174d525e5c2SMaciej S. Szmigiero 			ret = d->props.priv_init(d);
17513a79f14STakashi Iwai 			if (ret != 0)
17613a79f14STakashi Iwai 				goto err_priv_init;
177d525e5c2SMaciej S. Szmigiero 		}
178786baecfSMauro Carvalho Chehab 	}
179786baecfSMauro Carvalho Chehab 
180786baecfSMauro Carvalho Chehab 	/* check the capabilities and set appropriate variables */
181786baecfSMauro Carvalho Chehab 	dvb_usb_device_power_ctrl(d, 1);
182786baecfSMauro Carvalho Chehab 
18313a79f14STakashi Iwai 	ret = dvb_usb_i2c_init(d);
18413a79f14STakashi Iwai 	if (ret)
18513a79f14STakashi Iwai 		goto err_i2c_init;
18613a79f14STakashi Iwai 	ret = dvb_usb_adapter_init(d, adapter_nums);
18713a79f14STakashi Iwai 	if (ret)
18813a79f14STakashi Iwai 		goto err_adapter_init;
189786baecfSMauro Carvalho Chehab 
190786baecfSMauro Carvalho Chehab 	if ((ret = dvb_usb_remote_init(d)))
191786baecfSMauro Carvalho Chehab 		err("could not initialize remote control.");
192786baecfSMauro Carvalho Chehab 
193786baecfSMauro Carvalho Chehab 	dvb_usb_device_power_ctrl(d, 0);
194786baecfSMauro Carvalho Chehab 
195786baecfSMauro Carvalho Chehab 	return 0;
19613a79f14STakashi Iwai 
19713a79f14STakashi Iwai err_adapter_init:
19813a79f14STakashi Iwai 	dvb_usb_adapter_exit(d);
19913a79f14STakashi Iwai 	dvb_usb_i2c_exit(d);
200131ae388SDongliang Mu err_i2c_init:
20113a79f14STakashi Iwai 	if (d->priv && d->props.priv_destroy)
20213a79f14STakashi Iwai 		d->props.priv_destroy(d);
20313a79f14STakashi Iwai err_priv_init:
20413a79f14STakashi Iwai 	kfree(d->priv);
20513a79f14STakashi Iwai 	d->priv = NULL;
20613a79f14STakashi Iwai 	return ret;
207786baecfSMauro Carvalho Chehab }
208786baecfSMauro Carvalho Chehab 
209786baecfSMauro Carvalho Chehab /* determine the name and the state of the just found USB device */
dvb_usb_find_device(struct usb_device * udev,const struct dvb_usb_device_properties * props,int * cold)210d27958dfSSean Young static const struct dvb_usb_device_description *dvb_usb_find_device(struct usb_device *udev, const struct dvb_usb_device_properties *props, int *cold)
211786baecfSMauro Carvalho Chehab {
212786baecfSMauro Carvalho Chehab 	int i, j;
213d27958dfSSean Young 	const struct dvb_usb_device_description *desc = NULL;
214786baecfSMauro Carvalho Chehab 
215786baecfSMauro Carvalho Chehab 	*cold = -1;
216786baecfSMauro Carvalho Chehab 
217786baecfSMauro Carvalho Chehab 	for (i = 0; i < props->num_device_descs; i++) {
218786baecfSMauro Carvalho Chehab 
219786baecfSMauro Carvalho Chehab 		for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].cold_ids[j] != NULL; j++) {
220786baecfSMauro Carvalho Chehab 			deb_info("check for cold %x %x\n", props->devices[i].cold_ids[j]->idVendor, props->devices[i].cold_ids[j]->idProduct);
221786baecfSMauro Carvalho Chehab 			if (props->devices[i].cold_ids[j]->idVendor  == le16_to_cpu(udev->descriptor.idVendor) &&
222786baecfSMauro Carvalho Chehab 				props->devices[i].cold_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
223786baecfSMauro Carvalho Chehab 				*cold = 1;
224786baecfSMauro Carvalho Chehab 				desc = &props->devices[i];
225786baecfSMauro Carvalho Chehab 				break;
226786baecfSMauro Carvalho Chehab 			}
227786baecfSMauro Carvalho Chehab 		}
228786baecfSMauro Carvalho Chehab 
229786baecfSMauro Carvalho Chehab 		if (desc != NULL)
230786baecfSMauro Carvalho Chehab 			break;
231786baecfSMauro Carvalho Chehab 
232786baecfSMauro Carvalho Chehab 		for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].warm_ids[j] != NULL; j++) {
233786baecfSMauro Carvalho Chehab 			deb_info("check for warm %x %x\n", props->devices[i].warm_ids[j]->idVendor, props->devices[i].warm_ids[j]->idProduct);
234786baecfSMauro Carvalho Chehab 			if (props->devices[i].warm_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) &&
235786baecfSMauro Carvalho Chehab 				props->devices[i].warm_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
236786baecfSMauro Carvalho Chehab 				*cold = 0;
237786baecfSMauro Carvalho Chehab 				desc = &props->devices[i];
238786baecfSMauro Carvalho Chehab 				break;
239786baecfSMauro Carvalho Chehab 			}
240786baecfSMauro Carvalho Chehab 		}
241786baecfSMauro Carvalho Chehab 	}
242786baecfSMauro Carvalho Chehab 
243786baecfSMauro Carvalho Chehab 	if (desc != NULL && props->identify_state != NULL)
244786baecfSMauro Carvalho Chehab 		props->identify_state(udev, props, &desc, cold);
245786baecfSMauro Carvalho Chehab 
246786baecfSMauro Carvalho Chehab 	return desc;
247786baecfSMauro Carvalho Chehab }
248786baecfSMauro Carvalho Chehab 
dvb_usb_device_power_ctrl(struct dvb_usb_device * d,int onoff)249786baecfSMauro Carvalho Chehab int dvb_usb_device_power_ctrl(struct dvb_usb_device *d, int onoff)
250786baecfSMauro Carvalho Chehab {
251786baecfSMauro Carvalho Chehab 	if (onoff)
252786baecfSMauro Carvalho Chehab 		d->powered++;
253786baecfSMauro Carvalho Chehab 	else
254786baecfSMauro Carvalho Chehab 		d->powered--;
255786baecfSMauro Carvalho Chehab 
256786baecfSMauro Carvalho Chehab 	if (d->powered == 0 || (onoff && d->powered == 1)) { /* when switching from 1 to 0 or from 0 to 1 */
257786baecfSMauro Carvalho Chehab 		deb_info("power control: %d\n", onoff);
258786baecfSMauro Carvalho Chehab 		if (d->props.power_ctrl)
259786baecfSMauro Carvalho Chehab 			return d->props.power_ctrl(d, onoff);
260786baecfSMauro Carvalho Chehab 	}
261786baecfSMauro Carvalho Chehab 	return 0;
262786baecfSMauro Carvalho Chehab }
263786baecfSMauro Carvalho Chehab 
264786baecfSMauro Carvalho Chehab /*
265786baecfSMauro Carvalho Chehab  * USB
266786baecfSMauro Carvalho Chehab  */
dvb_usb_device_init(struct usb_interface * intf,const struct dvb_usb_device_properties * props,struct module * owner,struct dvb_usb_device ** du,short * adapter_nums)267786baecfSMauro Carvalho Chehab int dvb_usb_device_init(struct usb_interface *intf,
268d27958dfSSean Young 			const struct dvb_usb_device_properties *props,
269786baecfSMauro Carvalho Chehab 			struct module *owner, struct dvb_usb_device **du,
270786baecfSMauro Carvalho Chehab 			short *adapter_nums)
271786baecfSMauro Carvalho Chehab {
272786baecfSMauro Carvalho Chehab 	struct usb_device *udev = interface_to_usbdev(intf);
273786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = NULL;
274d27958dfSSean Young 	const struct dvb_usb_device_description *desc = NULL;
275786baecfSMauro Carvalho Chehab 
276786baecfSMauro Carvalho Chehab 	int ret = -ENOMEM, cold = 0;
277786baecfSMauro Carvalho Chehab 
278786baecfSMauro Carvalho Chehab 	if (du != NULL)
279786baecfSMauro Carvalho Chehab 		*du = NULL;
280786baecfSMauro Carvalho Chehab 
281c4920678STakashi Iwai 	d = kzalloc(sizeof(*d), GFP_KERNEL);
282c4920678STakashi Iwai 	if (!d) {
283c4920678STakashi Iwai 		err("no memory for 'struct dvb_usb_device'");
284c4920678STakashi Iwai 		return -ENOMEM;
285c4920678STakashi Iwai 	}
286c4920678STakashi Iwai 
287c4920678STakashi Iwai 	memcpy(&d->props, props, sizeof(struct dvb_usb_device_properties));
288c4920678STakashi Iwai 
289c4920678STakashi Iwai 	desc = dvb_usb_find_device(udev, &d->props, &cold);
290c4920678STakashi Iwai 	if (!desc) {
291786baecfSMauro Carvalho Chehab 		deb_err("something went very wrong, device was not found in current device list - let's see what comes next.\n");
292c4920678STakashi Iwai 		ret = -ENODEV;
293c4920678STakashi Iwai 		goto error;
294786baecfSMauro Carvalho Chehab 	}
295786baecfSMauro Carvalho Chehab 
296786baecfSMauro Carvalho Chehab 	if (cold) {
297786baecfSMauro Carvalho Chehab 		info("found a '%s' in cold state, will try to load a firmware", desc->name);
298786baecfSMauro Carvalho Chehab 		ret = dvb_usb_download_firmware(udev, props);
299786baecfSMauro Carvalho Chehab 		if (!props->no_reconnect || ret != 0)
300c4920678STakashi Iwai 			goto error;
301786baecfSMauro Carvalho Chehab 	}
302786baecfSMauro Carvalho Chehab 
303786baecfSMauro Carvalho Chehab 	info("found a '%s' in warm state.", desc->name);
304786baecfSMauro Carvalho Chehab 	d->udev = udev;
305786baecfSMauro Carvalho Chehab 	d->desc = desc;
306786baecfSMauro Carvalho Chehab 	d->owner = owner;
307786baecfSMauro Carvalho Chehab 
308786baecfSMauro Carvalho Chehab 	usb_set_intfdata(intf, d);
309786baecfSMauro Carvalho Chehab 
31013a79f14STakashi Iwai 	ret = dvb_usb_init(d, adapter_nums);
31113a79f14STakashi Iwai 	if (ret) {
31213a79f14STakashi Iwai 		info("%s error while loading driver (%d)", desc->name, ret);
31313a79f14STakashi Iwai 		goto error;
31413a79f14STakashi Iwai 	}
31513a79f14STakashi Iwai 
31613a79f14STakashi Iwai 	if (du)
317786baecfSMauro Carvalho Chehab 		*du = d;
318786baecfSMauro Carvalho Chehab 
319786baecfSMauro Carvalho Chehab 	info("%s successfully initialized and connected.", desc->name);
32013a79f14STakashi Iwai 	return 0;
32113a79f14STakashi Iwai 
32213a79f14STakashi Iwai  error:
32313a79f14STakashi Iwai 	usb_set_intfdata(intf, NULL);
32413a79f14STakashi Iwai 	kfree(d);
325786baecfSMauro Carvalho Chehab 	return ret;
326786baecfSMauro Carvalho Chehab }
327786baecfSMauro Carvalho Chehab EXPORT_SYMBOL(dvb_usb_device_init);
328786baecfSMauro Carvalho Chehab 
dvb_usb_device_exit(struct usb_interface * intf)329786baecfSMauro Carvalho Chehab void dvb_usb_device_exit(struct usb_interface *intf)
330786baecfSMauro Carvalho Chehab {
331786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = usb_get_intfdata(intf);
3326cf97230SOliver Neukum 	const char *default_name = "generic DVB-USB module";
3336cf97230SOliver Neukum 	char name[40];
334786baecfSMauro Carvalho Chehab 
335786baecfSMauro Carvalho Chehab 	usb_set_intfdata(intf, NULL);
336786baecfSMauro Carvalho Chehab 	if (d != NULL && d->desc != NULL) {
3376cf97230SOliver Neukum 		strscpy(name, d->desc->name, sizeof(name));
338786baecfSMauro Carvalho Chehab 		dvb_usb_exit(d);
3396cf97230SOliver Neukum 	} else {
3406cf97230SOliver Neukum 		strscpy(name, default_name, sizeof(name));
341786baecfSMauro Carvalho Chehab 	}
342786baecfSMauro Carvalho Chehab 	info("%s successfully deinitialized and disconnected.", name);
343786baecfSMauro Carvalho Chehab 
344786baecfSMauro Carvalho Chehab }
345786baecfSMauro Carvalho Chehab EXPORT_SYMBOL(dvb_usb_device_exit);
346786baecfSMauro Carvalho Chehab 
347786baecfSMauro Carvalho Chehab MODULE_VERSION("1.0");
34899e44da7SPatrick Boettcher MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
349786baecfSMauro Carvalho Chehab MODULE_DESCRIPTION("A library module containing commonly used USB and DVB function USB DVB devices");
350786baecfSMauro Carvalho Chehab MODULE_LICENSE("GPL");
351