Commit | Line | Data |
---|---|---|
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 | |
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 | ||
91c79530 GL |
39 | /* Parallel flags */ |
40 | /* | |
ddf5c927 | 41 | * The client runs in master or in slave mode. By "Master mode" an operation |
91c79530 GL |
42 | * 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 | */ | |
2120961f MCC |
46 | #define V4L2_MBUS_MASTER BIT(0) |
47 | #define V4L2_MBUS_SLAVE BIT(1) | |
3c6938f8 SN |
48 | /* |
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 | */ | |
2120961f MCC |
54 | #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) | |
3c6938f8 | 62 | /* FIELD = 0/1 - Field1 (odd)/Field2 (even) */ |
2120961f | 63 | #define V4L2_MBUS_FIELD_EVEN_HIGH BIT(10) |
3c6938f8 | 64 | /* FIELD = 1/0 - Field1 (odd)/Field2 (even) */ |
2120961f | 65 | #define V4L2_MBUS_FIELD_EVEN_LOW BIT(11) |
d1d70aa6 | 66 | /* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */ |
2120961f MCC |
67 | #define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH BIT(12) |
68 | #define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW BIT(13) | |
9b04fcc1 JM |
69 | #define V4L2_MBUS_DATA_ENABLE_HIGH BIT(14) |
70 | #define V4L2_MBUS_DATA_ENABLE_LOW BIT(15) | |
91c79530 GL |
71 | |
72 | /* Serial flags */ | |
ddf5c927 | 73 | /* CSI-2 D-PHY number of data lanes. */ |
2120961f MCC |
74 | #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) | |
ddf5c927 | 78 | /* CSI-2 Virtual Channel identifiers. */ |
2120961f MCC |
79 | #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) | |
ddf5c927 | 83 | /* Clock non-continuous mode support. */ |
2120961f MCC |
84 | #define V4L2_MBUS_CSI2_CONTINUOUS_CLOCK BIT(8) |
85 | #define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK BIT(9) | |
91c79530 | 86 | |
6087b215 MCC |
87 | #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) | |
91c79530 GL |
95 | |
96 | /** | |
98d00bd7 | 97 | * enum v4l2_mbus_type - media bus type |
2835b5b1 | 98 | * @V4L2_MBUS_UNKNOWN: unknown bus type, no V4L2 mediabus configuration |
91c79530 GL |
99 | * @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 | |
97bbdf02 SA |
102 | * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface |
103 | * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2) | |
2d95e7ed SA |
104 | * @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 | |
91c79530 GL |
106 | */ |
107 | enum v4l2_mbus_type { | |
2835b5b1 | 108 | V4L2_MBUS_UNKNOWN, |
91c79530 GL |
109 | V4L2_MBUS_PARALLEL, |
110 | V4L2_MBUS_BT656, | |
97bbdf02 SA |
111 | V4L2_MBUS_CSI1, |
112 | V4L2_MBUS_CCP2, | |
2d95e7ed SA |
113 | V4L2_MBUS_CSI2_DPHY, |
114 | V4L2_MBUS_CSI2_CPHY, | |
91c79530 GL |
115 | }; |
116 | ||
117 | /** | |
98d00bd7 | 118 | * struct v4l2_mbus_config - media bus configuration |
91c79530 GL |
119 | * @type: in: interface type |
120 | * @flags: in / out: configuration flags, depending on @type | |
121 | */ | |
122 | struct v4l2_mbus_config { | |
123 | enum v4l2_mbus_type type; | |
124 | unsigned int flags; | |
125 | }; | |
126 | ||
4839c58f MCC |
127 | /** |
128 | * v4l2_fill_pix_format - Ancillary routine that fills a &struct | |
129 | * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt. | |
130 | * | |
131 | * @pix_fmt: pointer to &struct v4l2_pix_format to be filled | |
132 | * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model | |
133 | */ | |
6087b215 MCC |
134 | static inline void |
135 | v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt, | |
136 | const struct v4l2_mbus_framefmt *mbus_fmt) | |
3a21ceed HV |
137 | { |
138 | pix_fmt->width = mbus_fmt->width; | |
139 | pix_fmt->height = mbus_fmt->height; | |
140 | pix_fmt->field = mbus_fmt->field; | |
141 | pix_fmt->colorspace = mbus_fmt->colorspace; | |
11ff030c HV |
142 | pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc; |
143 | pix_fmt->quantization = mbus_fmt->quantization; | |
74fdcb2e | 144 | pix_fmt->xfer_func = mbus_fmt->xfer_func; |
3a21ceed HV |
145 | } |
146 | ||
4839c58f MCC |
147 | /** |
148 | * v4l2_fill_pix_format - Ancillary routine that fills a &struct | |
149 | * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a | |
150 | * data format code. | |
151 | * | |
152 | * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled | |
153 | * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model | |
154 | * @code: data format code (from &enum v4l2_mbus_pixelcode) | |
155 | */ | |
3a21ceed | 156 | static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt, |
6087b215 | 157 | const struct v4l2_pix_format *pix_fmt, |
32b32ce8 | 158 | u32 code) |
3a21ceed HV |
159 | { |
160 | mbus_fmt->width = pix_fmt->width; | |
161 | mbus_fmt->height = pix_fmt->height; | |
162 | mbus_fmt->field = pix_fmt->field; | |
163 | mbus_fmt->colorspace = pix_fmt->colorspace; | |
11ff030c HV |
164 | mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc; |
165 | mbus_fmt->quantization = pix_fmt->quantization; | |
74fdcb2e | 166 | mbus_fmt->xfer_func = pix_fmt->xfer_func; |
3a21ceed HV |
167 | mbus_fmt->code = code; |
168 | } | |
169 | ||
4839c58f MCC |
170 | /** |
171 | * v4l2_fill_pix_format - Ancillary routine that fills a &struct | |
172 | * v4l2_pix_format_mplane fields from a media bus structure. | |
173 | * | |
174 | * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled | |
175 | * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model | |
176 | */ | |
6087b215 MCC |
177 | static inline void |
178 | v4l2_fill_pix_format_mplane(struct v4l2_pix_format_mplane *pix_mp_fmt, | |
179 | const struct v4l2_mbus_framefmt *mbus_fmt) | |
f1923010 TT |
180 | { |
181 | pix_mp_fmt->width = mbus_fmt->width; | |
182 | pix_mp_fmt->height = mbus_fmt->height; | |
183 | pix_mp_fmt->field = mbus_fmt->field; | |
184 | pix_mp_fmt->colorspace = mbus_fmt->colorspace; | |
185 | pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc; | |
186 | pix_mp_fmt->quantization = mbus_fmt->quantization; | |
187 | pix_mp_fmt->xfer_func = mbus_fmt->xfer_func; | |
188 | } | |
189 | ||
4839c58f MCC |
190 | /** |
191 | * v4l2_fill_pix_format - Ancillary routine that fills a &struct | |
192 | * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane. | |
193 | * | |
194 | * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled | |
195 | * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model | |
196 | */ | |
6087b215 MCC |
197 | static inline void |
198 | v4l2_fill_mbus_format_mplane(struct v4l2_mbus_framefmt *mbus_fmt, | |
199 | const struct v4l2_pix_format_mplane *pix_mp_fmt) | |
f1923010 TT |
200 | { |
201 | mbus_fmt->width = pix_mp_fmt->width; | |
202 | mbus_fmt->height = pix_mp_fmt->height; | |
203 | mbus_fmt->field = pix_mp_fmt->field; | |
204 | mbus_fmt->colorspace = pix_mp_fmt->colorspace; | |
205 | mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc; | |
206 | mbus_fmt->quantization = pix_mp_fmt->quantization; | |
207 | mbus_fmt->xfer_func = pix_mp_fmt->xfer_func; | |
208 | } | |
209 | ||
9a74251d | 210 | #endif |