aboutsummaryrefslogtreecommitdiffstats
path: root/include/media/ir-core.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/media/ir-core.h')
-rw-r--r--include/media/ir-core.h181
1 files changed, 80 insertions, 101 deletions
diff --git a/include/media/ir-core.h b/include/media/ir-core.h
index d41502d9919c..c5909981b075 100644
--- a/include/media/ir-core.h
+++ b/include/media/ir-core.h
@@ -32,21 +32,38 @@ enum rc_driver_type {
32}; 32};
33 33
34/** 34/**
35 * struct ir_dev_props - Allow caller drivers to set special properties 35 * struct rc_dev - represents a remote control device
36 * @driver_type: specifies if the driver or hardware have already a decoder, 36 * @dev: driver model's view of this device
37 * or if it needs to use the IR raw event decoders to produce a scancode 37 * @input_name: name of the input child device
38 * @input_phys: physical path to the input child device
39 * @input_id: id of the input child device (struct input_id)
40 * @driver_name: name of the hardware driver which registered this device
41 * @map_name: name of the default keymap
42 * @rc_tab: current scan/key table
43 * @devno: unique remote control device number
44 * @raw: additional data for raw pulse/space devices
45 * @input_dev: the input child device used to communicate events to userspace
46 * @driver_type: specifies if protocol decoding is done in hardware or software
47 * @idle: used to keep track of RX state
38 * @allowed_protos: bitmask with the supported IR_TYPE_* protocols 48 * @allowed_protos: bitmask with the supported IR_TYPE_* protocols
39 * @scanmask: some hardware decoders are not capable of providing the full 49 * @scanmask: some hardware decoders are not capable of providing the full
40 * scancode to the application. As this is a hardware limit, we can't do 50 * scancode to the application. As this is a hardware limit, we can't do
41 * anything with it. Yet, as the same keycode table can be used with other 51 * 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 52 * devices, a mask is provided to allow its usage. Drivers should generally
43 * leave this field in blank 53 * leave this field in blank
54 * @priv: driver-specific data
55 * @keylock: protects the remaining members of the struct
56 * @keypressed: whether a key is currently pressed
57 * @keyup_jiffies: time (in jiffies) when the current keypress should be released
58 * @timer_keyup: timer for releasing a keypress
59 * @last_keycode: keycode of last keypress
60 * @last_scancode: scancode of last keypress
61 * @last_toggle: toggle value of last command
44 * @timeout: optional time after which device stops sending data 62 * @timeout: optional time after which device stops sending data
45 * @min_timeout: minimum timeout supported by device 63 * @min_timeout: minimum timeout supported by device
46 * @max_timeout: maximum timeout supported by device 64 * @max_timeout: maximum timeout supported by device
47 * @rx_resolution : resolution (in ns) of input sampler 65 * @rx_resolution : resolution (in ns) of input sampler
48 * @tx_resolution: resolution (in ns) of output sampler 66 * @tx_resolution: resolution (in ns) of output sampler
49 * @priv: driver-specific data, to be used on the callbacks
50 * @change_protocol: allow changing the protocol used on hardware decoders 67 * @change_protocol: allow changing the protocol used on hardware decoders
51 * @open: callback to allow drivers to enable polling/irq when IR input device 68 * @open: callback to allow drivers to enable polling/irq when IR input device
52 * is opened. 69 * is opened.
@@ -57,55 +74,50 @@ enum rc_driver_type {
57 * @s_tx_duty_cycle: set transmit duty cycle (0% - 100%) 74 * @s_tx_duty_cycle: set transmit duty cycle (0% - 100%)
58 * @s_rx_carrier: inform driver about carrier it is expected to handle 75 * @s_rx_carrier: inform driver about carrier it is expected to handle
59 * @tx_ir: transmit IR 76 * @tx_ir: transmit IR
60 * @s_idle: optional: enable/disable hardware idle mode, upon which, 77 * @s_idle: enable/disable hardware idle mode, upon which,
61 device doesn't interrupt host until it sees IR pulses 78 * device doesn't interrupt host until it sees IR pulses
62 * @s_learning_mode: enable wide band receiver used for learning 79 * @s_learning_mode: enable wide band receiver used for learning
63 * @s_carrier_report: enable carrier reports 80 * @s_carrier_report: enable carrier reports
64 */ 81 */
65struct ir_dev_props { 82struct rc_dev {
66 enum rc_driver_type driver_type; 83 struct device dev;
67 unsigned long allowed_protos; 84 const char *input_name;
68 u32 scanmask; 85 const char *input_phys;
69 86 struct input_id input_id;
70 u32 timeout; 87 char *driver_name;
71 u32 min_timeout; 88 const char *map_name;
72 u32 max_timeout; 89 struct ir_scancode_table rc_tab;
73 90 unsigned long devno;
74 u32 rx_resolution; 91 struct ir_raw_event_ctrl *raw;
75 u32 tx_resolution; 92 struct input_dev *input_dev;
76 93 enum rc_driver_type driver_type;
77 void *priv;
78 int (*change_protocol)(void *priv, u64 ir_type);
79 int (*open)(void *priv);
80 void (*close)(void *priv);
81 int (*s_tx_mask)(void *priv, u32 mask);
82 int (*s_tx_carrier)(void *priv, u32 carrier);
83 int (*s_tx_duty_cycle)(void *priv, u32 duty_cycle);
84 int (*s_rx_carrier_range)(void *priv, u32 min, u32 max);
85 int (*tx_ir)(void *priv, int *txbuf, u32 n);
86 void (*s_idle)(void *priv, bool enable);
87 int (*s_learning_mode)(void *priv, int enable);
88 int (*s_carrier_report) (void *priv, int enable);
89};
90
91struct ir_input_dev {
92 struct device dev; /* device */
93 char *driver_name; /* Name of the driver module */
94 struct ir_scancode_table rc_tab; /* scan/key table */
95 unsigned long devno; /* device number */
96 struct ir_dev_props *props; /* Device properties */
97 struct ir_raw_event_ctrl *raw; /* for raw pulse/space events */
98 struct input_dev *input_dev; /* the input device associated with this device */
99 bool idle; 94 bool idle;
100 95 u64 allowed_protos;
101 /* key info - needed by IR keycode handlers */ 96 u32 scanmask;
102 spinlock_t keylock; /* protects the below members */ 97 void *priv;
103 bool keypressed; /* current state */ 98 spinlock_t keylock;
104 unsigned long keyup_jiffies; /* when should the current keypress be released? */ 99 bool keypressed;
105 struct timer_list timer_keyup; /* timer for releasing a keypress */ 100 unsigned long keyup_jiffies;
106 u32 last_keycode; /* keycode of last command */ 101 struct timer_list timer_keyup;
107 u32 last_scancode; /* scancode of last command */ 102 u32 last_keycode;
108 u8 last_toggle; /* toggle of last command */ 103 u32 last_scancode;
104 u8 last_toggle;
105 u32 timeout;
106 u32 min_timeout;
107 u32 max_timeout;
108 u32 rx_resolution;
109 u32 tx_resolution;
110 int (*change_protocol)(struct rc_dev *dev, u64 ir_type);
111 int (*open)(struct rc_dev *dev);
112 void (*close)(struct rc_dev *dev);
113 int (*s_tx_mask)(struct rc_dev *dev, u32 mask);
114 int (*s_tx_carrier)(struct rc_dev *dev, u32 carrier);
115 int (*s_tx_duty_cycle)(struct rc_dev *dev, u32 duty_cycle);
116 int (*s_rx_carrier_range)(struct rc_dev *dev, u32 min, u32 max);
117 int (*tx_ir)(struct rc_dev *dev, int *txbuf, u32 n);
118 void (*s_idle)(struct rc_dev *dev, bool enable);
119 int (*s_learning_mode)(struct rc_dev *dev, int enable);
120 int (*s_carrier_report) (struct rc_dev *dev, int enable);
109}; 121};
110 122
111enum raw_event_type { 123enum raw_event_type {
@@ -115,52 +127,14 @@ enum raw_event_type {
115 IR_STOP_EVENT = (1 << 3), 127 IR_STOP_EVENT = (1 << 3),
116}; 128};
117 129
118#define to_ir_input_dev(_attr) container_of(_attr, struct ir_input_dev, attr) 130#define to_rc_dev(d) container_of(d, struct rc_dev, dev)
119
120int __ir_input_register(struct input_dev *dev,
121 const struct ir_scancode_table *ir_codes,
122 struct ir_dev_props *props,
123 const char *driver_name);
124
125static inline int ir_input_register(struct input_dev *dev,
126 const char *map_name,
127 struct ir_dev_props *props,
128 const char *driver_name) {
129 struct ir_scancode_table *ir_codes;
130 struct ir_input_dev *ir_dev;
131 int rc;
132
133 if (!map_name)
134 return -EINVAL;
135
136 ir_codes = get_rc_map(map_name);
137 if (!ir_codes) {
138 ir_codes = get_rc_map(RC_MAP_EMPTY);
139 131
140 if (!ir_codes)
141 return -EINVAL;
142 }
143 132
144 rc = __ir_input_register(dev, ir_codes, props, driver_name); 133void ir_repeat(struct rc_dev *dev);
145 if (rc < 0) 134void ir_keydown(struct rc_dev *dev, int scancode, u8 toggle);
146 return -EINVAL; 135void ir_keydown_notimeout(struct rc_dev *dev, int scancode, u8 toggle);
147 136void ir_keyup(struct rc_dev *dev);
148 ir_dev = input_get_drvdata(dev); 137u32 ir_g_keycode_from_table(struct rc_dev *dev, u32 scancode);
149
150 if (!rc && ir_dev->props && ir_dev->props->change_protocol)
151 rc = ir_dev->props->change_protocol(ir_dev->props->priv,
152 ir_codes->ir_type);
153
154 return rc;
155}
156
157void ir_input_unregister(struct input_dev *input_dev);
158
159void ir_repeat(struct input_dev *dev);
160void ir_keydown(struct input_dev *dev, int scancode, u8 toggle);
161void ir_keydown_notimeout(struct input_dev *dev, int scancode, u8 toggle);
162void ir_keyup(struct input_dev *dev);
163u32 ir_g_keycode_from_table(struct input_dev *input_dev, u32 scancode);
164 138
165/* From ir-raw-event.c */ 139/* From ir-raw-event.c */
166struct ir_raw_event { 140struct ir_raw_event {
@@ -194,20 +168,25 @@ static inline void init_ir_raw_event(struct ir_raw_event *ev)
194 168
195#define IR_MAX_DURATION 0xFFFFFFFF /* a bit more than 4 seconds */ 169#define IR_MAX_DURATION 0xFFFFFFFF /* a bit more than 4 seconds */
196 170
197void ir_raw_event_handle(struct input_dev *input_dev); 171struct rc_dev *rc_allocate_device(void);
198int ir_raw_event_store(struct input_dev *input_dev, struct ir_raw_event *ev); 172void rc_free_device(struct rc_dev *dev);
199int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type type); 173int rc_register_device(struct rc_dev *dev);
200int ir_raw_event_store_with_filter(struct input_dev *input_dev, 174void rc_unregister_device(struct rc_dev *dev);
175
176void ir_raw_event_handle(struct rc_dev *dev);
177int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev);
178int ir_raw_event_store_edge(struct rc_dev *dev, enum raw_event_type type);
179int ir_raw_event_store_with_filter(struct rc_dev *dev,
201 struct ir_raw_event *ev); 180 struct ir_raw_event *ev);
202void ir_raw_event_set_idle(struct input_dev *input_dev, bool idle); 181void ir_raw_event_set_idle(struct rc_dev *dev, bool idle);
203 182
204static inline void ir_raw_event_reset(struct input_dev *input_dev) 183static inline void ir_raw_event_reset(struct rc_dev *dev)
205{ 184{
206 DEFINE_IR_RAW_EVENT(ev); 185 DEFINE_IR_RAW_EVENT(ev);
207 ev.reset = true; 186 ev.reset = true;
208 187
209 ir_raw_event_store(input_dev, &ev); 188 ir_raw_event_store(dev, &ev);
210 ir_raw_event_handle(input_dev); 189 ir_raw_event_handle(dev);
211} 190}
212 191
213 192