Linux 4.19.133
[linux/fpc-iii.git] / drivers / media / rc / img-ir / img-ir-rc6.c
blob5f34f59ca2573e27c7153fd6df2a9e3d24cde103
1 /*
2 * ImgTec IR Decoder setup for Philips RC-6 protocol.
4 * Copyright 2012-2014 Imagination Technologies Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
12 #include "img-ir-hw.h"
14 /* Convert RC6 data to a scancode */
15 static int img_ir_rc6_scancode(int len, u64 raw, u64 enabled_protocols,
16 struct img_ir_scancode_req *request)
18 unsigned int addr, cmd, mode, trl1, trl2;
21 * Due to a side effect of the decoder handling the double length
22 * Trailer bit, the header information is a bit scrambled, and the
23 * raw data is shifted incorrectly.
24 * This workaround effectively recovers the header bits.
26 * The Header field should look like this:
28 * StartBit ModeBit2 ModeBit1 ModeBit0 TrailerBit
30 * But what we get is:
32 * ModeBit2 ModeBit1 ModeBit0 TrailerBit1 TrailerBit2
34 * The start bit is not important to recover the scancode.
37 raw >>= 27;
39 trl1 = (raw >> 17) & 0x01;
40 trl2 = (raw >> 16) & 0x01;
42 mode = (raw >> 18) & 0x07;
43 addr = (raw >> 8) & 0xff;
44 cmd = raw & 0xff;
47 * Due to the above explained irregularity the trailer bits cannot
48 * have the same value.
50 if (trl1 == trl2)
51 return -EINVAL;
53 /* Only mode 0 supported for now */
54 if (mode)
55 return -EINVAL;
57 request->protocol = RC_PROTO_RC6_0;
58 request->scancode = addr << 8 | cmd;
59 request->toggle = trl2;
60 return IMG_IR_SCANCODE;
63 /* Convert RC6 scancode to RC6 data filter */
64 static int img_ir_rc6_filter(const struct rc_scancode_filter *in,
65 struct img_ir_filter *out, u64 protocols)
67 /* Not supported by the hw. */
68 return -EINVAL;
72 * RC-6 decoder
73 * see http://www.sbprojects.com/knowledge/ir/rc6.php
75 struct img_ir_decoder img_ir_rc6 = {
76 .type = RC_PROTO_BIT_RC6_0,
77 .control = {
78 .bitorien = 1,
79 .code_type = IMG_IR_CODETYPE_BIPHASE,
80 .decoden = 1,
81 .decodinpol = 1,
83 /* main timings */
84 .tolerance = 20,
86 * Due to a quirk in the img-ir decoder, default header values do
87 * not work, the values described below were extracted from
88 * successful RTL test cases.
90 .timings = {
91 /* leader symbol */
92 .ldr = {
93 .pulse = { 650 },
94 .space = { 660 },
96 /* 0 symbol */
97 .s00 = {
98 .pulse = { 370 },
99 .space = { 370 },
101 /* 01 symbol */
102 .s01 = {
103 .pulse = { 370 },
104 .space = { 370 },
106 /* free time */
107 .ft = {
108 .minlen = 21,
109 .maxlen = 21,
110 .ft_min = 2666, /* 2.666 ms */
114 /* scancode logic */
115 .scancode = img_ir_rc6_scancode,
116 .filter = img_ir_rc6_filter,