Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d8c2ba1 authored by Palash Bandyopadhyay's avatar Palash Bandyopadhyay Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB: cx25821: Removed duplicate code and cleaned up

parent fab81259
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
cx25821-objs	:= cx25821-core.o cx25821-cards.o cx25821-i2c.o cx25821-gpio.o 				\
				cx25821-medusa-video.o cx25821-video.o cx25821-video0.o cx25821-video1.o    \
				cx25821-video2.o cx25821-video3.o cx25821-video4.o cx25821-video5.o         \
				cx25821-video6.o cx25821-video7.o cx25821-vidups9.o cx25821-vidups10.o      \
				cx25821-audups11.o cx25821-video-upstream.o cx25821-video-upstream-ch2.o 	\
				cx25821-audio-upstream.o cx25821-videoioctl.o
cx25821-objs   := cx25821-core.o cx25821-cards.o cx25821-i2c.o \
                       cx25821-gpio.o cx25821-medusa-video.o \
                       cx25821-video.o cx25821-video-upstream.o \
                       cx25821-video-upstream-ch2.o \
                       cx25821-audio-upstream.o

obj-$(CONFIG_VIDEO_CX25821) += cx25821.o
obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o
+9 −7
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ static __le32 *cx25821_risc_field_upstream_audio(struct cx25821_dev *dev,
{
	unsigned int line;
	struct sram_channel *sram_ch =
	    &dev->sram_channels[dev->_audio_upstream_channel_select];
           dev->channels[dev->_audio_upstream_channel_select].sram_channels;
	int offset = 0;

	/* scan lines */
@@ -217,7 +217,7 @@ void cx25821_free_memory_audio(struct cx25821_dev *dev)
void cx25821_stop_upstream_audio(struct cx25821_dev *dev)
{
	struct sram_channel *sram_ch =
	    &dev->sram_channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B];
           dev->channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B].sram_channels;
	u32 tmp = 0;

	if (!dev->_audio_is_running) {
@@ -353,8 +353,9 @@ static void cx25821_audioups_handler(struct work_struct *work)
	}

	cx25821_get_audio_data(dev,
			       &dev->sram_channels[dev->
						   _audio_upstream_channel_select]);
                              dev->channels[dev->
                                       _audio_upstream_channel_select].
                                       sram_channels);
}

int cx25821_openfile_audio(struct cx25821_dev *dev,
@@ -505,7 +506,7 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
{
	int i = 0;
	u32 int_msk_tmp;
	struct sram_channel *channel = &dev->sram_channels[chan_num];
       struct sram_channel *channel = dev->channels[chan_num].sram_channels;
	dma_addr_t risc_phys_jump_addr;
	__le32 *rp;

@@ -607,7 +608,8 @@ static irqreturn_t cx25821_upstream_irq_audio(int irq, void *dev_id)
	if (!dev)
		return -1;

	sram_ch = &dev->sram_channels[dev->_audio_upstream_channel_select];
       sram_ch = dev->channels[dev->_audio_upstream_channel_select].
                                       sram_channels;

	msk_stat = cx_read(sram_ch->int_mstat);
	audio_status = cx_read(sram_ch->int_stat);
@@ -731,7 +733,7 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
	}

	dev->_audio_upstream_channel_select = channel_select;
	sram_ch = &dev->sram_channels[channel_select];
       sram_ch = dev->channels[channel_select].sram_channels;

	/* Work queue */
	INIT_WORK(&dev->_audio_work_entry, cx25821_audioups_handler);
+7 −6
Original line number Diff line number Diff line
@@ -27,24 +27,25 @@
#define LINES_PER_BUFFER            15
#define AUDIO_LINE_SIZE             128

//Number of buffer programs to use at once.
/* Number of buffer programs to use at once. */
#define NUMBER_OF_PROGRAMS  8

//Max size of the RISC program for a buffer. - worst case is 2 writes per line
// Space is also added for the 4 no-op instructions added on the end.

/*
  Max size of the RISC program for a buffer. - worst case is 2 writes per line
  Space is also added for the 4 no-op instructions added on the end.
*/
#ifndef USE_RISC_NOOP
#define MAX_BUFFER_PROGRAM_SIZE     \
    (2*LINES_PER_BUFFER*RISC_WRITE_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE*4)
#endif

// MAE 12 July 2005 Try to use NOOP RISC instruction instead
/* MAE 12 July 2005 Try to use NOOP RISC instruction instead */
#ifdef USE_RISC_NOOP
#define MAX_BUFFER_PROGRAM_SIZE     \
    (2*LINES_PER_BUFFER*RISC_WRITE_INSTRUCTION_SIZE + RISC_NOOP_INSTRUCTION_SIZE*4)
#endif

//Sizes of various instructions in bytes.  Used when adding instructions.
/* Sizes of various instructions in bytes.  Used when adding instructions. */
#define RISC_WRITE_INSTRUCTION_SIZE 12
#define RISC_JUMP_INSTRUCTION_SIZE  12
#define RISC_SKIP_INSTRUCTION_SIZE  4
+0 −420
Original line number Diff line number Diff line
/*
 *  Driver for the Conexant CX25821 PCIe bridge
 *
 *  Copyright (C) 2009 Conexant Systems Inc.
 *  Authors  <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
 *  Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
 *
 *  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 <linux/slab.h>

#include "cx25821-video.h"

static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
{
	struct cx25821_buffer *buf =
	    container_of(vb, struct cx25821_buffer, vb);
	struct cx25821_buffer *prev;
	struct cx25821_fh *fh = vq->priv_data;
	struct cx25821_dev *dev = fh->dev;
	struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH11];

	/* add jump to stopper */
	buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
	buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
	buf->risc.jmp[2] = cpu_to_le32(0);	/* bits 63-32 */

	dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);

	if (!list_empty(&q->queued)) {
		list_add_tail(&buf->vb.queue, &q->queued);
		buf->vb.state = VIDEOBUF_QUEUED;
		dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
			buf->vb.i);

	} else if (list_empty(&q->active)) {
		list_add_tail(&buf->vb.queue, &q->active);
		cx25821_start_video_dma(dev, q, buf,
					&dev->sram_channels[SRAM_CH11]);
		buf->vb.state = VIDEOBUF_ACTIVE;
		buf->count = q->count++;
		mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
		dprintk(2,
			"[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
			buf, buf->vb.i, buf->count, q->count);
	} else {
		prev =
		    list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
		if (prev->vb.width == buf->vb.width
		    && prev->vb.height == buf->vb.height
		    && prev->fmt == buf->fmt) {
			list_add_tail(&buf->vb.queue, &q->active);
			buf->vb.state = VIDEOBUF_ACTIVE;
			buf->count = q->count++;
			prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);

			/* 64 bit bits 63-32 */
			prev->risc.jmp[2] = cpu_to_le32(0);
			dprintk(2,
				"[%p/%d] buffer_queue - append to active, buf->count=%d\n",
				buf, buf->vb.i, buf->count);

		} else {
			list_add_tail(&buf->vb.queue, &q->queued);
			buf->vb.state = VIDEOBUF_QUEUED;
			dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
				buf->vb.i);
		}
	}

	if (list_empty(&q->active)) {
		dprintk(2, "active queue empty!\n");
	}
}

static struct videobuf_queue_ops cx25821_video_qops = {
	.buf_setup = cx25821_buffer_setup,
	.buf_prepare = cx25821_buffer_prepare,
	.buf_queue = buffer_queue,
	.buf_release = cx25821_buffer_release,
};

static int video_open(struct file *file)
{
	struct video_device *vdev = video_devdata(file);
	struct cx25821_dev *dev = video_drvdata(file);
	struct cx25821_fh *fh;
	enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

	printk("open dev=%s type=%s\n", video_device_node_name(vdev),
		v4l2_type_names[type]);

	/* allocate + initialize per filehandle data */
	fh = kzalloc(sizeof(*fh), GFP_KERNEL);
	if (NULL == fh)
		return -ENOMEM;

	lock_kernel();

	file->private_data = fh;
	fh->dev = dev;
	fh->type = type;
	fh->width = 720;

	if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
		fh->height = 576;
	else
		fh->height = 480;

	dev->channel_opened = 10;
	fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);

	v4l2_prio_open(&dev->prio, &fh->prio);

	videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
			       &dev->pci->dev, &dev->slock,
			       V4L2_BUF_TYPE_VIDEO_CAPTURE,
			       V4L2_FIELD_INTERLACED,
			       sizeof(struct cx25821_buffer), fh);

	dprintk(1, "post videobuf_queue_init()\n");
	unlock_kernel();

	return 0;
}

static ssize_t video_read(struct file *file, char __user * data, size_t count,
			  loff_t * ppos)
{
	struct cx25821_fh *fh = file->private_data;

	switch (fh->type) {
	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
		if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO11))
			return -EBUSY;

		return videobuf_read_one(&fh->vidq, data, count, ppos,
					 file->f_flags & O_NONBLOCK);

	default:
		BUG();
		return 0;
	}
}

static unsigned int video_poll(struct file *file,
			       struct poll_table_struct *wait)
{
	struct cx25821_fh *fh = file->private_data;
	struct cx25821_buffer *buf;

	if (cx25821_res_check(fh, RESOURCE_VIDEO11)) {
		/* streaming capture */
		if (list_empty(&fh->vidq.stream))
			return POLLERR;
		buf = list_entry(fh->vidq.stream.next,
				 struct cx25821_buffer, vb.stream);
	} else {
		/* read() capture */
		buf = (struct cx25821_buffer *)fh->vidq.read_buf;
		if (NULL == buf)
			return POLLERR;
	}

	poll_wait(file, &buf->vb.done, wait);
	if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
		return POLLIN | POLLRDNORM;
	return 0;
}

static int video_release(struct file *file)
{
	struct cx25821_fh *fh = file->private_data;
	struct cx25821_dev *dev = fh->dev;

	//stop the risc engine and fifo
	//cx_write(channel11->dma_ctl, 0);

	/* stop video capture */
	if (cx25821_res_check(fh, RESOURCE_VIDEO11)) {
		videobuf_queue_cancel(&fh->vidq);
		cx25821_res_free(dev, fh, RESOURCE_VIDEO11);
	}

	if (fh->vidq.read_buf) {
		cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
		kfree(fh->vidq.read_buf);
	}

	videobuf_mmap_free(&fh->vidq);

	v4l2_prio_close(&dev->prio, fh->prio);

	file->private_data = NULL;
	kfree(fh);

	return 0;
}

static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
{
	struct cx25821_fh *fh = priv;
	struct cx25821_dev *dev = fh->dev;

	if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
		return -EINVAL;
	}

	if (unlikely(i != fh->type)) {
		return -EINVAL;
	}

	if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO11)))) {
		return -EBUSY;
	}

	return videobuf_streamon(get_queue(fh));
}

static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
{
	struct cx25821_fh *fh = priv;
	struct cx25821_dev *dev = fh->dev;
	int err, res;

	if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
		return -EINVAL;
	if (i != fh->type)
		return -EINVAL;

	res = cx25821_get_resource(fh, RESOURCE_VIDEO11);
	err = videobuf_streamoff(get_queue(fh));
	if (err < 0)
		return err;
	cx25821_res_free(dev, fh, res);
	return 0;
}

static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
				struct v4l2_format *f)
{
	struct cx25821_fh *fh = priv;
	struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
	int err;

	if (fh) {
		err = v4l2_prio_check(&dev->prio, fh->prio);
		if (0 != err)
			return err;
	}

	dprintk(2, "%s()\n", __func__);
	err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);

	if (0 != err)
		return err;
	fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
	fh->width = f->fmt.pix.width;
	fh->height = f->fmt.pix.height;
	fh->vidq.field = f->fmt.pix.field;
	dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
		fh->height, fh->vidq.field);
	cx25821_call_all(dev, video, s_fmt, f);
	return 0;
}

static long video_ioctl_upstream11(struct file *file, unsigned int cmd,
				   unsigned long arg)
{
	struct cx25821_fh *fh = file->private_data;
	struct cx25821_dev *dev = fh->dev;
	int command = 0;
	struct upstream_user_struct *data_from_user;

	data_from_user = (struct upstream_user_struct *)arg;

	if (!data_from_user) {
		printk
		    ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
		     __func__);
		return 0;
	}

	command = data_from_user->command;

	if (command != UPSTREAM_START_AUDIO && command != UPSTREAM_STOP_AUDIO) {
		return 0;
	}

	dev->input_filename = data_from_user->input_filename;
	dev->input_audiofilename = data_from_user->input_filename;
	dev->vid_stdname = data_from_user->vid_stdname;
	dev->pixel_format = data_from_user->pixel_format;
	dev->channel_select = data_from_user->channel_select;
	dev->command = data_from_user->command;

	switch (command) {
	case UPSTREAM_START_AUDIO:
		cx25821_start_upstream_audio(dev, data_from_user);
		break;

	case UPSTREAM_STOP_AUDIO:
		cx25821_stop_upstream_audio(dev);
		break;
	}

	return 0;
}

static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
{
	struct cx25821_fh *fh = priv;
	return videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
}

static int vidioc_log_status(struct file *file, void *priv)
{
	struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
	char name[32 + 2];

	snprintf(name, sizeof(name), "%s/2", dev->name);
	printk(KERN_INFO "%s/2: ============  START LOG STATUS  ============\n",
	       dev->name);
	cx25821_call_all(dev, core, log_status);
	printk(KERN_INFO "%s/2: =============  END LOG STATUS  =============\n",
	       dev->name);
	return 0;
}

static int vidioc_s_ctrl(struct file *file, void *priv,
			 struct v4l2_control *ctl)
{
	struct cx25821_fh *fh = priv;
	struct cx25821_dev *dev;
	int err;

	if (fh) {
		dev = fh->dev;
		err = v4l2_prio_check(&dev->prio, fh->prio);
		if (0 != err)
			return err;
	}
	return 0;
}

// exported stuff
static const struct v4l2_file_operations video_fops = {
	.owner = THIS_MODULE,
	.open = video_open,
	.release = video_release,
	.read = video_read,
	.poll = video_poll,
	.mmap = cx25821_video_mmap,
	.ioctl = video_ioctl_upstream11,
};

static const struct v4l2_ioctl_ops video_ioctl_ops = {
	.vidioc_querycap = cx25821_vidioc_querycap,
	.vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
	.vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
	.vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
	.vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
	.vidioc_reqbufs = cx25821_vidioc_reqbufs,
	.vidioc_querybuf = cx25821_vidioc_querybuf,
	.vidioc_qbuf = cx25821_vidioc_qbuf,
	.vidioc_dqbuf = vidioc_dqbuf,
#ifdef TUNER_FLAG
	.vidioc_s_std = cx25821_vidioc_s_std,
	.vidioc_querystd = cx25821_vidioc_querystd,
#endif
	.vidioc_cropcap = cx25821_vidioc_cropcap,
	.vidioc_s_crop = cx25821_vidioc_s_crop,
	.vidioc_g_crop = cx25821_vidioc_g_crop,
	.vidioc_enum_input = cx25821_vidioc_enum_input,
	.vidioc_g_input = cx25821_vidioc_g_input,
	.vidioc_s_input = cx25821_vidioc_s_input,
	.vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
	.vidioc_s_ctrl = vidioc_s_ctrl,
	.vidioc_queryctrl = cx25821_vidioc_queryctrl,
	.vidioc_streamon = vidioc_streamon,
	.vidioc_streamoff = vidioc_streamoff,
	.vidioc_log_status = vidioc_log_status,
	.vidioc_g_priority = cx25821_vidioc_g_priority,
	.vidioc_s_priority = cx25821_vidioc_s_priority,
#ifdef CONFIG_VIDEO_V4L1_COMPAT
	.vidiocgmbuf = cx25821_vidiocgmbuf,
#endif
#ifdef TUNER_FLAG
	.vidioc_g_tuner = cx25821_vidioc_g_tuner,
	.vidioc_s_tuner = cx25821_vidioc_s_tuner,
	.vidioc_g_frequency = cx25821_vidioc_g_frequency,
	.vidioc_s_frequency = cx25821_vidioc_s_frequency,
#endif
#ifdef CONFIG_VIDEO_ADV_DEBUG
	.vidioc_g_register = cx25821_vidioc_g_register,
	.vidioc_s_register = cx25821_vidioc_s_register,
#endif
};

struct video_device cx25821_video_template11 = {
	.name = "cx25821-audioupstream",
	.fops = &video_fops,
	.ioctl_ops = &video_ioctl_ops,
	.tvnorms = CX25821_NORMS,
	.current_norm = V4L2_STD_NTSC_M,
};
+28 −56
Original line number Diff line number Diff line
@@ -781,14 +781,14 @@ static void cx25821_shutdown(struct cx25821_dev *dev)

	/* Disable Video A/B activity */
	for (i = 0; i < VID_CHANNEL_NUM; i++) {
		cx_write(dev->sram_channels[i].dma_ctl, 0);
		cx_write(dev->sram_channels[i].int_msk, 0);
               cx_write(dev->channels[i].sram_channels->dma_ctl, 0);
               cx_write(dev->channels[i].sram_channels->int_msk, 0);
	}

	for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J;
	     i++) {
		cx_write(dev->sram_channels[i].dma_ctl, 0);
		cx_write(dev->sram_channels[i].int_msk, 0);
               cx_write(dev->channels[i].sram_channels->dma_ctl, 0);
               cx_write(dev->channels[i].sram_channels->int_msk, 0);
	}

	/* Disable Audio activity */
@@ -805,12 +805,10 @@ static void cx25821_shutdown(struct cx25821_dev *dev)
void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel_select,
			      u32 format)
{
	struct sram_channel *ch;

	if (channel_select <= 7 && channel_select >= 0) {
		ch = &cx25821_sram_channels[channel_select];
		cx_write(ch->pix_frmt, format);
		dev->pixel_formats[channel_select] = format;
               cx_write(dev->channels[channel_select].
                               sram_channels->pix_frmt, format);
               dev->channels[channel_select].pixel_formats = format;
	}
}

@@ -831,7 +829,7 @@ static void cx25821_initialize(struct cx25821_dev *dev)
	cx_write(PCI_INT_STAT, 0xffffffff);

	for (i = 0; i < VID_CHANNEL_NUM; i++)
		cx_write(dev->sram_channels[i].int_stat, 0xffffffff);
               cx_write(dev->channels[i].sram_channels->int_stat, 0xffffffff);

	cx_write(AUD_A_INT_STAT, 0xffffffff);
	cx_write(AUD_B_INT_STAT, 0xffffffff);
@@ -845,20 +843,21 @@ static void cx25821_initialize(struct cx25821_dev *dev)
	mdelay(100);

	for (i = 0; i < VID_CHANNEL_NUM; i++) {
		cx25821_set_vip_mode(dev, &dev->sram_channels[i]);
		cx25821_sram_channel_setup(dev, &dev->sram_channels[i], 1440,
					   0);
		dev->pixel_formats[i] = PIXEL_FRMT_422;
		dev->use_cif_resolution[i] = FALSE;
               cx25821_set_vip_mode(dev, dev->channels[i].sram_channels);
               cx25821_sram_channel_setup(dev, dev->channels[i].sram_channels,
                                               1440, 0);
               dev->channels[i].pixel_formats = PIXEL_FRMT_422;
               dev->channels[i].use_cif_resolution = FALSE;
	}

	/* Probably only affect Downstream */
	for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J;
	     i++) {
		cx25821_set_vip_mode(dev, &dev->sram_channels[i]);
               cx25821_set_vip_mode(dev, dev->channels[i].sram_channels);
	}

	cx25821_sram_channel_setup_audio(dev, &dev->sram_channels[SRAM_CH08],
       cx25821_sram_channel_setup_audio(dev,
                               dev->channels[SRAM_CH08].sram_channels,
                               128, 0);

	cx25821_gpio_init(dev);
@@ -902,21 +901,6 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
{
	int io_size = 0, i;

	struct video_device *video_template[] = {
		&cx25821_video_template0,
		&cx25821_video_template1,
		&cx25821_video_template2,
		&cx25821_video_template3,
		&cx25821_video_template4,
		&cx25821_video_template5,
		&cx25821_video_template6,
		&cx25821_video_template7,
		&cx25821_video_template9,
		&cx25821_video_template10,
		&cx25821_video_template11,
		&cx25821_videoioctl_template,
	};

	printk(KERN_INFO "\n***********************************\n");
	printk(KERN_INFO "cx25821 set up\n");
	printk(KERN_INFO "***********************************\n\n");
@@ -947,7 +931,8 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)

	/* Apply a sensible clock frequency for the PCIe bridge */
	dev->clk_freq = 28000000;
	dev->sram_channels = cx25821_sram_channels;
       for (i = 0; i < MAX_VID_CHANNEL_NUM; i++)
               dev->channels[i].sram_channels = &cx25821_sram_channels[i];

	if (dev->nr > 1)
		CX25821_INFO("dev->nr > 1!");
@@ -970,7 +955,6 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
	dev->i2c_bus[0].reg_wdata = I2C1_WDATA;
	dev->i2c_bus[0].i2c_period = (0x07 << 24);	/* 1.95MHz */


	if (cx25821_get_resources(dev) < 0) {
		printk(KERN_ERR "%s No more PCIe resources for "
		       "subsystem: %04x:%04x\n",
@@ -1018,37 +1002,24 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
		     dev->i2c_bus[0].i2c_rc);

	cx25821_card_setup(dev);
	medusa_video_init(dev);

	for (i = 0; i < VID_CHANNEL_NUM; i++) {
		if (cx25821_video_register(dev, i, video_template[i]) < 0) {
			printk(KERN_ERR
			       "%s() Failed to register analog video adapters on VID channel %d\n",
			       __func__, i);
		}
	}
       if (medusa_video_init(dev) < 0)
               CX25821_ERR("%s() Failed to initialize medusa!\n"
               , __func__);

	for (i = VID_UPSTREAM_SRAM_CHANNEL_I;
	     i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++) {
		/* Since we don't have template8 for Audio Downstream */
		if (cx25821_video_register(dev, i, video_template[i - 1]) < 0) {
			printk(KERN_ERR
			       "%s() Failed to register analog video adapters for Upstream channel %d.\n",
			       __func__, i);
		}
	}
       cx25821_video_register(dev);

	/* register IOCTL device */
	dev->ioctl_dev =
	    cx25821_vdev_init(dev, dev->pci, video_template[VIDEO_IOCTL_CH],
           cx25821_vdev_init(dev, dev->pci, &cx25821_videoioctl_template,
			      "video");

	if (video_register_device
	    (dev->ioctl_dev, VFL_TYPE_GRABBER, VIDEO_IOCTL_CH) < 0) {
		cx25821_videoioctl_unregister(dev);
		printk(KERN_ERR
		       "%s() Failed to register video adapter for IOCTL so releasing.\n",
		       __func__);
                   "%s() Failed to register video adapter for IOCTL, so \
                   unregistering videoioctl device.\n", __func__);
	}

	cx25821_dev_checkrevision(dev);
@@ -1371,7 +1342,8 @@ static irqreturn_t cx25821_irq(int irq, void *dev_id)

	for (i = 0; i < VID_CHANNEL_NUM; i++) {
		if (pci_status & mask[i]) {
			vid_status = cx_read(dev->sram_channels[i].int_stat);
                       vid_status = cx_read(dev->channels[i].
                               sram_channels->int_stat);

			if (vid_status)
				handled +=
Loading