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>
16 #include <linux/module.h>
17 #include <linux/usb.h>
18 #include <linux/delay.h>
19 #include <linux/time.h>
20 #include <linux/errno.h>
21 #include <linux/jiffies.h>
22 #include <linux/mutex.h>
23 #include <linux/firmware.h>
25 #include "dvb_frontend.h"
27 #include "dvb_demux.h"
37 #include <linux/dvb/frontend.h>
38 #include <linux/dvb/dmx.h>
39 #include <linux/pci.h>
43 the DSP supports filtering in hardware, however, since the "muxstream"
44 is a bit braindead (no matching channel masks or no matching filter mask),
45 we won't support this - yet. it doesn't event support negative filters,
46 so the best way is maybe to keep TTUSB_HWSECTIONS undef'd and just
47 parse TS data. USB bandwidth will be a problem when having large
48 datastreams, especially for dvb-net, but hey, that's not my problem.
50 TTUSB_DISEQC, TTUSB_TONE:
51 let the STC do the diseqc/tone stuff. this isn't supported at least with
52 my TTUSB, so let it undef'd unless you want to implement another
53 frontend. never tested.
56 define it to > 3 for really hardcore debugging. you probably don't want
57 this unless the device doesn't load at all. > 2 for bandwidth statistics.
61 module_param(debug
, int, 0644);
62 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
64 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
66 #define dprintk(x...) do { if (debug) printk(KERN_DEBUG x); } while (0)
68 #define ISO_BUF_COUNT 4
69 #define FRAMES_PER_ISO_BUF 4
70 #define ISO_FRAME_SIZE 912
71 #define TTUSB_MAXCHANNEL 32
72 #ifdef TTUSB_HWSECTIONS
73 #define TTUSB_MAXFILTER 16 /* ??? */
76 #define TTUSB_REV_2_2 0x22
77 #define TTUSB_BUDGET_NAME "ttusb_stc_fw"
80 * since we're casting (struct ttusb*) <-> (struct dvb_demux*) around
81 * the dvb_demux field must be the first in struct!!
84 struct dvb_demux dvb_demux
;
86 struct dvb_net dvbnet
;
88 /* and one for USB access. */
92 struct dvb_adapter adapter
;
93 struct usb_device
*dev
;
95 struct i2c_adapter i2c_adap
;
100 unsigned int bulk_out_pipe
;
101 unsigned int bulk_in_pipe
;
102 unsigned int isoc_in_pipe
;
105 dma_addr_t iso_dma_handle
;
107 struct urb
*iso_urb
[ISO_BUF_COUNT
];
109 int running_feed_count
;
113 u8 c
; /* transaction counter, wraps around... */
114 fe_sec_tone_mode_t tone
;
115 fe_sec_voltage_t voltage
;
117 int mux_state
; // 0..2 - MuxSyncWord, 3 - nMuxPacks, 4 - muxpack
120 int muxpack_ptr
, muxpack_len
;
124 int cc
; /* MuxCounter - will increment on EVERY MUX PACKET */
125 /* (including stuffing. yes. really.) */
131 struct dvb_frontend
* fe
;
134 /* ugly workaround ... don't know why it's necessary to read */
135 /* all result codes. */
138 static int ttusb_cmd(struct ttusb
*ttusb
,
139 const u8
* data
, int len
, int needresult
)
147 for (i
= 0; i
< len
; ++i
)
148 printk(" %02x", data
[i
]);
152 if (mutex_lock_interruptible(&ttusb
->semusb
) < 0)
155 err
= usb_bulk_msg(ttusb
->dev
, ttusb
->bulk_out_pipe
,
156 (u8
*) data
, len
, &actual_len
, 1000);
158 dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n",
160 mutex_unlock(&ttusb
->semusb
);
163 if (actual_len
!= len
) {
164 dprintk("%s: only wrote %d of %d bytes\n", __func__
,
166 mutex_unlock(&ttusb
->semusb
);
170 err
= usb_bulk_msg(ttusb
->dev
, ttusb
->bulk_in_pipe
,
171 ttusb
->last_result
, 32, &actual_len
, 1000);
174 printk("%s: failed, receive error %d\n", __func__
,
176 mutex_unlock(&ttusb
->semusb
);
180 actual_len
= ttusb
->last_result
[3] + 4;
182 for (i
= 0; i
< actual_len
; ++i
)
183 printk(" %02x", ttusb
->last_result
[i
]);
187 mutex_unlock(&ttusb
->semusb
);
191 static int ttusb_result(struct ttusb
*ttusb
, u8
* data
, int len
)
193 memcpy(data
, ttusb
->last_result
, len
);
194 mutex_unlock(&ttusb
->semusb
);
198 static int ttusb_i2c_msg(struct ttusb
*ttusb
,
199 u8 addr
, u8
* snd_buf
, u8 snd_len
, u8
* rcv_buf
,
206 if (snd_len
> 0x28 - 7 || rcv_len
> 0x20 - 7)
217 for (i
= 0; i
< snd_len
; i
++)
218 b
[7 + i
] = snd_buf
[i
];
220 err
= ttusb_cmd(ttusb
, b
, snd_len
+ 7, 1);
225 err
= ttusb_result(ttusb
, b
, 0x20);
227 /* check if the i2c transaction was successful */
228 if ((snd_len
!= b
[5]) || (rcv_len
!= b
[6])) return -EREMOTEIO
;
232 if (err
|| b
[0] != 0x55 || b
[1] != id
) {
234 ("%s: usb_bulk_msg(recv) failed, err == %i, id == %02x, b == ",
239 for (i
= 0; i
< rcv_len
; i
++)
240 rcv_buf
[i
] = b
[7 + i
];
246 static int master_xfer(struct i2c_adapter
* adapter
, struct i2c_msg
*msg
, int num
)
248 struct ttusb
*ttusb
= i2c_get_adapdata(adapter
);
252 if (mutex_lock_interruptible(&ttusb
->semi2c
) < 0)
256 u8 addr
, snd_len
, rcv_len
, *snd_buf
, *rcv_buf
;
259 if (num
> i
+ 1 && (msg
[i
+ 1].flags
& I2C_M_RD
)) {
261 snd_buf
= msg
[i
].buf
;
262 snd_len
= msg
[i
].len
;
263 rcv_buf
= msg
[i
+ 1].buf
;
264 rcv_len
= msg
[i
+ 1].len
;
268 snd_buf
= msg
[i
].buf
;
269 snd_len
= msg
[i
].len
;
275 err
= ttusb_i2c_msg(ttusb
, addr
,
276 snd_buf
, snd_len
, rcv_buf
, rcv_len
);
279 dprintk("%s: i == %i\n", __func__
, i
);
286 mutex_unlock(&ttusb
->semi2c
);
290 static int ttusb_boot_dsp(struct ttusb
*ttusb
)
292 const struct firmware
*fw
;
296 err
= request_firmware(&fw
, "ttusb-budget/dspbootcode.bin",
299 printk(KERN_ERR
"ttusb-budget: failed to request firmware\n");
308 /* upload dsp code in 32 byte steps (36 didn't work for me ...) */
309 /* 32 is max packet size, no messages should be splitted. */
310 for (i
= 0; i
< fw
->size
; i
+= 28) {
311 memcpy(&b
[4], &fw
->data
[i
], 28);
315 err
= ttusb_cmd(ttusb
, b
, 32, 0);
325 err
= ttusb_cmd(ttusb
, b
, 4, 0);
334 err
= ttusb_cmd(ttusb
, b
, 4, 0);
337 release_firmware(fw
);
339 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
346 static int ttusb_set_channel(struct ttusb
*ttusb
, int chan_id
, int filter_type
,
351 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x22, 4, chan_id
, filter_type
,
352 (pid
>> 8) & 0xff, pid
& 0xff
355 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
359 static int ttusb_del_channel(struct ttusb
*ttusb
, int channel_id
)
363 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x23, 1, channel_id
};
365 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
369 #ifdef TTUSB_HWSECTIONS
370 static int ttusb_set_filter(struct ttusb
*ttusb
, int filter_id
,
371 int associated_chan
, u8 filter
[8], u8 mask
[8])
375 u8 b
[] = { 0xaa, 0, 0x24, 0x1a, filter_id
, associated_chan
,
376 filter
[0], filter
[1], filter
[2], filter
[3],
377 filter
[4], filter
[5], filter
[6], filter
[7],
378 filter
[8], filter
[9], filter
[10], filter
[11],
379 mask
[0], mask
[1], mask
[2], mask
[3],
380 mask
[4], mask
[5], mask
[6], mask
[7],
381 mask
[8], mask
[9], mask
[10], mask
[11]
384 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
388 static int ttusb_del_filter(struct ttusb
*ttusb
, int filter_id
)
392 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x25, 1, filter_id
};
394 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
399 static int ttusb_init_controller(struct ttusb
*ttusb
)
401 u8 b0
[] = { 0xaa, ++ttusb
->c
, 0x15, 1, 0 };
402 u8 b1
[] = { 0xaa, ++ttusb
->c
, 0x15, 1, 1 };
403 u8 b2
[] = { 0xaa, ++ttusb
->c
, 0x32, 1, 0 };
404 /* i2c write read: 5 bytes, addr 0x10, 0x02 bytes write, 1 bytes read. */
406 { 0xaa, ++ttusb
->c
, 0x31, 5, 0x10, 0x02, 0x01, 0x00, 0x1e };
408 { 0x55, ttusb
->c
, 0x31, 4, 0x10, 0x02, 0x01, 0x00, 0x1e };
410 u8 get_version
[] = { 0xaa, ++ttusb
->c
, 0x17, 5, 0, 0, 0, 0, 0 };
411 u8 get_dsp_version
[0x20] =
412 { 0xaa, ++ttusb
->c
, 0x26, 28, 0, 0, 0, 0, 0 };
416 if ((err
= ttusb_cmd(ttusb
, b0
, sizeof(b0
), 0)))
419 /* reset board (again?) */
420 if ((err
= ttusb_cmd(ttusb
, b1
, sizeof(b1
), 0)))
423 ttusb_boot_dsp(ttusb
);
425 /* set i2c bit rate */
426 if ((err
= ttusb_cmd(ttusb
, b2
, sizeof(b2
), 0)))
429 if ((err
= ttusb_cmd(ttusb
, b3
, sizeof(b3
), 1)))
432 err
= ttusb_result(ttusb
, b4
, sizeof(b4
));
434 if ((err
= ttusb_cmd(ttusb
, get_version
, sizeof(get_version
), 1)))
437 if ((err
= ttusb_result(ttusb
, get_version
, sizeof(get_version
))))
440 dprintk("%s: stc-version: %c%c%c%c%c\n", __func__
,
441 get_version
[4], get_version
[5], get_version
[6],
442 get_version
[7], get_version
[8]);
444 if (memcmp(get_version
+ 4, "V 0.0", 5) &&
445 memcmp(get_version
+ 4, "V 1.1", 5) &&
446 memcmp(get_version
+ 4, "V 2.1", 5) &&
447 memcmp(get_version
+ 4, "V 2.2", 5)) {
449 ("%s: unknown STC version %c%c%c%c%c, please report!\n",
450 __func__
, get_version
[4], get_version
[5],
451 get_version
[6], get_version
[7], get_version
[8]);
454 ttusb
->revision
= ((get_version
[6] - '0') << 4) |
455 (get_version
[8] - '0');
458 ttusb_cmd(ttusb
, get_dsp_version
, sizeof(get_dsp_version
), 1);
463 ttusb_result(ttusb
, get_dsp_version
, sizeof(get_dsp_version
));
466 printk("%s: dsp-version: %c%c%c\n", __func__
,
467 get_dsp_version
[4], get_dsp_version
[5], get_dsp_version
[6]);
472 static int ttusb_send_diseqc(struct dvb_frontend
* fe
,
473 const struct dvb_diseqc_master_cmd
*cmd
)
475 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
476 u8 b
[12] = { 0xaa, ++ttusb
->c
, 0x18 };
480 b
[3] = 4 + 2 + cmd
->msg_len
;
481 b
[4] = 0xFF; /* send diseqc master, not burst */
484 memcpy(b
+ 5, cmd
->msg
, cmd
->msg_len
);
487 if ((err
= ttusb_cmd(ttusb
, b
, 4 + b
[3], 0))) {
488 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
496 static int ttusb_update_lnb(struct ttusb
*ttusb
)
498 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x16, 5, /*power: */ 1,
499 ttusb
->voltage
== SEC_VOLTAGE_18
? 0 : 1,
500 ttusb
->tone
== SEC_TONE_ON
? 1 : 0, 1, 1
505 if ((err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0))) {
506 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
513 static int ttusb_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
)
515 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
517 ttusb
->voltage
= voltage
;
518 return ttusb_update_lnb(ttusb
);
522 static int ttusb_set_tone(struct dvb_frontend
* fe
, fe_sec_tone_mode_t tone
)
524 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
527 return ttusb_update_lnb(ttusb
);
533 static void ttusb_set_led_freq(struct ttusb
*ttusb
, u8 freq
)
535 u8 b
[] = { 0xaa, ++ttusb
->c
, 0x19, 1, freq
};
538 err
= ttusb_cmd(ttusb
, b
, sizeof(b
), 0);
540 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
546 /*****************************************************************************/
548 #ifdef TTUSB_HWSECTIONS
549 static void ttusb_handle_ts_data(struct ttusb_channel
*channel
,
550 const u8
* data
, int len
);
551 static void ttusb_handle_sec_data(struct ttusb_channel
*channel
,
552 const u8
* data
, int len
);
555 static int numpkt
, numts
, numstuff
, numsec
, numinvalid
;
556 static unsigned long lastj
;
558 static void ttusb_process_muxpack(struct ttusb
*ttusb
, const u8
* muxpack
,
563 for (i
= 0; i
< len
; i
+= 2)
564 csum
^= le16_to_cpup((__le16
*) (muxpack
+ i
));
566 printk("%s: muxpack with incorrect checksum, ignoring\n",
572 cc
= (muxpack
[len
- 4] << 8) | muxpack
[len
- 3];
574 if ((cc
!= ttusb
->cc
) && (ttusb
->cc
!= -1))
575 printk("%s: cc discontinuity (%d frames missing)\n",
576 __func__
, (cc
- ttusb
->cc
) & 0x7FFF);
577 ttusb
->cc
= (cc
+ 1) & 0x7FFF;
578 if (muxpack
[0] & 0x80) {
579 #ifdef TTUSB_HWSECTIONS
581 int pusi
= muxpack
[0] & 0x40;
582 int channel
= muxpack
[0] & 0x1F;
583 int payload
= muxpack
[1];
584 const u8
*data
= muxpack
+ 2;
585 /* check offset flag */
586 if (muxpack
[0] & 0x20)
589 ttusb_handle_sec_data(ttusb
->channel
+ channel
, data
,
593 if ((!!(ttusb
->muxpack
[0] & 0x20)) ^
594 !!(ttusb
->muxpack
[1] & 1))
597 printk("cc: %04x\n", (data
[0] << 8) | data
[1]);
600 } else if (muxpack
[0] == 0x47) {
601 #ifdef TTUSB_HWSECTIONS
602 /* we have TS data here! */
603 int pid
= ((muxpack
[1] & 0x0F) << 8) | muxpack
[2];
605 for (channel
= 0; channel
< TTUSB_MAXCHANNEL
; ++channel
)
606 if (ttusb
->channel
[channel
].active
607 && (pid
== ttusb
->channel
[channel
].pid
))
608 ttusb_handle_ts_data(ttusb
->channel
+
613 dvb_dmx_swfilter_packets(&ttusb
->dvb_demux
, muxpack
, 1);
614 } else if (muxpack
[0] != 0) {
616 printk("illegal muxpack type %02x\n", muxpack
[0]);
621 static void ttusb_process_frame(struct ttusb
*ttusb
, u8
* data
, int len
)
626 printk("%s: too much work\n", __func__
);
630 switch (ttusb
->mux_state
) {
638 ttusb
->mux_state
= 0;
641 printk("%02x ", data
[-1]);
644 printk("%s: lost sync.\n",
654 ttusb
->mux_npacks
= *data
++;
656 ttusb
->muxpack_ptr
= 0;
657 /* maximum bytes, until we know the length */
658 ttusb
->muxpack_len
= 2;
665 (ttusb
->muxpack_len
-
670 memcpy(ttusb
->muxpack
+ ttusb
->muxpack_ptr
,
672 ttusb
->muxpack_ptr
+= avail
;
673 BUG_ON(ttusb
->muxpack_ptr
> 264);
676 /* determine length */
677 if (ttusb
->muxpack_ptr
== 2) {
678 if (ttusb
->muxpack
[0] & 0x80) {
680 ttusb
->muxpack
[1] + 2;
687 muxpack
[0] & 0x20)) ^
692 ttusb
->muxpack_len
+= 4;
693 } else if (ttusb
->muxpack
[0] ==
697 else if (ttusb
->muxpack
[0] == 0x00)
699 ttusb
->muxpack
[1] + 2 +
703 ("%s: invalid state: first byte is %x\n",
706 ttusb
->mux_state
= 0;
711 * if length is valid and we reached the end:
714 if ((ttusb
->muxpack_ptr
>= 2) &&
715 (ttusb
->muxpack_ptr
==
716 ttusb
->muxpack_len
)) {
717 ttusb_process_muxpack(ttusb
,
722 ttusb
->muxpack_ptr
= 0;
723 /* maximum bytes, until we know the length */
724 ttusb
->muxpack_len
= 2;
728 * return to search-sync state
730 if (!ttusb
->mux_npacks
--) {
731 ttusb
->mux_state
= 0;
744 static void ttusb_iso_irq(struct urb
*urb
)
746 struct ttusb
*ttusb
= urb
->context
;
748 if (!ttusb
->iso_streaming
)
752 printk("%s: status %d, errcount == %d, length == %i\n",
754 urb
->status
, urb
->error_count
, urb
->actual_length
);
759 for (i
= 0; i
< urb
->number_of_packets
; ++i
) {
760 struct usb_iso_packet_descriptor
*d
;
764 if (time_after_eq(jiffies
, lastj
+ HZ
)) {
767 ("frames/s: %d (ts: %d, stuff %d, sec: %d, invalid: %d, all: %d)\n",
768 numpkt
* HZ
/ (jiffies
- lastj
),
769 numts
, numstuff
, numsec
, numinvalid
,
770 numts
+ numstuff
+ numsec
+
773 numts
= numstuff
= numsec
= numinvalid
= 0;
777 d
= &urb
->iso_frame_desc
[i
];
778 data
= urb
->transfer_buffer
+ d
->offset
;
779 len
= d
->actual_length
;
780 d
->actual_length
= 0;
782 ttusb_process_frame(ttusb
, data
, len
);
785 usb_submit_urb(urb
, GFP_ATOMIC
);
788 static void ttusb_free_iso_urbs(struct ttusb
*ttusb
)
792 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
793 if (ttusb
->iso_urb
[i
])
794 usb_free_urb(ttusb
->iso_urb
[i
]);
796 pci_free_consistent(NULL
,
797 ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
*
798 ISO_BUF_COUNT
, ttusb
->iso_buffer
,
799 ttusb
->iso_dma_handle
);
802 static int ttusb_alloc_iso_urbs(struct ttusb
*ttusb
)
806 ttusb
->iso_buffer
= pci_alloc_consistent(NULL
,
810 &ttusb
->iso_dma_handle
);
812 if (!ttusb
->iso_buffer
) {
813 dprintk("%s: pci_alloc_consistent - not enough memory\n",
818 memset(ttusb
->iso_buffer
, 0,
819 ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
* ISO_BUF_COUNT
);
821 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
826 usb_alloc_urb(FRAMES_PER_ISO_BUF
, GFP_ATOMIC
))) {
827 ttusb_free_iso_urbs(ttusb
);
831 ttusb
->iso_urb
[i
] = urb
;
837 static void ttusb_stop_iso_xfer(struct ttusb
*ttusb
)
841 for (i
= 0; i
< ISO_BUF_COUNT
; i
++)
842 usb_kill_urb(ttusb
->iso_urb
[i
]);
844 ttusb
->iso_streaming
= 0;
847 static int ttusb_start_iso_xfer(struct ttusb
*ttusb
)
849 int i
, j
, err
, buffer_offset
= 0;
851 if (ttusb
->iso_streaming
) {
852 printk("%s: iso xfer already running!\n", __func__
);
858 ttusb
->mux_state
= 0;
860 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
861 int frame_offset
= 0;
862 struct urb
*urb
= ttusb
->iso_urb
[i
];
864 urb
->dev
= ttusb
->dev
;
865 urb
->context
= ttusb
;
866 urb
->complete
= ttusb_iso_irq
;
867 urb
->pipe
= ttusb
->isoc_in_pipe
;
868 urb
->transfer_flags
= URB_ISO_ASAP
;
870 urb
->number_of_packets
= FRAMES_PER_ISO_BUF
;
871 urb
->transfer_buffer_length
=
872 ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
;
873 urb
->transfer_buffer
= ttusb
->iso_buffer
+ buffer_offset
;
874 buffer_offset
+= ISO_FRAME_SIZE
* FRAMES_PER_ISO_BUF
;
876 for (j
= 0; j
< FRAMES_PER_ISO_BUF
; j
++) {
877 urb
->iso_frame_desc
[j
].offset
= frame_offset
;
878 urb
->iso_frame_desc
[j
].length
= ISO_FRAME_SIZE
;
879 frame_offset
+= ISO_FRAME_SIZE
;
883 for (i
= 0; i
< ISO_BUF_COUNT
; i
++) {
884 if ((err
= usb_submit_urb(ttusb
->iso_urb
[i
], GFP_ATOMIC
))) {
885 ttusb_stop_iso_xfer(ttusb
);
887 ("%s: failed urb submission (%i: err = %i)!\n",
893 ttusb
->iso_streaming
= 1;
898 #ifdef TTUSB_HWSECTIONS
899 static void ttusb_handle_ts_data(struct dvb_demux_feed
*dvbdmxfeed
, const u8
* data
,
902 dvbdmxfeed
->cb
.ts(data
, len
, 0, 0, &dvbdmxfeed
->feed
.ts
, 0);
905 static void ttusb_handle_sec_data(struct dvb_demux_feed
*dvbdmxfeed
, const u8
* data
,
908 // struct dvb_demux_feed *dvbdmxfeed = channel->dvbdmxfeed;
909 #error TODO: handle ugly stuff
910 // dvbdmxfeed->cb.sec(data, len, 0, 0, &dvbdmxfeed->feed.sec, 0);
914 static int ttusb_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
916 struct ttusb
*ttusb
= (struct ttusb
*) dvbdmxfeed
->demux
;
919 dprintk("ttusb_start_feed\n");
921 switch (dvbdmxfeed
->type
) {
930 if (dvbdmxfeed
->type
== DMX_TYPE_TS
) {
931 switch (dvbdmxfeed
->pes_type
) {
932 case DMX_TS_PES_VIDEO
:
933 case DMX_TS_PES_AUDIO
:
934 case DMX_TS_PES_TELETEXT
:
936 case DMX_TS_PES_OTHER
:
943 #ifdef TTUSB_HWSECTIONS
944 #error TODO: allocate filters
945 if (dvbdmxfeed
->type
== DMX_TYPE_TS
) {
947 } else if (dvbdmxfeed
->type
== DMX_TYPE_SEC
) {
952 ttusb_set_channel(ttusb
, dvbdmxfeed
->index
, feed_type
, dvbdmxfeed
->pid
);
954 if (0 == ttusb
->running_feed_count
++)
955 ttusb_start_iso_xfer(ttusb
);
960 static int ttusb_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
962 struct ttusb
*ttusb
= (struct ttusb
*) dvbdmxfeed
->demux
;
964 ttusb_del_channel(ttusb
, dvbdmxfeed
->index
);
966 if (--ttusb
->running_feed_count
== 0)
967 ttusb_stop_iso_xfer(ttusb
);
972 static int ttusb_setup_interfaces(struct ttusb
*ttusb
)
974 usb_set_interface(ttusb
->dev
, 1, 1);
976 ttusb
->bulk_out_pipe
= usb_sndbulkpipe(ttusb
->dev
, 1);
977 ttusb
->bulk_in_pipe
= usb_rcvbulkpipe(ttusb
->dev
, 1);
978 ttusb
->isoc_in_pipe
= usb_rcvisocpipe(ttusb
->dev
, 2);
984 static u8 stc_firmware
[8192];
986 static int stc_open(struct inode
*inode
, struct file
*file
)
988 struct ttusb
*ttusb
= file
->private_data
;
991 for (addr
= 0; addr
< 8192; addr
+= 16) {
992 u8 snd_buf
[2] = { addr
>> 8, addr
& 0xFF };
993 ttusb_i2c_msg(ttusb
, 0x50, snd_buf
, 2, stc_firmware
+ addr
,
1000 static ssize_t
stc_read(struct file
*file
, char *buf
, size_t count
,
1003 return simple_read_from_buffer(buf
, count
, offset
, stc_firmware
, 8192);
1006 static int stc_release(struct inode
*inode
, struct file
*file
)
1011 static const struct file_operations stc_fops
= {
1012 .owner
= THIS_MODULE
,
1015 .release
= stc_release
,
1019 static u32
functionality(struct i2c_adapter
*adapter
)
1021 return I2C_FUNC_I2C
;
1026 static int alps_tdmb7_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
* params
)
1028 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1030 struct i2c_msg msg
= {.addr
=0x61, .flags
=0, .buf
=data
, .len
=sizeof(data
) };
1033 div
= (params
->frequency
+ 36166667) / 166667;
1035 data
[0] = (div
>> 8) & 0x7f;
1036 data
[1] = div
& 0xff;
1037 data
[2] = ((div
>> 10) & 0x60) | 0x85;
1038 data
[3] = params
->frequency
< 592000000 ? 0x40 : 0x80;
1040 if (fe
->ops
.i2c_gate_ctrl
)
1041 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1042 if (i2c_transfer(&ttusb
->i2c_adap
, &msg
, 1) != 1) return -EIO
;
1046 static struct cx22700_config alps_tdmb7_config
= {
1047 .demod_address
= 0x43,
1054 static int philips_tdm1316l_tuner_init(struct dvb_frontend
* fe
)
1056 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1057 static u8 td1316_init
[] = { 0x0b, 0xf5, 0x85, 0xab };
1058 static u8 disable_mc44BC374c
[] = { 0x1d, 0x74, 0xa0, 0x68 };
1059 struct i2c_msg tuner_msg
= { .addr
=0x60, .flags
=0, .buf
=td1316_init
, .len
=sizeof(td1316_init
) };
1061 // setup PLL configuration
1062 if (fe
->ops
.i2c_gate_ctrl
)
1063 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1064 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) return -EIO
;
1067 // disable the mc44BC374c (do not check for errors)
1068 tuner_msg
.addr
= 0x65;
1069 tuner_msg
.buf
= disable_mc44BC374c
;
1070 tuner_msg
.len
= sizeof(disable_mc44BC374c
);
1071 if (fe
->ops
.i2c_gate_ctrl
)
1072 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1073 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) {
1074 i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1);
1080 static int philips_tdm1316l_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
* params
)
1082 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1084 struct i2c_msg tuner_msg
= {.addr
=0x60, .flags
=0, .buf
=tuner_buf
, .len
=sizeof(tuner_buf
) };
1085 int tuner_frequency
= 0;
1086 u8 band
, cp
, filter
;
1088 // determine charge pump
1089 tuner_frequency
= params
->frequency
+ 36130000;
1090 if (tuner_frequency
< 87000000) return -EINVAL
;
1091 else if (tuner_frequency
< 130000000) cp
= 3;
1092 else if (tuner_frequency
< 160000000) cp
= 5;
1093 else if (tuner_frequency
< 200000000) cp
= 6;
1094 else if (tuner_frequency
< 290000000) cp
= 3;
1095 else if (tuner_frequency
< 420000000) cp
= 5;
1096 else if (tuner_frequency
< 480000000) cp
= 6;
1097 else if (tuner_frequency
< 620000000) cp
= 3;
1098 else if (tuner_frequency
< 830000000) cp
= 5;
1099 else if (tuner_frequency
< 895000000) cp
= 7;
1100 else return -EINVAL
;
1103 if (params
->frequency
< 49000000) return -EINVAL
;
1104 else if (params
->frequency
< 159000000) band
= 1;
1105 else if (params
->frequency
< 444000000) band
= 2;
1106 else if (params
->frequency
< 861000000) band
= 4;
1107 else return -EINVAL
;
1110 switch (params
->u
.ofdm
.bandwidth
) {
1111 case BANDWIDTH_6_MHZ
:
1112 tda1004x_writereg(fe
, 0x0C, 0);
1116 case BANDWIDTH_7_MHZ
:
1117 tda1004x_writereg(fe
, 0x0C, 0);
1121 case BANDWIDTH_8_MHZ
:
1122 tda1004x_writereg(fe
, 0x0C, 0xFF);
1130 // calculate divisor
1131 // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
1132 tuner_frequency
= (((params
->frequency
/ 1000) * 6) + 217280) / 1000;
1134 // setup tuner buffer
1135 tuner_buf
[0] = tuner_frequency
>> 8;
1136 tuner_buf
[1] = tuner_frequency
& 0xff;
1137 tuner_buf
[2] = 0xca;
1138 tuner_buf
[3] = (cp
<< 5) | (filter
<< 3) | band
;
1140 if (fe
->ops
.i2c_gate_ctrl
)
1141 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1142 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1)
1149 static int philips_tdm1316l_request_firmware(struct dvb_frontend
* fe
, const struct firmware
**fw
, char* name
)
1151 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1153 return request_firmware(fw
, name
, &ttusb
->dev
->dev
);
1156 static struct tda1004x_config philips_tdm1316l_config
= {
1158 .demod_address
= 0x8,
1161 .request_firmware
= philips_tdm1316l_request_firmware
,
1164 static u8 alps_bsbe1_inittab
[] = {
1168 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1169 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1170 0x06, 0x40, /* DAC not used, set to high impendance mode */
1171 0x07, 0x00, /* DAC LSB */
1172 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1173 0x09, 0x00, /* FIFO */
1174 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1175 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1176 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1177 0x10, 0x3f, // AGC2 0x3d
1180 0x15, 0xc9, // lock detector threshold
1191 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1192 0x29, 0x1e, // 1/2 threshold
1193 0x2a, 0x14, // 2/3 threshold
1194 0x2b, 0x0f, // 3/4 threshold
1195 0x2c, 0x09, // 5/6 threshold
1196 0x2d, 0x05, // 7/8 threshold
1198 0x31, 0x1f, // test all FECs
1199 0x32, 0x19, // viterbi and synchro search
1200 0x33, 0xfc, // rs control
1201 0x34, 0x93, // error control
1206 static u8 alps_bsru6_inittab
[] = {
1210 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1211 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1212 0x06, 0x40, /* DAC not used, set to high impendance mode */
1213 0x07, 0x00, /* DAC LSB */
1214 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1215 0x09, 0x00, /* FIFO */
1216 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1217 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1218 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1219 0x10, 0x3f, // AGC2 0x3d
1222 0x15, 0xc9, // lock detector threshold
1233 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1234 0x29, 0x1e, // 1/2 threshold
1235 0x2a, 0x14, // 2/3 threshold
1236 0x2b, 0x0f, // 3/4 threshold
1237 0x2c, 0x09, // 5/6 threshold
1238 0x2d, 0x05, // 7/8 threshold
1240 0x31, 0x1f, // test all FECs
1241 0x32, 0x19, // viterbi and synchro search
1242 0x33, 0xfc, // rs control
1243 0x34, 0x93, // error control
1248 static int alps_stv0299_set_symbol_rate(struct dvb_frontend
*fe
, u32 srate
, u32 ratio
)
1253 if (srate
< 1500000) {
1256 } else if (srate
< 3000000) {
1259 } else if (srate
< 7000000) {
1262 } else if (srate
< 14000000) {
1265 } else if (srate
< 30000000) {
1268 } else if (srate
< 45000000) {
1273 stv0299_writereg(fe
, 0x13, aclk
);
1274 stv0299_writereg(fe
, 0x14, bclk
);
1275 stv0299_writereg(fe
, 0x1f, (ratio
>> 16) & 0xff);
1276 stv0299_writereg(fe
, 0x20, (ratio
>> 8) & 0xff);
1277 stv0299_writereg(fe
, 0x21, (ratio
) & 0xf0);
1282 static int philips_tsa5059_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
1284 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1287 struct i2c_msg msg
= {.addr
= 0x61,.flags
= 0,.buf
= buf
,.len
= sizeof(buf
) };
1289 if ((params
->frequency
< 950000) || (params
->frequency
> 2150000))
1292 div
= (params
->frequency
+ (125 - 1)) / 125; // round correctly
1293 buf
[0] = (div
>> 8) & 0x7f;
1294 buf
[1] = div
& 0xff;
1295 buf
[2] = 0x80 | ((div
& 0x18000) >> 10) | 4;
1298 if (params
->frequency
> 1530000)
1301 /* BSBE1 wants XCE bit set */
1302 if (ttusb
->revision
== TTUSB_REV_2_2
)
1305 if (fe
->ops
.i2c_gate_ctrl
)
1306 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1307 if (i2c_transfer(&ttusb
->i2c_adap
, &msg
, 1) != 1)
1313 static struct stv0299_config alps_stv0299_config
= {
1314 .demod_address
= 0x68,
1315 .inittab
= alps_bsru6_inittab
,
1319 .lock_output
= STV0299_LOCKOUTPUT_1
,
1320 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
1321 .min_delay_ms
= 100,
1322 .set_symbol_rate
= alps_stv0299_set_symbol_rate
,
1325 static int ttusb_novas_grundig_29504_491_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
1327 struct ttusb
* ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1330 struct i2c_msg msg
= {.addr
= 0x61,.flags
= 0,.buf
= buf
,.len
= sizeof(buf
) };
1332 div
= params
->frequency
/ 125;
1334 buf
[0] = (div
>> 8) & 0x7f;
1335 buf
[1] = div
& 0xff;
1339 if (fe
->ops
.i2c_gate_ctrl
)
1340 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1341 if (i2c_transfer(&ttusb
->i2c_adap
, &msg
, 1) != 1)
1347 static struct tda8083_config ttusb_novas_grundig_29504_491_config
= {
1349 .demod_address
= 0x68,
1352 static int alps_tdbe2_tuner_set_params(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
* params
)
1354 struct ttusb
* ttusb
= fe
->dvb
->priv
;
1357 struct i2c_msg msg
= { .addr
= 0x62, .flags
= 0, .buf
= data
, .len
= sizeof(data
) };
1359 div
= (params
->frequency
+ 35937500 + 31250) / 62500;
1361 data
[0] = (div
>> 8) & 0x7f;
1362 data
[1] = div
& 0xff;
1363 data
[2] = 0x85 | ((div
>> 10) & 0x60);
1364 data
[3] = (params
->frequency
< 174000000 ? 0x88 : params
->frequency
< 470000000 ? 0x84 : 0x81);
1366 if (fe
->ops
.i2c_gate_ctrl
)
1367 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1368 if (i2c_transfer (&ttusb
->i2c_adap
, &msg
, 1) != 1)
1375 static struct ves1820_config alps_tdbe2_config
= {
1376 .demod_address
= 0x09,
1379 .selagc
= VES1820_SELAGC_SIGNAMPERR
,
1382 static u8
read_pwm(struct ttusb
* ttusb
)
1386 struct i2c_msg msg
[] = { { .addr
= 0x50,.flags
= 0,.buf
= &b
,.len
= 1 },
1387 { .addr
= 0x50,.flags
= I2C_M_RD
,.buf
= &pwm
,.len
= 1} };
1389 if ((i2c_transfer(&ttusb
->i2c_adap
, msg
, 2) != 2) || (pwm
== 0xff))
1396 static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend
*fe
, struct dvb_frontend_parameters
*params
)
1398 struct ttusb
*ttusb
= (struct ttusb
*) fe
->dvb
->priv
;
1400 struct i2c_msg tuner_msg
= {.addr
= 0x60,
1403 .len
= sizeof(tuner_buf
) };
1404 int tuner_frequency
= 0;
1405 u8 band
, cp
, filter
;
1407 // determine charge pump
1408 tuner_frequency
= params
->frequency
;
1409 if (tuner_frequency
< 87000000) {return -EINVAL
;}
1410 else if (tuner_frequency
< 130000000) {cp
= 3; band
= 1;}
1411 else if (tuner_frequency
< 160000000) {cp
= 5; band
= 1;}
1412 else if (tuner_frequency
< 200000000) {cp
= 6; band
= 1;}
1413 else if (tuner_frequency
< 290000000) {cp
= 3; band
= 2;}
1414 else if (tuner_frequency
< 420000000) {cp
= 5; band
= 2;}
1415 else if (tuner_frequency
< 480000000) {cp
= 6; band
= 2;}
1416 else if (tuner_frequency
< 620000000) {cp
= 3; band
= 4;}
1417 else if (tuner_frequency
< 830000000) {cp
= 5; band
= 4;}
1418 else if (tuner_frequency
< 895000000) {cp
= 7; band
= 4;}
1419 else {return -EINVAL
;}
1421 // assume PLL filter should always be 8MHz for the moment.
1424 // calculate divisor
1425 // (Finput + Fif)/Fref; Fif = 36125000 Hz, Fref = 62500 Hz
1426 tuner_frequency
= ((params
->frequency
+ 36125000) / 62500);
1428 // setup tuner buffer
1429 tuner_buf
[0] = tuner_frequency
>> 8;
1430 tuner_buf
[1] = tuner_frequency
& 0xff;
1431 tuner_buf
[2] = 0xc8;
1432 tuner_buf
[3] = (cp
<< 5) | (filter
<< 3) | band
;
1433 tuner_buf
[4] = 0x80;
1435 if (fe
->ops
.i2c_gate_ctrl
)
1436 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1437 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) {
1438 printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 1\n");
1444 if (fe
->ops
.i2c_gate_ctrl
)
1445 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1446 if (i2c_transfer(&ttusb
->i2c_adap
, &tuner_msg
, 1) != 1) {
1447 printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 2\n");
1456 static u8 dvbc_philips_tdm1316l_inittab
[] = {
1558 static struct stv0297_config dvbc_philips_tdm1316l_config
= {
1559 .demod_address
= 0x1c,
1560 .inittab
= dvbc_philips_tdm1316l_inittab
,
1564 static void frontend_init(struct ttusb
* ttusb
)
1566 switch(le16_to_cpu(ttusb
->dev
->descriptor
.idProduct
)) {
1567 case 0x1003: // Hauppauge/TT Nova-USB-S budget (stv0299/ALPS BSRU6|BSBE1(tsa5059))
1568 // try the stv0299 based first
1569 ttusb
->fe
= dvb_attach(stv0299_attach
, &alps_stv0299_config
, &ttusb
->i2c_adap
);
1570 if (ttusb
->fe
!= NULL
) {
1571 ttusb
->fe
->ops
.tuner_ops
.set_params
= philips_tsa5059_tuner_set_params
;
1573 if(ttusb
->revision
== TTUSB_REV_2_2
) { // ALPS BSBE1
1574 alps_stv0299_config
.inittab
= alps_bsbe1_inittab
;
1575 dvb_attach(lnbp21_attach
, ttusb
->fe
, &ttusb
->i2c_adap
, 0, 0);
1576 } else { // ALPS BSRU6
1577 ttusb
->fe
->ops
.set_voltage
= ttusb_set_voltage
;
1582 // Grundig 29504-491
1583 ttusb
->fe
= dvb_attach(tda8083_attach
, &ttusb_novas_grundig_29504_491_config
, &ttusb
->i2c_adap
);
1584 if (ttusb
->fe
!= NULL
) {
1585 ttusb
->fe
->ops
.tuner_ops
.set_params
= ttusb_novas_grundig_29504_491_tuner_set_params
;
1586 ttusb
->fe
->ops
.set_voltage
= ttusb_set_voltage
;
1591 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
1592 ttusb
->fe
= dvb_attach(ves1820_attach
, &alps_tdbe2_config
, &ttusb
->i2c_adap
, read_pwm(ttusb
));
1593 if (ttusb
->fe
!= NULL
) {
1594 ttusb
->fe
->ops
.tuner_ops
.set_params
= alps_tdbe2_tuner_set_params
;
1598 ttusb
->fe
= dvb_attach(stv0297_attach
, &dvbc_philips_tdm1316l_config
, &ttusb
->i2c_adap
);
1599 if (ttusb
->fe
!= NULL
) {
1600 ttusb
->fe
->ops
.tuner_ops
.set_params
= dvbc_philips_tdm1316l_tuner_set_params
;
1605 case 0x1005: // Hauppauge/TT Nova-USB-t budget (tda10046/Philips td1316(tda6651tt) OR cx22700/ALPS TDMB7(??))
1606 // try the ALPS TDMB7 first
1607 ttusb
->fe
= dvb_attach(cx22700_attach
, &alps_tdmb7_config
, &ttusb
->i2c_adap
);
1608 if (ttusb
->fe
!= NULL
) {
1609 ttusb
->fe
->ops
.tuner_ops
.set_params
= alps_tdmb7_tuner_set_params
;
1614 ttusb
->fe
= dvb_attach(tda10046_attach
, &philips_tdm1316l_config
, &ttusb
->i2c_adap
);
1615 if (ttusb
->fe
!= NULL
) {
1616 ttusb
->fe
->ops
.tuner_ops
.init
= philips_tdm1316l_tuner_init
;
1617 ttusb
->fe
->ops
.tuner_ops
.set_params
= philips_tdm1316l_tuner_set_params
;
1623 if (ttusb
->fe
== NULL
) {
1624 printk("dvb-ttusb-budget: A frontend driver was not found for device [%04x:%04x]\n",
1625 le16_to_cpu(ttusb
->dev
->descriptor
.idVendor
),
1626 le16_to_cpu(ttusb
->dev
->descriptor
.idProduct
));
1628 if (dvb_register_frontend(&ttusb
->adapter
, ttusb
->fe
)) {
1629 printk("dvb-ttusb-budget: Frontend registration failed!\n");
1630 dvb_frontend_detach(ttusb
->fe
);
1638 static struct i2c_algorithm ttusb_dec_algo
= {
1639 .master_xfer
= master_xfer
,
1640 .functionality
= functionality
,
1643 static int ttusb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1645 struct usb_device
*udev
;
1646 struct ttusb
*ttusb
;
1649 dprintk("%s: TTUSB DVB connected\n", __func__
);
1651 udev
= interface_to_usbdev(intf
);
1653 if (intf
->altsetting
->desc
.bInterfaceNumber
!= 1) return -ENODEV
;
1655 if (!(ttusb
= kzalloc(sizeof(struct ttusb
), GFP_KERNEL
)))
1660 ttusb
->mux_state
= 0;
1661 mutex_init(&ttusb
->semi2c
);
1663 mutex_lock(&ttusb
->semi2c
);
1665 mutex_init(&ttusb
->semusb
);
1667 ttusb_setup_interfaces(ttusb
);
1669 result
= ttusb_alloc_iso_urbs(ttusb
);
1671 dprintk("%s: ttusb_alloc_iso_urbs - failed\n", __func__
);
1672 mutex_unlock(&ttusb
->semi2c
);
1677 if (ttusb_init_controller(ttusb
))
1678 printk("ttusb_init_controller: error\n");
1680 mutex_unlock(&ttusb
->semi2c
);
1682 result
= dvb_register_adapter(&ttusb
->adapter
,
1683 "Technotrend/Hauppauge Nova-USB",
1684 THIS_MODULE
, &udev
->dev
, adapter_nr
);
1686 ttusb_free_iso_urbs(ttusb
);
1690 ttusb
->adapter
.priv
= ttusb
;
1693 memset(&ttusb
->i2c_adap
, 0, sizeof(struct i2c_adapter
));
1694 strcpy(ttusb
->i2c_adap
.name
, "TTUSB DEC");
1696 i2c_set_adapdata(&ttusb
->i2c_adap
, ttusb
);
1698 ttusb
->i2c_adap
.algo
= &ttusb_dec_algo
;
1699 ttusb
->i2c_adap
.algo_data
= NULL
;
1700 ttusb
->i2c_adap
.dev
.parent
= &udev
->dev
;
1702 result
= i2c_add_adapter(&ttusb
->i2c_adap
);
1704 dvb_unregister_adapter (&ttusb
->adapter
);
1708 memset(&ttusb
->dvb_demux
, 0, sizeof(ttusb
->dvb_demux
));
1710 ttusb
->dvb_demux
.dmx
.capabilities
=
1711 DMX_TS_FILTERING
| DMX_SECTION_FILTERING
;
1712 ttusb
->dvb_demux
.priv
= NULL
;
1713 #ifdef TTUSB_HWSECTIONS
1714 ttusb
->dvb_demux
.filternum
= TTUSB_MAXFILTER
;
1716 ttusb
->dvb_demux
.filternum
= 32;
1718 ttusb
->dvb_demux
.feednum
= TTUSB_MAXCHANNEL
;
1719 ttusb
->dvb_demux
.start_feed
= ttusb_start_feed
;
1720 ttusb
->dvb_demux
.stop_feed
= ttusb_stop_feed
;
1721 ttusb
->dvb_demux
.write_to_decoder
= NULL
;
1723 if ((result
= dvb_dmx_init(&ttusb
->dvb_demux
)) < 0) {
1724 printk("ttusb_dvb: dvb_dmx_init failed (errno = %d)\n", result
);
1725 i2c_del_adapter(&ttusb
->i2c_adap
);
1726 dvb_unregister_adapter (&ttusb
->adapter
);
1729 //FIXME dmxdev (nur WAS?)
1730 ttusb
->dmxdev
.filternum
= ttusb
->dvb_demux
.filternum
;
1731 ttusb
->dmxdev
.demux
= &ttusb
->dvb_demux
.dmx
;
1732 ttusb
->dmxdev
.capabilities
= 0;
1734 if ((result
= dvb_dmxdev_init(&ttusb
->dmxdev
, &ttusb
->adapter
)) < 0) {
1735 printk("ttusb_dvb: dvb_dmxdev_init failed (errno = %d)\n",
1737 dvb_dmx_release(&ttusb
->dvb_demux
);
1738 i2c_del_adapter(&ttusb
->i2c_adap
);
1739 dvb_unregister_adapter (&ttusb
->adapter
);
1743 if (dvb_net_init(&ttusb
->adapter
, &ttusb
->dvbnet
, &ttusb
->dvb_demux
.dmx
)) {
1744 printk("ttusb_dvb: dvb_net_init failed!\n");
1745 dvb_dmxdev_release(&ttusb
->dmxdev
);
1746 dvb_dmx_release(&ttusb
->dvb_demux
);
1747 i2c_del_adapter(&ttusb
->i2c_adap
);
1748 dvb_unregister_adapter (&ttusb
->adapter
);
1752 usb_set_intfdata(intf
, (void *) ttusb
);
1754 frontend_init(ttusb
);
1759 static void ttusb_disconnect(struct usb_interface
*intf
)
1761 struct ttusb
*ttusb
= usb_get_intfdata(intf
);
1763 usb_set_intfdata(intf
, NULL
);
1765 ttusb
->disconnecting
= 1;
1767 ttusb_stop_iso_xfer(ttusb
);
1769 ttusb
->dvb_demux
.dmx
.close(&ttusb
->dvb_demux
.dmx
);
1770 dvb_net_release(&ttusb
->dvbnet
);
1771 dvb_dmxdev_release(&ttusb
->dmxdev
);
1772 dvb_dmx_release(&ttusb
->dvb_demux
);
1773 if (ttusb
->fe
!= NULL
) {
1774 dvb_unregister_frontend(ttusb
->fe
);
1775 dvb_frontend_detach(ttusb
->fe
);
1777 i2c_del_adapter(&ttusb
->i2c_adap
);
1778 dvb_unregister_adapter(&ttusb
->adapter
);
1780 ttusb_free_iso_urbs(ttusb
);
1784 dprintk("%s: TTUSB DVB disconnected\n", __func__
);
1787 static struct usb_device_id ttusb_table
[] = {
1788 {USB_DEVICE(0xb48, 0x1003)},
1789 {USB_DEVICE(0xb48, 0x1004)},
1790 {USB_DEVICE(0xb48, 0x1005)},
1794 MODULE_DEVICE_TABLE(usb
, ttusb_table
);
1796 static struct usb_driver ttusb_driver
= {
1798 .probe
= ttusb_probe
,
1799 .disconnect
= ttusb_disconnect
,
1800 .id_table
= ttusb_table
,
1803 static int __init
ttusb_init(void)
1807 if ((err
= usb_register(&ttusb_driver
)) < 0) {
1808 printk("%s: usb_register failed! Error number %d",
1816 static void __exit
ttusb_exit(void)
1818 usb_deregister(&ttusb_driver
);
1821 module_init(ttusb_init
);
1822 module_exit(ttusb_exit
);
1824 MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>");
1825 MODULE_DESCRIPTION("TTUSB DVB Driver");
1826 MODULE_LICENSE("GPL");
1827 MODULE_FIRMWARE("ttusb-budget/dspbootcode.bin");