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 <linux/list.h>
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/spinlock.h>
28 #include <linux/usb.h>
29 #include <linux/interrupt.h>
30 #include <linux/firmware.h>
31 #include <linux/crc32.h>
32 #include <linux/init.h>
33 #include <linux/input.h>
35 #include <linux/mutex.h>
38 #include "dvb_demux.h"
39 #include "dvb_frontend.h"
41 #include "ttusbdecfe.h"
44 static int output_pva
;
47 module_param(debug
, int, 0644);
48 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
49 module_param(output_pva
, int, 0444);
50 MODULE_PARM_DESC(output_pva
, "Output PVA from dvr device (default:off)");
51 module_param(enable_rc
, int, 0644);
52 MODULE_PARM_DESC(enable_rc
, "Turn on/off IR remote control(default: off)");
54 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
56 #define dprintk if (debug) printk
58 #define DRIVER_NAME "TechnoTrend/Hauppauge DEC USB"
60 #define COMMAND_PIPE 0x03
61 #define RESULT_PIPE 0x04
66 #define COMMAND_PACKET_SIZE 0x3c
67 #define ARM_PACKET_SIZE 0x1000
68 #define IRQ_PACKET_SIZE 0x8
70 #define ISO_BUF_COUNT 0x04
71 #define FRAMES_PER_ISO_BUF 0x04
72 #define ISO_FRAME_SIZE 0x0380
74 #define MAX_PVA_LENGTH 6144
76 enum ttusb_dec_model
{
82 enum ttusb_dec_packet_type
{
84 TTUSB_DEC_PACKET_SECTION
,
85 TTUSB_DEC_PACKET_EMPTY
88 enum ttusb_dec_interface
{
89 TTUSB_DEC_INTERFACE_INITIAL
,
90 TTUSB_DEC_INTERFACE_IN
,
91 TTUSB_DEC_INTERFACE_OUT
94 typedef int (dvb_filter_pes2ts_cb_t
) (void *, unsigned char *);
96 struct dvb_filter_pes2ts
{
97 unsigned char buf
[188];
99 dvb_filter_pes2ts_cb_t
*cb
;
104 enum ttusb_dec_model model
;
110 struct dvb_adapter adapter
;
111 struct dmxdev dmxdev
;
112 struct dvb_demux demux
;
113 struct dmx_frontend frontend
;
114 struct dvb_net dvb_net
;
115 struct dvb_frontend
* fe
;
117 u16 pid
[DMX_PES_OTHER
];
120 struct usb_device
*udev
;
122 unsigned int command_pipe
;
123 unsigned int result_pipe
;
124 unsigned int in_pipe
;
125 unsigned int out_pipe
;
126 unsigned int irq_pipe
;
127 enum ttusb_dec_interface interface
;
128 struct mutex usb_mutex
;
132 dma_addr_t irq_dma_handle
;
134 dma_addr_t iso_dma_handle
;
135 struct urb
*iso_urb
[ISO_BUF_COUNT
];
136 int iso_stream_count
;
137 struct mutex iso_mutex
;
139 u8 packet
[MAX_PVA_LENGTH
+ 4];
140 enum ttusb_dec_packet_type packet_type
;
143 int packet_payload_length
;
146 int pva_stream_count
;
147 int filter_stream_count
;
149 struct dvb_filter_pes2ts a_pes2ts
;
150 struct dvb_filter_pes2ts v_pes2ts
;
152 u8 v_pes
[16 + MAX_PVA_LENGTH
];
156 struct list_head urb_frame_list
;
157 struct tasklet_struct urb_tasklet
;
158 spinlock_t urb_frame_list_lock
;
160 struct dvb_demux_filter
*audio_filter
;
161 struct dvb_demux_filter
*video_filter
;
162 struct list_head filter_info_list
;
163 spinlock_t filter_info_list_lock
;
165 struct input_dev
*rc_input_dev
;
168 int active
; /* Loaded successfully */
172 u8 data
[ISO_FRAME_SIZE
];
174 struct list_head urb_frame_list
;
179 struct dvb_demux_filter
*filter
;
180 struct list_head filter_info_list
;
183 static u16 rc_keys
[] = {
212 static void dvb_filter_pes2ts_init(struct dvb_filter_pes2ts
*p2ts
,
214 dvb_filter_pes2ts_cb_t
*cb
, void *priv
)
216 unsigned char *buf
=p2ts
->buf
;
226 static int dvb_filter_pes2ts(struct dvb_filter_pes2ts
*p2ts
,
227 unsigned char *pes
, int len
, int payload_start
)
229 unsigned char *buf
=p2ts
->buf
;
232 //len=6+((pes[4]<<8)|pes[5]);
239 buf
[3]=0x10|((p2ts
->cc
++)&0x0f);
240 memcpy(buf
+4, pes
, 184);
241 if ((ret
=p2ts
->cb(p2ts
->priv
, buf
)))
248 buf
[3]=0x30|((p2ts
->cc
++)&0x0f);
253 memset(buf
+6, 0xff, rest
-1);
256 memcpy(buf
+5+rest
, pes
, len
);
257 return p2ts
->cb(p2ts
->priv
, buf
);
260 static void ttusb_dec_set_model(struct ttusb_dec
*dec
,
261 enum ttusb_dec_model model
);
263 static void ttusb_dec_handle_irq( struct urb
*urb
)
265 struct ttusb_dec
*dec
= urb
->context
;
266 char *buffer
= dec
->irq_buffer
;
269 switch(urb
->status
) {
276 /* this urb is dead, cleanup */
277 dprintk("%s:urb shutting down with status: %d\n",
278 __func__
, urb
->status
);
281 dprintk("%s:nonzero status received: %d\n",
282 __func__
,urb
->status
);
286 if ((buffer
[0] == 0x1) && (buffer
[2] == 0x15)) {
290 * this is an fact a bit too simple implementation;
291 * the box also reports a keyrepeat signal
292 * (with buffer[3] == 0x40) in an intervall of ~100ms.
293 * But to handle this correctly we had to imlemenent some
294 * kind of timer which signals a 'key up' event if no
295 * keyrepeat signal is received for lets say 200ms.
296 * this should/could be added later ...
297 * for now lets report each signal as a key down and up
299 if (buffer
[4] - 1 < ARRAY_SIZE(rc_keys
)) {
300 dprintk("%s:rc signal:%d\n", __func__
, buffer
[4]);
301 input_report_key(dec
->rc_input_dev
, rc_keys
[buffer
[4] - 1], 1);
302 input_sync(dec
->rc_input_dev
);
303 input_report_key(dec
->rc_input_dev
, rc_keys
[buffer
[4] - 1], 0);
304 input_sync(dec
->rc_input_dev
);
309 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
311 printk("%s - usb_commit_urb failed with result: %d\n",
315 static u16
crc16(u16 crc
, const u8
*buf
, size_t len
)
323 crc
^= (tmp
^ (tmp
<< 1)) << 4;
328 static int ttusb_dec_send_command(struct ttusb_dec
*dec
, const u8 command
,
329 int param_length
, const u8 params
[],
330 int *result_length
, u8 cmd_result
[])
332 int result
, actual_len
;
335 dprintk("%s\n", __func__
);
337 b
= kmalloc(COMMAND_PACKET_SIZE
+ 4, GFP_KERNEL
);
341 if ((result
= mutex_lock_interruptible(&dec
->usb_mutex
))) {
343 printk("%s: Failed to lock usb mutex.\n", __func__
);
348 b
[1] = ++dec
->trans_count
;
353 memcpy(&b
[4], params
, param_length
);
356 printk(KERN_DEBUG
"%s: command: %*ph\n",
357 __func__
, param_length
, b
);
360 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
361 COMMAND_PACKET_SIZE
+ 4, &actual_len
, 1000);
364 printk("%s: command bulk message failed: error %d\n",
366 mutex_unlock(&dec
->usb_mutex
);
371 result
= usb_bulk_msg(dec
->udev
, dec
->result_pipe
, b
,
372 COMMAND_PACKET_SIZE
+ 4, &actual_len
, 1000);
375 printk("%s: result bulk message failed: error %d\n",
377 mutex_unlock(&dec
->usb_mutex
);
382 printk(KERN_DEBUG
"%s: result: %*ph\n",
383 __func__
, actual_len
, b
);
387 *result_length
= b
[3];
388 if (cmd_result
&& b
[3] > 0)
389 memcpy(cmd_result
, &b
[4], b
[3]);
391 mutex_unlock(&dec
->usb_mutex
);
398 static int ttusb_dec_get_stb_state (struct ttusb_dec
*dec
, unsigned int *mode
,
399 unsigned int *model
, unsigned int *version
)
401 u8 c
[COMMAND_PACKET_SIZE
];
406 dprintk("%s\n", __func__
);
408 result
= ttusb_dec_send_command(dec
, 0x08, 0, NULL
, &c_length
, c
);
412 if (c_length
>= 0x0c) {
418 memcpy(&tmp
, &c
[4], 4);
421 if (version
!= NULL
) {
422 memcpy(&tmp
, &c
[8], 4);
423 *version
= ntohl(tmp
);
431 static int ttusb_dec_audio_pes2ts_cb(void *priv
, unsigned char *data
)
433 struct ttusb_dec
*dec
= priv
;
435 dec
->audio_filter
->feed
->cb
.ts(data
, 188, NULL
, 0,
436 &dec
->audio_filter
->feed
->feed
.ts
);
441 static int ttusb_dec_video_pes2ts_cb(void *priv
, unsigned char *data
)
443 struct ttusb_dec
*dec
= priv
;
445 dec
->video_filter
->feed
->cb
.ts(data
, 188, NULL
, 0,
446 &dec
->video_filter
->feed
->feed
.ts
);
451 static void ttusb_dec_set_pids(struct ttusb_dec
*dec
)
453 u8 b
[] = { 0x00, 0x00, 0x00, 0x00,
454 0x00, 0x00, 0xff, 0xff,
455 0xff, 0xff, 0xff, 0xff };
457 __be16 pcr
= htons(dec
->pid
[DMX_PES_PCR
]);
458 __be16 audio
= htons(dec
->pid
[DMX_PES_AUDIO
]);
459 __be16 video
= htons(dec
->pid
[DMX_PES_VIDEO
]);
461 dprintk("%s\n", __func__
);
463 memcpy(&b
[0], &pcr
, 2);
464 memcpy(&b
[2], &audio
, 2);
465 memcpy(&b
[4], &video
, 2);
467 ttusb_dec_send_command(dec
, 0x50, sizeof(b
), b
, NULL
, NULL
);
469 dvb_filter_pes2ts_init(&dec
->a_pes2ts
, dec
->pid
[DMX_PES_AUDIO
],
470 ttusb_dec_audio_pes2ts_cb
, dec
);
471 dvb_filter_pes2ts_init(&dec
->v_pes2ts
, dec
->pid
[DMX_PES_VIDEO
],
472 ttusb_dec_video_pes2ts_cb
, dec
);
473 dec
->v_pes_length
= 0;
474 dec
->v_pes_postbytes
= 0;
477 static void ttusb_dec_process_pva(struct ttusb_dec
*dec
, u8
*pva
, int length
)
480 printk("%s: packet too short - discarding\n", __func__
);
484 if (length
> 8 + MAX_PVA_LENGTH
) {
485 printk("%s: packet too long - discarding\n", __func__
);
491 case 0x01: { /* VideoStream */
492 int prebytes
= pva
[5] & 0x03;
493 int postbytes
= (pva
[5] & 0x0c) >> 2;
494 __be16 v_pes_payload_length
;
497 dec
->video_filter
->feed
->cb
.ts(pva
, length
, NULL
, 0,
498 &dec
->video_filter
->feed
->feed
.ts
);
502 if (dec
->v_pes_postbytes
> 0 &&
503 dec
->v_pes_postbytes
== prebytes
) {
504 memcpy(&dec
->v_pes
[dec
->v_pes_length
],
507 dvb_filter_pes2ts(&dec
->v_pes2ts
, dec
->v_pes
,
508 dec
->v_pes_length
+ prebytes
, 1);
512 dec
->v_pes
[7] = 0x80;
513 dec
->v_pes
[8] = 0x05;
515 dec
->v_pes
[9] = 0x21 | ((pva
[8] & 0xc0) >> 5);
516 dec
->v_pes
[10] = ((pva
[8] & 0x3f) << 2) |
517 ((pva
[9] & 0xc0) >> 6);
518 dec
->v_pes
[11] = 0x01 |
519 ((pva
[9] & 0x3f) << 2) |
520 ((pva
[10] & 0x80) >> 6);
521 dec
->v_pes
[12] = ((pva
[10] & 0x7f) << 1) |
522 ((pva
[11] & 0xc0) >> 7);
523 dec
->v_pes
[13] = 0x01 | ((pva
[11] & 0x7f) << 1);
525 memcpy(&dec
->v_pes
[14], &pva
[12 + prebytes
],
526 length
- 12 - prebytes
);
527 dec
->v_pes_length
= 14 + length
- 12 - prebytes
;
529 dec
->v_pes
[7] = 0x00;
530 dec
->v_pes
[8] = 0x00;
532 memcpy(&dec
->v_pes
[9], &pva
[8], length
- 8);
533 dec
->v_pes_length
= 9 + length
- 8;
536 dec
->v_pes_postbytes
= postbytes
;
538 if (dec
->v_pes
[9 + dec
->v_pes
[8]] == 0x00 &&
539 dec
->v_pes
[10 + dec
->v_pes
[8]] == 0x00 &&
540 dec
->v_pes
[11 + dec
->v_pes
[8]] == 0x01)
541 dec
->v_pes
[6] = 0x84;
543 dec
->v_pes
[6] = 0x80;
545 v_pes_payload_length
= htons(dec
->v_pes_length
- 6 +
547 memcpy(&dec
->v_pes
[4], &v_pes_payload_length
, 2);
550 dvb_filter_pes2ts(&dec
->v_pes2ts
, dec
->v_pes
,
551 dec
->v_pes_length
, 1);
556 case 0x02: /* MainAudioStream */
558 dec
->audio_filter
->feed
->cb
.ts(pva
, length
, NULL
, 0,
559 &dec
->audio_filter
->feed
->feed
.ts
);
563 dvb_filter_pes2ts(&dec
->a_pes2ts
, &pva
[8], length
- 8,
568 printk("%s: unknown PVA type: %02x.\n", __func__
,
574 static void ttusb_dec_process_filter(struct ttusb_dec
*dec
, u8
*packet
,
577 struct list_head
*item
;
578 struct filter_info
*finfo
;
579 struct dvb_demux_filter
*filter
= NULL
;
584 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
585 for (item
= dec
->filter_info_list
.next
; item
!= &dec
->filter_info_list
;
587 finfo
= list_entry(item
, struct filter_info
, filter_info_list
);
588 if (finfo
->stream_id
== sid
) {
589 filter
= finfo
->filter
;
593 spin_unlock_irqrestore(&dec
->filter_info_list_lock
, flags
);
596 filter
->feed
->cb
.sec(&packet
[2], length
- 2, NULL
, 0,
600 static void ttusb_dec_process_packet(struct ttusb_dec
*dec
)
606 if (dec
->packet_length
% 2) {
607 printk("%s: odd sized packet - discarding\n", __func__
);
611 for (i
= 0; i
< dec
->packet_length
; i
+= 2)
612 csum
^= ((dec
->packet
[i
] << 8) + dec
->packet
[i
+ 1]);
615 printk("%s: checksum failed - discarding\n", __func__
);
619 packet_id
= dec
->packet
[dec
->packet_length
- 4] << 8;
620 packet_id
+= dec
->packet
[dec
->packet_length
- 3];
622 if ((packet_id
!= dec
->next_packet_id
) && dec
->next_packet_id
) {
623 printk("%s: warning: lost packets between %u and %u\n",
624 __func__
, dec
->next_packet_id
- 1, packet_id
);
627 if (packet_id
== 0xffff)
628 dec
->next_packet_id
= 0x8000;
630 dec
->next_packet_id
= packet_id
+ 1;
632 switch (dec
->packet_type
) {
633 case TTUSB_DEC_PACKET_PVA
:
634 if (dec
->pva_stream_count
)
635 ttusb_dec_process_pva(dec
, dec
->packet
,
636 dec
->packet_payload_length
);
639 case TTUSB_DEC_PACKET_SECTION
:
640 if (dec
->filter_stream_count
)
641 ttusb_dec_process_filter(dec
, dec
->packet
,
642 dec
->packet_payload_length
);
645 case TTUSB_DEC_PACKET_EMPTY
:
650 static void swap_bytes(u8
*b
, int length
)
652 length
-= length
% 2;
653 for (; length
; b
+= 2, length
-= 2)
657 static void ttusb_dec_process_urb_frame(struct ttusb_dec
*dec
, u8
*b
,
660 swap_bytes(b
, length
);
663 switch (dec
->packet_state
) {
671 dec
->packet_state
= 0;
679 dec
->packet_length
= 0;
680 } else if (*b
!= 0xaa) {
681 dec
->packet_state
= 0;
689 dec
->packet
[dec
->packet_length
++] = *b
++;
691 if (dec
->packet_length
== 2) {
692 if (dec
->packet
[0] == 'A' &&
693 dec
->packet
[1] == 'V') {
695 TTUSB_DEC_PACKET_PVA
;
697 } else if (dec
->packet
[0] == 'S') {
699 TTUSB_DEC_PACKET_SECTION
;
701 } else if (dec
->packet
[0] == 0x00) {
703 TTUSB_DEC_PACKET_EMPTY
;
704 dec
->packet_payload_length
= 2;
705 dec
->packet_state
= 7;
707 printk("%s: unknown packet type: %02x%02x\n",
709 dec
->packet
[0], dec
->packet
[1]);
710 dec
->packet_state
= 0;
718 dec
->packet
[dec
->packet_length
++] = *b
++;
720 if (dec
->packet_type
== TTUSB_DEC_PACKET_PVA
&&
721 dec
->packet_length
== 8) {
723 dec
->packet_payload_length
= 8 +
724 (dec
->packet
[6] << 8) +
726 } else if (dec
->packet_type
==
727 TTUSB_DEC_PACKET_SECTION
&&
728 dec
->packet_length
== 5) {
730 dec
->packet_payload_length
= 5 +
731 ((dec
->packet
[3] & 0x0f) << 8) +
739 int remainder
= dec
->packet_payload_length
-
742 if (length
>= remainder
) {
743 memcpy(dec
->packet
+ dec
->packet_length
,
745 dec
->packet_length
+= remainder
;
750 memcpy(&dec
->packet
[dec
->packet_length
],
752 dec
->packet_length
+= length
;
762 dec
->packet
[dec
->packet_length
++] = *b
++;
764 if (dec
->packet_type
== TTUSB_DEC_PACKET_SECTION
&&
765 dec
->packet_payload_length
% 2)
768 if (dec
->packet_length
==
769 dec
->packet_payload_length
+ tail
) {
770 ttusb_dec_process_packet(dec
);
771 dec
->packet_state
= 0;
779 printk("%s: illegal packet state encountered.\n",
781 dec
->packet_state
= 0;
786 static void ttusb_dec_process_urb_frame_list(unsigned long data
)
788 struct ttusb_dec
*dec
= (struct ttusb_dec
*)data
;
789 struct list_head
*item
;
790 struct urb_frame
*frame
;
794 spin_lock_irqsave(&dec
->urb_frame_list_lock
, flags
);
795 if ((item
= dec
->urb_frame_list
.next
) != &dec
->urb_frame_list
) {
796 frame
= list_entry(item
, struct urb_frame
,
798 list_del(&frame
->urb_frame_list
);
800 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
,
804 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
, flags
);
806 ttusb_dec_process_urb_frame(dec
, frame
->data
, frame
->length
);
811 static void ttusb_dec_process_urb(struct urb
*urb
)
813 struct ttusb_dec
*dec
= urb
->context
;
818 for (i
= 0; i
< FRAMES_PER_ISO_BUF
; i
++) {
819 struct usb_iso_packet_descriptor
*d
;
822 struct urb_frame
*frame
;
824 d
= &urb
->iso_frame_desc
[i
];
825 b
= urb
->transfer_buffer
+ d
->offset
;
826 length
= d
->actual_length
;
828 if ((frame
= kmalloc(sizeof(struct urb_frame
),
832 memcpy(frame
->data
, b
, length
);
833 frame
->length
= length
;
835 spin_lock_irqsave(&dec
->urb_frame_list_lock
,
837 list_add_tail(&frame
->urb_frame_list
,
838 &dec
->urb_frame_list
);
839 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
,
842 tasklet_schedule(&dec
->urb_tasklet
);
846 /* -ENOENT is expected when unlinking urbs */
847 if (urb
->status
!= -ENOENT
)
848 dprintk("%s: urb error: %d\n", __func__
,
852 if (dec
->iso_stream_count
)
853 usb_submit_urb(urb
, GFP_ATOMIC
);
856 static void ttusb_dec_setup_urbs(struct ttusb_dec
*dec
)
858 int i
, j
, buffer_offset
= 0;
860 dprintk("%s\n", __func__
);
862 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
863 int frame_offset
= 0;
864 struct urb
*urb
= dec
->iso_urb
[i
];
866 urb
->dev
= dec
->udev
;
868 urb
->complete
= ttusb_dec_process_urb
;
869 urb
->pipe
= dec
->in_pipe
;
870 urb
->transfer_flags
= URB_ISO_ASAP
;
872 urb
->number_of_packets
= FRAMES_PER_ISO_BUF
;
873 urb
->transfer_buffer_length
= ISO_FRAME_SIZE
*
875 urb
->transfer_buffer
= dec
->iso_buffer
+ buffer_offset
;
876 buffer_offset
+= ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
;
878 for (j
= 0; j
< FRAMES_PER_ISO_BUF
; j
++) {
879 urb
->iso_frame_desc
[j
].offset
= frame_offset
;
880 urb
->iso_frame_desc
[j
].length
= ISO_FRAME_SIZE
;
881 frame_offset
+= ISO_FRAME_SIZE
;
886 static void ttusb_dec_stop_iso_xfer(struct ttusb_dec
*dec
)
890 dprintk("%s\n", __func__
);
892 if (mutex_lock_interruptible(&dec
->iso_mutex
))
895 dec
->iso_stream_count
--;
897 if (!dec
->iso_stream_count
) {
898 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
899 usb_kill_urb(dec
->iso_urb
[i
]);
902 mutex_unlock(&dec
->iso_mutex
);
905 /* Setting the interface of the DEC tends to take down the USB communications
906 * for a short period, so it's important not to call this function just before
907 * trying to talk to it.
909 static int ttusb_dec_set_interface(struct ttusb_dec
*dec
,
910 enum ttusb_dec_interface interface
)
915 if (interface
!= dec
->interface
) {
917 case TTUSB_DEC_INTERFACE_INITIAL
:
918 result
= usb_set_interface(dec
->udev
, 0, 0);
920 case TTUSB_DEC_INTERFACE_IN
:
921 result
= ttusb_dec_send_command(dec
, 0x80, sizeof(b
),
925 result
= usb_set_interface(dec
->udev
, 0, 8);
927 case TTUSB_DEC_INTERFACE_OUT
:
928 result
= usb_set_interface(dec
->udev
, 0, 1);
935 dec
->interface
= interface
;
941 static int ttusb_dec_start_iso_xfer(struct ttusb_dec
*dec
)
945 dprintk("%s\n", __func__
);
947 if (mutex_lock_interruptible(&dec
->iso_mutex
))
950 if (!dec
->iso_stream_count
) {
951 ttusb_dec_setup_urbs(dec
);
953 dec
->packet_state
= 0;
954 dec
->v_pes_postbytes
= 0;
955 dec
->next_packet_id
= 0;
957 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
958 if ((result
= usb_submit_urb(dec
->iso_urb
[i
],
960 printk("%s: failed urb submission %d: error %d\n",
961 __func__
, i
, result
);
964 usb_kill_urb(dec
->iso_urb
[i
- 1]);
968 mutex_unlock(&dec
->iso_mutex
);
974 dec
->iso_stream_count
++;
976 mutex_unlock(&dec
->iso_mutex
);
981 static int ttusb_dec_start_ts_feed(struct dvb_demux_feed
*dvbdmxfeed
)
983 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
984 struct ttusb_dec
*dec
= dvbdmx
->priv
;
988 dprintk("%s\n", __func__
);
990 dprintk(" ts_type:");
992 if (dvbdmxfeed
->ts_type
& TS_DECODER
)
993 dprintk(" TS_DECODER");
995 if (dvbdmxfeed
->ts_type
& TS_PACKET
)
996 dprintk(" TS_PACKET");
998 if (dvbdmxfeed
->ts_type
& TS_PAYLOAD_ONLY
)
999 dprintk(" TS_PAYLOAD_ONLY");
1003 switch (dvbdmxfeed
->pes_type
) {
1006 dprintk(" pes_type: DMX_PES_VIDEO\n");
1007 dec
->pid
[DMX_PES_PCR
] = dvbdmxfeed
->pid
;
1008 dec
->pid
[DMX_PES_VIDEO
] = dvbdmxfeed
->pid
;
1009 dec
->video_filter
= dvbdmxfeed
->filter
;
1010 ttusb_dec_set_pids(dec
);
1014 dprintk(" pes_type: DMX_PES_AUDIO\n");
1015 dec
->pid
[DMX_PES_AUDIO
] = dvbdmxfeed
->pid
;
1016 dec
->audio_filter
= dvbdmxfeed
->filter
;
1017 ttusb_dec_set_pids(dec
);
1020 case DMX_PES_TELETEXT
:
1021 dec
->pid
[DMX_PES_TELETEXT
] = dvbdmxfeed
->pid
;
1022 dprintk(" pes_type: DMX_PES_TELETEXT(not supported)\n");
1026 dprintk(" pes_type: DMX_PES_PCR\n");
1027 dec
->pid
[DMX_PES_PCR
] = dvbdmxfeed
->pid
;
1028 ttusb_dec_set_pids(dec
);
1032 dprintk(" pes_type: DMX_PES_OTHER(not supported)\n");
1036 dprintk(" pes_type: unknown (%d)\n", dvbdmxfeed
->pes_type
);
1041 result
= ttusb_dec_send_command(dec
, 0x80, sizeof(b0
), b0
, NULL
, NULL
);
1045 dec
->pva_stream_count
++;
1046 return ttusb_dec_start_iso_xfer(dec
);
1049 static int ttusb_dec_start_sec_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1051 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
1052 u8 b0
[] = { 0x00, 0x00, 0x00, 0x01,
1053 0x00, 0x00, 0x00, 0x00,
1054 0x00, 0x00, 0x00, 0x00,
1055 0x00, 0x00, 0x00, 0x00,
1056 0x00, 0xff, 0x00, 0x00,
1057 0x00, 0x00, 0x00, 0x00,
1058 0x00, 0x00, 0x00, 0x00,
1061 u8 c
[COMMAND_PACKET_SIZE
];
1064 struct filter_info
*finfo
;
1065 unsigned long flags
;
1068 dprintk("%s\n", __func__
);
1070 pid
= htons(dvbdmxfeed
->pid
);
1071 memcpy(&b0
[0], &pid
, 2);
1072 memcpy(&b0
[4], &x
, 1);
1073 memcpy(&b0
[5], &dvbdmxfeed
->filter
->filter
.filter_value
[0], 1);
1075 result
= ttusb_dec_send_command(dec
, 0x60, sizeof(b0
), b0
,
1079 if (c_length
== 2) {
1080 if (!(finfo
= kmalloc(sizeof(struct filter_info
),
1084 finfo
->stream_id
= c
[1];
1085 finfo
->filter
= dvbdmxfeed
->filter
;
1087 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
1088 list_add_tail(&finfo
->filter_info_list
,
1089 &dec
->filter_info_list
);
1090 spin_unlock_irqrestore(&dec
->filter_info_list_lock
,
1093 dvbdmxfeed
->priv
= finfo
;
1095 dec
->filter_stream_count
++;
1096 return ttusb_dec_start_iso_xfer(dec
);
1104 static int ttusb_dec_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1106 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
1108 dprintk("%s\n", __func__
);
1110 if (!dvbdmx
->dmx
.frontend
)
1113 dprintk(" pid: 0x%04X\n", dvbdmxfeed
->pid
);
1115 switch (dvbdmxfeed
->type
) {
1118 return ttusb_dec_start_ts_feed(dvbdmxfeed
);
1122 return ttusb_dec_start_sec_feed(dvbdmxfeed
);
1126 dprintk(" type: unknown (%d)\n", dvbdmxfeed
->type
);
1132 static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1134 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
1137 ttusb_dec_send_command(dec
, 0x81, sizeof(b0
), b0
, NULL
, NULL
);
1139 dec
->pva_stream_count
--;
1141 ttusb_dec_stop_iso_xfer(dec
);
1146 static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1148 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
1149 u8 b0
[] = { 0x00, 0x00 };
1150 struct filter_info
*finfo
= (struct filter_info
*)dvbdmxfeed
->priv
;
1151 unsigned long flags
;
1153 b0
[1] = finfo
->stream_id
;
1154 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
1155 list_del(&finfo
->filter_info_list
);
1156 spin_unlock_irqrestore(&dec
->filter_info_list_lock
, flags
);
1158 ttusb_dec_send_command(dec
, 0x62, sizeof(b0
), b0
, NULL
, NULL
);
1160 dec
->filter_stream_count
--;
1162 ttusb_dec_stop_iso_xfer(dec
);
1167 static int ttusb_dec_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1169 dprintk("%s\n", __func__
);
1171 switch (dvbdmxfeed
->type
) {
1173 return ttusb_dec_stop_ts_feed(dvbdmxfeed
);
1177 return ttusb_dec_stop_sec_feed(dvbdmxfeed
);
1184 static void ttusb_dec_free_iso_urbs(struct ttusb_dec
*dec
)
1188 dprintk("%s\n", __func__
);
1190 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
1191 usb_free_urb(dec
->iso_urb
[i
]);
1193 pci_free_consistent(NULL
,
1194 ISO_FRAME_SIZE
* (FRAMES_PER_ISO_BUF
*
1196 dec
->iso_buffer
, dec
->iso_dma_handle
);
1199 static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec
*dec
)
1203 dprintk("%s\n", __func__
);
1205 dec
->iso_buffer
= pci_zalloc_consistent(NULL
,
1206 ISO_FRAME_SIZE
* (FRAMES_PER_ISO_BUF
* ISO_BUF_COUNT
),
1207 &dec
->iso_dma_handle
);
1209 if (!dec
->iso_buffer
) {
1210 dprintk("%s: pci_alloc_consistent - not enough memory\n",
1215 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
1218 if (!(urb
= usb_alloc_urb(FRAMES_PER_ISO_BUF
, GFP_ATOMIC
))) {
1219 ttusb_dec_free_iso_urbs(dec
);
1223 dec
->iso_urb
[i
] = urb
;
1226 ttusb_dec_setup_urbs(dec
);
1231 static void ttusb_dec_init_tasklet(struct ttusb_dec
*dec
)
1233 spin_lock_init(&dec
->urb_frame_list_lock
);
1234 INIT_LIST_HEAD(&dec
->urb_frame_list
);
1235 tasklet_init(&dec
->urb_tasklet
, ttusb_dec_process_urb_frame_list
,
1236 (unsigned long)dec
);
1239 static int ttusb_init_rc( struct ttusb_dec
*dec
)
1241 struct input_dev
*input_dev
;
1242 u8 b
[] = { 0x00, 0x01 };
1246 usb_make_path(dec
->udev
, dec
->rc_phys
, sizeof(dec
->rc_phys
));
1247 strlcat(dec
->rc_phys
, "/input0", sizeof(dec
->rc_phys
));
1249 input_dev
= input_allocate_device();
1253 input_dev
->name
= "ttusb_dec remote control";
1254 input_dev
->phys
= dec
->rc_phys
;
1255 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
);
1256 input_dev
->keycodesize
= sizeof(u16
);
1257 input_dev
->keycodemax
= 0x1a;
1258 input_dev
->keycode
= rc_keys
;
1260 for (i
= 0; i
< ARRAY_SIZE(rc_keys
); i
++)
1261 set_bit(rc_keys
[i
], input_dev
->keybit
);
1263 err
= input_register_device(input_dev
);
1265 input_free_device(input_dev
);
1269 dec
->rc_input_dev
= input_dev
;
1270 if (usb_submit_urb(dec
->irq_urb
, GFP_KERNEL
))
1271 printk("%s: usb_submit_urb failed\n",__func__
);
1272 /* enable irq pipe */
1273 ttusb_dec_send_command(dec
,0xb0,sizeof(b
),b
,NULL
,NULL
);
1278 static void ttusb_dec_init_v_pes(struct ttusb_dec
*dec
)
1280 dprintk("%s\n", __func__
);
1282 dec
->v_pes
[0] = 0x00;
1283 dec
->v_pes
[1] = 0x00;
1284 dec
->v_pes
[2] = 0x01;
1285 dec
->v_pes
[3] = 0xe0;
1288 static int ttusb_dec_init_usb(struct ttusb_dec
*dec
)
1292 dprintk("%s\n", __func__
);
1294 mutex_init(&dec
->usb_mutex
);
1295 mutex_init(&dec
->iso_mutex
);
1297 dec
->command_pipe
= usb_sndbulkpipe(dec
->udev
, COMMAND_PIPE
);
1298 dec
->result_pipe
= usb_rcvbulkpipe(dec
->udev
, RESULT_PIPE
);
1299 dec
->in_pipe
= usb_rcvisocpipe(dec
->udev
, IN_PIPE
);
1300 dec
->out_pipe
= usb_sndisocpipe(dec
->udev
, OUT_PIPE
);
1301 dec
->irq_pipe
= usb_rcvintpipe(dec
->udev
, IRQ_PIPE
);
1304 dec
->irq_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1308 dec
->irq_buffer
= usb_alloc_coherent(dec
->udev
,IRQ_PACKET_SIZE
,
1309 GFP_KERNEL
, &dec
->irq_dma_handle
);
1310 if(!dec
->irq_buffer
) {
1311 usb_free_urb(dec
->irq_urb
);
1314 usb_fill_int_urb(dec
->irq_urb
, dec
->udev
,dec
->irq_pipe
,
1315 dec
->irq_buffer
, IRQ_PACKET_SIZE
,
1316 ttusb_dec_handle_irq
, dec
, 1);
1317 dec
->irq_urb
->transfer_dma
= dec
->irq_dma_handle
;
1318 dec
->irq_urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1321 result
= ttusb_dec_alloc_iso_urbs(dec
);
1323 usb_free_urb(dec
->irq_urb
);
1324 usb_free_coherent(dec
->udev
, IRQ_PACKET_SIZE
,
1325 dec
->irq_buffer
, dec
->irq_dma_handle
);
1330 static int ttusb_dec_boot_dsp(struct ttusb_dec
*dec
)
1332 int i
, j
, actual_len
, result
, size
, trans_count
;
1333 u8 b0
[] = { 0x00, 0x00, 0x00, 0x00,
1334 0x00, 0x00, 0x00, 0x00,
1339 const u8
*firmware
= NULL
;
1340 size_t firmware_size
= 0;
1341 u16 firmware_csum
= 0;
1342 __be16 firmware_csum_ns
;
1343 __be32 firmware_size_nl
;
1344 u32 crc32_csum
, crc32_check
;
1346 const struct firmware
*fw_entry
= NULL
;
1348 dprintk("%s\n", __func__
);
1350 result
= request_firmware(&fw_entry
, dec
->firmware_name
, &dec
->udev
->dev
);
1352 printk(KERN_ERR
"%s: Firmware (%s) unavailable.\n",
1353 __func__
, dec
->firmware_name
);
1357 firmware
= fw_entry
->data
;
1358 firmware_size
= fw_entry
->size
;
1360 if (firmware_size
< 60) {
1361 printk("%s: firmware size too small for DSP code (%zu < 60).\n",
1362 __func__
, firmware_size
);
1363 release_firmware(fw_entry
);
1367 /* a 32 bit checksum over the first 56 bytes of the DSP Code is stored
1368 at offset 56 of file, so use it to check if the firmware file is
1370 crc32_csum
= crc32(~0L, firmware
, 56) ^ ~0L;
1371 memcpy(&tmp
, &firmware
[56], 4);
1372 crc32_check
= ntohl(tmp
);
1373 if (crc32_csum
!= crc32_check
) {
1374 printk("%s: crc32 check of DSP code failed (calculated 0x%08x != 0x%08x in file), file invalid.\n",
1375 __func__
, crc32_csum
, crc32_check
);
1376 release_firmware(fw_entry
);
1379 memcpy(idstring
, &firmware
[36], 20);
1380 idstring
[20] = '\0';
1381 printk(KERN_INFO
"ttusb_dec: found DSP code \"%s\".\n", idstring
);
1383 firmware_size_nl
= htonl(firmware_size
);
1384 memcpy(b0
, &firmware_size_nl
, 4);
1385 firmware_csum
= crc16(~0, firmware
, firmware_size
) ^ ~0;
1386 firmware_csum_ns
= htons(firmware_csum
);
1387 memcpy(&b0
[6], &firmware_csum_ns
, 2);
1389 result
= ttusb_dec_send_command(dec
, 0x41, sizeof(b0
), b0
, NULL
, NULL
);
1392 release_firmware(fw_entry
);
1399 b
= kmalloc(ARM_PACKET_SIZE
, GFP_KERNEL
);
1401 release_firmware(fw_entry
);
1405 for (i
= 0; i
< firmware_size
; i
+= COMMAND_PACKET_SIZE
) {
1406 size
= firmware_size
- i
;
1407 if (size
> COMMAND_PACKET_SIZE
)
1408 size
= COMMAND_PACKET_SIZE
;
1411 b
[j
+ 1] = trans_count
++;
1414 memcpy(&b
[j
+ 4], &firmware
[i
], size
);
1416 j
+= COMMAND_PACKET_SIZE
+ 4;
1418 if (j
>= ARM_PACKET_SIZE
) {
1419 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
1420 ARM_PACKET_SIZE
, &actual_len
,
1423 } else if (size
< COMMAND_PACKET_SIZE
) {
1424 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
1425 j
- COMMAND_PACKET_SIZE
+ size
,
1430 result
= ttusb_dec_send_command(dec
, 0x43, sizeof(b1
), b1
, NULL
, NULL
);
1432 release_firmware(fw_entry
);
1438 static int ttusb_dec_init_stb(struct ttusb_dec
*dec
)
1441 unsigned int mode
= 0, model
= 0, version
= 0;
1443 dprintk("%s\n", __func__
);
1445 result
= ttusb_dec_get_stb_state(dec
, &mode
, &model
, &version
);
1450 if (version
== 0xABCDEFAB)
1451 printk(KERN_INFO
"ttusb_dec: no version info in Firmware\n");
1453 printk(KERN_INFO
"ttusb_dec: Firmware %x.%02x%c%c\n",
1454 version
>> 24, (version
>> 16) & 0xff,
1455 (version
>> 8) & 0xff, version
& 0xff);
1457 result
= ttusb_dec_boot_dsp(dec
);
1461 /* We can't trust the USB IDs that some firmwares
1467 ttusb_dec_set_model(dec
, TTUSB_DEC3000S
);
1471 ttusb_dec_set_model(dec
, TTUSB_DEC2000T
);
1474 ttusb_dec_set_model(dec
, TTUSB_DEC2540T
);
1477 printk(KERN_ERR
"%s: unknown model returned by firmware (%08x) - please report\n",
1481 if (version
>= 0x01770000)
1482 dec
->can_playback
= 1;
1487 static int ttusb_dec_init_dvb(struct ttusb_dec
*dec
)
1491 dprintk("%s\n", __func__
);
1493 if ((result
= dvb_register_adapter(&dec
->adapter
,
1494 dec
->model_name
, THIS_MODULE
,
1497 printk("%s: dvb_register_adapter failed: error %d\n",
1503 dec
->demux
.dmx
.capabilities
= DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
1505 dec
->demux
.priv
= (void *)dec
;
1506 dec
->demux
.filternum
= 31;
1507 dec
->demux
.feednum
= 31;
1508 dec
->demux
.start_feed
= ttusb_dec_start_feed
;
1509 dec
->demux
.stop_feed
= ttusb_dec_stop_feed
;
1510 dec
->demux
.write_to_decoder
= NULL
;
1512 if ((result
= dvb_dmx_init(&dec
->demux
)) < 0) {
1513 printk("%s: dvb_dmx_init failed: error %d\n", __func__
,
1516 dvb_unregister_adapter(&dec
->adapter
);
1521 dec
->dmxdev
.filternum
= 32;
1522 dec
->dmxdev
.demux
= &dec
->demux
.dmx
;
1523 dec
->dmxdev
.capabilities
= 0;
1525 if ((result
= dvb_dmxdev_init(&dec
->dmxdev
, &dec
->adapter
)) < 0) {
1526 printk("%s: dvb_dmxdev_init failed: error %d\n",
1529 dvb_dmx_release(&dec
->demux
);
1530 dvb_unregister_adapter(&dec
->adapter
);
1535 dec
->frontend
.source
= DMX_FRONTEND_0
;
1537 if ((result
= dec
->demux
.dmx
.add_frontend(&dec
->demux
.dmx
,
1538 &dec
->frontend
)) < 0) {
1539 printk("%s: dvb_dmx_init failed: error %d\n", __func__
,
1542 dvb_dmxdev_release(&dec
->dmxdev
);
1543 dvb_dmx_release(&dec
->demux
);
1544 dvb_unregister_adapter(&dec
->adapter
);
1549 if ((result
= dec
->demux
.dmx
.connect_frontend(&dec
->demux
.dmx
,
1550 &dec
->frontend
)) < 0) {
1551 printk("%s: dvb_dmx_init failed: error %d\n", __func__
,
1554 dec
->demux
.dmx
.remove_frontend(&dec
->demux
.dmx
, &dec
->frontend
);
1555 dvb_dmxdev_release(&dec
->dmxdev
);
1556 dvb_dmx_release(&dec
->demux
);
1557 dvb_unregister_adapter(&dec
->adapter
);
1562 dvb_net_init(&dec
->adapter
, &dec
->dvb_net
, &dec
->demux
.dmx
);
1567 static void ttusb_dec_exit_dvb(struct ttusb_dec
*dec
)
1569 dprintk("%s\n", __func__
);
1571 dvb_net_release(&dec
->dvb_net
);
1572 dec
->demux
.dmx
.close(&dec
->demux
.dmx
);
1573 dec
->demux
.dmx
.remove_frontend(&dec
->demux
.dmx
, &dec
->frontend
);
1574 dvb_dmxdev_release(&dec
->dmxdev
);
1575 dvb_dmx_release(&dec
->demux
);
1577 dvb_unregister_frontend(dec
->fe
);
1578 if (dec
->fe
->ops
.release
)
1579 dec
->fe
->ops
.release(dec
->fe
);
1581 dvb_unregister_adapter(&dec
->adapter
);
1584 static void ttusb_dec_exit_rc(struct ttusb_dec
*dec
)
1586 dprintk("%s\n", __func__
);
1588 if (dec
->rc_input_dev
) {
1589 input_unregister_device(dec
->rc_input_dev
);
1590 dec
->rc_input_dev
= NULL
;
1595 static void ttusb_dec_exit_usb(struct ttusb_dec
*dec
)
1599 dprintk("%s\n", __func__
);
1602 /* we have to check whether the irq URB is already submitted.
1603 * As the irq is submitted after the interface is changed,
1604 * this is the best method i figured out.
1606 if (dec
->interface
== TTUSB_DEC_INTERFACE_IN
)
1607 usb_kill_urb(dec
->irq_urb
);
1609 usb_free_urb(dec
->irq_urb
);
1611 usb_free_coherent(dec
->udev
, IRQ_PACKET_SIZE
,
1612 dec
->irq_buffer
, dec
->irq_dma_handle
);
1615 dec
->iso_stream_count
= 0;
1617 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
1618 usb_kill_urb(dec
->iso_urb
[i
]);
1620 ttusb_dec_free_iso_urbs(dec
);
1623 static void ttusb_dec_exit_tasklet(struct ttusb_dec
*dec
)
1625 struct list_head
*item
;
1626 struct urb_frame
*frame
;
1628 tasklet_kill(&dec
->urb_tasklet
);
1630 while ((item
= dec
->urb_frame_list
.next
) != &dec
->urb_frame_list
) {
1631 frame
= list_entry(item
, struct urb_frame
, urb_frame_list
);
1632 list_del(&frame
->urb_frame_list
);
1637 static void ttusb_dec_init_filters(struct ttusb_dec
*dec
)
1639 INIT_LIST_HEAD(&dec
->filter_info_list
);
1640 spin_lock_init(&dec
->filter_info_list_lock
);
1643 static void ttusb_dec_exit_filters(struct ttusb_dec
*dec
)
1645 struct list_head
*item
;
1646 struct filter_info
*finfo
;
1648 while ((item
= dec
->filter_info_list
.next
) != &dec
->filter_info_list
) {
1649 finfo
= list_entry(item
, struct filter_info
, filter_info_list
);
1650 list_del(&finfo
->filter_info_list
);
1655 static int fe_send_command(struct dvb_frontend
* fe
, const u8 command
,
1656 int param_length
, const u8 params
[],
1657 int *result_length
, u8 cmd_result
[])
1659 struct ttusb_dec
* dec
= fe
->dvb
->priv
;
1660 return ttusb_dec_send_command(dec
, command
, param_length
, params
, result_length
, cmd_result
);
1663 static const struct ttusbdecfe_config fe_config
= {
1664 .send_command
= fe_send_command
1667 static int ttusb_dec_probe(struct usb_interface
*intf
,
1668 const struct usb_device_id
*id
)
1670 struct usb_device
*udev
;
1671 struct ttusb_dec
*dec
;
1674 dprintk("%s\n", __func__
);
1676 udev
= interface_to_usbdev(intf
);
1678 if (!(dec
= kzalloc(sizeof(struct ttusb_dec
), GFP_KERNEL
))) {
1679 printk("%s: couldn't allocate memory.\n", __func__
);
1683 usb_set_intfdata(intf
, (void *)dec
);
1685 switch (id
->idProduct
) {
1687 ttusb_dec_set_model(dec
, TTUSB_DEC3000S
);
1691 ttusb_dec_set_model(dec
, TTUSB_DEC2000T
);
1695 ttusb_dec_set_model(dec
, TTUSB_DEC2540T
);
1701 result
= ttusb_dec_init_usb(dec
);
1704 result
= ttusb_dec_init_stb(dec
);
1707 result
= ttusb_dec_init_dvb(dec
);
1711 dec
->adapter
.priv
= dec
;
1712 switch (id
->idProduct
) {
1714 dec
->fe
= ttusbdecfe_dvbs_attach(&fe_config
);
1719 dec
->fe
= ttusbdecfe_dvbt_attach(&fe_config
);
1723 if (dec
->fe
== NULL
) {
1724 printk("dvb-ttusb-dec: A frontend driver was not found for device [%04x:%04x]\n",
1725 le16_to_cpu(dec
->udev
->descriptor
.idVendor
),
1726 le16_to_cpu(dec
->udev
->descriptor
.idProduct
));
1728 if (dvb_register_frontend(&dec
->adapter
, dec
->fe
)) {
1729 printk("budget-ci: Frontend registration failed!\n");
1730 if (dec
->fe
->ops
.release
)
1731 dec
->fe
->ops
.release(dec
->fe
);
1736 ttusb_dec_init_v_pes(dec
);
1737 ttusb_dec_init_filters(dec
);
1738 ttusb_dec_init_tasklet(dec
);
1742 ttusb_dec_set_interface(dec
, TTUSB_DEC_INTERFACE_IN
);
1749 ttusb_dec_exit_usb(dec
);
1755 static void ttusb_dec_disconnect(struct usb_interface
*intf
)
1757 struct ttusb_dec
*dec
= usb_get_intfdata(intf
);
1759 usb_set_intfdata(intf
, NULL
);
1761 dprintk("%s\n", __func__
);
1764 ttusb_dec_exit_tasklet(dec
);
1765 ttusb_dec_exit_filters(dec
);
1767 ttusb_dec_exit_rc(dec
);
1768 ttusb_dec_exit_usb(dec
);
1769 ttusb_dec_exit_dvb(dec
);
1775 static void ttusb_dec_set_model(struct ttusb_dec
*dec
,
1776 enum ttusb_dec_model model
)
1781 case TTUSB_DEC2000T
:
1782 dec
->model_name
= "DEC2000-t";
1783 dec
->firmware_name
= "dvb-ttusb-dec-2000t.fw";
1786 case TTUSB_DEC2540T
:
1787 dec
->model_name
= "DEC2540-t";
1788 dec
->firmware_name
= "dvb-ttusb-dec-2540t.fw";
1791 case TTUSB_DEC3000S
:
1792 dec
->model_name
= "DEC3000-s";
1793 dec
->firmware_name
= "dvb-ttusb-dec-3000s.fw";
1798 static struct usb_device_id ttusb_dec_table
[] = {
1799 {USB_DEVICE(0x0b48, 0x1006)}, /* DEC3000-s */
1800 /*{USB_DEVICE(0x0b48, 0x1007)}, Unconfirmed */
1801 {USB_DEVICE(0x0b48, 0x1008)}, /* DEC2000-t */
1802 {USB_DEVICE(0x0b48, 0x1009)}, /* DEC2540-t */
1806 static struct usb_driver ttusb_dec_driver
= {
1807 .name
= "ttusb-dec",
1808 .probe
= ttusb_dec_probe
,
1809 .disconnect
= ttusb_dec_disconnect
,
1810 .id_table
= ttusb_dec_table
,
1813 module_usb_driver(ttusb_dec_driver
);
1815 MODULE_AUTHOR("Alex Woods <linux-dvb@giblets.org>");
1816 MODULE_DESCRIPTION(DRIVER_NAME
);
1817 MODULE_LICENSE("GPL");
1818 MODULE_DEVICE_TABLE(usb
, ttusb_dec_table
);