v4l2-mediabus.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. * enum v4l2_mbus_csi2_cphy_line_orders_type - CSI-2 C-PHY line order
  71. * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_ABC: C-PHY line order ABC (default)
  72. * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_ACB: C-PHY line order ACB
  73. * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_BAC: C-PHY line order BAC
  74. * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_BCA: C-PHY line order BCA
  75. * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_CAB: C-PHY line order CAB
  76. * @V4L2_MBUS_CSI2_CPHY_LINE_ORDER_CBA: C-PHY line order CBA
  77. */
  78. enum v4l2_mbus_csi2_cphy_line_orders_type {
  79. V4L2_MBUS_CSI2_CPHY_LINE_ORDER_ABC,
  80. V4L2_MBUS_CSI2_CPHY_LINE_ORDER_ACB,
  81. V4L2_MBUS_CSI2_CPHY_LINE_ORDER_BAC,
  82. V4L2_MBUS_CSI2_CPHY_LINE_ORDER_BCA,
  83. V4L2_MBUS_CSI2_CPHY_LINE_ORDER_CAB,
  84. V4L2_MBUS_CSI2_CPHY_LINE_ORDER_CBA,
  85. };
  86. /**
  87. * struct v4l2_mbus_config_mipi_csi2 - MIPI CSI-2 data bus configuration
  88. * @flags: media bus (V4L2_MBUS_*) flags
  89. * @data_lanes: an array of physical data lane indexes
  90. * @clock_lane: physical lane index of the clock lane
  91. * @num_data_lanes: number of data lanes
  92. * @lane_polarities: polarity of the lanes. The order is the same of
  93. * the physical lanes.
  94. * @line_orders: line order of the data lanes. The order is the same of the
  95. * physical lanes.
  96. */
  97. struct v4l2_mbus_config_mipi_csi2 {
  98. unsigned int flags;
  99. unsigned char data_lanes[V4L2_MBUS_CSI2_MAX_DATA_LANES];
  100. unsigned char clock_lane;
  101. unsigned char num_data_lanes;
  102. bool lane_polarities[1 + V4L2_MBUS_CSI2_MAX_DATA_LANES];
  103. enum v4l2_mbus_csi2_cphy_line_orders_type line_orders[V4L2_MBUS_CSI2_MAX_DATA_LANES];
  104. };
  105. /**
  106. * struct v4l2_mbus_config_parallel - parallel data bus configuration
  107. * @flags: media bus (V4L2_MBUS_*) flags
  108. * @bus_width: bus width in bits
  109. * @data_shift: data shift in bits
  110. */
  111. struct v4l2_mbus_config_parallel {
  112. unsigned int flags;
  113. unsigned char bus_width;
  114. unsigned char data_shift;
  115. };
  116. /**
  117. * struct v4l2_mbus_config_mipi_csi1 - CSI-1/CCP2 data bus configuration
  118. * @clock_inv: polarity of clock/strobe signal
  119. * false - not inverted, true - inverted
  120. * @strobe: false - data/clock, true - data/strobe
  121. * @lane_polarity: the polarities of the clock (index 0) and data lanes
  122. * index (1)
  123. * @data_lane: the number of the data lane
  124. * @clock_lane: the number of the clock lane
  125. */
  126. struct v4l2_mbus_config_mipi_csi1 {
  127. unsigned char clock_inv:1;
  128. unsigned char strobe:1;
  129. bool lane_polarity[2];
  130. unsigned char data_lane;
  131. unsigned char clock_lane;
  132. };
  133. /**
  134. * enum v4l2_mbus_type - media bus type
  135. * @V4L2_MBUS_UNKNOWN: unknown bus type, no V4L2 mediabus configuration
  136. * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync
  137. * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can
  138. * also be used for BT.1120
  139. * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface
  140. * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2)
  141. * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY
  142. * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
  143. * @V4L2_MBUS_DPI: MIPI VIDEO DPI interface
  144. * @V4L2_MBUS_INVALID: invalid bus type (keep as last)
  145. */
  146. enum v4l2_mbus_type {
  147. V4L2_MBUS_UNKNOWN,
  148. V4L2_MBUS_PARALLEL,
  149. V4L2_MBUS_BT656,
  150. V4L2_MBUS_CSI1,
  151. V4L2_MBUS_CCP2,
  152. V4L2_MBUS_CSI2_DPHY,
  153. V4L2_MBUS_CSI2_CPHY,
  154. V4L2_MBUS_DPI,
  155. V4L2_MBUS_INVALID,
  156. };
  157. /**
  158. * struct v4l2_mbus_config - media bus configuration
  159. * @type: interface type
  160. * @link_freq: The link frequency. See also V4L2_CID_LINK_FREQ control.
  161. * @bus: bus configuration data structure
  162. * @bus.parallel: embedded &struct v4l2_mbus_config_parallel.
  163. * Used if the bus is parallel or BT.656.
  164. * @bus.mipi_csi1: embedded &struct v4l2_mbus_config_mipi_csi1.
  165. * Used if the bus is MIPI Alliance's Camera Serial
  166. * Interface version 1 (MIPI CSI1) or Standard
  167. * Mobile Imaging Architecture's Compact Camera Port 2
  168. * (SMIA CCP2).
  169. * @bus.mipi_csi2: embedded &struct v4l2_mbus_config_mipi_csi2.
  170. * Used if the bus is MIPI Alliance's Camera Serial
  171. * Interface version 2 (MIPI CSI2).
  172. */
  173. struct v4l2_mbus_config {
  174. enum v4l2_mbus_type type;
  175. u64 link_freq;
  176. union {
  177. struct v4l2_mbus_config_parallel parallel;
  178. struct v4l2_mbus_config_mipi_csi1 mipi_csi1;
  179. struct v4l2_mbus_config_mipi_csi2 mipi_csi2;
  180. } bus;
  181. };
  182. /**
  183. * v4l2_fill_pix_format - Ancillary routine that fills a &struct
  184. * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt.
  185. *
  186. * @pix_fmt: pointer to &struct v4l2_pix_format to be filled
  187. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
  188. */
  189. static inline void
  190. v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
  191. const struct v4l2_mbus_framefmt *mbus_fmt)
  192. {
  193. pix_fmt->width = mbus_fmt->width;
  194. pix_fmt->height = mbus_fmt->height;
  195. pix_fmt->field = mbus_fmt->field;
  196. pix_fmt->colorspace = mbus_fmt->colorspace;
  197. pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
  198. pix_fmt->quantization = mbus_fmt->quantization;
  199. pix_fmt->xfer_func = mbus_fmt->xfer_func;
  200. }
  201. /**
  202. * v4l2_fill_mbus_format - Ancillary routine that fills a &struct
  203. * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a
  204. * data format code.
  205. *
  206. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
  207. * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model
  208. * @code: data format code (from &enum v4l2_mbus_pixelcode)
  209. */
  210. static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
  211. const struct v4l2_pix_format *pix_fmt,
  212. u32 code)
  213. {
  214. mbus_fmt->width = pix_fmt->width;
  215. mbus_fmt->height = pix_fmt->height;
  216. mbus_fmt->field = pix_fmt->field;
  217. mbus_fmt->colorspace = pix_fmt->colorspace;
  218. mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc;
  219. mbus_fmt->quantization = pix_fmt->quantization;
  220. mbus_fmt->xfer_func = pix_fmt->xfer_func;
  221. mbus_fmt->code = code;
  222. }
  223. /**
  224. * v4l2_fill_pix_format_mplane - Ancillary routine that fills a &struct
  225. * v4l2_pix_format_mplane fields from a media bus structure.
  226. *
  227. * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled
  228. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
  229. */
  230. static inline void
  231. v4l2_fill_pix_format_mplane(struct v4l2_pix_format_mplane *pix_mp_fmt,
  232. const struct v4l2_mbus_framefmt *mbus_fmt)
  233. {
  234. pix_mp_fmt->width = mbus_fmt->width;
  235. pix_mp_fmt->height = mbus_fmt->height;
  236. pix_mp_fmt->field = mbus_fmt->field;
  237. pix_mp_fmt->colorspace = mbus_fmt->colorspace;
  238. pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
  239. pix_mp_fmt->quantization = mbus_fmt->quantization;
  240. pix_mp_fmt->xfer_func = mbus_fmt->xfer_func;
  241. }
  242. /**
  243. * v4l2_fill_mbus_format_mplane - Ancillary routine that fills a &struct
  244. * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane.
  245. *
  246. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
  247. * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model
  248. */
  249. static inline void
  250. v4l2_fill_mbus_format_mplane(struct v4l2_mbus_framefmt *mbus_fmt,
  251. const struct v4l2_pix_format_mplane *pix_mp_fmt)
  252. {
  253. mbus_fmt->width = pix_mp_fmt->width;
  254. mbus_fmt->height = pix_mp_fmt->height;
  255. mbus_fmt->field = pix_mp_fmt->field;
  256. mbus_fmt->colorspace = pix_mp_fmt->colorspace;
  257. mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc;
  258. mbus_fmt->quantization = pix_mp_fmt->quantization;
  259. mbus_fmt->xfer_func = pix_mp_fmt->xfer_func;
  260. }
  261. #endif