blob: 246eed39864825a12c6f2cf45000be88b75e48ec [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Mauro Carvalho Chehab6aad1272016-01-29 06:11:30 -02002/*
3 * v4l2-mc.h - Media Controller V4L2 types and prototypes
4 *
Mauro Carvalho Chehabdc19ed12016-06-14 14:48:50 -03005 * Copyright (C) 2016 Mauro Carvalho Chehab <mchehab@kernel.org>
Sakari Ailus76413792016-02-21 13:25:09 -03006 * Copyright (C) 2006-2010 Nokia Corporation
7 * Copyright (c) 2016 Intel Corporation.
Mauro Carvalho Chehab6aad1272016-01-29 06:11:30 -02008 */
9
Mauro Carvalho Chehabdb152272016-02-12 07:35:44 -020010#ifndef _V4L2_MC_H
11#define _V4L2_MC_H
12
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -020013#include <media/media-device.h>
Shuah Khand0a164f2016-02-11 21:41:25 -020014#include <media/v4l2-dev.h>
Steve Longerbeam0d3c81e2020-05-01 19:15:37 +020015#include <media/v4l2-subdev.h>
Sakari Ailus76413792016-02-21 13:25:09 -030016#include <linux/types.h>
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -020017
Mauro Carvalho Chehabeee7d352016-02-11 15:21:46 -020018/* We don't need to include pci.h or usb.h here */
19struct pci_dev;
20struct usb_device;
Mauro Carvalho Chehab7047f292016-02-05 13:16:18 -020021
22#ifdef CONFIG_MEDIA_CONTROLLER
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -020023/**
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 Chehab89cb3dd2016-07-17 08:44:08 -030031 *
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 Chehab54d0dba2016-02-05 07:02:43 -020039 */
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -020040int v4l2_mc_create_media_graph(struct media_device *mdev);
Mauro Carvalho Chehab7047f292016-02-05 13:16:18 -020041
Shuah Khand0a164f2016-02-11 21:41:25 -020042/**
43 * v4l_enable_media_source() - Hold media source for exclusive use
44 * if free
45 *
Mauro Carvalho Chehab4f27dba2016-03-03 12:14:33 -030046 * @vdev: pointer to struct video_device
Shuah Khand0a164f2016-02-11 21:41:25 -020047 *
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 */
58int v4l_enable_media_source(struct video_device *vdev);
59
60/**
61 * v4l_disable_media_source() - Release media source
62 *
Mauro Carvalho Chehab4f27dba2016-03-03 12:14:33 -030063 * @vdev: pointer to struct video_device
Shuah Khand0a164f2016-02-11 21:41:25 -020064 *
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 */
72void 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 */
86int v4l_vb2q_enable_media_source(struct vb2_queue *q);
87
Steve Longerbeam0d3c81e2020-05-01 19:15:37 +020088/**
89 * v4l2_create_fwnode_links_to_pad - Create fwnode-based links from a
90 * source subdev to a sink subdev pad.
91 *
92 * @src_sd - pointer to a source subdev
93 * @sink - pointer to a subdev sink pad
94 *
95 * This function searches for fwnode endpoint connections from a source
96 * subdevice to a single sink pad, and if suitable connections are found,
97 * translates them into media links to that pad. The function can be
98 * called by the sink subdevice, in its v4l2-async notifier subdev bound
99 * callback, to create links from a bound source subdevice.
100 *
101 * .. note::
102 *
103 * Any sink subdevice that calls this function must implement the
104 * .get_fwnode_pad media operation in order to verify endpoints passed
105 * to the sink are owned by the sink.
106 *
107 * Return 0 on success or a negative error code on failure.
108 */
109int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd,
110 struct media_pad *sink);
111
112/**
113 * v4l2_create_fwnode_links - Create fwnode-based links from a source
114 * subdev to a sink subdev.
115 *
116 * @src_sd - pointer to a source subdevice
117 * @sink_sd - pointer to a sink subdevice
118 *
119 * This function searches for any and all fwnode endpoint connections
120 * between source and sink subdevices, and translates them into media
121 * links. The function can be called by the sink subdevice, in its
122 * v4l2-async notifier subdev bound callback, to create all links from
123 * a bound source subdevice.
124 *
125 * .. note::
126 *
127 * Any sink subdevice that calls this function must implement the
128 * .get_fwnode_pad media operation in order to verify endpoints passed
129 * to the sink are owned by the sink.
130 *
131 * Return 0 on success or a negative error code on failure.
132 */
133int v4l2_create_fwnode_links(struct v4l2_subdev *src_sd,
134 struct v4l2_subdev *sink_sd);
Sakari Ailus76413792016-02-21 13:25:09 -0300135
136/**
Ezequiel Garcia8fd390b2020-01-24 21:35:43 +0100137 * v4l2_pipeline_pm_get - Increase the use count of a pipeline
138 * @entity: The root entity of a pipeline
Sakari Ailus76413792016-02-21 13:25:09 -0300139 *
Ezequiel Garcia8fd390b2020-01-24 21:35:43 +0100140 * Update the use count of all entities in the pipeline and power entities on.
Sakari Ailus76413792016-02-21 13:25:09 -0300141 *
Ezequiel Garcia8fd390b2020-01-24 21:35:43 +0100142 * This function is intended to be called in video node open. It uses
143 * struct media_entity.use_count to track the power status. The use
144 * of this function should be paired with v4l2_pipeline_link_notify().
Sakari Ailus76413792016-02-21 13:25:09 -0300145 *
Ezequiel Garcia8fd390b2020-01-24 21:35:43 +0100146 * Return 0 on success or a negative error code on failure.
Sakari Ailus76413792016-02-21 13:25:09 -0300147 */
Ezequiel Garcia8fd390b2020-01-24 21:35:43 +0100148int v4l2_pipeline_pm_get(struct media_entity *entity);
149
150/**
151 * v4l2_pipeline_pm_put - Decrease the use count of a pipeline
152 * @entity: The root entity of a pipeline
153 *
154 * Update the use count of all entities in the pipeline and power entities off.
155 *
156 * This function is intended to be called in video node release. It uses
157 * struct media_entity.use_count to track the power status. The use
158 * of this function should be paired with v4l2_pipeline_link_notify().
159 */
160void v4l2_pipeline_pm_put(struct media_entity *entity);
Sakari Ailus76413792016-02-21 13:25:09 -0300161
162
163/**
164 * v4l2_pipeline_link_notify - Link management notification callback
165 * @link: The link
166 * @flags: New link flags that will be applied
167 * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*)
168 *
169 * React to link management on powered pipelines by updating the use count of
170 * all entities in the source and sink sides of the link. Entities are powered
171 * on or off accordingly. The use of this function should be paired
Ezequiel Garcia8fd390b2020-01-24 21:35:43 +0100172 * with v4l2_pipeline_pm_{get,put}().
Sakari Ailus76413792016-02-21 13:25:09 -0300173 *
174 * Return 0 on success or a negative error code on failure. Powering entities
175 * off is assumed to never fail. This function will not fail for disconnection
176 * events.
177 */
178int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
179 unsigned int notification);
180
Mauro Carvalho Chehaba77bf702016-03-03 12:30:51 -0300181#else /* CONFIG_MEDIA_CONTROLLER */
Shuah Khand0a164f2016-02-11 21:41:25 -0200182
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -0200183static inline int v4l2_mc_create_media_graph(struct media_device *mdev)
184{
185 return 0;
186}
Mauro Carvalho Chehab7047f292016-02-05 13:16:18 -0200187
Hans Verkuil9532e6b2016-03-03 04:37:14 -0300188static inline int v4l_enable_media_source(struct video_device *vdev)
Shuah Khand0a164f2016-02-11 21:41:25 -0200189{
190 return 0;
191}
192
Hans Verkuil9532e6b2016-03-03 04:37:14 -0300193static inline void v4l_disable_media_source(struct video_device *vdev)
Shuah Khand0a164f2016-02-11 21:41:25 -0200194{
Shuah Khand0a164f2016-02-11 21:41:25 -0200195}
196
Hans Verkuil9532e6b2016-03-03 04:37:14 -0300197static inline int v4l_vb2q_enable_media_source(struct vb2_queue *q)
Shuah Khand0a164f2016-02-11 21:41:25 -0200198{
199 return 0;
200}
Mauro Carvalho Chehaba77bf702016-03-03 12:30:51 -0300201
Ezequiel Garcia8fd390b2020-01-24 21:35:43 +0100202static inline int v4l2_pipeline_pm_get(struct media_entity *entity)
Mauro Carvalho Chehaba77bf702016-03-03 12:30:51 -0300203{
204 return 0;
205}
206
Ezequiel Garcia8fd390b2020-01-24 21:35:43 +0100207static inline void v4l2_pipeline_pm_put(struct media_entity *entity)
208{}
209
Hans Verkuil1e89f582016-03-04 05:46:58 -0300210static inline int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
211 unsigned int notification)
Mauro Carvalho Chehaba77bf702016-03-03 12:30:51 -0300212{
213 return 0;
214}
215
216#endif /* CONFIG_MEDIA_CONTROLLER */
Shuah Khand0a164f2016-02-11 21:41:25 -0200217#endif /* _V4L2_MC_H */