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

[media] ov9640: 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 d34bfcd2
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,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-common.h> #include <media/v4l2-common.h>
#include <media/v4l2-ctrls.h>
#include "ov9640.h" #include "ov9640.h"
...@@ -164,27 +165,6 @@ static enum v4l2_mbus_pixelcode ov9640_codes[] = { ...@@ -164,27 +165,6 @@ static enum v4l2_mbus_pixelcode ov9640_codes[] = {
V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_MBUS_FMT_RGB565_2X8_LE,
}; };
static const struct v4l2_queryctrl ov9640_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,
},
};
/* read a register */ /* read a register */
static int ov9640_reg_read(struct i2c_client *client, u8 reg, u8 *val) static int ov9640_reg_read(struct i2c_client *client, u8 reg, u8 *val)
{ {
...@@ -286,52 +266,25 @@ static int ov9640_s_stream(struct v4l2_subdev *sd, int enable) ...@@ -286,52 +266,25 @@ static int ov9640_s_stream(struct v4l2_subdev *sd, int enable)
return 0; return 0;
} }
/* Get status of additional camera capabilities */
static int ov9640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{
struct ov9640_priv *priv = to_ov9640_sensor(sd);
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;
}
/* Set status of additional camera capabilities */ /* Set status of additional camera capabilities */
static int ov9640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) static int ov9640_s_ctrl(struct v4l2_ctrl *ctrl)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct ov9640_priv *priv = container_of(ctrl->handler, struct ov9640_priv, hdl);
struct ov9640_priv *priv = to_ov9640_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev);
int ret = 0;
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_VFLIP: case V4L2_CID_VFLIP:
priv->flag_vflip = ctrl->value; if (ctrl->val)
if (ctrl->value) return ov9640_reg_rmw(client, OV9640_MVFP,
ret = ov9640_reg_rmw(client, OV9640_MVFP,
OV9640_MVFP_V, 0); OV9640_MVFP_V, 0);
else return ov9640_reg_rmw(client, OV9640_MVFP, 0, OV9640_MVFP_V);
ret = ov9640_reg_rmw(client, OV9640_MVFP,
0, OV9640_MVFP_V);
break;
case V4L2_CID_HFLIP: case V4L2_CID_HFLIP:
priv->flag_hflip = ctrl->value; if (ctrl->val)
if (ctrl->value) return ov9640_reg_rmw(client, OV9640_MVFP,
ret = ov9640_reg_rmw(client, OV9640_MVFP,
OV9640_MVFP_H, 0); OV9640_MVFP_H, 0);
else return ov9640_reg_rmw(client, OV9640_MVFP, 0, OV9640_MVFP_H);
ret = ov9640_reg_rmw(client, OV9640_MVFP,
0, OV9640_MVFP_H);
break;
} }
return -EINVAL;
return ret;
} }
/* Get chip identification */ /* Get chip identification */
...@@ -643,20 +596,14 @@ static int ov9640_video_probe(struct soc_camera_device *icd, ...@@ -643,20 +596,14 @@ static int ov9640_video_probe(struct soc_camera_device *icd,
*/ */
ret = ov9640_reg_read(client, OV9640_PID, &pid); ret = ov9640_reg_read(client, OV9640_PID, &pid);
if (!ret)
ret = ov9640_reg_read(client, OV9640_VER, &ver);
if (!ret)
ret = ov9640_reg_read(client, OV9640_MIDH, &midh);
if (!ret)
ret = ov9640_reg_read(client, OV9640_MIDL, &midl);
if (ret) if (ret)
goto err; return ret;
ret = ov9640_reg_read(client, OV9640_VER, &ver);
if (ret)
goto err;
ret = ov9640_reg_read(client, OV9640_MIDH, &midh);
if (ret)
goto err;
ret = ov9640_reg_read(client, OV9640_MIDL, &midl);
if (ret)
goto err;
switch (VERSION(pid, ver)) { switch (VERSION(pid, ver)) {
case OV9640_V2: case OV9640_V2:
...@@ -670,25 +617,20 @@ static int ov9640_video_probe(struct soc_camera_device *icd, ...@@ -670,25 +617,20 @@ static int ov9640_video_probe(struct soc_camera_device *icd,
break; break;
default: default:
dev_err(&client->dev, "Product ID error %x:%x\n", pid, ver); dev_err(&client->dev, "Product ID error %x:%x\n", pid, ver);
ret = -ENODEV; return -ENODEV;
goto err;
} }
dev_info(&client->dev, "%s Product ID %0x:%0x Manufacturer ID %x:%x\n", dev_info(&client->dev, "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
devname, pid, ver, midh, midl); devname, pid, ver, midh, midl);
err: return v4l2_ctrl_handler_setup(&priv->hdl);
return ret;
} }
static struct soc_camera_ops ov9640_ops = { static const struct v4l2_ctrl_ops ov9640_ctrl_ops = {
.controls = ov9640_controls, .s_ctrl = ov9640_s_ctrl,
.num_controls = ARRAY_SIZE(ov9640_controls),
}; };
static struct v4l2_subdev_core_ops ov9640_core_ops = { static struct v4l2_subdev_core_ops ov9640_core_ops = {
.g_ctrl = ov9640_g_ctrl,
.s_ctrl = ov9640_s_ctrl,
.g_chip_ident = ov9640_g_chip_ident, .g_chip_ident = ov9640_g_chip_ident,
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
.g_register = ov9640_get_register, .g_register = ov9640_get_register,
...@@ -760,12 +702,23 @@ static int ov9640_probe(struct i2c_client *client, ...@@ -760,12 +702,23 @@ static int ov9640_probe(struct i2c_client *client,
v4l2_i2c_subdev_init(&priv->subdev, client, &ov9640_subdev_ops); v4l2_i2c_subdev_init(&priv->subdev, client, &ov9640_subdev_ops);
icd->ops = &ov9640_ops; v4l2_ctrl_handler_init(&priv->hdl, 2);
v4l2_ctrl_new_std(&priv->hdl, &ov9640_ctrl_ops,
V4L2_CID_VFLIP, 0, 1, 1, 0);
v4l2_ctrl_new_std(&priv->hdl, &ov9640_ctrl_ops,
V4L2_CID_HFLIP, 0, 1, 1, 0);
priv->subdev.ctrl_handler = &priv->hdl;
if (priv->hdl.error) {
int err = priv->hdl.error;
kfree(priv);
return err;
}
ret = ov9640_video_probe(icd, client); ret = ov9640_video_probe(icd, client);
if (ret) { if (ret) {
icd->ops = NULL; v4l2_ctrl_handler_free(&priv->hdl);
kfree(priv); kfree(priv);
} }
...@@ -777,6 +730,8 @@ static int ov9640_remove(struct i2c_client *client) ...@@ -777,6 +730,8 @@ static int ov9640_remove(struct i2c_client *client)
struct v4l2_subdev *sd = i2c_get_clientdata(client); struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct ov9640_priv *priv = to_ov9640_sensor(sd); struct ov9640_priv *priv = to_ov9640_sensor(sd);
v4l2_device_unregister_subdev(&priv->subdev);
v4l2_ctrl_handler_free(&priv->hdl);
kfree(priv); kfree(priv);
return 0; return 0;
} }
......
...@@ -198,12 +198,10 @@ struct ov9640_reg { ...@@ -198,12 +198,10 @@ struct ov9640_reg {
struct ov9640_priv { struct ov9640_priv {
struct v4l2_subdev subdev; struct v4l2_subdev subdev;
struct v4l2_ctrl_handler hdl;
int model; int model;
int revision; int revision;
bool flag_vflip;
bool flag_hflip;
}; };
#endif /* __DRIVERS_MEDIA_VIDEO_OV9640_H__ */ #endif /* __DRIVERS_MEDIA_VIDEO_OV9640_H__ */
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