{
unsigned int i;
- for (i = 0; i < icd->ops->num_formats; i++)
- if (icd->ops->formats[i].fourcc == fourcc)
- return icd->ops->formats + i;
+ for (i = 0; i < icd->num_formats; i++)
+ if (icd->formats[i].fourcc == fourcc)
+ return icd->formats + i;
return NULL;
}
-static int soc_camera_try_fmt_cap(struct file *file, void *priv,
+static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
{
struct soc_camera_file *icf = file->private_data;
}
/* test physical bus parameters */
- ret = ici->try_bus_param(icd, f->fmt.pix.pixelformat);
+ ret = ici->ops->try_bus_param(icd, f->fmt.pix.pixelformat);
if (ret)
return ret;
/* limit format to hardware capabilities */
- ret = ici->try_fmt_cap(icd, f);
+ ret = ici->ops->try_fmt_cap(icd, f);
/* calculate missing fields */
f->fmt.pix.field = field;
WARN_ON(priv != file->private_data);
- dev_dbg(&icd->dev, "%s: %d\n", __FUNCTION__, p->memory);
+ dev_dbg(&icd->dev, "%s: %d\n", __func__, p->memory);
ret = videobuf_reqbufs(&icf->vb_vidq, p);
if (ret < 0)
return ret;
- return ici->reqbufs(icf, p);
-
- return ret;
+ return ici->ops->reqbufs(icf, p);
}
static int soc_camera_querybuf(struct file *file, void *priv,
struct soc_camera_device *icd;
struct soc_camera_host *ici;
struct soc_camera_file *icf;
+ spinlock_t *lock;
int ret;
icf = vmalloc(sizeof(*icf));
goto emgd;
}
- if (!try_module_get(ici->owner)) {
+ if (!try_module_get(ici->ops->owner)) {
dev_err(&icd->dev, "Couldn't lock capture bus driver.\n");
ret = -EINVAL;
goto emgi;
}
- icd->use_count++;
-
icf->icd = icd;
+ icf->lock = ici->ops->spinlock_alloc(icf);
+ if (!icf->lock) {
+ ret = -ENOMEM;
+ goto esla;
+ }
+
+ icd->use_count++;
+
/* Now we really have to activate the camera */
if (icd->use_count == 1) {
- ret = ici->add(icd);
+ ret = ici->ops->add(icd);
if (ret < 0) {
dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret);
icd->use_count--;
dev_dbg(&icd->dev, "camera device open\n");
/* We must pass NULL as dev pointer, then all pci_* dma operations
- * transform to normal dma_* ones. Do we need an irqlock? */
- videobuf_queue_sg_init(&icf->vb_vidq, ici->vbq_ops, NULL, NULL,
+ * transform to normal dma_* ones. */
+ videobuf_queue_sg_init(&icf->vb_vidq, ici->vbq_ops, NULL, icf->lock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
ici->msize, icd);
/* All errors are entered with the video_lock held */
eiciadd:
- module_put(ici->owner);
+ lock = icf->lock;
+ icf->lock = NULL;
+ if (ici->ops->spinlock_free)
+ ici->ops->spinlock_free(lock);
+esla:
+ module_put(ici->ops->owner);
emgi:
module_put(icd->ops->owner);
emgd:
struct soc_camera_device *icd = icf->icd;
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct video_device *vdev = icd->vdev;
+ spinlock_t *lock = icf->lock;
mutex_lock(&video_lock);
icd->use_count--;
if (!icd->use_count)
- ici->remove(icd);
+ ici->ops->remove(icd);
+ icf->lock = NULL;
+ if (ici->ops->spinlock_free)
+ ici->ops->spinlock_free(lock);
module_put(icd->ops->owner);
- module_put(ici->owner);
+ module_put(ici->ops->owner);
mutex_unlock(&video_lock);
- vfree(file->private_data);
+ vfree(icf);
dev_dbg(vdev->dev, "camera device close\n");
return POLLERR;
}
- return ici->poll(file, pt);
+ return ici->ops->poll(file, pt);
}
};
-static int soc_camera_s_fmt_cap(struct file *file, void *priv,
+static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
{
struct soc_camera_file *icf = file->private_data;
/* buswidth may be further adjusted by the ici */
icd->buswidth = data_fmt->depth;
- ret = soc_camera_try_fmt_cap(file, icf, f);
+ ret = soc_camera_try_fmt_vid_cap(file, icf, f);
if (ret < 0)
return ret;
rect.top = icd->y_current;
rect.width = f->fmt.pix.width;
rect.height = f->fmt.pix.height;
- ret = ici->set_fmt_cap(icd, f->fmt.pix.pixelformat, &rect);
+ ret = ici->ops->set_fmt_cap(icd, f->fmt.pix.pixelformat, &rect);
if (ret < 0)
return ret;
icd->width, icd->height);
/* set physical bus parameters */
- return ici->set_bus_param(icd, f->fmt.pix.pixelformat);
+ return ici->ops->set_bus_param(icd, f->fmt.pix.pixelformat);
}
-static int soc_camera_enum_fmt_cap(struct file *file, void *priv,
+static int soc_camera_enum_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
struct soc_camera_file *icf = file->private_data;
WARN_ON(priv != file->private_data);
- if (f->index >= icd->ops->num_formats)
+ if (f->index >= icd->num_formats)
return -EINVAL;
- format = &icd->ops->formats[f->index];
+ format = &icd->formats[f->index];
strlcpy(f->description, format->name, sizeof(f->description));
f->pixelformat = format->fourcc;
return 0;
}
-static int soc_camera_g_fmt_cap(struct file *file, void *priv,
+static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
{
struct soc_camera_file *icf = file->private_data;
WARN_ON(priv != file->private_data);
strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver));
- return ici->querycap(ici, cap);
+ return ici->ops->querycap(ici, cap);
}
static int soc_camera_streamon(struct file *file, void *priv,
WARN_ON(priv != file->private_data);
- dev_dbg(&icd->dev, "%s\n", __FUNCTION__);
+ dev_dbg(&icd->dev, "%s\n", __func__);
if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
WARN_ON(priv != file->private_data);
- dev_dbg(&icd->dev, "%s\n", __FUNCTION__);
+ dev_dbg(&icd->dev, "%s\n", __func__);
if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
- ret = ici->set_fmt_cap(icd, 0, &a->c);
+ ret = ici->ops->set_fmt_cap(icd, 0, &a->c);
if (!ret) {
icd->width = a->c.width;
icd->height = a->c.height;
to_soc_camera_host(icd->dev.parent);
int ret;
- if (!icd->probe)
+ if (!icd->ops->probe)
return -ENODEV;
/* We only call ->add() here to activate and probe the camera.
* We shall ->remove() and deactivate it immediately afterwards. */
- ret = ici->add(icd);
+ ret = ici->ops->add(icd);
if (ret < 0)
return ret;
- ret = icd->probe(icd);
+ ret = icd->ops->probe(icd);
if (ret >= 0) {
const struct v4l2_queryctrl *qctrl;
icd->exposure = qctrl ? qctrl->default_value :
(unsigned short)~0;
}
- ici->remove(icd);
+ ici->ops->remove(icd);
return ret;
}
{
struct soc_camera_device *icd = to_soc_camera_dev(dev);
- if (icd->remove)
- icd->remove(icd);
+ if (icd->ops->remove)
+ icd->ops->remove(icd);
return 0;
}
.owner = THIS_MODULE,
};
-/*
- * Image capture host - this is a host device, not a bus device, so,
- * no bus reference, no probing.
- */
-static struct class soc_camera_host_class = {
- .owner = THIS_MODULE,
- .name = "camera_host",
-};
-
static void dummy_release(struct device *dev)
{
}
-int soc_camera_host_register(struct soc_camera_host *ici, struct module *owner)
+static spinlock_t *spinlock_alloc(struct soc_camera_file *icf)
+{
+ spinlock_t *lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
+
+ if (lock)
+ spin_lock_init(lock);
+
+ return lock;
+}
+
+static void spinlock_free(spinlock_t *lock)
+{
+ kfree(lock);
+}
+
+int soc_camera_host_register(struct soc_camera_host *ici)
{
int ret;
struct soc_camera_host *ix;
- if (!ici->vbq_ops || !ici->add || !ici->remove || !owner)
+ if (!ici->vbq_ops || !ici->ops->add || !ici->ops->remove)
return -EINVAL;
/* Number might be equal to the platform device ID */
sprintf(ici->dev.bus_id, "camera_host%d", ici->nr);
- ici->dev.class = &soc_camera_host_class;
mutex_lock(&list_lock);
list_for_each_entry(ix, &hosts, list) {
list_add_tail(&ici->list, &hosts);
mutex_unlock(&list_lock);
- ici->owner = owner;
ici->dev.release = dummy_release;
ret = device_register(&ici->dev);
if (ret)
goto edevr;
+ if (!ici->ops->spinlock_alloc) {
+ ici->ops->spinlock_alloc = spinlock_alloc;
+ ici->ops->spinlock_free = spinlock_free;
+ }
+
scan_add_host(ici);
return 0;
if (icd->dev.parent == &ici->dev) {
device_unregister(&icd->dev);
/* Not before device_unregister(), .remove
- * needs parent to call ici->remove() */
+ * needs parent to call ici->ops->remove() */
icd->dev.parent = NULL;
memset(&icd->dev.kobj, 0, sizeof(icd->dev.kobj));
}
vdev->minor = -1;
vdev->tvnorms = V4L2_STD_UNKNOWN,
vdev->vidioc_querycap = soc_camera_querycap;
- vdev->vidioc_g_fmt_cap = soc_camera_g_fmt_cap;
- vdev->vidioc_enum_fmt_cap = soc_camera_enum_fmt_cap;
- vdev->vidioc_s_fmt_cap = soc_camera_s_fmt_cap;
+ vdev->vidioc_g_fmt_vid_cap = soc_camera_g_fmt_vid_cap;
+ vdev->vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap;
+ vdev->vidioc_s_fmt_vid_cap = soc_camera_s_fmt_vid_cap;
vdev->vidioc_enum_input = soc_camera_enum_input;
vdev->vidioc_g_input = soc_camera_g_input;
vdev->vidioc_s_input = soc_camera_s_input;
vdev->vidioc_s_std = soc_camera_s_std;
vdev->vidioc_reqbufs = soc_camera_reqbufs;
- vdev->vidioc_try_fmt_cap = soc_camera_try_fmt_cap;
+ vdev->vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap;
vdev->vidioc_querybuf = soc_camera_querybuf;
vdev->vidioc_qbuf = soc_camera_qbuf;
vdev->vidioc_dqbuf = soc_camera_dqbuf;
vdev->vidioc_s_register = soc_camera_s_register;
#endif
- icd->current_fmt = &icd->ops->formats[0];
+ icd->current_fmt = &icd->formats[0];
err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor);
if (err < 0) {
{
struct video_device *vdev = icd->vdev;
- dev_dbg(&icd->dev, "%s\n", __FUNCTION__);
+ dev_dbg(&icd->dev, "%s\n", __func__);
if (!icd->dev.parent || !vdev)
return;
ret = driver_register(&ic_drv);
if (ret)
goto edrvr;
- ret = class_register(&soc_camera_host_class);
- if (ret)
- goto eclr;
return 0;
-eclr:
- driver_unregister(&ic_drv);
edrvr:
bus_unregister(&soc_camera_bus_type);
return ret;
static void __exit soc_camera_exit(void)
{
- class_unregister(&soc_camera_host_class);
driver_unregister(&ic_drv);
bus_unregister(&soc_camera_bus_type);
}