diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2009-03-18 12:23:13 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-03-30 11:43:30 -0400 |
commit | ca07561ac70b00b5c2b5af727b3d0b6a4f91bee2 (patch) | |
tree | 0f5237cb2574e1b268cbbdbc1ce47d0639b94dec /drivers/media/video/ov7670.c | |
parent | 8bcfd7af902eaa7c0029082247fe0682ce0c1a5b (diff) |
V4L/DVB (11116): ov7670: cleanup and remove legacy code.
v4l2-i2c-drv-legacy.h and ov7670_command are no longer needed after the
cafe driver is converted to use v4l2_subdev.
Rather than using a large ov7670_control array, just call the handlers
via a simple switch and use v4l2_ctrl_query_fill() to handle queryctrl.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Acked-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/ov7670.c')
-rw-r--r-- | drivers/media/video/ov7670.c | 210 |
1 files changed, 58 insertions, 152 deletions
diff --git a/drivers/media/video/ov7670.c b/drivers/media/video/ov7670.c index 78bd430716c8..ab245f71b195 100644 --- a/drivers/media/video/ov7670.c +++ b/drivers/media/video/ov7670.c | |||
@@ -17,7 +17,7 @@ | |||
17 | #include <linux/videodev2.h> | 17 | #include <linux/videodev2.h> |
18 | #include <media/v4l2-device.h> | 18 | #include <media/v4l2-device.h> |
19 | #include <media/v4l2-chip-ident.h> | 19 | #include <media/v4l2-chip-ident.h> |
20 | #include <media/v4l2-i2c-drv-legacy.h> | 20 | #include <media/v4l2-i2c-drv.h> |
21 | 21 | ||
22 | 22 | ||
23 | MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>"); | 23 | MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>"); |
@@ -962,7 +962,7 @@ static void ov7670_calc_cmatrix(struct ov7670_info *info, | |||
962 | 962 | ||
963 | 963 | ||
964 | 964 | ||
965 | static int ov7670_t_sat(struct v4l2_subdev *sd, int value) | 965 | static int ov7670_s_sat(struct v4l2_subdev *sd, int value) |
966 | { | 966 | { |
967 | struct ov7670_info *info = to_state(sd); | 967 | struct ov7670_info *info = to_state(sd); |
968 | int matrix[CMATRIX_LEN]; | 968 | int matrix[CMATRIX_LEN]; |
@@ -974,7 +974,7 @@ static int ov7670_t_sat(struct v4l2_subdev *sd, int value) | |||
974 | return ret; | 974 | return ret; |
975 | } | 975 | } |
976 | 976 | ||
977 | static int ov7670_q_sat(struct v4l2_subdev *sd, __s32 *value) | 977 | static int ov7670_g_sat(struct v4l2_subdev *sd, __s32 *value) |
978 | { | 978 | { |
979 | struct ov7670_info *info = to_state(sd); | 979 | struct ov7670_info *info = to_state(sd); |
980 | 980 | ||
@@ -982,7 +982,7 @@ static int ov7670_q_sat(struct v4l2_subdev *sd, __s32 *value) | |||
982 | return 0; | 982 | return 0; |
983 | } | 983 | } |
984 | 984 | ||
985 | static int ov7670_t_hue(struct v4l2_subdev *sd, int value) | 985 | static int ov7670_s_hue(struct v4l2_subdev *sd, int value) |
986 | { | 986 | { |
987 | struct ov7670_info *info = to_state(sd); | 987 | struct ov7670_info *info = to_state(sd); |
988 | int matrix[CMATRIX_LEN]; | 988 | int matrix[CMATRIX_LEN]; |
@@ -997,7 +997,7 @@ static int ov7670_t_hue(struct v4l2_subdev *sd, int value) | |||
997 | } | 997 | } |
998 | 998 | ||
999 | 999 | ||
1000 | static int ov7670_q_hue(struct v4l2_subdev *sd, __s32 *value) | 1000 | static int ov7670_g_hue(struct v4l2_subdev *sd, __s32 *value) |
1001 | { | 1001 | { |
1002 | struct ov7670_info *info = to_state(sd); | 1002 | struct ov7670_info *info = to_state(sd); |
1003 | 1003 | ||
@@ -1024,7 +1024,7 @@ static unsigned char ov7670_abs_to_sm(unsigned char v) | |||
1024 | return (128 - v) | 0x80; | 1024 | return (128 - v) | 0x80; |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | static int ov7670_t_brightness(struct v4l2_subdev *sd, int value) | 1027 | static int ov7670_s_brightness(struct v4l2_subdev *sd, int value) |
1028 | { | 1028 | { |
1029 | unsigned char com8 = 0, v; | 1029 | unsigned char com8 = 0, v; |
1030 | int ret; | 1030 | int ret; |
@@ -1037,7 +1037,7 @@ static int ov7670_t_brightness(struct v4l2_subdev *sd, int value) | |||
1037 | return ret; | 1037 | return ret; |
1038 | } | 1038 | } |
1039 | 1039 | ||
1040 | static int ov7670_q_brightness(struct v4l2_subdev *sd, __s32 *value) | 1040 | static int ov7670_g_brightness(struct v4l2_subdev *sd, __s32 *value) |
1041 | { | 1041 | { |
1042 | unsigned char v = 0; | 1042 | unsigned char v = 0; |
1043 | int ret = ov7670_read(sd, REG_BRIGHT, &v); | 1043 | int ret = ov7670_read(sd, REG_BRIGHT, &v); |
@@ -1046,12 +1046,12 @@ static int ov7670_q_brightness(struct v4l2_subdev *sd, __s32 *value) | |||
1046 | return ret; | 1046 | return ret; |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | static int ov7670_t_contrast(struct v4l2_subdev *sd, int value) | 1049 | static int ov7670_s_contrast(struct v4l2_subdev *sd, int value) |
1050 | { | 1050 | { |
1051 | return ov7670_write(sd, REG_CONTRAS, (unsigned char) value); | 1051 | return ov7670_write(sd, REG_CONTRAS, (unsigned char) value); |
1052 | } | 1052 | } |
1053 | 1053 | ||
1054 | static int ov7670_q_contrast(struct v4l2_subdev *sd, __s32 *value) | 1054 | static int ov7670_g_contrast(struct v4l2_subdev *sd, __s32 *value) |
1055 | { | 1055 | { |
1056 | unsigned char v = 0; | 1056 | unsigned char v = 0; |
1057 | int ret = ov7670_read(sd, REG_CONTRAS, &v); | 1057 | int ret = ov7670_read(sd, REG_CONTRAS, &v); |
@@ -1060,7 +1060,7 @@ static int ov7670_q_contrast(struct v4l2_subdev *sd, __s32 *value) | |||
1060 | return ret; | 1060 | return ret; |
1061 | } | 1061 | } |
1062 | 1062 | ||
1063 | static int ov7670_q_hflip(struct v4l2_subdev *sd, __s32 *value) | 1063 | static int ov7670_g_hflip(struct v4l2_subdev *sd, __s32 *value) |
1064 | { | 1064 | { |
1065 | int ret; | 1065 | int ret; |
1066 | unsigned char v = 0; | 1066 | unsigned char v = 0; |
@@ -1071,7 +1071,7 @@ static int ov7670_q_hflip(struct v4l2_subdev *sd, __s32 *value) | |||
1071 | } | 1071 | } |
1072 | 1072 | ||
1073 | 1073 | ||
1074 | static int ov7670_t_hflip(struct v4l2_subdev *sd, int value) | 1074 | static int ov7670_s_hflip(struct v4l2_subdev *sd, int value) |
1075 | { | 1075 | { |
1076 | unsigned char v = 0; | 1076 | unsigned char v = 0; |
1077 | int ret; | 1077 | int ret; |
@@ -1088,7 +1088,7 @@ static int ov7670_t_hflip(struct v4l2_subdev *sd, int value) | |||
1088 | 1088 | ||
1089 | 1089 | ||
1090 | 1090 | ||
1091 | static int ov7670_q_vflip(struct v4l2_subdev *sd, __s32 *value) | 1091 | static int ov7670_g_vflip(struct v4l2_subdev *sd, __s32 *value) |
1092 | { | 1092 | { |
1093 | int ret; | 1093 | int ret; |
1094 | unsigned char v = 0; | 1094 | unsigned char v = 0; |
@@ -1099,7 +1099,7 @@ static int ov7670_q_vflip(struct v4l2_subdev *sd, __s32 *value) | |||
1099 | } | 1099 | } |
1100 | 1100 | ||
1101 | 1101 | ||
1102 | static int ov7670_t_vflip(struct v4l2_subdev *sd, int value) | 1102 | static int ov7670_s_vflip(struct v4l2_subdev *sd, int value) |
1103 | { | 1103 | { |
1104 | unsigned char v = 0; | 1104 | unsigned char v = 0; |
1105 | int ret; | 1105 | int ret; |
@@ -1114,144 +1114,62 @@ static int ov7670_t_vflip(struct v4l2_subdev *sd, int value) | |||
1114 | return ret; | 1114 | return ret; |
1115 | } | 1115 | } |
1116 | 1116 | ||
1117 | |||
1118 | static struct ov7670_control { | ||
1119 | struct v4l2_queryctrl qc; | ||
1120 | int (*query)(struct v4l2_subdev *sd, __s32 *value); | ||
1121 | int (*tweak)(struct v4l2_subdev *sd, int value); | ||
1122 | } ov7670_controls[] = | ||
1123 | { | ||
1124 | { | ||
1125 | .qc = { | ||
1126 | .id = V4L2_CID_BRIGHTNESS, | ||
1127 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
1128 | .name = "Brightness", | ||
1129 | .minimum = 0, | ||
1130 | .maximum = 255, | ||
1131 | .step = 1, | ||
1132 | .default_value = 0x80, | ||
1133 | .flags = V4L2_CTRL_FLAG_SLIDER | ||
1134 | }, | ||
1135 | .tweak = ov7670_t_brightness, | ||
1136 | .query = ov7670_q_brightness, | ||
1137 | }, | ||
1138 | { | ||
1139 | .qc = { | ||
1140 | .id = V4L2_CID_CONTRAST, | ||
1141 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
1142 | .name = "Contrast", | ||
1143 | .minimum = 0, | ||
1144 | .maximum = 127, | ||
1145 | .step = 1, | ||
1146 | .default_value = 0x40, /* XXX ov7670 spec */ | ||
1147 | .flags = V4L2_CTRL_FLAG_SLIDER | ||
1148 | }, | ||
1149 | .tweak = ov7670_t_contrast, | ||
1150 | .query = ov7670_q_contrast, | ||
1151 | }, | ||
1152 | { | ||
1153 | .qc = { | ||
1154 | .id = V4L2_CID_SATURATION, | ||
1155 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
1156 | .name = "Saturation", | ||
1157 | .minimum = 0, | ||
1158 | .maximum = 256, | ||
1159 | .step = 1, | ||
1160 | .default_value = 0x80, | ||
1161 | .flags = V4L2_CTRL_FLAG_SLIDER | ||
1162 | }, | ||
1163 | .tweak = ov7670_t_sat, | ||
1164 | .query = ov7670_q_sat, | ||
1165 | }, | ||
1166 | { | ||
1167 | .qc = { | ||
1168 | .id = V4L2_CID_HUE, | ||
1169 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
1170 | .name = "HUE", | ||
1171 | .minimum = -180, | ||
1172 | .maximum = 180, | ||
1173 | .step = 5, | ||
1174 | .default_value = 0, | ||
1175 | .flags = V4L2_CTRL_FLAG_SLIDER | ||
1176 | }, | ||
1177 | .tweak = ov7670_t_hue, | ||
1178 | .query = ov7670_q_hue, | ||
1179 | }, | ||
1180 | { | ||
1181 | .qc = { | ||
1182 | .id = V4L2_CID_VFLIP, | ||
1183 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
1184 | .name = "Vertical flip", | ||
1185 | .minimum = 0, | ||
1186 | .maximum = 1, | ||
1187 | .step = 1, | ||
1188 | .default_value = 0, | ||
1189 | }, | ||
1190 | .tweak = ov7670_t_vflip, | ||
1191 | .query = ov7670_q_vflip, | ||
1192 | }, | ||
1193 | { | ||
1194 | .qc = { | ||
1195 | .id = V4L2_CID_HFLIP, | ||
1196 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
1197 | .name = "Horizontal mirror", | ||
1198 | .minimum = 0, | ||
1199 | .maximum = 1, | ||
1200 | .step = 1, | ||
1201 | .default_value = 0, | ||
1202 | }, | ||
1203 | .tweak = ov7670_t_hflip, | ||
1204 | .query = ov7670_q_hflip, | ||
1205 | }, | ||
1206 | }; | ||
1207 | #define N_CONTROLS (ARRAY_SIZE(ov7670_controls)) | ||
1208 | |||
1209 | static struct ov7670_control *ov7670_find_control(__u32 id) | ||
1210 | { | ||
1211 | int i; | ||
1212 | |||
1213 | for (i = 0; i < N_CONTROLS; i++) | ||
1214 | if (ov7670_controls[i].qc.id == id) | ||
1215 | return ov7670_controls + i; | ||
1216 | return NULL; | ||
1217 | } | ||
1218 | |||
1219 | |||
1220 | static int ov7670_queryctrl(struct v4l2_subdev *sd, | 1117 | static int ov7670_queryctrl(struct v4l2_subdev *sd, |
1221 | struct v4l2_queryctrl *qc) | 1118 | struct v4l2_queryctrl *qc) |
1222 | { | 1119 | { |
1223 | struct ov7670_control *ctrl = ov7670_find_control(qc->id); | 1120 | /* Fill in min, max, step and default value for these controls. */ |
1224 | 1121 | switch (qc->id) { | |
1225 | if (ctrl == NULL) | 1122 | case V4L2_CID_BRIGHTNESS: |
1226 | return -EINVAL; | 1123 | return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128); |
1227 | *qc = ctrl->qc; | 1124 | case V4L2_CID_CONTRAST: |
1228 | return 0; | 1125 | return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64); |
1126 | case V4L2_CID_VFLIP: | ||
1127 | case V4L2_CID_HFLIP: | ||
1128 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0); | ||
1129 | case V4L2_CID_SATURATION: | ||
1130 | return v4l2_ctrl_query_fill(qc, 0, 256, 1, 128); | ||
1131 | case V4L2_CID_HUE: | ||
1132 | return v4l2_ctrl_query_fill(qc, -180, 180, 5, 0); | ||
1133 | } | ||
1134 | return -EINVAL; | ||
1229 | } | 1135 | } |
1230 | 1136 | ||
1231 | static int ov7670_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | 1137 | static int ov7670_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
1232 | { | 1138 | { |
1233 | struct ov7670_control *octrl = ov7670_find_control(ctrl->id); | 1139 | switch (ctrl->id) { |
1234 | int ret; | 1140 | case V4L2_CID_BRIGHTNESS: |
1235 | 1141 | return ov7670_g_brightness(sd, &ctrl->value); | |
1236 | if (octrl == NULL) | 1142 | case V4L2_CID_CONTRAST: |
1237 | return -EINVAL; | 1143 | return ov7670_g_contrast(sd, &ctrl->value); |
1238 | ret = octrl->query(sd, &ctrl->value); | 1144 | case V4L2_CID_SATURATION: |
1239 | if (ret >= 0) | 1145 | return ov7670_g_sat(sd, &ctrl->value); |
1240 | return 0; | 1146 | case V4L2_CID_HUE: |
1241 | return ret; | 1147 | return ov7670_g_hue(sd, &ctrl->value); |
1148 | case V4L2_CID_VFLIP: | ||
1149 | return ov7670_g_vflip(sd, &ctrl->value); | ||
1150 | case V4L2_CID_HFLIP: | ||
1151 | return ov7670_g_hflip(sd, &ctrl->value); | ||
1152 | } | ||
1153 | return -EINVAL; | ||
1242 | } | 1154 | } |
1243 | 1155 | ||
1244 | static int ov7670_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | 1156 | static int ov7670_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
1245 | { | 1157 | { |
1246 | struct ov7670_control *octrl = ov7670_find_control(ctrl->id); | 1158 | switch (ctrl->id) { |
1247 | int ret; | 1159 | case V4L2_CID_BRIGHTNESS: |
1248 | 1160 | return ov7670_s_brightness(sd, ctrl->value); | |
1249 | if (octrl == NULL) | 1161 | case V4L2_CID_CONTRAST: |
1250 | return -EINVAL; | 1162 | return ov7670_s_contrast(sd, ctrl->value); |
1251 | ret = octrl->tweak(sd, ctrl->value); | 1163 | case V4L2_CID_SATURATION: |
1252 | if (ret >= 0) | 1164 | return ov7670_s_sat(sd, ctrl->value); |
1253 | return 0; | 1165 | case V4L2_CID_HUE: |
1254 | return ret; | 1166 | return ov7670_s_hue(sd, ctrl->value); |
1167 | case V4L2_CID_VFLIP: | ||
1168 | return ov7670_s_vflip(sd, ctrl->value); | ||
1169 | case V4L2_CID_HFLIP: | ||
1170 | return ov7670_s_hflip(sd, ctrl->value); | ||
1171 | } | ||
1172 | return -EINVAL; | ||
1255 | } | 1173 | } |
1256 | 1174 | ||
1257 | static int ov7670_g_chip_ident(struct v4l2_subdev *sd, | 1175 | static int ov7670_g_chip_ident(struct v4l2_subdev *sd, |
@@ -1262,11 +1180,6 @@ static int ov7670_g_chip_ident(struct v4l2_subdev *sd, | |||
1262 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_OV7670, 0); | 1180 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_OV7670, 0); |
1263 | } | 1181 | } |
1264 | 1182 | ||
1265 | static int ov7670_command(struct i2c_client *client, unsigned cmd, void *arg) | ||
1266 | { | ||
1267 | return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg); | ||
1268 | } | ||
1269 | |||
1270 | /* ----------------------------------------------------------------------- */ | 1183 | /* ----------------------------------------------------------------------- */ |
1271 | 1184 | ||
1272 | static const struct v4l2_subdev_core_ops ov7670_core_ops = { | 1185 | static const struct v4l2_subdev_core_ops ov7670_core_ops = { |
@@ -1300,11 +1213,6 @@ static int ov7670_probe(struct i2c_client *client, | |||
1300 | struct ov7670_info *info; | 1213 | struct ov7670_info *info; |
1301 | int ret; | 1214 | int ret; |
1302 | 1215 | ||
1303 | /* | ||
1304 | * For now: only deal with adapters we recognize. | ||
1305 | */ | ||
1306 | if (client->adapter->id != I2C_HW_SMBUS_CAFE) | ||
1307 | return -ENODEV; | ||
1308 | info = kzalloc(sizeof(struct ov7670_info), GFP_KERNEL); | 1216 | info = kzalloc(sizeof(struct ov7670_info), GFP_KERNEL); |
1309 | if (info == NULL) | 1217 | if (info == NULL) |
1310 | return -ENOMEM; | 1218 | return -ENOMEM; |
@@ -1347,9 +1255,7 @@ MODULE_DEVICE_TABLE(i2c, ov7670_id); | |||
1347 | 1255 | ||
1348 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { | 1256 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
1349 | .name = "ov7670", | 1257 | .name = "ov7670", |
1350 | .command = ov7670_command, | ||
1351 | .probe = ov7670_probe, | 1258 | .probe = ov7670_probe, |
1352 | .remove = ov7670_remove, | 1259 | .remove = ov7670_remove, |
1353 | .legacy_class = I2C_CLASS_TV_ANALOG, | ||
1354 | .id_table = ov7670_id, | 1260 | .id_table = ov7670_id, |
1355 | }; | 1261 | }; |