4 * Copyright (C) 2003-2004 Alex Woods <linux-dvb@giblets.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <asm/semaphore.h>
23 #include <linux/list.h>
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/pci.h>
27 #include <linux/slab.h>
28 #include <linux/spinlock.h>
29 #include <linux/usb.h>
30 #include <linux/version.h>
31 #include <linux/interrupt.h>
32 #include <linux/firmware.h>
33 #if defined(CONFIG_CRC32) || defined(CONFIG_CRC32_MODULE)
34 #include <linux/crc32.h>
36 #warning "CRC checking of firmware not available"
38 #include <linux/init.h>
41 #include "dvb_demux.h"
42 #include "dvb_filter.h"
43 #include "dvb_frontend.h"
47 static int output_pva
;
49 module_param(debug
, int, 0644);
50 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
51 module_param(output_pva
, int, 0444);
52 MODULE_PARM_DESC(output_pva
, "Output PVA from dvr device (default:off)");
54 #define dprintk if (debug) printk
56 #define DRIVER_NAME "TechnoTrend/Hauppauge DEC USB"
58 #define COMMAND_PIPE 0x03
59 #define RESULT_PIPE 0x84
63 #define COMMAND_PACKET_SIZE 0x3c
64 #define ARM_PACKET_SIZE 0x1000
66 #define ISO_BUF_COUNT 0x04
67 #define FRAMES_PER_ISO_BUF 0x04
68 #define ISO_FRAME_SIZE 0x03FF
70 #define MAX_PVA_LENGTH 6144
72 #define LOF_HI 10600000
73 #define LOF_LO 9750000
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_info
*frontend_info
;
106 int (*frontend_ioctl
) (struct dvb_frontend
*, unsigned int, void *);
108 u16 pid
[DMX_PES_OTHER
];
113 struct usb_device
*udev
;
115 unsigned int command_pipe
;
116 unsigned int result_pipe
;
117 unsigned int in_pipe
;
118 unsigned int out_pipe
;
119 enum ttusb_dec_interface interface
;
120 struct semaphore usb_sem
;
123 dma_addr_t iso_dma_handle
;
124 struct urb
*iso_urb
[ISO_BUF_COUNT
];
125 int iso_stream_count
;
126 struct semaphore iso_sem
;
128 u8 packet
[MAX_PVA_LENGTH
+ 4];
129 enum ttusb_dec_packet_type packet_type
;
132 int packet_payload_length
;
135 int pva_stream_count
;
136 int filter_stream_count
;
138 struct dvb_filter_pes2ts a_pes2ts
;
139 struct dvb_filter_pes2ts v_pes2ts
;
141 u8 v_pes
[16 + MAX_PVA_LENGTH
];
145 struct list_head urb_frame_list
;
146 struct tasklet_struct urb_tasklet
;
147 spinlock_t urb_frame_list_lock
;
149 struct dvb_demux_filter
*audio_filter
;
150 struct dvb_demux_filter
*video_filter
;
151 struct list_head filter_info_list
;
152 spinlock_t filter_info_list_lock
;
154 int active
; /* Loaded successfully */
158 u8 data
[ISO_FRAME_SIZE
];
160 struct list_head urb_frame_list
;
165 struct dvb_demux_filter
*filter
;
166 struct list_head filter_info_list
;
169 static struct dvb_frontend_info dec2000t_frontend_info
= {
170 .name
= "TechnoTrend/Hauppauge DEC2000-t Frontend",
172 .frequency_min
= 51000000,
173 .frequency_max
= 858000000,
174 .frequency_stepsize
= 62500,
175 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
176 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
177 FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
178 FE_CAN_TRANSMISSION_MODE_AUTO
| FE_CAN_GUARD_INTERVAL_AUTO
|
179 FE_CAN_HIERARCHY_AUTO
,
182 static struct dvb_frontend_info dec3000s_frontend_info
= {
183 .name
= "TechnoTrend/Hauppauge DEC3000-s Frontend",
185 .frequency_min
= 950000,
186 .frequency_max
= 2150000,
187 .frequency_stepsize
= 125,
188 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
189 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
190 FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
191 FE_CAN_TRANSMISSION_MODE_AUTO
| FE_CAN_GUARD_INTERVAL_AUTO
|
192 FE_CAN_HIERARCHY_AUTO
,
195 static void ttusb_dec_set_model(struct ttusb_dec
*dec
,
196 enum ttusb_dec_model model
);
198 static u16
crc16(u16 crc
, const u8
*buf
, size_t len
)
206 crc
^= (tmp
^ (tmp
<< 1)) << 4;
211 static int ttusb_dec_send_command(struct ttusb_dec
*dec
, const u8 command
,
212 int param_length
, const u8 params
[],
213 int *result_length
, u8 cmd_result
[])
215 int result
, actual_len
, i
;
218 dprintk("%s\n", __FUNCTION__
);
220 b
= kmalloc(COMMAND_PACKET_SIZE
+ 4, GFP_KERNEL
);
224 if ((result
= down_interruptible(&dec
->usb_sem
))) {
226 printk("%s: Failed to down usb semaphore.\n", __FUNCTION__
);
231 b
[1] = ++dec
->trans_count
;
236 memcpy(&b
[4], params
, param_length
);
239 printk("%s: command: ", __FUNCTION__
);
240 for (i
= 0; i
< param_length
+ 4; i
++)
241 printk("0x%02X ", b
[i
]);
245 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
246 COMMAND_PACKET_SIZE
+ 4, &actual_len
, HZ
);
249 printk("%s: command bulk message failed: error %d\n",
250 __FUNCTION__
, result
);
256 result
= usb_bulk_msg(dec
->udev
, dec
->result_pipe
, b
,
257 COMMAND_PACKET_SIZE
+ 4, &actual_len
, HZ
);
260 printk("%s: result bulk message failed: error %d\n",
261 __FUNCTION__
, result
);
267 printk("%s: result: ", __FUNCTION__
);
268 for (i
= 0; i
< actual_len
; i
++)
269 printk("0x%02X ", b
[i
]);
274 *result_length
= b
[3];
275 if (cmd_result
&& b
[3] > 0)
276 memcpy(cmd_result
, &b
[4], b
[3]);
285 static int ttusb_dec_get_stb_state (struct ttusb_dec
*dec
, unsigned int *mode
,
286 unsigned int *model
, unsigned int *version
)
288 u8 c
[COMMAND_PACKET_SIZE
];
293 dprintk("%s\n", __FUNCTION__
);
295 result
= ttusb_dec_send_command(dec
, 0x08, 0, NULL
, &c_length
, c
);
299 if (c_length
>= 0x0c) {
305 memcpy(&tmp
, &c
[4], 4);
308 if (version
!= NULL
) {
309 memcpy(&tmp
, &c
[8], 4);
310 *version
= ntohl(tmp
);
318 static int ttusb_dec_audio_pes2ts_cb(void *priv
, unsigned char *data
)
320 struct ttusb_dec
*dec
= (struct ttusb_dec
*)priv
;
322 dec
->audio_filter
->feed
->cb
.ts(data
, 188, NULL
, 0,
323 &dec
->audio_filter
->feed
->feed
.ts
,
329 static int ttusb_dec_video_pes2ts_cb(void *priv
, unsigned char *data
)
331 struct ttusb_dec
*dec
= (struct ttusb_dec
*)priv
;
333 dec
->video_filter
->feed
->cb
.ts(data
, 188, NULL
, 0,
334 &dec
->video_filter
->feed
->feed
.ts
,
340 static void ttusb_dec_set_pids(struct ttusb_dec
*dec
)
342 u8 b
[] = { 0x00, 0x00, 0x00, 0x00,
343 0x00, 0x00, 0xff, 0xff,
344 0xff, 0xff, 0xff, 0xff };
346 u16 pcr
= htons(dec
->pid
[DMX_PES_PCR
]);
347 u16 audio
= htons(dec
->pid
[DMX_PES_AUDIO
]);
348 u16 video
= htons(dec
->pid
[DMX_PES_VIDEO
]);
350 dprintk("%s\n", __FUNCTION__
);
352 memcpy(&b
[0], &pcr
, 2);
353 memcpy(&b
[2], &audio
, 2);
354 memcpy(&b
[4], &video
, 2);
356 ttusb_dec_send_command(dec
, 0x50, sizeof(b
), b
, NULL
, NULL
);
358 dvb_filter_pes2ts_init(&dec
->a_pes2ts
, dec
->pid
[DMX_PES_AUDIO
],
359 ttusb_dec_audio_pes2ts_cb
, dec
);
360 dvb_filter_pes2ts_init(&dec
->v_pes2ts
, dec
->pid
[DMX_PES_VIDEO
],
361 ttusb_dec_video_pes2ts_cb
, dec
);
362 dec
->v_pes_length
= 0;
363 dec
->v_pes_postbytes
= 0;
366 static void ttusb_dec_process_pva(struct ttusb_dec
*dec
, u8
*pva
, int length
)
369 printk("%s: packet too short - discarding\n", __FUNCTION__
);
373 if (length
> 8 + MAX_PVA_LENGTH
) {
374 printk("%s: packet too long - discarding\n", __FUNCTION__
);
380 case 0x01: { /* VideoStream */
381 int prebytes
= pva
[5] & 0x03;
382 int postbytes
= (pva
[5] & 0x0c) >> 2;
383 u16 v_pes_payload_length
;
386 dec
->video_filter
->feed
->cb
.ts(pva
, length
, NULL
, 0,
387 &dec
->video_filter
->feed
->feed
.ts
, DMX_OK
);
391 if (dec
->v_pes_postbytes
> 0 &&
392 dec
->v_pes_postbytes
== prebytes
) {
393 memcpy(&dec
->v_pes
[dec
->v_pes_length
],
396 dvb_filter_pes2ts(&dec
->v_pes2ts
, dec
->v_pes
,
397 dec
->v_pes_length
+ prebytes
, 1);
401 dec
->v_pes
[7] = 0x80;
402 dec
->v_pes
[8] = 0x05;
404 dec
->v_pes
[9] = 0x21 | ((pva
[8] & 0xc0) >> 5);
405 dec
->v_pes
[10] = ((pva
[8] & 0x3f) << 2) |
406 ((pva
[9] & 0xc0) >> 6);
407 dec
->v_pes
[11] = 0x01 |
408 ((pva
[9] & 0x3f) << 2) |
409 ((pva
[10] & 0x80) >> 6);
410 dec
->v_pes
[12] = ((pva
[10] & 0x7f) << 1) |
411 ((pva
[11] & 0xc0) >> 7);
412 dec
->v_pes
[13] = 0x01 | ((pva
[11] & 0x7f) << 1);
414 memcpy(&dec
->v_pes
[14], &pva
[12 + prebytes
],
415 length
- 12 - prebytes
);
416 dec
->v_pes_length
= 14 + length
- 12 - prebytes
;
418 dec
->v_pes
[7] = 0x00;
419 dec
->v_pes
[8] = 0x00;
421 memcpy(&dec
->v_pes
[9], &pva
[8], length
- 8);
422 dec
->v_pes_length
= 9 + length
- 8;
425 dec
->v_pes_postbytes
= postbytes
;
427 if (dec
->v_pes
[9 + dec
->v_pes
[8]] == 0x00 &&
428 dec
->v_pes
[10 + dec
->v_pes
[8]] == 0x00 &&
429 dec
->v_pes
[11 + dec
->v_pes
[8]] == 0x01)
430 dec
->v_pes
[6] = 0x84;
432 dec
->v_pes
[6] = 0x80;
434 v_pes_payload_length
= htons(dec
->v_pes_length
- 6 +
436 memcpy(&dec
->v_pes
[4], &v_pes_payload_length
, 2);
439 dvb_filter_pes2ts(&dec
->v_pes2ts
, dec
->v_pes
,
440 dec
->v_pes_length
, 1);
445 case 0x02: /* MainAudioStream */
447 dec
->audio_filter
->feed
->cb
.ts(pva
, length
, NULL
, 0,
448 &dec
->audio_filter
->feed
->feed
.ts
, DMX_OK
);
452 dvb_filter_pes2ts(&dec
->a_pes2ts
, &pva
[8], length
- 8,
457 printk("%s: unknown PVA type: %02x.\n", __FUNCTION__
,
463 static void ttusb_dec_process_filter(struct ttusb_dec
*dec
, u8
*packet
,
466 struct list_head
*item
;
467 struct filter_info
*finfo
;
468 struct dvb_demux_filter
*filter
= NULL
;
473 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
474 for (item
= dec
->filter_info_list
.next
; item
!= &dec
->filter_info_list
;
476 finfo
= list_entry(item
, struct filter_info
, filter_info_list
);
477 if (finfo
->stream_id
== sid
) {
478 filter
= finfo
->filter
;
482 spin_unlock_irqrestore(&dec
->filter_info_list_lock
, flags
);
485 filter
->feed
->cb
.sec(&packet
[2], length
- 2, NULL
, 0,
486 &filter
->filter
, DMX_OK
);
489 static void ttusb_dec_process_packet(struct ttusb_dec
*dec
)
495 if (dec
->packet_length
% 2) {
496 printk("%s: odd sized packet - discarding\n", __FUNCTION__
);
500 for (i
= 0; i
< dec
->packet_length
; i
+= 2)
501 csum
^= ((dec
->packet
[i
] << 8) + dec
->packet
[i
+ 1]);
504 printk("%s: checksum failed - discarding\n", __FUNCTION__
);
508 packet_id
= dec
->packet
[dec
->packet_length
- 4] << 8;
509 packet_id
+= dec
->packet
[dec
->packet_length
- 3];
511 if ((packet_id
!= dec
->next_packet_id
) && dec
->next_packet_id
) {
512 printk("%s: warning: lost packets between %u and %u\n",
513 __FUNCTION__
, dec
->next_packet_id
- 1, packet_id
);
516 if (packet_id
== 0xffff)
517 dec
->next_packet_id
= 0x8000;
519 dec
->next_packet_id
= packet_id
+ 1;
521 switch (dec
->packet_type
) {
522 case TTUSB_DEC_PACKET_PVA
:
523 if (dec
->pva_stream_count
)
524 ttusb_dec_process_pva(dec
, dec
->packet
,
525 dec
->packet_payload_length
);
528 case TTUSB_DEC_PACKET_SECTION
:
529 if (dec
->filter_stream_count
)
530 ttusb_dec_process_filter(dec
, dec
->packet
,
531 dec
->packet_payload_length
);
534 case TTUSB_DEC_PACKET_EMPTY
:
539 static void swap_bytes(u8
*b
, int length
)
543 length
-= length
% 2;
544 for (; length
; b
+= 2, length
-= 2) {
551 static void ttusb_dec_process_urb_frame(struct ttusb_dec
* dec
, u8
* b
,
554 swap_bytes(b
, length
);
557 switch (dec
->packet_state
) {
565 dec
->packet_state
= 0;
573 dec
->packet_length
= 0;
574 } else if (*b
!= 0xaa) {
575 dec
->packet_state
= 0;
583 dec
->packet
[dec
->packet_length
++] = *b
++;
585 if (dec
->packet_length
== 2) {
586 if (dec
->packet
[0] == 'A' &&
587 dec
->packet
[1] == 'V') {
589 TTUSB_DEC_PACKET_PVA
;
591 } else if (dec
->packet
[0] == 'S') {
593 TTUSB_DEC_PACKET_SECTION
;
595 } else if (dec
->packet
[0] == 0x00) {
597 TTUSB_DEC_PACKET_EMPTY
;
598 dec
->packet_payload_length
= 2;
599 dec
->packet_state
= 7;
601 printk("%s: unknown packet type: "
602 "%02x%02x\n", __FUNCTION__
,
603 dec
->packet
[0], dec
->packet
[1]);
604 dec
->packet_state
= 0;
612 dec
->packet
[dec
->packet_length
++] = *b
++;
614 if (dec
->packet_type
== TTUSB_DEC_PACKET_PVA
&&
615 dec
->packet_length
== 8) {
617 dec
->packet_payload_length
= 8 +
618 (dec
->packet
[6] << 8) +
620 } else if (dec
->packet_type
==
621 TTUSB_DEC_PACKET_SECTION
&&
622 dec
->packet_length
== 5) {
624 dec
->packet_payload_length
= 5 +
625 ((dec
->packet
[3] & 0x0f) << 8) +
633 int remainder
= dec
->packet_payload_length
-
636 if (length
>= remainder
) {
637 memcpy(dec
->packet
+ dec
->packet_length
,
639 dec
->packet_length
+= remainder
;
644 memcpy(&dec
->packet
[dec
->packet_length
],
646 dec
->packet_length
+= length
;
656 dec
->packet
[dec
->packet_length
++] = *b
++;
658 if (dec
->packet_type
== TTUSB_DEC_PACKET_SECTION
&&
659 dec
->packet_payload_length
% 2)
662 if (dec
->packet_length
==
663 dec
->packet_payload_length
+ tail
) {
664 ttusb_dec_process_packet(dec
);
665 dec
->packet_state
= 0;
673 printk("%s: illegal packet state encountered.\n",
675 dec
->packet_state
= 0;
680 static void ttusb_dec_process_urb_frame_list(unsigned long data
)
682 struct ttusb_dec
*dec
= (struct ttusb_dec
*)data
;
683 struct list_head
*item
;
684 struct urb_frame
*frame
;
688 spin_lock_irqsave(&dec
->urb_frame_list_lock
, flags
);
689 if ((item
= dec
->urb_frame_list
.next
) != &dec
->urb_frame_list
) {
690 frame
= list_entry(item
, struct urb_frame
,
692 list_del(&frame
->urb_frame_list
);
694 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
,
698 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
, flags
);
700 ttusb_dec_process_urb_frame(dec
, frame
->data
, frame
->length
);
705 static void ttusb_dec_process_urb(struct urb
*urb
, struct pt_regs
*ptregs
)
707 struct ttusb_dec
*dec
= urb
->context
;
712 for (i
= 0; i
< FRAMES_PER_ISO_BUF
; i
++) {
713 struct usb_iso_packet_descriptor
*d
;
717 struct urb_frame
*frame
;
719 d
= &urb
->iso_frame_desc
[i
];
720 b
= urb
->transfer_buffer
+ d
->offset
;
721 length
= d
->actual_length
;
723 if ((frame
= kmalloc(sizeof(struct urb_frame
),
727 memcpy(frame
->data
, b
, length
);
728 frame
->length
= length
;
730 spin_lock_irqsave(&dec
->urb_frame_list_lock
,
732 list_add_tail(&frame
->urb_frame_list
,
733 &dec
->urb_frame_list
);
734 spin_unlock_irqrestore(&dec
->urb_frame_list_lock
,
737 tasklet_schedule(&dec
->urb_tasklet
);
741 /* -ENOENT is expected when unlinking urbs */
742 if (urb
->status
!= -ENOENT
)
743 dprintk("%s: urb error: %d\n", __FUNCTION__
,
747 if (dec
->iso_stream_count
)
748 usb_submit_urb(urb
, GFP_ATOMIC
);
751 static void ttusb_dec_setup_urbs(struct ttusb_dec
*dec
)
753 int i
, j
, buffer_offset
= 0;
755 dprintk("%s\n", __FUNCTION__
);
757 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
758 int frame_offset
= 0;
759 struct urb
*urb
= dec
->iso_urb
[i
];
761 urb
->dev
= dec
->udev
;
763 urb
->complete
= ttusb_dec_process_urb
;
764 urb
->pipe
= dec
->in_pipe
;
765 urb
->transfer_flags
= URB_ISO_ASAP
;
767 urb
->number_of_packets
= FRAMES_PER_ISO_BUF
;
768 urb
->transfer_buffer_length
= ISO_FRAME_SIZE
*
770 urb
->transfer_buffer
= dec
->iso_buffer
+ buffer_offset
;
771 buffer_offset
+= ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
;
773 for (j
= 0; j
< FRAMES_PER_ISO_BUF
; j
++) {
774 urb
->iso_frame_desc
[j
].offset
= frame_offset
;
775 urb
->iso_frame_desc
[j
].length
= ISO_FRAME_SIZE
;
776 frame_offset
+= ISO_FRAME_SIZE
;
781 static void ttusb_dec_stop_iso_xfer(struct ttusb_dec
*dec
)
785 dprintk("%s\n", __FUNCTION__
);
787 if (down_interruptible(&dec
->iso_sem
))
790 dec
->iso_stream_count
--;
792 if (!dec
->iso_stream_count
) {
793 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
794 usb_unlink_urb(dec
->iso_urb
[i
]);
800 /* Setting the interface of the DEC tends to take down the USB communications
801 * for a short period, so it's important not to call this function just before
802 * trying to talk to it.
804 static int ttusb_dec_set_interface(struct ttusb_dec
*dec
,
805 enum ttusb_dec_interface interface
)
810 if (interface
!= dec
->interface
) {
812 case TTUSB_DEC_INTERFACE_INITIAL
:
813 result
= usb_set_interface(dec
->udev
, 0, 0);
815 case TTUSB_DEC_INTERFACE_IN
:
816 result
= ttusb_dec_send_command(dec
, 0x80, sizeof(b
),
820 result
= usb_set_interface(dec
->udev
, 0, 7);
822 case TTUSB_DEC_INTERFACE_OUT
:
823 result
= usb_set_interface(dec
->udev
, 0, 1);
830 dec
->interface
= interface
;
836 static int ttusb_dec_start_iso_xfer(struct ttusb_dec
*dec
)
840 dprintk("%s\n", __FUNCTION__
);
842 if (down_interruptible(&dec
->iso_sem
))
845 if (!dec
->iso_stream_count
) {
846 ttusb_dec_setup_urbs(dec
);
848 dec
->packet_state
= 0;
849 dec
->v_pes_postbytes
= 0;
850 dec
->next_packet_id
= 0;
852 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
853 if ((result
= usb_submit_urb(dec
->iso_urb
[i
],
855 printk("%s: failed urb submission %d: "
856 "error %d\n", __FUNCTION__
, i
, result
);
859 usb_unlink_urb(dec
->iso_urb
[i
- 1]);
869 dec
->iso_stream_count
++;
876 static int ttusb_dec_start_ts_feed(struct dvb_demux_feed
*dvbdmxfeed
)
878 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
879 struct ttusb_dec
*dec
= dvbdmx
->priv
;
883 dprintk("%s\n", __FUNCTION__
);
885 dprintk(" ts_type:");
887 if (dvbdmxfeed
->ts_type
& TS_DECODER
)
888 dprintk(" TS_DECODER");
890 if (dvbdmxfeed
->ts_type
& TS_PACKET
)
891 dprintk(" TS_PACKET");
893 if (dvbdmxfeed
->ts_type
& TS_PAYLOAD_ONLY
)
894 dprintk(" TS_PAYLOAD_ONLY");
898 switch (dvbdmxfeed
->pes_type
) {
900 case DMX_TS_PES_VIDEO
:
901 dprintk(" pes_type: DMX_TS_PES_VIDEO\n");
902 dec
->pid
[DMX_PES_PCR
] = dvbdmxfeed
->pid
;
903 dec
->pid
[DMX_PES_VIDEO
] = dvbdmxfeed
->pid
;
904 dec
->video_filter
= dvbdmxfeed
->filter
;
905 ttusb_dec_set_pids(dec
);
908 case DMX_TS_PES_AUDIO
:
909 dprintk(" pes_type: DMX_TS_PES_AUDIO\n");
910 dec
->pid
[DMX_PES_AUDIO
] = dvbdmxfeed
->pid
;
911 dec
->audio_filter
= dvbdmxfeed
->filter
;
912 ttusb_dec_set_pids(dec
);
915 case DMX_TS_PES_TELETEXT
:
916 dec
->pid
[DMX_PES_TELETEXT
] = dvbdmxfeed
->pid
;
917 dprintk(" pes_type: DMX_TS_PES_TELETEXT\n");
921 dprintk(" pes_type: DMX_TS_PES_PCR\n");
922 dec
->pid
[DMX_PES_PCR
] = dvbdmxfeed
->pid
;
923 ttusb_dec_set_pids(dec
);
926 case DMX_TS_PES_OTHER
:
927 dprintk(" pes_type: DMX_TS_PES_OTHER\n");
931 dprintk(" pes_type: unknown (%d)\n", dvbdmxfeed
->pes_type
);
936 result
= ttusb_dec_send_command(dec
, 0x80, sizeof(b0
), b0
, NULL
, NULL
);
940 dec
->pva_stream_count
++;
941 return ttusb_dec_start_iso_xfer(dec
);
944 static int ttusb_dec_start_sec_feed(struct dvb_demux_feed
*dvbdmxfeed
)
946 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
947 u8 b0
[] = { 0x00, 0x00, 0x00, 0x01,
948 0x00, 0x00, 0x00, 0x00,
949 0x00, 0x00, 0x00, 0x00,
950 0x00, 0x00, 0x00, 0x00,
951 0x00, 0xff, 0x00, 0x00,
952 0x00, 0x00, 0x00, 0x00,
953 0x00, 0x00, 0x00, 0x00,
956 u8 c
[COMMAND_PACKET_SIZE
];
959 struct filter_info
*finfo
;
963 dprintk("%s\n", __FUNCTION__
);
965 pid
= htons(dvbdmxfeed
->pid
);
966 memcpy(&b0
[0], &pid
, 2);
967 memcpy(&b0
[4], &x
, 1);
968 memcpy(&b0
[5], &dvbdmxfeed
->filter
->filter
.filter_value
[0], 1);
970 result
= ttusb_dec_send_command(dec
, 0x60, sizeof(b0
), b0
,
975 if (!(finfo
= kmalloc(sizeof(struct filter_info
),
979 finfo
->stream_id
= c
[1];
980 finfo
->filter
= dvbdmxfeed
->filter
;
982 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
983 list_add_tail(&finfo
->filter_info_list
,
984 &dec
->filter_info_list
);
985 spin_unlock_irqrestore(&dec
->filter_info_list_lock
,
988 dvbdmxfeed
->priv
= finfo
;
990 dec
->filter_stream_count
++;
991 return ttusb_dec_start_iso_xfer(dec
);
999 static int ttusb_dec_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1001 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
1003 dprintk("%s\n", __FUNCTION__
);
1005 if (!dvbdmx
->dmx
.frontend
)
1008 dprintk(" pid: 0x%04X\n", dvbdmxfeed
->pid
);
1010 switch (dvbdmxfeed
->type
) {
1013 return ttusb_dec_start_ts_feed(dvbdmxfeed
);
1017 return ttusb_dec_start_sec_feed(dvbdmxfeed
);
1021 dprintk(" type: unknown (%d)\n", dvbdmxfeed
->type
);
1027 static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1029 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
1032 ttusb_dec_send_command(dec
, 0x81, sizeof(b0
), b0
, NULL
, NULL
);
1034 dec
->pva_stream_count
--;
1036 ttusb_dec_stop_iso_xfer(dec
);
1041 static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1043 struct ttusb_dec
*dec
= dvbdmxfeed
->demux
->priv
;
1044 u8 b0
[] = { 0x00, 0x00 };
1045 struct filter_info
*finfo
= (struct filter_info
*)dvbdmxfeed
->priv
;
1046 unsigned long flags
;
1048 b0
[1] = finfo
->stream_id
;
1049 spin_lock_irqsave(&dec
->filter_info_list_lock
, flags
);
1050 list_del(&finfo
->filter_info_list
);
1051 spin_unlock_irqrestore(&dec
->filter_info_list_lock
, flags
);
1053 ttusb_dec_send_command(dec
, 0x62, sizeof(b0
), b0
, NULL
, NULL
);
1055 dec
->filter_stream_count
--;
1057 ttusb_dec_stop_iso_xfer(dec
);
1062 static int ttusb_dec_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1064 dprintk("%s\n", __FUNCTION__
);
1066 switch (dvbdmxfeed
->type
) {
1068 return ttusb_dec_stop_ts_feed(dvbdmxfeed
);
1072 return ttusb_dec_stop_sec_feed(dvbdmxfeed
);
1079 static void ttusb_dec_free_iso_urbs(struct ttusb_dec
*dec
)
1083 dprintk("%s\n", __FUNCTION__
);
1085 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
1086 if (dec
->iso_urb
[i
])
1087 usb_free_urb(dec
->iso_urb
[i
]);
1089 pci_free_consistent(NULL
,
1090 ISO_FRAME_SIZE
* (FRAMES_PER_ISO_BUF
*
1092 dec
->iso_buffer
, dec
->iso_dma_handle
);
1095 static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec
*dec
)
1099 dprintk("%s\n", __FUNCTION__
);
1101 dec
->iso_buffer
= pci_alloc_consistent(NULL
,
1103 (FRAMES_PER_ISO_BUF
*
1105 &dec
->iso_dma_handle
);
1107 memset(dec
->iso_buffer
, 0,
1108 ISO_FRAME_SIZE
* (FRAMES_PER_ISO_BUF
* ISO_BUF_COUNT
));
1110 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
1113 if (!(urb
= usb_alloc_urb(FRAMES_PER_ISO_BUF
, GFP_ATOMIC
))) {
1114 ttusb_dec_free_iso_urbs(dec
);
1118 dec
->iso_urb
[i
] = urb
;
1121 ttusb_dec_setup_urbs(dec
);
1126 static void ttusb_dec_init_tasklet(struct ttusb_dec
*dec
)
1128 dec
->urb_frame_list_lock
= SPIN_LOCK_UNLOCKED
;
1129 INIT_LIST_HEAD(&dec
->urb_frame_list
);
1130 tasklet_init(&dec
->urb_tasklet
, ttusb_dec_process_urb_frame_list
,
1131 (unsigned long)dec
);
1134 static void ttusb_dec_init_v_pes(struct ttusb_dec
*dec
)
1136 dprintk("%s\n", __FUNCTION__
);
1138 dec
->v_pes
[0] = 0x00;
1139 dec
->v_pes
[1] = 0x00;
1140 dec
->v_pes
[2] = 0x01;
1141 dec
->v_pes
[3] = 0xe0;
1144 static void ttusb_dec_init_usb(struct ttusb_dec
*dec
)
1146 dprintk("%s\n", __FUNCTION__
);
1148 sema_init(&dec
->usb_sem
, 1);
1149 sema_init(&dec
->iso_sem
, 1);
1151 dec
->command_pipe
= usb_sndbulkpipe(dec
->udev
, COMMAND_PIPE
);
1152 dec
->result_pipe
= usb_rcvbulkpipe(dec
->udev
, RESULT_PIPE
);
1153 dec
->in_pipe
= usb_rcvisocpipe(dec
->udev
, IN_PIPE
);
1154 dec
->out_pipe
= usb_sndisocpipe(dec
->udev
, OUT_PIPE
);
1156 ttusb_dec_alloc_iso_urbs(dec
);
1159 static int ttusb_dec_boot_dsp(struct ttusb_dec
*dec
)
1161 int i
, j
, actual_len
, result
, size
, trans_count
;
1162 u8 b0
[] = { 0x00, 0x00, 0x00, 0x00,
1163 0x00, 0x00, 0x00, 0x00,
1168 u8
*firmware
= NULL
;
1169 size_t firmware_size
= 0;
1170 u16 firmware_csum
= 0;
1171 u16 firmware_csum_ns
;
1172 u32 firmware_size_nl
;
1173 #if defined(CONFIG_CRC32) || defined(CONFIG_CRC32_MODULE)
1174 u32 crc32_csum
, crc32_check
, tmp
;
1176 const struct firmware
*fw_entry
= NULL
;
1177 dprintk("%s\n", __FUNCTION__
);
1179 if (request_firmware(&fw_entry
, dec
->firmware_name
, &dec
->udev
->dev
)) {
1180 printk(KERN_ERR
"%s: Firmware (%s) unavailable.\n",
1181 __FUNCTION__
, dec
->firmware_name
);
1185 firmware
= fw_entry
->data
;
1186 firmware_size
= fw_entry
->size
;
1188 if (firmware_size
< 60) {
1189 printk("%s: firmware size too small for DSP code (%zu < 60).\n",
1190 __FUNCTION__
, firmware_size
);
1194 /* a 32 bit checksum over the first 56 bytes of the DSP Code is stored
1195 at offset 56 of file, so use it to check if the firmware file is
1197 #if defined(CONFIG_CRC32) || defined(CONFIG_CRC32_MODULE)
1198 crc32_csum
= crc32(~0L, firmware
, 56) ^ ~0L;
1199 memcpy(&tmp
, &firmware
[56], 4);
1200 crc32_check
= htonl(tmp
);
1201 if (crc32_csum
!= crc32_check
) {
1202 printk("%s: crc32 check of DSP code failed (calculated "
1203 "0x%08x != 0x%08x in file), file invalid.\n",
1204 __FUNCTION__
, crc32_csum
, crc32_check
);
1208 memcpy(idstring
, &firmware
[36], 20);
1209 idstring
[20] = '\0';
1210 printk(KERN_INFO
"ttusb_dec: found DSP code \"%s\".\n", idstring
);
1212 firmware_size_nl
= htonl(firmware_size
);
1213 memcpy(b0
, &firmware_size_nl
, 4);
1214 firmware_csum
= crc16(~0, firmware
, firmware_size
) ^ ~0;
1215 firmware_csum_ns
= htons(firmware_csum
);
1216 memcpy(&b0
[6], &firmware_csum_ns
, 2);
1218 result
= ttusb_dec_send_command(dec
, 0x41, sizeof(b0
), b0
, NULL
, NULL
);
1226 b
= kmalloc(ARM_PACKET_SIZE
, GFP_KERNEL
);
1230 for (i
= 0; i
< firmware_size
; i
+= COMMAND_PACKET_SIZE
) {
1231 size
= firmware_size
- i
;
1232 if (size
> COMMAND_PACKET_SIZE
)
1233 size
= COMMAND_PACKET_SIZE
;
1236 b
[j
+ 1] = trans_count
++;
1239 memcpy(&b
[j
+ 4], &firmware
[i
], size
);
1241 j
+= COMMAND_PACKET_SIZE
+ 4;
1243 if (j
>= ARM_PACKET_SIZE
) {
1244 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
1245 ARM_PACKET_SIZE
, &actual_len
,
1248 } else if (size
< COMMAND_PACKET_SIZE
) {
1249 result
= usb_bulk_msg(dec
->udev
, dec
->command_pipe
, b
,
1250 j
- COMMAND_PACKET_SIZE
+ size
,
1251 &actual_len
, HZ
/ 10);
1255 result
= ttusb_dec_send_command(dec
, 0x43, sizeof(b1
), b1
, NULL
, NULL
);
1262 static int ttusb_dec_init_stb(struct ttusb_dec
*dec
)
1265 unsigned int mode
, model
, version
;
1267 dprintk("%s\n", __FUNCTION__
);
1269 result
= ttusb_dec_get_stb_state(dec
, &mode
, &model
, &version
);
1273 if (version
== 0xABCDEFAB)
1274 printk(KERN_INFO
"ttusb_dec: no version "
1275 "info in Firmware\n");
1277 printk(KERN_INFO
"ttusb_dec: Firmware "
1279 version
>> 24, (version
>> 16) & 0xff,
1280 (version
>> 8) & 0xff, version
& 0xff);
1282 result
= ttusb_dec_boot_dsp(dec
);
1288 /* We can't trust the USB IDs that some firmwares
1293 ttusb_dec_set_model(dec
, TTUSB_DEC3000S
);
1296 ttusb_dec_set_model(dec
, TTUSB_DEC2000T
);
1299 ttusb_dec_set_model(dec
, TTUSB_DEC2540T
);
1302 printk(KERN_ERR
"%s: unknown model returned "
1303 "by firmware (%08x) - please report\n",
1304 __FUNCTION__
, model
);
1309 if (version
>= 0x01770000)
1310 dec
->can_playback
= 1;
1319 static int ttusb_dec_init_dvb(struct ttusb_dec
*dec
)
1323 dprintk("%s\n", __FUNCTION__
);
1325 if ((result
= dvb_register_adapter(&dec
->adapter
,
1326 dec
->model_name
, THIS_MODULE
)) < 0) {
1327 printk("%s: dvb_register_adapter failed: error %d\n",
1328 __FUNCTION__
, result
);
1333 dec
->demux
.dmx
.capabilities
= DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
1335 dec
->demux
.priv
= (void *)dec
;
1336 dec
->demux
.filternum
= 31;
1337 dec
->demux
.feednum
= 31;
1338 dec
->demux
.start_feed
= ttusb_dec_start_feed
;
1339 dec
->demux
.stop_feed
= ttusb_dec_stop_feed
;
1340 dec
->demux
.write_to_decoder
= NULL
;
1342 if ((result
= dvb_dmx_init(&dec
->demux
)) < 0) {
1343 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__
,
1346 dvb_unregister_adapter(dec
->adapter
);
1351 dec
->dmxdev
.filternum
= 32;
1352 dec
->dmxdev
.demux
= &dec
->demux
.dmx
;
1353 dec
->dmxdev
.capabilities
= 0;
1355 if ((result
= dvb_dmxdev_init(&dec
->dmxdev
, dec
->adapter
)) < 0) {
1356 printk("%s: dvb_dmxdev_init failed: error %d\n",
1357 __FUNCTION__
, result
);
1359 dvb_dmx_release(&dec
->demux
);
1360 dvb_unregister_adapter(dec
->adapter
);
1365 dec
->frontend
.source
= DMX_FRONTEND_0
;
1367 if ((result
= dec
->demux
.dmx
.add_frontend(&dec
->demux
.dmx
,
1368 &dec
->frontend
)) < 0) {
1369 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__
,
1372 dvb_dmxdev_release(&dec
->dmxdev
);
1373 dvb_dmx_release(&dec
->demux
);
1374 dvb_unregister_adapter(dec
->adapter
);
1379 if ((result
= dec
->demux
.dmx
.connect_frontend(&dec
->demux
.dmx
,
1380 &dec
->frontend
)) < 0) {
1381 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__
,
1384 dec
->demux
.dmx
.remove_frontend(&dec
->demux
.dmx
, &dec
->frontend
);
1385 dvb_dmxdev_release(&dec
->dmxdev
);
1386 dvb_dmx_release(&dec
->demux
);
1387 dvb_unregister_adapter(dec
->adapter
);
1392 dvb_net_init(dec
->adapter
, &dec
->dvb_net
, &dec
->demux
.dmx
);
1397 static void ttusb_dec_exit_dvb(struct ttusb_dec
*dec
)
1399 dprintk("%s\n", __FUNCTION__
);
1401 dvb_net_release(&dec
->dvb_net
);
1402 dec
->demux
.dmx
.close(&dec
->demux
.dmx
);
1403 dec
->demux
.dmx
.remove_frontend(&dec
->demux
.dmx
, &dec
->frontend
);
1404 dvb_dmxdev_release(&dec
->dmxdev
);
1405 dvb_dmx_release(&dec
->demux
);
1406 dvb_unregister_adapter(dec
->adapter
);
1409 static void ttusb_dec_exit_usb(struct ttusb_dec
*dec
)
1413 dprintk("%s\n", __FUNCTION__
);
1415 dec
->iso_stream_count
= 0;
1417 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
1418 usb_unlink_urb(dec
->iso_urb
[i
]);
1420 ttusb_dec_free_iso_urbs(dec
);
1423 static void ttusb_dec_exit_tasklet(struct ttusb_dec
*dec
)
1425 struct list_head
*item
;
1426 struct urb_frame
*frame
;
1428 tasklet_kill(&dec
->urb_tasklet
);
1430 while ((item
= dec
->urb_frame_list
.next
) != &dec
->urb_frame_list
) {
1431 frame
= list_entry(item
, struct urb_frame
, urb_frame_list
);
1432 list_del(&frame
->urb_frame_list
);
1437 static int ttusb_dec_2000t_frontend_ioctl(struct dvb_frontend
*fe
, unsigned int cmd
,
1440 struct ttusb_dec
*dec
= fe
->data
;
1442 dprintk("%s\n", __FUNCTION__
);
1447 dprintk("%s: FE_GET_INFO\n", __FUNCTION__
);
1448 memcpy(arg
, dec
->frontend_info
,
1449 sizeof (struct dvb_frontend_info
));
1452 case FE_READ_STATUS
: {
1453 fe_status_t
*status
= (fe_status_t
*)arg
;
1454 dprintk("%s: FE_READ_STATUS\n", __FUNCTION__
);
1455 *status
= FE_HAS_SIGNAL
| FE_HAS_VITERBI
|
1456 FE_HAS_SYNC
| FE_HAS_CARRIER
| FE_HAS_LOCK
;
1461 u32
*ber
= (u32
*)arg
;
1462 dprintk("%s: FE_READ_BER\n", __FUNCTION__
);
1468 case FE_READ_SIGNAL_STRENGTH
: {
1469 dprintk("%s: FE_READ_SIGNAL_STRENGTH\n", __FUNCTION__
);
1476 dprintk("%s: FE_READ_SNR\n", __FUNCTION__
);
1481 case FE_READ_UNCORRECTED_BLOCKS
:
1482 dprintk("%s: FE_READ_UNCORRECTED_BLOCKS\n", __FUNCTION__
);
1487 case FE_SET_FRONTEND
: {
1488 struct dvb_frontend_parameters
*p
=
1489 (struct dvb_frontend_parameters
*)arg
;
1490 u8 b
[] = { 0x00, 0x00, 0x00, 0x03,
1491 0x00, 0x00, 0x00, 0x00,
1492 0x00, 0x00, 0x00, 0x01,
1493 0x00, 0x00, 0x00, 0xff,
1494 0x00, 0x00, 0x00, 0xff };
1497 dprintk("%s: FE_SET_FRONTEND\n", __FUNCTION__
);
1499 dprintk(" frequency->%d\n", p
->frequency
);
1500 dprintk(" symbol_rate->%d\n",
1501 p
->u
.qam
.symbol_rate
);
1502 dprintk(" inversion->%d\n", p
->inversion
);
1504 freq
= htonl(p
->frequency
/ 1000);
1505 memcpy(&b
[4], &freq
, sizeof (u32
));
1506 ttusb_dec_send_command(dec
, 0x71, sizeof(b
), b
, NULL
, NULL
);
1511 case FE_GET_FRONTEND
:
1512 dprintk("%s: FE_GET_FRONTEND\n", __FUNCTION__
);
1516 dprintk("%s: FE_SLEEP\n", __FUNCTION__
);
1521 dprintk("%s: FE_INIT\n", __FUNCTION__
);
1525 dprintk("%s: unknown IOCTL (0x%X)\n", __FUNCTION__
, cmd
);
1533 static int ttusb_dec_3000s_frontend_ioctl(struct dvb_frontend
*fe
,
1534 unsigned int cmd
, void *arg
)
1536 struct ttusb_dec
*dec
= fe
->data
;
1538 dprintk("%s\n", __FUNCTION__
);
1543 dprintk("%s: FE_GET_INFO\n", __FUNCTION__
);
1544 memcpy(arg
, dec
->frontend_info
,
1545 sizeof (struct dvb_frontend_info
));
1548 case FE_READ_STATUS
: {
1549 fe_status_t
*status
= (fe_status_t
*)arg
;
1550 dprintk("%s: FE_READ_STATUS\n", __FUNCTION__
);
1551 *status
= FE_HAS_SIGNAL
| FE_HAS_VITERBI
|
1552 FE_HAS_SYNC
| FE_HAS_CARRIER
| FE_HAS_LOCK
;
1557 u32
*ber
= (u32
*)arg
;
1558 dprintk("%s: FE_READ_BER\n", __FUNCTION__
);
1564 case FE_READ_SIGNAL_STRENGTH
: {
1565 dprintk("%s: FE_READ_SIGNAL_STRENGTH\n", __FUNCTION__
);
1572 dprintk("%s: FE_READ_SNR\n", __FUNCTION__
);
1577 case FE_READ_UNCORRECTED_BLOCKS
:
1578 dprintk("%s: FE_READ_UNCORRECTED_BLOCKS\n", __FUNCTION__
);
1583 case FE_SET_FRONTEND
: {
1584 struct dvb_frontend_parameters
*p
=
1585 (struct dvb_frontend_parameters
*)arg
;
1586 u8 b
[] = { 0x00, 0x00, 0x00, 0x01,
1587 0x00, 0x00, 0x00, 0x00,
1588 0x00, 0x00, 0x00, 0x01,
1589 0x00, 0x00, 0x00, 0x00,
1590 0x00, 0x00, 0x00, 0x00,
1591 0x00, 0x00, 0x00, 0x00,
1592 0x00, 0x00, 0x00, 0x00,
1593 0x00, 0x00, 0x00, 0x00,
1594 0x00, 0x00, 0x00, 0x00,
1595 0x00, 0x00, 0x00, 0x00 };
1601 dprintk("%s: FE_SET_FRONTEND\n", __FUNCTION__
);
1603 dprintk(" frequency->%d\n", p
->frequency
);
1604 dprintk(" symbol_rate->%d\n",
1605 p
->u
.qam
.symbol_rate
);
1606 dprintk(" inversion->%d\n", p
->inversion
);
1608 freq
= htonl(p
->frequency
+
1609 (dec
->hi_band
? LOF_HI
: LOF_LO
));
1610 memcpy(&b
[4], &freq
, sizeof(u32
));
1611 sym_rate
= htonl(p
->u
.qam
.symbol_rate
);
1612 memcpy(&b
[12], &sym_rate
, sizeof(u32
));
1613 band
= htonl(dec
->hi_band
? LOF_HI
: LOF_LO
);
1614 memcpy(&b
[24], &band
, sizeof(u32
));
1615 lnb_voltage
= htonl(dec
->voltage
);
1616 memcpy(&b
[28], &lnb_voltage
, sizeof(u32
));
1618 ttusb_dec_send_command(dec
, 0x71, sizeof(b
), b
, NULL
, NULL
);
1623 case FE_GET_FRONTEND
:
1624 dprintk("%s: FE_GET_FRONTEND\n", __FUNCTION__
);
1628 dprintk("%s: FE_SLEEP\n", __FUNCTION__
);
1633 dprintk("%s: FE_INIT\n", __FUNCTION__
);
1636 case FE_DISEQC_SEND_MASTER_CMD
: {
1637 u8 b
[] = { 0x00, 0xff, 0x00, 0x00,
1638 0x00, 0x00, 0x00, 0x00,
1640 struct dvb_diseqc_master_cmd
*cmd
= arg
;
1641 memcpy(&b
[4], cmd
->msg
, cmd
->msg_len
);
1642 dprintk("%s: FE_DISEQC_SEND_MASTER_CMD\n", __FUNCTION__
);
1643 ttusb_dec_send_command(dec
, 0x72,
1644 sizeof(b
) - (6 - cmd
->msg_len
), b
,
1649 case FE_DISEQC_SEND_BURST
:
1650 dprintk("%s: FE_DISEQC_SEND_BURST\n", __FUNCTION__
);
1654 fe_sec_tone_mode_t tone
= (fe_sec_tone_mode_t
)arg
;
1655 dprintk("%s: FE_SET_TONE\n", __FUNCTION__
);
1656 dec
->hi_band
= (SEC_TONE_ON
== tone
);
1660 case FE_SET_VOLTAGE
:
1661 dprintk("%s: FE_SET_VOLTAGE\n", __FUNCTION__
);
1662 switch ((fe_sec_voltage_t
) arg
) {
1663 case SEC_VOLTAGE_13
:
1666 case SEC_VOLTAGE_18
:
1676 dprintk("%s: unknown IOCTL (0x%X)\n", __FUNCTION__
, cmd
);
1684 static void ttusb_dec_init_frontend(struct ttusb_dec
*dec
)
1687 ret
= dvb_register_frontend(dec
->frontend_ioctl
, dec
->adapter
, dec
, dec
->frontend_info
, THIS_MODULE
);
1690 static void ttusb_dec_exit_frontend(struct ttusb_dec
*dec
)
1692 dvb_unregister_frontend_new(dec
->frontend_ioctl
, dec
->adapter
);
1695 static void ttusb_dec_init_filters(struct ttusb_dec
*dec
)
1697 INIT_LIST_HEAD(&dec
->filter_info_list
);
1698 dec
->filter_info_list_lock
= SPIN_LOCK_UNLOCKED
;
1701 static void ttusb_dec_exit_filters(struct ttusb_dec
*dec
)
1703 struct list_head
*item
;
1704 struct filter_info
*finfo
;
1706 while ((item
= dec
->filter_info_list
.next
) != &dec
->filter_info_list
) {
1707 finfo
= list_entry(item
, struct filter_info
, filter_info_list
);
1708 list_del(&finfo
->filter_info_list
);
1713 static int ttusb_dec_probe(struct usb_interface
*intf
,
1714 const struct usb_device_id
*id
)
1716 struct usb_device
*udev
;
1717 struct ttusb_dec
*dec
;
1719 dprintk("%s\n", __FUNCTION__
);
1721 udev
= interface_to_usbdev(intf
);
1723 if (!(dec
= kmalloc(sizeof(struct ttusb_dec
), GFP_KERNEL
))) {
1724 printk("%s: couldn't allocate memory.\n", __FUNCTION__
);
1728 usb_set_intfdata(intf
, (void *)dec
);
1730 memset(dec
, 0, sizeof(struct ttusb_dec
));
1732 switch (id
->idProduct
) {
1734 ttusb_dec_set_model(dec
, TTUSB_DEC3000S
);
1738 ttusb_dec_set_model(dec
, TTUSB_DEC2000T
);
1742 ttusb_dec_set_model(dec
, TTUSB_DEC2540T
);
1748 ttusb_dec_init_usb(dec
);
1749 if (ttusb_dec_init_stb(dec
)) {
1750 ttusb_dec_exit_usb(dec
);
1753 ttusb_dec_init_dvb(dec
);
1754 ttusb_dec_init_frontend(dec
);
1755 ttusb_dec_init_v_pes(dec
);
1756 ttusb_dec_init_filters(dec
);
1757 ttusb_dec_init_tasklet(dec
);
1761 ttusb_dec_set_interface(dec
, TTUSB_DEC_INTERFACE_IN
);
1766 static void ttusb_dec_disconnect(struct usb_interface
*intf
)
1768 struct ttusb_dec
*dec
= usb_get_intfdata(intf
);
1770 usb_set_intfdata(intf
, NULL
);
1772 dprintk("%s\n", __FUNCTION__
);
1775 ttusb_dec_exit_tasklet(dec
);
1776 ttusb_dec_exit_filters(dec
);
1777 ttusb_dec_exit_usb(dec
);
1778 ttusb_dec_exit_frontend(dec
);
1779 ttusb_dec_exit_dvb(dec
);
1785 static void ttusb_dec_set_model(struct ttusb_dec
*dec
,
1786 enum ttusb_dec_model model
)
1791 case TTUSB_DEC2000T
:
1792 dec
->model_name
= "DEC2000-t";
1793 dec
->firmware_name
= "dvb-ttusb-dec-2000t.fw";
1794 dec
->frontend_info
= &dec2000t_frontend_info
;
1795 dec
->frontend_ioctl
= ttusb_dec_2000t_frontend_ioctl
;
1798 case TTUSB_DEC2540T
:
1799 dec
->model_name
= "DEC2540-t";
1800 dec
->firmware_name
= "dvb-ttusb-dec-2540t.fw";
1801 dec
->frontend_info
= &dec2000t_frontend_info
;
1802 dec
->frontend_ioctl
= ttusb_dec_2000t_frontend_ioctl
;
1805 case TTUSB_DEC3000S
:
1806 dec
->model_name
= "DEC3000-s";
1807 dec
->firmware_name
= "dvb-ttusb-dec-3000s.fw";
1808 dec
->frontend_info
= &dec3000s_frontend_info
;
1809 dec
->frontend_ioctl
= ttusb_dec_3000s_frontend_ioctl
;
1814 static struct usb_device_id ttusb_dec_table
[] = {
1815 {USB_DEVICE(0x0b48, 0x1006)}, /* DEC3000-s */
1816 /*{USB_DEVICE(0x0b48, 0x1007)}, Unconfirmed */
1817 {USB_DEVICE(0x0b48, 0x1008)}, /* DEC2000-t */
1818 {USB_DEVICE(0x0b48, 0x1009)}, /* DEC2540-t */
1822 static struct usb_driver ttusb_dec_driver
= {
1823 .name
= "ttusb-dec",
1824 .probe
= ttusb_dec_probe
,
1825 .disconnect
= ttusb_dec_disconnect
,
1826 .id_table
= ttusb_dec_table
,
1829 static int __init
ttusb_dec_init(void)
1833 if ((result
= usb_register(&ttusb_dec_driver
)) < 0) {
1834 printk("%s: initialisation failed: error %d.\n", __FUNCTION__
,
1842 static void __exit
ttusb_dec_exit(void)
1844 usb_deregister(&ttusb_dec_driver
);
1847 module_init(ttusb_dec_init
);
1848 module_exit(ttusb_dec_exit
);
1850 MODULE_AUTHOR("Alex Woods <linux-dvb@giblets.org>");
1851 MODULE_DESCRIPTION(DRIVER_NAME
);
1852 MODULE_LICENSE("GPL");
1853 MODULE_DEVICE_TABLE(usb
, ttusb_dec_table
);