1/*
2 * ImgTec IR Decoder setup for Philips RC-5 protocol.
3 *
4 * Copyright 2012-2014 Imagination Technologies Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include "img-ir-hw.h"
13
14/* Convert RC5 data to a scancode */
15static int img_ir_rc5_scancode(int len, u64 raw, u64 enabled_protocols,
16				struct img_ir_scancode_req *request)
17{
18	unsigned int addr, cmd, tgl, start;
19
20	/* Quirk in the decoder shifts everything by 2 to the left. */
21	raw   >>= 2;
22
23	start	=  (raw >> 13)	& 0x01;
24	tgl	=  (raw >> 11)	& 0x01;
25	addr	=  (raw >>  6)	& 0x1f;
26	cmd	=   raw		& 0x3f;
27	/*
28	 * 12th bit is used to extend the command in extended RC5 and has
29	 * no effect on standard RC5.
30	 */
31	cmd	+= ((raw >> 12) & 0x01) ? 0 : 0x40;
32
33	if (!start)
34		return -EINVAL;
35
36	request->protocol = RC_TYPE_RC5;
37	request->scancode = addr << 8 | cmd;
38	request->toggle   = tgl;
39	return IMG_IR_SCANCODE;
40}
41
42/* Convert RC5 scancode to RC5 data filter */
43static int img_ir_rc5_filter(const struct rc_scancode_filter *in,
44				 struct img_ir_filter *out, u64 protocols)
45{
46	/* Not supported by the hw. */
47	return -EINVAL;
48}
49
50/*
51 * RC-5 decoder
52 * see http://www.sbprojects.com/knowledge/ir/rc5.php
53 */
54struct img_ir_decoder img_ir_rc5 = {
55	.type      = RC_BIT_RC5,
56	.control   = {
57		.bitoriend2	= 1,
58		.code_type	= IMG_IR_CODETYPE_BIPHASE,
59		.decodend2	= 1,
60	},
61	/* main timings */
62	.tolerance	= 16,
63	.unit		= 888888, /* 1/36k*32=888.888microseconds */
64	.timings	= {
65		/* 10 symbol */
66		.s10 = {
67			.pulse	= { 1 },
68			.space	= { 1 },
69		},
70
71		/* 11 symbol */
72		.s11 = {
73			.pulse	= { 1 },
74			.space	= { 1 },
75		},
76
77		/* free time */
78		.ft  = {
79			.minlen = 14,
80			.maxlen = 14,
81			.ft_min = 5,
82		},
83	},
84
85	/* scancode logic */
86	.scancode	= img_ir_rc5_scancode,
87	.filter		= img_ir_rc5_filter,
88};
89