4 * Copyright (C) 2003-2004 Alex Woods <linux-dvb@giblets.org>
5 * IR support by Peter Beutner <p.beutner@gmx.net>
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.
19 #include <linux/list.h>
20 #include <linux/module.h>
21 #include <linux/pci.h>
22 #include <linux/slab.h>
23 #include <linux/spinlock.h>
24 #include <linux/usb.h>
25 #include <linux/interrupt.h>
26 #include <linux/firmware.h>
27 #include <linux/crc32.h>
28 #include <linux/init.h>
29 #include <linux/input.h>
31 #include <linux/mutex.h>
33 #include <media/dmxdev.h>
34 #include <media/dvb_demux.h>
35 #include <media/dvb_frontend.h>
36 #include <media/dvb_net.h>
37 #include "ttusbdecfe.h"
40 static int output_pva
;
43 module_param(debug
, int, 0644);
44 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
45 module_param(output_pva
, int, 0444);
46 MODULE_PARM_DESC(output_pva
, "Output PVA from dvr device (default:off)");
47 module_param(enable_rc
, int, 0644);
48 MODULE_PARM_DESC(enable_rc
, "Turn on/off IR remote control(default: off)");
50 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
52 #define dprintk if (debug) printk
54 #define DRIVER_NAME "TechnoTrend/Hauppauge DEC USB"
56 #define COMMAND_PIPE 0x03
57 #define RESULT_PIPE 0x04
62 #define COMMAND_PACKET_SIZE 0x3c
63 #define ARM_PACKET_SIZE 0x1000
64 #define IRQ_PACKET_SIZE 0x8
66 #define ISO_BUF_COUNT 0x04
67 #define FRAMES_PER_ISO_BUF 0x04
68 #define ISO_FRAME_SIZE 0x0380
70 #define MAX_PVA_LENGTH 6144
72 enum ttusb_dec_model
{
78 enum ttusb_dec_packet_type
{
80 TTUSB_DEC_PACKET_SECTION
,
81 TTUSB_DEC_PACKET_EMPTY
84 enum ttusb_dec_interface
{
85 TTUSB_DEC_INTERFACE_INITIAL
,
86 TTUSB_DEC_INTERFACE_IN
,
87 TTUSB_DEC_INTERFACE_OUT
90 typedef int (dvb_filter_pes2ts_cb_t
) (void *, unsigned char *);
92 struct dvb_filter_pes2ts
{
93 unsigned char buf
[188];
95 dvb_filter_pes2ts_cb_t
*cb
;
100 enum ttusb_dec_model model
;
106 struct dvb_adapter adapter
;
107 struct dmxdev dmxdev
;
108 struct dvb_demux demux
;
109 struct dmx_frontend frontend
;
110 struct dvb_net dvb_net
;
111 struct dvb_frontend
* fe
;
113 u16 pid
[DMX_PES_OTHER
];
116 struct usb_device
*udev
;
118 unsigned int command_pipe
;
119 unsigned int result_pipe
;
120 unsigned int in_pipe
;
121 unsigned int out_pipe
;
122 unsigned int irq_pipe
;
123 enum ttusb_dec_interface interface
;
124 struct mutex usb_mutex
;
128 dma_addr_t irq_dma_handle
;
130 struct urb
*iso_urb
[ISO_BUF_COUNT
];
131 int iso_stream_count
;
132 struct mutex iso_mutex
;
134 u8 packet
[MAX_PVA_LENGTH
+ 4];
135 enum ttusb_dec_packet_type packet_type
;
138 int packet_payload_length
;
141 int pva_stream_count
;
142 int filter_stream_count
;
144 struct dvb_filter_pes2ts a_pes2ts
;
145 struct dvb_filter_pes2ts v_pes2ts
;
147 u8 v_pes
[16 + MAX_PVA_LENGTH
];
151 struct list_head urb_frame_list
;
152 struct tasklet_struct urb_tasklet
;
153 spinlock_t urb_frame_list_lock
;
155 struct dvb_demux_filter
*audio_filter
;
156 struct dvb_demux_filter
*video_filter
;
157 struct list_head filter_info_list
;
158 spinlock_t filter_info_list_lock
;
160 struct input_dev
*rc_input_dev
;
163 int active
; /* Loaded successfully */
167 u8 data
[ISO_FRAME_SIZE
];
169 struct list_head urb_frame_list
;
174 struct dvb_demux_filter
*filter
;
175 struct list_head filter_info_list
;
178 static u16 rc_keys
[] = {
207 static void dvb_filter_pes2ts_init(struct dvb_filter_pes2ts
*p2ts
,
209 dvb_filter_pes2ts_cb_t
*cb
, void *priv
)
211 unsigned char *buf
=p2ts
->buf
;
221 static int dvb_filter_pes2ts(struct dvb_filter_pes2ts
*p2ts
,
222 unsigned char *pes
, int len
, int payload_start
)
224 unsigned char *buf
=p2ts
->buf
;
227 //len=6+((pes[4]<<8)|pes[5]);
234 buf
[3]=0x10|((p2ts
->cc
++)&0x0f);
235 memcpy(buf
+4, pes
, 184);
236 if ((ret
=p2ts
->cb(p2ts
->priv
, buf
)))
243 buf
[3]=0x30|((p2ts
->cc
++)&0x0f);
248 memset(buf
+6, 0xff, rest
-1);
251 memcpy(buf
+5+rest
, pes
, len
);
252 return p2ts
->cb(p2ts
->priv
, buf
);
255 static void ttusb_dec_set_model(struct ttusb_dec
*dec
,
256 enum ttusb_dec_model model
);
258 static void ttusb_dec_handle_irq( struct urb
*urb
)
260 struct ttusb_dec
*dec
= urb
->context
;
261 char *buffer
= dec
->irq_buffer
;
264 switch(urb
->status
) {
271 /* this urb is dead, cleanup */
272 dprintk("%s:urb shutting down with status: %d\n",
273 __func__
, urb
->status
);
276 dprintk("%s:nonzero status received: %d\n",
277 __func__
,urb
->status
);
281 if ((buffer
[0] == 0x1) && (buffer
[2] == 0x15)) {
285 * this is an fact a bit too simple implementation;
286 * the box also reports a keyrepeat signal
287 * (with buffer[3] == 0x40) in an intervall of ~100ms.
288 * But to handle this correctly we had to imlemenent some
289 * kind of timer which signals a 'key up' event if no
290 * keyrepeat signal is received for lets say 200ms.
291 * this should/could be added later ...
292 * for now lets report each signal as a key down and up
294 if (buffer
[4] - 1 < ARRAY_SIZE(rc_keys
)) {
295 dprintk("%s:rc signal:%d\n", __func__
, buffer
[4]);
296 input_report_key(dec
->rc_input_dev
, rc_keys
[buffer
[4] - 1], 1);
297 input_sync(dec
->rc_input_dev
);
298 input_report_key(dec
->rc_input_dev
, rc_keys
[buffer
[4] - 1], 0);
299 input_sync(dec
->rc_input_dev
);
304 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
306 printk("%s - usb_commit_urb failed with result: %d\n",
310 static u16
crc16(u16 crc
, const u8
*buf
, size_t len
)
318 crc
^= (tmp
^ (tmp
<< 1)) << 4;
323 static int ttusb_dec_send_command(struct ttusb_dec
*dec
, const u8 command
,
324 int param_length
, const u8 params
[],
325 int *result_length
, u8 cmd_result
[])
327 int result
, actual_len
;
330 dprintk("%s\n", __func__
);
332 b
= kmalloc(COMMAND_PACKET_SIZE
+ 4, GFP_KERNEL
);
336 if ((result
= mutex_lock_interruptible(&dec
->usb_mutex
))) {
338 printk("%s: Failed to lock usb mutex.\n", __func__
);
343 b
[1] = ++dec
->trans_count
;
348 memcpy(&b
[4], params
, param_length
);
351 printk(KERN_DEBUG
"%s: command: %*ph\n",
352 __func__
, param_length
, b
);
355 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
356 COMMAND_PACKET_SIZE
+ 4, &actual_len
, 1000);
359 printk("%s: command bulk message failed: error %d\n",
361 mutex_unlock(&dec
->usb_mutex
);
366 result
= usb_bulk_msg(dec
->udev
, dec
->result_pipe
, b
,
367 COMMAND_PACKET_SIZE
+ 4, &actual_len
, 1000);
370 printk("%s: result bulk message failed: error %d\n",
372 mutex_unlock(&dec
->usb_mutex
);
377 printk(KERN_DEBUG
"%s: result: %*ph\n",
378 __func__
, actual_len
, b
);
382 *result_length
= b
[3];
383 if (cmd_result
&& b
[3] > 0)
384 memcpy(cmd_result
, &b
[4], b
[3]);
386 mutex_unlock(&dec
->usb_mutex
);
393 static int ttusb_dec_get_stb_state (struct ttusb_dec
*dec
, unsigned int *mode
,
394 unsigned int *model
, unsigned int *version
)
396 u8 c
[COMMAND_PACKET_SIZE
];
401 dprintk("%s\n", __func__
);
403 result
= ttusb_dec_send_command(dec
, 0x08, 0, NULL
, &c_length
, c
);
407 if (c_length
>= 0x0c) {
413 memcpy(&tmp
, &c
[4], 4);
416 if (version
!= NULL
) {
417 memcpy(&tmp
, &c
[8], 4);
418 *version
= ntohl(tmp
);
426 static int ttusb_dec_audio_pes2ts_cb(void *priv
, unsigned char *data
)
428 struct ttusb_dec
*dec
= priv
;
430 dec
->audio_filter
->feed
->cb
.ts(data
, 188, NULL
, 0,
431 &dec
->audio_filter
->feed
->feed
.ts
);
436 static int ttusb_dec_video_pes2ts_cb(void *priv
, unsigned char *data
)
438 struct ttusb_dec
*dec
= priv
;
440 dec
->video_filter
->feed
->cb
.ts(data
, 188, NULL
, 0,
441 &dec
->video_filter
->feed
->feed
.ts
);
446 static void ttusb_dec_set_pids(struct ttusb_dec
*dec
)
448 u8 b
[] = { 0x00, 0x00, 0x00, 0x00,
449 0x00, 0x00, 0xff, 0xff,
450 0xff, 0xff, 0xff, 0xff };
452 __be16 pcr
= htons(dec
->pid
[DMX_PES_PCR
]);
453 __be16 audio
= htons(dec
->pid
[DMX_PES_AUDIO
]);
454 __be16 video
= htons(dec
->pid
[DMX_PES_VIDEO
]);
456 dprintk("%s\n", __func__
);
458 memcpy(&b
[0], &pcr
, 2);
459 memcpy(&b
[2], &audio
, 2);
460 memcpy(&b
[4], &video
, 2);
462 ttusb_dec_send_command(dec
, 0x50, sizeof(b
), b
, NULL
, NULL
);
464 dvb_filter_pes2ts_init(&dec
->a_pes2ts
, dec
->pid
[DMX_PES_AUDIO
],
465 ttusb_dec_audio_pes2ts_cb
, dec
);
466 dvb_filter_pes2ts_init(&dec
->v_pes2ts
, dec
->pid
[DMX_PES_VIDEO
],
467 ttusb_dec_video_pes2ts_cb
, dec
);
468 dec
->v_pes_length
= 0;
469 dec
->v_pes_postbytes
= 0;
472 static void ttusb_dec_process_pva(struct ttusb_dec
*dec
, u8
*pva
, int length
)
475 printk("%s: packet too short - discarding\n", __func__
);
479 if (length
> 8 + MAX_PVA_LENGTH
) {
480 printk("%s: packet too long - discarding\n", __func__
);
486 case 0x01: { /* VideoStream */
487 int prebytes
= pva
[5] & 0x03;
488 int postbytes
= (pva
[5] & 0x0c) >> 2;
489 __be16 v_pes_payload_length
;
492 dec
->video_filter
->feed
->cb
.ts(pva
, length
, NULL
, 0,
493 &dec
->video_filter
->feed
->feed
.ts
);
497 if (dec
->v_pes_postbytes
> 0 &&
498 dec
->v_pes_postbytes
== prebytes
) {
499 memcpy(&dec
->v_pes
[dec
->v_pes_length
],
502 dvb_filter_pes2ts(&dec
->v_pes2ts
, dec
->v_pes
,
503 dec
->v_pes_length
+ prebytes
, 1);
507 dec
->v_pes
[7] = 0x80;
508 dec
->v_pes
[8] = 0x05;
510 dec
->v_pes
[9] = 0x21 | ((pva
[8] & 0xc0) >> 5);
511 dec
->v_pes
[10] = ((pva
[8] & 0x3f) << 2) |
512 ((pva
[9] & 0xc0) >> 6);
513 dec
->v_pes
[11] = 0x01 |
514 ((pva
[9] & 0x3f) << 2) |
515 ((pva
[10] & 0x80) >> 6);
516 dec
->v_pes
[12] = ((pva
[10] & 0x7f) << 1) |
517 ((pva
[11] & 0xc0) >> 7);
518 dec
->v_pes
[13] = 0x01 | ((pva
[11] & 0x7f) << 1);
520 memcpy(&dec
->v_pes
[14], &pva
[12 + prebytes
],
521 length
- 12 - prebytes
);
522 dec
->v_pes_length
= 14 + length
- 12 - prebytes
;
524 dec
->v_pes
[7] = 0x00;
525 dec
->v_pes
[8] = 0x00;
527 memcpy(&dec
->v_pes
[9], &pva
[8], length
- 8);
528 dec
->v_pes_length
= 9 + length
- 8;
531 dec
->v_pes_postbytes
= postbytes
;
533 if (dec
->v_pes
[9 + dec
->v_pes
[8]] == 0x00 &&
534 dec
->v_pes
[10 + dec
->v_pes
[8]] == 0x00 &&
535 dec
->v_pes
[11 + dec
->v_pes
[8]] == 0x01)
536 dec
->v_pes
[6] = 0x84;
538 dec
->v_pes
[6] = 0x80;
540 v_pes_payload_length
= htons(dec
->v_pes_length
- 6 +
542 memcpy(&dec
->v_pes
[4], &v_pes_payload_length
, 2);
545 dvb_filter_pes2ts(&dec
->v_pes2ts
, dec
->v_pes
,
546 dec
->v_pes_length
, 1);
551 case 0x02: /* MainAudioStream */
553 dec
->audio_filter
->feed
->cb
.ts(pva
, length
, NULL
, 0,
554 &dec
->audio_filter
->feed
->feed
.ts
);
558 dvb_filter_pes2ts(&dec
->a_pes2ts
, &pva
[8], length
- 8,
563 printk("%s: unknown PVA type: %02x.\n", __func__
,
569 static void ttusb_dec_process_filter(struct ttusb_dec
*dec
, u8
*packet
,
572 struct list_head
*item
;
573 struct filter_info
*finfo
;
574 struct dvb_demux_filter
*filter
= NULL
;
579 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
580 for (item
= dec
->filter_info_list
.next
; item
!= &dec
->filter_info_list
;
582 finfo
= list_entry(item
, struct filter_info
, filter_info_list
);
583 if (finfo
->stream_id
== sid
) {
584 filter
= finfo
->filter
;
588 spin_unlock_irqrestore(&dec
->filter_info_list_lock
, flags
);
591 filter
->feed
->cb
.sec(&packet
[2], length
- 2, NULL
, 0,
595 static void ttusb_dec_process_packet(struct ttusb_dec
*dec
)
601 if (dec
->packet_length
% 2) {
602 printk("%s: odd sized packet - discarding\n", __func__
);
606 for (i
= 0; i
< dec
->packet_length
; i
+= 2)
607 csum
^= ((dec
->packet
[i
] << 8) + dec
->packet
[i
+ 1]);
610 printk("%s: checksum failed - discarding\n", __func__
);
614 packet_id
= dec
->packet
[dec
->packet_length
- 4] << 8;
615 packet_id
+= dec
->packet
[dec
->packet_length
- 3];
617 if ((packet_id
!= dec
->next_packet_id
) && dec
->next_packet_id
) {
618 printk("%s: warning: lost packets between %u and %u\n",
619 __func__
, dec
->next_packet_id
- 1, packet_id
);
622 if (packet_id
== 0xffff)
623 dec
->next_packet_id
= 0x8000;
625 dec
->next_packet_id
= packet_id
+ 1;
627 switch (dec
->packet_type
) {
628 case TTUSB_DEC_PACKET_PVA
:
629 if (dec
->pva_stream_count
)
630 ttusb_dec_process_pva(dec
, dec
->packet
,
631 dec
->packet_payload_length
);
634 case TTUSB_DEC_PACKET_SECTION
:
635 if (dec
->filter_stream_count
)
636 ttusb_dec_process_filter(dec
, dec
->packet
,
637 dec
->packet_payload_length
);
640 case TTUSB_DEC_PACKET_EMPTY
:
645 static void swap_bytes(u8
*b
, int length
)
647 length
-= length
% 2;
648 for (; length
; b
+= 2, length
-= 2)
652 static void ttusb_dec_process_urb_frame(struct ttusb_dec
*dec
, u8
*b
,
655 swap_bytes(b
, length
);
658 switch (dec
->packet_state
) {
666 dec
->packet_state
= 0;
674 dec
->packet_length
= 0;
675 } else if (*b
!= 0xaa) {
676 dec
->packet_state
= 0;
684 dec
->packet
[dec
->packet_length
++] = *b
++;
686 if (dec
->packet_length
== 2) {
687 if (dec
->packet
[0] == 'A' &&
688 dec
->packet
[1] == 'V') {
690 TTUSB_DEC_PACKET_PVA
;
692 } else if (dec
->packet
[0] == 'S') {
694 TTUSB_DEC_PACKET_SECTION
;
696 } else if (dec
->packet
[0] == 0x00) {
698 TTUSB_DEC_PACKET_EMPTY
;
699 dec
->packet_payload_length
= 2;
700 dec
->packet_state
= 7;
702 printk("%s: unknown packet type: %02x%02x\n",
704 dec
->packet
[0], dec
->packet
[1]);
705 dec
->packet_state
= 0;
713 dec
->packet
[dec
->packet_length
++] = *b
++;
715 if (dec
->packet_type
== TTUSB_DEC_PACKET_PVA
&&
716 dec
->packet_length
== 8) {
718 dec
->packet_payload_length
= 8 +
719 (dec
->packet
[6] << 8) +
721 } else if (dec
->packet_type
==
722 TTUSB_DEC_PACKET_SECTION
&&
723 dec
->packet_length
== 5) {
725 dec
->packet_payload_length
= 5 +
726 ((dec
->packet
[3] & 0x0f) << 8) +
734 int remainder
= dec
->packet_payload_length
-
737 if (length
>= remainder
) {
738 memcpy(dec
->packet
+ dec
->packet_length
,
740 dec
->packet_length
+= remainder
;
745 memcpy(&dec
->packet
[dec
->packet_length
],
747 dec
->packet_length
+= length
;
757 dec
->packet
[dec
->packet_length
++] = *b
++;
759 if (dec
->packet_type
== TTUSB_DEC_PACKET_SECTION
&&
760 dec
->packet_payload_length
% 2)
763 if (dec
->packet_length
==
764 dec
->packet_payload_length
+ tail
) {
765 ttusb_dec_process_packet(dec
);
766 dec
->packet_state
= 0;
774 printk("%s: illegal packet state encountered.\n",
776 dec
->packet_state
= 0;
781 static void ttusb_dec_process_urb_frame_list(unsigned long data
)
783 struct ttusb_dec
*dec
= (struct ttusb_dec
*)data
;
784 struct list_head
*item
;
785 struct urb_frame
*frame
;
789 spin_lock_irqsave(&dec
->urb_frame_list_lock
, flags
);
790 if ((item
= dec
->urb_frame_list
.next
) != &dec
->urb_frame_list
) {
791 frame
= list_entry(item
, struct urb_frame
,
793 list_del(&frame
->urb_frame_list
);
795 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
,
799 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
, flags
);
801 ttusb_dec_process_urb_frame(dec
, frame
->data
, frame
->length
);
806 static void ttusb_dec_process_urb(struct urb
*urb
)
808 struct ttusb_dec
*dec
= urb
->context
;
813 for (i
= 0; i
< FRAMES_PER_ISO_BUF
; i
++) {
814 struct usb_iso_packet_descriptor
*d
;
817 struct urb_frame
*frame
;
819 d
= &urb
->iso_frame_desc
[i
];
820 b
= urb
->transfer_buffer
+ d
->offset
;
821 length
= d
->actual_length
;
823 if ((frame
= kmalloc(sizeof(struct urb_frame
),
827 memcpy(frame
->data
, b
, length
);
828 frame
->length
= length
;
830 spin_lock_irqsave(&dec
->urb_frame_list_lock
,
832 list_add_tail(&frame
->urb_frame_list
,
833 &dec
->urb_frame_list
);
834 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
,
837 tasklet_schedule(&dec
->urb_tasklet
);
841 /* -ENOENT is expected when unlinking urbs */
842 if (urb
->status
!= -ENOENT
)
843 dprintk("%s: urb error: %d\n", __func__
,
847 if (dec
->iso_stream_count
)
848 usb_submit_urb(urb
, GFP_ATOMIC
);
851 static void ttusb_dec_setup_urbs(struct ttusb_dec
*dec
)
853 int i
, j
, buffer_offset
= 0;
855 dprintk("%s\n", __func__
);
857 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
858 int frame_offset
= 0;
859 struct urb
*urb
= dec
->iso_urb
[i
];
861 urb
->dev
= dec
->udev
;
863 urb
->complete
= ttusb_dec_process_urb
;
864 urb
->pipe
= dec
->in_pipe
;
865 urb
->transfer_flags
= URB_ISO_ASAP
;
867 urb
->number_of_packets
= FRAMES_PER_ISO_BUF
;
868 urb
->transfer_buffer_length
= ISO_FRAME_SIZE
*
870 urb
->transfer_buffer
= dec
->iso_buffer
+ buffer_offset
;
871 buffer_offset
+= ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
;
873 for (j
= 0; j
< FRAMES_PER_ISO_BUF
; j
++) {
874 urb
->iso_frame_desc
[j
].offset
= frame_offset
;
875 urb
->iso_frame_desc
[j
].length
= ISO_FRAME_SIZE
;
876 frame_offset
+= ISO_FRAME_SIZE
;
881 static void ttusb_dec_stop_iso_xfer(struct ttusb_dec
*dec
)
885 dprintk("%s\n", __func__
);
887 if (mutex_lock_interruptible(&dec
->iso_mutex
))
890 dec
->iso_stream_count
--;
892 if (!dec
->iso_stream_count
) {
893 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
894 usb_kill_urb(dec
->iso_urb
[i
]);
897 mutex_unlock(&dec
->iso_mutex
);
900 /* Setting the interface of the DEC tends to take down the USB communications
901 * for a short period, so it's important not to call this function just before
902 * trying to talk to it.
904 static int ttusb_dec_set_interface(struct ttusb_dec
*dec
,
905 enum ttusb_dec_interface interface
)
910 if (interface
!= dec
->interface
) {
912 case TTUSB_DEC_INTERFACE_INITIAL
:
913 result
= usb_set_interface(dec
->udev
, 0, 0);
915 case TTUSB_DEC_INTERFACE_IN
:
916 result
= ttusb_dec_send_command(dec
, 0x80, sizeof(b
),
920 result
= usb_set_interface(dec
->udev
, 0, 8);
922 case TTUSB_DEC_INTERFACE_OUT
:
923 result
= usb_set_interface(dec
->udev
, 0, 1);
930 dec
->interface
= interface
;
936 static int ttusb_dec_start_iso_xfer(struct ttusb_dec
*dec
)
940 dprintk("%s\n", __func__
);
942 if (mutex_lock_interruptible(&dec
->iso_mutex
))
945 if (!dec
->iso_stream_count
) {
946 ttusb_dec_setup_urbs(dec
);
948 dec
->packet_state
= 0;
949 dec
->v_pes_postbytes
= 0;
950 dec
->next_packet_id
= 0;
952 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
953 if ((result
= usb_submit_urb(dec
->iso_urb
[i
],
955 printk("%s: failed urb submission %d: error %d\n",
956 __func__
, i
, result
);
959 usb_kill_urb(dec
->iso_urb
[i
- 1]);
963 mutex_unlock(&dec
->iso_mutex
);
969 dec
->iso_stream_count
++;
971 mutex_unlock(&dec
->iso_mutex
);
976 static int ttusb_dec_start_ts_feed(struct dvb_demux_feed
*dvbdmxfeed
)
978 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
979 struct ttusb_dec
*dec
= dvbdmx
->priv
;
983 dprintk("%s\n", __func__
);
985 dprintk(" ts_type:");
987 if (dvbdmxfeed
->ts_type
& TS_DECODER
)
988 dprintk(" TS_DECODER");
990 if (dvbdmxfeed
->ts_type
& TS_PACKET
)
991 dprintk(" TS_PACKET");
993 if (dvbdmxfeed
->ts_type
& TS_PAYLOAD_ONLY
)
994 dprintk(" TS_PAYLOAD_ONLY");
998 switch (dvbdmxfeed
->pes_type
) {
1001 dprintk(" pes_type: DMX_PES_VIDEO\n");
1002 dec
->pid
[DMX_PES_PCR
] = dvbdmxfeed
->pid
;
1003 dec
->pid
[DMX_PES_VIDEO
] = dvbdmxfeed
->pid
;
1004 dec
->video_filter
= dvbdmxfeed
->filter
;
1005 ttusb_dec_set_pids(dec
);
1009 dprintk(" pes_type: DMX_PES_AUDIO\n");
1010 dec
->pid
[DMX_PES_AUDIO
] = dvbdmxfeed
->pid
;
1011 dec
->audio_filter
= dvbdmxfeed
->filter
;
1012 ttusb_dec_set_pids(dec
);
1015 case DMX_PES_TELETEXT
:
1016 dec
->pid
[DMX_PES_TELETEXT
] = dvbdmxfeed
->pid
;
1017 dprintk(" pes_type: DMX_PES_TELETEXT(not supported)\n");
1021 dprintk(" pes_type: DMX_PES_PCR\n");
1022 dec
->pid
[DMX_PES_PCR
] = dvbdmxfeed
->pid
;
1023 ttusb_dec_set_pids(dec
);
1027 dprintk(" pes_type: DMX_PES_OTHER(not supported)\n");
1031 dprintk(" pes_type: unknown (%d)\n", dvbdmxfeed
->pes_type
);
1036 result
= ttusb_dec_send_command(dec
, 0x80, sizeof(b0
), b0
, NULL
, NULL
);
1040 dec
->pva_stream_count
++;
1041 return ttusb_dec_start_iso_xfer(dec
);
1044 static int ttusb_dec_start_sec_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1046 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
1047 u8 b0
[] = { 0x00, 0x00, 0x00, 0x01,
1048 0x00, 0x00, 0x00, 0x00,
1049 0x00, 0x00, 0x00, 0x00,
1050 0x00, 0x00, 0x00, 0x00,
1051 0x00, 0xff, 0x00, 0x00,
1052 0x00, 0x00, 0x00, 0x00,
1053 0x00, 0x00, 0x00, 0x00,
1056 u8 c
[COMMAND_PACKET_SIZE
];
1059 struct filter_info
*finfo
;
1060 unsigned long flags
;
1063 dprintk("%s\n", __func__
);
1065 pid
= htons(dvbdmxfeed
->pid
);
1066 memcpy(&b0
[0], &pid
, 2);
1067 memcpy(&b0
[4], &x
, 1);
1068 memcpy(&b0
[5], &dvbdmxfeed
->filter
->filter
.filter_value
[0], 1);
1070 result
= ttusb_dec_send_command(dec
, 0x60, sizeof(b0
), b0
,
1074 if (c_length
== 2) {
1075 if (!(finfo
= kmalloc(sizeof(struct filter_info
),
1079 finfo
->stream_id
= c
[1];
1080 finfo
->filter
= dvbdmxfeed
->filter
;
1082 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
1083 list_add_tail(&finfo
->filter_info_list
,
1084 &dec
->filter_info_list
);
1085 spin_unlock_irqrestore(&dec
->filter_info_list_lock
,
1088 dvbdmxfeed
->priv
= finfo
;
1090 dec
->filter_stream_count
++;
1091 return ttusb_dec_start_iso_xfer(dec
);
1099 static int ttusb_dec_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1101 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
1103 dprintk("%s\n", __func__
);
1105 if (!dvbdmx
->dmx
.frontend
)
1108 dprintk(" pid: 0x%04X\n", dvbdmxfeed
->pid
);
1110 switch (dvbdmxfeed
->type
) {
1113 return ttusb_dec_start_ts_feed(dvbdmxfeed
);
1117 return ttusb_dec_start_sec_feed(dvbdmxfeed
);
1121 dprintk(" type: unknown (%d)\n", dvbdmxfeed
->type
);
1127 static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1129 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
1132 ttusb_dec_send_command(dec
, 0x81, sizeof(b0
), b0
, NULL
, NULL
);
1134 dec
->pva_stream_count
--;
1136 ttusb_dec_stop_iso_xfer(dec
);
1141 static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1143 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
1144 u8 b0
[] = { 0x00, 0x00 };
1145 struct filter_info
*finfo
= (struct filter_info
*)dvbdmxfeed
->priv
;
1146 unsigned long flags
;
1148 b0
[1] = finfo
->stream_id
;
1149 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
1150 list_del(&finfo
->filter_info_list
);
1151 spin_unlock_irqrestore(&dec
->filter_info_list_lock
, flags
);
1153 ttusb_dec_send_command(dec
, 0x62, sizeof(b0
), b0
, NULL
, NULL
);
1155 dec
->filter_stream_count
--;
1157 ttusb_dec_stop_iso_xfer(dec
);
1162 static int ttusb_dec_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1164 dprintk("%s\n", __func__
);
1166 switch (dvbdmxfeed
->type
) {
1168 return ttusb_dec_stop_ts_feed(dvbdmxfeed
);
1172 return ttusb_dec_stop_sec_feed(dvbdmxfeed
);
1179 static void ttusb_dec_free_iso_urbs(struct ttusb_dec
*dec
)
1183 dprintk("%s\n", __func__
);
1185 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
1186 usb_free_urb(dec
->iso_urb
[i
]);
1187 kfree(dec
->iso_buffer
);
1190 static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec
*dec
)
1194 dprintk("%s\n", __func__
);
1196 dec
->iso_buffer
= kcalloc(FRAMES_PER_ISO_BUF
* ISO_BUF_COUNT
,
1197 ISO_FRAME_SIZE
, GFP_KERNEL
);
1198 if (!dec
->iso_buffer
)
1201 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
1204 if (!(urb
= usb_alloc_urb(FRAMES_PER_ISO_BUF
, GFP_ATOMIC
))) {
1205 ttusb_dec_free_iso_urbs(dec
);
1209 dec
->iso_urb
[i
] = urb
;
1212 ttusb_dec_setup_urbs(dec
);
1217 static void ttusb_dec_init_tasklet(struct ttusb_dec
*dec
)
1219 spin_lock_init(&dec
->urb_frame_list_lock
);
1220 INIT_LIST_HEAD(&dec
->urb_frame_list
);
1221 tasklet_init(&dec
->urb_tasklet
, ttusb_dec_process_urb_frame_list
,
1222 (unsigned long)dec
);
1225 static int ttusb_init_rc( struct ttusb_dec
*dec
)
1227 struct input_dev
*input_dev
;
1228 u8 b
[] = { 0x00, 0x01 };
1232 usb_make_path(dec
->udev
, dec
->rc_phys
, sizeof(dec
->rc_phys
));
1233 strlcat(dec
->rc_phys
, "/input0", sizeof(dec
->rc_phys
));
1235 input_dev
= input_allocate_device();
1239 input_dev
->name
= "ttusb_dec remote control";
1240 input_dev
->phys
= dec
->rc_phys
;
1241 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
);
1242 input_dev
->keycodesize
= sizeof(u16
);
1243 input_dev
->keycodemax
= 0x1a;
1244 input_dev
->keycode
= rc_keys
;
1246 for (i
= 0; i
< ARRAY_SIZE(rc_keys
); i
++)
1247 set_bit(rc_keys
[i
], input_dev
->keybit
);
1249 err
= input_register_device(input_dev
);
1251 input_free_device(input_dev
);
1255 dec
->rc_input_dev
= input_dev
;
1256 if (usb_submit_urb(dec
->irq_urb
, GFP_KERNEL
))
1257 printk("%s: usb_submit_urb failed\n",__func__
);
1258 /* enable irq pipe */
1259 ttusb_dec_send_command(dec
,0xb0,sizeof(b
),b
,NULL
,NULL
);
1264 static void ttusb_dec_init_v_pes(struct ttusb_dec
*dec
)
1266 dprintk("%s\n", __func__
);
1268 dec
->v_pes
[0] = 0x00;
1269 dec
->v_pes
[1] = 0x00;
1270 dec
->v_pes
[2] = 0x01;
1271 dec
->v_pes
[3] = 0xe0;
1274 static int ttusb_dec_init_usb(struct ttusb_dec
*dec
)
1278 dprintk("%s\n", __func__
);
1280 mutex_init(&dec
->usb_mutex
);
1281 mutex_init(&dec
->iso_mutex
);
1283 dec
->command_pipe
= usb_sndbulkpipe(dec
->udev
, COMMAND_PIPE
);
1284 dec
->result_pipe
= usb_rcvbulkpipe(dec
->udev
, RESULT_PIPE
);
1285 dec
->in_pipe
= usb_rcvisocpipe(dec
->udev
, IN_PIPE
);
1286 dec
->out_pipe
= usb_sndisocpipe(dec
->udev
, OUT_PIPE
);
1287 dec
->irq_pipe
= usb_rcvintpipe(dec
->udev
, IRQ_PIPE
);
1290 dec
->irq_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1294 dec
->irq_buffer
= usb_alloc_coherent(dec
->udev
,IRQ_PACKET_SIZE
,
1295 GFP_KERNEL
, &dec
->irq_dma_handle
);
1296 if(!dec
->irq_buffer
) {
1297 usb_free_urb(dec
->irq_urb
);
1300 usb_fill_int_urb(dec
->irq_urb
, dec
->udev
,dec
->irq_pipe
,
1301 dec
->irq_buffer
, IRQ_PACKET_SIZE
,
1302 ttusb_dec_handle_irq
, dec
, 1);
1303 dec
->irq_urb
->transfer_dma
= dec
->irq_dma_handle
;
1304 dec
->irq_urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1307 result
= ttusb_dec_alloc_iso_urbs(dec
);
1309 usb_free_urb(dec
->irq_urb
);
1310 usb_free_coherent(dec
->udev
, IRQ_PACKET_SIZE
,
1311 dec
->irq_buffer
, dec
->irq_dma_handle
);
1316 static int ttusb_dec_boot_dsp(struct ttusb_dec
*dec
)
1318 int i
, j
, actual_len
, result
, size
, trans_count
;
1319 u8 b0
[] = { 0x00, 0x00, 0x00, 0x00,
1320 0x00, 0x00, 0x00, 0x00,
1325 const u8
*firmware
= NULL
;
1326 size_t firmware_size
= 0;
1327 u16 firmware_csum
= 0;
1328 __be16 firmware_csum_ns
;
1329 __be32 firmware_size_nl
;
1330 u32 crc32_csum
, crc32_check
;
1332 const struct firmware
*fw_entry
= NULL
;
1334 dprintk("%s\n", __func__
);
1336 result
= request_firmware(&fw_entry
, dec
->firmware_name
, &dec
->udev
->dev
);
1338 printk(KERN_ERR
"%s: Firmware (%s) unavailable.\n",
1339 __func__
, dec
->firmware_name
);
1343 firmware
= fw_entry
->data
;
1344 firmware_size
= fw_entry
->size
;
1346 if (firmware_size
< 60) {
1347 printk("%s: firmware size too small for DSP code (%zu < 60).\n",
1348 __func__
, firmware_size
);
1349 release_firmware(fw_entry
);
1353 /* a 32 bit checksum over the first 56 bytes of the DSP Code is stored
1354 at offset 56 of file, so use it to check if the firmware file is
1356 crc32_csum
= crc32(~0L, firmware
, 56) ^ ~0L;
1357 memcpy(&tmp
, &firmware
[56], 4);
1358 crc32_check
= ntohl(tmp
);
1359 if (crc32_csum
!= crc32_check
) {
1360 printk("%s: crc32 check of DSP code failed (calculated 0x%08x != 0x%08x in file), file invalid.\n",
1361 __func__
, crc32_csum
, crc32_check
);
1362 release_firmware(fw_entry
);
1365 memcpy(idstring
, &firmware
[36], 20);
1366 idstring
[20] = '\0';
1367 printk(KERN_INFO
"ttusb_dec: found DSP code \"%s\".\n", idstring
);
1369 firmware_size_nl
= htonl(firmware_size
);
1370 memcpy(b0
, &firmware_size_nl
, 4);
1371 firmware_csum
= crc16(~0, firmware
, firmware_size
) ^ ~0;
1372 firmware_csum_ns
= htons(firmware_csum
);
1373 memcpy(&b0
[6], &firmware_csum_ns
, 2);
1375 result
= ttusb_dec_send_command(dec
, 0x41, sizeof(b0
), b0
, NULL
, NULL
);
1378 release_firmware(fw_entry
);
1385 b
= kmalloc(ARM_PACKET_SIZE
, GFP_KERNEL
);
1387 release_firmware(fw_entry
);
1391 for (i
= 0; i
< firmware_size
; i
+= COMMAND_PACKET_SIZE
) {
1392 size
= firmware_size
- i
;
1393 if (size
> COMMAND_PACKET_SIZE
)
1394 size
= COMMAND_PACKET_SIZE
;
1397 b
[j
+ 1] = trans_count
++;
1400 memcpy(&b
[j
+ 4], &firmware
[i
], size
);
1402 j
+= COMMAND_PACKET_SIZE
+ 4;
1404 if (j
>= ARM_PACKET_SIZE
) {
1405 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
1406 ARM_PACKET_SIZE
, &actual_len
,
1409 } else if (size
< COMMAND_PACKET_SIZE
) {
1410 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
1411 j
- COMMAND_PACKET_SIZE
+ size
,
1416 result
= ttusb_dec_send_command(dec
, 0x43, sizeof(b1
), b1
, NULL
, NULL
);
1418 release_firmware(fw_entry
);
1424 static int ttusb_dec_init_stb(struct ttusb_dec
*dec
)
1427 unsigned int mode
= 0, model
= 0, version
= 0;
1429 dprintk("%s\n", __func__
);
1431 result
= ttusb_dec_get_stb_state(dec
, &mode
, &model
, &version
);
1436 if (version
== 0xABCDEFAB)
1437 printk(KERN_INFO
"ttusb_dec: no version info in Firmware\n");
1439 printk(KERN_INFO
"ttusb_dec: Firmware %x.%02x%c%c\n",
1440 version
>> 24, (version
>> 16) & 0xff,
1441 (version
>> 8) & 0xff, version
& 0xff);
1443 result
= ttusb_dec_boot_dsp(dec
);
1447 /* We can't trust the USB IDs that some firmwares
1453 ttusb_dec_set_model(dec
, TTUSB_DEC3000S
);
1457 ttusb_dec_set_model(dec
, TTUSB_DEC2000T
);
1460 ttusb_dec_set_model(dec
, TTUSB_DEC2540T
);
1463 printk(KERN_ERR
"%s: unknown model returned by firmware (%08x) - please report\n",
1467 if (version
>= 0x01770000)
1468 dec
->can_playback
= 1;
1473 static int ttusb_dec_init_dvb(struct ttusb_dec
*dec
)
1477 dprintk("%s\n", __func__
);
1479 if ((result
= dvb_register_adapter(&dec
->adapter
,
1480 dec
->model_name
, THIS_MODULE
,
1483 printk("%s: dvb_register_adapter failed: error %d\n",
1489 dec
->demux
.dmx
.capabilities
= DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
1491 dec
->demux
.priv
= (void *)dec
;
1492 dec
->demux
.filternum
= 31;
1493 dec
->demux
.feednum
= 31;
1494 dec
->demux
.start_feed
= ttusb_dec_start_feed
;
1495 dec
->demux
.stop_feed
= ttusb_dec_stop_feed
;
1496 dec
->demux
.write_to_decoder
= NULL
;
1498 if ((result
= dvb_dmx_init(&dec
->demux
)) < 0) {
1499 printk("%s: dvb_dmx_init failed: error %d\n", __func__
,
1502 dvb_unregister_adapter(&dec
->adapter
);
1507 dec
->dmxdev
.filternum
= 32;
1508 dec
->dmxdev
.demux
= &dec
->demux
.dmx
;
1509 dec
->dmxdev
.capabilities
= 0;
1511 if ((result
= dvb_dmxdev_init(&dec
->dmxdev
, &dec
->adapter
)) < 0) {
1512 printk("%s: dvb_dmxdev_init failed: error %d\n",
1515 dvb_dmx_release(&dec
->demux
);
1516 dvb_unregister_adapter(&dec
->adapter
);
1521 dec
->frontend
.source
= DMX_FRONTEND_0
;
1523 if ((result
= dec
->demux
.dmx
.add_frontend(&dec
->demux
.dmx
,
1524 &dec
->frontend
)) < 0) {
1525 printk("%s: dvb_dmx_init failed: error %d\n", __func__
,
1528 dvb_dmxdev_release(&dec
->dmxdev
);
1529 dvb_dmx_release(&dec
->demux
);
1530 dvb_unregister_adapter(&dec
->adapter
);
1535 if ((result
= dec
->demux
.dmx
.connect_frontend(&dec
->demux
.dmx
,
1536 &dec
->frontend
)) < 0) {
1537 printk("%s: dvb_dmx_init failed: error %d\n", __func__
,
1540 dec
->demux
.dmx
.remove_frontend(&dec
->demux
.dmx
, &dec
->frontend
);
1541 dvb_dmxdev_release(&dec
->dmxdev
);
1542 dvb_dmx_release(&dec
->demux
);
1543 dvb_unregister_adapter(&dec
->adapter
);
1548 dvb_net_init(&dec
->adapter
, &dec
->dvb_net
, &dec
->demux
.dmx
);
1553 static void ttusb_dec_exit_dvb(struct ttusb_dec
*dec
)
1555 dprintk("%s\n", __func__
);
1557 dvb_net_release(&dec
->dvb_net
);
1558 dec
->demux
.dmx
.close(&dec
->demux
.dmx
);
1559 dec
->demux
.dmx
.remove_frontend(&dec
->demux
.dmx
, &dec
->frontend
);
1560 dvb_dmxdev_release(&dec
->dmxdev
);
1561 dvb_dmx_release(&dec
->demux
);
1563 dvb_unregister_frontend(dec
->fe
);
1564 if (dec
->fe
->ops
.release
)
1565 dec
->fe
->ops
.release(dec
->fe
);
1567 dvb_unregister_adapter(&dec
->adapter
);
1570 static void ttusb_dec_exit_rc(struct ttusb_dec
*dec
)
1572 dprintk("%s\n", __func__
);
1574 if (dec
->rc_input_dev
) {
1575 input_unregister_device(dec
->rc_input_dev
);
1576 dec
->rc_input_dev
= NULL
;
1581 static void ttusb_dec_exit_usb(struct ttusb_dec
*dec
)
1585 dprintk("%s\n", __func__
);
1588 /* we have to check whether the irq URB is already submitted.
1589 * As the irq is submitted after the interface is changed,
1590 * this is the best method i figured out.
1592 if (dec
->interface
== TTUSB_DEC_INTERFACE_IN
)
1593 usb_kill_urb(dec
->irq_urb
);
1595 usb_free_urb(dec
->irq_urb
);
1597 usb_free_coherent(dec
->udev
, IRQ_PACKET_SIZE
,
1598 dec
->irq_buffer
, dec
->irq_dma_handle
);
1601 dec
->iso_stream_count
= 0;
1603 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
1604 usb_kill_urb(dec
->iso_urb
[i
]);
1606 ttusb_dec_free_iso_urbs(dec
);
1609 static void ttusb_dec_exit_tasklet(struct ttusb_dec
*dec
)
1611 struct list_head
*item
;
1612 struct urb_frame
*frame
;
1614 tasklet_kill(&dec
->urb_tasklet
);
1616 while ((item
= dec
->urb_frame_list
.next
) != &dec
->urb_frame_list
) {
1617 frame
= list_entry(item
, struct urb_frame
, urb_frame_list
);
1618 list_del(&frame
->urb_frame_list
);
1623 static void ttusb_dec_init_filters(struct ttusb_dec
*dec
)
1625 INIT_LIST_HEAD(&dec
->filter_info_list
);
1626 spin_lock_init(&dec
->filter_info_list_lock
);
1629 static void ttusb_dec_exit_filters(struct ttusb_dec
*dec
)
1631 struct list_head
*item
;
1632 struct filter_info
*finfo
;
1634 while ((item
= dec
->filter_info_list
.next
) != &dec
->filter_info_list
) {
1635 finfo
= list_entry(item
, struct filter_info
, filter_info_list
);
1636 list_del(&finfo
->filter_info_list
);
1641 static int fe_send_command(struct dvb_frontend
* fe
, const u8 command
,
1642 int param_length
, const u8 params
[],
1643 int *result_length
, u8 cmd_result
[])
1645 struct ttusb_dec
* dec
= fe
->dvb
->priv
;
1646 return ttusb_dec_send_command(dec
, command
, param_length
, params
, result_length
, cmd_result
);
1649 static const struct ttusbdecfe_config fe_config
= {
1650 .send_command
= fe_send_command
1653 static int ttusb_dec_probe(struct usb_interface
*intf
,
1654 const struct usb_device_id
*id
)
1656 struct usb_device
*udev
;
1657 struct ttusb_dec
*dec
;
1660 dprintk("%s\n", __func__
);
1662 udev
= interface_to_usbdev(intf
);
1664 if (!(dec
= kzalloc(sizeof(struct ttusb_dec
), GFP_KERNEL
))) {
1665 printk("%s: couldn't allocate memory.\n", __func__
);
1669 usb_set_intfdata(intf
, (void *)dec
);
1671 switch (id
->idProduct
) {
1673 ttusb_dec_set_model(dec
, TTUSB_DEC3000S
);
1677 ttusb_dec_set_model(dec
, TTUSB_DEC2000T
);
1681 ttusb_dec_set_model(dec
, TTUSB_DEC2540T
);
1687 result
= ttusb_dec_init_usb(dec
);
1690 result
= ttusb_dec_init_stb(dec
);
1693 result
= ttusb_dec_init_dvb(dec
);
1697 dec
->adapter
.priv
= dec
;
1698 switch (id
->idProduct
) {
1700 dec
->fe
= ttusbdecfe_dvbs_attach(&fe_config
);
1705 dec
->fe
= ttusbdecfe_dvbt_attach(&fe_config
);
1709 if (dec
->fe
== NULL
) {
1710 printk("dvb-ttusb-dec: A frontend driver was not found for device [%04x:%04x]\n",
1711 le16_to_cpu(dec
->udev
->descriptor
.idVendor
),
1712 le16_to_cpu(dec
->udev
->descriptor
.idProduct
));
1714 if (dvb_register_frontend(&dec
->adapter
, dec
->fe
)) {
1715 printk("budget-ci: Frontend registration failed!\n");
1716 if (dec
->fe
->ops
.release
)
1717 dec
->fe
->ops
.release(dec
->fe
);
1722 ttusb_dec_init_v_pes(dec
);
1723 ttusb_dec_init_filters(dec
);
1724 ttusb_dec_init_tasklet(dec
);
1728 ttusb_dec_set_interface(dec
, TTUSB_DEC_INTERFACE_IN
);
1735 ttusb_dec_exit_usb(dec
);
1741 static void ttusb_dec_disconnect(struct usb_interface
*intf
)
1743 struct ttusb_dec
*dec
= usb_get_intfdata(intf
);
1745 usb_set_intfdata(intf
, NULL
);
1747 dprintk("%s\n", __func__
);
1750 ttusb_dec_exit_tasklet(dec
);
1751 ttusb_dec_exit_filters(dec
);
1753 ttusb_dec_exit_rc(dec
);
1754 ttusb_dec_exit_usb(dec
);
1755 ttusb_dec_exit_dvb(dec
);
1761 static void ttusb_dec_set_model(struct ttusb_dec
*dec
,
1762 enum ttusb_dec_model model
)
1767 case TTUSB_DEC2000T
:
1768 dec
->model_name
= "DEC2000-t";
1769 dec
->firmware_name
= "dvb-ttusb-dec-2000t.fw";
1772 case TTUSB_DEC2540T
:
1773 dec
->model_name
= "DEC2540-t";
1774 dec
->firmware_name
= "dvb-ttusb-dec-2540t.fw";
1777 case TTUSB_DEC3000S
:
1778 dec
->model_name
= "DEC3000-s";
1779 dec
->firmware_name
= "dvb-ttusb-dec-3000s.fw";
1784 static const struct usb_device_id ttusb_dec_table
[] = {
1785 {USB_DEVICE(0x0b48, 0x1006)}, /* DEC3000-s */
1786 /*{USB_DEVICE(0x0b48, 0x1007)}, Unconfirmed */
1787 {USB_DEVICE(0x0b48, 0x1008)}, /* DEC2000-t */
1788 {USB_DEVICE(0x0b48, 0x1009)}, /* DEC2540-t */
1792 static struct usb_driver ttusb_dec_driver
= {
1793 .name
= "ttusb-dec",
1794 .probe
= ttusb_dec_probe
,
1795 .disconnect
= ttusb_dec_disconnect
,
1796 .id_table
= ttusb_dec_table
,
1799 module_usb_driver(ttusb_dec_driver
);
1801 MODULE_AUTHOR("Alex Woods <linux-dvb@giblets.org>");
1802 MODULE_DESCRIPTION(DRIVER_NAME
);
1803 MODULE_LICENSE("GPL");
1804 MODULE_DEVICE_TABLE(usb
, ttusb_dec_table
);