2 * ImgTec IR Decoder setup for Sony (SIRC) 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 Sony data to a scancode */
15 static int img_ir_sony_scancode(int len, u64 raw, u64 enabled_protocols,
16 struct img_ir_scancode_req *request)
18 unsigned int dev, subdev, func;
22 if (!(enabled_protocols & RC_PROTO_BIT_SONY12))
24 func = raw & 0x7f; /* first 7 bits */
26 dev = raw & 0x1f; /* next 5 bits */
28 request->protocol = RC_PROTO_SONY12;
31 if (!(enabled_protocols & RC_PROTO_BIT_SONY15))
33 func = raw & 0x7f; /* first 7 bits */
35 dev = raw & 0xff; /* next 8 bits */
37 request->protocol = RC_PROTO_SONY15;
40 if (!(enabled_protocols & RC_PROTO_BIT_SONY20))
42 func = raw & 0x7f; /* first 7 bits */
44 dev = raw & 0x1f; /* next 5 bits */
46 subdev = raw & 0xff; /* next 8 bits */
47 request->protocol = RC_PROTO_SONY20;
52 request->scancode = dev << 16 | subdev << 8 | func;
53 return IMG_IR_SCANCODE;
56 /* Convert NEC scancode to NEC data filter */
57 static int img_ir_sony_filter(const struct rc_scancode_filter *in,
58 struct img_ir_filter *out, u64 protocols)
60 unsigned int dev, subdev, func;
61 unsigned int dev_m, subdev_m, func_m;
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;
71 protocols &= RC_PROTO_BIT_SONY12 | RC_PROTO_BIT_SONY15 |
75 * If only one bit is set, we were requested to do an exact
76 * protocol. This should be the case for wakeup filters; for
77 * normal filters, guess the protocol from the scancode.
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;
85 protocols = RC_PROTO_BIT_SONY12;
88 if (protocols == RC_PROTO_BIT_SONY20) {
89 /* can't encode subdev and higher device bits */
90 if (dev & dev_m & 0xe0)
94 } else if (protocols == RC_PROTO_BIT_SONY15) {
99 * The hardware mask cannot distinguish high device bits and low
100 * extended bits, so logically AND those bits of the masks
103 subdev_m &= (dev_m >> 5) | 0xf8;
107 /* ensure there aren't any bits straying between fields */
111 /* write the hardware filter */
128 * See also http://www.sbprojects.com/knowledge/ir/sirc.php
129 * http://picprojects.org.uk/projects/sirc/sonysirc.pdf
131 struct img_ir_decoder img_ir_sony = {
132 .type = RC_PROTO_BIT_SONY12 | RC_PROTO_BIT_SONY15 | RC_PROTO_BIT_SONY20,
135 .code_type = IMG_IR_CODETYPE_PULSELEN,
138 .unit = 600000, /* 600 us */
142 .pulse = { 4 /* 2.4 ms */ },
143 .space = { 1 /* 600 us */ },
147 .pulse = { 1 /* 600 us */ },
148 .space = { 1 /* 600 us */ },
152 .pulse = { 2 /* 1.2 ms */ },
153 .space = { 1 /* 600 us */ },
159 .ft_min = 10, /* 6 ms */
163 .scancode = img_ir_sony_scancode,
164 .filter = img_ir_sony_filter,