Lines Matching +full:- +full:d +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
3 * DVB USB library - provides a generic interface for a DVB USB device driver.
5 * dvb-usb-init.c
7 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
9 * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
11 #include "dvb-usb-common.h"
16 …ng level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64,mem=128,uxfer=256 (or-able))." DVB_USB_DEBU…
24 MODULE_PARM_DESC(force_pid_filter_usage, "force all dvb-usb-devices to use a PID filter, if any (de…
26 static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs) in dvb_usb_adapter_init() argument
31 for (n = 0; n < d->props.num_adapters; n++) { in dvb_usb_adapter_init()
32 adap = &d->adapter[n]; in dvb_usb_adapter_init()
33 adap->dev = d; in dvb_usb_adapter_init()
34 adap->id = n; in dvb_usb_adapter_init()
36 memcpy(&adap->props, &d->props.adapter[n], sizeof(struct dvb_usb_adapter_properties)); in dvb_usb_adapter_init()
38 for (o = 0; o < adap->props.num_frontends; o++) { in dvb_usb_adapter_init()
39 struct dvb_usb_adapter_fe_properties *props = &adap->props.fe[o]; in dvb_usb_adapter_init()
40 /* speed - when running at FULL speed we need a HW PID filter */ in dvb_usb_adapter_init()
41 if (d->udev->speed == USB_SPEED_FULL && !(props->caps & DVB_USB_ADAP_HAS_PID_FILTER)) { in dvb_usb_adapter_init()
43 return -ENODEV; in dvb_usb_adapter_init()
46 if ((d->udev->speed == USB_SPEED_FULL && props->caps & DVB_USB_ADAP_HAS_PID_FILTER) || in dvb_usb_adapter_init()
47 (props->caps & DVB_USB_ADAP_NEED_PID_FILTERING)) { in dvb_usb_adapter_init()
48 info("will use the device's hardware PID filter (table count: %d).", props->pid_filter_count); in dvb_usb_adapter_init()
49 adap->fe_adap[o].pid_filtering = 1; in dvb_usb_adapter_init()
50 adap->fe_adap[o].max_feed_count = props->pid_filter_count; in dvb_usb_adapter_init()
53 adap->fe_adap[o].pid_filtering = 0; in dvb_usb_adapter_init()
54 adap->fe_adap[o].max_feed_count = 255; in dvb_usb_adapter_init()
57 if (!adap->fe_adap[o].pid_filtering && in dvb_usb_adapter_init()
59 props->caps & DVB_USB_ADAP_HAS_PID_FILTER) { in dvb_usb_adapter_init()
61 adap->fe_adap[o].pid_filtering = 1; in dvb_usb_adapter_init()
62 adap->fe_adap[o].max_feed_count = props->pid_filter_count; in dvb_usb_adapter_init()
65 if (props->size_of_priv > 0) { in dvb_usb_adapter_init()
66 adap->fe_adap[o].priv = kzalloc(props->size_of_priv, GFP_KERNEL); in dvb_usb_adapter_init()
67 if (adap->fe_adap[o].priv == NULL) { in dvb_usb_adapter_init()
68 err("no memory for priv for adapter %d fe %d.", n, o); in dvb_usb_adapter_init()
69 return -ENOMEM; in dvb_usb_adapter_init()
74 if (adap->props.size_of_priv > 0) { in dvb_usb_adapter_init()
75 adap->priv = kzalloc(adap->props.size_of_priv, GFP_KERNEL); in dvb_usb_adapter_init()
76 if (adap->priv == NULL) { in dvb_usb_adapter_init()
77 err("no memory for priv for adapter %d.", n); in dvb_usb_adapter_init()
78 return -ENOMEM; in dvb_usb_adapter_init()
95 if (adap->fe_adap[1].fe && adap->dvb_adap.mfe_shared < 1) in dvb_usb_adapter_init()
96 adap->dvb_adap.mfe_shared = 1; in dvb_usb_adapter_init()
98 d->num_adapters_initialized++; in dvb_usb_adapter_init()
99 d->state |= DVB_USB_STATE_DVB; in dvb_usb_adapter_init()
106 if (d->props.generic_bulk_ctrl_endpoint != 0) { in dvb_usb_adapter_init()
107 usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint)); in dvb_usb_adapter_init()
108 usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint)); in dvb_usb_adapter_init()
118 kfree(adap->priv); in dvb_usb_adapter_init()
122 static int dvb_usb_adapter_exit(struct dvb_usb_device *d) in dvb_usb_adapter_exit() argument
126 for (n = 0; n < d->num_adapters_initialized; n++) { in dvb_usb_adapter_exit()
127 dvb_usb_adapter_frontend_exit(&d->adapter[n]); in dvb_usb_adapter_exit()
128 dvb_usb_adapter_dvb_exit(&d->adapter[n]); in dvb_usb_adapter_exit()
129 dvb_usb_adapter_stream_exit(&d->adapter[n]); in dvb_usb_adapter_exit()
130 kfree(d->adapter[n].priv); in dvb_usb_adapter_exit()
132 d->num_adapters_initialized = 0; in dvb_usb_adapter_exit()
133 d->state &= ~DVB_USB_STATE_DVB; in dvb_usb_adapter_exit()
139 static int dvb_usb_exit(struct dvb_usb_device *d) in dvb_usb_exit() argument
141 deb_info("state before exiting everything: %x\n", d->state); in dvb_usb_exit()
142 dvb_usb_remote_exit(d); in dvb_usb_exit()
143 dvb_usb_adapter_exit(d); in dvb_usb_exit()
144 dvb_usb_i2c_exit(d); in dvb_usb_exit()
145 deb_info("state should be zero now: %x\n", d->state); in dvb_usb_exit()
146 d->state = DVB_USB_STATE_INIT; in dvb_usb_exit()
148 if (d->priv != NULL && d->props.priv_destroy != NULL) in dvb_usb_exit()
149 d->props.priv_destroy(d); in dvb_usb_exit()
151 kfree(d->priv); in dvb_usb_exit()
152 kfree(d); in dvb_usb_exit()
156 static int dvb_usb_init(struct dvb_usb_device *d, short *adapter_nums) in dvb_usb_init() argument
160 mutex_init(&d->data_mutex); in dvb_usb_init()
161 mutex_init(&d->usb_mutex); in dvb_usb_init()
162 mutex_init(&d->i2c_mutex); in dvb_usb_init()
164 d->state = DVB_USB_STATE_INIT; in dvb_usb_init()
166 if (d->props.size_of_priv > 0) { in dvb_usb_init()
167 d->priv = kzalloc(d->props.size_of_priv, GFP_KERNEL); in dvb_usb_init()
168 if (d->priv == NULL) { in dvb_usb_init()
170 return -ENOMEM; in dvb_usb_init()
173 if (d->props.priv_init != NULL) { in dvb_usb_init()
174 ret = d->props.priv_init(d); in dvb_usb_init()
181 dvb_usb_device_power_ctrl(d, 1); in dvb_usb_init()
183 ret = dvb_usb_i2c_init(d); in dvb_usb_init()
186 ret = dvb_usb_adapter_init(d, adapter_nums); in dvb_usb_init()
190 if ((ret = dvb_usb_remote_init(d))) in dvb_usb_init()
193 dvb_usb_device_power_ctrl(d, 0); in dvb_usb_init()
198 dvb_usb_adapter_exit(d); in dvb_usb_init()
199 dvb_usb_i2c_exit(d); in dvb_usb_init()
201 if (d->priv && d->props.priv_destroy) in dvb_usb_init()
202 d->props.priv_destroy(d); in dvb_usb_init()
204 kfree(d->priv); in dvb_usb_init()
205 d->priv = NULL; in dvb_usb_init()
215 *cold = -1; in dvb_usb_find_device()
217 for (i = 0; i < props->num_device_descs; i++) { in dvb_usb_find_device()
219 for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].cold_ids[j] != NULL; j++) { in dvb_usb_find_device()
220 …deb_info("check for cold %x %x\n", props->devices[i].cold_ids[j]->idVendor, props->devices[i].cold… in dvb_usb_find_device()
221 if (props->devices[i].cold_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) && in dvb_usb_find_device()
222 props->devices[i].cold_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) { in dvb_usb_find_device()
224 desc = &props->devices[i]; in dvb_usb_find_device()
232 for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].warm_ids[j] != NULL; j++) { in dvb_usb_find_device()
233 …deb_info("check for warm %x %x\n", props->devices[i].warm_ids[j]->idVendor, props->devices[i].warm… in dvb_usb_find_device()
234 if (props->devices[i].warm_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) && in dvb_usb_find_device()
235 props->devices[i].warm_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) { in dvb_usb_find_device()
237 desc = &props->devices[i]; in dvb_usb_find_device()
243 if (desc != NULL && props->identify_state != NULL) in dvb_usb_find_device()
244 props->identify_state(udev, props, &desc, cold); in dvb_usb_find_device()
249 int dvb_usb_device_power_ctrl(struct dvb_usb_device *d, int onoff) in dvb_usb_device_power_ctrl() argument
252 d->powered++; in dvb_usb_device_power_ctrl()
254 d->powered--; in dvb_usb_device_power_ctrl()
256 …if (d->powered == 0 || (onoff && d->powered == 1)) { /* when switching from 1 to 0 or from 0 to 1 … in dvb_usb_device_power_ctrl()
257 deb_info("power control: %d\n", onoff); in dvb_usb_device_power_ctrl()
258 if (d->props.power_ctrl) in dvb_usb_device_power_ctrl()
259 return d->props.power_ctrl(d, onoff); in dvb_usb_device_power_ctrl()
273 struct dvb_usb_device *d = NULL; in dvb_usb_device_init() local
276 int ret = -ENOMEM, cold = 0; in dvb_usb_device_init()
281 d = kzalloc(sizeof(*d), GFP_KERNEL); in dvb_usb_device_init()
282 if (!d) { in dvb_usb_device_init()
284 return -ENOMEM; in dvb_usb_device_init()
287 memcpy(&d->props, props, sizeof(struct dvb_usb_device_properties)); in dvb_usb_device_init()
289 desc = dvb_usb_find_device(udev, &d->props, &cold); in dvb_usb_device_init()
291 …deb_err("something went very wrong, device was not found in current device list - let's see what c… in dvb_usb_device_init()
292 ret = -ENODEV; in dvb_usb_device_init()
297 info("found a '%s' in cold state, will try to load a firmware", desc->name); in dvb_usb_device_init()
299 if (!props->no_reconnect || ret != 0) in dvb_usb_device_init()
303 info("found a '%s' in warm state.", desc->name); in dvb_usb_device_init()
304 d->udev = udev; in dvb_usb_device_init()
305 d->desc = desc; in dvb_usb_device_init()
306 d->owner = owner; in dvb_usb_device_init()
308 usb_set_intfdata(intf, d); in dvb_usb_device_init()
310 ret = dvb_usb_init(d, adapter_nums); in dvb_usb_device_init()
312 info("%s error while loading driver (%d)", desc->name, ret); in dvb_usb_device_init()
317 *du = d; in dvb_usb_device_init()
319 info("%s successfully initialized and connected.", desc->name); in dvb_usb_device_init()
324 kfree(d); in dvb_usb_device_init()
331 struct dvb_usb_device *d = usb_get_intfdata(intf); in dvb_usb_device_exit() local
332 const char *default_name = "generic DVB-USB module"; in dvb_usb_device_exit()
336 if (d != NULL && d->desc != NULL) { in dvb_usb_device_exit()
337 strscpy(name, d->desc->name, sizeof(name)); in dvb_usb_device_exit()
338 dvb_usb_exit(d); in dvb_usb_device_exit()