pxa_camera.rst 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. .. SPDX-License-Identifier: GPL-2.0
  2. PXA-Camera Host Driver
  3. ======================
  4. Author: Robert Jarzmik <[email protected]>
  5. Constraints
  6. -----------
  7. a) Image size for YUV422P format
  8. All YUV422P images are enforced to have width x height % 16 = 0.
  9. This is due to DMA constraints, which transfers only planes of 8 byte
  10. multiples.
  11. Global video workflow
  12. ---------------------
  13. a) QCI stopped
  14. Initially, the QCI interface is stopped.
  15. When a buffer is queued, start_streaming is called and the QCI starts.
  16. b) QCI started
  17. More buffers can be queued while the QCI is started without halting the
  18. capture. The new buffers are "appended" at the tail of the DMA chain, and
  19. smoothly captured one frame after the other.
  20. Once a buffer is filled in the QCI interface, it is marked as "DONE" and
  21. removed from the active buffers list. It can be then requeud or dequeued by
  22. userland application.
  23. Once the last buffer is filled in, the QCI interface stops.
  24. c) Capture global finite state machine schema
  25. .. code-block:: none
  26. +----+ +---+ +----+
  27. | DQ | | Q | | DQ |
  28. | v | v | v
  29. +-----------+ +------------------------+
  30. | STOP | | Wait for capture start |
  31. +-----------+ Q +------------------------+
  32. +-> | QCI: stop | ------------------> | QCI: run | <------------+
  33. | | DMA: stop | | DMA: stop | |
  34. | +-----------+ +-----> +------------------------+ |
  35. | / | |
  36. | / +---+ +----+ | |
  37. |capture list empty / | Q | | DQ | | QCI Irq EOF |
  38. | / | v | v v |
  39. | +--------------------+ +----------------------+ |
  40. | | DMA hotlink missed | | Capture running | |
  41. | +--------------------+ +----------------------+ |
  42. | | QCI: run | +-----> | QCI: run | <-+ |
  43. | | DMA: stop | / | DMA: run | | |
  44. | +--------------------+ / +----------------------+ | Other |
  45. | ^ /DMA still | | channels |
  46. | | capture list / running | DMA Irq End | not |
  47. | | not empty / | | finished |
  48. | | / v | yet |
  49. | +----------------------+ +----------------------+ | |
  50. | | Videobuf released | | Channel completed | | |
  51. | +----------------------+ +----------------------+ | |
  52. +-- | QCI: run | | QCI: run | --+ |
  53. | DMA: run | | DMA: run | |
  54. +----------------------+ +----------------------+ |
  55. ^ / | |
  56. | no overrun / | overrun |
  57. | / v |
  58. +--------------------+ / +----------------------+ |
  59. | Frame completed | / | Frame overran | |
  60. +--------------------+ <-----+ +----------------------+ restart frame |
  61. | QCI: run | | QCI: stop | --------------+
  62. | DMA: run | | DMA: stop |
  63. +--------------------+ +----------------------+
  64. Legend: - each box is a FSM state
  65. - each arrow is the condition to transition to another state
  66. - an arrow with a comment is a mandatory transition (no condition)
  67. - arrow "Q" means : a buffer was enqueued
  68. - arrow "DQ" means : a buffer was dequeued
  69. - "QCI: stop" means the QCI interface is not enabled
  70. - "DMA: stop" means all 3 DMA channels are stopped
  71. - "DMA: run" means at least 1 DMA channel is still running
  72. DMA usage
  73. ---------
  74. a) DMA flow
  75. - first buffer queued for capture
  76. Once a first buffer is queued for capture, the QCI is started, but data
  77. transfer is not started. On "End Of Frame" interrupt, the irq handler
  78. starts the DMA chain.
  79. - capture of one videobuffer
  80. The DMA chain starts transferring data into videobuffer RAM pages.
  81. When all pages are transferred, the DMA irq is raised on "ENDINTR" status
  82. - finishing one videobuffer
  83. The DMA irq handler marks the videobuffer as "done", and removes it from
  84. the active running queue
  85. Meanwhile, the next videobuffer (if there is one), is transferred by DMA
  86. - finishing the last videobuffer
  87. On the DMA irq of the last videobuffer, the QCI is stopped.
  88. b) DMA prepared buffer will have this structure
  89. .. code-block:: none
  90. +------------+-----+---------------+-----------------+
  91. | desc-sg[0] | ... | desc-sg[last] | finisher/linker |
  92. +------------+-----+---------------+-----------------+
  93. This structure is pointed by dma->sg_cpu.
  94. The descriptors are used as follows:
  95. - desc-sg[i]: i-th descriptor, transferring the i-th sg
  96. element to the video buffer scatter gather
  97. - finisher: has ddadr=DADDR_STOP, dcmd=ENDIRQEN
  98. - linker: has ddadr= desc-sg[0] of next video buffer, dcmd=0
  99. For the next schema, let's assume d0=desc-sg[0] .. dN=desc-sg[N],
  100. "f" stands for finisher and "l" for linker.
  101. A typical running chain is :
  102. .. code-block:: none
  103. Videobuffer 1 Videobuffer 2
  104. +---------+----+---+ +----+----+----+---+
  105. | d0 | .. | dN | l | | d0 | .. | dN | f |
  106. +---------+----+-|-+ ^----+----+----+---+
  107. | |
  108. +----+
  109. After the chaining is finished, the chain looks like :
  110. .. code-block:: none
  111. Videobuffer 1 Videobuffer 2 Videobuffer 3
  112. +---------+----+---+ +----+----+----+---+ +----+----+----+---+
  113. | d0 | .. | dN | l | | d0 | .. | dN | l | | d0 | .. | dN | f |
  114. +---------+----+-|-+ ^----+----+----+-|-+ ^----+----+----+---+
  115. | | | |
  116. +----+ +----+
  117. new_link
  118. c) DMA hot chaining timeslice issue
  119. As DMA chaining is done while DMA _is_ running, the linking may be done
  120. while the DMA jumps from one Videobuffer to another. On the schema, that
  121. would be a problem if the following sequence is encountered :
  122. - DMA chain is Videobuffer1 + Videobuffer2
  123. - pxa_videobuf_queue() is called to queue Videobuffer3
  124. - DMA controller finishes Videobuffer2, and DMA stops
  125. .. code-block:: none
  126. =>
  127. Videobuffer 1 Videobuffer 2
  128. +---------+----+---+ +----+----+----+---+
  129. | d0 | .. | dN | l | | d0 | .. | dN | f |
  130. +---------+----+-|-+ ^----+----+----+-^-+
  131. | | |
  132. +----+ +-- DMA DDADR loads DDADR_STOP
  133. - pxa_dma_add_tail_buf() is called, the Videobuffer2 "finisher" is
  134. replaced by a "linker" to Videobuffer3 (creation of new_link)
  135. - pxa_videobuf_queue() finishes
  136. - the DMA irq handler is called, which terminates Videobuffer2
  137. - Videobuffer3 capture is not scheduled on DMA chain (as it stopped !!!)
  138. .. code-block:: none
  139. Videobuffer 1 Videobuffer 2 Videobuffer 3
  140. +---------+----+---+ +----+----+----+---+ +----+----+----+---+
  141. | d0 | .. | dN | l | | d0 | .. | dN | l | | d0 | .. | dN | f |
  142. +---------+----+-|-+ ^----+----+----+-|-+ ^----+----+----+---+
  143. | | | |
  144. +----+ +----+
  145. new_link
  146. DMA DDADR still is DDADR_STOP
  147. - pxa_camera_check_link_miss() is called
  148. This checks if the DMA is finished and a buffer is still on the
  149. pcdev->capture list. If that's the case, the capture will be restarted,
  150. and Videobuffer3 is scheduled on DMA chain.
  151. - the DMA irq handler finishes
  152. .. note::
  153. If DMA stops just after pxa_camera_check_link_miss() reads DDADR()
  154. value, we have the guarantee that the DMA irq handler will be called back
  155. when the DMA will finish the buffer, and pxa_camera_check_link_miss() will
  156. be called again, to reschedule Videobuffer3.