blob: 1e3c8cb43bd7ac61650da4b6e31ab854af4a7b89 [file] [log] [blame]
Laurent Pinchart140d8812010-08-18 11:41:22 -03001/*
2 * Multimedia device API
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 * Sakari Ailus <sakari.ailus@iki.fi>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef __LINUX_MEDIA_H
24#define __LINUX_MEDIA_H
25
Mauro Carvalho Chehabb3b7a9f2015-12-11 16:07:57 -020026#ifndef __KERNEL__
27#include <stdint.h>
28#endif
Laurent Pinchart140d8812010-08-18 11:41:22 -030029#include <linux/ioctl.h>
30#include <linux/types.h>
31#include <linux/version.h>
32
33#define MEDIA_API_VERSION KERNEL_VERSION(0, 1, 0)
34
35struct media_device_info {
36 char driver[16];
37 char model[32];
38 char serial[40];
39 char bus_info[32];
40 __u32 media_version;
41 __u32 hw_revision;
42 __u32 driver_version;
43 __u32 reserved[31];
44};
45
Laurent Pinchart16513332009-12-09 08:40:01 -030046#define MEDIA_ENT_ID_FLAG_NEXT (1 << 31)
47
Mauro Carvalho Chehabb50bde42015-05-07 22:12:38 -030048/*
49 * Initial value to be used when a new entity is created
50 * Drivers should change it to something useful
51 */
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -020052#define MEDIA_ENT_F_UNKNOWN 0x00000000
Mauro Carvalho Chehabb50bde42015-05-07 22:12:38 -030053
Mauro Carvalho Chehab32fdc0e2015-08-21 11:40:34 -030054/*
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -020055 * Base number ranges for entity functions
Mauro Carvalho Chehab32fdc0e2015-08-21 11:40:34 -030056 *
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -020057 * NOTE: those ranges and entity function number are phased just to
58 * make it easier to maintain this file. Userspace should not rely on
59 * the ranges to identify a group of function types, as newer
60 * functions can be added with any name within the full u32 range.
61 */
62#define MEDIA_ENT_F_BASE 0x00000000
63#define MEDIA_ENT_F_OLD_BASE 0x00010000
64#define MEDIA_ENT_F_OLD_SUBDEV_BASE 0x00020000
65
66/*
67 * DVB entities
68 */
69#define MEDIA_ENT_F_DTV_DEMOD (MEDIA_ENT_F_BASE + 1)
70#define MEDIA_ENT_F_TS_DEMUX (MEDIA_ENT_F_BASE + 2)
71#define MEDIA_ENT_F_DTV_CA (MEDIA_ENT_F_BASE + 3)
72#define MEDIA_ENT_F_DTV_NET_DECAP (MEDIA_ENT_F_BASE + 4)
73
74/*
75 * Connectors
76 */
Mauro Carvalho Chehabb3109d62015-12-11 18:26:53 -020077/* It is a responsibility of the entity drivers to add connectors and links */
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -020078#define MEDIA_ENT_F_CONN_RF (MEDIA_ENT_F_BASE + 21)
79#define MEDIA_ENT_F_CONN_SVIDEO (MEDIA_ENT_F_BASE + 22)
80#define MEDIA_ENT_F_CONN_COMPOSITE (MEDIA_ENT_F_BASE + 23)
Mauro Carvalho Chehabb3109d62015-12-11 18:26:53 -020081/* For internal test signal generators and other debug connectors */
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -020082#define MEDIA_ENT_F_CONN_TEST (MEDIA_ENT_F_BASE + 24)
83
84/*
85 * I/O entities
86 */
87#define MEDIA_ENT_F_IO_DTV (MEDIA_ENT_F_BASE + 31)
88#define MEDIA_ENT_F_IO_VBI (MEDIA_ENT_F_BASE + 32)
89#define MEDIA_ENT_F_IO_SWRADIO (MEDIA_ENT_F_BASE + 33)
90
91/*
92 * Don't touch on those. The ranges MEDIA_ENT_F_OLD_BASE and
93 * MEDIA_ENT_F_OLD_SUBDEV_BASE are kept to keep backward compatibility
94 * with the legacy v1 API.The number range is out of range by purpose:
95 * several previously reserved numbers got excluded from this range.
Mauro Carvalho Chehab32fdc0e2015-08-21 11:40:34 -030096 *
Mauro Carvalho Chehabb50bde42015-05-07 22:12:38 -030097 * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
98 * in order to preserve backward compatibility.
Mauro Carvalho Chehabd1b9da22015-12-11 12:41:12 -020099 * Drivers must change to the proper subdev type before
Mauro Carvalho Chehabb50bde42015-05-07 22:12:38 -0300100 * registering the entity.
101 */
Mauro Carvalho Chehabfa17b462015-08-21 12:17:40 -0300102
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -0200103#define MEDIA_ENT_F_IO_V4L (MEDIA_ENT_F_OLD_BASE + 1)
Mauro Carvalho Chehab32fdc0e2015-08-21 11:40:34 -0300104
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -0200105#define MEDIA_ENT_F_CAM_SENSOR (MEDIA_ENT_F_OLD_SUBDEV_BASE + 1)
106#define MEDIA_ENT_F_FLASH (MEDIA_ENT_F_OLD_SUBDEV_BASE + 2)
107#define MEDIA_ENT_F_LENS (MEDIA_ENT_F_OLD_SUBDEV_BASE + 3)
108#define MEDIA_ENT_F_ATV_DECODER (MEDIA_ENT_F_OLD_SUBDEV_BASE + 4)
Mauro Carvalho Chehabb3109d62015-12-11 18:26:53 -0200109/*
110 * It is a responsibility of the entity drivers to add connectors and links
111 * for the tuner entities.
112 */
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -0200113#define MEDIA_ENT_F_TUNER (MEDIA_ENT_F_OLD_SUBDEV_BASE + 5)
Mauro Carvalho Chehab32fdc0e2015-08-21 11:40:34 -0300114
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -0200115#define MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN MEDIA_ENT_F_OLD_SUBDEV_BASE
Mauro Carvalho Chehab49a11512015-08-31 11:41:29 -0300116
Mauro Carvalho Chehab43766792015-08-29 14:50:46 -0300117#ifndef __KERNEL__
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -0200118
119/*
120 * Legacy symbols used to avoid userspace compilation breakages
121 *
122 * Those symbols map the entity function into types and should be
123 * used only on legacy programs for legacy hardware. Don't rely
124 * on those for MEDIA_IOC_G_TOPOLOGY.
125 */
Laurent Pinchart16513332009-12-09 08:40:01 -0300126#define MEDIA_ENT_TYPE_SHIFT 16
127#define MEDIA_ENT_TYPE_MASK 0x00ff0000
128#define MEDIA_ENT_SUBTYPE_MASK 0x0000ffff
129
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -0200130#define MEDIA_ENT_T_DEVNODE MEDIA_ENT_F_OLD_BASE
131#define MEDIA_ENT_T_DEVNODE_V4L MEDIA_ENT_F_IO_V4L
Laurent Pinchart16513332009-12-09 08:40:01 -0300132#define MEDIA_ENT_T_DEVNODE_FB (MEDIA_ENT_T_DEVNODE + 2)
133#define MEDIA_ENT_T_DEVNODE_ALSA (MEDIA_ENT_T_DEVNODE + 3)
Mauro Carvalho Chehab32fdc0e2015-08-21 11:40:34 -0300134#define MEDIA_ENT_T_DEVNODE_DVB (MEDIA_ENT_T_DEVNODE + 4)
Mauro Carvalho Chehab4ca72ef2015-12-10 17:25:41 -0200135
136#define MEDIA_ENT_T_UNKNOWN MEDIA_ENT_F_UNKNOWN
137#define MEDIA_ENT_T_V4L2_VIDEO MEDIA_ENT_F_IO_V4L
138#define MEDIA_ENT_T_V4L2_SUBDEV MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN
139#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR MEDIA_ENT_F_CAM_SENSOR
140#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH MEDIA_ENT_F_FLASH
141#define MEDIA_ENT_T_V4L2_SUBDEV_LENS MEDIA_ENT_F_LENS
142#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER MEDIA_ENT_F_ATV_DECODER
143#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER MEDIA_ENT_F_TUNER
Mauro Carvalho Chehab43766792015-08-29 14:50:46 -0300144#endif
Mauro Carvalho Chehab1d20f9f2015-01-03 11:09:39 -0300145
Mauro Carvalho Chehab49a11512015-08-31 11:41:29 -0300146/* Entity flags */
Laurent Pinchart16513332009-12-09 08:40:01 -0300147#define MEDIA_ENT_FL_DEFAULT (1 << 0)
Mauro Carvalho Chehab49a11512015-08-31 11:41:29 -0300148#define MEDIA_ENT_FL_CONNECTOR (1 << 1)
Laurent Pinchart16513332009-12-09 08:40:01 -0300149
150struct media_entity_desc {
151 __u32 id;
152 char name[32];
153 __u32 type;
154 __u32 revision;
155 __u32 flags;
156 __u32 group_id;
157 __u16 pads;
158 __u16 links;
159
160 __u32 reserved[4];
161
162 union {
163 /* Node specifications */
164 struct {
165 __u32 major;
166 __u32 minor;
Mauro Carvalho Chehabe31a0ba2015-01-02 12:18:23 -0300167 } dev;
168
169#if 1
170 /*
Hans Verkuil7e182f72015-02-25 12:05:13 -0300171 * TODO: this shouldn't have been added without
172 * actual drivers that use this. When the first real driver
173 * appears that sets this information, special attention
174 * should be given whether this information is 1) enough, and
175 * 2) can deal with udev rules that rename devices. The struct
176 * dev would not be sufficient for this since that does not
177 * contain the subdevice information. In addition, struct dev
178 * can only refer to a single device, and not to multiple (e.g.
179 * pcm and mixer devices).
180 *
181 * So for now mark this as a to do.
182 */
183 struct {
184 __u32 card;
185 __u32 device;
186 __u32 subdevice;
187 } alsa;
188#endif
189
190#if 1
191 /*
Mauro Carvalho Chehabe31a0ba2015-01-02 12:18:23 -0300192 * DEPRECATED: previous node specifications. Kept just to
193 * avoid breaking compilation, but media_entity_desc.dev
194 * should be used instead. In particular, alsa and dvb
195 * fields below are wrong: for all devnodes, there should
196 * be just major/minor inside the struct, as this is enough
197 * to represent any devnode, no matter what type.
198 */
199 struct {
200 __u32 major;
201 __u32 minor;
Laurent Pinchart16513332009-12-09 08:40:01 -0300202 } v4l;
203 struct {
204 __u32 major;
205 __u32 minor;
206 } fb;
Laurent Pinchart16513332009-12-09 08:40:01 -0300207 int dvb;
Mauro Carvalho Chehabe31a0ba2015-01-02 12:18:23 -0300208#endif
Laurent Pinchart16513332009-12-09 08:40:01 -0300209
210 /* Sub-device specifications */
211 /* Nothing needed yet */
212 __u8 raw[184];
213 };
214};
215
216#define MEDIA_PAD_FL_SINK (1 << 0)
217#define MEDIA_PAD_FL_SOURCE (1 << 1)
Sakari Ailusd0700c52013-10-13 07:58:43 -0300218#define MEDIA_PAD_FL_MUST_CONNECT (1 << 2)
Laurent Pinchart16513332009-12-09 08:40:01 -0300219
220struct media_pad_desc {
221 __u32 entity; /* entity ID */
222 __u16 index; /* pad index */
223 __u32 flags; /* pad flags */
224 __u32 reserved[2];
225};
226
227#define MEDIA_LNK_FL_ENABLED (1 << 0)
228#define MEDIA_LNK_FL_IMMUTABLE (1 << 1)
Laurent Pincharte02188c2010-08-25 09:00:41 -0300229#define MEDIA_LNK_FL_DYNAMIC (1 << 2)
Laurent Pinchart16513332009-12-09 08:40:01 -0300230
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300231#define MEDIA_LNK_FL_LINK_TYPE (0xf << 28)
232# define MEDIA_LNK_FL_DATA_LINK (0 << 28)
233# define MEDIA_LNK_FL_INTERFACE_LINK (1 << 28)
234
Laurent Pinchart16513332009-12-09 08:40:01 -0300235struct media_link_desc {
236 struct media_pad_desc source;
237 struct media_pad_desc sink;
238 __u32 flags;
239 __u32 reserved[2];
240};
241
242struct media_links_enum {
243 __u32 entity;
244 /* Should have enough room for pads elements */
245 struct media_pad_desc __user *pads;
246 /* Should have enough room for links elements */
247 struct media_link_desc __user *links;
248 __u32 reserved[4];
249};
250
Mauro Carvalho Chehaba1d25102015-08-20 07:43:07 -0300251/* Interface type ranges */
252
253#define MEDIA_INTF_T_DVB_BASE 0x00000100
254#define MEDIA_INTF_T_V4L_BASE 0x00000200
255
256/* Interface types */
257
258#define MEDIA_INTF_T_DVB_FE (MEDIA_INTF_T_DVB_BASE)
259#define MEDIA_INTF_T_DVB_DEMUX (MEDIA_INTF_T_DVB_BASE + 1)
260#define MEDIA_INTF_T_DVB_DVR (MEDIA_INTF_T_DVB_BASE + 2)
261#define MEDIA_INTF_T_DVB_CA (MEDIA_INTF_T_DVB_BASE + 3)
262#define MEDIA_INTF_T_DVB_NET (MEDIA_INTF_T_DVB_BASE + 4)
263
264#define MEDIA_INTF_T_V4L_VIDEO (MEDIA_INTF_T_V4L_BASE)
265#define MEDIA_INTF_T_V4L_VBI (MEDIA_INTF_T_V4L_BASE + 1)
266#define MEDIA_INTF_T_V4L_RADIO (MEDIA_INTF_T_V4L_BASE + 2)
267#define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
268#define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
269
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300270/*
271 * MC next gen API definitions
272 *
273 * NOTE: The declarations below are close to the MC RFC for the Media
274 * Controller, the next generation. Yet, there are a few adjustments
275 * to do, as we want to be able to have a functional API before
276 * the MC properties change. Those will be properly marked below.
277 * Please also notice that I removed "num_pads", "num_links",
278 * from the proposal, as a proper userspace application will likely
279 * use lists for pads/links, just as we intend to do in Kernelspace.
280 * The API definition should be freed from fields that are bound to
281 * some specific data structure.
282 *
283 * FIXME: Currently, I opted to name the new types as "media_v2", as this
284 * won't cause any conflict with the Kernelspace namespace, nor with
285 * the previous kAPI media_*_desc namespace. This can be changed
286 * later, before the adding this API upstream.
287 */
288
Mauro Carvalho Chehabbe0270ec2015-12-28 12:03:47 -0200289#if 0 /* Let's postpone it to Kernel 4.6 */
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300290struct media_v2_entity {
291 __u32 id;
292 char name[64]; /* FIXME: move to a property? (RFC says so) */
Mauro Carvalho Chehabd87cdb82015-09-06 10:59:08 -0300293 __u32 function; /* Main function of the entity */
294 __u16 reserved[12];
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300295};
296
297/* Should match the specific fields at media_intf_devnode */
298struct media_v2_intf_devnode {
299 __u32 major;
300 __u32 minor;
301};
302
303struct media_v2_interface {
304 __u32 id;
305 __u32 intf_type;
306 __u32 flags;
307 __u32 reserved[9];
308
309 union {
310 struct media_v2_intf_devnode devnode;
311 __u32 raw[16];
312 };
313};
314
315struct media_v2_pad {
316 __u32 id;
317 __u32 entity_id;
318 __u32 flags;
319 __u16 reserved[9];
320};
321
322struct media_v2_link {
323 __u32 id;
324 __u32 source_id;
325 __u32 sink_id;
326 __u32 flags;
327 __u32 reserved[5];
328};
329
330struct media_v2_topology {
Mauro Carvalho Chehabb3b7a9f2015-12-11 16:07:57 -0200331 __u64 topology_version;
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300332
Mauro Carvalho Chehab7c9d6732015-12-17 09:07:38 -0200333 __u32 num_entities;
334 __u32 reserved1;
Mauro Carvalho Chehabb3b7a9f2015-12-11 16:07:57 -0200335 __u64 ptr_entities;
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300336
Mauro Carvalho Chehab7c9d6732015-12-17 09:07:38 -0200337 __u32 num_interfaces;
338 __u32 reserved2;
Mauro Carvalho Chehabb3b7a9f2015-12-11 16:07:57 -0200339 __u64 ptr_interfaces;
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300340
Mauro Carvalho Chehab7c9d6732015-12-17 09:07:38 -0200341 __u32 num_pads;
342 __u32 reserved3;
Mauro Carvalho Chehabb3b7a9f2015-12-11 16:07:57 -0200343 __u64 ptr_pads;
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300344
Mauro Carvalho Chehab7c9d6732015-12-17 09:07:38 -0200345 __u32 num_links;
346 __u32 reserved4;
Mauro Carvalho Chehabb3b7a9f2015-12-11 16:07:57 -0200347 __u64 ptr_links;
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300348};
349
Mauro Carvalho Chehabb3b7a9f2015-12-11 16:07:57 -0200350static inline void __user *media_get_uptr(__u64 arg)
351{
352 return (void __user *)(uintptr_t)arg;
353}
Mauro Carvalho Chehabbe0270ec2015-12-28 12:03:47 -0200354#endif
Mauro Carvalho Chehabb3b7a9f2015-12-11 16:07:57 -0200355
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300356/* ioctls */
Mauro Carvalho Chehaba1d25102015-08-20 07:43:07 -0300357
Laurent Pinchart474966e2011-03-05 17:14:33 -0300358#define MEDIA_IOC_DEVICE_INFO _IOWR('|', 0x00, struct media_device_info)
359#define MEDIA_IOC_ENUM_ENTITIES _IOWR('|', 0x01, struct media_entity_desc)
360#define MEDIA_IOC_ENUM_LINKS _IOWR('|', 0x02, struct media_links_enum)
361#define MEDIA_IOC_SETUP_LINK _IOWR('|', 0x03, struct media_link_desc)
Mauro Carvalho Chehabbe0270ec2015-12-28 12:03:47 -0200362
363#if 0 /* Let's postpone it to Kernel 4.6 */
Mauro Carvalho Chehabc398bb62015-08-23 08:28:21 -0300364#define MEDIA_IOC_G_TOPOLOGY _IOWR('|', 0x04, struct media_v2_topology)
Mauro Carvalho Chehabbe0270ec2015-12-28 12:03:47 -0200365#endif
Laurent Pinchart140d8812010-08-18 11:41:22 -0300366
367#endif /* __LINUX_MEDIA_H */