sched: Remove double_rq_lock() from __migrate_task()
[linux/fpc-iii.git] / drivers / media / rc / img-ir / img-ir-nec.c
blob751d9d94526931bb78b210eb1e5f18146c6aa789
1 /*
2 * ImgTec IR Decoder setup for NEC protocol.
4 * Copyright 2010-2014 Imagination Technologies Ltd.
5 */
7 #include "img-ir-hw.h"
8 #include <linux/bitrev.h>
10 /* Convert NEC data to a scancode */
11 static int img_ir_nec_scancode(int len, u64 raw, int *scancode, u64 protocols)
13 unsigned int addr, addr_inv, data, data_inv;
14 /* a repeat code has no data */
15 if (!len)
16 return IMG_IR_REPEATCODE;
17 if (len != 32)
18 return -EINVAL;
19 /* raw encoding: ddDDaaAA */
20 addr = (raw >> 0) & 0xff;
21 addr_inv = (raw >> 8) & 0xff;
22 data = (raw >> 16) & 0xff;
23 data_inv = (raw >> 24) & 0xff;
24 if ((data_inv ^ data) != 0xff) {
25 /* 32-bit NEC (used by Apple and TiVo remotes) */
26 /* scan encoding: as transmitted, MSBit = first received bit */
27 *scancode = bitrev8(addr) << 24 |
28 bitrev8(addr_inv) << 16 |
29 bitrev8(data) << 8 |
30 bitrev8(data_inv);
31 } else if ((addr_inv ^ addr) != 0xff) {
32 /* Extended NEC */
33 /* scan encoding: AAaaDD */
34 *scancode = addr << 16 |
35 addr_inv << 8 |
36 data;
37 } else {
38 /* Normal NEC */
39 /* scan encoding: AADD */
40 *scancode = addr << 8 |
41 data;
43 return IMG_IR_SCANCODE;
46 /* Convert NEC scancode to NEC data filter */
47 static int img_ir_nec_filter(const struct rc_scancode_filter *in,
48 struct img_ir_filter *out, u64 protocols)
50 unsigned int addr, addr_inv, data, data_inv;
51 unsigned int addr_m, addr_inv_m, data_m, data_inv_m;
53 data = in->data & 0xff;
54 data_m = in->mask & 0xff;
56 if ((in->data | in->mask) & 0xff000000) {
57 /* 32-bit NEC (used by Apple and TiVo remotes) */
58 /* scan encoding: as transmitted, MSBit = first received bit */
59 addr = bitrev8(in->data >> 24);
60 addr_m = bitrev8(in->mask >> 24);
61 addr_inv = bitrev8(in->data >> 16);
62 addr_inv_m = bitrev8(in->mask >> 16);
63 data = bitrev8(in->data >> 8);
64 data_m = bitrev8(in->mask >> 8);
65 data_inv = bitrev8(in->data >> 0);
66 data_inv_m = bitrev8(in->mask >> 0);
67 } else if ((in->data | in->mask) & 0x00ff0000) {
68 /* Extended NEC */
69 /* scan encoding AAaaDD */
70 addr = (in->data >> 16) & 0xff;
71 addr_m = (in->mask >> 16) & 0xff;
72 addr_inv = (in->data >> 8) & 0xff;
73 addr_inv_m = (in->mask >> 8) & 0xff;
74 data_inv = data ^ 0xff;
75 data_inv_m = data_m;
76 } else {
77 /* Normal NEC */
78 /* scan encoding: AADD */
79 addr = (in->data >> 8) & 0xff;
80 addr_m = (in->mask >> 8) & 0xff;
81 addr_inv = addr ^ 0xff;
82 addr_inv_m = addr_m;
83 data_inv = data ^ 0xff;
84 data_inv_m = data_m;
87 /* raw encoding: ddDDaaAA */
88 out->data = data_inv << 24 |
89 data << 16 |
90 addr_inv << 8 |
91 addr;
92 out->mask = data_inv_m << 24 |
93 data_m << 16 |
94 addr_inv_m << 8 |
95 addr_m;
96 return 0;
100 * NEC decoder
101 * See also http://www.sbprojects.com/knowledge/ir/nec.php
102 * http://wiki.altium.com/display/ADOH/NEC+Infrared+Transmission+Protocol
104 struct img_ir_decoder img_ir_nec = {
105 .type = RC_BIT_NEC,
106 .control = {
107 .decoden = 1,
108 .code_type = IMG_IR_CODETYPE_PULSEDIST,
110 /* main timings */
111 .unit = 562500, /* 562.5 us */
112 .timings = {
113 /* leader symbol */
114 .ldr = {
115 .pulse = { 16 /* 9ms */ },
116 .space = { 8 /* 4.5ms */ },
118 /* 0 symbol */
119 .s00 = {
120 .pulse = { 1 /* 562.5 us */ },
121 .space = { 1 /* 562.5 us */ },
123 /* 1 symbol */
124 .s01 = {
125 .pulse = { 1 /* 562.5 us */ },
126 .space = { 3 /* 1687.5 us */ },
128 /* free time */
129 .ft = {
130 .minlen = 32,
131 .maxlen = 32,
132 .ft_min = 10, /* 5.625 ms */
135 /* repeat codes */
136 .repeat = 108, /* 108 ms */
137 .rtimings = {
138 /* leader symbol */
139 .ldr = {
140 .space = { 4 /* 2.25 ms */ },
142 /* free time */
143 .ft = {
144 .minlen = 0, /* repeat code has no data */
145 .maxlen = 0,
148 /* scancode logic */
149 .scancode = img_ir_nec_scancode,
150 .filter = img_ir_nec_filter,