Linux 6.12-rc1
[linux-block.git] / include / uapi / linux / media.h
CommitLineData
e2be04c7 1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
140d8816
LP
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.
140d8816
LP
18 */
19
20#ifndef __LINUX_MEDIA_H
21#define __LINUX_MEDIA_H
22
23#include <linux/ioctl.h>
24#include <linux/types.h>
140d8816 25
140d8816
LP
26struct media_device_info {
27 char driver[16];
28 char model[32];
29 char serial[40];
30 char bus_info[32];
31 __u32 media_version;
32 __u32 hw_revision;
33 __u32 driver_version;
34 __u32 reserved[31];
35};
36
32fdc0e1 37/*
4ca72efa 38 * Base number ranges for entity functions
32fdc0e1 39 *
ed3056f0
HV
40 * NOTE: Userspace should not rely on these ranges to identify a group
41 * of function types, as newer functions can be added with any name within
42 * the full u32 range.
43 *
44 * Some older functions use the MEDIA_ENT_F_OLD_*_BASE range. Do not
45 * change this, this is for backwards compatibility. When adding new
46 * functions always use MEDIA_ENT_F_BASE.
32fdc0e1 47 */
ed3056f0
HV
48#define MEDIA_ENT_F_BASE 0x00000000
49#define MEDIA_ENT_F_OLD_BASE 0x00010000
50#define MEDIA_ENT_F_OLD_SUBDEV_BASE 0x00020000
32fdc0e1
MCC
51
52/*
ed3056f0
HV
53 * Initial value to be used when a new entity is created
54 * Drivers should change it to something useful.
32fdc0e1 55 */
ed3056f0 56#define MEDIA_ENT_F_UNKNOWN MEDIA_ENT_F_BASE
fa17b46a 57
b50bde4e 58/*
ed3056f0
HV
59 * Subdevs are initialized with MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN in order
60 * to preserve backward compatibility. Drivers must change to the proper
61 * subdev type before registering the entity.
4ca72efa 62 */
ed3056f0 63#define MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN MEDIA_ENT_F_OLD_SUBDEV_BASE
4ca72efa 64
06131932 65/*
ed3056f0 66 * DVB entity functions
06131932 67 */
ed3056f0
HV
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)
8c755c29 72
7a2eba12 73/*
ed3056f0 74 * I/O entity functions
7a2eba12 75 */
ed3056f0
HV
76#define MEDIA_ENT_F_IO_V4L (MEDIA_ENT_F_OLD_BASE + 1)
77#define MEDIA_ENT_F_IO_DTV (MEDIA_ENT_F_BASE + 0x01001)
78#define MEDIA_ENT_F_IO_VBI (MEDIA_ENT_F_BASE + 0x01002)
79#define MEDIA_ENT_F_IO_SWRADIO (MEDIA_ENT_F_BASE + 0x01003)
7a2eba12 80
1179aab1 81/*
ed3056f0 82 * Sensor functions
1179aab1 83 */
ed3056f0
HV
84#define MEDIA_ENT_F_CAM_SENSOR (MEDIA_ENT_F_OLD_SUBDEV_BASE + 1)
85#define MEDIA_ENT_F_FLASH (MEDIA_ENT_F_OLD_SUBDEV_BASE + 2)
86#define MEDIA_ENT_F_LENS (MEDIA_ENT_F_OLD_SUBDEV_BASE + 3)
1179aab1 87
4ca72efa 88/*
ed3056f0 89 * Digital TV, analog TV, radio and/or software defined radio tuner functions.
4ca72efa 90 *
06131932
MCC
91 * It is a responsibility of the master/bridge drivers to add connectors
92 * and links for MEDIA_ENT_F_TUNER. Please notice that some old tuners
93 * may require the usage of separate I2C chips to decode analog TV signals,
94 * when the master/bridge chipset doesn't have its own TV standard decoder.
95 * On such cases, the IF-PLL staging is mapped via one or two entities:
96 * MEDIA_ENT_F_IF_VID_DECODER and/or MEDIA_ENT_F_IF_AUD_DECODER.
b3109d66 97 */
ed3056f0 98#define MEDIA_ENT_F_TUNER (MEDIA_ENT_F_OLD_SUBDEV_BASE + 5)
4ca72efa 99
ed3056f0
HV
100/*
101 * Analog TV IF-PLL decoder functions
102 *
103 * It is a responsibility of the master/bridge drivers to create links
104 * for MEDIA_ENT_F_IF_VID_DECODER and MEDIA_ENT_F_IF_AUD_DECODER.
105 */
106#define MEDIA_ENT_F_IF_VID_DECODER (MEDIA_ENT_F_BASE + 0x02001)
107#define MEDIA_ENT_F_IF_AUD_DECODER (MEDIA_ENT_F_BASE + 0x02002)
49a11518 108
ed3056f0
HV
109/*
110 * Audio entity functions
111 */
112#define MEDIA_ENT_F_AUDIO_CAPTURE (MEDIA_ENT_F_BASE + 0x03001)
113#define MEDIA_ENT_F_AUDIO_PLAYBACK (MEDIA_ENT_F_BASE + 0x03002)
114#define MEDIA_ENT_F_AUDIO_MIXER (MEDIA_ENT_F_BASE + 0x03003)
4ca72efa
MCC
115
116/*
ed3056f0 117 * Processing entity functions
4ca72efa 118 */
ed3056f0
HV
119#define MEDIA_ENT_F_PROC_VIDEO_COMPOSER (MEDIA_ENT_F_BASE + 0x4001)
120#define MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER (MEDIA_ENT_F_BASE + 0x4002)
121#define MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV (MEDIA_ENT_F_BASE + 0x4003)
122#define MEDIA_ENT_F_PROC_VIDEO_LUT (MEDIA_ENT_F_BASE + 0x4004)
123#define MEDIA_ENT_F_PROC_VIDEO_SCALER (MEDIA_ENT_F_BASE + 0x4005)
124#define MEDIA_ENT_F_PROC_VIDEO_STATISTICS (MEDIA_ENT_F_BASE + 0x4006)
45841a97
HV
125#define MEDIA_ENT_F_PROC_VIDEO_ENCODER (MEDIA_ENT_F_BASE + 0x4007)
126#define MEDIA_ENT_F_PROC_VIDEO_DECODER (MEDIA_ENT_F_BASE + 0x4008)
f7c7d6cc 127#define MEDIA_ENT_F_PROC_VIDEO_ISP (MEDIA_ENT_F_BASE + 0x4009)
6c2c188f 128
ed3056f0
HV
129/*
130 * Switch and bridge entity functions
131 */
132#define MEDIA_ENT_F_VID_MUX (MEDIA_ENT_F_BASE + 0x5001)
133#define MEDIA_ENT_F_VID_IF_BRIDGE (MEDIA_ENT_F_BASE + 0x5002)
32fdc0e1 134
f2399f75
HV
135/*
136 * Video decoder/encoder functions
137 */
138#define MEDIA_ENT_F_ATV_DECODER (MEDIA_ENT_F_OLD_SUBDEV_BASE + 4)
139#define MEDIA_ENT_F_DV_DECODER (MEDIA_ENT_F_BASE + 0x6001)
140#define MEDIA_ENT_F_DV_ENCODER (MEDIA_ENT_F_BASE + 0x6002)
141
49a11518 142/* Entity flags */
98b95642
SA
143#define MEDIA_ENT_FL_DEFAULT (1U << 0)
144#define MEDIA_ENT_FL_CONNECTOR (1U << 1)
ed3056f0
HV
145
146/* OR with the entity id value to find the next entity */
5ca004d1 147#define MEDIA_ENT_ID_FLAG_NEXT (1U << 31)
1651333b
LP
148
149struct media_entity_desc {
150 __u32 id;
151 char name[32];
152 __u32 type;
153 __u32 revision;
154 __u32 flags;
155 __u32 group_id;
156 __u16 pads;
157 __u16 links;
158
159 __u32 reserved[4];
160
161 union {
162 /* Node specifications */
e31a0ba7
MCC
163 struct {
164 __u32 major;
165 __u32 minor;
166 } dev;
167
ed3056f0 168#if !defined(__KERNEL__)
7e182f78
HV
169 /*
170 * TODO: this shouldn't have been added without
171 * actual drivers that use this. When the first real driver
172 * appears that sets this information, special attention
173 * should be given whether this information is 1) enough, and
174 * 2) can deal with udev rules that rename devices. The struct
175 * dev would not be sufficient for this since that does not
176 * contain the subdevice information. In addition, struct dev
177 * can only refer to a single device, and not to multiple (e.g.
178 * pcm and mixer devices).
7e182f78
HV
179 */
180 struct {
181 __u32 card;
182 __u32 device;
183 __u32 subdevice;
184 } alsa;
7e182f78 185
e31a0ba7
MCC
186 /*
187 * DEPRECATED: previous node specifications. Kept just to
ed3056f0
HV
188 * avoid breaking compilation. Use media_entity_desc.dev
189 * instead.
e31a0ba7 190 */
1651333b
LP
191 struct {
192 __u32 major;
193 __u32 minor;
194 } v4l;
195 struct {
196 __u32 major;
197 __u32 minor;
198 } fb;
1651333b 199 int dvb;
e31a0ba7 200#endif
1651333b
LP
201
202 /* Sub-device specifications */
203 /* Nothing needed yet */
204 __u8 raw[184];
205 };
206};
207
98b95642
SA
208#define MEDIA_PAD_FL_SINK (1U << 0)
209#define MEDIA_PAD_FL_SOURCE (1U << 1)
210#define MEDIA_PAD_FL_MUST_CONNECT (1U << 2)
1651333b
LP
211
212struct media_pad_desc {
213 __u32 entity; /* entity ID */
214 __u16 index; /* pad index */
215 __u32 flags; /* pad flags */
216 __u32 reserved[2];
217};
218
98b95642
SA
219#define MEDIA_LNK_FL_ENABLED (1U << 0)
220#define MEDIA_LNK_FL_IMMUTABLE (1U << 1)
221#define MEDIA_LNK_FL_DYNAMIC (1U << 2)
1651333b 222
ed3056f0 223#define MEDIA_LNK_FL_LINK_TYPE (0xf << 28)
98b95642
SA
224# define MEDIA_LNK_FL_DATA_LINK (0U << 28)
225# define MEDIA_LNK_FL_INTERFACE_LINK (1U << 28)
226# define MEDIA_LNK_FL_ANCILLARY_LINK (2U << 28)
c398bb64 227
1651333b
LP
228struct media_link_desc {
229 struct media_pad_desc source;
230 struct media_pad_desc sink;
231 __u32 flags;
232 __u32 reserved[2];
233};
234
235struct media_links_enum {
236 __u32 entity;
237 /* Should have enough room for pads elements */
238 struct media_pad_desc __user *pads;
239 /* Should have enough room for links elements */
240 struct media_link_desc __user *links;
241 __u32 reserved[4];
242};
243
a1d2510e
MCC
244/* Interface type ranges */
245
ed3056f0
HV
246#define MEDIA_INTF_T_DVB_BASE 0x00000100
247#define MEDIA_INTF_T_V4L_BASE 0x00000200
a1d2510e
MCC
248
249/* Interface types */
250
ed3056f0
HV
251#define MEDIA_INTF_T_DVB_FE (MEDIA_INTF_T_DVB_BASE)
252#define MEDIA_INTF_T_DVB_DEMUX (MEDIA_INTF_T_DVB_BASE + 1)
253#define MEDIA_INTF_T_DVB_DVR (MEDIA_INTF_T_DVB_BASE + 2)
254#define MEDIA_INTF_T_DVB_CA (MEDIA_INTF_T_DVB_BASE + 3)
255#define MEDIA_INTF_T_DVB_NET (MEDIA_INTF_T_DVB_BASE + 4)
256
257#define MEDIA_INTF_T_V4L_VIDEO (MEDIA_INTF_T_V4L_BASE)
258#define MEDIA_INTF_T_V4L_VBI (MEDIA_INTF_T_V4L_BASE + 1)
259#define MEDIA_INTF_T_V4L_RADIO (MEDIA_INTF_T_V4L_BASE + 2)
260#define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
261#define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
262#define MEDIA_INTF_T_V4L_TOUCH (MEDIA_INTF_T_V4L_BASE + 5)
263
e377d3e9
SK
264#define MEDIA_INTF_T_ALSA_BASE 0x00000300
265#define MEDIA_INTF_T_ALSA_PCM_CAPTURE (MEDIA_INTF_T_ALSA_BASE)
266#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK (MEDIA_INTF_T_ALSA_BASE + 1)
267#define MEDIA_INTF_T_ALSA_CONTROL (MEDIA_INTF_T_ALSA_BASE + 2)
268
ed3056f0 269#if defined(__KERNEL__)
5af557a6 270
c398bb64 271/*
ed3056f0 272 * Connector functions
c398bb64 273 *
ed3056f0
HV
274 * For now these should not be used in userspace, as some definitions may
275 * change.
c398bb64 276 *
ed3056f0 277 * It is the responsibility of the entity drivers to add connectors and links.
c398bb64 278 */
ed3056f0
HV
279#define MEDIA_ENT_F_CONN_RF (MEDIA_ENT_F_BASE + 0x30001)
280#define MEDIA_ENT_F_CONN_SVIDEO (MEDIA_ENT_F_BASE + 0x30002)
281#define MEDIA_ENT_F_CONN_COMPOSITE (MEDIA_ENT_F_BASE + 0x30003)
c398bb64 282
ed3056f0
HV
283#endif
284
285/*
286 * MC next gen API definitions
287 */
333a6515 288
588f4ee7
HV
289/*
290 * Appeared in 4.19.0.
291 *
292 * The media_version argument comes from the media_version field in
293 * struct media_device_info.
294 */
295#define MEDIA_V2_ENTITY_HAS_FLAGS(media_version) \
98b95642 296 ((media_version) >= ((4U << 16) | (19U << 8) | 0U))
588f4ee7 297
c398bb64
MCC
298struct media_v2_entity {
299 __u32 id;
ed3056f0 300 char name[64];
d87cdb88 301 __u32 function; /* Main function of the entity */
588f4ee7
HV
302 __u32 flags;
303 __u32 reserved[5];
fbe093ac 304} __attribute__ ((packed));
c398bb64
MCC
305
306/* Should match the specific fields at media_intf_devnode */
307struct media_v2_intf_devnode {
308 __u32 major;
309 __u32 minor;
fbe093ac 310} __attribute__ ((packed));
c398bb64
MCC
311
312struct media_v2_interface {
313 __u32 id;
314 __u32 intf_type;
315 __u32 flags;
316 __u32 reserved[9];
317
318 union {
319 struct media_v2_intf_devnode devnode;
320 __u32 raw[16];
321 };
fbe093ac 322} __attribute__ ((packed));
c398bb64 323
30b914c8
HV
324/*
325 * Appeared in 4.19.0.
326 *
327 * The media_version argument comes from the media_version field in
328 * struct media_device_info.
329 */
330#define MEDIA_V2_PAD_HAS_INDEX(media_version) \
98b95642 331 ((media_version) >= ((4U << 16) | (19U << 8) | 0U))
30b914c8 332
c398bb64
MCC
333struct media_v2_pad {
334 __u32 id;
335 __u32 entity_id;
336 __u32 flags;
30b914c8
HV
337 __u32 index;
338 __u32 reserved[4];
fbe093ac 339} __attribute__ ((packed));
c398bb64
MCC
340
341struct media_v2_link {
342 __u32 id;
343 __u32 source_id;
344 __u32 sink_id;
345 __u32 flags;
fbe093ac
SA
346 __u32 reserved[6];
347} __attribute__ ((packed));
c398bb64
MCC
348
349struct media_v2_topology {
b3b7a9f1 350 __u64 topology_version;
c398bb64 351
7c9d6731
MCC
352 __u32 num_entities;
353 __u32 reserved1;
b3b7a9f1 354 __u64 ptr_entities;
c398bb64 355
7c9d6731
MCC
356 __u32 num_interfaces;
357 __u32 reserved2;
b3b7a9f1 358 __u64 ptr_interfaces;
c398bb64 359
7c9d6731
MCC
360 __u32 num_pads;
361 __u32 reserved3;
b3b7a9f1 362 __u64 ptr_pads;
c398bb64 363
7c9d6731
MCC
364 __u32 num_links;
365 __u32 reserved4;
b3b7a9f1 366 __u64 ptr_links;
fbe093ac 367} __attribute__ ((packed));
c398bb64
MCC
368
369/* ioctls */
a1d2510e 370
ed3056f0
HV
371#define MEDIA_IOC_DEVICE_INFO _IOWR('|', 0x00, struct media_device_info)
372#define MEDIA_IOC_ENUM_ENTITIES _IOWR('|', 0x01, struct media_entity_desc)
373#define MEDIA_IOC_ENUM_LINKS _IOWR('|', 0x02, struct media_links_enum)
374#define MEDIA_IOC_SETUP_LINK _IOWR('|', 0x03, struct media_link_desc)
375#define MEDIA_IOC_G_TOPOLOGY _IOWR('|', 0x04, struct media_v2_topology)
66431c0b
HV
376#define MEDIA_IOC_REQUEST_ALLOC _IOR ('|', 0x05, int)
377
378/*
379 * These ioctls are called on the request file descriptor as returned
380 * by MEDIA_IOC_REQUEST_ALLOC.
381 */
382#define MEDIA_REQUEST_IOC_QUEUE _IO('|', 0x80)
383#define MEDIA_REQUEST_IOC_REINIT _IO('|', 0x81)
ed3056f0 384
e1a98c16 385#ifndef __KERNEL__
ed3056f0
HV
386
387/*
388 * Legacy symbols used to avoid userspace compilation breakages.
389 * Do not use any of this in new applications!
390 *
391 * Those symbols map the entity function into types and should be
392 * used only on legacy programs for legacy hardware. Don't rely
393 * on those for MEDIA_IOC_G_TOPOLOGY.
394 */
395#define MEDIA_ENT_TYPE_SHIFT 16
396#define MEDIA_ENT_TYPE_MASK 0x00ff0000
397#define MEDIA_ENT_SUBTYPE_MASK 0x0000ffff
398
399#define MEDIA_ENT_T_DEVNODE_UNKNOWN (MEDIA_ENT_F_OLD_BASE | \
400 MEDIA_ENT_SUBTYPE_MASK)
401
402#define MEDIA_ENT_T_DEVNODE MEDIA_ENT_F_OLD_BASE
403#define MEDIA_ENT_T_DEVNODE_V4L MEDIA_ENT_F_IO_V4L
404#define MEDIA_ENT_T_DEVNODE_FB (MEDIA_ENT_F_OLD_BASE + 2)
405#define MEDIA_ENT_T_DEVNODE_ALSA (MEDIA_ENT_F_OLD_BASE + 3)
406#define MEDIA_ENT_T_DEVNODE_DVB (MEDIA_ENT_F_OLD_BASE + 4)
407
408#define MEDIA_ENT_T_UNKNOWN MEDIA_ENT_F_UNKNOWN
409#define MEDIA_ENT_T_V4L2_VIDEO MEDIA_ENT_F_IO_V4L
410#define MEDIA_ENT_T_V4L2_SUBDEV MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN
411#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR MEDIA_ENT_F_CAM_SENSOR
412#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH MEDIA_ENT_F_FLASH
413#define MEDIA_ENT_T_V4L2_SUBDEV_LENS MEDIA_ENT_F_LENS
414#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER MEDIA_ENT_F_ATV_DECODER
415#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER MEDIA_ENT_F_TUNER
416
d272bc92
HV
417#define MEDIA_ENT_F_DTV_DECODER MEDIA_ENT_F_DV_DECODER
418
ed3056f0 419/*
e377d3e9 420 * There is still no full ALSA support in the media controller. These
ed3056f0
HV
421 * defines should not have been added and we leave them here only
422 * in case some application tries to use these defines.
e377d3e9
SK
423 *
424 * The ALSA defines that are in use have been moved into __KERNEL__
425 * scope. As support gets added to these interface types, they should
426 * be moved into __KERNEL__ scope with the code that uses them.
ed3056f0 427 */
e377d3e9
SK
428#define MEDIA_INTF_T_ALSA_COMPRESS (MEDIA_INTF_T_ALSA_BASE + 3)
429#define MEDIA_INTF_T_ALSA_RAWMIDI (MEDIA_INTF_T_ALSA_BASE + 4)
430#define MEDIA_INTF_T_ALSA_HWDEP (MEDIA_INTF_T_ALSA_BASE + 5)
431#define MEDIA_INTF_T_ALSA_SEQUENCER (MEDIA_INTF_T_ALSA_BASE + 6)
432#define MEDIA_INTF_T_ALSA_TIMER (MEDIA_INTF_T_ALSA_BASE + 7)
ed3056f0
HV
433
434/* Obsolete symbol for media_version, no longer used in the kernel */
98b95642 435#define MEDIA_API_VERSION ((0U << 16) | (1U << 8) | 0U)
ed3056f0
HV
436
437#endif
140d8816
LP
438
439#endif /* __LINUX_MEDIA_H */