1
2
3
4
5
6
7
8
9
10
11
12#include "img-ir-hw.h"
13
14
15static int img_ir_sony_scancode(int len, u64 raw, u64 enabled_protocols,
16 struct img_ir_scancode_req *request)
17{
18 unsigned int dev, subdev, func;
19
20 switch (len) {
21 case 12:
22 if (!(enabled_protocols & RC_PROTO_BIT_SONY12))
23 return -EINVAL;
24 func = raw & 0x7f;
25 raw >>= 7;
26 dev = raw & 0x1f;
27 subdev = 0;
28 request->protocol = RC_PROTO_SONY12;
29 break;
30 case 15:
31 if (!(enabled_protocols & RC_PROTO_BIT_SONY15))
32 return -EINVAL;
33 func = raw & 0x7f;
34 raw >>= 7;
35 dev = raw & 0xff;
36 subdev = 0;
37 request->protocol = RC_PROTO_SONY15;
38 break;
39 case 20:
40 if (!(enabled_protocols & RC_PROTO_BIT_SONY20))
41 return -EINVAL;
42 func = raw & 0x7f;
43 raw >>= 7;
44 dev = raw & 0x1f;
45 raw >>= 5;
46 subdev = raw & 0xff;
47 request->protocol = RC_PROTO_SONY20;
48 break;
49 default:
50 return -EINVAL;
51 }
52 request->scancode = dev << 16 | subdev << 8 | func;
53 return IMG_IR_SCANCODE;
54}
55
56
57static int img_ir_sony_filter(const struct rc_scancode_filter *in,
58 struct img_ir_filter *out, u64 protocols)
59{
60 unsigned int dev, subdev, func;
61 unsigned int dev_m, subdev_m, func_m;
62 unsigned int len = 0;
63
64 dev = (in->data >> 16) & 0xff;
65 dev_m = (in->mask >> 16) & 0xff;
66 subdev = (in->data >> 8) & 0xff;
67 subdev_m = (in->mask >> 8) & 0xff;
68 func = (in->data >> 0) & 0x7f;
69 func_m = (in->mask >> 0) & 0x7f;
70
71 protocols &= RC_PROTO_BIT_SONY12 | RC_PROTO_BIT_SONY15 |
72 RC_PROTO_BIT_SONY20;
73
74
75
76
77
78
79 if (!is_power_of_2(protocols)) {
80 if (subdev & subdev_m)
81 protocols = RC_PROTO_BIT_SONY20;
82 else if (dev & dev_m & 0xe0)
83 protocols = RC_PROTO_BIT_SONY15;
84 else
85 protocols = RC_PROTO_BIT_SONY12;
86 }
87
88 if (protocols == RC_PROTO_BIT_SONY20) {
89
90 if (dev & dev_m & 0xe0)
91 return -EINVAL;
92 len = 20;
93 dev_m &= 0x1f;
94 } else if (protocols == RC_PROTO_BIT_SONY15) {
95 len = 15;
96 subdev_m = 0;
97 } else {
98
99
100
101
102
103 subdev_m &= (dev_m >> 5) | 0xf8;
104 dev_m &= 0x1f;
105 }
106
107
108 dev &= dev_m;
109 subdev &= subdev_m;
110
111
112 out->data = func |
113 dev << 7 |
114 subdev << 15;
115 out->mask = func_m |
116 dev_m << 7 |
117 subdev_m << 15;
118
119 if (len) {
120 out->minlen = len;
121 out->maxlen = len;
122 }
123 return 0;
124}
125
126
127
128
129
130
131struct img_ir_decoder img_ir_sony = {
132 .type = RC_PROTO_BIT_SONY12 | RC_PROTO_BIT_SONY15 | RC_PROTO_BIT_SONY20,
133 .control = {
134 .decoden = 1,
135 .code_type = IMG_IR_CODETYPE_PULSELEN,
136 },
137
138 .unit = 600000,
139 .timings = {
140
141 .ldr = {
142 .pulse = { 4 },
143 .space = { 1 },
144 },
145
146 .s00 = {
147 .pulse = { 1 },
148 .space = { 1 },
149 },
150
151 .s01 = {
152 .pulse = { 2 },
153 .space = { 1 },
154 },
155
156 .ft = {
157 .minlen = 12,
158 .maxlen = 20,
159 .ft_min = 10,
160 },
161 },
162
163 .scancode = img_ir_sony_scancode,
164 .filter = img_ir_sony_filter,
165};
166