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 rc_set_allowed_protocols(dev
, 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 dev_dbg(&adap_to_d(adap
)->udev
->dev
, "%s: adap=%d\n", __func__
,
671 for (i
= MAX_NO_OF_FE_PER_ADAP
- 1; i
>= 0; i
--) {
673 dvb_unregister_frontend(adap
->fe
[i
]);
674 dvb_frontend_detach(adap
->fe
[i
]);
681 static int dvb_usbv2_adapter_init(struct dvb_usb_device
*d
)
683 struct dvb_usb_adapter
*adap
;
684 int ret
, i
, adapter_count
;
686 /* resolve adapter count */
687 adapter_count
= d
->props
->num_adapters
;
688 if (d
->props
->get_adapter_count
) {
689 ret
= d
->props
->get_adapter_count(d
);
696 for (i
= 0; i
< adapter_count
; i
++) {
697 adap
= &d
->adapter
[i
];
699 adap
->props
= &d
->props
->adapter
[i
];
701 /* speed - when running at FULL speed we need a HW PID filter */
702 if (d
->udev
->speed
== USB_SPEED_FULL
&&
703 !(adap
->props
->caps
& DVB_USB_ADAP_HAS_PID_FILTER
)) {
704 dev_err(&d
->udev
->dev
,
705 "%s: this USB2.0 device cannot be run on a USB1.1 port (it lacks a hardware PID filter)\n",
709 } else if ((d
->udev
->speed
== USB_SPEED_FULL
&&
710 adap
->props
->caps
& DVB_USB_ADAP_HAS_PID_FILTER
) ||
711 (adap
->props
->caps
& DVB_USB_ADAP_NEED_PID_FILTERING
)) {
712 dev_info(&d
->udev
->dev
,
713 "%s: will use the device's hardware PID filter (table count: %d)\n",
715 adap
->props
->pid_filter_count
);
716 adap
->pid_filtering
= 1;
717 adap
->max_feed_count
= adap
->props
->pid_filter_count
;
719 dev_info(&d
->udev
->dev
,
720 "%s: will pass the complete MPEG2 transport stream to the software demuxer\n",
722 adap
->pid_filtering
= 0;
723 adap
->max_feed_count
= 255;
726 if (!adap
->pid_filtering
&& dvb_usb_force_pid_filter_usage
&&
727 adap
->props
->caps
& DVB_USB_ADAP_HAS_PID_FILTER
) {
728 dev_info(&d
->udev
->dev
,
729 "%s: PID filter enabled by module option\n",
731 adap
->pid_filtering
= 1;
732 adap
->max_feed_count
= adap
->props
->pid_filter_count
;
735 ret
= dvb_usbv2_adapter_stream_init(adap
);
739 ret
= dvb_usbv2_adapter_dvb_init(adap
);
743 ret
= dvb_usbv2_adapter_frontend_init(adap
);
747 /* use exclusive FE lock if there is multiple shared FEs */
749 adap
->dvb_adap
.mfe_shared
= 1;
754 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
758 static int dvb_usbv2_adapter_exit(struct dvb_usb_device
*d
)
761 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
763 for (i
= MAX_NO_OF_ADAPTER_PER_DEVICE
- 1; i
>= 0; i
--) {
764 if (d
->adapter
[i
].props
) {
765 dvb_usbv2_adapter_frontend_exit(&d
->adapter
[i
]);
766 dvb_usbv2_adapter_dvb_exit(&d
->adapter
[i
]);
767 dvb_usbv2_adapter_stream_exit(&d
->adapter
[i
]);
774 /* general initialization functions */
775 static int dvb_usbv2_exit(struct dvb_usb_device
*d
)
777 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
779 dvb_usbv2_remote_exit(d
);
780 dvb_usbv2_adapter_exit(d
);
781 dvb_usbv2_i2c_exit(d
);
788 static int dvb_usbv2_init(struct dvb_usb_device
*d
)
791 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
793 dvb_usbv2_device_power_ctrl(d
, 1);
795 if (d
->props
->read_config
) {
796 ret
= d
->props
->read_config(d
);
801 ret
= dvb_usbv2_i2c_init(d
);
805 ret
= dvb_usbv2_adapter_init(d
);
809 if (d
->props
->init
) {
810 ret
= d
->props
->init(d
);
815 ret
= dvb_usbv2_remote_init(d
);
819 dvb_usbv2_device_power_ctrl(d
, 0);
823 dvb_usbv2_device_power_ctrl(d
, 0);
824 dev_dbg(&d
->udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
828 int dvb_usbv2_probe(struct usb_interface
*intf
,
829 const struct usb_device_id
*id
)
832 struct dvb_usb_device
*d
;
833 struct usb_device
*udev
= interface_to_usbdev(intf
);
834 struct dvb_usb_driver_info
*driver_info
=
835 (struct dvb_usb_driver_info
*) id
->driver_info
;
837 dev_dbg(&udev
->dev
, "%s: bInterfaceNumber=%d\n", __func__
,
838 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
840 if (!id
->driver_info
) {
841 dev_err(&udev
->dev
, "%s: driver_info failed\n", KBUILD_MODNAME
);
846 d
= kzalloc(sizeof(struct dvb_usb_device
), GFP_KERNEL
);
848 dev_err(&udev
->dev
, "%s: kzalloc() failed\n", KBUILD_MODNAME
);
853 d
->name
= driver_info
->name
;
854 d
->rc_map
= driver_info
->rc_map
;
856 d
->props
= driver_info
->props
;
858 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
!=
859 d
->props
->bInterfaceNumber
) {
864 mutex_init(&d
->usb_mutex
);
865 mutex_init(&d
->i2c_mutex
);
867 if (d
->props
->size_of_priv
) {
868 d
->priv
= kzalloc(d
->props
->size_of_priv
, GFP_KERNEL
);
870 dev_err(&d
->udev
->dev
, "%s: kzalloc() failed\n",
877 if (d
->props
->identify_state
) {
878 const char *name
= NULL
;
879 ret
= d
->props
->identify_state(d
, &name
);
882 } else if (ret
== COLD
) {
883 dev_info(&d
->udev
->dev
,
884 "%s: found a '%s' in cold state\n",
885 KBUILD_MODNAME
, d
->name
);
888 name
= d
->props
->firmware
;
890 ret
= dvb_usbv2_download_firmware(d
, name
);
892 /* device is warm, continue initialization */
894 } else if (ret
== RECONNECTS_USB
) {
896 * USB core will call disconnect() and then
897 * probe() as device reconnects itself from the
898 * USB bus. disconnect() will release all driver
899 * resources and probe() is called for 'new'
900 * device. As 'new' device is warm we should
901 * never go here again.
912 dev_info(&d
->udev
->dev
, "%s: found a '%s' in warm state\n",
913 KBUILD_MODNAME
, d
->name
);
915 ret
= dvb_usbv2_init(d
);
919 dev_info(&d
->udev
->dev
,
920 "%s: '%s' successfully initialized and connected\n",
921 KBUILD_MODNAME
, d
->name
);
923 usb_set_intfdata(intf
, d
);
929 dev_dbg(&udev
->dev
, "%s: failed=%d\n", __func__
, ret
);
932 EXPORT_SYMBOL(dvb_usbv2_probe
);
934 void dvb_usbv2_disconnect(struct usb_interface
*intf
)
936 struct dvb_usb_device
*d
= usb_get_intfdata(intf
);
937 const char *name
= d
->name
;
938 struct device dev
= d
->udev
->dev
;
939 dev_dbg(&d
->udev
->dev
, "%s: bInterfaceNumber=%d\n", __func__
,
940 intf
->cur_altsetting
->desc
.bInterfaceNumber
);
947 dev_info(&dev
, "%s: '%s' successfully deinitialized and disconnected\n",
948 KBUILD_MODNAME
, name
);
950 EXPORT_SYMBOL(dvb_usbv2_disconnect
);
952 int dvb_usbv2_suspend(struct usb_interface
*intf
, pm_message_t msg
)
954 struct dvb_usb_device
*d
= usb_get_intfdata(intf
);
955 int ret
= 0, i
, active_fe
;
956 struct dvb_frontend
*fe
;
957 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
959 /* stop remote controller poll */
960 if (d
->rc_polling_active
)
961 cancel_delayed_work_sync(&d
->rc_query_work
);
963 for (i
= MAX_NO_OF_ADAPTER_PER_DEVICE
- 1; i
>= 0; i
--) {
964 active_fe
= d
->adapter
[i
].active_fe
;
965 if (d
->adapter
[i
].dvb_adap
.priv
&& active_fe
!= -1) {
966 fe
= d
->adapter
[i
].fe
[active_fe
];
967 d
->adapter
[i
].suspend_resume_active
= true;
969 if (d
->props
->streaming_ctrl
)
970 d
->props
->streaming_ctrl(fe
, 0);
972 /* stop usb streaming */
973 usb_urb_killv2(&d
->adapter
[i
].stream
);
975 ret
= dvb_frontend_suspend(fe
);
981 EXPORT_SYMBOL(dvb_usbv2_suspend
);
983 static int dvb_usbv2_resume_common(struct dvb_usb_device
*d
)
985 int ret
= 0, i
, active_fe
;
986 struct dvb_frontend
*fe
;
987 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
989 for (i
= 0; i
< MAX_NO_OF_ADAPTER_PER_DEVICE
; i
++) {
990 active_fe
= d
->adapter
[i
].active_fe
;
991 if (d
->adapter
[i
].dvb_adap
.priv
&& active_fe
!= -1) {
992 fe
= d
->adapter
[i
].fe
[active_fe
];
994 ret
= dvb_frontend_resume(fe
);
996 /* resume usb streaming */
997 usb_urb_submitv2(&d
->adapter
[i
].stream
, NULL
);
999 if (d
->props
->streaming_ctrl
)
1000 d
->props
->streaming_ctrl(fe
, 1);
1002 d
->adapter
[i
].suspend_resume_active
= false;
1006 /* start remote controller poll */
1007 if (d
->rc_polling_active
)
1008 schedule_delayed_work(&d
->rc_query_work
,
1009 msecs_to_jiffies(d
->rc
.interval
));
1014 int dvb_usbv2_resume(struct usb_interface
*intf
)
1016 struct dvb_usb_device
*d
= usb_get_intfdata(intf
);
1017 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
1019 return dvb_usbv2_resume_common(d
);
1021 EXPORT_SYMBOL(dvb_usbv2_resume
);
1023 int dvb_usbv2_reset_resume(struct usb_interface
*intf
)
1025 struct dvb_usb_device
*d
= usb_get_intfdata(intf
);
1027 dev_dbg(&d
->udev
->dev
, "%s:\n", __func__
);
1029 dvb_usbv2_device_power_ctrl(d
, 1);
1034 ret
= dvb_usbv2_resume_common(d
);
1036 dvb_usbv2_device_power_ctrl(d
, 0);
1040 EXPORT_SYMBOL(dvb_usbv2_reset_resume
);
1042 MODULE_VERSION("2.0");
1043 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
1044 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1045 MODULE_DESCRIPTION("DVB USB common");
1046 MODULE_LICENSE("GPL");