v4l2-mediabus.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Media Bus API header
  3. *
  4. * Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef V4L2_MEDIABUS_H
  11. #define V4L2_MEDIABUS_H
  12. #include <linux/v4l2-mediabus.h>
  13. #include <linux/bitops.h>
  14. /* Parallel flags */
  15. /*
  16. * Can the client run in master or in slave mode. By "Master mode" an operation
  17. * mode is meant, when the client (e.g., a camera sensor) is producing
  18. * horizontal and vertical synchronisation. In "Slave mode" the host is
  19. * providing these signals to the slave.
  20. */
  21. #define V4L2_MBUS_MASTER BIT(0)
  22. #define V4L2_MBUS_SLAVE BIT(1)
  23. /*
  24. * Signal polarity flags
  25. * Note: in BT.656 mode HSYNC, FIELD, and VSYNC are unused
  26. * V4L2_MBUS_[HV]SYNC* flags should be also used for specifying
  27. * configuration of hardware that uses [HV]REF signals
  28. */
  29. #define V4L2_MBUS_HSYNC_ACTIVE_HIGH BIT(2)
  30. #define V4L2_MBUS_HSYNC_ACTIVE_LOW BIT(3)
  31. #define V4L2_MBUS_VSYNC_ACTIVE_HIGH BIT(4)
  32. #define V4L2_MBUS_VSYNC_ACTIVE_LOW BIT(5)
  33. #define V4L2_MBUS_PCLK_SAMPLE_RISING BIT(6)
  34. #define V4L2_MBUS_PCLK_SAMPLE_FALLING BIT(7)
  35. #define V4L2_MBUS_DATA_ACTIVE_HIGH BIT(8)
  36. #define V4L2_MBUS_DATA_ACTIVE_LOW BIT(9)
  37. /* FIELD = 0/1 - Field1 (odd)/Field2 (even) */
  38. #define V4L2_MBUS_FIELD_EVEN_HIGH BIT(10)
  39. /* FIELD = 1/0 - Field1 (odd)/Field2 (even) */
  40. #define V4L2_MBUS_FIELD_EVEN_LOW BIT(11)
  41. /* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */
  42. #define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH BIT(12)
  43. #define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW BIT(13)
  44. #define V4L2_MBUS_DATA_ENABLE_HIGH BIT(14)
  45. #define V4L2_MBUS_DATA_ENABLE_LOW BIT(15)
  46. /* Serial flags */
  47. /* How many lanes the client can use */
  48. #define V4L2_MBUS_CSI2_1_LANE BIT(0)
  49. #define V4L2_MBUS_CSI2_2_LANE BIT(1)
  50. #define V4L2_MBUS_CSI2_3_LANE BIT(2)
  51. #define V4L2_MBUS_CSI2_4_LANE BIT(3)
  52. /* On which channels it can send video data */
  53. #define V4L2_MBUS_CSI2_CHANNEL_0 BIT(4)
  54. #define V4L2_MBUS_CSI2_CHANNEL_1 BIT(5)
  55. #define V4L2_MBUS_CSI2_CHANNEL_2 BIT(6)
  56. #define V4L2_MBUS_CSI2_CHANNEL_3 BIT(7)
  57. /* Does it support only continuous or also non-continuous clock mode */
  58. #define V4L2_MBUS_CSI2_CONTINUOUS_CLOCK BIT(8)
  59. #define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK BIT(9)
  60. #define V4L2_MBUS_CSI2_LANES (V4L2_MBUS_CSI2_1_LANE | \
  61. V4L2_MBUS_CSI2_2_LANE | \
  62. V4L2_MBUS_CSI2_3_LANE | \
  63. V4L2_MBUS_CSI2_4_LANE)
  64. #define V4L2_MBUS_CSI2_CHANNELS (V4L2_MBUS_CSI2_CHANNEL_0 | \
  65. V4L2_MBUS_CSI2_CHANNEL_1 | \
  66. V4L2_MBUS_CSI2_CHANNEL_2 | \
  67. V4L2_MBUS_CSI2_CHANNEL_3)
  68. /**
  69. * enum v4l2_mbus_type - media bus type
  70. * @V4L2_MBUS_UNKNOWN: unknown bus type, no V4L2 mediabus configuration
  71. * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync
  72. * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can
  73. * also be used for BT.1120
  74. * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface
  75. * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2)
  76. * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY
  77. * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
  78. */
  79. enum v4l2_mbus_type {
  80. V4L2_MBUS_UNKNOWN,
  81. V4L2_MBUS_PARALLEL,
  82. V4L2_MBUS_BT656,
  83. V4L2_MBUS_CSI1,
  84. V4L2_MBUS_CCP2,
  85. V4L2_MBUS_CSI2_DPHY,
  86. V4L2_MBUS_CSI2_CPHY,
  87. };
  88. /**
  89. * struct v4l2_mbus_config - media bus configuration
  90. * @type: in: interface type
  91. * @flags: in / out: configuration flags, depending on @type
  92. */
  93. struct v4l2_mbus_config {
  94. enum v4l2_mbus_type type;
  95. unsigned int flags;
  96. };
  97. /**
  98. * v4l2_fill_pix_format - Ancillary routine that fills a &struct
  99. * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt.
  100. *
  101. * @pix_fmt: pointer to &struct v4l2_pix_format to be filled
  102. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
  103. */
  104. static inline void
  105. v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
  106. const struct v4l2_mbus_framefmt *mbus_fmt)
  107. {
  108. pix_fmt->width = mbus_fmt->width;
  109. pix_fmt->height = mbus_fmt->height;
  110. pix_fmt->field = mbus_fmt->field;
  111. pix_fmt->colorspace = mbus_fmt->colorspace;
  112. pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
  113. pix_fmt->quantization = mbus_fmt->quantization;
  114. pix_fmt->xfer_func = mbus_fmt->xfer_func;
  115. }
  116. /**
  117. * v4l2_fill_pix_format - Ancillary routine that fills a &struct
  118. * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a
  119. * data format code.
  120. *
  121. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
  122. * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model
  123. * @code: data format code (from &enum v4l2_mbus_pixelcode)
  124. */
  125. static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
  126. const struct v4l2_pix_format *pix_fmt,
  127. u32 code)
  128. {
  129. mbus_fmt->width = pix_fmt->width;
  130. mbus_fmt->height = pix_fmt->height;
  131. mbus_fmt->field = pix_fmt->field;
  132. mbus_fmt->colorspace = pix_fmt->colorspace;
  133. mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc;
  134. mbus_fmt->quantization = pix_fmt->quantization;
  135. mbus_fmt->xfer_func = pix_fmt->xfer_func;
  136. mbus_fmt->code = code;
  137. }
  138. /**
  139. * v4l2_fill_pix_format - Ancillary routine that fills a &struct
  140. * v4l2_pix_format_mplane fields from a media bus structure.
  141. *
  142. * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled
  143. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
  144. */
  145. static inline void
  146. v4l2_fill_pix_format_mplane(struct v4l2_pix_format_mplane *pix_mp_fmt,
  147. const struct v4l2_mbus_framefmt *mbus_fmt)
  148. {
  149. pix_mp_fmt->width = mbus_fmt->width;
  150. pix_mp_fmt->height = mbus_fmt->height;
  151. pix_mp_fmt->field = mbus_fmt->field;
  152. pix_mp_fmt->colorspace = mbus_fmt->colorspace;
  153. pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
  154. pix_mp_fmt->quantization = mbus_fmt->quantization;
  155. pix_mp_fmt->xfer_func = mbus_fmt->xfer_func;
  156. }
  157. /**
  158. * v4l2_fill_pix_format - Ancillary routine that fills a &struct
  159. * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane.
  160. *
  161. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
  162. * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model
  163. */
  164. static inline void
  165. v4l2_fill_mbus_format_mplane(struct v4l2_mbus_framefmt *mbus_fmt,
  166. const struct v4l2_pix_format_mplane *pix_mp_fmt)
  167. {
  168. mbus_fmt->width = pix_mp_fmt->width;
  169. mbus_fmt->height = pix_mp_fmt->height;
  170. mbus_fmt->field = pix_mp_fmt->field;
  171. mbus_fmt->colorspace = pix_mp_fmt->colorspace;
  172. mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc;
  173. mbus_fmt->quantization = pix_mp_fmt->quantization;
  174. mbus_fmt->xfer_func = pix_mp_fmt->xfer_func;
  175. }
  176. #endif