treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / media / rc / img-ir / img-ir-sharp.c
blobce5d1a0df3259b8ae1dfd7118c4aa6e2db8d01e4
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * ImgTec IR Decoder setup for Sharp protocol.
5 * Copyright 2012-2014 Imagination Technologies Ltd.
6 */
8 #include "img-ir-hw.h"
10 /* Convert Sharp data to a scancode */
11 static int img_ir_sharp_scancode(int len, u64 raw, u64 enabled_protocols,
12 struct img_ir_scancode_req *request)
14 unsigned int addr, cmd, exp, chk;
16 if (len != 15)
17 return -EINVAL;
19 addr = (raw >> 0) & 0x1f;
20 cmd = (raw >> 5) & 0xff;
21 exp = (raw >> 13) & 0x1;
22 chk = (raw >> 14) & 0x1;
24 /* validate data */
25 if (!exp)
26 return -EINVAL;
27 if (chk)
28 /* probably the second half of the message */
29 return -EINVAL;
31 request->protocol = RC_PROTO_SHARP;
32 request->scancode = addr << 8 | cmd;
33 return IMG_IR_SCANCODE;
36 /* Convert Sharp scancode to Sharp data filter */
37 static int img_ir_sharp_filter(const struct rc_scancode_filter *in,
38 struct img_ir_filter *out, u64 protocols)
40 unsigned int addr, cmd, exp = 0, chk = 0;
41 unsigned int addr_m, cmd_m, exp_m = 0, chk_m = 0;
43 addr = (in->data >> 8) & 0x1f;
44 addr_m = (in->mask >> 8) & 0x1f;
45 cmd = (in->data >> 0) & 0xff;
46 cmd_m = (in->mask >> 0) & 0xff;
47 if (cmd_m) {
48 /* if filtering commands, we can only match the first part */
49 exp = 1;
50 exp_m = 1;
51 chk = 0;
52 chk_m = 1;
55 out->data = addr |
56 cmd << 5 |
57 exp << 13 |
58 chk << 14;
59 out->mask = addr_m |
60 cmd_m << 5 |
61 exp_m << 13 |
62 chk_m << 14;
64 return 0;
68 * Sharp decoder
69 * See also http://www.sbprojects.com/knowledge/ir/sharp.php
71 struct img_ir_decoder img_ir_sharp = {
72 .type = RC_PROTO_BIT_SHARP,
73 .control = {
74 .decoden = 0,
75 .decodend2 = 1,
76 .code_type = IMG_IR_CODETYPE_PULSEDIST,
77 .d1validsel = 1,
79 /* main timings */
80 .tolerance = 20, /* 20% */
81 .timings = {
82 /* 0 symbol */
83 .s10 = {
84 .pulse = { 320 /* 320 us */ },
85 .space = { 680 /* 1 ms period */ },
87 /* 1 symbol */
88 .s11 = {
89 .pulse = { 320 /* 320 us */ },
90 .space = { 1680 /* 2 ms period */ },
92 /* free time */
93 .ft = {
94 .minlen = 15,
95 .maxlen = 15,
96 .ft_min = 5000, /* 5 ms */
99 /* scancode logic */
100 .scancode = img_ir_sharp_scancode,
101 .filter = img_ir_sharp_filter,