v4l2-mc.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * v4l2-mc.h - Media Controller V4L2 types and prototypes
  4. *
  5. * Copyright (C) 2016 Mauro Carvalho Chehab <[email protected]>
  6. * Copyright (C) 2006-2010 Nokia Corporation
  7. * Copyright (c) 2016 Intel Corporation.
  8. */
  9. #ifndef _V4L2_MC_H
  10. #define _V4L2_MC_H
  11. #include <media/media-device.h>
  12. #include <media/v4l2-dev.h>
  13. #include <media/v4l2-subdev.h>
  14. #include <linux/types.h>
  15. /* We don't need to include pci.h or usb.h here */
  16. struct pci_dev;
  17. struct usb_device;
  18. #ifdef CONFIG_MEDIA_CONTROLLER
  19. /**
  20. * v4l2_mc_create_media_graph() - create Media Controller links at the graph.
  21. *
  22. * @mdev: pointer to the &media_device struct.
  23. *
  24. * Add links between the entities commonly found on PC customer's hardware at
  25. * the V4L2 side: camera sensors, audio and video PLL-IF decoders, tuners,
  26. * analog TV decoder and I/O entities (video, VBI and Software Defined Radio).
  27. *
  28. * .. note::
  29. *
  30. * Webcams are modelled on a very simple way: the sensor is
  31. * connected directly to the I/O entity. All dirty details, like
  32. * scaler and crop HW are hidden. While such mapping is enough for v4l2
  33. * interface centric PC-consumer's hardware, V4L2 subdev centric camera
  34. * hardware should not use this routine, as it will not build the right graph.
  35. */
  36. int v4l2_mc_create_media_graph(struct media_device *mdev);
  37. /**
  38. * v4l_enable_media_source() - Hold media source for exclusive use
  39. * if free
  40. *
  41. * @vdev: pointer to struct video_device
  42. *
  43. * This interface calls enable_source handler to determine if
  44. * media source is free for use. The enable_source handler is
  45. * responsible for checking is the media source is free and
  46. * start a pipeline between the media source and the media
  47. * entity associated with the video device. This interface
  48. * should be called from v4l2-core and dvb-core interfaces
  49. * that change the source configuration.
  50. *
  51. * Return: returns zero on success or a negative error code.
  52. */
  53. int v4l_enable_media_source(struct video_device *vdev);
  54. /**
  55. * v4l_disable_media_source() - Release media source
  56. *
  57. * @vdev: pointer to struct video_device
  58. *
  59. * This interface calls disable_source handler to release
  60. * the media source. The disable_source handler stops the
  61. * active media pipeline between the media source and the
  62. * media entity associated with the video device.
  63. *
  64. * Return: returns zero on success or a negative error code.
  65. */
  66. void v4l_disable_media_source(struct video_device *vdev);
  67. /*
  68. * v4l_vb2q_enable_media_tuner - Hold media source for exclusive use
  69. * if free.
  70. * @q - pointer to struct vb2_queue
  71. *
  72. * Wrapper for v4l_enable_media_source(). This function should
  73. * be called from v4l2-core to enable the media source with
  74. * pointer to struct vb2_queue as the input argument. Some
  75. * v4l2-core interfaces don't have access to video device and
  76. * this interface finds the struct video_device for the q and
  77. * calls v4l_enable_media_source().
  78. */
  79. int v4l_vb2q_enable_media_source(struct vb2_queue *q);
  80. /**
  81. * v4l2_create_fwnode_links_to_pad - Create fwnode-based links from a
  82. * source subdev to a sink subdev pad.
  83. *
  84. * @src_sd: pointer to a source subdev
  85. * @sink: pointer to a subdev sink pad
  86. * @flags: the link flags
  87. *
  88. * This function searches for fwnode endpoint connections from a source
  89. * subdevice to a single sink pad, and if suitable connections are found,
  90. * translates them into media links to that pad. The function can be
  91. * called by the sink subdevice, in its v4l2-async notifier subdev bound
  92. * callback, to create links from a bound source subdevice.
  93. *
  94. * The @flags argument specifies the link flags. The caller shall ensure that
  95. * the flags are valid regardless of the number of links that may be created.
  96. * For instance, setting the MEDIA_LNK_FL_ENABLED flag will cause all created
  97. * links to be enabled, which isn't valid if more than one link is created.
  98. *
  99. * .. note::
  100. *
  101. * Any sink subdevice that calls this function must implement the
  102. * .get_fwnode_pad media operation in order to verify endpoints passed
  103. * to the sink are owned by the sink.
  104. *
  105. * Return 0 on success or a negative error code on failure.
  106. */
  107. int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd,
  108. struct media_pad *sink, u32 flags);
  109. /**
  110. * v4l2_create_fwnode_links - Create fwnode-based links from a source
  111. * subdev to a sink subdev.
  112. *
  113. * @src_sd: pointer to a source subdevice
  114. * @sink_sd: pointer to a sink subdevice
  115. *
  116. * This function searches for any and all fwnode endpoint connections
  117. * between source and sink subdevices, and translates them into media
  118. * links. The function can be called by the sink subdevice, in its
  119. * v4l2-async notifier subdev bound callback, to create all links from
  120. * a bound source subdevice.
  121. *
  122. * .. note::
  123. *
  124. * Any sink subdevice that calls this function must implement the
  125. * .get_fwnode_pad media operation in order to verify endpoints passed
  126. * to the sink are owned by the sink.
  127. *
  128. * Return 0 on success or a negative error code on failure.
  129. */
  130. int v4l2_create_fwnode_links(struct v4l2_subdev *src_sd,
  131. struct v4l2_subdev *sink_sd);
  132. /**
  133. * v4l2_pipeline_pm_get - Increase the use count of a pipeline
  134. * @entity: The root entity of a pipeline
  135. *
  136. * Update the use count of all entities in the pipeline and power entities on.
  137. *
  138. * This function is intended to be called in video node open. It uses
  139. * struct media_entity.use_count to track the power status. The use
  140. * of this function should be paired with v4l2_pipeline_link_notify().
  141. *
  142. * Return 0 on success or a negative error code on failure.
  143. */
  144. int v4l2_pipeline_pm_get(struct media_entity *entity);
  145. /**
  146. * v4l2_pipeline_pm_put - Decrease the use count of a pipeline
  147. * @entity: The root entity of a pipeline
  148. *
  149. * Update the use count of all entities in the pipeline and power entities off.
  150. *
  151. * This function is intended to be called in video node release. It uses
  152. * struct media_entity.use_count to track the power status. The use
  153. * of this function should be paired with v4l2_pipeline_link_notify().
  154. */
  155. void v4l2_pipeline_pm_put(struct media_entity *entity);
  156. /**
  157. * v4l2_pipeline_link_notify - Link management notification callback
  158. * @link: The link
  159. * @flags: New link flags that will be applied
  160. * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*)
  161. *
  162. * React to link management on powered pipelines by updating the use count of
  163. * all entities in the source and sink sides of the link. Entities are powered
  164. * on or off accordingly. The use of this function should be paired
  165. * with v4l2_pipeline_pm_{get,put}().
  166. *
  167. * Return 0 on success or a negative error code on failure. Powering entities
  168. * off is assumed to never fail. This function will not fail for disconnection
  169. * events.
  170. */
  171. int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
  172. unsigned int notification);
  173. #else /* CONFIG_MEDIA_CONTROLLER */
  174. static inline int v4l2_mc_create_media_graph(struct media_device *mdev)
  175. {
  176. return 0;
  177. }
  178. static inline int v4l_enable_media_source(struct video_device *vdev)
  179. {
  180. return 0;
  181. }
  182. static inline void v4l_disable_media_source(struct video_device *vdev)
  183. {
  184. }
  185. static inline int v4l_vb2q_enable_media_source(struct vb2_queue *q)
  186. {
  187. return 0;
  188. }
  189. static inline int v4l2_pipeline_pm_get(struct media_entity *entity)
  190. {
  191. return 0;
  192. }
  193. static inline void v4l2_pipeline_pm_put(struct media_entity *entity)
  194. {}
  195. static inline int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
  196. unsigned int notification)
  197. {
  198. return 0;
  199. }
  200. #endif /* CONFIG_MEDIA_CONTROLLER */
  201. #endif /* _V4L2_MC_H */