brcm2708: update 3.10 patches with raspberrypi/rpi-3.10.y of 27 Apr. 2014
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-3.10 / 0194-lirc_rpi-Use-read_current_timer-to-determine-transmi.patch
1 From fd945928d6fd544d2f4bdde718b097b01bafb048 Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Tue, 22 Apr 2014 13:58:14 +0100
4 Subject: [PATCH 194/196] lirc_rpi: Use read_current_timer to determine
5 transmitter delay. Thanks to jjmz and others See:
6 https://github.com/raspberrypi/linux/issues/525
7
8 ---
9 drivers/staging/media/lirc/lirc_rpi.c | 32 +++++++++++++++++---------------
10 1 file changed, 17 insertions(+), 15 deletions(-)
11
12 diff --git a/drivers/staging/media/lirc/lirc_rpi.c b/drivers/staging/media/lirc/lirc_rpi.c
13 index 8aee83f..57ffacf 100644
14 --- a/drivers/staging/media/lirc/lirc_rpi.c
15 +++ b/drivers/staging/media/lirc/lirc_rpi.c
16 @@ -30,6 +30,7 @@
17 #include <linux/sched.h>
18 #include <linux/kernel.h>
19 #include <linux/time.h>
20 +#include <linux/timex.h>
21 #include <linux/string.h>
22 #include <linux/delay.h>
23 #include <linux/platform_device.h>
24 @@ -41,7 +42,7 @@
25
26 #define LIRC_DRIVER_NAME "lirc_rpi"
27 #define RBUF_LEN 256
28 -#define LIRC_TRANSMITTER_LATENCY 256
29 +#define LIRC_TRANSMITTER_LATENCY 50
30
31 #ifndef MAX_UDELAY_MS
32 #define MAX_UDELAY_US 5000
33 @@ -107,19 +108,15 @@ static void safe_udelay(unsigned long usecs)
34 static int init_timing_params(unsigned int new_duty_cycle,
35 unsigned int new_freq)
36 {
37 - /*
38 - * period, pulse/space width are kept with 8 binary places -
39 - * IE multiplied by 256.
40 - */
41 - if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
42 + if (1000 * 1000000L / new_freq * new_duty_cycle / 100 <=
43 LIRC_TRANSMITTER_LATENCY)
44 return -EINVAL;
45 - if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
46 + if (1000 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
47 LIRC_TRANSMITTER_LATENCY)
48 return -EINVAL;
49 duty_cycle = new_duty_cycle;
50 freq = new_freq;
51 - period = 256 * 1000000L / freq;
52 + period = 1000 * 1000000L / freq;
53 pulse_width = period * duty_cycle / 100;
54 space_width = period - pulse_width;
55 dprintk("in init_timing_params, freq=%d pulse=%ld, "
56 @@ -130,11 +127,14 @@ static int init_timing_params(unsigned int new_duty_cycle,
57 static long send_pulse_softcarrier(unsigned long length)
58 {
59 int flag;
60 - unsigned long actual, target, d;
61 + unsigned long actual, target;
62 + unsigned long actual_us, initial_us, target_us;
63
64 - length <<= 8;
65 + length *= 1000;
66
67 actual = 0; target = 0; flag = 0;
68 + read_current_timer(&actual_us);
69 +
70 while (actual < length) {
71 if (flag) {
72 gpiochip->set(gpiochip, gpio_out_pin, invert);
73 @@ -143,17 +143,19 @@ static long send_pulse_softcarrier(unsigned long length)
74 gpiochip->set(gpiochip, gpio_out_pin, !invert);
75 target += pulse_width;
76 }
77 - d = (target - actual -
78 - LIRC_TRANSMITTER_LATENCY + 128) >> 8;
79 + initial_us = actual_us;
80 + target_us = actual_us + (target - actual) / 1000;
81 /*
82 * Note - we've checked in ioctl that the pulse/space
83 * widths are big enough so that d is > 0
84 */
85 - udelay(d);
86 - actual += (d << 8) + LIRC_TRANSMITTER_LATENCY;
87 + if ((int)(target_us - actual_us) > 0)
88 + udelay(target_us - actual_us);
89 + read_current_timer(&actual_us);
90 + actual += (actual_us - initial_us) * 1000;
91 flag = !flag;
92 }
93 - return (actual-length) >> 8;
94 + return (actual-length) / 1000;
95 }
96
97 static long send_pulse(unsigned long length)
98 --
99 1.9.1
100