Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Video for Linux Two |
| 3 | * |
| 4 | * A generic video device interface for the LINUX operating system |
| 5 | * using a set of device structures/vectors for low level operations. |
| 6 | * |
| 7 | * This file replaces the videodev.c file that comes with the |
| 8 | * regular kernel distribution. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version |
| 13 | * 2 of the License, or (at your option) any later version. |
| 14 | * |
Mauro Carvalho Chehab | 43db48d | 2007-01-09 11:20:59 -0300 | [diff] [blame] | 15 | * Author: Bill Dirks <bill@thedirks.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * based on code by Alan Cox, <alan@cymru.net> |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Video capture interface for Linux |
| 22 | * |
| 23 | * A generic video device interface for the LINUX operating system |
| 24 | * using a set of device structures/vectors for low level operations. |
| 25 | * |
| 26 | * This program is free software; you can redistribute it and/or |
| 27 | * modify it under the terms of the GNU General Public License |
| 28 | * as published by the Free Software Foundation; either version |
| 29 | * 2 of the License, or (at your option) any later version. |
| 30 | * |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 31 | * Author: Alan Cox, <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | * |
| 33 | * Fixes: |
| 34 | */ |
| 35 | |
| 36 | /* |
| 37 | * Video4linux 1/2 integration by Justin Schoeman |
| 38 | * <justin@suntiger.ee.up.ac.za> |
| 39 | * 2.4 PROCFS support ported from 2.4 kernels by |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 40 | * Iñaki García Etxebarria <garetxe@euskalnet.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | * Makefile fix by "W. Michael Petullo" <mike@flyn.org> |
| 42 | * 2.4 devfs support ported from 2.4 kernels by |
| 43 | * Dan Merillat <dan@merillat.org> |
| 44 | * Added Gerd Knorrs v4l1 enhancements (Justin Schoeman) |
| 45 | */ |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/module.h> |
| 48 | #include <linux/types.h> |
| 49 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <linux/mm.h> |
| 51 | #include <linux/string.h> |
| 52 | #include <linux/errno.h> |
Hans Verkuil | f3d092b | 2007-02-23 20:55:14 -0300 | [diff] [blame] | 53 | #include <linux/i2c.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <asm/uaccess.h> |
| 55 | #include <asm/system.h> |
| 56 | #include <asm/pgtable.h> |
| 57 | #include <asm/io.h> |
| 58 | #include <asm/div64.h> |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 59 | #define __OLD_VIDIOC_ /* To allow fixing old calls*/ |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 60 | #include <media/v4l2-common.h> |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 61 | #include <media/v4l2-device.h> |
Hans Verkuil | 3434eb7 | 2007-04-27 12:31:08 -0300 | [diff] [blame] | 62 | #include <media/v4l2-chip-ident.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Hans Verkuil | 33b687c | 2008-07-25 05:32:50 -0300 | [diff] [blame] | 64 | #include <linux/videodev2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr"); |
| 67 | MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers"); |
| 68 | MODULE_LICENSE("GPL"); |
| 69 | |
| 70 | /* |
| 71 | * |
| 72 | * V 4 L 2 D R I V E R H E L P E R A P I |
| 73 | * |
| 74 | */ |
| 75 | |
| 76 | /* |
| 77 | * Video Standard Operations (contributed by Michael Schimek) |
| 78 | */ |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | /* ----------------------------------------------------------------- */ |
| 82 | /* priority handling */ |
| 83 | |
| 84 | #define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND || \ |
| 85 | val == V4L2_PRIORITY_INTERACTIVE || \ |
| 86 | val == V4L2_PRIORITY_RECORD) |
| 87 | |
| 88 | int v4l2_prio_init(struct v4l2_prio_state *global) |
| 89 | { |
| 90 | memset(global,0,sizeof(*global)); |
| 91 | return 0; |
| 92 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 93 | EXPORT_SYMBOL(v4l2_prio_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local, |
| 96 | enum v4l2_priority new) |
| 97 | { |
| 98 | if (!V4L2_PRIO_VALID(new)) |
| 99 | return -EINVAL; |
| 100 | if (*local == new) |
| 101 | return 0; |
| 102 | |
| 103 | atomic_inc(&global->prios[new]); |
| 104 | if (V4L2_PRIO_VALID(*local)) |
| 105 | atomic_dec(&global->prios[*local]); |
| 106 | *local = new; |
| 107 | return 0; |
| 108 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 109 | EXPORT_SYMBOL(v4l2_prio_change); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local) |
| 112 | { |
| 113 | return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT); |
| 114 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 115 | EXPORT_SYMBOL(v4l2_prio_open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local) |
| 118 | { |
| 119 | if (V4L2_PRIO_VALID(*local)) |
| 120 | atomic_dec(&global->prios[*local]); |
| 121 | return 0; |
| 122 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 123 | EXPORT_SYMBOL(v4l2_prio_close); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global) |
| 126 | { |
| 127 | if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0) |
| 128 | return V4L2_PRIORITY_RECORD; |
| 129 | if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0) |
| 130 | return V4L2_PRIORITY_INTERACTIVE; |
| 131 | if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0) |
| 132 | return V4L2_PRIORITY_BACKGROUND; |
| 133 | return V4L2_PRIORITY_UNSET; |
| 134 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 135 | EXPORT_SYMBOL(v4l2_prio_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local) |
| 138 | { |
| 139 | if (*local < v4l2_prio_max(global)) |
| 140 | return -EBUSY; |
| 141 | return 0; |
| 142 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 143 | EXPORT_SYMBOL(v4l2_prio_check); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | /* ----------------------------------------------------------------- */ |
| 146 | |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 147 | /* Helper functions for control handling */ |
| 148 | |
| 149 | /* Check for correctness of the ctrl's value based on the data from |
| 150 | struct v4l2_queryctrl and the available menu items. Note that |
| 151 | menu_items may be NULL, in that case it is ignored. */ |
| 152 | int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl, |
| 153 | const char **menu_items) |
| 154 | { |
| 155 | if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED) |
| 156 | return -EINVAL; |
| 157 | if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED) |
| 158 | return -EBUSY; |
| 159 | if (qctrl->type == V4L2_CTRL_TYPE_BUTTON || |
| 160 | qctrl->type == V4L2_CTRL_TYPE_INTEGER64 || |
| 161 | qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) |
| 162 | return 0; |
| 163 | if (ctrl->value < qctrl->minimum || ctrl->value > qctrl->maximum) |
| 164 | return -ERANGE; |
| 165 | if (qctrl->type == V4L2_CTRL_TYPE_MENU && menu_items != NULL) { |
| 166 | if (menu_items[ctrl->value] == NULL || |
| 167 | menu_items[ctrl->value][0] == '\0') |
| 168 | return -EINVAL; |
| 169 | } |
| 170 | return 0; |
| 171 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 172 | EXPORT_SYMBOL(v4l2_ctrl_check); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 173 | |
| 174 | /* Returns NULL or a character pointer array containing the menu for |
| 175 | the given control ID. The pointer array ends with a NULL pointer. |
| 176 | An empty string signifies a menu entry that is invalid. This allows |
| 177 | drivers to disable certain options if it is not supported. */ |
| 178 | const char **v4l2_ctrl_get_menu(u32 id) |
| 179 | { |
| 180 | static const char *mpeg_audio_sampling_freq[] = { |
| 181 | "44.1 kHz", |
| 182 | "48 kHz", |
| 183 | "32 kHz", |
| 184 | NULL |
| 185 | }; |
| 186 | static const char *mpeg_audio_encoding[] = { |
Hans Verkuil | e6b5da8 | 2008-08-08 07:38:07 -0300 | [diff] [blame] | 187 | "MPEG-1/2 Layer I", |
| 188 | "MPEG-1/2 Layer II", |
| 189 | "MPEG-1/2 Layer III", |
| 190 | "MPEG-2/4 AAC", |
| 191 | "AC-3", |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 192 | NULL |
| 193 | }; |
| 194 | static const char *mpeg_audio_l1_bitrate[] = { |
| 195 | "32 kbps", |
| 196 | "64 kbps", |
| 197 | "96 kbps", |
| 198 | "128 kbps", |
| 199 | "160 kbps", |
| 200 | "192 kbps", |
| 201 | "224 kbps", |
| 202 | "256 kbps", |
| 203 | "288 kbps", |
| 204 | "320 kbps", |
| 205 | "352 kbps", |
| 206 | "384 kbps", |
| 207 | "416 kbps", |
| 208 | "448 kbps", |
| 209 | NULL |
| 210 | }; |
| 211 | static const char *mpeg_audio_l2_bitrate[] = { |
| 212 | "32 kbps", |
| 213 | "48 kbps", |
| 214 | "56 kbps", |
| 215 | "64 kbps", |
| 216 | "80 kbps", |
| 217 | "96 kbps", |
| 218 | "112 kbps", |
| 219 | "128 kbps", |
| 220 | "160 kbps", |
| 221 | "192 kbps", |
| 222 | "224 kbps", |
| 223 | "256 kbps", |
| 224 | "320 kbps", |
| 225 | "384 kbps", |
| 226 | NULL |
| 227 | }; |
| 228 | static const char *mpeg_audio_l3_bitrate[] = { |
| 229 | "32 kbps", |
| 230 | "40 kbps", |
| 231 | "48 kbps", |
| 232 | "56 kbps", |
| 233 | "64 kbps", |
| 234 | "80 kbps", |
| 235 | "96 kbps", |
| 236 | "112 kbps", |
| 237 | "128 kbps", |
| 238 | "160 kbps", |
| 239 | "192 kbps", |
| 240 | "224 kbps", |
| 241 | "256 kbps", |
| 242 | "320 kbps", |
| 243 | NULL |
| 244 | }; |
Hans Verkuil | e6b5da8 | 2008-08-08 07:38:07 -0300 | [diff] [blame] | 245 | static const char *mpeg_audio_ac3_bitrate[] = { |
| 246 | "32 kbps", |
| 247 | "40 kbps", |
| 248 | "48 kbps", |
| 249 | "56 kbps", |
| 250 | "64 kbps", |
| 251 | "80 kbps", |
| 252 | "96 kbps", |
| 253 | "112 kbps", |
| 254 | "128 kbps", |
| 255 | "160 kbps", |
| 256 | "192 kbps", |
| 257 | "224 kbps", |
| 258 | "256 kbps", |
| 259 | "320 kbps", |
| 260 | "384 kbps", |
| 261 | "448 kbps", |
| 262 | "512 kbps", |
| 263 | "576 kbps", |
| 264 | "640 kbps", |
| 265 | NULL |
| 266 | }; |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 267 | static const char *mpeg_audio_mode[] = { |
| 268 | "Stereo", |
| 269 | "Joint Stereo", |
| 270 | "Dual", |
| 271 | "Mono", |
| 272 | NULL |
| 273 | }; |
| 274 | static const char *mpeg_audio_mode_extension[] = { |
| 275 | "Bound 4", |
| 276 | "Bound 8", |
| 277 | "Bound 12", |
| 278 | "Bound 16", |
| 279 | NULL |
| 280 | }; |
| 281 | static const char *mpeg_audio_emphasis[] = { |
| 282 | "No Emphasis", |
| 283 | "50/15 us", |
| 284 | "CCITT J17", |
| 285 | NULL |
| 286 | }; |
| 287 | static const char *mpeg_audio_crc[] = { |
| 288 | "No CRC", |
| 289 | "16-bit CRC", |
| 290 | NULL |
| 291 | }; |
| 292 | static const char *mpeg_video_encoding[] = { |
| 293 | "MPEG-1", |
| 294 | "MPEG-2", |
Janne Grunau | 188919a | 2008-08-08 07:21:00 -0300 | [diff] [blame] | 295 | "MPEG-4 AVC", |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 296 | NULL |
| 297 | }; |
| 298 | static const char *mpeg_video_aspect[] = { |
| 299 | "1x1", |
| 300 | "4x3", |
| 301 | "16x9", |
| 302 | "2.21x1", |
| 303 | NULL |
| 304 | }; |
| 305 | static const char *mpeg_video_bitrate_mode[] = { |
| 306 | "Variable Bitrate", |
| 307 | "Constant Bitrate", |
| 308 | NULL |
| 309 | }; |
| 310 | static const char *mpeg_stream_type[] = { |
| 311 | "MPEG-2 Program Stream", |
| 312 | "MPEG-2 Transport Stream", |
| 313 | "MPEG-1 System Stream", |
| 314 | "MPEG-2 DVD-compatible Stream", |
| 315 | "MPEG-1 VCD-compatible Stream", |
| 316 | "MPEG-2 SVCD-compatible Stream", |
| 317 | NULL |
| 318 | }; |
Hans Verkuil | 8cbde94 | 2006-06-24 14:36:02 -0300 | [diff] [blame] | 319 | static const char *mpeg_stream_vbi_fmt[] = { |
| 320 | "No VBI", |
Hans Verkuil | 9952351 | 2006-06-25 11:18:54 -0300 | [diff] [blame] | 321 | "Private packet, IVTV format", |
Hans Verkuil | 8cbde94 | 2006-06-24 14:36:02 -0300 | [diff] [blame] | 322 | NULL |
| 323 | }; |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 324 | static const char *camera_power_line_frequency[] = { |
| 325 | "Disabled", |
| 326 | "50 Hz", |
| 327 | "60 Hz", |
| 328 | NULL |
| 329 | }; |
| 330 | static const char *camera_exposure_auto[] = { |
| 331 | "Auto Mode", |
| 332 | "Manual Mode", |
| 333 | "Shutter Priority Mode", |
| 334 | "Aperture Priority Mode", |
| 335 | NULL |
| 336 | }; |
Hans Verkuil | 11c469e | 2009-02-20 05:50:52 -0300 | [diff] [blame] | 337 | static const char *colorfx[] = { |
| 338 | "None", |
| 339 | "Black & White", |
| 340 | "Sepia", |
| 341 | NULL |
| 342 | }; |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 343 | |
| 344 | switch (id) { |
| 345 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: |
| 346 | return mpeg_audio_sampling_freq; |
| 347 | case V4L2_CID_MPEG_AUDIO_ENCODING: |
| 348 | return mpeg_audio_encoding; |
| 349 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: |
| 350 | return mpeg_audio_l1_bitrate; |
| 351 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: |
| 352 | return mpeg_audio_l2_bitrate; |
| 353 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: |
| 354 | return mpeg_audio_l3_bitrate; |
Hans Verkuil | e6b5da8 | 2008-08-08 07:38:07 -0300 | [diff] [blame] | 355 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: |
| 356 | return mpeg_audio_ac3_bitrate; |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 357 | case V4L2_CID_MPEG_AUDIO_MODE: |
| 358 | return mpeg_audio_mode; |
| 359 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: |
| 360 | return mpeg_audio_mode_extension; |
| 361 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: |
| 362 | return mpeg_audio_emphasis; |
| 363 | case V4L2_CID_MPEG_AUDIO_CRC: |
| 364 | return mpeg_audio_crc; |
| 365 | case V4L2_CID_MPEG_VIDEO_ENCODING: |
| 366 | return mpeg_video_encoding; |
| 367 | case V4L2_CID_MPEG_VIDEO_ASPECT: |
| 368 | return mpeg_video_aspect; |
| 369 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: |
| 370 | return mpeg_video_bitrate_mode; |
| 371 | case V4L2_CID_MPEG_STREAM_TYPE: |
| 372 | return mpeg_stream_type; |
Hans Verkuil | 8cbde94 | 2006-06-24 14:36:02 -0300 | [diff] [blame] | 373 | case V4L2_CID_MPEG_STREAM_VBI_FMT: |
| 374 | return mpeg_stream_vbi_fmt; |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 375 | case V4L2_CID_POWER_LINE_FREQUENCY: |
| 376 | return camera_power_line_frequency; |
| 377 | case V4L2_CID_EXPOSURE_AUTO: |
| 378 | return camera_exposure_auto; |
Hans Verkuil | 11c469e | 2009-02-20 05:50:52 -0300 | [diff] [blame] | 379 | case V4L2_CID_COLORFX: |
| 380 | return colorfx; |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 381 | default: |
| 382 | return NULL; |
| 383 | } |
| 384 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 385 | EXPORT_SYMBOL(v4l2_ctrl_get_menu); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 386 | |
Hans Verkuil | 69028d7 | 2008-08-08 07:55:00 -0300 | [diff] [blame] | 387 | /* Return the control name. */ |
| 388 | const char *v4l2_ctrl_get_name(u32 id) |
| 389 | { |
| 390 | switch (id) { |
| 391 | /* USER controls */ |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 392 | case V4L2_CID_USER_CLASS: return "User Controls"; |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 393 | case V4L2_CID_BRIGHTNESS: return "Brightness"; |
| 394 | case V4L2_CID_CONTRAST: return "Contrast"; |
| 395 | case V4L2_CID_SATURATION: return "Saturation"; |
| 396 | case V4L2_CID_HUE: return "Hue"; |
Hans Verkuil | 81dde91 | 2009-02-20 06:30:12 -0300 | [diff] [blame] | 397 | case V4L2_CID_AUDIO_VOLUME: return "Volume"; |
| 398 | case V4L2_CID_AUDIO_BALANCE: return "Balance"; |
| 399 | case V4L2_CID_AUDIO_BASS: return "Bass"; |
| 400 | case V4L2_CID_AUDIO_TREBLE: return "Treble"; |
| 401 | case V4L2_CID_AUDIO_MUTE: return "Mute"; |
| 402 | case V4L2_CID_AUDIO_LOUDNESS: return "Loudness"; |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 403 | case V4L2_CID_BLACK_LEVEL: return "Black Level"; |
| 404 | case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic"; |
| 405 | case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance"; |
| 406 | case V4L2_CID_RED_BALANCE: return "Red Balance"; |
| 407 | case V4L2_CID_BLUE_BALANCE: return "Blue Balance"; |
| 408 | case V4L2_CID_GAMMA: return "Gamma"; |
| 409 | case V4L2_CID_EXPOSURE: return "Exposure"; |
| 410 | case V4L2_CID_AUTOGAIN: return "Gain, Automatic"; |
| 411 | case V4L2_CID_GAIN: return "Gain"; |
| 412 | case V4L2_CID_HFLIP: return "Horizontal Flip"; |
| 413 | case V4L2_CID_VFLIP: return "Vertical Flip"; |
| 414 | case V4L2_CID_HCENTER: return "Horizontal Center"; |
| 415 | case V4L2_CID_VCENTER: return "Vertical Center"; |
| 416 | case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency"; |
| 417 | case V4L2_CID_HUE_AUTO: return "Hue, Automatic"; |
| 418 | case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature"; |
| 419 | case V4L2_CID_SHARPNESS: return "Sharpness"; |
| 420 | case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation"; |
| 421 | case V4L2_CID_CHROMA_AGC: return "Chroma AGC"; |
| 422 | case V4L2_CID_COLOR_KILLER: return "Color Killer"; |
Hans Verkuil | 11c469e | 2009-02-20 05:50:52 -0300 | [diff] [blame] | 423 | case V4L2_CID_COLORFX: return "Color Effects"; |
Hans Verkuil | 69028d7 | 2008-08-08 07:55:00 -0300 | [diff] [blame] | 424 | |
| 425 | /* MPEG controls */ |
| 426 | case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls"; |
| 427 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency"; |
| 428 | case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding"; |
| 429 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate"; |
| 430 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate"; |
| 431 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate"; |
Hans Verkuil | f723af1 | 2008-08-09 10:35:29 -0300 | [diff] [blame] | 432 | case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate"; |
Hans Verkuil | 69028d7 | 2008-08-08 07:55:00 -0300 | [diff] [blame] | 433 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate"; |
| 434 | case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode"; |
| 435 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension"; |
| 436 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis"; |
| 437 | case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC"; |
| 438 | case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute"; |
| 439 | case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding"; |
| 440 | case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect"; |
| 441 | case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames"; |
| 442 | case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size"; |
| 443 | case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure"; |
| 444 | case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown"; |
| 445 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode"; |
| 446 | case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate"; |
| 447 | case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate"; |
| 448 | case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation"; |
| 449 | case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute"; |
| 450 | case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV"; |
| 451 | case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type"; |
| 452 | case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID"; |
| 453 | case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID"; |
| 454 | case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID"; |
| 455 | case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID"; |
| 456 | case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID"; |
| 457 | case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID"; |
| 458 | case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format"; |
| 459 | |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 460 | /* CAMERA controls */ |
| 461 | case V4L2_CID_CAMERA_CLASS: return "Camera Controls"; |
| 462 | case V4L2_CID_EXPOSURE_AUTO: return "Auto Exposure"; |
| 463 | case V4L2_CID_EXPOSURE_ABSOLUTE: return "Exposure Time, Absolute"; |
| 464 | case V4L2_CID_EXPOSURE_AUTO_PRIORITY: return "Exposure, Dynamic Framerate"; |
| 465 | case V4L2_CID_PAN_RELATIVE: return "Pan, Relative"; |
| 466 | case V4L2_CID_TILT_RELATIVE: return "Tilt, Relative"; |
| 467 | case V4L2_CID_PAN_RESET: return "Pan, Reset"; |
| 468 | case V4L2_CID_TILT_RESET: return "Tilt, Reset"; |
| 469 | case V4L2_CID_PAN_ABSOLUTE: return "Pan, Absolute"; |
| 470 | case V4L2_CID_TILT_ABSOLUTE: return "Tilt, Absolute"; |
| 471 | case V4L2_CID_FOCUS_ABSOLUTE: return "Focus, Absolute"; |
| 472 | case V4L2_CID_FOCUS_RELATIVE: return "Focus, Relative"; |
| 473 | case V4L2_CID_FOCUS_AUTO: return "Focus, Automatic"; |
| 474 | case V4L2_CID_ZOOM_ABSOLUTE: return "Zoom, Absolute"; |
| 475 | case V4L2_CID_ZOOM_RELATIVE: return "Zoom, Relative"; |
| 476 | case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous"; |
| 477 | case V4L2_CID_PRIVACY: return "Privacy"; |
| 478 | |
Hans Verkuil | 69028d7 | 2008-08-08 07:55:00 -0300 | [diff] [blame] | 479 | default: |
| 480 | return NULL; |
| 481 | } |
| 482 | } |
| 483 | EXPORT_SYMBOL(v4l2_ctrl_get_name); |
| 484 | |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 485 | /* Fill in a struct v4l2_queryctrl */ |
| 486 | int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def) |
| 487 | { |
Hans Verkuil | 69028d7 | 2008-08-08 07:55:00 -0300 | [diff] [blame] | 488 | const char *name = v4l2_ctrl_get_name(qctrl->id); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 489 | |
| 490 | qctrl->flags = 0; |
Hans Verkuil | 69028d7 | 2008-08-08 07:55:00 -0300 | [diff] [blame] | 491 | if (name == NULL) |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 492 | return -EINVAL; |
Hans Verkuil | 69028d7 | 2008-08-08 07:55:00 -0300 | [diff] [blame] | 493 | |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 494 | switch (qctrl->id) { |
| 495 | case V4L2_CID_AUDIO_MUTE: |
| 496 | case V4L2_CID_AUDIO_LOUDNESS: |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 497 | case V4L2_CID_AUTO_WHITE_BALANCE: |
| 498 | case V4L2_CID_AUTOGAIN: |
| 499 | case V4L2_CID_HFLIP: |
| 500 | case V4L2_CID_VFLIP: |
| 501 | case V4L2_CID_HUE_AUTO: |
Hans Verkuil | 81dde91 | 2009-02-20 06:30:12 -0300 | [diff] [blame] | 502 | case V4L2_CID_CHROMA_AGC: |
| 503 | case V4L2_CID_COLOR_KILLER: |
Hans Verkuil | 5eee72e | 2007-04-27 12:31:00 -0300 | [diff] [blame] | 504 | case V4L2_CID_MPEG_AUDIO_MUTE: |
Hans Verkuil | 01f1e44 | 2007-08-21 18:32:42 -0300 | [diff] [blame] | 505 | case V4L2_CID_MPEG_VIDEO_MUTE: |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 506 | case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: |
| 507 | case V4L2_CID_MPEG_VIDEO_PULLDOWN: |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 508 | case V4L2_CID_EXPOSURE_AUTO_PRIORITY: |
Hans Verkuil | 81dde91 | 2009-02-20 06:30:12 -0300 | [diff] [blame] | 509 | case V4L2_CID_FOCUS_AUTO: |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 510 | case V4L2_CID_PRIVACY: |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 511 | qctrl->type = V4L2_CTRL_TYPE_BOOLEAN; |
| 512 | min = 0; |
| 513 | max = step = 1; |
| 514 | break; |
Hans Verkuil | 81dde91 | 2009-02-20 06:30:12 -0300 | [diff] [blame] | 515 | case V4L2_CID_PAN_RESET: |
| 516 | case V4L2_CID_TILT_RESET: |
| 517 | qctrl->type = V4L2_CTRL_TYPE_BUTTON; |
| 518 | qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY; |
| 519 | min = max = step = def = 0; |
| 520 | break; |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 521 | case V4L2_CID_POWER_LINE_FREQUENCY: |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 522 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: |
| 523 | case V4L2_CID_MPEG_AUDIO_ENCODING: |
| 524 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: |
| 525 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: |
| 526 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: |
Hans Verkuil | e6b5da8 | 2008-08-08 07:38:07 -0300 | [diff] [blame] | 527 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 528 | case V4L2_CID_MPEG_AUDIO_MODE: |
| 529 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: |
| 530 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: |
| 531 | case V4L2_CID_MPEG_AUDIO_CRC: |
| 532 | case V4L2_CID_MPEG_VIDEO_ENCODING: |
| 533 | case V4L2_CID_MPEG_VIDEO_ASPECT: |
| 534 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: |
| 535 | case V4L2_CID_MPEG_STREAM_TYPE: |
Hans Verkuil | 8cbde94 | 2006-06-24 14:36:02 -0300 | [diff] [blame] | 536 | case V4L2_CID_MPEG_STREAM_VBI_FMT: |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 537 | case V4L2_CID_EXPOSURE_AUTO: |
Hans Verkuil | 11c469e | 2009-02-20 05:50:52 -0300 | [diff] [blame] | 538 | case V4L2_CID_COLORFX: |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 539 | qctrl->type = V4L2_CTRL_TYPE_MENU; |
| 540 | step = 1; |
| 541 | break; |
| 542 | case V4L2_CID_USER_CLASS: |
Laurent Pinchart | 7498015 | 2008-12-14 16:24:04 -0300 | [diff] [blame] | 543 | case V4L2_CID_CAMERA_CLASS: |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 544 | case V4L2_CID_MPEG_CLASS: |
| 545 | qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS; |
| 546 | qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; |
| 547 | min = max = step = def = 0; |
| 548 | break; |
| 549 | default: |
| 550 | qctrl->type = V4L2_CTRL_TYPE_INTEGER; |
| 551 | break; |
| 552 | } |
| 553 | switch (qctrl->id) { |
| 554 | case V4L2_CID_MPEG_AUDIO_ENCODING: |
| 555 | case V4L2_CID_MPEG_AUDIO_MODE: |
| 556 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: |
| 557 | case V4L2_CID_MPEG_VIDEO_B_FRAMES: |
| 558 | case V4L2_CID_MPEG_STREAM_TYPE: |
| 559 | qctrl->flags |= V4L2_CTRL_FLAG_UPDATE; |
| 560 | break; |
| 561 | case V4L2_CID_AUDIO_VOLUME: |
| 562 | case V4L2_CID_AUDIO_BALANCE: |
| 563 | case V4L2_CID_AUDIO_BASS: |
| 564 | case V4L2_CID_AUDIO_TREBLE: |
| 565 | case V4L2_CID_BRIGHTNESS: |
| 566 | case V4L2_CID_CONTRAST: |
| 567 | case V4L2_CID_SATURATION: |
| 568 | case V4L2_CID_HUE: |
Hans Verkuil | 81dde91 | 2009-02-20 06:30:12 -0300 | [diff] [blame] | 569 | case V4L2_CID_RED_BALANCE: |
| 570 | case V4L2_CID_BLUE_BALANCE: |
| 571 | case V4L2_CID_GAMMA: |
Janne Grunau | 8c84cfd | 2009-03-18 17:00:39 -0300 | [diff] [blame] | 572 | case V4L2_CID_SHARPNESS: |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 573 | qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; |
| 574 | break; |
Hans Verkuil | 81dde91 | 2009-02-20 06:30:12 -0300 | [diff] [blame] | 575 | case V4L2_CID_PAN_RELATIVE: |
| 576 | case V4L2_CID_TILT_RELATIVE: |
| 577 | case V4L2_CID_FOCUS_RELATIVE: |
| 578 | case V4L2_CID_ZOOM_RELATIVE: |
| 579 | qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY; |
| 580 | break; |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 581 | } |
| 582 | qctrl->minimum = min; |
| 583 | qctrl->maximum = max; |
| 584 | qctrl->step = step; |
| 585 | qctrl->default_value = def; |
| 586 | qctrl->reserved[0] = qctrl->reserved[1] = 0; |
Hans Verkuil | b634a93 | 2009-01-17 11:26:59 -0300 | [diff] [blame] | 587 | strlcpy(qctrl->name, name, sizeof(qctrl->name)); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 588 | return 0; |
| 589 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 590 | EXPORT_SYMBOL(v4l2_ctrl_query_fill); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 591 | |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 592 | /* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and |
Hans Verkuil | e281db58 | 2008-08-08 12:43:59 -0300 | [diff] [blame] | 593 | the menu. The qctrl pointer may be NULL, in which case it is ignored. |
| 594 | If menu_items is NULL, then the menu items are retrieved using |
| 595 | v4l2_ctrl_get_menu. */ |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 596 | int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl, |
| 597 | const char **menu_items) |
| 598 | { |
| 599 | int i; |
| 600 | |
Hans Verkuil | 1e55126 | 2008-08-08 08:34:19 -0300 | [diff] [blame] | 601 | qmenu->reserved = 0; |
Hans Verkuil | e281db58 | 2008-08-08 12:43:59 -0300 | [diff] [blame] | 602 | if (menu_items == NULL) |
| 603 | menu_items = v4l2_ctrl_get_menu(qmenu->id); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 604 | if (menu_items == NULL || |
| 605 | (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum))) |
| 606 | return -EINVAL; |
| 607 | for (i = 0; i < qmenu->index && menu_items[i]; i++) ; |
| 608 | if (menu_items[i] == NULL || menu_items[i][0] == '\0') |
| 609 | return -EINVAL; |
Hans Verkuil | b634a93 | 2009-01-17 11:26:59 -0300 | [diff] [blame] | 610 | strlcpy(qmenu->name, menu_items[qmenu->index], sizeof(qmenu->name)); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 611 | return 0; |
| 612 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 613 | EXPORT_SYMBOL(v4l2_ctrl_query_menu); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 614 | |
Hans Verkuil | 1e55126 | 2008-08-08 08:34:19 -0300 | [diff] [blame] | 615 | /* Fill in a struct v4l2_querymenu based on the specified array of valid |
| 616 | menu items (terminated by V4L2_CTRL_MENU_IDS_END). |
| 617 | Use this if there are 'holes' in the list of valid menu items. */ |
| 618 | int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids) |
| 619 | { |
| 620 | const char **menu_items = v4l2_ctrl_get_menu(qmenu->id); |
| 621 | |
| 622 | qmenu->reserved = 0; |
| 623 | if (menu_items == NULL || ids == NULL) |
| 624 | return -EINVAL; |
| 625 | while (*ids != V4L2_CTRL_MENU_IDS_END) { |
| 626 | if (*ids++ == qmenu->index) { |
Hans Verkuil | b634a93 | 2009-01-17 11:26:59 -0300 | [diff] [blame] | 627 | strlcpy(qmenu->name, menu_items[qmenu->index], |
| 628 | sizeof(qmenu->name)); |
Hans Verkuil | 1e55126 | 2008-08-08 08:34:19 -0300 | [diff] [blame] | 629 | return 0; |
| 630 | } |
| 631 | } |
| 632 | return -EINVAL; |
| 633 | } |
| 634 | EXPORT_SYMBOL(v4l2_ctrl_query_menu_valid_items); |
| 635 | |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 636 | /* ctrl_classes points to an array of u32 pointers, the last element is |
| 637 | a NULL pointer. Each u32 array is a 0-terminated array of control IDs. |
| 638 | Each array must be sorted low to high and belong to the same control |
Hans Verkuil | 2ba5889 | 2009-02-13 10:57:48 -0300 | [diff] [blame] | 639 | class. The array of u32 pointers must also be sorted, from low class IDs |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 640 | to high class IDs. |
| 641 | |
| 642 | This function returns the first ID that follows after the given ID. |
| 643 | When no more controls are available 0 is returned. */ |
| 644 | u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id) |
| 645 | { |
Hans Verkuil | a46c5fb | 2007-07-19 04:53:36 -0300 | [diff] [blame] | 646 | u32 ctrl_class = V4L2_CTRL_ID2CLASS(id); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 647 | const u32 *pctrl; |
| 648 | |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 649 | if (ctrl_classes == NULL) |
| 650 | return 0; |
Hans Verkuil | a46c5fb | 2007-07-19 04:53:36 -0300 | [diff] [blame] | 651 | |
| 652 | /* if no query is desired, then check if the ID is part of ctrl_classes */ |
| 653 | if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0) { |
| 654 | /* find class */ |
| 655 | while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) != ctrl_class) |
| 656 | ctrl_classes++; |
| 657 | if (*ctrl_classes == NULL) |
| 658 | return 0; |
| 659 | pctrl = *ctrl_classes; |
| 660 | /* find control ID */ |
| 661 | while (*pctrl && *pctrl != id) pctrl++; |
| 662 | return *pctrl ? id : 0; |
| 663 | } |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 664 | id &= V4L2_CTRL_ID_MASK; |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 665 | id++; /* select next control */ |
| 666 | /* find first class that matches (or is greater than) the class of |
| 667 | the ID */ |
| 668 | while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) < ctrl_class) |
| 669 | ctrl_classes++; |
| 670 | /* no more classes */ |
| 671 | if (*ctrl_classes == NULL) |
| 672 | return 0; |
| 673 | pctrl = *ctrl_classes; |
| 674 | /* find first ctrl within the class that is >= ID */ |
| 675 | while (*pctrl && *pctrl < id) pctrl++; |
| 676 | if (*pctrl) |
| 677 | return *pctrl; |
| 678 | /* we are at the end of the controls of the current class. */ |
| 679 | /* continue with next class if available */ |
| 680 | ctrl_classes++; |
| 681 | if (*ctrl_classes == NULL) |
| 682 | return 0; |
| 683 | return **ctrl_classes; |
| 684 | } |
Mauro Carvalho Chehab | 057596e | 2008-02-02 11:25:31 -0300 | [diff] [blame] | 685 | EXPORT_SYMBOL(v4l2_ctrl_next); |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 686 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 687 | int v4l2_chip_match_host(const struct v4l2_dbg_match *match) |
Mauro Carvalho Chehab | a925447 | 2008-01-29 18:32:35 -0300 | [diff] [blame] | 688 | { |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 689 | switch (match->type) { |
Mauro Carvalho Chehab | a925447 | 2008-01-29 18:32:35 -0300 | [diff] [blame] | 690 | case V4L2_CHIP_MATCH_HOST: |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 691 | return match->addr == 0; |
Mauro Carvalho Chehab | a925447 | 2008-01-29 18:32:35 -0300 | [diff] [blame] | 692 | default: |
| 693 | return 0; |
| 694 | } |
| 695 | } |
| 696 | EXPORT_SYMBOL(v4l2_chip_match_host); |
| 697 | |
| 698 | #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 699 | int v4l2_chip_match_i2c_client(struct i2c_client *c, const struct v4l2_dbg_match *match) |
Hans Verkuil | f3d092b | 2007-02-23 20:55:14 -0300 | [diff] [blame] | 700 | { |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 701 | int len; |
| 702 | |
| 703 | if (c == NULL || match == NULL) |
| 704 | return 0; |
| 705 | |
| 706 | switch (match->type) { |
Hans Verkuil | f3d092b | 2007-02-23 20:55:14 -0300 | [diff] [blame] | 707 | case V4L2_CHIP_MATCH_I2C_DRIVER: |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 708 | if (c->driver == NULL || c->driver->driver.name == NULL) |
| 709 | return 0; |
| 710 | len = strlen(c->driver->driver.name); |
| 711 | /* legacy drivers have a ' suffix, don't try to match that */ |
| 712 | if (len && c->driver->driver.name[len - 1] == '\'') |
| 713 | len--; |
| 714 | return len && !strncmp(c->driver->driver.name, match->name, len); |
Hans Verkuil | f3d092b | 2007-02-23 20:55:14 -0300 | [diff] [blame] | 715 | case V4L2_CHIP_MATCH_I2C_ADDR: |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 716 | return c->addr == match->addr; |
Hans Verkuil | f3d092b | 2007-02-23 20:55:14 -0300 | [diff] [blame] | 717 | default: |
| 718 | return 0; |
| 719 | } |
| 720 | } |
Mauro Carvalho Chehab | a925447 | 2008-01-29 18:32:35 -0300 | [diff] [blame] | 721 | EXPORT_SYMBOL(v4l2_chip_match_i2c_client); |
Hans Verkuil | f3d092b | 2007-02-23 20:55:14 -0300 | [diff] [blame] | 722 | |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 723 | int v4l2_chip_ident_i2c_client(struct i2c_client *c, struct v4l2_dbg_chip_ident *chip, |
Hans Verkuil | 3434eb7 | 2007-04-27 12:31:08 -0300 | [diff] [blame] | 724 | u32 ident, u32 revision) |
| 725 | { |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 726 | if (!v4l2_chip_match_i2c_client(c, &chip->match)) |
Hans Verkuil | 3434eb7 | 2007-04-27 12:31:08 -0300 | [diff] [blame] | 727 | return 0; |
| 728 | if (chip->ident == V4L2_IDENT_NONE) { |
| 729 | chip->ident = ident; |
| 730 | chip->revision = revision; |
| 731 | } |
| 732 | else { |
| 733 | chip->ident = V4L2_IDENT_AMBIGUOUS; |
| 734 | chip->revision = 0; |
| 735 | } |
| 736 | return 0; |
| 737 | } |
Mauro Carvalho Chehab | a925447 | 2008-01-29 18:32:35 -0300 | [diff] [blame] | 738 | EXPORT_SYMBOL(v4l2_chip_ident_i2c_client); |
Hans Verkuil | f3d092b | 2007-02-23 20:55:14 -0300 | [diff] [blame] | 739 | |
Hans Verkuil | 9cb2318 | 2006-06-18 14:11:08 -0300 | [diff] [blame] | 740 | /* ----------------------------------------------------------------- */ |
| 741 | |
Hans Verkuil | 78a3b4d | 2009-04-01 03:41:09 -0300 | [diff] [blame] | 742 | /* I2C Helper functions */ |
Hans Verkuil | 8ffbc65 | 2007-09-12 08:32:50 -0300 | [diff] [blame] | 743 | |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 744 | |
| 745 | void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, |
| 746 | const struct v4l2_subdev_ops *ops) |
| 747 | { |
| 748 | v4l2_subdev_init(sd, ops); |
| 749 | /* the owner is the same as the i2c_client's driver owner */ |
| 750 | sd->owner = client->driver->driver.owner; |
| 751 | /* i2c_client and v4l2_subdev point to one another */ |
| 752 | v4l2_set_subdevdata(sd, client); |
| 753 | i2c_set_clientdata(client, sd); |
| 754 | /* initialize name */ |
| 755 | snprintf(sd->name, sizeof(sd->name), "%s %d-%04x", |
| 756 | client->driver->driver.name, i2c_adapter_id(client->adapter), |
| 757 | client->addr); |
| 758 | } |
| 759 | EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init); |
| 760 | |
| 761 | |
| 762 | |
| 763 | /* Load an i2c sub-device. It assumes that i2c_get_adapdata(adapter) |
| 764 | returns the v4l2_device and that i2c_get_clientdata(client) |
| 765 | returns the v4l2_subdev. */ |
| 766 | struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter, |
| 767 | const char *module_name, const char *client_type, u8 addr) |
| 768 | { |
| 769 | struct v4l2_device *dev = i2c_get_adapdata(adapter); |
| 770 | struct v4l2_subdev *sd = NULL; |
| 771 | struct i2c_client *client; |
| 772 | struct i2c_board_info info; |
| 773 | |
| 774 | BUG_ON(!dev); |
Hans Verkuil | d64260d | 2009-03-18 15:48:01 -0300 | [diff] [blame] | 775 | |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 776 | if (module_name) |
| 777 | request_module(module_name); |
Hans Verkuil | d64260d | 2009-03-18 15:48:01 -0300 | [diff] [blame] | 778 | |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 779 | /* Setup the i2c board info with the device type and |
| 780 | the device address. */ |
| 781 | memset(&info, 0, sizeof(info)); |
| 782 | strlcpy(info.type, client_type, sizeof(info.type)); |
| 783 | info.addr = addr; |
| 784 | |
| 785 | /* Create the i2c client */ |
| 786 | client = i2c_new_device(adapter, &info); |
| 787 | /* Note: it is possible in the future that |
| 788 | c->driver is NULL if the driver is still being loaded. |
| 789 | We need better support from the kernel so that we |
| 790 | can easily wait for the load to finish. */ |
| 791 | if (client == NULL || client->driver == NULL) |
Hans Verkuil | 7c026c3 | 2009-03-12 18:56:15 -0300 | [diff] [blame] | 792 | goto error; |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 793 | |
| 794 | /* Lock the module so we can safely get the v4l2_subdev pointer */ |
| 795 | if (!try_module_get(client->driver->driver.owner)) |
Hans Verkuil | 7c026c3 | 2009-03-12 18:56:15 -0300 | [diff] [blame] | 796 | goto error; |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 797 | sd = i2c_get_clientdata(client); |
| 798 | |
| 799 | /* Register with the v4l2_device which increases the module's |
| 800 | use count as well. */ |
| 801 | if (v4l2_device_register_subdev(dev, sd)) |
| 802 | sd = NULL; |
| 803 | /* Decrease the module use count to match the first try_module_get. */ |
| 804 | module_put(client->driver->driver.owner); |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 805 | |
Hans Verkuil | 7c026c3 | 2009-03-12 18:56:15 -0300 | [diff] [blame] | 806 | error: |
| 807 | /* If we have a client but no subdev, then something went wrong and |
| 808 | we must unregister the client. */ |
| 809 | if (client && sd == NULL) |
| 810 | i2c_unregister_device(client); |
| 811 | return sd; |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 812 | } |
| 813 | EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev); |
| 814 | |
| 815 | /* Probe and load an i2c sub-device. It assumes that i2c_get_adapdata(adapter) |
| 816 | returns the v4l2_device and that i2c_get_clientdata(client) |
| 817 | returns the v4l2_subdev. */ |
| 818 | struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter, |
| 819 | const char *module_name, const char *client_type, |
| 820 | const unsigned short *addrs) |
| 821 | { |
| 822 | struct v4l2_device *dev = i2c_get_adapdata(adapter); |
| 823 | struct v4l2_subdev *sd = NULL; |
| 824 | struct i2c_client *client = NULL; |
| 825 | struct i2c_board_info info; |
| 826 | |
| 827 | BUG_ON(!dev); |
Hans Verkuil | d64260d | 2009-03-18 15:48:01 -0300 | [diff] [blame] | 828 | |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 829 | if (module_name) |
| 830 | request_module(module_name); |
Hans Verkuil | d64260d | 2009-03-18 15:48:01 -0300 | [diff] [blame] | 831 | |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 832 | /* Setup the i2c board info with the device type and |
| 833 | the device address. */ |
| 834 | memset(&info, 0, sizeof(info)); |
| 835 | strlcpy(info.type, client_type, sizeof(info.type)); |
| 836 | |
| 837 | /* Probe and create the i2c client */ |
| 838 | client = i2c_new_probed_device(adapter, &info, addrs); |
| 839 | /* Note: it is possible in the future that |
| 840 | c->driver is NULL if the driver is still being loaded. |
| 841 | We need better support from the kernel so that we |
| 842 | can easily wait for the load to finish. */ |
| 843 | if (client == NULL || client->driver == NULL) |
Hans Verkuil | 7c026c3 | 2009-03-12 18:56:15 -0300 | [diff] [blame] | 844 | goto error; |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 845 | |
| 846 | /* Lock the module so we can safely get the v4l2_subdev pointer */ |
| 847 | if (!try_module_get(client->driver->driver.owner)) |
Hans Verkuil | 7c026c3 | 2009-03-12 18:56:15 -0300 | [diff] [blame] | 848 | goto error; |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 849 | sd = i2c_get_clientdata(client); |
| 850 | |
| 851 | /* Register with the v4l2_device which increases the module's |
| 852 | use count as well. */ |
| 853 | if (v4l2_device_register_subdev(dev, sd)) |
| 854 | sd = NULL; |
| 855 | /* Decrease the module use count to match the first try_module_get. */ |
| 856 | module_put(client->driver->driver.owner); |
Hans Verkuil | 7c026c3 | 2009-03-12 18:56:15 -0300 | [diff] [blame] | 857 | |
| 858 | error: |
| 859 | /* If we have a client but no subdev, then something went wrong and |
| 860 | we must unregister the client. */ |
| 861 | if (client && sd == NULL) |
| 862 | i2c_unregister_device(client); |
Hans Verkuil | dd99120 | 2008-11-23 12:19:45 -0300 | [diff] [blame] | 863 | return sd; |
| 864 | } |
| 865 | EXPORT_SYMBOL_GPL(v4l2_i2c_new_probed_subdev); |
| 866 | |
Hans Verkuil | 868f985 | 2009-03-30 11:40:54 -0300 | [diff] [blame^] | 867 | struct v4l2_subdev *v4l2_i2c_new_probed_subdev_addr(struct v4l2_device *v4l2_dev, |
| 868 | struct i2c_adapter *adapter, |
| 869 | const char *module_name, const char *client_type, u8 addr) |
| 870 | { |
| 871 | unsigned short addrs[2] = { addr, I2C_CLIENT_END }; |
| 872 | |
| 873 | return v4l2_i2c_new_probed_subdev(v4l2_dev, adapter, |
| 874 | module_name, client_type, addrs); |
| 875 | } |
| 876 | EXPORT_SYMBOL_GPL(v4l2_i2c_new_probed_subdev_addr); |
| 877 | |
Hans Verkuil | ab373190 | 2009-02-21 18:08:41 -0300 | [diff] [blame] | 878 | /* Return i2c client address of v4l2_subdev. */ |
| 879 | unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd) |
| 880 | { |
| 881 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 882 | |
| 883 | return client ? client->addr : I2C_CLIENT_END; |
| 884 | } |
| 885 | EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_addr); |
| 886 | |
Hans Verkuil | c7d29e2 | 2009-01-18 19:37:59 -0300 | [diff] [blame] | 887 | /* Return a list of I2C tuner addresses to probe. Use only if the tuner |
| 888 | addresses are unknown. */ |
| 889 | const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type) |
| 890 | { |
| 891 | static const unsigned short radio_addrs[] = { |
| 892 | #if defined(CONFIG_MEDIA_TUNER_TEA5761) || defined(CONFIG_MEDIA_TUNER_TEA5761_MODULE) |
| 893 | 0x10, |
| 894 | #endif |
| 895 | 0x60, |
| 896 | I2C_CLIENT_END |
| 897 | }; |
| 898 | static const unsigned short demod_addrs[] = { |
| 899 | 0x42, 0x43, 0x4a, 0x4b, |
| 900 | I2C_CLIENT_END |
| 901 | }; |
| 902 | static const unsigned short tv_addrs[] = { |
| 903 | 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */ |
| 904 | 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, |
| 905 | 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, |
| 906 | I2C_CLIENT_END |
| 907 | }; |
| 908 | |
| 909 | switch (type) { |
| 910 | case ADDRS_RADIO: |
| 911 | return radio_addrs; |
| 912 | case ADDRS_DEMOD: |
| 913 | return demod_addrs; |
| 914 | case ADDRS_TV: |
| 915 | return tv_addrs; |
| 916 | case ADDRS_TV_WITH_DEMOD: |
| 917 | return tv_addrs + 4; |
| 918 | } |
| 919 | return NULL; |
| 920 | } |
| 921 | EXPORT_SYMBOL_GPL(v4l2_i2c_tuner_addrs); |
| 922 | |
Mauro Carvalho Chehab | a925447 | 2008-01-29 18:32:35 -0300 | [diff] [blame] | 923 | #endif |