2009-09-15 22:33:54 +08:00
|
|
|
/*
|
|
|
|
* Driver for the Conexant CX25821 PCIe bridge
|
|
|
|
*
|
2009-09-13 22:25:45 +08:00
|
|
|
* Copyright (C) 2009 Conexant Systems Inc.
|
2009-09-15 22:33:54 +08:00
|
|
|
* Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
|
|
|
|
* Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
|
2010-07-05 01:15:38 +08:00
|
|
|
* Parts adapted/taken from Eduardo Moscoso Rubino
|
|
|
|
* Copyright (C) 2009 Eduardo Moscoso Rubino <moscoso@TopoLogica.com>
|
|
|
|
*
|
2009-09-15 22:33:54 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-11-08 04:48:21 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2009-09-15 22:33:54 +08:00
|
|
|
#include "cx25821-video.h"
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
|
2010-07-05 01:15:38 +08:00
|
|
|
MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
|
2009-09-15 22:33:54 +08:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2009-09-13 22:39:12 +08:00
|
|
|
static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
module_param_array(video_nr, int, NULL, 0444);
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(video_nr, "video device numbers");
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
static unsigned int video_debug = VIDEO_DEBUG;
|
2009-09-15 22:33:54 +08:00
|
|
|
module_param(video_debug, int, 0644);
|
|
|
|
MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
|
|
|
|
|
|
|
|
static unsigned int irq_debug;
|
|
|
|
module_param(irq_debug, int, 0644);
|
|
|
|
MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static unsigned int vid_limit = 16;
|
2009-09-15 22:33:54 +08:00
|
|
|
module_param(vid_limit, int, 0644);
|
|
|
|
MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
|
|
|
|
|
|
|
|
#define FORMAT_FLAGS_PACKED 0x01
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static const struct cx25821_fmt formats[] = {
|
2009-09-13 22:30:11 +08:00
|
|
|
{
|
2010-03-25 01:23:25 +08:00
|
|
|
.name = "4:1:1, packed, Y41P",
|
|
|
|
.fourcc = V4L2_PIX_FMT_Y41P,
|
|
|
|
.depth = 12,
|
|
|
|
.flags = FORMAT_FLAGS_PACKED,
|
|
|
|
}, {
|
|
|
|
.name = "4:2:2, packed, YUYV",
|
|
|
|
.fourcc = V4L2_PIX_FMT_YUYV,
|
|
|
|
.depth = 16,
|
|
|
|
.flags = FORMAT_FLAGS_PACKED,
|
|
|
|
},
|
2009-09-15 22:33:54 +08:00
|
|
|
};
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static const struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2009-09-13 22:30:11 +08:00
|
|
|
unsigned int i;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(formats); i++)
|
|
|
|
if (formats[i].fourcc == fourcc)
|
|
|
|
return formats + i;
|
|
|
|
return NULL;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q,
|
|
|
|
u32 count)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2009-09-13 22:30:11 +08:00
|
|
|
struct cx25821_buffer *buf;
|
|
|
|
int bc;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
for (bc = 0;; bc++) {
|
|
|
|
if (list_empty(&q->active)) {
|
|
|
|
dprintk(1, "bc=%d (=0: active empty)\n", bc);
|
|
|
|
break;
|
|
|
|
}
|
2009-09-13 22:25:45 +08:00
|
|
|
|
2011-10-22 12:43:55 +08:00
|
|
|
buf = list_entry(q->active.next, struct cx25821_buffer,
|
|
|
|
vb.queue);
|
2009-09-13 22:25:45 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
/* count comes from the hw and it is 16bit wide --
|
|
|
|
* this trick handles wrap-arounds correctly for
|
|
|
|
* up to 32767 buffers in flight... */
|
2011-09-16 14:15:13 +08:00
|
|
|
if ((s16) (count - buf->count) < 0)
|
2009-09-13 22:30:11 +08:00
|
|
|
break;
|
2009-09-13 22:25:45 +08:00
|
|
|
|
2012-09-16 02:14:42 +08:00
|
|
|
v4l2_get_timestamp(&buf->vb.ts);
|
2009-09-13 22:30:11 +08:00
|
|
|
buf->vb.state = VIDEOBUF_DONE;
|
|
|
|
list_del(&buf->vb.queue);
|
|
|
|
wake_up(&buf->vb.done);
|
|
|
|
}
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
if (list_empty(&q->active))
|
|
|
|
del_timer(&q->timeout);
|
|
|
|
else
|
|
|
|
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
|
|
|
|
if (bc != 1)
|
2011-09-16 14:14:36 +08:00
|
|
|
pr_err("%s: %d buffers handled (should be 1)\n", __func__, bc);
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int cx25821_start_video_dma(struct cx25821_dev *dev,
|
2009-09-13 22:30:11 +08:00
|
|
|
struct cx25821_dmaqueue *q,
|
|
|
|
struct cx25821_buffer *buf,
|
2013-04-13 17:28:54 +08:00
|
|
|
const struct sram_channel *channel)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2009-09-13 22:30:11 +08:00
|
|
|
int tmp = 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
/* setup fifo + format */
|
|
|
|
cx25821_sram_channel_setup(dev, channel, buf->bpl, buf->risc.dma);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
/* reset counter */
|
|
|
|
cx_write(channel->gpcnt_ctl, 3);
|
|
|
|
q->count = 1;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
/* enable irq */
|
|
|
|
cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i));
|
|
|
|
cx_set(channel->int_msk, 0x11);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
/* start dma */
|
|
|
|
cx_write(channel->dma_ctl, 0x11); /* FIFO and RISC enable */
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
/* make sure upstream setting if any is reversed */
|
|
|
|
tmp = cx_read(VID_CH_MODE_SEL);
|
|
|
|
cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
return 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2012-10-27 23:42:59 +08:00
|
|
|
static int cx25821_restart_video_queue(struct cx25821_dev *dev,
|
|
|
|
struct cx25821_dmaqueue *q,
|
2013-04-13 17:28:54 +08:00
|
|
|
const struct sram_channel *channel)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2009-09-13 22:30:11 +08:00
|
|
|
struct cx25821_buffer *buf, *prev;
|
|
|
|
struct list_head *item;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
if (!list_empty(&q->active)) {
|
2011-10-22 12:43:55 +08:00
|
|
|
buf = list_entry(q->active.next, struct cx25821_buffer,
|
|
|
|
vb.queue);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
cx25821_start_video_dma(dev, q, buf, channel);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
list_for_each(item, &q->active) {
|
|
|
|
buf = list_entry(item, struct cx25821_buffer, vb.queue);
|
|
|
|
buf->count = q->count++;
|
|
|
|
}
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
prev = NULL;
|
|
|
|
for (;;) {
|
|
|
|
if (list_empty(&q->queued))
|
|
|
|
return 0;
|
|
|
|
|
2011-10-22 12:43:55 +08:00
|
|
|
buf = list_entry(q->queued.next, struct cx25821_buffer,
|
|
|
|
vb.queue);
|
2009-09-13 22:30:11 +08:00
|
|
|
|
|
|
|
if (NULL == prev) {
|
|
|
|
list_move_tail(&buf->vb.queue, &q->active);
|
|
|
|
cx25821_start_video_dma(dev, q, buf, channel);
|
|
|
|
buf->vb.state = VIDEOBUF_ACTIVE;
|
|
|
|
buf->count = q->count++;
|
|
|
|
mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
|
|
|
|
} else if (prev->vb.width == buf->vb.width &&
|
|
|
|
prev->vb.height == buf->vb.height &&
|
|
|
|
prev->fmt == buf->fmt) {
|
|
|
|
list_move_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);
|
2011-09-16 14:14:38 +08:00
|
|
|
prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */
|
2009-09-13 22:30:11 +08:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
prev = buf;
|
2009-09-13 22:25:45 +08:00
|
|
|
}
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2012-10-27 23:42:59 +08:00
|
|
|
static void cx25821_vid_timeout(unsigned long data)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2009-09-13 22:30:11 +08:00
|
|
|
struct cx25821_data *timeout_data = (struct cx25821_data *)data;
|
|
|
|
struct cx25821_dev *dev = timeout_data->dev;
|
2013-04-13 17:28:54 +08:00
|
|
|
const struct sram_channel *channel = timeout_data->channel;
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_dmaqueue *q = &dev->channels[channel->i].dma_vidq;
|
2009-09-13 22:30:11 +08:00
|
|
|
struct cx25821_buffer *buf;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-09-16 14:14:38 +08:00
|
|
|
/* cx25821_sram_channel_dump(dev, channel); */
|
2009-09-13 22:30:11 +08:00
|
|
|
cx_clear(channel->dma_ctl, 0x11);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->slock, flags);
|
|
|
|
while (!list_empty(&q->active)) {
|
2011-10-22 12:43:55 +08:00
|
|
|
buf = list_entry(q->active.next, struct cx25821_buffer,
|
|
|
|
vb.queue);
|
2009-09-13 22:30:11 +08:00
|
|
|
list_del(&buf->vb.queue);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
buf->vb.state = VIDEOBUF_ERROR;
|
|
|
|
wake_up(&buf->vb.done);
|
|
|
|
}
|
|
|
|
|
|
|
|
cx25821_restart_video_queue(dev, q, channel);
|
|
|
|
spin_unlock_irqrestore(&dev->slock, flags);
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
|
|
|
|
{
|
2009-09-13 22:30:11 +08:00
|
|
|
u32 count = 0;
|
|
|
|
int handled = 0;
|
|
|
|
u32 mask;
|
2013-04-13 17:28:54 +08:00
|
|
|
const struct sram_channel *channel = dev->channels[chan_num].sram_channels;
|
2009-09-13 22:30:11 +08:00
|
|
|
|
|
|
|
mask = cx_read(channel->int_msk);
|
|
|
|
if (0 == (status & mask))
|
|
|
|
return handled;
|
|
|
|
|
|
|
|
cx_write(channel->int_stat, status);
|
|
|
|
|
|
|
|
/* risc op code error */
|
|
|
|
if (status & (1 << 16)) {
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_warn("%s, %s: video risc op code error\n",
|
|
|
|
dev->name, channel->name);
|
2009-09-13 22:30:11 +08:00
|
|
|
cx_clear(channel->dma_ctl, 0x11);
|
|
|
|
cx25821_sram_channel_dump(dev, channel);
|
|
|
|
}
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
/* risc1 y */
|
|
|
|
if (status & FLD_VID_DST_RISC1) {
|
|
|
|
spin_lock(&dev->slock);
|
|
|
|
count = cx_read(channel->gpcnt);
|
2013-04-13 21:00:52 +08:00
|
|
|
cx25821_video_wakeup(dev, &dev->channels[channel->i].dma_vidq,
|
2011-09-16 14:14:38 +08:00
|
|
|
count);
|
2009-09-13 22:30:11 +08:00
|
|
|
spin_unlock(&dev->slock);
|
|
|
|
handled++;
|
|
|
|
}
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
/* risc2 y */
|
|
|
|
if (status & 0x10) {
|
|
|
|
dprintk(2, "stopper video\n");
|
|
|
|
spin_lock(&dev->slock);
|
2011-09-16 14:14:39 +08:00
|
|
|
cx25821_restart_video_queue(dev,
|
2013-04-13 21:00:52 +08:00
|
|
|
&dev->channels[channel->i].dma_vidq, channel);
|
2009-09-13 22:30:11 +08:00
|
|
|
spin_unlock(&dev->slock);
|
|
|
|
handled++;
|
|
|
|
}
|
|
|
|
return handled;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count,
|
2009-09-13 22:30:11 +08:00
|
|
|
unsigned int *size)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = q->priv_data;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
*size = chan->fmt->depth * chan->width * chan->height >> 3;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
if (0 == *count)
|
|
|
|
*count = 32;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2010-03-22 03:02:45 +08:00
|
|
|
if (*size * *count > vid_limit * 1024 * 1024)
|
|
|
|
*count = (vid_limit * 1024 * 1024) / *size;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
return 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
|
2009-09-13 22:30:11 +08:00
|
|
|
enum v4l2_field field)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = q->priv_data;
|
|
|
|
struct cx25821_dev *dev = chan->dev;
|
2009-09-13 22:30:11 +08:00
|
|
|
struct cx25821_buffer *buf =
|
2011-10-22 12:43:54 +08:00
|
|
|
container_of(vb, struct cx25821_buffer, vb);
|
2009-09-13 22:30:11 +08:00
|
|
|
int rc, init_buffer = 0;
|
2012-04-20 17:26:19 +08:00
|
|
|
u32 line0_offset;
|
2009-09-13 22:30:11 +08:00
|
|
|
struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
|
|
|
|
int bpl_local = LINE_SIZE_D1;
|
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
BUG_ON(NULL == chan->fmt);
|
|
|
|
if (chan->width < 48 || chan->width > 720 ||
|
|
|
|
chan->height < 32 || chan->height > 576)
|
2009-09-13 22:30:11 +08:00
|
|
|
return -EINVAL;
|
2009-09-13 22:25:45 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
buf->vb.size = (chan->width * chan->height * chan->fmt->depth) >> 3;
|
2009-09-13 22:25:45 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
|
|
|
|
return -EINVAL;
|
2009-09-13 22:25:45 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
if (buf->fmt != chan->fmt ||
|
|
|
|
buf->vb.width != chan->width ||
|
|
|
|
buf->vb.height != chan->height || buf->vb.field != field) {
|
|
|
|
buf->fmt = chan->fmt;
|
|
|
|
buf->vb.width = chan->width;
|
|
|
|
buf->vb.height = chan->height;
|
2009-09-13 22:30:11 +08:00
|
|
|
buf->vb.field = field;
|
|
|
|
init_buffer = 1;
|
2009-09-13 22:25:45 +08:00
|
|
|
}
|
2009-09-13 22:30:11 +08:00
|
|
|
|
|
|
|
if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
|
|
|
|
init_buffer = 1;
|
|
|
|
rc = videobuf_iolock(q, &buf->vb, NULL);
|
|
|
|
if (0 != rc) {
|
2010-11-08 04:48:21 +08:00
|
|
|
printk(KERN_DEBUG pr_fmt("videobuf_iolock failed!\n"));
|
2009-09-13 22:30:11 +08:00
|
|
|
goto fail;
|
2009-09-13 22:25:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
dprintk(1, "init_buffer=%d\n", init_buffer);
|
|
|
|
|
|
|
|
if (init_buffer) {
|
2013-04-14 22:57:18 +08:00
|
|
|
if (chan->pixel_formats == PIXEL_FRMT_411)
|
2009-09-13 22:30:11 +08:00
|
|
|
buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3;
|
|
|
|
else
|
|
|
|
buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width);
|
|
|
|
|
2013-04-14 22:57:18 +08:00
|
|
|
if (chan->pixel_formats == PIXEL_FRMT_411) {
|
2009-09-13 22:30:11 +08:00
|
|
|
bpl_local = buf->bpl;
|
|
|
|
} else {
|
2011-09-16 14:14:43 +08:00
|
|
|
bpl_local = buf->bpl; /* Default */
|
2009-09-13 22:30:11 +08:00
|
|
|
|
2013-04-14 22:57:18 +08:00
|
|
|
if (chan->use_cif_resolution) {
|
2013-04-14 00:06:00 +08:00
|
|
|
if (dev->tvnorm & V4L2_STD_625_50)
|
2013-04-14 22:57:18 +08:00
|
|
|
bpl_local = 352 << 1;
|
|
|
|
else
|
|
|
|
bpl_local = chan->cif_width << 1;
|
2009-09-13 22:30:11 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-13 22:25:45 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
switch (buf->vb.field) {
|
|
|
|
case V4L2_FIELD_TOP:
|
|
|
|
cx25821_risc_buffer(dev->pci, &buf->risc,
|
|
|
|
dma->sglist, 0, UNSET,
|
|
|
|
buf->bpl, 0, buf->vb.height);
|
|
|
|
break;
|
|
|
|
case V4L2_FIELD_BOTTOM:
|
|
|
|
cx25821_risc_buffer(dev->pci, &buf->risc,
|
|
|
|
dma->sglist, UNSET, 0,
|
|
|
|
buf->bpl, 0, buf->vb.height);
|
|
|
|
break;
|
|
|
|
case V4L2_FIELD_INTERLACED:
|
|
|
|
/* All other formats are top field first */
|
|
|
|
line0_offset = 0;
|
|
|
|
dprintk(1, "top field first\n");
|
|
|
|
|
|
|
|
cx25821_risc_buffer(dev->pci, &buf->risc,
|
|
|
|
dma->sglist, line0_offset,
|
|
|
|
bpl_local, bpl_local, bpl_local,
|
|
|
|
buf->vb.height >> 1);
|
|
|
|
break;
|
|
|
|
case V4L2_FIELD_SEQ_TB:
|
|
|
|
cx25821_risc_buffer(dev->pci, &buf->risc,
|
|
|
|
dma->sglist,
|
|
|
|
0, buf->bpl * (buf->vb.height >> 1),
|
|
|
|
buf->bpl, 0, buf->vb.height >> 1);
|
|
|
|
break;
|
|
|
|
case V4L2_FIELD_SEQ_BT:
|
|
|
|
cx25821_risc_buffer(dev->pci, &buf->risc,
|
|
|
|
dma->sglist,
|
|
|
|
buf->bpl * (buf->vb.height >> 1), 0,
|
|
|
|
buf->bpl, 0, buf->vb.height >> 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
2009-09-13 22:25:45 +08:00
|
|
|
}
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
|
2013-04-13 21:00:52 +08:00
|
|
|
buf, buf->vb.i, chan->width, chan->height, chan->fmt->depth,
|
|
|
|
chan->fmt->name, (unsigned long)buf->risc.dma);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
buf->vb.state = VIDEOBUF_PREPARED;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
return 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2011-09-16 14:14:34 +08:00
|
|
|
fail:
|
2009-09-13 22:30:11 +08:00
|
|
|
cx25821_free_buffer(q, buf);
|
|
|
|
return rc;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static void cx25821_buffer_release(struct videobuf_queue *q,
|
2011-09-16 14:14:35 +08:00
|
|
|
struct videobuf_buffer *vb)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2009-09-13 22:30:11 +08:00
|
|
|
struct cx25821_buffer *buf =
|
2011-10-22 12:43:54 +08:00
|
|
|
container_of(vb, struct cx25821_buffer, vb);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
cx25821_free_buffer(q, buf);
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
return videobuf_mmap_mapper(&chan->vidq, vma);
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2010-07-05 01:15:38 +08:00
|
|
|
|
|
|
|
static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
|
|
|
|
{
|
2011-09-16 14:14:43 +08:00
|
|
|
struct cx25821_buffer *buf =
|
2011-10-22 12:43:54 +08:00
|
|
|
container_of(vb, struct cx25821_buffer, vb);
|
2011-09-16 14:14:44 +08:00
|
|
|
struct cx25821_buffer *prev;
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = vq->priv_data;
|
|
|
|
struct cx25821_dev *dev = chan->dev;
|
|
|
|
struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq;
|
2011-09-16 14:14:44 +08:00
|
|
|
|
|
|
|
/* 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);
|
2013-04-13 21:00:52 +08:00
|
|
|
cx25821_start_video_dma(dev, q, buf, chan->sram_channels);
|
2011-09-16 14:14:44 +08:00
|
|
|
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
|
2010-07-05 02:37:05 +08:00
|
|
|
&& prev->vb.height == buf->vb.height
|
|
|
|
&& prev->fmt == buf->fmt) {
|
2011-09-16 14:14:45 +08:00
|
|
|
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");
|
2010-07-05 01:15:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct videobuf_queue_ops cx25821_video_qops = {
|
2011-09-16 14:14:46 +08:00
|
|
|
.buf_setup = cx25821_buffer_setup,
|
|
|
|
.buf_prepare = cx25821_buffer_prepare,
|
|
|
|
.buf_queue = buffer_queue,
|
|
|
|
.buf_release = cx25821_buffer_release,
|
2010-07-05 01:15:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t video_read(struct file *file, char __user * data, size_t count,
|
2010-07-05 02:37:05 +08:00
|
|
|
loff_t *ppos)
|
2010-07-05 01:15:38 +08:00
|
|
|
{
|
2013-04-14 22:57:18 +08:00
|
|
|
struct v4l2_fh *fh = file->private_data;
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
2013-04-14 22:57:18 +08:00
|
|
|
struct cx25821_dev *dev = chan->dev;
|
2013-04-14 22:56:39 +08:00
|
|
|
int err = 0;
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2013-04-14 22:54:56 +08:00
|
|
|
if (mutex_lock_interruptible(&dev->lock))
|
|
|
|
return -ERESTARTSYS;
|
2013-04-14 22:56:39 +08:00
|
|
|
if (chan->streaming_fh && chan->streaming_fh != fh) {
|
2013-04-14 22:54:56 +08:00
|
|
|
err = -EBUSY;
|
2013-04-14 22:56:39 +08:00
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
chan->streaming_fh = fh;
|
|
|
|
|
|
|
|
err = videobuf_read_one(&chan->vidq, data, count, ppos,
|
2013-04-14 22:54:56 +08:00
|
|
|
file->f_flags & O_NONBLOCK);
|
2013-04-14 22:56:39 +08:00
|
|
|
unlock:
|
2013-04-14 22:54:56 +08:00
|
|
|
mutex_unlock(&dev->lock);
|
|
|
|
return err;
|
2010-07-05 01:15:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int video_poll(struct file *file,
|
2010-07-05 02:37:05 +08:00
|
|
|
struct poll_table_struct *wait)
|
2010-07-05 01:15:38 +08:00
|
|
|
{
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
2013-04-14 22:57:18 +08:00
|
|
|
unsigned long req_events = poll_requested_events(wait);
|
|
|
|
unsigned int res = v4l2_ctrl_poll(file, wait);
|
2011-09-16 14:14:50 +08:00
|
|
|
|
2013-04-14 22:57:18 +08:00
|
|
|
if (req_events & (POLLIN | POLLRDNORM))
|
|
|
|
res |= videobuf_poll_stream(file, &chan->vidq, wait);
|
|
|
|
return res;
|
2011-09-16 14:14:50 +08:00
|
|
|
|
2013-04-14 22:56:39 +08:00
|
|
|
/* This doesn't belong in poll(). This can be done
|
|
|
|
* much better with vb2. We keep this code here as a
|
|
|
|
* reminder.
|
|
|
|
if ((res & POLLIN) && buf->vb.state == VIDEOBUF_DONE) {
|
|
|
|
struct cx25821_dev *dev = chan->dev;
|
2010-07-05 02:37:05 +08:00
|
|
|
|
2013-04-14 22:56:39 +08:00
|
|
|
if (dev && chan->use_cif_resolution) {
|
|
|
|
u8 cam_id = *((char *)buf->vb.baddr + 3);
|
|
|
|
memcpy((char *)buf->vb.baddr,
|
|
|
|
(char *)buf->vb.baddr + (chan->width * 2),
|
|
|
|
(chan->width * 2));
|
|
|
|
*((char *)buf->vb.baddr + 3) = cam_id;
|
|
|
|
}
|
2011-09-16 14:14:50 +08:00
|
|
|
}
|
2013-04-14 22:56:39 +08:00
|
|
|
*/
|
2010-07-05 01:15:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int video_release(struct file *file)
|
|
|
|
{
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
2013-04-14 22:57:18 +08:00
|
|
|
struct v4l2_fh *fh = file->private_data;
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_dev *dev = chan->dev;
|
2013-04-13 17:28:54 +08:00
|
|
|
const struct sram_channel *sram_ch =
|
|
|
|
dev->channels[0].sram_channels;
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2013-04-14 22:53:35 +08:00
|
|
|
mutex_lock(&dev->lock);
|
2011-09-16 14:14:51 +08:00
|
|
|
/* stop the risc engine and fifo */
|
2013-04-13 17:28:54 +08:00
|
|
|
cx_write(sram_ch->dma_ctl, 0); /* FIFO and RISC disable */
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2011-09-16 14:14:51 +08:00
|
|
|
/* stop video capture */
|
2013-04-14 22:56:39 +08:00
|
|
|
if (chan->streaming_fh == fh) {
|
2013-04-13 21:00:52 +08:00
|
|
|
videobuf_queue_cancel(&chan->vidq);
|
2013-04-14 22:56:39 +08:00
|
|
|
chan->streaming_fh = NULL;
|
2011-09-16 14:14:51 +08:00
|
|
|
}
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
if (chan->vidq.read_buf) {
|
|
|
|
cx25821_buffer_release(&chan->vidq, chan->vidq.read_buf);
|
|
|
|
kfree(chan->vidq.read_buf);
|
2011-09-16 14:14:51 +08:00
|
|
|
}
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
videobuf_mmap_free(&chan->vidq);
|
2013-04-14 22:56:39 +08:00
|
|
|
mutex_unlock(&dev->lock);
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2013-04-14 22:57:18 +08:00
|
|
|
return v4l2_fh_release(file);
|
2010-07-05 01:15:38 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
/* VIDEO IOCTLS */
|
2013-04-14 18:13:02 +08:00
|
|
|
|
|
|
|
static int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_fmtdesc *f)
|
|
|
|
{
|
|
|
|
if (unlikely(f->index >= ARRAY_SIZE(formats)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
strlcpy(f->description, formats[f->index].name, sizeof(f->description));
|
|
|
|
f->pixelformat = formats[f->index].fourcc;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *f)
|
|
|
|
{
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
2013-04-13 18:41:29 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
f->fmt.pix.width = chan->width;
|
|
|
|
f->fmt.pix.height = chan->height;
|
|
|
|
f->fmt.pix.field = chan->vidq.field;
|
|
|
|
f->fmt.pix.pixelformat = chan->fmt->fourcc;
|
2013-04-14 00:06:00 +08:00
|
|
|
f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3;
|
|
|
|
f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline;
|
|
|
|
f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
|
|
|
|
f->fmt.pix.priv = 0;
|
2013-04-13 18:41:29 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *f)
|
|
|
|
{
|
2013-04-14 00:06:00 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
struct cx25821_dev *dev = chan->dev;
|
2013-04-13 18:41:29 +08:00
|
|
|
const struct cx25821_fmt *fmt;
|
2013-04-14 00:06:00 +08:00
|
|
|
enum v4l2_field field = f->fmt.pix.field;
|
2013-04-13 18:41:29 +08:00
|
|
|
unsigned int maxw, maxh;
|
2013-04-14 00:06:00 +08:00
|
|
|
unsigned w;
|
2013-04-13 18:41:29 +08:00
|
|
|
|
|
|
|
fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
|
|
|
|
if (NULL == fmt)
|
|
|
|
return -EINVAL;
|
|
|
|
maxw = 720;
|
2013-04-14 00:06:00 +08:00
|
|
|
maxh = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480;
|
|
|
|
|
|
|
|
w = f->fmt.pix.width;
|
|
|
|
if (field != V4L2_FIELD_BOTTOM)
|
|
|
|
field = V4L2_FIELD_TOP;
|
|
|
|
if (w < 352) {
|
|
|
|
w = 176;
|
|
|
|
f->fmt.pix.height = maxh / 4;
|
|
|
|
} else if (w < 720) {
|
|
|
|
w = 352;
|
|
|
|
f->fmt.pix.height = maxh / 2;
|
|
|
|
} else {
|
|
|
|
w = 720;
|
|
|
|
f->fmt.pix.height = maxh;
|
|
|
|
field = V4L2_FIELD_INTERLACED;
|
2013-04-13 18:41:29 +08:00
|
|
|
}
|
|
|
|
f->fmt.pix.field = field;
|
2013-04-14 00:06:00 +08:00
|
|
|
f->fmt.pix.width = w;
|
2013-04-13 18:41:29 +08:00
|
|
|
f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
|
|
|
|
f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
|
2013-04-14 00:06:00 +08:00
|
|
|
f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
|
|
|
|
f->fmt.pix.priv = 0;
|
2013-04-13 18:41:29 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-05 01:15:38 +08:00
|
|
|
|
|
|
|
static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
|
2011-09-16 14:14:35 +08:00
|
|
|
struct v4l2_format *f)
|
2010-07-05 01:15:38 +08:00
|
|
|
{
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
2013-04-14 22:57:18 +08:00
|
|
|
struct cx25821_dev *dev = chan->dev;
|
2011-09-16 14:14:54 +08:00
|
|
|
int pix_format = PIXEL_FRMT_422;
|
2013-04-14 00:34:34 +08:00
|
|
|
int err;
|
2011-09-16 14:14:54 +08:00
|
|
|
|
2011-09-16 14:14:55 +08:00
|
|
|
err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2011-09-16 14:14:55 +08:00
|
|
|
if (0 != err)
|
|
|
|
return err;
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
|
|
|
|
chan->vidq.field = f->fmt.pix.field;
|
2013-04-14 00:06:00 +08:00
|
|
|
chan->width = f->fmt.pix.width;
|
|
|
|
chan->height = f->fmt.pix.height;
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2011-09-16 14:14:56 +08:00
|
|
|
if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
|
|
|
|
pix_format = PIXEL_FRMT_411;
|
|
|
|
else
|
2013-04-14 00:06:00 +08:00
|
|
|
pix_format = PIXEL_FRMT_422;
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2011-09-16 14:14:56 +08:00
|
|
|
cx25821_set_pixel_format(dev, SRAM_CH00, pix_format);
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2011-09-16 14:14:56 +08:00
|
|
|
/* check if cif resolution */
|
2013-04-13 21:00:52 +08:00
|
|
|
if (chan->width == 320 || chan->width == 352)
|
|
|
|
chan->use_cif_resolution = 1;
|
2011-09-16 14:14:56 +08:00
|
|
|
else
|
2013-04-13 21:00:52 +08:00
|
|
|
chan->use_cif_resolution = 0;
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
chan->cif_width = chan->width;
|
|
|
|
medusa_set_resolution(dev, chan->width, SRAM_CH00);
|
2011-09-16 14:14:56 +08:00
|
|
|
return 0;
|
2010-07-05 01:15:38 +08:00
|
|
|
}
|
|
|
|
|
2013-04-14 18:13:02 +08:00
|
|
|
static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
|
|
|
|
{
|
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
|
|
|
|
if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (chan->streaming_fh && chan->streaming_fh != priv)
|
|
|
|
return -EBUSY;
|
|
|
|
chan->streaming_fh = priv;
|
|
|
|
|
|
|
|
return videobuf_streamon(&chan->vidq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
|
|
|
|
{
|
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
|
|
|
|
if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (chan->streaming_fh && chan->streaming_fh != priv)
|
|
|
|
return -EBUSY;
|
|
|
|
if (chan->streaming_fh == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
chan->streaming_fh = NULL;
|
|
|
|
return videobuf_streamoff(&chan->vidq);
|
|
|
|
}
|
|
|
|
|
2010-07-05 01:15:38 +08:00
|
|
|
static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
|
|
|
|
{
|
2011-09-16 14:14:57 +08:00
|
|
|
int ret_val = 0;
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
ret_val = videobuf_dqbuf(&chan->vidq, p, file->f_flags & O_NONBLOCK);
|
|
|
|
p->sequence = chan->dma_vidq.count;
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2011-09-16 14:14:57 +08:00
|
|
|
return ret_val;
|
2010-07-05 01:15:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vidioc_log_status(struct file *file, void *priv)
|
|
|
|
{
|
2013-04-14 22:57:18 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
struct cx25821_dev *dev = chan->dev;
|
|
|
|
const struct sram_channel *sram_ch = chan->sram_channels;
|
2011-09-16 14:14:57 +08:00
|
|
|
u32 tmp = 0;
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2011-09-16 14:14:57 +08:00
|
|
|
tmp = cx_read(sram_ch->dma_ctl);
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_info("Video input 0 is %s\n",
|
|
|
|
(tmp & 0x11) ? "streaming" : "stopped");
|
2011-09-16 14:14:57 +08:00
|
|
|
return 0;
|
2010-07-05 01:15:38 +08:00
|
|
|
}
|
|
|
|
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_vidioc_querycap(struct file *file, void *priv,
|
2011-09-16 14:14:35 +08:00
|
|
|
struct v4l2_capability *cap)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-14 22:57:18 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
struct cx25821_dev *dev = chan->dev;
|
2013-04-13 17:06:18 +08:00
|
|
|
const u32 cap_input = V4L2_CAP_VIDEO_CAPTURE |
|
|
|
|
V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
|
2013-04-14 18:14:42 +08:00
|
|
|
const u32 cap_output = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_READWRITE;
|
2009-09-13 22:30:11 +08:00
|
|
|
|
|
|
|
strcpy(cap->driver, "cx25821");
|
|
|
|
strlcpy(cap->card, cx25821_boards[dev->board].name, sizeof(cap->card));
|
|
|
|
sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
|
2013-04-14 22:57:18 +08:00
|
|
|
if (chan->id >= VID_CHANNEL_NUM)
|
2013-04-13 17:06:18 +08:00
|
|
|
cap->device_caps = cap_output;
|
|
|
|
else
|
|
|
|
cap->device_caps = cap_input;
|
2013-04-14 18:14:42 +08:00
|
|
|
cap->capabilities = cap_input | cap_output | V4L2_CAP_DEVICE_CAPS;
|
2009-09-13 22:30:11 +08:00
|
|
|
return 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_vidioc_reqbufs(struct file *file, void *priv,
|
2011-09-16 14:14:35 +08:00
|
|
|
struct v4l2_requestbuffers *p)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
|
|
|
|
return videobuf_reqbufs(&chan->vidq, p);
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_vidioc_querybuf(struct file *file, void *priv,
|
2011-09-16 14:14:35 +08:00
|
|
|
struct v4l2_buffer *p)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
|
|
|
|
return videobuf_querybuf(&chan->vidq, p);
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
|
|
|
|
return videobuf_qbuf(&chan->vidq, p);
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
|
2013-04-13 16:50:18 +08:00
|
|
|
{
|
2013-04-14 22:57:18 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
2013-04-13 16:50:18 +08:00
|
|
|
|
2013-04-14 22:57:18 +08:00
|
|
|
*tvnorms = chan->dev->tvnorm;
|
2013-04-13 16:50:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-15 17:10:40 +08:00
|
|
|
int cx25821_vidioc_s_std(struct file *file, void *priv, v4l2_std_id tvnorms)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-14 22:57:18 +08:00
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
struct cx25821_dev *dev = chan->dev;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2013-03-15 17:10:40 +08:00
|
|
|
if (dev->tvnorm == tvnorms)
|
2009-09-13 22:30:11 +08:00
|
|
|
return 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2013-04-14 00:34:34 +08:00
|
|
|
dev->tvnorm = tvnorms;
|
2013-04-14 00:06:00 +08:00
|
|
|
chan->width = 720;
|
|
|
|
chan->height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
medusa_set_videostandard(dev);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
return 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_vidioc_enum_input(struct file *file, void *priv,
|
|
|
|
struct v4l2_input *i)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-14 00:34:34 +08:00
|
|
|
if (i->index)
|
2009-09-13 22:30:11 +08:00
|
|
|
return -EINVAL;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
i->type = V4L2_INPUT_TYPE_CAMERA;
|
|
|
|
i->std = CX25821_NORMS;
|
2013-04-14 00:34:34 +08:00
|
|
|
strcpy(i->name, "Composite");
|
2009-09-13 22:30:11 +08:00
|
|
|
return 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
|
2009-09-13 22:25:45 +08:00
|
|
|
{
|
2013-04-14 00:34:34 +08:00
|
|
|
*i = 0;
|
2009-09-13 22:30:11 +08:00
|
|
|
return 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 18:41:29 +08:00
|
|
|
static int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-14 00:34:34 +08:00
|
|
|
return i ? -EINVAL : 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-13 19:38:14 +08:00
|
|
|
static int cx25821_s_ctrl(struct v4l2_ctrl *ctrl)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2013-04-13 19:38:14 +08:00
|
|
|
struct cx25821_channel *chan =
|
|
|
|
container_of(ctrl->handler, struct cx25821_channel, hdl);
|
|
|
|
struct cx25821_dev *dev = chan->dev;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2013-04-13 19:38:14 +08:00
|
|
|
switch (ctrl->id) {
|
2009-09-13 22:30:11 +08:00
|
|
|
case V4L2_CID_BRIGHTNESS:
|
2013-04-13 19:38:14 +08:00
|
|
|
medusa_set_brightness(dev, ctrl->val, chan->id);
|
2009-09-15 22:33:54 +08:00
|
|
|
break;
|
2009-09-13 22:30:11 +08:00
|
|
|
case V4L2_CID_HUE:
|
2013-04-13 19:38:14 +08:00
|
|
|
medusa_set_hue(dev, ctrl->val, chan->id);
|
2009-09-15 22:33:54 +08:00
|
|
|
break;
|
2009-09-13 22:30:11 +08:00
|
|
|
case V4L2_CID_CONTRAST:
|
2013-04-13 19:38:14 +08:00
|
|
|
medusa_set_contrast(dev, ctrl->val, chan->id);
|
2009-09-15 22:33:54 +08:00
|
|
|
break;
|
2009-09-13 22:30:11 +08:00
|
|
|
case V4L2_CID_SATURATION:
|
2013-04-13 19:38:14 +08:00
|
|
|
medusa_set_saturation(dev, ctrl->val, chan->id);
|
2009-09-15 22:33:54 +08:00
|
|
|
break;
|
2009-09-13 22:30:11 +08:00
|
|
|
default:
|
2013-04-13 19:38:14 +08:00
|
|
|
return -EINVAL;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
2013-04-13 19:38:14 +08:00
|
|
|
return 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2013-04-14 23:07:13 +08:00
|
|
|
static int cx25821_vidioc_enum_output(struct file *file, void *priv,
|
|
|
|
struct v4l2_output *o)
|
2010-07-05 01:15:38 +08:00
|
|
|
{
|
2013-04-14 23:07:13 +08:00
|
|
|
if (o->index)
|
|
|
|
return -EINVAL;
|
2010-07-05 01:15:38 +08:00
|
|
|
|
2013-04-14 23:07:13 +08:00
|
|
|
o->type = V4L2_INPUT_TYPE_CAMERA;
|
|
|
|
o->std = CX25821_NORMS;
|
|
|
|
strcpy(o->name, "Composite");
|
2011-09-16 14:15:03 +08:00
|
|
|
return 0;
|
2010-07-05 01:15:38 +08:00
|
|
|
}
|
|
|
|
|
2013-04-14 23:07:13 +08:00
|
|
|
static int cx25821_vidioc_g_output(struct file *file, void *priv, unsigned int *o)
|
2010-07-05 01:15:38 +08:00
|
|
|
{
|
2013-04-14 23:07:13 +08:00
|
|
|
*o = 0;
|
2011-09-16 14:15:05 +08:00
|
|
|
return 0;
|
2010-07-05 01:15:38 +08:00
|
|
|
}
|
|
|
|
|
2013-04-14 23:07:13 +08:00
|
|
|
static int cx25821_vidioc_s_output(struct file *file, void *priv, unsigned int o)
|
2010-07-05 01:15:38 +08:00
|
|
|
{
|
2013-04-14 23:07:13 +08:00
|
|
|
return o ? -EINVAL : 0;
|
2010-07-05 01:15:38 +08:00
|
|
|
}
|
|
|
|
|
2013-04-14 22:40:26 +08:00
|
|
|
static int cx25821_vidioc_try_fmt_vid_out(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *f)
|
|
|
|
{
|
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
struct cx25821_dev *dev = chan->dev;
|
|
|
|
const struct cx25821_fmt *fmt;
|
|
|
|
|
|
|
|
fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
|
|
|
|
if (NULL == fmt)
|
|
|
|
return -EINVAL;
|
|
|
|
f->fmt.pix.width = 720;
|
|
|
|
f->fmt.pix.height = (dev->tvnorm & V4L2_STD_625_50) ? 576 : 480;
|
|
|
|
f->fmt.pix.field = V4L2_FIELD_INTERLACED;
|
|
|
|
f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
|
|
|
|
f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
|
|
|
|
f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
|
|
|
|
f->fmt.pix.priv = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vidioc_s_fmt_vid_out(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *f)
|
|
|
|
{
|
|
|
|
struct cx25821_channel *chan = video_drvdata(file);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = cx25821_vidioc_try_fmt_vid_out(file, priv, f);
|
|
|
|
|
|
|
|
if (0 != err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
|
|
|
|
chan->vidq.field = f->fmt.pix.field;
|
|
|
|
chan->width = f->fmt.pix.width;
|
|
|
|
chan->height = f->fmt.pix.height;
|
|
|
|
if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
|
|
|
|
chan->pixel_formats = PIXEL_FRMT_411;
|
|
|
|
else
|
|
|
|
chan->pixel_formats = PIXEL_FRMT_422;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-13 19:38:14 +08:00
|
|
|
static const struct v4l2_ctrl_ops cx25821_ctrl_ops = {
|
|
|
|
.s_ctrl = cx25821_s_ctrl,
|
|
|
|
};
|
|
|
|
|
2010-07-05 01:15:38 +08:00
|
|
|
static const struct v4l2_file_operations video_fops = {
|
2011-09-16 14:15:11 +08:00
|
|
|
.owner = THIS_MODULE,
|
2013-04-14 22:57:18 +08:00
|
|
|
.open = v4l2_fh_open,
|
2011-09-16 14:15:11 +08:00
|
|
|
.release = video_release,
|
|
|
|
.read = video_read,
|
|
|
|
.poll = video_poll,
|
|
|
|
.mmap = cx25821_video_mmap,
|
2013-04-14 23:07:13 +08:00
|
|
|
.unlocked_ioctl = video_ioctl2,
|
2010-07-05 01:15:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct v4l2_ioctl_ops video_ioctl_ops = {
|
2011-09-16 14:15:11 +08:00
|
|
|
.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,
|
2013-04-13 16:50:18 +08:00
|
|
|
.vidioc_g_std = cx25821_vidioc_g_std,
|
2011-09-16 14:15:11 +08:00
|
|
|
.vidioc_s_std = cx25821_vidioc_s_std,
|
|
|
|
.vidioc_enum_input = cx25821_vidioc_enum_input,
|
|
|
|
.vidioc_g_input = cx25821_vidioc_g_input,
|
|
|
|
.vidioc_s_input = cx25821_vidioc_s_input,
|
|
|
|
.vidioc_streamon = vidioc_streamon,
|
|
|
|
.vidioc_streamoff = vidioc_streamoff,
|
|
|
|
.vidioc_log_status = vidioc_log_status,
|
2013-04-14 22:57:18 +08:00
|
|
|
.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
|
|
|
|
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
|
2010-07-05 01:15:38 +08:00
|
|
|
};
|
|
|
|
|
2013-04-13 16:30:48 +08:00
|
|
|
static const struct video_device cx25821_video_device = {
|
|
|
|
.name = "cx25821-video",
|
2011-09-16 14:15:12 +08:00
|
|
|
.fops = &video_fops,
|
2013-04-13 19:18:00 +08:00
|
|
|
.release = video_device_release_empty,
|
2013-04-13 16:30:48 +08:00
|
|
|
.minor = -1,
|
2011-09-16 14:15:12 +08:00
|
|
|
.ioctl_ops = &video_ioctl_ops,
|
|
|
|
.tvnorms = CX25821_NORMS,
|
2010-07-05 01:15:38 +08:00
|
|
|
};
|
2013-04-13 16:30:48 +08:00
|
|
|
|
2013-04-14 23:07:13 +08:00
|
|
|
static const struct v4l2_file_operations video_out_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = v4l2_fh_open,
|
|
|
|
.release = v4l2_fh_release,
|
|
|
|
.unlocked_ioctl = video_ioctl2,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct v4l2_ioctl_ops video_out_ioctl_ops = {
|
|
|
|
.vidioc_querycap = cx25821_vidioc_querycap,
|
2013-04-14 22:40:26 +08:00
|
|
|
.vidioc_enum_fmt_vid_out = cx25821_vidioc_enum_fmt_vid_cap,
|
|
|
|
.vidioc_g_fmt_vid_out = cx25821_vidioc_g_fmt_vid_cap,
|
|
|
|
.vidioc_try_fmt_vid_out = cx25821_vidioc_try_fmt_vid_out,
|
|
|
|
.vidioc_s_fmt_vid_out = vidioc_s_fmt_vid_out,
|
2013-04-14 23:07:13 +08:00
|
|
|
.vidioc_g_std = cx25821_vidioc_g_std,
|
|
|
|
.vidioc_s_std = cx25821_vidioc_s_std,
|
|
|
|
.vidioc_enum_output = cx25821_vidioc_enum_output,
|
|
|
|
.vidioc_g_output = cx25821_vidioc_g_output,
|
|
|
|
.vidioc_s_output = cx25821_vidioc_s_output,
|
|
|
|
.vidioc_log_status = vidioc_log_status,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct video_device cx25821_video_out_device = {
|
|
|
|
.name = "cx25821-video",
|
|
|
|
.fops = &video_out_fops,
|
|
|
|
.release = video_device_release_empty,
|
|
|
|
.minor = -1,
|
|
|
|
.ioctl_ops = &video_out_ioctl_ops,
|
|
|
|
.tvnorms = CX25821_NORMS,
|
|
|
|
};
|
|
|
|
|
2013-04-13 16:30:48 +08:00
|
|
|
void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
|
|
|
|
{
|
|
|
|
cx_clear(PCI_INT_MSK, 1);
|
|
|
|
|
2013-04-13 19:18:00 +08:00
|
|
|
if (video_is_registered(&dev->channels[chan_num].vdev)) {
|
|
|
|
video_unregister_device(&dev->channels[chan_num].vdev);
|
2013-04-13 19:38:14 +08:00
|
|
|
v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl);
|
2013-04-13 16:30:48 +08:00
|
|
|
|
|
|
|
btcx_riscmem_free(dev->pci,
|
2013-04-13 21:00:52 +08:00
|
|
|
&dev->channels[chan_num].dma_vidq.stopper);
|
2013-04-13 16:30:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int cx25821_video_register(struct cx25821_dev *dev)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int i;
|
|
|
|
|
2013-04-14 22:53:35 +08:00
|
|
|
/* initial device configuration */
|
2013-04-14 00:34:34 +08:00
|
|
|
dev->tvnorm = V4L2_STD_NTSC_M;
|
2013-04-14 22:53:35 +08:00
|
|
|
|
2013-04-13 16:30:48 +08:00
|
|
|
spin_lock_init(&dev->slock);
|
|
|
|
|
2013-04-14 23:07:13 +08:00
|
|
|
for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; ++i) {
|
2013-04-13 21:00:52 +08:00
|
|
|
struct cx25821_channel *chan = &dev->channels[i];
|
|
|
|
struct video_device *vdev = &chan->vdev;
|
|
|
|
struct v4l2_ctrl_handler *hdl = &chan->hdl;
|
2013-04-14 23:07:13 +08:00
|
|
|
bool is_output = i > SRAM_CH08;
|
2013-04-13 19:18:00 +08:00
|
|
|
|
2013-04-13 16:30:48 +08:00
|
|
|
if (i == SRAM_CH08) /* audio channel */
|
|
|
|
continue;
|
|
|
|
|
2013-04-14 23:07:13 +08:00
|
|
|
if (!is_output) {
|
|
|
|
v4l2_ctrl_handler_init(hdl, 4);
|
|
|
|
v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
|
|
|
|
V4L2_CID_BRIGHTNESS, 0, 10000, 1, 6200);
|
|
|
|
v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
|
|
|
|
V4L2_CID_CONTRAST, 0, 10000, 1, 5000);
|
|
|
|
v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
|
|
|
|
V4L2_CID_SATURATION, 0, 10000, 1, 5000);
|
|
|
|
v4l2_ctrl_new_std(hdl, &cx25821_ctrl_ops,
|
|
|
|
V4L2_CID_HUE, 0, 10000, 1, 5000);
|
|
|
|
if (hdl->error) {
|
|
|
|
err = hdl->error;
|
|
|
|
goto fail_unreg;
|
|
|
|
}
|
|
|
|
err = v4l2_ctrl_handler_setup(hdl);
|
|
|
|
if (err)
|
|
|
|
goto fail_unreg;
|
2013-04-13 19:38:14 +08:00
|
|
|
}
|
2013-04-13 16:30:48 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
cx25821_risc_stopper(dev->pci, &chan->dma_vidq.stopper,
|
|
|
|
chan->sram_channels->dma_ctl, 0x11, 0);
|
2013-04-13 16:30:48 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
chan->sram_channels = &cx25821_sram_channels[i];
|
|
|
|
chan->width = 720;
|
|
|
|
if (dev->tvnorm & V4L2_STD_625_50)
|
|
|
|
chan->height = 576;
|
|
|
|
else
|
|
|
|
chan->height = 480;
|
2013-04-13 16:30:48 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
if (chan->pixel_formats == PIXEL_FRMT_411)
|
|
|
|
chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_Y41P);
|
|
|
|
else
|
|
|
|
chan->fmt = cx25821_format_by_fourcc(V4L2_PIX_FMT_YUYV);
|
2013-04-13 16:30:48 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
cx_write(chan->sram_channels->int_stat, 0xffffffff);
|
2013-04-13 16:30:48 +08:00
|
|
|
|
2013-04-13 21:00:52 +08:00
|
|
|
INIT_LIST_HEAD(&chan->dma_vidq.active);
|
|
|
|
INIT_LIST_HEAD(&chan->dma_vidq.queued);
|
|
|
|
|
|
|
|
chan->timeout_data.dev = dev;
|
|
|
|
chan->timeout_data.channel = &cx25821_sram_channels[i];
|
|
|
|
chan->dma_vidq.timeout.function = cx25821_vid_timeout;
|
|
|
|
chan->dma_vidq.timeout.data = (unsigned long)&chan->timeout_data;
|
|
|
|
init_timer(&chan->dma_vidq.timeout);
|
|
|
|
|
2013-04-14 23:07:13 +08:00
|
|
|
if (!is_output)
|
|
|
|
videobuf_queue_sg_init(&chan->vidq, &cx25821_video_qops, &dev->pci->dev,
|
|
|
|
&dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
|
|
|
V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer),
|
|
|
|
chan, &dev->lock);
|
2013-04-13 16:30:48 +08:00
|
|
|
|
|
|
|
/* register v4l devices */
|
2013-04-14 23:07:13 +08:00
|
|
|
*vdev = is_output ? cx25821_video_out_device : cx25821_video_device;
|
2013-04-13 19:18:00 +08:00
|
|
|
vdev->v4l2_dev = &dev->v4l2_dev;
|
2013-04-14 23:07:13 +08:00
|
|
|
if (!is_output)
|
|
|
|
vdev->ctrl_handler = hdl;
|
|
|
|
else
|
|
|
|
vdev->vfl_dir = VFL_DIR_TX;
|
2013-04-14 22:53:35 +08:00
|
|
|
vdev->lock = &dev->lock;
|
2013-04-14 22:57:18 +08:00
|
|
|
set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags);
|
2013-04-13 19:18:00 +08:00
|
|
|
snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i);
|
2013-04-13 21:00:52 +08:00
|
|
|
video_set_drvdata(vdev, chan);
|
2013-04-13 16:30:48 +08:00
|
|
|
|
2013-04-13 19:18:00 +08:00
|
|
|
err = video_register_device(vdev, VFL_TYPE_GRABBER,
|
|
|
|
video_nr[dev->nr]);
|
2013-04-13 16:30:48 +08:00
|
|
|
|
|
|
|
if (err < 0)
|
|
|
|
goto fail_unreg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set PCI interrupt */
|
|
|
|
cx_set(PCI_INT_MSK, 0xff);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_unreg:
|
2013-04-13 19:18:00 +08:00
|
|
|
while (i >= 0)
|
|
|
|
cx25821_video_unregister(dev, i--);
|
2013-04-13 16:30:48 +08:00
|
|
|
return err;
|
|
|
|
}
|