364600158dd5d6f24b22d3af74111f17502cdde6
[openwrt/staging/rmilecki.git] /
1 From e86fdc72907b8cf1aab4dfd70843ffb166de0405 Mon Sep 17 00:00:00 2001
2 From: Naushir Patuck <naush@raspberrypi.com>
3 Date: Fri, 5 Mar 2021 15:40:45 +0000
4 Subject: [PATCH] media: bcm2835-unicam: Fix bug in buffer swapping
5 logic
6
7 If multiple sets of interrupts occur simultaneously, it may be unsafe
8 to swap buffers, as the hardware may already be re-using the current
9 buffers. In such cases, avoid swapping buffers, and wait for the next
10 opportunity at the Frame End interrupt to signal completion.
11
12 Additionally, check the packet compare status when watching for frame
13 end for buffers swaps, as this could also signify a frame end event.
14
15 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
16 ---
17 .../media/platform/bcm2835/bcm2835-unicam.c | 21 ++++++++++++++++---
18 1 file changed, 18 insertions(+), 3 deletions(-)
19
20 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
21 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
22 @@ -798,6 +798,7 @@ static irqreturn_t unicam_isr(int irq, v
23 unsigned int sequence = unicam->sequence;
24 unsigned int i;
25 u32 ista, sta;
26 + bool fe;
27 u64 ts;
28
29 sta = reg_read(unicam, UNICAM_STA);
30 @@ -815,12 +816,18 @@ static irqreturn_t unicam_isr(int irq, v
31 return IRQ_HANDLED;
32
33 /*
34 + * Look for either the Frame End interrupt or the Packet Capture status
35 + * to signal a frame end.
36 + */
37 + fe = (ista & UNICAM_FEI || sta & UNICAM_PI0);
38 +
39 + /*
40 * We must run the frame end handler first. If we have a valid next_frm
41 * and we get a simultaneout FE + FS interrupt, running the FS handler
42 * first would null out the next_frm ptr and we would have lost the
43 * buffer forever.
44 */
45 - if (ista & UNICAM_FEI || sta & UNICAM_PI0) {
46 + if (fe) {
47 /*
48 * Ensure we have swapped buffers already as we can't
49 * stop the peripheral. If no buffer is available, use a
50 @@ -831,7 +838,15 @@ static irqreturn_t unicam_isr(int irq, v
51 if (!unicam->node[i].streaming)
52 continue;
53
54 - if (unicam->node[i].cur_frm)
55 + /*
56 + * If cur_frm == next_frm, it means we have not had
57 + * a chance to swap buffers, likely due to having
58 + * multiple interrupts occurring simultaneously (like FE
59 + * + FS + LS). In this case, we cannot signal the buffer
60 + * as complete, as the HW will reuse that buffer.
61 + */
62 + if (unicam->node[i].cur_frm &&
63 + unicam->node[i].cur_frm != unicam->node[i].next_frm)
64 unicam_process_buffer_complete(&unicam->node[i],
65 sequence);
66 unicam->node[i].cur_frm = unicam->node[i].next_frm;
67 @@ -868,7 +883,7 @@ static irqreturn_t unicam_isr(int irq, v
68 * where the HW does not actually swap it if the new frame has
69 * already started.
70 */
71 - if (ista & (UNICAM_FSI | UNICAM_LCI) && !(ista & UNICAM_FEI)) {
72 + if (ista & (UNICAM_FSI | UNICAM_LCI) && !fe) {
73 for (i = 0; i < ARRAY_SIZE(unicam->node); i++) {
74 if (!unicam->node[i].streaming)
75 continue;