* [PATCH 1/3] soc-camera: remove .init() and .release() methods from struct soc_camera_ops
2009-08-25 11:05 [PATCH 0/3] soc-camera: moving towards v4l2-subdev Guennadi Liakhovetski
@ 2009-08-25 11:05 ` Guennadi Liakhovetski
2009-08-25 11:05 ` [PATCH 2/3] soc-camera: remove .gain and .exposure struct soc_camera_device members Guennadi Liakhovetski
2009-08-25 11:06 ` [PATCH 3/3] soc-camera: fix recently introduced overlong lines Guennadi Liakhovetski
2 siblings, 0 replies; 5+ messages in thread
From: Guennadi Liakhovetski @ 2009-08-25 11:05 UTC (permalink / raw)
To: Linux Media Mailing List
Remove unneeded soc-camera operations, this also makes the soc-camera API to
v4l2 subdevices thinner.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
drivers/media/video/mt9m001.c | 22 ++++++--------------
drivers/media/video/mt9m111.c | 40 +++++++------------------------------
drivers/media/video/mt9t031.c | 23 +++++----------------
drivers/media/video/mt9v022.c | 8 ++++--
drivers/media/video/soc_camera.c | 11 ----------
include/media/soc_camera.h | 4 ---
6 files changed, 26 insertions(+), 82 deletions(-)
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c
index e8cf561..4b39479 100644
--- a/drivers/media/video/mt9m001.c
+++ b/drivers/media/video/mt9m001.c
@@ -122,9 +122,8 @@ static int reg_clear(struct i2c_client *client, const u8 reg,
return reg_write(client, reg, ret & ~data);
}
-static int mt9m001_init(struct soc_camera_device *icd)
+static int mt9m001_init(struct i2c_client *client)
{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
int ret;
dev_dbg(&client->dev, "%s\n", __func__);
@@ -144,16 +143,6 @@ static int mt9m001_init(struct soc_camera_device *icd)
return ret;
}
-static int mt9m001_release(struct soc_camera_device *icd)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- /* Disable the chip */
- reg_write(client, MT9M001_OUTPUT_CONTROL, 0);
-
- return 0;
-}
-
static int mt9m001_s_stream(struct v4l2_subdev *sd, int enable)
{
struct i2c_client *client = sd->priv;
@@ -446,8 +435,6 @@ static const struct v4l2_queryctrl mt9m001_controls[] = {
};
static struct soc_camera_ops mt9m001_ops = {
- .init = mt9m001_init,
- .release = mt9m001_release,
.set_bus_param = mt9m001_set_bus_param,
.query_bus_param = mt9m001_query_bus_param,
.controls = mt9m001_controls,
@@ -581,6 +568,7 @@ static int mt9m001_video_probe(struct soc_camera_device *icd,
struct soc_camera_link *icl = to_soc_camera_link(icd);
s32 data;
unsigned long flags;
+ int ret;
/* We must have a parent by now. And it cannot be a wrong one.
* So this entire test is completely redundant. */
@@ -637,7 +625,11 @@ static int mt9m001_video_probe(struct soc_camera_device *icd,
dev_info(&client->dev, "Detected a MT9M001 chip ID %x (%s)\n", data,
data == 0x8431 ? "C12STM" : "C12ST");
- return 0;
+ ret = mt9m001_init(client);
+ if (ret < 0)
+ dev_err(&client->dev, "Failed to initialise the camera\n");
+
+ return ret;
}
static void mt9m001_video_remove(struct soc_camera_device *icd)
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 920dd53..186902f 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -672,13 +672,9 @@ static const struct v4l2_queryctrl mt9m111_controls[] = {
};
static int mt9m111_resume(struct soc_camera_device *icd);
-static int mt9m111_init(struct soc_camera_device *icd);
-static int mt9m111_release(struct soc_camera_device *icd);
static struct soc_camera_ops mt9m111_ops = {
- .init = mt9m111_init,
.resume = mt9m111_resume,
- .release = mt9m111_release,
.query_bus_param = mt9m111_query_bus_param,
.set_bus_param = mt9m111_set_bus_param,
.controls = mt9m111_controls,
@@ -880,9 +876,8 @@ static int mt9m111_resume(struct soc_camera_device *icd)
return ret;
}
-static int mt9m111_init(struct soc_camera_device *icd)
+static int mt9m111_init(struct i2c_client *client)
{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
struct mt9m111 *mt9m111 = to_mt9m111(client);
int ret;
@@ -899,22 +894,6 @@ static int mt9m111_init(struct soc_camera_device *icd)
return ret;
}
-static int mt9m111_release(struct soc_camera_device *icd)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
- struct mt9m111 *mt9m111 = to_mt9m111(client);
- int ret;
-
- ret = reg_clear(RESET, MT9M111_RESET_CHIP_ENABLE);
- if (!ret)
- mt9m111->powered = 0;
-
- if (ret < 0)
- dev_err(&client->dev, "mt9m11x release failed: %d\n", ret);
-
- return ret;
-}
-
/*
* Interface active, can use i2c. If it fails, it can indeed mean, that
* this wasn't our capture interface, so, we wait for the right one
@@ -934,10 +913,13 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
return -ENODEV;
- ret = mt9m111_enable(client);
- if (ret)
- goto ei2c;
- ret = mt9m111_reset(client);
+ mt9m111->autoexposure = 1;
+ mt9m111->autowhitebalance = 1;
+
+ mt9m111->swap_rgb_even_odd = 1;
+ mt9m111->swap_rgb_red_blue = 1;
+
+ ret = mt9m111_init(client);
if (ret)
goto ei2c;
@@ -962,12 +944,6 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
dev_info(&client->dev, "Detected a MT9M11x chip ID %x\n", data);
- mt9m111->autoexposure = 1;
- mt9m111->autowhitebalance = 1;
-
- mt9m111->swap_rgb_even_odd = 1;
- mt9m111->swap_rgb_red_blue = 1;
-
ei2c:
return ret;
}
diff --git a/drivers/media/video/mt9t031.c b/drivers/media/video/mt9t031.c
index f234ba6..9a64896 100644
--- a/drivers/media/video/mt9t031.c
+++ b/drivers/media/video/mt9t031.c
@@ -163,20 +163,6 @@ static int mt9t031_disable(struct i2c_client *client)
return 0;
}
-static int mt9t031_init(struct soc_camera_device *icd)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- return mt9t031_idle(client);
-}
-
-static int mt9t031_release(struct soc_camera_device *icd)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- return mt9t031_disable(client);
-}
-
static int mt9t031_s_stream(struct v4l2_subdev *sd, int enable)
{
struct i2c_client *client = sd->priv;
@@ -539,8 +525,6 @@ static const struct v4l2_queryctrl mt9t031_controls[] = {
};
static struct soc_camera_ops mt9t031_ops = {
- .init = mt9t031_init,
- .release = mt9t031_release,
.set_bus_param = mt9t031_set_bus_param,
.query_bus_param = mt9t031_query_bus_param,
.controls = mt9t031_controls,
@@ -689,6 +673,7 @@ static int mt9t031_video_probe(struct i2c_client *client)
struct soc_camera_device *icd = client->dev.platform_data;
struct mt9t031 *mt9t031 = to_mt9t031(client);
s32 data;
+ int ret;
/* Enable the chip */
data = reg_write(client, MT9T031_CHIP_ENABLE, 1);
@@ -711,7 +696,11 @@ static int mt9t031_video_probe(struct i2c_client *client)
dev_info(&client->dev, "Detected a MT9T031 chip ID %x\n", data);
- return 0;
+ ret = mt9t031_idle(client);
+ if (ret < 0)
+ dev_err(&client->dev, "Failed to initialise the camera\n");
+
+ return ret;
}
static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index 35ea0dd..5c47b55 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -138,9 +138,8 @@ static int reg_clear(struct i2c_client *client, const u8 reg,
return reg_write(client, reg, ret & ~data);
}
-static int mt9v022_init(struct soc_camera_device *icd)
+static int mt9v022_init(struct i2c_client *client)
{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
struct mt9v022 *mt9v022 = to_mt9v022(client);
int ret;
@@ -532,7 +531,6 @@ static const struct v4l2_queryctrl mt9v022_controls[] = {
};
static struct soc_camera_ops mt9v022_ops = {
- .init = mt9v022_init,
.set_bus_param = mt9v022_set_bus_param,
.query_bus_param = mt9v022_query_bus_param,
.controls = mt9v022_controls,
@@ -751,6 +749,10 @@ static int mt9v022_video_probe(struct soc_camera_device *icd,
data, mt9v022->model == V4L2_IDENT_MT9V022IX7ATM ?
"monochrome" : "colour");
+ ret = mt9v022_init(client);
+ if (ret < 0)
+ dev_err(&client->dev, "Failed to initialise the camera\n");
+
ei2c:
return ret;
}
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 86e0648..2792116 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -385,12 +385,6 @@ static int soc_camera_open(struct file *file)
goto eiciadd;
}
- if (icd->ops->init) {
- ret = icd->ops->init(icd);
- if (ret < 0)
- goto einit;
- }
-
/* Try to configure with default parameters */
ret = soc_camera_set_fmt(icf, &f);
if (ret < 0)
@@ -411,9 +405,6 @@ static int soc_camera_open(struct file *file)
* and use_count == 1
*/
esfmt:
- if (icd->ops->release)
- icd->ops->release(icd);
-einit:
ici->ops->remove(icd);
eiciadd:
if (icl->power)
@@ -438,8 +429,6 @@ static int soc_camera_close(struct file *file)
if (!icd->use_count) {
struct soc_camera_link *icl = to_soc_camera_link(icd);
- if (icd->ops->release)
- icd->ops->release(icd);
ici->ops->remove(icd);
if (icl->power)
icl->power(icd->pdev, 0);
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h
index 3185e8d..f95cc4a 100644
--- a/include/media/soc_camera.h
+++ b/include/media/soc_camera.h
@@ -191,12 +191,8 @@ struct soc_camera_format_xlate {
struct soc_camera_ops {
int (*suspend)(struct soc_camera_device *, pm_message_t state);
int (*resume)(struct soc_camera_device *);
- int (*init)(struct soc_camera_device *);
- int (*release)(struct soc_camera_device *);
unsigned long (*query_bus_param)(struct soc_camera_device *);
int (*set_bus_param)(struct soc_camera_device *, unsigned long);
- int (*get_chip_id)(struct soc_camera_device *,
- struct v4l2_dbg_chip_ident *);
int (*enum_input)(struct soc_camera_device *, struct v4l2_input *);
const struct v4l2_queryctrl *controls;
int num_controls;
--
1.6.2.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/3] soc-camera: remove .gain and .exposure struct soc_camera_device members
2009-08-25 11:05 [PATCH 0/3] soc-camera: moving towards v4l2-subdev Guennadi Liakhovetski
2009-08-25 11:05 ` [PATCH 1/3] soc-camera: remove .init() and .release() methods from struct soc_camera_ops Guennadi Liakhovetski
@ 2009-08-25 11:05 ` Guennadi Liakhovetski
2009-08-25 11:06 ` [PATCH 3/3] soc-camera: fix recently introduced overlong lines Guennadi Liakhovetski
2 siblings, 0 replies; 5+ messages in thread
From: Guennadi Liakhovetski @ 2009-08-25 11:05 UTC (permalink / raw)
To: Linux Media Mailing List
This makes the soc-camera interface for V4L2 subdevices thinner yet. Handle
gain and exposure internally in each driver just like all other controls.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
drivers/media/video/mt9m001.c | 43 ++++++++++++++++++++++++-------------
drivers/media/video/mt9m111.c | 20 ++++++++++++++---
drivers/media/video/mt9t031.c | 37 +++++++++++++++++++++-----------
drivers/media/video/mt9v022.c | 43 ++++++++++++++++++++++++++++---------
drivers/media/video/soc_camera.c | 19 ----------------
include/media/soc_camera.h | 2 -
6 files changed, 100 insertions(+), 64 deletions(-)
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c
index 4b39479..45388d2 100644
--- a/drivers/media/video/mt9m001.c
+++ b/drivers/media/video/mt9m001.c
@@ -80,6 +80,8 @@ struct mt9m001 {
struct v4l2_rect rect; /* Sensor window */
__u32 fourcc;
int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */
+ unsigned int gain;
+ unsigned int exposure;
unsigned char autoexposure;
};
@@ -129,8 +131,8 @@ static int mt9m001_init(struct i2c_client *client)
dev_dbg(&client->dev, "%s\n", __func__);
/*
- * We don't know, whether platform provides reset,
- * issue a soft reset too
+ * We don't know, whether platform provides reset, issue a soft reset
+ * too. This returns all registers to their default values.
*/
ret = reg_write(client, MT9M001_RESET, 1);
if (!ret)
@@ -200,6 +202,7 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
struct soc_camera_device *icd = client->dev.platform_data;
int ret;
const u16 hblank = 9, vblank = 25;
+ unsigned int total_h;
if (mt9m001->fourcc == V4L2_PIX_FMT_SBGGR8 ||
mt9m001->fourcc == V4L2_PIX_FMT_SBGGR16)
@@ -219,6 +222,8 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
soc_camera_limit_side(&rect.top, &rect.height,
MT9M001_ROW_SKIP, MT9M001_MIN_HEIGHT, MT9M001_MAX_HEIGHT);
+ total_h = rect.height + icd->y_skip_top + vblank;
+
/* Blanking and start values - default... */
ret = reg_write(client, MT9M001_HORIZONTAL_BLANKING, hblank);
if (!ret)
@@ -236,15 +241,13 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
ret = reg_write(client, MT9M001_WINDOW_HEIGHT,
rect.height + icd->y_skip_top - 1);
if (!ret && mt9m001->autoexposure) {
- ret = reg_write(client, MT9M001_SHUTTER_WIDTH,
- rect.height + icd->y_skip_top + vblank);
+ ret = reg_write(client, MT9M001_SHUTTER_WIDTH, total_h);
if (!ret) {
const struct v4l2_queryctrl *qctrl =
soc_camera_find_qctrl(icd->ops,
V4L2_CID_EXPOSURE);
- icd->exposure = (524 + (rect.height + icd->y_skip_top +
- vblank - 1) *
- (qctrl->maximum - qctrl->minimum)) /
+ mt9m001->exposure = (524 + (total_h - 1) *
+ (qctrl->maximum - qctrl->minimum)) /
1048 + qctrl->minimum;
}
}
@@ -457,6 +460,12 @@ static int mt9m001_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
case V4L2_CID_EXPOSURE_AUTO:
ctrl->value = mt9m001->autoexposure;
break;
+ case V4L2_CID_GAIN:
+ ctrl->value = mt9m001->gain;
+ break;
+ case V4L2_CID_EXPOSURE:
+ ctrl->value = mt9m001->exposure;
+ break;
}
return 0;
}
@@ -518,7 +527,7 @@ static int mt9m001_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
}
/* Success */
- icd->gain = ctrl->value;
+ mt9m001->gain = ctrl->value;
break;
case V4L2_CID_EXPOSURE:
/* mt9m001 has maximum == default */
@@ -535,21 +544,21 @@ static int mt9m001_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
shutter);
if (reg_write(client, MT9M001_SHUTTER_WIDTH, shutter) < 0)
return -EIO;
- icd->exposure = ctrl->value;
+ mt9m001->exposure = ctrl->value;
mt9m001->autoexposure = 0;
}
break;
case V4L2_CID_EXPOSURE_AUTO:
if (ctrl->value) {
const u16 vblank = 25;
+ unsigned int total_h = mt9m001->rect.height +
+ icd->y_skip_top + vblank;
if (reg_write(client, MT9M001_SHUTTER_WIDTH,
- mt9m001->rect.height +
- icd->y_skip_top + vblank) < 0)
+ total_h) < 0)
return -EIO;
qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
- icd->exposure = (524 + (mt9m001->rect.height +
- icd->y_skip_top + vblank - 1) *
- (qctrl->maximum - qctrl->minimum)) /
+ mt9m001->exposure = (524 + (total_h - 1) *
+ (qctrl->maximum - qctrl->minimum)) /
1048 + qctrl->minimum;
mt9m001->autoexposure = 1;
} else
@@ -629,6 +638,10 @@ static int mt9m001_video_probe(struct soc_camera_device *icd,
if (ret < 0)
dev_err(&client->dev, "Failed to initialise the camera\n");
+ /* mt9m001_init() has reset the chip, returning registers to defaults */
+ mt9m001->gain = 64;
+ mt9m001->exposure = 255;
+
return ret;
}
@@ -701,7 +714,7 @@ static int mt9m001_probe(struct i2c_client *client,
/* Second stage probe - when a capture adapter is there */
icd->ops = &mt9m001_ops;
- icd->y_skip_top = 1;
+ icd->y_skip_top = 0;
mt9m001->rect.left = MT9M001_COLUMN_SKIP;
mt9m001->rect.top = MT9M001_ROW_SKIP;
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 186902f..3ec6e4a 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -153,6 +153,7 @@ struct mt9m111 {
enum mt9m111_context context;
struct v4l2_rect rect;
u32 pixfmt;
+ unsigned int gain;
unsigned char autoexposure;
unsigned char datawidth;
unsigned int powered:1;
@@ -672,8 +673,10 @@ static const struct v4l2_queryctrl mt9m111_controls[] = {
};
static int mt9m111_resume(struct soc_camera_device *icd);
+static int mt9m111_suspend(struct soc_camera_device *icd, pm_message_t state);
static struct soc_camera_ops mt9m111_ops = {
+ .suspend = mt9m111_suspend,
.resume = mt9m111_resume,
.query_bus_param = mt9m111_query_bus_param,
.set_bus_param = mt9m111_set_bus_param,
@@ -714,13 +717,13 @@ static int mt9m111_get_global_gain(struct i2c_client *client)
static int mt9m111_set_global_gain(struct i2c_client *client, int gain)
{
- struct soc_camera_device *icd = client->dev.platform_data;
+ struct mt9m111 *mt9m111 = to_mt9m111(client);
u16 val;
if (gain > 63 * 2 * 2)
return -EINVAL;
- icd->gain = gain;
+ mt9m111->gain = gain;
if ((gain >= 64 * 2) && (gain < 63 * 2 * 2))
val = (1 << 10) | (1 << 9) | (gain / 4);
else if ((gain >= 64) && (gain < 64 * 2))
@@ -844,17 +847,26 @@ static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
return ret;
}
+static int mt9m111_suspend(struct soc_camera_device *icd, pm_message_t state)
+{
+ struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
+ struct mt9m111 *mt9m111 = to_mt9m111(client);
+
+ mt9m111->gain = mt9m111_get_global_gain(client);
+
+ return 0;
+}
+
static int mt9m111_restore_state(struct i2c_client *client)
{
struct mt9m111 *mt9m111 = to_mt9m111(client);
- struct soc_camera_device *icd = client->dev.platform_data;
mt9m111_set_context(client, mt9m111->context);
mt9m111_set_pixfmt(client, mt9m111->pixfmt);
mt9m111_setup_rect(client, &mt9m111->rect);
mt9m111_set_flip(client, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS);
mt9m111_set_flip(client, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS);
- mt9m111_set_global_gain(client, icd->gain);
+ mt9m111_set_global_gain(client, mt9m111->gain);
mt9m111_set_autoexposure(client, mt9m111->autoexposure);
mt9m111_set_autowhitebalance(client, mt9m111->autowhitebalance);
return 0;
diff --git a/drivers/media/video/mt9t031.c b/drivers/media/video/mt9t031.c
index 9a64896..6966f64 100644
--- a/drivers/media/video/mt9t031.c
+++ b/drivers/media/video/mt9t031.c
@@ -73,6 +73,8 @@ struct mt9t031 {
int model; /* V4L2_IDENT_MT9T031* codes from v4l2-chip-ident.h */
u16 xskip;
u16 yskip;
+ unsigned int gain;
+ unsigned int exposure;
unsigned char autoexposure;
};
@@ -301,16 +303,15 @@ static int mt9t031_set_params(struct soc_camera_device *icd,
ret = reg_write(client, MT9T031_WINDOW_HEIGHT,
rect->height + icd->y_skip_top - 1);
if (ret >= 0 && mt9t031->autoexposure) {
- ret = set_shutter(client,
- rect->height + icd->y_skip_top + vblank);
+ unsigned int total_h = rect->height + icd->y_skip_top + vblank;
+ ret = set_shutter(client, total_h);
if (ret >= 0) {
const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank;
const struct v4l2_queryctrl *qctrl =
soc_camera_find_qctrl(icd->ops,
V4L2_CID_EXPOSURE);
- icd->exposure = (shutter_max / 2 + (rect->height +
- icd->y_skip_top + vblank - 1) *
- (qctrl->maximum - qctrl->minimum)) /
+ mt9t031->exposure = (shutter_max / 2 + (total_h - 1) *
+ (qctrl->maximum - qctrl->minimum)) /
shutter_max + qctrl->minimum;
}
}
@@ -553,6 +554,12 @@ static int mt9t031_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
case V4L2_CID_EXPOSURE_AUTO:
ctrl->value = mt9t031->autoexposure;
break;
+ case V4L2_CID_GAIN:
+ ctrl->value = mt9t031->gain;
+ break;
+ case V4L2_CID_EXPOSURE:
+ ctrl->value = mt9t031->exposure;
+ break;
}
return 0;
}
@@ -624,7 +631,7 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
}
/* Success */
- icd->gain = ctrl->value;
+ mt9t031->gain = ctrl->value;
break;
case V4L2_CID_EXPOSURE:
/* mt9t031 has maximum == default */
@@ -641,7 +648,7 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
old, shutter);
if (set_shutter(client, shutter) < 0)
return -EIO;
- icd->exposure = ctrl->value;
+ mt9t031->exposure = ctrl->value;
mt9t031->autoexposure = 0;
}
break;
@@ -649,14 +656,14 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
if (ctrl->value) {
const u16 vblank = MT9T031_VERTICAL_BLANK;
const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank;
- if (set_shutter(client, mt9t031->rect.height +
- icd->y_skip_top + vblank) < 0)
+ unsigned int total_h = mt9t031->rect.height +
+ icd->y_skip_top + vblank;
+
+ if (set_shutter(client, total_h) < 0)
return -EIO;
qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
- icd->exposure = (shutter_max / 2 +
- (mt9t031->rect.height +
- icd->y_skip_top + vblank - 1) *
- (qctrl->maximum - qctrl->minimum)) /
+ mt9t031->exposure = (shutter_max / 2 + (total_h - 1) *
+ (qctrl->maximum - qctrl->minimum)) /
shutter_max + qctrl->minimum;
mt9t031->autoexposure = 1;
} else
@@ -700,6 +707,10 @@ static int mt9t031_video_probe(struct i2c_client *client)
if (ret < 0)
dev_err(&client->dev, "Failed to initialise the camera\n");
+ /* mt9t031_idle() has reset the chip to default. */
+ mt9t031->exposure = 255;
+ mt9t031->gain = 64;
+
return ret;
}
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index 5c47b55..2bfb26b 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -45,7 +45,7 @@ MODULE_PARM_DESC(sensor_type, "Sensor type: \"colour\" or \"monochrome\"");
#define MT9V022_PIXEL_OPERATION_MODE 0x0f
#define MT9V022_LED_OUT_CONTROL 0x1b
#define MT9V022_ADC_MODE_CONTROL 0x1c
-#define MT9V022_ANALOG_GAIN 0x34
+#define MT9V022_ANALOG_GAIN 0x35
#define MT9V022_BLACK_LEVEL_CALIB_CTRL 0x47
#define MT9V022_PIXCLK_FV_LV 0x74
#define MT9V022_DIGITAL_TEST_PATTERN 0x7f
@@ -156,6 +156,10 @@ static int mt9v022_init(struct i2c_client *client)
/* AEC, AGC on */
ret = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x3);
if (!ret)
+ ret = reg_write(client, MT9V022_ANALOG_GAIN, 16);
+ if (!ret)
+ ret = reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH, 480);
+ if (!ret)
ret = reg_write(client, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, 480);
if (!ret)
/* default - auto */
@@ -540,8 +544,12 @@ static struct soc_camera_ops mt9v022_ops = {
static int mt9v022_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{
struct i2c_client *client = sd->priv;
+ const struct v4l2_queryctrl *qctrl;
+ unsigned long range;
int data;
+ qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id);
+
switch (ctrl->id) {
case V4L2_CID_VFLIP:
data = reg_read(client, MT9V022_READ_MODE);
@@ -567,6 +575,24 @@ static int mt9v022_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
return -EIO;
ctrl->value = !!(data & 0x2);
break;
+ case V4L2_CID_GAIN:
+ data = reg_read(client, MT9V022_ANALOG_GAIN);
+ if (data < 0)
+ return -EIO;
+
+ range = qctrl->maximum - qctrl->minimum;
+ ctrl->value = ((data - 16) * range + 24) / 48 + qctrl->minimum;
+
+ break;
+ case V4L2_CID_EXPOSURE:
+ data = reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH);
+ if (data < 0)
+ return -EIO;
+
+ range = qctrl->maximum - qctrl->minimum;
+ ctrl->value = ((data - 1) * range + 239) / 479 + qctrl->minimum;
+
+ break;
}
return 0;
}
@@ -575,7 +601,6 @@ static int mt9v022_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{
int data;
struct i2c_client *client = sd->priv;
- struct soc_camera_device *icd = client->dev.platform_data;
const struct v4l2_queryctrl *qctrl;
qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id);
@@ -605,12 +630,9 @@ static int mt9v022_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
return -EINVAL;
else {
unsigned long range = qctrl->maximum - qctrl->minimum;
- /* Datasheet says 16 to 64. autogain only works properly
- * after setting gain to maximum 14. Larger values
- * produce "white fly" noise effect. On the whole,
- * manually setting analog gain does no good. */
+ /* Valid values 16 to 64, 32 to 64 must be even. */
unsigned long gain = ((ctrl->value - qctrl->minimum) *
- 10 + range / 2) / range + 4;
+ 48 + range / 2) / range + 16;
if (gain >= 32)
gain &= ~1;
/* The user wants to set gain manually, hope, she
@@ -619,11 +641,10 @@ static int mt9v022_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2) < 0)
return -EIO;
- dev_info(&client->dev, "Setting gain from %d to %lu\n",
- reg_read(client, MT9V022_ANALOG_GAIN), gain);
+ dev_dbg(&client->dev, "Setting gain from %d to %lu\n",
+ reg_read(client, MT9V022_ANALOG_GAIN), gain);
if (reg_write(client, MT9V022_ANALOG_GAIN, gain) < 0)
return -EIO;
- icd->gain = ctrl->value;
}
break;
case V4L2_CID_EXPOSURE:
@@ -646,7 +667,6 @@ static int mt9v022_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
if (reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH,
shutter) < 0)
return -EIO;
- icd->exposure = ctrl->value;
}
break;
case V4L2_CID_AUTOGAIN:
@@ -827,6 +847,7 @@ static int mt9v022_probe(struct i2c_client *client,
mt9v022->chip_control = MT9V022_CHIP_CONTROL_DEFAULT;
icd->ops = &mt9v022_ops;
+ /* MT9V022 _really_ corrupts the first read out line. TODO: verify on i.MX31 */
icd->y_skip_top = 1;
mt9v022->rect.left = MT9V022_COLUMN_SKIP;
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 2792116..95dfa43 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -670,19 +670,6 @@ static int soc_camera_g_ctrl(struct file *file, void *priv,
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;
- }
-
if (ici->ops->get_ctrl) {
ret = ici->ops->get_ctrl(icd, ctrl);
if (ret != -ENOIOCTLCMD)
@@ -1279,7 +1266,6 @@ static int video_dev_create(struct soc_camera_device *icd)
*/
static int soc_camera_video_start(struct soc_camera_device *icd)
{
- const struct v4l2_queryctrl *qctrl;
int ret;
if (!icd->dev.parent)
@@ -1297,11 +1283,6 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
return ret;
}
- qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_GAIN);
- icd->gain = qctrl ? qctrl->default_value : (unsigned short)~0;
- qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
- icd->exposure = qctrl ? qctrl->default_value : (unsigned short)~0;
-
return 0;
}
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h
index f95cc4a..fe20e33 100644
--- a/include/media/soc_camera.h
+++ b/include/media/soc_camera.h
@@ -27,8 +27,6 @@ struct soc_camera_device {
unsigned short width_min;
unsigned short height_min;
unsigned short y_skip_top; /* Lines to skip at the top */
- unsigned short gain;
- unsigned short exposure;
unsigned char iface; /* Host number */
unsigned char devnum; /* Device number per host */
unsigned char buswidth; /* See comment in .c */
--
1.6.2.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/3] soc-camera: fix recently introduced overlong lines
2009-08-25 11:05 [PATCH 0/3] soc-camera: moving towards v4l2-subdev Guennadi Liakhovetski
2009-08-25 11:05 ` [PATCH 1/3] soc-camera: remove .init() and .release() methods from struct soc_camera_ops Guennadi Liakhovetski
2009-08-25 11:05 ` [PATCH 2/3] soc-camera: remove .gain and .exposure struct soc_camera_device members Guennadi Liakhovetski
@ 2009-08-25 11:06 ` Guennadi Liakhovetski
2009-08-25 11:23 ` Paul Mundt
2 siblings, 1 reply; 5+ messages in thread
From: Guennadi Liakhovetski @ 2009-08-25 11:06 UTC (permalink / raw)
To: Linux Media Mailing List; +Cc: Paul Mundt
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: Paul Mundt <lethal@linux-sh.org>
---
arch/sh/boards/board-ap325rxa.c | 3 ++-
drivers/media/video/mt9m111.c | 9 +++++----
drivers/media/video/mt9v022.c | 5 ++++-
drivers/media/video/mx1_camera.c | 3 ++-
drivers/media/video/ov772x.c | 6 ++++--
drivers/media/video/pxa_camera.c | 3 ++-
drivers/media/video/soc_camera.c | 14 +++++++++++---
drivers/media/video/soc_camera_platform.c | 3 ++-
drivers/media/video/tw9910.c | 3 ++-
include/media/soc_camera.h | 15 ++++++++++-----
10 files changed, 44 insertions(+), 20 deletions(-)
diff --git a/arch/sh/boards/board-ap325rxa.c b/arch/sh/boards/board-ap325rxa.c
index e6a6428..b633b25 100644
--- a/arch/sh/boards/board-ap325rxa.c
+++ b/arch/sh/boards/board-ap325rxa.c
@@ -359,7 +359,8 @@ static void ap325rxa_camera_del(struct soc_camera_link *icl)
return;
platform_device_unregister(&camera_device);
- memset(&migor_camera_device.dev.kobj, 0, sizeof(migor_camera_device.dev.kobj));
+ memset(&migor_camera_device.dev.kobj, 0,
+ sizeof(migor_camera_device.dev.kobj));
}
#endif /* CONFIG_I2C */
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 3ec6e4a..90da699 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -514,7 +514,8 @@ static int mt9m111_set_pixfmt(struct i2c_client *client, u32 pixfmt)
ret = mt9m111_setfmt_yuv(client);
break;
default:
- dev_err(&client->dev, "Pixel format not handled : %x\n", pixfmt);
+ dev_err(&client->dev, "Pixel format not handled : %x\n",
+ pixfmt);
ret = -EINVAL;
}
@@ -537,9 +538,9 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
};
int ret;
- dev_dbg(&client->dev, "%s fmt=%x left=%d, top=%d, width=%d, height=%d\n",
- __func__, pix->pixelformat, rect.left, rect.top, rect.width,
- rect.height);
+ dev_dbg(&client->dev,
+ "%s fmt=%x left=%d, top=%d, width=%d, height=%d\n", __func__,
+ pix->pixelformat, rect.left, rect.top, rect.width, rect.height);
ret = mt9m111_make_rect(client, &rect);
if (!ret)
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index 2bfb26b..995607f 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -847,7 +847,10 @@ static int mt9v022_probe(struct i2c_client *client,
mt9v022->chip_control = MT9V022_CHIP_CONTROL_DEFAULT;
icd->ops = &mt9v022_ops;
- /* MT9V022 _really_ corrupts the first read out line. TODO: verify on i.MX31 */
+ /*
+ * MT9V022 _really_ corrupts the first read out line.
+ * TODO: verify on i.MX31
+ */
icd->y_skip_top = 1;
mt9v022->rect.left = MT9V022_COLUMN_SKIP;
diff --git a/drivers/media/video/mx1_camera.c b/drivers/media/video/mx1_camera.c
index 3875483..5f37952 100644
--- a/drivers/media/video/mx1_camera.c
+++ b/drivers/media/video/mx1_camera.c
@@ -548,7 +548,8 @@ static int mx1_camera_set_fmt(struct soc_camera_device *icd,
xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
if (!xlate) {
- dev_warn(icd->dev.parent, "Format %x not found\n", pix->pixelformat);
+ dev_warn(icd->dev.parent, "Format %x not found\n",
+ pix->pixelformat);
return -EINVAL;
}
diff --git a/drivers/media/video/ov772x.c b/drivers/media/video/ov772x.c
index 776a91d..eccb40a 100644
--- a/drivers/media/video/ov772x.c
+++ b/drivers/media/video/ov772x.c
@@ -404,7 +404,8 @@ struct ov772x_priv {
int model;
unsigned short flag_vflip:1;
unsigned short flag_hflip:1;
- unsigned short band_filter; /* 256 - BDBASE, 0 if (!COM8[5]) */
+ /* band_filter = COM8[5] ? 256 - BDBASE : 0 */
+ unsigned short band_filter;
};
#define ENDMARKER { 0xff, 0xff }
@@ -587,7 +588,8 @@ static const struct v4l2_queryctrl ov772x_controls[] = {
static struct ov772x_priv *to_ov772x(const struct i2c_client *client)
{
- return container_of(i2c_get_clientdata(client), struct ov772x_priv, subdev);
+ return container_of(i2c_get_clientdata(client), struct ov772x_priv,
+ subdev);
}
static int ov772x_write_array(struct i2c_client *client,
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index a19bb76..6952e96 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -274,7 +274,8 @@ static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) {
if (buf->dmas[i].sg_cpu)
- dma_free_coherent(ici->v4l2_dev.dev, buf->dmas[i].sg_size,
+ dma_free_coherent(ici->v4l2_dev.dev,
+ buf->dmas[i].sg_size,
buf->dmas[i].sg_cpu,
buf->dmas[i].sg_dma);
buf->dmas[i].sg_cpu = NULL;
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 95dfa43..e8248ba 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -327,7 +327,9 @@ static int soc_camera_set_fmt(struct soc_camera_file *icf,
static int soc_camera_open(struct file *file)
{
struct video_device *vdev = video_devdata(file);
- struct soc_camera_device *icd = container_of(vdev->parent, struct soc_camera_device, dev);
+ struct soc_camera_device *icd = container_of(vdev->parent,
+ struct soc_camera_device,
+ dev);
struct soc_camera_link *icl = to_soc_camera_link(icd);
struct soc_camera_host *ici;
struct soc_camera_file *icf;
@@ -349,7 +351,10 @@ static int soc_camera_open(struct file *file)
goto emgi;
}
- /* Protect against icd->ops->remove() until we module_get() both drivers. */
+ /*
+ * Protect against icd->ops->remove() until we module_get() both
+ * drivers.
+ */
mutex_lock(&icd->video_lock);
icf->icd = icd;
@@ -931,7 +936,10 @@ static int soc_camera_probe(struct device *dev)
if (ret < 0)
goto eadddev;
- /* FIXME: this is racy, have to use driver-binding notification */
+ /*
+ * FIXME: this is racy, have to use driver-binding notification,
+ * when it is available
+ */
control = to_soc_camera_control(icd);
if (!control || !control->driver || !dev_get_drvdata(control) ||
!try_module_get(control->driver->owner)) {
diff --git a/drivers/media/video/soc_camera_platform.c b/drivers/media/video/soc_camera_platform.c
index 3825c35..1b6dd02 100644
--- a/drivers/media/video/soc_camera_platform.c
+++ b/drivers/media/video/soc_camera_platform.c
@@ -33,7 +33,8 @@ static struct soc_camera_platform_priv *get_priv(struct platform_device *pdev)
static struct soc_camera_platform_info *get_info(struct soc_camera_device *icd)
{
- struct platform_device *pdev = to_platform_device(to_soc_camera_control(icd));
+ struct platform_device *pdev =
+ to_platform_device(to_soc_camera_control(icd));
return pdev->dev.platform_data;
}
diff --git a/drivers/media/video/tw9910.c b/drivers/media/video/tw9910.c
index fbf4130..269ab04 100644
--- a/drivers/media/video/tw9910.c
+++ b/drivers/media/video/tw9910.c
@@ -357,7 +357,8 @@ static const struct tw9910_hsync_ctrl tw9910_hsync_ctrl = {
*/
static struct tw9910_priv *to_tw9910(const struct i2c_client *client)
{
- return container_of(i2c_get_clientdata(client), struct tw9910_priv, subdev);
+ return container_of(i2c_get_clientdata(client), struct tw9910_priv,
+ subdev);
}
static int tw9910_set_scale(struct i2c_client *client,
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h
index fe20e33..3d74e60 100644
--- a/include/media/soc_camera.h
+++ b/include/media/soc_camera.h
@@ -126,29 +126,34 @@ struct soc_camera_link {
void (*free_bus)(struct soc_camera_link *);
};
-static inline struct soc_camera_device *to_soc_camera_dev(const struct device *dev)
+static inline struct soc_camera_device *to_soc_camera_dev(
+ const struct device *dev)
{
return container_of(dev, struct soc_camera_device, dev);
}
-static inline struct soc_camera_host *to_soc_camera_host(const struct device *dev)
+static inline struct soc_camera_host *to_soc_camera_host(
+ const struct device *dev)
{
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
return container_of(v4l2_dev, struct soc_camera_host, v4l2_dev);
}
-static inline struct soc_camera_link *to_soc_camera_link(const struct soc_camera_device *icd)
+static inline struct soc_camera_link *to_soc_camera_link(
+ const struct soc_camera_device *icd)
{
return icd->dev.platform_data;
}
-static inline struct device *to_soc_camera_control(const struct soc_camera_device *icd)
+static inline struct device *to_soc_camera_control(
+ const struct soc_camera_device *icd)
{
return dev_get_drvdata(&icd->dev);
}
-static inline struct v4l2_subdev *soc_camera_to_subdev(const struct soc_camera_device *icd)
+static inline struct v4l2_subdev *soc_camera_to_subdev(
+ const struct soc_camera_device *icd)
{
struct device *control = to_soc_camera_control(icd);
return dev_get_drvdata(control);
--
1.6.2.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 3/3] soc-camera: fix recently introduced overlong lines
2009-08-25 11:06 ` [PATCH 3/3] soc-camera: fix recently introduced overlong lines Guennadi Liakhovetski
@ 2009-08-25 11:23 ` Paul Mundt
0 siblings, 0 replies; 5+ messages in thread
From: Paul Mundt @ 2009-08-25 11:23 UTC (permalink / raw)
To: Guennadi Liakhovetski; +Cc: Linux Media Mailing List
On Tue, Aug 25, 2009 at 01:06:07PM +0200, Guennadi Liakhovetski wrote:
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> Cc: Paul Mundt <lethal@linux-sh.org>
> ---
> arch/sh/boards/board-ap325rxa.c | 3 ++-
> drivers/media/video/mt9m111.c | 9 +++++----
> drivers/media/video/mt9v022.c | 5 ++++-
> drivers/media/video/mx1_camera.c | 3 ++-
> drivers/media/video/ov772x.c | 6 ++++--
> drivers/media/video/pxa_camera.c | 3 ++-
> drivers/media/video/soc_camera.c | 14 +++++++++++---
> drivers/media/video/soc_camera_platform.c | 3 ++-
> drivers/media/video/tw9910.c | 3 ++-
> include/media/soc_camera.h | 15 ++++++++++-----
> 10 files changed, 44 insertions(+), 20 deletions(-)
>
Acked-by: Paul Mundt <lethal@linux-sh.org>
^ permalink raw reply [flat|nested] 5+ messages in thread