media.h 12 KB

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