xref: /openbmc/linux/include/uapi/linux/media.h (revision 10c1d542c7e871865bca381842fd04a92d2b95ec)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * Multimedia device API
4  *
5  * Copyright (C) 2010 Nokia Corporation
6  *
7  * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8  *	     Sakari Ailus <sakari.ailus@iki.fi>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 
24 #ifndef __LINUX_MEDIA_H
25 #define __LINUX_MEDIA_H
26 
27 #ifndef __KERNEL__
28 #include <stdint.h>
29 #endif
30 #include <linux/ioctl.h>
31 #include <linux/types.h>
32 #include <linux/version.h>
33 
34 struct media_device_info {
35 	char driver[16];
36 	char model[32];
37 	char serial[40];
38 	char bus_info[32];
39 	__u32 media_version;
40 	__u32 hw_revision;
41 	__u32 driver_version;
42 	__u32 reserved[31];
43 };
44 
45 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
46 
47 /*
48  * Initial value to be used when a new entity is created
49  * Drivers should change it to something useful
50  */
51 #define MEDIA_ENT_F_UNKNOWN	0x00000000
52 
53 /*
54  * Base number ranges for entity functions
55  *
56  * NOTE: those ranges and entity function number are phased just to
57  * make it easier to maintain this file. Userspace should not rely on
58  * the ranges to identify a group of function types, as newer
59  * functions can be added with any name within the full u32 range.
60  */
61 #define MEDIA_ENT_F_BASE		0x00000000
62 #define MEDIA_ENT_F_OLD_BASE		0x00010000
63 #define MEDIA_ENT_F_OLD_SUBDEV_BASE	0x00020000
64 
65 /*
66  * DVB entities
67  */
68 #define MEDIA_ENT_F_DTV_DEMOD		(MEDIA_ENT_F_BASE + 0x00001)
69 #define MEDIA_ENT_F_TS_DEMUX		(MEDIA_ENT_F_BASE + 0x00002)
70 #define MEDIA_ENT_F_DTV_CA		(MEDIA_ENT_F_BASE + 0x00003)
71 #define MEDIA_ENT_F_DTV_NET_DECAP	(MEDIA_ENT_F_BASE + 0x00004)
72 
73 /*
74  * I/O entities
75  */
76 #define MEDIA_ENT_F_IO_DTV		(MEDIA_ENT_F_BASE + 0x01001)
77 #define MEDIA_ENT_F_IO_VBI		(MEDIA_ENT_F_BASE + 0x01002)
78 #define MEDIA_ENT_F_IO_SWRADIO		(MEDIA_ENT_F_BASE + 0x01003)
79 
80 /*
81  * Analog TV IF-PLL decoders
82  *
83  * It is a responsibility of the master/bridge drivers to create links
84  * for MEDIA_ENT_F_IF_VID_DECODER and MEDIA_ENT_F_IF_AUD_DECODER.
85  */
86 #define MEDIA_ENT_F_IF_VID_DECODER	(MEDIA_ENT_F_BASE + 0x02001)
87 #define MEDIA_ENT_F_IF_AUD_DECODER	(MEDIA_ENT_F_BASE + 0x02002)
88 
89 /*
90  * Audio Entity Functions
91  */
92 #define MEDIA_ENT_F_AUDIO_CAPTURE	(MEDIA_ENT_F_BASE + 0x03001)
93 #define MEDIA_ENT_F_AUDIO_PLAYBACK	(MEDIA_ENT_F_BASE + 0x03002)
94 #define MEDIA_ENT_F_AUDIO_MIXER		(MEDIA_ENT_F_BASE + 0x03003)
95 
96 /*
97  * Processing entities
98  */
99 #define MEDIA_ENT_F_PROC_VIDEO_COMPOSER		(MEDIA_ENT_F_BASE + 0x4001)
100 #define MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER	(MEDIA_ENT_F_BASE + 0x4002)
101 #define MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV	(MEDIA_ENT_F_BASE + 0x4003)
102 #define MEDIA_ENT_F_PROC_VIDEO_LUT		(MEDIA_ENT_F_BASE + 0x4004)
103 #define MEDIA_ENT_F_PROC_VIDEO_SCALER		(MEDIA_ENT_F_BASE + 0x4005)
104 #define MEDIA_ENT_F_PROC_VIDEO_STATISTICS	(MEDIA_ENT_F_BASE + 0x4006)
105 
106 /*
107  * Switch and bridge entitites
108  */
109 #define MEDIA_ENT_F_VID_MUX			(MEDIA_ENT_F_BASE + 0x5001)
110 #define MEDIA_ENT_F_VID_IF_BRIDGE		(MEDIA_ENT_F_BASE + 0x5002)
111 
112 /*
113  * Digital video decoder entities
114  */
115 #define MEDIA_ENT_F_DTV_DECODER			(MEDIA_ENT_F_BASE + 0x6001)
116 
117 /*
118  * Connectors
119  */
120 /* It is a responsibility of the entity drivers to add connectors and links */
121 #ifdef __KERNEL__
122 	/*
123 	 * For now, it should not be used in userspace, as some
124 	 * definitions may change
125 	 */
126 
127 #define MEDIA_ENT_F_CONN_RF		(MEDIA_ENT_F_BASE + 0x30001)
128 #define MEDIA_ENT_F_CONN_SVIDEO		(MEDIA_ENT_F_BASE + 0x30002)
129 #define MEDIA_ENT_F_CONN_COMPOSITE	(MEDIA_ENT_F_BASE + 0x30003)
130 
131 #endif
132 
133 /*
134  * Don't touch on those. The ranges MEDIA_ENT_F_OLD_BASE and
135  * MEDIA_ENT_F_OLD_SUBDEV_BASE are kept to keep backward compatibility
136  * with the legacy v1 API.The number range is out of range by purpose:
137  * several previously reserved numbers got excluded from this range.
138  *
139  * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
140  * in order to preserve backward compatibility.
141  * Drivers must change to the proper subdev type before
142  * registering the entity.
143  */
144 
145 #define MEDIA_ENT_F_IO_V4L  		(MEDIA_ENT_F_OLD_BASE + 1)
146 
147 #define MEDIA_ENT_F_CAM_SENSOR		(MEDIA_ENT_F_OLD_SUBDEV_BASE + 1)
148 #define MEDIA_ENT_F_FLASH		(MEDIA_ENT_F_OLD_SUBDEV_BASE + 2)
149 #define MEDIA_ENT_F_LENS		(MEDIA_ENT_F_OLD_SUBDEV_BASE + 3)
150 #define MEDIA_ENT_F_ATV_DECODER		(MEDIA_ENT_F_OLD_SUBDEV_BASE + 4)
151 /*
152  * It is a responsibility of the master/bridge drivers to add connectors
153  * and links for MEDIA_ENT_F_TUNER. Please notice that some old tuners
154  * may require the usage of separate I2C chips to decode analog TV signals,
155  * when the master/bridge chipset doesn't have its own TV standard decoder.
156  * On such cases, the IF-PLL staging is mapped via one or two entities:
157  * MEDIA_ENT_F_IF_VID_DECODER and/or MEDIA_ENT_F_IF_AUD_DECODER.
158  */
159 #define MEDIA_ENT_F_TUNER		(MEDIA_ENT_F_OLD_SUBDEV_BASE + 5)
160 
161 #define MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_F_OLD_SUBDEV_BASE
162 
163 #if !defined(__KERNEL__) || defined(__NEED_MEDIA_LEGACY_API)
164 
165 /*
166  * Legacy symbols used to avoid userspace compilation breakages
167  *
168  * Those symbols map the entity function into types and should be
169  * used only on legacy programs for legacy hardware. Don't rely
170  * on those for MEDIA_IOC_G_TOPOLOGY.
171  */
172 #define MEDIA_ENT_TYPE_SHIFT		16
173 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
174 #define MEDIA_ENT_SUBTYPE_MASK		0x0000ffff
175 
176 /* End of the old subdev reserved numberspace */
177 #define MEDIA_ENT_T_DEVNODE_UNKNOWN	(MEDIA_ENT_T_DEVNODE | \
178 					 MEDIA_ENT_SUBTYPE_MASK)
179 
180 #define MEDIA_ENT_T_DEVNODE		MEDIA_ENT_F_OLD_BASE
181 #define MEDIA_ENT_T_DEVNODE_V4L		MEDIA_ENT_F_IO_V4L
182 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
183 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
184 #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
185 
186 #define MEDIA_ENT_T_UNKNOWN		MEDIA_ENT_F_UNKNOWN
187 #define MEDIA_ENT_T_V4L2_VIDEO		MEDIA_ENT_F_IO_V4L
188 #define MEDIA_ENT_T_V4L2_SUBDEV		MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN
189 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	MEDIA_ENT_F_CAM_SENSOR
190 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	MEDIA_ENT_F_FLASH
191 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	MEDIA_ENT_F_LENS
192 #define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	MEDIA_ENT_F_ATV_DECODER
193 #define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	MEDIA_ENT_F_TUNER
194 
195 /* Obsolete symbol for media_version, no longer used in the kernel */
196 #define MEDIA_API_VERSION		KERNEL_VERSION(0, 1, 0)
197 #endif
198 
199 /* Entity flags */
200 #define MEDIA_ENT_FL_DEFAULT		(1 << 0)
201 #define MEDIA_ENT_FL_CONNECTOR		(1 << 1)
202 
203 struct media_entity_desc {
204 	__u32 id;
205 	char name[32];
206 	__u32 type;
207 	__u32 revision;
208 	__u32 flags;
209 	__u32 group_id;
210 	__u16 pads;
211 	__u16 links;
212 
213 	__u32 reserved[4];
214 
215 	union {
216 		/* Node specifications */
217 		struct {
218 			__u32 major;
219 			__u32 minor;
220 		} dev;
221 
222 #if 1
223 		/*
224 		 * TODO: this shouldn't have been added without
225 		 * actual drivers that use this. When the first real driver
226 		 * appears that sets this information, special attention
227 		 * should be given whether this information is 1) enough, and
228 		 * 2) can deal with udev rules that rename devices. The struct
229 		 * dev would not be sufficient for this since that does not
230 		 * contain the subdevice information. In addition, struct dev
231 		 * can only refer to a single device, and not to multiple (e.g.
232 		 * pcm and mixer devices).
233 		 *
234 		 * So for now mark this as a to do.
235 		 */
236 		struct {
237 			__u32 card;
238 			__u32 device;
239 			__u32 subdevice;
240 		} alsa;
241 #endif
242 
243 #if 1
244 		/*
245 		 * DEPRECATED: previous node specifications. Kept just to
246 		 * avoid breaking compilation, but media_entity_desc.dev
247 		 * should be used instead. In particular, alsa and dvb
248 		 * fields below are wrong: for all devnodes, there should
249 		 * be just major/minor inside the struct, as this is enough
250 		 * to represent any devnode, no matter what type.
251 		 */
252 		struct {
253 			__u32 major;
254 			__u32 minor;
255 		} v4l;
256 		struct {
257 			__u32 major;
258 			__u32 minor;
259 		} fb;
260 		int dvb;
261 #endif
262 
263 		/* Sub-device specifications */
264 		/* Nothing needed yet */
265 		__u8 raw[184];
266 	};
267 };
268 
269 #define MEDIA_PAD_FL_SINK		(1 << 0)
270 #define MEDIA_PAD_FL_SOURCE		(1 << 1)
271 #define MEDIA_PAD_FL_MUST_CONNECT	(1 << 2)
272 
273 struct media_pad_desc {
274 	__u32 entity;		/* entity ID */
275 	__u16 index;		/* pad index */
276 	__u32 flags;		/* pad flags */
277 	__u32 reserved[2];
278 };
279 
280 #define MEDIA_LNK_FL_ENABLED		(1 << 0)
281 #define MEDIA_LNK_FL_IMMUTABLE		(1 << 1)
282 #define MEDIA_LNK_FL_DYNAMIC		(1 << 2)
283 
284 #define MEDIA_LNK_FL_LINK_TYPE		(0xf << 28)
285 #  define MEDIA_LNK_FL_DATA_LINK	(0 << 28)
286 #  define MEDIA_LNK_FL_INTERFACE_LINK	(1 << 28)
287 
288 struct media_link_desc {
289 	struct media_pad_desc source;
290 	struct media_pad_desc sink;
291 	__u32 flags;
292 	__u32 reserved[2];
293 };
294 
295 struct media_links_enum {
296 	__u32 entity;
297 	/* Should have enough room for pads elements */
298 	struct media_pad_desc __user *pads;
299 	/* Should have enough room for links elements */
300 	struct media_link_desc __user *links;
301 	__u32 reserved[4];
302 };
303 
304 /* Interface type ranges */
305 
306 #define MEDIA_INTF_T_DVB_BASE	0x00000100
307 #define MEDIA_INTF_T_V4L_BASE	0x00000200
308 #define MEDIA_INTF_T_ALSA_BASE	0x00000300
309 
310 /* Interface types */
311 
312 #define MEDIA_INTF_T_DVB_FE    	(MEDIA_INTF_T_DVB_BASE)
313 #define MEDIA_INTF_T_DVB_DEMUX  (MEDIA_INTF_T_DVB_BASE + 1)
314 #define MEDIA_INTF_T_DVB_DVR    (MEDIA_INTF_T_DVB_BASE + 2)
315 #define MEDIA_INTF_T_DVB_CA     (MEDIA_INTF_T_DVB_BASE + 3)
316 #define MEDIA_INTF_T_DVB_NET    (MEDIA_INTF_T_DVB_BASE + 4)
317 
318 #define MEDIA_INTF_T_V4L_VIDEO  (MEDIA_INTF_T_V4L_BASE)
319 #define MEDIA_INTF_T_V4L_VBI    (MEDIA_INTF_T_V4L_BASE + 1)
320 #define MEDIA_INTF_T_V4L_RADIO  (MEDIA_INTF_T_V4L_BASE + 2)
321 #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
322 #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
323 #define MEDIA_INTF_T_V4L_TOUCH	(MEDIA_INTF_T_V4L_BASE + 5)
324 
325 #define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
326 #define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
327 #define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
328 #define MEDIA_INTF_T_ALSA_COMPRESS      (MEDIA_INTF_T_ALSA_BASE + 3)
329 #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
330 #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
331 #define MEDIA_INTF_T_ALSA_SEQUENCER     (MEDIA_INTF_T_ALSA_BASE + 6)
332 #define MEDIA_INTF_T_ALSA_TIMER         (MEDIA_INTF_T_ALSA_BASE + 7)
333 
334 /*
335  * MC next gen API definitions
336  *
337  * NOTE: The declarations below are close to the MC RFC for the Media
338  *	 Controller, the next generation. Yet, there are a few adjustments
339  *	 to do, as we want to be able to have a functional API before
340  *	 the MC properties change. Those will be properly marked below.
341  *	 Please also notice that I removed "num_pads", "num_links",
342  *	 from the proposal, as a proper userspace application will likely
343  *	 use lists for pads/links, just as we intend to do in Kernelspace.
344  *	 The API definition should be freed from fields that are bound to
345  *	 some specific data structure.
346  *
347  * FIXME: Currently, I opted to name the new types as "media_v2", as this
348  *	  won't cause any conflict with the Kernelspace namespace, nor with
349  *	  the previous kAPI media_*_desc namespace. This can be changed
350  *	  later, before the adding this API upstream.
351  */
352 
353 
354 struct media_v2_entity {
355 	__u32 id;
356 	char name[64];		/* FIXME: move to a property? (RFC says so) */
357 	__u32 function;		/* Main function of the entity */
358 	__u32 reserved[6];
359 } __attribute__ ((packed));
360 
361 /* Should match the specific fields at media_intf_devnode */
362 struct media_v2_intf_devnode {
363 	__u32 major;
364 	__u32 minor;
365 } __attribute__ ((packed));
366 
367 struct media_v2_interface {
368 	__u32 id;
369 	__u32 intf_type;
370 	__u32 flags;
371 	__u32 reserved[9];
372 
373 	union {
374 		struct media_v2_intf_devnode devnode;
375 		__u32 raw[16];
376 	};
377 } __attribute__ ((packed));
378 
379 struct media_v2_pad {
380 	__u32 id;
381 	__u32 entity_id;
382 	__u32 flags;
383 	__u32 reserved[5];
384 } __attribute__ ((packed));
385 
386 struct media_v2_link {
387 	__u32 id;
388 	__u32 source_id;
389 	__u32 sink_id;
390 	__u32 flags;
391 	__u32 reserved[6];
392 } __attribute__ ((packed));
393 
394 struct media_v2_topology {
395 	__u64 topology_version;
396 
397 	__u32 num_entities;
398 	__u32 reserved1;
399 	__u64 ptr_entities;
400 
401 	__u32 num_interfaces;
402 	__u32 reserved2;
403 	__u64 ptr_interfaces;
404 
405 	__u32 num_pads;
406 	__u32 reserved3;
407 	__u64 ptr_pads;
408 
409 	__u32 num_links;
410 	__u32 reserved4;
411 	__u64 ptr_links;
412 } __attribute__ ((packed));
413 
414 /* ioctls */
415 
416 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
417 #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct media_entity_desc)
418 #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
419 #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
420 #define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
421 
422 #endif /* __LINUX_MEDIA_H */
423