| 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 | * | 
|---|
| 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 |  | 
|---|
| 36 | /* Parallel flags */ | 
|---|
| 37 | /* | 
|---|
| 38 | * The client runs in master or in slave mode. By "Master mode" an operation | 
|---|
| 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 | */ | 
|---|
| 43 | #define V4L2_MBUS_MASTER			BIT(0) | 
|---|
| 44 | #define V4L2_MBUS_SLAVE				BIT(1) | 
|---|
| 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 | */ | 
|---|
| 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_PCLK_SAMPLE_DUALEDGE		BIT(8) | 
|---|
| 58 | #define V4L2_MBUS_DATA_ACTIVE_HIGH		BIT(9) | 
|---|
| 59 | #define V4L2_MBUS_DATA_ACTIVE_LOW		BIT(10) | 
|---|
| 60 | /* FIELD = 0/1 - Field1 (odd)/Field2 (even) */ | 
|---|
| 61 | #define V4L2_MBUS_FIELD_EVEN_HIGH		BIT(11) | 
|---|
| 62 | /* FIELD = 1/0 - Field1 (odd)/Field2 (even) */ | 
|---|
| 63 | #define V4L2_MBUS_FIELD_EVEN_LOW		BIT(12) | 
|---|
| 64 | /* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */ | 
|---|
| 65 | #define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH		BIT(13) | 
|---|
| 66 | #define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW		BIT(14) | 
|---|
| 67 | #define V4L2_MBUS_DATA_ENABLE_HIGH		BIT(15) | 
|---|
| 68 | #define V4L2_MBUS_DATA_ENABLE_LOW		BIT(16) | 
|---|
| 69 |  | 
|---|
| 70 | /* Serial flags */ | 
|---|
| 71 | /* Clock non-continuous mode support. */ | 
|---|
| 72 | #define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK	BIT(0) | 
|---|
| 73 |  | 
|---|
| 74 | #define V4L2_MBUS_CSI2_MAX_DATA_LANES		8 | 
|---|
| 75 |  | 
|---|
| 76 | /** | 
|---|
| 77 | * enum v4l2_mbus_csi2_cphy_line_orders_type - CSI-2 C-PHY line order | 
|---|
| 78 | * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_ABC: C-PHY line order ABC (default) | 
|---|
| 79 | * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_ACB: C-PHY line order ACB | 
|---|
| 80 | * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_BAC: C-PHY line order BAC | 
|---|
| 81 | * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_BCA: C-PHY line order BCA | 
|---|
| 82 | * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_CAB: C-PHY line order CAB | 
|---|
| 83 | * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_CBA: C-PHY line order CBA | 
|---|
| 84 | */ | 
|---|
| 85 | enum v4l2_mbus_csi2_cphy_line_orders_type { | 
|---|
| 86 | V4L2_MBUS_CSI2_CPHY_LINE_ORDER_ABC, | 
|---|
| 87 | V4L2_MBUS_CSI2_CPHY_LINE_ORDER_ACB, | 
|---|
| 88 | V4L2_MBUS_CSI2_CPHY_LINE_ORDER_BAC, | 
|---|
| 89 | V4L2_MBUS_CSI2_CPHY_LINE_ORDER_BCA, | 
|---|
| 90 | V4L2_MBUS_CSI2_CPHY_LINE_ORDER_CAB, | 
|---|
| 91 | V4L2_MBUS_CSI2_CPHY_LINE_ORDER_CBA, | 
|---|
| 92 | }; | 
|---|
| 93 |  | 
|---|
| 94 | /** | 
|---|
| 95 | * struct v4l2_mbus_config_mipi_csi2 - MIPI CSI-2 data bus configuration | 
|---|
| 96 | * @flags: media bus (V4L2_MBUS_*) flags | 
|---|
| 97 | * @data_lanes: an array of physical data lane indexes | 
|---|
| 98 | * @clock_lane: physical lane index of the clock lane | 
|---|
| 99 | * @num_data_lanes: number of data lanes | 
|---|
| 100 | * @lane_polarities: polarity of the lanes. The order is the same of | 
|---|
| 101 | *		   the physical lanes. | 
|---|
| 102 | * @line_orders: line order of the data lanes. The order is the same of the | 
|---|
| 103 | *		   physical lanes. | 
|---|
| 104 | */ | 
|---|
| 105 | struct v4l2_mbus_config_mipi_csi2 { | 
|---|
| 106 | unsigned int flags; | 
|---|
| 107 | unsigned char data_lanes[V4L2_MBUS_CSI2_MAX_DATA_LANES]; | 
|---|
| 108 | unsigned char clock_lane; | 
|---|
| 109 | unsigned char num_data_lanes; | 
|---|
| 110 | bool lane_polarities[1 + V4L2_MBUS_CSI2_MAX_DATA_LANES]; | 
|---|
| 111 | enum v4l2_mbus_csi2_cphy_line_orders_type line_orders[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_DPI:      MIPI VIDEO DPI interface | 
|---|
| 155 | * @V4L2_MBUS_INVALID:	invalid bus type (keep as last) | 
|---|
| 156 | */ | 
|---|
| 157 | enum v4l2_mbus_type { | 
|---|
| 158 | V4L2_MBUS_UNKNOWN, | 
|---|
| 159 | V4L2_MBUS_PARALLEL, | 
|---|
| 160 | V4L2_MBUS_BT656, | 
|---|
| 161 | V4L2_MBUS_CSI1, | 
|---|
| 162 | V4L2_MBUS_CCP2, | 
|---|
| 163 | V4L2_MBUS_CSI2_DPHY, | 
|---|
| 164 | V4L2_MBUS_CSI2_CPHY, | 
|---|
| 165 | V4L2_MBUS_DPI, | 
|---|
| 166 | V4L2_MBUS_INVALID, | 
|---|
| 167 | }; | 
|---|
| 168 |  | 
|---|
| 169 | /** | 
|---|
| 170 | * struct v4l2_mbus_config - media bus configuration | 
|---|
| 171 | * @type: interface type | 
|---|
| 172 | * @link_freq: The link frequency. See also V4L2_CID_LINK_FREQ control. | 
|---|
| 173 | * @bus: bus configuration data structure | 
|---|
| 174 | * @bus.parallel: embedded &struct v4l2_mbus_config_parallel. | 
|---|
| 175 | *		  Used if the bus is parallel or BT.656. | 
|---|
| 176 | * @bus.mipi_csi1: embedded &struct v4l2_mbus_config_mipi_csi1. | 
|---|
| 177 | *		   Used if the bus is MIPI Alliance's Camera Serial | 
|---|
| 178 | *		   Interface version 1 (MIPI CSI1) or Standard | 
|---|
| 179 | *		   Mobile Imaging Architecture's Compact Camera Port 2 | 
|---|
| 180 | *		   (SMIA CCP2). | 
|---|
| 181 | * @bus.mipi_csi2: embedded &struct v4l2_mbus_config_mipi_csi2. | 
|---|
| 182 | *		   Used if the bus is MIPI Alliance's Camera Serial | 
|---|
| 183 | *		   Interface version 2 (MIPI CSI2). | 
|---|
| 184 | */ | 
|---|
| 185 | struct v4l2_mbus_config { | 
|---|
| 186 | enum v4l2_mbus_type type; | 
|---|
| 187 | u64 link_freq; | 
|---|
| 188 | union { | 
|---|
| 189 | struct v4l2_mbus_config_parallel parallel; | 
|---|
| 190 | struct v4l2_mbus_config_mipi_csi1 mipi_csi1; | 
|---|
| 191 | struct v4l2_mbus_config_mipi_csi2 mipi_csi2; | 
|---|
| 192 | } bus; | 
|---|
| 193 | }; | 
|---|
| 194 |  | 
|---|
| 195 | /** | 
|---|
| 196 | * v4l2_fill_pix_format - Ancillary routine that fills a &struct | 
|---|
| 197 | *	v4l2_pix_format fields from a &struct v4l2_mbus_framefmt. | 
|---|
| 198 | * | 
|---|
| 199 | * @pix_fmt:	pointer to &struct v4l2_pix_format to be filled | 
|---|
| 200 | * @mbus_fmt:	pointer to &struct v4l2_mbus_framefmt to be used as model | 
|---|
| 201 | */ | 
|---|
| 202 | static inline void | 
|---|
| 203 | v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt, | 
|---|
| 204 | const struct v4l2_mbus_framefmt *mbus_fmt) | 
|---|
| 205 | { | 
|---|
| 206 | pix_fmt->width = mbus_fmt->width; | 
|---|
| 207 | pix_fmt->height = mbus_fmt->height; | 
|---|
| 208 | pix_fmt->field = mbus_fmt->field; | 
|---|
| 209 | pix_fmt->colorspace = mbus_fmt->colorspace; | 
|---|
| 210 | pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc; | 
|---|
| 211 | pix_fmt->quantization = mbus_fmt->quantization; | 
|---|
| 212 | pix_fmt->xfer_func = mbus_fmt->xfer_func; | 
|---|
| 213 | } | 
|---|
| 214 |  | 
|---|
| 215 | /** | 
|---|
| 216 | * v4l2_fill_mbus_format - Ancillary routine that fills a &struct | 
|---|
| 217 | *	v4l2_mbus_framefmt from a &struct v4l2_pix_format and a | 
|---|
| 218 | *	data format code. | 
|---|
| 219 | * | 
|---|
| 220 | * @mbus_fmt:	pointer to &struct v4l2_mbus_framefmt to be filled | 
|---|
| 221 | * @pix_fmt:	pointer to &struct v4l2_pix_format to be used as model | 
|---|
| 222 | * @code:	data format code (from &enum v4l2_mbus_pixelcode) | 
|---|
| 223 | */ | 
|---|
| 224 | static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt, | 
|---|
| 225 | const struct v4l2_pix_format *pix_fmt, | 
|---|
| 226 | u32 code) | 
|---|
| 227 | { | 
|---|
| 228 | mbus_fmt->width = pix_fmt->width; | 
|---|
| 229 | mbus_fmt->height = pix_fmt->height; | 
|---|
| 230 | mbus_fmt->field = pix_fmt->field; | 
|---|
| 231 | mbus_fmt->colorspace = pix_fmt->colorspace; | 
|---|
| 232 | mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc; | 
|---|
| 233 | mbus_fmt->quantization = pix_fmt->quantization; | 
|---|
| 234 | mbus_fmt->xfer_func = pix_fmt->xfer_func; | 
|---|
| 235 | mbus_fmt->code = code; | 
|---|
| 236 | } | 
|---|
| 237 |  | 
|---|
| 238 | /** | 
|---|
| 239 | * v4l2_fill_pix_format_mplane - Ancillary routine that fills a &struct | 
|---|
| 240 | *	v4l2_pix_format_mplane fields from a media bus structure. | 
|---|
| 241 | * | 
|---|
| 242 | * @pix_mp_fmt:	pointer to &struct v4l2_pix_format_mplane to be filled | 
|---|
| 243 | * @mbus_fmt:	pointer to &struct v4l2_mbus_framefmt to be used as model | 
|---|
| 244 | */ | 
|---|
| 245 | static inline void | 
|---|
| 246 | v4l2_fill_pix_format_mplane(struct v4l2_pix_format_mplane *pix_mp_fmt, | 
|---|
| 247 | const struct v4l2_mbus_framefmt *mbus_fmt) | 
|---|
| 248 | { | 
|---|
| 249 | pix_mp_fmt->width = mbus_fmt->width; | 
|---|
| 250 | pix_mp_fmt->height = mbus_fmt->height; | 
|---|
| 251 | pix_mp_fmt->field = mbus_fmt->field; | 
|---|
| 252 | pix_mp_fmt->colorspace = mbus_fmt->colorspace; | 
|---|
| 253 | pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc; | 
|---|
| 254 | pix_mp_fmt->quantization = mbus_fmt->quantization; | 
|---|
| 255 | pix_mp_fmt->xfer_func = mbus_fmt->xfer_func; | 
|---|
| 256 | } | 
|---|
| 257 |  | 
|---|
| 258 | /** | 
|---|
| 259 | * v4l2_fill_mbus_format_mplane - Ancillary routine that fills a &struct | 
|---|
| 260 | *	v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane. | 
|---|
| 261 | * | 
|---|
| 262 | * @mbus_fmt:	pointer to &struct v4l2_mbus_framefmt to be filled | 
|---|
| 263 | * @pix_mp_fmt:	pointer to &struct v4l2_pix_format_mplane to be used as model | 
|---|
| 264 | */ | 
|---|
| 265 | static inline void | 
|---|
| 266 | v4l2_fill_mbus_format_mplane(struct v4l2_mbus_framefmt *mbus_fmt, | 
|---|
| 267 | const struct v4l2_pix_format_mplane *pix_mp_fmt) | 
|---|
| 268 | { | 
|---|
| 269 | mbus_fmt->width = pix_mp_fmt->width; | 
|---|
| 270 | mbus_fmt->height = pix_mp_fmt->height; | 
|---|
| 271 | mbus_fmt->field = pix_mp_fmt->field; | 
|---|
| 272 | mbus_fmt->colorspace = pix_mp_fmt->colorspace; | 
|---|
| 273 | mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc; | 
|---|
| 274 | mbus_fmt->quantization = pix_mp_fmt->quantization; | 
|---|
| 275 | mbus_fmt->xfer_func = pix_mp_fmt->xfer_func; | 
|---|
| 276 | } | 
|---|
| 277 |  | 
|---|
| 278 | #endif | 
|---|
| 279 |  | 
|---|