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