xref: /openbmc/linux/drivers/media/usb/dvb-usb/dvb-usb-init.c (revision 131ae388b88e3daf4cb0721ed4b4cb8bfc201465)
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 
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)
84786baecfSMauro Carvalho Chehab 			return ret;
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 */
95786baecfSMauro Carvalho Chehab 		if (adap->fe_adap[1].fe)
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 	 */
106786baecfSMauro Carvalho Chehab 	if (d->props.generic_bulk_ctrl_endpoint != 0) {
107786baecfSMauro Carvalho Chehab 		usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
108786baecfSMauro Carvalho Chehab 		usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
109786baecfSMauro Carvalho Chehab 	}
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);
117b7cd0da9SPavel Skripkin 	return ret;
118786baecfSMauro Carvalho Chehab }
119786baecfSMauro Carvalho Chehab 
120786baecfSMauro Carvalho Chehab static int dvb_usb_adapter_exit(struct dvb_usb_device *d)
121786baecfSMauro Carvalho Chehab {
122786baecfSMauro Carvalho Chehab 	int n;
123786baecfSMauro Carvalho Chehab 
124786baecfSMauro Carvalho Chehab 	for (n = 0; n < d->num_adapters_initialized; n++) {
125786baecfSMauro Carvalho Chehab 		dvb_usb_adapter_frontend_exit(&d->adapter[n]);
126786baecfSMauro Carvalho Chehab 		dvb_usb_adapter_dvb_exit(&d->adapter[n]);
127786baecfSMauro Carvalho Chehab 		dvb_usb_adapter_stream_exit(&d->adapter[n]);
128786baecfSMauro Carvalho Chehab 		kfree(d->adapter[n].priv);
129786baecfSMauro Carvalho Chehab 	}
130786baecfSMauro Carvalho Chehab 	d->num_adapters_initialized = 0;
131786baecfSMauro Carvalho Chehab 	d->state &= ~DVB_USB_STATE_DVB;
132786baecfSMauro Carvalho Chehab 	return 0;
133786baecfSMauro Carvalho Chehab }
134786baecfSMauro Carvalho Chehab 
135786baecfSMauro Carvalho Chehab 
136786baecfSMauro Carvalho Chehab /* general initialization functions */
137786baecfSMauro Carvalho Chehab static int dvb_usb_exit(struct dvb_usb_device *d)
138786baecfSMauro Carvalho Chehab {
139786baecfSMauro Carvalho Chehab 	deb_info("state before exiting everything: %x\n", d->state);
140786baecfSMauro Carvalho Chehab 	dvb_usb_remote_exit(d);
141786baecfSMauro Carvalho Chehab 	dvb_usb_adapter_exit(d);
142786baecfSMauro Carvalho Chehab 	dvb_usb_i2c_exit(d);
143786baecfSMauro Carvalho Chehab 	deb_info("state should be zero now: %x\n", d->state);
144786baecfSMauro Carvalho Chehab 	d->state = DVB_USB_STATE_INIT;
145d525e5c2SMaciej S. Szmigiero 
146d525e5c2SMaciej S. Szmigiero 	if (d->priv != NULL && d->props.priv_destroy != NULL)
147d525e5c2SMaciej S. Szmigiero 		d->props.priv_destroy(d);
148d525e5c2SMaciej S. Szmigiero 
149786baecfSMauro Carvalho Chehab 	kfree(d->priv);
150786baecfSMauro Carvalho Chehab 	kfree(d);
151786baecfSMauro Carvalho Chehab 	return 0;
152786baecfSMauro Carvalho Chehab }
153786baecfSMauro Carvalho Chehab 
154786baecfSMauro Carvalho Chehab static int dvb_usb_init(struct dvb_usb_device *d, short *adapter_nums)
155786baecfSMauro Carvalho Chehab {
156786baecfSMauro Carvalho Chehab 	int ret = 0;
157786baecfSMauro Carvalho Chehab 
1587724325aSMauro Carvalho Chehab 	mutex_init(&d->data_mutex);
159786baecfSMauro Carvalho Chehab 	mutex_init(&d->usb_mutex);
160786baecfSMauro Carvalho Chehab 	mutex_init(&d->i2c_mutex);
161786baecfSMauro Carvalho Chehab 
162786baecfSMauro Carvalho Chehab 	d->state = DVB_USB_STATE_INIT;
163786baecfSMauro Carvalho Chehab 
164786baecfSMauro Carvalho Chehab 	if (d->props.size_of_priv > 0) {
165786baecfSMauro Carvalho Chehab 		d->priv = kzalloc(d->props.size_of_priv, GFP_KERNEL);
166786baecfSMauro Carvalho Chehab 		if (d->priv == NULL) {
167786baecfSMauro Carvalho Chehab 			err("no memory for priv in 'struct dvb_usb_device'");
168786baecfSMauro Carvalho Chehab 			return -ENOMEM;
169786baecfSMauro Carvalho Chehab 		}
170d525e5c2SMaciej S. Szmigiero 
171d525e5c2SMaciej S. Szmigiero 		if (d->props.priv_init != NULL) {
172d525e5c2SMaciej S. Szmigiero 			ret = d->props.priv_init(d);
17313a79f14STakashi Iwai 			if (ret != 0)
17413a79f14STakashi Iwai 				goto err_priv_init;
175d525e5c2SMaciej S. Szmigiero 		}
176786baecfSMauro Carvalho Chehab 	}
177786baecfSMauro Carvalho Chehab 
178786baecfSMauro Carvalho Chehab 	/* check the capabilities and set appropriate variables */
179786baecfSMauro Carvalho Chehab 	dvb_usb_device_power_ctrl(d, 1);
180786baecfSMauro Carvalho Chehab 
18113a79f14STakashi Iwai 	ret = dvb_usb_i2c_init(d);
18213a79f14STakashi Iwai 	if (ret)
18313a79f14STakashi Iwai 		goto err_i2c_init;
18413a79f14STakashi Iwai 	ret = dvb_usb_adapter_init(d, adapter_nums);
18513a79f14STakashi Iwai 	if (ret)
18613a79f14STakashi Iwai 		goto err_adapter_init;
187786baecfSMauro Carvalho Chehab 
188786baecfSMauro Carvalho Chehab 	if ((ret = dvb_usb_remote_init(d)))
189786baecfSMauro Carvalho Chehab 		err("could not initialize remote control.");
190786baecfSMauro Carvalho Chehab 
191786baecfSMauro Carvalho Chehab 	dvb_usb_device_power_ctrl(d, 0);
192786baecfSMauro Carvalho Chehab 
193786baecfSMauro Carvalho Chehab 	return 0;
19413a79f14STakashi Iwai 
19513a79f14STakashi Iwai err_adapter_init:
19613a79f14STakashi Iwai 	dvb_usb_adapter_exit(d);
19713a79f14STakashi Iwai 	dvb_usb_i2c_exit(d);
198*131ae388SDongliang Mu err_i2c_init:
19913a79f14STakashi Iwai 	if (d->priv && d->props.priv_destroy)
20013a79f14STakashi Iwai 		d->props.priv_destroy(d);
20113a79f14STakashi Iwai err_priv_init:
20213a79f14STakashi Iwai 	kfree(d->priv);
20313a79f14STakashi Iwai 	d->priv = NULL;
20413a79f14STakashi Iwai 	return ret;
205786baecfSMauro Carvalho Chehab }
206786baecfSMauro Carvalho Chehab 
207786baecfSMauro Carvalho Chehab /* determine the name and the state of the just found USB device */
208d27958dfSSean 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)
209786baecfSMauro Carvalho Chehab {
210786baecfSMauro Carvalho Chehab 	int i, j;
211d27958dfSSean Young 	const struct dvb_usb_device_description *desc = NULL;
212786baecfSMauro Carvalho Chehab 
213786baecfSMauro Carvalho Chehab 	*cold = -1;
214786baecfSMauro Carvalho Chehab 
215786baecfSMauro Carvalho Chehab 	for (i = 0; i < props->num_device_descs; i++) {
216786baecfSMauro Carvalho Chehab 
217786baecfSMauro Carvalho Chehab 		for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].cold_ids[j] != NULL; j++) {
218786baecfSMauro Carvalho Chehab 			deb_info("check for cold %x %x\n", props->devices[i].cold_ids[j]->idVendor, props->devices[i].cold_ids[j]->idProduct);
219786baecfSMauro Carvalho Chehab 			if (props->devices[i].cold_ids[j]->idVendor  == le16_to_cpu(udev->descriptor.idVendor) &&
220786baecfSMauro Carvalho Chehab 				props->devices[i].cold_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
221786baecfSMauro Carvalho Chehab 				*cold = 1;
222786baecfSMauro Carvalho Chehab 				desc = &props->devices[i];
223786baecfSMauro Carvalho Chehab 				break;
224786baecfSMauro Carvalho Chehab 			}
225786baecfSMauro Carvalho Chehab 		}
226786baecfSMauro Carvalho Chehab 
227786baecfSMauro Carvalho Chehab 		if (desc != NULL)
228786baecfSMauro Carvalho Chehab 			break;
229786baecfSMauro Carvalho Chehab 
230786baecfSMauro Carvalho Chehab 		for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].warm_ids[j] != NULL; j++) {
231786baecfSMauro Carvalho Chehab 			deb_info("check for warm %x %x\n", props->devices[i].warm_ids[j]->idVendor, props->devices[i].warm_ids[j]->idProduct);
232786baecfSMauro Carvalho Chehab 			if (props->devices[i].warm_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) &&
233786baecfSMauro Carvalho Chehab 				props->devices[i].warm_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
234786baecfSMauro Carvalho Chehab 				*cold = 0;
235786baecfSMauro Carvalho Chehab 				desc = &props->devices[i];
236786baecfSMauro Carvalho Chehab 				break;
237786baecfSMauro Carvalho Chehab 			}
238786baecfSMauro Carvalho Chehab 		}
239786baecfSMauro Carvalho Chehab 	}
240786baecfSMauro Carvalho Chehab 
241786baecfSMauro Carvalho Chehab 	if (desc != NULL && props->identify_state != NULL)
242786baecfSMauro Carvalho Chehab 		props->identify_state(udev, props, &desc, cold);
243786baecfSMauro Carvalho Chehab 
244786baecfSMauro Carvalho Chehab 	return desc;
245786baecfSMauro Carvalho Chehab }
246786baecfSMauro Carvalho Chehab 
247786baecfSMauro Carvalho Chehab int dvb_usb_device_power_ctrl(struct dvb_usb_device *d, int onoff)
248786baecfSMauro Carvalho Chehab {
249786baecfSMauro Carvalho Chehab 	if (onoff)
250786baecfSMauro Carvalho Chehab 		d->powered++;
251786baecfSMauro Carvalho Chehab 	else
252786baecfSMauro Carvalho Chehab 		d->powered--;
253786baecfSMauro Carvalho Chehab 
254786baecfSMauro Carvalho Chehab 	if (d->powered == 0 || (onoff && d->powered == 1)) { /* when switching from 1 to 0 or from 0 to 1 */
255786baecfSMauro Carvalho Chehab 		deb_info("power control: %d\n", onoff);
256786baecfSMauro Carvalho Chehab 		if (d->props.power_ctrl)
257786baecfSMauro Carvalho Chehab 			return d->props.power_ctrl(d, onoff);
258786baecfSMauro Carvalho Chehab 	}
259786baecfSMauro Carvalho Chehab 	return 0;
260786baecfSMauro Carvalho Chehab }
261786baecfSMauro Carvalho Chehab 
262786baecfSMauro Carvalho Chehab /*
263786baecfSMauro Carvalho Chehab  * USB
264786baecfSMauro Carvalho Chehab  */
265786baecfSMauro Carvalho Chehab int dvb_usb_device_init(struct usb_interface *intf,
266d27958dfSSean Young 			const struct dvb_usb_device_properties *props,
267786baecfSMauro Carvalho Chehab 			struct module *owner, struct dvb_usb_device **du,
268786baecfSMauro Carvalho Chehab 			short *adapter_nums)
269786baecfSMauro Carvalho Chehab {
270786baecfSMauro Carvalho Chehab 	struct usb_device *udev = interface_to_usbdev(intf);
271786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = NULL;
272d27958dfSSean Young 	const struct dvb_usb_device_description *desc = NULL;
273786baecfSMauro Carvalho Chehab 
274786baecfSMauro Carvalho Chehab 	int ret = -ENOMEM, cold = 0;
275786baecfSMauro Carvalho Chehab 
276786baecfSMauro Carvalho Chehab 	if (du != NULL)
277786baecfSMauro Carvalho Chehab 		*du = NULL;
278786baecfSMauro Carvalho Chehab 
279c4920678STakashi Iwai 	d = kzalloc(sizeof(*d), GFP_KERNEL);
280c4920678STakashi Iwai 	if (!d) {
281c4920678STakashi Iwai 		err("no memory for 'struct dvb_usb_device'");
282c4920678STakashi Iwai 		return -ENOMEM;
283c4920678STakashi Iwai 	}
284c4920678STakashi Iwai 
285c4920678STakashi Iwai 	memcpy(&d->props, props, sizeof(struct dvb_usb_device_properties));
286c4920678STakashi Iwai 
287c4920678STakashi Iwai 	desc = dvb_usb_find_device(udev, &d->props, &cold);
288c4920678STakashi Iwai 	if (!desc) {
289786baecfSMauro Carvalho Chehab 		deb_err("something went very wrong, device was not found in current device list - let's see what comes next.\n");
290c4920678STakashi Iwai 		ret = -ENODEV;
291c4920678STakashi Iwai 		goto error;
292786baecfSMauro Carvalho Chehab 	}
293786baecfSMauro Carvalho Chehab 
294786baecfSMauro Carvalho Chehab 	if (cold) {
295786baecfSMauro Carvalho Chehab 		info("found a '%s' in cold state, will try to load a firmware", desc->name);
296786baecfSMauro Carvalho Chehab 		ret = dvb_usb_download_firmware(udev, props);
297786baecfSMauro Carvalho Chehab 		if (!props->no_reconnect || ret != 0)
298c4920678STakashi Iwai 			goto error;
299786baecfSMauro Carvalho Chehab 	}
300786baecfSMauro Carvalho Chehab 
301786baecfSMauro Carvalho Chehab 	info("found a '%s' in warm state.", desc->name);
302786baecfSMauro Carvalho Chehab 	d->udev = udev;
303786baecfSMauro Carvalho Chehab 	d->desc = desc;
304786baecfSMauro Carvalho Chehab 	d->owner = owner;
305786baecfSMauro Carvalho Chehab 
306786baecfSMauro Carvalho Chehab 	usb_set_intfdata(intf, d);
307786baecfSMauro Carvalho Chehab 
30813a79f14STakashi Iwai 	ret = dvb_usb_init(d, adapter_nums);
30913a79f14STakashi Iwai 	if (ret) {
31013a79f14STakashi Iwai 		info("%s error while loading driver (%d)", desc->name, ret);
31113a79f14STakashi Iwai 		goto error;
31213a79f14STakashi Iwai 	}
31313a79f14STakashi Iwai 
31413a79f14STakashi Iwai 	if (du)
315786baecfSMauro Carvalho Chehab 		*du = d;
316786baecfSMauro Carvalho Chehab 
317786baecfSMauro Carvalho Chehab 	info("%s successfully initialized and connected.", desc->name);
31813a79f14STakashi Iwai 	return 0;
31913a79f14STakashi Iwai 
32013a79f14STakashi Iwai  error:
32113a79f14STakashi Iwai 	usb_set_intfdata(intf, NULL);
32213a79f14STakashi Iwai 	kfree(d);
323786baecfSMauro Carvalho Chehab 	return ret;
324786baecfSMauro Carvalho Chehab }
325786baecfSMauro Carvalho Chehab EXPORT_SYMBOL(dvb_usb_device_init);
326786baecfSMauro Carvalho Chehab 
327786baecfSMauro Carvalho Chehab void dvb_usb_device_exit(struct usb_interface *intf)
328786baecfSMauro Carvalho Chehab {
329786baecfSMauro Carvalho Chehab 	struct dvb_usb_device *d = usb_get_intfdata(intf);
3306cf97230SOliver Neukum 	const char *default_name = "generic DVB-USB module";
3316cf97230SOliver Neukum 	char name[40];
332786baecfSMauro Carvalho Chehab 
333786baecfSMauro Carvalho Chehab 	usb_set_intfdata(intf, NULL);
334786baecfSMauro Carvalho Chehab 	if (d != NULL && d->desc != NULL) {
3356cf97230SOliver Neukum 		strscpy(name, d->desc->name, sizeof(name));
336786baecfSMauro Carvalho Chehab 		dvb_usb_exit(d);
3376cf97230SOliver Neukum 	} else {
3386cf97230SOliver Neukum 		strscpy(name, default_name, sizeof(name));
339786baecfSMauro Carvalho Chehab 	}
340786baecfSMauro Carvalho Chehab 	info("%s successfully deinitialized and disconnected.", name);
341786baecfSMauro Carvalho Chehab 
342786baecfSMauro Carvalho Chehab }
343786baecfSMauro Carvalho Chehab EXPORT_SYMBOL(dvb_usb_device_exit);
344786baecfSMauro Carvalho Chehab 
345786baecfSMauro Carvalho Chehab MODULE_VERSION("1.0");
34699e44da7SPatrick Boettcher MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
347786baecfSMauro Carvalho Chehab MODULE_DESCRIPTION("A library module containing commonly used USB and DVB function USB DVB devices");
348786baecfSMauro Carvalho Chehab MODULE_LICENSE("GPL");
349