Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * ImgTec IR Decoder setup for Philips RC-6 protocol.
0004  *
0005  * Copyright 2012-2014 Imagination Technologies Ltd.
0006  */
0007 
0008 #include "img-ir-hw.h"
0009 
0010 /* Convert RC6 data to a scancode */
0011 static int img_ir_rc6_scancode(int len, u64 raw, u64 enabled_protocols,
0012                 struct img_ir_scancode_req *request)
0013 {
0014     unsigned int addr, cmd, mode, trl1, trl2;
0015 
0016     /*
0017      * Due to a side effect of the decoder handling the double length
0018      * Trailer bit, the header information is a bit scrambled, and the
0019      * raw data is shifted incorrectly.
0020      * This workaround effectively recovers the header bits.
0021      *
0022      * The Header field should look like this:
0023      *
0024      * StartBit ModeBit2 ModeBit1 ModeBit0 TrailerBit
0025      *
0026      * But what we get is:
0027      *
0028      * ModeBit2 ModeBit1 ModeBit0 TrailerBit1 TrailerBit2
0029      *
0030      * The start bit is not important to recover the scancode.
0031      */
0032 
0033     raw >>= 27;
0034 
0035     trl1    = (raw >>  17)  & 0x01;
0036     trl2    = (raw >>  16)  & 0x01;
0037 
0038     mode    = (raw >>  18)  & 0x07;
0039     addr    = (raw >>   8)  & 0xff;
0040     cmd =  raw      & 0xff;
0041 
0042     /*
0043      * Due to the above explained irregularity the trailer bits cannot
0044      * have the same value.
0045      */
0046     if (trl1 == trl2)
0047         return -EINVAL;
0048 
0049     /* Only mode 0 supported for now */
0050     if (mode)
0051         return -EINVAL;
0052 
0053     request->protocol = RC_PROTO_RC6_0;
0054     request->scancode = addr << 8 | cmd;
0055     request->toggle   = trl2;
0056     return IMG_IR_SCANCODE;
0057 }
0058 
0059 /* Convert RC6 scancode to RC6 data filter */
0060 static int img_ir_rc6_filter(const struct rc_scancode_filter *in,
0061                  struct img_ir_filter *out, u64 protocols)
0062 {
0063     /* Not supported by the hw. */
0064     return -EINVAL;
0065 }
0066 
0067 /*
0068  * RC-6 decoder
0069  * see http://www.sbprojects.com/knowledge/ir/rc6.php
0070  */
0071 struct img_ir_decoder img_ir_rc6 = {
0072     .type       = RC_PROTO_BIT_RC6_0,
0073     .control    = {
0074         .bitorien   = 1,
0075         .code_type  = IMG_IR_CODETYPE_BIPHASE,
0076         .decoden    = 1,
0077         .decodinpol = 1,
0078     },
0079     /* main timings */
0080     .tolerance  = 20,
0081     /*
0082      * Due to a quirk in the img-ir decoder, default header values do
0083      * not work, the values described below were extracted from
0084      * successful RTL test cases.
0085      */
0086     .timings    = {
0087         /* leader symbol */
0088         .ldr = {
0089             .pulse  = { 650 },
0090             .space  = { 660 },
0091         },
0092         /* 0 symbol */
0093         .s00 = {
0094             .pulse  = { 370 },
0095             .space  = { 370 },
0096         },
0097         /* 01 symbol */
0098         .s01 = {
0099             .pulse  = { 370 },
0100             .space  = { 370 },
0101         },
0102         /* free time */
0103         .ft  = {
0104             .minlen = 21,
0105             .maxlen = 21,
0106             .ft_min = 2666, /* 2.666 ms */
0107         },
0108     },
0109 
0110     /* scancode logic */
0111     .scancode   = img_ir_rc6_scancode,
0112     .filter     = img_ir_rc6_filter,
0113 };