Commit 34668350 authored by Ksenija Stanojevic's avatar Ksenija Stanojevic Committed by Mauro Carvalho Chehab

[media] Staging: media: lirc: Replace timeval with ktime_t

'struct timeval last_tv' is used to get the time of last signal change
and 'struct timeval last_intr_tv' is used to get the time of last UART
interrupt.
32-bit systems using 'struct timeval' will break in the year 2038, so we
have to replace that code with more appropriate types.
Here struct timeval is replaced with ktime_t.
Signed-off-by: default avatarKsenija Stanojevic <ksenija.stanojevic@gmail.com>
Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent bba795fc
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/serial_reg.h> #include <linux/serial_reg.h>
#include <linux/time.h> #include <linux/ktime.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/wait.h> #include <linux/wait.h>
...@@ -127,9 +127,9 @@ static int threshold = 3; ...@@ -127,9 +127,9 @@ static int threshold = 3;
static DEFINE_SPINLOCK(timer_lock); static DEFINE_SPINLOCK(timer_lock);
static struct timer_list timerlist; static struct timer_list timerlist;
/* time of last signal change detected */ /* time of last signal change detected */
static struct timeval last_tv = {0, 0}; static ktime_t last;
/* time of last UART data ready interrupt */ /* time of last UART data ready interrupt */
static struct timeval last_intr_tv = {0, 0}; static ktime_t last_intr_time;
static int last_value; static int last_value;
static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue); static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
...@@ -400,20 +400,6 @@ static void drop_chrdev(void) ...@@ -400,20 +400,6 @@ static void drop_chrdev(void)
} }
/* SECTION: Hardware */ /* SECTION: Hardware */
static long delta(struct timeval *tv1, struct timeval *tv2)
{
unsigned long deltv;
deltv = tv2->tv_sec - tv1->tv_sec;
if (deltv > 15)
deltv = 0xFFFFFF;
else
deltv = deltv*1000000 +
tv2->tv_usec -
tv1->tv_usec;
return deltv;
}
static void sir_timeout(unsigned long data) static void sir_timeout(unsigned long data)
{ {
/* /*
...@@ -432,12 +418,14 @@ static void sir_timeout(unsigned long data) ...@@ -432,12 +418,14 @@ static void sir_timeout(unsigned long data)
/* clear unread bits in UART and restart */ /* clear unread bits in UART and restart */
outb(UART_FCR_CLEAR_RCVR, io + UART_FCR); outb(UART_FCR_CLEAR_RCVR, io + UART_FCR);
/* determine 'virtual' pulse end: */ /* determine 'virtual' pulse end: */
pulse_end = delta(&last_tv, &last_intr_tv); pulse_end = min_t(unsigned long,
ktime_us_delta(last, last_intr_time),
PULSE_MASK);
dev_dbg(driver.dev, "timeout add %d for %lu usec\n", dev_dbg(driver.dev, "timeout add %d for %lu usec\n",
last_value, pulse_end); last_value, pulse_end);
add_read_queue(last_value, pulse_end); add_read_queue(last_value, pulse_end);
last_value = 0; last_value = 0;
last_tv = last_intr_tv; last = last_intr_time;
} }
spin_unlock_irqrestore(&timer_lock, flags); spin_unlock_irqrestore(&timer_lock, flags);
} }
...@@ -445,9 +433,9 @@ static void sir_timeout(unsigned long data) ...@@ -445,9 +433,9 @@ static void sir_timeout(unsigned long data)
static irqreturn_t sir_interrupt(int irq, void *dev_id) static irqreturn_t sir_interrupt(int irq, void *dev_id)
{ {
unsigned char data; unsigned char data;
struct timeval curr_tv; ktime_t curr_time;
static unsigned long deltv; static unsigned long delt;
unsigned long deltintrtv; unsigned long deltintr;
unsigned long flags; unsigned long flags;
int iir, lsr; int iir, lsr;
...@@ -471,49 +459,46 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id) ...@@ -471,49 +459,46 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id)
do { do {
del_timer(&timerlist); del_timer(&timerlist);
data = inb(io + UART_RX); data = inb(io + UART_RX);
do_gettimeofday(&curr_tv); curr_time = ktime_get();
deltv = delta(&last_tv, &curr_tv); delt = min_t(unsigned long,
deltintrtv = delta(&last_intr_tv, &curr_tv); ktime_us_delta(last, curr_time),
PULSE_MASK);
deltintr = min_t(unsigned long,
ktime_us_delta(last_intr_time,
curr_time),
PULSE_MASK);
dev_dbg(driver.dev, "t %lu, d %d\n", dev_dbg(driver.dev, "t %lu, d %d\n",
deltintrtv, (int)data); deltintr, (int)data);
/* /*
* if nothing came in last X cycles, * if nothing came in last X cycles,
* it was gap * it was gap
*/ */
if (deltintrtv > TIME_CONST * threshold) { if (deltintr > TIME_CONST * threshold) {
if (last_value) { if (last_value) {
dev_dbg(driver.dev, "GAP\n"); dev_dbg(driver.dev, "GAP\n");
/* simulate signal change */ /* simulate signal change */
add_read_queue(last_value, add_read_queue(last_value,
deltv - delt -
deltintrtv); deltintr);
last_value = 0; last_value = 0;
last_tv.tv_sec = last = last_intr_time;
last_intr_tv.tv_sec; delt = deltintr;
last_tv.tv_usec =
last_intr_tv.tv_usec;
deltv = deltintrtv;
} }
} }
data = 1; data = 1;
if (data ^ last_value) { if (data ^ last_value) {
/* /*
* deltintrtv > 2*TIME_CONST, remember? * deltintr > 2*TIME_CONST, remember?
* the other case is timeout * the other case is timeout
*/ */
add_read_queue(last_value, add_read_queue(last_value,
deltv-TIME_CONST); delt-TIME_CONST);
last_value = data; last_value = data;
last_tv = curr_tv; last = curr_time;
if (last_tv.tv_usec >= TIME_CONST) { last = ktime_sub_us(last,
last_tv.tv_usec -= TIME_CONST; TIME_CONST);
} else {
last_tv.tv_sec--;
last_tv.tv_usec += 1000000 -
TIME_CONST;
}
} }
last_intr_tv = curr_tv; last_intr_time = curr_time;
if (data) { if (data) {
/* /*
* start timer for end of * start timer for end of
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment