4 * Copyright (C) 2004-6 Patrick Boettcher <patrick.boettcher@desy.de>
5 * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "dvb_usb_common.h"
24 static int dvb_usbv2_disable_rc_polling;
25 module_param_named(disable_rc_polling, dvb_usbv2_disable_rc_polling, int, 0644);
26 MODULE_PARM_DESC(disable_rc_polling,
27 "disable remote control polling (default: 0)");
28 static int dvb_usb_force_pid_filter_usage;
29 module_param_named(force_pid_filter_usage, dvb_usb_force_pid_filter_usage,
31 MODULE_PARM_DESC(force_pid_filter_usage,
32 "force all DVB USB devices to use a PID filter, if any (default: 0)");
34 static int dvb_usbv2_download_firmware(struct dvb_usb_device *d,
38 const struct firmware *fw;
39 dev_dbg(&d->udev->dev, "%s:\n", __func__);
41 if (!d->props->download_firmware) {
46 ret = request_firmware(&fw, name, &d->udev->dev);
48 dev_err(&d->udev->dev,
49 "%s: Did not find the firmware file '%s'. Please see linux/Documentation/dvb/ for more details on firmware-problems. Status %d\n",
50 KBUILD_MODNAME, name, ret);
54 dev_info(&d->udev->dev, "%s: downloading firmware from file '%s'\n",
55 KBUILD_MODNAME, name);
57 ret = d->props->download_firmware(d, fw);
64 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
68 static int dvb_usbv2_i2c_init(struct dvb_usb_device *d)
71 dev_dbg(&d->udev->dev, "%s:\n", __func__);
73 if (!d->props->i2c_algo)
76 strlcpy(d->i2c_adap.name, d->name, sizeof(d->i2c_adap.name));
77 d->i2c_adap.algo = d->props->i2c_algo;
78 d->i2c_adap.dev.parent = &d->udev->dev;
79 i2c_set_adapdata(&d->i2c_adap, d);
81 ret = i2c_add_adapter(&d->i2c_adap);
83 d->i2c_adap.algo = NULL;
84 dev_err(&d->udev->dev, "%s: i2c_add_adapter() failed=%d\n",
91 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
95 static int dvb_usbv2_i2c_exit(struct dvb_usb_device *d)
97 dev_dbg(&d->udev->dev, "%s:\n", __func__);
100 i2c_del_adapter(&d->i2c_adap);
105 #if IS_ENABLED(CONFIG_RC_CORE)
106 static void dvb_usb_read_remote_control(struct work_struct *work)
108 struct dvb_usb_device *d = container_of(work,
109 struct dvb_usb_device, rc_query_work.work);
113 * When the parameter has been set to 1 via sysfs while the
114 * driver was running, or when bulk mode is enabled after IR init.
116 if (dvb_usbv2_disable_rc_polling || d->rc.bulk_mode) {
117 d->rc_polling_active = false;
121 ret = d->rc.query(d);
123 dev_err(&d->udev->dev, "%s: rc.query() failed=%d\n",
124 KBUILD_MODNAME, ret);
125 d->rc_polling_active = false;
126 return; /* stop polling */
129 schedule_delayed_work(&d->rc_query_work,
130 msecs_to_jiffies(d->rc.interval));
133 static int dvb_usbv2_remote_init(struct dvb_usb_device *d)
137 dev_dbg(&d->udev->dev, "%s:\n", __func__);
139 if (dvb_usbv2_disable_rc_polling || !d->props->get_rc_config)
142 d->rc.map_name = d->rc_map;
143 ret = d->props->get_rc_config(d, &d->rc);
147 /* disable rc when there is no keymap defined */
151 dev = rc_allocate_device();
157 dev->dev.parent = &d->udev->dev;
158 dev->input_name = d->name;
159 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys));
160 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys));
161 dev->input_phys = d->rc_phys;
162 usb_to_input_id(d->udev, &dev->input_id);
163 /* TODO: likely RC-core should took const char * */
164 dev->driver_name = (char *) d->props->driver_name;
165 dev->map_name = d->rc.map_name;
166 dev->driver_type = d->rc.driver_type;
167 dev->allowed_protocols = d->rc.allowed_protos;
168 dev->change_protocol = d->rc.change_protocol;
171 ret = rc_register_device(dev);
179 /* start polling if needed */
180 if (d->rc.query && !d->rc.bulk_mode) {
181 /* initialize a work queue for handling polling */
182 INIT_DELAYED_WORK(&d->rc_query_work,
183 dvb_usb_read_remote_control);
184 dev_info(&d->udev->dev,
185 "%s: schedule remote query interval to %d msecs\n",
186 KBUILD_MODNAME, d->rc.interval);
187 schedule_delayed_work(&d->rc_query_work,
188 msecs_to_jiffies(d->rc.interval));
189 d->rc_polling_active = true;
194 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
198 static int dvb_usbv2_remote_exit(struct dvb_usb_device *d)
200 dev_dbg(&d->udev->dev, "%s:\n", __func__);
203 cancel_delayed_work_sync(&d->rc_query_work);
204 rc_unregister_device(d->rc_dev);
211 #define dvb_usbv2_remote_init(args...) 0
212 #define dvb_usbv2_remote_exit(args...)
215 static void dvb_usb_data_complete(struct usb_data_stream *stream, u8 *buf,
218 struct dvb_usb_adapter *adap = stream->user_priv;
219 dvb_dmx_swfilter(&adap->demux, buf, len);
222 static void dvb_usb_data_complete_204(struct usb_data_stream *stream, u8 *buf,
225 struct dvb_usb_adapter *adap = stream->user_priv;
226 dvb_dmx_swfilter_204(&adap->demux, buf, len);
229 static void dvb_usb_data_complete_raw(struct usb_data_stream *stream, u8 *buf,
232 struct dvb_usb_adapter *adap = stream->user_priv;
233 dvb_dmx_swfilter_raw(&adap->demux, buf, len);
236 static int dvb_usbv2_adapter_stream_init(struct dvb_usb_adapter *adap)
238 dev_dbg(&adap_to_d(adap)->udev->dev, "%s: adap=%d\n", __func__,
241 adap->stream.udev = adap_to_d(adap)->udev;
242 adap->stream.user_priv = adap;
243 adap->stream.complete = dvb_usb_data_complete;
245 return usb_urb_initv2(&adap->stream, &adap->props->stream);
248 static int dvb_usbv2_adapter_stream_exit(struct dvb_usb_adapter *adap)
250 dev_dbg(&adap_to_d(adap)->udev->dev, "%s: adap=%d\n", __func__,
253 return usb_urb_exitv2(&adap->stream);
256 static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
258 struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv;
259 struct dvb_usb_device *d = adap_to_d(adap);
261 struct usb_data_stream_properties stream_props;
262 dev_dbg(&d->udev->dev,
263 "%s: adap=%d active_fe=%d feed_type=%d setting pid [%s]: %04x (%04d) at index %d\n",
264 __func__, adap->id, adap->active_fe, dvbdmxfeed->type,
265 adap->pid_filtering ? "yes" : "no", dvbdmxfeed->pid,
266 dvbdmxfeed->pid, dvbdmxfeed->index);
268 /* wait init is done */
269 wait_on_bit(&adap->state_bits, ADAP_INIT, TASK_UNINTERRUPTIBLE);
271 if (adap->active_fe == -1)
274 /* skip feed setup if we are already feeding */
275 if (adap->feed_count++ > 0)
276 goto skip_feed_start;
278 /* set 'streaming' status bit */
279 set_bit(ADAP_STREAMING, &adap->state_bits);
281 /* resolve input and output streaming parameters */
282 if (d->props->get_stream_config) {
283 memcpy(&stream_props, &adap->props->stream,
284 sizeof(struct usb_data_stream_properties));
285 ret = d->props->get_stream_config(adap->fe[adap->active_fe],
286 &adap->ts_type, &stream_props);
288 dev_err(&d->udev->dev,
289 "%s: get_stream_config() failed=%d\n",
290 KBUILD_MODNAME, ret);
292 stream_props = adap->props->stream;
295 switch (adap->ts_type) {
296 case DVB_USB_FE_TS_TYPE_204:
297 adap->stream.complete = dvb_usb_data_complete_204;
299 case DVB_USB_FE_TS_TYPE_RAW:
300 adap->stream.complete = dvb_usb_data_complete_raw;
302 case DVB_USB_FE_TS_TYPE_188:
304 adap->stream.complete = dvb_usb_data_complete;
308 /* submit USB streaming packets */
309 usb_urb_submitv2(&adap->stream, &stream_props);
311 /* enable HW PID filter */
312 if (adap->pid_filtering && adap->props->pid_filter_ctrl) {
313 ret = adap->props->pid_filter_ctrl(adap, 1);
315 dev_err(&d->udev->dev,
316 "%s: pid_filter_ctrl() failed=%d\n",
317 KBUILD_MODNAME, ret);
320 /* ask device to start streaming */
321 if (d->props->streaming_ctrl) {
322 ret = d->props->streaming_ctrl(adap->fe[adap->active_fe], 1);
324 dev_err(&d->udev->dev,
325 "%s: streaming_ctrl() failed=%d\n",
326 KBUILD_MODNAME, ret);
330 /* add PID to device HW PID filter */
331 if (adap->pid_filtering && adap->props->pid_filter) {
332 ret = adap->props->pid_filter(adap, dvbdmxfeed->index,
335 dev_err(&d->udev->dev, "%s: pid_filter() failed=%d\n",
336 KBUILD_MODNAME, ret);
340 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
344 static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
346 struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv;
347 struct dvb_usb_device *d = adap_to_d(adap);
349 dev_dbg(&d->udev->dev,
350 "%s: adap=%d active_fe=%d feed_type=%d setting pid [%s]: %04x (%04d) at index %d\n",
351 __func__, adap->id, adap->active_fe, dvbdmxfeed->type,
352 adap->pid_filtering ? "yes" : "no", dvbdmxfeed->pid,
353 dvbdmxfeed->pid, dvbdmxfeed->index);
355 if (adap->active_fe == -1)
358 /* remove PID from device HW PID filter */
359 if (adap->pid_filtering && adap->props->pid_filter) {
360 ret = adap->props->pid_filter(adap, dvbdmxfeed->index,
363 dev_err(&d->udev->dev, "%s: pid_filter() failed=%d\n",
364 KBUILD_MODNAME, ret);
367 /* we cannot stop streaming until last PID is removed */
368 if (--adap->feed_count > 0)
371 /* ask device to stop streaming */
372 if (d->props->streaming_ctrl) {
373 ret = d->props->streaming_ctrl(adap->fe[adap->active_fe], 0);
375 dev_err(&d->udev->dev,
376 "%s: streaming_ctrl() failed=%d\n",
377 KBUILD_MODNAME, ret);
380 /* disable HW PID filter */
381 if (adap->pid_filtering && adap->props->pid_filter_ctrl) {
382 ret = adap->props->pid_filter_ctrl(adap, 0);
384 dev_err(&d->udev->dev,
385 "%s: pid_filter_ctrl() failed=%d\n",
386 KBUILD_MODNAME, ret);
389 /* kill USB streaming packets */
390 usb_urb_killv2(&adap->stream);
392 /* clear 'streaming' status bit */
393 clear_bit(ADAP_STREAMING, &adap->state_bits);
394 smp_mb__after_atomic();
395 wake_up_bit(&adap->state_bits, ADAP_STREAMING);
399 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
403 static int dvb_usbv2_adapter_dvb_init(struct dvb_usb_adapter *adap)
406 struct dvb_usb_device *d = adap_to_d(adap);
407 dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, adap->id);
409 ret = dvb_register_adapter(&adap->dvb_adap, d->name, d->props->owner,
410 &d->udev->dev, d->props->adapter_nr);
412 dev_dbg(&d->udev->dev, "%s: dvb_register_adapter() failed=%d\n",
414 goto err_dvb_register_adapter;
417 adap->dvb_adap.priv = adap;
419 if (d->props->read_mac_address) {
420 ret = d->props->read_mac_address(adap,
421 adap->dvb_adap.proposed_mac);
423 goto err_dvb_dmx_init;
425 dev_info(&d->udev->dev, "%s: MAC address: %pM\n",
426 KBUILD_MODNAME, adap->dvb_adap.proposed_mac);
429 adap->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING;
430 adap->demux.priv = adap;
431 adap->demux.filternum = 0;
432 adap->demux.filternum = adap->max_feed_count;
433 adap->demux.feednum = adap->demux.filternum;
434 adap->demux.start_feed = dvb_usb_start_feed;
435 adap->demux.stop_feed = dvb_usb_stop_feed;
436 adap->demux.write_to_decoder = NULL;
437 ret = dvb_dmx_init(&adap->demux);
439 dev_err(&d->udev->dev, "%s: dvb_dmx_init() failed=%d\n",
440 KBUILD_MODNAME, ret);
441 goto err_dvb_dmx_init;
444 adap->dmxdev.filternum = adap->demux.filternum;
445 adap->dmxdev.demux = &adap->demux.dmx;
446 adap->dmxdev.capabilities = 0;
447 ret = dvb_dmxdev_init(&adap->dmxdev, &adap->dvb_adap);
449 dev_err(&d->udev->dev, "%s: dvb_dmxdev_init() failed=%d\n",
450 KBUILD_MODNAME, ret);
451 goto err_dvb_dmxdev_init;
454 ret = dvb_net_init(&adap->dvb_adap, &adap->dvb_net, &adap->demux.dmx);
456 dev_err(&d->udev->dev, "%s: dvb_net_init() failed=%d\n",
457 KBUILD_MODNAME, ret);
458 goto err_dvb_net_init;
463 dvb_dmxdev_release(&adap->dmxdev);
465 dvb_dmx_release(&adap->demux);
467 dvb_unregister_adapter(&adap->dvb_adap);
468 err_dvb_register_adapter:
469 adap->dvb_adap.priv = NULL;
473 static int dvb_usbv2_adapter_dvb_exit(struct dvb_usb_adapter *adap)
475 dev_dbg(&adap_to_d(adap)->udev->dev, "%s: adap=%d\n", __func__,
478 if (adap->dvb_adap.priv) {
479 dvb_net_release(&adap->dvb_net);
480 adap->demux.dmx.close(&adap->demux.dmx);
481 dvb_dmxdev_release(&adap->dmxdev);
482 dvb_dmx_release(&adap->demux);
483 dvb_unregister_adapter(&adap->dvb_adap);
489 static int dvb_usbv2_device_power_ctrl(struct dvb_usb_device *d, int onoff)
498 if (d->powered == 0 || (onoff && d->powered == 1)) {
499 /* when switching from 1 to 0 or from 0 to 1 */
500 dev_dbg(&d->udev->dev, "%s: power=%d\n", __func__, onoff);
501 if (d->props->power_ctrl) {
502 ret = d->props->power_ctrl(d, onoff);
510 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
514 static int dvb_usb_fe_init(struct dvb_frontend *fe)
517 struct dvb_usb_adapter *adap = fe->dvb->priv;
518 struct dvb_usb_device *d = adap_to_d(adap);
519 dev_dbg(&d->udev->dev, "%s: adap=%d fe=%d\n", __func__, adap->id,
522 if (!adap->suspend_resume_active) {
523 adap->active_fe = fe->id;
524 set_bit(ADAP_INIT, &adap->state_bits);
527 ret = dvb_usbv2_device_power_ctrl(d, 1);
531 if (d->props->frontend_ctrl) {
532 ret = d->props->frontend_ctrl(fe, 1);
537 if (adap->fe_init[fe->id]) {
538 ret = adap->fe_init[fe->id](fe);
543 if (!adap->suspend_resume_active) {
544 clear_bit(ADAP_INIT, &adap->state_bits);
545 smp_mb__after_atomic();
546 wake_up_bit(&adap->state_bits, ADAP_INIT);
549 dev_dbg(&d->udev->dev, "%s: ret=%d\n", __func__, ret);
553 static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
556 struct dvb_usb_adapter *adap = fe->dvb->priv;
557 struct dvb_usb_device *d = adap_to_d(adap);
558 dev_dbg(&d->udev->dev, "%s: adap=%d fe=%d\n", __func__, adap->id,
561 if (!adap->suspend_resume_active) {
562 set_bit(ADAP_SLEEP, &adap->state_bits);
563 wait_on_bit(&adap->state_bits, ADAP_STREAMING,
564 TASK_UNINTERRUPTIBLE);
567 if (adap->fe_sleep[fe->id]) {
568 ret = adap->fe_sleep[fe->id](fe);
573 if (d->props->frontend_ctrl) {
574 ret = d->props->frontend_ctrl(fe, 0);
579 ret = dvb_usbv2_device_power_ctrl(d, 0);
583 if (!adap->suspend_resume_active) {
584 adap->active_fe = -1;
585 clear_bit(ADAP_SLEEP, &adap->state_bits);
586 smp_mb__after_atomic();
587 wake_up_bit(&adap->state_bits, ADAP_SLEEP);
590 dev_dbg(&d->udev->dev, "%s: ret=%d\n", __func__, ret);
594 static int dvb_usbv2_adapter_frontend_init(struct dvb_usb_adapter *adap)
596 int ret, i, count_registered = 0;
597 struct dvb_usb_device *d = adap_to_d(adap);
598 dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, adap->id);
600 memset(adap->fe, 0, sizeof(adap->fe));
601 adap->active_fe = -1;
603 if (d->props->frontend_attach) {
604 ret = d->props->frontend_attach(adap);
606 dev_dbg(&d->udev->dev,
607 "%s: frontend_attach() failed=%d\n",
609 goto err_dvb_frontend_detach;
612 dev_dbg(&d->udev->dev, "%s: frontend_attach() do not exists\n",
618 for (i = 0; i < MAX_NO_OF_FE_PER_ADAP && adap->fe[i]; i++) {
620 /* re-assign sleep and wakeup functions */
621 adap->fe_init[i] = adap->fe[i]->ops.init;
622 adap->fe[i]->ops.init = dvb_usb_fe_init;
623 adap->fe_sleep[i] = adap->fe[i]->ops.sleep;
624 adap->fe[i]->ops.sleep = dvb_usb_fe_sleep;
626 ret = dvb_register_frontend(&adap->dvb_adap, adap->fe[i]);
628 dev_err(&d->udev->dev,
629 "%s: frontend%d registration failed\n",
631 goto err_dvb_unregister_frontend;
637 if (d->props->tuner_attach) {
638 ret = d->props->tuner_attach(adap);
640 dev_dbg(&d->udev->dev, "%s: tuner_attach() failed=%d\n",
642 goto err_dvb_unregister_frontend;
648 err_dvb_unregister_frontend:
649 for (i = count_registered - 1; i >= 0; i--)
650 dvb_unregister_frontend(adap->fe[i]);
652 err_dvb_frontend_detach:
653 for (i = MAX_NO_OF_FE_PER_ADAP - 1; i >= 0; i--) {
655 dvb_frontend_detach(adap->fe[i]);
661 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
665 static int dvb_usbv2_adapter_frontend_exit(struct dvb_usb_adapter *adap)
668 struct dvb_usb_device *d = adap_to_d(adap);
670 dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, adap->id);
672 for (i = MAX_NO_OF_FE_PER_ADAP - 1; i >= 0; i--) {
674 dvb_unregister_frontend(adap->fe[i]);
675 dvb_frontend_detach(adap->fe[i]);
679 if (d->props->tuner_detach) {
680 ret = d->props->tuner_detach(adap);
682 dev_dbg(&d->udev->dev, "%s: tuner_detach() failed=%d\n",
687 if (d->props->frontend_detach) {
688 ret = d->props->frontend_detach(adap);
690 dev_dbg(&d->udev->dev,
691 "%s: frontend_detach() failed=%d\n",
699 static int dvb_usbv2_adapter_init(struct dvb_usb_device *d)
701 struct dvb_usb_adapter *adap;
702 int ret, i, adapter_count;
704 /* resolve adapter count */
705 adapter_count = d->props->num_adapters;
706 if (d->props->get_adapter_count) {
707 ret = d->props->get_adapter_count(d);
714 for (i = 0; i < adapter_count; i++) {
715 adap = &d->adapter[i];
717 adap->props = &d->props->adapter[i];
719 /* speed - when running at FULL speed we need a HW PID filter */
720 if (d->udev->speed == USB_SPEED_FULL &&
721 !(adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER)) {
722 dev_err(&d->udev->dev,
723 "%s: this USB2.0 device cannot be run on a USB1.1 port (it lacks a hardware PID filter)\n",
727 } else if ((d->udev->speed == USB_SPEED_FULL &&
728 adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER) ||
729 (adap->props->caps & DVB_USB_ADAP_NEED_PID_FILTERING)) {
730 dev_info(&d->udev->dev,
731 "%s: will use the device's hardware PID filter (table count: %d)\n",
733 adap->props->pid_filter_count);
734 adap->pid_filtering = 1;
735 adap->max_feed_count = adap->props->pid_filter_count;
737 dev_info(&d->udev->dev,
738 "%s: will pass the complete MPEG2 transport stream to the software demuxer\n",
740 adap->pid_filtering = 0;
741 adap->max_feed_count = 255;
744 if (!adap->pid_filtering && dvb_usb_force_pid_filter_usage &&
745 adap->props->caps & DVB_USB_ADAP_HAS_PID_FILTER) {
746 dev_info(&d->udev->dev,
747 "%s: PID filter enabled by module option\n",
749 adap->pid_filtering = 1;
750 adap->max_feed_count = adap->props->pid_filter_count;
753 ret = dvb_usbv2_adapter_stream_init(adap);
757 ret = dvb_usbv2_adapter_dvb_init(adap);
761 ret = dvb_usbv2_adapter_frontend_init(adap);
765 /* use exclusive FE lock if there is multiple shared FEs */
767 adap->dvb_adap.mfe_shared = 1;
772 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
776 static int dvb_usbv2_adapter_exit(struct dvb_usb_device *d)
779 dev_dbg(&d->udev->dev, "%s:\n", __func__);
781 for (i = MAX_NO_OF_ADAPTER_PER_DEVICE - 1; i >= 0; i--) {
782 if (d->adapter[i].props) {
783 dvb_usbv2_adapter_dvb_exit(&d->adapter[i]);
784 dvb_usbv2_adapter_stream_exit(&d->adapter[i]);
785 dvb_usbv2_adapter_frontend_exit(&d->adapter[i]);
792 /* general initialization functions */
793 static int dvb_usbv2_exit(struct dvb_usb_device *d)
795 dev_dbg(&d->udev->dev, "%s:\n", __func__);
797 dvb_usbv2_remote_exit(d);
798 dvb_usbv2_adapter_exit(d);
799 dvb_usbv2_i2c_exit(d);
806 static int dvb_usbv2_init(struct dvb_usb_device *d)
809 dev_dbg(&d->udev->dev, "%s:\n", __func__);
811 dvb_usbv2_device_power_ctrl(d, 1);
813 if (d->props->read_config) {
814 ret = d->props->read_config(d);
819 ret = dvb_usbv2_i2c_init(d);
823 ret = dvb_usbv2_adapter_init(d);
827 if (d->props->init) {
828 ret = d->props->init(d);
833 ret = dvb_usbv2_remote_init(d);
837 dvb_usbv2_device_power_ctrl(d, 0);
841 dvb_usbv2_device_power_ctrl(d, 0);
842 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
846 int dvb_usbv2_probe(struct usb_interface *intf,
847 const struct usb_device_id *id)
850 struct dvb_usb_device *d;
851 struct usb_device *udev = interface_to_usbdev(intf);
852 struct dvb_usb_driver_info *driver_info =
853 (struct dvb_usb_driver_info *) id->driver_info;
855 dev_dbg(&udev->dev, "%s: bInterfaceNumber=%d\n", __func__,
856 intf->cur_altsetting->desc.bInterfaceNumber);
858 if (!id->driver_info) {
859 dev_err(&udev->dev, "%s: driver_info failed\n", KBUILD_MODNAME);
864 d = kzalloc(sizeof(struct dvb_usb_device), GFP_KERNEL);
866 dev_err(&udev->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME);
872 d->name = driver_info->name;
873 d->rc_map = driver_info->rc_map;
875 d->props = driver_info->props;
877 if (intf->cur_altsetting->desc.bInterfaceNumber !=
878 d->props->bInterfaceNumber) {
883 mutex_init(&d->usb_mutex);
884 mutex_init(&d->i2c_mutex);
886 if (d->props->size_of_priv) {
887 d->priv = kzalloc(d->props->size_of_priv, GFP_KERNEL);
889 dev_err(&d->udev->dev, "%s: kzalloc() failed\n",
896 if (d->props->identify_state) {
897 const char *name = NULL;
898 ret = d->props->identify_state(d, &name);
901 } else if (ret == COLD) {
902 dev_info(&d->udev->dev,
903 "%s: found a '%s' in cold state\n",
904 KBUILD_MODNAME, d->name);
907 name = d->props->firmware;
909 ret = dvb_usbv2_download_firmware(d, name);
911 /* device is warm, continue initialization */
913 } else if (ret == RECONNECTS_USB) {
915 * USB core will call disconnect() and then
916 * probe() as device reconnects itself from the
917 * USB bus. disconnect() will release all driver
918 * resources and probe() is called for 'new'
919 * device. As 'new' device is warm we should
920 * never go here again.
931 dev_info(&d->udev->dev, "%s: found a '%s' in warm state\n",
932 KBUILD_MODNAME, d->name);
934 ret = dvb_usbv2_init(d);
938 dev_info(&d->udev->dev,
939 "%s: '%s' successfully initialized and connected\n",
940 KBUILD_MODNAME, d->name);
942 usb_set_intfdata(intf, d);
948 dev_dbg(&udev->dev, "%s: failed=%d\n", __func__, ret);
951 EXPORT_SYMBOL(dvb_usbv2_probe);
953 void dvb_usbv2_disconnect(struct usb_interface *intf)
955 struct dvb_usb_device *d = usb_get_intfdata(intf);
956 const char *name = d->name;
957 struct device dev = d->udev->dev;
958 dev_dbg(&d->udev->dev, "%s: bInterfaceNumber=%d\n", __func__,
959 intf->cur_altsetting->desc.bInterfaceNumber);
966 dev_info(&dev, "%s: '%s' successfully deinitialized and disconnected\n",
967 KBUILD_MODNAME, name);
969 EXPORT_SYMBOL(dvb_usbv2_disconnect);
971 int dvb_usbv2_suspend(struct usb_interface *intf, pm_message_t msg)
973 struct dvb_usb_device *d = usb_get_intfdata(intf);
974 int ret = 0, i, active_fe;
975 struct dvb_frontend *fe;
976 dev_dbg(&d->udev->dev, "%s:\n", __func__);
978 /* stop remote controller poll */
979 if (d->rc_polling_active)
980 cancel_delayed_work_sync(&d->rc_query_work);
982 for (i = MAX_NO_OF_ADAPTER_PER_DEVICE - 1; i >= 0; i--) {
983 active_fe = d->adapter[i].active_fe;
984 if (d->adapter[i].dvb_adap.priv && active_fe != -1) {
985 fe = d->adapter[i].fe[active_fe];
986 d->adapter[i].suspend_resume_active = true;
988 if (d->props->streaming_ctrl)
989 d->props->streaming_ctrl(fe, 0);
991 /* stop usb streaming */
992 usb_urb_killv2(&d->adapter[i].stream);
994 ret = dvb_frontend_suspend(fe);
1000 EXPORT_SYMBOL(dvb_usbv2_suspend);
1002 static int dvb_usbv2_resume_common(struct dvb_usb_device *d)
1004 int ret = 0, i, active_fe;
1005 struct dvb_frontend *fe;
1006 dev_dbg(&d->udev->dev, "%s:\n", __func__);
1008 for (i = 0; i < MAX_NO_OF_ADAPTER_PER_DEVICE; i++) {
1009 active_fe = d->adapter[i].active_fe;
1010 if (d->adapter[i].dvb_adap.priv && active_fe != -1) {
1011 fe = d->adapter[i].fe[active_fe];
1013 ret = dvb_frontend_resume(fe);
1015 /* resume usb streaming */
1016 usb_urb_submitv2(&d->adapter[i].stream, NULL);
1018 if (d->props->streaming_ctrl)
1019 d->props->streaming_ctrl(fe, 1);
1021 d->adapter[i].suspend_resume_active = false;
1025 /* start remote controller poll */
1026 if (d->rc_polling_active)
1027 schedule_delayed_work(&d->rc_query_work,
1028 msecs_to_jiffies(d->rc.interval));
1033 int dvb_usbv2_resume(struct usb_interface *intf)
1035 struct dvb_usb_device *d = usb_get_intfdata(intf);
1036 dev_dbg(&d->udev->dev, "%s:\n", __func__);
1038 return dvb_usbv2_resume_common(d);
1040 EXPORT_SYMBOL(dvb_usbv2_resume);
1042 int dvb_usbv2_reset_resume(struct usb_interface *intf)
1044 struct dvb_usb_device *d = usb_get_intfdata(intf);
1046 dev_dbg(&d->udev->dev, "%s:\n", __func__);
1048 dvb_usbv2_device_power_ctrl(d, 1);
1053 ret = dvb_usbv2_resume_common(d);
1055 dvb_usbv2_device_power_ctrl(d, 0);
1059 EXPORT_SYMBOL(dvb_usbv2_reset_resume);
1061 MODULE_VERSION("2.0");
1062 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
1063 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1064 MODULE_DESCRIPTION("DVB USB common");
1065 MODULE_LICENSE("GPL");