#include <media/saa7146_vv.h>
-#define BOARD_CAN_DO_VBI(dev) (dev->revision != 0 && dev->vv_data->vbi_minor != -1)
+#define BOARD_CAN_DO_VBI(dev) (dev->revision != 0 && dev->vv_data->vbi_minor != -1)
/****************************************************************************/
/* resource management functions, shamelessly stolen from saa7134 driver */
return 1;
}
-int saa7146_res_check(struct saa7146_fh *fh, unsigned int bit)
-{
- return (fh->resources & bit);
-}
-
-int saa7146_res_locked(struct saa7146_dev *dev, unsigned int bit)
-{
- struct saa7146_vv *vv = dev->vv_data;
- return (vv->resources & bit);
-}
-
void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits)
{
struct saa7146_dev *dev = fh->dev;
struct saa7146_dmaqueue *q,
struct saa7146_buf *buf)
{
-#if DEBUG_SPINLOCKS
- BUG_ON(!spin_is_locked(&dev->slock));
-#endif
+ assert_spin_locked(&dev->slock);
DEB_EE(("dev:%p, dmaq:%p, buf:%p\n", dev, q, buf));
- if( NULL == q ) {
- ERR(("internal error: fatal NULL pointer for q.\n"));
- return 0;
- }
+ BUG_ON(!q);
if (NULL == q->curr) {
q->curr = buf;
struct saa7146_dmaqueue *q,
int state)
{
-#if DEBUG_SPINLOCKS
- BUG_ON(!spin_is_locked(&dev->slock));
-#endif
- if( NULL == q->curr ) {
- ERR(("internal error: fatal NULL pointer for q->curr.\n"));
- return;
- }
-
+ assert_spin_locked(&dev->slock);
DEB_EE(("dev:%p, dmaq:%p, state:%d\n", dev, q, state));
DEB_EE(("q->curr:%p\n",q->curr));
+ BUG_ON(!q->curr);
+
/* finish current buffer */
if (NULL == q->curr) {
DEB_D(("aiii. no current buffer\n"));
- return;
+ return;
}
-
+
q->curr->vb.state = state;
do_gettimeofday(&q->curr->vb.ts);
wake_up(&q->curr->vb.done);
{
struct saa7146_buf *buf,*next = NULL;
- if( NULL == q ) {
- ERR(("internal error: fatal NULL pointer for q.\n"));
- return;
- }
+ BUG_ON(!q);
DEB_INT(("dev:%p, dmaq:%p, vbi:%d\n", dev, q, vbi));
-#if DEBUG_SPINLOCKS
- BUG_ON(!spin_is_locked(&dev->slock));
-#endif
+ assert_spin_locked(&dev->slock);
if (!list_empty(&q->queue)) {
/* activate next one from queue */
buf = list_entry(q->queue.next,struct saa7146_buf,vb.queue);
// fixme: fix this for vflip != 0
saa7146_write(dev, PROT_ADDR1, 0);
- saa7146_write(dev, MC2, (MASK_02|MASK_18));
+ saa7146_write(dev, MC2, (MASK_02|MASK_18));
/* write the address of the rps-program */
saa7146_write(dev, RPS_ADDR0, dev->d_rps0.dma_handle);
/* turn on rps */
saa7146_write(dev, MC1, (MASK_12 | MASK_28));
-
+
/*
printk("vdma%d.base_even: 0x%08x\n", 1,saa7146_read(dev,BASE_EVEN1));
printk("vdma%d.base_odd: 0x%08x\n", 1,saa7146_read(dev,BASE_ODD1));
}
/* allocate per open data */
- fh = kmalloc(sizeof(*fh),GFP_KERNEL);
+ fh = kzalloc(sizeof(*fh),GFP_KERNEL);
if (NULL == fh) {
DEB_S(("cannot allocate memory for per open data.\n"));
result = -ENOMEM;
goto out;
}
- memset(fh,0,sizeof(*fh));
-
+
file->private_data = fh;
fh->dev = dev;
fh->type = type;
if( fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
DEB_S(("initializing vbi...\n"));
- result = saa7146_vbi_uops.open(dev,file);
+ if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
+ result = saa7146_vbi_uops.open(dev,file);
+ if (dev->ext_vv_data->vbi_fops.open)
+ dev->ext_vv_data->vbi_fops.open(inode, file);
} else {
DEB_S(("initializing video...\n"));
result = saa7146_video_uops.open(dev,file);
file->private_data = NULL;
}
up(&saa7146_devices_lock);
- return result;
+ return result;
}
static int fops_release(struct inode *inode, struct file *file)
return -ERESTARTSYS;
if( fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
- saa7146_vbi_uops.release(dev,file);
+ if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
+ saa7146_vbi_uops.release(dev,file);
+ if (dev->ext_vv_data->vbi_fops.release)
+ dev->ext_vv_data->vbi_fops.release(inode, file);
} else {
saa7146_video_uops.release(dev,file);
}
BUG();
return 0;
}
- return videobuf_mmap_mapper(vma,q);
+
+ return videobuf_mmap_mapper(q,vma);
}
static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait)
return 0;
}
-static ssize_t fops_read(struct file *file, char *data, size_t count, loff_t *ppos)
+static ssize_t fops_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
{
struct saa7146_fh *fh = file->private_data;
}
case V4L2_BUF_TYPE_VBI_CAPTURE: {
// DEB_EE(("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, data:%p, count:%lu\n", file, data, (unsigned long)count));
- return saa7146_vbi_uops.read(file,data,count,ppos);
+ if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
+ return saa7146_vbi_uops.read(file,data,count,ppos);
+ else
+ return -EINVAL;
}
break;
default:
}
}
+static ssize_t fops_write(struct file *file, const char __user *data, size_t count, loff_t *ppos)
+{
+ struct saa7146_fh *fh = file->private_data;
+
+ switch (fh->type) {
+ case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+ return -EINVAL;
+ case V4L2_BUF_TYPE_VBI_CAPTURE:
+ if (fh->dev->ext_vv_data->vbi_fops.write)
+ return fh->dev->ext_vv_data->vbi_fops.write(file, data, count, ppos);
+ else
+ return -EINVAL;
+ default:
+ BUG();
+ return -EINVAL;
+ }
+}
+
static struct file_operations video_fops =
{
.owner = THIS_MODULE,
.open = fops_open,
.release = fops_release,
.read = fops_read,
+ .write = fops_write,
.poll = fops_poll,
.mmap = fops_mmap,
.ioctl = fops_ioctl,
.llseek = no_llseek,
};
-void vv_callback(struct saa7146_dev *dev, unsigned long status)
+static void vv_callback(struct saa7146_dev *dev, unsigned long status)
{
u32 isr = status;
-
+
DEB_INT(("dev:%p, isr:0x%08x\n",dev,(u32)status));
if (0 != (isr & (MASK_27))) {
int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
{
- struct saa7146_vv *vv = kmalloc (sizeof(struct saa7146_vv),GFP_KERNEL);
+ struct saa7146_vv *vv = kzalloc (sizeof(struct saa7146_vv),GFP_KERNEL);
if( NULL == vv ) {
ERR(("out of memory. aborting.\n"));
return -1;
}
- memset(vv, 0x0, sizeof(*vv));
DEB_EE(("dev:%p\n",dev));
-
+
/* set default values for video parts of the saa7146 */
saa7146_write(dev, BCS_CTRL, 0x80400040);
handle different devices that might need different
configuration data) */
dev->ext_vv_data = ext_vv;
-
+
vv->video_minor = -1;
vv->vbi_minor = -1;
- vv->d_clipping.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_CLIPPING_MEM, &vv->d_clipping.dma_handle);
+ vv->d_clipping.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_CLIPPING_MEM, &vv->d_clipping.dma_handle);
if( NULL == vv->d_clipping.cpu_addr ) {
ERR(("out of memory. aborting.\n"));
kfree(vv);
memset(vv->d_clipping.cpu_addr, 0x0, SAA7146_CLIPPING_MEM);
saa7146_video_uops.init(dev,vv);
- saa7146_vbi_uops.init(dev,vv);
-
+ if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
+ saa7146_vbi_uops.init(dev,vv);
+
dev->vv_data = vv;
dev->vv_callback = &vv_callback;
struct saa7146_vv *vv = dev->vv_data;
DEB_EE(("dev:%p\n",dev));
-
+
pci_free_consistent(dev->pci, SAA7146_RPS_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle);
- kfree(vv);
+ kfree(vv);
dev->vv_data = NULL;
dev->vv_callback = NULL;
-
+
return 0;
}
-int saa7146_register_device(struct video_device *vid, struct saa7146_dev* dev, char *name, int type)
+int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
+ char *name, int type)
{
struct saa7146_vv *vv = dev->vv_data;
+ struct video_device *vfd;
DEB_EE(("dev:%p, name:'%s', type:%d\n",dev,name,type));
-
- *vid = device_template;
- strlcpy(vid->name, name, sizeof(vid->name));
- vid->priv = dev;
+
+ // released by vfd->release
+ vfd = video_device_alloc();
+ if (vfd == NULL)
+ return -ENOMEM;
+
+ memcpy(vfd, &device_template, sizeof(struct video_device));
+ strlcpy(vfd->name, name, sizeof(vfd->name));
+ vfd->release = video_device_release;
+ vfd->priv = dev;
// fixme: -1 should be an insmod parameter *for the extension* (like "video_nr");
- if (video_register_device(vid,type,-1) < 0) {
+ if (video_register_device(vfd, type, -1) < 0) {
ERR(("cannot register v4l2 device. skipping.\n"));
return -1;
}
if( VFL_TYPE_GRABBER == type ) {
- vv->video_minor = vid->minor;
- INFO(("%s: registered device video%d [v4l2]\n", dev->name,vid->minor & 0x1f));
+ vv->video_minor = vfd->minor;
+ INFO(("%s: registered device video%d [v4l2]\n",
+ dev->name, vfd->minor & 0x1f));
} else {
- vv->vbi_minor = vid->minor;
- INFO(("%s: registered device vbi%d [v4l2]\n", dev->name,vid->minor & 0x1f));
+ vv->vbi_minor = vfd->minor;
+ INFO(("%s: registered device vbi%d [v4l2]\n",
+ dev->name, vfd->minor & 0x1f));
}
+ *vid = vfd;
return 0;
}
-int saa7146_unregister_device(struct video_device *vid, struct saa7146_dev* dev)
+int saa7146_unregister_device(struct video_device **vid, struct saa7146_dev* dev)
{
struct saa7146_vv *vv = dev->vv_data;
-
+
DEB_EE(("dev:%p\n",dev));
- if( VFL_TYPE_GRABBER == vid->type ) {
+ if( VFL_TYPE_GRABBER == (*vid)->type ) {
vv->video_minor = -1;
} else {
vv->vbi_minor = -1;
}
- video_unregister_device(vid);
+
+ video_unregister_device(*vid);
+ *vid = NULL;
return 0;
}