1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ImgTec IR Decoder setup for Sony (SIRC) protocol.
5 * Copyright 2012-2014 Imagination Technologies Ltd.
10 /* Convert Sony data to a scancode */
11 static int img_ir_sony_scancode(int len, u64 raw, u64 enabled_protocols,
12 struct img_ir_scancode_req *request)
14 unsigned int dev, subdev, func;
18 if (!(enabled_protocols & RC_PROTO_BIT_SONY12))
20 func = raw & 0x7f; /* first 7 bits */
22 dev = raw & 0x1f; /* next 5 bits */
24 request->protocol = RC_PROTO_SONY12;
27 if (!(enabled_protocols & RC_PROTO_BIT_SONY15))
29 func = raw & 0x7f; /* first 7 bits */
31 dev = raw & 0xff; /* next 8 bits */
33 request->protocol = RC_PROTO_SONY15;
36 if (!(enabled_protocols & RC_PROTO_BIT_SONY20))
38 func = raw & 0x7f; /* first 7 bits */
40 dev = raw & 0x1f; /* next 5 bits */
42 subdev = raw & 0xff; /* next 8 bits */
43 request->protocol = RC_PROTO_SONY20;
48 request->scancode = dev << 16 | subdev << 8 | func;
49 return IMG_IR_SCANCODE;
52 /* Convert NEC scancode to NEC data filter */
53 static int img_ir_sony_filter(const struct rc_scancode_filter *in,
54 struct img_ir_filter *out, u64 protocols)
56 unsigned int dev, subdev, func;
57 unsigned int dev_m, subdev_m, func_m;
60 dev = (in->data >> 16) & 0xff;
61 dev_m = (in->mask >> 16) & 0xff;
62 subdev = (in->data >> 8) & 0xff;
63 subdev_m = (in->mask >> 8) & 0xff;
64 func = (in->data >> 0) & 0x7f;
65 func_m = (in->mask >> 0) & 0x7f;
67 protocols &= RC_PROTO_BIT_SONY12 | RC_PROTO_BIT_SONY15 |
71 * If only one bit is set, we were requested to do an exact
72 * protocol. This should be the case for wakeup filters; for
73 * normal filters, guess the protocol from the scancode.
75 if (!is_power_of_2(protocols)) {
76 if (subdev & subdev_m)
77 protocols = RC_PROTO_BIT_SONY20;
78 else if (dev & dev_m & 0xe0)
79 protocols = RC_PROTO_BIT_SONY15;
81 protocols = RC_PROTO_BIT_SONY12;
84 if (protocols == RC_PROTO_BIT_SONY20) {
85 /* can't encode subdev and higher device bits */
86 if (dev & dev_m & 0xe0)
90 } else if (protocols == RC_PROTO_BIT_SONY15) {
95 * The hardware mask cannot distinguish high device bits and low
96 * extended bits, so logically AND those bits of the masks
99 subdev_m &= (dev_m >> 5) | 0xf8;
103 /* ensure there aren't any bits straying between fields */
107 /* write the hardware filter */
124 * See also http://www.sbprojects.com/knowledge/ir/sirc.php
125 * http://picprojects.org.uk/projects/sirc/sonysirc.pdf
127 struct img_ir_decoder img_ir_sony = {
128 .type = RC_PROTO_BIT_SONY12 | RC_PROTO_BIT_SONY15 | RC_PROTO_BIT_SONY20,
131 .code_type = IMG_IR_CODETYPE_PULSELEN,
134 .unit = 600000, /* 600 us */
138 .pulse = { 4 /* 2.4 ms */ },
139 .space = { 1 /* 600 us */ },
143 .pulse = { 1 /* 600 us */ },
144 .space = { 1 /* 600 us */ },
148 .pulse = { 2 /* 1.2 ms */ },
149 .space = { 1 /* 600 us */ },
155 .ft_min = 10, /* 6 ms */
159 .scancode = img_ir_sony_scancode,
160 .filter = img_ir_sony_filter,