blob: 45bf5cf59458e6abc1a7d8eead4cf6379b816ffc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * some common structs and functions to handle infrared remotes via
4 * input layer ...
5 *
6 * (c) 2003 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080023#ifndef _IR_COMMON
24#define _IR_COMMON
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080026#include <linux/input.h>
Mauro Carvalho Chehab0b778a52006-12-27 14:04:09 -020027#include <linux/workqueue.h>
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -030028#include <linux/interrupt.h>
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -030029#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Mauro Carvalho Chehab4e892172009-11-27 21:54:41 -030031extern int media_ir_debug; /* media_ir_debug level (0,1,2) */
32#define IR_dprintk(level, fmt, arg...) if (media_ir_debug >= level) \
Mauro Carvalho Chehaba53e2122009-12-02 15:44:30 -030033 printk(KERN_DEBUG "%s: " fmt , __func__, ## arg)
Mauro Carvalho Chehab4e892172009-11-27 21:54:41 -030034
Mauro Carvalho Chehabd30a3fe2009-12-05 01:19:47 -030035enum ir_type {
36 IR_TYPE_UNKNOWN = 0,
37 IR_TYPE_RC5 = 1,
38 IR_TYPE_PD = 2, /* Pulse distance encoded IR */
39 IR_TYPE_NEC = 3,
40 IR_TYPE_OTHER = 99,
41};
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -030043struct ir_scancode {
44 u16 scancode;
45 u32 keycode;
46};
47
48struct ir_scancode_table {
49 struct ir_scancode *scan;
50 int size;
Mauro Carvalho Chehabd30a3fe2009-12-05 01:19:47 -030051 enum ir_type ir_type;
Mauro Carvalho Chehab7fee03e2009-12-02 15:56:47 -030052 spinlock_t lock;
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -030053};
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Hermann Pitton91607232006-12-07 21:45:28 -030055#define RC5_START(x) (((x)>>12)&3)
56#define RC5_TOGGLE(x) (((x)>>11)&1)
57#define RC5_ADDR(x) (((x)>>6)&31)
58#define RC5_INSTR(x) ((x)&63)
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060struct ir_input_state {
61 /* configuration */
62 int ir_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -030064 struct ir_scancode_table keytable;
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 /* key info */
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -030067 u32 ir_key; /* ir scancode */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 u32 keycode; /* linux key code */
69 int keypressed; /* current state */
70};
71
Hermann Pitton91607232006-12-07 21:45:28 -030072/* this was saa7134_ir and bttv_ir, moved here for
73 * rc5 decoding. */
74struct card_ir {
75 struct input_dev *dev;
76 struct ir_input_state ir;
77 char name[32];
78 char phys[32];
79
80 /* Usual gpio signalling */
81
82 u32 mask_keycode;
83 u32 mask_keydown;
84 u32 mask_keyup;
85 u32 polling;
86 u32 last_gpio;
87 int shift_by;
88 int start; // What should RC5_START() be
89 int addr; // What RC5_ADDR() should be.
90 int rc5_key_timeout;
91 int rc5_remote_gap;
92 struct work_struct work;
93 struct timer_list timer;
94
95 /* RC5 gpio */
96 u32 rc5_gpio;
97 struct timer_list timer_end; /* timer_end for code completion */
98 struct timer_list timer_keyup; /* timer_end for key release */
99 u32 last_rc5; /* last good rc5 code */
100 u32 last_bit; /* last raw bit seen */
101 u32 code; /* raw code under construction */
102 struct timeval base_time; /* time of last seen code */
103 int active; /* building raw code */
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300104
105 /* NEC decoding */
106 u32 nec_gpio;
107 struct tasklet_struct tlet;
Hermann Pitton91607232006-12-07 21:45:28 -0300108};
109
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300110/* Routines from ir-functions.c */
111
Mauro Carvalho Chehab055cd552009-11-29 08:19:59 -0300112int ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300113 int ir_type, struct ir_scancode_table *ir_codes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir);
115void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir,
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300116 u32 ir_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117u32 ir_extract_bits(u32 data, u32 mask);
118int ir_dump_samples(u32 *samples, int count);
119int ir_decode_biphase(u32 *samples, int count, int low, int high);
Mauro Carvalho Chehab793cf9e2005-09-09 13:03:37 -0700120int ir_decode_pulsedistance(u32 *samples, int count, int low, int high);
Andy Walls1d23a002009-09-27 20:05:23 -0300121u32 ir_rc5_decode(unsigned int code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Hermann Pitton91607232006-12-07 21:45:28 -0300123void ir_rc5_timer_end(unsigned long data);
124void ir_rc5_timer_keyup(unsigned long data);
125
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300126/* Routines from ir-keytable.c */
127
128u32 ir_g_keycode_from_table(struct input_dev *input_dev,
129 u32 scancode);
130
131int ir_set_keycode_table(struct input_dev *input_dev,
132 struct ir_scancode_table *rc_tab);
Mauro Carvalho Chehabf6fc5042009-11-29 11:08:02 -0300133
134int ir_roundup_tablesize(int n_elems);
135int ir_copy_table(struct ir_scancode_table *destin,
136 const struct ir_scancode_table *origin);
Mauro Carvalho Chehab055cd552009-11-29 08:19:59 -0300137void ir_input_free(struct input_dev *input_dev);
Mauro Carvalho Chehabef53a112009-11-27 22:01:23 -0300138
139/* scancode->keycode map tables from ir-keymaps.c */
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200140
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300141extern struct ir_scancode_table ir_codes_empty_table;
142extern struct ir_scancode_table ir_codes_avermedia_table;
143extern struct ir_scancode_table ir_codes_avermedia_dvbt_table;
144extern struct ir_scancode_table ir_codes_avermedia_m135a_table;
145extern struct ir_scancode_table ir_codes_avermedia_cardbus_table;
146extern struct ir_scancode_table ir_codes_apac_viewcomp_table;
147extern struct ir_scancode_table ir_codes_pixelview_table;
148extern struct ir_scancode_table ir_codes_pixelview_new_table;
149extern struct ir_scancode_table ir_codes_nebula_table;
150extern struct ir_scancode_table ir_codes_dntv_live_dvb_t_table;
151extern struct ir_scancode_table ir_codes_iodata_bctv7e_table;
152extern struct ir_scancode_table ir_codes_adstech_dvb_t_pci_table;
153extern struct ir_scancode_table ir_codes_msi_tvanywhere_table;
154extern struct ir_scancode_table ir_codes_cinergy_1400_table;
155extern struct ir_scancode_table ir_codes_avertv_303_table;
156extern struct ir_scancode_table ir_codes_dntv_live_dvbt_pro_table;
157extern struct ir_scancode_table ir_codes_em_terratec_table;
158extern struct ir_scancode_table ir_codes_pinnacle_grey_table;
159extern struct ir_scancode_table ir_codes_flyvideo_table;
160extern struct ir_scancode_table ir_codes_flydvb_table;
161extern struct ir_scancode_table ir_codes_cinergy_table;
162extern struct ir_scancode_table ir_codes_eztv_table;
163extern struct ir_scancode_table ir_codes_avermedia_table;
164extern struct ir_scancode_table ir_codes_videomate_tv_pvr_table;
165extern struct ir_scancode_table ir_codes_manli_table;
166extern struct ir_scancode_table ir_codes_gotview7135_table;
167extern struct ir_scancode_table ir_codes_purpletv_table;
168extern struct ir_scancode_table ir_codes_pctv_sedna_table;
169extern struct ir_scancode_table ir_codes_pv951_table;
170extern struct ir_scancode_table ir_codes_rc5_tv_table;
171extern struct ir_scancode_table ir_codes_winfast_table;
172extern struct ir_scancode_table ir_codes_pinnacle_color_table;
173extern struct ir_scancode_table ir_codes_hauppauge_new_table;
Mauro Carvalho Chehab35d19882009-11-27 23:25:13 -0300174extern struct ir_scancode_table ir_codes_rc5_hauppauge_new_table;
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300175extern struct ir_scancode_table ir_codes_npgtech_table;
176extern struct ir_scancode_table ir_codes_norwood_table;
177extern struct ir_scancode_table ir_codes_proteus_2309_table;
178extern struct ir_scancode_table ir_codes_budget_ci_old_table;
179extern struct ir_scancode_table ir_codes_asus_pc39_table;
180extern struct ir_scancode_table ir_codes_encore_enltv_table;
181extern struct ir_scancode_table ir_codes_encore_enltv2_table;
182extern struct ir_scancode_table ir_codes_tt_1500_table;
183extern struct ir_scancode_table ir_codes_fusionhdtv_mce_table;
184extern struct ir_scancode_table ir_codes_behold_table;
185extern struct ir_scancode_table ir_codes_behold_columbus_table;
186extern struct ir_scancode_table ir_codes_pinnacle_pctv_hd_table;
187extern struct ir_scancode_table ir_codes_genius_tvgo_a11mce_table;
188extern struct ir_scancode_table ir_codes_powercolor_real_angel_table;
189extern struct ir_scancode_table ir_codes_avermedia_a16d_table;
190extern struct ir_scancode_table ir_codes_encore_enltv_fm53_table;
191extern struct ir_scancode_table ir_codes_real_audio_220_32_keys_table;
192extern struct ir_scancode_table ir_codes_msi_tvanywhere_plus_table;
193extern struct ir_scancode_table ir_codes_ati_tv_wonder_hd_600_table;
194extern struct ir_scancode_table ir_codes_kworld_plus_tv_analog_table;
195extern struct ir_scancode_table ir_codes_kaiomy_table;
196extern struct ir_scancode_table ir_codes_dm1105_nec_table;
Igor M. Liplianin9d2ba7a2009-09-23 14:44:12 -0300197extern struct ir_scancode_table ir_codes_tevii_nec_table;
Igor M. Liplianind8d86222009-09-19 09:51:12 -0300198extern struct ir_scancode_table ir_codes_tbs_nec_table;
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300199extern struct ir_scancode_table ir_codes_evga_indtube_table;
200extern struct ir_scancode_table ir_codes_terratec_cinergy_xs_table;
201extern struct ir_scancode_table ir_codes_videomate_s350_table;
202extern struct ir_scancode_table ir_codes_gadmei_rm008z_table;
Mauro Carvalho Chehabcda43032009-12-05 09:34:21 -0300203extern struct ir_scancode_table ir_codes_nec_terratec_cinergy_xs_table;
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800204#endif