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