/* Declare static vars that will be used as parameters */
static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
-static struct video_device vivi; /* Video device */
static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
static int n_devs = 1; /* Number of virtual devices */
static int qctl_regs[ARRAY_SIZE(vivi_qctrl)];
-#define dprintk(level, fmt, arg...) \
+#define dprintk(dev, level, fmt, arg...) \
do { \
- if (vivi.debug >= (level)) \
+ if (dev->vfd->debug >= (level)) \
printk(KERN_DEBUG "vivi: " fmt , ## arg); \
} while (0)
struct list_head vivi_devlist;
struct mutex lock;
+ spinlock_t slock;
int users;
dev->timestr);
/* FIXME: replacing to __copy_to_user */
if (copy_to_user(vbuf + pos, tmpbuf, wmax * 2) != 0)
- dprintk(2, "vivifill copy_to_user failed.\n");
+ dprintk(dev, 2, "vivifill copy_to_user failed.\n");
pos += wmax*2;
}
sprintf(dev->timestr, "%02d:%02d:%02d:%03d",
dev->h, dev->m, dev->s, (dev->us + 500) / 1000);
- dprintk(2, "vivifill at %s: Buffer 0x%08lx size= %d\n", dev->timestr,
- (unsigned long)tmpbuf, pos);
+ dprintk(dev, 2, "vivifill at %s: Buffer 0x%08lx size= %d\n",
+ dev->timestr, (unsigned long)tmpbuf, pos);
/* Advice that buffer was filled */
buf->vb.state = VIDEOBUF_DONE;
int bc;
+ spin_lock(&dev->slock);
/* Announces videobuf that all went ok */
for (bc = 0;; bc++) {
if (list_empty(&dma_q->active)) {
- dprintk(1, "No active queue to serve\n");
+ dprintk(dev, 1, "No active queue to serve\n");
break;
}
/* Nobody is waiting something to be done, just return */
if (!waitqueue_active(&buf->vb.done)) {
mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
+ spin_unlock(&dev->slock);
return;
}
do_gettimeofday(&buf->vb.ts);
- dprintk(2, "[%p/%d] wakeup\n", buf, buf->vb. i);
+ dprintk(dev, 2, "[%p/%d] wakeup\n", buf, buf->vb. i);
/* Fill buffer */
vivi_fillbuff(dev, buf);
}
}
if (bc != 1)
- dprintk(1, "%s: %d buffers handled (should be 1)\n",
+ dprintk(dev, 1, "%s: %d buffers handled (should be 1)\n",
__FUNCTION__, bc);
+ spin_unlock(&dev->slock);
}
+#define frames_to_ms(frames) \
+ ((frames * WAKE_NUMERATOR * 1000) / WAKE_DENOMINATOR)
+
static void vivi_sleep(struct vivi_dmaqueue *dma_q)
{
- int timeout;
+ struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
+ int timeout, running_time;
DECLARE_WAITQUEUE(wait, current);
- dprintk(1, "%s dma_q=0x%08lx\n", __FUNCTION__, (unsigned long)dma_q);
+ dprintk(dev, 1, "%s dma_q=0x%08lx\n", __FUNCTION__,
+ (unsigned long)dma_q);
add_wait_queue(&dma_q->wq, &wait);
- if (!kthread_should_stop()) {
- dma_q->frame++;
-
- /* Calculate time to wake up */
- timeout = dma_q->ini_jiffies+
- msecs_to_jiffies((dma_q->frame*WAKE_NUMERATOR * 1000)
- / WAKE_DENOMINATOR) - jiffies;
-
- if (timeout <= 0) {
- int old = dma_q->frame;
- dma_q->frame = (jiffies_to_msecs(jiffies -
- dma_q->ini_jiffies) *
- WAKE_DENOMINATOR) /
- (WAKE_NUMERATOR * 1000) + 1;
-
- timeout = dma_q->ini_jiffies+
- msecs_to_jiffies((dma_q->frame *
- WAKE_NUMERATOR * 1000)
- / WAKE_DENOMINATOR) - jiffies;
-
- dprintk(1, "underrun, losed %d frames. "
- "Now, frame is %d. Waking on %d jiffies\n",
- dma_q->frame-old, dma_q->frame, timeout);
- } else
- dprintk(1, "will sleep for %i jiffies\n", timeout);
-
- vivi_thread_tick(dma_q);
-
- schedule_timeout_interruptible(timeout);
- }
+ if (kthread_should_stop())
+ goto stop_task;
+
+ running_time = jiffies - dma_q->ini_jiffies;
+ dma_q->frame++;
+
+ /* Calculate time to wake up */
+ timeout = msecs_to_jiffies(frames_to_ms(dma_q->frame)) - running_time;
+
+ if (timeout > msecs_to_jiffies(frames_to_ms(2)) || timeout <= 0) {
+ int old = dma_q->frame;
+ int nframes;
+
+ dma_q->frame = (jiffies_to_msecs(running_time) /
+ frames_to_ms(1)) + 1;
+
+ timeout = msecs_to_jiffies(frames_to_ms(dma_q->frame))
+ - running_time;
+
+ if (unlikely (timeout <= 0))
+ timeout = 1;
+
+ nframes = (dma_q->frame > old)?
+ dma_q->frame - old : old - dma_q->frame;
+
+ dprintk(dev, 1, "%ld: %s %d frames. "
+ "Current frame is %d. Will sleep for %d jiffies\n",
+ jiffies,
+ (dma_q->frame > old)? "Underrun, losed" : "Overrun of",
+ nframes, dma_q->frame, timeout);
+ } else
+ dprintk(dev, 1, "will sleep for %d jiffies\n", timeout);
+
+ vivi_thread_tick(dma_q);
+ schedule_timeout_interruptible(timeout);
+
+stop_task:
remove_wait_queue(&dma_q->wq, &wait);
try_to_freeze();
}
static int vivi_thread(void *data)
{
struct vivi_dmaqueue *dma_q = data;
+ struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
- dprintk(1, "thread started\n");
+ dprintk(dev, 1, "thread started\n");
mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
set_freezable();
if (kthread_should_stop())
break;
}
- dprintk(1, "thread: exit\n");
+ dprintk(dev, 1, "thread: exit\n");
return 0;
}
static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
{
+ struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
+
dma_q->frame = 0;
dma_q->ini_jiffies = jiffies;
- dprintk(1, "%s\n", __FUNCTION__);
+ dprintk(dev, 1, "%s\n", __FUNCTION__);
dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi");
/* Wakes thread */
wake_up_interruptible(&dma_q->wq);
- dprintk(1, "returning from %s\n", __FUNCTION__);
+ dprintk(dev, 1, "returning from %s\n", __FUNCTION__);
return 0;
}
static void vivi_stop_thread(struct vivi_dmaqueue *dma_q)
{
- dprintk(1, "%s\n", __FUNCTION__);
+ struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
+
+ dprintk(dev, 1, "%s\n", __FUNCTION__);
/* shutdown control thread */
if (dma_q->kthread) {
kthread_stop(dma_q->kthread);
static int restart_video_queue(struct vivi_dmaqueue *dma_q)
{
+ struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
struct vivi_buffer *buf, *prev;
- dprintk(1, "%s dma_q=0x%08lx\n", __FUNCTION__, (unsigned long)dma_q);
+ dprintk(dev, 1, "%s dma_q=0x%08lx\n", __FUNCTION__,
+ (unsigned long)dma_q);
if (!list_empty(&dma_q->active)) {
buf = list_entry(dma_q->active.next,
struct vivi_buffer, vb.queue);
- dprintk(2, "restart_queue [%p/%d]: restart dma\n",
+ dprintk(dev, 2, "restart_queue [%p/%d]: restart dma\n",
buf, buf->vb.i);
- dprintk(1, "Restarting video dma\n");
+ dprintk(dev, 1, "Restarting video dma\n");
vivi_stop_thread(dma_q);
/* cancel all outstanding capture / vbi requests */
list_del(&buf->vb.queue);
list_add_tail(&buf->vb.queue, &dma_q->active);
- dprintk(1, "Restarting video dma\n");
+ dprintk(dev, 1, "Restarting video dma\n");
vivi_stop_thread(dma_q);
vivi_start_thread(dma_q);
buf->vb.state = VIDEOBUF_ACTIVE;
mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
- dprintk(2, "[%p/%d] restart_queue - first active\n",
+ dprintk(dev, 2,
+ "[%p/%d] restart_queue - first active\n",
buf, buf->vb.i);
} else if (prev->vb.width == buf->vb.width &&
list_del(&buf->vb.queue);
list_add_tail(&buf->vb.queue, &dma_q->active);
buf->vb.state = VIDEOBUF_ACTIVE;
- dprintk(2, "[%p/%d] restart_queue - move to active\n",
+ dprintk(dev, 2,
+ "[%p/%d] restart_queue - move to active\n",
buf, buf->vb.i);
} else {
return 0;
struct vivi_dmaqueue *vidq = &dev->vidq;
struct vivi_buffer *buf;
+ spin_lock(&dev->slock);
+
while (!list_empty(&vidq->active)) {
buf = list_entry(vidq->active.next,
struct vivi_buffer, vb.queue);
wake_up(&buf->vb.done);
printk(KERN_INFO "vivi/0: [%p/%d] timeout\n", buf, buf->vb.i);
}
-
restart_video_queue(vidq);
+
+ spin_unlock(&dev->slock);
}
/* ------------------------------------------------------------------
static int
buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
{
- struct vivi_fh *fh = vq->priv_data;
+ struct vivi_fh *fh = vq->priv_data;
+ struct vivi_dev *dev = fh->dev;
*size = fh->width*fh->height*2;
while (*size * *count > vid_limit * 1024 * 1024)
(*count)--;
- dprintk(1, "%s, count=%d, size=%d\n", __FUNCTION__, *count, *size);
+ dprintk(dev, 1, "%s, count=%d, size=%d\n", __FUNCTION__,
+ *count, *size);
return 0;
}
static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf)
{
- dprintk(1, "%s\n", __FUNCTION__);
+ struct vivi_fh *fh = vq->priv_data;
+ struct vivi_dev *dev = fh->dev;
+
+ dprintk(dev, 1, "%s\n", __FUNCTION__);
if (in_interrupt())
BUG();
enum v4l2_field field)
{
struct vivi_fh *fh = vq->priv_data;
+ struct vivi_dev *dev = fh->dev;
struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
int rc, init_buffer = 0;
- dprintk(1, "%s, field=%d\n", __FUNCTION__, field);
+ dprintk(dev, 1, "%s, field=%d\n", __FUNCTION__, field);
BUG_ON(NULL == fh->fmt);
if (fh->width < 48 || fh->width > norm_maxw() ||
struct vivi_buffer *prev;
if (!list_empty(&vidq->queued)) {
- dprintk(1, "adding vb queue=0x%08lx\n",
+ dprintk(dev, 1, "adding vb queue=0x%08lx\n",
(unsigned long)&buf->vb.queue);
list_add_tail(&buf->vb.queue, &vidq->queued);
buf->vb.state = VIDEOBUF_QUEUED;
- dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
+ dprintk(dev, 2, "[%p/%d] buffer_queue - append to queued\n",
buf, buf->vb.i);
} else if (list_empty(&vidq->active)) {
list_add_tail(&buf->vb.queue, &vidq->active);
buf->vb.state = VIDEOBUF_ACTIVE;
mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT);
- dprintk(2, "[%p/%d] buffer_queue - first active\n",
+ dprintk(dev, 2, "[%p/%d] buffer_queue - first active\n",
buf, buf->vb.i);
vivi_start_thread(vidq);
prev->fmt == buf->fmt) {
list_add_tail(&buf->vb.queue, &vidq->active);
buf->vb.state = VIDEOBUF_ACTIVE;
- dprintk(2, "[%p/%d] buffer_queue - append to active\n",
+ dprintk(dev, 2,
+ "[%p/%d] buffer_queue - append to active\n",
buf, buf->vb.i);
} else {
list_add_tail(&buf->vb.queue, &vidq->queued);
buf->vb.state = VIDEOBUF_QUEUED;
- dprintk(2, "[%p/%d] buffer_queue - first queued\n",
+ dprintk(dev, 2,
+ "[%p/%d] buffer_queue - first queued\n",
buf, buf->vb.i);
}
}
struct vivi_dev *dev = (struct vivi_dev *)fh->dev;
struct vivi_dmaqueue *vidq = &dev->vidq;
- dprintk(1, "%s\n", __FUNCTION__);
+ dprintk(dev, 1, "%s\n", __FUNCTION__);
vivi_stop_thread(vidq);
static int vidioc_try_fmt_cap(struct file *file, void *priv,
struct v4l2_format *f)
{
+ struct vivi_fh *fh = priv;
+ struct vivi_dev *dev = fh->dev;
struct vivi_fmt *fmt;
enum v4l2_field field;
unsigned int maxw, maxh;
if (format.fourcc != f->fmt.pix.pixelformat) {
- dprintk(1, "Fourcc format (0x%08x) invalid. Driver accepts "
- "only 0x%08x\n", f->fmt.pix.pixelformat, format.fourcc);
+ dprintk(dev, 1, "Fourcc format (0x%08x) invalid. "
+ "Driver accepts only 0x%08x\n",
+ f->fmt.pix.pixelformat, format.fourcc);
return -EINVAL;
}
fmt = &format;
if (field == V4L2_FIELD_ANY) {
field = V4L2_FIELD_INTERLACED;
} else if (V4L2_FIELD_INTERLACED != field) {
- dprintk(1, "Field type invalid.\n");
+ dprintk(dev, 1, "Field type invalid.\n");
return -EINVAL;
}
return -EINVAL;
inp->type = V4L2_INPUT_TYPE_CAMERA;
- inp->std = V4L2_STD_NTSC_M;
+ inp->std = V4L2_STD_525_60;
strcpy(inp->name, "Camera");
return (0);
/* If more than one user, mutex should be added */
dev->users++;
- dprintk(1, "open minor=%d type=%s users=%d\n", minor,
+ dprintk(dev, 1, "open minor=%d type=%s users=%d\n", minor,
v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
/* allocate + initialize per filehandle data */
dev->h, dev->m, dev->s, (dev->us + 500) / 1000);
videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops,
- NULL, NULL, fh->type, V4L2_FIELD_INTERLACED,
+ NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED,
sizeof(struct vivi_buffer), fh);
return 0;
vivi_poll(struct file *file, struct poll_table_struct *wait)
{
struct vivi_fh *fh = file->private_data;
+ struct vivi_dev *dev = fh->dev;
struct videobuf_queue *q = &fh->vb_vidq;
- dprintk(1, "%s\n", __FUNCTION__);
+ dprintk(dev, 1, "%s\n", __FUNCTION__);
if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
return POLLERR;
dev->users--;
- dprintk(1, "close called (minor=%d, users=%d)\n", minor, dev->users);
+ dprintk(dev, 1, "close called (minor=%d, users=%d)\n",
+ minor, dev->users);
return 0;
}
static int vivi_mmap(struct file *file, struct vm_area_struct *vma)
{
- struct vivi_fh *fh = file->private_data;
+ struct vivi_fh *fh = file->private_data;
+ struct vivi_dev *dev = fh->dev;
int ret;
- dprintk(1, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
+ dprintk(dev, 1, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
- dprintk(1, "vma start=0x%08lx, size=%ld, ret=%d\n",
+ dprintk(dev, 1, "vma start=0x%08lx, size=%ld, ret=%d\n",
(unsigned long)vma->vm_start,
(unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
ret);
#ifdef CONFIG_VIDEO_V4L1_COMPAT
.vidiocgmbuf = vidiocgmbuf,
#endif
- .tvnorms = V4L2_STD_NTSC_M,
+ .tvnorms = V4L2_STD_525_60,
.current_norm = V4L2_STD_NTSC_M,
};
/* -----------------------------------------------------------------
/* initialize locks */
mutex_init(&dev->lock);
+ spin_lock_init(&dev->slock);
dev->vidq.timeout.function = vivi_vid_timeout;
dev->vidq.timeout.data = (unsigned long)dev;
module_param(n_devs, int, 0);
MODULE_PARM_DESC(n_devs, "number of video devices to create");
-module_param_named(debug, vivi.debug, int, 0644);
+module_param_named(debug, vivi_template.debug, int, 0444);
MODULE_PARM_DESC(debug, "activates debug info");
module_param(vid_limit, int, 0644);