|
@@ -4,6 +4,9 @@
|
|
|
* Copyright (C) 2009 Conexant Systems Inc.
|
|
|
* Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
|
|
|
* Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
|
|
|
+ * Parts adapted/taken from Eduardo Moscoso Rubino
|
|
|
+ * Copyright (C) 2009 Eduardo Moscoso Rubino <moscoso@TopoLogica.com>
|
|
|
+ *
|
|
|
*
|
|
|
* 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
|
|
@@ -24,7 +27,7 @@
|
|
|
#include "cx25821-video.h"
|
|
|
|
|
|
MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
|
|
|
-MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
|
|
|
+MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
|
|
@@ -48,7 +51,10 @@ unsigned int vid_limit = 16;
|
|
|
module_param(vid_limit, int, 0644);
|
|
|
MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
|
|
|
|
|
|
-static void init_controls(struct cx25821_dev *dev, int chan_num);
|
|
|
+static void cx25821_init_controls(struct cx25821_dev *dev, int chan_num);
|
|
|
+
|
|
|
+static const struct v4l2_file_operations video_fops;
|
|
|
+static const struct v4l2_ioctl_ops video_ioctl_ops;
|
|
|
|
|
|
#define FORMAT_FLAGS_PACKED 0x01
|
|
|
|
|
@@ -211,7 +217,7 @@ static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl)
|
|
|
}
|
|
|
*/
|
|
|
|
|
|
-// resource management
|
|
|
+/* resource management */
|
|
|
int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bit)
|
|
|
{
|
|
|
dprintk(1, "%s()\n", __func__);
|
|
@@ -221,14 +227,14 @@ int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int
|
|
|
|
|
|
/* is it free? */
|
|
|
mutex_lock(&dev->lock);
|
|
|
- if (dev->resources & bit) {
|
|
|
+ if (dev->channels[fh->channel_id].resources & bit) {
|
|
|
/* no, someone else uses it */
|
|
|
mutex_unlock(&dev->lock);
|
|
|
return 0;
|
|
|
}
|
|
|
/* it's free, grab it */
|
|
|
fh->resources |= bit;
|
|
|
- dev->resources |= bit;
|
|
|
+ dev->channels[fh->channel_id].resources |= bit;
|
|
|
dprintk(1, "res: get %d\n", bit);
|
|
|
mutex_unlock(&dev->lock);
|
|
|
return 1;
|
|
@@ -239,9 +245,9 @@ int cx25821_res_check(struct cx25821_fh *fh, unsigned int bit)
|
|
|
return fh->resources & bit;
|
|
|
}
|
|
|
|
|
|
-int cx25821_res_locked(struct cx25821_dev *dev, unsigned int bit)
|
|
|
+int cx25821_res_locked(struct cx25821_fh *fh, unsigned int bit)
|
|
|
{
|
|
|
- return dev->resources & bit;
|
|
|
+ return fh->dev->channels[fh->channel_id].resources & bit;
|
|
|
}
|
|
|
|
|
|
void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bits)
|
|
@@ -251,7 +257,7 @@ void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned i
|
|
|
|
|
|
mutex_lock(&dev->lock);
|
|
|
fh->resources &= ~bits;
|
|
|
- dev->resources &= ~bits;
|
|
|
+ dev->channels[fh->channel_id].resources &= ~bits;
|
|
|
dprintk(1, "res: put %d\n", bits);
|
|
|
mutex_unlock(&dev->lock);
|
|
|
}
|
|
@@ -358,11 +364,11 @@ void cx25821_vid_timeout(unsigned long data)
|
|
|
struct cx25821_data *timeout_data = (struct cx25821_data *)data;
|
|
|
struct cx25821_dev *dev = timeout_data->dev;
|
|
|
struct sram_channel *channel = timeout_data->channel;
|
|
|
- struct cx25821_dmaqueue *q = &dev->vidq[channel->i];
|
|
|
+ struct cx25821_dmaqueue *q = &dev->channels[channel->i].vidq;
|
|
|
struct cx25821_buffer *buf;
|
|
|
unsigned long flags;
|
|
|
|
|
|
- //cx25821_sram_channel_dump(dev, channel);
|
|
|
+ /* cx25821_sram_channel_dump(dev, channel); */
|
|
|
cx_clear(channel->dma_ctl, 0x11);
|
|
|
|
|
|
spin_lock_irqsave(&dev->slock, flags);
|
|
@@ -384,7 +390,7 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
|
|
|
u32 count = 0;
|
|
|
int handled = 0;
|
|
|
u32 mask;
|
|
|
- struct sram_channel *channel = &dev->sram_channels[chan_num];
|
|
|
+ struct sram_channel *channel = dev->channels[chan_num].sram_channels;
|
|
|
|
|
|
mask = cx_read(channel->int_msk);
|
|
|
if (0 == (status & mask))
|
|
@@ -404,7 +410,8 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
|
|
|
if (status & FLD_VID_DST_RISC1) {
|
|
|
spin_lock(&dev->slock);
|
|
|
count = cx_read(channel->gpcnt);
|
|
|
- cx25821_video_wakeup(dev, &dev->vidq[channel->i], count);
|
|
|
+ cx25821_video_wakeup(dev,
|
|
|
+ &dev->channels[channel->i].vidq, count);
|
|
|
spin_unlock(&dev->slock);
|
|
|
handled++;
|
|
|
}
|
|
@@ -413,8 +420,9 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
|
|
|
if (status & 0x10) {
|
|
|
dprintk(2, "stopper video\n");
|
|
|
spin_lock(&dev->slock);
|
|
|
- cx25821_restart_video_queue(dev, &dev->vidq[channel->i],
|
|
|
- channel);
|
|
|
+ cx25821_restart_video_queue(dev,
|
|
|
+ &dev->channels[channel->i].vidq,
|
|
|
+ channel);
|
|
|
spin_unlock(&dev->slock);
|
|
|
handled++;
|
|
|
}
|
|
@@ -437,72 +445,95 @@ void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
|
|
|
{
|
|
|
cx_clear(PCI_INT_MSK, 1);
|
|
|
|
|
|
- if (dev->video_dev[chan_num]) {
|
|
|
- if (video_is_registered(dev->video_dev[chan_num]))
|
|
|
- video_unregister_device(dev->video_dev[chan_num]);
|
|
|
+ if (dev->channels[chan_num].video_dev) {
|
|
|
+ if (video_is_registered(dev->channels[chan_num].video_dev))
|
|
|
+ video_unregister_device(
|
|
|
+ dev->channels[chan_num].video_dev);
|
|
|
else
|
|
|
- video_device_release(dev->video_dev[chan_num]);
|
|
|
+ video_device_release(
|
|
|
+ dev->channels[chan_num].video_dev);
|
|
|
|
|
|
- dev->video_dev[chan_num] = NULL;
|
|
|
+ dev->channels[chan_num].video_dev = NULL;
|
|
|
|
|
|
- btcx_riscmem_free(dev->pci, &dev->vidq[chan_num].stopper);
|
|
|
+ btcx_riscmem_free(dev->pci,
|
|
|
+ &dev->channels[chan_num].vidq.stopper);
|
|
|
|
|
|
printk(KERN_WARNING "device %d released!\n", chan_num);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-int cx25821_video_register(struct cx25821_dev *dev, int chan_num,
|
|
|
- struct video_device *video_template)
|
|
|
+int cx25821_video_register(struct cx25821_dev *dev)
|
|
|
{
|
|
|
int err;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ struct video_device cx25821_video_device = {
|
|
|
+ .name = "cx25821-video",
|
|
|
+ .fops = &video_fops,
|
|
|
+ .minor = -1,
|
|
|
+ .ioctl_ops = &video_ioctl_ops,
|
|
|
+ .tvnorms = CX25821_NORMS,
|
|
|
+ .current_norm = V4L2_STD_NTSC_M,
|
|
|
+ };
|
|
|
|
|
|
spin_lock_init(&dev->slock);
|
|
|
|
|
|
- //printk(KERN_WARNING "Channel %d\n", chan_num);
|
|
|
+ for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; ++i) {
|
|
|
+ cx25821_init_controls(dev, i);
|
|
|
|
|
|
-#ifdef TUNER_FLAG
|
|
|
- dev->tvnorm = video_template->current_norm;
|
|
|
-#endif
|
|
|
+ cx25821_risc_stopper(dev->pci,
|
|
|
+ &dev->channels[i].vidq.stopper,
|
|
|
+ dev->channels[i].sram_channels->dma_ctl,
|
|
|
+ 0x11, 0);
|
|
|
+
|
|
|
+ dev->channels[i].sram_channels = &cx25821_sram_channels[i];
|
|
|
+ dev->channels[i].video_dev = NULL;
|
|
|
+ dev->channels[i].resources = 0;
|
|
|
+
|
|
|
+ cx_write(dev->channels[i].sram_channels->int_stat,
|
|
|
+ 0xffffffff);
|
|
|
+
|
|
|
+ INIT_LIST_HEAD(&dev->channels[i].vidq.active);
|
|
|
+ INIT_LIST_HEAD(&dev->channels[i].vidq.queued);
|
|
|
+
|
|
|
+ dev->channels[i].timeout_data.dev = dev;
|
|
|
+ dev->channels[i].timeout_data.channel =
|
|
|
+ &cx25821_sram_channels[i];
|
|
|
+ dev->channels[i].vidq.timeout.function =
|
|
|
+ cx25821_vid_timeout;
|
|
|
+ dev->channels[i].vidq.timeout.data =
|
|
|
+ (unsigned long)&dev->channels[i].timeout_data;
|
|
|
+ init_timer(&dev->channels[i].vidq.timeout);
|
|
|
+
|
|
|
+ /* register v4l devices */
|
|
|
+ dev->channels[i].video_dev = cx25821_vdev_init(dev,
|
|
|
+ dev->pci, &cx25821_video_device, "video");
|
|
|
+
|
|
|
+ err = video_register_device(dev->channels[i].video_dev,
|
|
|
+ VFL_TYPE_GRABBER, video_nr[dev->nr]);
|
|
|
+
|
|
|
+ if (err < 0)
|
|
|
+ goto fail_unreg;
|
|
|
|
|
|
- /* init video dma queues */
|
|
|
- dev->timeout_data[chan_num].dev = dev;
|
|
|
- dev->timeout_data[chan_num].channel = &dev->sram_channels[chan_num];
|
|
|
- INIT_LIST_HEAD(&dev->vidq[chan_num].active);
|
|
|
- INIT_LIST_HEAD(&dev->vidq[chan_num].queued);
|
|
|
- dev->vidq[chan_num].timeout.function = cx25821_vid_timeout;
|
|
|
- dev->vidq[chan_num].timeout.data =
|
|
|
- (unsigned long)&dev->timeout_data[chan_num];
|
|
|
- init_timer(&dev->vidq[chan_num].timeout);
|
|
|
- cx25821_risc_stopper(dev->pci, &dev->vidq[chan_num].stopper,
|
|
|
- dev->sram_channels[chan_num].dma_ctl, 0x11, 0);
|
|
|
-
|
|
|
- /* register v4l devices */
|
|
|
- dev->video_dev[chan_num] =
|
|
|
- cx25821_vdev_init(dev, dev->pci, video_template, "video");
|
|
|
- err =
|
|
|
- video_register_device(dev->video_dev[chan_num], VFL_TYPE_GRABBER,
|
|
|
- video_nr[dev->nr]);
|
|
|
-
|
|
|
- if (err < 0) {
|
|
|
- goto fail_unreg;
|
|
|
}
|
|
|
- //set PCI interrupt
|
|
|
+
|
|
|
+ /* set PCI interrupt */
|
|
|
cx_set(PCI_INT_MSK, 0xff);
|
|
|
|
|
|
/* initial device configuration */
|
|
|
mutex_lock(&dev->lock);
|
|
|
#ifdef TUNER_FLAG
|
|
|
+ dev->tvnorm = cx25821_video_device.current_norm;
|
|
|
cx25821_set_tvnorm(dev, dev->tvnorm);
|
|
|
#endif
|
|
|
mutex_unlock(&dev->lock);
|
|
|
|
|
|
- init_controls(dev, chan_num);
|
|
|
|
|
|
- return 0;
|
|
|
+ return 0;
|
|
|
|
|
|
- fail_unreg:
|
|
|
- cx25821_video_unregister(dev, chan_num);
|
|
|
+fail_unreg:
|
|
|
+ cx25821_video_unregister(dev, i);
|
|
|
return err;
|
|
|
}
|
|
|
|
|
@@ -533,7 +564,7 @@ int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
|
|
|
u32 line0_offset, line1_offset;
|
|
|
struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
|
|
|
int bpl_local = LINE_SIZE_D1;
|
|
|
- int channel_opened = 0;
|
|
|
+ int channel_opened = fh->channel_id;
|
|
|
|
|
|
BUG_ON(NULL == fh->fmt);
|
|
|
if (fh->width < 48 || fh->width > 720 ||
|
|
@@ -572,26 +603,29 @@ int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
|
|
|
channel_opened = (channel_opened < 0
|
|
|
|| channel_opened > 7) ? 7 : channel_opened;
|
|
|
|
|
|
- if (dev->pixel_formats[channel_opened] == PIXEL_FRMT_411)
|
|
|
+ if (dev->channels[channel_opened]
|
|
|
+ .pixel_formats == PIXEL_FRMT_411)
|
|
|
buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3;
|
|
|
else
|
|
|
buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width);
|
|
|
|
|
|
- if (dev->pixel_formats[channel_opened] == PIXEL_FRMT_411) {
|
|
|
+ if (dev->channels[channel_opened]
|
|
|
+ .pixel_formats == PIXEL_FRMT_411) {
|
|
|
bpl_local = buf->bpl;
|
|
|
} else {
|
|
|
- bpl_local = buf->bpl; //Default
|
|
|
+ bpl_local = buf->bpl; /* Default */
|
|
|
|
|
|
if (channel_opened >= 0 && channel_opened <= 7) {
|
|
|
- if (dev->use_cif_resolution[channel_opened]) {
|
|
|
+ if (dev->channels[channel_opened]
|
|
|
+ .use_cif_resolution) {
|
|
|
if (dev->tvnorm & V4L2_STD_PAL_BG
|
|
|
|| dev->tvnorm & V4L2_STD_PAL_DK)
|
|
|
bpl_local = 352 << 1;
|
|
|
else
|
|
|
bpl_local =
|
|
|
- dev->
|
|
|
- cif_width[channel_opened] <<
|
|
|
- 1;
|
|
|
+ dev->channels[channel_opened].
|
|
|
+ cif_width <<
|
|
|
+ 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -685,6 +719,383 @@ int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma)
|
|
|
return videobuf_mmap_mapper(get_queue(fh), vma);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+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->channels[fh->channel_id].vidq;
|
|
|
+
|
|
|
+ /* 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->channels[fh->channel_id].
|
|
|
+ sram_channels);
|
|
|
+ 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 *h, *dev = video_drvdata(file);
|
|
|
+ struct cx25821_fh *fh;
|
|
|
+ struct list_head *list;
|
|
|
+ int minor = video_devdata(file)->minor;
|
|
|
+ enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
+ u32 pix_format;
|
|
|
+ int ch_id = 0;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ dprintk(1, "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();
|
|
|
+
|
|
|
+ list_for_each(list, &cx25821_devlist)
|
|
|
+ {
|
|
|
+ h = list_entry(list, struct cx25821_dev, devlist);
|
|
|
+
|
|
|
+ for (i = 0; i < MAX_VID_CHANNEL_NUM; i++) {
|
|
|
+ if (h->channels[i].video_dev &&
|
|
|
+ h->channels[i].video_dev->minor == minor) {
|
|
|
+ dev = h;
|
|
|
+ ch_id = i;
|
|
|
+ type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (NULL == dev) {
|
|
|
+ unlock_kernel();
|
|
|
+ return -ENODEV;
|
|
|
+ }
|
|
|
+
|
|
|
+ file->private_data = fh;
|
|
|
+ fh->dev = dev;
|
|
|
+ fh->type = type;
|
|
|
+ fh->width = 720;
|
|
|
+ fh->channel_id = ch_id;
|
|
|
+
|
|
|
+ if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
|
|
|
+ fh->height = 576;
|
|
|
+ else
|
|
|
+ fh->height = 480;
|
|
|
+
|
|
|
+ dev->channel_opened = fh->channel_id;
|
|
|
+ pix_format =
|
|
|
+ (dev->channels[ch_id].pixel_formats ==
|
|
|
+ PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
|
|
|
+ fh->fmt = format_by_fourcc(pix_format);
|
|
|
+
|
|
|
+ v4l2_prio_open(&dev->channels[ch_id].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, RESOURCE_VIDEO0))
|
|
|
+ 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_VIDEO0)) {
|
|
|
+ /* 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) {
|
|
|
+ if (buf->vb.state == VIDEOBUF_DONE) {
|
|
|
+ struct cx25821_dev *dev = fh->dev;
|
|
|
+
|
|
|
+ if (dev && dev->channels[fh->channel_id]
|
|
|
+ .use_cif_resolution) {
|
|
|
+ u8 cam_id = *((char *)buf->vb.baddr + 3);
|
|
|
+ memcpy((char *)buf->vb.baddr,
|
|
|
+ (char *)buf->vb.baddr + (fh->width * 2),
|
|
|
+ (fh->width * 2));
|
|
|
+ *((char *)buf->vb.baddr + 3) = cam_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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(channel0->dma_ctl, 0); /* FIFO and RISC disable */
|
|
|
+
|
|
|
+ /* stop video capture */
|
|
|
+ if (cx25821_res_check(fh, RESOURCE_VIDEO0)) {
|
|
|
+ videobuf_queue_cancel(&fh->vidq);
|
|
|
+ cx25821_res_free(dev, fh, RESOURCE_VIDEO0);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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->channels[fh->channel_id].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_VIDEO0))))
|
|
|
+ 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_VIDEO0);
|
|
|
+ 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;
|
|
|
+ int pix_format = PIXEL_FRMT_422;
|
|
|
+
|
|
|
+ if (fh) {
|
|
|
+ err = v4l2_prio_check(&dev->channels[fh->channel_id]
|
|
|
+ .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->vidq.field = f->fmt.pix.field;
|
|
|
+
|
|
|
+ /* check if width and height is valid based on set standard */
|
|
|
+ if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm))
|
|
|
+ fh->width = f->fmt.pix.width;
|
|
|
+
|
|
|
+ if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm))
|
|
|
+ fh->height = f->fmt.pix.height;
|
|
|
+
|
|
|
+ if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
|
|
|
+ pix_format = PIXEL_FRMT_411;
|
|
|
+ else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
|
|
|
+ pix_format = PIXEL_FRMT_422;
|
|
|
+ else
|
|
|
+ return -EINVAL;
|
|
|
+
|
|
|
+ cx25821_set_pixel_format(dev, SRAM_CH00, pix_format);
|
|
|
+
|
|
|
+ /* check if cif resolution */
|
|
|
+ if (fh->width == 320 || fh->width == 352)
|
|
|
+ dev->channels[fh->channel_id].use_cif_resolution = 1;
|
|
|
+ else
|
|
|
+ dev->channels[fh->channel_id].use_cif_resolution = 0;
|
|
|
+
|
|
|
+ dev->channels[fh->channel_id].cif_width = fh->width;
|
|
|
+ medusa_set_resolution(dev, fh->width, SRAM_CH00);
|
|
|
+
|
|
|
+ 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 int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
|
|
|
+{
|
|
|
+ int ret_val = 0;
|
|
|
+ struct cx25821_fh *fh = priv;
|
|
|
+ struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
|
|
|
+
|
|
|
+ ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
|
|
|
+
|
|
|
+ p->sequence = dev->channels[fh->channel_id].vidq.count;
|
|
|
+
|
|
|
+ return ret_val;
|
|
|
+}
|
|
|
+
|
|
|
+static int vidioc_log_status(struct file *file, void *priv)
|
|
|
+{
|
|
|
+ struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
|
|
|
+ struct cx25821_fh *fh = priv;
|
|
|
+ char name[32 + 2];
|
|
|
+
|
|
|
+ struct sram_channel *sram_ch = dev->channels[fh->channel_id]
|
|
|
+ .sram_channels;
|
|
|
+ u32 tmp = 0;
|
|
|
+
|
|
|
+ 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);
|
|
|
+ tmp = cx_read(sram_ch->dma_ctl);
|
|
|
+ printk(KERN_INFO "Video input 0 is %s\n",
|
|
|
+ (tmp & 0x11) ? "streaming" : "stopped");
|
|
|
+ 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 = ((struct cx25821_fh *)priv)->dev;
|
|
|
+ int err;
|
|
|
+
|
|
|
+ if (fh) {
|
|
|
+ err = v4l2_prio_check(&dev->channels[fh->channel_id]
|
|
|
+ .prio, fh->prio);
|
|
|
+ if (0 != err)
|
|
|
+ return err;
|
|
|
+ }
|
|
|
+
|
|
|
+ return cx25821_set_control(dev, ctl, fh->channel_id);
|
|
|
+}
|
|
|
+
|
|
|
/* VIDEO IOCTLS */
|
|
|
int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
|
|
|
{
|
|
@@ -822,8 +1233,9 @@ int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
|
|
|
int cx25821_vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p)
|
|
|
{
|
|
|
struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev;
|
|
|
+ struct cx25821_fh *fh = f;
|
|
|
|
|
|
- *p = v4l2_prio_max(&dev->prio);
|
|
|
+ *p = v4l2_prio_max(&dev->channels[fh->channel_id].prio);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -833,7 +1245,8 @@ int cx25821_vidioc_s_priority(struct file *file, void *f, enum v4l2_priority pri
|
|
|
struct cx25821_fh *fh = f;
|
|
|
struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev;
|
|
|
|
|
|
- return v4l2_prio_change(&dev->prio, &fh->prio, prio);
|
|
|
+ return v4l2_prio_change(&dev->channels[fh->channel_id]
|
|
|
+ .prio, &fh->prio, prio);
|
|
|
}
|
|
|
|
|
|
#ifdef TUNER_FLAG
|
|
@@ -846,7 +1259,8 @@ int cx25821_vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms)
|
|
|
dprintk(1, "%s()\n", __func__);
|
|
|
|
|
|
if (fh) {
|
|
|
- err = v4l2_prio_check(&dev->prio, fh->prio);
|
|
|
+ err = v4l2_prio_check(&dev->channels[fh->channel_id]
|
|
|
+ .prio, fh->prio);
|
|
|
if (0 != err)
|
|
|
return err;
|
|
|
}
|
|
@@ -916,7 +1330,8 @@ int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
|
|
|
dprintk(1, "%s(%d)\n", __func__, i);
|
|
|
|
|
|
if (fh) {
|
|
|
- err = v4l2_prio_check(&dev->prio, fh->prio);
|
|
|
+ err = v4l2_prio_check(&dev->channels[fh->channel_id]
|
|
|
+ .prio, fh->prio);
|
|
|
if (0 != err)
|
|
|
return err;
|
|
|
}
|
|
@@ -967,9 +1382,14 @@ int cx25821_vidioc_s_frequency(struct file *file, void *priv, struct v4l2_freque
|
|
|
int err;
|
|
|
|
|
|
if (fh) {
|
|
|
- err = v4l2_prio_check(&dev->prio, fh->prio);
|
|
|
+ dev = fh->dev;
|
|
|
+ err = v4l2_prio_check(&dev->channels[fh->channel_id]
|
|
|
+ .prio, fh->prio);
|
|
|
if (0 != err)
|
|
|
return err;
|
|
|
+ } else {
|
|
|
+ printk(KERN_ERR "Invalid fh pointer!\n");
|
|
|
+ return -EINVAL;
|
|
|
}
|
|
|
|
|
|
return cx25821_set_freq(dev, f);
|
|
@@ -1031,7 +1451,8 @@ int cx25821_vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
|
|
|
int err;
|
|
|
|
|
|
if (fh) {
|
|
|
- err = v4l2_prio_check(&dev->prio, fh->prio);
|
|
|
+ err = v4l2_prio_check(&dev->channels[fh->channel_id]
|
|
|
+ .prio, fh->prio);
|
|
|
if (0 != err)
|
|
|
return err;
|
|
|
}
|
|
@@ -1046,7 +1467,7 @@ int cx25821_vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
-// ******************************************************************************************
|
|
|
+/*****************************************************************************/
|
|
|
static const struct v4l2_queryctrl no_ctl = {
|
|
|
.name = "42",
|
|
|
.flags = V4L2_CTRL_FLAG_DISABLED,
|
|
@@ -1129,6 +1550,7 @@ static const struct v4l2_queryctrl *ctrl_by_id(unsigned int id)
|
|
|
int cx25821_vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctl)
|
|
|
{
|
|
|
struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
|
|
|
+ struct cx25821_fh *fh = priv;
|
|
|
|
|
|
const struct v4l2_queryctrl *ctrl;
|
|
|
|
|
@@ -1138,16 +1560,16 @@ int cx25821_vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ct
|
|
|
return -EINVAL;
|
|
|
switch (ctl->id) {
|
|
|
case V4L2_CID_BRIGHTNESS:
|
|
|
- ctl->value = dev->ctl_bright;
|
|
|
+ ctl->value = dev->channels[fh->channel_id].ctl_bright;
|
|
|
break;
|
|
|
case V4L2_CID_HUE:
|
|
|
- ctl->value = dev->ctl_hue;
|
|
|
+ ctl->value = dev->channels[fh->channel_id].ctl_hue;
|
|
|
break;
|
|
|
case V4L2_CID_CONTRAST:
|
|
|
- ctl->value = dev->ctl_contrast;
|
|
|
+ ctl->value = dev->channels[fh->channel_id].ctl_contrast;
|
|
|
break;
|
|
|
case V4L2_CID_SATURATION:
|
|
|
- ctl->value = dev->ctl_saturation;
|
|
|
+ ctl->value = dev->channels[fh->channel_id].ctl_saturation;
|
|
|
break;
|
|
|
}
|
|
|
return 0;
|
|
@@ -1181,19 +1603,19 @@ int cx25821_set_control(struct cx25821_dev *dev,
|
|
|
|
|
|
switch (ctl->id) {
|
|
|
case V4L2_CID_BRIGHTNESS:
|
|
|
- dev->ctl_bright = ctl->value;
|
|
|
+ dev->channels[chan_num].ctl_bright = ctl->value;
|
|
|
medusa_set_brightness(dev, ctl->value, chan_num);
|
|
|
break;
|
|
|
case V4L2_CID_HUE:
|
|
|
- dev->ctl_hue = ctl->value;
|
|
|
+ dev->channels[chan_num].ctl_hue = ctl->value;
|
|
|
medusa_set_hue(dev, ctl->value, chan_num);
|
|
|
break;
|
|
|
case V4L2_CID_CONTRAST:
|
|
|
- dev->ctl_contrast = ctl->value;
|
|
|
+ dev->channels[chan_num].ctl_contrast = ctl->value;
|
|
|
medusa_set_contrast(dev, ctl->value, chan_num);
|
|
|
break;
|
|
|
case V4L2_CID_SATURATION:
|
|
|
- dev->ctl_saturation = ctl->value;
|
|
|
+ dev->channels[chan_num].ctl_saturation = ctl->value;
|
|
|
medusa_set_saturation(dev, ctl->value, chan_num);
|
|
|
break;
|
|
|
}
|
|
@@ -1203,7 +1625,7 @@ int cx25821_set_control(struct cx25821_dev *dev,
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
-static void init_controls(struct cx25821_dev *dev, int chan_num)
|
|
|
+static void cx25821_init_controls(struct cx25821_dev *dev, int chan_num)
|
|
|
{
|
|
|
struct v4l2_control ctrl;
|
|
|
int i;
|
|
@@ -1239,23 +1661,24 @@ int cx25821_vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop)
|
|
|
int err;
|
|
|
|
|
|
if (fh) {
|
|
|
- err = v4l2_prio_check(&dev->prio, fh->prio);
|
|
|
+ err = v4l2_prio_check(&dev->channels[fh->channel_id].
|
|
|
+ prio, fh->prio);
|
|
|
if (0 != err)
|
|
|
return err;
|
|
|
}
|
|
|
- // cx25821_vidioc_s_crop not supported
|
|
|
+ /* cx25821_vidioc_s_crop not supported */
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
|
|
|
int cx25821_vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop)
|
|
|
{
|
|
|
- // cx25821_vidioc_g_crop not supported
|
|
|
+ /* cx25821_vidioc_g_crop not supported */
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
|
|
|
int cx25821_vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm)
|
|
|
{
|
|
|
- // medusa does not support video standard sensing of current input
|
|
|
+ /* medusa does not support video standard sensing of current input */
|
|
|
*norm = CX25821_NORMS;
|
|
|
|
|
|
return 0;
|
|
@@ -1297,3 +1720,325 @@ int cx25821_is_valid_height(u32 height, v4l2_std_id tvnorm)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
+static long video_ioctl_upstream9(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_VIDEO &&
|
|
|
+ command != UPSTREAM_STOP_VIDEO)
|
|
|
+ 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_VIDEO:
|
|
|
+ cx25821_start_upstream_video_ch1(dev, data_from_user);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case UPSTREAM_STOP_VIDEO:
|
|
|
+ cx25821_stop_upstream_video_ch1(dev);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static long video_ioctl_upstream10(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_VIDEO &&
|
|
|
+ command != UPSTREAM_STOP_VIDEO)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ dev->input_filename_ch2 = data_from_user->input_filename;
|
|
|
+ dev->input_audiofilename = data_from_user->input_filename;
|
|
|
+ dev->vid_stdname_ch2 = data_from_user->vid_stdname;
|
|
|
+ dev->pixel_format_ch2 = data_from_user->pixel_format;
|
|
|
+ dev->channel_select_ch2 = data_from_user->channel_select;
|
|
|
+ dev->command_ch2 = data_from_user->command;
|
|
|
+
|
|
|
+ switch (command) {
|
|
|
+ case UPSTREAM_START_VIDEO:
|
|
|
+ cx25821_start_upstream_video_ch2(dev, data_from_user);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case UPSTREAM_STOP_VIDEO:
|
|
|
+ cx25821_stop_upstream_video_ch2(dev);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 long video_ioctl_set(struct file *file, unsigned int cmd,
|
|
|
+ unsigned long arg)
|
|
|
+{
|
|
|
+ struct cx25821_fh *fh = file->private_data;
|
|
|
+ struct cx25821_dev *dev = fh->dev;
|
|
|
+ struct downstream_user_struct *data_from_user;
|
|
|
+ int command;
|
|
|
+ int width = 720;
|
|
|
+ int selected_channel = 0, pix_format = 0, i = 0;
|
|
|
+ int cif_enable = 0, cif_width = 0;
|
|
|
+ u32 value = 0;
|
|
|
+
|
|
|
+ data_from_user = (struct downstream_user_struct *)arg;
|
|
|
+
|
|
|
+ if (!data_from_user) {
|
|
|
+ printk(
|
|
|
+ "cx25821 in %s(): User data is INVALID. Returning.\n",
|
|
|
+ __func__);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ command = data_from_user->command;
|
|
|
+
|
|
|
+ if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT
|
|
|
+ && command != ENABLE_CIF_RESOLUTION && command != REG_READ
|
|
|
+ && command != REG_WRITE && command != MEDUSA_READ
|
|
|
+ && command != MEDUSA_WRITE) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (command) {
|
|
|
+ case SET_VIDEO_STD:
|
|
|
+ dev->tvnorm =
|
|
|
+ !strcmp(data_from_user->vid_stdname,
|
|
|
+ "PAL") ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M;
|
|
|
+ medusa_set_videostandard(dev);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case SET_PIXEL_FORMAT:
|
|
|
+ selected_channel = data_from_user->decoder_select;
|
|
|
+ pix_format = data_from_user->pixel_format;
|
|
|
+
|
|
|
+ if (!(selected_channel <= 7 && selected_channel >= 0)) {
|
|
|
+ selected_channel -= 4;
|
|
|
+ selected_channel = selected_channel % 8;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (selected_channel >= 0)
|
|
|
+ cx25821_set_pixel_format(dev, selected_channel,
|
|
|
+ pix_format);
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case ENABLE_CIF_RESOLUTION:
|
|
|
+ selected_channel = data_from_user->decoder_select;
|
|
|
+ cif_enable = data_from_user->cif_resolution_enable;
|
|
|
+ cif_width = data_from_user->cif_width;
|
|
|
+
|
|
|
+ if (cif_enable) {
|
|
|
+ if (dev->tvnorm & V4L2_STD_PAL_BG
|
|
|
+ || dev->tvnorm & V4L2_STD_PAL_DK)
|
|
|
+ width = 352;
|
|
|
+ else
|
|
|
+ width = (cif_width == 320
|
|
|
+ || cif_width == 352) ? cif_width : 320;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!(selected_channel <= 7 && selected_channel >= 0)) {
|
|
|
+ selected_channel -= 4;
|
|
|
+ selected_channel = selected_channel % 8;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (selected_channel <= 7 && selected_channel >= 0) {
|
|
|
+ dev->channels[selected_channel].
|
|
|
+ use_cif_resolution = cif_enable;
|
|
|
+ dev->channels[selected_channel].cif_width = width;
|
|
|
+ } else {
|
|
|
+ for (i = 0; i < VID_CHANNEL_NUM; i++) {
|
|
|
+ dev->channels[i].use_cif_resolution =
|
|
|
+ cif_enable;
|
|
|
+ dev->channels[i].cif_width = width;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ medusa_set_resolution(dev, width, selected_channel);
|
|
|
+ break;
|
|
|
+ case REG_READ:
|
|
|
+ data_from_user->reg_data = cx_read(data_from_user->reg_address);
|
|
|
+ break;
|
|
|
+ case REG_WRITE:
|
|
|
+ cx_write(data_from_user->reg_address, data_from_user->reg_data);
|
|
|
+ break;
|
|
|
+ case MEDUSA_READ:
|
|
|
+ value =
|
|
|
+ cx25821_i2c_read(&dev->i2c_bus[0],
|
|
|
+ (u16) data_from_user->reg_address,
|
|
|
+ &data_from_user->reg_data);
|
|
|
+ break;
|
|
|
+ case MEDUSA_WRITE:
|
|
|
+ cx25821_i2c_write(&dev->i2c_bus[0],
|
|
|
+ (u16) data_from_user->reg_address,
|
|
|
+ data_from_user->reg_data);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static long cx25821_video_ioctl(struct file *file,
|
|
|
+ unsigned int cmd, unsigned long arg)
|
|
|
+{
|
|
|
+ int ret = 0;
|
|
|
+
|
|
|
+ struct cx25821_fh *fh = file->private_data;
|
|
|
+
|
|
|
+ /* check to see if it's the video upstream */
|
|
|
+ if (fh->channel_id == SRAM_CH09) {
|
|
|
+ ret = video_ioctl_upstream9(file, cmd, arg);
|
|
|
+ return ret;
|
|
|
+ } else if (fh->channel_id == SRAM_CH10) {
|
|
|
+ ret = video_ioctl_upstream10(file, cmd, arg);
|
|
|
+ return ret;
|
|
|
+ } else if (fh->channel_id == SRAM_CH11) {
|
|
|
+ ret = video_ioctl_upstream11(file, cmd, arg);
|
|
|
+ ret = video_ioctl_set(file, cmd, arg);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ return video_ioctl2(file, cmd, arg);
|
|
|
+}
|
|
|
+
|
|
|
+/* 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 = cx25821_video_ioctl,
|
|
|
+};
|
|
|
+
|
|
|
+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_videoioctl_template = {
|
|
|
+ .name = "cx25821-videoioctl",
|
|
|
+ .fops = &video_fops,
|
|
|
+ .ioctl_ops = &video_ioctl_ops,
|
|
|
+ .tvnorms = CX25821_NORMS,
|
|
|
+ .current_norm = V4L2_STD_NTSC_M,
|
|
|
+};
|