xref: /linux/drivers/media/rc/img-ir/img-ir-sanyo.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
246b35083SJames Hogan /*
346b35083SJames Hogan  * ImgTec IR Decoder setup for Sanyo protocol.
446b35083SJames Hogan  *
546b35083SJames Hogan  * Copyright 2012-2014 Imagination Technologies Ltd.
646b35083SJames Hogan  *
746b35083SJames Hogan  * From ir-sanyo-decoder.c:
846b35083SJames Hogan  *
946b35083SJames Hogan  * This protocol uses the NEC protocol timings. However, data is formatted as:
1046b35083SJames Hogan  *	13 bits Custom Code
1146b35083SJames Hogan  *	13 bits NOT(Custom Code)
1246b35083SJames Hogan  *	8 bits Key data
1346b35083SJames Hogan  *	8 bits NOT(Key data)
1446b35083SJames Hogan  *
1546b35083SJames Hogan  * According with LIRC, this protocol is used on Sanyo, Aiwa and Chinon
1646b35083SJames Hogan  * Information for this protocol is available at the Sanyo LC7461 datasheet.
1746b35083SJames Hogan  */
1846b35083SJames Hogan 
1946b35083SJames Hogan #include "img-ir-hw.h"
2046b35083SJames Hogan 
2146b35083SJames Hogan /* Convert Sanyo data to a scancode */
img_ir_sanyo_scancode(int len,u64 raw,u64 enabled_protocols,struct img_ir_scancode_req * request)22ab93ce06SSifan Naeem static int img_ir_sanyo_scancode(int len, u64 raw, u64 enabled_protocols,
23ab93ce06SSifan Naeem 				 struct img_ir_scancode_req *request)
2446b35083SJames Hogan {
2546b35083SJames Hogan 	unsigned int addr, addr_inv, data, data_inv;
2646b35083SJames Hogan 	/* a repeat code has no data */
2746b35083SJames Hogan 	if (!len)
2846b35083SJames Hogan 		return IMG_IR_REPEATCODE;
2946b35083SJames Hogan 	if (len != 42)
3046b35083SJames Hogan 		return -EINVAL;
3146b35083SJames Hogan 	addr     = (raw >>  0) & 0x1fff;
3246b35083SJames Hogan 	addr_inv = (raw >> 13) & 0x1fff;
3346b35083SJames Hogan 	data     = (raw >> 26) & 0xff;
3446b35083SJames Hogan 	data_inv = (raw >> 34) & 0xff;
3546b35083SJames Hogan 	/* Validate data */
3646b35083SJames Hogan 	if ((data_inv ^ data) != 0xff)
3746b35083SJames Hogan 		return -EINVAL;
3846b35083SJames Hogan 	/* Validate address */
3946b35083SJames Hogan 	if ((addr_inv ^ addr) != 0x1fff)
4046b35083SJames Hogan 		return -EINVAL;
4146b35083SJames Hogan 
4246b35083SJames Hogan 	/* Normal Sanyo */
436d741bfeSSean Young 	request->protocol = RC_PROTO_SANYO;
44ab93ce06SSifan Naeem 	request->scancode = addr << 8 | data;
4546b35083SJames Hogan 	return IMG_IR_SCANCODE;
4646b35083SJames Hogan }
4746b35083SJames Hogan 
4846b35083SJames Hogan /* Convert Sanyo scancode to Sanyo data filter */
img_ir_sanyo_filter(const struct rc_scancode_filter * in,struct img_ir_filter * out,u64 protocols)4946b35083SJames Hogan static int img_ir_sanyo_filter(const struct rc_scancode_filter *in,
5046b35083SJames Hogan 			       struct img_ir_filter *out, u64 protocols)
5146b35083SJames Hogan {
5246b35083SJames Hogan 	unsigned int addr, addr_inv, data, data_inv;
5346b35083SJames Hogan 	unsigned int addr_m, data_m;
5446b35083SJames Hogan 
5546b35083SJames Hogan 	data = in->data & 0xff;
5646b35083SJames Hogan 	data_m = in->mask & 0xff;
5746b35083SJames Hogan 	data_inv = data ^ 0xff;
5846b35083SJames Hogan 
5946b35083SJames Hogan 	if (in->data & 0xff700000)
6046b35083SJames Hogan 		return -EINVAL;
6146b35083SJames Hogan 
6246b35083SJames Hogan 	addr       = (in->data >> 8) & 0x1fff;
6346b35083SJames Hogan 	addr_m     = (in->mask >> 8) & 0x1fff;
6446b35083SJames Hogan 	addr_inv   = addr ^ 0x1fff;
6546b35083SJames Hogan 
6646b35083SJames Hogan 	out->data = (u64)data_inv << 34 |
6746b35083SJames Hogan 		    (u64)data     << 26 |
6846b35083SJames Hogan 			 addr_inv << 13 |
6946b35083SJames Hogan 			 addr;
7046b35083SJames Hogan 	out->mask = (u64)data_m << 34 |
7146b35083SJames Hogan 		    (u64)data_m << 26 |
7246b35083SJames Hogan 			 addr_m << 13 |
7346b35083SJames Hogan 			 addr_m;
7446b35083SJames Hogan 	return 0;
7546b35083SJames Hogan }
7646b35083SJames Hogan 
7746b35083SJames Hogan /* Sanyo decoder */
7846b35083SJames Hogan struct img_ir_decoder img_ir_sanyo = {
796d741bfeSSean Young 	.type = RC_PROTO_BIT_SANYO,
8046b35083SJames Hogan 	.control = {
8146b35083SJames Hogan 		.decoden = 1,
8246b35083SJames Hogan 		.code_type = IMG_IR_CODETYPE_PULSEDIST,
8346b35083SJames Hogan 	},
8446b35083SJames Hogan 	/* main timings */
8546b35083SJames Hogan 	.unit = 562500, /* 562.5 us */
8646b35083SJames Hogan 	.timings = {
8746b35083SJames Hogan 		/* leader symbol */
8846b35083SJames Hogan 		.ldr = {
8946b35083SJames Hogan 			.pulse = { 16	/* 9ms */ },
9046b35083SJames Hogan 			.space = { 8	/* 4.5ms */ },
9146b35083SJames Hogan 		},
9246b35083SJames Hogan 		/* 0 symbol */
9346b35083SJames Hogan 		.s00 = {
9446b35083SJames Hogan 			.pulse = { 1	/* 562.5 us */ },
9546b35083SJames Hogan 			.space = { 1	/* 562.5 us */ },
9646b35083SJames Hogan 		},
9746b35083SJames Hogan 		/* 1 symbol */
9846b35083SJames Hogan 		.s01 = {
9946b35083SJames Hogan 			.pulse = { 1	/* 562.5 us */ },
10046b35083SJames Hogan 			.space = { 3	/* 1687.5 us */ },
10146b35083SJames Hogan 		},
10246b35083SJames Hogan 		/* free time */
10346b35083SJames Hogan 		.ft = {
10446b35083SJames Hogan 			.minlen = 42,
10546b35083SJames Hogan 			.maxlen = 42,
10646b35083SJames Hogan 			.ft_min = 10,	/* 5.625 ms */
10746b35083SJames Hogan 		},
10846b35083SJames Hogan 	},
10946b35083SJames Hogan 	/* repeat codes */
11046b35083SJames Hogan 	.repeat = 108,			/* 108 ms */
11146b35083SJames Hogan 	.rtimings = {
11246b35083SJames Hogan 		/* leader symbol */
11346b35083SJames Hogan 		.ldr = {
11446b35083SJames Hogan 			.space = { 4	/* 2.25 ms */ },
11546b35083SJames Hogan 		},
11646b35083SJames Hogan 		/* free time */
11746b35083SJames Hogan 		.ft = {
11846b35083SJames Hogan 			.minlen = 0,	/* repeat code has no data */
11946b35083SJames Hogan 			.maxlen = 0,
12046b35083SJames Hogan 		},
12146b35083SJames Hogan 	},
12246b35083SJames Hogan 	/* scancode logic */
12346b35083SJames Hogan 	.scancode = img_ir_sanyo_scancode,
12446b35083SJames Hogan 	.filter = img_ir_sanyo_filter,
12546b35083SJames Hogan };
126