2 * ImgTec IR Decoder setup for Sony (SIRC) protocol.
4 * Copyright 2012-2014 Imagination Technologies Ltd.
9 /* Convert Sony data to a scancode */
10 static int img_ir_sony_scancode(int len
, u64 raw
, int *scancode
, u64 protocols
)
12 unsigned int dev
, subdev
, func
;
16 if (!(protocols
& RC_BIT_SONY12
))
18 func
= raw
& 0x7f; /* first 7 bits */
20 dev
= raw
& 0x1f; /* next 5 bits */
24 if (!(protocols
& RC_BIT_SONY15
))
26 func
= raw
& 0x7f; /* first 7 bits */
28 dev
= raw
& 0xff; /* next 8 bits */
32 if (!(protocols
& RC_BIT_SONY20
))
34 func
= raw
& 0x7f; /* first 7 bits */
36 dev
= raw
& 0x1f; /* next 5 bits */
38 subdev
= raw
& 0xff; /* next 8 bits */
43 *scancode
= dev
<< 16 | subdev
<< 8 | func
;
44 return IMG_IR_SCANCODE
;
47 /* Convert NEC scancode to NEC data filter */
48 static int img_ir_sony_filter(const struct rc_scancode_filter
*in
,
49 struct img_ir_filter
*out
, u64 protocols
)
51 unsigned int dev
, subdev
, func
;
52 unsigned int dev_m
, subdev_m
, func_m
;
55 dev
= (in
->data
>> 16) & 0xff;
56 dev_m
= (in
->mask
>> 16) & 0xff;
57 subdev
= (in
->data
>> 8) & 0xff;
58 subdev_m
= (in
->mask
>> 8) & 0xff;
59 func
= (in
->data
>> 0) & 0x7f;
60 func_m
= (in
->mask
>> 0) & 0x7f;
62 if (subdev
& subdev_m
) {
63 /* can't encode subdev and higher device bits */
64 if (dev
& dev_m
& 0xe0)
66 /* subdevice (extended) bits only in 20 bit encoding */
67 if (!(protocols
& RC_BIT_SONY20
))
71 } else if (dev
& dev_m
& 0xe0) {
72 /* upper device bits only in 15 bit encoding */
73 if (!(protocols
& RC_BIT_SONY15
))
79 * The hardware mask cannot distinguish high device bits and low
80 * extended bits, so logically AND those bits of the masks
83 subdev_m
&= (dev_m
>> 5) | 0xf8;
87 /* ensure there aren't any bits straying between fields */
91 /* write the hardware filter */
108 * See also http://www.sbprojects.com/knowledge/ir/sirc.php
109 * http://picprojects.org.uk/projects/sirc/sonysirc.pdf
111 struct img_ir_decoder img_ir_sony
= {
112 .type
= RC_BIT_SONY12
| RC_BIT_SONY15
| RC_BIT_SONY20
,
115 .code_type
= IMG_IR_CODETYPE_PULSELEN
,
118 .unit
= 600000, /* 600 us */
122 .pulse
= { 4 /* 2.4 ms */ },
123 .space
= { 1 /* 600 us */ },
127 .pulse
= { 1 /* 600 us */ },
128 .space
= { 1 /* 600 us */ },
132 .pulse
= { 2 /* 1.2 ms */ },
133 .space
= { 1 /* 600 us */ },
139 .ft_min
= 10, /* 6 ms */
143 .scancode
= img_ir_sony_scancode
,
144 .filter
= img_ir_sony_filter
,