v4l2-mediabus.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. #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_PCLK_SAMPLE_DUALEDGE BIT(8)
  54. #define V4L2_MBUS_DATA_ACTIVE_HIGH BIT(9)
  55. #define V4L2_MBUS_DATA_ACTIVE_LOW BIT(10)
  56. /* FIELD = 0/1 - Field1 (odd)/Field2 (even) */
  57. #define V4L2_MBUS_FIELD_EVEN_HIGH BIT(11)
  58. /* FIELD = 1/0 - Field1 (odd)/Field2 (even) */
  59. #define V4L2_MBUS_FIELD_EVEN_LOW BIT(12)
  60. /* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */
  61. #define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH BIT(13)
  62. #define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW BIT(14)
  63. #define V4L2_MBUS_DATA_ENABLE_HIGH BIT(15)
  64. #define V4L2_MBUS_DATA_ENABLE_LOW BIT(16)
  65. /* Serial flags */
  66. /* Clock non-continuous mode support. */
  67. #define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK BIT(0)
  68. #define V4L2_MBUS_CSI2_MAX_DATA_LANES 8
  69. /**
  70. * struct v4l2_mbus_config_mipi_csi2 - MIPI CSI-2 data bus configuration
  71. * @flags: media bus (V4L2_MBUS_*) flags
  72. * @data_lanes: an array of physical data lane indexes
  73. * @clock_lane: physical lane index of the clock lane
  74. * @num_data_lanes: number of data lanes
  75. * @lane_polarities: polarity of the lanes. The order is the same of
  76. * the physical lanes.
  77. */
  78. struct v4l2_mbus_config_mipi_csi2 {
  79. unsigned int flags;
  80. unsigned char data_lanes[V4L2_MBUS_CSI2_MAX_DATA_LANES];
  81. unsigned char clock_lane;
  82. unsigned char num_data_lanes;
  83. bool lane_polarities[1 + V4L2_MBUS_CSI2_MAX_DATA_LANES];
  84. };
  85. /**
  86. * struct v4l2_mbus_config_parallel - parallel data bus configuration
  87. * @flags: media bus (V4L2_MBUS_*) flags
  88. * @bus_width: bus width in bits
  89. * @data_shift: data shift in bits
  90. */
  91. struct v4l2_mbus_config_parallel {
  92. unsigned int flags;
  93. unsigned char bus_width;
  94. unsigned char data_shift;
  95. };
  96. /**
  97. * struct v4l2_mbus_config_mipi_csi1 - CSI-1/CCP2 data bus configuration
  98. * @clock_inv: polarity of clock/strobe signal
  99. * false - not inverted, true - inverted
  100. * @strobe: false - data/clock, true - data/strobe
  101. * @lane_polarity: the polarities of the clock (index 0) and data lanes
  102. * index (1)
  103. * @data_lane: the number of the data lane
  104. * @clock_lane: the number of the clock lane
  105. */
  106. struct v4l2_mbus_config_mipi_csi1 {
  107. unsigned char clock_inv:1;
  108. unsigned char strobe:1;
  109. bool lane_polarity[2];
  110. unsigned char data_lane;
  111. unsigned char clock_lane;
  112. };
  113. /**
  114. * enum v4l2_mbus_type - media bus type
  115. * @V4L2_MBUS_UNKNOWN: unknown bus type, no V4L2 mediabus configuration
  116. * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync
  117. * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can
  118. * also be used for BT.1120
  119. * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface
  120. * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2)
  121. * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY
  122. * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
  123. * @V4L2_MBUS_DPI: MIPI VIDEO DPI interface
  124. * @V4L2_MBUS_INVALID: invalid bus type (keep as last)
  125. */
  126. enum v4l2_mbus_type {
  127. V4L2_MBUS_UNKNOWN,
  128. V4L2_MBUS_PARALLEL,
  129. V4L2_MBUS_BT656,
  130. V4L2_MBUS_CSI1,
  131. V4L2_MBUS_CCP2,
  132. V4L2_MBUS_CSI2_DPHY,
  133. V4L2_MBUS_CSI2_CPHY,
  134. V4L2_MBUS_DPI,
  135. V4L2_MBUS_INVALID,
  136. };
  137. /**
  138. * struct v4l2_mbus_config - media bus configuration
  139. * @type: interface type
  140. * @bus: bus configuration data structure
  141. * @bus.parallel: embedded &struct v4l2_mbus_config_parallel.
  142. * Used if the bus is parallel or BT.656.
  143. * @bus.mipi_csi1: embedded &struct v4l2_mbus_config_mipi_csi1.
  144. * Used if the bus is MIPI Alliance's Camera Serial
  145. * Interface version 1 (MIPI CSI1) or Standard
  146. * Mobile Imaging Architecture's Compact Camera Port 2
  147. * (SMIA CCP2).
  148. * @bus.mipi_csi2: embedded &struct v4l2_mbus_config_mipi_csi2.
  149. * Used if the bus is MIPI Alliance's Camera Serial
  150. * Interface version 2 (MIPI CSI2).
  151. */
  152. struct v4l2_mbus_config {
  153. enum v4l2_mbus_type type;
  154. union {
  155. struct v4l2_mbus_config_parallel parallel;
  156. struct v4l2_mbus_config_mipi_csi1 mipi_csi1;
  157. struct v4l2_mbus_config_mipi_csi2 mipi_csi2;
  158. } bus;
  159. };
  160. /**
  161. * v4l2_fill_pix_format - Ancillary routine that fills a &struct
  162. * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt.
  163. *
  164. * @pix_fmt: pointer to &struct v4l2_pix_format to be filled
  165. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
  166. */
  167. static inline void
  168. v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
  169. const struct v4l2_mbus_framefmt *mbus_fmt)
  170. {
  171. pix_fmt->width = mbus_fmt->width;
  172. pix_fmt->height = mbus_fmt->height;
  173. pix_fmt->field = mbus_fmt->field;
  174. pix_fmt->colorspace = mbus_fmt->colorspace;
  175. pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
  176. pix_fmt->quantization = mbus_fmt->quantization;
  177. pix_fmt->xfer_func = mbus_fmt->xfer_func;
  178. }
  179. /**
  180. * v4l2_fill_mbus_format - Ancillary routine that fills a &struct
  181. * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a
  182. * data format code.
  183. *
  184. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
  185. * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model
  186. * @code: data format code (from &enum v4l2_mbus_pixelcode)
  187. */
  188. static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
  189. const struct v4l2_pix_format *pix_fmt,
  190. u32 code)
  191. {
  192. mbus_fmt->width = pix_fmt->width;
  193. mbus_fmt->height = pix_fmt->height;
  194. mbus_fmt->field = pix_fmt->field;
  195. mbus_fmt->colorspace = pix_fmt->colorspace;
  196. mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc;
  197. mbus_fmt->quantization = pix_fmt->quantization;
  198. mbus_fmt->xfer_func = pix_fmt->xfer_func;
  199. mbus_fmt->code = code;
  200. }
  201. /**
  202. * v4l2_fill_pix_format_mplane - Ancillary routine that fills a &struct
  203. * v4l2_pix_format_mplane fields from a media bus structure.
  204. *
  205. * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled
  206. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
  207. */
  208. static inline void
  209. v4l2_fill_pix_format_mplane(struct v4l2_pix_format_mplane *pix_mp_fmt,
  210. const struct v4l2_mbus_framefmt *mbus_fmt)
  211. {
  212. pix_mp_fmt->width = mbus_fmt->width;
  213. pix_mp_fmt->height = mbus_fmt->height;
  214. pix_mp_fmt->field = mbus_fmt->field;
  215. pix_mp_fmt->colorspace = mbus_fmt->colorspace;
  216. pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
  217. pix_mp_fmt->quantization = mbus_fmt->quantization;
  218. pix_mp_fmt->xfer_func = mbus_fmt->xfer_func;
  219. }
  220. /**
  221. * v4l2_fill_mbus_format_mplane - Ancillary routine that fills a &struct
  222. * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane.
  223. *
  224. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
  225. * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model
  226. */
  227. static inline void
  228. v4l2_fill_mbus_format_mplane(struct v4l2_mbus_framefmt *mbus_fmt,
  229. const struct v4l2_pix_format_mplane *pix_mp_fmt)
  230. {
  231. mbus_fmt->width = pix_mp_fmt->width;
  232. mbus_fmt->height = pix_mp_fmt->height;
  233. mbus_fmt->field = pix_mp_fmt->field;
  234. mbus_fmt->colorspace = pix_mp_fmt->colorspace;
  235. mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc;
  236. mbus_fmt->quantization = pix_mp_fmt->quantization;
  237. mbus_fmt->xfer_func = pix_mp_fmt->xfer_func;
  238. }
  239. #endif