WIP FPC-III support
[linux/fpc-iii.git] / drivers / media / rc / img-ir / img-ir-rc6.c
blobb2bf46886420422d0a151685b2b7ee48779d1844
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * ImgTec IR Decoder setup for Philips RC-6 protocol.
5 * Copyright 2012-2014 Imagination Technologies Ltd.
6 */
8 #include "img-ir-hw.h"
10 /* Convert RC6 data to a scancode */
11 static int img_ir_rc6_scancode(int len, u64 raw, u64 enabled_protocols,
12 struct img_ir_scancode_req *request)
14 unsigned int addr, cmd, mode, trl1, trl2;
17 * Due to a side effect of the decoder handling the double length
18 * Trailer bit, the header information is a bit scrambled, and the
19 * raw data is shifted incorrectly.
20 * This workaround effectively recovers the header bits.
22 * The Header field should look like this:
24 * StartBit ModeBit2 ModeBit1 ModeBit0 TrailerBit
26 * But what we get is:
28 * ModeBit2 ModeBit1 ModeBit0 TrailerBit1 TrailerBit2
30 * The start bit is not important to recover the scancode.
33 raw >>= 27;
35 trl1 = (raw >> 17) & 0x01;
36 trl2 = (raw >> 16) & 0x01;
38 mode = (raw >> 18) & 0x07;
39 addr = (raw >> 8) & 0xff;
40 cmd = raw & 0xff;
43 * Due to the above explained irregularity the trailer bits cannot
44 * have the same value.
46 if (trl1 == trl2)
47 return -EINVAL;
49 /* Only mode 0 supported for now */
50 if (mode)
51 return -EINVAL;
53 request->protocol = RC_PROTO_RC6_0;
54 request->scancode = addr << 8 | cmd;
55 request->toggle = trl2;
56 return IMG_IR_SCANCODE;
59 /* Convert RC6 scancode to RC6 data filter */
60 static int img_ir_rc6_filter(const struct rc_scancode_filter *in,
61 struct img_ir_filter *out, u64 protocols)
63 /* Not supported by the hw. */
64 return -EINVAL;
68 * RC-6 decoder
69 * see http://www.sbprojects.com/knowledge/ir/rc6.php
71 struct img_ir_decoder img_ir_rc6 = {
72 .type = RC_PROTO_BIT_RC6_0,
73 .control = {
74 .bitorien = 1,
75 .code_type = IMG_IR_CODETYPE_BIPHASE,
76 .decoden = 1,
77 .decodinpol = 1,
79 /* main timings */
80 .tolerance = 20,
82 * Due to a quirk in the img-ir decoder, default header values do
83 * not work, the values described below were extracted from
84 * successful RTL test cases.
86 .timings = {
87 /* leader symbol */
88 .ldr = {
89 .pulse = { 650 },
90 .space = { 660 },
92 /* 0 symbol */
93 .s00 = {
94 .pulse = { 370 },
95 .space = { 370 },
97 /* 01 symbol */
98 .s01 = {
99 .pulse = { 370 },
100 .space = { 370 },
102 /* free time */
103 .ft = {
104 .minlen = 21,
105 .maxlen = 21,
106 .ft_min = 2666, /* 2.666 ms */
110 /* scancode logic */
111 .scancode = img_ir_rc6_scancode,
112 .filter = img_ir_rc6_filter,