pxa_camera.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. DMA usage
  23. ---------
  24. a) DMA flow
  25. - first buffer queued for capture
  26. Once a first buffer is queued for capture, the QCI is started, but data
  27. transfer is not started. On "End Of Frame" interrupt, the irq handler
  28. starts the DMA chain.
  29. - capture of one videobuffer
  30. The DMA chain starts transfering data into videobuffer RAM pages.
  31. When all pages are transfered, the DMA irq is raised on "ENDINTR" status
  32. - finishing one videobuffer
  33. The DMA irq handler marks the videobuffer as "done", and removes it from
  34. the active running queue
  35. Meanwhile, the next videobuffer (if there is one), is transfered by DMA
  36. - finishing the last videobuffer
  37. On the DMA irq of the last videobuffer, the QCI is stopped.
  38. b) DMA prepared buffer will have this structure
  39. +------------+-----+---------------+-----------------+
  40. | desc-sg[0] | ... | desc-sg[last] | finisher/linker |
  41. +------------+-----+---------------+-----------------+
  42. This structure is pointed by dma->sg_cpu.
  43. The descriptors are used as follows :
  44. - desc-sg[i]: i-th descriptor, transfering the i-th sg
  45. element to the video buffer scatter gather
  46. - finisher: has ddadr=DADDR_STOP, dcmd=ENDIRQEN
  47. - linker: has ddadr= desc-sg[0] of next video buffer, dcmd=0
  48. For the next schema, let's assume d0=desc-sg[0] .. dN=desc-sg[N],
  49. "f" stands for finisher and "l" for linker.
  50. A typical running chain is :
  51. Videobuffer 1 Videobuffer 2
  52. +---------+----+---+ +----+----+----+---+
  53. | d0 | .. | dN | l | | d0 | .. | dN | f |
  54. +---------+----+-|-+ ^----+----+----+---+
  55. | |
  56. +----+
  57. After the chaining is finished, the chain looks like :
  58. Videobuffer 1 Videobuffer 2 Videobuffer 3
  59. +---------+----+---+ +----+----+----+---+ +----+----+----+---+
  60. | d0 | .. | dN | l | | d0 | .. | dN | l | | d0 | .. | dN | f |
  61. +---------+----+-|-+ ^----+----+----+-|-+ ^----+----+----+---+
  62. | | | |
  63. +----+ +----+
  64. new_link
  65. c) DMA hot chaining timeslice issue
  66. As DMA chaining is done while DMA _is_ running, the linking may be done
  67. while the DMA jumps from one Videobuffer to another. On the schema, that
  68. would be a problem if the following sequence is encountered :
  69. - DMA chain is Videobuffer1 + Videobuffer2
  70. - pxa_videobuf_queue() is called to queue Videobuffer3
  71. - DMA controller finishes Videobuffer2, and DMA stops
  72. =>
  73. Videobuffer 1 Videobuffer 2
  74. +---------+----+---+ +----+----+----+---+
  75. | d0 | .. | dN | l | | d0 | .. | dN | f |
  76. +---------+----+-|-+ ^----+----+----+-^-+
  77. | | |
  78. +----+ +-- DMA DDADR loads DDADR_STOP
  79. - pxa_dma_add_tail_buf() is called, the Videobuffer2 "finisher" is
  80. replaced by a "linker" to Videobuffer3 (creation of new_link)
  81. - pxa_videobuf_queue() finishes
  82. - the DMA irq handler is called, which terminates Videobuffer2
  83. - Videobuffer3 capture is not scheduled on DMA chain (as it stopped !!!)
  84. Videobuffer 1 Videobuffer 2 Videobuffer 3
  85. +---------+----+---+ +----+----+----+---+ +----+----+----+---+
  86. | d0 | .. | dN | l | | d0 | .. | dN | l | | d0 | .. | dN | f |
  87. +---------+----+-|-+ ^----+----+----+-|-+ ^----+----+----+---+
  88. | | | |
  89. +----+ +----+
  90. new_link
  91. DMA DDADR still is DDADR_STOP
  92. - pxa_camera_check_link_miss() is called
  93. This checks if the DMA is finished and a buffer is still on the
  94. pcdev->capture list. If that's the case, the capture will be restarted,
  95. and Videobuffer3 is scheduled on DMA chain.
  96. - the DMA irq handler finishes
  97. Note: if DMA stops just after pxa_camera_check_link_miss() reads DDADR()
  98. value, we have the guarantee that the DMA irq handler will be called back
  99. when the DMA will finish the buffer, and pxa_camera_check_link_miss() will
  100. be called again, to reschedule Videobuffer3.
  101. --
  102. Author: Robert Jarzmik <robert.jarzmik@free.fr>