b5fbceba241bad3c78ba99b9178b5cb41169305d
[openwrt/staging/jow.git] /
1 From 754a5ed1aa42ce9d5be5f84a5a0888f850b15e00 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Thu, 28 Jun 2018 15:57:25 +0100
4 Subject: [PATCH 252/703] staging: bcm2835_camera: Ensure all buffers are
5 returned on disable
6
7 With the recent change to match MMAL and V4L2 buffers there
8 is a need to wait for all MMAL buffers to be returned during
9 stop_streaming.
10
11 Fixes: 9384167 "staging: bcm2835-camera: Remove V4L2/MMAL buffer remapping"
12 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
13 ---
14 .../bcm2835-camera/bcm2835-camera.c | 22 ++++++++++++++-----
15 .../vc04_services/bcm2835-camera/mmal-vchiq.c | 4 ++++
16 .../vc04_services/bcm2835-camera/mmal-vchiq.h | 3 +++
17 3 files changed, 23 insertions(+), 6 deletions(-)
18
19 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
20 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
21 @@ -607,6 +607,7 @@ static void stop_streaming(struct vb2_qu
22 int ret;
23 unsigned long timeout;
24 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
25 + struct vchiq_mmal_port *port = dev->capture.port;
26
27 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
28 __func__, dev);
29 @@ -630,12 +631,6 @@ static void stop_streaming(struct vb2_qu
30 &dev->capture.frame_count,
31 sizeof(dev->capture.frame_count));
32
33 - /* wait for last frame to complete */
34 - timeout = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
35 - if (timeout == 0)
36 - v4l2_err(&dev->v4l2_dev,
37 - "timed out waiting for frame completion\n");
38 -
39 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
40 "disabling connection\n");
41
42 @@ -650,6 +645,21 @@ static void stop_streaming(struct vb2_qu
43 ret);
44 }
45
46 + /* wait for all buffers to be returned */
47 + while (atomic_read(&port->buffers_with_vpu)) {
48 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
49 + "%s: Waiting for buffers to be returned - %d outstanding\n",
50 + __func__, atomic_read(&port->buffers_with_vpu));
51 + timeout = wait_for_completion_timeout(&dev->capture.frame_cmplt,
52 + HZ);
53 + if (timeout == 0) {
54 + v4l2_err(&dev->v4l2_dev, "%s: Timeout waiting for buffers to be returned - %d outstanding\n",
55 + __func__,
56 + atomic_read(&port->buffers_with_vpu));
57 + break;
58 + }
59 + }
60 +
61 if (disable_camera(dev) < 0)
62 v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
63 }
64 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
65 +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
66 @@ -246,6 +246,8 @@ static void buffer_work_cb(struct work_s
67 struct mmal_msg_context *msg_context =
68 container_of(work, struct mmal_msg_context, u.bulk.work);
69
70 + atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu);
71 +
72 msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
73 msg_context->u.bulk.port,
74 msg_context->u.bulk.status,
75 @@ -389,6 +391,8 @@ buffer_from_host(struct vchiq_mmal_insta
76 INIT_WORK(&msg_context->u.bulk.buffer_to_host_work,
77 buffer_to_host_work_cb);
78
79 + atomic_inc(&port->buffers_with_vpu);
80 +
81 /* prep the buffer from host message */
82 memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
83
84 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
85 +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
86 @@ -72,6 +72,9 @@ struct vchiq_mmal_port {
87 struct list_head buffers;
88 /* lock to serialise adding and removing buffers from list */
89 spinlock_t slock;
90 +
91 + /* Count of buffers the VPU has yet to return */
92 + atomic_t buffers_with_vpu;
93 /* callback on buffer completion */
94 vchiq_mmal_buffer_cb buffer_cb;
95 /* callback context */