v4l2-mediabus.h 8.7 KB

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