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