Commit afd9690c authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] ov6650: convert to the control framework

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
[g.liakhovetski@gmx.de: simplified pointer arithmetic]
[jkrzyszt@tis.icnet.pl: fix a typo in the register name]
Acked-by: default avatarJanusz Krzysztofik <jkrzyszt@tis.icnet.pl>
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent f026671d
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <media/soc_camera.h> #include <media/soc_camera.h>
#include <media/soc_mediabus.h> #include <media/soc_mediabus.h>
#include <media/v4l2-chip-ident.h> #include <media/v4l2-chip-ident.h>
#include <media/v4l2-ctrls.h>
/* Register definitions */ /* Register definitions */
#define REG_GAIN 0x00 /* range 00 - 3F */ #define REG_GAIN 0x00 /* range 00 - 3F */
...@@ -177,20 +178,23 @@ struct ov6650_reg { ...@@ -177,20 +178,23 @@ struct ov6650_reg {
struct ov6650 { struct ov6650 {
struct v4l2_subdev subdev; struct v4l2_subdev subdev;
struct v4l2_ctrl_handler hdl;
int gain; struct {
int blue; /* exposure/autoexposure cluster */
int red; struct v4l2_ctrl *autoexposure;
int saturation; struct v4l2_ctrl *exposure;
int hue; };
int brightness; struct {
int exposure; /* gain/autogain cluster */
int gamma; struct v4l2_ctrl *autogain;
int aec; struct v4l2_ctrl *gain;
bool vflip; };
bool hflip; struct {
bool awb; /* blue/red/autowhitebalance cluster */
bool agc; struct v4l2_ctrl *autowb;
struct v4l2_ctrl *blue;
struct v4l2_ctrl *red;
};
bool half_scale; /* scale down output by 2 */ bool half_scale; /* scale down output by 2 */
struct v4l2_rect rect; /* sensor cropping window */ struct v4l2_rect rect; /* sensor cropping window */
unsigned long pclk_limit; /* from host */ unsigned long pclk_limit; /* from host */
...@@ -210,126 +214,6 @@ static enum v4l2_mbus_pixelcode ov6650_codes[] = { ...@@ -210,126 +214,6 @@ static enum v4l2_mbus_pixelcode ov6650_codes[] = {
V4L2_MBUS_FMT_Y8_1X8, V4L2_MBUS_FMT_Y8_1X8,
}; };
static const struct v4l2_queryctrl ov6650_controls[] = {
{
.id = V4L2_CID_AUTOGAIN,
.type = V4L2_CTRL_TYPE_BOOLEAN,
.name = "AGC",
.minimum = 0,
.maximum = 1,
.step = 1,
.default_value = 1,
},
{
.id = V4L2_CID_GAIN,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Gain",
.minimum = 0,
.maximum = 0x3f,
.step = 1,
.default_value = DEF_GAIN,
},
{
.id = V4L2_CID_AUTO_WHITE_BALANCE,
.type = V4L2_CTRL_TYPE_BOOLEAN,
.name = "AWB",
.minimum = 0,
.maximum = 1,
.step = 1,
.default_value = 1,
},
{
.id = V4L2_CID_BLUE_BALANCE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Blue",
.minimum = 0,
.maximum = 0xff,
.step = 1,
.default_value = DEF_BLUE,
},
{
.id = V4L2_CID_RED_BALANCE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Red",
.minimum = 0,
.maximum = 0xff,
.step = 1,
.default_value = DEF_RED,
},
{
.id = V4L2_CID_SATURATION,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Saturation",
.minimum = 0,
.maximum = 0xf,
.step = 1,
.default_value = 0x8,
},
{
.id = V4L2_CID_HUE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Hue",
.minimum = 0,
.maximum = HUE_MASK,
.step = 1,
.default_value = DEF_HUE,
},
{
.id = V4L2_CID_BRIGHTNESS,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Brightness",
.minimum = 0,
.maximum = 0xff,
.step = 1,
.default_value = 0x80,
},
{
.id = V4L2_CID_EXPOSURE_AUTO,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "AEC",
.minimum = 0,
.maximum = 3,
.step = 1,
.default_value = 0,
},
{
.id = V4L2_CID_EXPOSURE,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Exposure",
.minimum = 0,
.maximum = 0xff,
.step = 1,
.default_value = DEF_AECH,
},
{
.id = V4L2_CID_GAMMA,
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Gamma",
.minimum = 0,
.maximum = 0xff,
.step = 1,
.default_value = 0x12,
},
{
.id = V4L2_CID_VFLIP,
.type = V4L2_CTRL_TYPE_BOOLEAN,
.name = "Flip Vertically",
.minimum = 0,
.maximum = 1,
.step = 1,
.default_value = 0,
},
{
.id = V4L2_CID_HFLIP,
.type = V4L2_CTRL_TYPE_BOOLEAN,
.name = "Flip Horizontally",
.minimum = 0,
.maximum = 1,
.step = 1,
.default_value = 0,
},
};
/* read a register */ /* read a register */
static int ov6650_reg_read(struct i2c_client *client, u8 reg, u8 *val) static int ov6650_reg_read(struct i2c_client *client, u8 reg, u8 *val)
{ {
...@@ -420,166 +304,91 @@ static int ov6650_s_stream(struct v4l2_subdev *sd, int enable) ...@@ -420,166 +304,91 @@ static int ov6650_s_stream(struct v4l2_subdev *sd, int enable)
} }
/* Get status of additional camera capabilities */ /* Get status of additional camera capabilities */
static int ov6650_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) static int ov6550_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
{ {
struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl);
struct v4l2_subdev *sd = &priv->subdev;
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
struct ov6650 *priv = to_ov6650(client); uint8_t reg, reg2;
uint8_t reg;
int ret = 0; int ret = 0;
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_AUTOGAIN: case V4L2_CID_AUTOGAIN:
ctrl->value = priv->agc;
break;
case V4L2_CID_GAIN:
if (priv->agc) {
ret = ov6650_reg_read(client, REG_GAIN, &reg); ret = ov6650_reg_read(client, REG_GAIN, &reg);
ctrl->value = reg; if (!ret)
} else { priv->gain->val = reg;
ctrl->value = priv->gain; return ret;
}
break;
case V4L2_CID_AUTO_WHITE_BALANCE: case V4L2_CID_AUTO_WHITE_BALANCE:
ctrl->value = priv->awb;
break;
case V4L2_CID_BLUE_BALANCE:
if (priv->awb) {
ret = ov6650_reg_read(client, REG_BLUE, &reg); ret = ov6650_reg_read(client, REG_BLUE, &reg);
ctrl->value = reg; if (!ret)
} else { ret = ov6650_reg_read(client, REG_RED, &reg2);
ctrl->value = priv->blue; if (!ret) {
} priv->blue->val = reg;
break; priv->red->val = reg2;
case V4L2_CID_RED_BALANCE:
if (priv->awb) {
ret = ov6650_reg_read(client, REG_RED, &reg);
ctrl->value = reg;
} else {
ctrl->value = priv->red;
} }
break; return ret;
case V4L2_CID_SATURATION:
ctrl->value = priv->saturation;
break;
case V4L2_CID_HUE:
ctrl->value = priv->hue;
break;
case V4L2_CID_BRIGHTNESS:
ctrl->value = priv->brightness;
break;
case V4L2_CID_EXPOSURE_AUTO: case V4L2_CID_EXPOSURE_AUTO:
ctrl->value = priv->aec;
break;
case V4L2_CID_EXPOSURE:
if (priv->aec) {
ret = ov6650_reg_read(client, REG_AECH, &reg); ret = ov6650_reg_read(client, REG_AECH, &reg);
ctrl->value = reg; if (!ret)
} else { priv->exposure->val = reg;
ctrl->value = priv->exposure;
}
break;
case V4L2_CID_GAMMA:
ctrl->value = priv->gamma;
break;
case V4L2_CID_VFLIP:
ctrl->value = priv->vflip;
break;
case V4L2_CID_HFLIP:
ctrl->value = priv->hflip;
break;
}
return ret; return ret;
}
return -EINVAL;
} }
/* Set status of additional camera capabilities */ /* Set status of additional camera capabilities */
static int ov6650_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) static int ov6550_s_ctrl(struct v4l2_ctrl *ctrl)
{ {
struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl);
struct v4l2_subdev *sd = &priv->subdev;
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
struct ov6650 *priv = to_ov6650(client);
int ret = 0; int ret = 0;
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_AUTOGAIN: case V4L2_CID_AUTOGAIN:
ret = ov6650_reg_rmw(client, REG_COMB, ret = ov6650_reg_rmw(client, REG_COMB,
ctrl->value ? COMB_AGC : 0, COMB_AGC); ctrl->val ? COMB_AGC : 0, COMB_AGC);
if (!ret) if (!ret && !ctrl->val)
priv->agc = ctrl->value; ret = ov6650_reg_write(client, REG_GAIN, priv->gain->val);
break; return ret;
case V4L2_CID_GAIN:
ret = ov6650_reg_write(client, REG_GAIN, ctrl->value);
if (!ret)
priv->gain = ctrl->value;
break;
case V4L2_CID_AUTO_WHITE_BALANCE: case V4L2_CID_AUTO_WHITE_BALANCE:
ret = ov6650_reg_rmw(client, REG_COMB, ret = ov6650_reg_rmw(client, REG_COMB,
ctrl->value ? COMB_AWB : 0, COMB_AWB); ctrl->val ? COMB_AWB : 0, COMB_AWB);
if (!ret && !ctrl->val) {
ret = ov6650_reg_write(client, REG_BLUE, priv->blue->val);
if (!ret) if (!ret)
priv->awb = ctrl->value; ret = ov6650_reg_write(client, REG_RED,
break; priv->red->val);
case V4L2_CID_BLUE_BALANCE: }
ret = ov6650_reg_write(client, REG_BLUE, ctrl->value); return ret;
if (!ret)
priv->blue = ctrl->value;
break;
case V4L2_CID_RED_BALANCE:
ret = ov6650_reg_write(client, REG_RED, ctrl->value);
if (!ret)
priv->red = ctrl->value;
break;
case V4L2_CID_SATURATION: case V4L2_CID_SATURATION:
ret = ov6650_reg_rmw(client, REG_SAT, SET_SAT(ctrl->value), return ov6650_reg_rmw(client, REG_SAT, SET_SAT(ctrl->val),
SAT_MASK); SAT_MASK);
if (!ret)
priv->saturation = ctrl->value;
break;
case V4L2_CID_HUE: case V4L2_CID_HUE:
ret = ov6650_reg_rmw(client, REG_HUE, SET_HUE(ctrl->value), return ov6650_reg_rmw(client, REG_HUE, SET_HUE(ctrl->val),
HUE_MASK); HUE_MASK);
if (!ret)
priv->hue = ctrl->value;
break;
case V4L2_CID_BRIGHTNESS: case V4L2_CID_BRIGHTNESS:
ret = ov6650_reg_write(client, REG_BRT, ctrl->value); return ov6650_reg_write(client, REG_BRT, ctrl->val);
if (!ret)
priv->brightness = ctrl->value;
break;
case V4L2_CID_EXPOSURE_AUTO: case V4L2_CID_EXPOSURE_AUTO:
switch (ctrl->value) { if (ctrl->val == V4L2_EXPOSURE_AUTO)
case V4L2_EXPOSURE_AUTO:
ret = ov6650_reg_rmw(client, REG_COMB, COMB_AEC, 0); ret = ov6650_reg_rmw(client, REG_COMB, COMB_AEC, 0);
break; else
default:
ret = ov6650_reg_rmw(client, REG_COMB, 0, COMB_AEC); ret = ov6650_reg_rmw(client, REG_COMB, 0, COMB_AEC);
break; if (!ret && ctrl->val == V4L2_EXPOSURE_MANUAL)
} ret = ov6650_reg_write(client, REG_AECH,
if (!ret) priv->exposure->val);
priv->aec = ctrl->value; return ret;
break;
case V4L2_CID_EXPOSURE:
ret = ov6650_reg_write(client, REG_AECH, ctrl->value);
if (!ret)
priv->exposure = ctrl->value;
break;
case V4L2_CID_GAMMA: case V4L2_CID_GAMMA:
ret = ov6650_reg_write(client, REG_GAM1, ctrl->value); return ov6650_reg_write(client, REG_GAM1, ctrl->val);
if (!ret)
priv->gamma = ctrl->value;
break;
case V4L2_CID_VFLIP: case V4L2_CID_VFLIP:
ret = ov6650_reg_rmw(client, REG_COMB, return ov6650_reg_rmw(client, REG_COMB,
ctrl->value ? COMB_FLIP_V : 0, COMB_FLIP_V); ctrl->val ? COMB_FLIP_V : 0, COMB_FLIP_V);
if (!ret)
priv->vflip = ctrl->value;
break;
case V4L2_CID_HFLIP: case V4L2_CID_HFLIP:
ret = ov6650_reg_rmw(client, REG_COMB, return ov6650_reg_rmw(client, REG_COMB,
ctrl->value ? COMB_FLIP_H : 0, COMB_FLIP_H); ctrl->val ? COMB_FLIP_H : 0, COMB_FLIP_H);
if (!ret)
priv->hflip = ctrl->value;
break;
} }
return ret; return -EINVAL;
} }
/* Get chip identification */ /* Get chip identification */
...@@ -1048,14 +857,12 @@ static int ov6650_video_probe(struct soc_camera_device *icd, ...@@ -1048,14 +857,12 @@ static int ov6650_video_probe(struct soc_camera_device *icd,
return ret; return ret;
} }
static struct soc_camera_ops ov6650_ops = { static const struct v4l2_ctrl_ops ov6550_ctrl_ops = {
.controls = ov6650_controls, .g_volatile_ctrl = ov6550_g_volatile_ctrl,
.num_controls = ARRAY_SIZE(ov6650_controls), .s_ctrl = ov6550_s_ctrl,
}; };
static struct v4l2_subdev_core_ops ov6650_core_ops = { static struct v4l2_subdev_core_ops ov6650_core_ops = {
.g_ctrl = ov6650_g_ctrl,
.s_ctrl = ov6650_s_ctrl,
.g_chip_ident = ov6650_g_chip_ident, .g_chip_ident = ov6650_g_chip_ident,
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
.g_register = ov6650_get_register, .g_register = ov6650_get_register,
...@@ -1164,8 +971,46 @@ static int ov6650_probe(struct i2c_client *client, ...@@ -1164,8 +971,46 @@ static int ov6650_probe(struct i2c_client *client,
} }
v4l2_i2c_subdev_init(&priv->subdev, client, &ov6650_subdev_ops); v4l2_i2c_subdev_init(&priv->subdev, client, &ov6650_subdev_ops);
v4l2_ctrl_handler_init(&priv->hdl, 13);
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_VFLIP, 0, 1, 1, 0);
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_HFLIP, 0, 1, 1, 0);
priv->autogain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
priv->gain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_GAIN, 0, 0x3f, 1, DEF_GAIN);
priv->autowb = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
priv->blue = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_BLUE_BALANCE, 0, 0xff, 1, DEF_BLUE);
priv->red = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_RED_BALANCE, 0, 0xff, 1, DEF_RED);
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_SATURATION, 0, 0xf, 1, 0x8);
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_HUE, 0, HUE_MASK, 1, DEF_HUE);
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_BRIGHTNESS, 0, 0xff, 1, 0x80);
priv->autoexposure = v4l2_ctrl_new_std_menu(&priv->hdl,
&ov6550_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
V4L2_EXPOSURE_AUTO);
priv->exposure = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_EXPOSURE, 0, 0xff, 1, DEF_AECH);
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
V4L2_CID_GAMMA, 0, 0xff, 1, 0x12);
priv->subdev.ctrl_handler = &priv->hdl;
if (priv->hdl.error) {
int err = priv->hdl.error;
icd->ops = &ov6650_ops; kfree(priv);
return err;
}
v4l2_ctrl_auto_cluster(2, &priv->autogain, 0, true);
v4l2_ctrl_auto_cluster(3, &priv->autowb, 0, true);
v4l2_ctrl_auto_cluster(2, &priv->autoexposure,
V4L2_EXPOSURE_MANUAL, true);
priv->rect.left = DEF_HSTRT << 1; priv->rect.left = DEF_HSTRT << 1;
priv->rect.top = DEF_VSTRT << 1; priv->rect.top = DEF_VSTRT << 1;
...@@ -1176,9 +1021,11 @@ static int ov6650_probe(struct i2c_client *client, ...@@ -1176,9 +1021,11 @@ static int ov6650_probe(struct i2c_client *client,
priv->colorspace = V4L2_COLORSPACE_JPEG; priv->colorspace = V4L2_COLORSPACE_JPEG;
ret = ov6650_video_probe(icd, client); ret = ov6650_video_probe(icd, client);
if (!ret)
ret = v4l2_ctrl_handler_setup(&priv->hdl);
if (ret) { if (ret) {
icd->ops = NULL; v4l2_ctrl_handler_free(&priv->hdl);
kfree(priv); kfree(priv);
} }
...@@ -1189,6 +1036,8 @@ static int ov6650_remove(struct i2c_client *client) ...@@ -1189,6 +1036,8 @@ static int ov6650_remove(struct i2c_client *client)
{ {
struct ov6650 *priv = to_ov6650(client); struct ov6650 *priv = to_ov6650(client);
v4l2_device_unregister_subdev(&priv->subdev);
v4l2_ctrl_handler_free(&priv->hdl);
kfree(priv); kfree(priv);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment