Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * ImgTec IR Decoder setup for Sanyo protocol.
0004  *
0005  * Copyright 2012-2014 Imagination Technologies Ltd.
0006  *
0007  * From ir-sanyo-decoder.c:
0008  *
0009  * This protocol uses the NEC protocol timings. However, data is formatted as:
0010  *  13 bits Custom Code
0011  *  13 bits NOT(Custom Code)
0012  *  8 bits Key data
0013  *  8 bits NOT(Key data)
0014  *
0015  * According with LIRC, this protocol is used on Sanyo, Aiwa and Chinon
0016  * Information for this protocol is available at the Sanyo LC7461 datasheet.
0017  */
0018 
0019 #include "img-ir-hw.h"
0020 
0021 /* Convert Sanyo data to a scancode */
0022 static int img_ir_sanyo_scancode(int len, u64 raw, u64 enabled_protocols,
0023                  struct img_ir_scancode_req *request)
0024 {
0025     unsigned int addr, addr_inv, data, data_inv;
0026     /* a repeat code has no data */
0027     if (!len)
0028         return IMG_IR_REPEATCODE;
0029     if (len != 42)
0030         return -EINVAL;
0031     addr     = (raw >>  0) & 0x1fff;
0032     addr_inv = (raw >> 13) & 0x1fff;
0033     data     = (raw >> 26) & 0xff;
0034     data_inv = (raw >> 34) & 0xff;
0035     /* Validate data */
0036     if ((data_inv ^ data) != 0xff)
0037         return -EINVAL;
0038     /* Validate address */
0039     if ((addr_inv ^ addr) != 0x1fff)
0040         return -EINVAL;
0041 
0042     /* Normal Sanyo */
0043     request->protocol = RC_PROTO_SANYO;
0044     request->scancode = addr << 8 | data;
0045     return IMG_IR_SCANCODE;
0046 }
0047 
0048 /* Convert Sanyo scancode to Sanyo data filter */
0049 static int img_ir_sanyo_filter(const struct rc_scancode_filter *in,
0050                    struct img_ir_filter *out, u64 protocols)
0051 {
0052     unsigned int addr, addr_inv, data, data_inv;
0053     unsigned int addr_m, data_m;
0054 
0055     data = in->data & 0xff;
0056     data_m = in->mask & 0xff;
0057     data_inv = data ^ 0xff;
0058 
0059     if (in->data & 0xff700000)
0060         return -EINVAL;
0061 
0062     addr       = (in->data >> 8) & 0x1fff;
0063     addr_m     = (in->mask >> 8) & 0x1fff;
0064     addr_inv   = addr ^ 0x1fff;
0065 
0066     out->data = (u64)data_inv << 34 |
0067             (u64)data     << 26 |
0068              addr_inv << 13 |
0069              addr;
0070     out->mask = (u64)data_m << 34 |
0071             (u64)data_m << 26 |
0072              addr_m << 13 |
0073              addr_m;
0074     return 0;
0075 }
0076 
0077 /* Sanyo decoder */
0078 struct img_ir_decoder img_ir_sanyo = {
0079     .type = RC_PROTO_BIT_SANYO,
0080     .control = {
0081         .decoden = 1,
0082         .code_type = IMG_IR_CODETYPE_PULSEDIST,
0083     },
0084     /* main timings */
0085     .unit = 562500, /* 562.5 us */
0086     .timings = {
0087         /* leader symbol */
0088         .ldr = {
0089             .pulse = { 16   /* 9ms */ },
0090             .space = { 8    /* 4.5ms */ },
0091         },
0092         /* 0 symbol */
0093         .s00 = {
0094             .pulse = { 1    /* 562.5 us */ },
0095             .space = { 1    /* 562.5 us */ },
0096         },
0097         /* 1 symbol */
0098         .s01 = {
0099             .pulse = { 1    /* 562.5 us */ },
0100             .space = { 3    /* 1687.5 us */ },
0101         },
0102         /* free time */
0103         .ft = {
0104             .minlen = 42,
0105             .maxlen = 42,
0106             .ft_min = 10,   /* 5.625 ms */
0107         },
0108     },
0109     /* repeat codes */
0110     .repeat = 108,          /* 108 ms */
0111     .rtimings = {
0112         /* leader symbol */
0113         .ldr = {
0114             .space = { 4    /* 2.25 ms */ },
0115         },
0116         /* free time */
0117         .ft = {
0118             .minlen = 0,    /* repeat code has no data */
0119             .maxlen = 0,
0120         },
0121     },
0122     /* scancode logic */
0123     .scancode = img_ir_sanyo_scancode,
0124     .filter = img_ir_sanyo_filter,
0125 };