media.h 13 KB

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