Skip to contentSkip to conversation

soc-camera: Why are exposure and gain handled via special cases?

DISCUSSION Jonathan Cameron 2 participants 2 messages Jun 8, 2009 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

Hi All,

Whilst working on merging the various ov7670 drivers posted recently, I came across the following in soc-camera:

static int soc_camera_g_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl)

{
	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);

	WARN_ON(priv != file->private_data);

	switch (ctrl->id) {
	case V4L2_CID_GAIN:
		if (icd->gain == (unsigned short)~0)
			return -EINVAL;
		ctrl->value = icd->gain;
		return 0;
	case V4L2_CID_EXPOSURE:
		if (icd->exposure == (unsigned short)~0)
			return -EINVAL;
		ctrl->value = icd->exposure;
		return 0;
	}

	return v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, core, g_ctrl, ctrl);
}

Why are these two cases and only these two handled by soc-camera rather than being passed on to the drivers?

Thanks,

Jonathan

#1 lore raw
Quoted 30 lines · Jonathan Cameron

Hi All,

Whilst working on merging the various ov7670 drivers posted recently, I came across the following in soc-camera:

static int soc_camera_g_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl)

{
	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);

	WARN_ON(priv != file->private_data);

	switch (ctrl->id) {
	case V4L2_CID_GAIN:
		if (icd->gain == (unsigned short)~0)
			return -EINVAL;
		ctrl->value = icd->gain;
		return 0;
	case V4L2_CID_EXPOSURE:
		if (icd->exposure == (unsigned short)~0)
			return -EINVAL;
		ctrl->value = icd->exposure;
		return 0;
	}

	return v4l2_device_call_until_err(&ici->v4l2_dev, (__u32)icd, core, g_ctrl, ctrl);
}
Quoted 2 lines

Why are these two cases and only these two handled by soc-camera rather than being passed on to the drivers?

In the case of statically configured gain and exposure it is the easiest to cache the last configured value and just return it when requested. At the time I wrote that code I wasn't sure what to return if autoexposure or autogain were configured. In the beginning these two controls actually also were implemented individually, but their implementation was identical, so, I united them. If this is becomming a problem now, we can revert it.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/