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.
60 module_param(debug
, int, 0644);
61 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
63 #define dprintk(x...) do { if (debug) printk(KERN_DEBUG x); } while (0)
65 #define ISO_BUF_COUNT 4
66 #define FRAMES_PER_ISO_BUF 4
67 #define ISO_FRAME_SIZE 912
68 #define TTUSB_MAXCHANNEL 32
69 #ifdef TTUSB_HWSECTIONS
70 #define TTUSB_MAXFILTER 16 /* ??? */
73 #define TTUSB_REV_2_2 0x22
74 #define TTUSB_BUDGET_NAME "ttusb_stc_fw"
77 * since we're casting (struct ttusb*) <-> (struct dvb_demux*) around
78 * the dvb_demux field must be the first in struct!!
81 struct dvb_demux dvb_demux
;
83 struct dvb_net dvbnet
;
85 /* and one for USB access. */
89 struct dvb_adapter adapter
;
90 struct usb_device
*dev
;
92 struct i2c_adapter i2c_adap
;
97 unsigned int bulk_out_pipe
;
98 unsigned int bulk_in_pipe
;
99 unsigned int isoc_in_pipe
;
102 dma_addr_t iso_dma_handle
;
104 struct urb
*iso_urb
[ISO_BUF_COUNT
];
106 int running_feed_count
;
110 u8 c
; /* transaction counter, wraps around... */
111 fe_sec_tone_mode_t tone
;
112 fe_sec_voltage_t voltage
;
114 int mux_state
; // 0..2 - MuxSyncWord, 3 - nMuxPacks, 4 - muxpack
117 int muxpack_ptr
, muxpack_len
;
121 int cc
; /* MuxCounter - will increment on EVERY MUX PACKET */
122 /* (including stuffing. yes. really.) */
128 struct dvb_frontend
* fe
;
131 /* ugly workaround ... don't know why it's necessary to read */
132 /* all result codes. */
135 static int ttusb_cmd(struct ttusb
*ttusb
,
136 const u8
* data
, int len
, int needresult
)
144 for (i
= 0; i
< len
; ++i
)
145 printk(" %02x", data
[i
]);
149 if (mutex_lock_interruptible(&ttusb
->semusb
) < 0)
152 err
= usb_bulk_msg(ttusb
->dev
, ttusb
->bulk_out_pipe
,
153 (u8
*) data
, len
, &actual_len
, 1000);
155 dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n",
157 mutex_unlock(&ttusb
->semusb
);
160 if (actual_len
!= len
) {
161 dprintk("%s: only wrote %d of %d bytes\n", __FUNCTION__
,
163 mutex_unlock(&ttusb
->semusb
);
167 err
= usb_bulk_msg(ttusb
->dev
, ttusb
->bulk_in_pipe
,
168 ttusb
->last_result
, 32, &actual_len
, 1000);
171 printk("%s: failed, receive error %d\n", __FUNCTION__
,
173 mutex_unlock(&ttusb
->semusb
);
177 actual_len
= ttusb
->last_result
[3] + 4;
179 for (i
= 0; i
< actual_len
; ++i
)
180 printk(" %02x", ttusb
->last_result
[i
]);
184 mutex_unlock(&ttusb
->semusb
);
188 static int ttusb_result(struct ttusb
*ttusb
, u8
* data
, int len
)
190 memcpy(data
, ttusb
->last_result
, len
);
191 mutex_unlock(&ttusb
->semusb
);
195 static int ttusb_i2c_msg(struct ttusb
*ttusb
,
196 u8 addr
, u8
* snd_buf
, u8 snd_len
, u8
* rcv_buf
,
203 if (snd_len
> 0x28 - 7 || rcv_len
> 0x20 - 7)
214 for (i
= 0; i
< snd_len
; i
++)
215 b
[7 + i
] = snd_buf
[i
];
217 err
= ttusb_cmd(ttusb
, b
, snd_len
+ 7, 1);
222 err
= ttusb_result(ttusb
, b
, 0x20);
224 /* check if the i2c transaction was successful */
225 if ((snd_len
!= b
[5]) || (rcv_len
!= b
[6])) return -EREMOTEIO
;
229 if (err
|| b
[0] != 0x55 || b
[1] != id
) {
231 ("%s: usb_bulk_msg(recv) failed, err == %i, id == %02x, b == ",
232 __FUNCTION__
, err
, id
);
236 for (i
= 0; i
< rcv_len
; i
++)
237 rcv_buf
[i
] = b
[7 + i
];
243 static int master_xfer(struct i2c_adapter
* adapter
, struct i2c_msg
*msg
, int num
)
245 struct ttusb
*ttusb
= i2c_get_adapdata(adapter
);
249 if (mutex_lock_interruptible(&ttusb
->semi2c
) < 0)
253 u8 addr
, snd_len
, rcv_len
, *snd_buf
, *rcv_buf
;
256 if (num
> i
+ 1 && (msg
[i
+ 1].flags
& I2C_M_RD
)) {
258 snd_buf
= msg
[i
].buf
;
259 snd_len
= msg
[i
].len
;
260 rcv_buf
= msg
[i
+ 1].buf
;
261 rcv_len
= msg
[i
+ 1].len
;
265 snd_buf
= msg
[i
].buf
;
266 snd_len
= msg
[i
].len
;
272 err
= ttusb_i2c_msg(ttusb
, addr
,
273 snd_buf
, snd_len
, rcv_buf
, rcv_len
);
276 dprintk("%s: i == %i\n", __FUNCTION__
, i
);
283 mutex_unlock(&ttusb
->semi2c
);
287 #include "dvb-ttusb-dspbootcode.h"
289 static int ttusb_boot_dsp(struct ttusb
*ttusb
)
299 /* upload dsp code in 32 byte steps (36 didn't work for me ...) */
300 /* 32 is max packet size, no messages should be splitted. */
301 for (i
= 0; i
< sizeof(dsp_bootcode
); i
+= 28) {
302 memcpy(&b
[4], &dsp_bootcode
[i
], 28);
306 err
= ttusb_cmd(ttusb
, b
, 32, 0);
316 err
= ttusb_cmd(ttusb
, b
, 4, 0);
325 err
= ttusb_cmd(ttusb
, b
, 4, 0);
329 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
336 static int ttusb_set_channel(struct ttusb
*ttusb
, int chan_id
, int filter_type
,
341 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x22, 4, chan_id
, filter_type
,
342 (pid
>> 8) & 0xff, pid
& 0xff
345 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
349 static int ttusb_del_channel(struct ttusb
*ttusb
, int channel_id
)
353 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x23, 1, channel_id
};
355 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
359 #ifdef TTUSB_HWSECTIONS
360 static int ttusb_set_filter(struct ttusb
*ttusb
, int filter_id
,
361 int associated_chan
, u8 filter
[8], u8 mask
[8])
365 u8 b
[] = { 0xaa, 0, 0x24, 0x1a, filter_id
, associated_chan
,
366 filter
[0], filter
[1], filter
[2], filter
[3],
367 filter
[4], filter
[5], filter
[6], filter
[7],
368 filter
[8], filter
[9], filter
[10], filter
[11],
369 mask
[0], mask
[1], mask
[2], mask
[3],
370 mask
[4], mask
[5], mask
[6], mask
[7],
371 mask
[8], mask
[9], mask
[10], mask
[11]
374 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
378 static int ttusb_del_filter(struct ttusb
*ttusb
, int filter_id
)
382 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x25, 1, filter_id
};
384 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
389 static int ttusb_init_controller(struct ttusb
*ttusb
)
391 u8 b0
[] = { 0xaa, ++ttusb
->c
, 0x15, 1, 0 };
392 u8 b1
[] = { 0xaa, ++ttusb
->c
, 0x15, 1, 1 };
393 u8 b2
[] = { 0xaa, ++ttusb
->c
, 0x32, 1, 0 };
394 /* i2c write read: 5 bytes, addr 0x10, 0x02 bytes write, 1 bytes read. */
396 { 0xaa, ++ttusb
->c
, 0x31, 5, 0x10, 0x02, 0x01, 0x00, 0x1e };
398 { 0x55, ttusb
->c
, 0x31, 4, 0x10, 0x02, 0x01, 0x00, 0x1e };
400 u8 get_version
[] = { 0xaa, ++ttusb
->c
, 0x17, 5, 0, 0, 0, 0, 0 };
401 u8 get_dsp_version
[0x20] =
402 { 0xaa, ++ttusb
->c
, 0x26, 28, 0, 0, 0, 0, 0 };
406 if ((err
= ttusb_cmd(ttusb
, b0
, sizeof(b0
), 0)))
409 /* reset board (again?) */
410 if ((err
= ttusb_cmd(ttusb
, b1
, sizeof(b1
), 0)))
413 ttusb_boot_dsp(ttusb
);
415 /* set i2c bit rate */
416 if ((err
= ttusb_cmd(ttusb
, b2
, sizeof(b2
), 0)))
419 if ((err
= ttusb_cmd(ttusb
, b3
, sizeof(b3
), 1)))
422 err
= ttusb_result(ttusb
, b4
, sizeof(b4
));
424 if ((err
= ttusb_cmd(ttusb
, get_version
, sizeof(get_version
), 1)))
427 if ((err
= ttusb_result(ttusb
, get_version
, sizeof(get_version
))))
430 dprintk("%s: stc-version: %c%c%c%c%c\n", __FUNCTION__
,
431 get_version
[4], get_version
[5], get_version
[6],
432 get_version
[7], get_version
[8]);
434 if (memcmp(get_version
+ 4, "V 0.0", 5) &&
435 memcmp(get_version
+ 4, "V 1.1", 5) &&
436 memcmp(get_version
+ 4, "V 2.1", 5) &&
437 memcmp(get_version
+ 4, "V 2.2", 5)) {
439 ("%s: unknown STC version %c%c%c%c%c, please report!\n",
440 __FUNCTION__
, get_version
[4], get_version
[5],
441 get_version
[6], get_version
[7], get_version
[8]);
444 ttusb
->revision
= ((get_version
[6] - '0') << 4) |
445 (get_version
[8] - '0');
448 ttusb_cmd(ttusb
, get_dsp_version
, sizeof(get_dsp_version
), 1);
453 ttusb_result(ttusb
, get_dsp_version
, sizeof(get_dsp_version
));
456 printk("%s: dsp-version: %c%c%c\n", __FUNCTION__
,
457 get_dsp_version
[4], get_dsp_version
[5], get_dsp_version
[6]);
462 static int ttusb_send_diseqc(struct dvb_frontend
* fe
,
463 const struct dvb_diseqc_master_cmd
*cmd
)
465 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
466 u8 b
[12] = { 0xaa, ++ttusb
->c
, 0x18 };
470 b
[3] = 4 + 2 + cmd
->msg_len
;
471 b
[4] = 0xFF; /* send diseqc master, not burst */
474 memcpy(b
+ 5, cmd
->msg
, cmd
->msg_len
);
477 if ((err
= ttusb_cmd(ttusb
, b
, 4 + b
[3], 0))) {
478 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
486 static int ttusb_update_lnb(struct ttusb
*ttusb
)
488 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x16, 5, /*power: */ 1,
489 ttusb
->voltage
== SEC_VOLTAGE_18
? 0 : 1,
490 ttusb
->tone
== SEC_TONE_ON
? 1 : 0, 1, 1
495 if ((err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0))) {
496 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
503 static int ttusb_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
)
505 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
507 ttusb
->voltage
= voltage
;
508 return ttusb_update_lnb(ttusb
);
512 static int ttusb_set_tone(struct dvb_frontend
* fe
, fe_sec_tone_mode_t tone
)
514 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
517 return ttusb_update_lnb(ttusb
);
523 static void ttusb_set_led_freq(struct ttusb
*ttusb
, u8 freq
)
525 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x19, 1, freq
};
528 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
530 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
536 /*****************************************************************************/
538 #ifdef TTUSB_HWSECTIONS
539 static void ttusb_handle_ts_data(struct ttusb_channel
*channel
,
540 const u8
* data
, int len
);
541 static void ttusb_handle_sec_data(struct ttusb_channel
*channel
,
542 const u8
* data
, int len
);
545 static int numpkt
= 0, numts
, numstuff
, numsec
, numinvalid
;
546 static unsigned long lastj
;
548 static void ttusb_process_muxpack(struct ttusb
*ttusb
, const u8
* muxpack
,
553 for (i
= 0; i
< len
; i
+= 2)
554 csum
^= le16_to_cpup((u16
*) (muxpack
+ i
));
556 printk("%s: muxpack with incorrect checksum, ignoring\n",
562 cc
= (muxpack
[len
- 4] << 8) | muxpack
[len
- 3];
564 if ((cc
!= ttusb
->cc
) && (ttusb
->cc
!= -1))
565 printk("%s: cc discontinuity (%d frames missing)\n",
566 __FUNCTION__
, (cc
- ttusb
->cc
) & 0x7FFF);
567 ttusb
->cc
= (cc
+ 1) & 0x7FFF;
568 if (muxpack
[0] & 0x80) {
569 #ifdef TTUSB_HWSECTIONS
571 int pusi
= muxpack
[0] & 0x40;
572 int channel
= muxpack
[0] & 0x1F;
573 int payload
= muxpack
[1];
574 const u8
*data
= muxpack
+ 2;
575 /* check offset flag */
576 if (muxpack
[0] & 0x20)
579 ttusb_handle_sec_data(ttusb
->channel
+ channel
, data
,
583 if ((!!(ttusb
->muxpack
[0] & 0x20)) ^
584 !!(ttusb
->muxpack
[1] & 1))
587 printk("cc: %04x\n", (data
[0] << 8) | data
[1]);
590 } else if (muxpack
[0] == 0x47) {
591 #ifdef TTUSB_HWSECTIONS
592 /* we have TS data here! */
593 int pid
= ((muxpack
[1] & 0x0F) << 8) | muxpack
[2];
595 for (channel
= 0; channel
< TTUSB_MAXCHANNEL
; ++channel
)
596 if (ttusb
->channel
[channel
].active
597 && (pid
== ttusb
->channel
[channel
].pid
))
598 ttusb_handle_ts_data(ttusb
->channel
+
603 dvb_dmx_swfilter_packets(&ttusb
->dvb_demux
, muxpack
, 1);
604 } else if (muxpack
[0] != 0) {
606 printk("illegal muxpack type %02x\n", muxpack
[0]);
611 static void ttusb_process_frame(struct ttusb
*ttusb
, u8
* data
, int len
)
616 printk("%s: too much work\n", __FUNCTION__
);
620 switch (ttusb
->mux_state
) {
628 ttusb
->mux_state
= 0;
631 printk("%02x ", data
[-1]);
634 printk("%s: lost sync.\n",
644 ttusb
->mux_npacks
= *data
++;
646 ttusb
->muxpack_ptr
= 0;
647 /* maximum bytes, until we know the length */
648 ttusb
->muxpack_len
= 2;
655 (ttusb
->muxpack_len
-
660 memcpy(ttusb
->muxpack
+ ttusb
->muxpack_ptr
,
662 ttusb
->muxpack_ptr
+= avail
;
663 BUG_ON(ttusb
->muxpack_ptr
> 264);
666 /* determine length */
667 if (ttusb
->muxpack_ptr
== 2) {
668 if (ttusb
->muxpack
[0] & 0x80) {
670 ttusb
->muxpack
[1] + 2;
677 muxpack
[0] & 0x20)) ^
682 ttusb
->muxpack_len
+= 4;
683 } else if (ttusb
->muxpack
[0] ==
687 else if (ttusb
->muxpack
[0] == 0x00)
689 ttusb
->muxpack
[1] + 2 +
693 ("%s: invalid state: first byte is %x\n",
696 ttusb
->mux_state
= 0;
701 * if length is valid and we reached the end:
704 if ((ttusb
->muxpack_ptr
>= 2) &&
705 (ttusb
->muxpack_ptr
==
706 ttusb
->muxpack_len
)) {
707 ttusb_process_muxpack(ttusb
,
712 ttusb
->muxpack_ptr
= 0;
713 /* maximum bytes, until we know the length */
714 ttusb
->muxpack_len
= 2;
718 * return to search-sync state
720 if (!ttusb
->mux_npacks
--) {
721 ttusb
->mux_state
= 0;
734 static void ttusb_iso_irq(struct urb
*urb
)
736 struct ttusb
*ttusb
= urb
->context
;
738 if (!ttusb
->iso_streaming
)
742 printk("%s: status %d, errcount == %d, length == %i\n",
744 urb
->status
, urb
->error_count
, urb
->actual_length
);
749 for (i
= 0; i
< urb
->number_of_packets
; ++i
) {
750 struct usb_iso_packet_descriptor
*d
;
754 if (time_after_eq(jiffies
, lastj
+ HZ
)) {
757 ("frames/s: %d (ts: %d, stuff %d, sec: %d, invalid: %d, all: %d)\n",
758 numpkt
* HZ
/ (jiffies
- lastj
),
759 numts
, numstuff
, numsec
, numinvalid
,
760 numts
+ numstuff
+ numsec
+
763 numts
= numstuff
= numsec
= numinvalid
= 0;
767 d
= &urb
->iso_frame_desc
[i
];
768 data
= urb
->transfer_buffer
+ d
->offset
;
769 len
= d
->actual_length
;
770 d
->actual_length
= 0;
772 ttusb_process_frame(ttusb
, data
, len
);
775 usb_submit_urb(urb
, GFP_ATOMIC
);
778 static void ttusb_free_iso_urbs(struct ttusb
*ttusb
)
782 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
783 if (ttusb
->iso_urb
[i
])
784 usb_free_urb(ttusb
->iso_urb
[i
]);
786 pci_free_consistent(NULL
,
787 ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
*
788 ISO_BUF_COUNT
, ttusb
->iso_buffer
,
789 ttusb
->iso_dma_handle
);
792 static int ttusb_alloc_iso_urbs(struct ttusb
*ttusb
)
796 ttusb
->iso_buffer
= pci_alloc_consistent(NULL
,
800 &ttusb
->iso_dma_handle
);
802 memset(ttusb
->iso_buffer
, 0,
803 ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
* ISO_BUF_COUNT
);
805 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
810 usb_alloc_urb(FRAMES_PER_ISO_BUF
, GFP_ATOMIC
))) {
811 ttusb_free_iso_urbs(ttusb
);
815 ttusb
->iso_urb
[i
] = urb
;
821 static void ttusb_stop_iso_xfer(struct ttusb
*ttusb
)
825 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
826 usb_kill_urb(ttusb
->iso_urb
[i
]);
828 ttusb
->iso_streaming
= 0;
831 static int ttusb_start_iso_xfer(struct ttusb
*ttusb
)
833 int i
, j
, err
, buffer_offset
= 0;
835 if (ttusb
->iso_streaming
) {
836 printk("%s: iso xfer already running!\n", __FUNCTION__
);
842 ttusb
->mux_state
= 0;
844 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
845 int frame_offset
= 0;
846 struct urb
*urb
= ttusb
->iso_urb
[i
];
848 urb
->dev
= ttusb
->dev
;
849 urb
->context
= ttusb
;
850 urb
->complete
= ttusb_iso_irq
;
851 urb
->pipe
= ttusb
->isoc_in_pipe
;
852 urb
->transfer_flags
= URB_ISO_ASAP
;
854 urb
->number_of_packets
= FRAMES_PER_ISO_BUF
;
855 urb
->transfer_buffer_length
=
856 ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
;
857 urb
->transfer_buffer
= ttusb
->iso_buffer
+ buffer_offset
;
858 buffer_offset
+= ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
;
860 for (j
= 0; j
< FRAMES_PER_ISO_BUF
; j
++) {
861 urb
->iso_frame_desc
[j
].offset
= frame_offset
;
862 urb
->iso_frame_desc
[j
].length
= ISO_FRAME_SIZE
;
863 frame_offset
+= ISO_FRAME_SIZE
;
867 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
868 if ((err
= usb_submit_urb(ttusb
->iso_urb
[i
], GFP_ATOMIC
))) {
869 ttusb_stop_iso_xfer(ttusb
);
871 ("%s: failed urb submission (%i: err = %i)!\n",
872 __FUNCTION__
, i
, err
);
877 ttusb
->iso_streaming
= 1;
882 #ifdef TTUSB_HWSECTIONS
883 static void ttusb_handle_ts_data(struct dvb_demux_feed
*dvbdmxfeed
, const u8
* data
,
886 dvbdmxfeed
->cb
.ts(data
, len
, 0, 0, &dvbdmxfeed
->feed
.ts
, 0);
889 static void ttusb_handle_sec_data(struct dvb_demux_feed
*dvbdmxfeed
, const u8
* data
,
892 // struct dvb_demux_feed *dvbdmxfeed = channel->dvbdmxfeed;
893 #error TODO: handle ugly stuff
894 // dvbdmxfeed->cb.sec(data, len, 0, 0, &dvbdmxfeed->feed.sec, 0);
898 static int ttusb_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
900 struct ttusb
*ttusb
= (struct ttusb
*) dvbdmxfeed
->demux
;
903 dprintk("ttusb_start_feed\n");
905 switch (dvbdmxfeed
->type
) {
914 if (dvbdmxfeed
->type
== DMX_TYPE_TS
) {
915 switch (dvbdmxfeed
->pes_type
) {
916 case DMX_TS_PES_VIDEO
:
917 case DMX_TS_PES_AUDIO
:
918 case DMX_TS_PES_TELETEXT
:
920 case DMX_TS_PES_OTHER
:
927 #ifdef TTUSB_HWSECTIONS
928 #error TODO: allocate filters
929 if (dvbdmxfeed
->type
== DMX_TYPE_TS
) {
931 } else if (dvbdmxfeed
->type
== DMX_TYPE_SEC
) {
936 ttusb_set_channel(ttusb
, dvbdmxfeed
->index
, feed_type
, dvbdmxfeed
->pid
);
938 if (0 == ttusb
->running_feed_count
++)
939 ttusb_start_iso_xfer(ttusb
);
944 static int ttusb_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
946 struct ttusb
*ttusb
= (struct ttusb
*) dvbdmxfeed
->demux
;
948 ttusb_del_channel(ttusb
, dvbdmxfeed
->index
);
950 if (--ttusb
->running_feed_count
== 0)
951 ttusb_stop_iso_xfer(ttusb
);
956 static int ttusb_setup_interfaces(struct ttusb
*ttusb
)
958 usb_set_interface(ttusb
->dev
, 1, 1);
960 ttusb
->bulk_out_pipe
= usb_sndbulkpipe(ttusb
->dev
, 1);
961 ttusb
->bulk_in_pipe
= usb_rcvbulkpipe(ttusb
->dev
, 1);
962 ttusb
->isoc_in_pipe
= usb_rcvisocpipe(ttusb
->dev
, 2);
968 static u8 stc_firmware
[8192];
970 static int stc_open(struct inode
*inode
, struct file
*file
)
972 struct ttusb
*ttusb
= file
->private_data
;
975 for (addr
= 0; addr
< 8192; addr
+= 16) {
976 u8 snd_buf
[2] = { addr
>> 8, addr
& 0xFF };
977 ttusb_i2c_msg(ttusb
, 0x50, snd_buf
, 2, stc_firmware
+ addr
,
984 static ssize_t
stc_read(struct file
*file
, char *buf
, size_t count
,
989 if ((tc
+ *offset
) > 8192)
995 if (copy_to_user(buf
, stc_firmware
+ *offset
, tc
))
1003 static int stc_release(struct inode
*inode
, struct file
*file
)
1008 static struct file_operations stc_fops
= {
1009 .owner
= THIS_MODULE
,
1012 .release
= stc_release
,
1016 static u32
functionality(struct i2c_adapter
*adapter
)
1018 return I2C_FUNC_I2C
;
1023 static int alps_tdmb7_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
* params
)
1025 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1027 struct i2c_msg msg
= {.addr
=0x61, .flags
=0, .buf
=data
, .len
=sizeof(data
) };
1030 div
= (params
->frequency
+ 36166667) / 166667;
1032 data
[0] = (div
>> 8) & 0x7f;
1033 data
[1] = div
& 0xff;
1034 data
[2] = ((div
>> 10) & 0x60) | 0x85;
1035 data
[3] = params
->frequency
< 592000000 ? 0x40 : 0x80;
1037 if (fe
->ops
.i2c_gate_ctrl
)
1038 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1039 if (i2c_transfer(&ttusb
->i2c_adap
, &msg
, 1) != 1) return -EIO
;
1043 static struct cx22700_config alps_tdmb7_config
= {
1044 .demod_address
= 0x43,
1051 static int philips_tdm1316l_tuner_init(struct dvb_frontend
* fe
)
1053 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1054 static u8 td1316_init
[] = { 0x0b, 0xf5, 0x85, 0xab };
1055 static u8 disable_mc44BC374c
[] = { 0x1d, 0x74, 0xa0, 0x68 };
1056 struct i2c_msg tuner_msg
= { .addr
=0x60, .flags
=0, .buf
=td1316_init
, .len
=sizeof(td1316_init
) };
1058 // setup PLL configuration
1059 if (fe
->ops
.i2c_gate_ctrl
)
1060 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1061 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) return -EIO
;
1064 // disable the mc44BC374c (do not check for errors)
1065 tuner_msg
.addr
= 0x65;
1066 tuner_msg
.buf
= disable_mc44BC374c
;
1067 tuner_msg
.len
= sizeof(disable_mc44BC374c
);
1068 if (fe
->ops
.i2c_gate_ctrl
)
1069 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1070 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) {
1071 i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1);
1077 static int philips_tdm1316l_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
* params
)
1079 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1081 struct i2c_msg tuner_msg
= {.addr
=0x60, .flags
=0, .buf
=tuner_buf
, .len
=sizeof(tuner_buf
) };
1082 int tuner_frequency
= 0;
1083 u8 band
, cp
, filter
;
1085 // determine charge pump
1086 tuner_frequency
= params
->frequency
+ 36130000;
1087 if (tuner_frequency
< 87000000) return -EINVAL
;
1088 else if (tuner_frequency
< 130000000) cp
= 3;
1089 else if (tuner_frequency
< 160000000) cp
= 5;
1090 else if (tuner_frequency
< 200000000) cp
= 6;
1091 else if (tuner_frequency
< 290000000) cp
= 3;
1092 else if (tuner_frequency
< 420000000) cp
= 5;
1093 else if (tuner_frequency
< 480000000) cp
= 6;
1094 else if (tuner_frequency
< 620000000) cp
= 3;
1095 else if (tuner_frequency
< 830000000) cp
= 5;
1096 else if (tuner_frequency
< 895000000) cp
= 7;
1097 else return -EINVAL
;
1100 if (params
->frequency
< 49000000) return -EINVAL
;
1101 else if (params
->frequency
< 159000000) band
= 1;
1102 else if (params
->frequency
< 444000000) band
= 2;
1103 else if (params
->frequency
< 861000000) band
= 4;
1104 else return -EINVAL
;
1107 switch (params
->u
.ofdm
.bandwidth
) {
1108 case BANDWIDTH_6_MHZ
:
1109 tda1004x_writereg(fe
, 0x0C, 0);
1113 case BANDWIDTH_7_MHZ
:
1114 tda1004x_writereg(fe
, 0x0C, 0);
1118 case BANDWIDTH_8_MHZ
:
1119 tda1004x_writereg(fe
, 0x0C, 0xFF);
1127 // calculate divisor
1128 // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
1129 tuner_frequency
= (((params
->frequency
/ 1000) * 6) + 217280) / 1000;
1131 // setup tuner buffer
1132 tuner_buf
[0] = tuner_frequency
>> 8;
1133 tuner_buf
[1] = tuner_frequency
& 0xff;
1134 tuner_buf
[2] = 0xca;
1135 tuner_buf
[3] = (cp
<< 5) | (filter
<< 3) | band
;
1137 if (fe
->ops
.i2c_gate_ctrl
)
1138 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1139 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1)
1146 static int philips_tdm1316l_request_firmware(struct dvb_frontend
* fe
, const struct firmware
**fw
, char* name
)
1148 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1150 return request_firmware(fw
, name
, &ttusb
->dev
->dev
);
1153 static struct tda1004x_config philips_tdm1316l_config
= {
1155 .demod_address
= 0x8,
1158 .request_firmware
= philips_tdm1316l_request_firmware
,
1161 static u8 alps_bsbe1_inittab
[] = {
1165 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1166 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1167 0x06, 0x40, /* DAC not used, set to high impendance mode */
1168 0x07, 0x00, /* DAC LSB */
1169 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1170 0x09, 0x00, /* FIFO */
1171 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1172 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1173 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1174 0x10, 0x3f, // AGC2 0x3d
1177 0x15, 0xc9, // lock detector threshold
1188 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1189 0x29, 0x1e, // 1/2 threshold
1190 0x2a, 0x14, // 2/3 threshold
1191 0x2b, 0x0f, // 3/4 threshold
1192 0x2c, 0x09, // 5/6 threshold
1193 0x2d, 0x05, // 7/8 threshold
1195 0x31, 0x1f, // test all FECs
1196 0x32, 0x19, // viterbi and synchro search
1197 0x33, 0xfc, // rs control
1198 0x34, 0x93, // error control
1203 static u8 alps_bsru6_inittab
[] = {
1207 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1208 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1209 0x06, 0x40, /* DAC not used, set to high impendance mode */
1210 0x07, 0x00, /* DAC LSB */
1211 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1212 0x09, 0x00, /* FIFO */
1213 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1214 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1215 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1216 0x10, 0x3f, // AGC2 0x3d
1219 0x15, 0xc9, // lock detector threshold
1230 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1231 0x29, 0x1e, // 1/2 threshold
1232 0x2a, 0x14, // 2/3 threshold
1233 0x2b, 0x0f, // 3/4 threshold
1234 0x2c, 0x09, // 5/6 threshold
1235 0x2d, 0x05, // 7/8 threshold
1237 0x31, 0x1f, // test all FECs
1238 0x32, 0x19, // viterbi and synchro search
1239 0x33, 0xfc, // rs control
1240 0x34, 0x93, // error control
1245 static int alps_stv0299_set_symbol_rate(struct dvb_frontend
*fe
, u32 srate
, u32 ratio
)
1250 if (srate
< 1500000) {
1253 } else if (srate
< 3000000) {
1256 } else if (srate
< 7000000) {
1259 } else if (srate
< 14000000) {
1262 } else if (srate
< 30000000) {
1265 } else if (srate
< 45000000) {
1270 stv0299_writereg(fe
, 0x13, aclk
);
1271 stv0299_writereg(fe
, 0x14, bclk
);
1272 stv0299_writereg(fe
, 0x1f, (ratio
>> 16) & 0xff);
1273 stv0299_writereg(fe
, 0x20, (ratio
>> 8) & 0xff);
1274 stv0299_writereg(fe
, 0x21, (ratio
) & 0xf0);
1279 static int philips_tsa5059_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
1281 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1284 struct i2c_msg msg
= {.addr
= 0x61,.flags
= 0,.buf
= buf
,.len
= sizeof(buf
) };
1286 if ((params
->frequency
< 950000) || (params
->frequency
> 2150000))
1289 div
= (params
->frequency
+ (125 - 1)) / 125; // round correctly
1290 buf
[0] = (div
>> 8) & 0x7f;
1291 buf
[1] = div
& 0xff;
1292 buf
[2] = 0x80 | ((div
& 0x18000) >> 10) | 4;
1295 if (params
->frequency
> 1530000)
1298 /* BSBE1 wants XCE bit set */
1299 if (ttusb
->revision
== TTUSB_REV_2_2
)
1302 if (fe
->ops
.i2c_gate_ctrl
)
1303 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1304 if (i2c_transfer(&ttusb
->i2c_adap
, &msg
, 1) != 1)
1310 static struct stv0299_config alps_stv0299_config
= {
1311 .demod_address
= 0x68,
1312 .inittab
= alps_bsru6_inittab
,
1316 .lock_output
= STV0229_LOCKOUTPUT_1
,
1317 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
1318 .min_delay_ms
= 100,
1319 .set_symbol_rate
= alps_stv0299_set_symbol_rate
,
1322 static int ttusb_novas_grundig_29504_491_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
1324 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1327 struct i2c_msg msg
= {.addr
= 0x61,.flags
= 0,.buf
= buf
,.len
= sizeof(buf
) };
1329 div
= params
->frequency
/ 125;
1331 buf
[0] = (div
>> 8) & 0x7f;
1332 buf
[1] = div
& 0xff;
1336 if (fe
->ops
.i2c_gate_ctrl
)
1337 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1338 if (i2c_transfer(&ttusb
->i2c_adap
, &msg
, 1) != 1)
1344 static struct tda8083_config ttusb_novas_grundig_29504_491_config
= {
1346 .demod_address
= 0x68,
1349 static int alps_tdbe2_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
* params
)
1351 struct ttusb
* ttusb
= fe
->dvb
->priv
;
1354 struct i2c_msg msg
= { .addr
= 0x62, .flags
= 0, .buf
= data
, .len
= sizeof(data
) };
1356 div
= (params
->frequency
+ 35937500 + 31250) / 62500;
1358 data
[0] = (div
>> 8) & 0x7f;
1359 data
[1] = div
& 0xff;
1360 data
[2] = 0x85 | ((div
>> 10) & 0x60);
1361 data
[3] = (params
->frequency
< 174000000 ? 0x88 : params
->frequency
< 470000000 ? 0x84 : 0x81);
1363 if (fe
->ops
.i2c_gate_ctrl
)
1364 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1365 if (i2c_transfer (&ttusb
->i2c_adap
, &msg
, 1) != 1)
1372 static struct ves1820_config alps_tdbe2_config
= {
1373 .demod_address
= 0x09,
1376 .selagc
= VES1820_SELAGC_SIGNAMPERR
,
1379 static u8
read_pwm(struct ttusb
* ttusb
)
1383 struct i2c_msg msg
[] = { { .addr
= 0x50,.flags
= 0,.buf
= &b
,.len
= 1 },
1384 { .addr
= 0x50,.flags
= I2C_M_RD
,.buf
= &pwm
,.len
= 1} };
1386 if ((i2c_transfer(&ttusb
->i2c_adap
, msg
, 2) != 2) || (pwm
== 0xff))
1393 static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
1395 struct ttusb
*ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1397 struct i2c_msg tuner_msg
= {.addr
= 0x60,
1400 .len
= sizeof(tuner_buf
) };
1401 int tuner_frequency
= 0;
1402 u8 band
, cp
, filter
;
1404 // determine charge pump
1405 tuner_frequency
= params
->frequency
;
1406 if (tuner_frequency
< 87000000) {return -EINVAL
;}
1407 else if (tuner_frequency
< 130000000) {cp
= 3; band
= 1;}
1408 else if (tuner_frequency
< 160000000) {cp
= 5; band
= 1;}
1409 else if (tuner_frequency
< 200000000) {cp
= 6; band
= 1;}
1410 else if (tuner_frequency
< 290000000) {cp
= 3; band
= 2;}
1411 else if (tuner_frequency
< 420000000) {cp
= 5; band
= 2;}
1412 else if (tuner_frequency
< 480000000) {cp
= 6; band
= 2;}
1413 else if (tuner_frequency
< 620000000) {cp
= 3; band
= 4;}
1414 else if (tuner_frequency
< 830000000) {cp
= 5; band
= 4;}
1415 else if (tuner_frequency
< 895000000) {cp
= 7; band
= 4;}
1416 else {return -EINVAL
;}
1418 // assume PLL filter should always be 8MHz for the moment.
1421 // calculate divisor
1422 // (Finput + Fif)/Fref; Fif = 36125000 Hz, Fref = 62500 Hz
1423 tuner_frequency
= ((params
->frequency
+ 36125000) / 62500);
1425 // setup tuner buffer
1426 tuner_buf
[0] = tuner_frequency
>> 8;
1427 tuner_buf
[1] = tuner_frequency
& 0xff;
1428 tuner_buf
[2] = 0xc8;
1429 tuner_buf
[3] = (cp
<< 5) | (filter
<< 3) | band
;
1430 tuner_buf
[4] = 0x80;
1432 if (fe
->ops
.i2c_gate_ctrl
)
1433 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1434 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) {
1435 printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 1\n");
1441 if (fe
->ops
.i2c_gate_ctrl
)
1442 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1443 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) {
1444 printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 2\n");
1453 static u8 dvbc_philips_tdm1316l_inittab
[] = {
1555 static struct stv0297_config dvbc_philips_tdm1316l_config
= {
1556 .demod_address
= 0x1c,
1557 .inittab
= dvbc_philips_tdm1316l_inittab
,
1561 static void frontend_init(struct ttusb
* ttusb
)
1563 switch(le16_to_cpu(ttusb
->dev
->descriptor
.idProduct
)) {
1564 case 0x1003: // Hauppauge/TT Nova-USB-S budget (stv0299/ALPS BSRU6|BSBE1(tsa5059))
1565 // try the stv0299 based first
1566 ttusb
->fe
= dvb_attach(stv0299_attach
, &alps_stv0299_config
, &ttusb
->i2c_adap
);
1567 if (ttusb
->fe
!= NULL
) {
1568 ttusb
->fe
->ops
.tuner_ops
.set_params
= philips_tsa5059_tuner_set_params
;
1570 if(ttusb
->revision
== TTUSB_REV_2_2
) { // ALPS BSBE1
1571 alps_stv0299_config
.inittab
= alps_bsbe1_inittab
;
1572 dvb_attach(lnbp21_attach
, ttusb
->fe
, &ttusb
->i2c_adap
, 0, 0);
1573 } else { // ALPS BSRU6
1574 ttusb
->fe
->ops
.set_voltage
= ttusb_set_voltage
;
1579 // Grundig 29504-491
1580 ttusb
->fe
= dvb_attach(tda8083_attach
, &ttusb_novas_grundig_29504_491_config
, &ttusb
->i2c_adap
);
1581 if (ttusb
->fe
!= NULL
) {
1582 ttusb
->fe
->ops
.tuner_ops
.set_params
= ttusb_novas_grundig_29504_491_tuner_set_params
;
1583 ttusb
->fe
->ops
.set_voltage
= ttusb_set_voltage
;
1588 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
1589 ttusb
->fe
= dvb_attach(ves1820_attach
, &alps_tdbe2_config
, &ttusb
->i2c_adap
, read_pwm(ttusb
));
1590 if (ttusb
->fe
!= NULL
) {
1591 ttusb
->fe
->ops
.tuner_ops
.set_params
= alps_tdbe2_tuner_set_params
;
1595 ttusb
->fe
= dvb_attach(stv0297_attach
, &dvbc_philips_tdm1316l_config
, &ttusb
->i2c_adap
);
1596 if (ttusb
->fe
!= NULL
) {
1597 ttusb
->fe
->ops
.tuner_ops
.set_params
= dvbc_philips_tdm1316l_tuner_set_params
;
1602 case 0x1005: // Hauppauge/TT Nova-USB-t budget (tda10046/Philips td1316(tda6651tt) OR cx22700/ALPS TDMB7(??))
1603 // try the ALPS TDMB7 first
1604 ttusb
->fe
= dvb_attach(cx22700_attach
, &alps_tdmb7_config
, &ttusb
->i2c_adap
);
1605 if (ttusb
->fe
!= NULL
) {
1606 ttusb
->fe
->ops
.tuner_ops
.set_params
= alps_tdmb7_tuner_set_params
;
1611 ttusb
->fe
= dvb_attach(tda10046_attach
, &philips_tdm1316l_config
, &ttusb
->i2c_adap
);
1612 if (ttusb
->fe
!= NULL
) {
1613 ttusb
->fe
->ops
.tuner_ops
.init
= philips_tdm1316l_tuner_init
;
1614 ttusb
->fe
->ops
.tuner_ops
.set_params
= philips_tdm1316l_tuner_set_params
;
1620 if (ttusb
->fe
== NULL
) {
1621 printk("dvb-ttusb-budget: A frontend driver was not found for device %04x/%04x\n",
1622 le16_to_cpu(ttusb
->dev
->descriptor
.idVendor
),
1623 le16_to_cpu(ttusb
->dev
->descriptor
.idProduct
));
1625 if (dvb_register_frontend(&ttusb
->adapter
, ttusb
->fe
)) {
1626 printk("dvb-ttusb-budget: Frontend registration failed!\n");
1627 dvb_frontend_detach(ttusb
->fe
);
1635 static struct i2c_algorithm ttusb_dec_algo
= {
1636 .master_xfer
= master_xfer
,
1637 .functionality
= functionality
,
1640 static int ttusb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1642 struct usb_device
*udev
;
1643 struct ttusb
*ttusb
;
1646 dprintk("%s: TTUSB DVB connected\n", __FUNCTION__
);
1648 udev
= interface_to_usbdev(intf
);
1650 if (intf
->altsetting
->desc
.bInterfaceNumber
!= 1) return -ENODEV
;
1652 if (!(ttusb
= kzalloc(sizeof(struct ttusb
), GFP_KERNEL
)))
1657 ttusb
->mux_state
= 0;
1658 mutex_init(&ttusb
->semi2c
);
1660 mutex_lock(&ttusb
->semi2c
);
1662 mutex_init(&ttusb
->semusb
);
1664 ttusb_setup_interfaces(ttusb
);
1666 ttusb_alloc_iso_urbs(ttusb
);
1667 if (ttusb_init_controller(ttusb
))
1668 printk("ttusb_init_controller: error\n");
1670 mutex_unlock(&ttusb
->semi2c
);
1672 if ((result
= dvb_register_adapter(&ttusb
->adapter
, "Technotrend/Hauppauge Nova-USB", THIS_MODULE
, &udev
->dev
)) < 0) {
1673 ttusb_free_iso_urbs(ttusb
);
1677 ttusb
->adapter
.priv
= ttusb
;
1680 memset(&ttusb
->i2c_adap
, 0, sizeof(struct i2c_adapter
));
1681 strcpy(ttusb
->i2c_adap
.name
, "TTUSB DEC");
1683 i2c_set_adapdata(&ttusb
->i2c_adap
, ttusb
);
1685 #ifdef I2C_ADAP_CLASS_TV_DIGITAL
1686 ttusb
->i2c_adap
.class = I2C_ADAP_CLASS_TV_DIGITAL
;
1688 ttusb
->i2c_adap
.class = I2C_CLASS_TV_DIGITAL
;
1690 ttusb
->i2c_adap
.algo
= &ttusb_dec_algo
;
1691 ttusb
->i2c_adap
.algo_data
= NULL
;
1692 ttusb
->i2c_adap
.dev
.parent
= &udev
->dev
;
1694 result
= i2c_add_adapter(&ttusb
->i2c_adap
);
1696 dvb_unregister_adapter (&ttusb
->adapter
);
1700 memset(&ttusb
->dvb_demux
, 0, sizeof(ttusb
->dvb_demux
));
1702 ttusb
->dvb_demux
.dmx
.capabilities
=
1703 DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
1704 ttusb
->dvb_demux
.priv
= NULL
;
1705 #ifdef TTUSB_HWSECTIONS
1706 ttusb
->dvb_demux
.filternum
= TTUSB_MAXFILTER
;
1708 ttusb
->dvb_demux
.filternum
= 32;
1710 ttusb
->dvb_demux
.feednum
= TTUSB_MAXCHANNEL
;
1711 ttusb
->dvb_demux
.start_feed
= ttusb_start_feed
;
1712 ttusb
->dvb_demux
.stop_feed
= ttusb_stop_feed
;
1713 ttusb
->dvb_demux
.write_to_decoder
= NULL
;
1715 if ((result
= dvb_dmx_init(&ttusb
->dvb_demux
)) < 0) {
1716 printk("ttusb_dvb: dvb_dmx_init failed (errno = %d)\n", result
);
1717 i2c_del_adapter(&ttusb
->i2c_adap
);
1718 dvb_unregister_adapter (&ttusb
->adapter
);
1721 //FIXME dmxdev (nur WAS?)
1722 ttusb
->dmxdev
.filternum
= ttusb
->dvb_demux
.filternum
;
1723 ttusb
->dmxdev
.demux
= &ttusb
->dvb_demux
.dmx
;
1724 ttusb
->dmxdev
.capabilities
= 0;
1726 if ((result
= dvb_dmxdev_init(&ttusb
->dmxdev
, &ttusb
->adapter
)) < 0) {
1727 printk("ttusb_dvb: dvb_dmxdev_init failed (errno = %d)\n",
1729 dvb_dmx_release(&ttusb
->dvb_demux
);
1730 i2c_del_adapter(&ttusb
->i2c_adap
);
1731 dvb_unregister_adapter (&ttusb
->adapter
);
1735 if (dvb_net_init(&ttusb
->adapter
, &ttusb
->dvbnet
, &ttusb
->dvb_demux
.dmx
)) {
1736 printk("ttusb_dvb: dvb_net_init failed!\n");
1737 dvb_dmxdev_release(&ttusb
->dmxdev
);
1738 dvb_dmx_release(&ttusb
->dvb_demux
);
1739 i2c_del_adapter(&ttusb
->i2c_adap
);
1740 dvb_unregister_adapter (&ttusb
->adapter
);
1744 usb_set_intfdata(intf
, (void *) ttusb
);
1746 frontend_init(ttusb
);
1751 static void ttusb_disconnect(struct usb_interface
*intf
)
1753 struct ttusb
*ttusb
= usb_get_intfdata(intf
);
1755 usb_set_intfdata(intf
, NULL
);
1757 ttusb
->disconnecting
= 1;
1759 ttusb_stop_iso_xfer(ttusb
);
1761 ttusb
->dvb_demux
.dmx
.close(&ttusb
->dvb_demux
.dmx
);
1762 dvb_net_release(&ttusb
->dvbnet
);
1763 dvb_dmxdev_release(&ttusb
->dmxdev
);
1764 dvb_dmx_release(&ttusb
->dvb_demux
);
1765 if (ttusb
->fe
!= NULL
) {
1766 dvb_unregister_frontend(ttusb
->fe
);
1767 dvb_frontend_detach(ttusb
->fe
);
1769 i2c_del_adapter(&ttusb
->i2c_adap
);
1770 dvb_unregister_adapter(&ttusb
->adapter
);
1772 ttusb_free_iso_urbs(ttusb
);
1776 dprintk("%s: TTUSB DVB disconnected\n", __FUNCTION__
);
1779 static struct usb_device_id ttusb_table
[] = {
1780 {USB_DEVICE(0xb48, 0x1003)},
1781 {USB_DEVICE(0xb48, 0x1004)},
1782 {USB_DEVICE(0xb48, 0x1005)},
1786 MODULE_DEVICE_TABLE(usb
, ttusb_table
);
1788 static struct usb_driver ttusb_driver
= {
1790 .probe
= ttusb_probe
,
1791 .disconnect
= ttusb_disconnect
,
1792 .id_table
= ttusb_table
,
1795 static int __init
ttusb_init(void)
1799 if ((err
= usb_register(&ttusb_driver
)) < 0) {
1800 printk("%s: usb_register failed! Error number %d",
1808 static void __exit
ttusb_exit(void)
1810 usb_deregister(&ttusb_driver
);
1813 module_init(ttusb_init
);
1814 module_exit(ttusb_exit
);
1816 MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>");
1817 MODULE_DESCRIPTION("TTUSB DVB Driver");
1818 MODULE_LICENSE("GPL");