blob: 198fd61f0da9ef4d1c35687db2a1eee0d4c4f38f [file] [log] [blame]
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -03001/*
2 * Remote Controller core header
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#ifndef _IR_CORE
15#define _IR_CORE
16
17#include <linux/input.h>
18#include <linux/spinlock.h>
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -030019#include <linux/kfifo.h>
20#include <linux/time.h>
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -030021
22extern int ir_core_debug;
23#define IR_dprintk(level, fmt, arg...) if (ir_core_debug >= level) \
24 printk(KERN_DEBUG "%s: " fmt , __func__, ## arg)
25
Mauro Carvalho Chehab971e8292009-12-14 13:53:37 -030026#define IR_TYPE_UNKNOWN 0
27#define IR_TYPE_RC5 (1 << 0) /* Philips RC5 protocol */
28#define IR_TYPE_PD (1 << 1) /* Pulse distance encoded IR */
29#define IR_TYPE_NEC (1 << 2)
30#define IR_TYPE_OTHER (((u64)1) << 63l)
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -030031
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -030032enum raw_event_type {
33 IR_SPACE = (1 << 0),
34 IR_PULSE = (1 << 1),
35 IR_START_EVENT = (1 << 2),
36 IR_STOP_EVENT = (1 << 3),
37};
38
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -030039struct ir_scancode {
40 u16 scancode;
41 u32 keycode;
42};
43
44struct ir_scancode_table {
45 struct ir_scancode *scan;
46 int size;
Mauro Carvalho Chehab2915e5e2010-03-12 11:40:13 -030047 u64 ir_type;
48 char *name;
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -030049 spinlock_t lock;
50};
51
Mauro Carvalho Chehabe93854d2009-12-14 00:16:55 -030052struct ir_dev_props {
53 unsigned long allowed_protos;
54 void *priv;
Mauro Carvalho Chehab971e8292009-12-14 13:53:37 -030055 int (*change_protocol)(void *priv, u64 ir_type);
Mauro Carvalho Chehabe93854d2009-12-14 00:16:55 -030056};
57
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -030058struct ir_raw_event {
59 struct timespec delta; /* Time spent before event */
60 enum raw_event_type type; /* event type */
61};
62
63struct ir_raw_event_ctrl {
64 struct kfifo kfifo; /* fifo for the pulse/space events */
65 struct timespec last_event; /* when last event occurred */
66};
Mauro Carvalho Chehab53f87022009-12-14 02:16:36 -030067
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -030068struct ir_input_dev {
Mauro Carvalho Chehab945cdfa2010-03-11 12:41:56 -030069 struct device dev; /* device */
Mauro Carvalho Chehab727e6252010-03-12 21:18:14 -030070 char *driver_name; /* Name of the driver module */
Mauro Carvalho Chehab4714eda2009-12-13 16:00:08 -030071 struct ir_scancode_table rc_tab; /* scan/key table */
72 unsigned long devno; /* device number */
Mauro Carvalho Chehabe93854d2009-12-14 00:16:55 -030073 const struct ir_dev_props *props; /* Device properties */
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -030074 struct ir_raw_event_ctrl *raw; /* for raw pulse/space events */
Mauro Carvalho Chehab6660de52010-03-21 12:15:16 -030075
76 /* key info - needed by IR keycode handlers */
77 u32 keycode; /* linux key code */
78 int keypressed; /* current state */
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -030079};
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -030080
Mauro Carvalho Chehab53f87022009-12-14 02:16:36 -030081#define to_ir_input_dev(_attr) container_of(_attr, struct ir_input_dev, attr)
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -030082
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -030083/* Routines from ir-keytable.c */
84
85u32 ir_g_keycode_from_table(struct input_dev *input_dev,
86 u32 scancode);
87
Mauro Carvalho Chehab75543cc2009-12-11 09:44:23 -030088int ir_input_register(struct input_dev *dev,
Mauro Carvalho Chehabe93854d2009-12-14 00:16:55 -030089 const struct ir_scancode_table *ir_codes,
Mauro Carvalho Chehab727e6252010-03-12 21:18:14 -030090 const struct ir_dev_props *props,
91 const char *driver_name);
Mauro Carvalho Chehab38ef6aa2009-12-11 09:47:42 -030092void ir_input_unregister(struct input_dev *input_dev);
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -030093
Mauro Carvalho Chehab4714eda2009-12-13 16:00:08 -030094/* Routines from ir-sysfs.c */
95
96int ir_register_class(struct input_dev *input_dev);
97void ir_unregister_class(struct input_dev *input_dev);
98
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -030099/* Routines from ir-raw-event.c */
100int ir_raw_event_register(struct input_dev *input_dev);
101void ir_raw_event_unregister(struct input_dev *input_dev);
102int ir_raw_event_store(struct input_dev *input_dev, enum raw_event_type type);
103int ir_raw_event_handle(struct input_dev *input_dev);
104
105/* from ir-nec-decoder.c */
106int ir_nec_decode(struct input_dev *input_dev,
107 struct ir_raw_event *evs,
108 int len);
109
110
Mauro Carvalho Chehab446e4a62009-12-11 08:34:07 -0300111#endif