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/moduleparam.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>
24 #include "dvb_frontend.h"
26 #include "dvb_demux.h"
36 #include <linux/dvb/frontend.h>
37 #include <linux/dvb/dmx.h>
38 #include <linux/pci.h>
42 the DSP supports filtering in hardware, however, since the "muxstream"
43 is a bit braindead (no matching channel masks or no matching filter mask),
44 we won't support this - yet. it doesn't event support negative filters,
45 so the best way is maybe to keep TTUSB_HWSECTIONS undef'd and just
46 parse TS data. USB bandwith will be a problem when having large
47 datastreams, especially for dvb-net, but hey, that's not my problem.
49 TTUSB_DISEQC, TTUSB_TONE:
50 let the STC do the diseqc/tone stuff. this isn't supported at least with
51 my TTUSB, so let it undef'd unless you want to implement another
52 frontend. never tested.
55 define it to > 3 for really hardcore debugging. you probably don't want
56 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 #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.) */
130 devfs_handle_t stc_devfs_handle;
133 struct dvb_frontend* fe;
136 /* ugly workaround ... don't know why it's neccessary to read */
137 /* all result codes. */
140 static int ttusb_cmd(struct ttusb *ttusb,
141 const u8 * data, int len, int needresult)
149 for (i = 0; i < len; ++i)
150 printk(" %02x", data[i]);
154 if (mutex_lock_interruptible(&ttusb->semusb) < 0)
157 err = usb_bulk_msg(ttusb->dev, ttusb->bulk_out_pipe,
158 (u8 *) data, len, &actual_len, 1000);
160 dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n",
162 mutex_unlock(&ttusb->semusb);
165 if (actual_len != len) {
166 dprintk("%s: only wrote %d of %d bytes\n", __FUNCTION__,
168 mutex_unlock(&ttusb->semusb);
172 err = usb_bulk_msg(ttusb->dev, ttusb->bulk_in_pipe,
173 ttusb->last_result, 32, &actual_len, 1000);
176 printk("%s: failed, receive error %d\n", __FUNCTION__,
178 mutex_unlock(&ttusb->semusb);
182 actual_len = ttusb->last_result[3] + 4;
184 for (i = 0; i < actual_len; ++i)
185 printk(" %02x", ttusb->last_result[i]);
189 mutex_unlock(&ttusb->semusb);
193 static int ttusb_result(struct ttusb *ttusb, u8 * data, int len)
195 memcpy(data, ttusb->last_result, len);
196 mutex_unlock(&ttusb->semusb);
200 static int ttusb_i2c_msg(struct ttusb *ttusb,
201 u8 addr, u8 * snd_buf, u8 snd_len, u8 * rcv_buf,
208 if (snd_len > 0x28 - 7 || rcv_len > 0x20 - 7)
219 for (i = 0; i < snd_len; i++)
220 b[7 + i] = snd_buf[i];
222 err = ttusb_cmd(ttusb, b, snd_len + 7, 1);
227 err = ttusb_result(ttusb, b, 0x20);
229 /* check if the i2c transaction was successful */
230 if ((snd_len != b[5]) || (rcv_len != b[6])) return -EREMOTEIO;
234 if (err || b[0] != 0x55 || b[1] != id) {
236 ("%s: usb_bulk_msg(recv) failed, err == %i, id == %02x, b == ",
237 __FUNCTION__, err, id);
241 for (i = 0; i < rcv_len; i++)
242 rcv_buf[i] = b[7 + i];
248 static int master_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num)
250 struct ttusb *ttusb = i2c_get_adapdata(adapter);
254 if (mutex_lock_interruptible(&ttusb->semi2c) < 0)
258 u8 addr, snd_len, rcv_len, *snd_buf, *rcv_buf;
261 if (num > i + 1 && (msg[i + 1].flags & I2C_M_RD)) {
263 snd_buf = msg[i].buf;
264 snd_len = msg[i].len;
265 rcv_buf = msg[i + 1].buf;
266 rcv_len = msg[i + 1].len;
270 snd_buf = msg[i].buf;
271 snd_len = msg[i].len;
277 err = ttusb_i2c_msg(ttusb, addr,
278 snd_buf, snd_len, rcv_buf, rcv_len);
281 dprintk("%s: i == %i\n", __FUNCTION__, i);
288 mutex_unlock(&ttusb->semi2c);
292 #include "dvb-ttusb-dspbootcode.h"
294 static int ttusb_boot_dsp(struct ttusb *ttusb)
304 /* upload dsp code in 32 byte steps (36 didn't work for me ...) */
305 /* 32 is max packet size, no messages should be splitted. */
306 for (i = 0; i < sizeof(dsp_bootcode); i += 28) {
307 memcpy(&b[4], &dsp_bootcode[i], 28);
311 err = ttusb_cmd(ttusb, b, 32, 0);
321 err = ttusb_cmd(ttusb, b, 4, 0);
330 err = ttusb_cmd(ttusb, b, 4, 0);
334 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
341 static int ttusb_set_channel(struct ttusb *ttusb, int chan_id, int filter_type,
346 u8 b[] = { 0xaa, ++ttusb->c, 0x22, 4, chan_id, filter_type,
347 (pid >> 8) & 0xff, pid & 0xff
350 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
354 static int ttusb_del_channel(struct ttusb *ttusb, int channel_id)
358 u8 b[] = { 0xaa, ++ttusb->c, 0x23, 1, channel_id };
360 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
364 #ifdef TTUSB_HWSECTIONS
365 static int ttusb_set_filter(struct ttusb *ttusb, int filter_id,
366 int associated_chan, u8 filter[8], u8 mask[8])
370 u8 b[] = { 0xaa, 0, 0x24, 0x1a, filter_id, associated_chan,
371 filter[0], filter[1], filter[2], filter[3],
372 filter[4], filter[5], filter[6], filter[7],
373 filter[8], filter[9], filter[10], filter[11],
374 mask[0], mask[1], mask[2], mask[3],
375 mask[4], mask[5], mask[6], mask[7],
376 mask[8], mask[9], mask[10], mask[11]
379 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
383 static int ttusb_del_filter(struct ttusb *ttusb, int filter_id)
387 u8 b[] = { 0xaa, ++ttusb->c, 0x25, 1, filter_id };
389 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
394 static int ttusb_init_controller(struct ttusb *ttusb)
396 u8 b0[] = { 0xaa, ++ttusb->c, 0x15, 1, 0 };
397 u8 b1[] = { 0xaa, ++ttusb->c, 0x15, 1, 1 };
398 u8 b2[] = { 0xaa, ++ttusb->c, 0x32, 1, 0 };
399 /* i2c write read: 5 bytes, addr 0x10, 0x02 bytes write, 1 bytes read. */
401 { 0xaa, ++ttusb->c, 0x31, 5, 0x10, 0x02, 0x01, 0x00, 0x1e };
403 { 0x55, ttusb->c, 0x31, 4, 0x10, 0x02, 0x01, 0x00, 0x1e };
405 u8 get_version[] = { 0xaa, ++ttusb->c, 0x17, 5, 0, 0, 0, 0, 0 };
406 u8 get_dsp_version[0x20] =
407 { 0xaa, ++ttusb->c, 0x26, 28, 0, 0, 0, 0, 0 };
411 if ((err = ttusb_cmd(ttusb, b0, sizeof(b0), 0)))
414 /* reset board (again?) */
415 if ((err = ttusb_cmd(ttusb, b1, sizeof(b1), 0)))
418 ttusb_boot_dsp(ttusb);
420 /* set i2c bit rate */
421 if ((err = ttusb_cmd(ttusb, b2, sizeof(b2), 0)))
424 if ((err = ttusb_cmd(ttusb, b3, sizeof(b3), 1)))
427 err = ttusb_result(ttusb, b4, sizeof(b4));
429 if ((err = ttusb_cmd(ttusb, get_version, sizeof(get_version), 1)))
432 if ((err = ttusb_result(ttusb, get_version, sizeof(get_version))))
435 dprintk("%s: stc-version: %c%c%c%c%c\n", __FUNCTION__,
436 get_version[4], get_version[5], get_version[6],
437 get_version[7], get_version[8]);
439 if (memcmp(get_version + 4, "V 0.0", 5) &&
440 memcmp(get_version + 4, "V 1.1", 5) &&
441 memcmp(get_version + 4, "V 2.1", 5) &&
442 memcmp(get_version + 4, "V 2.2", 5)) {
444 ("%s: unknown STC version %c%c%c%c%c, please report!\n",
445 __FUNCTION__, get_version[4], get_version[5],
446 get_version[6], get_version[7], get_version[8]);
449 ttusb->revision = ((get_version[6] - '0') << 4) |
450 (get_version[8] - '0');
453 ttusb_cmd(ttusb, get_dsp_version, sizeof(get_dsp_version), 1);
458 ttusb_result(ttusb, get_dsp_version, sizeof(get_dsp_version));
461 printk("%s: dsp-version: %c%c%c\n", __FUNCTION__,
462 get_dsp_version[4], get_dsp_version[5], get_dsp_version[6]);
467 static int ttusb_send_diseqc(struct dvb_frontend* fe,
468 const struct dvb_diseqc_master_cmd *cmd)
470 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
471 u8 b[12] = { 0xaa, ++ttusb->c, 0x18 };
475 b[3] = 4 + 2 + cmd->msg_len;
476 b[4] = 0xFF; /* send diseqc master, not burst */
479 memcpy(b + 5, cmd->msg, cmd->msg_len);
482 if ((err = ttusb_cmd(ttusb, b, 4 + b[3], 0))) {
483 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
491 static int ttusb_update_lnb(struct ttusb *ttusb)
493 u8 b[] = { 0xaa, ++ttusb->c, 0x16, 5, /*power: */ 1,
494 ttusb->voltage == SEC_VOLTAGE_18 ? 0 : 1,
495 ttusb->tone == SEC_TONE_ON ? 1 : 0, 1, 1
500 if ((err = ttusb_cmd(ttusb, b, sizeof(b), 0))) {
501 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
508 static int ttusb_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
510 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
512 ttusb->voltage = voltage;
513 return ttusb_update_lnb(ttusb);
517 static int ttusb_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
519 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
522 return ttusb_update_lnb(ttusb);
528 static void ttusb_set_led_freq(struct ttusb *ttusb, u8 freq)
530 u8 b[] = { 0xaa, ++ttusb->c, 0x19, 1, freq };
533 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
535 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
541 /*****************************************************************************/
543 #ifdef TTUSB_HWSECTIONS
544 static void ttusb_handle_ts_data(struct ttusb_channel *channel,
545 const u8 * data, int len);
546 static void ttusb_handle_sec_data(struct ttusb_channel *channel,
547 const u8 * data, int len);
550 static int numpkt = 0, numts, numstuff, numsec, numinvalid;
551 static unsigned long lastj;
553 static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
558 for (i = 0; i < len; i += 2)
559 csum ^= le16_to_cpup((u16 *) (muxpack + i));
561 printk("%s: muxpack with incorrect checksum, ignoring\n",
567 cc = (muxpack[len - 4] << 8) | muxpack[len - 3];
569 if ((cc != ttusb->cc) && (ttusb->cc != -1))
570 printk("%s: cc discontinuity (%d frames missing)\n",
571 __FUNCTION__, (cc - ttusb->cc) & 0x7FFF);
572 ttusb->cc = (cc + 1) & 0x7FFF;
573 if (muxpack[0] & 0x80) {
574 #ifdef TTUSB_HWSECTIONS
576 int pusi = muxpack[0] & 0x40;
577 int channel = muxpack[0] & 0x1F;
578 int payload = muxpack[1];
579 const u8 *data = muxpack + 2;
580 /* check offset flag */
581 if (muxpack[0] & 0x20)
584 ttusb_handle_sec_data(ttusb->channel + channel, data,
588 if ((!!(ttusb->muxpack[0] & 0x20)) ^
589 !!(ttusb->muxpack[1] & 1))
592 printk("cc: %04x\n", (data[0] << 8) | data[1]);
595 } else if (muxpack[0] == 0x47) {
596 #ifdef TTUSB_HWSECTIONS
597 /* we have TS data here! */
598 int pid = ((muxpack[1] & 0x0F) << 8) | muxpack[2];
600 for (channel = 0; channel < TTUSB_MAXCHANNEL; ++channel)
601 if (ttusb->channel[channel].active
602 && (pid == ttusb->channel[channel].pid))
603 ttusb_handle_ts_data(ttusb->channel +
608 dvb_dmx_swfilter_packets(&ttusb->dvb_demux, muxpack, 1);
609 } else if (muxpack[0] != 0) {
611 printk("illegal muxpack type %02x\n", muxpack[0]);
616 static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)
621 printk("%s: too much work\n", __FUNCTION__);
625 switch (ttusb->mux_state) {
633 ttusb->mux_state = 0;
636 printk("%02x ", data[-1]);
639 printk("%s: lost sync.\n",
649 ttusb->mux_npacks = *data++;
651 ttusb->muxpack_ptr = 0;
652 /* maximum bytes, until we know the length */
653 ttusb->muxpack_len = 2;
660 (ttusb->muxpack_len -
665 memcpy(ttusb->muxpack + ttusb->muxpack_ptr,
667 ttusb->muxpack_ptr += avail;
668 BUG_ON(ttusb->muxpack_ptr > 264);
671 /* determine length */
672 if (ttusb->muxpack_ptr == 2) {
673 if (ttusb->muxpack[0] & 0x80) {
675 ttusb->muxpack[1] + 2;
682 muxpack[0] & 0x20)) ^
687 ttusb->muxpack_len += 4;
688 } else if (ttusb->muxpack[0] ==
692 else if (ttusb->muxpack[0] == 0x00)
694 ttusb->muxpack[1] + 2 +
698 ("%s: invalid state: first byte is %x\n",
701 ttusb->mux_state = 0;
706 * if length is valid and we reached the end:
709 if ((ttusb->muxpack_ptr >= 2) &&
710 (ttusb->muxpack_ptr ==
711 ttusb->muxpack_len)) {
712 ttusb_process_muxpack(ttusb,
717 ttusb->muxpack_ptr = 0;
718 /* maximum bytes, until we know the length */
719 ttusb->muxpack_len = 2;
723 * return to search-sync state
725 if (!ttusb->mux_npacks--) {
726 ttusb->mux_state = 0;
739 static void ttusb_iso_irq(struct urb *urb, struct pt_regs *ptregs)
741 struct ttusb *ttusb = urb->context;
743 if (!ttusb->iso_streaming)
747 printk("%s: status %d, errcount == %d, length == %i\n",
749 urb->status, urb->error_count, urb->actual_length);
754 for (i = 0; i < urb->number_of_packets; ++i) {
755 struct usb_iso_packet_descriptor *d;
759 if (time_after_eq(jiffies, lastj + HZ)) {
762 ("frames/s: %d (ts: %d, stuff %d, sec: %d, invalid: %d, all: %d)\n",
763 numpkt * HZ / (jiffies - lastj),
764 numts, numstuff, numsec, numinvalid,
765 numts + numstuff + numsec +
768 numts = numstuff = numsec = numinvalid = 0;
772 d = &urb->iso_frame_desc[i];
773 data = urb->transfer_buffer + d->offset;
774 len = d->actual_length;
775 d->actual_length = 0;
777 ttusb_process_frame(ttusb, data, len);
780 usb_submit_urb(urb, GFP_ATOMIC);
783 static void ttusb_free_iso_urbs(struct ttusb *ttusb)
787 for (i = 0; i < ISO_BUF_COUNT; i++)
788 if (ttusb->iso_urb[i])
789 usb_free_urb(ttusb->iso_urb[i]);
791 pci_free_consistent(NULL,
792 ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF *
793 ISO_BUF_COUNT, ttusb->iso_buffer,
794 ttusb->iso_dma_handle);
797 static int ttusb_alloc_iso_urbs(struct ttusb *ttusb)
801 ttusb->iso_buffer = pci_alloc_consistent(NULL,
805 &ttusb->iso_dma_handle);
807 memset(ttusb->iso_buffer, 0,
808 ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF * ISO_BUF_COUNT);
810 for (i = 0; i < ISO_BUF_COUNT; i++) {
815 usb_alloc_urb(FRAMES_PER_ISO_BUF, GFP_ATOMIC))) {
816 ttusb_free_iso_urbs(ttusb);
820 ttusb->iso_urb[i] = urb;
826 static void ttusb_stop_iso_xfer(struct ttusb *ttusb)
830 for (i = 0; i < ISO_BUF_COUNT; i++)
831 usb_kill_urb(ttusb->iso_urb[i]);
833 ttusb->iso_streaming = 0;
836 static int ttusb_start_iso_xfer(struct ttusb *ttusb)
838 int i, j, err, buffer_offset = 0;
840 if (ttusb->iso_streaming) {
841 printk("%s: iso xfer already running!\n", __FUNCTION__);
847 ttusb->mux_state = 0;
849 for (i = 0; i < ISO_BUF_COUNT; i++) {
850 int frame_offset = 0;
851 struct urb *urb = ttusb->iso_urb[i];
853 urb->dev = ttusb->dev;
854 urb->context = ttusb;
855 urb->complete = ttusb_iso_irq;
856 urb->pipe = ttusb->isoc_in_pipe;
857 urb->transfer_flags = URB_ISO_ASAP;
859 urb->number_of_packets = FRAMES_PER_ISO_BUF;
860 urb->transfer_buffer_length =
861 ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF;
862 urb->transfer_buffer = ttusb->iso_buffer + buffer_offset;
863 buffer_offset += ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF;
865 for (j = 0; j < FRAMES_PER_ISO_BUF; j++) {
866 urb->iso_frame_desc[j].offset = frame_offset;
867 urb->iso_frame_desc[j].length = ISO_FRAME_SIZE;
868 frame_offset += ISO_FRAME_SIZE;
872 for (i = 0; i < ISO_BUF_COUNT; i++) {
873 if ((err = usb_submit_urb(ttusb->iso_urb[i], GFP_ATOMIC))) {
874 ttusb_stop_iso_xfer(ttusb);
876 ("%s: failed urb submission (%i: err = %i)!\n",
877 __FUNCTION__, i, err);
882 ttusb->iso_streaming = 1;
887 #ifdef TTUSB_HWSECTIONS
888 static void ttusb_handle_ts_data(struct dvb_demux_feed *dvbdmxfeed, const u8 * data,
891 dvbdmxfeed->cb.ts(data, len, 0, 0, &dvbdmxfeed->feed.ts, 0);
894 static void ttusb_handle_sec_data(struct dvb_demux_feed *dvbdmxfeed, const u8 * data,
897 // struct dvb_demux_feed *dvbdmxfeed = channel->dvbdmxfeed;
898 #error TODO: handle ugly stuff
899 // dvbdmxfeed->cb.sec(data, len, 0, 0, &dvbdmxfeed->feed.sec, 0);
903 static int ttusb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
905 struct ttusb *ttusb = (struct ttusb *) dvbdmxfeed->demux;
908 dprintk("ttusb_start_feed\n");
910 switch (dvbdmxfeed->type) {
919 if (dvbdmxfeed->type == DMX_TYPE_TS) {
920 switch (dvbdmxfeed->pes_type) {
921 case DMX_TS_PES_VIDEO:
922 case DMX_TS_PES_AUDIO:
923 case DMX_TS_PES_TELETEXT:
925 case DMX_TS_PES_OTHER:
932 #ifdef TTUSB_HWSECTIONS
933 #error TODO: allocate filters
934 if (dvbdmxfeed->type == DMX_TYPE_TS) {
936 } else if (dvbdmxfeed->type == DMX_TYPE_SEC) {
941 ttusb_set_channel(ttusb, dvbdmxfeed->index, feed_type, dvbdmxfeed->pid);
943 if (0 == ttusb->running_feed_count++)
944 ttusb_start_iso_xfer(ttusb);
949 static int ttusb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
951 struct ttusb *ttusb = (struct ttusb *) dvbdmxfeed->demux;
953 ttusb_del_channel(ttusb, dvbdmxfeed->index);
955 if (--ttusb->running_feed_count == 0)
956 ttusb_stop_iso_xfer(ttusb);
961 static int ttusb_setup_interfaces(struct ttusb *ttusb)
963 usb_set_interface(ttusb->dev, 1, 1);
965 ttusb->bulk_out_pipe = usb_sndbulkpipe(ttusb->dev, 1);
966 ttusb->bulk_in_pipe = usb_rcvbulkpipe(ttusb->dev, 1);
967 ttusb->isoc_in_pipe = usb_rcvisocpipe(ttusb->dev, 2);
973 static u8 stc_firmware[8192];
975 static int stc_open(struct inode *inode, struct file *file)
977 struct ttusb *ttusb = file->private_data;
980 for (addr = 0; addr < 8192; addr += 16) {
981 u8 snd_buf[2] = { addr >> 8, addr & 0xFF };
982 ttusb_i2c_msg(ttusb, 0x50, snd_buf, 2, stc_firmware + addr,
989 static ssize_t stc_read(struct file *file, char *buf, size_t count,
994 if ((tc + *offset) > 8192)
1000 if (copy_to_user(buf, stc_firmware + *offset, tc))
1008 static int stc_release(struct inode *inode, struct file *file)
1013 static struct file_operations stc_fops = {
1014 .owner = THIS_MODULE,
1017 .release = stc_release,
1021 static u32 functionality(struct i2c_adapter *adapter)
1023 return I2C_FUNC_I2C;
1028 static int alps_tdmb7_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
1030 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1032 struct i2c_msg msg = {.addr=0x61, .flags=0, .buf=data, .len=sizeof(data) };
1035 div = (params->frequency + 36166667) / 166667;
1037 data[0] = (div >> 8) & 0x7f;
1038 data[1] = div & 0xff;
1039 data[2] = ((div >> 10) & 0x60) | 0x85;
1040 data[3] = params->frequency < 592000000 ? 0x40 : 0x80;
1042 if (fe->ops.i2c_gate_ctrl)
1043 fe->ops.i2c_gate_ctrl(fe, 1);
1044 if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1) return -EIO;
1048 static struct cx22700_config alps_tdmb7_config = {
1049 .demod_address = 0x43,
1056 static int philips_tdm1316l_tuner_init(struct dvb_frontend* fe)
1058 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1059 static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
1060 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
1061 struct i2c_msg tuner_msg = { .addr=0x60, .flags=0, .buf=td1316_init, .len=sizeof(td1316_init) };
1063 // setup PLL configuration
1064 if (fe->ops.i2c_gate_ctrl)
1065 fe->ops.i2c_gate_ctrl(fe, 1);
1066 if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) return -EIO;
1069 // disable the mc44BC374c (do not check for errors)
1070 tuner_msg.addr = 0x65;
1071 tuner_msg.buf = disable_mc44BC374c;
1072 tuner_msg.len = sizeof(disable_mc44BC374c);
1073 if (fe->ops.i2c_gate_ctrl)
1074 fe->ops.i2c_gate_ctrl(fe, 1);
1075 if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {
1076 i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1);
1082 static int philips_tdm1316l_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
1084 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1086 struct i2c_msg tuner_msg = {.addr=0x60, .flags=0, .buf=tuner_buf, .len=sizeof(tuner_buf) };
1087 int tuner_frequency = 0;
1088 u8 band, cp, filter;
1090 // determine charge pump
1091 tuner_frequency = params->frequency + 36130000;
1092 if (tuner_frequency < 87000000) return -EINVAL;
1093 else if (tuner_frequency < 130000000) cp = 3;
1094 else if (tuner_frequency < 160000000) cp = 5;
1095 else if (tuner_frequency < 200000000) cp = 6;
1096 else if (tuner_frequency < 290000000) cp = 3;
1097 else if (tuner_frequency < 420000000) cp = 5;
1098 else if (tuner_frequency < 480000000) cp = 6;
1099 else if (tuner_frequency < 620000000) cp = 3;
1100 else if (tuner_frequency < 830000000) cp = 5;
1101 else if (tuner_frequency < 895000000) cp = 7;
1102 else return -EINVAL;
1105 if (params->frequency < 49000000) return -EINVAL;
1106 else if (params->frequency < 159000000) band = 1;
1107 else if (params->frequency < 444000000) band = 2;
1108 else if (params->frequency < 861000000) band = 4;
1109 else return -EINVAL;
1112 switch (params->u.ofdm.bandwidth) {
1113 case BANDWIDTH_6_MHZ:
1114 tda1004x_write_byte(fe, 0x0C, 0);
1118 case BANDWIDTH_7_MHZ:
1119 tda1004x_write_byte(fe, 0x0C, 0);
1123 case BANDWIDTH_8_MHZ:
1124 tda1004x_write_byte(fe, 0x0C, 0xFF);
1132 // calculate divisor
1133 // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
1134 tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;
1136 // setup tuner buffer
1137 tuner_buf[0] = tuner_frequency >> 8;
1138 tuner_buf[1] = tuner_frequency & 0xff;
1139 tuner_buf[2] = 0xca;
1140 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
1142 if (fe->ops.i2c_gate_ctrl)
1143 fe->ops.i2c_gate_ctrl(fe, 1);
1144 if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1)
1151 static int philips_tdm1316l_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
1153 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1155 return request_firmware(fw, name, &ttusb->dev->dev);
1158 static struct tda1004x_config philips_tdm1316l_config = {
1160 .demod_address = 0x8,
1163 .request_firmware = philips_tdm1316l_request_firmware,
1166 static u8 alps_bsbe1_inittab[] = {
1170 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1171 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1172 0x06, 0x40, /* DAC not used, set to high impendance mode */
1173 0x07, 0x00, /* DAC LSB */
1174 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1175 0x09, 0x00, /* FIFO */
1176 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1177 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1178 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1179 0x10, 0x3f, // AGC2 0x3d
1182 0x15, 0xc9, // lock detector threshold
1193 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1194 0x29, 0x1e, // 1/2 threshold
1195 0x2a, 0x14, // 2/3 threshold
1196 0x2b, 0x0f, // 3/4 threshold
1197 0x2c, 0x09, // 5/6 threshold
1198 0x2d, 0x05, // 7/8 threshold
1200 0x31, 0x1f, // test all FECs
1201 0x32, 0x19, // viterbi and synchro search
1202 0x33, 0xfc, // rs control
1203 0x34, 0x93, // error control
1208 static u8 alps_bsru6_inittab[] = {
1212 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
1213 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
1214 0x06, 0x40, /* DAC not used, set to high impendance mode */
1215 0x07, 0x00, /* DAC LSB */
1216 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
1217 0x09, 0x00, /* FIFO */
1218 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
1219 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
1220 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
1221 0x10, 0x3f, // AGC2 0x3d
1224 0x15, 0xc9, // lock detector threshold
1235 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
1236 0x29, 0x1e, // 1/2 threshold
1237 0x2a, 0x14, // 2/3 threshold
1238 0x2b, 0x0f, // 3/4 threshold
1239 0x2c, 0x09, // 5/6 threshold
1240 0x2d, 0x05, // 7/8 threshold
1242 0x31, 0x1f, // test all FECs
1243 0x32, 0x19, // viterbi and synchro search
1244 0x33, 0xfc, // rs control
1245 0x34, 0x93, // error control
1250 static int alps_stv0299_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
1255 if (srate < 1500000) {
1258 } else if (srate < 3000000) {
1261 } else if (srate < 7000000) {
1264 } else if (srate < 14000000) {
1267 } else if (srate < 30000000) {
1270 } else if (srate < 45000000) {
1275 stv0299_writereg(fe, 0x13, aclk);
1276 stv0299_writereg(fe, 0x14, bclk);
1277 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
1278 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
1279 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
1284 static int philips_tsa5059_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
1286 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1289 struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };
1291 if ((params->frequency < 950000) || (params->frequency > 2150000))
1294 div = (params->frequency + (125 - 1)) / 125; // round correctly
1295 buf[0] = (div >> 8) & 0x7f;
1296 buf[1] = div & 0xff;
1297 buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
1300 if (params->frequency > 1530000)
1303 /* BSBE1 wants XCE bit set */
1304 if (ttusb->revision == TTUSB_REV_2_2)
1307 if (fe->ops.i2c_gate_ctrl)
1308 fe->ops.i2c_gate_ctrl(fe, 1);
1309 if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1)
1315 static struct stv0299_config alps_stv0299_config = {
1316 .demod_address = 0x68,
1317 .inittab = alps_bsru6_inittab,
1321 .lock_output = STV0229_LOCKOUTPUT_1,
1322 .volt13_op0_op1 = STV0299_VOLT13_OP1,
1323 .min_delay_ms = 100,
1324 .set_symbol_rate = alps_stv0299_set_symbol_rate,
1327 static int ttusb_novas_grundig_29504_491_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
1329 struct ttusb* ttusb = (struct ttusb*) fe->dvb->priv;
1332 struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };
1334 div = params->frequency / 125;
1336 buf[0] = (div >> 8) & 0x7f;
1337 buf[1] = div & 0xff;
1341 if (fe->ops.i2c_gate_ctrl)
1342 fe->ops.i2c_gate_ctrl(fe, 1);
1343 if (i2c_transfer(&ttusb->i2c_adap, &msg, 1) != 1)
1349 static struct tda8083_config ttusb_novas_grundig_29504_491_config = {
1351 .demod_address = 0x68,
1354 static int alps_tdbe2_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
1356 struct ttusb* ttusb = fe->dvb->priv;
1359 struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };
1361 div = (params->frequency + 35937500 + 31250) / 62500;
1363 data[0] = (div >> 8) & 0x7f;
1364 data[1] = div & 0xff;
1365 data[2] = 0x85 | ((div >> 10) & 0x60);
1366 data[3] = (params->frequency < 174000000 ? 0x88 : params->frequency < 470000000 ? 0x84 : 0x81);
1368 if (fe->ops.i2c_gate_ctrl)
1369 fe->ops.i2c_gate_ctrl(fe, 1);
1370 if (i2c_transfer (&ttusb->i2c_adap, &msg, 1) != 1)
1377 static struct ves1820_config alps_tdbe2_config = {
1378 .demod_address = 0x09,
1381 .selagc = VES1820_SELAGC_SIGNAMPERR,
1384 static u8 read_pwm(struct ttusb* ttusb)
1388 struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
1389 { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
1391 if ((i2c_transfer(&ttusb->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
1398 static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
1400 struct ttusb *ttusb = (struct ttusb *) fe->dvb->priv;
1402 struct i2c_msg tuner_msg = {.addr = 0x60,
1405 .len = sizeof(tuner_buf) };
1406 int tuner_frequency = 0;
1407 u8 band, cp, filter;
1409 // determine charge pump
1410 tuner_frequency = params->frequency;
1411 if (tuner_frequency < 87000000) {return -EINVAL;}
1412 else if (tuner_frequency < 130000000) {cp = 3; band = 1;}
1413 else if (tuner_frequency < 160000000) {cp = 5; band = 1;}
1414 else if (tuner_frequency < 200000000) {cp = 6; band = 1;}
1415 else if (tuner_frequency < 290000000) {cp = 3; band = 2;}
1416 else if (tuner_frequency < 420000000) {cp = 5; band = 2;}
1417 else if (tuner_frequency < 480000000) {cp = 6; band = 2;}
1418 else if (tuner_frequency < 620000000) {cp = 3; band = 4;}
1419 else if (tuner_frequency < 830000000) {cp = 5; band = 4;}
1420 else if (tuner_frequency < 895000000) {cp = 7; band = 4;}
1421 else {return -EINVAL;}
1423 // assume PLL filter should always be 8MHz for the moment.
1426 // calculate divisor
1427 // (Finput + Fif)/Fref; Fif = 36125000 Hz, Fref = 62500 Hz
1428 tuner_frequency = ((params->frequency + 36125000) / 62500);
1430 // setup tuner buffer
1431 tuner_buf[0] = tuner_frequency >> 8;
1432 tuner_buf[1] = tuner_frequency & 0xff;
1433 tuner_buf[2] = 0xc8;
1434 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
1435 tuner_buf[4] = 0x80;
1437 if (fe->ops.i2c_gate_ctrl)
1438 fe->ops.i2c_gate_ctrl(fe, 1);
1439 if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {
1440 printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 1\n");
1446 if (fe->ops.i2c_gate_ctrl)
1447 fe->ops.i2c_gate_ctrl(fe, 1);
1448 if (i2c_transfer(&ttusb->i2c_adap, &tuner_msg, 1) != 1) {
1449 printk("dvb-ttusb-budget: dvbc_philips_tdm1316l_pll_set Error 2\n");
1458 static u8 dvbc_philips_tdm1316l_inittab[] = {
1560 static struct stv0297_config dvbc_philips_tdm1316l_config = {
1561 .demod_address = 0x1c,
1562 .inittab = dvbc_philips_tdm1316l_inittab,
1566 static void frontend_init(struct ttusb* ttusb)
1568 switch(le16_to_cpu(ttusb->dev->descriptor.idProduct)) {
1569 case 0x1003: // Hauppauge/TT Nova-USB-S budget (stv0299/ALPS BSRU6|BSBE1(tsa5059))
1570 // try the stv0299 based first
1571 ttusb->fe = stv0299_attach(&alps_stv0299_config, &ttusb->i2c_adap);
1572 if (ttusb->fe != NULL) {
1573 ttusb->fe->ops.tuner_ops.set_params = philips_tsa5059_tuner_set_params;
1575 if(ttusb->revision == TTUSB_REV_2_2) { // ALPS BSBE1
1576 alps_stv0299_config.inittab = alps_bsbe1_inittab;
1577 lnbp21_attach(ttusb->fe, &ttusb->i2c_adap, 0, 0);
1578 } else { // ALPS BSRU6
1579 ttusb->fe->ops.set_voltage = ttusb_set_voltage;
1584 // Grundig 29504-491
1585 ttusb->fe = tda8083_attach(&ttusb_novas_grundig_29504_491_config, &ttusb->i2c_adap);
1586 if (ttusb->fe != NULL) {
1587 ttusb->fe->ops.tuner_ops.set_params = ttusb_novas_grundig_29504_491_tuner_set_params;
1588 ttusb->fe->ops.set_voltage = ttusb_set_voltage;
1593 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
1594 ttusb->fe = ves1820_attach(&alps_tdbe2_config, &ttusb->i2c_adap, read_pwm(ttusb));
1595 if (ttusb->fe != NULL) {
1596 ttusb->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
1600 ttusb->fe = stv0297_attach(&dvbc_philips_tdm1316l_config, &ttusb->i2c_adap);
1601 if (ttusb->fe != NULL) {
1602 ttusb->fe->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
1607 case 0x1005: // Hauppauge/TT Nova-USB-t budget (tda10046/Philips td1316(tda6651tt) OR cx22700/ALPS TDMB7(??))
1608 // try the ALPS TDMB7 first
1609 ttusb->fe = cx22700_attach(&alps_tdmb7_config, &ttusb->i2c_adap);
1610 if (ttusb->fe != NULL) {
1611 ttusb->fe->ops.tuner_ops.set_params = alps_tdmb7_tuner_set_params;
1616 ttusb->fe = tda10046_attach(&philips_tdm1316l_config, &ttusb->i2c_adap);
1617 if (ttusb->fe != NULL) {
1618 ttusb->fe->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1619 ttusb->fe->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1625 if (ttusb->fe == NULL) {
1626 printk("dvb-ttusb-budget: A frontend driver was not found for device %04x/%04x\n",
1627 le16_to_cpu(ttusb->dev->descriptor.idVendor),
1628 le16_to_cpu(ttusb->dev->descriptor.idProduct));
1630 if (dvb_register_frontend(&ttusb->adapter, ttusb->fe)) {
1631 printk("dvb-ttusb-budget: Frontend registration failed!\n");
1632 if (ttusb->fe->ops.release)
1633 ttusb->fe->ops.release(ttusb->fe);
1641 static struct i2c_algorithm ttusb_dec_algo = {
1642 .master_xfer = master_xfer,
1643 .functionality = functionality,
1646 static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1648 struct usb_device *udev;
1649 struct ttusb *ttusb;
1652 dprintk("%s: TTUSB DVB connected\n", __FUNCTION__);
1654 udev = interface_to_usbdev(intf);
1656 if (intf->altsetting->desc.bInterfaceNumber != 1) return -ENODEV;
1658 if (!(ttusb = kzalloc(sizeof(struct ttusb), GFP_KERNEL)))
1663 ttusb->mux_state = 0;
1664 mutex_init(&ttusb->semi2c);
1666 mutex_lock(&ttusb->semi2c);
1668 mutex_init(&ttusb->semusb);
1670 ttusb_setup_interfaces(ttusb);
1672 ttusb_alloc_iso_urbs(ttusb);
1673 if (ttusb_init_controller(ttusb))
1674 printk("ttusb_init_controller: error\n");
1676 mutex_unlock(&ttusb->semi2c);
1678 if ((result = dvb_register_adapter(&ttusb->adapter, "Technotrend/Hauppauge Nova-USB", THIS_MODULE, &udev->dev)) < 0) {
1679 ttusb_free_iso_urbs(ttusb);
1683 ttusb->adapter.priv = ttusb;
1686 memset(&ttusb->i2c_adap, 0, sizeof(struct i2c_adapter));
1687 strcpy(ttusb->i2c_adap.name, "TTUSB DEC");
1689 i2c_set_adapdata(&ttusb->i2c_adap, ttusb);
1691 #ifdef I2C_ADAP_CLASS_TV_DIGITAL
1692 ttusb->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL;
1694 ttusb->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
1696 ttusb->i2c_adap.algo = &ttusb_dec_algo;
1697 ttusb->i2c_adap.algo_data = NULL;
1699 result = i2c_add_adapter(&ttusb->i2c_adap);
1701 dvb_unregister_adapter (&ttusb->adapter);
1705 memset(&ttusb->dvb_demux, 0, sizeof(ttusb->dvb_demux));
1707 ttusb->dvb_demux.dmx.capabilities =
1708 DMX_TS_FILTERING | DMX_SECTION_FILTERING;
1709 ttusb->dvb_demux.priv = NULL;
1710 #ifdef TTUSB_HWSECTIONS
1711 ttusb->dvb_demux.filternum = TTUSB_MAXFILTER;
1713 ttusb->dvb_demux.filternum = 32;
1715 ttusb->dvb_demux.feednum = TTUSB_MAXCHANNEL;
1716 ttusb->dvb_demux.start_feed = ttusb_start_feed;
1717 ttusb->dvb_demux.stop_feed = ttusb_stop_feed;
1718 ttusb->dvb_demux.write_to_decoder = NULL;
1720 if ((result = dvb_dmx_init(&ttusb->dvb_demux)) < 0) {
1721 printk("ttusb_dvb: dvb_dmx_init failed (errno = %d)\n", result);
1722 i2c_del_adapter(&ttusb->i2c_adap);
1723 dvb_unregister_adapter (&ttusb->adapter);
1726 //FIXME dmxdev (nur WAS?)
1727 ttusb->dmxdev.filternum = ttusb->dvb_demux.filternum;
1728 ttusb->dmxdev.demux = &ttusb->dvb_demux.dmx;
1729 ttusb->dmxdev.capabilities = 0;
1731 if ((result = dvb_dmxdev_init(&ttusb->dmxdev, &ttusb->adapter)) < 0) {
1732 printk("ttusb_dvb: dvb_dmxdev_init failed (errno = %d)\n",
1734 dvb_dmx_release(&ttusb->dvb_demux);
1735 i2c_del_adapter(&ttusb->i2c_adap);
1736 dvb_unregister_adapter (&ttusb->adapter);
1740 if (dvb_net_init(&ttusb->adapter, &ttusb->dvbnet, &ttusb->dvb_demux.dmx)) {
1741 printk("ttusb_dvb: dvb_net_init failed!\n");
1742 dvb_dmxdev_release(&ttusb->dmxdev);
1743 dvb_dmx_release(&ttusb->dvb_demux);
1744 i2c_del_adapter(&ttusb->i2c_adap);
1745 dvb_unregister_adapter (&ttusb->adapter);
1750 ttusb->stc_devfs_handle =
1751 devfs_register(ttusb->adapter->devfs_handle, TTUSB_BUDGET_NAME,
1752 DEVFS_FL_DEFAULT, 0, 192,
1753 S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
1754 | S_IROTH | S_IWOTH, &stc_fops, ttusb);
1756 usb_set_intfdata(intf, (void *) ttusb);
1758 frontend_init(ttusb);
1763 static void ttusb_disconnect(struct usb_interface *intf)
1765 struct ttusb *ttusb = usb_get_intfdata(intf);
1767 usb_set_intfdata(intf, NULL);
1769 ttusb->disconnecting = 1;
1771 ttusb_stop_iso_xfer(ttusb);
1773 ttusb->dvb_demux.dmx.close(&ttusb->dvb_demux.dmx);
1774 dvb_net_release(&ttusb->dvbnet);
1775 dvb_dmxdev_release(&ttusb->dmxdev);
1776 dvb_dmx_release(&ttusb->dvb_demux);
1777 if (ttusb->fe != NULL) dvb_unregister_frontend(ttusb->fe);
1778 i2c_del_adapter(&ttusb->i2c_adap);
1779 dvb_unregister_adapter(&ttusb->adapter);
1781 ttusb_free_iso_urbs(ttusb);
1785 dprintk("%s: TTUSB DVB disconnected\n", __FUNCTION__);
1788 static struct usb_device_id ttusb_table[] = {
1789 {USB_DEVICE(0xb48, 0x1003)},
1790 {USB_DEVICE(0xb48, 0x1004)},
1791 {USB_DEVICE(0xb48, 0x1005)},
1795 MODULE_DEVICE_TABLE(usb, ttusb_table);
1797 static struct usb_driver ttusb_driver = {
1799 .probe = ttusb_probe,
1800 .disconnect = ttusb_disconnect,
1801 .id_table = ttusb_table,
1804 static int __init ttusb_init(void)
1808 if ((err = usb_register(&ttusb_driver)) < 0) {
1809 printk("%s: usb_register failed! Error number %d",
1817 static void __exit ttusb_exit(void)
1819 usb_deregister(&ttusb_driver);
1822 module_init(ttusb_init);
1823 module_exit(ttusb_exit);
1825 MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>");
1826 MODULE_DESCRIPTION("TTUSB DVB Driver");
1827 MODULE_LICENSE("GPL");