diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2011-09-07 05:03:11 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-11-03 16:28:51 -0400 |
commit | 34e181c5211f106f1d464e9bcb50bb88398126e2 (patch) | |
tree | 3f64769364326d36f46ce282e47cc1ae9db48e0f /drivers/media | |
parent | afd9690c72c3acf77b7f8731b2fcafafd3b7e29e (diff) |
[media] ov9740: convert to the control framework
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/video/ov9740.c | 83 |
1 files changed, 28 insertions, 55 deletions
diff --git a/drivers/media/video/ov9740.c b/drivers/media/video/ov9740.c index 5920f600990f..3dd910dcc5b8 100644 --- a/drivers/media/video/ov9740.c +++ b/drivers/media/video/ov9740.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <media/soc_camera.h> | 18 | #include <media/soc_camera.h> |
19 | #include <media/soc_mediabus.h> | 19 | #include <media/soc_mediabus.h> |
20 | #include <media/v4l2-chip-ident.h> | 20 | #include <media/v4l2-chip-ident.h> |
21 | #include <media/v4l2-ctrls.h> | ||
21 | 22 | ||
22 | #define to_ov9740(sd) container_of(sd, struct ov9740_priv, subdev) | 23 | #define to_ov9740(sd) container_of(sd, struct ov9740_priv, subdev) |
23 | 24 | ||
@@ -194,6 +195,7 @@ struct ov9740_reg { | |||
194 | 195 | ||
195 | struct ov9740_priv { | 196 | struct ov9740_priv { |
196 | struct v4l2_subdev subdev; | 197 | struct v4l2_subdev subdev; |
198 | struct v4l2_ctrl_handler hdl; | ||
197 | 199 | ||
198 | int ident; | 200 | int ident; |
199 | u16 model; | 201 | u16 model; |
@@ -394,27 +396,6 @@ static enum v4l2_mbus_pixelcode ov9740_codes[] = { | |||
394 | V4L2_MBUS_FMT_YUYV8_2X8, | 396 | V4L2_MBUS_FMT_YUYV8_2X8, |
395 | }; | 397 | }; |
396 | 398 | ||
397 | static const struct v4l2_queryctrl ov9740_controls[] = { | ||
398 | { | ||
399 | .id = V4L2_CID_VFLIP, | ||
400 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
401 | .name = "Flip Vertically", | ||
402 | .minimum = 0, | ||
403 | .maximum = 1, | ||
404 | .step = 1, | ||
405 | .default_value = 0, | ||
406 | }, | ||
407 | { | ||
408 | .id = V4L2_CID_HFLIP, | ||
409 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
410 | .name = "Flip Horizontally", | ||
411 | .minimum = 0, | ||
412 | .maximum = 1, | ||
413 | .step = 1, | ||
414 | .default_value = 0, | ||
415 | }, | ||
416 | }; | ||
417 | |||
418 | /* read a register */ | 399 | /* read a register */ |
419 | static int ov9740_reg_read(struct i2c_client *client, u16 reg, u8 *val) | 400 | static int ov9740_reg_read(struct i2c_client *client, u16 reg, u8 *val) |
420 | { | 401 | { |
@@ -771,36 +752,18 @@ static int ov9740_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) | |||
771 | return 0; | 752 | return 0; |
772 | } | 753 | } |
773 | 754 | ||
774 | /* Get status of additional camera capabilities */ | ||
775 | static int ov9740_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | ||
776 | { | ||
777 | struct ov9740_priv *priv = to_ov9740(sd); | ||
778 | |||
779 | switch (ctrl->id) { | ||
780 | case V4L2_CID_VFLIP: | ||
781 | ctrl->value = priv->flag_vflip; | ||
782 | break; | ||
783 | case V4L2_CID_HFLIP: | ||
784 | ctrl->value = priv->flag_hflip; | ||
785 | break; | ||
786 | default: | ||
787 | return -EINVAL; | ||
788 | } | ||
789 | |||
790 | return 0; | ||
791 | } | ||
792 | |||
793 | /* Set status of additional camera capabilities */ | 755 | /* Set status of additional camera capabilities */ |
794 | static int ov9740_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | 756 | static int ov9740_s_ctrl(struct v4l2_ctrl *ctrl) |
795 | { | 757 | { |
796 | struct ov9740_priv *priv = to_ov9740(sd); | 758 | struct ov9740_priv *priv = |
759 | container_of(ctrl->handler, struct ov9740_priv, hdl); | ||
797 | 760 | ||
798 | switch (ctrl->id) { | 761 | switch (ctrl->id) { |
799 | case V4L2_CID_VFLIP: | 762 | case V4L2_CID_VFLIP: |
800 | priv->flag_vflip = ctrl->value; | 763 | priv->flag_vflip = ctrl->val; |
801 | break; | 764 | break; |
802 | case V4L2_CID_HFLIP: | 765 | case V4L2_CID_HFLIP: |
803 | priv->flag_hflip = ctrl->value; | 766 | priv->flag_hflip = ctrl->val; |
804 | break; | 767 | break; |
805 | default: | 768 | default: |
806 | return -EINVAL; | 769 | return -EINVAL; |
@@ -925,11 +888,6 @@ err: | |||
925 | return ret; | 888 | return ret; |
926 | } | 889 | } |
927 | 890 | ||
928 | static struct soc_camera_ops ov9740_ops = { | ||
929 | .controls = ov9740_controls, | ||
930 | .num_controls = ARRAY_SIZE(ov9740_controls), | ||
931 | }; | ||
932 | |||
933 | /* Request bus settings on camera side */ | 891 | /* Request bus settings on camera side */ |
934 | static int ov9740_g_mbus_config(struct v4l2_subdev *sd, | 892 | static int ov9740_g_mbus_config(struct v4l2_subdev *sd, |
935 | struct v4l2_mbus_config *cfg) | 893 | struct v4l2_mbus_config *cfg) |
@@ -958,8 +916,6 @@ static struct v4l2_subdev_video_ops ov9740_video_ops = { | |||
958 | }; | 916 | }; |
959 | 917 | ||
960 | static struct v4l2_subdev_core_ops ov9740_core_ops = { | 918 | static struct v4l2_subdev_core_ops ov9740_core_ops = { |
961 | .g_ctrl = ov9740_g_ctrl, | ||
962 | .s_ctrl = ov9740_s_ctrl, | ||
963 | .g_chip_ident = ov9740_g_chip_ident, | 919 | .g_chip_ident = ov9740_g_chip_ident, |
964 | .s_power = ov9740_s_power, | 920 | .s_power = ov9740_s_power, |
965 | #ifdef CONFIG_VIDEO_ADV_DEBUG | 921 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
@@ -973,6 +929,10 @@ static struct v4l2_subdev_ops ov9740_subdev_ops = { | |||
973 | .video = &ov9740_video_ops, | 929 | .video = &ov9740_video_ops, |
974 | }; | 930 | }; |
975 | 931 | ||
932 | static const struct v4l2_ctrl_ops ov9740_ctrl_ops = { | ||
933 | .s_ctrl = ov9740_s_ctrl, | ||
934 | }; | ||
935 | |||
976 | /* | 936 | /* |
977 | * i2c_driver function | 937 | * i2c_driver function |
978 | */ | 938 | */ |
@@ -980,7 +940,7 @@ static int ov9740_probe(struct i2c_client *client, | |||
980 | const struct i2c_device_id *did) | 940 | const struct i2c_device_id *did) |
981 | { | 941 | { |
982 | struct ov9740_priv *priv; | 942 | struct ov9740_priv *priv; |
983 | struct soc_camera_device *icd = client->dev.platform_data; | 943 | struct soc_camera_device *icd = client->dev.platform_data; |
984 | struct soc_camera_link *icl; | 944 | struct soc_camera_link *icl; |
985 | int ret; | 945 | int ret; |
986 | 946 | ||
@@ -1002,12 +962,24 @@ static int ov9740_probe(struct i2c_client *client, | |||
1002 | } | 962 | } |
1003 | 963 | ||
1004 | v4l2_i2c_subdev_init(&priv->subdev, client, &ov9740_subdev_ops); | 964 | v4l2_i2c_subdev_init(&priv->subdev, client, &ov9740_subdev_ops); |
965 | v4l2_ctrl_handler_init(&priv->hdl, 13); | ||
966 | v4l2_ctrl_new_std(&priv->hdl, &ov9740_ctrl_ops, | ||
967 | V4L2_CID_VFLIP, 0, 1, 1, 0); | ||
968 | v4l2_ctrl_new_std(&priv->hdl, &ov9740_ctrl_ops, | ||
969 | V4L2_CID_HFLIP, 0, 1, 1, 0); | ||
970 | priv->subdev.ctrl_handler = &priv->hdl; | ||
971 | if (priv->hdl.error) { | ||
972 | int err = priv->hdl.error; | ||
1005 | 973 | ||
1006 | icd->ops = &ov9740_ops; | 974 | kfree(priv); |
975 | return err; | ||
976 | } | ||
1007 | 977 | ||
1008 | ret = ov9740_video_probe(icd, client); | 978 | ret = ov9740_video_probe(icd, client); |
979 | if (!ret) | ||
980 | ret = v4l2_ctrl_handler_setup(&priv->hdl); | ||
1009 | if (ret < 0) { | 981 | if (ret < 0) { |
1010 | icd->ops = NULL; | 982 | v4l2_ctrl_handler_free(&priv->hdl); |
1011 | kfree(priv); | 983 | kfree(priv); |
1012 | } | 984 | } |
1013 | 985 | ||
@@ -1018,8 +990,9 @@ static int ov9740_remove(struct i2c_client *client) | |||
1018 | { | 990 | { |
1019 | struct ov9740_priv *priv = i2c_get_clientdata(client); | 991 | struct ov9740_priv *priv = i2c_get_clientdata(client); |
1020 | 992 | ||
993 | v4l2_device_unregister_subdev(&priv->subdev); | ||
994 | v4l2_ctrl_handler_free(&priv->hdl); | ||
1021 | kfree(priv); | 995 | kfree(priv); |
1022 | |||
1023 | return 0; | 996 | return 0; |
1024 | } | 997 | } |
1025 | 998 | ||