--- margi2/margi.c 2001/04/06 09:03:54 1.12 +++ margi2/margi.c 2001/04/25 15:31:09 1.13 @@ -38,6 +38,9 @@ #include "video.h" #include "cvdv.h" + +static char *version = "margi_cs.c 0.5 11/1/2000 (Marcus Metzler)"; + //#define USE_BH 1 #ifdef USE_BH #define MARGI_BH 31 @@ -47,15 +50,6 @@ MODULE_AUTHOR(AUTHOR); MODULE_DESCRIPTION(MEDDEVNAME " Driver V." DVERSION); -#ifdef PCMCIA_DEBUG -static int pc_debug = PCMCIA_DEBUG; -MODULE_PARM(pc_debug, "i"); -#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) -static char *version = "margi_cs.c 0.42 11/1/2000 (Marcus Metzler)"; -#else -#define DEBUG(n, args...) -#endif - #define MAX_DEV 4 #define DEVICE_NR(minor) ((minor)>>4) @@ -197,37 +191,54 @@ void DACSetFrequency(struct cvdv_cards * int MargiFreeBuffers(struct cvdv_cards *card) { - printk(KERN_DEBUG LOGNAME ": -- MargiFreeBuffers\n"); + MDEBUG(1, ": -- MargiFreeBuffers\n"); - ring_destroy(&(card->rbuf)); - card->use_ring = 0; + ring_destroy(&(card->rbufA)); + card->use_ringA = 0; + ring_destroy(&(card->rbufB)); + card->use_ringB = 0; return 0; } -int MargiSetBuffers(struct cvdv_cards *card, uint32_t size) +int MargiSetABuffers(struct cvdv_cards *card, uint32_t size) { MargiFreeBuffers(card); - printk(KERN_DEBUG LOGNAME ": -- MargiSetBuffers(%d)\n", + MDEBUG(1, ": -- MargiSetABuffers(%d)\n", size); - ring_init(&(card->rbuf),size); - card->use_ring = 1; + ring_init(&(card->rbufA),size); + card->use_ringA = 1; return 0; +} +int MargiSetBBuffers(struct cvdv_cards *card, uint32_t size) +{ + MargiFreeBuffers(card); + MDEBUG(1, ": -- MargiSetBBuffers(%d)\n", + size); + + ring_init(&(card->rbufB),size); + card->use_ringB = 1; + return 0; } int MargiFlush (struct cvdv_cards *card) { int co = 0; int i; - for (i=0;i<100;i++) - MargiPush(card, 32, FlushPacket); - while (ring_write_rest(&(card->rbuf)) && co<100) co++; + for (i=0;i<100;i++){ + MargiPushA(card, 32, FlushPacket); + MargiPushB(card, 32, FlushPacket); + } + while ( (ring_write_rest(&(card->rbufA))|| ring_write_rest(&(card->rbufB))) && co<100) + co++; VideoSetBackground(card, 1, 0, 0, 0); // black - ring_flush(&(card->rbuf)); + if (card->use_ringA) ring_flush(&(card->rbufA)); + if (card->use_ringB) ring_flush(&(card->rbufB)); card->DMAABusy = 0; + card->DMABBusy = 0; DecoderStopChannel(card); @@ -235,26 +246,45 @@ int MargiFlush (struct cvdv_cards *card) DecoderSetupReset(card); card->channelrun = 0; - printk(KERN_DEBUG LOGNAME ": Margi Flush \n"); + MDEBUG(1, ": Margi Flush \n"); return 0; } -int MargiPush(struct cvdv_cards *card, int count, const char *data) +int MargiPushA(struct cvdv_cards *card, int count, const char *data) { int fill; - fill = ring_read_rest(&(card->rbuf)); + fill = ring_read_rest(&(card->rbufA)); - if (!card->use_ring) + if (!card->use_ringA) return 0; - if (fill > 3*card->rbuf.size/4 && !card->channelrun){ + if (fill > 3*card->rbufA.size/4 && !card->channelrun){ DecoderStartChannel(card); card->DMAABusy = 1; } - count = ring_write(&(card->rbuf),data,count); + count = ring_write(&(card->rbufA),data,count); + + return count; +} + +int MargiPushB(struct cvdv_cards *card, int count, const char *data) +{ + int fill; + + fill = ring_read_rest(&(card->rbufB)); + + if (!card->use_ringB) + return 0; + + if (fill > 3*card->rbufB.size/4 && !card->channelrun){ + DecoderStartChannel(card); + card->DMABBusy = 1; + } + + count = ring_write(&(card->rbufB),data,count); return count; } @@ -322,46 +352,19 @@ uint32_t DecoderGetBufferSpace(struct cv return video; } -int MargiWriteDirect(struct cvdv_cards *card, uint32_t count, const char *buf) -{ + +static int ringDMA_PES (struct cvdv_cards *card){ + uint32_t size = 0; u_char stat; dev_link_t *link = &(((margi_info_t *) card->margi)->link); + uint32_t count=0; uint8_t data; - stat = read_lsi_status(card); - if (stat & LSI_ARQ) { - stat = read_lsi_status(card); - } - printk(KERN_DEBUG LOGNAME ": -- stat: %d \n",stat); + return 0; +} - if (stat & LSI_READY){ - data = read_indexed_register(card, IIO_LSI_CONTROL); - data |= RR; - write_indexed_register(card, IIO_LSI_CONTROL, data); - return 0; - } - if ((stat & LSI_ARQ) == 0) { - size = DecoderGetBufferSpace(card); - if (count > size) count = size & 0xfffffffc; - if (count>=2048) count &=0xfffff800; - count &=0xfffffffc; - - if (count > size) count = size & 0xfffffffc; - printk(KERN_DEBUG LOGNAME ": -- stat:%d length:%d size:%d\n", - stat, count, size); - if (count) { - outsl_ns(link->io.BasePort1+DIO_LSI_STATUS, - buf,count); - - } - } else { - count = 0; - } - - return count; -} static int ringDMA (struct cvdv_cards *card){ @@ -370,9 +373,8 @@ static int ringDMA (struct cvdv_cards *c dev_link_t *link = &(((margi_info_t *) card->margi)->link); uint32_t count=0; uint8_t data; - - count = ring_read_rest(&(card->rbuf)); + count = ring_read_rest(&(card->rbufA)); if (count < 2048) { wake_up_interruptible(&(card->wqA)); return 0; @@ -380,11 +382,8 @@ static int ringDMA (struct cvdv_cards *c stat = read_lsi_status(card); -#if 0 - printk(KERN_ERR LOGNAME - ": -- stat: %d readpos: %d writepos: %d \n", - stat,card->rbuf.read_pos,card->rbuf.write_pos); -#endif + MDEBUG( 3, ": -- stat: %d readpos: %d writepos: %d \n", + stat,(int) card->rbufA.read_pos,(int) card->rbufA.write_pos); if (stat & LSI_ARQ) { stat = read_lsi_status(card); } @@ -412,14 +411,11 @@ static int ringDMA (struct cvdv_cards *c } if (count > size) count = size & 0xfffffffc; -#if 0 - printk(KERN_ERR LOGNAME - ": -- stat: %d length: %d size: %d startV: %d startA: %d\n", + MDEBUG(3,": -- stat: %d length: %d size: %d startV: %d startA: %d\n", stat,count,size, card->startingV, card->startingA); -#endif if (count) { - ring_read_direct(&(card->rbuf), + ring_read_direct(&(card->rbufA), link->io.BasePort1+DIO_LSI_STATUS, count); } @@ -521,6 +517,7 @@ static void do_margi(struct cvdv_cards * #endif int countA, countB; int try; + int stype = card->setup.streamtype; countA = 0; countB = 0; @@ -529,13 +526,25 @@ static void do_margi(struct cvdv_cards * for ( try = 0; try < MAX_COUNT ;try++) if (countA < MAXWRITE){ int count = 0; - count = ringDMA(card); - countA += count; - if (!count) - try=MAX_COUNT; + switch (stype){ + case stream_PES: + case stream_ES: +// count = ringDMA_PES(card); + count = ringDMA(card); + countA += count; + if (!count) + try=MAX_COUNT; + break; + case stream_PS: + case stream_DVD: + count = ringDMA(card); + countA += count; + if (!count) + try=MAX_COUNT; + break; + } } else break; - } @@ -546,6 +555,7 @@ void L64014Intr_function(struct cvdv_car uint8_t control,mask,stat; int try; + control= read_indexed_register(card, IIO_IRQ_CONTROL); if (control & IRQ_EN){ mask = 0; @@ -563,7 +573,7 @@ void L64014Intr_function(struct cvdv_car control); - if (card->DMAABusy){ + if (card->DMAABusy || card->DMABBusy){ #ifdef USE_BH bh_card = card; @@ -571,9 +581,12 @@ void L64014Intr_function(struct cvdv_car #else do_margi(card); #endif - if(card->use_ring){ + if(card->use_ringA || card->use_ringB){ L64021Intr(card); } + } else { + wake_up_interruptible(&(card->wqA)); + wake_up_interruptible(&(card->wqB)); } } @@ -583,7 +596,7 @@ void L64014Intr_function(struct cvdv_car write_indexed_register(card,IIO_IRQ_CONTROL, control); - if(card->use_ring){ + if(card->use_ringA || card->use_ringB){ L64021Intr(card); } } @@ -606,7 +619,7 @@ void Timerfunction(unsigned long data) card->timer.function = Timerfunction; card->timer.data=(unsigned long) card; card->timer.expires=jiffies+1; - if ( card->open ) + if ( card->open) add_timer(&card->timer); } @@ -641,7 +654,7 @@ void L64014Intr(int irq, void *dev_id, s int L64014RemoveIntr(struct cvdv_cards *card) { - printk(KERN_DEBUG LOGNAME ": -- L64014RemoveIntr\n"); + MDEBUG(1, ": -- L64014RemoveIntr\n"); // Disable the IRQ's write_indexed_register(card, IIO_IRQ_CONTROL, 0x00); if (!card->IntInstalled) @@ -700,7 +713,7 @@ int L64014Init(struct cvdv_cards *card) uint16_t testram[16]; int i, err; - printk(KERN_DEBUG LOGNAME ": -- L64014Init\n"); + MDEBUG(1, ": -- L64014Init\n"); card->videomode = VIDEO_MODE; /* Reset 64020 */ @@ -720,9 +733,9 @@ int L64014Init(struct cvdv_cards *card) write_indexed_register(card, CSS_COMMAND, 0x01); - printk("CSID: %02x\n", I2CRead(card, 0, 0x3d)); + MDEBUG(0, "CSID: %02x\n", I2CRead(card, 0, 0x3d)); card->i2c_addr = I2CRead(card, 0, 0x0f); - printk("I2CADDR: %02x\n", card->i2c_addr); + MDEBUG(0, "I2CADDR: %02x\n", card->i2c_addr); I2CWrite(card, card->i2c_addr, CS_CONTROL0, 0x4a); I2CWrite(card, card->i2c_addr, CS_CONTROL1, 0x04); @@ -735,8 +748,8 @@ int L64014Init(struct cvdv_cards *card) I2CWrite(card, card->i2c_addr, CS_DAC, 0x87); I2CWrite(card, card->i2c_addr, CS_BKG_COL, 0x03); - printk("Decoder Status: %d\n", read_lsi_status(card)); - printk("lsi stat %d\n", DecoderReadByte(card, 0x005)); + MDEBUG(0,"Decoder Status: %d\n", read_lsi_status(card)); + MDEBUG(0,"lsi stat %d\n", DecoderReadByte(card, 0x005)); #ifdef USE_ZV ZV_init(card); @@ -746,39 +759,39 @@ int L64014Init(struct cvdv_cards *card) // Find out how much DRAM we have card->DRAMSize = 0x00100000; // maximum size do { - printk(KERN_DEBUG LOGNAME + MDEBUG(0, ": Probing DRAM Size: 0x%08X (%d kByte) ... ", card->DRAMSize, card->DRAMSize / 512); for (i = 0; i < 8; i++) testram[i] = rnd(0x100) | (rnd(0x100) << 8); if (DRAMWriteWord(card, 0, 4, &testram[0], 0)) - printk(KERN_DEBUG LOGNAME ": DRAM Write error.\n"); + MDEBUG(0, ": DRAM Write error.\n"); if (DRAMWriteWord (card, card->DRAMSize - 4, 4, &testram[4], - 0)) printk(KERN_DEBUG LOGNAME + 0)) MDEBUG(0, ": DRAM Write error.\n"); if (DRAMReadWord(card, 0, 4, &testram[8], 0)) - printk(KERN_DEBUG LOGNAME ": DRAM Read error.\n"); + MDEBUG(0, ": DRAM Read error.\n"); if (DRAMReadWord (card, card->DRAMSize - 4, 4, &testram[12], - 0)) printk(KERN_DEBUG LOGNAME ": DRAM Read error.\n"); + 0)) MDEBUG(0, ": DRAM Read error.\n"); err = 0; for (i = 0; (!err) && (i < 8); i++) if (testram[i] != testram[i + 8]) err = i + 1; - if (err) printk(" failed\n"); - else printk(" ok\n"); - /* + if (err) { + MDEBUG(0," failed\n"); + } else { + MDEBUG(0," ok\n"); + } if (err) - printk(KERN_DEBUG LOGNAME - ": DRAM compare error at cell %d: 0x%04X %04X %04X %04X->0x%04X %04X %04X %04X / 0x%04X %04X %04X %04X->0x%04X %04X %04X %04X\n", + MDEBUG(2,": DRAM compare error at cell %d: 0x%04X %04X %04X %04X->0x%04X %04X %04X %04X / 0x%04X %04X %04X %04X->0x%04X %04X %04X %04X\n", err, testram[0], testram[1], testram[2], testram[3], testram[8], testram[9], testram[10], testram[11], testram[4], testram[5], testram[6], testram[7], testram[12], testram[13], testram[14], testram[15]); - */ if (err) card->DRAMSize >>= 1; } while (err && (card->DRAMSize >= 0x00100000)); @@ -838,7 +851,7 @@ static dev_link_t *margi_attach(void) client_reg_t client_reg; int ret, i; - DEBUG(0, "margi_attach()\n"); + MDEBUG(0, "margi_attach()\n"); for (i = 0; i < MAX_DEV; i++) if (dev_table[i] == NULL) @@ -925,7 +938,7 @@ static void margi_detach(dev_link_t * li int nd; - DEBUG(0, "margi_detach(0x%p)\n", link); + MDEBUG(0, "margi_detach(0x%p)\n", link); for (nd = 0; nd < MAX_DEV; nd++) if (dev_table[nd] == link) @@ -947,10 +960,8 @@ static void margi_detach(dev_link_t * li detach(). */ if (link->state & DEV_CONFIG) { -#ifdef PCMCIA_DEBUG - printk(KERN_DEBUG "margi_cs: detach postponed, '%s' " + MDEBUG(2, "margi_cs: detach postponed, '%s' " "still locked\n", link->dev->dev_name); -#endif link->state |= DEV_STALE_LINK; return; } @@ -996,7 +1007,7 @@ static void margi_config(dev_link_t * li memreq_t map; int minor = 0; - DEBUG(0, "margi_config(0x%p)\n", link); + MDEBUG(0, "margi_config(0x%p)\n", link); /* This reads the card's CONFIG tuple to find its configuration @@ -1264,14 +1275,14 @@ static void margi_release(u_long arg) margi_info_t *dev = link->priv; struct cvdv_cards *card = &(dev->card); - DEBUG(0, "margi_release(0x%p)\n", link); + MDEBUG(0, "margi_release(0x%p)\n", link); /* If the device is currently in use, we won't release until it is actually closed, because until then, we can't be sure that no one will try to access the device or its data structures. */ if (link->open) { - DEBUG(1, "margi_cs: release postponed, '%s' still open\n", + MDEBUG(1, "margi_cs: release postponed, '%s' still open\n", link->dev->dev_name); link->state |= DEV_STALE_CONFIG; return; @@ -1285,7 +1296,7 @@ static void margi_release(u_long arg) other kernel data structures associated with this device. */ - printk(KERN_INFO LOGNAME ": Unloading device driver\n"); + MDEBUG(1,": Unloading device driver\n"); if (major_device_number) unregister_chrdev(major_device_number, CVDV_PROCNAME); CardDeInit(card); @@ -1335,7 +1346,7 @@ static int margi_event(event_t event, in dev_link_t *link = args->client_data; margi_info_t *dev = link->priv; - DEBUG(1, "margi_event(0x%06x)\n", event); + MDEBUG(1, "margi_event(0x%06x)\n", event); switch (event) { case CS_EVENT_CARD_REMOVAL: @@ -1382,7 +1393,7 @@ static int margi_event(event_t event, in static int __init init_margi_cs(void) { servinfo_t serv; - DEBUG(0, "%s\n", version); + MDEBUG(0, "%s\n", version); CardServices(GetCardServicesInfo, &serv); if (serv.Revision != CS_RELEASE_CODE) { printk(KERN_NOTICE "margi_cs: Card Services release " @@ -1395,7 +1406,7 @@ static int __init init_margi_cs(void) static void __exit exit_margi_cs(void) { - DEBUG(0, "margi_cs: unloading\n"); + MDEBUG(0, "margi_cs: unloading\n"); unregister_pccard_driver(&dev_info); while (dev_list != NULL) { if (dev_list->state & DEV_CONFIG)