pxa_camera.txt 8.7 KB

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