diff options
| -rw-r--r-- | drivers/media/video/Makefile | 2 | ||||
| -rw-r--r-- | drivers/media/video/v4l2-common.c | 479 | ||||
| -rw-r--r-- | drivers/media/video/v4l2-ctrls.c | 1847 | ||||
| -rw-r--r-- | include/media/v4l2-ctrls.h | 460 | ||||
| -rw-r--r-- | include/media/v4l2-dev.h | 4 | ||||
| -rw-r--r-- | include/media/v4l2-device.h | 4 | ||||
| -rw-r--r-- | include/media/v4l2-subdev.h | 3 |
7 files changed, 2324 insertions, 475 deletions
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index c76fef390797..40f98fba5f88 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile | |||
| @@ -11,7 +11,7 @@ stkwebcam-objs := stk-webcam.o stk-sensor.o | |||
| 11 | omap2cam-objs := omap24xxcam.o omap24xxcam-dma.o | 11 | omap2cam-objs := omap24xxcam.o omap24xxcam-dma.o |
| 12 | 12 | ||
| 13 | videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \ | 13 | videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \ |
| 14 | v4l2-event.o | 14 | v4l2-event.o v4l2-ctrls.o |
| 15 | 15 | ||
| 16 | # V4L2 core modules | 16 | # V4L2 core modules |
| 17 | 17 | ||
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c index 4e53b0b3339c..3ce7c64e5789 100644 --- a/drivers/media/video/v4l2-common.c +++ b/drivers/media/video/v4l2-common.c | |||
| @@ -62,6 +62,7 @@ | |||
| 62 | #define __OLD_VIDIOC_ /* To allow fixing old calls*/ | 62 | #define __OLD_VIDIOC_ /* To allow fixing old calls*/ |
| 63 | #include <media/v4l2-common.h> | 63 | #include <media/v4l2-common.h> |
| 64 | #include <media/v4l2-device.h> | 64 | #include <media/v4l2-device.h> |
| 65 | #include <media/v4l2-ctrls.h> | ||
| 65 | #include <media/v4l2-chip-ident.h> | 66 | #include <media/v4l2-chip-ident.h> |
| 66 | 67 | ||
| 67 | #include <linux/videodev2.h> | 68 | #include <linux/videodev2.h> |
| @@ -172,487 +173,17 @@ int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl, | |||
| 172 | } | 173 | } |
| 173 | EXPORT_SYMBOL(v4l2_ctrl_check); | 174 | EXPORT_SYMBOL(v4l2_ctrl_check); |
| 174 | 175 | ||
| 175 | /* Returns NULL or a character pointer array containing the menu for | ||
| 176 | the given control ID. The pointer array ends with a NULL pointer. | ||
| 177 | An empty string signifies a menu entry that is invalid. This allows | ||
| 178 | drivers to disable certain options if it is not supported. */ | ||
| 179 | const char **v4l2_ctrl_get_menu(u32 id) | ||
| 180 | { | ||
| 181 | static const char *mpeg_audio_sampling_freq[] = { | ||
| 182 | "44.1 kHz", | ||
| 183 | "48 kHz", | ||
| 184 | "32 kHz", | ||
| 185 | NULL | ||
| 186 | }; | ||
| 187 | static const char *mpeg_audio_encoding[] = { | ||
| 188 | "MPEG-1/2 Layer I", | ||
| 189 | "MPEG-1/2 Layer II", | ||
| 190 | "MPEG-1/2 Layer III", | ||
| 191 | "MPEG-2/4 AAC", | ||
| 192 | "AC-3", | ||
| 193 | NULL | ||
| 194 | }; | ||
| 195 | static const char *mpeg_audio_l1_bitrate[] = { | ||
| 196 | "32 kbps", | ||
| 197 | "64 kbps", | ||
| 198 | "96 kbps", | ||
| 199 | "128 kbps", | ||
| 200 | "160 kbps", | ||
| 201 | "192 kbps", | ||
| 202 | "224 kbps", | ||
| 203 | "256 kbps", | ||
| 204 | "288 kbps", | ||
| 205 | "320 kbps", | ||
| 206 | "352 kbps", | ||
| 207 | "384 kbps", | ||
| 208 | "416 kbps", | ||
| 209 | "448 kbps", | ||
| 210 | NULL | ||
| 211 | }; | ||
| 212 | static const char *mpeg_audio_l2_bitrate[] = { | ||
| 213 | "32 kbps", | ||
| 214 | "48 kbps", | ||
| 215 | "56 kbps", | ||
| 216 | "64 kbps", | ||
| 217 | "80 kbps", | ||
| 218 | "96 kbps", | ||
| 219 | "112 kbps", | ||
| 220 | "128 kbps", | ||
| 221 | "160 kbps", | ||
| 222 | "192 kbps", | ||
| 223 | "224 kbps", | ||
| 224 | "256 kbps", | ||
| 225 | "320 kbps", | ||
| 226 | "384 kbps", | ||
| 227 | NULL | ||
| 228 | }; | ||
| 229 | static const char *mpeg_audio_l3_bitrate[] = { | ||
| 230 | "32 kbps", | ||
| 231 | "40 kbps", | ||
| 232 | "48 kbps", | ||
| 233 | "56 kbps", | ||
| 234 | "64 kbps", | ||
| 235 | "80 kbps", | ||
| 236 | "96 kbps", | ||
| 237 | "112 kbps", | ||
| 238 | "128 kbps", | ||
| 239 | "160 kbps", | ||
| 240 | "192 kbps", | ||
| 241 | "224 kbps", | ||
| 242 | "256 kbps", | ||
| 243 | "320 kbps", | ||
| 244 | NULL | ||
| 245 | }; | ||
| 246 | static const char *mpeg_audio_ac3_bitrate[] = { | ||
| 247 | "32 kbps", | ||
| 248 | "40 kbps", | ||
| 249 | "48 kbps", | ||
| 250 | "56 kbps", | ||
| 251 | "64 kbps", | ||
| 252 | "80 kbps", | ||
| 253 | "96 kbps", | ||
| 254 | "112 kbps", | ||
| 255 | "128 kbps", | ||
| 256 | "160 kbps", | ||
| 257 | "192 kbps", | ||
| 258 | "224 kbps", | ||
| 259 | "256 kbps", | ||
| 260 | "320 kbps", | ||
| 261 | "384 kbps", | ||
| 262 | "448 kbps", | ||
| 263 | "512 kbps", | ||
| 264 | "576 kbps", | ||
| 265 | "640 kbps", | ||
| 266 | NULL | ||
| 267 | }; | ||
| 268 | static const char *mpeg_audio_mode[] = { | ||
| 269 | "Stereo", | ||
| 270 | "Joint Stereo", | ||
| 271 | "Dual", | ||
| 272 | "Mono", | ||
| 273 | NULL | ||
| 274 | }; | ||
| 275 | static const char *mpeg_audio_mode_extension[] = { | ||
| 276 | "Bound 4", | ||
| 277 | "Bound 8", | ||
| 278 | "Bound 12", | ||
| 279 | "Bound 16", | ||
| 280 | NULL | ||
| 281 | }; | ||
| 282 | static const char *mpeg_audio_emphasis[] = { | ||
| 283 | "No Emphasis", | ||
| 284 | "50/15 us", | ||
| 285 | "CCITT J17", | ||
| 286 | NULL | ||
| 287 | }; | ||
| 288 | static const char *mpeg_audio_crc[] = { | ||
| 289 | "No CRC", | ||
| 290 | "16-bit CRC", | ||
| 291 | NULL | ||
| 292 | }; | ||
| 293 | static const char *mpeg_video_encoding[] = { | ||
| 294 | "MPEG-1", | ||
| 295 | "MPEG-2", | ||
| 296 | "MPEG-4 AVC", | ||
| 297 | NULL | ||
| 298 | }; | ||
| 299 | static const char *mpeg_video_aspect[] = { | ||
| 300 | "1x1", | ||
| 301 | "4x3", | ||
| 302 | "16x9", | ||
| 303 | "2.21x1", | ||
| 304 | NULL | ||
| 305 | }; | ||
| 306 | static const char *mpeg_video_bitrate_mode[] = { | ||
| 307 | "Variable Bitrate", | ||
| 308 | "Constant Bitrate", | ||
| 309 | NULL | ||
| 310 | }; | ||
| 311 | static const char *mpeg_stream_type[] = { | ||
| 312 | "MPEG-2 Program Stream", | ||
| 313 | "MPEG-2 Transport Stream", | ||
| 314 | "MPEG-1 System Stream", | ||
| 315 | "MPEG-2 DVD-compatible Stream", | ||
| 316 | "MPEG-1 VCD-compatible Stream", | ||
| 317 | "MPEG-2 SVCD-compatible Stream", | ||
| 318 | NULL | ||
| 319 | }; | ||
| 320 | static const char *mpeg_stream_vbi_fmt[] = { | ||
| 321 | "No VBI", | ||
| 322 | "Private packet, IVTV format", | ||
| 323 | NULL | ||
| 324 | }; | ||
| 325 | static const char *camera_power_line_frequency[] = { | ||
| 326 | "Disabled", | ||
| 327 | "50 Hz", | ||
| 328 | "60 Hz", | ||
| 329 | NULL | ||
| 330 | }; | ||
| 331 | static const char *camera_exposure_auto[] = { | ||
| 332 | "Auto Mode", | ||
| 333 | "Manual Mode", | ||
| 334 | "Shutter Priority Mode", | ||
| 335 | "Aperture Priority Mode", | ||
| 336 | NULL | ||
| 337 | }; | ||
| 338 | static const char *colorfx[] = { | ||
| 339 | "None", | ||
| 340 | "Black & White", | ||
| 341 | "Sepia", | ||
| 342 | "Negative", | ||
| 343 | "Emboss", | ||
| 344 | "Sketch", | ||
| 345 | "Sky blue", | ||
| 346 | "Grass green", | ||
| 347 | "Skin whiten", | ||
| 348 | "Vivid", | ||
| 349 | NULL | ||
| 350 | }; | ||
| 351 | static const char *tune_preemphasis[] = { | ||
| 352 | "No preemphasis", | ||
| 353 | "50 useconds", | ||
| 354 | "75 useconds", | ||
| 355 | NULL, | ||
| 356 | }; | ||
| 357 | |||
| 358 | switch (id) { | ||
| 359 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: | ||
| 360 | return mpeg_audio_sampling_freq; | ||
| 361 | case V4L2_CID_MPEG_AUDIO_ENCODING: | ||
| 362 | return mpeg_audio_encoding; | ||
| 363 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: | ||
| 364 | return mpeg_audio_l1_bitrate; | ||
| 365 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: | ||
| 366 | return mpeg_audio_l2_bitrate; | ||
| 367 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: | ||
| 368 | return mpeg_audio_l3_bitrate; | ||
| 369 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: | ||
| 370 | return mpeg_audio_ac3_bitrate; | ||
| 371 | case V4L2_CID_MPEG_AUDIO_MODE: | ||
| 372 | return mpeg_audio_mode; | ||
| 373 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: | ||
| 374 | return mpeg_audio_mode_extension; | ||
| 375 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: | ||
| 376 | return mpeg_audio_emphasis; | ||
| 377 | case V4L2_CID_MPEG_AUDIO_CRC: | ||
| 378 | return mpeg_audio_crc; | ||
| 379 | case V4L2_CID_MPEG_VIDEO_ENCODING: | ||
| 380 | return mpeg_video_encoding; | ||
| 381 | case V4L2_CID_MPEG_VIDEO_ASPECT: | ||
| 382 | return mpeg_video_aspect; | ||
| 383 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: | ||
| 384 | return mpeg_video_bitrate_mode; | ||
| 385 | case V4L2_CID_MPEG_STREAM_TYPE: | ||
| 386 | return mpeg_stream_type; | ||
| 387 | case V4L2_CID_MPEG_STREAM_VBI_FMT: | ||
| 388 | return mpeg_stream_vbi_fmt; | ||
| 389 | case V4L2_CID_POWER_LINE_FREQUENCY: | ||
| 390 | return camera_power_line_frequency; | ||
| 391 | case V4L2_CID_EXPOSURE_AUTO: | ||
| 392 | return camera_exposure_auto; | ||
| 393 | case V4L2_CID_COLORFX: | ||
| 394 | return colorfx; | ||
| 395 | case V4L2_CID_TUNE_PREEMPHASIS: | ||
| 396 | return tune_preemphasis; | ||
| 397 | default: | ||
| 398 | return NULL; | ||
| 399 | } | ||
| 400 | } | ||
| 401 | EXPORT_SYMBOL(v4l2_ctrl_get_menu); | ||
| 402 | |||
| 403 | /* Return the control name. */ | ||
| 404 | const char *v4l2_ctrl_get_name(u32 id) | ||
| 405 | { | ||
| 406 | switch (id) { | ||
| 407 | /* USER controls */ | ||
| 408 | case V4L2_CID_USER_CLASS: return "User Controls"; | ||
| 409 | case V4L2_CID_BRIGHTNESS: return "Brightness"; | ||
| 410 | case V4L2_CID_CONTRAST: return "Contrast"; | ||
| 411 | case V4L2_CID_SATURATION: return "Saturation"; | ||
| 412 | case V4L2_CID_HUE: return "Hue"; | ||
| 413 | case V4L2_CID_AUDIO_VOLUME: return "Volume"; | ||
| 414 | case V4L2_CID_AUDIO_BALANCE: return "Balance"; | ||
| 415 | case V4L2_CID_AUDIO_BASS: return "Bass"; | ||
| 416 | case V4L2_CID_AUDIO_TREBLE: return "Treble"; | ||
| 417 | case V4L2_CID_AUDIO_MUTE: return "Mute"; | ||
| 418 | case V4L2_CID_AUDIO_LOUDNESS: return "Loudness"; | ||
| 419 | case V4L2_CID_BLACK_LEVEL: return "Black Level"; | ||
| 420 | case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic"; | ||
| 421 | case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance"; | ||
| 422 | case V4L2_CID_RED_BALANCE: return "Red Balance"; | ||
| 423 | case V4L2_CID_BLUE_BALANCE: return "Blue Balance"; | ||
| 424 | case V4L2_CID_GAMMA: return "Gamma"; | ||
| 425 | case V4L2_CID_EXPOSURE: return "Exposure"; | ||
| 426 | case V4L2_CID_AUTOGAIN: return "Gain, Automatic"; | ||
| 427 | case V4L2_CID_GAIN: return "Gain"; | ||
| 428 | case V4L2_CID_HFLIP: return "Horizontal Flip"; | ||
| 429 | case V4L2_CID_VFLIP: return "Vertical Flip"; | ||
| 430 | case V4L2_CID_HCENTER: return "Horizontal Center"; | ||
| 431 | case V4L2_CID_VCENTER: return "Vertical Center"; | ||
| 432 | case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency"; | ||
| 433 | case V4L2_CID_HUE_AUTO: return "Hue, Automatic"; | ||
| 434 | case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature"; | ||
| 435 | case V4L2_CID_SHARPNESS: return "Sharpness"; | ||
| 436 | case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation"; | ||
| 437 | case V4L2_CID_CHROMA_AGC: return "Chroma AGC"; | ||
| 438 | case V4L2_CID_CHROMA_GAIN: return "Chroma Gain"; | ||
| 439 | case V4L2_CID_COLOR_KILLER: return "Color Killer"; | ||
| 440 | case V4L2_CID_COLORFX: return "Color Effects"; | ||
| 441 | case V4L2_CID_AUTOBRIGHTNESS: return "Brightness, Automatic"; | ||
| 442 | case V4L2_CID_BAND_STOP_FILTER: return "Band-Stop Filter"; | ||
| 443 | case V4L2_CID_ROTATE: return "Rotate"; | ||
| 444 | case V4L2_CID_BG_COLOR: return "Background Color"; | ||
| 445 | |||
| 446 | /* MPEG controls */ | ||
| 447 | case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls"; | ||
| 448 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency"; | ||
| 449 | case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding"; | ||
| 450 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate"; | ||
| 451 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate"; | ||
| 452 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate"; | ||
| 453 | case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate"; | ||
| 454 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate"; | ||
| 455 | case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode"; | ||
| 456 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension"; | ||
| 457 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis"; | ||
| 458 | case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC"; | ||
| 459 | case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute"; | ||
| 460 | case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding"; | ||
| 461 | case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect"; | ||
| 462 | case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames"; | ||
| 463 | case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size"; | ||
| 464 | case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure"; | ||
| 465 | case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown"; | ||
| 466 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode"; | ||
| 467 | case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate"; | ||
| 468 | case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate"; | ||
| 469 | case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation"; | ||
| 470 | case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute"; | ||
| 471 | case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV"; | ||
| 472 | case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type"; | ||
| 473 | case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID"; | ||
| 474 | case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID"; | ||
| 475 | case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID"; | ||
| 476 | case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID"; | ||
| 477 | case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID"; | ||
| 478 | case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID"; | ||
| 479 | case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format"; | ||
| 480 | |||
| 481 | /* CAMERA controls */ | ||
| 482 | case V4L2_CID_CAMERA_CLASS: return "Camera Controls"; | ||
| 483 | case V4L2_CID_EXPOSURE_AUTO: return "Auto Exposure"; | ||
| 484 | case V4L2_CID_EXPOSURE_ABSOLUTE: return "Exposure Time, Absolute"; | ||
| 485 | case V4L2_CID_EXPOSURE_AUTO_PRIORITY: return "Exposure, Dynamic Framerate"; | ||
| 486 | case V4L2_CID_PAN_RELATIVE: return "Pan, Relative"; | ||
| 487 | case V4L2_CID_TILT_RELATIVE: return "Tilt, Relative"; | ||
| 488 | case V4L2_CID_PAN_RESET: return "Pan, Reset"; | ||
| 489 | case V4L2_CID_TILT_RESET: return "Tilt, Reset"; | ||
| 490 | case V4L2_CID_PAN_ABSOLUTE: return "Pan, Absolute"; | ||
| 491 | case V4L2_CID_TILT_ABSOLUTE: return "Tilt, Absolute"; | ||
| 492 | case V4L2_CID_FOCUS_ABSOLUTE: return "Focus, Absolute"; | ||
| 493 | case V4L2_CID_FOCUS_RELATIVE: return "Focus, Relative"; | ||
| 494 | case V4L2_CID_FOCUS_AUTO: return "Focus, Automatic"; | ||
| 495 | case V4L2_CID_IRIS_ABSOLUTE: return "Iris, Absolute"; | ||
| 496 | case V4L2_CID_IRIS_RELATIVE: return "Iris, Relative"; | ||
| 497 | case V4L2_CID_ZOOM_ABSOLUTE: return "Zoom, Absolute"; | ||
| 498 | case V4L2_CID_ZOOM_RELATIVE: return "Zoom, Relative"; | ||
| 499 | case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous"; | ||
| 500 | case V4L2_CID_PRIVACY: return "Privacy"; | ||
| 501 | |||
| 502 | /* FM Radio Modulator control */ | ||
| 503 | case V4L2_CID_FM_TX_CLASS: return "FM Radio Modulator Controls"; | ||
| 504 | case V4L2_CID_RDS_TX_DEVIATION: return "RDS Signal Deviation"; | ||
| 505 | case V4L2_CID_RDS_TX_PI: return "RDS Program ID"; | ||
| 506 | case V4L2_CID_RDS_TX_PTY: return "RDS Program Type"; | ||
| 507 | case V4L2_CID_RDS_TX_PS_NAME: return "RDS PS Name"; | ||
| 508 | case V4L2_CID_RDS_TX_RADIO_TEXT: return "RDS Radio Text"; | ||
| 509 | case V4L2_CID_AUDIO_LIMITER_ENABLED: return "Audio Limiter Feature Enabled"; | ||
| 510 | case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: return "Audio Limiter Release Time"; | ||
| 511 | case V4L2_CID_AUDIO_LIMITER_DEVIATION: return "Audio Limiter Deviation"; | ||
| 512 | case V4L2_CID_AUDIO_COMPRESSION_ENABLED: return "Audio Compression Feature Enabled"; | ||
| 513 | case V4L2_CID_AUDIO_COMPRESSION_GAIN: return "Audio Compression Gain"; | ||
| 514 | case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: return "Audio Compression Threshold"; | ||
| 515 | case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: return "Audio Compression Attack Time"; | ||
| 516 | case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: return "Audio Compression Release Time"; | ||
| 517 | case V4L2_CID_PILOT_TONE_ENABLED: return "Pilot Tone Feature Enabled"; | ||
| 518 | case V4L2_CID_PILOT_TONE_DEVIATION: return "Pilot Tone Deviation"; | ||
| 519 | case V4L2_CID_PILOT_TONE_FREQUENCY: return "Pilot Tone Frequency"; | ||
| 520 | case V4L2_CID_TUNE_PREEMPHASIS: return "Pre-emphasis settings"; | ||
| 521 | case V4L2_CID_TUNE_POWER_LEVEL: return "Tune Power Level"; | ||
| 522 | case V4L2_CID_TUNE_ANTENNA_CAPACITOR: return "Tune Antenna Capacitor"; | ||
| 523 | |||
| 524 | default: | ||
| 525 | return NULL; | ||
| 526 | } | ||
| 527 | } | ||
| 528 | EXPORT_SYMBOL(v4l2_ctrl_get_name); | ||
| 529 | |||
| 530 | /* Fill in a struct v4l2_queryctrl */ | 176 | /* Fill in a struct v4l2_queryctrl */ |
| 531 | int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def) | 177 | int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def) |
| 532 | { | 178 | { |
| 533 | const char *name = v4l2_ctrl_get_name(qctrl->id); | 179 | const char *name; |
| 180 | |||
| 181 | v4l2_ctrl_fill(qctrl->id, &name, &qctrl->type, | ||
| 182 | &min, &max, &step, &def, &qctrl->flags); | ||
| 534 | 183 | ||
| 535 | qctrl->flags = 0; | ||
| 536 | if (name == NULL) | 184 | if (name == NULL) |
| 537 | return -EINVAL; | 185 | return -EINVAL; |
| 538 | 186 | ||
| 539 | switch (qctrl->id) { | ||
| 540 | case V4L2_CID_AUDIO_MUTE: | ||
| 541 | case V4L2_CID_AUDIO_LOUDNESS: | ||
| 542 | case V4L2_CID_AUTO_WHITE_BALANCE: | ||
| 543 | case V4L2_CID_AUTOGAIN: | ||
| 544 | case V4L2_CID_HFLIP: | ||
| 545 | case V4L2_CID_VFLIP: | ||
| 546 | case V4L2_CID_HUE_AUTO: | ||
| 547 | case V4L2_CID_CHROMA_AGC: | ||
| 548 | case V4L2_CID_COLOR_KILLER: | ||
| 549 | case V4L2_CID_MPEG_AUDIO_MUTE: | ||
| 550 | case V4L2_CID_MPEG_VIDEO_MUTE: | ||
| 551 | case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: | ||
| 552 | case V4L2_CID_MPEG_VIDEO_PULLDOWN: | ||
| 553 | case V4L2_CID_EXPOSURE_AUTO_PRIORITY: | ||
| 554 | case V4L2_CID_FOCUS_AUTO: | ||
| 555 | case V4L2_CID_PRIVACY: | ||
| 556 | case V4L2_CID_AUDIO_LIMITER_ENABLED: | ||
| 557 | case V4L2_CID_AUDIO_COMPRESSION_ENABLED: | ||
| 558 | case V4L2_CID_PILOT_TONE_ENABLED: | ||
| 559 | qctrl->type = V4L2_CTRL_TYPE_BOOLEAN; | ||
| 560 | min = 0; | ||
| 561 | max = step = 1; | ||
| 562 | break; | ||
| 563 | case V4L2_CID_PAN_RESET: | ||
| 564 | case V4L2_CID_TILT_RESET: | ||
| 565 | qctrl->type = V4L2_CTRL_TYPE_BUTTON; | ||
| 566 | qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY; | ||
| 567 | min = max = step = def = 0; | ||
| 568 | break; | ||
| 569 | case V4L2_CID_POWER_LINE_FREQUENCY: | ||
| 570 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: | ||
| 571 | case V4L2_CID_MPEG_AUDIO_ENCODING: | ||
| 572 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: | ||
| 573 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: | ||
| 574 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: | ||
| 575 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: | ||
| 576 | case V4L2_CID_MPEG_AUDIO_MODE: | ||
| 577 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: | ||
| 578 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: | ||
| 579 | case V4L2_CID_MPEG_AUDIO_CRC: | ||
| 580 | case V4L2_CID_MPEG_VIDEO_ENCODING: | ||
| 581 | case V4L2_CID_MPEG_VIDEO_ASPECT: | ||
| 582 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: | ||
| 583 | case V4L2_CID_MPEG_STREAM_TYPE: | ||
| 584 | case V4L2_CID_MPEG_STREAM_VBI_FMT: | ||
| 585 | case V4L2_CID_EXPOSURE_AUTO: | ||
| 586 | case V4L2_CID_COLORFX: | ||
| 587 | case V4L2_CID_TUNE_PREEMPHASIS: | ||
| 588 | qctrl->type = V4L2_CTRL_TYPE_MENU; | ||
| 589 | step = 1; | ||
| 590 | break; | ||
| 591 | case V4L2_CID_RDS_TX_PS_NAME: | ||
| 592 | case V4L2_CID_RDS_TX_RADIO_TEXT: | ||
| 593 | qctrl->type = V4L2_CTRL_TYPE_STRING; | ||
| 594 | break; | ||
| 595 | case V4L2_CID_USER_CLASS: | ||
| 596 | case V4L2_CID_CAMERA_CLASS: | ||
| 597 | case V4L2_CID_MPEG_CLASS: | ||
| 598 | case V4L2_CID_FM_TX_CLASS: | ||
| 599 | qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS; | ||
| 600 | qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; | ||
| 601 | min = max = step = def = 0; | ||
| 602 | break; | ||
| 603 | case V4L2_CID_BG_COLOR: | ||
| 604 | qctrl->type = V4L2_CTRL_TYPE_INTEGER; | ||
| 605 | step = 1; | ||
| 606 | min = 0; | ||
| 607 | /* Max is calculated as RGB888 that is 2^24 */ | ||
| 608 | max = 0xFFFFFF; | ||
| 609 | break; | ||
| 610 | default: | ||
| 611 | qctrl->type = V4L2_CTRL_TYPE_INTEGER; | ||
| 612 | break; | ||
| 613 | } | ||
| 614 | switch (qctrl->id) { | ||
| 615 | case V4L2_CID_MPEG_AUDIO_ENCODING: | ||
| 616 | case V4L2_CID_MPEG_AUDIO_MODE: | ||
| 617 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: | ||
| 618 | case V4L2_CID_MPEG_VIDEO_B_FRAMES: | ||
| 619 | case V4L2_CID_MPEG_STREAM_TYPE: | ||
| 620 | qctrl->flags |= V4L2_CTRL_FLAG_UPDATE; | ||
| 621 | break; | ||
| 622 | case V4L2_CID_AUDIO_VOLUME: | ||
| 623 | case V4L2_CID_AUDIO_BALANCE: | ||
| 624 | case V4L2_CID_AUDIO_BASS: | ||
| 625 | case V4L2_CID_AUDIO_TREBLE: | ||
| 626 | case V4L2_CID_BRIGHTNESS: | ||
| 627 | case V4L2_CID_CONTRAST: | ||
| 628 | case V4L2_CID_SATURATION: | ||
| 629 | case V4L2_CID_HUE: | ||
| 630 | case V4L2_CID_RED_BALANCE: | ||
| 631 | case V4L2_CID_BLUE_BALANCE: | ||
| 632 | case V4L2_CID_GAMMA: | ||
| 633 | case V4L2_CID_SHARPNESS: | ||
| 634 | case V4L2_CID_CHROMA_GAIN: | ||
| 635 | case V4L2_CID_RDS_TX_DEVIATION: | ||
| 636 | case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: | ||
| 637 | case V4L2_CID_AUDIO_LIMITER_DEVIATION: | ||
| 638 | case V4L2_CID_AUDIO_COMPRESSION_GAIN: | ||
| 639 | case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: | ||
| 640 | case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: | ||
| 641 | case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: | ||
| 642 | case V4L2_CID_PILOT_TONE_DEVIATION: | ||
| 643 | case V4L2_CID_PILOT_TONE_FREQUENCY: | ||
| 644 | case V4L2_CID_TUNE_POWER_LEVEL: | ||
| 645 | case V4L2_CID_TUNE_ANTENNA_CAPACITOR: | ||
| 646 | qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; | ||
| 647 | break; | ||
| 648 | case V4L2_CID_PAN_RELATIVE: | ||
| 649 | case V4L2_CID_TILT_RELATIVE: | ||
| 650 | case V4L2_CID_FOCUS_RELATIVE: | ||
| 651 | case V4L2_CID_IRIS_RELATIVE: | ||
| 652 | case V4L2_CID_ZOOM_RELATIVE: | ||
| 653 | qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY; | ||
| 654 | break; | ||
| 655 | } | ||
| 656 | qctrl->minimum = min; | 187 | qctrl->minimum = min; |
| 657 | qctrl->maximum = max; | 188 | qctrl->maximum = max; |
| 658 | qctrl->step = step; | 189 | qctrl->step = step; |
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c new file mode 100644 index 000000000000..8489894ee427 --- /dev/null +++ b/drivers/media/video/v4l2-ctrls.c | |||
| @@ -0,0 +1,1847 @@ | |||
| 1 | /* | ||
| 2 | V4L2 controls framework implementation. | ||
| 3 | |||
| 4 | Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl> | ||
| 5 | |||
| 6 | This program is free software; you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 2 of the License, or | ||
| 9 | (at your option) any later version. | ||
| 10 | |||
| 11 | This program is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with this program; if not, write to the Free Software | ||
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <linux/ctype.h> | ||
| 22 | #include <media/v4l2-ioctl.h> | ||
| 23 | #include <media/v4l2-device.h> | ||
| 24 | #include <media/v4l2-ctrls.h> | ||
| 25 | #include <media/v4l2-dev.h> | ||
| 26 | |||
| 27 | /* Internal temporary helper struct, one for each v4l2_ext_control */ | ||
| 28 | struct ctrl_helper { | ||
| 29 | /* The control corresponding to the v4l2_ext_control ID field. */ | ||
| 30 | struct v4l2_ctrl *ctrl; | ||
| 31 | /* Used internally to mark whether this control was already | ||
| 32 | processed. */ | ||
| 33 | bool handled; | ||
| 34 | }; | ||
| 35 | |||
| 36 | /* Returns NULL or a character pointer array containing the menu for | ||
| 37 | the given control ID. The pointer array ends with a NULL pointer. | ||
| 38 | An empty string signifies a menu entry that is invalid. This allows | ||
| 39 | drivers to disable certain options if it is not supported. */ | ||
| 40 | const char **v4l2_ctrl_get_menu(u32 id) | ||
| 41 | { | ||
| 42 | static const char *mpeg_audio_sampling_freq[] = { | ||
| 43 | "44.1 kHz", | ||
| 44 | "48 kHz", | ||
| 45 | "32 kHz", | ||
| 46 | NULL | ||
| 47 | }; | ||
| 48 | static const char *mpeg_audio_encoding[] = { | ||
| 49 | "MPEG-1/2 Layer I", | ||
| 50 | "MPEG-1/2 Layer II", | ||
| 51 | "MPEG-1/2 Layer III", | ||
| 52 | "MPEG-2/4 AAC", | ||
| 53 | "AC-3", | ||
| 54 | NULL | ||
| 55 | }; | ||
| 56 | static const char *mpeg_audio_l1_bitrate[] = { | ||
| 57 | "32 kbps", | ||
| 58 | "64 kbps", | ||
| 59 | "96 kbps", | ||
| 60 | "128 kbps", | ||
| 61 | "160 kbps", | ||
| 62 | "192 kbps", | ||
| 63 | "224 kbps", | ||
| 64 | "256 kbps", | ||
| 65 | "288 kbps", | ||
| 66 | "320 kbps", | ||
| 67 | "352 kbps", | ||
| 68 | "384 kbps", | ||
| 69 | "416 kbps", | ||
| 70 | "448 kbps", | ||
| 71 | NULL | ||
| 72 | }; | ||
| 73 | static const char *mpeg_audio_l2_bitrate[] = { | ||
| 74 | "32 kbps", | ||
| 75 | "48 kbps", | ||
| 76 | "56 kbps", | ||
| 77 | "64 kbps", | ||
| 78 | "80 kbps", | ||
| 79 | "96 kbps", | ||
| 80 | "112 kbps", | ||
| 81 | "128 kbps", | ||
| 82 | "160 kbps", | ||
| 83 | "192 kbps", | ||
| 84 | "224 kbps", | ||
| 85 | "256 kbps", | ||
| 86 | "320 kbps", | ||
| 87 | "384 kbps", | ||
| 88 | NULL | ||
| 89 | }; | ||
| 90 | static const char *mpeg_audio_l3_bitrate[] = { | ||
| 91 | "32 kbps", | ||
| 92 | "40 kbps", | ||
| 93 | "48 kbps", | ||
| 94 | "56 kbps", | ||
| 95 | "64 kbps", | ||
| 96 | "80 kbps", | ||
| 97 | "96 kbps", | ||
| 98 | "112 kbps", | ||
| 99 | "128 kbps", | ||
| 100 | "160 kbps", | ||
| 101 | "192 kbps", | ||
| 102 | "224 kbps", | ||
| 103 | "256 kbps", | ||
| 104 | "320 kbps", | ||
| 105 | NULL | ||
| 106 | }; | ||
| 107 | static const char *mpeg_audio_ac3_bitrate[] = { | ||
| 108 | "32 kbps", | ||
| 109 | "40 kbps", | ||
| 110 | "48 kbps", | ||
| 111 | "56 kbps", | ||
| 112 | "64 kbps", | ||
| 113 | "80 kbps", | ||
| 114 | "96 kbps", | ||
| 115 | "112 kbps", | ||
| 116 | "128 kbps", | ||
| 117 | "160 kbps", | ||
| 118 | "192 kbps", | ||
| 119 | "224 kbps", | ||
| 120 | "256 kbps", | ||
| 121 | "320 kbps", | ||
| 122 | "384 kbps", | ||
| 123 | "448 kbps", | ||
| 124 | "512 kbps", | ||
| 125 | "576 kbps", | ||
| 126 | "640 kbps", | ||
| 127 | NULL | ||
| 128 | }; | ||
| 129 | static const char *mpeg_audio_mode[] = { | ||
| 130 | "Stereo", | ||
| 131 | "Joint Stereo", | ||
| 132 | "Dual", | ||
| 133 | "Mono", | ||
| 134 | NULL | ||
| 135 | }; | ||
| 136 | static const char *mpeg_audio_mode_extension[] = { | ||
| 137 | "Bound 4", | ||
| 138 | "Bound 8", | ||
| 139 | "Bound 12", | ||
| 140 | "Bound 16", | ||
| 141 | NULL | ||
| 142 | }; | ||
| 143 | static const char *mpeg_audio_emphasis[] = { | ||
| 144 | "No Emphasis", | ||
| 145 | "50/15 us", | ||
| 146 | "CCITT J17", | ||
| 147 | NULL | ||
| 148 | }; | ||
| 149 | static const char *mpeg_audio_crc[] = { | ||
| 150 | "No CRC", | ||
| 151 | "16-bit CRC", | ||
| 152 | NULL | ||
| 153 | }; | ||
| 154 | static const char *mpeg_video_encoding[] = { | ||
| 155 | "MPEG-1", | ||
| 156 | "MPEG-2", | ||
| 157 | "MPEG-4 AVC", | ||
| 158 | NULL | ||
| 159 | }; | ||
| 160 | static const char *mpeg_video_aspect[] = { | ||
| 161 | "1x1", | ||
| 162 | "4x3", | ||
| 163 | "16x9", | ||
| 164 | "2.21x1", | ||
| 165 | NULL | ||
| 166 | }; | ||
| 167 | static const char *mpeg_video_bitrate_mode[] = { | ||
| 168 | "Variable Bitrate", | ||
| 169 | "Constant Bitrate", | ||
| 170 | NULL | ||
| 171 | }; | ||
| 172 | static const char *mpeg_stream_type[] = { | ||
| 173 | "MPEG-2 Program Stream", | ||
| 174 | "MPEG-2 Transport Stream", | ||
| 175 | "MPEG-1 System Stream", | ||
| 176 | "MPEG-2 DVD-compatible Stream", | ||
| 177 | "MPEG-1 VCD-compatible Stream", | ||
| 178 | "MPEG-2 SVCD-compatible Stream", | ||
| 179 | NULL | ||
| 180 | }; | ||
| 181 | static const char *mpeg_stream_vbi_fmt[] = { | ||
| 182 | "No VBI", | ||
| 183 | "Private packet, IVTV format", | ||
| 184 | NULL | ||
| 185 | }; | ||
| 186 | static const char *camera_power_line_frequency[] = { | ||
| 187 | "Disabled", | ||
| 188 | "50 Hz", | ||
| 189 | "60 Hz", | ||
| 190 | NULL | ||
| 191 | }; | ||
| 192 | static const char *camera_exposure_auto[] = { | ||
| 193 | "Auto Mode", | ||
| 194 | "Manual Mode", | ||
| 195 | "Shutter Priority Mode", | ||
| 196 | "Aperture Priority Mode", | ||
| 197 | NULL | ||
| 198 | }; | ||
| 199 | static const char *colorfx[] = { | ||
| 200 | "None", | ||
| 201 | "Black & White", | ||
| 202 | "Sepia", | ||
| 203 | "Negative", | ||
| 204 | "Emboss", | ||
| 205 | "Sketch", | ||
| 206 | "Sky blue", | ||
| 207 | "Grass green", | ||
| 208 | "Skin whiten", | ||
| 209 | "Vivid", | ||
| 210 | NULL | ||
| 211 | }; | ||
| 212 | static const char *tune_preemphasis[] = { | ||
| 213 | "No preemphasis", | ||
| 214 | "50 useconds", | ||
| 215 | "75 useconds", | ||
| 216 | NULL, | ||
| 217 | }; | ||
| 218 | |||
| 219 | switch (id) { | ||
| 220 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: | ||
| 221 | return mpeg_audio_sampling_freq; | ||
| 222 | case V4L2_CID_MPEG_AUDIO_ENCODING: | ||
| 223 | return mpeg_audio_encoding; | ||
| 224 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: | ||
| 225 | return mpeg_audio_l1_bitrate; | ||
| 226 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: | ||
| 227 | return mpeg_audio_l2_bitrate; | ||
| 228 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: | ||
| 229 | return mpeg_audio_l3_bitrate; | ||
| 230 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: | ||
| 231 | return mpeg_audio_ac3_bitrate; | ||
| 232 | case V4L2_CID_MPEG_AUDIO_MODE: | ||
| 233 | return mpeg_audio_mode; | ||
| 234 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: | ||
| 235 | return mpeg_audio_mode_extension; | ||
| 236 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: | ||
| 237 | return mpeg_audio_emphasis; | ||
| 238 | case V4L2_CID_MPEG_AUDIO_CRC: | ||
| 239 | return mpeg_audio_crc; | ||
| 240 | case V4L2_CID_MPEG_VIDEO_ENCODING: | ||
| 241 | return mpeg_video_encoding; | ||
| 242 | case V4L2_CID_MPEG_VIDEO_ASPECT: | ||
| 243 | return mpeg_video_aspect; | ||
| 244 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: | ||
| 245 | return mpeg_video_bitrate_mode; | ||
| 246 | case V4L2_CID_MPEG_STREAM_TYPE: | ||
| 247 | return mpeg_stream_type; | ||
| 248 | case V4L2_CID_MPEG_STREAM_VBI_FMT: | ||
| 249 | return mpeg_stream_vbi_fmt; | ||
| 250 | case V4L2_CID_POWER_LINE_FREQUENCY: | ||
| 251 | return camera_power_line_frequency; | ||
| 252 | case V4L2_CID_EXPOSURE_AUTO: | ||
| 253 | return camera_exposure_auto; | ||
| 254 | case V4L2_CID_COLORFX: | ||
| 255 | return colorfx; | ||
| 256 | case V4L2_CID_TUNE_PREEMPHASIS: | ||
| 257 | return tune_preemphasis; | ||
| 258 | default: | ||
| 259 | return NULL; | ||
| 260 | } | ||
| 261 | } | ||
| 262 | EXPORT_SYMBOL(v4l2_ctrl_get_menu); | ||
| 263 | |||
| 264 | /* Return the control name. */ | ||
| 265 | const char *v4l2_ctrl_get_name(u32 id) | ||
| 266 | { | ||
| 267 | switch (id) { | ||
| 268 | /* USER controls */ | ||
| 269 | case V4L2_CID_USER_CLASS: return "User Controls"; | ||
| 270 | case V4L2_CID_BRIGHTNESS: return "Brightness"; | ||
| 271 | case V4L2_CID_CONTRAST: return "Contrast"; | ||
| 272 | case V4L2_CID_SATURATION: return "Saturation"; | ||
| 273 | case V4L2_CID_HUE: return "Hue"; | ||
| 274 | case V4L2_CID_AUDIO_VOLUME: return "Volume"; | ||
| 275 | case V4L2_CID_AUDIO_BALANCE: return "Balance"; | ||
| 276 | case V4L2_CID_AUDIO_BASS: return "Bass"; | ||
| 277 | case V4L2_CID_AUDIO_TREBLE: return "Treble"; | ||
| 278 | case V4L2_CID_AUDIO_MUTE: return "Mute"; | ||
| 279 | case V4L2_CID_AUDIO_LOUDNESS: return "Loudness"; | ||
| 280 | case V4L2_CID_BLACK_LEVEL: return "Black Level"; | ||
| 281 | case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic"; | ||
| 282 | case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance"; | ||
| 283 | case V4L2_CID_RED_BALANCE: return "Red Balance"; | ||
| 284 | case V4L2_CID_BLUE_BALANCE: return "Blue Balance"; | ||
| 285 | case V4L2_CID_GAMMA: return "Gamma"; | ||
| 286 | case V4L2_CID_EXPOSURE: return "Exposure"; | ||
| 287 | case V4L2_CID_AUTOGAIN: return "Gain, Automatic"; | ||
| 288 | case V4L2_CID_GAIN: return "Gain"; | ||
| 289 | case V4L2_CID_HFLIP: return "Horizontal Flip"; | ||
| 290 | case V4L2_CID_VFLIP: return "Vertical Flip"; | ||
| 291 | case V4L2_CID_HCENTER: return "Horizontal Center"; | ||
| 292 | case V4L2_CID_VCENTER: return "Vertical Center"; | ||
| 293 | case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency"; | ||
| 294 | case V4L2_CID_HUE_AUTO: return "Hue, Automatic"; | ||
| 295 | case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature"; | ||
| 296 | case V4L2_CID_SHARPNESS: return "Sharpness"; | ||
| 297 | case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation"; | ||
| 298 | case V4L2_CID_CHROMA_AGC: return "Chroma AGC"; | ||
| 299 | case V4L2_CID_CHROMA_GAIN: return "Chroma Gain"; | ||
| 300 | case V4L2_CID_COLOR_KILLER: return "Color Killer"; | ||
| 301 | case V4L2_CID_COLORFX: return "Color Effects"; | ||
| 302 | case V4L2_CID_AUTOBRIGHTNESS: return "Brightness, Automatic"; | ||
| 303 | case V4L2_CID_BAND_STOP_FILTER: return "Band-Stop Filter"; | ||
| 304 | case V4L2_CID_ROTATE: return "Rotate"; | ||
| 305 | case V4L2_CID_BG_COLOR: return "Background Color"; | ||
| 306 | |||
| 307 | /* MPEG controls */ | ||
| 308 | case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls"; | ||
| 309 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency"; | ||
| 310 | case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding"; | ||
| 311 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate"; | ||
| 312 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate"; | ||
| 313 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate"; | ||
| 314 | case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate"; | ||
| 315 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate"; | ||
| 316 | case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode"; | ||
| 317 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension"; | ||
| 318 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis"; | ||
| 319 | case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC"; | ||
| 320 | case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute"; | ||
| 321 | case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding"; | ||
| 322 | case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect"; | ||
| 323 | case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames"; | ||
| 324 | case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size"; | ||
| 325 | case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure"; | ||
| 326 | case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown"; | ||
| 327 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode"; | ||
| 328 | case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate"; | ||
| 329 | case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate"; | ||
| 330 | case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation"; | ||
| 331 | case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute"; | ||
| 332 | case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV"; | ||
| 333 | case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type"; | ||
| 334 | case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID"; | ||
| 335 | case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID"; | ||
| 336 | case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID"; | ||
| 337 | case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID"; | ||
| 338 | case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID"; | ||
| 339 | case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID"; | ||
| 340 | case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format"; | ||
| 341 | |||
| 342 | /* CAMERA controls */ | ||
| 343 | case V4L2_CID_CAMERA_CLASS: return "Camera Controls"; | ||
| 344 | case V4L2_CID_EXPOSURE_AUTO: return "Auto Exposure"; | ||
| 345 | case V4L2_CID_EXPOSURE_ABSOLUTE: return "Exposure Time, Absolute"; | ||
| 346 | case V4L2_CID_EXPOSURE_AUTO_PRIORITY: return "Exposure, Dynamic Framerate"; | ||
| 347 | case V4L2_CID_PAN_RELATIVE: return "Pan, Relative"; | ||
| 348 | case V4L2_CID_TILT_RELATIVE: return "Tilt, Relative"; | ||
| 349 | case V4L2_CID_PAN_RESET: return "Pan, Reset"; | ||
| 350 | case V4L2_CID_TILT_RESET: return "Tilt, Reset"; | ||
| 351 | case V4L2_CID_PAN_ABSOLUTE: return "Pan, Absolute"; | ||
| 352 | case V4L2_CID_TILT_ABSOLUTE: return "Tilt, Absolute"; | ||
| 353 | case V4L2_CID_FOCUS_ABSOLUTE: return "Focus, Absolute"; | ||
| 354 | case V4L2_CID_FOCUS_RELATIVE: return "Focus, Relative"; | ||
| 355 | case V4L2_CID_FOCUS_AUTO: return "Focus, Automatic"; | ||
| 356 | case V4L2_CID_IRIS_ABSOLUTE: return "Iris, Absolute"; | ||
| 357 | case V4L2_CID_IRIS_RELATIVE: return "Iris, Relative"; | ||
| 358 | case V4L2_CID_ZOOM_ABSOLUTE: return "Zoom, Absolute"; | ||
| 359 | case V4L2_CID_ZOOM_RELATIVE: return "Zoom, Relative"; | ||
| 360 | case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous"; | ||
| 361 | case V4L2_CID_PRIVACY: return "Privacy"; | ||
| 362 | |||
| 363 | /* FM Radio Modulator control */ | ||
| 364 | case V4L2_CID_FM_TX_CLASS: return "FM Radio Modulator Controls"; | ||
| 365 | case V4L2_CID_RDS_TX_DEVIATION: return "RDS Signal Deviation"; | ||
| 366 | case V4L2_CID_RDS_TX_PI: return "RDS Program ID"; | ||
| 367 | case V4L2_CID_RDS_TX_PTY: return "RDS Program Type"; | ||
| 368 | case V4L2_CID_RDS_TX_PS_NAME: return "RDS PS Name"; | ||
| 369 | case V4L2_CID_RDS_TX_RADIO_TEXT: return "RDS Radio Text"; | ||
| 370 | case V4L2_CID_AUDIO_LIMITER_ENABLED: return "Audio Limiter Feature Enabled"; | ||
| 371 | case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: return "Audio Limiter Release Time"; | ||
| 372 | case V4L2_CID_AUDIO_LIMITER_DEVIATION: return "Audio Limiter Deviation"; | ||
| 373 | case V4L2_CID_AUDIO_COMPRESSION_ENABLED: return "Audio Compression Feature Enabled"; | ||
| 374 | case V4L2_CID_AUDIO_COMPRESSION_GAIN: return "Audio Compression Gain"; | ||
| 375 | case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: return "Audio Compression Threshold"; | ||
| 376 | case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: return "Audio Compression Attack Time"; | ||
| 377 | case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: return "Audio Compression Release Time"; | ||
| 378 | case V4L2_CID_PILOT_TONE_ENABLED: return "Pilot Tone Feature Enabled"; | ||
| 379 | case V4L2_CID_PILOT_TONE_DEVIATION: return "Pilot Tone Deviation"; | ||
| 380 | case V4L2_CID_PILOT_TONE_FREQUENCY: return "Pilot Tone Frequency"; | ||
| 381 | case V4L2_CID_TUNE_PREEMPHASIS: return "Pre-emphasis settings"; | ||
| 382 | case V4L2_CID_TUNE_POWER_LEVEL: return "Tune Power Level"; | ||
| 383 | case V4L2_CID_TUNE_ANTENNA_CAPACITOR: return "Tune Antenna Capacitor"; | ||
| 384 | |||
| 385 | default: | ||
| 386 | return NULL; | ||
| 387 | } | ||
| 388 | } | ||
| 389 | EXPORT_SYMBOL(v4l2_ctrl_get_name); | ||
| 390 | |||
| 391 | void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, | ||
| 392 | s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags) | ||
| 393 | { | ||
| 394 | *name = v4l2_ctrl_get_name(id); | ||
| 395 | *flags = 0; | ||
| 396 | |||
| 397 | switch (id) { | ||
| 398 | case V4L2_CID_AUDIO_MUTE: | ||
| 399 | case V4L2_CID_AUDIO_LOUDNESS: | ||
| 400 | case V4L2_CID_AUTO_WHITE_BALANCE: | ||
| 401 | case V4L2_CID_AUTOGAIN: | ||
| 402 | case V4L2_CID_HFLIP: | ||
| 403 | case V4L2_CID_VFLIP: | ||
| 404 | case V4L2_CID_HUE_AUTO: | ||
| 405 | case V4L2_CID_CHROMA_AGC: | ||
| 406 | case V4L2_CID_COLOR_KILLER: | ||
| 407 | case V4L2_CID_MPEG_AUDIO_MUTE: | ||
| 408 | case V4L2_CID_MPEG_VIDEO_MUTE: | ||
| 409 | case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: | ||
| 410 | case V4L2_CID_MPEG_VIDEO_PULLDOWN: | ||
| 411 | case V4L2_CID_EXPOSURE_AUTO_PRIORITY: | ||
| 412 | case V4L2_CID_FOCUS_AUTO: | ||
| 413 | case V4L2_CID_PRIVACY: | ||
| 414 | case V4L2_CID_AUDIO_LIMITER_ENABLED: | ||
| 415 | case V4L2_CID_AUDIO_COMPRESSION_ENABLED: | ||
| 416 | case V4L2_CID_PILOT_TONE_ENABLED: | ||
| 417 | *type = V4L2_CTRL_TYPE_BOOLEAN; | ||
| 418 | *min = 0; | ||
| 419 | *max = *step = 1; | ||
| 420 | break; | ||
| 421 | case V4L2_CID_PAN_RESET: | ||
| 422 | case V4L2_CID_TILT_RESET: | ||
| 423 | *type = V4L2_CTRL_TYPE_BUTTON; | ||
| 424 | *flags |= V4L2_CTRL_FLAG_WRITE_ONLY; | ||
| 425 | *min = *max = *step = *def = 0; | ||
| 426 | break; | ||
| 427 | case V4L2_CID_POWER_LINE_FREQUENCY: | ||
| 428 | case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: | ||
| 429 | case V4L2_CID_MPEG_AUDIO_ENCODING: | ||
| 430 | case V4L2_CID_MPEG_AUDIO_L1_BITRATE: | ||
| 431 | case V4L2_CID_MPEG_AUDIO_L2_BITRATE: | ||
| 432 | case V4L2_CID_MPEG_AUDIO_L3_BITRATE: | ||
| 433 | case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: | ||
| 434 | case V4L2_CID_MPEG_AUDIO_MODE: | ||
| 435 | case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: | ||
| 436 | case V4L2_CID_MPEG_AUDIO_EMPHASIS: | ||
| 437 | case V4L2_CID_MPEG_AUDIO_CRC: | ||
| 438 | case V4L2_CID_MPEG_VIDEO_ENCODING: | ||
| 439 | case V4L2_CID_MPEG_VIDEO_ASPECT: | ||
| 440 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: | ||
| 441 | case V4L2_CID_MPEG_STREAM_TYPE: | ||
| 442 | case V4L2_CID_MPEG_STREAM_VBI_FMT: | ||
| 443 | case V4L2_CID_EXPOSURE_AUTO: | ||
| 444 | case V4L2_CID_COLORFX: | ||
| 445 | case V4L2_CID_TUNE_PREEMPHASIS: | ||
| 446 | *type = V4L2_CTRL_TYPE_MENU; | ||
| 447 | break; | ||
| 448 | case V4L2_CID_RDS_TX_PS_NAME: | ||
| 449 | case V4L2_CID_RDS_TX_RADIO_TEXT: | ||
| 450 | *type = V4L2_CTRL_TYPE_STRING; | ||
| 451 | break; | ||
| 452 | case V4L2_CID_USER_CLASS: | ||
| 453 | case V4L2_CID_CAMERA_CLASS: | ||
| 454 | case V4L2_CID_MPEG_CLASS: | ||
| 455 | case V4L2_CID_FM_TX_CLASS: | ||
| 456 | *type = V4L2_CTRL_TYPE_CTRL_CLASS; | ||
| 457 | /* You can neither read not write these */ | ||
| 458 | *flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY; | ||
| 459 | *min = *max = *step = *def = 0; | ||
| 460 | break; | ||
| 461 | case V4L2_CID_BG_COLOR: | ||
| 462 | *type = V4L2_CTRL_TYPE_INTEGER; | ||
| 463 | *step = 1; | ||
| 464 | *min = 0; | ||
| 465 | /* Max is calculated as RGB888 that is 2^24 */ | ||
| 466 | *max = 0xFFFFFF; | ||
| 467 | break; | ||
| 468 | default: | ||
| 469 | *type = V4L2_CTRL_TYPE_INTEGER; | ||
| 470 | break; | ||
| 471 | } | ||
| 472 | switch (id) { | ||
| 473 | case V4L2_CID_MPEG_AUDIO_ENCODING: | ||
| 474 | case V4L2_CID_MPEG_AUDIO_MODE: | ||
| 475 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: | ||
| 476 | case V4L2_CID_MPEG_VIDEO_B_FRAMES: | ||
| 477 | case V4L2_CID_MPEG_STREAM_TYPE: | ||
| 478 | *flags |= V4L2_CTRL_FLAG_UPDATE; | ||
| 479 | break; | ||
| 480 | case V4L2_CID_AUDIO_VOLUME: | ||
| 481 | case V4L2_CID_AUDIO_BALANCE: | ||
| 482 | case V4L2_CID_AUDIO_BASS: | ||
| 483 | case V4L2_CID_AUDIO_TREBLE: | ||
| 484 | case V4L2_CID_BRIGHTNESS: | ||
| 485 | case V4L2_CID_CONTRAST: | ||
| 486 | case V4L2_CID_SATURATION: | ||
| 487 | case V4L2_CID_HUE: | ||
| 488 | case V4L2_CID_RED_BALANCE: | ||
| 489 | case V4L2_CID_BLUE_BALANCE: | ||
| 490 | case V4L2_CID_GAMMA: | ||
| 491 | case V4L2_CID_SHARPNESS: | ||
| 492 | case V4L2_CID_CHROMA_GAIN: | ||
| 493 | case V4L2_CID_RDS_TX_DEVIATION: | ||
| 494 | case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: | ||
| 495 | case V4L2_CID_AUDIO_LIMITER_DEVIATION: | ||
| 496 | case V4L2_CID_AUDIO_COMPRESSION_GAIN: | ||
| 497 | case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: | ||
| 498 | case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: | ||
| 499 | case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: | ||
| 500 | case V4L2_CID_PILOT_TONE_DEVIATION: | ||
| 501 | case V4L2_CID_PILOT_TONE_FREQUENCY: | ||
| 502 | case V4L2_CID_TUNE_POWER_LEVEL: | ||
| 503 | case V4L2_CID_TUNE_ANTENNA_CAPACITOR: | ||
| 504 | *flags |= V4L2_CTRL_FLAG_SLIDER; | ||
| 505 | break; | ||
| 506 | case V4L2_CID_PAN_RELATIVE: | ||
| 507 | case V4L2_CID_TILT_RELATIVE: | ||
| 508 | case V4L2_CID_FOCUS_RELATIVE: | ||
| 509 | case V4L2_CID_IRIS_RELATIVE: | ||
| 510 | case V4L2_CID_ZOOM_RELATIVE: | ||
| 511 | *flags |= V4L2_CTRL_FLAG_WRITE_ONLY; | ||
| 512 | break; | ||
| 513 | } | ||
| 514 | } | ||
| 515 | EXPORT_SYMBOL(v4l2_ctrl_fill); | ||
| 516 | |||
| 517 | /* Helper function to determine whether the control type is compatible with | ||
| 518 | VIDIOC_G/S_CTRL. */ | ||
| 519 | static bool type_is_int(const struct v4l2_ctrl *ctrl) | ||
| 520 | { | ||
| 521 | switch (ctrl->type) { | ||
| 522 | case V4L2_CTRL_TYPE_INTEGER64: | ||
| 523 | case V4L2_CTRL_TYPE_STRING: | ||
| 524 | /* Nope, these need v4l2_ext_control */ | ||
| 525 | return false; | ||
| 526 | default: | ||
| 527 | return true; | ||
| 528 | } | ||
| 529 | } | ||
| 530 | |||
| 531 | /* Helper function: copy the current control value back to the caller */ | ||
| 532 | static int cur_to_user(struct v4l2_ext_control *c, | ||
| 533 | struct v4l2_ctrl *ctrl) | ||
| 534 | { | ||
| 535 | u32 len; | ||
| 536 | |||
| 537 | switch (ctrl->type) { | ||
| 538 | case V4L2_CTRL_TYPE_STRING: | ||
| 539 | len = strlen(ctrl->cur.string); | ||
| 540 | if (c->size < len + 1) { | ||
| 541 | c->size = len + 1; | ||
| 542 | return -ENOSPC; | ||
| 543 | } | ||
| 544 | return copy_to_user(c->string, ctrl->cur.string, | ||
| 545 | len + 1) ? -EFAULT : 0; | ||
| 546 | case V4L2_CTRL_TYPE_INTEGER64: | ||
| 547 | c->value64 = ctrl->cur.val64; | ||
| 548 | break; | ||
| 549 | default: | ||
| 550 | c->value = ctrl->cur.val; | ||
| 551 | break; | ||
| 552 | } | ||
| 553 | return 0; | ||
| 554 | } | ||
| 555 | |||
| 556 | /* Helper function: copy the caller-provider value as the new control value */ | ||
| 557 | static int user_to_new(struct v4l2_ext_control *c, | ||
| 558 | struct v4l2_ctrl *ctrl) | ||
| 559 | { | ||
| 560 | int ret; | ||
| 561 | u32 size; | ||
| 562 | |||
| 563 | ctrl->has_new = 1; | ||
| 564 | switch (ctrl->type) { | ||
| 565 | case V4L2_CTRL_TYPE_INTEGER64: | ||
| 566 | ctrl->val64 = c->value64; | ||
| 567 | break; | ||
| 568 | case V4L2_CTRL_TYPE_STRING: | ||
| 569 | size = c->size; | ||
| 570 | if (size == 0) | ||
| 571 | return -ERANGE; | ||
| 572 | if (size > ctrl->maximum + 1) | ||
| 573 | size = ctrl->maximum + 1; | ||
| 574 | ret = copy_from_user(ctrl->string, c->string, size); | ||
| 575 | if (!ret) { | ||
| 576 | char last = ctrl->string[size - 1]; | ||
| 577 | |||
| 578 | ctrl->string[size - 1] = 0; | ||
| 579 | /* If the string was longer than ctrl->maximum, | ||
| 580 | then return an error. */ | ||
| 581 | if (strlen(ctrl->string) == ctrl->maximum && last) | ||
| 582 | return -ERANGE; | ||
| 583 | } | ||
| 584 | return ret ? -EFAULT : 0; | ||
| 585 | default: | ||
| 586 | ctrl->val = c->value; | ||
| 587 | break; | ||
| 588 | } | ||
| 589 | return 0; | ||
| 590 | } | ||
| 591 | |||
| 592 | /* Helper function: copy the new control value back to the caller */ | ||
| 593 | static int new_to_user(struct v4l2_ext_control *c, | ||
| 594 | struct v4l2_ctrl *ctrl) | ||
| 595 | { | ||
| 596 | u32 len; | ||
| 597 | |||
| 598 | switch (ctrl->type) { | ||
| 599 | case V4L2_CTRL_TYPE_STRING: | ||
| 600 | len = strlen(ctrl->string); | ||
| 601 | if (c->size < len + 1) { | ||
| 602 | c->size = ctrl->maximum + 1; | ||
| 603 | return -ENOSPC; | ||
| 604 | } | ||
| 605 | return copy_to_user(c->string, ctrl->string, | ||
| 606 | len + 1) ? -EFAULT : 0; | ||
| 607 | case V4L2_CTRL_TYPE_INTEGER64: | ||
| 608 | c->value64 = ctrl->val64; | ||
| 609 | break; | ||
| 610 | default: | ||
| 611 | c->value = ctrl->val; | ||
| 612 | break; | ||
| 613 | } | ||
| 614 | return 0; | ||
| 615 | } | ||
| 616 | |||
| 617 | /* Copy the new value to the current value. */ | ||
| 618 | static void new_to_cur(struct v4l2_ctrl *ctrl) | ||
| 619 | { | ||
| 620 | if (ctrl == NULL) | ||
| 621 | return; | ||
| 622 | switch (ctrl->type) { | ||
| 623 | case V4L2_CTRL_TYPE_STRING: | ||
| 624 | /* strings are always 0-terminated */ | ||
| 625 | strcpy(ctrl->cur.string, ctrl->string); | ||
| 626 | break; | ||
| 627 | case V4L2_CTRL_TYPE_INTEGER64: | ||
| 628 | ctrl->cur.val64 = ctrl->val64; | ||
| 629 | break; | ||
| 630 | default: | ||
| 631 | ctrl->cur.val = ctrl->val; | ||
| 632 | break; | ||
| 633 | } | ||
| 634 | } | ||
| 635 | |||
| 636 | /* Copy the current value to the new value */ | ||
| 637 | static void cur_to_new(struct v4l2_ctrl *ctrl) | ||
| 638 | { | ||
| 639 | if (ctrl == NULL) | ||
| 640 | return; | ||
| 641 | switch (ctrl->type) { | ||
| 642 | case V4L2_CTRL_TYPE_STRING: | ||
| 643 | /* strings are always 0-terminated */ | ||
| 644 | strcpy(ctrl->string, ctrl->cur.string); | ||
| 645 | break; | ||
| 646 | case V4L2_CTRL_TYPE_INTEGER64: | ||
| 647 | ctrl->val64 = ctrl->cur.val64; | ||
| 648 | break; | ||
| 649 | default: | ||
| 650 | ctrl->val = ctrl->cur.val; | ||
| 651 | break; | ||
| 652 | } | ||
| 653 | } | ||
| 654 | |||
| 655 | /* Return non-zero if one or more of the controls in the cluster has a new | ||
| 656 | value that differs from the current value. */ | ||
| 657 | static int cluster_changed(struct v4l2_ctrl *master) | ||
| 658 | { | ||
| 659 | int diff = 0; | ||
| 660 | int i; | ||
| 661 | |||
| 662 | for (i = 0; !diff && i < master->ncontrols; i++) { | ||
| 663 | struct v4l2_ctrl *ctrl = master->cluster[i]; | ||
| 664 | |||
| 665 | if (ctrl == NULL) | ||
| 666 | continue; | ||
| 667 | switch (ctrl->type) { | ||
| 668 | case V4L2_CTRL_TYPE_BUTTON: | ||
| 669 | /* Button controls are always 'different' */ | ||
| 670 | return 1; | ||
| 671 | case V4L2_CTRL_TYPE_STRING: | ||
| 672 | /* strings are always 0-terminated */ | ||
| 673 | diff = strcmp(ctrl->string, ctrl->cur.string); | ||
| 674 | break; | ||
| 675 | case V4L2_CTRL_TYPE_INTEGER64: | ||
| 676 | diff = ctrl->val64 != ctrl->cur.val64; | ||
| 677 | break; | ||
| 678 | default: | ||
| 679 | diff = ctrl->val != ctrl->cur.val; | ||
| 680 | break; | ||
| 681 | } | ||
| 682 | } | ||
| 683 | return diff; | ||
| 684 | } | ||
| 685 | |||
| 686 | /* Validate a new control */ | ||
| 687 | static int validate_new(struct v4l2_ctrl *ctrl) | ||
| 688 | { | ||
| 689 | s32 val = ctrl->val; | ||
| 690 | char *s = ctrl->string; | ||
| 691 | u32 offset; | ||
| 692 | size_t len; | ||
| 693 | |||
| 694 | switch (ctrl->type) { | ||
| 695 | case V4L2_CTRL_TYPE_INTEGER: | ||
| 696 | /* Round towards the closest legal value */ | ||
| 697 | val += ctrl->step / 2; | ||
| 698 | if (val < ctrl->minimum) | ||
| 699 | val = ctrl->minimum; | ||
| 700 | if (val > ctrl->maximum) | ||
| 701 | val = ctrl->maximum; | ||
| 702 | offset = val - ctrl->minimum; | ||
| 703 | offset = ctrl->step * (offset / ctrl->step); | ||
| 704 | val = ctrl->minimum + offset; | ||
| 705 | ctrl->val = val; | ||
| 706 | return 0; | ||
| 707 | |||
| 708 | case V4L2_CTRL_TYPE_BOOLEAN: | ||
| 709 | ctrl->val = !!ctrl->val; | ||
| 710 | return 0; | ||
| 711 | |||
| 712 | case V4L2_CTRL_TYPE_MENU: | ||
| 713 | if (val < ctrl->minimum || val > ctrl->maximum) | ||
| 714 | return -ERANGE; | ||
| 715 | if (ctrl->qmenu[val][0] == '\0' || | ||
| 716 | (ctrl->menu_skip_mask & (1 << val))) | ||
| 717 | return -EINVAL; | ||
| 718 | return 0; | ||
| 719 | |||
| 720 | case V4L2_CTRL_TYPE_BUTTON: | ||
| 721 | case V4L2_CTRL_TYPE_CTRL_CLASS: | ||
| 722 | ctrl->val64 = 0; | ||
| 723 | return 0; | ||
| 724 | |||
| 725 | case V4L2_CTRL_TYPE_INTEGER64: | ||
| 726 | return 0; | ||
| 727 | |||
| 728 | case V4L2_CTRL_TYPE_STRING: | ||
| 729 | len = strlen(s); | ||
| 730 | if (len < ctrl->minimum) | ||
| 731 | return -ERANGE; | ||
| 732 | if ((len - ctrl->minimum) % ctrl->step) | ||
| 733 | return -ERANGE; | ||
| 734 | return 0; | ||
| 735 | |||
| 736 | default: | ||
| 737 | return -EINVAL; | ||
| 738 | } | ||
| 739 | } | ||
| 740 | |||
| 741 | static inline u32 node2id(struct list_head *node) | ||
| 742 | { | ||
| 743 | return list_entry(node, struct v4l2_ctrl_ref, node)->ctrl->id; | ||
| 744 | } | ||
| 745 | |||
| 746 | /* Set the handler's error code if it wasn't set earlier already */ | ||
| 747 | static inline int handler_set_err(struct v4l2_ctrl_handler *hdl, int err) | ||
| 748 | { | ||
| 749 | if (hdl->error == 0) | ||
| 750 | hdl->error = err; | ||
| 751 | return err; | ||
| 752 | } | ||
| 753 | |||
| 754 | /* Initialize the handler */ | ||
| 755 | int v4l2_ctrl_handler_init(struct v4l2_ctrl_handler *hdl, | ||
| 756 | unsigned nr_of_controls_hint) | ||
| 757 | { | ||
| 758 | mutex_init(&hdl->lock); | ||
| 759 | INIT_LIST_HEAD(&hdl->ctrls); | ||
| 760 | INIT_LIST_HEAD(&hdl->ctrl_refs); | ||
| 761 | hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8; | ||
| 762 | hdl->buckets = kzalloc(sizeof(hdl->buckets[0]) * hdl->nr_of_buckets, | ||
| 763 | GFP_KERNEL); | ||
| 764 | hdl->error = hdl->buckets ? 0 : -ENOMEM; | ||
| 765 | return hdl->error; | ||
| 766 | } | ||
| 767 | EXPORT_SYMBOL(v4l2_ctrl_handler_init); | ||
| 768 | |||
| 769 | /* Free all controls and control refs */ | ||
| 770 | void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl) | ||
| 771 | { | ||
| 772 | struct v4l2_ctrl_ref *ref, *next_ref; | ||
| 773 | struct v4l2_ctrl *ctrl, *next_ctrl; | ||
| 774 | |||
| 775 | if (hdl == NULL || hdl->buckets == NULL) | ||
| 776 | return; | ||
| 777 | |||
| 778 | mutex_lock(&hdl->lock); | ||
| 779 | /* Free all nodes */ | ||
| 780 | list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) { | ||
| 781 | list_del(&ref->node); | ||
| 782 | kfree(ref); | ||
| 783 | } | ||
| 784 | /* Free all controls owned by the handler */ | ||
| 785 | list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) { | ||
| 786 | list_del(&ctrl->node); | ||
| 787 | kfree(ctrl); | ||
| 788 | } | ||
| 789 | kfree(hdl->buckets); | ||
| 790 | hdl->buckets = NULL; | ||
| 791 | hdl->cached = NULL; | ||
| 792 | hdl->error = 0; | ||
| 793 | mutex_unlock(&hdl->lock); | ||
| 794 | } | ||
| 795 | EXPORT_SYMBOL(v4l2_ctrl_handler_free); | ||
| 796 | |||
| 797 | /* For backwards compatibility: V4L2_CID_PRIVATE_BASE should no longer | ||
| 798 | be used except in G_CTRL, S_CTRL, QUERYCTRL and QUERYMENU when dealing | ||
| 799 | with applications that do not use the NEXT_CTRL flag. | ||
| 800 | |||
| 801 | We just find the n-th private user control. It's O(N), but that should not | ||
| 802 | be an issue in this particular case. */ | ||
| 803 | static struct v4l2_ctrl_ref *find_private_ref( | ||
| 804 | struct v4l2_ctrl_handler *hdl, u32 id) | ||
| 805 | { | ||
| 806 | struct v4l2_ctrl_ref *ref; | ||
| 807 | |||
| 808 | id -= V4L2_CID_PRIVATE_BASE; | ||
| 809 | list_for_each_entry(ref, &hdl->ctrl_refs, node) { | ||
| 810 | /* Search for private user controls that are compatible with | ||
| 811 | VIDIOC_G/S_CTRL. */ | ||
| 812 | if (V4L2_CTRL_ID2CLASS(ref->ctrl->id) == V4L2_CTRL_CLASS_USER && | ||
| 813 | V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) { | ||
| 814 | if (!type_is_int(ref->ctrl)) | ||
| 815 | continue; | ||
| 816 | if (id == 0) | ||
| 817 | return ref; | ||
| 818 | id--; | ||
| 819 | } | ||
| 820 | } | ||
| 821 | return NULL; | ||
| 822 | } | ||
| 823 | |||
| 824 | /* Find a control with the given ID. */ | ||
| 825 | static struct v4l2_ctrl_ref *find_ref(struct v4l2_ctrl_handler *hdl, u32 id) | ||
| 826 | { | ||
| 827 | struct v4l2_ctrl_ref *ref; | ||
| 828 | int bucket; | ||
| 829 | |||
| 830 | id &= V4L2_CTRL_ID_MASK; | ||
| 831 | |||
| 832 | /* Old-style private controls need special handling */ | ||
| 833 | if (id >= V4L2_CID_PRIVATE_BASE) | ||
| 834 | return find_private_ref(hdl, id); | ||
| 835 | bucket = id % hdl->nr_of_buckets; | ||
| 836 | |||
| 837 | /* Simple optimization: cache the last control found */ | ||
| 838 | if (hdl->cached && hdl->cached->ctrl->id == id) | ||
| 839 | return hdl->cached; | ||
| 840 | |||
| 841 | /* Not in cache, search the hash */ | ||
| 842 | ref = hdl->buckets ? hdl->buckets[bucket] : NULL; | ||
| 843 | while (ref && ref->ctrl->id != id) | ||
| 844 | ref = ref->next; | ||
| 845 | |||
| 846 | if (ref) | ||
| 847 | hdl->cached = ref; /* cache it! */ | ||
| 848 | return ref; | ||
| 849 | } | ||
| 850 | |||
| 851 | /* Find a control with the given ID. Take the handler's lock first. */ | ||
| 852 | static struct v4l2_ctrl_ref *find_ref_lock( | ||
| 853 | struct v4l2_ctrl_handler *hdl, u32 id) | ||
| 854 | { | ||
| 855 | struct v4l2_ctrl_ref *ref = NULL; | ||
| 856 | |||
| 857 | if (hdl) { | ||
| 858 | mutex_lock(&hdl->lock); | ||
| 859 | ref = find_ref(hdl, id); | ||
| 860 | mutex_unlock(&hdl->lock); | ||
| 861 | } | ||
| 862 | return ref; | ||
| 863 | } | ||
| 864 | |||
| 865 | /* Find a control with the given ID. */ | ||
| 866 | struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id) | ||
| 867 | { | ||
| 868 | struct v4l2_ctrl_ref *ref = find_ref_lock(hdl, id); | ||
| 869 | |||
| 870 | return ref ? ref->ctrl : NULL; | ||
| 871 | } | ||
| 872 | EXPORT_SYMBOL(v4l2_ctrl_find); | ||
| 873 | |||
| 874 | /* Allocate a new v4l2_ctrl_ref and hook it into the handler. */ | ||
| 875 | static int handler_new_ref(struct v4l2_ctrl_handler *hdl, | ||
| 876 | struct v4l2_ctrl *ctrl) | ||
| 877 | { | ||
| 878 | struct v4l2_ctrl_ref *ref; | ||
| 879 | struct v4l2_ctrl_ref *new_ref; | ||
| 880 | u32 id = ctrl->id; | ||
| 881 | u32 class_ctrl = V4L2_CTRL_ID2CLASS(id) | 1; | ||
| 882 | int bucket = id % hdl->nr_of_buckets; /* which bucket to use */ | ||
| 883 | |||
| 884 | /* Automatically add the control class if it is not yet present. */ | ||
| 885 | if (id != class_ctrl && find_ref_lock(hdl, class_ctrl) == NULL) | ||
| 886 | if (!v4l2_ctrl_new_std(hdl, NULL, class_ctrl, 0, 0, 0, 0)) | ||
| 887 | return hdl->error; | ||
| 888 | |||
| 889 | if (hdl->error) | ||
| 890 | return hdl->error; | ||
| 891 | |||
| 892 | new_ref = kzalloc(sizeof(*new_ref), GFP_KERNEL); | ||
| 893 | if (!new_ref) | ||
| 894 | return handler_set_err(hdl, -ENOMEM); | ||
| 895 | new_ref->ctrl = ctrl; | ||
| 896 | if (ctrl->handler == hdl) { | ||
| 897 | /* By default each control starts in a cluster of its own. | ||
| 898 | new_ref->ctrl is basically a cluster array with one | ||
| 899 | element, so that's perfect to use as the cluster pointer. | ||
| 900 | But only do this for the handler that owns the control. */ | ||
| 901 | ctrl->cluster = &new_ref->ctrl; | ||
| 902 | ctrl->ncontrols = 1; | ||
| 903 | } | ||
| 904 | |||
| 905 | INIT_LIST_HEAD(&new_ref->node); | ||
| 906 | |||
| 907 | mutex_lock(&hdl->lock); | ||
| 908 | |||
| 909 | /* Add immediately at the end of the list if the list is empty, or if | ||
| 910 | the last element in the list has a lower ID. | ||
| 911 | This ensures that when elements are added in ascending order the | ||
| 912 | insertion is an O(1) operation. */ | ||
| 913 | if (list_empty(&hdl->ctrl_refs) || id > node2id(hdl->ctrl_refs.prev)) { | ||
| 914 | list_add_tail(&new_ref->node, &hdl->ctrl_refs); | ||
| 915 | goto insert_in_hash; | ||
| 916 | } | ||
| 917 | |||
| 918 | /* Find insert position in sorted list */ | ||
| 919 | list_for_each_entry(ref, &hdl->ctrl_refs, node) { | ||
| 920 | if (ref->ctrl->id < id) | ||
| 921 | continue; | ||
| 922 | /* Don't add duplicates */ | ||
| 923 | if (ref->ctrl->id == id) { | ||
| 924 | kfree(new_ref); | ||
| 925 | goto unlock; | ||
| 926 | } | ||
| 927 | list_add(&new_ref->node, ref->node.prev); | ||
| 928 | break; | ||
| 929 | } | ||
| 930 | |||
| 931 | insert_in_hash: | ||
| 932 | /* Insert the control node in the hash */ | ||
| 933 | new_ref->next = hdl->buckets[bucket]; | ||
| 934 | hdl->buckets[bucket] = new_ref; | ||
| 935 | |||
| 936 | unlock: | ||
| 937 | mutex_unlock(&hdl->lock); | ||
| 938 | return 0; | ||
| 939 | } | ||
| 940 | |||
| 941 | /* Add a new control */ | ||
| 942 | static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, | ||
| 943 | const struct v4l2_ctrl_ops *ops, | ||
| 944 | u32 id, const char *name, enum v4l2_ctrl_type type, | ||
| 945 | s32 min, s32 max, u32 step, s32 def, | ||
| 946 | u32 flags, const char **qmenu, void *priv) | ||
| 947 | { | ||
| 948 | struct v4l2_ctrl *ctrl; | ||
| 949 | unsigned sz_extra = 0; | ||
| 950 | |||
| 951 | if (hdl->error) | ||
| 952 | return NULL; | ||
| 953 | |||
| 954 | /* Sanity checks */ | ||
| 955 | if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE || | ||
| 956 | def < min || def > max || max < min || | ||
| 957 | (type == V4L2_CTRL_TYPE_INTEGER && step == 0) || | ||
| 958 | (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) || | ||
| 959 | (type == V4L2_CTRL_TYPE_STRING && max == 0)) { | ||
| 960 | handler_set_err(hdl, -ERANGE); | ||
| 961 | return NULL; | ||
| 962 | } | ||
| 963 | |||
| 964 | if (type == V4L2_CTRL_TYPE_BUTTON) | ||
| 965 | flags |= V4L2_CTRL_FLAG_WRITE_ONLY; | ||
| 966 | else if (type == V4L2_CTRL_TYPE_CTRL_CLASS) | ||
| 967 | flags |= V4L2_CTRL_FLAG_READ_ONLY; | ||
| 968 | else if (type == V4L2_CTRL_TYPE_STRING) | ||
| 969 | sz_extra += 2 * (max + 1); | ||
| 970 | |||
| 971 | ctrl = kzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL); | ||
| 972 | if (ctrl == NULL) { | ||
| 973 | handler_set_err(hdl, -ENOMEM); | ||
| 974 | return NULL; | ||
| 975 | } | ||
| 976 | |||
| 977 | INIT_LIST_HEAD(&ctrl->node); | ||
| 978 | ctrl->handler = hdl; | ||
| 979 | ctrl->ops = ops; | ||
| 980 | ctrl->id = id; | ||
| 981 | ctrl->name = name; | ||
| 982 | ctrl->type = type; | ||
| 983 | ctrl->flags = flags; | ||
| 984 | ctrl->minimum = min; | ||
| 985 | ctrl->maximum = max; | ||
| 986 | ctrl->step = step; | ||
| 987 | ctrl->qmenu = qmenu; | ||
| 988 | ctrl->priv = priv; | ||
| 989 | ctrl->cur.val = ctrl->val = ctrl->default_value = def; | ||
| 990 | |||
| 991 | if (ctrl->type == V4L2_CTRL_TYPE_STRING) { | ||
| 992 | ctrl->cur.string = (char *)&ctrl[1] + sz_extra - (max + 1); | ||
| 993 | ctrl->string = (char *)&ctrl[1] + sz_extra - 2 * (max + 1); | ||
| 994 | if (ctrl->minimum) | ||
| 995 | memset(ctrl->cur.string, ' ', ctrl->minimum); | ||
| 996 | } | ||
| 997 | if (handler_new_ref(hdl, ctrl)) { | ||
| 998 | kfree(ctrl); | ||
| 999 | return NULL; | ||
| 1000 | } | ||
| 1001 | mutex_lock(&hdl->lock); | ||
| 1002 | list_add_tail(&ctrl->node, &hdl->ctrls); | ||
| 1003 | mutex_unlock(&hdl->lock); | ||
| 1004 | return ctrl; | ||
| 1005 | } | ||
| 1006 | |||
| 1007 | struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, | ||
| 1008 | const struct v4l2_ctrl_config *cfg, void *priv) | ||
| 1009 | { | ||
| 1010 | bool is_menu; | ||
| 1011 | struct v4l2_ctrl *ctrl; | ||
| 1012 | const char *name = cfg->name; | ||
| 1013 | const char **qmenu = cfg->qmenu; | ||
| 1014 | enum v4l2_ctrl_type type = cfg->type; | ||
| 1015 | u32 flags = cfg->flags; | ||
| 1016 | s32 min = cfg->min; | ||
| 1017 | s32 max = cfg->max; | ||
| 1018 | u32 step = cfg->step; | ||
| 1019 | s32 def = cfg->def; | ||
| 1020 | |||
| 1021 | if (name == NULL) | ||
| 1022 | v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step, | ||
| 1023 | &def, &flags); | ||
| 1024 | |||
| 1025 | is_menu = (cfg->type == V4L2_CTRL_TYPE_MENU); | ||
| 1026 | if (is_menu) | ||
| 1027 | WARN_ON(step); | ||
| 1028 | else | ||
| 1029 | WARN_ON(cfg->menu_skip_mask); | ||
| 1030 | if (is_menu && qmenu == NULL) | ||
| 1031 | qmenu = v4l2_ctrl_get_menu(cfg->id); | ||
| 1032 | |||
| 1033 | ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->id, name, | ||
| 1034 | type, min, max, | ||
| 1035 | is_menu ? cfg->menu_skip_mask : step, | ||
| 1036 | def, flags, qmenu, priv); | ||
| 1037 | if (ctrl) { | ||
| 1038 | ctrl->is_private = cfg->is_private; | ||
| 1039 | ctrl->is_volatile = cfg->is_volatile; | ||
| 1040 | } | ||
| 1041 | return ctrl; | ||
| 1042 | } | ||
| 1043 | EXPORT_SYMBOL(v4l2_ctrl_new_custom); | ||
| 1044 | |||
| 1045 | /* Helper function for standard non-menu controls */ | ||
| 1046 | struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, | ||
| 1047 | const struct v4l2_ctrl_ops *ops, | ||
| 1048 | u32 id, s32 min, s32 max, u32 step, s32 def) | ||
| 1049 | { | ||
| 1050 | const char *name; | ||
| 1051 | enum v4l2_ctrl_type type; | ||
| 1052 | u32 flags; | ||
| 1053 | |||
| 1054 | v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags); | ||
| 1055 | if (type == V4L2_CTRL_TYPE_MENU) { | ||
| 1056 | handler_set_err(hdl, -EINVAL); | ||
| 1057 | return NULL; | ||
| 1058 | } | ||
| 1059 | return v4l2_ctrl_new(hdl, ops, id, name, type, | ||
| 1060 | min, max, step, def, flags, NULL, NULL); | ||
| 1061 | } | ||
| 1062 | EXPORT_SYMBOL(v4l2_ctrl_new_std); | ||
| 1063 | |||
| 1064 | /* Helper function for standard menu controls */ | ||
| 1065 | struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, | ||
| 1066 | const struct v4l2_ctrl_ops *ops, | ||
| 1067 | u32 id, s32 max, s32 mask, s32 def) | ||
| 1068 | { | ||
| 1069 | const char **qmenu = v4l2_ctrl_get_menu(id); | ||
| 1070 | const char *name; | ||
| 1071 | enum v4l2_ctrl_type type; | ||
| 1072 | s32 min; | ||
| 1073 | s32 step; | ||
| 1074 | u32 flags; | ||
| 1075 | |||
| 1076 | v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags); | ||
| 1077 | if (type != V4L2_CTRL_TYPE_MENU) { | ||
| 1078 | handler_set_err(hdl, -EINVAL); | ||
| 1079 | return NULL; | ||
| 1080 | } | ||
| 1081 | return v4l2_ctrl_new(hdl, ops, id, name, type, | ||
| 1082 | 0, max, mask, def, flags, qmenu, NULL); | ||
| 1083 | } | ||
| 1084 | EXPORT_SYMBOL(v4l2_ctrl_new_std_menu); | ||
| 1085 | |||
| 1086 | /* Add a control from another handler to this handler */ | ||
| 1087 | struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, | ||
| 1088 | struct v4l2_ctrl *ctrl) | ||
| 1089 | { | ||
| 1090 | if (hdl == NULL || hdl->error) | ||
| 1091 | return NULL; | ||
| 1092 | if (ctrl == NULL) { | ||
| 1093 | handler_set_err(hdl, -EINVAL); | ||
| 1094 | return NULL; | ||
| 1095 | } | ||
| 1096 | if (ctrl->handler == hdl) | ||
| 1097 | return ctrl; | ||
| 1098 | return handler_new_ref(hdl, ctrl) ? NULL : ctrl; | ||
| 1099 | } | ||
| 1100 | EXPORT_SYMBOL(v4l2_ctrl_add_ctrl); | ||
| 1101 | |||
| 1102 | /* Add the controls from another handler to our own. */ | ||
| 1103 | int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, | ||
| 1104 | struct v4l2_ctrl_handler *add) | ||
| 1105 | { | ||
| 1106 | struct v4l2_ctrl *ctrl; | ||
| 1107 | int ret = 0; | ||
| 1108 | |||
| 1109 | /* Do nothing if either handler is NULL or if they are the same */ | ||
| 1110 | if (!hdl || !add || hdl == add) | ||
| 1111 | return 0; | ||
| 1112 | if (hdl->error) | ||
| 1113 | return hdl->error; | ||
| 1114 | mutex_lock(&add->lock); | ||
| 1115 | list_for_each_entry(ctrl, &add->ctrls, node) { | ||
| 1116 | /* Skip handler-private controls. */ | ||
| 1117 | if (ctrl->is_private) | ||
| 1118 | continue; | ||
| 1119 | ret = handler_new_ref(hdl, ctrl); | ||
| 1120 | if (ret) | ||
| 1121 | break; | ||
| 1122 | } | ||
| 1123 | mutex_unlock(&add->lock); | ||
| 1124 | return ret; | ||
| 1125 | } | ||
| 1126 | EXPORT_SYMBOL(v4l2_ctrl_add_handler); | ||
| 1127 | |||
| 1128 | /* Cluster controls */ | ||
| 1129 | void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls) | ||
| 1130 | { | ||
| 1131 | int i; | ||
| 1132 | |||
| 1133 | /* The first control is the master control and it must not be NULL */ | ||
| 1134 | BUG_ON(controls[0] == NULL); | ||
| 1135 | |||
| 1136 | for (i = 0; i < ncontrols; i++) { | ||
| 1137 | if (controls[i]) { | ||
| 1138 | controls[i]->cluster = controls; | ||
| 1139 | controls[i]->ncontrols = ncontrols; | ||
| 1140 | } | ||
| 1141 | } | ||
| 1142 | } | ||
| 1143 | EXPORT_SYMBOL(v4l2_ctrl_cluster); | ||
| 1144 | |||
| 1145 | /* Activate/deactivate a control. */ | ||
| 1146 | void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active) | ||
| 1147 | { | ||
| 1148 | if (ctrl == NULL) | ||
| 1149 | return; | ||
| 1150 | |||
| 1151 | if (!active) | ||
| 1152 | /* set V4L2_CTRL_FLAG_INACTIVE */ | ||
| 1153 | set_bit(4, &ctrl->flags); | ||
| 1154 | else | ||
| 1155 | /* clear V4L2_CTRL_FLAG_INACTIVE */ | ||
| 1156 | clear_bit(4, &ctrl->flags); | ||
| 1157 | } | ||
| 1158 | EXPORT_SYMBOL(v4l2_ctrl_activate); | ||
| 1159 | |||
| 1160 | /* Grab/ungrab a control. | ||
| 1161 | Typically used when streaming starts and you want to grab controls, | ||
| 1162 | preventing the user from changing them. | ||
| 1163 | |||
| 1164 | Just call this and the framework will block any attempts to change | ||
| 1165 | these controls. */ | ||
| 1166 | void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed) | ||
| 1167 | { | ||
| 1168 | if (ctrl == NULL) | ||
| 1169 | return; | ||
| 1170 | |||
| 1171 | if (grabbed) | ||
| 1172 | /* set V4L2_CTRL_FLAG_GRABBED */ | ||
| 1173 | set_bit(1, &ctrl->flags); | ||
| 1174 | else | ||
| 1175 | /* clear V4L2_CTRL_FLAG_GRABBED */ | ||
| 1176 | clear_bit(1, &ctrl->flags); | ||
| 1177 | } | ||
| 1178 | EXPORT_SYMBOL(v4l2_ctrl_grab); | ||
| 1179 | |||
| 1180 | /* Log the control name and value */ | ||
| 1181 | static void log_ctrl(const struct v4l2_ctrl *ctrl, | ||
| 1182 | const char *prefix, const char *colon) | ||
| 1183 | { | ||
| 1184 | int fl_inact = ctrl->flags & V4L2_CTRL_FLAG_INACTIVE; | ||
| 1185 | int fl_grabbed = ctrl->flags & V4L2_CTRL_FLAG_GRABBED; | ||
| 1186 | |||
| 1187 | if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY)) | ||
| 1188 | return; | ||
| 1189 | if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) | ||
| 1190 | return; | ||
| 1191 | |||
| 1192 | printk(KERN_INFO "%s%s%s: ", prefix, colon, ctrl->name); | ||
| 1193 | |||
| 1194 | switch (ctrl->type) { | ||
| 1195 | case V4L2_CTRL_TYPE_INTEGER: | ||
| 1196 | printk(KERN_CONT "%d", ctrl->cur.val); | ||
| 1197 | break; | ||
| 1198 | case V4L2_CTRL_TYPE_BOOLEAN: | ||
| 1199 | printk(KERN_CONT "%s", ctrl->cur.val ? "true" : "false"); | ||
| 1200 | break; | ||
| 1201 | case V4L2_CTRL_TYPE_MENU: | ||
| 1202 | printk(KERN_CONT "%s", ctrl->qmenu[ctrl->cur.val]); | ||
| 1203 | break; | ||
| 1204 | case V4L2_CTRL_TYPE_INTEGER64: | ||
| 1205 | printk(KERN_CONT "%lld", ctrl->cur.val64); | ||
| 1206 | break; | ||
| 1207 | case V4L2_CTRL_TYPE_STRING: | ||
| 1208 | printk(KERN_CONT "%s", ctrl->cur.string); | ||
| 1209 | break; | ||
| 1210 | default: | ||
| 1211 | printk(KERN_CONT "unknown type %d", ctrl->type); | ||
| 1212 | break; | ||
| 1213 | } | ||
| 1214 | if (fl_inact && fl_grabbed) | ||
| 1215 | printk(KERN_CONT " (inactive, grabbed)\n"); | ||
| 1216 | else if (fl_inact) | ||
| 1217 | printk(KERN_CONT " (inactive)\n"); | ||
| 1218 | else if (fl_grabbed) | ||
| 1219 | printk(KERN_CONT " (grabbed)\n"); | ||
| 1220 | else | ||
| 1221 | printk(KERN_CONT "\n"); | ||
| 1222 | } | ||
| 1223 | |||
| 1224 | /* Log all controls owned by the handler */ | ||
| 1225 | void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, | ||
| 1226 | const char *prefix) | ||
| 1227 | { | ||
| 1228 | struct v4l2_ctrl *ctrl; | ||
| 1229 | const char *colon = ""; | ||
| 1230 | int len; | ||
| 1231 | |||
| 1232 | if (hdl == NULL) | ||
| 1233 | return; | ||
| 1234 | if (prefix == NULL) | ||
| 1235 | prefix = ""; | ||
| 1236 | len = strlen(prefix); | ||
| 1237 | if (len && prefix[len - 1] != ' ') | ||
| 1238 | colon = ": "; | ||
| 1239 | mutex_lock(&hdl->lock); | ||
| 1240 | list_for_each_entry(ctrl, &hdl->ctrls, node) | ||
| 1241 | if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED)) | ||
| 1242 | log_ctrl(ctrl, prefix, colon); | ||
| 1243 | mutex_unlock(&hdl->lock); | ||
| 1244 | } | ||
| 1245 | EXPORT_SYMBOL(v4l2_ctrl_handler_log_status); | ||
| 1246 | |||
| 1247 | /* Call s_ctrl for all controls owned by the handler */ | ||
| 1248 | int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl) | ||
| 1249 | { | ||
| 1250 | struct v4l2_ctrl *ctrl; | ||
| 1251 | int ret = 0; | ||
| 1252 | |||
| 1253 | if (hdl == NULL) | ||
| 1254 | return 0; | ||
| 1255 | mutex_lock(&hdl->lock); | ||
| 1256 | list_for_each_entry(ctrl, &hdl->ctrls, node) | ||
| 1257 | ctrl->done = false; | ||
| 1258 | |||
| 1259 | list_for_each_entry(ctrl, &hdl->ctrls, node) { | ||
| 1260 | struct v4l2_ctrl *master = ctrl->cluster[0]; | ||
| 1261 | int i; | ||
| 1262 | |||
| 1263 | /* Skip if this control was already handled by a cluster. */ | ||
| 1264 | if (ctrl->done) | ||
| 1265 | continue; | ||
| 1266 | |||
| 1267 | for (i = 0; i < master->ncontrols; i++) | ||
| 1268 | cur_to_new(master->cluster[i]); | ||
| 1269 | |||
| 1270 | /* Skip button controls and read-only controls. */ | ||
| 1271 | if (ctrl->type == V4L2_CTRL_TYPE_BUTTON || | ||
| 1272 | (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)) | ||
| 1273 | continue; | ||
| 1274 | ret = master->ops->s_ctrl(master); | ||
| 1275 | if (ret) | ||
| 1276 | break; | ||
| 1277 | for (i = 0; i < master->ncontrols; i++) | ||
| 1278 | if (master->cluster[i]) | ||
| 1279 | master->cluster[i]->done = true; | ||
| 1280 | } | ||
| 1281 | mutex_unlock(&hdl->lock); | ||
| 1282 | return ret; | ||
| 1283 | } | ||
| 1284 | EXPORT_SYMBOL(v4l2_ctrl_handler_setup); | ||
| 1285 | |||
| 1286 | /* Implement VIDIOC_QUERYCTRL */ | ||
| 1287 | int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc) | ||
| 1288 | { | ||
| 1289 | u32 id = qc->id & V4L2_CTRL_ID_MASK; | ||
| 1290 | struct v4l2_ctrl_ref *ref; | ||
| 1291 | struct v4l2_ctrl *ctrl; | ||
| 1292 | |||
| 1293 | if (hdl == NULL) | ||
| 1294 | return -EINVAL; | ||
| 1295 | |||
| 1296 | mutex_lock(&hdl->lock); | ||
| 1297 | |||
| 1298 | /* Try to find it */ | ||
| 1299 | ref = find_ref(hdl, id); | ||
| 1300 | |||
| 1301 | if ((qc->id & V4L2_CTRL_FLAG_NEXT_CTRL) && !list_empty(&hdl->ctrl_refs)) { | ||
| 1302 | /* Find the next control with ID > qc->id */ | ||
| 1303 | |||
| 1304 | /* Did we reach the end of the control list? */ | ||
| 1305 | if (id >= node2id(hdl->ctrl_refs.prev)) { | ||
| 1306 | ref = NULL; /* Yes, so there is no next control */ | ||
| 1307 | } else if (ref) { | ||
| 1308 | /* We found a control with the given ID, so just get | ||
| 1309 | the next one in the list. */ | ||
| 1310 | ref = list_entry(ref->node.next, typeof(*ref), node); | ||
| 1311 | } else { | ||
| 1312 | /* No control with the given ID exists, so start | ||
| 1313 | searching for the next largest ID. We know there | ||
| 1314 | is one, otherwise the first 'if' above would have | ||
| 1315 | been true. */ | ||
| 1316 | list_for_each_entry(ref, &hdl->ctrl_refs, node) | ||
| 1317 | if (id < ref->ctrl->id) | ||
| 1318 | break; | ||
| 1319 | } | ||
| 1320 | } | ||
| 1321 | mutex_unlock(&hdl->lock); | ||
| 1322 | if (!ref) | ||
| 1323 | return -EINVAL; | ||
| 1324 | |||
| 1325 | ctrl = ref->ctrl; | ||
| 1326 | memset(qc, 0, sizeof(*qc)); | ||
| 1327 | qc->id = ctrl->id; | ||
| 1328 | strlcpy(qc->name, ctrl->name, sizeof(qc->name)); | ||
| 1329 | qc->minimum = ctrl->minimum; | ||
| 1330 | qc->maximum = ctrl->maximum; | ||
| 1331 | qc->default_value = ctrl->default_value; | ||
| 1332 | if (qc->type == V4L2_CTRL_TYPE_MENU) | ||
| 1333 | qc->step = 1; | ||
| 1334 | else | ||
| 1335 | qc->step = ctrl->step; | ||
| 1336 | qc->flags = ctrl->flags; | ||
| 1337 | qc->type = ctrl->type; | ||
| 1338 | return 0; | ||
| 1339 | } | ||
| 1340 | EXPORT_SYMBOL(v4l2_queryctrl); | ||
| 1341 | |||
| 1342 | int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) | ||
| 1343 | { | ||
| 1344 | return v4l2_queryctrl(sd->ctrl_handler, qc); | ||
| 1345 | } | ||
| 1346 | EXPORT_SYMBOL(v4l2_subdev_queryctrl); | ||
| 1347 | |||
| 1348 | /* Implement VIDIOC_QUERYMENU */ | ||
| 1349 | int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm) | ||
| 1350 | { | ||
| 1351 | struct v4l2_ctrl *ctrl; | ||
| 1352 | u32 i = qm->index; | ||
| 1353 | |||
| 1354 | ctrl = v4l2_ctrl_find(hdl, qm->id); | ||
| 1355 | if (!ctrl) | ||
| 1356 | return -EINVAL; | ||
| 1357 | |||
| 1358 | qm->reserved = 0; | ||
| 1359 | /* Sanity checks */ | ||
| 1360 | if (ctrl->qmenu == NULL || | ||
| 1361 | i < ctrl->minimum || i > ctrl->maximum) | ||
| 1362 | return -EINVAL; | ||
| 1363 | /* Use mask to see if this menu item should be skipped */ | ||
| 1364 | if (ctrl->menu_skip_mask & (1 << i)) | ||
| 1365 | return -EINVAL; | ||
| 1366 | /* Empty menu items should also be skipped */ | ||
| 1367 | if (ctrl->qmenu[i] == NULL || ctrl->qmenu[i][0] == '\0') | ||
| 1368 | return -EINVAL; | ||
| 1369 | strlcpy(qm->name, ctrl->qmenu[i], sizeof(qm->name)); | ||
| 1370 | return 0; | ||
| 1371 | } | ||
| 1372 | EXPORT_SYMBOL(v4l2_querymenu); | ||
| 1373 | |||
| 1374 | int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm) | ||
| 1375 | { | ||
| 1376 | return v4l2_querymenu(sd->ctrl_handler, qm); | ||
| 1377 | } | ||
| 1378 | EXPORT_SYMBOL(v4l2_subdev_querymenu); | ||
| 1379 | |||
| 1380 | |||
| 1381 | |||
| 1382 | /* Some general notes on the atomic requirements of VIDIOC_G/TRY/S_EXT_CTRLS: | ||
| 1383 | |||
| 1384 | It is not a fully atomic operation, just best-effort only. After all, if | ||
| 1385 | multiple controls have to be set through multiple i2c writes (for example) | ||
| 1386 | then some initial writes may succeed while others fail. Thus leaving the | ||
| 1387 | system in an inconsistent state. The question is how much effort you are | ||
| 1388 | willing to spend on trying to make something atomic that really isn't. | ||
| 1389 | |||
| 1390 | From the point of view of an application the main requirement is that | ||
| 1391 | when you call VIDIOC_S_EXT_CTRLS and some values are invalid then an | ||
| 1392 | error should be returned without actually affecting any controls. | ||
| 1393 | |||
| 1394 | If all the values are correct, then it is acceptable to just give up | ||
| 1395 | in case of low-level errors. | ||
| 1396 | |||
| 1397 | It is important though that the application can tell when only a partial | ||
| 1398 | configuration was done. The way we do that is through the error_idx field | ||
| 1399 | of struct v4l2_ext_controls: if that is equal to the count field then no | ||
| 1400 | controls were affected. Otherwise all controls before that index were | ||
| 1401 | successful in performing their 'get' or 'set' operation, the control at | ||
| 1402 | the given index failed, and you don't know what happened with the controls | ||
| 1403 | after the failed one. Since if they were part of a control cluster they | ||
| 1404 | could have been successfully processed (if a cluster member was encountered | ||
| 1405 | at index < error_idx), they could have failed (if a cluster member was at | ||
| 1406 | error_idx), or they may not have been processed yet (if the first cluster | ||
| 1407 | member appeared after error_idx). | ||
| 1408 | |||
| 1409 | It is all fairly theoretical, though. In practice all you can do is to | ||
| 1410 | bail out. If error_idx == count, then it is an application bug. If | ||
| 1411 | error_idx < count then it is only an application bug if the error code was | ||
| 1412 | EBUSY. That usually means that something started streaming just when you | ||
| 1413 | tried to set the controls. In all other cases it is a driver/hardware | ||
| 1414 | problem and all you can do is to retry or bail out. | ||
| 1415 | |||
| 1416 | Note that these rules do not apply to VIDIOC_TRY_EXT_CTRLS: since that | ||
| 1417 | never modifies controls the error_idx is just set to whatever control | ||
| 1418 | has an invalid value. | ||
| 1419 | */ | ||
| 1420 | |||
| 1421 | /* Prepare for the extended g/s/try functions. | ||
| 1422 | Find the controls in the control array and do some basic checks. */ | ||
| 1423 | static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, | ||
| 1424 | struct v4l2_ext_controls *cs, | ||
| 1425 | struct ctrl_helper *helpers, | ||
| 1426 | bool try) | ||
| 1427 | { | ||
| 1428 | u32 i; | ||
| 1429 | |||
| 1430 | for (i = 0; i < cs->count; i++) { | ||
| 1431 | struct v4l2_ext_control *c = &cs->controls[i]; | ||
| 1432 | struct v4l2_ctrl *ctrl; | ||
| 1433 | u32 id = c->id & V4L2_CTRL_ID_MASK; | ||
| 1434 | |||
| 1435 | if (try) | ||
| 1436 | cs->error_idx = i; | ||
| 1437 | |||
| 1438 | if (cs->ctrl_class && V4L2_CTRL_ID2CLASS(id) != cs->ctrl_class) | ||
| 1439 | return -EINVAL; | ||
| 1440 | |||
| 1441 | /* Old-style private controls are not allowed for | ||
| 1442 | extended controls */ | ||
| 1443 | if (id >= V4L2_CID_PRIVATE_BASE) | ||
| 1444 | return -EINVAL; | ||
| 1445 | ctrl = v4l2_ctrl_find(hdl, id); | ||
| 1446 | if (ctrl == NULL) | ||
| 1447 | return -EINVAL; | ||
| 1448 | if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED) | ||
| 1449 | return -EINVAL; | ||
| 1450 | |||
| 1451 | helpers[i].ctrl = ctrl; | ||
| 1452 | helpers[i].handled = false; | ||
| 1453 | } | ||
| 1454 | return 0; | ||
| 1455 | } | ||
| 1456 | |||
| 1457 | typedef int (*cluster_func)(struct v4l2_ext_control *c, | ||
| 1458 | struct v4l2_ctrl *ctrl); | ||
| 1459 | |||
| 1460 | /* Walk over all controls in v4l2_ext_controls belonging to the same cluster | ||
| 1461 | and call the provided function. */ | ||
| 1462 | static int cluster_walk(unsigned from, | ||
| 1463 | struct v4l2_ext_controls *cs, | ||
| 1464 | struct ctrl_helper *helpers, | ||
| 1465 | cluster_func f) | ||
| 1466 | { | ||
| 1467 | struct v4l2_ctrl **cluster = helpers[from].ctrl->cluster; | ||
| 1468 | int ret = 0; | ||
| 1469 | int i; | ||
| 1470 | |||
| 1471 | /* Find any controls from the same cluster and call the function */ | ||
| 1472 | for (i = from; !ret && i < cs->count; i++) { | ||
| 1473 | struct v4l2_ctrl *ctrl = helpers[i].ctrl; | ||
| 1474 | |||
| 1475 | if (!helpers[i].handled && ctrl->cluster == cluster) | ||
| 1476 | ret = f(&cs->controls[i], ctrl); | ||
| 1477 | } | ||
| 1478 | return ret; | ||
| 1479 | } | ||
| 1480 | |||
| 1481 | static void cluster_done(unsigned from, | ||
| 1482 | struct v4l2_ext_controls *cs, | ||
| 1483 | struct ctrl_helper *helpers) | ||
| 1484 | { | ||
| 1485 | struct v4l2_ctrl **cluster = helpers[from].ctrl->cluster; | ||
| 1486 | int i; | ||
| 1487 | |||
| 1488 | /* Find any controls from the same cluster and mark them as handled */ | ||
| 1489 | for (i = from; i < cs->count; i++) | ||
| 1490 | if (helpers[i].ctrl->cluster == cluster) | ||
| 1491 | helpers[i].handled = true; | ||
| 1492 | } | ||
| 1493 | |||
| 1494 | /* Handles the corner case where cs->count == 0. It checks whether the | ||
| 1495 | specified control class exists. If that class ID is 0, then it checks | ||
| 1496 | whether there are any controls at all. */ | ||
| 1497 | static int class_check(struct v4l2_ctrl_handler *hdl, u32 ctrl_class) | ||
| 1498 | { | ||
| 1499 | if (ctrl_class == 0) | ||
| 1500 | return list_empty(&hdl->ctrl_refs) ? -EINVAL : 0; | ||
| 1501 | return find_ref_lock(hdl, ctrl_class | 1) ? 0 : -EINVAL; | ||
| 1502 | } | ||
| 1503 | |||
| 1504 | |||
| 1505 | |||
| 1506 | /* Get extended controls. Allocates the helpers array if needed. */ | ||
| 1507 | int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) | ||
| 1508 | { | ||
| 1509 | struct ctrl_helper helper[4]; | ||
| 1510 | struct ctrl_helper *helpers = helper; | ||
| 1511 | int ret; | ||
| 1512 | int i; | ||
| 1513 | |||
| 1514 | cs->error_idx = cs->count; | ||
| 1515 | cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class); | ||
| 1516 | |||
| 1517 | if (hdl == NULL) | ||
| 1518 | return -EINVAL; | ||
| 1519 | |||
| 1520 | if (cs->count == 0) | ||
| 1521 | return class_check(hdl, cs->ctrl_class); | ||
| 1522 | |||
| 1523 | if (cs->count > ARRAY_SIZE(helper)) { | ||
| 1524 | helpers = kmalloc(sizeof(helper[0]) * cs->count, GFP_KERNEL); | ||
| 1525 | if (helpers == NULL) | ||
| 1526 | return -ENOMEM; | ||
| 1527 | } | ||
| 1528 | |||
| 1529 | ret = prepare_ext_ctrls(hdl, cs, helpers, false); | ||
| 1530 | |||
| 1531 | for (i = 0; !ret && i < cs->count; i++) | ||
| 1532 | if (helpers[i].ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) | ||
| 1533 | ret = -EACCES; | ||
| 1534 | |||
| 1535 | for (i = 0; !ret && i < cs->count; i++) { | ||
| 1536 | struct v4l2_ctrl *ctrl = helpers[i].ctrl; | ||
| 1537 | struct v4l2_ctrl *master = ctrl->cluster[0]; | ||
| 1538 | |||
| 1539 | if (helpers[i].handled) | ||
| 1540 | continue; | ||
| 1541 | |||
| 1542 | cs->error_idx = i; | ||
| 1543 | |||
| 1544 | v4l2_ctrl_lock(master); | ||
| 1545 | /* g_volatile_ctrl will update the current control values */ | ||
| 1546 | if (ctrl->is_volatile && master->ops->g_volatile_ctrl) | ||
| 1547 | ret = master->ops->g_volatile_ctrl(master); | ||
| 1548 | /* If OK, then copy the current control values to the caller */ | ||
| 1549 | if (!ret) | ||
| 1550 | ret = cluster_walk(i, cs, helpers, cur_to_user); | ||
| 1551 | v4l2_ctrl_unlock(master); | ||
| 1552 | cluster_done(i, cs, helpers); | ||
| 1553 | } | ||
| 1554 | |||
| 1555 | if (cs->count > ARRAY_SIZE(helper)) | ||
| 1556 | kfree(helpers); | ||
| 1557 | return ret; | ||
| 1558 | } | ||
| 1559 | EXPORT_SYMBOL(v4l2_g_ext_ctrls); | ||
| 1560 | |||
| 1561 | int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs) | ||
| 1562 | { | ||
| 1563 | return v4l2_g_ext_ctrls(sd->ctrl_handler, cs); | ||
| 1564 | } | ||
| 1565 | EXPORT_SYMBOL(v4l2_subdev_g_ext_ctrls); | ||
| 1566 | |||
| 1567 | /* Helper function to get a single control */ | ||
| 1568 | static int get_ctrl(struct v4l2_ctrl *ctrl, s32 *val) | ||
| 1569 | { | ||
| 1570 | struct v4l2_ctrl *master = ctrl->cluster[0]; | ||
| 1571 | int ret = 0; | ||
| 1572 | |||
| 1573 | if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) | ||
| 1574 | return -EACCES; | ||
| 1575 | |||
| 1576 | v4l2_ctrl_lock(master); | ||
| 1577 | /* g_volatile_ctrl will update the current control values */ | ||
| 1578 | if (ctrl->is_volatile && master->ops->g_volatile_ctrl) | ||
| 1579 | ret = master->ops->g_volatile_ctrl(master); | ||
| 1580 | *val = ctrl->cur.val; | ||
| 1581 | v4l2_ctrl_unlock(master); | ||
| 1582 | return ret; | ||
| 1583 | } | ||
| 1584 | |||
| 1585 | int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control) | ||
| 1586 | { | ||
| 1587 | struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); | ||
| 1588 | |||
| 1589 | if (ctrl == NULL || !type_is_int(ctrl)) | ||
| 1590 | return -EINVAL; | ||
| 1591 | return get_ctrl(ctrl, &control->value); | ||
| 1592 | } | ||
| 1593 | EXPORT_SYMBOL(v4l2_g_ctrl); | ||
| 1594 | |||
| 1595 | int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *control) | ||
| 1596 | { | ||
| 1597 | return v4l2_g_ctrl(sd->ctrl_handler, control); | ||
| 1598 | } | ||
| 1599 | EXPORT_SYMBOL(v4l2_subdev_g_ctrl); | ||
| 1600 | |||
| 1601 | s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl) | ||
| 1602 | { | ||
| 1603 | s32 val = 0; | ||
| 1604 | |||
| 1605 | /* It's a driver bug if this happens. */ | ||
| 1606 | WARN_ON(!type_is_int(ctrl)); | ||
| 1607 | get_ctrl(ctrl, &val); | ||
| 1608 | return val; | ||
| 1609 | } | ||
| 1610 | EXPORT_SYMBOL(v4l2_ctrl_g_ctrl); | ||
| 1611 | |||
| 1612 | |||
| 1613 | /* Core function that calls try/s_ctrl and ensures that the new value is | ||
| 1614 | copied to the current value on a set. | ||
| 1615 | Must be called with ctrl->handler->lock held. */ | ||
| 1616 | static int try_or_set_control_cluster(struct v4l2_ctrl *master, bool set) | ||
| 1617 | { | ||
| 1618 | bool try = !set; | ||
| 1619 | int ret = 0; | ||
| 1620 | int i; | ||
| 1621 | |||
| 1622 | /* Go through the cluster and either validate the new value or | ||
| 1623 | (if no new value was set), copy the current value to the new | ||
| 1624 | value, ensuring a consistent view for the control ops when | ||
| 1625 | called. */ | ||
| 1626 | for (i = 0; !ret && i < master->ncontrols; i++) { | ||
| 1627 | struct v4l2_ctrl *ctrl = master->cluster[i]; | ||
| 1628 | |||
| 1629 | if (ctrl == NULL) | ||
| 1630 | continue; | ||
| 1631 | |||
| 1632 | if (ctrl->has_new) { | ||
| 1633 | /* Double check this: it may have changed since the | ||
| 1634 | last check in try_or_set_ext_ctrls(). */ | ||
| 1635 | if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) | ||
| 1636 | return -EBUSY; | ||
| 1637 | |||
| 1638 | /* Validate if required */ | ||
| 1639 | if (!set) | ||
| 1640 | ret = validate_new(ctrl); | ||
| 1641 | continue; | ||
| 1642 | } | ||
| 1643 | /* No new value was set, so copy the current and force | ||
| 1644 | a call to try_ctrl later, since the values for the cluster | ||
| 1645 | may now have changed and the end result might be invalid. */ | ||
| 1646 | try = true; | ||
| 1647 | cur_to_new(ctrl); | ||
| 1648 | } | ||
| 1649 | |||
| 1650 | /* For larger clusters you have to call try_ctrl again to | ||
| 1651 | verify that the controls are still valid after the | ||
| 1652 | 'cur_to_new' above. */ | ||
| 1653 | if (!ret && master->ops->try_ctrl && try) | ||
| 1654 | ret = master->ops->try_ctrl(master); | ||
| 1655 | |||
| 1656 | /* Don't set if there is no change */ | ||
| 1657 | if (!ret && set && cluster_changed(master)) { | ||
| 1658 | ret = master->ops->s_ctrl(master); | ||
| 1659 | /* If OK, then make the new values permanent. */ | ||
| 1660 | if (!ret) | ||
| 1661 | for (i = 0; i < master->ncontrols; i++) | ||
| 1662 | new_to_cur(master->cluster[i]); | ||
| 1663 | } | ||
| 1664 | return ret; | ||
| 1665 | } | ||
| 1666 | |||
| 1667 | /* Try or set controls. */ | ||
| 1668 | static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, | ||
| 1669 | struct v4l2_ext_controls *cs, | ||
| 1670 | struct ctrl_helper *helpers, | ||
| 1671 | bool set) | ||
| 1672 | { | ||
| 1673 | unsigned i, j; | ||
| 1674 | int ret = 0; | ||
| 1675 | |||
| 1676 | cs->error_idx = cs->count; | ||
| 1677 | for (i = 0; i < cs->count; i++) { | ||
| 1678 | struct v4l2_ctrl *ctrl = helpers[i].ctrl; | ||
| 1679 | |||
| 1680 | if (!set) | ||
| 1681 | cs->error_idx = i; | ||
| 1682 | |||
| 1683 | if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) | ||
| 1684 | return -EACCES; | ||
| 1685 | /* This test is also done in try_set_control_cluster() which | ||
| 1686 | is called in atomic context, so that has the final say, | ||
| 1687 | but it makes sense to do an up-front check as well. Once | ||
| 1688 | an error occurs in try_set_control_cluster() some other | ||
| 1689 | controls may have been set already and we want to do a | ||
| 1690 | best-effort to avoid that. */ | ||
| 1691 | if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) | ||
| 1692 | return -EBUSY; | ||
| 1693 | } | ||
| 1694 | |||
| 1695 | for (i = 0; !ret && i < cs->count; i++) { | ||
| 1696 | struct v4l2_ctrl *ctrl = helpers[i].ctrl; | ||
| 1697 | struct v4l2_ctrl *master = ctrl->cluster[0]; | ||
| 1698 | |||
| 1699 | cs->error_idx = i; | ||
| 1700 | |||
| 1701 | if (helpers[i].handled) | ||
| 1702 | continue; | ||
| 1703 | |||
| 1704 | v4l2_ctrl_lock(ctrl); | ||
| 1705 | |||
| 1706 | /* Reset the 'has_new' flags of the cluster */ | ||
| 1707 | for (j = 0; j < master->ncontrols; j++) | ||
| 1708 | if (master->cluster[j]) | ||
| 1709 | master->cluster[j]->has_new = 0; | ||
| 1710 | |||
| 1711 | /* Copy the new caller-supplied control values. | ||
| 1712 | user_to_new() sets 'has_new' to 1. */ | ||
| 1713 | ret = cluster_walk(i, cs, helpers, user_to_new); | ||
| 1714 | |||
| 1715 | if (!ret) | ||
| 1716 | ret = try_or_set_control_cluster(master, set); | ||
| 1717 | |||
| 1718 | /* Copy the new values back to userspace. */ | ||
| 1719 | if (!ret) | ||
| 1720 | ret = cluster_walk(i, cs, helpers, new_to_user); | ||
| 1721 | |||
| 1722 | v4l2_ctrl_unlock(ctrl); | ||
| 1723 | cluster_done(i, cs, helpers); | ||
| 1724 | } | ||
| 1725 | return ret; | ||
| 1726 | } | ||
| 1727 | |||
| 1728 | /* Try or try-and-set controls */ | ||
| 1729 | static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, | ||
| 1730 | struct v4l2_ext_controls *cs, | ||
| 1731 | bool set) | ||
| 1732 | { | ||
| 1733 | struct ctrl_helper helper[4]; | ||
| 1734 | struct ctrl_helper *helpers = helper; | ||
| 1735 | int ret; | ||
| 1736 | int i; | ||
| 1737 | |||
| 1738 | cs->error_idx = cs->count; | ||
| 1739 | cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class); | ||
| 1740 | |||
| 1741 | if (hdl == NULL) | ||
| 1742 | return -EINVAL; | ||
| 1743 | |||
| 1744 | if (cs->count == 0) | ||
| 1745 | return class_check(hdl, cs->ctrl_class); | ||
| 1746 | |||
| 1747 | if (cs->count > ARRAY_SIZE(helper)) { | ||
| 1748 | helpers = kmalloc(sizeof(helper[0]) * cs->count, GFP_KERNEL); | ||
| 1749 | if (!helpers) | ||
| 1750 | return -ENOMEM; | ||
| 1751 | } | ||
| 1752 | ret = prepare_ext_ctrls(hdl, cs, helpers, !set); | ||
| 1753 | if (ret) | ||
| 1754 | goto free; | ||
| 1755 | |||
| 1756 | /* First 'try' all controls and abort on error */ | ||
| 1757 | ret = try_or_set_ext_ctrls(hdl, cs, helpers, false); | ||
| 1758 | /* If this is a 'set' operation and the initial 'try' failed, | ||
| 1759 | then set error_idx to count to tell the application that no | ||
| 1760 | controls changed value yet. */ | ||
| 1761 | if (set) | ||
| 1762 | cs->error_idx = cs->count; | ||
| 1763 | if (!ret && set) { | ||
| 1764 | /* Reset 'handled' state */ | ||
| 1765 | for (i = 0; i < cs->count; i++) | ||
| 1766 | helpers[i].handled = false; | ||
| 1767 | ret = try_or_set_ext_ctrls(hdl, cs, helpers, true); | ||
| 1768 | } | ||
| 1769 | |||
| 1770 | free: | ||
| 1771 | if (cs->count > ARRAY_SIZE(helper)) | ||
| 1772 | kfree(helpers); | ||
| 1773 | return ret; | ||
| 1774 | } | ||
| 1775 | |||
| 1776 | int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) | ||
| 1777 | { | ||
| 1778 | return try_set_ext_ctrls(hdl, cs, false); | ||
| 1779 | } | ||
| 1780 | EXPORT_SYMBOL(v4l2_try_ext_ctrls); | ||
| 1781 | |||
| 1782 | int v4l2_s_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) | ||
| 1783 | { | ||
| 1784 | return try_set_ext_ctrls(hdl, cs, true); | ||
| 1785 | } | ||
| 1786 | EXPORT_SYMBOL(v4l2_s_ext_ctrls); | ||
| 1787 | |||
| 1788 | int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs) | ||
| 1789 | { | ||
| 1790 | return try_set_ext_ctrls(sd->ctrl_handler, cs, false); | ||
| 1791 | } | ||
| 1792 | EXPORT_SYMBOL(v4l2_subdev_try_ext_ctrls); | ||
| 1793 | |||
| 1794 | int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs) | ||
| 1795 | { | ||
| 1796 | return try_set_ext_ctrls(sd->ctrl_handler, cs, true); | ||
| 1797 | } | ||
| 1798 | EXPORT_SYMBOL(v4l2_subdev_s_ext_ctrls); | ||
| 1799 | |||
| 1800 | /* Helper function for VIDIOC_S_CTRL compatibility */ | ||
| 1801 | static int set_ctrl(struct v4l2_ctrl *ctrl, s32 *val) | ||
| 1802 | { | ||
| 1803 | struct v4l2_ctrl *master = ctrl->cluster[0]; | ||
| 1804 | int ret; | ||
| 1805 | int i; | ||
| 1806 | |||
| 1807 | v4l2_ctrl_lock(ctrl); | ||
| 1808 | |||
| 1809 | /* Reset the 'has_new' flags of the cluster */ | ||
| 1810 | for (i = 0; i < master->ncontrols; i++) | ||
| 1811 | if (master->cluster[i]) | ||
| 1812 | master->cluster[i]->has_new = 0; | ||
| 1813 | |||
| 1814 | ctrl->val = *val; | ||
| 1815 | ctrl->has_new = 1; | ||
| 1816 | ret = try_or_set_control_cluster(master, false); | ||
| 1817 | if (!ret) | ||
| 1818 | ret = try_or_set_control_cluster(master, true); | ||
| 1819 | *val = ctrl->cur.val; | ||
| 1820 | v4l2_ctrl_unlock(ctrl); | ||
| 1821 | return ret; | ||
| 1822 | } | ||
| 1823 | |||
| 1824 | int v4l2_s_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control) | ||
| 1825 | { | ||
| 1826 | struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); | ||
| 1827 | |||
| 1828 | if (ctrl == NULL || !type_is_int(ctrl)) | ||
| 1829 | return -EINVAL; | ||
| 1830 | |||
| 1831 | return set_ctrl(ctrl, &control->value); | ||
| 1832 | } | ||
| 1833 | EXPORT_SYMBOL(v4l2_s_ctrl); | ||
| 1834 | |||
| 1835 | int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *control) | ||
| 1836 | { | ||
| 1837 | return v4l2_s_ctrl(sd->ctrl_handler, control); | ||
| 1838 | } | ||
| 1839 | EXPORT_SYMBOL(v4l2_subdev_s_ctrl); | ||
| 1840 | |||
| 1841 | int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val) | ||
| 1842 | { | ||
| 1843 | /* It's a driver bug if this happens. */ | ||
| 1844 | WARN_ON(!type_is_int(ctrl)); | ||
| 1845 | return set_ctrl(ctrl, &val); | ||
| 1846 | } | ||
| 1847 | EXPORT_SYMBOL(v4l2_ctrl_s_ctrl); | ||
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h new file mode 100644 index 000000000000..9b7bea928a88 --- /dev/null +++ b/include/media/v4l2-ctrls.h | |||
| @@ -0,0 +1,460 @@ | |||
| 1 | /* | ||
| 2 | V4L2 controls support header. | ||
| 3 | |||
| 4 | Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl> | ||
| 5 | |||
| 6 | This program is free software; you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 2 of the License, or | ||
| 9 | (at your option) any later version. | ||
| 10 | |||
| 11 | This program is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with this program; if not, write to the Free Software | ||
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #ifndef _V4L2_CTRLS_H | ||
| 22 | #define _V4L2_CTRLS_H | ||
| 23 | |||
| 24 | #include <linux/list.h> | ||
| 25 | #include <linux/device.h> | ||
| 26 | |||
| 27 | /* forward references */ | ||
| 28 | struct v4l2_ctrl_handler; | ||
| 29 | struct v4l2_ctrl; | ||
| 30 | struct video_device; | ||
| 31 | struct v4l2_subdev; | ||
| 32 | |||
| 33 | /** struct v4l2_ctrl_ops - The control operations that the driver has to provide. | ||
| 34 | * @g_volatile_ctrl: Get a new value for this control. Generally only relevant | ||
| 35 | * for volatile (and usually read-only) controls such as a control | ||
| 36 | * that returns the current signal strength which changes | ||
| 37 | * continuously. | ||
| 38 | * If not set, then the currently cached value will be returned. | ||
| 39 | * @try_ctrl: Test whether the control's value is valid. Only relevant when | ||
| 40 | * the usual min/max/step checks are not sufficient. | ||
| 41 | * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The | ||
| 42 | * ctrl->handler->lock is held when these ops are called, so no | ||
| 43 | * one else can access controls owned by that handler. | ||
| 44 | */ | ||
| 45 | struct v4l2_ctrl_ops { | ||
| 46 | int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl); | ||
| 47 | int (*try_ctrl)(struct v4l2_ctrl *ctrl); | ||
| 48 | int (*s_ctrl)(struct v4l2_ctrl *ctrl); | ||
| 49 | }; | ||
| 50 | |||
| 51 | /** struct v4l2_ctrl - The control structure. | ||
| 52 | * @node: The list node. | ||
| 53 | * @handler: The handler that owns the control. | ||
| 54 | * @cluster: Point to start of cluster array. | ||
| 55 | * @ncontrols: Number of controls in cluster array. | ||
| 56 | * @has_new: Internal flag: set when there is a valid new value. | ||
| 57 | * @done: Internal flag: set for each processed control. | ||
| 58 | * @is_private: If set, then this control is private to its handler and it | ||
| 59 | * will not be added to any other handlers. Drivers can set | ||
| 60 | * this flag. | ||
| 61 | * @is_volatile: If set, then this control is volatile. This means that the | ||
| 62 | * control's current value cannot be cached and needs to be | ||
| 63 | * retrieved through the g_volatile_ctrl op. Drivers can set | ||
| 64 | * this flag. | ||
| 65 | * @ops: The control ops. | ||
| 66 | * @id: The control ID. | ||
| 67 | * @name: The control name. | ||
| 68 | * @type: The control type. | ||
| 69 | * @minimum: The control's minimum value. | ||
| 70 | * @maximum: The control's maximum value. | ||
| 71 | * @default_value: The control's default value. | ||
| 72 | * @step: The control's step value for non-menu controls. | ||
| 73 | * @menu_skip_mask: The control's skip mask for menu controls. This makes it | ||
| 74 | * easy to skip menu items that are not valid. If bit X is set, | ||
| 75 | * then menu item X is skipped. Of course, this only works for | ||
| 76 | * menus with <= 32 menu items. There are no menus that come | ||
| 77 | * close to that number, so this is OK. Should we ever need more, | ||
| 78 | * then this will have to be extended to a u64 or a bit array. | ||
| 79 | * @qmenu: A const char * array for all menu items. Array entries that are | ||
| 80 | * empty strings ("") correspond to non-existing menu items (this | ||
| 81 | * is in addition to the menu_skip_mask above). The last entry | ||
| 82 | * must be NULL. | ||
| 83 | * @flags: The control's flags. | ||
| 84 | * @cur: The control's current value. | ||
| 85 | * @val: The control's new s32 value. | ||
| 86 | * @val64: The control's new s64 value. | ||
| 87 | * @string: The control's new string value. | ||
| 88 | * @priv: The control's private pointer. For use by the driver. It is | ||
| 89 | * untouched by the control framework. Note that this pointer is | ||
| 90 | * not freed when the control is deleted. Should this be needed | ||
| 91 | * then a new internal bitfield can be added to tell the framework | ||
| 92 | * to free this pointer. | ||
| 93 | */ | ||
| 94 | struct v4l2_ctrl { | ||
| 95 | /* Administrative fields */ | ||
| 96 | struct list_head node; | ||
| 97 | struct v4l2_ctrl_handler *handler; | ||
| 98 | struct v4l2_ctrl **cluster; | ||
| 99 | unsigned ncontrols; | ||
| 100 | unsigned int has_new:1; | ||
| 101 | unsigned int done:1; | ||
| 102 | |||
| 103 | unsigned int is_private:1; | ||
| 104 | unsigned int is_volatile:1; | ||
| 105 | |||
| 106 | const struct v4l2_ctrl_ops *ops; | ||
| 107 | u32 id; | ||
| 108 | const char *name; | ||
| 109 | enum v4l2_ctrl_type type; | ||
| 110 | s32 minimum, maximum, default_value; | ||
| 111 | union { | ||
| 112 | u32 step; | ||
| 113 | u32 menu_skip_mask; | ||
| 114 | }; | ||
| 115 | const char **qmenu; | ||
| 116 | unsigned long flags; | ||
| 117 | union { | ||
| 118 | s32 val; | ||
| 119 | s64 val64; | ||
| 120 | char *string; | ||
| 121 | } cur; | ||
| 122 | union { | ||
| 123 | s32 val; | ||
| 124 | s64 val64; | ||
| 125 | char *string; | ||
| 126 | }; | ||
| 127 | void *priv; | ||
| 128 | }; | ||
| 129 | |||
| 130 | /** struct v4l2_ctrl_ref - The control reference. | ||
| 131 | * @node: List node for the sorted list. | ||
| 132 | * @next: Single-link list node for the hash. | ||
| 133 | * @ctrl: The actual control information. | ||
| 134 | * | ||
| 135 | * Each control handler has a list of these refs. The list_head is used to | ||
| 136 | * keep a sorted-by-control-ID list of all controls, while the next pointer | ||
| 137 | * is used to link the control in the hash's bucket. | ||
| 138 | */ | ||
| 139 | struct v4l2_ctrl_ref { | ||
| 140 | struct list_head node; | ||
| 141 | struct v4l2_ctrl_ref *next; | ||
| 142 | struct v4l2_ctrl *ctrl; | ||
| 143 | }; | ||
| 144 | |||
| 145 | /** struct v4l2_ctrl_handler - The control handler keeps track of all the | ||
| 146 | * controls: both the controls owned by the handler and those inherited | ||
| 147 | * from other handlers. | ||
| 148 | * @lock: Lock to control access to this handler and its controls. | ||
| 149 | * @ctrls: The list of controls owned by this handler. | ||
| 150 | * @ctrl_refs: The list of control references. | ||
| 151 | * @cached: The last found control reference. It is common that the same | ||
| 152 | * control is needed multiple times, so this is a simple | ||
| 153 | * optimization. | ||
| 154 | * @buckets: Buckets for the hashing. Allows for quick control lookup. | ||
| 155 | * @nr_of_buckets: Total number of buckets in the array. | ||
| 156 | * @error: The error code of the first failed control addition. | ||
| 157 | */ | ||
| 158 | struct v4l2_ctrl_handler { | ||
| 159 | struct mutex lock; | ||
| 160 | struct list_head ctrls; | ||
| 161 | struct list_head ctrl_refs; | ||
| 162 | struct v4l2_ctrl_ref *cached; | ||
| 163 | struct v4l2_ctrl_ref **buckets; | ||
| 164 | u16 nr_of_buckets; | ||
| 165 | int error; | ||
| 166 | }; | ||
| 167 | |||
| 168 | /** struct v4l2_ctrl_config - Control configuration structure. | ||
| 169 | * @ops: The control ops. | ||
| 170 | * @id: The control ID. | ||
| 171 | * @name: The control name. | ||
| 172 | * @type: The control type. | ||
| 173 | * @min: The control's minimum value. | ||
| 174 | * @max: The control's maximum value. | ||
| 175 | * @step: The control's step value for non-menu controls. | ||
| 176 | * @def: The control's default value. | ||
| 177 | * @flags: The control's flags. | ||
| 178 | * @menu_skip_mask: The control's skip mask for menu controls. This makes it | ||
| 179 | * easy to skip menu items that are not valid. If bit X is set, | ||
| 180 | * then menu item X is skipped. Of course, this only works for | ||
| 181 | * menus with <= 32 menu items. There are no menus that come | ||
| 182 | * close to that number, so this is OK. Should we ever need more, | ||
| 183 | * then this will have to be extended to a u64 or a bit array. | ||
| 184 | * @qmenu: A const char * array for all menu items. Array entries that are | ||
| 185 | * empty strings ("") correspond to non-existing menu items (this | ||
| 186 | * is in addition to the menu_skip_mask above). The last entry | ||
| 187 | * must be NULL. | ||
| 188 | * @is_private: If set, then this control is private to its handler and it | ||
| 189 | * will not be added to any other handlers. | ||
| 190 | * @is_volatile: If set, then this control is volatile. This means that the | ||
| 191 | * control's current value cannot be cached and needs to be | ||
| 192 | * retrieved through the g_volatile_ctrl op. | ||
| 193 | */ | ||
| 194 | struct v4l2_ctrl_config { | ||
| 195 | const struct v4l2_ctrl_ops *ops; | ||
| 196 | u32 id; | ||
| 197 | const char *name; | ||
| 198 | enum v4l2_ctrl_type type; | ||
| 199 | s32 min; | ||
| 200 | s32 max; | ||
| 201 | u32 step; | ||
| 202 | s32 def; | ||
| 203 | u32 flags; | ||
| 204 | u32 menu_skip_mask; | ||
| 205 | const char **qmenu; | ||
| 206 | unsigned int is_private:1; | ||
| 207 | unsigned int is_volatile:1; | ||
| 208 | }; | ||
| 209 | |||
| 210 | /** v4l2_ctrl_fill() - Fill in the control fields based on the control ID. | ||
| 211 | * | ||
| 212 | * This works for all standard V4L2 controls. | ||
| 213 | * For non-standard controls it will only fill in the given arguments | ||
| 214 | * and @name will be NULL. | ||
| 215 | * | ||
| 216 | * This function will overwrite the contents of @name, @type and @flags. | ||
| 217 | * The contents of @min, @max, @step and @def may be modified depending on | ||
| 218 | * the type. | ||
| 219 | * | ||
| 220 | * Do not use in drivers! It is used internally for backwards compatibility | ||
| 221 | * control handling only. Once all drivers are converted to use the new | ||
| 222 | * control framework this function will no longer be exported. | ||
| 223 | */ | ||
| 224 | void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, | ||
| 225 | s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags); | ||
| 226 | |||
| 227 | |||
| 228 | /** v4l2_ctrl_handler_init() - Initialize the control handler. | ||
| 229 | * @hdl: The control handler. | ||
| 230 | * @nr_of_controls_hint: A hint of how many controls this handler is | ||
| 231 | * expected to refer to. This is the total number, so including | ||
| 232 | * any inherited controls. It doesn't have to be precise, but if | ||
| 233 | * it is way off, then you either waste memory (too many buckets | ||
| 234 | * are allocated) or the control lookup becomes slower (not enough | ||
| 235 | * buckets are allocated, so there are more slow list lookups). | ||
| 236 | * It will always work, though. | ||
| 237 | * | ||
| 238 | * Returns an error if the buckets could not be allocated. This error will | ||
| 239 | * also be stored in @hdl->error. | ||
| 240 | */ | ||
| 241 | int v4l2_ctrl_handler_init(struct v4l2_ctrl_handler *hdl, | ||
| 242 | unsigned nr_of_controls_hint); | ||
| 243 | |||
| 244 | /** v4l2_ctrl_handler_free() - Free all controls owned by the handler and free | ||
| 245 | * the control list. | ||
| 246 | * @hdl: The control handler. | ||
| 247 | * | ||
| 248 | * Does nothing if @hdl == NULL. | ||
| 249 | */ | ||
| 250 | void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl); | ||
| 251 | |||
| 252 | /** v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging | ||
| 253 | * to the handler to initialize the hardware to the current control values. | ||
| 254 | * @hdl: The control handler. | ||
| 255 | * | ||
| 256 | * Button controls will be skipped, as are read-only controls. | ||
| 257 | * | ||
| 258 | * If @hdl == NULL, then this just returns 0. | ||
| 259 | */ | ||
| 260 | int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl); | ||
| 261 | |||
| 262 | /** v4l2_ctrl_handler_log_status() - Log all controls owned by the handler. | ||
| 263 | * @hdl: The control handler. | ||
| 264 | * @prefix: The prefix to use when logging the control values. If the | ||
| 265 | * prefix does not end with a space, then ": " will be added | ||
| 266 | * after the prefix. If @prefix == NULL, then no prefix will be | ||
| 267 | * used. | ||
| 268 | * | ||
| 269 | * For use with VIDIOC_LOG_STATUS. | ||
| 270 | * | ||
| 271 | * Does nothing if @hdl == NULL. | ||
| 272 | */ | ||
| 273 | void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, | ||
| 274 | const char *prefix); | ||
| 275 | |||
| 276 | /** v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2 | ||
| 277 | * control. | ||
| 278 | * @hdl: The control handler. | ||
| 279 | * @cfg: The control's configuration data. | ||
| 280 | * @priv: The control's driver-specific private data. | ||
| 281 | * | ||
| 282 | * If the &v4l2_ctrl struct could not be allocated then NULL is returned | ||
| 283 | * and @hdl->error is set to the error code (if it wasn't set already). | ||
| 284 | */ | ||
| 285 | struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, | ||
| 286 | const struct v4l2_ctrl_config *cfg, void *priv); | ||
| 287 | |||
| 288 | /** v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu control. | ||
| 289 | * @hdl: The control handler. | ||
| 290 | * @ops: The control ops. | ||
| 291 | * @id: The control ID. | ||
| 292 | * @min: The control's minimum value. | ||
| 293 | * @max: The control's maximum value. | ||
| 294 | * @step: The control's step value | ||
| 295 | * @def: The control's default value. | ||
| 296 | * | ||
| 297 | * If the &v4l2_ctrl struct could not be allocated, or the control | ||
| 298 | * ID is not known, then NULL is returned and @hdl->error is set to the | ||
| 299 | * appropriate error code (if it wasn't set already). | ||
| 300 | * | ||
| 301 | * If @id refers to a menu control, then this function will return NULL. | ||
| 302 | * | ||
| 303 | * Use v4l2_ctrl_new_std_menu() when adding menu controls. | ||
| 304 | */ | ||
| 305 | struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, | ||
| 306 | const struct v4l2_ctrl_ops *ops, | ||
| 307 | u32 id, s32 min, s32 max, u32 step, s32 def); | ||
| 308 | |||
| 309 | /** v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control. | ||
| 310 | * @hdl: The control handler. | ||
| 311 | * @ops: The control ops. | ||
| 312 | * @id: The control ID. | ||
| 313 | * @max: The control's maximum value. | ||
| 314 | * @mask: The control's skip mask for menu controls. This makes it | ||
| 315 | * easy to skip menu items that are not valid. If bit X is set, | ||
| 316 | * then menu item X is skipped. Of course, this only works for | ||
| 317 | * menus with <= 32 menu items. There are no menus that come | ||
| 318 | * close to that number, so this is OK. Should we ever need more, | ||
| 319 | * then this will have to be extended to a u64 or a bit array. | ||
| 320 | * @def: The control's default value. | ||
| 321 | * | ||
| 322 | * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value | ||
| 323 | * determines which menu items are to be skipped. | ||
| 324 | * | ||
| 325 | * If @id refers to a non-menu control, then this function will return NULL. | ||
| 326 | */ | ||
| 327 | struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, | ||
| 328 | const struct v4l2_ctrl_ops *ops, | ||
| 329 | u32 id, s32 max, s32 mask, s32 def); | ||
| 330 | |||
| 331 | /** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler. | ||
| 332 | * @hdl: The control handler. | ||
| 333 | * @ctrl: The control to add. | ||
| 334 | * | ||
| 335 | * It will return NULL if it was unable to add the control reference. | ||
| 336 | * If the control already belonged to the handler, then it will do | ||
| 337 | * nothing and just return @ctrl. | ||
| 338 | */ | ||
| 339 | struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, | ||
| 340 | struct v4l2_ctrl *ctrl); | ||
| 341 | |||
| 342 | /** v4l2_ctrl_add_handler() - Add all controls from handler @add to | ||
| 343 | * handler @hdl. | ||
| 344 | * @hdl: The control handler. | ||
| 345 | * @add: The control handler whose controls you want to add to | ||
| 346 | * the @hdl control handler. | ||
| 347 | * | ||
| 348 | * Does nothing if either of the two is a NULL pointer. | ||
| 349 | * In case of an error @hdl->error will be set to the error code (if it | ||
| 350 | * wasn't set already). | ||
| 351 | */ | ||
| 352 | int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, | ||
| 353 | struct v4l2_ctrl_handler *add); | ||
| 354 | |||
| 355 | |||
| 356 | /** v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster. | ||
| 357 | * @ncontrols: The number of controls in this cluster. | ||
| 358 | * @controls: The cluster control array of size @ncontrols. | ||
| 359 | */ | ||
| 360 | void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls); | ||
| 361 | |||
| 362 | |||
| 363 | /** v4l2_ctrl_find() - Find a control with the given ID. | ||
| 364 | * @hdl: The control handler. | ||
| 365 | * @id: The control ID to find. | ||
| 366 | * | ||
| 367 | * If @hdl == NULL this will return NULL as well. Will lock the handler so | ||
| 368 | * do not use from inside &v4l2_ctrl_ops. | ||
| 369 | */ | ||
| 370 | struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id); | ||
| 371 | |||
| 372 | /** v4l2_ctrl_activate() - Make the control active or inactive. | ||
| 373 | * @ctrl: The control to (de)activate. | ||
| 374 | * @active: True if the control should become active. | ||
| 375 | * | ||
| 376 | * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically. | ||
| 377 | * Does nothing if @ctrl == NULL. | ||
| 378 | * This will usually be called from within the s_ctrl op. | ||
| 379 | * | ||
| 380 | * This function can be called regardless of whether the control handler | ||
| 381 | * is locked or not. | ||
| 382 | */ | ||
| 383 | void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active); | ||
| 384 | |||
| 385 | /** v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed. | ||
| 386 | * @ctrl: The control to (de)activate. | ||
| 387 | * @grabbed: True if the control should become grabbed. | ||
| 388 | * | ||
| 389 | * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically. | ||
| 390 | * Does nothing if @ctrl == NULL. | ||
| 391 | * This will usually be called when starting or stopping streaming in the | ||
| 392 | * driver. | ||
| 393 | * | ||
| 394 | * This function can be called regardless of whether the control handler | ||
| 395 | * is locked or not. | ||
| 396 | */ | ||
| 397 | void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed); | ||
| 398 | |||
| 399 | /** v4l2_ctrl_lock() - Helper function to lock the handler | ||
| 400 | * associated with the control. | ||
| 401 | * @ctrl: The control to lock. | ||
| 402 | */ | ||
| 403 | static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl) | ||
| 404 | { | ||
| 405 | mutex_lock(&ctrl->handler->lock); | ||
| 406 | } | ||
| 407 | |||
| 408 | /** v4l2_ctrl_lock() - Helper function to unlock the handler | ||
| 409 | * associated with the control. | ||
| 410 | * @ctrl: The control to unlock. | ||
| 411 | */ | ||
| 412 | static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) | ||
| 413 | { | ||
| 414 | mutex_unlock(&ctrl->handler->lock); | ||
| 415 | } | ||
| 416 | |||
| 417 | /** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver. | ||
| 418 | * @ctrl: The control. | ||
| 419 | * | ||
| 420 | * This returns the control's value safely by going through the control | ||
| 421 | * framework. This function will lock the control's handler, so it cannot be | ||
| 422 | * used from within the &v4l2_ctrl_ops functions. | ||
| 423 | * | ||
| 424 | * This function is for integer type controls only. | ||
| 425 | */ | ||
| 426 | s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl); | ||
| 427 | |||
| 428 | /** v4l2_ctrl_s_ctrl() - Helper function to set the control's value from within a driver. | ||
| 429 | * @ctrl: The control. | ||
| 430 | * @val: The new value. | ||
| 431 | * | ||
| 432 | * This set the control's new value safely by going through the control | ||
| 433 | * framework. This function will lock the control's handler, so it cannot be | ||
| 434 | * used from within the &v4l2_ctrl_ops functions. | ||
| 435 | * | ||
| 436 | * This function is for integer type controls only. | ||
| 437 | */ | ||
| 438 | int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val); | ||
| 439 | |||
| 440 | |||
| 441 | /* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */ | ||
| 442 | int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc); | ||
| 443 | int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm); | ||
| 444 | int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl); | ||
| 445 | int v4l2_s_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl); | ||
| 446 | int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c); | ||
| 447 | int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c); | ||
| 448 | int v4l2_s_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c); | ||
| 449 | |||
| 450 | /* Helpers for subdevices. If the associated ctrl_handler == NULL then they | ||
| 451 | will all return -EINVAL. */ | ||
| 452 | int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc); | ||
| 453 | int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm); | ||
| 454 | int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs); | ||
| 455 | int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs); | ||
| 456 | int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs); | ||
| 457 | int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl); | ||
| 458 | int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl); | ||
| 459 | |||
| 460 | #endif | ||
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index bebe44b03e0f..1efcacbed01a 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | struct v4l2_ioctl_callbacks; | 27 | struct v4l2_ioctl_callbacks; |
| 28 | struct video_device; | 28 | struct video_device; |
| 29 | struct v4l2_device; | 29 | struct v4l2_device; |
| 30 | struct v4l2_ctrl_handler; | ||
| 30 | 31 | ||
| 31 | /* Flag to mark the video_device struct as registered. | 32 | /* Flag to mark the video_device struct as registered. |
| 32 | Drivers can clear this flag if they want to block all future | 33 | Drivers can clear this flag if they want to block all future |
| @@ -67,6 +68,9 @@ struct video_device | |||
| 67 | struct device *parent; /* device parent */ | 68 | struct device *parent; /* device parent */ |
| 68 | struct v4l2_device *v4l2_dev; /* v4l2_device parent */ | 69 | struct v4l2_device *v4l2_dev; /* v4l2_device parent */ |
| 69 | 70 | ||
| 71 | /* Control handler associated with this device node. May be NULL. */ | ||
| 72 | struct v4l2_ctrl_handler *ctrl_handler; | ||
| 73 | |||
| 70 | /* device info */ | 74 | /* device info */ |
| 71 | char name[32]; | 75 | char name[32]; |
| 72 | int vfl_type; | 76 | int vfl_type; |
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h index 5d5d550e63ad..8bcbd7a0271c 100644 --- a/include/media/v4l2-device.h +++ b/include/media/v4l2-device.h | |||
| @@ -32,6 +32,8 @@ | |||
| 32 | 32 | ||
| 33 | #define V4L2_DEVICE_NAME_SIZE (20 + 16) | 33 | #define V4L2_DEVICE_NAME_SIZE (20 + 16) |
| 34 | 34 | ||
| 35 | struct v4l2_ctrl_handler; | ||
| 36 | |||
| 35 | struct v4l2_device { | 37 | struct v4l2_device { |
| 36 | /* dev->driver_data points to this struct. | 38 | /* dev->driver_data points to this struct. |
| 37 | Note: dev might be NULL if there is no parent device | 39 | Note: dev might be NULL if there is no parent device |
| @@ -47,6 +49,8 @@ struct v4l2_device { | |||
| 47 | /* notify callback called by some sub-devices. */ | 49 | /* notify callback called by some sub-devices. */ |
| 48 | void (*notify)(struct v4l2_subdev *sd, | 50 | void (*notify)(struct v4l2_subdev *sd, |
| 49 | unsigned int notification, void *arg); | 51 | unsigned int notification, void *arg); |
| 52 | /* The control handler. May be NULL. */ | ||
| 53 | struct v4l2_ctrl_handler *ctrl_handler; | ||
| 50 | }; | 54 | }; |
| 51 | 55 | ||
| 52 | /* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev. | 56 | /* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev. |
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 08880dd15d2f..4a97d7341a94 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | #define V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ 0x00000001 | 35 | #define V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ 0x00000001 |
| 36 | 36 | ||
| 37 | struct v4l2_device; | 37 | struct v4l2_device; |
| 38 | struct v4l2_ctrl_handler; | ||
| 38 | struct v4l2_subdev; | 39 | struct v4l2_subdev; |
| 39 | struct tuner_setup; | 40 | struct tuner_setup; |
| 40 | 41 | ||
| @@ -434,6 +435,8 @@ struct v4l2_subdev { | |||
| 434 | u32 flags; | 435 | u32 flags; |
| 435 | struct v4l2_device *v4l2_dev; | 436 | struct v4l2_device *v4l2_dev; |
| 436 | const struct v4l2_subdev_ops *ops; | 437 | const struct v4l2_subdev_ops *ops; |
| 438 | /* The control handler of this subdev. May be NULL. */ | ||
| 439 | struct v4l2_ctrl_handler *ctrl_handler; | ||
| 437 | /* name must be unique */ | 440 | /* name must be unique */ |
| 438 | char name[V4L2_SUBDEV_NAME_SIZE]; | 441 | char name[V4L2_SUBDEV_NAME_SIZE]; |
| 439 | /* can be used to group similar subdevs, value is driver-specific */ | 442 | /* can be used to group similar subdevs, value is driver-specific */ |
