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/delay.h>
23 #include <linux/interrupt.h>
24 #include <linux/input.h>
26 #include "saa7134-reg.h"
29 /* ---------------------------------------------------------------------- */
31 static IR_KEYTAB_TYPE flyvideo_codes[IR_KEYTAB_SIZE] = {
43 [ 14 ] = KEY_TUNER, // Air/Cable
44 [ 17 ] = KEY_VIDEO, // Video
45 [ 21 ] = KEY_AUDIO, // Audio
46 [ 0 ] = KEY_POWER, // Pover
47 [ 2 ] = KEY_ZOOM, // Fullscreen
48 [ 27 ] = KEY_MUTE, // Mute
49 [ 20 ] = KEY_VOLUMEUP,
50 [ 23 ] = KEY_VOLUMEDOWN,
51 [ 18 ] = KEY_CHANNELUP, // Channel +
52 [ 19 ] = KEY_CHANNELDOWN, // Channel -
53 [ 6 ] = KEY_AGAIN, // Recal
54 [ 16 ] = KEY_KPENTER, // Enter
57 [ 26 ] = KEY_F22, // Stereo
58 [ 24 ] = KEY_EDIT, // AV Source
62 static IR_KEYTAB_TYPE cinergy_codes[IR_KEYTAB_SIZE] = {
75 [ 0x0b ] = KEY_PROG1, // app
76 [ 0x0c ] = KEY_ZOOM, // zoom/fullscreen
77 [ 0x0d ] = KEY_CHANNELUP, // channel
78 [ 0x0e ] = KEY_CHANNELDOWN, // channel-
79 [ 0x0f ] = KEY_VOLUMEUP,
80 [ 0x10 ] = KEY_VOLUMEDOWN,
81 [ 0x11 ] = KEY_TUNER, // AV
82 [ 0x12 ] = KEY_NUMLOCK, // -/--
83 [ 0x13 ] = KEY_AUDIO, // audio
91 [ 0x1b ] = KEY_WWW, // text
92 [ 0x1c ] = KEY_REWIND,
93 [ 0x1d ] = KEY_FORWARD,
94 [ 0x1e ] = KEY_RECORD,
96 [ 0x20 ] = KEY_PREVIOUSSONG,
97 [ 0x21 ] = KEY_NEXTSONG,
102 /* Alfons Geser <a.geser@cox.net>
103 * updates from Job D. R. Borges <jobdrb@ig.com.br> */
104 static IR_KEYTAB_TYPE eztv_codes[IR_KEYTAB_SIZE] = {
106 [ 1 ] = KEY_TV, // DVR
107 [ 21 ] = KEY_DVD, // DVD
108 [ 23 ] = KEY_AUDIO, // music
109 // DVR mode / DVD mode / music mode
111 [ 27 ] = KEY_MUTE, // mute
112 [ 2 ] = KEY_LANGUAGE, // MTS/SAP / audio / autoseek
113 [ 30 ] = KEY_SUBTITLE, // closed captioning / subtitle / seek
114 [ 22 ] = KEY_ZOOM, // full screen
115 [ 28 ] = KEY_VIDEO, // video source / eject / delall
116 [ 29 ] = KEY_RESTART, // playback / angle / del
117 [ 47 ] = KEY_SEARCH, // scan / menu / playlist
118 [ 48 ] = KEY_CHANNEL, // CH surfing / bookmark / memo
120 [ 49 ] = KEY_HELP, // help
121 [ 50 ] = KEY_MODE, // num/memo
122 [ 51 ] = KEY_ESC, // cancel
124 [ 12 ] = KEY_UP, // up
125 [ 16 ] = KEY_DOWN, // down
126 [ 8 ] = KEY_LEFT, // left
127 [ 4 ] = KEY_RIGHT, // right
128 [ 3 ] = KEY_SELECT, // select
130 [ 31 ] = KEY_REWIND, // rewind
131 [ 32 ] = KEY_PLAYPAUSE, // play/pause
132 [ 41 ] = KEY_FORWARD, // forward
133 [ 20 ] = KEY_AGAIN, // repeat
134 [ 43 ] = KEY_RECORD, // recording
135 [ 44 ] = KEY_STOP, // stop
136 [ 45 ] = KEY_PLAY, // play
137 [ 46 ] = KEY_SHUFFLE, // snapshot / shuffle
150 [ 42 ] = KEY_VOLUMEUP,
151 [ 17 ] = KEY_VOLUMEDOWN,
152 [ 24 ] = KEY_CHANNELUP, // CH.tracking up
153 [ 25 ] = KEY_CHANNELDOWN, // CH.tracking down
155 [ 19 ] = KEY_KPENTER, // enter
156 [ 33 ] = KEY_KPDOT, // . (decimal dot)
159 /* ---------------------------------------------------------------------- */
161 static int build_key(struct saa7134_dev *dev)
163 struct saa7134_ir *ir = dev->remote;
166 /* rising SAA7134_GPIO_GPRESCAN reads the status */
167 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
168 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
170 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
172 if (ir->last_gpio == gpio)
174 ir->last_gpio = gpio;
177 data = ir_extract_bits(gpio, ir->mask_keycode);
178 printk("%s: build_key gpio=0x%x mask=0x%x data=%d\n",
179 dev->name, gpio, ir->mask_keycode, data);
181 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
182 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
183 ir_input_keydown(&ir->dev,&ir->ir,data,data);
185 ir_input_nokey(&ir->dev,&ir->ir);
190 /* ---------------------------------------------------------------------- */
192 void saa7134_input_irq(struct saa7134_dev *dev)
194 struct saa7134_ir *ir = dev->remote;
200 static void saa7134_input_timer(unsigned long data)
202 struct saa7134_dev *dev = (struct saa7134_dev*)data;
203 struct saa7134_ir *ir = dev->remote;
204 unsigned long timeout;
207 timeout = jiffies + (ir->polling * HZ / 1000);
208 mod_timer(&ir->timer, timeout);
211 int saa7134_input_init1(struct saa7134_dev *dev)
213 struct saa7134_ir *ir;
214 IR_KEYTAB_TYPE *ir_codes = NULL;
215 u32 mask_keycode = 0;
216 u32 mask_keydown = 0;
219 int ir_type = IR_TYPE_OTHER;
221 /* detect & configure */
222 if (!dev->has_remote)
224 switch (dev->board) {
225 case SAA7134_BOARD_FLYVIDEO2000:
226 case SAA7134_BOARD_FLYVIDEO3000:
227 ir_codes = flyvideo_codes;
228 mask_keycode = 0xEC00000;
229 mask_keydown = 0x0040000;
231 case SAA7134_BOARD_CINERGY400:
232 case SAA7134_BOARD_CINERGY600:
233 ir_codes = cinergy_codes;
234 mask_keycode = 0x00003f;
235 mask_keyup = 0x040000;
237 case SAA7134_BOARD_ECS_TVP3XP:
238 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
239 ir_codes = eztv_codes;
240 mask_keycode = 0x00017c;
241 mask_keyup = 0x000002;
245 if (NULL == ir_codes) {
246 printk("%s: Oops: IR config error [card=%d]\n",
247 dev->name, dev->board);
251 ir = kmalloc(sizeof(*ir),GFP_KERNEL);
254 memset(ir,0,sizeof(*ir));
256 /* init hardware-specific stuff */
257 ir->mask_keycode = mask_keycode;
258 ir->mask_keydown = mask_keydown;
259 ir->mask_keyup = mask_keyup;
260 ir->polling = polling;
262 /* init input device */
263 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
264 saa7134_boards[dev->board].name);
265 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
268 ir_input_init(&ir->dev, &ir->ir, ir_type, ir_codes);
269 ir->dev.name = ir->name;
270 ir->dev.phys = ir->phys;
271 ir->dev.id.bustype = BUS_PCI;
272 ir->dev.id.version = 1;
273 if (dev->pci->subsystem_vendor) {
274 ir->dev.id.vendor = dev->pci->subsystem_vendor;
275 ir->dev.id.product = dev->pci->subsystem_device;
277 ir->dev.id.vendor = dev->pci->vendor;
278 ir->dev.id.product = dev->pci->device;
284 init_timer(&ir->timer);
285 ir->timer.function = saa7134_input_timer;
286 ir->timer.data = (unsigned long)dev;
287 ir->timer.expires = jiffies + HZ;
288 add_timer(&ir->timer);
291 input_register_device(&dev->remote->dev);
292 printk("%s: registered input device for IR\n",dev->name);
296 void saa7134_input_fini(struct saa7134_dev *dev)
298 if (NULL == dev->remote)
301 input_unregister_device(&dev->remote->dev);
302 if (dev->remote->polling)
303 del_timer_sync(&dev->remote->timer);
308 /* ----------------------------------------------------------------------