1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* DVB USB compliant Linux driver for the Afatech 9005
3 * USB1.1 DVB-T receiver.
5 * Standard remote decode function
7 * Copyright (C) 2007 Luca Olivetti (luca@ventoso.org)
9 * Thanks to Afatech who kindly provided information.
11 * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
15 static int dvb_usb_af9005_remote_debug
;
16 module_param_named(debug
, dvb_usb_af9005_remote_debug
, int, 0644);
17 MODULE_PARM_DESC(debug
,
18 "enable (1) or disable (0) debug messages."
19 DVB_USB_DEBUG_STATUS
);
21 #define deb_decode(args...) dprintk(dvb_usb_af9005_remote_debug,0x01,args)
23 struct rc_map_table rc_map_af9005_table
[] = {
26 {0x01a7, KEY_VOLUMEUP
},
27 {0x0187, KEY_CHANNELUP
},
29 {0x01bf, KEY_VOLUMEDOWN
},
30 {0x013f, KEY_CHANNELDOWN
},
42 {0x018f, KEY_GOTO
}, /* marked jump on the remote */
45 {0x007d, KEY_VOLUMEUP
},
46 {0x00fd, KEY_CHANNELUP
},
48 {0x005d, KEY_VOLUMEDOWN
},
49 {0x00dd, KEY_CHANNELDOWN
},
61 {0x00d5, KEY_GOTO
}, /* marked jump on the remote */
64 int rc_map_af9005_table_size
= ARRAY_SIZE(rc_map_af9005_table
);
66 static int repeatable_keys
[] = {
73 int af9005_rc_decode(struct dvb_usb_device
*d
, u8
* data
, int len
, u32
* event
,
82 mark
= (u16
) (data
[0] << 8) + data
[1];
83 space
= (u16
) (data
[2] << 8) + data
[3];
84 if (space
* 3 < mark
) {
85 for (i
= 0; i
< ARRAY_SIZE(repeatable_keys
); i
++) {
86 if (d
->last_event
== repeatable_keys
[i
]) {
87 *state
= REMOTE_KEY_REPEAT
;
88 *event
= d
->last_event
;
89 deb_decode("repeat key, event %x\n",
94 deb_decode("repeated key ignored (non repeatable)\n");
96 } else if (len
>= 33 * 4) { /*32 bits + start code */
98 for (i
= 4; i
< 4 + 32 * 4; i
+= 4) {
100 mark
= (u16
) (data
[i
] << 8) + data
[i
+ 1];
102 space
= (u16
) (data
[i
+ 2] << 8) + data
[i
+ 3];
104 if (mark
* 2 > space
)
107 deb_decode("key pressed, raw value %x\n", result
);
108 if ((result
& 0xff000000) != 0xfe000000) {
110 ("doesn't start with 0xfe, ignored\n");
113 cust
= (result
>> 16) & 0xff;
114 dat
= (result
>> 8) & 0xff;
115 invdat
= (~result
) & 0xff;
117 deb_decode("code != inverted code\n");
120 for (i
= 0; i
< rc_map_af9005_table_size
; i
++) {
121 if (rc5_custom(&rc_map_af9005_table
[i
]) == cust
122 && rc5_data(&rc_map_af9005_table
[i
]) == dat
) {
123 *event
= rc_map_af9005_table
[i
].keycode
;
124 *state
= REMOTE_KEY_PRESSED
;
126 ("key pressed, event %x\n", *event
);
130 deb_decode("not found in table\n");
136 EXPORT_SYMBOL(rc_map_af9005_table
);
137 EXPORT_SYMBOL(rc_map_af9005_table_size
);
138 EXPORT_SYMBOL(af9005_rc_decode
);
140 MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
142 ("Standard remote control decoder for Afatech 9005 DVB-T USB1.1 stick");
143 MODULE_VERSION("1.0");
144 MODULE_LICENSE("GPL");