media: imx: imx7-media-csi: Add support for fast-tracking queued buffers
authorPaul Elder <paul.elder@ideasonboard.com>
Wed, 7 Sep 2022 11:47:37 +0000 (12:47 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 25 Nov 2022 08:31:46 +0000 (08:31 +0000)
commita868d306de5848b1e2f4911a7aed941a902cc578
treeebe6c75c993c9dca1d5760785a075ded2e110996
parent64a863e3fb9c6b046102f7a1f421082963aa080d
media: imx: imx7-media-csi: Add support for fast-tracking queued buffers

The CSI hardware compatible with this driver handles buffers using a
ping-pong mechanism with two sets of destination addresses. Normally,
when an interrupt comes in to signal the completion of one buffer, say
FB1, it assigns the next buffer in the queue to the next FB1, and the
hardware starts to capture into FB2 in the meantime.

In a buffer underrun situation, in the above example without loss of
generality, if a new buffer is queued before the interrupt for FB1 comes
in, we can program the buffer into FB2 (which is programmed with a dummy
buffer, as there is a buffer underrun).

This of course races with the interrupt that signals FB1 completion, as
once that interrupt comes in, we are no longer guaranteed that the
programming of FB2 was in time and must assume it was too late. This
race is resolved partly by locking the programming of FB2. If it came
after the interrupt for FB1, then the variable that is used to determine
which FB to program would have been swapped by the interrupt handler.

This alone isn't sufficient, however, because the interrupt could still
be generated (thus the hardware starts capturing into the other fb)
while the fast-tracking routine has the irq lock. Thus, after
programming the fb register to fast-track the buffer, the isr also must
be checked to confirm that an interrupt didn't come in the meantime. If
it has, we must assume that programming the register for the
fast-tracked buffer was not in time, and queue the buffer normally.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/staging/media/imx/imx7-media-csi.c