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 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_protos
= 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 wait_schedule(void *ptr
)
263 static int dvb_usb_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
265 struct dvb_usb_adapter
*adap
= dvbdmxfeed
->demux
->priv
;
266 struct dvb_usb_device
*d
= adap_to_d(adap
);
268 struct usb_data_stream_properties stream_props
;
269 dev_dbg(&d
->udev
->dev
,
270 "%s: adap=%d active_fe=%d feed_type=%d setting pid [%s]: %04x (%04d) at index %d\n",
271 __func__
, adap
->id
, adap
->active_fe
, dvbdmxfeed
->type
,
272 adap
->pid_filtering
? "yes" : "no", dvbdmxfeed
->pid
,
273 dvbdmxfeed
->pid
, dvbdmxfeed
->index
);
275 /* wait init is done */
276 wait_on_bit(&adap
->state_bits
, ADAP_INIT
, wait_schedule
,
277 TASK_UNINTERRUPTIBLE
);
279 if (adap
->active_fe
== -1)
282 /* skip feed setup if we are already feeding */
283 if (adap
->feed_count
++ > 0)
284 goto skip_feed_start
;
286 /* set 'streaming' status bit */
287 set_bit(ADAP_STREAMING
, &adap
->state_bits
);
289 /* resolve input and output streaming parameters */
290 if (d
->props
->get_stream_config
) {
291 memcpy(&stream_props
, &adap
->props
->stream
,
292 sizeof(struct usb_data_stream_properties
));
293 ret
= d
->props
->get_stream_config(adap
->fe
[adap
->active_fe
],
294 &adap
->ts_type
, &stream_props
);
296 dev_err(&d
->udev
->dev
,
297 "%s: get_stream_config() failed=%d\n",
298 KBUILD_MODNAME
, ret
);
300 stream_props
= adap
->props
->stream
;
303 switch (adap
->ts_type
) {
304 case DVB_USB_FE_TS_TYPE_204
:
305 adap
->stream
.complete
= dvb_usb_data_complete_204
;
307 case DVB_USB_FE_TS_TYPE_RAW
:
308 adap
->stream
.complete
= dvb_usb_data_complete_raw
;
310 case DVB_USB_FE_TS_TYPE_188
:
312 adap
->stream
.complete
= dvb_usb_data_complete
;
316 /* submit USB streaming packets */
317 usb_urb_submitv2(&adap
->stream
, &stream_props
);
319 /* enable HW PID filter */
320 if (adap
->pid_filtering
&& adap
->props
->pid_filter_ctrl
) {
321 ret
= adap
->props
->pid_filter_ctrl(adap
, 1);
323 dev_err(&d
->udev
->dev
,
324 "%s: pid_filter_ctrl() failed=%d\n",
325 KBUILD_MODNAME
, ret
);
328 /* ask device to start streaming */
329 if (d
->props
->streaming_ctrl
) {
330 ret
= d
->props
->streaming_ctrl(adap
->fe
[adap
->active_fe
], 1);
332 dev_err(&d
->udev
->dev
,
333 "%s: streaming_ctrl() failed=%d\n",
334 KBUILD_MODNAME
, ret
);
338 /* add PID to device HW PID filter */
339 if (adap
->pid_filtering
&& adap
->props
->pid_filter
) {
340 ret
= adap
->props
->pid_filter(adap
, dvbdmxfeed
->index
,
343 dev_err(&d
->udev
->dev
, "%s: pid_filter() failed=%d\n",
344 KBUILD_MODNAME
, ret
);
348 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
352 static int dvb_usb_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
354 struct dvb_usb_adapter
*adap
= dvbdmxfeed
->demux
->priv
;
355 struct dvb_usb_device
*d
= adap_to_d(adap
);
357 dev_dbg(&d
->udev
->dev
,
358 "%s: adap=%d active_fe=%d feed_type=%d setting pid [%s]: %04x (%04d) at index %d\n",
359 __func__
, adap
->id
, adap
->active_fe
, dvbdmxfeed
->type
,
360 adap
->pid_filtering
? "yes" : "no", dvbdmxfeed
->pid
,
361 dvbdmxfeed
->pid
, dvbdmxfeed
->index
);
363 if (adap
->active_fe
== -1)
366 /* remove PID from device HW PID filter */
367 if (adap
->pid_filtering
&& adap
->props
->pid_filter
) {
368 ret
= adap
->props
->pid_filter(adap
, dvbdmxfeed
->index
,
371 dev_err(&d
->udev
->dev
, "%s: pid_filter() failed=%d\n",
372 KBUILD_MODNAME
, ret
);
375 /* we cannot stop streaming until last PID is removed */
376 if (--adap
->feed_count
> 0)
379 /* ask device to stop streaming */
380 if (d
->props
->streaming_ctrl
) {
381 ret
= d
->props
->streaming_ctrl(adap
->fe
[adap
->active_fe
], 0);
383 dev_err(&d
->udev
->dev
,
384 "%s: streaming_ctrl() failed=%d\n",
385 KBUILD_MODNAME
, ret
);
388 /* disable HW PID filter */
389 if (adap
->pid_filtering
&& adap
->props
->pid_filter_ctrl
) {
390 ret
= adap
->props
->pid_filter_ctrl(adap
, 0);
392 dev_err(&d
->udev
->dev
,
393 "%s: pid_filter_ctrl() failed=%d\n",
394 KBUILD_MODNAME
, ret
);
397 /* kill USB streaming packets */
398 usb_urb_killv2(&adap
->stream
);
400 /* clear 'streaming' status bit */
401 clear_bit(ADAP_STREAMING
, &adap
->state_bits
);
402 smp_mb__after_clear_bit();
403 wake_up_bit(&adap
->state_bits
, ADAP_STREAMING
);
407 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
411 static int dvb_usbv2_adapter_dvb_init(struct dvb_usb_adapter
*adap
)
414 struct dvb_usb_device
*d
= adap_to_d(adap
);
415 dev_dbg(&d
->udev
->dev
, "%s: adap=%d\n", __func__
, adap
->id
);
417 ret
= dvb_register_adapter(&adap
->dvb_adap
, d
->name
, d
->props
->owner
,
418 &d
->udev
->dev
, d
->props
->adapter_nr
);
420 dev_dbg(&d
->udev
->dev
, "%s: dvb_register_adapter() failed=%d\n",
422 goto err_dvb_register_adapter
;
425 adap
->dvb_adap
.priv
= adap
;
427 if (d
->props
->read_mac_address
) {
428 ret
= d
->props
->read_mac_address(adap
,
429 adap
->dvb_adap
.proposed_mac
);
431 goto err_dvb_dmx_init
;
433 dev_info(&d
->udev
->dev
, "%s: MAC address: %pM\n",
434 KBUILD_MODNAME
, adap
->dvb_adap
.proposed_mac
);
437 adap
->demux
.dmx
.capabilities
= DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
438 adap
->demux
.priv
= adap
;
439 adap
->demux
.filternum
= 0;
440 adap
->demux
.filternum
= adap
->max_feed_count
;
441 adap
->demux
.feednum
= adap
->demux
.filternum
;
442 adap
->demux
.start_feed
= dvb_usb_start_feed
;
443 adap
->demux
.stop_feed
= dvb_usb_stop_feed
;
444 adap
->demux
.write_to_decoder
= NULL
;
445 ret
= dvb_dmx_init(&adap
->demux
);
447 dev_err(&d
->udev
->dev
, "%s: dvb_dmx_init() failed=%d\n",
448 KBUILD_MODNAME
, ret
);
449 goto err_dvb_dmx_init
;
452 adap
->dmxdev
.filternum
= adap
->demux
.filternum
;
453 adap
->dmxdev
.demux
= &adap
->demux
.dmx
;
454 adap
->dmxdev
.capabilities
= 0;
455 ret
= dvb_dmxdev_init(&adap
->dmxdev
, &adap
->dvb_adap
);
457 dev_err(&d
->udev
->dev
, "%s: dvb_dmxdev_init() failed=%d\n",
458 KBUILD_MODNAME
, ret
);
459 goto err_dvb_dmxdev_init
;
462 ret
= dvb_net_init(&adap
->dvb_adap
, &adap
->dvb_net
, &adap
->demux
.dmx
);
464 dev_err(&d
->udev
->dev
, "%s: dvb_net_init() failed=%d\n",
465 KBUILD_MODNAME
, ret
);
466 goto err_dvb_net_init
;
471 dvb_dmxdev_release(&adap
->dmxdev
);
473 dvb_dmx_release(&adap
->demux
);
475 dvb_unregister_adapter(&adap
->dvb_adap
);
476 err_dvb_register_adapter
:
477 adap
->dvb_adap
.priv
= NULL
;
481 static int dvb_usbv2_adapter_dvb_exit(struct dvb_usb_adapter
*adap
)
483 dev_dbg(&adap_to_d(adap
)->udev
->dev
, "%s: adap=%d\n", __func__
,
486 if (adap
->dvb_adap
.priv
) {
487 dvb_net_release(&adap
->dvb_net
);
488 adap
->demux
.dmx
.close(&adap
->demux
.dmx
);
489 dvb_dmxdev_release(&adap
->dmxdev
);
490 dvb_dmx_release(&adap
->demux
);
491 dvb_unregister_adapter(&adap
->dvb_adap
);
497 static int dvb_usbv2_device_power_ctrl(struct dvb_usb_device
*d
, int onoff
)
506 if (d
->powered
== 0 || (onoff
&& d
->powered
== 1)) {
507 /* when switching from 1 to 0 or from 0 to 1 */
508 dev_dbg(&d
->udev
->dev
, "%s: power=%d\n", __func__
, onoff
);
509 if (d
->props
->power_ctrl
) {
510 ret
= d
->props
->power_ctrl(d
, onoff
);
518 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
522 static int dvb_usb_fe_init(struct dvb_frontend
*fe
)
525 struct dvb_usb_adapter
*adap
= fe
->dvb
->priv
;
526 struct dvb_usb_device
*d
= adap_to_d(adap
);
527 dev_dbg(&d
->udev
->dev
, "%s: adap=%d fe=%d\n", __func__
, adap
->id
,
530 if (!adap
->suspend_resume_active
) {
531 adap
->active_fe
= fe
->id
;
532 set_bit(ADAP_INIT
, &adap
->state_bits
);
535 ret
= dvb_usbv2_device_power_ctrl(d
, 1);
539 if (d
->props
->frontend_ctrl
) {
540 ret
= d
->props
->frontend_ctrl(fe
, 1);
545 if (adap
->fe_init
[fe
->id
]) {
546 ret
= adap
->fe_init
[fe
->id
](fe
);
551 if (!adap
->suspend_resume_active
) {
552 clear_bit(ADAP_INIT
, &adap
->state_bits
);
553 smp_mb__after_clear_bit();
554 wake_up_bit(&adap
->state_bits
, ADAP_INIT
);
557 dev_dbg(&d
->udev
->dev
, "%s: ret=%d\n", __func__
, ret
);
561 static int dvb_usb_fe_sleep(struct dvb_frontend
*fe
)
564 struct dvb_usb_adapter
*adap
= fe
->dvb
->priv
;
565 struct dvb_usb_device
*d
= adap_to_d(adap
);
566 dev_dbg(&d
->udev
->dev
, "%s: adap=%d fe=%d\n", __func__
, adap
->id
,
569 if (!adap
->suspend_resume_active
) {
570 set_bit(ADAP_SLEEP
, &adap
->state_bits
);
571 wait_on_bit(&adap
->state_bits
, ADAP_STREAMING
, wait_schedule
,
572 TASK_UNINTERRUPTIBLE
);
575 if (adap
->fe_sleep
[fe
->id
]) {
576 ret
= adap
->fe_sleep
[fe
->id
](fe
);
581 if (d
->props
->frontend_ctrl
) {
582 ret
= d
->props
->frontend_ctrl(fe
, 0);
587 ret
= dvb_usbv2_device_power_ctrl(d
, 0);
591 if (!adap
->suspend_resume_active
) {
592 adap
->active_fe
= -1;
593 clear_bit(ADAP_SLEEP
, &adap
->state_bits
);
594 smp_mb__after_clear_bit();
595 wake_up_bit(&adap
->state_bits
, ADAP_SLEEP
);
598 dev_dbg(&d
->udev
->dev
, "%s: ret=%d\n", __func__
, ret
);
602 static int dvb_usbv2_adapter_frontend_init(struct dvb_usb_adapter
*adap
)
604 int ret
, i
, count_registered
= 0;
605 struct dvb_usb_device
*d
= adap_to_d(adap
);
606 dev_dbg(&d
->udev
->dev
, "%s: adap=%d\n", __func__
, adap
->id
);
608 memset(adap
->fe
, 0, sizeof(adap
->fe
));
609 adap
->active_fe
= -1;
611 if (d
->props
->frontend_attach
) {
612 ret
= d
->props
->frontend_attach(adap
);
614 dev_dbg(&d
->udev
->dev
,
615 "%s: frontend_attach() failed=%d\n",
617 goto err_dvb_frontend_detach
;
620 dev_dbg(&d
->udev
->dev
, "%s: frontend_attach() do not exists\n",
626 for (i
= 0; i
< MAX_NO_OF_FE_PER_ADAP
&& adap
->fe
[i
]; i
++) {
628 /* re-assign sleep and wakeup functions */
629 adap
->fe_init
[i
] = adap
->fe
[i
]->ops
.init
;
630 adap
->fe
[i
]->ops
.init
= dvb_usb_fe_init
;
631 adap
->fe_sleep
[i
] = adap
->fe
[i
]->ops
.sleep
;
632 adap
->fe
[i
]->ops
.sleep
= dvb_usb_fe_sleep
;
634 ret
= dvb_register_frontend(&adap
->dvb_adap
, adap
->fe
[i
]);
636 dev_err(&d
->udev
->dev
,
637 "%s: frontend%d registration failed\n",
639 goto err_dvb_unregister_frontend
;
645 if (d
->props
->tuner_attach
) {
646 ret
= d
->props
->tuner_attach(adap
);
648 dev_dbg(&d
->udev
->dev
, "%s: tuner_attach() failed=%d\n",
650 goto err_dvb_unregister_frontend
;
656 err_dvb_unregister_frontend
:
657 for (i
= count_registered
- 1; i
>= 0; i
--)
658 dvb_unregister_frontend(adap
->fe
[i
]);
660 err_dvb_frontend_detach
:
661 for (i
= MAX_NO_OF_FE_PER_ADAP
- 1; i
>= 0; i
--) {
663 dvb_frontend_detach(adap
->fe
[i
]);
669 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
673 static int dvb_usbv2_adapter_frontend_exit(struct dvb_usb_adapter
*adap
)
676 dev_dbg(&adap_to_d(adap
)->udev
->dev
, "%s: adap=%d\n", __func__
,
679 for (i
= MAX_NO_OF_FE_PER_ADAP
- 1; i
>= 0; i
--) {
681 dvb_unregister_frontend(adap
->fe
[i
]);
682 dvb_frontend_detach(adap
->fe
[i
]);
689 static int dvb_usbv2_adapter_init(struct dvb_usb_device
*d
)
691 struct dvb_usb_adapter
*adap
;
692 int ret
, i
, adapter_count
;
694 /* resolve adapter count */
695 adapter_count
= d
->props
->num_adapters
;
696 if (d
->props
->get_adapter_count
) {
697 ret
= d
->props
->get_adapter_count(d
);
704 for (i
= 0; i
< adapter_count
; i
++) {
705 adap
= &d
->adapter
[i
];
707 adap
->props
= &d
->props
->adapter
[i
];
709 /* speed - when running at FULL speed we need a HW PID filter */
710 if (d
->udev
->speed
== USB_SPEED_FULL
&&
711 !(adap
->props
->caps
& DVB_USB_ADAP_HAS_PID_FILTER
)) {
712 dev_err(&d
->udev
->dev
,
713 "%s: this USB2.0 device cannot be run on a USB1.1 port (it lacks a hardware PID filter)\n",
717 } else if ((d
->udev
->speed
== USB_SPEED_FULL
&&
718 adap
->props
->caps
& DVB_USB_ADAP_HAS_PID_FILTER
) ||
719 (adap
->props
->caps
& DVB_USB_ADAP_NEED_PID_FILTERING
)) {
720 dev_info(&d
->udev
->dev
,
721 "%s: will use the device's hardware PID filter (table count: %d)\n",
723 adap
->props
->pid_filter_count
);
724 adap
->pid_filtering
= 1;
725 adap
->max_feed_count
= adap
->props
->pid_filter_count
;
727 dev_info(&d
->udev
->dev
,
728 "%s: will pass the complete MPEG2 transport stream to the software demuxer\n",
730 adap
->pid_filtering
= 0;
731 adap
->max_feed_count
= 255;
734 if (!adap
->pid_filtering
&& dvb_usb_force_pid_filter_usage
&&
735 adap
->props
->caps
& DVB_USB_ADAP_HAS_PID_FILTER
) {
736 dev_info(&d
->udev
->dev
,
737 "%s: PID filter enabled by module option\n",
739 adap
->pid_filtering
= 1;
740 adap
->max_feed_count
= adap
->props
->pid_filter_count
;
743 ret
= dvb_usbv2_adapter_stream_init(adap
);
747 ret
= dvb_usbv2_adapter_dvb_init(adap
);
751 ret
= dvb_usbv2_adapter_frontend_init(adap
);
755 /* use exclusive FE lock if there is multiple shared FEs */
757 adap
->dvb_adap
.mfe_shared
= 1;
762 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
766 static int dvb_usbv2_adapter_exit(struct dvb_usb_device
*d
)
769 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
771 for (i
= MAX_NO_OF_ADAPTER_PER_DEVICE
- 1; i
>= 0; i
--) {
772 if (d
->adapter
[i
].props
) {
773 dvb_usbv2_adapter_frontend_exit(&d
->adapter
[i
]);
774 dvb_usbv2_adapter_dvb_exit(&d
->adapter
[i
]);
775 dvb_usbv2_adapter_stream_exit(&d
->adapter
[i
]);
782 /* general initialization functions */
783 static int dvb_usbv2_exit(struct dvb_usb_device
*d
)
785 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
787 dvb_usbv2_remote_exit(d
);
788 dvb_usbv2_adapter_exit(d
);
789 dvb_usbv2_i2c_exit(d
);
796 static int dvb_usbv2_init(struct dvb_usb_device
*d
)
799 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
801 dvb_usbv2_device_power_ctrl(d
, 1);
803 if (d
->props
->read_config
) {
804 ret
= d
->props
->read_config(d
);
809 ret
= dvb_usbv2_i2c_init(d
);
813 ret
= dvb_usbv2_adapter_init(d
);
817 if (d
->props
->init
) {
818 ret
= d
->props
->init(d
);
823 ret
= dvb_usbv2_remote_init(d
);
827 dvb_usbv2_device_power_ctrl(d
, 0);
831 dvb_usbv2_device_power_ctrl(d
, 0);
832 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
836 int dvb_usbv2_probe(struct usb_interface
*intf
,
837 const struct usb_device_id
*id
)
840 struct dvb_usb_device
*d
;
841 struct usb_device
*udev
= interface_to_usbdev(intf
);
842 struct dvb_usb_driver_info
*driver_info
=
843 (struct dvb_usb_driver_info
*) id
->driver_info
;
845 dev_dbg(&udev
->dev
, "%s: bInterfaceNumber=%d\n", __func__
,
846 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
848 if (!id
->driver_info
) {
849 dev_err(&udev
->dev
, "%s: driver_info failed\n", KBUILD_MODNAME
);
854 d
= kzalloc(sizeof(struct dvb_usb_device
), GFP_KERNEL
);
856 dev_err(&udev
->dev
, "%s: kzalloc() failed\n", KBUILD_MODNAME
);
861 d
->name
= driver_info
->name
;
862 d
->rc_map
= driver_info
->rc_map
;
864 d
->props
= driver_info
->props
;
866 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
!=
867 d
->props
->bInterfaceNumber
) {
872 mutex_init(&d
->usb_mutex
);
873 mutex_init(&d
->i2c_mutex
);
875 if (d
->props
->size_of_priv
) {
876 d
->priv
= kzalloc(d
->props
->size_of_priv
, GFP_KERNEL
);
878 dev_err(&d
->udev
->dev
, "%s: kzalloc() failed\n",
885 if (d
->props
->identify_state
) {
886 const char *name
= NULL
;
887 ret
= d
->props
->identify_state(d
, &name
);
890 } else if (ret
== COLD
) {
891 dev_info(&d
->udev
->dev
,
892 "%s: found a '%s' in cold state\n",
893 KBUILD_MODNAME
, d
->name
);
896 name
= d
->props
->firmware
;
898 ret
= dvb_usbv2_download_firmware(d
, name
);
900 /* device is warm, continue initialization */
902 } else if (ret
== RECONNECTS_USB
) {
904 * USB core will call disconnect() and then
905 * probe() as device reconnects itself from the
906 * USB bus. disconnect() will release all driver
907 * resources and probe() is called for 'new'
908 * device. As 'new' device is warm we should
909 * never go here again.
920 dev_info(&d
->udev
->dev
, "%s: found a '%s' in warm state\n",
921 KBUILD_MODNAME
, d
->name
);
923 ret
= dvb_usbv2_init(d
);
927 dev_info(&d
->udev
->dev
,
928 "%s: '%s' successfully initialized and connected\n",
929 KBUILD_MODNAME
, d
->name
);
931 usb_set_intfdata(intf
, d
);
937 dev_dbg(&udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
940 EXPORT_SYMBOL(dvb_usbv2_probe
);
942 void dvb_usbv2_disconnect(struct usb_interface
*intf
)
944 struct dvb_usb_device
*d
= usb_get_intfdata(intf
);
945 const char *name
= d
->name
;
946 struct device dev
= d
->udev
->dev
;
947 dev_dbg(&d
->udev
->dev
, "%s: bInterfaceNumber=%d\n", __func__
,
948 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
955 dev_info(&dev
, "%s: '%s' successfully deinitialized and disconnected\n",
956 KBUILD_MODNAME
, name
);
958 EXPORT_SYMBOL(dvb_usbv2_disconnect
);
960 int dvb_usbv2_suspend(struct usb_interface
*intf
, pm_message_t msg
)
962 struct dvb_usb_device
*d
= usb_get_intfdata(intf
);
963 int ret
= 0, i
, active_fe
;
964 struct dvb_frontend
*fe
;
965 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
967 /* stop remote controller poll */
968 if (d
->rc_polling_active
)
969 cancel_delayed_work_sync(&d
->rc_query_work
);
971 for (i
= MAX_NO_OF_ADAPTER_PER_DEVICE
- 1; i
>= 0; i
--) {
972 active_fe
= d
->adapter
[i
].active_fe
;
973 if (d
->adapter
[i
].dvb_adap
.priv
&& active_fe
!= -1) {
974 fe
= d
->adapter
[i
].fe
[active_fe
];
975 d
->adapter
[i
].suspend_resume_active
= true;
977 if (d
->props
->streaming_ctrl
)
978 d
->props
->streaming_ctrl(fe
, 0);
980 /* stop usb streaming */
981 usb_urb_killv2(&d
->adapter
[i
].stream
);
983 ret
= dvb_frontend_suspend(fe
);
989 EXPORT_SYMBOL(dvb_usbv2_suspend
);
991 static int dvb_usbv2_resume_common(struct dvb_usb_device
*d
)
993 int ret
= 0, i
, active_fe
;
994 struct dvb_frontend
*fe
;
995 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
997 for (i
= 0; i
< MAX_NO_OF_ADAPTER_PER_DEVICE
; i
++) {
998 active_fe
= d
->adapter
[i
].active_fe
;
999 if (d
->adapter
[i
].dvb_adap
.priv
&& active_fe
!= -1) {
1000 fe
= d
->adapter
[i
].fe
[active_fe
];
1002 ret
= dvb_frontend_resume(fe
);
1004 /* resume usb streaming */
1005 usb_urb_submitv2(&d
->adapter
[i
].stream
, NULL
);
1007 if (d
->props
->streaming_ctrl
)
1008 d
->props
->streaming_ctrl(fe
, 1);
1010 d
->adapter
[i
].suspend_resume_active
= false;
1014 /* start remote controller poll */
1015 if (d
->rc_polling_active
)
1016 schedule_delayed_work(&d
->rc_query_work
,
1017 msecs_to_jiffies(d
->rc
.interval
));
1022 int dvb_usbv2_resume(struct usb_interface
*intf
)
1024 struct dvb_usb_device
*d
= usb_get_intfdata(intf
);
1025 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
1027 return dvb_usbv2_resume_common(d
);
1029 EXPORT_SYMBOL(dvb_usbv2_resume
);
1031 int dvb_usbv2_reset_resume(struct usb_interface
*intf
)
1033 struct dvb_usb_device
*d
= usb_get_intfdata(intf
);
1035 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
1037 dvb_usbv2_device_power_ctrl(d
, 1);
1042 ret
= dvb_usbv2_resume_common(d
);
1044 dvb_usbv2_device_power_ctrl(d
, 0);
1048 EXPORT_SYMBOL(dvb_usbv2_reset_resume
);
1050 MODULE_VERSION("2.0");
1051 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
1052 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1053 MODULE_DESCRIPTION("DVB USB common");
1054 MODULE_LICENSE("GPL");