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