diff options
author | Maxim Levitsky <maximlevitsky@gmail.com> | 2010-07-31 10:59:22 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-08-08 22:43:00 -0400 |
commit | 4a702ebf61120906696f8366dd2be0653b1643e3 (patch) | |
tree | d83d2662edcf538ebcb6bac103bdcadbed430426 | |
parent | b378f43fe9466e7712a8b16be64795ffca3a937e (diff) |
V4L/DVB: IR: add helper function for hardware with small o/b buffer
Some ir input devices have small buffer, and interrupt the host
each time it is full (or half full)
Add a helper that automaticly handles timeouts, and also
automaticly merges samples of same time (space-space)
Such samples might be placed by hardware because size of
sample in the buffer is small (a byte for example).
Also remove constness from ir_dev_props, because it now contains timeout
settings that driver might want to change
Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
Acked-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/IR/ir-core-priv.h | 1 | ||||
-rw-r--r-- | drivers/media/IR/ir-keytable.c | 2 | ||||
-rw-r--r-- | drivers/media/IR/ir-raw-event.c | 84 | ||||
-rw-r--r-- | include/media/ir-core.h | 23 |
4 files changed, 106 insertions, 4 deletions
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h index be6817261c8f..8053e3b84272 100644 --- a/drivers/media/IR/ir-core-priv.h +++ b/drivers/media/IR/ir-core-priv.h | |||
@@ -41,6 +41,7 @@ struct ir_raw_event_ctrl { | |||
41 | 41 | ||
42 | /* raw decoder state follows */ | 42 | /* raw decoder state follows */ |
43 | struct ir_raw_event prev_ev; | 43 | struct ir_raw_event prev_ev; |
44 | struct ir_raw_event this_ev; | ||
44 | struct nec_dec { | 45 | struct nec_dec { |
45 | int state; | 46 | int state; |
46 | unsigned count; | 47 | unsigned count; |
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c index 15a0f192d413..411976d10f83 100644 --- a/drivers/media/IR/ir-keytable.c +++ b/drivers/media/IR/ir-keytable.c | |||
@@ -428,7 +428,7 @@ static void ir_close(struct input_dev *input_dev) | |||
428 | */ | 428 | */ |
429 | int __ir_input_register(struct input_dev *input_dev, | 429 | int __ir_input_register(struct input_dev *input_dev, |
430 | const struct ir_scancode_table *rc_tab, | 430 | const struct ir_scancode_table *rc_tab, |
431 | const struct ir_dev_props *props, | 431 | struct ir_dev_props *props, |
432 | const char *driver_name) | 432 | const char *driver_name) |
433 | { | 433 | { |
434 | struct ir_input_dev *ir_dev; | 434 | struct ir_input_dev *ir_dev; |
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c index d0c18db4c0d3..43094e7eccfa 100644 --- a/drivers/media/IR/ir-raw-event.c +++ b/drivers/media/IR/ir-raw-event.c | |||
@@ -140,6 +140,90 @@ int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type typ | |||
140 | EXPORT_SYMBOL_GPL(ir_raw_event_store_edge); | 140 | EXPORT_SYMBOL_GPL(ir_raw_event_store_edge); |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * ir_raw_event_store_with_filter() - pass next pulse/space to decoders with some processing | ||
144 | * @input_dev: the struct input_dev device descriptor | ||
145 | * @type: the type of the event that has occurred | ||
146 | * | ||
147 | * This routine (which may be called from an interrupt context) works | ||
148 | * in similiar manner to ir_raw_event_store_edge. | ||
149 | * This routine is intended for devices with limited internal buffer | ||
150 | * It automerges samples of same type, and handles timeouts | ||
151 | */ | ||
152 | int ir_raw_event_store_with_filter(struct input_dev *input_dev, | ||
153 | struct ir_raw_event *ev) | ||
154 | { | ||
155 | struct ir_input_dev *ir = input_get_drvdata(input_dev); | ||
156 | struct ir_raw_event_ctrl *raw = ir->raw; | ||
157 | |||
158 | if (!raw || !ir->props) | ||
159 | return -EINVAL; | ||
160 | |||
161 | /* Ignore spaces in idle mode */ | ||
162 | if (ir->idle && !ev->pulse) | ||
163 | return 0; | ||
164 | else if (ir->idle) | ||
165 | ir_raw_event_set_idle(input_dev, 0); | ||
166 | |||
167 | if (!raw->this_ev.duration) { | ||
168 | raw->this_ev = *ev; | ||
169 | } else if (ev->pulse == raw->this_ev.pulse) { | ||
170 | raw->this_ev.duration += ev->duration; | ||
171 | } else { | ||
172 | ir_raw_event_store(input_dev, &raw->this_ev); | ||
173 | raw->this_ev = *ev; | ||
174 | } | ||
175 | |||
176 | /* Enter idle mode if nessesary */ | ||
177 | if (!ev->pulse && ir->props->timeout && | ||
178 | raw->this_ev.duration >= ir->props->timeout) | ||
179 | ir_raw_event_set_idle(input_dev, 1); | ||
180 | return 0; | ||
181 | } | ||
182 | EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter); | ||
183 | |||
184 | void ir_raw_event_set_idle(struct input_dev *input_dev, int idle) | ||
185 | { | ||
186 | struct ir_input_dev *ir = input_get_drvdata(input_dev); | ||
187 | struct ir_raw_event_ctrl *raw = ir->raw; | ||
188 | ktime_t now; | ||
189 | u64 delta; | ||
190 | |||
191 | if (!ir->props) | ||
192 | return; | ||
193 | |||
194 | if (!ir->raw) | ||
195 | goto out; | ||
196 | |||
197 | if (idle) { | ||
198 | IR_dprintk(2, "enter idle mode\n"); | ||
199 | raw->last_event = ktime_get(); | ||
200 | } else { | ||
201 | IR_dprintk(2, "exit idle mode\n"); | ||
202 | |||
203 | now = ktime_get(); | ||
204 | delta = ktime_to_ns(ktime_sub(now, ir->raw->last_event)); | ||
205 | |||
206 | WARN_ON(raw->this_ev.pulse); | ||
207 | |||
208 | raw->this_ev.duration = | ||
209 | min(raw->this_ev.duration + delta, | ||
210 | (u64)IR_MAX_DURATION); | ||
211 | |||
212 | ir_raw_event_store(input_dev, &raw->this_ev); | ||
213 | |||
214 | if (raw->this_ev.duration == IR_MAX_DURATION) | ||
215 | ir_raw_event_reset(input_dev); | ||
216 | |||
217 | raw->this_ev.duration = 0; | ||
218 | } | ||
219 | out: | ||
220 | if (ir->props->s_idle) | ||
221 | ir->props->s_idle(ir->props->priv, idle); | ||
222 | ir->idle = idle; | ||
223 | } | ||
224 | EXPORT_SYMBOL_GPL(ir_raw_event_set_idle); | ||
225 | |||
226 | /** | ||
143 | * ir_raw_event_handle() - schedules the decoding of stored ir data | 227 | * ir_raw_event_handle() - schedules the decoding of stored ir data |
144 | * @input_dev: the struct input_dev device descriptor | 228 | * @input_dev: the struct input_dev device descriptor |
145 | * | 229 | * |
diff --git a/include/media/ir-core.h b/include/media/ir-core.h index 197d05aa83dc..a781045aeed5 100644 --- a/include/media/ir-core.h +++ b/include/media/ir-core.h | |||
@@ -41,6 +41,9 @@ enum rc_driver_type { | |||
41 | * anything with it. Yet, as the same keycode table can be used with other | 41 | * anything with it. Yet, as the same keycode table can be used with other |
42 | * devices, a mask is provided to allow its usage. Drivers should generally | 42 | * devices, a mask is provided to allow its usage. Drivers should generally |
43 | * leave this field in blank | 43 | * leave this field in blank |
44 | * @timeout: optional time after which device stops sending data | ||
45 | * @min_timeout: minimum timeout supported by device | ||
46 | * @max_timeout: maximum timeout supported by device | ||
44 | * @priv: driver-specific data, to be used on the callbacks | 47 | * @priv: driver-specific data, to be used on the callbacks |
45 | * @change_protocol: allow changing the protocol used on hardware decoders | 48 | * @change_protocol: allow changing the protocol used on hardware decoders |
46 | * @open: callback to allow drivers to enable polling/irq when IR input device | 49 | * @open: callback to allow drivers to enable polling/irq when IR input device |
@@ -50,11 +53,19 @@ enum rc_driver_type { | |||
50 | * @s_tx_mask: set transmitter mask (for devices with multiple tx outputs) | 53 | * @s_tx_mask: set transmitter mask (for devices with multiple tx outputs) |
51 | * @s_tx_carrier: set transmit carrier frequency | 54 | * @s_tx_carrier: set transmit carrier frequency |
52 | * @tx_ir: transmit IR | 55 | * @tx_ir: transmit IR |
56 | * @s_idle: optional: enable/disable hardware idle mode, upon which, | ||
57 | * device doesn't interrupt host untill it sees IR data | ||
53 | */ | 58 | */ |
54 | struct ir_dev_props { | 59 | struct ir_dev_props { |
55 | enum rc_driver_type driver_type; | 60 | enum rc_driver_type driver_type; |
56 | unsigned long allowed_protos; | 61 | unsigned long allowed_protos; |
57 | u32 scanmask; | 62 | u32 scanmask; |
63 | |||
64 | u32 timeout; | ||
65 | u32 min_timeout; | ||
66 | u32 max_timeout; | ||
67 | |||
68 | |||
58 | void *priv; | 69 | void *priv; |
59 | int (*change_protocol)(void *priv, u64 ir_type); | 70 | int (*change_protocol)(void *priv, u64 ir_type); |
60 | int (*open)(void *priv); | 71 | int (*open)(void *priv); |
@@ -62,6 +73,7 @@ struct ir_dev_props { | |||
62 | int (*s_tx_mask)(void *priv, u32 mask); | 73 | int (*s_tx_mask)(void *priv, u32 mask); |
63 | int (*s_tx_carrier)(void *priv, u32 carrier); | 74 | int (*s_tx_carrier)(void *priv, u32 carrier); |
64 | int (*tx_ir)(void *priv, int *txbuf, u32 n); | 75 | int (*tx_ir)(void *priv, int *txbuf, u32 n); |
76 | void (*s_idle)(void *priv, int enable); | ||
65 | }; | 77 | }; |
66 | 78 | ||
67 | struct ir_input_dev { | 79 | struct ir_input_dev { |
@@ -69,9 +81,10 @@ struct ir_input_dev { | |||
69 | char *driver_name; /* Name of the driver module */ | 81 | char *driver_name; /* Name of the driver module */ |
70 | struct ir_scancode_table rc_tab; /* scan/key table */ | 82 | struct ir_scancode_table rc_tab; /* scan/key table */ |
71 | unsigned long devno; /* device number */ | 83 | unsigned long devno; /* device number */ |
72 | const struct ir_dev_props *props; /* Device properties */ | 84 | struct ir_dev_props *props; /* Device properties */ |
73 | struct ir_raw_event_ctrl *raw; /* for raw pulse/space events */ | 85 | struct ir_raw_event_ctrl *raw; /* for raw pulse/space events */ |
74 | struct input_dev *input_dev; /* the input device associated with this device */ | 86 | struct input_dev *input_dev; /* the input device associated with this device */ |
87 | bool idle; | ||
75 | 88 | ||
76 | /* key info - needed by IR keycode handlers */ | 89 | /* key info - needed by IR keycode handlers */ |
77 | spinlock_t keylock; /* protects the below members */ | 90 | spinlock_t keylock; /* protects the below members */ |
@@ -95,12 +108,12 @@ enum raw_event_type { | |||
95 | /* From ir-keytable.c */ | 108 | /* From ir-keytable.c */ |
96 | int __ir_input_register(struct input_dev *dev, | 109 | int __ir_input_register(struct input_dev *dev, |
97 | const struct ir_scancode_table *ir_codes, | 110 | const struct ir_scancode_table *ir_codes, |
98 | const struct ir_dev_props *props, | 111 | struct ir_dev_props *props, |
99 | const char *driver_name); | 112 | const char *driver_name); |
100 | 113 | ||
101 | static inline int ir_input_register(struct input_dev *dev, | 114 | static inline int ir_input_register(struct input_dev *dev, |
102 | const char *map_name, | 115 | const char *map_name, |
103 | const struct ir_dev_props *props, | 116 | struct ir_dev_props *props, |
104 | const char *driver_name) { | 117 | const char *driver_name) { |
105 | struct ir_scancode_table *ir_codes; | 118 | struct ir_scancode_table *ir_codes; |
106 | struct ir_input_dev *ir_dev; | 119 | struct ir_input_dev *ir_dev; |
@@ -148,6 +161,10 @@ struct ir_raw_event { | |||
148 | void ir_raw_event_handle(struct input_dev *input_dev); | 161 | void ir_raw_event_handle(struct input_dev *input_dev); |
149 | int ir_raw_event_store(struct input_dev *input_dev, struct ir_raw_event *ev); | 162 | int ir_raw_event_store(struct input_dev *input_dev, struct ir_raw_event *ev); |
150 | int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type type); | 163 | int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type type); |
164 | int ir_raw_event_store_with_filter(struct input_dev *input_dev, | ||
165 | struct ir_raw_event *ev); | ||
166 | void ir_raw_event_set_idle(struct input_dev *input_dev, int idle); | ||
167 | |||
151 | static inline void ir_raw_event_reset(struct input_dev *input_dev) | 168 | static inline void ir_raw_event_reset(struct input_dev *input_dev) |
152 | { | 169 | { |
153 | struct ir_raw_event ev = { .pulse = false, .duration = 0 }; | 170 | struct ir_raw_event ev = { .pulse = false, .duration = 0 }; |