[media] bt8xxx: Use monotonic time
authorAbhilash Jindal <klock.android@gmail.com>
Tue, 11 Aug 2015 15:22:57 +0000 (12:22 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Sun, 16 Aug 2015 16:29:59 +0000 (13:29 -0300)
Wall time obtained from do_gettimeofday is susceptible to sudden jumps due to
user setting the time or due to NTP.

Monotonic time is constantly increasing time better suited for comparing two
timestamps.

Signed-off-by: Abhilash Jindal <klock.android@gmail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/pci/bt8xx/bttv-input.c
drivers/media/pci/bt8xx/bttvp.h

index 67c8d6b2c33596032b294e99b7511e91d48eb8ac..a75c53da224a645675c15c9a1318c539c14e5153 100644 (file)
@@ -194,21 +194,18 @@ static u32 bttv_rc5_decode(unsigned int code)
 static void bttv_rc5_timer_end(unsigned long data)
 {
        struct bttv_ir *ir = (struct bttv_ir *)data;
-       struct timeval tv;
+       ktime_t tv;
        u32 gap, rc5, scancode;
        u8 toggle, command, system;
 
        /* get time */
-       do_gettimeofday(&tv);
+       tv = ktime_get();
 
+       gap = ktime_to_us(ktime_sub(tv, ir->base_time));
        /* avoid overflow with gap >1s */
-       if (tv.tv_sec - ir->base_time.tv_sec > 1) {
+       if (gap > USEC_PER_SEC) {
                gap = 200000;
-       } else {
-               gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
-                   tv.tv_usec - ir->base_time.tv_usec;
        }
-
        /* signal we're ready to start a new code */
        ir->active = false;
 
@@ -249,7 +246,7 @@ static void bttv_rc5_timer_end(unsigned long data)
 static int bttv_rc5_irq(struct bttv *btv)
 {
        struct bttv_ir *ir = btv->remote;
-       struct timeval tv;
+       ktime_t tv;
        u32 gpio;
        u32 gap;
        unsigned long current_jiffies;
@@ -259,14 +256,12 @@ static int bttv_rc5_irq(struct bttv *btv)
 
        /* get time of bit */
        current_jiffies = jiffies;
-       do_gettimeofday(&tv);
+       tv = ktime_get();
 
+       gap = ktime_to_us(ktime_sub(tv, ir->base_time));
        /* avoid overflow with gap >1s */
-       if (tv.tv_sec - ir->base_time.tv_sec > 1) {
+       if (gap > USEC_PER_SEC) {
                gap = 200000;
-       } else {
-               gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
-                   tv.tv_usec - ir->base_time.tv_usec;
        }
 
        dprintk("RC5 IRQ: gap %d us for %s\n",
index a444cfb35c0b8a37cc6f9d1ffc78e1918aab008a..31bf79d3b0d263e312c1849d8eb9c49a7d48f819 100644 (file)
@@ -140,7 +140,7 @@ struct bttv_ir {
        bool                    rc5_gpio;   /* Is RC5 legacy GPIO enabled? */
        u32                     last_bit;   /* last raw bit seen */
        u32                     code;       /* raw code under construction */
-       struct timeval          base_time;  /* time of last seen code */
+       ktime_t                                         base_time;  /* time of last seen code */
        bool                    active;     /* building raw code */
 };