blob: 841e190aedd9048396c3147289e2ae78fe16d4b0 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -03002/*
3 * Media Bus API header
4 *
5 * Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -03006 */
7
8#ifndef V4L2_MEDIABUS_H
9#define V4L2_MEDIABUS_H
10
Laurent Pinchart2ef2d5a2010-03-15 19:33:31 -030011#include <linux/v4l2-mediabus.h>
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040012#include <linux/bitops.h>
13
Jacopo Mondiddf5c922020-07-17 16:53:20 +020014/*
15 * How to use the V4L2_MBUS_* flags:
16 * Flags are defined for each of the possible states and values of a media
17 * bus configuration parameter. One and only one bit of each group of flags
18 * shall be set by the users of the v4l2_subdev_pad_ops.get_mbus_config and
19 * v4l2_subdev_pad_ops.set_mbus_config operations to ensure that no
20 * conflicting settings are specified when reporting and setting the media bus
21 * configuration with the two operations respectively. For example, it is
22 * invalid to set or clear both the V4L2_MBUS_HSYNC_ACTIVE_HIGH and the
23 * V4L2_MBUS_HSYNC_ACTIVE_LOW flag at the same time. Instead either flag
24 * V4L2_MBUS_HSYNC_ACTIVE_HIGH or flag V4L2_MBUS_HSYNC_ACTIVE_LOW shall be
25 * set. The same is true for the V4L2_MBUS_CSI2_1/2/3/4_LANE flags group: only
26 * one of these four bits shall be set.
27 *
28 * TODO: replace the existing V4L2_MBUS_* flags with structures of fields
29 * to avoid conflicting settings.
30 *
31 * In example:
32 * #define V4L2_MBUS_HSYNC_ACTIVE_HIGH BIT(2)
33 * #define V4L2_MBUS_HSYNC_ACTIVE_LOW BIT(3)
34 * will be replaced by a field whose value reports the intended active state of
35 * the signal:
36 * unsigned int v4l2_mbus_hsync_active : 1;
37 */
38
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030039/* Parallel flags */
40/*
Jacopo Mondiddf5c922020-07-17 16:53:20 +020041 * The client runs in master or in slave mode. By "Master mode" an operation
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030042 * mode is meant, when the client (e.g., a camera sensor) is producing
43 * horizontal and vertical synchronisation. In "Slave mode" the host is
44 * providing these signals to the slave.
45 */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040046#define V4L2_MBUS_MASTER BIT(0)
47#define V4L2_MBUS_SLAVE BIT(1)
Sylwester Nawrocki3c6938f2011-09-19 12:58:54 -030048/*
49 * Signal polarity flags
50 * Note: in BT.656 mode HSYNC, FIELD, and VSYNC are unused
51 * V4L2_MBUS_[HV]SYNC* flags should be also used for specifying
52 * configuration of hardware that uses [HV]REF signals
53 */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040054#define V4L2_MBUS_HSYNC_ACTIVE_HIGH BIT(2)
55#define V4L2_MBUS_HSYNC_ACTIVE_LOW BIT(3)
56#define V4L2_MBUS_VSYNC_ACTIVE_HIGH BIT(4)
57#define V4L2_MBUS_VSYNC_ACTIVE_LOW BIT(5)
58#define V4L2_MBUS_PCLK_SAMPLE_RISING BIT(6)
59#define V4L2_MBUS_PCLK_SAMPLE_FALLING BIT(7)
60#define V4L2_MBUS_DATA_ACTIVE_HIGH BIT(8)
61#define V4L2_MBUS_DATA_ACTIVE_LOW BIT(9)
Sylwester Nawrocki3c6938f2011-09-19 12:58:54 -030062/* FIELD = 0/1 - Field1 (odd)/Field2 (even) */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040063#define V4L2_MBUS_FIELD_EVEN_HIGH BIT(10)
Sylwester Nawrocki3c6938f2011-09-19 12:58:54 -030064/* FIELD = 1/0 - Field1 (odd)/Field2 (even) */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040065#define V4L2_MBUS_FIELD_EVEN_LOW BIT(11)
Lad, Prabhakard1d70aa62013-08-11 02:02:24 -030066/* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040067#define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH BIT(12)
68#define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW BIT(13)
Jacopo Mondi9b04fcc2018-07-09 10:19:19 -040069#define V4L2_MBUS_DATA_ENABLE_HIGH BIT(14)
70#define V4L2_MBUS_DATA_ENABLE_LOW BIT(15)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030071
72/* Serial flags */
Jacopo Mondiddf5c922020-07-17 16:53:20 +020073/* CSI-2 D-PHY number of data lanes. */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040074#define V4L2_MBUS_CSI2_1_LANE BIT(0)
75#define V4L2_MBUS_CSI2_2_LANE BIT(1)
76#define V4L2_MBUS_CSI2_3_LANE BIT(2)
77#define V4L2_MBUS_CSI2_4_LANE BIT(3)
Jacopo Mondiddf5c922020-07-17 16:53:20 +020078/* CSI-2 Virtual Channel identifiers. */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040079#define V4L2_MBUS_CSI2_CHANNEL_0 BIT(4)
80#define V4L2_MBUS_CSI2_CHANNEL_1 BIT(5)
81#define V4L2_MBUS_CSI2_CHANNEL_2 BIT(6)
82#define V4L2_MBUS_CSI2_CHANNEL_3 BIT(7)
Jacopo Mondiddf5c922020-07-17 16:53:20 +020083/* Clock non-continuous mode support. */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040084#define V4L2_MBUS_CSI2_CONTINUOUS_CLOCK BIT(8)
85#define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK BIT(9)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030086
Mauro Carvalho Chehab6087b212018-10-04 17:10:46 -040087#define V4L2_MBUS_CSI2_LANES (V4L2_MBUS_CSI2_1_LANE | \
88 V4L2_MBUS_CSI2_2_LANE | \
89 V4L2_MBUS_CSI2_3_LANE | \
90 V4L2_MBUS_CSI2_4_LANE)
91#define V4L2_MBUS_CSI2_CHANNELS (V4L2_MBUS_CSI2_CHANNEL_0 | \
92 V4L2_MBUS_CSI2_CHANNEL_1 | \
93 V4L2_MBUS_CSI2_CHANNEL_2 | \
94 V4L2_MBUS_CSI2_CHANNEL_3)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030095
96/**
Mauro Carvalho Chehab98d00bd2015-08-22 09:04:46 -030097 * enum v4l2_mbus_type - media bus type
Sakari Ailus2835b5b2018-07-31 06:43:14 -040098 * @V4L2_MBUS_UNKNOWN: unknown bus type, no V4L2 mediabus configuration
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030099 * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync
100 * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can
101 * also be used for BT.1120
Sakari Ailus97bbdf02015-02-25 14:39:11 -0500102 * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface
103 * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2)
Sakari Ailus2d95e7e2018-07-03 17:19:27 -0400104 * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY
105 * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
Lad Prabhakar69baf332020-09-17 18:08:47 +0200106 * @V4L2_MBUS_INVALID: invalid bus type (keep as last)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -0300107 */
108enum v4l2_mbus_type {
Sakari Ailus2835b5b2018-07-31 06:43:14 -0400109 V4L2_MBUS_UNKNOWN,
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -0300110 V4L2_MBUS_PARALLEL,
111 V4L2_MBUS_BT656,
Sakari Ailus97bbdf02015-02-25 14:39:11 -0500112 V4L2_MBUS_CSI1,
113 V4L2_MBUS_CCP2,
Sakari Ailus2d95e7e2018-07-03 17:19:27 -0400114 V4L2_MBUS_CSI2_DPHY,
115 V4L2_MBUS_CSI2_CPHY,
Lad Prabhakar69baf332020-09-17 18:08:47 +0200116 V4L2_MBUS_INVALID,
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -0300117};
118
119/**
Mauro Carvalho Chehab98d00bd2015-08-22 09:04:46 -0300120 * struct v4l2_mbus_config - media bus configuration
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -0300121 * @type: in: interface type
122 * @flags: in / out: configuration flags, depending on @type
123 */
124struct v4l2_mbus_config {
125 enum v4l2_mbus_type type;
126 unsigned int flags;
127};
128
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400129/**
130 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
131 * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt.
132 *
133 * @pix_fmt: pointer to &struct v4l2_pix_format to be filled
134 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
135 */
Mauro Carvalho Chehab6087b212018-10-04 17:10:46 -0400136static inline void
137v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
138 const struct v4l2_mbus_framefmt *mbus_fmt)
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300139{
140 pix_fmt->width = mbus_fmt->width;
141 pix_fmt->height = mbus_fmt->height;
142 pix_fmt->field = mbus_fmt->field;
143 pix_fmt->colorspace = mbus_fmt->colorspace;
Hans Verkuil11ff0302014-11-17 09:10:33 -0300144 pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
145 pix_fmt->quantization = mbus_fmt->quantization;
Hans Verkuil74fdcb22015-04-28 08:49:09 -0300146 pix_fmt->xfer_func = mbus_fmt->xfer_func;
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300147}
148
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400149/**
Mauro Carvalho Chehabb0649452020-10-23 16:08:10 +0200150 * v4l2_fill_mbus_format - Ancillary routine that fills a &struct
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400151 * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a
152 * data format code.
153 *
154 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
155 * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model
156 * @code: data format code (from &enum v4l2_mbus_pixelcode)
157 */
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300158static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
Mauro Carvalho Chehab6087b212018-10-04 17:10:46 -0400159 const struct v4l2_pix_format *pix_fmt,
Boris BREZILLON32b32ce2014-11-10 14:28:28 -0300160 u32 code)
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300161{
162 mbus_fmt->width = pix_fmt->width;
163 mbus_fmt->height = pix_fmt->height;
164 mbus_fmt->field = pix_fmt->field;
165 mbus_fmt->colorspace = pix_fmt->colorspace;
Hans Verkuil11ff0302014-11-17 09:10:33 -0300166 mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc;
167 mbus_fmt->quantization = pix_fmt->quantization;
Hans Verkuil74fdcb22015-04-28 08:49:09 -0300168 mbus_fmt->xfer_func = pix_fmt->xfer_func;
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300169 mbus_fmt->code = code;
170}
171
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400172/**
Mauro Carvalho Chehabb0649452020-10-23 16:08:10 +0200173 * v4l2_fill_pix_format_mplane - Ancillary routine that fills a &struct
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400174 * v4l2_pix_format_mplane fields from a media bus structure.
175 *
176 * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled
177 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
178 */
Mauro Carvalho Chehab6087b212018-10-04 17:10:46 -0400179static inline void
180v4l2_fill_pix_format_mplane(struct v4l2_pix_format_mplane *pix_mp_fmt,
181 const struct v4l2_mbus_framefmt *mbus_fmt)
Todor Tomovf1923012017-07-07 04:48:47 -0400182{
183 pix_mp_fmt->width = mbus_fmt->width;
184 pix_mp_fmt->height = mbus_fmt->height;
185 pix_mp_fmt->field = mbus_fmt->field;
186 pix_mp_fmt->colorspace = mbus_fmt->colorspace;
187 pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
188 pix_mp_fmt->quantization = mbus_fmt->quantization;
189 pix_mp_fmt->xfer_func = mbus_fmt->xfer_func;
190}
191
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400192/**
Mauro Carvalho Chehabb0649452020-10-23 16:08:10 +0200193 * v4l2_fill_mbus_format_mplane - Ancillary routine that fills a &struct
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400194 * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane.
195 *
196 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
197 * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model
198 */
Mauro Carvalho Chehab6087b212018-10-04 17:10:46 -0400199static inline void
200v4l2_fill_mbus_format_mplane(struct v4l2_mbus_framefmt *mbus_fmt,
201 const struct v4l2_pix_format_mplane *pix_mp_fmt)
Todor Tomovf1923012017-07-07 04:48:47 -0400202{
203 mbus_fmt->width = pix_mp_fmt->width;
204 mbus_fmt->height = pix_mp_fmt->height;
205 mbus_fmt->field = pix_mp_fmt->field;
206 mbus_fmt->colorspace = pix_mp_fmt->colorspace;
207 mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc;
208 mbus_fmt->quantization = pix_mp_fmt->quantization;
209 mbus_fmt->xfer_func = pix_mp_fmt->xfer_func;
210}
211
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300212#endif