diff options
author | Holger Waechtler <devnull@localhost> | 2003-03-18 10:10:14 +0000 |
---|---|---|
committer | Holger Waechtler <devnull@localhost> | 2003-03-18 10:10:14 +0000 |
commit | 60a8adcc8decab9d26a2884e9020ba125de81572 (patch) | |
tree | 01fa0c428bd207b80130c3c886aa244b8872cfe6 /linux/drivers | |
parent | 8ac97ecd30f3566bd4d477f32aa41068e3fa1d85 (diff) | |
download | mediapointer-dvb-s2-60a8adcc8decab9d26a2884e9020ba125de81572.tar.gz mediapointer-dvb-s2-60a8adcc8decab9d26a2884e9020ba125de81572.tar.bz2 |
- start iso transfers in start_feed() in order to avoid bogus transfer packets at DSP initialisation time
- some indentation to follow the kernel coding style rules
Diffstat (limited to 'linux/drivers')
-rw-r--r-- | linux/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c | 195 |
1 files changed, 94 insertions, 101 deletions
diff --git a/linux/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/linux/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c index 8bbfa0e13..179933c76 100644 --- a/linux/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c +++ b/linux/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c @@ -60,6 +60,12 @@ static int debug = 1; #define TTUSB_MAXFILTER 16 /* ??? */ #endif + + +/** + * since we're casting (struct ttusb*) <-> (struct dvb_demux*) around + * the dvb_demux field must be the first in struct!! + */ struct ttusb { struct dvb_demux dvb_demux; dmxdev_t dmxdev; @@ -278,8 +284,8 @@ int ttusb_boot_dsp (struct ttusb *ttusb) b [2] = 0x13; b [3] = 28; - /* upload dsp code in 16 byte steps (36 didn't work for me ...) */ - /* 32 is max packet size, no messages should be splitted. */ + /* upload dsp code in 32 byte steps (36 didn't work for me ...) */ + /* 32 is max packet size, no messages should be splitted. */ for (i=0; i<sizeof(dsp_bootcode); i+=28) { memcpy (&b[4], &dsp_bootcode[i], 28); @@ -290,7 +296,7 @@ int ttusb_boot_dsp (struct ttusb *ttusb) goto done; } - /* last block ... */ + /* last block ... */ b [1] = ++ttusb->c; b [2] = 0x13; b [3] = 0; @@ -299,7 +305,7 @@ int ttusb_boot_dsp (struct ttusb *ttusb) if (err) goto done; - /* BootEnd */ + /* BootEnd */ b [1] = ++ttusb->c; b [2] = 0x14; b [3] = 0; @@ -347,7 +353,7 @@ int ttusb_set_filter (struct ttusb *ttusb, int filter_id, int associated_chan, u8 filter [8], u8 mask [8]) { int err; - /* SetFilter */ + /* SetFilter */ u8 b [] = { 0xaa, 0, 0x24, 0x1a, filter_id, associated_chan, filter[0], filter[1], filter[2], filter[3], filter[4], filter[5], filter[6], filter[7], @@ -365,7 +371,7 @@ static int ttusb_del_filter (struct ttusb *ttusb, int filter_id) { int err; - /* DelFilter */ + /* DelFilter */ u8 b [] = { 0xaa, ++ttusb->c, 0x25, 1, filter_id }; err = ttusb_cmd (ttusb, b, sizeof(b)); @@ -379,47 +385,42 @@ int ttusb_init_controller (struct ttusb *ttusb) u8 b0 [] = { 0xaa, ++ttusb->c, 0x15, 1, 0 }; u8 b1 [] = { 0xaa, ++ttusb->c, 0x15, 1, 1 }; u8 b2 [] = { 0xaa, ++ttusb->c, 0x32, 1, 0 }; - /* i2c write read: 5 bytes, addr 0x10, 0x02 bytes write, 1 bytes read. */ + /* i2c write read: 5 bytes, addr 0x10, 0x02 bytes write, 1 bytes read. */ u8 b3 [] = { 0xaa, ++ttusb->c, 0x31, 5, 0x10, 0x02, 0x01, 0x00, 0x1e }; u8 b4 [] = { 0x55, ttusb->c, 0x31, 4, 0x10, 0x02, 0x01, 0x00, 0x1e }; u8 get_version [] = {0xaa, ++ttusb->c, 0x17, 5, 0, 0, 0, 0, 0}; int err; - /* reset board */ - err = ttusb_cmd (ttusb, b0, sizeof (b0)); - if (err) + /* reset board */ + if ((err = ttusb_cmd (ttusb, b0, sizeof (b0)))) return err; - /* reset board (again?) */ - err = ttusb_cmd (ttusb, b1, sizeof (b1)); - - if (err) + /* reset board (again?) */ + if ((err = ttusb_cmd (ttusb, b1, sizeof (b1)))) return err; ttusb_boot_dsp (ttusb); - /* set i2c bit rate */ - err = ttusb_cmd (ttusb, b2, sizeof (b2)); - if (err) + /* set i2c bit rate */ + if ((err = ttusb_cmd (ttusb, b2, sizeof (b2)))) return err; - err = ttusb_cmd (ttusb, b3, sizeof (b3)); - if (err) + if ((err = ttusb_cmd (ttusb, b3, sizeof (b3)))) return err; err = ttusb_result(ttusb, b4, sizeof(b4)); - err = ttusb_cmd (ttusb, get_version, sizeof (get_version)); - if (err) + if ((err = ttusb_cmd (ttusb, get_version, sizeof (get_version)))) return err; - err = ttusb_result(ttusb, get_version, sizeof(get_version)); - if (err) + if ((err = ttusb_result(ttusb, get_version, sizeof(get_version)))) return err; + dprintk("%s: stc-version: %c%c%c%c%c\n", __FUNCTION__, get_version[4], get_version[5], get_version[6], get_version[7], get_version[8]); + if (memcmp(get_version+4, "V 0.0", 5) && memcmp(get_version+4, "V 1.1", 5)) { @@ -428,9 +429,11 @@ int ttusb_init_controller (struct ttusb *ttusb) get_version[4], get_version[5], get_version[6], get_version[7], get_version[8]); } + return 0; } + #ifdef TTUSB_DISEQC static int ttusb_send_diseqc (struct ttusb *ttusb, const struct dvb_diseqc_master_cmd *cmd) @@ -446,8 +449,7 @@ int ttusb_send_diseqc (struct ttusb *ttusb, const struct dvb_diseqc_master_cmd * memcpy(b+5, cmd->msg, cmd->msg_len); /* Diseqc */ - err = ttusb_cmd (ttusb, b, 4 + b[3]); - if (err) { + if ((err = ttusb_cmd (ttusb, b, 4 + b[3]))) { dprintk ("%s: usb_bulk_msg() failed, return value %i!\n", __FUNCTION__, err); } @@ -464,9 +466,8 @@ int ttusb_update_lnb (struct ttusb *ttusb) ttusb->tone == SEC_TONE_ON ? 1 : 0, 1, 1 }; int err; - /* SetLNB */ - err = ttusb_cmd (ttusb, b, sizeof (b)); - if (err) { + /* SetLNB */ + if ((err = ttusb_cmd (ttusb, b, sizeof (b)))) { dprintk ("%s: usb_bulk_msg() failed, return value %i!\n", __FUNCTION__, err); } @@ -481,6 +482,7 @@ int ttusb_set_voltage (struct ttusb *ttusb, fe_sec_voltage_t voltage) return ttusb_update_lnb(ttusb); } + #ifdef TTUSB_TONE static int ttusb_set_tone (struct ttusb *ttusb, fe_sec_tone_mode_t tone) @@ -550,8 +552,7 @@ void ttusb_process_muxpack(struct ttusb *ttusb, const u8 *muxpack, int len) return; } - if (muxpack[0] & 0x80) - { + if (muxpack[0] & 0x80) { #ifdef TTUSB_HWSECTIONS /* section data */ int pusi=muxpack[0]&0x40; @@ -570,8 +571,7 @@ void ttusb_process_muxpack(struct ttusb *ttusb, const u8 *muxpack, int len) #warning TODO: pusi printk("cc: %04x\n", (data[0]<<8)|data[1]); #endif - } else if (muxpack[0] == 0x47) - { + } else if (muxpack[0] == 0x47) { #ifdef TTUSB_HWSECTIONS /* we have TS data here! */ int pid=((muxpack[1]&0x0F)<<8)|muxpack[2]; @@ -591,28 +591,25 @@ void ttusb_process_frame(struct ttusb *ttusb, u8 *data, int len) int maxwork=1024; while (len) { - if (! (maxwork--)) - { + if (! (maxwork--)) { printk("%s: too much work\n", __FUNCTION__); break; } - switch (ttusb->mux_state) - { + + switch (ttusb->mux_state) { case 0: case 1: case 2: len--; if (*data++ == 0xAA) ++ttusb->mux_state; - else - { + else { ttusb->mux_state=0; #if DEBUG > 3 if (ttusb->insync) printk("%02x ", data[-1]); #else - if (ttusb->insync) - { + if (ttusb->insync) { printk("%s: lost sync.\n", __FUNCTION__); ttusb->insync=0; } @@ -625,7 +622,8 @@ void ttusb_process_frame(struct ttusb *ttusb, u8 *data, int len) ttusb->mux_npacks = *data++; ++ttusb->mux_state; ttusb->muxpack_ptr=0; - ttusb->muxpack_len=2; /* maximum bytes, until we know the length */ + /* maximum bytes, until we know the length */ + ttusb->muxpack_len=2; break; case 4: { @@ -639,11 +637,9 @@ void ttusb_process_frame(struct ttusb *ttusb, u8 *data, int len) BUG(); data+=avail; len-=avail; - /* determine length */ - if (ttusb->muxpack_ptr == 2) - { - if (ttusb->muxpack[0] & 0x80) - { + /* determine length */ + if (ttusb->muxpack_ptr == 2) { + if (ttusb->muxpack[0] & 0x80) { ttusb->muxpack_len = ttusb->muxpack[1]+2; if (ttusb->muxpack[0] & 0x20) ttusb->muxpack_len++; @@ -654,8 +650,7 @@ void ttusb_process_frame(struct ttusb *ttusb, u8 *data, int len) ttusb->muxpack_len = 188+4; else if (ttusb->muxpack[0] == 0x00) ttusb->muxpack_len = ttusb->muxpack[1]+2+4; - else - { + else { dprintk("%s: invalid state: first byte is %x\n", __FUNCTION__, ttusb->muxpack[0]); ttusb->mux_state=0; @@ -679,8 +674,7 @@ void ttusb_process_frame(struct ttusb *ttusb, u8 *data, int len) * no muxpacks left? * return to search-sync state */ - if (! ttusb->mux_npacks--) - { + if (! ttusb->mux_npacks--) { ttusb->mux_state=0; break; } @@ -708,11 +702,9 @@ void ttusb_iso_irq (struct urb *urb) urb->status, urb->error_count, urb->actual_length); #endif - if (! urb->status) - { + if (! urb->status) { int i; - for (i=0; i < FRAMES_PER_ISO_BUF; ++i) - { + for (i=0; i < FRAMES_PER_ISO_BUF; ++i) { struct iso_packet_descriptor *d; d = &urb->iso_frame_desc[i]; ttusb_process_frame(ttusb, urb->transfer_buffer + d->offset, d->actual_length); @@ -817,7 +809,6 @@ int ttusb_start_iso_xfer (struct ttusb *ttusb) } for (i=0; i<ISO_BUF_COUNT; i++) { -//?????? usb_claim_bandwidth (ttusb->dev, ttusb->iso_urb[i], ??, 1); if ((err = usb_submit_urb (ttusb->iso_urb[i]))) { ttusb_stop_iso_xfer (ttusb); printk ("%s: failed urb submission (%i: err = %i)!\n", @@ -835,7 +826,7 @@ int ttusb_start_iso_xfer (struct ttusb *ttusb) static void ttusb_handle_ts_data(struct ttusb_channel *channel, const u8 *data, int len) { - struct dvb_demux_feed *dvbdmxfeed = channel->dvbdmxfeed; + struct dvb_demux_feed *dvbdmxfeed = channel->dvbdmxfeed; dvbdmxfeed->cb.ts(data, len, 0, 0, &dvbdmxfeed->feed.ts, 0); } @@ -853,62 +844,58 @@ static struct ttusb_channel * ttusb_channel_allocate(struct ttusb *ttusb) { int i; + if (down_interruptible(&ttusb->sem)) - return 0; - /* lock! */ - for (i=0; i<TTUSB_MAXCHANNEL; ++i) - if (! ttusb->channel[i].active) - { + return NULL; + + /* lock! */ + for (i=0; i<TTUSB_MAXCHANNEL; ++i) { + if (! ttusb->channel[i].active) { ttusb->channel[i].active=1; up(&ttusb->sem); return ttusb->channel+i; } + } + up(&ttusb->sem); - return 0; + + return NULL; } + +static int running_feed_count = 0; + static int ttusb_start_feed(struct dvb_demux_feed *dvbdmxfeed) { -// struct dvb_demux *dvbdmx = dvbdmxfeed->demux; - struct ttusb *ttusb = (struct ttusb *)dvbdmxfeed->demux; + struct ttusb *ttusb = (struct ttusb*) dvbdmxfeed->demux; struct ttusb_channel *channel; printk("ttusb_start_feed\n"); -// if (!dvbdmx->dmx.frontend) -// return -EINVAL; - - /* since we're on USB-1.1, we do not support full TS delivery. */ - if (dvbdmxfeed->pid == 0x2000) - return -EINVAL; - switch(dvbdmxfeed->type) { - case DMX_TYPE_TS: - break; - case DMX_TYPE_SEC: - break; - default: - return -EINVAL; + case DMX_TYPE_TS: + break; + case DMX_TYPE_SEC: + break; + default: + return -EINVAL; } - if (dvbdmxfeed->type == DMX_TYPE_TS) - { + if (dvbdmxfeed->type == DMX_TYPE_TS) { switch(dvbdmxfeed->pes_type) { - case DMX_TS_PES_VIDEO: - case DMX_TS_PES_AUDIO: - case DMX_TS_PES_TELETEXT: - case DMX_TS_PES_PCR: -// return -EINVAL; - case DMX_TS_PES_OTHER: - channel=ttusb_channel_allocate(ttusb); - break; - default: - return -EINVAL; + case DMX_TS_PES_VIDEO: + case DMX_TS_PES_AUDIO: + case DMX_TS_PES_TELETEXT: + case DMX_TS_PES_PCR: + case DMX_TS_PES_OTHER: + channel = ttusb_channel_allocate(ttusb); + break; + default: + return -EINVAL; } - } else - { - channel=ttusb_channel_allocate(ttusb); + } else { + channel = ttusb_channel_allocate(ttusb); } if (!channel) @@ -920,11 +907,9 @@ int ttusb_start_feed(struct dvb_demux_feed *dvbdmxfeed) channel->pid = dvbdmxfeed->pid; #ifdef TTUSB_HWSECTIONS - if (dvbdmxfeed->type == DMX_TYPE_TS) - { + if (dvbdmxfeed->type == DMX_TYPE_TS) { channel->type=1; - } else if (dvbdmxfeed->type == DMX_TYPE_SEC) - { + } else if (dvbdmxfeed->type == DMX_TYPE_SEC) { channel->type=2; #error TODO: allocate filters } @@ -933,14 +918,25 @@ int ttusb_start_feed(struct dvb_demux_feed *dvbdmxfeed) #endif ttusb_set_channel (ttusb, channel->id, channel->type, channel->pid); + + if (0 == running_feed_count++) + ttusb_start_iso_xfer (ttusb); + return 0; } static int ttusb_stop_feed(struct dvb_demux_feed *dvbdmxfeed) { - struct ttusb_channel *channel=(struct ttusb_channel *)dvbdmxfeed->priv; + struct ttusb_channel *channel = (struct ttusb_channel*) dvbdmxfeed->priv; + struct ttusb *ttusb = (struct ttusb*) dvbdmxfeed->demux; + ttusb_del_channel(channel->ttusb, channel->id); + + if (--running_feed_count == 0) + ttusb_stop_iso_xfer (ttusb); + channel->active = 0; + return 0; } @@ -1031,8 +1027,7 @@ void* ttusb_probe (struct usb_device *udev, unsigned int ifnum, memset (ttusb, 0, sizeof(struct ttusb)); - for (channel=0; channel < TTUSB_MAXCHANNEL; ++channel) - { + for (channel=0; channel < TTUSB_MAXCHANNEL; ++channel) { ttusb->channel[channel].id=channel; ttusb->channel[channel].ttusb=ttusb; } @@ -1096,8 +1091,6 @@ void* ttusb_probe (struct usb_device *udev, unsigned int ifnum, } err: - ttusb_start_iso_xfer (ttusb); - ttusb->stc_devfs_handle = devfs_register( ttusb->adapter->devfs_handle, "ttusb_stc_fw", |