2 * handle saa7134 IR remotes via linux kernel input layer.
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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/input.h>
23 #include <linux/delay.h>
24 #include <linux/interrupt.h>
25 #include <linux/input.h>
27 #include "saa7134-reg.h"
30 /* ---------------------------------------------------------------------- */
32 static IR_KEYTAB_TYPE flyvideo_codes[IR_KEYTAB_SIZE] = {
44 [ 14 ] = KEY_TUNER, // Air/Cable
45 [ 17 ] = KEY_VIDEO, // Video
46 [ 21 ] = KEY_AUDIO, // Audio
47 [ 0 ] = KEY_POWER, // Pover
48 [ 2 ] = KEY_ZOOM, // Fullscreen
49 [ 27 ] = KEY_MUTE, // Mute
50 [ 20 ] = KEY_VOLUMEUP,
51 [ 23 ] = KEY_VOLUMEDOWN,
52 [ 18 ] = KEY_CHANNELUP, // Channel +
53 [ 19 ] = KEY_CHANNELDOWN, // Channel -
54 [ 6 ] = KEY_AGAIN, // Recal
55 [ 16 ] = KEY_KPENTER, // Enter
58 [ 26 ] = KEY_F22, // Stereo
59 [ 24 ] = KEY_EDIT, // AV Source
63 static IR_KEYTAB_TYPE cinergy_codes[IR_KEYTAB_SIZE] = {
76 [ 0x0b ] = KEY_PROG1, // app
77 [ 0x0c ] = KEY_ZOOM, // zoom/fullscreen
78 [ 0x0d ] = KEY_CHANNELUP, // channel
79 [ 0x0e ] = KEY_CHANNELDOWN, // channel-
80 [ 0x0f ] = KEY_VOLUMEUP,
81 [ 0x10 ] = KEY_VOLUMEDOWN,
82 [ 0x11 ] = KEY_TUNER, // AV
83 [ 0x12 ] = KEY_NUMLOCK, // -/--
84 [ 0x13 ] = KEY_AUDIO, // audio
92 [ 0x1b ] = KEY_WWW, // text
93 [ 0x1c ] = KEY_REWIND,
94 [ 0x1d ] = KEY_FORWARD,
95 [ 0x1e ] = KEY_RECORD,
97 [ 0x20 ] = KEY_PREVIOUSSONG,
98 [ 0x21 ] = KEY_NEXTSONG,
103 /* Alfons Geser <a.geser@cox.net>
104 * updates from Job D. R. Borges <jobdrb@ig.com.br> */
105 static IR_KEYTAB_TYPE eztv_codes[IR_KEYTAB_SIZE] = {
107 [ 1 ] = KEY_TV, // DVR
108 [ 21 ] = KEY_DVD, // DVD
109 [ 23 ] = KEY_AUDIO, // music
110 // DVR mode / DVD mode / music mode
112 [ 27 ] = KEY_MUTE, // mute
113 [ 2 ] = KEY_LANGUAGE, // MTS/SAP / audio / autoseek
114 [ 30 ] = KEY_SUBTITLE, // closed captioning / subtitle / seek
115 [ 22 ] = KEY_ZOOM, // full screen
116 [ 28 ] = KEY_VIDEO, // video source / eject / delall
117 [ 29 ] = KEY_RESTART, // playback / angle / del
118 [ 47 ] = KEY_SEARCH, // scan / menu / playlist
119 [ 48 ] = KEY_CHANNEL, // CH surfing / bookmark / memo
121 [ 49 ] = KEY_HELP, // help
122 [ 50 ] = KEY_MODE, // num/memo
123 [ 51 ] = KEY_ESC, // cancel
125 [ 12 ] = KEY_UP, // up
126 [ 16 ] = KEY_DOWN, // down
127 [ 8 ] = KEY_LEFT, // left
128 [ 4 ] = KEY_RIGHT, // right
129 [ 3 ] = KEY_SELECT, // select
131 [ 31 ] = KEY_REWIND, // rewind
132 [ 32 ] = KEY_PLAYPAUSE, // play/pause
133 [ 41 ] = KEY_FORWARD, // forward
134 [ 20 ] = KEY_AGAIN, // repeat
135 [ 43 ] = KEY_RECORD, // recording
136 [ 44 ] = KEY_STOP, // stop
137 [ 45 ] = KEY_PLAY, // play
138 [ 46 ] = KEY_SHUFFLE, // snapshot / shuffle
151 [ 42 ] = KEY_VOLUMEUP,
152 [ 17 ] = KEY_VOLUMEDOWN,
153 [ 24 ] = KEY_CHANNELUP, // CH.tracking up
154 [ 25 ] = KEY_CHANNELDOWN, // CH.tracking down
156 [ 19 ] = KEY_KPENTER, // enter
157 [ 33 ] = KEY_KPDOT, // . (decimal dot)
160 /* ---------------------------------------------------------------------- */
162 static int build_key(struct saa7134_dev *dev)
164 struct saa7134_ir *ir = dev->remote;
167 /* rising SAA7134_GPIO_GPRESCAN reads the status */
168 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
169 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
171 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
173 if (ir->last_gpio == gpio)
175 ir->last_gpio = gpio;
178 data = ir_extract_bits(gpio, ir->mask_keycode);
179 printk("%s: build_key gpio=0x%x mask=0x%x data=%d\n",
180 dev->name, gpio, ir->mask_keycode, data);
182 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
183 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
184 ir_input_keydown(&ir->dev,&ir->ir,data,data);
186 ir_input_nokey(&ir->dev,&ir->ir);
191 /* ---------------------------------------------------------------------- */
193 void saa7134_input_irq(struct saa7134_dev *dev)
195 struct saa7134_ir *ir = dev->remote;
201 static void saa7134_input_timer(unsigned long data)
203 struct saa7134_dev *dev = (struct saa7134_dev*)data;
204 struct saa7134_ir *ir = dev->remote;
205 unsigned long timeout;
208 timeout = jiffies + (ir->polling * HZ / 1000);
209 mod_timer(&ir->timer, timeout);
212 int saa7134_input_init1(struct saa7134_dev *dev)
214 struct saa7134_ir *ir;
215 IR_KEYTAB_TYPE *ir_codes = NULL;
216 u32 mask_keycode = 0;
217 u32 mask_keydown = 0;
220 int ir_type = IR_TYPE_OTHER;
222 /* detect & configure */
223 if (!dev->has_remote)
225 switch (dev->board) {
226 case SAA7134_BOARD_FLYVIDEO2000:
227 case SAA7134_BOARD_FLYVIDEO3000:
228 ir_codes = flyvideo_codes;
229 mask_keycode = 0xEC00000;
230 mask_keydown = 0x0040000;
232 case SAA7134_BOARD_CINERGY400:
233 case SAA7134_BOARD_CINERGY600:
234 ir_codes = cinergy_codes;
235 mask_keycode = 0x00003f;
236 mask_keyup = 0x040000;
238 case SAA7134_BOARD_ECS_TVP3XP:
239 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
240 ir_codes = eztv_codes;
241 mask_keycode = 0x00017c;
242 mask_keyup = 0x000002;
246 if (NULL == ir_codes) {
247 printk("%s: Oops: IR config error [card=%d]\n",
248 dev->name, dev->board);
252 ir = kmalloc(sizeof(*ir),GFP_KERNEL);
255 memset(ir,0,sizeof(*ir));
257 /* init hardware-specific stuff */
258 ir->mask_keycode = mask_keycode;
259 ir->mask_keydown = mask_keydown;
260 ir->mask_keyup = mask_keyup;
261 ir->polling = polling;
263 /* init input device */
264 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
265 saa7134_boards[dev->board].name);
266 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
269 ir_input_init(&ir->dev, &ir->ir, ir_type, ir_codes);
270 ir->dev.name = ir->name;
271 ir->dev.phys = ir->phys;
272 ir->dev.id.bustype = BUS_PCI;
273 ir->dev.id.version = 1;
274 if (dev->pci->subsystem_vendor) {
275 ir->dev.id.vendor = dev->pci->subsystem_vendor;
276 ir->dev.id.product = dev->pci->subsystem_device;
278 ir->dev.id.vendor = dev->pci->vendor;
279 ir->dev.id.product = dev->pci->device;
285 init_timer(&ir->timer);
286 ir->timer.function = saa7134_input_timer;
287 ir->timer.data = (unsigned long)dev;
288 ir->timer.expires = jiffies + HZ;
289 add_timer(&ir->timer);
292 input_register_device(&dev->remote->dev);
293 printk("%s: registered input device for IR\n",dev->name);
297 void saa7134_input_fini(struct saa7134_dev *dev)
299 if (NULL == dev->remote)
302 input_unregister_device(&dev->remote->dev);
303 if (dev->remote->polling)
304 del_timer_sync(&dev->remote->timer);
309 /* ----------------------------------------------------------------------