blob: bf5043c1ab6b3a326f894c817ec59b244a451397 [file] [log] [blame]
Mauro Carvalho Chehab6aad1272016-01-29 06:11:30 -02001/*
2 * v4l2-mc.h - Media Controller V4L2 types and prototypes
3 *
Mauro Carvalho Chehabdc19ed12016-06-14 14:48:50 -03004 * Copyright (C) 2016 Mauro Carvalho Chehab <mchehab@kernel.org>
Sakari Ailus76413792016-02-21 13:25:09 -03005 * Copyright (C) 2006-2010 Nokia Corporation
6 * Copyright (c) 2016 Intel Corporation.
Mauro Carvalho Chehab6aad1272016-01-29 06:11:30 -02007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
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
Mauro Carvalho Chehabdb152272016-02-12 07:35:44 -020019#ifndef _V4L2_MC_H
20#define _V4L2_MC_H
21
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -020022#include <media/media-device.h>
Shuah Khand0a164f2016-02-11 21:41:25 -020023#include <media/v4l2-dev.h>
Sakari Ailus76413792016-02-21 13:25:09 -030024#include <linux/types.h>
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -020025
Mauro Carvalho Chehabeee7d352016-02-11 15:21:46 -020026/* We don't need to include pci.h or usb.h here */
27struct pci_dev;
28struct usb_device;
Mauro Carvalho Chehab7047f292016-02-05 13:16:18 -020029
30#ifdef CONFIG_MEDIA_CONTROLLER
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -020031/**
32 * v4l2_mc_create_media_graph() - create Media Controller links at the graph.
33 *
34 * @mdev: pointer to the &media_device struct.
35 *
36 * Add links between the entities commonly found on PC customer's hardware at
37 * the V4L2 side: camera sensors, audio and video PLL-IF decoders, tuners,
38 * analog TV decoder and I/O entities (video, VBI and Software Defined Radio).
Mauro Carvalho Chehab89cb3dd2016-07-17 08:44:08 -030039 *
40 * .. note::
41 *
42 * Webcams are modelled on a very simple way: the sensor is
43 * connected directly to the I/O entity. All dirty details, like
44 * scaler and crop HW are hidden. While such mapping is enough for v4l2
45 * interface centric PC-consumer's hardware, V4L2 subdev centric camera
46 * hardware should not use this routine, as it will not build the right graph.
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -020047 */
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -020048int v4l2_mc_create_media_graph(struct media_device *mdev);
Mauro Carvalho Chehab7047f292016-02-05 13:16:18 -020049
Shuah Khand0a164f2016-02-11 21:41:25 -020050/**
51 * v4l_enable_media_source() - Hold media source for exclusive use
52 * if free
53 *
Mauro Carvalho Chehab4f27dba2016-03-03 12:14:33 -030054 * @vdev: pointer to struct video_device
Shuah Khand0a164f2016-02-11 21:41:25 -020055 *
56 * This interface calls enable_source handler to determine if
57 * media source is free for use. The enable_source handler is
58 * responsible for checking is the media source is free and
59 * start a pipeline between the media source and the media
60 * entity associated with the video device. This interface
61 * should be called from v4l2-core and dvb-core interfaces
62 * that change the source configuration.
63 *
64 * Return: returns zero on success or a negative error code.
65 */
66int v4l_enable_media_source(struct video_device *vdev);
67
68/**
69 * v4l_disable_media_source() - Release media source
70 *
Mauro Carvalho Chehab4f27dba2016-03-03 12:14:33 -030071 * @vdev: pointer to struct video_device
Shuah Khand0a164f2016-02-11 21:41:25 -020072 *
73 * This interface calls disable_source handler to release
74 * the media source. The disable_source handler stops the
75 * active media pipeline between the media source and the
76 * media entity associated with the video device.
77 *
78 * Return: returns zero on success or a negative error code.
79 */
80void v4l_disable_media_source(struct video_device *vdev);
81
82/*
83 * v4l_vb2q_enable_media_tuner - Hold media source for exclusive use
84 * if free.
85 * @q - pointer to struct vb2_queue
86 *
87 * Wrapper for v4l_enable_media_source(). This function should
88 * be called from v4l2-core to enable the media source with
89 * pointer to struct vb2_queue as the input argument. Some
90 * v4l2-core interfaces don't have access to video device and
91 * this interface finds the struct video_device for the q and
92 * calls v4l_enable_media_source().
93 */
94int v4l_vb2q_enable_media_source(struct vb2_queue *q);
95
Sakari Ailus76413792016-02-21 13:25:09 -030096
97/**
98 * v4l2_pipeline_pm_use - Update the use count of an entity
99 * @entity: The entity
100 * @use: Use (1) or stop using (0) the entity
101 *
102 * Update the use count of all entities in the pipeline and power entities on or
103 * off accordingly.
104 *
105 * This function is intended to be called in video node open (use ==
106 * 1) and release (use == 0). It uses struct media_entity.use_count to
107 * track the power status. The use of this function should be paired
108 * with v4l2_pipeline_link_notify().
109 *
110 * Return 0 on success or a negative error code on failure. Powering entities
111 * off is assumed to never fail. No failure can occur when the use parameter is
112 * set to 0.
113 */
114int v4l2_pipeline_pm_use(struct media_entity *entity, int use);
115
116
117/**
118 * v4l2_pipeline_link_notify - Link management notification callback
119 * @link: The link
120 * @flags: New link flags that will be applied
121 * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*)
122 *
123 * React to link management on powered pipelines by updating the use count of
124 * all entities in the source and sink sides of the link. Entities are powered
125 * on or off accordingly. The use of this function should be paired
126 * with v4l2_pipeline_pm_use().
127 *
128 * Return 0 on success or a negative error code on failure. Powering entities
129 * off is assumed to never fail. This function will not fail for disconnection
130 * events.
131 */
132int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
133 unsigned int notification);
134
Mauro Carvalho Chehaba77bf702016-03-03 12:30:51 -0300135#else /* CONFIG_MEDIA_CONTROLLER */
Shuah Khand0a164f2016-02-11 21:41:25 -0200136
Mauro Carvalho Chehab54d0dba2016-02-05 07:02:43 -0200137static inline int v4l2_mc_create_media_graph(struct media_device *mdev)
138{
139 return 0;
140}
Mauro Carvalho Chehab7047f292016-02-05 13:16:18 -0200141
Hans Verkuil9532e6b2016-03-03 04:37:14 -0300142static inline int v4l_enable_media_source(struct video_device *vdev)
Shuah Khand0a164f2016-02-11 21:41:25 -0200143{
144 return 0;
145}
146
Hans Verkuil9532e6b2016-03-03 04:37:14 -0300147static inline void v4l_disable_media_source(struct video_device *vdev)
Shuah Khand0a164f2016-02-11 21:41:25 -0200148{
Shuah Khand0a164f2016-02-11 21:41:25 -0200149}
150
Hans Verkuil9532e6b2016-03-03 04:37:14 -0300151static inline int v4l_vb2q_enable_media_source(struct vb2_queue *q)
Shuah Khand0a164f2016-02-11 21:41:25 -0200152{
153 return 0;
154}
Mauro Carvalho Chehaba77bf702016-03-03 12:30:51 -0300155
Hans Verkuil1e89f582016-03-04 05:46:58 -0300156static inline int v4l2_pipeline_pm_use(struct media_entity *entity, int use)
Mauro Carvalho Chehaba77bf702016-03-03 12:30:51 -0300157{
158 return 0;
159}
160
Hans Verkuil1e89f582016-03-04 05:46:58 -0300161static inline int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
162 unsigned int notification)
Mauro Carvalho Chehaba77bf702016-03-03 12:30:51 -0300163{
164 return 0;
165}
166
167#endif /* CONFIG_MEDIA_CONTROLLER */
Shuah Khand0a164f2016-02-11 21:41:25 -0200168#endif /* _V4L2_MC_H */