5801afea524d168a1ec8142e2f3021ea53aa5ba0
[openwrt/staging/lynxis.git] / target / linux / brcm2708 / patches-4.14 / 950-0389-staging-bcm2835-camera-use-ktime_t-for-timestamps.patch
1 From fab723d6ce6dd2052b4febd65ae62425288d79d3 Mon Sep 17 00:00:00 2001
2 From: Arnd Bergmann <arnd@arndb.de>
3 Date: Mon, 27 Nov 2017 14:19:56 +0100
4 Subject: [PATCH 389/454] staging: bcm2835-camera use ktime_t for timestamps
5
6 commit 6cf83f2a9e81c500819938fad3555081471212c6 upstream with
7 minor mods
8
9 struct timeval is deprecated for in-kernel use, and converting
10 this function to use ktime_t makes it simpler as well.
11
12 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
15 ---
16 .../bcm2835-camera/bcm2835-camera.c | 37 +++++--------------
17 .../bcm2835-camera/bcm2835-camera.h | 2 +-
18 2 files changed, 10 insertions(+), 29 deletions(-)
19
20 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
21 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
22 @@ -374,37 +374,18 @@ static void buffer_cb(struct vchiq_mmal_
23 buf->vb.vb2_buf.timestamp);
24
25 } else if(pts != 0) {
26 - struct timeval timestamp;
27 + ktime_t timestamp;
28 s64 runtime_us = pts -
29 dev->capture.vc_start_timestamp;
30 - u32 div = 0;
31 - u32 rem = 0;
32 -
33 - div =
34 - div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
35 - timestamp.tv_sec =
36 - dev->capture.kernel_start_ts.tv_sec + div;
37 - timestamp.tv_usec =
38 - dev->capture.kernel_start_ts.tv_usec + rem;
39 -
40 - if (timestamp.tv_usec >=
41 - USEC_PER_SEC) {
42 - timestamp.tv_sec++;
43 - timestamp.tv_usec -=
44 - USEC_PER_SEC;
45 - }
46 + timestamp = ktime_add_us(dev->capture.kernel_start_ts,
47 + runtime_us);
48 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
49 - "Convert start time %d.%06d and %llu "
50 - "with offset %llu to %d.%06d\n",
51 - (int)dev->capture.kernel_start_ts.
52 - tv_sec,
53 - (int)dev->capture.kernel_start_ts.
54 - tv_usec,
55 + "Convert start time %llu and %llu "
56 + "with offset %llu to %llu\n",
57 + ktime_to_ns(dev->capture.kernel_start_ts),
58 dev->capture.vc_start_timestamp, pts,
59 - (int)timestamp.tv_sec,
60 - (int)timestamp.tv_usec);
61 - buf->vb.vb2_buf.timestamp = timestamp.tv_sec * 1000000000ULL +
62 - timestamp.tv_usec * 1000ULL;
63 + ktime_to_ns(timestamp));
64 + buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
65 } else {
66 if (dev->capture.last_timestamp) {
67 buf->vb.vb2_buf.timestamp = dev->capture.last_timestamp;
68 @@ -596,7 +577,7 @@ static int start_streaming(struct vb2_qu
69
70 dev->capture.last_timestamp = 0;
71
72 - v4l2_get_timestamp(&dev->capture.kernel_start_ts);
73 + dev->capture.kernel_start_ts = ktime_get();
74
75 /* enable the camera port */
76 dev->capture.port->cb_ctx = dev;
77 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
78 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
79 @@ -92,7 +92,7 @@ struct bm2835_mmal_dev {
80 /* VC start timestamp for streaming */
81 s64 vc_start_timestamp;
82 /* Kernel start timestamp for streaming */
83 - struct timeval kernel_start_ts;
84 + ktime_t kernel_start_ts;
85 /* Timestamp of last frame */
86 u64 last_timestamp;
87