提交 0996517c 编写于 作者: H Hans Verkuil 提交者: Mauro Carvalho Chehab

V4L/DVB: v4l2: Add new control handling framework

Add a new framework to handle controls which makes life for driver
developers much easier.

Note that this patch moves some of the control support that used to be in
v4l2-common.c to v4l2-ctrls.c. The tables were copied unchanged. The body
of v4l2_ctrl_query_fill() was copied to a new v4l2_ctrl_fill() function
in v4l2-ctrls.c. This new function doesn't use the v4l2_queryctrl
struct anymore, which makes it more general.

The remainder of v4l2-ctrls.c is all new. Highlights include:

- No need to implement VIDIOC_QUERYCTRL, QUERYMENU, S_CTRL, G_CTRL,
  S_EXT_CTRLS, G_EXT_CTRLS or TRY_EXT_CTRLS in either bridge drivers
  or subdevs. New wrapper functions are provided that can just be plugged in.
  Once everything has been converted these wrapper functions can be removed as well.

- When subdevices are added their controls can be automatically merged
  with the bridge driver's controls.

- Most drivers just need to implement s_ctrl to set the controls.
  The framework handles the locking and tries to be as 'atomic' as possible.

- Ready for the subdev device nodes: the same mechanism applies to subdevs
  and their device nodes as well. Sub-device drivers can make controls
  local, preventing them from being merged with bridge drivers.

- Takes care of backwards compatibility handling of VIDIOC_S_CTRL and
  VIDIOC_G_CTRL. Handling of V4L2_CID_PRIVATE_BASE is fully transparent.
  CTRL_CLASS controls are automatically added.
Signed-off-by: NHans Verkuil <hverkuil@xs4all.nl>
Reviewed-by: NLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: NMauro Carvalho Chehab <mchehab@redhat.com>
上级 03e30ca5
......@@ -11,7 +11,7 @@ stkwebcam-objs := stk-webcam.o stk-sensor.o
omap2cam-objs := omap24xxcam.o omap24xxcam-dma.o
videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \
v4l2-event.o
v4l2-event.o v4l2-ctrls.o
# V4L2 core modules
......
......@@ -62,6 +62,7 @@
#define __OLD_VIDIOC_ /* To allow fixing old calls*/
#include <media/v4l2-common.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-chip-ident.h>
#include <linux/videodev2.h>
......@@ -172,487 +173,17 @@ int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
}
EXPORT_SYMBOL(v4l2_ctrl_check);
/* Returns NULL or a character pointer array containing the menu for
the given control ID. The pointer array ends with a NULL pointer.
An empty string signifies a menu entry that is invalid. This allows
drivers to disable certain options if it is not supported. */
const char **v4l2_ctrl_get_menu(u32 id)
{
static const char *mpeg_audio_sampling_freq[] = {
"44.1 kHz",
"48 kHz",
"32 kHz",
NULL
};
static const char *mpeg_audio_encoding[] = {
"MPEG-1/2 Layer I",
"MPEG-1/2 Layer II",
"MPEG-1/2 Layer III",
"MPEG-2/4 AAC",
"AC-3",
NULL
};
static const char *mpeg_audio_l1_bitrate[] = {
"32 kbps",
"64 kbps",
"96 kbps",
"128 kbps",
"160 kbps",
"192 kbps",
"224 kbps",
"256 kbps",
"288 kbps",
"320 kbps",
"352 kbps",
"384 kbps",
"416 kbps",
"448 kbps",
NULL
};
static const char *mpeg_audio_l2_bitrate[] = {
"32 kbps",
"48 kbps",
"56 kbps",
"64 kbps",
"80 kbps",
"96 kbps",
"112 kbps",
"128 kbps",
"160 kbps",
"192 kbps",
"224 kbps",
"256 kbps",
"320 kbps",
"384 kbps",
NULL
};
static const char *mpeg_audio_l3_bitrate[] = {
"32 kbps",
"40 kbps",
"48 kbps",
"56 kbps",
"64 kbps",
"80 kbps",
"96 kbps",
"112 kbps",
"128 kbps",
"160 kbps",
"192 kbps",
"224 kbps",
"256 kbps",
"320 kbps",
NULL
};
static const char *mpeg_audio_ac3_bitrate[] = {
"32 kbps",
"40 kbps",
"48 kbps",
"56 kbps",
"64 kbps",
"80 kbps",
"96 kbps",
"112 kbps",
"128 kbps",
"160 kbps",
"192 kbps",
"224 kbps",
"256 kbps",
"320 kbps",
"384 kbps",
"448 kbps",
"512 kbps",
"576 kbps",
"640 kbps",
NULL
};
static const char *mpeg_audio_mode[] = {
"Stereo",
"Joint Stereo",
"Dual",
"Mono",
NULL
};
static const char *mpeg_audio_mode_extension[] = {
"Bound 4",
"Bound 8",
"Bound 12",
"Bound 16",
NULL
};
static const char *mpeg_audio_emphasis[] = {
"No Emphasis",
"50/15 us",
"CCITT J17",
NULL
};
static const char *mpeg_audio_crc[] = {
"No CRC",
"16-bit CRC",
NULL
};
static const char *mpeg_video_encoding[] = {
"MPEG-1",
"MPEG-2",
"MPEG-4 AVC",
NULL
};
static const char *mpeg_video_aspect[] = {
"1x1",
"4x3",
"16x9",
"2.21x1",
NULL
};
static const char *mpeg_video_bitrate_mode[] = {
"Variable Bitrate",
"Constant Bitrate",
NULL
};
static const char *mpeg_stream_type[] = {
"MPEG-2 Program Stream",
"MPEG-2 Transport Stream",
"MPEG-1 System Stream",
"MPEG-2 DVD-compatible Stream",
"MPEG-1 VCD-compatible Stream",
"MPEG-2 SVCD-compatible Stream",
NULL
};
static const char *mpeg_stream_vbi_fmt[] = {
"No VBI",
"Private packet, IVTV format",
NULL
};
static const char *camera_power_line_frequency[] = {
"Disabled",
"50 Hz",
"60 Hz",
NULL
};
static const char *camera_exposure_auto[] = {
"Auto Mode",
"Manual Mode",
"Shutter Priority Mode",
"Aperture Priority Mode",
NULL
};
static const char *colorfx[] = {
"None",
"Black & White",
"Sepia",
"Negative",
"Emboss",
"Sketch",
"Sky blue",
"Grass green",
"Skin whiten",
"Vivid",
NULL
};
static const char *tune_preemphasis[] = {
"No preemphasis",
"50 useconds",
"75 useconds",
NULL,
};
switch (id) {
case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
return mpeg_audio_sampling_freq;
case V4L2_CID_MPEG_AUDIO_ENCODING:
return mpeg_audio_encoding;
case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
return mpeg_audio_l1_bitrate;
case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
return mpeg_audio_l2_bitrate;
case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
return mpeg_audio_l3_bitrate;
case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
return mpeg_audio_ac3_bitrate;
case V4L2_CID_MPEG_AUDIO_MODE:
return mpeg_audio_mode;
case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
return mpeg_audio_mode_extension;
case V4L2_CID_MPEG_AUDIO_EMPHASIS:
return mpeg_audio_emphasis;
case V4L2_CID_MPEG_AUDIO_CRC:
return mpeg_audio_crc;
case V4L2_CID_MPEG_VIDEO_ENCODING:
return mpeg_video_encoding;
case V4L2_CID_MPEG_VIDEO_ASPECT:
return mpeg_video_aspect;
case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
return mpeg_video_bitrate_mode;
case V4L2_CID_MPEG_STREAM_TYPE:
return mpeg_stream_type;
case V4L2_CID_MPEG_STREAM_VBI_FMT:
return mpeg_stream_vbi_fmt;
case V4L2_CID_POWER_LINE_FREQUENCY:
return camera_power_line_frequency;
case V4L2_CID_EXPOSURE_AUTO:
return camera_exposure_auto;
case V4L2_CID_COLORFX:
return colorfx;
case V4L2_CID_TUNE_PREEMPHASIS:
return tune_preemphasis;
default:
return NULL;
}
}
EXPORT_SYMBOL(v4l2_ctrl_get_menu);
/* Return the control name. */
const char *v4l2_ctrl_get_name(u32 id)
{
switch (id) {
/* USER controls */
case V4L2_CID_USER_CLASS: return "User Controls";
case V4L2_CID_BRIGHTNESS: return "Brightness";
case V4L2_CID_CONTRAST: return "Contrast";
case V4L2_CID_SATURATION: return "Saturation";
case V4L2_CID_HUE: return "Hue";
case V4L2_CID_AUDIO_VOLUME: return "Volume";
case V4L2_CID_AUDIO_BALANCE: return "Balance";
case V4L2_CID_AUDIO_BASS: return "Bass";
case V4L2_CID_AUDIO_TREBLE: return "Treble";
case V4L2_CID_AUDIO_MUTE: return "Mute";
case V4L2_CID_AUDIO_LOUDNESS: return "Loudness";
case V4L2_CID_BLACK_LEVEL: return "Black Level";
case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic";
case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance";
case V4L2_CID_RED_BALANCE: return "Red Balance";
case V4L2_CID_BLUE_BALANCE: return "Blue Balance";
case V4L2_CID_GAMMA: return "Gamma";
case V4L2_CID_EXPOSURE: return "Exposure";
case V4L2_CID_AUTOGAIN: return "Gain, Automatic";
case V4L2_CID_GAIN: return "Gain";
case V4L2_CID_HFLIP: return "Horizontal Flip";
case V4L2_CID_VFLIP: return "Vertical Flip";
case V4L2_CID_HCENTER: return "Horizontal Center";
case V4L2_CID_VCENTER: return "Vertical Center";
case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency";
case V4L2_CID_HUE_AUTO: return "Hue, Automatic";
case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature";
case V4L2_CID_SHARPNESS: return "Sharpness";
case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation";
case V4L2_CID_CHROMA_AGC: return "Chroma AGC";
case V4L2_CID_CHROMA_GAIN: return "Chroma Gain";
case V4L2_CID_COLOR_KILLER: return "Color Killer";
case V4L2_CID_COLORFX: return "Color Effects";
case V4L2_CID_AUTOBRIGHTNESS: return "Brightness, Automatic";
case V4L2_CID_BAND_STOP_FILTER: return "Band-Stop Filter";
case V4L2_CID_ROTATE: return "Rotate";
case V4L2_CID_BG_COLOR: return "Background Color";
/* MPEG controls */
case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls";
case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding";
case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate";
case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate";
case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate";
case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate";
case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate";
case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode";
case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis";
case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC";
case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute";
case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding";
case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect";
case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames";
case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size";
case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure";
case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown";
case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode";
case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate";
case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate";
case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute";
case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV";
case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type";
case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID";
case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID";
case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID";
case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID";
case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format";
/* CAMERA controls */
case V4L2_CID_CAMERA_CLASS: return "Camera Controls";
case V4L2_CID_EXPOSURE_AUTO: return "Auto Exposure";
case V4L2_CID_EXPOSURE_ABSOLUTE: return "Exposure Time, Absolute";
case V4L2_CID_EXPOSURE_AUTO_PRIORITY: return "Exposure, Dynamic Framerate";
case V4L2_CID_PAN_RELATIVE: return "Pan, Relative";
case V4L2_CID_TILT_RELATIVE: return "Tilt, Relative";
case V4L2_CID_PAN_RESET: return "Pan, Reset";
case V4L2_CID_TILT_RESET: return "Tilt, Reset";
case V4L2_CID_PAN_ABSOLUTE: return "Pan, Absolute";
case V4L2_CID_TILT_ABSOLUTE: return "Tilt, Absolute";
case V4L2_CID_FOCUS_ABSOLUTE: return "Focus, Absolute";
case V4L2_CID_FOCUS_RELATIVE: return "Focus, Relative";
case V4L2_CID_FOCUS_AUTO: return "Focus, Automatic";
case V4L2_CID_IRIS_ABSOLUTE: return "Iris, Absolute";
case V4L2_CID_IRIS_RELATIVE: return "Iris, Relative";
case V4L2_CID_ZOOM_ABSOLUTE: return "Zoom, Absolute";
case V4L2_CID_ZOOM_RELATIVE: return "Zoom, Relative";
case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous";
case V4L2_CID_PRIVACY: return "Privacy";
/* FM Radio Modulator control */
case V4L2_CID_FM_TX_CLASS: return "FM Radio Modulator Controls";
case V4L2_CID_RDS_TX_DEVIATION: return "RDS Signal Deviation";
case V4L2_CID_RDS_TX_PI: return "RDS Program ID";
case V4L2_CID_RDS_TX_PTY: return "RDS Program Type";
case V4L2_CID_RDS_TX_PS_NAME: return "RDS PS Name";
case V4L2_CID_RDS_TX_RADIO_TEXT: return "RDS Radio Text";
case V4L2_CID_AUDIO_LIMITER_ENABLED: return "Audio Limiter Feature Enabled";
case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: return "Audio Limiter Release Time";
case V4L2_CID_AUDIO_LIMITER_DEVIATION: return "Audio Limiter Deviation";
case V4L2_CID_AUDIO_COMPRESSION_ENABLED: return "Audio Compression Feature Enabled";
case V4L2_CID_AUDIO_COMPRESSION_GAIN: return "Audio Compression Gain";
case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: return "Audio Compression Threshold";
case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: return "Audio Compression Attack Time";
case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: return "Audio Compression Release Time";
case V4L2_CID_PILOT_TONE_ENABLED: return "Pilot Tone Feature Enabled";
case V4L2_CID_PILOT_TONE_DEVIATION: return "Pilot Tone Deviation";
case V4L2_CID_PILOT_TONE_FREQUENCY: return "Pilot Tone Frequency";
case V4L2_CID_TUNE_PREEMPHASIS: return "Pre-emphasis settings";
case V4L2_CID_TUNE_POWER_LEVEL: return "Tune Power Level";
case V4L2_CID_TUNE_ANTENNA_CAPACITOR: return "Tune Antenna Capacitor";
default:
return NULL;
}
}
EXPORT_SYMBOL(v4l2_ctrl_get_name);
/* Fill in a struct v4l2_queryctrl */
int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
{
const char *name = v4l2_ctrl_get_name(qctrl->id);
const char *name;
v4l2_ctrl_fill(qctrl->id, &name, &qctrl->type,
&min, &max, &step, &def, &qctrl->flags);
qctrl->flags = 0;
if (name == NULL)
return -EINVAL;
switch (qctrl->id) {
case V4L2_CID_AUDIO_MUTE:
case V4L2_CID_AUDIO_LOUDNESS:
case V4L2_CID_AUTO_WHITE_BALANCE:
case V4L2_CID_AUTOGAIN:
case V4L2_CID_HFLIP:
case V4L2_CID_VFLIP:
case V4L2_CID_HUE_AUTO:
case V4L2_CID_CHROMA_AGC:
case V4L2_CID_COLOR_KILLER:
case V4L2_CID_MPEG_AUDIO_MUTE:
case V4L2_CID_MPEG_VIDEO_MUTE:
case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
case V4L2_CID_MPEG_VIDEO_PULLDOWN:
case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
case V4L2_CID_FOCUS_AUTO:
case V4L2_CID_PRIVACY:
case V4L2_CID_AUDIO_LIMITER_ENABLED:
case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
case V4L2_CID_PILOT_TONE_ENABLED:
qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
min = 0;
max = step = 1;
break;
case V4L2_CID_PAN_RESET:
case V4L2_CID_TILT_RESET:
qctrl->type = V4L2_CTRL_TYPE_BUTTON;
qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
min = max = step = def = 0;
break;
case V4L2_CID_POWER_LINE_FREQUENCY:
case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
case V4L2_CID_MPEG_AUDIO_ENCODING:
case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
case V4L2_CID_MPEG_AUDIO_MODE:
case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
case V4L2_CID_MPEG_AUDIO_EMPHASIS:
case V4L2_CID_MPEG_AUDIO_CRC:
case V4L2_CID_MPEG_VIDEO_ENCODING:
case V4L2_CID_MPEG_VIDEO_ASPECT:
case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
case V4L2_CID_MPEG_STREAM_TYPE:
case V4L2_CID_MPEG_STREAM_VBI_FMT:
case V4L2_CID_EXPOSURE_AUTO:
case V4L2_CID_COLORFX:
case V4L2_CID_TUNE_PREEMPHASIS:
qctrl->type = V4L2_CTRL_TYPE_MENU;
step = 1;
break;
case V4L2_CID_RDS_TX_PS_NAME:
case V4L2_CID_RDS_TX_RADIO_TEXT:
qctrl->type = V4L2_CTRL_TYPE_STRING;
break;
case V4L2_CID_USER_CLASS:
case V4L2_CID_CAMERA_CLASS:
case V4L2_CID_MPEG_CLASS:
case V4L2_CID_FM_TX_CLASS:
qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
min = max = step = def = 0;
break;
case V4L2_CID_BG_COLOR:
qctrl->type = V4L2_CTRL_TYPE_INTEGER;
step = 1;
min = 0;
/* Max is calculated as RGB888 that is 2^24 */
max = 0xFFFFFF;
break;
default:
qctrl->type = V4L2_CTRL_TYPE_INTEGER;
break;
}
switch (qctrl->id) {
case V4L2_CID_MPEG_AUDIO_ENCODING:
case V4L2_CID_MPEG_AUDIO_MODE:
case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
case V4L2_CID_MPEG_VIDEO_B_FRAMES:
case V4L2_CID_MPEG_STREAM_TYPE:
qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
break;
case V4L2_CID_AUDIO_VOLUME:
case V4L2_CID_AUDIO_BALANCE:
case V4L2_CID_AUDIO_BASS:
case V4L2_CID_AUDIO_TREBLE:
case V4L2_CID_BRIGHTNESS:
case V4L2_CID_CONTRAST:
case V4L2_CID_SATURATION:
case V4L2_CID_HUE:
case V4L2_CID_RED_BALANCE:
case V4L2_CID_BLUE_BALANCE:
case V4L2_CID_GAMMA:
case V4L2_CID_SHARPNESS:
case V4L2_CID_CHROMA_GAIN:
case V4L2_CID_RDS_TX_DEVIATION:
case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
case V4L2_CID_AUDIO_LIMITER_DEVIATION:
case V4L2_CID_AUDIO_COMPRESSION_GAIN:
case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
case V4L2_CID_PILOT_TONE_DEVIATION:
case V4L2_CID_PILOT_TONE_FREQUENCY:
case V4L2_CID_TUNE_POWER_LEVEL:
case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
break;
case V4L2_CID_PAN_RELATIVE:
case V4L2_CID_TILT_RELATIVE:
case V4L2_CID_FOCUS_RELATIVE:
case V4L2_CID_IRIS_RELATIVE:
case V4L2_CID_ZOOM_RELATIVE:
qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
break;
}
qctrl->minimum = min;
qctrl->maximum = max;
qctrl->step = step;
......
此差异已折叠。
/*
V4L2 controls support header.
Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _V4L2_CTRLS_H
#define _V4L2_CTRLS_H
#include <linux/list.h>
#include <linux/device.h>
/* forward references */
struct v4l2_ctrl_handler;
struct v4l2_ctrl;
struct video_device;
struct v4l2_subdev;
/** struct v4l2_ctrl_ops - The control operations that the driver has to provide.
* @g_volatile_ctrl: Get a new value for this control. Generally only relevant
* for volatile (and usually read-only) controls such as a control
* that returns the current signal strength which changes
* continuously.
* If not set, then the currently cached value will be returned.
* @try_ctrl: Test whether the control's value is valid. Only relevant when
* the usual min/max/step checks are not sufficient.
* @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
* ctrl->handler->lock is held when these ops are called, so no
* one else can access controls owned by that handler.
*/
struct v4l2_ctrl_ops {
int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
int (*try_ctrl)(struct v4l2_ctrl *ctrl);
int (*s_ctrl)(struct v4l2_ctrl *ctrl);
};
/** struct v4l2_ctrl - The control structure.
* @node: The list node.
* @handler: The handler that owns the control.
* @cluster: Point to start of cluster array.
* @ncontrols: Number of controls in cluster array.
* @has_new: Internal flag: set when there is a valid new value.
* @done: Internal flag: set for each processed control.
* @is_private: If set, then this control is private to its handler and it
* will not be added to any other handlers. Drivers can set
* this flag.
* @is_volatile: If set, then this control is volatile. This means that the
* control's current value cannot be cached and needs to be
* retrieved through the g_volatile_ctrl op. Drivers can set
* this flag.
* @ops: The control ops.
* @id: The control ID.
* @name: The control name.
* @type: The control type.
* @minimum: The control's minimum value.
* @maximum: The control's maximum value.
* @default_value: The control's default value.
* @step: The control's step value for non-menu controls.
* @menu_skip_mask: The control's skip mask for menu controls. This makes it
* easy to skip menu items that are not valid. If bit X is set,
* then menu item X is skipped. Of course, this only works for
* menus with <= 32 menu items. There are no menus that come
* close to that number, so this is OK. Should we ever need more,
* then this will have to be extended to a u64 or a bit array.
* @qmenu: A const char * array for all menu items. Array entries that are
* empty strings ("") correspond to non-existing menu items (this
* is in addition to the menu_skip_mask above). The last entry
* must be NULL.
* @flags: The control's flags.
* @cur: The control's current value.
* @val: The control's new s32 value.
* @val64: The control's new s64 value.
* @string: The control's new string value.
* @priv: The control's private pointer. For use by the driver. It is
* untouched by the control framework. Note that this pointer is
* not freed when the control is deleted. Should this be needed
* then a new internal bitfield can be added to tell the framework
* to free this pointer.
*/
struct v4l2_ctrl {
/* Administrative fields */
struct list_head node;
struct v4l2_ctrl_handler *handler;
struct v4l2_ctrl **cluster;
unsigned ncontrols;
unsigned int has_new:1;
unsigned int done:1;
unsigned int is_private:1;
unsigned int is_volatile:1;
const struct v4l2_ctrl_ops *ops;
u32 id;
const char *name;
enum v4l2_ctrl_type type;
s32 minimum, maximum, default_value;
union {
u32 step;
u32 menu_skip_mask;
};
const char **qmenu;
unsigned long flags;
union {
s32 val;
s64 val64;
char *string;
} cur;
union {
s32 val;
s64 val64;
char *string;
};
void *priv;
};
/** struct v4l2_ctrl_ref - The control reference.
* @node: List node for the sorted list.
* @next: Single-link list node for the hash.
* @ctrl: The actual control information.
*
* Each control handler has a list of these refs. The list_head is used to
* keep a sorted-by-control-ID list of all controls, while the next pointer
* is used to link the control in the hash's bucket.
*/
struct v4l2_ctrl_ref {
struct list_head node;
struct v4l2_ctrl_ref *next;
struct v4l2_ctrl *ctrl;
};
/** struct v4l2_ctrl_handler - The control handler keeps track of all the
* controls: both the controls owned by the handler and those inherited
* from other handlers.
* @lock: Lock to control access to this handler and its controls.
* @ctrls: The list of controls owned by this handler.
* @ctrl_refs: The list of control references.
* @cached: The last found control reference. It is common that the same
* control is needed multiple times, so this is a simple
* optimization.
* @buckets: Buckets for the hashing. Allows for quick control lookup.
* @nr_of_buckets: Total number of buckets in the array.
* @error: The error code of the first failed control addition.
*/
struct v4l2_ctrl_handler {
struct mutex lock;
struct list_head ctrls;
struct list_head ctrl_refs;
struct v4l2_ctrl_ref *cached;
struct v4l2_ctrl_ref **buckets;
u16 nr_of_buckets;
int error;
};
/** struct v4l2_ctrl_config - Control configuration structure.
* @ops: The control ops.
* @id: The control ID.
* @name: The control name.
* @type: The control type.
* @min: The control's minimum value.
* @max: The control's maximum value.
* @step: The control's step value for non-menu controls.
* @def: The control's default value.
* @flags: The control's flags.
* @menu_skip_mask: The control's skip mask for menu controls. This makes it
* easy to skip menu items that are not valid. If bit X is set,
* then menu item X is skipped. Of course, this only works for
* menus with <= 32 menu items. There are no menus that come
* close to that number, so this is OK. Should we ever need more,
* then this will have to be extended to a u64 or a bit array.
* @qmenu: A const char * array for all menu items. Array entries that are
* empty strings ("") correspond to non-existing menu items (this
* is in addition to the menu_skip_mask above). The last entry
* must be NULL.
* @is_private: If set, then this control is private to its handler and it
* will not be added to any other handlers.
* @is_volatile: If set, then this control is volatile. This means that the
* control's current value cannot be cached and needs to be
* retrieved through the g_volatile_ctrl op.
*/
struct v4l2_ctrl_config {
const struct v4l2_ctrl_ops *ops;
u32 id;
const char *name;
enum v4l2_ctrl_type type;
s32 min;
s32 max;
u32 step;
s32 def;
u32 flags;
u32 menu_skip_mask;
const char **qmenu;
unsigned int is_private:1;
unsigned int is_volatile:1;
};
/** v4l2_ctrl_fill() - Fill in the control fields based on the control ID.
*
* This works for all standard V4L2 controls.
* For non-standard controls it will only fill in the given arguments
* and @name will be NULL.
*
* This function will overwrite the contents of @name, @type and @flags.
* The contents of @min, @max, @step and @def may be modified depending on
* the type.
*
* Do not use in drivers! It is used internally for backwards compatibility
* control handling only. Once all drivers are converted to use the new
* control framework this function will no longer be exported.
*/
void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags);
/** v4l2_ctrl_handler_init() - Initialize the control handler.
* @hdl: The control handler.
* @nr_of_controls_hint: A hint of how many controls this handler is
* expected to refer to. This is the total number, so including
* any inherited controls. It doesn't have to be precise, but if
* it is way off, then you either waste memory (too many buckets
* are allocated) or the control lookup becomes slower (not enough
* buckets are allocated, so there are more slow list lookups).
* It will always work, though.
*
* Returns an error if the buckets could not be allocated. This error will
* also be stored in @hdl->error.
*/
int v4l2_ctrl_handler_init(struct v4l2_ctrl_handler *hdl,
unsigned nr_of_controls_hint);
/** v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
* the control list.
* @hdl: The control handler.
*
* Does nothing if @hdl == NULL.
*/
void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
/** v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
* to the handler to initialize the hardware to the current control values.
* @hdl: The control handler.
*
* Button controls will be skipped, as are read-only controls.
*
* If @hdl == NULL, then this just returns 0.
*/
int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
/** v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
* @hdl: The control handler.
* @prefix: The prefix to use when logging the control values. If the
* prefix does not end with a space, then ": " will be added
* after the prefix. If @prefix == NULL, then no prefix will be
* used.
*
* For use with VIDIOC_LOG_STATUS.
*
* Does nothing if @hdl == NULL.
*/
void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
const char *prefix);
/** v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
* control.
* @hdl: The control handler.
* @cfg: The control's configuration data.
* @priv: The control's driver-specific private data.
*
* If the &v4l2_ctrl struct could not be allocated then NULL is returned
* and @hdl->error is set to the error code (if it wasn't set already).
*/
struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_config *cfg, void *priv);
/** v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu control.
* @hdl: The control handler.
* @ops: The control ops.
* @id: The control ID.
* @min: The control's minimum value.
* @max: The control's maximum value.
* @step: The control's step value
* @def: The control's default value.
*
* If the &v4l2_ctrl struct could not be allocated, or the control
* ID is not known, then NULL is returned and @hdl->error is set to the
* appropriate error code (if it wasn't set already).
*
* If @id refers to a menu control, then this function will return NULL.
*
* Use v4l2_ctrl_new_std_menu() when adding menu controls.
*/
struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ops,
u32 id, s32 min, s32 max, u32 step, s32 def);
/** v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control.
* @hdl: The control handler.
* @ops: The control ops.
* @id: The control ID.
* @max: The control's maximum value.
* @mask: The control's skip mask for menu controls. This makes it
* easy to skip menu items that are not valid. If bit X is set,
* then menu item X is skipped. Of course, this only works for
* menus with <= 32 menu items. There are no menus that come
* close to that number, so this is OK. Should we ever need more,
* then this will have to be extended to a u64 or a bit array.
* @def: The control's default value.
*
* Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
* determines which menu items are to be skipped.
*
* If @id refers to a non-menu control, then this function will return NULL.
*/
struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ops,
u32 id, s32 max, s32 mask, s32 def);
/** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler.
* @hdl: The control handler.
* @ctrl: The control to add.
*
* It will return NULL if it was unable to add the control reference.
* If the control already belonged to the handler, then it will do
* nothing and just return @ctrl.
*/
struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl *ctrl);
/** v4l2_ctrl_add_handler() - Add all controls from handler @add to
* handler @hdl.
* @hdl: The control handler.
* @add: The control handler whose controls you want to add to
* the @hdl control handler.
*
* Does nothing if either of the two is a NULL pointer.
* In case of an error @hdl->error will be set to the error code (if it
* wasn't set already).
*/
int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl_handler *add);
/** v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster.
* @ncontrols: The number of controls in this cluster.
* @controls: The cluster control array of size @ncontrols.
*/
void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls);
/** v4l2_ctrl_find() - Find a control with the given ID.
* @hdl: The control handler.
* @id: The control ID to find.
*
* If @hdl == NULL this will return NULL as well. Will lock the handler so
* do not use from inside &v4l2_ctrl_ops.
*/
struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
/** v4l2_ctrl_activate() - Make the control active or inactive.
* @ctrl: The control to (de)activate.
* @active: True if the control should become active.
*
* This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
* Does nothing if @ctrl == NULL.
* This will usually be called from within the s_ctrl op.
*
* This function can be called regardless of whether the control handler
* is locked or not.
*/
void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
/** v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
* @ctrl: The control to (de)activate.
* @grabbed: True if the control should become grabbed.
*
* This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
* Does nothing if @ctrl == NULL.
* This will usually be called when starting or stopping streaming in the
* driver.
*
* This function can be called regardless of whether the control handler
* is locked or not.
*/
void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
/** v4l2_ctrl_lock() - Helper function to lock the handler
* associated with the control.
* @ctrl: The control to lock.
*/
static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
{
mutex_lock(&ctrl->handler->lock);
}
/** v4l2_ctrl_lock() - Helper function to unlock the handler
* associated with the control.
* @ctrl: The control to unlock.
*/
static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
{
mutex_unlock(&ctrl->handler->lock);
}
/** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver.
* @ctrl: The control.
*
* This returns the control's value safely by going through the control
* framework. This function will lock the control's handler, so it cannot be
* used from within the &v4l2_ctrl_ops functions.
*
* This function is for integer type controls only.
*/
s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
/** v4l2_ctrl_s_ctrl() - Helper function to set the control's value from within a driver.
* @ctrl: The control.
* @val: The new value.
*
* This set the control's new value safely by going through the control
* framework. This function will lock the control's handler, so it cannot be
* used from within the &v4l2_ctrl_ops functions.
*
* This function is for integer type controls only.
*/
int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
/* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */
int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
int v4l2_s_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
int v4l2_s_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
/* Helpers for subdevices. If the associated ctrl_handler == NULL then they
will all return -EINVAL. */
int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc);
int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm);
int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
#endif
......@@ -27,6 +27,7 @@
struct v4l2_ioctl_callbacks;
struct video_device;
struct v4l2_device;
struct v4l2_ctrl_handler;
/* Flag to mark the video_device struct as registered.
Drivers can clear this flag if they want to block all future
......@@ -67,6 +68,9 @@ struct video_device
struct device *parent; /* device parent */
struct v4l2_device *v4l2_dev; /* v4l2_device parent */
/* Control handler associated with this device node. May be NULL. */
struct v4l2_ctrl_handler *ctrl_handler;
/* device info */
char name[32];
int vfl_type;
......
......@@ -32,6 +32,8 @@
#define V4L2_DEVICE_NAME_SIZE (20 + 16)
struct v4l2_ctrl_handler;
struct v4l2_device {
/* dev->driver_data points to this struct.
Note: dev might be NULL if there is no parent device
......@@ -47,6 +49,8 @@ struct v4l2_device {
/* notify callback called by some sub-devices. */
void (*notify)(struct v4l2_subdev *sd,
unsigned int notification, void *arg);
/* The control handler. May be NULL. */
struct v4l2_ctrl_handler *ctrl_handler;
};
/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev.
......
......@@ -35,6 +35,7 @@
#define V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ 0x00000001
struct v4l2_device;
struct v4l2_ctrl_handler;
struct v4l2_subdev;
struct tuner_setup;
......@@ -434,6 +435,8 @@ struct v4l2_subdev {
u32 flags;
struct v4l2_device *v4l2_dev;
const struct v4l2_subdev_ops *ops;
/* The control handler of this subdev. May be NULL. */
struct v4l2_ctrl_handler *ctrl_handler;
/* name must be unique */
char name[V4L2_SUBDEV_NAME_SIZE];
/* can be used to group similar subdevs, value is driver-specific */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册