V4L/DVB (9787): soc-camera: let camera host drivers decide upon pixel format
[deliverable/linux.git] / drivers / media / video / soc_camera.c
index 66ebe5956a878ef45cb0a591d88cb2496bea3bc2..01c33841d1c6fc70feb9272768c42a7dce3b4a4d 100644 (file)
@@ -35,8 +35,8 @@ static LIST_HEAD(devices);
 static DEFINE_MUTEX(list_lock);
 static DEFINE_MUTEX(video_lock);
 
-const static struct soc_camera_data_format*
-format_by_fourcc(struct soc_camera_device *icd, unsigned int fourcc)
+const struct soc_camera_data_format *soc_camera_format_by_fourcc(
+       struct soc_camera_device *icd, unsigned int fourcc)
 {
        unsigned int i;
 
@@ -45,53 +45,36 @@ format_by_fourcc(struct soc_camera_device *icd, unsigned int fourcc)
                        return icd->formats + i;
        return NULL;
 }
+EXPORT_SYMBOL(soc_camera_format_by_fourcc);
 
 static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv,
-                                 struct v4l2_format *f)
+                                     struct v4l2_format *f)
 {
        struct soc_camera_file *icf = file->private_data;
        struct soc_camera_device *icd = icf->icd;
        struct soc_camera_host *ici =
                to_soc_camera_host(icd->dev.parent);
        enum v4l2_field field;
-       const struct soc_camera_data_format *fmt;
        int ret;
 
        WARN_ON(priv != file->private_data);
 
-       fmt = format_by_fourcc(icd, f->fmt.pix.pixelformat);
-       if (!fmt) {
-               dev_dbg(&icd->dev, "invalid format 0x%08x\n",
-                       f->fmt.pix.pixelformat);
-               return -EINVAL;
-       }
-
-       dev_dbg(&icd->dev, "fmt: 0x%08x\n", fmt->fourcc);
-
+       /*
+        * TODO: this might also have to migrate to host-drivers, if anyone
+        * wishes to support other fields
+        */
        field = f->fmt.pix.field;
 
        if (field == V4L2_FIELD_ANY) {
-               field = V4L2_FIELD_NONE;
-       } else if (V4L2_FIELD_NONE != field) {
+               f->fmt.pix.field = V4L2_FIELD_NONE;
+       } else if (field != V4L2_FIELD_NONE) {
                dev_err(&icd->dev, "Field type invalid.\n");
                return -EINVAL;
        }
 
-       /* test physical bus parameters */
-       ret = ici->ops->try_bus_param(icd, f->fmt.pix.pixelformat);
-       if (ret)
-               return ret;
-
        /* limit format to hardware capabilities */
        ret = ici->ops->try_fmt_cap(icd, f);
 
-       /* calculate missing fields */
-       f->fmt.pix.field = field;
-       f->fmt.pix.bytesperline =
-               (f->fmt.pix.width * fmt->depth) >> 3;
-       f->fmt.pix.sizeimage =
-               f->fmt.pix.height * f->fmt.pix.bytesperline;
-
        return ret;
 }
 
@@ -265,7 +248,7 @@ static int soc_camera_close(struct inode *inode, struct file *file)
 }
 
 static ssize_t soc_camera_read(struct file *file, char __user *buf,
-                          size_t count, loff_t *ppos)
+                              size_t count, loff_t *ppos)
 {
        struct soc_camera_file *icf = file->private_data;
        struct soc_camera_device *icd = icf->icd;
@@ -310,7 +293,6 @@ static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
        return ici->ops->poll(file, pt);
 }
 
-
 static struct file_operations soc_camera_fops = {
        .owner          = THIS_MODULE,
        .open           = soc_camera_open,
@@ -322,9 +304,8 @@ static struct file_operations soc_camera_fops = {
        .llseek         = no_llseek,
 };
 
-
 static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
-                               struct v4l2_format *f)
+                                   struct v4l2_format *f)
 {
        struct soc_camera_file *icf = file->private_data;
        struct soc_camera_device *icd = icf->icd;
@@ -332,18 +313,10 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
                to_soc_camera_host(icd->dev.parent);
        int ret;
        struct v4l2_rect rect;
-       const static struct soc_camera_data_format *data_fmt;
 
        WARN_ON(priv != file->private_data);
 
-       data_fmt = format_by_fourcc(icd, f->fmt.pix.pixelformat);
-       if (!data_fmt)
-               return -EINVAL;
-
-       /* buswidth may be further adjusted by the ici */
-       icd->buswidth = data_fmt->depth;
-
-       ret = soc_camera_try_fmt_vid_cap(file, icf, f);
+       ret = soc_camera_try_fmt_vid_cap(file, priv, f);
        if (ret < 0)
                return ret;
 
@@ -352,14 +325,21 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
        rect.width      = f->fmt.pix.width;
        rect.height     = f->fmt.pix.height;
        ret = ici->ops->set_fmt_cap(icd, f->fmt.pix.pixelformat, &rect);
-       if (ret < 0)
+       if (ret < 0) {
                return ret;
+       } else if (!icd->current_fmt ||
+                  icd->current_fmt->fourcc != f->fmt.pix.pixelformat) {
+               dev_err(&ici->dev, "Host driver hasn't set up current "
+                       "format correctly!\n");
+               return -EINVAL;
+       }
 
-       icd->current_fmt        = data_fmt;
+       /* buswidth may be further adjusted by the ici */
+       icd->buswidth           = icd->current_fmt->depth;
        icd->width              = rect.width;
        icd->height             = rect.height;
        icf->vb_vidq.field      = f->fmt.pix.field;
-       if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type)
+       if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
                         f->type);
 
@@ -371,7 +351,7 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
 }
 
 static int soc_camera_enum_fmt_vid_cap(struct file *file, void  *priv,
-                                  struct v4l2_fmtdesc *f)
+                                      struct v4l2_fmtdesc *f)
 {
        struct soc_camera_file *icf = file->private_data;
        struct soc_camera_device *icd = icf->icd;
@@ -390,7 +370,7 @@ static int soc_camera_enum_fmt_vid_cap(struct file *file, void  *priv,
 }
 
 static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv,
-                               struct v4l2_format *f)
+                                   struct v4l2_format *f)
 {
        struct soc_camera_file *icf = file->private_data;
        struct soc_camera_device *icd = icf->icd;
@@ -401,10 +381,9 @@ static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv,
        f->fmt.pix.height       = icd->height;
        f->fmt.pix.field        = icf->vb_vidq.field;
        f->fmt.pix.pixelformat  = icd->current_fmt->fourcc;
-       f->fmt.pix.bytesperline =
-               (f->fmt.pix.width * icd->current_fmt->depth) >> 3;
-       f->fmt.pix.sizeimage    =
-               f->fmt.pix.height * f->fmt.pix.bytesperline;
+       f->fmt.pix.bytesperline = f->fmt.pix.width *
+               DIV_ROUND_UP(icd->current_fmt->depth, 8);
+       f->fmt.pix.sizeimage    = f->fmt.pix.height * f->fmt.pix.bytesperline;
        dev_dbg(&icd->dev, "current_fmt->fourcc: 0x%08x\n",
                icd->current_fmt->fourcc);
        return 0;
@@ -783,7 +762,7 @@ int soc_camera_host_register(struct soc_camera_host *ici)
                return -EINVAL;
 
        /* Number might be equal to the platform device ID */
-       sprintf(ici->dev.bus_id, "camera_host%d", ici->nr);
+       dev_set_name(&ici->dev, "camera_host%d", ici->nr);
 
        mutex_lock(&list_lock);
        list_for_each_entry(ix, &hosts, list) {
@@ -867,8 +846,7 @@ int soc_camera_device_register(struct soc_camera_device *icd)
 
        icd->devnum = num;
        icd->dev.bus = &soc_camera_bus_type;
-       snprintf(icd->dev.bus_id, sizeof(icd->dev.bus_id),
-                "%u-%u", icd->iface, icd->devnum);
+       dev_set_name(&icd->dev, "%u-%u", icd->iface, icd->devnum);
 
        icd->dev.release = dummy_release;
 
This page took 0.030952 seconds and 5 git commands to generate.