4 * Copyright (c) 2002 Holger Waechtler <holger@convergence.de>
5 * Copyright (c) 2003 Felix Domke <tmbinc@elitedvb.net>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/wait.h>
15 #include <linux/module.h>
16 #include <linux/usb.h>
17 #include <linux/delay.h>
18 #include <linux/time.h>
19 #include <linux/errno.h>
20 #include <linux/jiffies.h>
21 #include <linux/mutex.h>
23 #include "dvb_frontend.h"
25 #include "dvb_demux.h"
35 #include <linux/dvb/frontend.h>
36 #include <linux/dvb/dmx.h>
37 #include <linux/pci.h>
41 the DSP supports filtering in hardware, however, since the "muxstream"
42 is a bit braindead (no matching channel masks or no matching filter mask),
43 we won't support this - yet. it doesn't event support negative filters,
44 so the best way is maybe to keep TTUSB_HWSECTIONS undef'd and just
45 parse TS data. USB bandwidth will be a problem when having large
46 datastreams, especially for dvb-net, but hey, that's not my problem.
48 TTUSB_DISEQC, TTUSB_TONE:
49 let the STC do the diseqc/tone stuff. this isn't supported at least with
50 my TTUSB, so let it undef'd unless you want to implement another
51 frontend. never tested.
54 define it to > 3 for really hardcore debugging. you probably don't want
55 this unless the device doesn't load at all. > 2 for bandwidth statistics.
59 module_param(debug
, int, 0644);
60 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
62 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
64 #define dprintk(x...) do { if (debug) printk(KERN_DEBUG x); } while (0)
66 #define ISO_BUF_COUNT 4
67 #define FRAMES_PER_ISO_BUF 4
68 #define ISO_FRAME_SIZE 912
69 #define TTUSB_MAXCHANNEL 32
70 #ifdef TTUSB_HWSECTIONS
71 #define TTUSB_MAXFILTER 16 /* ??? */
74 #define TTUSB_REV_2_2 0x22
75 #define TTUSB_BUDGET_NAME "ttusb_stc_fw"
78 * since we're casting (struct ttusb*) <-> (struct dvb_demux*) around
79 * the dvb_demux field must be the first in struct!!
82 struct dvb_demux dvb_demux
;
84 struct dvb_net dvbnet
;
86 /* and one for USB access. */
90 struct dvb_adapter adapter
;
91 struct usb_device
*dev
;
93 struct i2c_adapter i2c_adap
;
98 unsigned int bulk_out_pipe
;
99 unsigned int bulk_in_pipe
;
100 unsigned int isoc_in_pipe
;
103 dma_addr_t iso_dma_handle
;
105 struct urb
*iso_urb
[ISO_BUF_COUNT
];
107 int running_feed_count
;
111 u8 c
; /* transaction counter, wraps around... */
112 fe_sec_tone_mode_t tone
;
113 fe_sec_voltage_t voltage
;
115 int mux_state
; // 0..2 - MuxSyncWord, 3 - nMuxPacks, 4 - muxpack
118 int muxpack_ptr
, muxpack_len
;
122 int cc
; /* MuxCounter - will increment on EVERY MUX PACKET */
123 /* (including stuffing. yes. really.) */
129 struct dvb_frontend
* fe
;
132 /* ugly workaround ... don't know why it's necessary to read */
133 /* all result codes. */
136 static int ttusb_cmd(struct ttusb
*ttusb
,
137 const u8
* data
, int len
, int needresult
)
145 for (i
= 0; i
< len
; ++i
)
146 printk(" %02x", data
[i
]);
150 if (mutex_lock_interruptible(&ttusb
->semusb
) < 0)
153 err
= usb_bulk_msg(ttusb
->dev
, ttusb
->bulk_out_pipe
,
154 (u8
*) data
, len
, &actual_len
, 1000);
156 dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n",
158 mutex_unlock(&ttusb
->semusb
);
161 if (actual_len
!= len
) {
162 dprintk("%s: only wrote %d of %d bytes\n", __func__
,
164 mutex_unlock(&ttusb
->semusb
);
168 err
= usb_bulk_msg(ttusb
->dev
, ttusb
->bulk_in_pipe
,
169 ttusb
->last_result
, 32, &actual_len
, 1000);
172 printk("%s: failed, receive error %d\n", __func__
,
174 mutex_unlock(&ttusb
->semusb
);
178 actual_len
= ttusb
->last_result
[3] + 4;
180 for (i
= 0; i
< actual_len
; ++i
)
181 printk(" %02x", ttusb
->last_result
[i
]);
185 mutex_unlock(&ttusb
->semusb
);
189 static int ttusb_result(struct ttusb
*ttusb
, u8
* data
, int len
)
191 memcpy(data
, ttusb
->last_result
, len
);
192 mutex_unlock(&ttusb
->semusb
);
196 static int ttusb_i2c_msg(struct ttusb
*ttusb
,
197 u8 addr
, u8
* snd_buf
, u8 snd_len
, u8
* rcv_buf
,
204 if (snd_len
> 0x28 - 7 || rcv_len
> 0x20 - 7)
215 for (i
= 0; i
< snd_len
; i
++)
216 b
[7 + i
] = snd_buf
[i
];
218 err
= ttusb_cmd(ttusb
, b
, snd_len
+ 7, 1);
223 err
= ttusb_result(ttusb
, b
, 0x20);
225 /* check if the i2c transaction was successful */
226 if ((snd_len
!= b
[5]) || (rcv_len
!= b
[6])) return -EREMOTEIO
;
230 if (err
|| b
[0] != 0x55 || b
[1] != id
) {
232 ("%s: usb_bulk_msg(recv) failed, err == %i, id == %02x, b == ",
237 for (i
= 0; i
< rcv_len
; i
++)
238 rcv_buf
[i
] = b
[7 + i
];
244 static int master_xfer(struct i2c_adapter
* adapter
, struct i2c_msg
*msg
, int num
)
246 struct ttusb
*ttusb
= i2c_get_adapdata(adapter
);
250 if (mutex_lock_interruptible(&ttusb
->semi2c
) < 0)
254 u8 addr
, snd_len
, rcv_len
, *snd_buf
, *rcv_buf
;
257 if (num
> i
+ 1 && (msg
[i
+ 1].flags
& I2C_M_RD
)) {
259 snd_buf
= msg
[i
].buf
;
260 snd_len
= msg
[i
].len
;
261 rcv_buf
= msg
[i
+ 1].buf
;
262 rcv_len
= msg
[i
+ 1].len
;
266 snd_buf
= msg
[i
].buf
;
267 snd_len
= msg
[i
].len
;
273 err
= ttusb_i2c_msg(ttusb
, addr
,
274 snd_buf
, snd_len
, rcv_buf
, rcv_len
);
277 dprintk("%s: i == %i\n", __func__
, i
);
284 mutex_unlock(&ttusb
->semi2c
);
288 #include "dvb-ttusb-dspbootcode.h"
290 static int ttusb_boot_dsp(struct ttusb
*ttusb
)
300 /* upload dsp code in 32 byte steps (36 didn't work for me ...) */
301 /* 32 is max packet size, no messages should be splitted. */
302 for (i
= 0; i
< sizeof(dsp_bootcode
); i
+= 28) {
303 memcpy(&b
[4], &dsp_bootcode
[i
], 28);
307 err
= ttusb_cmd(ttusb
, b
, 32, 0);
317 err
= ttusb_cmd(ttusb
, b
, 4, 0);
326 err
= ttusb_cmd(ttusb
, b
, 4, 0);
330 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
337 static int ttusb_set_channel(struct ttusb
*ttusb
, int chan_id
, int filter_type
,
342 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x22, 4, chan_id
, filter_type
,
343 (pid
>> 8) & 0xff, pid
& 0xff
346 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
350 static int ttusb_del_channel(struct ttusb
*ttusb
, int channel_id
)
354 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x23, 1, channel_id
};
356 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
360 #ifdef TTUSB_HWSECTIONS
361 static int ttusb_set_filter(struct ttusb
*ttusb
, int filter_id
,
362 int associated_chan
, u8 filter
[8], u8 mask
[8])
366 u8 b
[] = { 0xaa, 0, 0x24, 0x1a, filter_id
, associated_chan
,
367 filter
[0], filter
[1], filter
[2], filter
[3],
368 filter
[4], filter
[5], filter
[6], filter
[7],
369 filter
[8], filter
[9], filter
[10], filter
[11],
370 mask
[0], mask
[1], mask
[2], mask
[3],
371 mask
[4], mask
[5], mask
[6], mask
[7],
372 mask
[8], mask
[9], mask
[10], mask
[11]
375 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
379 static int ttusb_del_filter(struct ttusb
*ttusb
, int filter_id
)
383 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x25, 1, filter_id
};
385 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
390 static int ttusb_init_controller(struct ttusb
*ttusb
)
392 u8 b0
[] = { 0xaa, ++ttusb
->c
, 0x15, 1, 0 };
393 u8 b1
[] = { 0xaa, ++ttusb
->c
, 0x15, 1, 1 };
394 u8 b2
[] = { 0xaa, ++ttusb
->c
, 0x32, 1, 0 };
395 /* i2c write read: 5 bytes, addr 0x10, 0x02 bytes write, 1 bytes read. */
397 { 0xaa, ++ttusb
->c
, 0x31, 5, 0x10, 0x02, 0x01, 0x00, 0x1e };
399 { 0x55, ttusb
->c
, 0x31, 4, 0x10, 0x02, 0x01, 0x00, 0x1e };
401 u8 get_version
[] = { 0xaa, ++ttusb
->c
, 0x17, 5, 0, 0, 0, 0, 0 };
402 u8 get_dsp_version
[0x20] =
403 { 0xaa, ++ttusb
->c
, 0x26, 28, 0, 0, 0, 0, 0 };
407 if ((err
= ttusb_cmd(ttusb
, b0
, sizeof(b0
), 0)))
410 /* reset board (again?) */
411 if ((err
= ttusb_cmd(ttusb
, b1
, sizeof(b1
), 0)))
414 ttusb_boot_dsp(ttusb
);
416 /* set i2c bit rate */
417 if ((err
= ttusb_cmd(ttusb
, b2
, sizeof(b2
), 0)))
420 if ((err
= ttusb_cmd(ttusb
, b3
, sizeof(b3
), 1)))
423 err
= ttusb_result(ttusb
, b4
, sizeof(b4
));
425 if ((err
= ttusb_cmd(ttusb
, get_version
, sizeof(get_version
), 1)))
428 if ((err
= ttusb_result(ttusb
, get_version
, sizeof(get_version
))))
431 dprintk("%s: stc-version: %c%c%c%c%c\n", __func__
,
432 get_version
[4], get_version
[5], get_version
[6],
433 get_version
[7], get_version
[8]);
435 if (memcmp(get_version
+ 4, "V 0.0", 5) &&
436 memcmp(get_version
+ 4, "V 1.1", 5) &&
437 memcmp(get_version
+ 4, "V 2.1", 5) &&
438 memcmp(get_version
+ 4, "V 2.2", 5)) {
440 ("%s: unknown STC version %c%c%c%c%c, please report!\n",
441 __func__
, get_version
[4], get_version
[5],
442 get_version
[6], get_version
[7], get_version
[8]);
445 ttusb
->revision
= ((get_version
[6] - '0') << 4) |
446 (get_version
[8] - '0');
449 ttusb_cmd(ttusb
, get_dsp_version
, sizeof(get_dsp_version
), 1);
454 ttusb_result(ttusb
, get_dsp_version
, sizeof(get_dsp_version
));
457 printk("%s: dsp-version: %c%c%c\n", __func__
,
458 get_dsp_version
[4], get_dsp_version
[5], get_dsp_version
[6]);
463 static int ttusb_send_diseqc(struct dvb_frontend
* fe
,
464 const struct dvb_diseqc_master_cmd
*cmd
)
466 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
467 u8 b
[12] = { 0xaa, ++ttusb
->c
, 0x18 };
471 b
[3] = 4 + 2 + cmd
->msg_len
;
472 b
[4] = 0xFF; /* send diseqc master, not burst */
475 memcpy(b
+ 5, cmd
->msg
, cmd
->msg_len
);
478 if ((err
= ttusb_cmd(ttusb
, b
, 4 + b
[3], 0))) {
479 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
487 static int ttusb_update_lnb(struct ttusb
*ttusb
)
489 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x16, 5, /*power: */ 1,
490 ttusb
->voltage
== SEC_VOLTAGE_18
? 0 : 1,
491 ttusb
->tone
== SEC_TONE_ON
? 1 : 0, 1, 1
496 if ((err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0))) {
497 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
504 static int ttusb_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
)
506 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
508 ttusb
->voltage
= voltage
;
509 return ttusb_update_lnb(ttusb
);
513 static int ttusb_set_tone(struct dvb_frontend
* fe
, fe_sec_tone_mode_t tone
)
515 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
518 return ttusb_update_lnb(ttusb
);
524 static void ttusb_set_led_freq(struct ttusb
*ttusb
, u8 freq
)
526 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x19, 1, freq
};
529 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
531 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
537 /*****************************************************************************/
539 #ifdef TTUSB_HWSECTIONS
540 static void ttusb_handle_ts_data(struct ttusb_channel
*channel
,
541 const u8
* data
, int len
);
542 static void ttusb_handle_sec_data(struct ttusb_channel
*channel
,
543 const u8
* data
, int len
);
546 static int numpkt
, numts
, numstuff
, numsec
, numinvalid
;
547 static unsigned long lastj
;
549 static void ttusb_process_muxpack(struct ttusb
*ttusb
, const u8
* muxpack
,
554 for (i
= 0; i
< len
; i
+= 2)
555 csum
^= le16_to_cpup((u16
*) (muxpack
+ i
));
557 printk("%s: muxpack with incorrect checksum, ignoring\n",
563 cc
= (muxpack
[len
- 4] << 8) | muxpack
[len
- 3];
565 if ((cc
!= ttusb
->cc
) && (ttusb
->cc
!= -1))
566 printk("%s: cc discontinuity (%d frames missing)\n",
567 __func__
, (cc
- ttusb
->cc
) & 0x7FFF);
568 ttusb
->cc
= (cc
+ 1) & 0x7FFF;
569 if (muxpack
[0] & 0x80) {
570 #ifdef TTUSB_HWSECTIONS
572 int pusi
= muxpack
[0] & 0x40;
573 int channel
= muxpack
[0] & 0x1F;
574 int payload
= muxpack
[1];
575 const u8
*data
= muxpack
+ 2;
576 /* check offset flag */
577 if (muxpack
[0] & 0x20)
580 ttusb_handle_sec_data(ttusb
->channel
+ channel
, data
,
584 if ((!!(ttusb
->muxpack
[0] & 0x20)) ^
585 !!(ttusb
->muxpack
[1] & 1))
588 printk("cc: %04x\n", (data
[0] << 8) | data
[1]);
591 } else if (muxpack
[0] == 0x47) {
592 #ifdef TTUSB_HWSECTIONS
593 /* we have TS data here! */
594 int pid
= ((muxpack
[1] & 0x0F) << 8) | muxpack
[2];
596 for (channel
= 0; channel
< TTUSB_MAXCHANNEL
; ++channel
)
597 if (ttusb
->channel
[channel
].active
598 && (pid
== ttusb
->channel
[channel
].pid
))
599 ttusb_handle_ts_data(ttusb
->channel
+
604 dvb_dmx_swfilter_packets(&ttusb
->dvb_demux
, muxpack
, 1);
605 } else if (muxpack
[0] != 0) {
607 printk("illegal muxpack type %02x\n", muxpack
[0]);
612 static void ttusb_process_frame(struct ttusb
*ttusb
, u8
* data
, int len
)
617 printk("%s: too much work\n", __func__
);
621 switch (ttusb
->mux_state
) {
629 ttusb
->mux_state
= 0;
632 printk("%02x ", data
[-1]);
635 printk("%s: lost sync.\n",
645 ttusb
->mux_npacks
= *data
++;
647 ttusb
->muxpack_ptr
= 0;
648 /* maximum bytes, until we know the length */
649 ttusb
->muxpack_len
= 2;
656 (ttusb
->muxpack_len
-
661 memcpy(ttusb
->muxpack
+ ttusb
->muxpack_ptr
,
663 ttusb
->muxpack_ptr
+= avail
;
664 BUG_ON(ttusb
->muxpack_ptr
> 264);
667 /* determine length */
668 if (ttusb
->muxpack_ptr
== 2) {
669 if (ttusb
->muxpack
[0] & 0x80) {
671 ttusb
->muxpack
[1] + 2;
678 muxpack
[0] & 0x20)) ^
683 ttusb
->muxpack_len
+= 4;
684 } else if (ttusb
->muxpack
[0] ==
688 else if (ttusb
->muxpack
[0] == 0x00)
690 ttusb
->muxpack
[1] + 2 +
694 ("%s: invalid state: first byte is %x\n",
697 ttusb
->mux_state
= 0;
702 * if length is valid and we reached the end:
705 if ((ttusb
->muxpack_ptr
>= 2) &&
706 (ttusb
->muxpack_ptr
==
707 ttusb
->muxpack_len
)) {
708 ttusb_process_muxpack(ttusb
,
713 ttusb
->muxpack_ptr
= 0;
714 /* maximum bytes, until we know the length */
715 ttusb
->muxpack_len
= 2;
719 * return to search-sync state
721 if (!ttusb
->mux_npacks
--) {
722 ttusb
->mux_state
= 0;
735 static void ttusb_iso_irq(struct urb
*urb
)
737 struct ttusb
*ttusb
= urb
->context
;
739 if (!ttusb
->iso_streaming
)
743 printk("%s: status %d, errcount == %d, length == %i\n",
745 urb
->status
, urb
->error_count
, urb
->actual_length
);
750 for (i
= 0; i
< urb
->number_of_packets
; ++i
) {
751 struct usb_iso_packet_descriptor
*d
;
755 if (time_after_eq(jiffies
, lastj
+ HZ
)) {
758 ("frames/s: %d (ts: %d, stuff %d, sec: %d, invalid: %d, all: %d)\n",
759 numpkt
* HZ
/ (jiffies
- lastj
),
760 numts
, numstuff
, numsec
, numinvalid
,
761 numts
+ numstuff
+ numsec
+
764 numts
= numstuff
= numsec
= numinvalid
= 0;
768 d
= &urb
->iso_frame_desc
[i
];
769 data
= urb
->transfer_buffer
+ d
->offset
;
770 len
= d
->actual_length
;
771 d
->actual_length
= 0;
773 ttusb_process_frame(ttusb
, data
, len
);
776 usb_submit_urb(urb
, GFP_ATOMIC
);
779 static void ttusb_free_iso_urbs(struct ttusb
*ttusb
)
783 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
784 if (ttusb
->iso_urb
[i
])
785 usb_free_urb(ttusb
->iso_urb
[i
]);
787 pci_free_consistent(NULL
,
788 ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
*
789 ISO_BUF_COUNT
, ttusb
->iso_buffer
,
790 ttusb
->iso_dma_handle
);
793 static int ttusb_alloc_iso_urbs(struct ttusb
*ttusb
)
797 ttusb
->iso_buffer
= pci_alloc_consistent(NULL
,
801 &ttusb
->iso_dma_handle
);
803 memset(ttusb
->iso_buffer
, 0,
804 ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
* ISO_BUF_COUNT
);
806 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
811 usb_alloc_urb(FRAMES_PER_ISO_BUF
, GFP_ATOMIC
))) {
812 ttusb_free_iso_urbs(ttusb
);
816 ttusb
->iso_urb
[i
] = urb
;
822 static void ttusb_stop_iso_xfer(struct ttusb
*ttusb
)
826 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
827 usb_kill_urb(ttusb
->iso_urb
[i
]);
829 ttusb
->iso_streaming
= 0;
832 static int ttusb_start_iso_xfer(struct ttusb
*ttusb
)
834 int i
, j
, err
, buffer_offset
= 0;
836 if (ttusb
->iso_streaming
) {
837 printk("%s: iso xfer already running!\n", __func__
);
843 ttusb
->mux_state
= 0;
845 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
846 int frame_offset
= 0;
847 struct urb
*urb
= ttusb
->iso_urb
[i
];
849 urb
->dev
= ttusb
->dev
;
850 urb
->context
= ttusb
;
851 urb
->complete
= ttusb_iso_irq
;
852 urb
->pipe
= ttusb
->isoc_in_pipe
;
853 urb
->transfer_flags
= URB_ISO_ASAP
;
855 urb
->number_of_packets
= FRAMES_PER_ISO_BUF
;
856 urb
->transfer_buffer_length
=
857 ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
;
858 urb
->transfer_buffer
= ttusb
->iso_buffer
+ buffer_offset
;
859 buffer_offset
+= ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
;
861 for (j
= 0; j
< FRAMES_PER_ISO_BUF
; j
++) {
862 urb
->iso_frame_desc
[j
].offset
= frame_offset
;
863 urb
->iso_frame_desc
[j
].length
= ISO_FRAME_SIZE
;
864 frame_offset
+= ISO_FRAME_SIZE
;
868 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
869 if ((err
= usb_submit_urb(ttusb
->iso_urb
[i
], GFP_ATOMIC
))) {
870 ttusb_stop_iso_xfer(ttusb
);
872 ("%s: failed urb submission (%i: err = %i)!\n",
878 ttusb
->iso_streaming
= 1;
883 #ifdef TTUSB_HWSECTIONS
884 static void ttusb_handle_ts_data(struct dvb_demux_feed
*dvbdmxfeed
, const u8
* data
,
887 dvbdmxfeed
->cb
.ts(data
, len
, 0, 0, &dvbdmxfeed
->feed
.ts
, 0);
890 static void ttusb_handle_sec_data(struct dvb_demux_feed
*dvbdmxfeed
, const u8
* data
,
893 // struct dvb_demux_feed *dvbdmxfeed = channel->dvbdmxfeed;
894 #error TODO: handle ugly stuff
895 // dvbdmxfeed->cb.sec(data, len, 0, 0, &dvbdmxfeed->feed.sec, 0);
899 static int ttusb_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
901 struct ttusb
*ttusb
= (struct ttusb
*) dvbdmxfeed
->demux
;
904 dprintk("ttusb_start_feed\n");
906 switch (dvbdmxfeed
->type
) {
915 if (dvbdmxfeed
->type
== DMX_TYPE_TS
) {
916 switch (dvbdmxfeed
->pes_type
) {
917 case DMX_TS_PES_VIDEO
:
918 case DMX_TS_PES_AUDIO
:
919 case DMX_TS_PES_TELETEXT
:
921 case DMX_TS_PES_OTHER
:
928 #ifdef TTUSB_HWSECTIONS
929 #error TODO: allocate filters
930 if (dvbdmxfeed
->type
== DMX_TYPE_TS
) {
932 } else if (dvbdmxfeed
->type
== DMX_TYPE_SEC
) {
937 ttusb_set_channel(ttusb
, dvbdmxfeed
->index
, feed_type
, dvbdmxfeed
->pid
);
939 if (0 == ttusb
->running_feed_count
++)
940 ttusb_start_iso_xfer(ttusb
);
945 static int ttusb_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
947 struct ttusb
*ttusb
= (struct ttusb
*) dvbdmxfeed
->demux
;
949 ttusb_del_channel(ttusb
, dvbdmxfeed
->index
);
951 if (--ttusb
->running_feed_count
== 0)
952 ttusb_stop_iso_xfer(ttusb
);
957 static int ttusb_setup_interfaces(struct ttusb
*ttusb
)
959 usb_set_interface(ttusb
->dev
, 1, 1);
961 ttusb
->bulk_out_pipe
= usb_sndbulkpipe(ttusb
->dev
, 1);
962 ttusb
->bulk_in_pipe
= usb_rcvbulkpipe(ttusb
->dev
, 1);
963 ttusb
->isoc_in_pipe
= usb_rcvisocpipe(ttusb
->dev
, 2);
969 static u8 stc_firmware
[8192];
971 static int stc_open(struct inode
*inode
, struct file
*file
)
973 struct ttusb
*ttusb
= file
->private_data
;
976 for (addr
= 0; addr
< 8192; addr
+= 16) {
977 u8 snd_buf
[2] = { addr
>> 8, addr
& 0xFF };
978 ttusb_i2c_msg(ttusb
, 0x50, snd_buf
, 2, stc_firmware
+ addr
,
985 static ssize_t
stc_read(struct file
*file
, char *buf
, size_t count
,
990 if ((tc
+ *offset
) > 8192)
996 if (copy_to_user(buf
, stc_firmware
+ *offset
, tc
))
1004 static int stc_release(struct inode
*inode
, struct file
*file
)
1009 static const struct file_operations stc_fops
= {
1010 .owner
= THIS_MODULE
,
1013 .release
= stc_release
,
1017 static u32
functionality(struct i2c_adapter
*adapter
)
1019 return I2C_FUNC_I2C
;
1024 static int alps_tdmb7_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
* params
)
1026 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1028 struct i2c_msg msg
= {.addr
=0x61, .flags
=0, .buf
=data
, .len
=sizeof(data
) };
1031 div
= (params
->frequency
+ 36166667) / 166667;
1033 data
[0] = (div
>> 8) & 0x7f;
1034 data
[1] = div
& 0xff;
1035 data
[2] = ((div
>> 10) & 0x60) | 0x85;
1036 data
[3] = params
->frequency
< 592000000 ? 0x40 : 0x80;
1038 if (fe
->ops
.i2c_gate_ctrl
)
1039 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1040 if (i2c_transfer(&ttusb
->i2c_adap
, &msg
, 1) != 1) return -EIO
;
1044 static struct cx22700_config alps_tdmb7_config
= {
1045 .demod_address
= 0x43,
1052 static int philips_tdm1316l_tuner_init(struct dvb_frontend
* fe
)
1054 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1055 static u8 td1316_init
[] = { 0x0b, 0xf5, 0x85, 0xab };
1056 static u8 disable_mc44BC374c
[] = { 0x1d, 0x74, 0xa0, 0x68 };
1057 struct i2c_msg tuner_msg
= { .addr
=0x60, .flags
=0, .buf
=td1316_init
, .len
=sizeof(td1316_init
) };
1059 // setup PLL configuration
1060 if (fe
->ops
.i2c_gate_ctrl
)
1061 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1062 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) return -EIO
;
1065 // disable the mc44BC374c (do not check for errors)
1066 tuner_msg
.addr
= 0x65;
1067 tuner_msg
.buf
= disable_mc44BC374c
;
1068 tuner_msg
.len
= sizeof(disable_mc44BC374c
);
1069 if (fe
->ops
.i2c_gate_ctrl
)
1070 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1071 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) {
1072 i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1);
1078 static int philips_tdm1316l_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
* params
)
1080 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1082 struct i2c_msg tuner_msg
= {.addr
=0x60, .flags
=0, .buf
=tuner_buf
, .len
=sizeof(tuner_buf
) };
1083 int tuner_frequency
= 0;
1084 u8 band
, cp
, filter
;
1086 // determine charge pump
1087 tuner_frequency
= params
->frequency
+ 36130000;
1088 if (tuner_frequency
< 87000000) return -EINVAL
;
1089 else if (tuner_frequency
< 130000000) cp
= 3;
1090 else if (tuner_frequency
< 160000000) cp
= 5;
1091 else if (tuner_frequency
< 200000000) cp
= 6;
1092 else if (tuner_frequency
< 290000000) cp
= 3;
1093 else if (tuner_frequency
< 420000000) cp
= 5;
1094 else if (tuner_frequency
< 480000000) cp
= 6;
1095 else if (tuner_frequency
< 620000000) cp
= 3;
1096 else if (tuner_frequency
< 830000000) cp
= 5;
1097 else if (tuner_frequency
< 895000000) cp
= 7;
1098 else return -EINVAL
;
1101 if (params
->frequency
< 49000000) return -EINVAL
;
1102 else if (params
->frequency
< 159000000) band
= 1;
1103 else if (params
->frequency
< 444000000) band
= 2;
1104 else if (params
->frequency
< 861000000) band
= 4;
1105 else return -EINVAL
;
1108 switch (params
->u
.ofdm
.bandwidth
) {
1109 case BANDWIDTH_6_MHZ
:
1110 tda1004x_writereg(fe
, 0x0C, 0);
1114 case BANDWIDTH_7_MHZ
:
1115 tda1004x_writereg(fe
, 0x0C, 0);
1119 case BANDWIDTH_8_MHZ
:
1120 tda1004x_writereg(fe
, 0x0C, 0xFF);
1128 // calculate divisor
1129 // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
1130 tuner_frequency
= (((params
->frequency
/ 1000) * 6) + 217280) / 1000;
1132 // setup tuner buffer
1133 tuner_buf
[0] = tuner_frequency
>> 8;
1134 tuner_buf
[1] = tuner_frequency
& 0xff;
1135 tuner_buf
[2] = 0xca;
1136 tuner_buf
[3] = (cp
<< 5) | (filter
<< 3) | band
;
1138 if (fe
->ops
.i2c_gate_ctrl
)
1139 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1140 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1)
1147 static int philips_tdm1316l_request_firmware(struct dvb_frontend
* fe
, const struct firmware
**fw
, char* name
)
1149 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1151 return request_firmware(fw
, name
, &ttusb
->dev
->dev
);
1154 static struct tda1004x_config philips_tdm1316l_config
= {
1156 .demod_address
= 0x8,
1159 .request_firmware
= philips_tdm1316l_request_firmware
,
1162 static u8 alps_bsbe1_inittab
[] = {
1166 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1167 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1168 0x06, 0x40, /* DAC not used, set to high impendance mode */
1169 0x07, 0x00, /* DAC LSB */
1170 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1171 0x09, 0x00, /* FIFO */
1172 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1173 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1174 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1175 0x10, 0x3f, // AGC2 0x3d
1178 0x15, 0xc9, // lock detector threshold
1189 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1190 0x29, 0x1e, // 1/2 threshold
1191 0x2a, 0x14, // 2/3 threshold
1192 0x2b, 0x0f, // 3/4 threshold
1193 0x2c, 0x09, // 5/6 threshold
1194 0x2d, 0x05, // 7/8 threshold
1196 0x31, 0x1f, // test all FECs
1197 0x32, 0x19, // viterbi and synchro search
1198 0x33, 0xfc, // rs control
1199 0x34, 0x93, // error control
1204 static u8 alps_bsru6_inittab
[] = {
1208 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1209 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1210 0x06, 0x40, /* DAC not used, set to high impendance mode */
1211 0x07, 0x00, /* DAC LSB */
1212 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1213 0x09, 0x00, /* FIFO */
1214 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1215 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1216 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1217 0x10, 0x3f, // AGC2 0x3d
1220 0x15, 0xc9, // lock detector threshold
1231 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1232 0x29, 0x1e, // 1/2 threshold
1233 0x2a, 0x14, // 2/3 threshold
1234 0x2b, 0x0f, // 3/4 threshold
1235 0x2c, 0x09, // 5/6 threshold
1236 0x2d, 0x05, // 7/8 threshold
1238 0x31, 0x1f, // test all FECs
1239 0x32, 0x19, // viterbi and synchro search
1240 0x33, 0xfc, // rs control
1241 0x34, 0x93, // error control
1246 static int alps_stv0299_set_symbol_rate(struct dvb_frontend
*fe
, u32 srate
, u32 ratio
)
1251 if (srate
< 1500000) {
1254 } else if (srate
< 3000000) {
1257 } else if (srate
< 7000000) {
1260 } else if (srate
< 14000000) {
1263 } else if (srate
< 30000000) {
1266 } else if (srate
< 45000000) {
1271 stv0299_writereg(fe
, 0x13, aclk
);
1272 stv0299_writereg(fe
, 0x14, bclk
);
1273 stv0299_writereg(fe
, 0x1f, (ratio
>> 16) & 0xff);
1274 stv0299_writereg(fe
, 0x20, (ratio
>> 8) & 0xff);
1275 stv0299_writereg(fe
, 0x21, (ratio
) & 0xf0);
1280 static int philips_tsa5059_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
1282 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1285 struct i2c_msg msg
= {.addr
= 0x61,.flags
= 0,.buf
= buf
,.len
= sizeof(buf
) };
1287 if ((params
->frequency
< 950000) || (params
->frequency
> 2150000))
1290 div
= (params
->frequency
+ (125 - 1)) / 125; // round correctly
1291 buf
[0] = (div
>> 8) & 0x7f;
1292 buf
[1] = div
& 0xff;
1293 buf
[2] = 0x80 | ((div
& 0x18000) >> 10) | 4;
1296 if (params
->frequency
> 1530000)
1299 /* BSBE1 wants XCE bit set */
1300 if (ttusb
->revision
== TTUSB_REV_2_2
)
1303 if (fe
->ops
.i2c_gate_ctrl
)
1304 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1305 if (i2c_transfer(&ttusb
->i2c_adap
, &msg
, 1) != 1)
1311 static struct stv0299_config alps_stv0299_config
= {
1312 .demod_address
= 0x68,
1313 .inittab
= alps_bsru6_inittab
,
1317 .lock_output
= STV0299_LOCKOUTPUT_1
,
1318 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
1319 .min_delay_ms
= 100,
1320 .set_symbol_rate
= alps_stv0299_set_symbol_rate
,
1323 static int ttusb_novas_grundig_29504_491_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
1325 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1328 struct i2c_msg msg
= {.addr
= 0x61,.flags
= 0,.buf
= buf
,.len
= sizeof(buf
) };
1330 div
= params
->frequency
/ 125;
1332 buf
[0] = (div
>> 8) & 0x7f;
1333 buf
[1] = div
& 0xff;
1337 if (fe
->ops
.i2c_gate_ctrl
)
1338 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1339 if (i2c_transfer(&ttusb
->i2c_adap
, &msg
, 1) != 1)
1345 static struct tda8083_config ttusb_novas_grundig_29504_491_config
= {
1347 .demod_address
= 0x68,
1350 static int alps_tdbe2_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
* params
)
1352 struct ttusb
* ttusb
= fe
->dvb
->priv
;
1355 struct i2c_msg msg
= { .addr
= 0x62, .flags
= 0, .buf
= data
, .len
= sizeof(data
) };
1357 div
= (params
->frequency
+ 35937500 + 31250) / 62500;
1359 data
[0] = (div
>> 8) & 0x7f;
1360 data
[1] = div
& 0xff;
1361 data
[2] = 0x85 | ((div
>> 10) & 0x60);
1362 data
[3] = (params
->frequency
< 174000000 ? 0x88 : params
->frequency
< 470000000 ? 0x84 : 0x81);
1364 if (fe
->ops
.i2c_gate_ctrl
)
1365 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1366 if (i2c_transfer (&ttusb
->i2c_adap
, &msg
, 1) != 1)
1373 static struct ves1820_config alps_tdbe2_config
= {
1374 .demod_address
= 0x09,
1377 .selagc
= VES1820_SELAGC_SIGNAMPERR
,
1380 static u8
read_pwm(struct ttusb
* ttusb
)
1384 struct i2c_msg msg
[] = { { .addr
= 0x50,.flags
= 0,.buf
= &b
,.len
= 1 },
1385 { .addr
= 0x50,.flags
= I2C_M_RD
,.buf
= &pwm
,.len
= 1} };
1387 if ((i2c_transfer(&ttusb
->i2c_adap
, msg
, 2) != 2) || (pwm
== 0xff))
1394 static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
1396 struct ttusb
*ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1398 struct i2c_msg tuner_msg
= {.addr
= 0x60,
1401 .len
= sizeof(tuner_buf
) };
1402 int tuner_frequency
= 0;
1403 u8 band
, cp
, filter
;
1405 // determine charge pump
1406 tuner_frequency
= params
->frequency
;
1407 if (tuner_frequency
< 87000000) {return -EINVAL
;}
1408 else if (tuner_frequency
< 130000000) {cp
= 3; band
= 1;}
1409 else if (tuner_frequency
< 160000000) {cp
= 5; band
= 1;}
1410 else if (tuner_frequency
< 200000000) {cp
= 6; band
= 1;}
1411 else if (tuner_frequency
< 290000000) {cp
= 3; band
= 2;}
1412 else if (tuner_frequency
< 420000000) {cp
= 5; band
= 2;}
1413 else if (tuner_frequency
< 480000000) {cp
= 6; band
= 2;}
1414 else if (tuner_frequency
< 620000000) {cp
= 3; band
= 4;}
1415 else if (tuner_frequency
< 830000000) {cp
= 5; band
= 4;}
1416 else if (tuner_frequency
< 895000000) {cp
= 7; band
= 4;}
1417 else {return -EINVAL
;}
1419 // assume PLL filter should always be 8MHz for the moment.
1422 // calculate divisor
1423 // (Finput + Fif)/Fref; Fif = 36125000 Hz, Fref = 62500 Hz
1424 tuner_frequency
= ((params
->frequency
+ 36125000) / 62500);
1426 // setup tuner buffer
1427 tuner_buf
[0] = tuner_frequency
>> 8;
1428 tuner_buf
[1] = tuner_frequency
& 0xff;
1429 tuner_buf
[2] = 0xc8;
1430 tuner_buf
[3] = (cp
<< 5) | (filter
<< 3) | band
;
1431 tuner_buf
[4] = 0x80;
1433 if (fe
->ops
.i2c_gate_ctrl
)
1434 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1435 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) {
1436 printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 1\n");
1442 if (fe
->ops
.i2c_gate_ctrl
)
1443 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1444 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) {
1445 printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 2\n");
1454 static u8 dvbc_philips_tdm1316l_inittab
[] = {
1556 static struct stv0297_config dvbc_philips_tdm1316l_config
= {
1557 .demod_address
= 0x1c,
1558 .inittab
= dvbc_philips_tdm1316l_inittab
,
1562 static void frontend_init(struct ttusb
* ttusb
)
1564 switch(le16_to_cpu(ttusb
->dev
->descriptor
.idProduct
)) {
1565 case 0x1003: // Hauppauge/TT Nova-USB-S budget (stv0299/ALPS BSRU6|BSBE1(tsa5059))
1566 // try the stv0299 based first
1567 ttusb
->fe
= dvb_attach(stv0299_attach
, &alps_stv0299_config
, &ttusb
->i2c_adap
);
1568 if (ttusb
->fe
!= NULL
) {
1569 ttusb
->fe
->ops
.tuner_ops
.set_params
= philips_tsa5059_tuner_set_params
;
1571 if(ttusb
->revision
== TTUSB_REV_2_2
) { // ALPS BSBE1
1572 alps_stv0299_config
.inittab
= alps_bsbe1_inittab
;
1573 dvb_attach(lnbp21_attach
, ttusb
->fe
, &ttusb
->i2c_adap
, 0, 0);
1574 } else { // ALPS BSRU6
1575 ttusb
->fe
->ops
.set_voltage
= ttusb_set_voltage
;
1580 // Grundig 29504-491
1581 ttusb
->fe
= dvb_attach(tda8083_attach
, &ttusb_novas_grundig_29504_491_config
, &ttusb
->i2c_adap
);
1582 if (ttusb
->fe
!= NULL
) {
1583 ttusb
->fe
->ops
.tuner_ops
.set_params
= ttusb_novas_grundig_29504_491_tuner_set_params
;
1584 ttusb
->fe
->ops
.set_voltage
= ttusb_set_voltage
;
1589 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
1590 ttusb
->fe
= dvb_attach(ves1820_attach
, &alps_tdbe2_config
, &ttusb
->i2c_adap
, read_pwm(ttusb
));
1591 if (ttusb
->fe
!= NULL
) {
1592 ttusb
->fe
->ops
.tuner_ops
.set_params
= alps_tdbe2_tuner_set_params
;
1596 ttusb
->fe
= dvb_attach(stv0297_attach
, &dvbc_philips_tdm1316l_config
, &ttusb
->i2c_adap
);
1597 if (ttusb
->fe
!= NULL
) {
1598 ttusb
->fe
->ops
.tuner_ops
.set_params
= dvbc_philips_tdm1316l_tuner_set_params
;
1603 case 0x1005: // Hauppauge/TT Nova-USB-t budget (tda10046/Philips td1316(tda6651tt) OR cx22700/ALPS TDMB7(??))
1604 // try the ALPS TDMB7 first
1605 ttusb
->fe
= dvb_attach(cx22700_attach
, &alps_tdmb7_config
, &ttusb
->i2c_adap
);
1606 if (ttusb
->fe
!= NULL
) {
1607 ttusb
->fe
->ops
.tuner_ops
.set_params
= alps_tdmb7_tuner_set_params
;
1612 ttusb
->fe
= dvb_attach(tda10046_attach
, &philips_tdm1316l_config
, &ttusb
->i2c_adap
);
1613 if (ttusb
->fe
!= NULL
) {
1614 ttusb
->fe
->ops
.tuner_ops
.init
= philips_tdm1316l_tuner_init
;
1615 ttusb
->fe
->ops
.tuner_ops
.set_params
= philips_tdm1316l_tuner_set_params
;
1621 if (ttusb
->fe
== NULL
) {
1622 printk("dvb-ttusb-budget: A frontend driver was not found for device %04x/%04x\n",
1623 le16_to_cpu(ttusb
->dev
->descriptor
.idVendor
),
1624 le16_to_cpu(ttusb
->dev
->descriptor
.idProduct
));
1626 if (dvb_register_frontend(&ttusb
->adapter
, ttusb
->fe
)) {
1627 printk("dvb-ttusb-budget: Frontend registration failed!\n");
1628 dvb_frontend_detach(ttusb
->fe
);
1636 static struct i2c_algorithm ttusb_dec_algo
= {
1637 .master_xfer
= master_xfer
,
1638 .functionality
= functionality
,
1641 static int ttusb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1643 struct usb_device
*udev
;
1644 struct ttusb
*ttusb
;
1647 dprintk("%s: TTUSB DVB connected\n", __func__
);
1649 udev
= interface_to_usbdev(intf
);
1651 if (intf
->altsetting
->desc
.bInterfaceNumber
!= 1) return -ENODEV
;
1653 if (!(ttusb
= kzalloc(sizeof(struct ttusb
), GFP_KERNEL
)))
1658 ttusb
->mux_state
= 0;
1659 mutex_init(&ttusb
->semi2c
);
1661 mutex_lock(&ttusb
->semi2c
);
1663 mutex_init(&ttusb
->semusb
);
1665 ttusb_setup_interfaces(ttusb
);
1667 ttusb_alloc_iso_urbs(ttusb
);
1668 if (ttusb_init_controller(ttusb
))
1669 printk("ttusb_init_controller: error\n");
1671 mutex_unlock(&ttusb
->semi2c
);
1673 result
= dvb_register_adapter(&ttusb
->adapter
,
1674 "Technotrend/Hauppauge Nova-USB",
1675 THIS_MODULE
, &udev
->dev
, adapter_nr
);
1677 ttusb_free_iso_urbs(ttusb
);
1681 ttusb
->adapter
.priv
= ttusb
;
1684 memset(&ttusb
->i2c_adap
, 0, sizeof(struct i2c_adapter
));
1685 strcpy(ttusb
->i2c_adap
.name
, "TTUSB DEC");
1687 i2c_set_adapdata(&ttusb
->i2c_adap
, ttusb
);
1689 #ifdef I2C_ADAP_CLASS_TV_DIGITAL
1690 ttusb
->i2c_adap
.class = I2C_ADAP_CLASS_TV_DIGITAL
;
1692 ttusb
->i2c_adap
.class = I2C_CLASS_TV_DIGITAL
;
1694 ttusb
->i2c_adap
.algo
= &ttusb_dec_algo
;
1695 ttusb
->i2c_adap
.algo_data
= NULL
;
1696 ttusb
->i2c_adap
.dev
.parent
= &udev
->dev
;
1698 result
= i2c_add_adapter(&ttusb
->i2c_adap
);
1700 dvb_unregister_adapter (&ttusb
->adapter
);
1704 memset(&ttusb
->dvb_demux
, 0, sizeof(ttusb
->dvb_demux
));
1706 ttusb
->dvb_demux
.dmx
.capabilities
=
1707 DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
1708 ttusb
->dvb_demux
.priv
= NULL
;
1709 #ifdef TTUSB_HWSECTIONS
1710 ttusb
->dvb_demux
.filternum
= TTUSB_MAXFILTER
;
1712 ttusb
->dvb_demux
.filternum
= 32;
1714 ttusb
->dvb_demux
.feednum
= TTUSB_MAXCHANNEL
;
1715 ttusb
->dvb_demux
.start_feed
= ttusb_start_feed
;
1716 ttusb
->dvb_demux
.stop_feed
= ttusb_stop_feed
;
1717 ttusb
->dvb_demux
.write_to_decoder
= NULL
;
1719 if ((result
= dvb_dmx_init(&ttusb
->dvb_demux
)) < 0) {
1720 printk("ttusb_dvb: dvb_dmx_init failed (errno = %d)\n", result
);
1721 i2c_del_adapter(&ttusb
->i2c_adap
);
1722 dvb_unregister_adapter (&ttusb
->adapter
);
1725 //FIXME dmxdev (nur WAS?)
1726 ttusb
->dmxdev
.filternum
= ttusb
->dvb_demux
.filternum
;
1727 ttusb
->dmxdev
.demux
= &ttusb
->dvb_demux
.dmx
;
1728 ttusb
->dmxdev
.capabilities
= 0;
1730 if ((result
= dvb_dmxdev_init(&ttusb
->dmxdev
, &ttusb
->adapter
)) < 0) {
1731 printk("ttusb_dvb: dvb_dmxdev_init failed (errno = %d)\n",
1733 dvb_dmx_release(&ttusb
->dvb_demux
);
1734 i2c_del_adapter(&ttusb
->i2c_adap
);
1735 dvb_unregister_adapter (&ttusb
->adapter
);
1739 if (dvb_net_init(&ttusb
->adapter
, &ttusb
->dvbnet
, &ttusb
->dvb_demux
.dmx
)) {
1740 printk("ttusb_dvb: dvb_net_init failed!\n");
1741 dvb_dmxdev_release(&ttusb
->dmxdev
);
1742 dvb_dmx_release(&ttusb
->dvb_demux
);
1743 i2c_del_adapter(&ttusb
->i2c_adap
);
1744 dvb_unregister_adapter (&ttusb
->adapter
);
1748 usb_set_intfdata(intf
, (void *) ttusb
);
1750 frontend_init(ttusb
);
1755 static void ttusb_disconnect(struct usb_interface
*intf
)
1757 struct ttusb
*ttusb
= usb_get_intfdata(intf
);
1759 usb_set_intfdata(intf
, NULL
);
1761 ttusb
->disconnecting
= 1;
1763 ttusb_stop_iso_xfer(ttusb
);
1765 ttusb
->dvb_demux
.dmx
.close(&ttusb
->dvb_demux
.dmx
);
1766 dvb_net_release(&ttusb
->dvbnet
);
1767 dvb_dmxdev_release(&ttusb
->dmxdev
);
1768 dvb_dmx_release(&ttusb
->dvb_demux
);
1769 if (ttusb
->fe
!= NULL
) {
1770 dvb_unregister_frontend(ttusb
->fe
);
1771 dvb_frontend_detach(ttusb
->fe
);
1773 i2c_del_adapter(&ttusb
->i2c_adap
);
1774 dvb_unregister_adapter(&ttusb
->adapter
);
1776 ttusb_free_iso_urbs(ttusb
);
1780 dprintk("%s: TTUSB DVB disconnected\n", __func__
);
1783 static struct usb_device_id ttusb_table
[] = {
1784 {USB_DEVICE(0xb48, 0x1003)},
1785 {USB_DEVICE(0xb48, 0x1004)},
1786 {USB_DEVICE(0xb48, 0x1005)},
1790 MODULE_DEVICE_TABLE(usb
, ttusb_table
);
1792 static struct usb_driver ttusb_driver
= {
1794 .probe
= ttusb_probe
,
1795 .disconnect
= ttusb_disconnect
,
1796 .id_table
= ttusb_table
,
1799 static int __init
ttusb_init(void)
1803 if ((err
= usb_register(&ttusb_driver
)) < 0) {
1804 printk("%s: usb_register failed! Error number %d",
1812 static void __exit
ttusb_exit(void)
1814 usb_deregister(&ttusb_driver
);
1817 module_init(ttusb_init
);
1818 module_exit(ttusb_exit
);
1820 MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>");
1821 MODULE_DESCRIPTION("TTUSB DVB Driver");
1822 MODULE_LICENSE("GPL");