Merge tag 'slab-for-6.1-rc1-hotfix' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / include / media / v4l2-mediabus.h
CommitLineData
d2912cb1 1/* SPDX-License-Identifier: GPL-2.0-only */
9a74251d
GL
2/*
3 * Media Bus API header
4 *
5 * Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
9a74251d
GL
6 */
7
8#ifndef V4L2_MEDIABUS_H
9#define V4L2_MEDIABUS_H
10
2ef2d5a3 11#include <linux/v4l2-mediabus.h>
2120961f
MCC
12#include <linux/bitops.h>
13
ddf5c927
JM
14/*
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
a2992999
LP
18 * shall be set by the users of the v4l2_subdev_pad_ops.get_mbus_config
19 * operation to ensure that no conflicting settings are specified when
20 * reporting the media bus configuration. For example, it is invalid to set or
21 * clear both the V4L2_MBUS_HSYNC_ACTIVE_HIGH and the
ddf5c927 22 * V4L2_MBUS_HSYNC_ACTIVE_LOW flag at the same time. Instead either flag
a2992999 23 * V4L2_MBUS_HSYNC_ACTIVE_HIGH or flag V4L2_MBUS_HSYNC_ACTIVE_LOW shall be set.
ddf5c927
JM
24 *
25 * TODO: replace the existing V4L2_MBUS_* flags with structures of fields
26 * to avoid conflicting settings.
27 *
28 * In example:
29 * #define V4L2_MBUS_HSYNC_ACTIVE_HIGH BIT(2)
30 * #define V4L2_MBUS_HSYNC_ACTIVE_LOW BIT(3)
31 * will be replaced by a field whose value reports the intended active state of
32 * the signal:
33 * unsigned int v4l2_mbus_hsync_active : 1;
34 */
35
91c79530
GL
36/* Parallel flags */
37/*
ddf5c927 38 * The client runs in master or in slave mode. By "Master mode" an operation
91c79530
GL
39 * mode is meant, when the client (e.g., a camera sensor) is producing
40 * horizontal and vertical synchronisation. In "Slave mode" the host is
41 * providing these signals to the slave.
42 */
2120961f
MCC
43#define V4L2_MBUS_MASTER BIT(0)
44#define V4L2_MBUS_SLAVE BIT(1)
3c6938f8
SN
45/*
46 * Signal polarity flags
47 * Note: in BT.656 mode HSYNC, FIELD, and VSYNC are unused
48 * V4L2_MBUS_[HV]SYNC* flags should be also used for specifying
49 * configuration of hardware that uses [HV]REF signals
50 */
2120961f
MCC
51#define V4L2_MBUS_HSYNC_ACTIVE_HIGH BIT(2)
52#define V4L2_MBUS_HSYNC_ACTIVE_LOW BIT(3)
53#define V4L2_MBUS_VSYNC_ACTIVE_HIGH BIT(4)
54#define V4L2_MBUS_VSYNC_ACTIVE_LOW BIT(5)
55#define V4L2_MBUS_PCLK_SAMPLE_RISING BIT(6)
56#define V4L2_MBUS_PCLK_SAMPLE_FALLING BIT(7)
57#define V4L2_MBUS_DATA_ACTIVE_HIGH BIT(8)
58#define V4L2_MBUS_DATA_ACTIVE_LOW BIT(9)
3c6938f8 59/* FIELD = 0/1 - Field1 (odd)/Field2 (even) */
2120961f 60#define V4L2_MBUS_FIELD_EVEN_HIGH BIT(10)
3c6938f8 61/* FIELD = 1/0 - Field1 (odd)/Field2 (even) */
2120961f 62#define V4L2_MBUS_FIELD_EVEN_LOW BIT(11)
d1d70aa6 63/* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */
2120961f
MCC
64#define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH BIT(12)
65#define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW BIT(13)
9b04fcc1
JM
66#define V4L2_MBUS_DATA_ENABLE_HIGH BIT(14)
67#define V4L2_MBUS_DATA_ENABLE_LOW BIT(15)
91c79530
GL
68
69/* Serial flags */
ddf5c927 70/* Clock non-continuous mode support. */
b9f7caa7 71#define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK BIT(0)
91c79530 72
94d964e5
LP
73#define V4L2_MBUS_CSI2_MAX_DATA_LANES 8
74
75/**
76 * struct v4l2_mbus_config_mipi_csi2 - MIPI CSI-2 data bus configuration
77 * @flags: media bus (V4L2_MBUS_*) flags
78 * @data_lanes: an array of physical data lane indexes
79 * @clock_lane: physical lane index of the clock lane
80 * @num_data_lanes: number of data lanes
81 * @lane_polarities: polarity of the lanes. The order is the same of
82 * the physical lanes.
83 */
84struct v4l2_mbus_config_mipi_csi2 {
85 unsigned int flags;
86 unsigned char data_lanes[V4L2_MBUS_CSI2_MAX_DATA_LANES];
87 unsigned char clock_lane;
88 unsigned char num_data_lanes;
89 bool lane_polarities[1 + V4L2_MBUS_CSI2_MAX_DATA_LANES];
90};
91
92/**
93 * struct v4l2_mbus_config_parallel - parallel data bus configuration
94 * @flags: media bus (V4L2_MBUS_*) flags
95 * @bus_width: bus width in bits
96 * @data_shift: data shift in bits
97 */
98struct v4l2_mbus_config_parallel {
99 unsigned int flags;
100 unsigned char bus_width;
101 unsigned char data_shift;
102};
103
104/**
105 * struct v4l2_mbus_config_mipi_csi1 - CSI-1/CCP2 data bus configuration
106 * @clock_inv: polarity of clock/strobe signal
107 * false - not inverted, true - inverted
108 * @strobe: false - data/clock, true - data/strobe
109 * @lane_polarity: the polarities of the clock (index 0) and data lanes
110 * index (1)
111 * @data_lane: the number of the data lane
112 * @clock_lane: the number of the clock lane
113 */
114struct v4l2_mbus_config_mipi_csi1 {
115 unsigned char clock_inv:1;
116 unsigned char strobe:1;
117 bool lane_polarity[2];
118 unsigned char data_lane;
119 unsigned char clock_lane;
120};
121
91c79530 122/**
98d00bd7 123 * enum v4l2_mbus_type - media bus type
2835b5b1 124 * @V4L2_MBUS_UNKNOWN: unknown bus type, no V4L2 mediabus configuration
91c79530
GL
125 * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync
126 * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can
127 * also be used for BT.1120
97bbdf02
SA
128 * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface
129 * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2)
2d95e7ed
SA
130 * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY
131 * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
5e052a4d 132 * @V4L2_MBUS_DPI: MIPI VIDEO DPI interface
69baf338 133 * @V4L2_MBUS_INVALID: invalid bus type (keep as last)
91c79530
GL
134 */
135enum v4l2_mbus_type {
2835b5b1 136 V4L2_MBUS_UNKNOWN,
91c79530
GL
137 V4L2_MBUS_PARALLEL,
138 V4L2_MBUS_BT656,
97bbdf02
SA
139 V4L2_MBUS_CSI1,
140 V4L2_MBUS_CCP2,
2d95e7ed
SA
141 V4L2_MBUS_CSI2_DPHY,
142 V4L2_MBUS_CSI2_CPHY,
5e052a4d 143 V4L2_MBUS_DPI,
69baf338 144 V4L2_MBUS_INVALID,
91c79530
GL
145};
146
147/**
98d00bd7 148 * struct v4l2_mbus_config - media bus configuration
6a7bdd89
LP
149 * @type: interface type
150 * @bus: bus configuration data structure
151 * @bus.parallel: embedded &struct v4l2_mbus_config_parallel.
152 * Used if the bus is parallel or BT.656.
153 * @bus.mipi_csi1: embedded &struct v4l2_mbus_config_mipi_csi1.
154 * Used if the bus is MIPI Alliance's Camera Serial
155 * Interface version 1 (MIPI CSI1) or Standard
156 * Mobile Imaging Architecture's Compact Camera Port 2
157 * (SMIA CCP2).
158 * @bus.mipi_csi2: embedded &struct v4l2_mbus_config_mipi_csi2.
159 * Used if the bus is MIPI Alliance's Camera Serial
160 * Interface version 2 (MIPI CSI2).
91c79530
GL
161 */
162struct v4l2_mbus_config {
163 enum v4l2_mbus_type type;
6a7bdd89
LP
164 union {
165 struct v4l2_mbus_config_parallel parallel;
166 struct v4l2_mbus_config_mipi_csi1 mipi_csi1;
167 struct v4l2_mbus_config_mipi_csi2 mipi_csi2;
168 } bus;
91c79530
GL
169};
170
4839c58f
MCC
171/**
172 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
173 * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt.
174 *
175 * @pix_fmt: pointer to &struct v4l2_pix_format to be filled
176 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
177 */
6087b215
MCC
178static inline void
179v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
180 const struct v4l2_mbus_framefmt *mbus_fmt)
3a21ceed
HV
181{
182 pix_fmt->width = mbus_fmt->width;
183 pix_fmt->height = mbus_fmt->height;
184 pix_fmt->field = mbus_fmt->field;
185 pix_fmt->colorspace = mbus_fmt->colorspace;
11ff030c
HV
186 pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
187 pix_fmt->quantization = mbus_fmt->quantization;
74fdcb2e 188 pix_fmt->xfer_func = mbus_fmt->xfer_func;
3a21ceed
HV
189}
190
4839c58f 191/**
b0649455 192 * v4l2_fill_mbus_format - Ancillary routine that fills a &struct
4839c58f
MCC
193 * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a
194 * data format code.
195 *
196 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
197 * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model
198 * @code: data format code (from &enum v4l2_mbus_pixelcode)
199 */
3a21ceed 200static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
6087b215 201 const struct v4l2_pix_format *pix_fmt,
32b32ce8 202 u32 code)
3a21ceed
HV
203{
204 mbus_fmt->width = pix_fmt->width;
205 mbus_fmt->height = pix_fmt->height;
206 mbus_fmt->field = pix_fmt->field;
207 mbus_fmt->colorspace = pix_fmt->colorspace;
11ff030c
HV
208 mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc;
209 mbus_fmt->quantization = pix_fmt->quantization;
74fdcb2e 210 mbus_fmt->xfer_func = pix_fmt->xfer_func;
3a21ceed
HV
211 mbus_fmt->code = code;
212}
213
4839c58f 214/**
b0649455 215 * v4l2_fill_pix_format_mplane - Ancillary routine that fills a &struct
4839c58f
MCC
216 * v4l2_pix_format_mplane fields from a media bus structure.
217 *
218 * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled
219 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
220 */
6087b215
MCC
221static inline void
222v4l2_fill_pix_format_mplane(struct v4l2_pix_format_mplane *pix_mp_fmt,
223 const struct v4l2_mbus_framefmt *mbus_fmt)
f1923010
TT
224{
225 pix_mp_fmt->width = mbus_fmt->width;
226 pix_mp_fmt->height = mbus_fmt->height;
227 pix_mp_fmt->field = mbus_fmt->field;
228 pix_mp_fmt->colorspace = mbus_fmt->colorspace;
229 pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
230 pix_mp_fmt->quantization = mbus_fmt->quantization;
231 pix_mp_fmt->xfer_func = mbus_fmt->xfer_func;
232}
233
4839c58f 234/**
b0649455 235 * v4l2_fill_mbus_format_mplane - Ancillary routine that fills a &struct
4839c58f
MCC
236 * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane.
237 *
238 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
239 * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model
240 */
6087b215
MCC
241static inline void
242v4l2_fill_mbus_format_mplane(struct v4l2_mbus_framefmt *mbus_fmt,
243 const struct v4l2_pix_format_mplane *pix_mp_fmt)
f1923010
TT
244{
245 mbus_fmt->width = pix_mp_fmt->width;
246 mbus_fmt->height = pix_mp_fmt->height;
247 mbus_fmt->field = pix_mp_fmt->field;
248 mbus_fmt->colorspace = pix_mp_fmt->colorspace;
249 mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc;
250 mbus_fmt->quantization = pix_mp_fmt->quantization;
251 mbus_fmt->xfer_func = pix_mp_fmt->xfer_func;
252}
253
9a74251d 254#endif