Commit e8ce2f21 authored by Steven Toth's avatar Steven Toth Committed by Mauro Carvalho Chehab
Browse files

[media] saa7164: add NTSC VBI support



IRQ handlers, firmware messages, deferred queue handlers, V4L api's
etc.

Signed-off-by: default avatarSteven Toth <stoth@kernellabs.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 11bd27b2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
saa7164-objs	:= saa7164-cards.o saa7164-core.o saa7164-i2c.o saa7164-dvb.o \
			saa7164-fw.o saa7164-bus.o saa7164-cmd.o saa7164-api.o \
			saa7164-buffer.o saa7164-encoder.o
			saa7164-buffer.o saa7164-encoder.o saa7164-vbi.o

obj-$(CONFIG_VIDEO_SAA7164) += saa7164.o

+106 −5
Original line number Diff line number Diff line
@@ -24,6 +24,62 @@

#include "saa7164.h"

int saa7164_api_set_vbi_format(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;
	tmComResProbeCommit_t fmt, rsp;
	int ret;

	dprintk(DBGLVL_API, "%s(nr=%d)\n", __func__, port->nr);

	fmt.bmHint = 0;
	fmt.bFormatIndex = 1;
	fmt.bFrameIndex = 1;

	/* Probe, see if it can support this format */
	ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
		SET_CUR, SAA_PROBE_CONTROL, sizeof(fmt), &fmt);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() set error, ret = 0x%x\n", __func__, ret);

	/* See of the format change was successful */
	ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
		GET_CUR, SAA_PROBE_CONTROL, sizeof(rsp), &rsp);
	if (ret != SAA_OK) {
		printk(KERN_ERR "%s() get error, ret = 0x%x\n", __func__, ret);
	} else {
		/* Compare requested vs received, should be same */
		if (memcmp(&fmt, &rsp, sizeof(rsp)) == 0) {
			/* Ask the device to select the negotiated format */
			ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
				SET_CUR, SAA_COMMIT_CONTROL, sizeof(fmt), &fmt);
			if (ret != SAA_OK)
				printk(KERN_ERR "%s() commit error, ret = 0x%x\n",
					__func__, ret);

			ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
				GET_CUR, SAA_COMMIT_CONTROL, sizeof(rsp), &rsp);
			if (ret != SAA_OK)
				printk(KERN_ERR "%s() GET commit error, ret = 0x%x\n",
					__func__, ret);

			if (memcmp(&fmt, &rsp, sizeof(rsp)) != 0)
				printk(KERN_ERR "%s() memcmp error, ret = 0x%x\n",
					__func__, ret);

			dprintk(DBGLVL_API, "rsp.bmHint = 0x%x\n", rsp.bmHint);
			dprintk(DBGLVL_API, "rsp.bFormatIndex = 0x%x\n", rsp.bFormatIndex);
			dprintk(DBGLVL_API, "rsp.bFrameIndex = 0x%x\n", rsp.bFrameIndex);
		} else
			printk(KERN_ERR "%s() compare failed\n", __func__);
	}

	if (ret == SAA_OK)
		dprintk(DBGLVL_API, "%s(nr=%d) Success\n", __func__, port->nr);

	return ret;
}

int saa7164_api_set_gop_size(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;
@@ -463,7 +519,8 @@ int saa7164_api_set_dif(struct saa7164_port *port, u8 reg, u8 val)
	int ret;
	u8 mas;

	dprintk(DBGLVL_API, "%s()\n", __func__);
	dprintk(DBGLVL_API, "%s(nr=%d type=%d val=%x)\n", __func__,
		port->nr, port->type, val);

	if (port->nr == 0)
		mas = 0xd0;
@@ -516,7 +573,7 @@ int saa7164_api_configure_dif(struct saa7164_port *port, u32 std)
	int ret = 0;
	u8 agc_disable;

	dprintk(DBGLVL_API, "%s(%p, 0x%x)\n", __func__, port, std);
	dprintk(DBGLVL_API, "%s(nr=%d, 0x%x)\n", __func__, port->nr, std);

	if (std & V4L2_STD_NTSC) {
		dprintk(DBGLVL_API, " NTSC\n");
@@ -580,6 +637,9 @@ int saa7164_api_initialize_dif(struct saa7164_port *port)
	int ret = -EINVAL;
	u32 std = 0;

	dprintk(DBGLVL_API, "%s(nr=%d type=%d)\n", __func__,
		port->nr, port->type);

	if (port->type == SAA7164_MPEG_ENCODER) {
		/* Pick any analog standard to init the diff.
		 * we'll come back during encoder_init'
@@ -592,6 +652,13 @@ int saa7164_api_initialize_dif(struct saa7164_port *port)
			p = &dev->ports[ SAA7164_PORT_ENC1 ];
		else
			p = &dev->ports[ SAA7164_PORT_ENC2 ];
	} else
	if (port->type == SAA7164_MPEG_VBI) {
		std = V4L2_STD_NTSC;
		if (port->nr == SAA7164_PORT_VBI1)
			p = &dev->ports[ SAA7164_PORT_ENC1 ];
		else
			p = &dev->ports[ SAA7164_PORT_ENC2 ];
	} else
		BUG();

@@ -603,12 +670,18 @@ int saa7164_api_initialize_dif(struct saa7164_port *port)

int saa7164_api_transition_port(struct saa7164_port *port, u8 mode)
{
	struct saa7164_dev *dev = port->dev;

	int ret;

	dprintk(DBGLVL_API, "%s(nr=%d unitid=0x%x,%d)\n",
		__func__, port->nr, port->hwcfg.unitid, mode);

	ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, SET_CUR,
		SAA_STATE_CONTROL, sizeof(mode), &mode);
	if (ret != SAA_OK)
		printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
		printk(KERN_ERR "%s(portnr %d unitid 0x%x) error, ret = 0x%x\n",
			__func__, port->nr, port->hwcfg.unitid, ret);

	return ret;
}
@@ -639,6 +712,23 @@ int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen)
}


int saa7164_api_configure_port_vbi(struct saa7164_dev *dev,
	struct saa7164_port *port)
{
	tmComResVBIFormatDescrHeader_t *fmt = &port->vbi_fmt_ntsc;

	dprintk(DBGLVL_API, "    bFormatIndex  = 0x%x\n", fmt->bFormatIndex);
	dprintk(DBGLVL_API, "    VideoStandard = 0x%x\n", fmt->VideoStandard);
	dprintk(DBGLVL_API, "    StartLine     = %d\n", fmt->StartLine);
	dprintk(DBGLVL_API, "    EndLine       = %d\n", fmt->EndLine);
	dprintk(DBGLVL_API, "    FieldRate     = %d\n", fmt->FieldRate);
	dprintk(DBGLVL_API, "    bNumLines     = %d\n", fmt->bNumLines);
	dprintk(DBGLVL_API, "   = VS_FORMAT_VBI (becomes dev->en[%d])\n",
		port->nr);

	return 0;
}

int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev,
	struct saa7164_port *port,
	tmComResTSFormatDescrHeader_t *tsfmt)
@@ -710,6 +800,7 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
{
	struct saa7164_port *tsport = 0;
	struct saa7164_port *encport = 0;
	struct saa7164_port *vbiport = 0;
	u32 idx, next_offset;
	int i;
	tmComResDescrHeader_t *hdr, *t;
@@ -724,6 +815,7 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
	tmComResProcDescrHeader_t *pdh;
	tmComResAFeatureDescrHeader_t *afd;
	tmComResEncoderDescrHeader_t *edh;
	tmComResVBIFormatDescrHeader_t *vbifmt;
	u32 currpath = 0;

	dprintk(DBGLVL_API,
@@ -881,8 +973,17 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
						encport, psfmt);
					break;
				case VS_FORMAT_VBI:
					dprintk(DBGLVL_API,
						"   = VS_FORMAT_VBI\n");
					vbifmt =
					(tmComResVBIFormatDescrHeader_t *)t;
					if (currpath == 1)
						vbiport = &dev->ports[ SAA7164_PORT_VBI1 ];
					else
						vbiport = &dev->ports[ SAA7164_PORT_VBI2 ];
					memcpy(&vbiport->hwcfg, vcoutputtermhdr,
						sizeof(*vcoutputtermhdr));
					memcpy(&vbiport->vbi_fmt_ntsc, vbifmt, sizeof(*vbifmt));
					saa7164_api_configure_port_vbi(dev,
						vbiport);
					break;
				case VS_FORMAT_RDS:
					dprintk(DBGLVL_API,
+14 −0
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ struct saa7164_board saa7164_boards[] = {
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.porte		= SAA7164_MPEG_VBI,
		.portf		= SAA7164_MPEG_VBI,
		.chiprev	= SAA7164_CHIP_REV3,
		.unit		= {{
			.id		= 0x1d,
@@ -101,6 +103,8 @@ struct saa7164_board saa7164_boards[] = {
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.porte		= SAA7164_MPEG_VBI,
		.portf		= SAA7164_MPEG_VBI,
		.chiprev	= SAA7164_CHIP_REV2,
		.unit		= {{
			.id		= 0x06,
@@ -145,6 +149,8 @@ struct saa7164_board saa7164_boards[] = {
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.porte		= SAA7164_MPEG_VBI,
		.portf		= SAA7164_MPEG_VBI,
		.chiprev	= SAA7164_CHIP_REV2,
		.unit		= {{
			.id		= 0x1d,
@@ -205,6 +211,8 @@ struct saa7164_board saa7164_boards[] = {
		.portd		= SAA7164_MPEG_ENCODER,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.porte		= SAA7164_MPEG_VBI,
		.portf		= SAA7164_MPEG_VBI,
		.chiprev	= SAA7164_CHIP_REV3,
		.unit		= {{
			.id		= 0x22,
@@ -263,6 +271,10 @@ struct saa7164_board saa7164_boards[] = {
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.porte		= SAA7164_MPEG_VBI,
		.portf		= SAA7164_MPEG_VBI,
		.porte		= SAA7164_MPEG_VBI,
		.portf		= SAA7164_MPEG_VBI,
		.chiprev	= SAA7164_CHIP_REV3,
		.unit		= {{
			.id		= 0x28,
@@ -321,6 +333,8 @@ struct saa7164_board saa7164_boards[] = {
		.portb		= SAA7164_MPEG_DVB,
		.portc		= SAA7164_MPEG_ENCODER,
		.portd		= SAA7164_MPEG_ENCODER,
		.porte		= SAA7164_MPEG_VBI,
		.portf		= SAA7164_MPEG_VBI,
		.chiprev	= SAA7164_CHIP_REV3,
		.unit		= {{
			.id		= 0x26,
+137 −6
Original line number Diff line number Diff line
@@ -53,6 +53,10 @@ unsigned int encoder_buffers = SAA7164_MAX_ENCODER_BUFFERS;
module_param(encoder_buffers, int, 0644);
MODULE_PARM_DESC(encoder_buffers, "Total buffers in read queue 16-512 def:64");

unsigned int vbi_buffers = SAA7164_MAX_VBI_BUFFERS;
module_param(vbi_buffers, int, 0644);
MODULE_PARM_DESC(vbi_buffers, "Total buffers in read queue 16-512 def:64");

unsigned int waitsecs = 10;
module_param(waitsecs, int, 0644);
MODULE_PARM_DESC(waitsecs, "timeout on firmware messages");
@@ -440,6 +444,61 @@ static void saa7164_work_enchandler(struct work_struct *w)
	}
}

static void saa7164_work_vbihandler(struct work_struct *w)
{
	struct saa7164_port *port =
		container_of(w, struct saa7164_port, workenc);
	struct saa7164_dev *dev = port->dev;

	u32 wp, mcb, rp, cnt = 0;

	port->last_svc_msecs_diff = port->last_svc_msecs;
	port->last_svc_msecs = jiffies_to_msecs(jiffies);
	port->last_svc_msecs_diff = port->last_svc_msecs -
		port->last_svc_msecs_diff;

	saa7164_histogram_update(&port->svc_interval,
		port->last_svc_msecs_diff);

	port->last_irq_svc_msecs_diff = port->last_svc_msecs -
		port->last_irq_msecs;

	saa7164_histogram_update(&port->irq_svc_interval,
		port->last_irq_svc_msecs_diff);

	dprintk(DBGLVL_IRQ,
		"%s() %Ldms elapsed irq->deferred %Ldms wp: %d rp: %d\n",
		__func__,
		port->last_svc_msecs_diff,
		port->last_irq_svc_msecs_diff,
		port->last_svc_wp,
		port->last_svc_rp
		);

	/* Current write position */
	wp = saa7164_readl(port->bufcounter);
	if (wp > (port->hwcfg.buffercount - 1)) {
		printk(KERN_ERR "%s() illegal buf count %d\n", __func__, wp);
		return;
	}

	/* Most current complete buffer */
	if (wp == 0)
		mcb = (port->hwcfg.buffercount - 1);
	else
		mcb = wp - 1;
	/* TODO: Convert this into a /proc/saa7164 style readable file */
	if (print_histogram == port->nr) {
		saa7164_histogram_print(port, &port->irq_interval);
		saa7164_histogram_print(port, &port->svc_interval);
		saa7164_histogram_print(port, &port->irq_svc_interval);
		saa7164_histogram_print(port, &port->read_interval);
		saa7164_histogram_print(port, &port->poll_interval);
		/* TODO: fix this to preserve any previous state */
		print_histogram = 64 + port->nr;
	}
}

static void saa7164_work_cmdhandler(struct work_struct *w)
{
	struct saa7164_dev *dev = container_of(w, struct saa7164_dev, workcmd);
@@ -458,6 +517,31 @@ static void saa7164_buffer_deliver(struct saa7164_buffer *buf)

}

static irqreturn_t saa7164_irq_vbi(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;

	/* Store old time */
	port->last_irq_msecs_diff = port->last_irq_msecs;

	/* Collect new stats */
	port->last_irq_msecs = jiffies_to_msecs(jiffies);

	/* Calculate stats */
	port->last_irq_msecs_diff = port->last_irq_msecs -
		port->last_irq_msecs_diff;

	saa7164_histogram_update(&port->irq_interval,
		port->last_irq_msecs_diff);

	dprintk(DBGLVL_IRQ, "%s() %Ldms elapsed\n", __func__,
		port->last_irq_msecs_diff);

	/* Tis calls the vbi irq handler */
	schedule_work(&port->workenc);
	return 0;
}

static irqreturn_t saa7164_irq_encoder(struct saa7164_port *port)
{
	struct saa7164_dev *dev = port->dev;
@@ -527,6 +611,8 @@ static irqreturn_t saa7164_irq(int irq, void *dev_id)
	struct saa7164_port *portb = &dev->ports[ SAA7164_PORT_TS2 ];
	struct saa7164_port *portc = &dev->ports[ SAA7164_PORT_ENC1 ];
	struct saa7164_port *portd = &dev->ports[ SAA7164_PORT_ENC2 ];
	struct saa7164_port *porte = &dev->ports[ SAA7164_PORT_VBI1 ];
	struct saa7164_port *portf = &dev->ports[ SAA7164_PORT_VBI2 ];

	u32 intid, intstat[INT_SIZE/4];
	int i, handled = 0, bit;
@@ -590,9 +676,19 @@ static irqreturn_t saa7164_irq(int irq, void *dev_id)

				} else if (intid == portd->hwcfg.interruptid) {

					/* Encoder path 1 */
					/* Encoder path 2 */
					saa7164_irq_encoder(portd);

				} else if (intid == porte->hwcfg.interruptid) {

					/* VBI path 1 */
					saa7164_irq_vbi(porte);

				} else if (intid == portf->hwcfg.interruptid) {

					/* VBI path 2 */
					saa7164_irq_vbi(portf);

				} else {
					/* Find the function */
					dprintk(DBGLVL_IRQ,
@@ -830,9 +926,19 @@ static int saa7164_port_init(struct saa7164_dev *dev, int portnr)
	if ((portnr == SAA7164_PORT_TS1) || (portnr == SAA7164_PORT_TS2))
		port->type = SAA7164_MPEG_DVB;
	else
	if ((portnr == SAA7164_PORT_ENC1) || (portnr == SAA7164_PORT_ENC2))
	if ((portnr == SAA7164_PORT_ENC1) || (portnr == SAA7164_PORT_ENC2)) {
		port->type = SAA7164_MPEG_ENCODER;

		/* We need a deferred interrupt handler for cmd handling */
		INIT_WORK(&port->workenc, saa7164_work_enchandler);
	}
	else
	if ((portnr == SAA7164_PORT_VBI1) || (portnr == SAA7164_PORT_VBI2)) {
		port->type = SAA7164_MPEG_VBI;

		/* We need a deferred interrupt handler for cmd handling */
		INIT_WORK(&port->workenc, saa7164_work_vbihandler);
	} else
		BUG();

	/* Init all the critical resources */
@@ -844,17 +950,15 @@ static int saa7164_port_init(struct saa7164_dev *dev, int portnr)
	INIT_LIST_HEAD(&port->list_buf_free.list);
	init_waitqueue_head(&port->wait_read);

	/* We need a deferred interrupt handler for cmd handling */
	INIT_WORK(&port->workenc, saa7164_work_enchandler);

	saa7164_histogram_reset(&port->irq_interval, "irq intervals");
	saa7164_histogram_reset(&port->svc_interval, "deferred intervals");
	saa7164_histogram_reset(&port->irq_svc_interval,
		"irq to deferred intervals");
	saa7164_histogram_reset(&port->read_interval,
		"encoder read() intervals");
		"encoder/vbi read() intervals");
	saa7164_histogram_reset(&port->poll_interval,
		"encoder poll() intervals");
		"encoder/vbi poll() intervals");

	return 0;
}
@@ -905,6 +1009,8 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)
	saa7164_port_init(dev, SAA7164_PORT_TS2);
	saa7164_port_init(dev, SAA7164_PORT_ENC1);
	saa7164_port_init(dev, SAA7164_PORT_ENC2);
	saa7164_port_init(dev, SAA7164_PORT_VBI1);
	saa7164_port_init(dev, SAA7164_PORT_VBI2);

	if (get_resources(dev) < 0) {
		printk(KERN_ERR "CORE %s No more PCIe resources for "
@@ -1107,6 +1213,21 @@ static int __devinit saa7164_initdev(struct pci_dev *pci_dev,
			}
		}

		if (saa7164_boards[dev->board].porte == SAA7164_MPEG_VBI) {
			if (saa7164_vbi_register(&dev->ports[ SAA7164_PORT_VBI1 ]) < 0) {
				printk(KERN_ERR"%s() Failed to register "
					"vbi device\n", __func__);
			}
		}

		if (saa7164_boards[dev->board].portf == SAA7164_MPEG_VBI) {
			if (saa7164_vbi_register(&dev->ports[ SAA7164_PORT_VBI2 ]) < 0) {
				printk(KERN_ERR"%s() Failed to register "
					"vbi device\n", __func__);
			}
		}


	} /* != BOARD_UNKNOWN */
	else
		printk(KERN_ERR "%s() Unsupported board detected, "
@@ -1144,6 +1265,10 @@ static void __devexit saa7164_finidev(struct pci_dev *pci_dev)
		&dev->ports[ SAA7164_PORT_ENC1 ].read_interval);
	saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
		&dev->ports[ SAA7164_PORT_ENC1 ].poll_interval);
	saa7164_histogram_print(&dev->ports[ SAA7164_PORT_VBI1 ],
		&dev->ports[ SAA7164_PORT_VBI1 ].read_interval);
	saa7164_histogram_print(&dev->ports[ SAA7164_PORT_VBI2 ],
		&dev->ports[ SAA7164_PORT_VBI2 ].poll_interval);

	saa7164_shutdown(dev);

@@ -1159,6 +1284,12 @@ static void __devexit saa7164_finidev(struct pci_dev *pci_dev)
	if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER)
		saa7164_encoder_unregister(&dev->ports[ SAA7164_PORT_ENC2 ]);

	if (saa7164_boards[dev->board].porte == SAA7164_MPEG_VBI)
		saa7164_vbi_unregister(&dev->ports[ SAA7164_PORT_VBI1 ]);

	if (saa7164_boards[dev->board].portf == SAA7164_MPEG_VBI)
		saa7164_vbi_unregister(&dev->ports[ SAA7164_PORT_VBI2 ]);

	saa7164_i2c_unregister(&dev->i2c_bus[0]);
	saa7164_i2c_unregister(&dev->i2c_bus[1]);
	saa7164_i2c_unregister(&dev->i2c_bus[2]);
+2 −0
Original line number Diff line number Diff line
@@ -156,6 +156,8 @@
#define EXU_INTERRUPT_CONTROL		0x03

/* State Transition and args */
#define SAA_PROBE_CONTROL	0x01
#define SAA_COMMIT_CONTROL	0x02
#define SAA_STATE_CONTROL	0x03
#define SAA_DMASTATE_STOP	0x00
#define SAA_DMASTATE_ACQUIRE	0x01
Loading