media: cpia2: use u64 for the timestamp internally
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 21 Jan 2019 13:32:25 +0000 (08:32 -0500)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Thu, 7 Feb 2019 17:12:43 +0000 (12:12 -0500)
Just like vb2 does, use u64 internally to store the timestamps
of the buffers. Only convert to timeval when interfacing with
userspace.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/usb/cpia2/cpia2.h
drivers/media/usb/cpia2/cpia2_usb.c
drivers/media/usb/cpia2/cpia2_v4l.c

index ab238ac..d0a4648 100644 (file)
@@ -350,7 +350,7 @@ struct cpia2_sbuf {
 };
 
 struct framebuf {
-       struct timeval timestamp;
+       u64 ts;
        unsigned long seq;
        int num;
        int length;
index a771e0a..e5d8dee 100644 (file)
@@ -324,7 +324,7 @@ static void cpia2_usb_complete(struct urb *urb)
                                continue;
                        }
                        DBG("Start of frame pattern found\n");
-                       v4l2_get_timestamp(&cam->workbuff->timestamp);
+                       cam->workbuff->ts = ktime_get_ns();
                        cam->workbuff->seq = cam->frame_count++;
                        cam->workbuff->data[0] = 0xFF;
                        cam->workbuff->data[1] = 0xD8;
index 748739c..95c0bd4 100644 (file)
@@ -833,7 +833,7 @@ static int cpia2_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
                break;
        case FRAME_READY:
                buf->bytesused = cam->buffers[buf->index].length;
-               buf->timestamp = cam->buffers[buf->index].timestamp;
+               buf->timestamp = ns_to_timeval(cam->buffers[buf->index].ts);
                buf->sequence = cam->buffers[buf->index].seq;
                buf->flags = V4L2_BUF_FLAG_DONE;
                break;
@@ -889,12 +889,7 @@ static int find_earliest_filled_buffer(struct camera_data *cam)
                                found = i;
                        } else {
                                /* find which buffer is earlier */
-                               struct timeval *tv1, *tv2;
-                               tv1 = &cam->buffers[i].timestamp;
-                               tv2 = &cam->buffers[found].timestamp;
-                               if(tv1->tv_sec < tv2->tv_sec ||
-                                  (tv1->tv_sec == tv2->tv_sec &&
-                                   tv1->tv_usec < tv2->tv_usec))
+                               if (cam->buffers[i].ts < cam->buffers[found].ts)
                                        found = i;
                        }
                }
@@ -945,7 +940,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
        buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE
                | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        buf->field = V4L2_FIELD_NONE;
-       buf->timestamp = cam->buffers[buf->index].timestamp;
+       buf->timestamp = ns_to_timeval(cam->buffers[buf->index].ts);
        buf->sequence = cam->buffers[buf->index].seq;
        buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
        buf->length = cam->frame_size;