1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
23c11305eSJames Hogan /*
33c11305eSJames Hogan * ImgTec IR Decoder setup for Sharp protocol.
43c11305eSJames Hogan *
53c11305eSJames Hogan * Copyright 2012-2014 Imagination Technologies Ltd.
63c11305eSJames Hogan */
73c11305eSJames Hogan
83c11305eSJames Hogan #include "img-ir-hw.h"
93c11305eSJames Hogan
103c11305eSJames Hogan /* Convert Sharp data to a scancode */
img_ir_sharp_scancode(int len,u64 raw,u64 enabled_protocols,struct img_ir_scancode_req * request)11ab93ce06SSifan Naeem static int img_ir_sharp_scancode(int len, u64 raw, u64 enabled_protocols,
12ab93ce06SSifan Naeem struct img_ir_scancode_req *request)
133c11305eSJames Hogan {
143c11305eSJames Hogan unsigned int addr, cmd, exp, chk;
153c11305eSJames Hogan
163c11305eSJames Hogan if (len != 15)
173c11305eSJames Hogan return -EINVAL;
183c11305eSJames Hogan
193c11305eSJames Hogan addr = (raw >> 0) & 0x1f;
203c11305eSJames Hogan cmd = (raw >> 5) & 0xff;
213c11305eSJames Hogan exp = (raw >> 13) & 0x1;
223c11305eSJames Hogan chk = (raw >> 14) & 0x1;
233c11305eSJames Hogan
243c11305eSJames Hogan /* validate data */
253c11305eSJames Hogan if (!exp)
263c11305eSJames Hogan return -EINVAL;
273c11305eSJames Hogan if (chk)
283c11305eSJames Hogan /* probably the second half of the message */
293c11305eSJames Hogan return -EINVAL;
303c11305eSJames Hogan
316d741bfeSSean Young request->protocol = RC_PROTO_SHARP;
32ab93ce06SSifan Naeem request->scancode = addr << 8 | cmd;
333c11305eSJames Hogan return IMG_IR_SCANCODE;
343c11305eSJames Hogan }
353c11305eSJames Hogan
363c11305eSJames Hogan /* Convert Sharp scancode to Sharp data filter */
img_ir_sharp_filter(const struct rc_scancode_filter * in,struct img_ir_filter * out,u64 protocols)373c11305eSJames Hogan static int img_ir_sharp_filter(const struct rc_scancode_filter *in,
383c11305eSJames Hogan struct img_ir_filter *out, u64 protocols)
393c11305eSJames Hogan {
403c11305eSJames Hogan unsigned int addr, cmd, exp = 0, chk = 0;
413c11305eSJames Hogan unsigned int addr_m, cmd_m, exp_m = 0, chk_m = 0;
423c11305eSJames Hogan
433c11305eSJames Hogan addr = (in->data >> 8) & 0x1f;
443c11305eSJames Hogan addr_m = (in->mask >> 8) & 0x1f;
453c11305eSJames Hogan cmd = (in->data >> 0) & 0xff;
463c11305eSJames Hogan cmd_m = (in->mask >> 0) & 0xff;
473c11305eSJames Hogan if (cmd_m) {
483c11305eSJames Hogan /* if filtering commands, we can only match the first part */
493c11305eSJames Hogan exp = 1;
503c11305eSJames Hogan exp_m = 1;
513c11305eSJames Hogan chk = 0;
523c11305eSJames Hogan chk_m = 1;
533c11305eSJames Hogan }
543c11305eSJames Hogan
553c11305eSJames Hogan out->data = addr |
563c11305eSJames Hogan cmd << 5 |
573c11305eSJames Hogan exp << 13 |
583c11305eSJames Hogan chk << 14;
593c11305eSJames Hogan out->mask = addr_m |
603c11305eSJames Hogan cmd_m << 5 |
613c11305eSJames Hogan exp_m << 13 |
623c11305eSJames Hogan chk_m << 14;
633c11305eSJames Hogan
643c11305eSJames Hogan return 0;
653c11305eSJames Hogan }
663c11305eSJames Hogan
673c11305eSJames Hogan /*
683c11305eSJames Hogan * Sharp decoder
693c11305eSJames Hogan * See also http://www.sbprojects.com/knowledge/ir/sharp.php
703c11305eSJames Hogan */
713c11305eSJames Hogan struct img_ir_decoder img_ir_sharp = {
726d741bfeSSean Young .type = RC_PROTO_BIT_SHARP,
733c11305eSJames Hogan .control = {
743c11305eSJames Hogan .decoden = 0,
753c11305eSJames Hogan .decodend2 = 1,
763c11305eSJames Hogan .code_type = IMG_IR_CODETYPE_PULSEDIST,
773c11305eSJames Hogan .d1validsel = 1,
783c11305eSJames Hogan },
793c11305eSJames Hogan /* main timings */
803c11305eSJames Hogan .tolerance = 20, /* 20% */
813c11305eSJames Hogan .timings = {
823c11305eSJames Hogan /* 0 symbol */
833c11305eSJames Hogan .s10 = {
843c11305eSJames Hogan .pulse = { 320 /* 320 us */ },
853c11305eSJames Hogan .space = { 680 /* 1 ms period */ },
863c11305eSJames Hogan },
873c11305eSJames Hogan /* 1 symbol */
883c11305eSJames Hogan .s11 = {
893c11305eSJames Hogan .pulse = { 320 /* 320 us */ },
903c11305eSJames Hogan .space = { 1680 /* 2 ms period */ },
913c11305eSJames Hogan },
923c11305eSJames Hogan /* free time */
933c11305eSJames Hogan .ft = {
943c11305eSJames Hogan .minlen = 15,
953c11305eSJames Hogan .maxlen = 15,
963c11305eSJames Hogan .ft_min = 5000, /* 5 ms */
973c11305eSJames Hogan },
983c11305eSJames Hogan },
993c11305eSJames Hogan /* scancode logic */
1003c11305eSJames Hogan .scancode = img_ir_sharp_scancode,
1013c11305eSJames Hogan .filter = img_ir_sharp_filter,
1023c11305eSJames Hogan };
103