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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <asm/semaphore.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/pci.h>
28 #include <linux/slab.h>
29 #include <linux/spinlock.h>
30 #include <linux/usb.h>
31 #include <linux/interrupt.h>
32 #include <linux/firmware.h>
33 #include <linux/crc32.h>
34 #include <linux/init.h>
35 #include <linux/input.h>
38 #include "dvb_demux.h"
39 #include "dvb_filter.h"
40 #include "dvb_frontend.h"
42 #include "ttusbdecfe.h"
45 static int output_pva
;
48 module_param(debug
, int, 0644);
49 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
50 module_param(output_pva
, int, 0444);
51 MODULE_PARM_DESC(output_pva
, "Output PVA from dvr device (default:off)");
52 module_param(enable_rc
, int, 0644);
53 MODULE_PARM_DESC(enable_rc
, "Turn on/off IR remote control(default: off)");
55 #define dprintk if (debug) printk
57 #define DRIVER_NAME "TechnoTrend/Hauppauge DEC USB"
59 #define COMMAND_PIPE 0x03
60 #define RESULT_PIPE 0x04
65 #define COMMAND_PACKET_SIZE 0x3c
66 #define ARM_PACKET_SIZE 0x1000
67 #define IRQ_PACKET_SIZE 0x8
69 #define ISO_BUF_COUNT 0x04
70 #define FRAMES_PER_ISO_BUF 0x04
71 #define ISO_FRAME_SIZE 0x0380
73 #define MAX_PVA_LENGTH 6144
75 enum ttusb_dec_model
{
81 enum ttusb_dec_packet_type
{
83 TTUSB_DEC_PACKET_SECTION
,
84 TTUSB_DEC_PACKET_EMPTY
87 enum ttusb_dec_interface
{
88 TTUSB_DEC_INTERFACE_INITIAL
,
89 TTUSB_DEC_INTERFACE_IN
,
90 TTUSB_DEC_INTERFACE_OUT
94 enum ttusb_dec_model model
;
100 struct dvb_adapter adapter
;
101 struct dmxdev dmxdev
;
102 struct dvb_demux demux
;
103 struct dmx_frontend frontend
;
104 struct dvb_net dvb_net
;
105 struct dvb_frontend
* fe
;
107 u16 pid
[DMX_PES_OTHER
];
110 struct usb_device
*udev
;
112 unsigned int command_pipe
;
113 unsigned int result_pipe
;
114 unsigned int in_pipe
;
115 unsigned int out_pipe
;
116 unsigned int irq_pipe
;
117 enum ttusb_dec_interface interface
;
118 struct semaphore usb_sem
;
122 dma_addr_t irq_dma_handle
;
124 dma_addr_t iso_dma_handle
;
125 struct urb
*iso_urb
[ISO_BUF_COUNT
];
126 int iso_stream_count
;
127 struct semaphore iso_sem
;
129 u8 packet
[MAX_PVA_LENGTH
+ 4];
130 enum ttusb_dec_packet_type packet_type
;
133 int packet_payload_length
;
136 int pva_stream_count
;
137 int filter_stream_count
;
139 struct dvb_filter_pes2ts a_pes2ts
;
140 struct dvb_filter_pes2ts v_pes2ts
;
142 u8 v_pes
[16 + MAX_PVA_LENGTH
];
146 struct list_head urb_frame_list
;
147 struct tasklet_struct urb_tasklet
;
148 spinlock_t urb_frame_list_lock
;
150 struct dvb_demux_filter
*audio_filter
;
151 struct dvb_demux_filter
*video_filter
;
152 struct list_head filter_info_list
;
153 spinlock_t filter_info_list_lock
;
155 struct input_dev
*rc_input_dev
;
158 int active
; /* Loaded successfully */
162 u8 data
[ISO_FRAME_SIZE
];
164 struct list_head urb_frame_list
;
169 struct dvb_demux_filter
*filter
;
170 struct list_head filter_info_list
;
173 static u16 rc_keys
[] = {
202 static void ttusb_dec_set_model(struct ttusb_dec
*dec
,
203 enum ttusb_dec_model model
);
205 static void ttusb_dec_handle_irq( struct urb
*urb
, struct pt_regs
*regs
)
207 struct ttusb_dec
* dec
= urb
->context
;
208 char *buffer
= dec
->irq_buffer
;
211 switch(urb
->status
) {
218 /* this urb is dead, cleanup */
219 dprintk("%s:urb shutting down with status: %d\n",
220 __FUNCTION__
, urb
->status
);
223 dprintk("%s:nonzero status received: %d\n",
224 __FUNCTION__
,urb
->status
);
228 if( (buffer
[0] == 0x1) && (buffer
[2] == 0x15) ) {
230 /* this is an fact a bit too simple implementation;
231 * the box also reports a keyrepeat signal
232 * (with buffer[3] == 0x40) in an intervall of ~100ms.
233 * But to handle this correctly we had to imlemenent some
234 * kind of timer which signals a 'key up' event if no
235 * keyrepeat signal is recieved for lets say 200ms.
236 * this should/could be added later ...
237 * for now lets report each signal as a key down and up*/
238 dprintk("%s:rc signal:%d\n", __FUNCTION__
, buffer
[4]);
239 input_report_key(dec
->rc_input_dev
, rc_keys
[buffer
[4] - 1], 1);
240 input_report_key(dec
->rc_input_dev
, rc_keys
[buffer
[4] - 1], 0);
241 input_sync(dec
->rc_input_dev
);
244 exit
: retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
246 printk("%s - usb_commit_urb failed with result: %d\n",
247 __FUNCTION__
, retval
);
250 static u16
crc16(u16 crc
, const u8
*buf
, size_t len
)
258 crc
^= (tmp
^ (tmp
<< 1)) << 4;
263 static int ttusb_dec_send_command(struct ttusb_dec
*dec
, const u8 command
,
264 int param_length
, const u8 params
[],
265 int *result_length
, u8 cmd_result
[])
267 int result
, actual_len
, i
;
270 dprintk("%s\n", __FUNCTION__
);
272 b
= kmalloc(COMMAND_PACKET_SIZE
+ 4, GFP_KERNEL
);
276 if ((result
= down_interruptible(&dec
->usb_sem
))) {
278 printk("%s: Failed to down usb semaphore.\n", __FUNCTION__
);
283 b
[1] = ++dec
->trans_count
;
288 memcpy(&b
[4], params
, param_length
);
291 printk("%s: command: ", __FUNCTION__
);
292 for (i
= 0; i
< param_length
+ 4; i
++)
293 printk("0x%02X ", b
[i
]);
297 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
298 COMMAND_PACKET_SIZE
+ 4, &actual_len
, 1000);
301 printk("%s: command bulk message failed: error %d\n",
302 __FUNCTION__
, result
);
308 result
= usb_bulk_msg(dec
->udev
, dec
->result_pipe
, b
,
309 COMMAND_PACKET_SIZE
+ 4, &actual_len
, 1000);
312 printk("%s: result bulk message failed: error %d\n",
313 __FUNCTION__
, result
);
319 printk("%s: result: ", __FUNCTION__
);
320 for (i
= 0; i
< actual_len
; i
++)
321 printk("0x%02X ", b
[i
]);
326 *result_length
= b
[3];
327 if (cmd_result
&& b
[3] > 0)
328 memcpy(cmd_result
, &b
[4], b
[3]);
337 static int ttusb_dec_get_stb_state (struct ttusb_dec
*dec
, unsigned int *mode
,
338 unsigned int *model
, unsigned int *version
)
340 u8 c
[COMMAND_PACKET_SIZE
];
345 dprintk("%s\n", __FUNCTION__
);
347 result
= ttusb_dec_send_command(dec
, 0x08, 0, NULL
, &c_length
, c
);
351 if (c_length
>= 0x0c) {
357 memcpy(&tmp
, &c
[4], 4);
360 if (version
!= NULL
) {
361 memcpy(&tmp
, &c
[8], 4);
362 *version
= ntohl(tmp
);
370 static int ttusb_dec_audio_pes2ts_cb(void *priv
, unsigned char *data
)
372 struct ttusb_dec
*dec
= priv
;
374 dec
->audio_filter
->feed
->cb
.ts(data
, 188, NULL
, 0,
375 &dec
->audio_filter
->feed
->feed
.ts
,
381 static int ttusb_dec_video_pes2ts_cb(void *priv
, unsigned char *data
)
383 struct ttusb_dec
*dec
= priv
;
385 dec
->video_filter
->feed
->cb
.ts(data
, 188, NULL
, 0,
386 &dec
->video_filter
->feed
->feed
.ts
,
392 static void ttusb_dec_set_pids(struct ttusb_dec
*dec
)
394 u8 b
[] = { 0x00, 0x00, 0x00, 0x00,
395 0x00, 0x00, 0xff, 0xff,
396 0xff, 0xff, 0xff, 0xff };
398 u16 pcr
= htons(dec
->pid
[DMX_PES_PCR
]);
399 u16 audio
= htons(dec
->pid
[DMX_PES_AUDIO
]);
400 u16 video
= htons(dec
->pid
[DMX_PES_VIDEO
]);
402 dprintk("%s\n", __FUNCTION__
);
404 memcpy(&b
[0], &pcr
, 2);
405 memcpy(&b
[2], &audio
, 2);
406 memcpy(&b
[4], &video
, 2);
408 ttusb_dec_send_command(dec
, 0x50, sizeof(b
), b
, NULL
, NULL
);
410 dvb_filter_pes2ts_init(&dec
->a_pes2ts
, dec
->pid
[DMX_PES_AUDIO
],
411 ttusb_dec_audio_pes2ts_cb
, dec
);
412 dvb_filter_pes2ts_init(&dec
->v_pes2ts
, dec
->pid
[DMX_PES_VIDEO
],
413 ttusb_dec_video_pes2ts_cb
, dec
);
414 dec
->v_pes_length
= 0;
415 dec
->v_pes_postbytes
= 0;
418 static void ttusb_dec_process_pva(struct ttusb_dec
*dec
, u8
*pva
, int length
)
421 printk("%s: packet too short - discarding\n", __FUNCTION__
);
425 if (length
> 8 + MAX_PVA_LENGTH
) {
426 printk("%s: packet too long - discarding\n", __FUNCTION__
);
432 case 0x01: { /* VideoStream */
433 int prebytes
= pva
[5] & 0x03;
434 int postbytes
= (pva
[5] & 0x0c) >> 2;
435 u16 v_pes_payload_length
;
438 dec
->video_filter
->feed
->cb
.ts(pva
, length
, NULL
, 0,
439 &dec
->video_filter
->feed
->feed
.ts
, DMX_OK
);
443 if (dec
->v_pes_postbytes
> 0 &&
444 dec
->v_pes_postbytes
== prebytes
) {
445 memcpy(&dec
->v_pes
[dec
->v_pes_length
],
448 dvb_filter_pes2ts(&dec
->v_pes2ts
, dec
->v_pes
,
449 dec
->v_pes_length
+ prebytes
, 1);
453 dec
->v_pes
[7] = 0x80;
454 dec
->v_pes
[8] = 0x05;
456 dec
->v_pes
[9] = 0x21 | ((pva
[8] & 0xc0) >> 5);
457 dec
->v_pes
[10] = ((pva
[8] & 0x3f) << 2) |
458 ((pva
[9] & 0xc0) >> 6);
459 dec
->v_pes
[11] = 0x01 |
460 ((pva
[9] & 0x3f) << 2) |
461 ((pva
[10] & 0x80) >> 6);
462 dec
->v_pes
[12] = ((pva
[10] & 0x7f) << 1) |
463 ((pva
[11] & 0xc0) >> 7);
464 dec
->v_pes
[13] = 0x01 | ((pva
[11] & 0x7f) << 1);
466 memcpy(&dec
->v_pes
[14], &pva
[12 + prebytes
],
467 length
- 12 - prebytes
);
468 dec
->v_pes_length
= 14 + length
- 12 - prebytes
;
470 dec
->v_pes
[7] = 0x00;
471 dec
->v_pes
[8] = 0x00;
473 memcpy(&dec
->v_pes
[9], &pva
[8], length
- 8);
474 dec
->v_pes_length
= 9 + length
- 8;
477 dec
->v_pes_postbytes
= postbytes
;
479 if (dec
->v_pes
[9 + dec
->v_pes
[8]] == 0x00 &&
480 dec
->v_pes
[10 + dec
->v_pes
[8]] == 0x00 &&
481 dec
->v_pes
[11 + dec
->v_pes
[8]] == 0x01)
482 dec
->v_pes
[6] = 0x84;
484 dec
->v_pes
[6] = 0x80;
486 v_pes_payload_length
= htons(dec
->v_pes_length
- 6 +
488 memcpy(&dec
->v_pes
[4], &v_pes_payload_length
, 2);
491 dvb_filter_pes2ts(&dec
->v_pes2ts
, dec
->v_pes
,
492 dec
->v_pes_length
, 1);
497 case 0x02: /* MainAudioStream */
499 dec
->audio_filter
->feed
->cb
.ts(pva
, length
, NULL
, 0,
500 &dec
->audio_filter
->feed
->feed
.ts
, DMX_OK
);
504 dvb_filter_pes2ts(&dec
->a_pes2ts
, &pva
[8], length
- 8,
509 printk("%s: unknown PVA type: %02x.\n", __FUNCTION__
,
515 static void ttusb_dec_process_filter(struct ttusb_dec
*dec
, u8
*packet
,
518 struct list_head
*item
;
519 struct filter_info
*finfo
;
520 struct dvb_demux_filter
*filter
= NULL
;
525 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
526 for (item
= dec
->filter_info_list
.next
; item
!= &dec
->filter_info_list
;
528 finfo
= list_entry(item
, struct filter_info
, filter_info_list
);
529 if (finfo
->stream_id
== sid
) {
530 filter
= finfo
->filter
;
534 spin_unlock_irqrestore(&dec
->filter_info_list_lock
, flags
);
537 filter
->feed
->cb
.sec(&packet
[2], length
- 2, NULL
, 0,
538 &filter
->filter
, DMX_OK
);
541 static void ttusb_dec_process_packet(struct ttusb_dec
*dec
)
547 if (dec
->packet_length
% 2) {
548 printk("%s: odd sized packet - discarding\n", __FUNCTION__
);
552 for (i
= 0; i
< dec
->packet_length
; i
+= 2)
553 csum
^= ((dec
->packet
[i
] << 8) + dec
->packet
[i
+ 1]);
556 printk("%s: checksum failed - discarding\n", __FUNCTION__
);
560 packet_id
= dec
->packet
[dec
->packet_length
- 4] << 8;
561 packet_id
+= dec
->packet
[dec
->packet_length
- 3];
563 if ((packet_id
!= dec
->next_packet_id
) && dec
->next_packet_id
) {
564 printk("%s: warning: lost packets between %u and %u\n",
565 __FUNCTION__
, dec
->next_packet_id
- 1, packet_id
);
568 if (packet_id
== 0xffff)
569 dec
->next_packet_id
= 0x8000;
571 dec
->next_packet_id
= packet_id
+ 1;
573 switch (dec
->packet_type
) {
574 case TTUSB_DEC_PACKET_PVA
:
575 if (dec
->pva_stream_count
)
576 ttusb_dec_process_pva(dec
, dec
->packet
,
577 dec
->packet_payload_length
);
580 case TTUSB_DEC_PACKET_SECTION
:
581 if (dec
->filter_stream_count
)
582 ttusb_dec_process_filter(dec
, dec
->packet
,
583 dec
->packet_payload_length
);
586 case TTUSB_DEC_PACKET_EMPTY
:
591 static void swap_bytes(u8
*b
, int length
)
595 length
-= length
% 2;
596 for (; length
; b
+= 2, length
-= 2) {
603 static void ttusb_dec_process_urb_frame(struct ttusb_dec
*dec
, u8
*b
,
606 swap_bytes(b
, length
);
609 switch (dec
->packet_state
) {
617 dec
->packet_state
= 0;
625 dec
->packet_length
= 0;
626 } else if (*b
!= 0xaa) {
627 dec
->packet_state
= 0;
635 dec
->packet
[dec
->packet_length
++] = *b
++;
637 if (dec
->packet_length
== 2) {
638 if (dec
->packet
[0] == 'A' &&
639 dec
->packet
[1] == 'V') {
641 TTUSB_DEC_PACKET_PVA
;
643 } else if (dec
->packet
[0] == 'S') {
645 TTUSB_DEC_PACKET_SECTION
;
647 } else if (dec
->packet
[0] == 0x00) {
649 TTUSB_DEC_PACKET_EMPTY
;
650 dec
->packet_payload_length
= 2;
651 dec
->packet_state
= 7;
653 printk("%s: unknown packet type: "
654 "%02x%02x\n", __FUNCTION__
,
655 dec
->packet
[0], dec
->packet
[1]);
656 dec
->packet_state
= 0;
664 dec
->packet
[dec
->packet_length
++] = *b
++;
666 if (dec
->packet_type
== TTUSB_DEC_PACKET_PVA
&&
667 dec
->packet_length
== 8) {
669 dec
->packet_payload_length
= 8 +
670 (dec
->packet
[6] << 8) +
672 } else if (dec
->packet_type
==
673 TTUSB_DEC_PACKET_SECTION
&&
674 dec
->packet_length
== 5) {
676 dec
->packet_payload_length
= 5 +
677 ((dec
->packet
[3] & 0x0f) << 8) +
685 int remainder
= dec
->packet_payload_length
-
688 if (length
>= remainder
) {
689 memcpy(dec
->packet
+ dec
->packet_length
,
691 dec
->packet_length
+= remainder
;
696 memcpy(&dec
->packet
[dec
->packet_length
],
698 dec
->packet_length
+= length
;
708 dec
->packet
[dec
->packet_length
++] = *b
++;
710 if (dec
->packet_type
== TTUSB_DEC_PACKET_SECTION
&&
711 dec
->packet_payload_length
% 2)
714 if (dec
->packet_length
==
715 dec
->packet_payload_length
+ tail
) {
716 ttusb_dec_process_packet(dec
);
717 dec
->packet_state
= 0;
725 printk("%s: illegal packet state encountered.\n",
727 dec
->packet_state
= 0;
732 static void ttusb_dec_process_urb_frame_list(unsigned long data
)
734 struct ttusb_dec
*dec
= (struct ttusb_dec
*)data
;
735 struct list_head
*item
;
736 struct urb_frame
*frame
;
740 spin_lock_irqsave(&dec
->urb_frame_list_lock
, flags
);
741 if ((item
= dec
->urb_frame_list
.next
) != &dec
->urb_frame_list
) {
742 frame
= list_entry(item
, struct urb_frame
,
744 list_del(&frame
->urb_frame_list
);
746 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
,
750 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
, flags
);
752 ttusb_dec_process_urb_frame(dec
, frame
->data
, frame
->length
);
757 static void ttusb_dec_process_urb(struct urb
*urb
, struct pt_regs
*ptregs
)
759 struct ttusb_dec
*dec
= urb
->context
;
764 for (i
= 0; i
< FRAMES_PER_ISO_BUF
; i
++) {
765 struct usb_iso_packet_descriptor
*d
;
768 struct urb_frame
*frame
;
770 d
= &urb
->iso_frame_desc
[i
];
771 b
= urb
->transfer_buffer
+ d
->offset
;
772 length
= d
->actual_length
;
774 if ((frame
= kmalloc(sizeof(struct urb_frame
),
778 memcpy(frame
->data
, b
, length
);
779 frame
->length
= length
;
781 spin_lock_irqsave(&dec
->urb_frame_list_lock
,
783 list_add_tail(&frame
->urb_frame_list
,
784 &dec
->urb_frame_list
);
785 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
,
788 tasklet_schedule(&dec
->urb_tasklet
);
792 /* -ENOENT is expected when unlinking urbs */
793 if (urb
->status
!= -ENOENT
)
794 dprintk("%s: urb error: %d\n", __FUNCTION__
,
798 if (dec
->iso_stream_count
)
799 usb_submit_urb(urb
, GFP_ATOMIC
);
802 static void ttusb_dec_setup_urbs(struct ttusb_dec
*dec
)
804 int i
, j
, buffer_offset
= 0;
806 dprintk("%s\n", __FUNCTION__
);
808 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
809 int frame_offset
= 0;
810 struct urb
*urb
= dec
->iso_urb
[i
];
812 urb
->dev
= dec
->udev
;
814 urb
->complete
= ttusb_dec_process_urb
;
815 urb
->pipe
= dec
->in_pipe
;
816 urb
->transfer_flags
= URB_ISO_ASAP
;
818 urb
->number_of_packets
= FRAMES_PER_ISO_BUF
;
819 urb
->transfer_buffer_length
= ISO_FRAME_SIZE
*
821 urb
->transfer_buffer
= dec
->iso_buffer
+ buffer_offset
;
822 buffer_offset
+= ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
;
824 for (j
= 0; j
< FRAMES_PER_ISO_BUF
; j
++) {
825 urb
->iso_frame_desc
[j
].offset
= frame_offset
;
826 urb
->iso_frame_desc
[j
].length
= ISO_FRAME_SIZE
;
827 frame_offset
+= ISO_FRAME_SIZE
;
832 static void ttusb_dec_stop_iso_xfer(struct ttusb_dec
*dec
)
836 dprintk("%s\n", __FUNCTION__
);
838 if (down_interruptible(&dec
->iso_sem
))
841 dec
->iso_stream_count
--;
843 if (!dec
->iso_stream_count
) {
844 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
845 usb_kill_urb(dec
->iso_urb
[i
]);
851 /* Setting the interface of the DEC tends to take down the USB communications
852 * for a short period, so it's important not to call this function just before
853 * trying to talk to it.
855 static int ttusb_dec_set_interface(struct ttusb_dec
*dec
,
856 enum ttusb_dec_interface interface
)
861 if (interface
!= dec
->interface
) {
863 case TTUSB_DEC_INTERFACE_INITIAL
:
864 result
= usb_set_interface(dec
->udev
, 0, 0);
866 case TTUSB_DEC_INTERFACE_IN
:
867 result
= ttusb_dec_send_command(dec
, 0x80, sizeof(b
),
871 result
= usb_set_interface(dec
->udev
, 0, 8);
873 case TTUSB_DEC_INTERFACE_OUT
:
874 result
= usb_set_interface(dec
->udev
, 0, 1);
881 dec
->interface
= interface
;
887 static int ttusb_dec_start_iso_xfer(struct ttusb_dec
*dec
)
891 dprintk("%s\n", __FUNCTION__
);
893 if (down_interruptible(&dec
->iso_sem
))
896 if (!dec
->iso_stream_count
) {
897 ttusb_dec_setup_urbs(dec
);
899 dec
->packet_state
= 0;
900 dec
->v_pes_postbytes
= 0;
901 dec
->next_packet_id
= 0;
903 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
904 if ((result
= usb_submit_urb(dec
->iso_urb
[i
],
906 printk("%s: failed urb submission %d: "
907 "error %d\n", __FUNCTION__
, i
, result
);
910 usb_kill_urb(dec
->iso_urb
[i
- 1]);
920 dec
->iso_stream_count
++;
927 static int ttusb_dec_start_ts_feed(struct dvb_demux_feed
*dvbdmxfeed
)
929 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
930 struct ttusb_dec
*dec
= dvbdmx
->priv
;
934 dprintk("%s\n", __FUNCTION__
);
936 dprintk(" ts_type:");
938 if (dvbdmxfeed
->ts_type
& TS_DECODER
)
939 dprintk(" TS_DECODER");
941 if (dvbdmxfeed
->ts_type
& TS_PACKET
)
942 dprintk(" TS_PACKET");
944 if (dvbdmxfeed
->ts_type
& TS_PAYLOAD_ONLY
)
945 dprintk(" TS_PAYLOAD_ONLY");
949 switch (dvbdmxfeed
->pes_type
) {
951 case DMX_TS_PES_VIDEO
:
952 dprintk(" pes_type: DMX_TS_PES_VIDEO\n");
953 dec
->pid
[DMX_PES_PCR
] = dvbdmxfeed
->pid
;
954 dec
->pid
[DMX_PES_VIDEO
] = dvbdmxfeed
->pid
;
955 dec
->video_filter
= dvbdmxfeed
->filter
;
956 ttusb_dec_set_pids(dec
);
959 case DMX_TS_PES_AUDIO
:
960 dprintk(" pes_type: DMX_TS_PES_AUDIO\n");
961 dec
->pid
[DMX_PES_AUDIO
] = dvbdmxfeed
->pid
;
962 dec
->audio_filter
= dvbdmxfeed
->filter
;
963 ttusb_dec_set_pids(dec
);
966 case DMX_TS_PES_TELETEXT
:
967 dec
->pid
[DMX_PES_TELETEXT
] = dvbdmxfeed
->pid
;
968 dprintk(" pes_type: DMX_TS_PES_TELETEXT(not supported)\n");
972 dprintk(" pes_type: DMX_TS_PES_PCR\n");
973 dec
->pid
[DMX_PES_PCR
] = dvbdmxfeed
->pid
;
974 ttusb_dec_set_pids(dec
);
977 case DMX_TS_PES_OTHER
:
978 dprintk(" pes_type: DMX_TS_PES_OTHER(not supported)\n");
982 dprintk(" pes_type: unknown (%d)\n", dvbdmxfeed
->pes_type
);
987 result
= ttusb_dec_send_command(dec
, 0x80, sizeof(b0
), b0
, NULL
, NULL
);
991 dec
->pva_stream_count
++;
992 return ttusb_dec_start_iso_xfer(dec
);
995 static int ttusb_dec_start_sec_feed(struct dvb_demux_feed
*dvbdmxfeed
)
997 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
998 u8 b0
[] = { 0x00, 0x00, 0x00, 0x01,
999 0x00, 0x00, 0x00, 0x00,
1000 0x00, 0x00, 0x00, 0x00,
1001 0x00, 0x00, 0x00, 0x00,
1002 0x00, 0xff, 0x00, 0x00,
1003 0x00, 0x00, 0x00, 0x00,
1004 0x00, 0x00, 0x00, 0x00,
1007 u8 c
[COMMAND_PACKET_SIZE
];
1010 struct filter_info
*finfo
;
1011 unsigned long flags
;
1014 dprintk("%s\n", __FUNCTION__
);
1016 pid
= htons(dvbdmxfeed
->pid
);
1017 memcpy(&b0
[0], &pid
, 2);
1018 memcpy(&b0
[4], &x
, 1);
1019 memcpy(&b0
[5], &dvbdmxfeed
->filter
->filter
.filter_value
[0], 1);
1021 result
= ttusb_dec_send_command(dec
, 0x60, sizeof(b0
), b0
,
1025 if (c_length
== 2) {
1026 if (!(finfo
= kmalloc(sizeof(struct filter_info
),
1030 finfo
->stream_id
= c
[1];
1031 finfo
->filter
= dvbdmxfeed
->filter
;
1033 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
1034 list_add_tail(&finfo
->filter_info_list
,
1035 &dec
->filter_info_list
);
1036 spin_unlock_irqrestore(&dec
->filter_info_list_lock
,
1039 dvbdmxfeed
->priv
= finfo
;
1041 dec
->filter_stream_count
++;
1042 return ttusb_dec_start_iso_xfer(dec
);
1050 static int ttusb_dec_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1052 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
1054 dprintk("%s\n", __FUNCTION__
);
1056 if (!dvbdmx
->dmx
.frontend
)
1059 dprintk(" pid: 0x%04X\n", dvbdmxfeed
->pid
);
1061 switch (dvbdmxfeed
->type
) {
1064 return ttusb_dec_start_ts_feed(dvbdmxfeed
);
1068 return ttusb_dec_start_sec_feed(dvbdmxfeed
);
1072 dprintk(" type: unknown (%d)\n", dvbdmxfeed
->type
);
1078 static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1080 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
1083 ttusb_dec_send_command(dec
, 0x81, sizeof(b0
), b0
, NULL
, NULL
);
1085 dec
->pva_stream_count
--;
1087 ttusb_dec_stop_iso_xfer(dec
);
1092 static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1094 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
1095 u8 b0
[] = { 0x00, 0x00 };
1096 struct filter_info
*finfo
= (struct filter_info
*)dvbdmxfeed
->priv
;
1097 unsigned long flags
;
1099 b0
[1] = finfo
->stream_id
;
1100 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
1101 list_del(&finfo
->filter_info_list
);
1102 spin_unlock_irqrestore(&dec
->filter_info_list_lock
, flags
);
1104 ttusb_dec_send_command(dec
, 0x62, sizeof(b0
), b0
, NULL
, NULL
);
1106 dec
->filter_stream_count
--;
1108 ttusb_dec_stop_iso_xfer(dec
);
1113 static int ttusb_dec_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1115 dprintk("%s\n", __FUNCTION__
);
1117 switch (dvbdmxfeed
->type
) {
1119 return ttusb_dec_stop_ts_feed(dvbdmxfeed
);
1123 return ttusb_dec_stop_sec_feed(dvbdmxfeed
);
1130 static void ttusb_dec_free_iso_urbs(struct ttusb_dec
*dec
)
1134 dprintk("%s\n", __FUNCTION__
);
1136 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
1137 if (dec
->iso_urb
[i
])
1138 usb_free_urb(dec
->iso_urb
[i
]);
1140 pci_free_consistent(NULL
,
1141 ISO_FRAME_SIZE
* (FRAMES_PER_ISO_BUF
*
1143 dec
->iso_buffer
, dec
->iso_dma_handle
);
1146 static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec
*dec
)
1150 dprintk("%s\n", __FUNCTION__
);
1152 dec
->iso_buffer
= pci_alloc_consistent(NULL
,
1154 (FRAMES_PER_ISO_BUF
*
1156 &dec
->iso_dma_handle
);
1158 memset(dec
->iso_buffer
, 0,
1159 ISO_FRAME_SIZE
* (FRAMES_PER_ISO_BUF
* ISO_BUF_COUNT
));
1161 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
1164 if (!(urb
= usb_alloc_urb(FRAMES_PER_ISO_BUF
, GFP_ATOMIC
))) {
1165 ttusb_dec_free_iso_urbs(dec
);
1169 dec
->iso_urb
[i
] = urb
;
1172 ttusb_dec_setup_urbs(dec
);
1177 static void ttusb_dec_init_tasklet(struct ttusb_dec
*dec
)
1179 spin_lock_init(&dec
->urb_frame_list_lock
);
1180 INIT_LIST_HEAD(&dec
->urb_frame_list
);
1181 tasklet_init(&dec
->urb_tasklet
, ttusb_dec_process_urb_frame_list
,
1182 (unsigned long)dec
);
1185 static int ttusb_init_rc( struct ttusb_dec
*dec
)
1187 struct input_dev
*input_dev
;
1188 u8 b
[] = { 0x00, 0x01 };
1191 usb_make_path(dec
->udev
, dec
->rc_phys
, sizeof(dec
->rc_phys
));
1192 strlcpy(dec
->rc_phys
, "/input0", sizeof(dec
->rc_phys
));
1194 dec
->rc_input_dev
= input_dev
= input_allocate_device();
1198 input_dev
->name
= "ttusb_dec remote control";
1199 input_dev
->phys
= dec
->rc_phys
;
1200 input_dev
->evbit
[0] = BIT(EV_KEY
);
1201 input_dev
->keycodesize
= sizeof(u16
);
1202 input_dev
->keycodemax
= 0x1a;
1203 input_dev
->keycode
= rc_keys
;
1205 for (i
= 0; i
< ARRAY_SIZE(rc_keys
); i
++)
1206 set_bit(rc_keys
[i
], input_dev
->keybit
);
1208 input_register_device(input_dev
);
1210 if (usb_submit_urb(dec
->irq_urb
, GFP_KERNEL
))
1211 printk("%s: usb_submit_urb failed\n",__FUNCTION__
);
1212 /* enable irq pipe */
1213 ttusb_dec_send_command(dec
,0xb0,sizeof(b
),b
,NULL
,NULL
);
1218 static void ttusb_dec_init_v_pes(struct ttusb_dec
*dec
)
1220 dprintk("%s\n", __FUNCTION__
);
1222 dec
->v_pes
[0] = 0x00;
1223 dec
->v_pes
[1] = 0x00;
1224 dec
->v_pes
[2] = 0x01;
1225 dec
->v_pes
[3] = 0xe0;
1228 static int ttusb_dec_init_usb(struct ttusb_dec
*dec
)
1230 dprintk("%s\n", __FUNCTION__
);
1232 sema_init(&dec
->usb_sem
, 1);
1233 sema_init(&dec
->iso_sem
, 1);
1235 dec
->command_pipe
= usb_sndbulkpipe(dec
->udev
, COMMAND_PIPE
);
1236 dec
->result_pipe
= usb_rcvbulkpipe(dec
->udev
, RESULT_PIPE
);
1237 dec
->in_pipe
= usb_rcvisocpipe(dec
->udev
, IN_PIPE
);
1238 dec
->out_pipe
= usb_sndisocpipe(dec
->udev
, OUT_PIPE
);
1239 dec
->irq_pipe
= usb_rcvintpipe(dec
->udev
, IRQ_PIPE
);
1242 dec
->irq_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1246 dec
->irq_buffer
= usb_buffer_alloc(dec
->udev
,IRQ_PACKET_SIZE
,
1247 SLAB_ATOMIC
, &dec
->irq_dma_handle
);
1248 if(!dec
->irq_buffer
) {
1251 usb_fill_int_urb(dec
->irq_urb
, dec
->udev
,dec
->irq_pipe
,
1252 dec
->irq_buffer
, IRQ_PACKET_SIZE
,
1253 ttusb_dec_handle_irq
, dec
, 1);
1254 dec
->irq_urb
->transfer_dma
= dec
->irq_dma_handle
;
1255 dec
->irq_urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1258 return ttusb_dec_alloc_iso_urbs(dec
);
1261 static int ttusb_dec_boot_dsp(struct ttusb_dec
*dec
)
1263 int i
, j
, actual_len
, result
, size
, trans_count
;
1264 u8 b0
[] = { 0x00, 0x00, 0x00, 0x00,
1265 0x00, 0x00, 0x00, 0x00,
1270 u8
*firmware
= NULL
;
1271 size_t firmware_size
= 0;
1272 u16 firmware_csum
= 0;
1273 u16 firmware_csum_ns
;
1274 u32 firmware_size_nl
;
1275 u32 crc32_csum
, crc32_check
, tmp
;
1276 const struct firmware
*fw_entry
= NULL
;
1278 dprintk("%s\n", __FUNCTION__
);
1280 if (request_firmware(&fw_entry
, dec
->firmware_name
, &dec
->udev
->dev
)) {
1281 printk(KERN_ERR
"%s: Firmware (%s) unavailable.\n",
1282 __FUNCTION__
, dec
->firmware_name
);
1286 firmware
= fw_entry
->data
;
1287 firmware_size
= fw_entry
->size
;
1289 if (firmware_size
< 60) {
1290 printk("%s: firmware size too small for DSP code (%zu < 60).\n",
1291 __FUNCTION__
, firmware_size
);
1292 release_firmware(fw_entry
);
1296 /* a 32 bit checksum over the first 56 bytes of the DSP Code is stored
1297 at offset 56 of file, so use it to check if the firmware file is
1299 crc32_csum
= crc32(~0L, firmware
, 56) ^ ~0L;
1300 memcpy(&tmp
, &firmware
[56], 4);
1301 crc32_check
= htonl(tmp
);
1302 if (crc32_csum
!= crc32_check
) {
1303 printk("%s: crc32 check of DSP code failed (calculated "
1304 "0x%08x != 0x%08x in file), file invalid.\n",
1305 __FUNCTION__
, crc32_csum
, crc32_check
);
1306 release_firmware(fw_entry
);
1309 memcpy(idstring
, &firmware
[36], 20);
1310 idstring
[20] = '\0';
1311 printk(KERN_INFO
"ttusb_dec: found DSP code \"%s\".\n", idstring
);
1313 firmware_size_nl
= htonl(firmware_size
);
1314 memcpy(b0
, &firmware_size_nl
, 4);
1315 firmware_csum
= crc16(~0, firmware
, firmware_size
) ^ ~0;
1316 firmware_csum_ns
= htons(firmware_csum
);
1317 memcpy(&b0
[6], &firmware_csum_ns
, 2);
1319 result
= ttusb_dec_send_command(dec
, 0x41, sizeof(b0
), b0
, NULL
, NULL
);
1322 release_firmware(fw_entry
);
1329 b
= kmalloc(ARM_PACKET_SIZE
, GFP_KERNEL
);
1331 release_firmware(fw_entry
);
1335 for (i
= 0; i
< firmware_size
; i
+= COMMAND_PACKET_SIZE
) {
1336 size
= firmware_size
- i
;
1337 if (size
> COMMAND_PACKET_SIZE
)
1338 size
= COMMAND_PACKET_SIZE
;
1341 b
[j
+ 1] = trans_count
++;
1344 memcpy(&b
[j
+ 4], &firmware
[i
], size
);
1346 j
+= COMMAND_PACKET_SIZE
+ 4;
1348 if (j
>= ARM_PACKET_SIZE
) {
1349 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
1350 ARM_PACKET_SIZE
, &actual_len
,
1353 } else if (size
< COMMAND_PACKET_SIZE
) {
1354 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
1355 j
- COMMAND_PACKET_SIZE
+ size
,
1360 result
= ttusb_dec_send_command(dec
, 0x43, sizeof(b1
), b1
, NULL
, NULL
);
1362 release_firmware(fw_entry
);
1368 static int ttusb_dec_init_stb(struct ttusb_dec
*dec
)
1371 unsigned int mode
, model
, version
;
1373 dprintk("%s\n", __FUNCTION__
);
1375 result
= ttusb_dec_get_stb_state(dec
, &mode
, &model
, &version
);
1379 if (version
== 0xABCDEFAB)
1380 printk(KERN_INFO
"ttusb_dec: no version "
1381 "info in Firmware\n");
1383 printk(KERN_INFO
"ttusb_dec: Firmware "
1385 version
>> 24, (version
>> 16) & 0xff,
1386 (version
>> 8) & 0xff, version
& 0xff);
1388 result
= ttusb_dec_boot_dsp(dec
);
1394 /* We can't trust the USB IDs that some firmwares
1400 ttusb_dec_set_model(dec
, TTUSB_DEC3000S
);
1404 ttusb_dec_set_model(dec
, TTUSB_DEC2000T
);
1407 ttusb_dec_set_model(dec
, TTUSB_DEC2540T
);
1410 printk(KERN_ERR
"%s: unknown model returned "
1411 "by firmware (%08x) - please report\n",
1412 __FUNCTION__
, model
);
1417 if (version
>= 0x01770000)
1418 dec
->can_playback
= 1;
1427 static int ttusb_dec_init_dvb(struct ttusb_dec
*dec
)
1431 dprintk("%s\n", __FUNCTION__
);
1433 if ((result
= dvb_register_adapter(&dec
->adapter
,
1434 dec
->model_name
, THIS_MODULE
)) < 0) {
1435 printk("%s: dvb_register_adapter failed: error %d\n",
1436 __FUNCTION__
, result
);
1441 dec
->demux
.dmx
.capabilities
= DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
1443 dec
->demux
.priv
= (void *)dec
;
1444 dec
->demux
.filternum
= 31;
1445 dec
->demux
.feednum
= 31;
1446 dec
->demux
.start_feed
= ttusb_dec_start_feed
;
1447 dec
->demux
.stop_feed
= ttusb_dec_stop_feed
;
1448 dec
->demux
.write_to_decoder
= NULL
;
1450 if ((result
= dvb_dmx_init(&dec
->demux
)) < 0) {
1451 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__
,
1454 dvb_unregister_adapter(&dec
->adapter
);
1459 dec
->dmxdev
.filternum
= 32;
1460 dec
->dmxdev
.demux
= &dec
->demux
.dmx
;
1461 dec
->dmxdev
.capabilities
= 0;
1463 if ((result
= dvb_dmxdev_init(&dec
->dmxdev
, &dec
->adapter
)) < 0) {
1464 printk("%s: dvb_dmxdev_init failed: error %d\n",
1465 __FUNCTION__
, result
);
1467 dvb_dmx_release(&dec
->demux
);
1468 dvb_unregister_adapter(&dec
->adapter
);
1473 dec
->frontend
.source
= DMX_FRONTEND_0
;
1475 if ((result
= dec
->demux
.dmx
.add_frontend(&dec
->demux
.dmx
,
1476 &dec
->frontend
)) < 0) {
1477 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__
,
1480 dvb_dmxdev_release(&dec
->dmxdev
);
1481 dvb_dmx_release(&dec
->demux
);
1482 dvb_unregister_adapter(&dec
->adapter
);
1487 if ((result
= dec
->demux
.dmx
.connect_frontend(&dec
->demux
.dmx
,
1488 &dec
->frontend
)) < 0) {
1489 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__
,
1492 dec
->demux
.dmx
.remove_frontend(&dec
->demux
.dmx
, &dec
->frontend
);
1493 dvb_dmxdev_release(&dec
->dmxdev
);
1494 dvb_dmx_release(&dec
->demux
);
1495 dvb_unregister_adapter(&dec
->adapter
);
1500 dvb_net_init(&dec
->adapter
, &dec
->dvb_net
, &dec
->demux
.dmx
);
1505 static void ttusb_dec_exit_dvb(struct ttusb_dec
*dec
)
1507 dprintk("%s\n", __FUNCTION__
);
1509 dvb_net_release(&dec
->dvb_net
);
1510 dec
->demux
.dmx
.close(&dec
->demux
.dmx
);
1511 dec
->demux
.dmx
.remove_frontend(&dec
->demux
.dmx
, &dec
->frontend
);
1512 dvb_dmxdev_release(&dec
->dmxdev
);
1513 dvb_dmx_release(&dec
->demux
);
1514 if (dec
->fe
) dvb_unregister_frontend(dec
->fe
);
1515 dvb_unregister_adapter(&dec
->adapter
);
1518 static void ttusb_dec_exit_rc(struct ttusb_dec
*dec
)
1521 dprintk("%s\n", __FUNCTION__
);
1522 /* we have to check whether the irq URB is already submitted.
1523 * As the irq is submitted after the interface is changed,
1524 * this is the best method i figured out.
1526 if (dec
->interface
== TTUSB_DEC_INTERFACE_IN
)
1527 usb_kill_urb(dec
->irq_urb
);
1529 usb_free_urb(dec
->irq_urb
);
1531 usb_buffer_free(dec
->udev
,IRQ_PACKET_SIZE
,
1532 dec
->irq_buffer
, dec
->irq_dma_handle
);
1534 if (dec
->rc_input_dev
) {
1535 input_unregister_device(dec
->rc_input_dev
);
1536 dec
->rc_input_dev
= NULL
;
1541 static void ttusb_dec_exit_usb(struct ttusb_dec
*dec
)
1545 dprintk("%s\n", __FUNCTION__
);
1547 dec
->iso_stream_count
= 0;
1549 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
1550 usb_kill_urb(dec
->iso_urb
[i
]);
1552 ttusb_dec_free_iso_urbs(dec
);
1555 static void ttusb_dec_exit_tasklet(struct ttusb_dec
*dec
)
1557 struct list_head
*item
;
1558 struct urb_frame
*frame
;
1560 tasklet_kill(&dec
->urb_tasklet
);
1562 while ((item
= dec
->urb_frame_list
.next
) != &dec
->urb_frame_list
) {
1563 frame
= list_entry(item
, struct urb_frame
, urb_frame_list
);
1564 list_del(&frame
->urb_frame_list
);
1569 static void ttusb_dec_init_filters(struct ttusb_dec
*dec
)
1571 INIT_LIST_HEAD(&dec
->filter_info_list
);
1572 spin_lock_init(&dec
->filter_info_list_lock
);
1575 static void ttusb_dec_exit_filters(struct ttusb_dec
*dec
)
1577 struct list_head
*item
;
1578 struct filter_info
*finfo
;
1580 while ((item
= dec
->filter_info_list
.next
) != &dec
->filter_info_list
) {
1581 finfo
= list_entry(item
, struct filter_info
, filter_info_list
);
1582 list_del(&finfo
->filter_info_list
);
1587 static int fe_send_command(struct dvb_frontend
* fe
, const u8 command
,
1588 int param_length
, const u8 params
[],
1589 int *result_length
, u8 cmd_result
[])
1591 struct ttusb_dec
* dec
= fe
->dvb
->priv
;
1592 return ttusb_dec_send_command(dec
, command
, param_length
, params
, result_length
, cmd_result
);
1595 static struct ttusbdecfe_config fe_config
= {
1596 .send_command
= fe_send_command
1599 static int ttusb_dec_probe(struct usb_interface
*intf
,
1600 const struct usb_device_id
*id
)
1602 struct usb_device
*udev
;
1603 struct ttusb_dec
*dec
;
1605 dprintk("%s\n", __FUNCTION__
);
1607 udev
= interface_to_usbdev(intf
);
1609 if (!(dec
= kzalloc(sizeof(struct ttusb_dec
), GFP_KERNEL
))) {
1610 printk("%s: couldn't allocate memory.\n", __FUNCTION__
);
1614 usb_set_intfdata(intf
, (void *)dec
);
1616 switch (le16_to_cpu(id
->idProduct
)) {
1618 ttusb_dec_set_model(dec
, TTUSB_DEC3000S
);
1622 ttusb_dec_set_model(dec
, TTUSB_DEC2000T
);
1626 ttusb_dec_set_model(dec
, TTUSB_DEC2540T
);
1632 if (ttusb_dec_init_usb(dec
))
1634 if (ttusb_dec_init_stb(dec
)) {
1635 ttusb_dec_exit_usb(dec
);
1638 ttusb_dec_init_dvb(dec
);
1640 dec
->adapter
.priv
= dec
;
1641 switch (le16_to_cpu(id
->idProduct
)) {
1643 dec
->fe
= ttusbdecfe_dvbs_attach(&fe_config
);
1648 dec
->fe
= ttusbdecfe_dvbt_attach(&fe_config
);
1652 if (dec
->fe
== NULL
) {
1653 printk("dvb-ttusb-dec: A frontend driver was not found for device %04x/%04x\n",
1654 le16_to_cpu(dec
->udev
->descriptor
.idVendor
),
1655 le16_to_cpu(dec
->udev
->descriptor
.idProduct
));
1657 if (dvb_register_frontend(&dec
->adapter
, dec
->fe
)) {
1658 printk("budget-ci: Frontend registration failed!\n");
1659 if (dec
->fe
->ops
->release
)
1660 dec
->fe
->ops
->release(dec
->fe
);
1665 ttusb_dec_init_v_pes(dec
);
1666 ttusb_dec_init_filters(dec
);
1667 ttusb_dec_init_tasklet(dec
);
1671 ttusb_dec_set_interface(dec
, TTUSB_DEC_INTERFACE_IN
);
1679 static void ttusb_dec_disconnect(struct usb_interface
*intf
)
1681 struct ttusb_dec
*dec
= usb_get_intfdata(intf
);
1683 usb_set_intfdata(intf
, NULL
);
1685 dprintk("%s\n", __FUNCTION__
);
1688 ttusb_dec_exit_tasklet(dec
);
1689 ttusb_dec_exit_filters(dec
);
1691 ttusb_dec_exit_rc(dec
);
1692 ttusb_dec_exit_usb(dec
);
1693 ttusb_dec_exit_dvb(dec
);
1699 static void ttusb_dec_set_model(struct ttusb_dec
*dec
,
1700 enum ttusb_dec_model model
)
1705 case TTUSB_DEC2000T
:
1706 dec
->model_name
= "DEC2000-t";
1707 dec
->firmware_name
= "dvb-ttusb-dec-2000t.fw";
1710 case TTUSB_DEC2540T
:
1711 dec
->model_name
= "DEC2540-t";
1712 dec
->firmware_name
= "dvb-ttusb-dec-2540t.fw";
1715 case TTUSB_DEC3000S
:
1716 dec
->model_name
= "DEC3000-s";
1717 dec
->firmware_name
= "dvb-ttusb-dec-3000s.fw";
1722 static struct usb_device_id ttusb_dec_table
[] = {
1723 {USB_DEVICE(0x0b48, 0x1006)}, /* DEC3000-s */
1724 /*{USB_DEVICE(0x0b48, 0x1007)}, Unconfirmed */
1725 {USB_DEVICE(0x0b48, 0x1008)}, /* DEC2000-t */
1726 {USB_DEVICE(0x0b48, 0x1009)}, /* DEC2540-t */
1730 static struct usb_driver ttusb_dec_driver
= {
1731 .name
= "ttusb-dec",
1732 .probe
= ttusb_dec_probe
,
1733 .disconnect
= ttusb_dec_disconnect
,
1734 .id_table
= ttusb_dec_table
,
1737 static int __init
ttusb_dec_init(void)
1741 if ((result
= usb_register(&ttusb_dec_driver
)) < 0) {
1742 printk("%s: initialisation failed: error %d.\n", __FUNCTION__
,
1750 static void __exit
ttusb_dec_exit(void)
1752 usb_deregister(&ttusb_dec_driver
);
1755 module_init(ttusb_dec_init
);
1756 module_exit(ttusb_dec_exit
);
1758 MODULE_AUTHOR("Alex Woods <linux-dvb@giblets.org>");
1759 MODULE_DESCRIPTION(DRIVER_NAME
);
1760 MODULE_LICENSE("GPL");
1761 MODULE_DEVICE_TABLE(usb
, ttusb_dec_table
);