⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 margi.c

📁 linux TV 源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*     margi.c    Copyright (C) Marcus Metzler for convergence integrated media.    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "margi.h"#include <linux/module.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/cisreg.h>#include <pcmcia/bus_ops.h>#include <pcmcia/ds.h>#include "l64014.h"#include "l64021.h"#include "i2c.h"#include "decoder.h"#include "dram.h"#include "video.h"#include "cvdv.h"static char *version = "margi_cs.c 0.6 02/04/2000 (Marcus Metzler)";//#define USE_BH 1#ifdef USE_BH#define MARGI_BH 31// shouldn't be a number, but then MARGI_BH must be entered into interrupt.h#endifMODULE_AUTHOR(AUTHOR);MODULE_DESCRIPTION(MEDDEVNAME " Driver V." DVERSION);#ifdef MODULE_LICENSEMODULE_LICENSE("GPL");#endif#define MAX_DEV 4/* Parameters that can be set with 'insmod' */static int svhs = 1;MODULE_PARM(svhs,"i");static int composite = 1;MODULE_PARM(composite,"i");#ifdef INT_ZOOMED_VIDEOstatic int use_zv = 1;MODULE_PARM(use_zv,"i");#elsestatic int use_zv = 0;#define INT_ZOOMED_VIDEO 0#warning NO ZV support in kernel#endif/* Release IO ports after configuration? */static int free_ports = 0;/* The old way: bit map of interrupts to choose from *//* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */static u_int irq_mask = 0xdeb8;/* Newer, simpler way of listing specific interrupts */static int irq_list[4] = { -1 };MODULE_PARM(free_ports, "i");MODULE_PARM(irq_mask, "i");MODULE_PARM(irq_list, "1-4i");typedef struct margi_info_t {	dev_link_t link;	dev_node_t node;	struct cvdv_cards card;	int stop;} margi_info_t;/*   The event() function is this driver's Card Services event handler.   It will be called by Card Services when an appropriate card status   event is received.  The config() and release() entry points are   used to configure or release a socket, in response to card   insertion and ejection events.  They are invoked from the margi   event handler. */static void margi_config(dev_link_t * link);static void margi_release(u_long arg);static int margi_event(event_t event, int priority,		       event_callback_args_t * args);/*   The attach() and detach() entry points are used to create and destroy   "instances" of the driver, where each instance represents everything   needed to manage one actual PCMCIA card.*/static dev_link_t *margi_attach(void);static void margi_detach(dev_link_t *);static u_char read_lsi_status(struct cvdv_cards *card);/*   You'll also need to prototype all the functions that will actually   be used to talk to your device.  See 'memory_cs' for a good example   of a fully self-sufficient driver; the other drivers rely more or   less on other parts of the kernel.*//*   The dev_info variable is the "key" that is used to match up this   device driver with appropriate cards, through the card configuration   database.*/static dev_link_t *dev_table[MAX_DEV] = { NULL, /* ... */  };static dev_info_t dev_info = "margi_cs";/*   A linked list of "instances" of the margi device.  Each actual   PCMCIA card corresponds to one device instance, and is described   by one dev_link_t structure (defined in ds.h).   You may not want to use a linked list for this -- for example, the   memory card driver uses an array of dev_link_t pointers, where minor   device numbers are used to derive the corresponding array index.*/static dev_link_t *dev_list = NULL;/*   A dev_link_t structure has fields for most things that are needed   to keep track of a socket, but there will usually be some device   specific information that also needs to be kept track of.  The   'priv' pointer in a dev_link_t structure can be used to point to   a device-specific private data structure, like this.   To simplify the data structure handling, we actually include the   dev_link_t structure in the device's private data structure.   A driver needs to provide a dev_node_t structure for each device   on a card.  In some cases, there is only one device per card (for   example, ethernet cards, modems).  In other cases, there may be   many actual or logical devices (SCSI adapters, memory cards with   multiple partitions).  The dev_node_t structures need to be kept   in a linked list starting at the 'dev' field of a dev_link_t   structure.  We allocate them in the card's private data structure,   because they generally shouldn't be allocated dynamically.   In this case, we also provide a flag to indicate if a device is   "stopped" due to a power management event, or card ejection.  The   device IO routines can use a flag like this to throttle IO to a   card that is not ready to accept it.   The bus_operations pointer is used on platforms for which we need   to use special socket-specific versions of normal IO primitives   (inb, outb, readb, writeb, etc) for card IO.*/void DACSetFrequency(struct cvdv_cards *card, int khz, int multiple) {	uint8_t b = 	read_indexed_register(card, IIO_OSC_AUD);	b &= 0xf8;	switch (khz){	case 32:		b |= 0x04;		break;	case 48:		b |= 0x00;		break;	case 44:		b |= 0x01;		break;	case 96:		b |= 0x02;		break;	default:		b |= 0x00;		break;   	}	write_indexed_register(card, IIO_OSC_AUD, b);}int MargiFreeBuffers(struct cvdv_cards *card){	MDEBUG(1, ": -- MargiFreeBuffers\n");		ring_destroy(&(card->rbufB));	card->use_ringB = 0;	ring_destroy(&(card->rbufA));	card->use_ringA = 0;		return 0;}int MargiSetBuffers(struct cvdv_cards *card, uint32_t size, int isB){	int err = 0;	MDEBUG(0, ": -- MargiSetBuffers(%d) %d\n",	       size, isB);	if (isB){		err = ring_init(&(card->rbufB),size);		if (!err) card->use_ringB = 1;	} else {		err = ring_init(&(card->rbufA),size);		if (!err) card->use_ringA = 1;	}		MDEBUG(0,"set buffers: %d use_ringA: %d  use_ringB: %d\n",err,card->use_ringA,card->use_ringB);	return err;}int MargiFlush (struct cvdv_cards *card){	int co = 0;	int i;	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	if (card->use_ringA) ring_flush(&(card->rbufA));	if (card->use_ringB) ring_flush(&(card->rbufB));	card->DMAABusy = 0;	card->DMABBusy = 0;	DecoderStopChannel(card);	DecoderStreamReset(card);	DecoderSetupReset(card);	card->channelrun = 0;	MDEBUG(1, ": Margi Flush \n");	return 0;}int MargiPushA(struct cvdv_cards *card, int count, const char *data){	int fill;  	fill =  ring_read_rest(&(card->rbufA));	if (!card->use_ringA)		return 0;	if ((count>fill || fill > 3*card->rbufA.size/4)	    && !card->channelrun){		DecoderStartChannel(card);		card->DMAABusy = 1;	}	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 ((count>fill || fill > 3*card->rbufB.size/4)	    && !card->channelrun){		DecoderStartChannel(card);		card->DMABBusy = 1;	}	count = ring_write(&(card->rbufB),data,count);	return count;}int DecoderStartChannel(struct cvdv_cards *card){	DecoderMaskByte(card, 0x007, 0xC3, 0xC3);	// channel start#ifdef BYPASS 	DecoderMaskByte(card,0x005,0x0F,0x08);#else	DecoderMaskByte(card,0x005,0x0F,0x01);#endif	card->channelrun = 1;	return 0;}int DecoderStopChannel(struct cvdv_cards *card){	DecoderMaskByte(card, 0x007, 0xC3, 0xC2);	// channel reset	DecoderSetByte(card, 0x005, 0x04);	// channel pause	card->channelrun = 0;	return 0;}uint32_t DecoderGetAudioBufferSpace(struct cvdv_cards *card){	uint32_t MaxSize, Size;	MaxSize = card->AudioESSize;	Size = DecoderGetAudioESLevel(card);	if (Size>MaxSize)	  return 0;	return (MaxSize - Size);}uint32_t DecoderGetVideoBufferSpace(struct cvdv_cards *card){	uint32_t MaxSize, Size;	MaxSize = card->VideoESSize;	Size = DecoderGetVideoESLevel(card);	if (Size>MaxSize)	  return 0;	return (MaxSize - Size);}uint32_t DecoderGetBufferSpace(struct cvdv_cards *card){	uint32_t audio,video;		audio = DecoderGetAudioBufferSpace(card);	video = DecoderGetVideoBufferSpace(card);	if (audio > 2048) audio -= 2048;	if (video > 2048) video -= 2048;	if (audio < video) return audio;	return video;}static int ringDMA (struct cvdv_cards *card){		uint32_t size = 0;	u_char stat;	dev_link_t *link = &(((margi_info_t *) card->margi)->link);	uint32_t acount=0;	uint32_t vcount=0;	uint8_t data;	ringbuffy *buffy;	int stype;	wait_queue_head_t *wq;	stat = read_lsi_status(card);		stype = card->setup.streamtype;	if (stat & LSI_ARQ) {		stat = read_lsi_status(card);	}	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) {		switch(stype){		case stream_PES:		case stream_ES:			data = read_indexed_register(card, IIO_LSI_CONTROL);			data &= ~DSVC;			write_indexed_register(card, IIO_LSI_CONTROL, data);			buffy = &card->rbufB;			wq = &(card->wqB);			acount = ring_read_rest(buffy);			size = DecoderGetAudioBufferSpace(card);			if (size > 2048) size -= 2048;			break;		default:			buffy = &card->rbufA;			wq = &(card->wqA);			acount = ring_read_rest(buffy);			size = DecoderGetBufferSpace(card);			break;		}		if (acount > size) acount = size & 0xfffffffc;		if (acount>=2048) acount &=0xfffff800;		acount &=0xfffffffc;	       		if (acount > size) acount = size & 0xfffffffc;		if (acount) {			ring_read_direct(buffy,					 link->io.BasePort1+DIO_LSI_STATUS, 					 acount);		} else {			wake_up_interruptible(wq);			acount = 0;		}	} else {		acount = 0;	}	if ((stat & LSI_VRQ) == 0 && 	    (stype == stream_PES || stype == stream_ES)) {		data = read_indexed_register(card, IIO_LSI_CONTROL);		data |= DSVC;		write_indexed_register(card, IIO_LSI_CONTROL, data);		buffy = &card->rbufA;		wq = &(card->wqA);		vcount = ring_read_rest(buffy);	        size = DecoderGetVideoBufferSpace(card);		if (size > 2048) size -= 2048;		if (vcount > size) vcount = size & 0xfffffffc;		if (vcount>=2048) vcount &=0xfffff800;		vcount &=0xfffffffc;	       		if (vcount > size) vcount = size & 0xfffffffc;		if (vcount) {			ring_read_direct(buffy,					 link->io.BasePort1+DIO_LSI_STATUS, 					 vcount);		} else {			wake_up_interruptible(wq);			vcount = 0;		}	} else {		vcount = 0;	}	return vcount+acount;}u_char read_indexed_register(struct cvdv_cards * card, int addr){	dev_link_t *link = &(((margi_info_t *) card->margi)->link);	u_char data;	spin_lock(&card->timelock);	outb(addr, link->io.BasePort1 + DIO_CONTROL_INDEX);	data = (inb(link->io.BasePort1 + DIO_CONTROL_DATA)); 	spin_unlock(&card->timelock);	return data;}void write_indexed_register(struct cvdv_cards *card, int addr, u_char data){	dev_link_t *link = &(((margi_info_t *) card->margi)->link);	spin_lock(&card->timelock);	outb(addr, link->io.BasePort1 + DIO_CONTROL_INDEX);	outb(data, link->io.BasePort1 + DIO_CONTROL_DATA);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -