^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * ImgTec IR Decoder setup for Philips RC-5 protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2012-2014 Imagination Technologies Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "img-ir-hw.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /* Convert RC5 data to a scancode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) static int img_ir_rc5_scancode(int len, u64 raw, u64 enabled_protocols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) struct img_ir_scancode_req *request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) unsigned int addr, cmd, tgl, start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /* Quirk in the decoder shifts everything by 2 to the left. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) raw >>= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) start = (raw >> 13) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) tgl = (raw >> 11) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) addr = (raw >> 6) & 0x1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) cmd = raw & 0x3f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * 12th bit is used to extend the command in extended RC5 and has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * no effect on standard RC5.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) cmd += ((raw >> 12) & 0x01) ? 0 : 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (!start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) request->protocol = RC_PROTO_RC5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) request->scancode = addr << 8 | cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) request->toggle = tgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return IMG_IR_SCANCODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* Convert RC5 scancode to RC5 data filter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int img_ir_rc5_filter(const struct rc_scancode_filter *in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct img_ir_filter *out, u64 protocols)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* Not supported by the hw. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * RC-5 decoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * see http://www.sbprojects.com/knowledge/ir/rc5.php
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct img_ir_decoder img_ir_rc5 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .type = RC_PROTO_BIT_RC5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .control = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .bitoriend2 = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .code_type = IMG_IR_CODETYPE_BIPHASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .decodend2 = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* main timings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .tolerance = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .unit = 888888, /* 1/36k*32=888.888microseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .timings = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* 10 symbol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .s10 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .pulse = { 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .space = { 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* 11 symbol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .s11 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .pulse = { 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .space = { 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* free time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) .ft = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .minlen = 14,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .maxlen = 14,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .ft_min = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* scancode logic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .scancode = img_ir_rc5_scancode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .filter = img_ir_rc5_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) };