v4l2-mediabus.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 | V4L2_MBUS_CSI2_2_LANE | \
  61. V4L2_MBUS_CSI2_3_LANE | V4L2_MBUS_CSI2_4_LANE)
  62. #define V4L2_MBUS_CSI2_CHANNELS (V4L2_MBUS_CSI2_CHANNEL_0 | V4L2_MBUS_CSI2_CHANNEL_1 | \
  63. V4L2_MBUS_CSI2_CHANNEL_2 | V4L2_MBUS_CSI2_CHANNEL_3)
  64. /**
  65. * enum v4l2_mbus_type - media bus type
  66. * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync
  67. * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can
  68. * also be used for BT.1120
  69. * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface
  70. * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2)
  71. * @V4L2_MBUS_CSI2: MIPI CSI-2 serial interface
  72. */
  73. enum v4l2_mbus_type {
  74. V4L2_MBUS_PARALLEL,
  75. V4L2_MBUS_BT656,
  76. V4L2_MBUS_CSI1,
  77. V4L2_MBUS_CCP2,
  78. V4L2_MBUS_CSI2,
  79. };
  80. /**
  81. * struct v4l2_mbus_config - media bus configuration
  82. * @type: in: interface type
  83. * @flags: in / out: configuration flags, depending on @type
  84. */
  85. struct v4l2_mbus_config {
  86. enum v4l2_mbus_type type;
  87. unsigned int flags;
  88. };
  89. /**
  90. * v4l2_fill_pix_format - Ancillary routine that fills a &struct
  91. * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt.
  92. *
  93. * @pix_fmt: pointer to &struct v4l2_pix_format to be filled
  94. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
  95. */
  96. static inline void v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
  97. const struct v4l2_mbus_framefmt *mbus_fmt)
  98. {
  99. pix_fmt->width = mbus_fmt->width;
  100. pix_fmt->height = mbus_fmt->height;
  101. pix_fmt->field = mbus_fmt->field;
  102. pix_fmt->colorspace = mbus_fmt->colorspace;
  103. pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
  104. pix_fmt->quantization = mbus_fmt->quantization;
  105. pix_fmt->xfer_func = mbus_fmt->xfer_func;
  106. }
  107. /**
  108. * v4l2_fill_pix_format - Ancillary routine that fills a &struct
  109. * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a
  110. * data format code.
  111. *
  112. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
  113. * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model
  114. * @code: data format code (from &enum v4l2_mbus_pixelcode)
  115. */
  116. static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
  117. const struct v4l2_pix_format *pix_fmt,
  118. u32 code)
  119. {
  120. mbus_fmt->width = pix_fmt->width;
  121. mbus_fmt->height = pix_fmt->height;
  122. mbus_fmt->field = pix_fmt->field;
  123. mbus_fmt->colorspace = pix_fmt->colorspace;
  124. mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc;
  125. mbus_fmt->quantization = pix_fmt->quantization;
  126. mbus_fmt->xfer_func = pix_fmt->xfer_func;
  127. mbus_fmt->code = code;
  128. }
  129. /**
  130. * v4l2_fill_pix_format - Ancillary routine that fills a &struct
  131. * v4l2_pix_format_mplane fields from a media bus structure.
  132. *
  133. * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled
  134. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
  135. */
  136. static inline void v4l2_fill_pix_format_mplane(
  137. struct v4l2_pix_format_mplane *pix_mp_fmt,
  138. const struct v4l2_mbus_framefmt *mbus_fmt)
  139. {
  140. pix_mp_fmt->width = mbus_fmt->width;
  141. pix_mp_fmt->height = mbus_fmt->height;
  142. pix_mp_fmt->field = mbus_fmt->field;
  143. pix_mp_fmt->colorspace = mbus_fmt->colorspace;
  144. pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
  145. pix_mp_fmt->quantization = mbus_fmt->quantization;
  146. pix_mp_fmt->xfer_func = mbus_fmt->xfer_func;
  147. }
  148. /**
  149. * v4l2_fill_pix_format - Ancillary routine that fills a &struct
  150. * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane.
  151. *
  152. * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
  153. * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model
  154. */
  155. static inline void v4l2_fill_mbus_format_mplane(
  156. struct v4l2_mbus_framefmt *mbus_fmt,
  157. const struct v4l2_pix_format_mplane *pix_mp_fmt)
  158. {
  159. mbus_fmt->width = pix_mp_fmt->width;
  160. mbus_fmt->height = pix_mp_fmt->height;
  161. mbus_fmt->field = pix_mp_fmt->field;
  162. mbus_fmt->colorspace = pix_mp_fmt->colorspace;
  163. mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc;
  164. mbus_fmt->quantization = pix_mp_fmt->quantization;
  165. mbus_fmt->xfer_func = pix_mp_fmt->xfer_func;
  166. }
  167. #endif