2bb3a47145c8bd685e4ff1a98433e93994229893
[oweals/openwrt.git] /
1 From a740e59bf8099d1f5b5b29be3e9993fbd51e729a Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Fri, 6 Jul 2018 17:43:03 +0100
4 Subject: [PATCH 388/454] Revert "bcm2835-camera: Fix timestamp calculation
5  problem (#2214)"
6
7 This reverts commit 90ac037dbeecbb514b677e43b53bc5b1a452ea22.
8 This has been fixed in an alternate format upstream, so adopt that.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
11 ---
12  .../bcm2835-camera/bcm2835-camera.c           | 41 ++++++++++++++-----
13  .../bcm2835-camera/bcm2835-camera.h           |  2 +-
14  2 files changed, 32 insertions(+), 11 deletions(-)
15
16 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
17 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
18 @@ -374,17 +374,37 @@ static void buffer_cb(struct vchiq_mmal_
19                                  buf->vb.vb2_buf.timestamp);
20  
21                         } else if(pts != 0) {
22 +                               struct timeval timestamp;
23                                 s64 runtime_us = pts -
24                                     dev->capture.vc_start_timestamp;
25 -                               buf->vb.vb2_buf.timestamp = (runtime_us * NSEC_PER_USEC) +
26 -                                   dev->capture.kernel_start_timestamp;
27 +                               u32 div = 0;
28 +                               u32 rem = 0;
29 +
30 +                               div =
31 +                                   div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
32 +                               timestamp.tv_sec =
33 +                                   dev->capture.kernel_start_ts.tv_sec + div;
34 +                               timestamp.tv_usec =
35 +                                   dev->capture.kernel_start_ts.tv_usec + rem;
36 +
37 +                               if (timestamp.tv_usec >=
38 +                                   USEC_PER_SEC) {
39 +                                       timestamp.tv_sec++;
40 +                                       timestamp.tv_usec -=
41 +                                           USEC_PER_SEC;
42 +                               }
43                                 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
44 -                                        "Buffer time set as converted timestamp - %llu "
45 -                                        "= (pts [%lld usec] - vc start time [%llu usec]) "
46 -                                        "+ kernel start time [%llu nsec]\n",
47 -                                        buf->vb.vb2_buf.timestamp,
48 -                                        pts, dev->capture.vc_start_timestamp,
49 -                                        dev->capture.kernel_start_timestamp);
50 +                                        "Convert start time %d.%06d and %llu "
51 +                                        "with offset %llu to %d.%06d\n",
52 +                                        (int)dev->capture.kernel_start_ts.
53 +                                        tv_sec,
54 +                                        (int)dev->capture.kernel_start_ts.
55 +                                        tv_usec,
56 +                                        dev->capture.vc_start_timestamp, pts,
57 +                                        (int)timestamp.tv_sec,
58 +                                        (int)timestamp.tv_usec);
59 +                               buf->vb.vb2_buf.timestamp = timestamp.tv_sec * 1000000000ULL +
60 +                                       timestamp.tv_usec * 1000ULL;
61                         } else {
62                                 if (dev->capture.last_timestamp) {
63                                         buf->vb.vb2_buf.timestamp = dev->capture.last_timestamp;
64 @@ -394,7 +414,8 @@ static void buffer_cb(struct vchiq_mmal_
65                                 }
66                                 else {
67                                         buf->vb.vb2_buf.timestamp =
68 -                                       dev->capture.kernel_start_timestamp;
69 +                                       dev->capture.kernel_start_ts.tv_sec  * 1000000000ULL +
70 +                                       dev->capture.kernel_start_ts.tv_usec * 1000ULL;
71                                         v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
72                                          "Buffer time set as start timestamp - %lld",
73                                          buf->vb.vb2_buf.timestamp);
74 @@ -575,7 +596,7 @@ static int start_streaming(struct vb2_qu
75  
76         dev->capture.last_timestamp = 0;
77  
78 -       dev->capture.kernel_start_timestamp = ktime_get_ns();
79 +       v4l2_get_timestamp(&dev->capture.kernel_start_ts);
80  
81         /* enable the camera port */
82         dev->capture.port->cb_ctx = dev;
83 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
84 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
85 @@ -92,7 +92,7 @@ struct bm2835_mmal_dev {
86                 /* VC start timestamp for streaming */
87                 s64         vc_start_timestamp;
88                 /* Kernel start timestamp for streaming */
89 -               u64         kernel_start_timestamp;
90 +               struct timeval kernel_start_ts;
91                 /* Timestamp of last frame */
92                 u64             last_timestamp;
93