Path: blob/master/drivers/media/dvb/dvb-usb/af9005-remote.c
15112 views
/* DVB USB compliant Linux driver for the Afatech 90051* USB1.1 DVB-T receiver.2*3* Standard remote decode function4*5* Copyright (C) 2007 Luca Olivetti ([email protected])6*7* Thanks to Afatech who kindly provided information.8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.22*23* see Documentation/dvb/REDME.dvb-usb for more information24*/25#include "af9005.h"26/* debug */27static int dvb_usb_af9005_remote_debug;28module_param_named(debug, dvb_usb_af9005_remote_debug, int, 0644);29MODULE_PARM_DESC(debug,30"enable (1) or disable (0) debug messages."31DVB_USB_DEBUG_STATUS);3233#define deb_decode(args...) dprintk(dvb_usb_af9005_remote_debug,0x01,args)3435struct rc_map_table rc_map_af9005_table[] = {3637{0x01b7, KEY_POWER},38{0x01a7, KEY_VOLUMEUP},39{0x0187, KEY_CHANNELUP},40{0x017f, KEY_MUTE},41{0x01bf, KEY_VOLUMEDOWN},42{0x013f, KEY_CHANNELDOWN},43{0x01df, KEY_1},44{0x015f, KEY_2},45{0x019f, KEY_3},46{0x011f, KEY_4},47{0x01ef, KEY_5},48{0x016f, KEY_6},49{0x01af, KEY_7},50{0x0127, KEY_8},51{0x0107, KEY_9},52{0x01cf, KEY_ZOOM},53{0x014f, KEY_0},54{0x018f, KEY_GOTO}, /* marked jump on the remote */5556{0x00bd, KEY_POWER},57{0x007d, KEY_VOLUMEUP},58{0x00fd, KEY_CHANNELUP},59{0x009d, KEY_MUTE},60{0x005d, KEY_VOLUMEDOWN},61{0x00dd, KEY_CHANNELDOWN},62{0x00ad, KEY_1},63{0x006d, KEY_2},64{0x00ed, KEY_3},65{0x008d, KEY_4},66{0x004d, KEY_5},67{0x00cd, KEY_6},68{0x00b5, KEY_7},69{0x0075, KEY_8},70{0x00f5, KEY_9},71{0x0095, KEY_ZOOM},72{0x0055, KEY_0},73{0x00d5, KEY_GOTO}, /* marked jump on the remote */74};7576int rc_map_af9005_table_size = ARRAY_SIZE(rc_map_af9005_table);7778static int repeatable_keys[] = {79KEY_VOLUMEUP,80KEY_VOLUMEDOWN,81KEY_CHANNELUP,82KEY_CHANNELDOWN83};8485int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,86int *state)87{88u16 mark, space;89u32 result;90u8 cust, dat, invdat;91int i;9293if (len >= 6) {94mark = (u16) (data[0] << 8) + data[1];95space = (u16) (data[2] << 8) + data[3];96if (space * 3 < mark) {97for (i = 0; i < ARRAY_SIZE(repeatable_keys); i++) {98if (d->last_event == repeatable_keys[i]) {99*state = REMOTE_KEY_REPEAT;100*event = d->last_event;101deb_decode("repeat key, event %x\n",102*event);103return 0;104}105}106deb_decode("repeated key ignored (non repeatable)\n");107return 0;108} else if (len >= 33 * 4) { /*32 bits + start code */109result = 0;110for (i = 4; i < 4 + 32 * 4; i += 4) {111result <<= 1;112mark = (u16) (data[i] << 8) + data[i + 1];113mark >>= 1;114space = (u16) (data[i + 2] << 8) + data[i + 3];115space >>= 1;116if (mark * 2 > space)117result += 1;118}119deb_decode("key pressed, raw value %x\n", result);120if ((result & 0xff000000) != 0xfe000000) {121deb_decode122("doesn't start with 0xfe, ignored\n");123return 0;124}125cust = (result >> 16) & 0xff;126dat = (result >> 8) & 0xff;127invdat = (~result) & 0xff;128if (dat != invdat) {129deb_decode("code != inverted code\n");130return 0;131}132for (i = 0; i < rc_map_af9005_table_size; i++) {133if (rc5_custom(&rc_map_af9005_table[i]) == cust134&& rc5_data(&rc_map_af9005_table[i]) == dat) {135*event = rc_map_af9005_table[i].keycode;136*state = REMOTE_KEY_PRESSED;137deb_decode138("key pressed, event %x\n", *event);139return 0;140}141}142deb_decode("not found in table\n");143}144}145return 0;146}147148EXPORT_SYMBOL(rc_map_af9005_table);149EXPORT_SYMBOL(rc_map_af9005_table_size);150EXPORT_SYMBOL(af9005_rc_decode);151152MODULE_AUTHOR("Luca Olivetti <[email protected]>");153MODULE_DESCRIPTION154("Standard remote control decoder for Afatech 9005 DVB-T USB1.1 stick");155MODULE_VERSION("1.0");156MODULE_LICENSE("GPL");157158159