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

[media] ov2640: convert to the control framework

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent ab7b50ae
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#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-subdev.h> #include <media/v4l2-subdev.h>
#include <media/v4l2-ctrls.h>
#define VAL_SET(x, mask, rshift, lshift) \ #define VAL_SET(x, mask, rshift, lshift) \
((((x) >> rshift) & mask) << lshift) ((((x) >> rshift) & mask) << lshift)
...@@ -300,11 +301,10 @@ struct ov2640_win_size { ...@@ -300,11 +301,10 @@ struct ov2640_win_size {
struct ov2640_priv { struct ov2640_priv {
struct v4l2_subdev subdev; struct v4l2_subdev subdev;
struct v4l2_ctrl_handler hdl;
enum v4l2_mbus_pixelcode cfmt_code; enum v4l2_mbus_pixelcode cfmt_code;
const struct ov2640_win_size *win; const struct ov2640_win_size *win;
int model; int model;
u16 flag_vflip:1;
u16 flag_hflip:1;
}; };
/* /*
...@@ -609,29 +609,6 @@ static enum v4l2_mbus_pixelcode ov2640_codes[] = { ...@@ -609,29 +609,6 @@ static enum v4l2_mbus_pixelcode ov2640_codes[] = {
V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_MBUS_FMT_RGB565_2X8_LE,
}; };
/*
* Supported controls
*/
static const struct v4l2_queryctrl ov2640_controls[] = {
{
.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,
},
};
/* /*
* General functions * General functions
*/ */
...@@ -701,43 +678,23 @@ static int ov2640_s_stream(struct v4l2_subdev *sd, int enable) ...@@ -701,43 +678,23 @@ static int ov2640_s_stream(struct v4l2_subdev *sd, int enable)
return 0; return 0;
} }
static int ov2640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) static int ov2640_s_ctrl(struct v4l2_ctrl *ctrl)
{ {
struct v4l2_subdev *sd =
&container_of(ctrl->handler, struct ov2640_priv, hdl)->subdev;
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
struct ov2640_priv *priv = to_ov2640(client);
switch (ctrl->id) {
case V4L2_CID_VFLIP:
ctrl->value = priv->flag_vflip;
break;
case V4L2_CID_HFLIP:
ctrl->value = priv->flag_hflip;
break;
}
return 0;
}
static int ov2640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct ov2640_priv *priv = to_ov2640(client);
int ret = 0;
u8 val; u8 val;
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_VFLIP: case V4L2_CID_VFLIP:
val = ctrl->value ? REG04_VFLIP_IMG : 0x00; val = ctrl->val ? REG04_VFLIP_IMG : 0x00;
priv->flag_vflip = ctrl->value ? 1 : 0; return ov2640_mask_set(client, REG04, REG04_VFLIP_IMG, val);
ret = ov2640_mask_set(client, REG04, REG04_VFLIP_IMG, val);
break;
case V4L2_CID_HFLIP: case V4L2_CID_HFLIP:
val = ctrl->value ? REG04_HFLIP_IMG : 0x00; val = ctrl->val ? REG04_HFLIP_IMG : 0x00;
priv->flag_hflip = ctrl->value ? 1 : 0; return ov2640_mask_set(client, REG04, REG04_HFLIP_IMG, val);
ret = ov2640_mask_set(client, REG04, REG04_HFLIP_IMG, val);
break;
} }
return ret; return -EINVAL;
} }
static int ov2640_g_chip_ident(struct v4l2_subdev *sd, static int ov2640_g_chip_ident(struct v4l2_subdev *sd,
...@@ -1022,20 +979,17 @@ static int ov2640_video_probe(struct soc_camera_device *icd, ...@@ -1022,20 +979,17 @@ static int ov2640_video_probe(struct soc_camera_device *icd,
"%s Product ID %0x:%0x Manufacturer ID %x:%x\n", "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
devname, pid, ver, midh, midl); devname, pid, ver, midh, midl);
return 0; return v4l2_ctrl_handler_setup(&priv->hdl);
err: err:
return ret; return ret;
} }
static struct soc_camera_ops ov2640_ops = { static const struct v4l2_ctrl_ops ov2640_ctrl_ops = {
.controls = ov2640_controls, .s_ctrl = ov2640_s_ctrl,
.num_controls = ARRAY_SIZE(ov2640_controls),
}; };
static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = { static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
.g_ctrl = ov2640_g_ctrl,
.s_ctrl = ov2640_s_ctrl,
.g_chip_ident = ov2640_g_chip_ident, .g_chip_ident = ov2640_g_chip_ident,
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
.g_register = ov2640_g_register, .g_register = ov2640_g_register,
...@@ -1113,12 +1067,22 @@ static int ov2640_probe(struct i2c_client *client, ...@@ -1113,12 +1067,22 @@ static int ov2640_probe(struct i2c_client *client,
} }
v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops); v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops);
v4l2_ctrl_handler_init(&priv->hdl, 2);
v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
V4L2_CID_VFLIP, 0, 1, 1, 0);
v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
V4L2_CID_HFLIP, 0, 1, 1, 0);
priv->subdev.ctrl_handler = &priv->hdl;
if (priv->hdl.error) {
int err = priv->hdl.error;
icd->ops = &ov2640_ops; kfree(priv);
return err;
}
ret = ov2640_video_probe(icd, client); ret = ov2640_video_probe(icd, client);
if (ret) { if (ret) {
icd->ops = NULL; v4l2_ctrl_handler_free(&priv->hdl);
kfree(priv); kfree(priv);
} else { } else {
dev_info(&adapter->dev, "OV2640 Probed\n"); dev_info(&adapter->dev, "OV2640 Probed\n");
...@@ -1130,9 +1094,9 @@ static int ov2640_probe(struct i2c_client *client, ...@@ -1130,9 +1094,9 @@ static int ov2640_probe(struct i2c_client *client,
static int ov2640_remove(struct i2c_client *client) static int ov2640_remove(struct i2c_client *client)
{ {
struct ov2640_priv *priv = to_ov2640(client); struct ov2640_priv *priv = to_ov2640(client);
struct soc_camera_device *icd = client->dev.platform_data;
icd->ops = NULL; 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