diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-12-30 20:41:32 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-12-30 20:41:32 -0500 |
commit | f54a6ec0fd85002d94d05b4bb679508eeb066683 (patch) | |
tree | 0f24dd66cce563d2c5e7656c2489e5b96eef31f9 /include/media/v4l2-subdev.h | |
parent | 5ed1836814d908f45cafde0e79cb85314ab9d41d (diff) | |
parent | 134179823b3ca9c8b98e0631906459dbb022ff9b (diff) |
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6: (583 commits)
V4L/DVB (10130): use USB API functions rather than constants
V4L/DVB (10129): dvb: remove deprecated use of RW_LOCK_UNLOCKED in frontends
V4L/DVB (10128): modify V4L documentation to be a valid XHTML
V4L/DVB (10127): stv06xx: Avoid having y unitialized
V4L/DVB (10125): em28xx: Don't do AC97 vendor detection for i2s audio devices
V4L/DVB (10124): em28xx: expand output formats available
V4L/DVB (10123): em28xx: fix reversed definitions of I2S audio modes
V4L/DVB (10122): em28xx: don't load em28xx-alsa for em2870 based devices
V4L/DVB (10121): em28xx: remove worthless Pinnacle PCTV HD Mini 80e device profile
V4L/DVB (10120): em28xx: remove redundant Pinnacle Dazzle DVC 100 profile
V4L/DVB (10119): em28xx: fix corrupted XCLK value
V4L/DVB (10118): zoran: fix warning for a variable not used
V4L/DVB (10116): af9013: Fix gcc false warnings
V4L/DVB (10111a): usbvideo.h: remove an useless blank line
V4L/DVB (10111): quickcam_messenger.c: fix a warning
V4L/DVB (10110): v4l2-ioctl: Fix warnings when using .unlocked_ioctl = __video_ioctl2
V4L/DVB (10109): anysee: Fix usage of an unitialized function
V4L/DVB (10104): uvcvideo: Add support for video output devices
V4L/DVB (10102): uvcvideo: Ignore interrupt endpoint for built-in iSight webcams.
V4L/DVB (10101): uvcvideo: Fix bulk URB processing when the header is erroneous
...
Diffstat (limited to 'include/media/v4l2-subdev.h')
-rw-r--r-- | include/media/v4l2-subdev.h | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h new file mode 100644 index 000000000000..ceef016bb0b7 --- /dev/null +++ b/include/media/v4l2-subdev.h | |||
@@ -0,0 +1,189 @@ | |||
1 | /* | ||
2 | V4L2 sub-device support header. | ||
3 | |||
4 | Copyright (C) 2008 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_SUBDEV_H | ||
22 | #define _V4L2_SUBDEV_H | ||
23 | |||
24 | #include <media/v4l2-common.h> | ||
25 | |||
26 | struct v4l2_device; | ||
27 | struct v4l2_subdev; | ||
28 | struct tuner_setup; | ||
29 | |||
30 | /* Sub-devices are devices that are connected somehow to the main bridge | ||
31 | device. These devices are usually audio/video muxers/encoders/decoders or | ||
32 | sensors and webcam controllers. | ||
33 | |||
34 | Usually these devices are controlled through an i2c bus, but other busses | ||
35 | may also be used. | ||
36 | |||
37 | The v4l2_subdev struct provides a way of accessing these devices in a | ||
38 | generic manner. Most operations that these sub-devices support fall in | ||
39 | a few categories: core ops, audio ops, video ops and tuner ops. | ||
40 | |||
41 | More categories can be added if needed, although this should remain a | ||
42 | limited set (no more than approx. 8 categories). | ||
43 | |||
44 | Each category has its own set of ops that subdev drivers can implement. | ||
45 | |||
46 | A subdev driver can leave the pointer to the category ops NULL if | ||
47 | it does not implement them (e.g. an audio subdev will generally not | ||
48 | implement the video category ops). The exception is the core category: | ||
49 | this must always be present. | ||
50 | |||
51 | These ops are all used internally so it is no problem to change, remove | ||
52 | or add ops or move ops from one to another category. Currently these | ||
53 | ops are based on the original ioctls, but since ops are not limited to | ||
54 | one argument there is room for improvement here once all i2c subdev | ||
55 | drivers are converted to use these ops. | ||
56 | */ | ||
57 | |||
58 | /* Core ops: it is highly recommended to implement at least these ops: | ||
59 | |||
60 | g_chip_ident | ||
61 | log_status | ||
62 | g_register | ||
63 | s_register | ||
64 | |||
65 | This provides basic debugging support. | ||
66 | |||
67 | The ioctl ops is meant for generic ioctl-like commands. Depending on | ||
68 | the use-case it might be better to use subdev-specific ops (currently | ||
69 | not yet implemented) since ops provide proper type-checking. | ||
70 | */ | ||
71 | struct v4l2_subdev_core_ops { | ||
72 | int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_chip_ident *chip); | ||
73 | int (*log_status)(struct v4l2_subdev *sd); | ||
74 | int (*init)(struct v4l2_subdev *sd, u32 val); | ||
75 | int (*s_standby)(struct v4l2_subdev *sd, u32 standby); | ||
76 | int (*reset)(struct v4l2_subdev *sd, u32 val); | ||
77 | int (*s_gpio)(struct v4l2_subdev *sd, u32 val); | ||
78 | int (*queryctrl)(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc); | ||
79 | int (*g_ctrl)(struct v4l2_subdev *sd, struct v4l2_control *ctrl); | ||
80 | int (*s_ctrl)(struct v4l2_subdev *sd, struct v4l2_control *ctrl); | ||
81 | int (*querymenu)(struct v4l2_subdev *sd, struct v4l2_querymenu *qm); | ||
82 | int (*ioctl)(struct v4l2_subdev *sd, unsigned int cmd, void *arg); | ||
83 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
84 | int (*g_register)(struct v4l2_subdev *sd, struct v4l2_register *reg); | ||
85 | int (*s_register)(struct v4l2_subdev *sd, struct v4l2_register *reg); | ||
86 | #endif | ||
87 | }; | ||
88 | |||
89 | struct v4l2_subdev_tuner_ops { | ||
90 | int (*s_mode)(struct v4l2_subdev *sd, enum v4l2_tuner_type); | ||
91 | int (*s_radio)(struct v4l2_subdev *sd); | ||
92 | int (*s_frequency)(struct v4l2_subdev *sd, struct v4l2_frequency *freq); | ||
93 | int (*g_frequency)(struct v4l2_subdev *sd, struct v4l2_frequency *freq); | ||
94 | int (*g_tuner)(struct v4l2_subdev *sd, struct v4l2_tuner *vt); | ||
95 | int (*s_tuner)(struct v4l2_subdev *sd, struct v4l2_tuner *vt); | ||
96 | int (*s_std)(struct v4l2_subdev *sd, v4l2_std_id norm); | ||
97 | int (*s_type_addr)(struct v4l2_subdev *sd, struct tuner_setup *type); | ||
98 | int (*s_config)(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *config); | ||
99 | }; | ||
100 | |||
101 | struct v4l2_subdev_audio_ops { | ||
102 | int (*s_clock_freq)(struct v4l2_subdev *sd, u32 freq); | ||
103 | int (*s_i2s_clock_freq)(struct v4l2_subdev *sd, u32 freq); | ||
104 | int (*s_routing)(struct v4l2_subdev *sd, const struct v4l2_routing *route); | ||
105 | }; | ||
106 | |||
107 | struct v4l2_subdev_video_ops { | ||
108 | int (*s_routing)(struct v4l2_subdev *sd, const struct v4l2_routing *route); | ||
109 | int (*s_crystal_freq)(struct v4l2_subdev *sd, struct v4l2_crystal_freq *freq); | ||
110 | int (*decode_vbi_line)(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi_line); | ||
111 | int (*s_vbi_data)(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *vbi_data); | ||
112 | int (*g_vbi_data)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_data *vbi_data); | ||
113 | int (*g_sliced_vbi_cap)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_cap *cap); | ||
114 | int (*s_std_output)(struct v4l2_subdev *sd, v4l2_std_id std); | ||
115 | int (*s_stream)(struct v4l2_subdev *sd, int enable); | ||
116 | int (*s_fmt)(struct v4l2_subdev *sd, struct v4l2_format *fmt); | ||
117 | int (*g_fmt)(struct v4l2_subdev *sd, struct v4l2_format *fmt); | ||
118 | }; | ||
119 | |||
120 | struct v4l2_subdev_ops { | ||
121 | const struct v4l2_subdev_core_ops *core; | ||
122 | const struct v4l2_subdev_tuner_ops *tuner; | ||
123 | const struct v4l2_subdev_audio_ops *audio; | ||
124 | const struct v4l2_subdev_video_ops *video; | ||
125 | }; | ||
126 | |||
127 | #define V4L2_SUBDEV_NAME_SIZE 32 | ||
128 | |||
129 | /* Each instance of a subdev driver should create this struct, either | ||
130 | stand-alone or embedded in a larger struct. | ||
131 | */ | ||
132 | struct v4l2_subdev { | ||
133 | struct list_head list; | ||
134 | struct module *owner; | ||
135 | struct v4l2_device *dev; | ||
136 | const struct v4l2_subdev_ops *ops; | ||
137 | /* name must be unique */ | ||
138 | char name[V4L2_SUBDEV_NAME_SIZE]; | ||
139 | /* can be used to group similar subdevs, value is driver-specific */ | ||
140 | u32 grp_id; | ||
141 | /* pointer to private data */ | ||
142 | void *priv; | ||
143 | }; | ||
144 | |||
145 | static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p) | ||
146 | { | ||
147 | sd->priv = p; | ||
148 | } | ||
149 | |||
150 | static inline void *v4l2_get_subdevdata(const struct v4l2_subdev *sd) | ||
151 | { | ||
152 | return sd->priv; | ||
153 | } | ||
154 | |||
155 | /* Convert an ioctl-type command to the proper v4l2_subdev_ops function call. | ||
156 | This is used by subdev modules that can be called by both old-style ioctl | ||
157 | commands and through the v4l2_subdev_ops. | ||
158 | |||
159 | The ioctl API of the subdev driver can call this function to call the | ||
160 | right ops based on the ioctl cmd and arg. | ||
161 | |||
162 | Once all subdev drivers have been converted and all drivers no longer | ||
163 | use the ioctl interface, then this function can be removed. | ||
164 | */ | ||
165 | int v4l2_subdev_command(struct v4l2_subdev *sd, unsigned cmd, void *arg); | ||
166 | |||
167 | static inline void v4l2_subdev_init(struct v4l2_subdev *sd, | ||
168 | const struct v4l2_subdev_ops *ops) | ||
169 | { | ||
170 | INIT_LIST_HEAD(&sd->list); | ||
171 | /* ops->core MUST be set */ | ||
172 | BUG_ON(!ops || !ops->core); | ||
173 | sd->ops = ops; | ||
174 | sd->dev = NULL; | ||
175 | sd->name[0] = '\0'; | ||
176 | sd->grp_id = 0; | ||
177 | sd->priv = NULL; | ||
178 | } | ||
179 | |||
180 | /* Call an ops of a v4l2_subdev, doing the right checks against | ||
181 | NULL pointers. | ||
182 | |||
183 | Example: err = v4l2_subdev_call(sd, core, g_chip_ident, &chip); | ||
184 | */ | ||
185 | #define v4l2_subdev_call(sd, o, f, args...) \ | ||
186 | (!(sd) ? -ENODEV : (((sd) && (sd)->ops->o && (sd)->ops->o->f) ? \ | ||
187 | (sd)->ops->o->f((sd) , ##args) : -ENOIOCTLCMD)) | ||
188 | |||
189 | #endif | ||