media.h 12 KB

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