media.h 12 KB

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