Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /* DVB USB compliant Linux driver for the Afatech 9005
0003  * USB1.1 DVB-T receiver.
0004  *
0005  * Standard remote decode function
0006  *
0007  * Copyright (C) 2007 Luca Olivetti (luca@ventoso.org)
0008  *
0009  * Thanks to Afatech who kindly provided information.
0010  *
0011  * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
0012  */
0013 #include "af9005.h"
0014 /* debug */
0015 static int dvb_usb_af9005_remote_debug;
0016 module_param_named(debug, dvb_usb_af9005_remote_debug, int, 0644);
0017 MODULE_PARM_DESC(debug,
0018          "enable (1) or disable (0) debug messages."
0019          DVB_USB_DEBUG_STATUS);
0020 
0021 #define deb_decode(args...)   dprintk(dvb_usb_af9005_remote_debug,0x01,args)
0022 
0023 struct rc_map_table rc_map_af9005_table[] = {
0024 
0025     {0x01b7, KEY_POWER},
0026     {0x01a7, KEY_VOLUMEUP},
0027     {0x0187, KEY_CHANNELUP},
0028     {0x017f, KEY_MUTE},
0029     {0x01bf, KEY_VOLUMEDOWN},
0030     {0x013f, KEY_CHANNELDOWN},
0031     {0x01df, KEY_1},
0032     {0x015f, KEY_2},
0033     {0x019f, KEY_3},
0034     {0x011f, KEY_4},
0035     {0x01ef, KEY_5},
0036     {0x016f, KEY_6},
0037     {0x01af, KEY_7},
0038     {0x0127, KEY_8},
0039     {0x0107, KEY_9},
0040     {0x01cf, KEY_ZOOM},
0041     {0x014f, KEY_0},
0042     {0x018f, KEY_GOTO}, /* marked jump on the remote */
0043 
0044     {0x00bd, KEY_POWER},
0045     {0x007d, KEY_VOLUMEUP},
0046     {0x00fd, KEY_CHANNELUP},
0047     {0x009d, KEY_MUTE},
0048     {0x005d, KEY_VOLUMEDOWN},
0049     {0x00dd, KEY_CHANNELDOWN},
0050     {0x00ad, KEY_1},
0051     {0x006d, KEY_2},
0052     {0x00ed, KEY_3},
0053     {0x008d, KEY_4},
0054     {0x004d, KEY_5},
0055     {0x00cd, KEY_6},
0056     {0x00b5, KEY_7},
0057     {0x0075, KEY_8},
0058     {0x00f5, KEY_9},
0059     {0x0095, KEY_ZOOM},
0060     {0x0055, KEY_0},
0061     {0x00d5, KEY_GOTO}, /* marked jump on the remote */
0062 };
0063 
0064 int rc_map_af9005_table_size = ARRAY_SIZE(rc_map_af9005_table);
0065 
0066 static int repeatable_keys[] = {
0067     KEY_VOLUMEUP,
0068     KEY_VOLUMEDOWN,
0069     KEY_CHANNELUP,
0070     KEY_CHANNELDOWN
0071 };
0072 
0073 int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,
0074              int *state)
0075 {
0076     u16 mark, space;
0077     u32 result;
0078     u8 cust, dat, invdat;
0079     int i;
0080 
0081     if (len >= 6) {
0082         mark = (u16) (data[0] << 8) + data[1];
0083         space = (u16) (data[2] << 8) + data[3];
0084         if (space * 3 < mark) {
0085             for (i = 0; i < ARRAY_SIZE(repeatable_keys); i++) {
0086                 if (d->last_event == repeatable_keys[i]) {
0087                     *state = REMOTE_KEY_REPEAT;
0088                     *event = d->last_event;
0089                     deb_decode("repeat key, event %x\n",
0090                            *event);
0091                     return 0;
0092                 }
0093             }
0094             deb_decode("repeated key ignored (non repeatable)\n");
0095             return 0;
0096         } else if (len >= 33 * 4) { /*32 bits + start code */
0097             result = 0;
0098             for (i = 4; i < 4 + 32 * 4; i += 4) {
0099                 result <<= 1;
0100                 mark = (u16) (data[i] << 8) + data[i + 1];
0101                 mark >>= 1;
0102                 space = (u16) (data[i + 2] << 8) + data[i + 3];
0103                 space >>= 1;
0104                 if (mark * 2 > space)
0105                     result += 1;
0106             }
0107             deb_decode("key pressed, raw value %x\n", result);
0108             if ((result & 0xff000000) != 0xfe000000) {
0109                 deb_decode
0110                     ("doesn't start with 0xfe, ignored\n");
0111                 return 0;
0112             }
0113             cust = (result >> 16) & 0xff;
0114             dat = (result >> 8) & 0xff;
0115             invdat = (~result) & 0xff;
0116             if (dat != invdat) {
0117                 deb_decode("code != inverted code\n");
0118                 return 0;
0119             }
0120             for (i = 0; i < rc_map_af9005_table_size; i++) {
0121                 if (rc5_custom(&rc_map_af9005_table[i]) == cust
0122                     && rc5_data(&rc_map_af9005_table[i]) == dat) {
0123                     *event = rc_map_af9005_table[i].keycode;
0124                     *state = REMOTE_KEY_PRESSED;
0125                     deb_decode
0126                         ("key pressed, event %x\n", *event);
0127                     return 0;
0128                 }
0129             }
0130             deb_decode("not found in table\n");
0131         }
0132     }
0133     return 0;
0134 }
0135 
0136 EXPORT_SYMBOL(rc_map_af9005_table);
0137 EXPORT_SYMBOL(rc_map_af9005_table_size);
0138 EXPORT_SYMBOL(af9005_rc_decode);
0139 
0140 MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
0141 MODULE_DESCRIPTION
0142     ("Standard remote control decoder for Afatech 9005 DVB-T USB1.1 stick");
0143 MODULE_VERSION("1.0");
0144 MODULE_LICENSE("GPL");