summaryrefslogtreecommitdiffstats
path: root/include/media
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2010-04-08 13:10:00 -0300
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-05-19 12:57:03 -0300
commit724e2495502a98aaa3f93c404472a991da8ff857 (patch)
treedfdc90b4408fa95f7757b1c6e5b36c2789da0df2 /include/media
parentd22e546ea18ee66c255af906f2714d3ee82d4b42 (diff)
V4L/DVB: Teach drivers/media/IR/ir-raw-event.c to use durations
drivers/media/IR/ir-raw-event.c is currently written with the assumption that all "raw" hardware will generate events only on state change (i.e. when a pulse or space starts). However, some hardware (like mceusb, probably the most popular IR receiver out there) only generates duration data (and that data is buffered so using any kind of timing on the data is futile). Furthermore, using signed int's to represent pulse/space durations is a well-known approach when writing ir decoders. With this patch: - s64 int's are used to represent pulse/space durations in ns - a workqueue is used to decode the ir protocols outside of interrupt context - #defines are added to make decoders clearer - decoder reset is implemented by passing a zero duration to the kfifo queue and decoders are updated accordingly Signed-off-by: David Härdeman <david@hardeman.nu> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'include/media')
-rw-r--r--include/media/ir-core.h47
1 files changed, 36 insertions, 11 deletions
diff --git a/include/media/ir-core.h b/include/media/ir-core.h
index e9fa94fe2ef..e9a0cbf67ff 100644
--- a/include/media/ir-core.h
+++ b/include/media/ir-core.h
@@ -65,14 +65,12 @@ struct ir_dev_props {
void (*close)(void *priv);
};
-struct ir_raw_event {
- struct timespec delta; /* Time spent before event */
- enum raw_event_type type; /* event type */
-};
-
struct ir_raw_event_ctrl {
- struct kfifo kfifo; /* fifo for the pulse/space events */
- struct timespec last_event; /* when last event occurred */
+ struct work_struct rx_work; /* for the rx decoding workqueue */
+ struct kfifo kfifo; /* fifo for the pulse/space durations */
+ ktime_t last_event; /* when last event occurred */
+ enum raw_event_type last_type; /* last event type */
+ struct input_dev *input_dev; /* pointer to the parent input_dev */
};
struct ir_input_dev {
@@ -97,8 +95,7 @@ struct ir_input_dev {
struct ir_raw_handler {
struct list_head list;
- int (*decode)(struct input_dev *input_dev,
- struct ir_raw_event *ev);
+ int (*decode)(struct input_dev *input_dev, s64 duration);
int (*raw_register)(struct input_dev *input_dev);
int (*raw_unregister)(struct input_dev *input_dev);
};
@@ -154,8 +151,14 @@ void ir_unregister_class(struct input_dev *input_dev);
/* Routines from ir-raw-event.c */
int ir_raw_event_register(struct input_dev *input_dev);
void ir_raw_event_unregister(struct input_dev *input_dev);
-int ir_raw_event_store(struct input_dev *input_dev, enum raw_event_type type);
-int ir_raw_event_handle(struct input_dev *input_dev);
+void ir_raw_event_handle(struct input_dev *input_dev);
+int ir_raw_event_store(struct input_dev *input_dev, s64 duration);
+int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type type);
+static inline void ir_raw_event_reset(struct input_dev *input_dev)
+{
+ ir_raw_event_store(input_dev, 0);
+ ir_raw_event_handle(input_dev);
+}
int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
void ir_raw_init(void);
@@ -174,4 +177,26 @@ void ir_raw_init(void);
#define load_rc5_decode() 0
#endif
+/* macros for ir decoders */
+#define PULSE(units) ((units))
+#define SPACE(units) (-(units))
+#define IS_RESET(duration) ((duration) == 0)
+#define IS_PULSE(duration) ((duration) > 0)
+#define IS_SPACE(duration) ((duration) < 0)
+#define DURATION(duration) (abs((duration)))
+#define IS_TRANSITION(x, y) ((x) * (y) < 0)
+#define DECREASE_DURATION(duration, amount) \
+ do { \
+ if (IS_SPACE(duration)) \
+ duration += (amount); \
+ else if (IS_PULSE(duration)) \
+ duration -= (amount); \
+ } while (0)
+
+#define TO_UNITS(duration, unit_len) \
+ ((int)((duration) > 0 ? \
+ DIV_ROUND_CLOSEST(abs((duration)), (unit_len)) :\
+ -DIV_ROUND_CLOSEST(abs((duration)), (unit_len))))
+#define TO_US(duration) ((int)TO_UNITS(duration, 1000))
+
#endif /* _IR_CORE */