mgb4.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. include:: <isonum.txt>
  3. The mgb4 driver
  4. ===============
  5. Copyright |copy| 2023 - 2025 Digiteq Automotive
  6. author: Martin Tůma <martin.tuma@digiteqautomotive.com>
  7. This is a v4l2 device driver for the Digiteq Automotive FrameGrabber 4, a PCIe
  8. card capable of capturing and generating FPD-Link III and GMSL2/3 video streams
  9. as used in the automotive industry.
  10. sysfs interface
  11. ---------------
  12. The mgb4 driver provides a sysfs interface, that is used to configure video
  13. stream related parameters (some of them must be set properly before the v4l2
  14. device can be opened) and obtain the video device/stream status.
  15. There are two types of parameters - global / PCI card related, found under
  16. ``/sys/class/video4linux/videoX/device`` and module specific found under
  17. ``/sys/class/video4linux/videoX``.
  18. Global (PCI card) parameters
  19. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. **module_type** (R):
  21. Module type.
  22. | 0 - No module present
  23. | 1 - FPDL3
  24. | 2 - GMSL3 (one serializer, two daisy chained deserializers)
  25. | 3 - GMSL3 (one serializer, two deserializers)
  26. | 4 - GMSL3 (two deserializers with two daisy chain outputs)
  27. | 6 - GMSL1
  28. | 8 - GMSL3 coax
  29. **module_version** (R):
  30. Module version number. Zero in case of a missing module.
  31. **fw_type** (R):
  32. Firmware type.
  33. | 1 - FPDL3
  34. | 2 - GMSL3
  35. | 3 - GMSL1
  36. **fw_version** (R):
  37. Firmware version number.
  38. **serial_number** (R):
  39. Card serial number. The format is::
  40. PRODUCT-REVISION-SERIES-SERIAL
  41. where each component is a 8b number.
  42. Common FPDL3/GMSL input parameters
  43. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. **input_id** (R):
  45. Input number ID, zero based.
  46. **oldi_lane_width** (RW):
  47. Number of deserializer output lanes.
  48. | 0 - single
  49. | 1 - dual (default)
  50. **color_mapping** (RW):
  51. Mapping of the incoming bits in the signal to the colour bits of the pixels.
  52. | 0 - OLDI/JEIDA
  53. | 1 - SPWG/VESA (default)
  54. **link_status** (R):
  55. Video link status. If the link is locked, chips are properly connected and
  56. communicating at the same speed and protocol. The link can be locked without
  57. an active video stream.
  58. A value of 0 is equivalent to the V4L2_IN_ST_NO_SYNC flag of the V4L2
  59. VIDIOC_ENUMINPUT status bits.
  60. | 0 - unlocked
  61. | 1 - locked
  62. **stream_status** (R):
  63. Video stream status. A stream is detected if the link is locked, the input
  64. pixel clock is running and the DE signal is moving.
  65. A value of 0 is equivalent to the V4L2_IN_ST_NO_SIGNAL flag of the V4L2
  66. VIDIOC_ENUMINPUT status bits.
  67. | 0 - not detected
  68. | 1 - detected
  69. **video_width** (R):
  70. Video stream width. This is the actual width as detected by the HW.
  71. The value is identical to what VIDIOC_QUERY_DV_TIMINGS returns in the width
  72. field of the v4l2_bt_timings struct.
  73. **video_height** (R):
  74. Video stream height. This is the actual height as detected by the HW.
  75. The value is identical to what VIDIOC_QUERY_DV_TIMINGS returns in the height
  76. field of the v4l2_bt_timings struct.
  77. **vsync_status** (R):
  78. The type of VSYNC pulses as detected by the video format detector.
  79. The value is equivalent to the flags returned by VIDIOC_QUERY_DV_TIMINGS in
  80. the polarities field of the v4l2_bt_timings struct.
  81. | 0 - active low
  82. | 1 - active high
  83. | 2 - not available
  84. **hsync_status** (R):
  85. The type of HSYNC pulses as detected by the video format detector.
  86. The value is equivalent to the flags returned by VIDIOC_QUERY_DV_TIMINGS in
  87. the polarities field of the v4l2_bt_timings struct.
  88. | 0 - active low
  89. | 1 - active high
  90. | 2 - not available
  91. **vsync_gap_length** (RW):
  92. If the incoming video signal does not contain synchronization VSYNC and
  93. HSYNC pulses, these must be generated internally in the FPGA to achieve
  94. the correct frame ordering. This value indicates, how many "empty" pixels
  95. (pixels with deasserted Data Enable signal) are necessary to generate the
  96. internal VSYNC pulse.
  97. **hsync_gap_length** (RW):
  98. If the incoming video signal does not contain synchronization VSYNC and
  99. HSYNC pulses, these must be generated internally in the FPGA to achieve
  100. the correct frame ordering. This value indicates, how many "empty" pixels
  101. (pixels with deasserted Data Enable signal) are necessary to generate the
  102. internal HSYNC pulse. The value must be greater than 1 and smaller than
  103. vsync_gap_length.
  104. **pclk_frequency** (R):
  105. Input pixel clock frequency in kHz.
  106. The value is identical to what VIDIOC_QUERY_DV_TIMINGS returns in
  107. the pixelclock field of the v4l2_bt_timings struct.
  108. *Note: The frequency_range parameter must be set properly first to get
  109. a valid frequency here.*
  110. **hsync_width** (R):
  111. Width of the HSYNC signal in PCLK clock ticks.
  112. The value is identical to what VIDIOC_QUERY_DV_TIMINGS returns in
  113. the hsync field of the v4l2_bt_timings struct.
  114. **vsync_width** (R):
  115. Width of the VSYNC signal in PCLK clock ticks.
  116. The value is identical to what VIDIOC_QUERY_DV_TIMINGS returns in
  117. the vsync field of the v4l2_bt_timings struct.
  118. **hback_porch** (R):
  119. Number of PCLK pulses between deassertion of the HSYNC signal and the first
  120. valid pixel in the video line (marked by DE=1).
  121. The value is identical to what VIDIOC_QUERY_DV_TIMINGS returns in
  122. the hbackporch field of the v4l2_bt_timings struct.
  123. **hfront_porch** (R):
  124. Number of PCLK pulses between the end of the last valid pixel in the video
  125. line (marked by DE=1) and assertion of the HSYNC signal.
  126. The value is identical to what VIDIOC_QUERY_DV_TIMINGS returns in
  127. the hfrontporch field of the v4l2_bt_timings struct.
  128. **vback_porch** (R):
  129. Number of video lines between deassertion of the VSYNC signal and the video
  130. line with the first valid pixel (marked by DE=1).
  131. The value is identical to what VIDIOC_QUERY_DV_TIMINGS returns in
  132. the vbackporch field of the v4l2_bt_timings struct.
  133. **vfront_porch** (R):
  134. Number of video lines between the end of the last valid pixel line (marked
  135. by DE=1) and assertion of the VSYNC signal.
  136. The value is identical to what VIDIOC_QUERY_DV_TIMINGS returns in
  137. the vfrontporch field of the v4l2_bt_timings struct.
  138. **frequency_range** (RW)
  139. PLL frequency range of the OLDI input clock generator. The PLL frequency is
  140. derived from the Pixel Clock Frequency (PCLK) and is equal to PCLK if
  141. oldi_lane_width is set to "single" and PCLK/2 if oldi_lane_width is set to
  142. "dual".
  143. | 0 - PLL < 50MHz (default)
  144. | 1 - PLL >= 50MHz
  145. *Note: This parameter can not be changed while the input v4l2 device is
  146. open.*
  147. Common FPDL3/GMSL output parameters
  148. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149. **output_id** (R):
  150. Output number ID, zero based.
  151. **video_source** (RW):
  152. Output video source. If set to 0 or 1, the source is the corresponding card
  153. input and the v4l2 output devices are disabled. If set to 2 or 3, the source
  154. is the corresponding v4l2 video output device. The default is
  155. the corresponding v4l2 output, i.e. 2 for OUT1 and 3 for OUT2.
  156. | 0 - input 0
  157. | 1 - input 1
  158. | 2 - v4l2 output 0
  159. | 3 - v4l2 output 1
  160. *Note: This parameter can not be changed while ANY of the input/output v4l2
  161. devices is open.*
  162. **display_width** (RW):
  163. Display width. There is no autodetection of the connected display, so the
  164. proper value must be set before the start of streaming. The default width
  165. is 1280.
  166. *Note: This parameter can not be changed while the output v4l2 device is
  167. open.*
  168. **display_height** (RW):
  169. Display height. There is no autodetection of the connected display, so the
  170. proper value must be set before the start of streaming. The default height
  171. is 640.
  172. *Note: This parameter can not be changed while the output v4l2 device is
  173. open.*
  174. **frame_rate** (RW):
  175. Output video signal frame rate limit in frames per second. Due to
  176. the limited output pixel clock steps, the card can not always generate
  177. a frame rate perfectly matching the value required by the connected display.
  178. Using this parameter one can limit the frame rate by "crippling" the signal
  179. so that the lines are not equal (the porches of the last line differ) but
  180. the signal appears like having the exact frame rate to the connected display.
  181. The default frame rate limit is 60Hz.
  182. **hsync_polarity** (RW):
  183. HSYNC signal polarity.
  184. | 0 - active low (default)
  185. | 1 - active high
  186. **vsync_polarity** (RW):
  187. VSYNC signal polarity.
  188. | 0 - active low (default)
  189. | 1 - active high
  190. **de_polarity** (RW):
  191. DE signal polarity.
  192. | 0 - active low
  193. | 1 - active high (default)
  194. **pclk_frequency** (RW):
  195. Output pixel clock frequency. Allowed values are between 25000-190000(kHz)
  196. and there is a non-linear stepping between two consecutive allowed
  197. frequencies. The driver finds the nearest allowed frequency to the given
  198. value and sets it. When reading this property, you get the exact
  199. frequency set by the driver. The default frequency is 61150kHz.
  200. *Note: This parameter can not be changed while the output v4l2 device is
  201. open.*
  202. **hsync_width** (RW):
  203. Width of the HSYNC signal in pixels. The default value is 40.
  204. **vsync_width** (RW):
  205. Width of the VSYNC signal in video lines. The default value is 20.
  206. **hback_porch** (RW):
  207. Number of PCLK pulses between deassertion of the HSYNC signal and the first
  208. valid pixel in the video line (marked by DE=1). The default value is 50.
  209. **hfront_porch** (RW):
  210. Number of PCLK pulses between the end of the last valid pixel in the video
  211. line (marked by DE=1) and assertion of the HSYNC signal. The default value
  212. is 50.
  213. **vback_porch** (RW):
  214. Number of video lines between deassertion of the VSYNC signal and the video
  215. line with the first valid pixel (marked by DE=1). The default value is 31.
  216. **vfront_porch** (RW):
  217. Number of video lines between the end of the last valid pixel line (marked
  218. by DE=1) and assertion of the VSYNC signal. The default value is 30.
  219. FPDL3 specific input parameters
  220. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  221. **fpdl3_input_width** (RW):
  222. Number of deserializer input lines.
  223. | 0 - auto (default)
  224. | 1 - single
  225. | 2 - dual
  226. FPDL3 specific output parameters
  227. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  228. **fpdl3_output_width** (RW):
  229. Number of serializer output lines.
  230. | 0 - auto (default)
  231. | 1 - single
  232. | 2 - dual
  233. GMSL specific input parameters
  234. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  235. **gmsl_mode** (RW):
  236. GMSL speed mode.
  237. | 0 - 12Gb/s (default)
  238. | 1 - 6Gb/s
  239. | 2 - 3Gb/s
  240. | 3 - 1.5Gb/s
  241. **gmsl_stream_id** (RW):
  242. The GMSL multi-stream contains up to four video streams. This parameter
  243. selects which stream is captured by the video input. The value is the
  244. zero-based index of the stream. The default stream id is 0.
  245. *Note: This parameter can not be changed while the input v4l2 device is
  246. open.*
  247. **gmsl_fec** (RW):
  248. GMSL Forward Error Correction (FEC).
  249. | 0 - disabled
  250. | 1 - enabled (default)
  251. MTD partitions
  252. --------------
  253. The mgb4 driver creates a MTD device with two partitions:
  254. - mgb4-fw.X - FPGA firmware.
  255. - mgb4-data.X - Factory settings, e.g. card serial number.
  256. The *mgb4-fw* partition is writable and is used for FW updates, *mgb4-data* is
  257. read-only. The *X* attached to the partition name represents the card number.
  258. Depending on the CONFIG_MTD_PARTITIONED_MASTER kernel configuration, you may
  259. also have a third partition named *mgb4-flash* available in the system. This
  260. partition represents the whole, unpartitioned, card's FLASH memory and one should
  261. not fiddle with it...
  262. IIO (triggers)
  263. --------------
  264. The mgb4 driver creates an Industrial I/O (IIO) device that provides trigger and
  265. signal level status capability. The following scan elements are available:
  266. **activity**:
  267. The trigger levels and pending status.
  268. | bit 1 - trigger 1 pending
  269. | bit 2 - trigger 2 pending
  270. | bit 5 - trigger 1 level
  271. | bit 6 - trigger 2 level
  272. **timestamp**:
  273. The trigger event timestamp.
  274. The iio device can operate either in "raw" mode where you can fetch the signal
  275. levels (activity bits 5 and 6) using sysfs access or in triggered buffer mode.
  276. In the triggered buffer mode you can follow the signal level changes (activity
  277. bits 1 and 2) using the iio device in /dev. If you enable the timestamps, you
  278. will also get the exact trigger event time that can be matched to a video frame
  279. (every mgb4 video frame has a timestamp with the same clock source).
  280. *Note: although the activity sample always contains all the status bits, it makes
  281. no sense to get the pending bits in raw mode or the level bits in the triggered
  282. buffer mode - the values do not represent valid data in such case.*