v4l2-mc.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 <mchehab@kernel.org>
  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 pad.
  83. *
  84. * @src_sd: pointer to a source subdev
  85. * @sink: pointer to a 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, in its v4l2-async notifier bound callback, to create
  92. * 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. * THIS FUNCTION IS DEPRECATED. DO NOT USE IN NEW DRIVERS. USE RUNTIME PM
  137. * ON SUB-DEVICE DRIVERS INSTEAD.
  138. *
  139. * Update the use count of all entities in the pipeline and power entities on.
  140. *
  141. * This function is intended to be called in video node open. It uses
  142. * struct media_entity.use_count to track the power status. The use
  143. * of this function should be paired with v4l2_pipeline_link_notify().
  144. *
  145. * Return 0 on success or a negative error code on failure.
  146. */
  147. int v4l2_pipeline_pm_get(struct media_entity *entity);
  148. /**
  149. * v4l2_pipeline_pm_put - Decrease the use count of a pipeline
  150. * @entity: The root entity of a pipeline
  151. *
  152. * THIS FUNCTION IS DEPRECATED. DO NOT USE IN NEW DRIVERS. USE RUNTIME PM
  153. * ON SUB-DEVICE DRIVERS INSTEAD.
  154. *
  155. * Update the use count of all entities in the pipeline and power entities off.
  156. *
  157. * This function is intended to be called in video node release. It uses
  158. * struct media_entity.use_count to track the power status. The use
  159. * of this function should be paired with v4l2_pipeline_link_notify().
  160. */
  161. void v4l2_pipeline_pm_put(struct media_entity *entity);
  162. /**
  163. * v4l2_pipeline_link_notify - Link management notification callback
  164. * @link: The link
  165. * @flags: New link flags that will be applied
  166. * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*)
  167. *
  168. * THIS FUNCTION IS DEPRECATED. DO NOT USE IN NEW DRIVERS. USE RUNTIME PM
  169. * ON SUB-DEVICE DRIVERS INSTEAD.
  170. *
  171. * React to link management on powered pipelines by updating the use count of
  172. * all entities in the source and sink sides of the link. Entities are powered
  173. * on or off accordingly. The use of this function should be paired
  174. * with v4l2_pipeline_pm_{get,put}().
  175. *
  176. * Return 0 on success or a negative error code on failure. Powering entities
  177. * off is assumed to never fail. This function will not fail for disconnection
  178. * events.
  179. */
  180. int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
  181. unsigned int notification);
  182. #else /* CONFIG_MEDIA_CONTROLLER */
  183. static inline int v4l2_mc_create_media_graph(struct media_device *mdev)
  184. {
  185. return 0;
  186. }
  187. static inline int v4l_enable_media_source(struct video_device *vdev)
  188. {
  189. return 0;
  190. }
  191. static inline void v4l_disable_media_source(struct video_device *vdev)
  192. {
  193. }
  194. static inline int v4l_vb2q_enable_media_source(struct vb2_queue *q)
  195. {
  196. return 0;
  197. }
  198. static inline int v4l2_pipeline_pm_get(struct media_entity *entity)
  199. {
  200. return 0;
  201. }
  202. static inline void v4l2_pipeline_pm_put(struct media_entity *entity)
  203. {}
  204. static inline int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
  205. unsigned int notification)
  206. {
  207. return 0;
  208. }
  209. #endif /* CONFIG_MEDIA_CONTROLLER */
  210. #endif /* _V4L2_MC_H */