12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
269336533SJames Hogan /*
369336533SJames Hogan  * ImgTec IR Decoder setup for JVC protocol.
469336533SJames Hogan  *
569336533SJames Hogan  * Copyright 2012-2014 Imagination Technologies Ltd.
669336533SJames Hogan  */
769336533SJames Hogan 
869336533SJames Hogan #include "img-ir-hw.h"
969336533SJames Hogan 
1069336533SJames Hogan /* Convert JVC data to a scancode */
img_ir_jvc_scancode(int len,u64 raw,u64 enabled_protocols,struct img_ir_scancode_req * request)11ab93ce06SSifan Naeem static int img_ir_jvc_scancode(int len, u64 raw, u64 enabled_protocols,
12ab93ce06SSifan Naeem 			       struct img_ir_scancode_req *request)
1369336533SJames Hogan {
1469336533SJames Hogan 	unsigned int cust, data;
1569336533SJames Hogan 
1669336533SJames Hogan 	if (len != 16)
1769336533SJames Hogan 		return -EINVAL;
1869336533SJames Hogan 
1969336533SJames Hogan 	cust = (raw >> 0) & 0xff;
2069336533SJames Hogan 	data = (raw >> 8) & 0xff;
2169336533SJames Hogan 
226d741bfeSSean Young 	request->protocol = RC_PROTO_JVC;
23ab93ce06SSifan Naeem 	request->scancode = cust << 8 | data;
2469336533SJames Hogan 	return IMG_IR_SCANCODE;
2569336533SJames Hogan }
2669336533SJames Hogan 
2769336533SJames Hogan /* Convert JVC scancode to JVC data filter */
img_ir_jvc_filter(const struct rc_scancode_filter * in,struct img_ir_filter * out,u64 protocols)2869336533SJames Hogan static int img_ir_jvc_filter(const struct rc_scancode_filter *in,
2969336533SJames Hogan 			     struct img_ir_filter *out, u64 protocols)
3069336533SJames Hogan {
3169336533SJames Hogan 	unsigned int cust, data;
3269336533SJames Hogan 	unsigned int cust_m, data_m;
3369336533SJames Hogan 
3469336533SJames Hogan 	cust   = (in->data >> 8) & 0xff;
3569336533SJames Hogan 	cust_m = (in->mask >> 8) & 0xff;
3669336533SJames Hogan 	data   = (in->data >> 0) & 0xff;
3769336533SJames Hogan 	data_m = (in->mask >> 0) & 0xff;
3869336533SJames Hogan 
3969336533SJames Hogan 	out->data = cust   | data << 8;
4069336533SJames Hogan 	out->mask = cust_m | data_m << 8;
4169336533SJames Hogan 
4269336533SJames Hogan 	return 0;
4369336533SJames Hogan }
4469336533SJames Hogan 
4569336533SJames Hogan /*
4669336533SJames Hogan  * JVC decoder
4769336533SJames Hogan  * See also http://www.sbprojects.com/knowledge/ir/jvc.php
4869336533SJames Hogan  *          http://support.jvc.com/consumer/support/documents/RemoteCodes.pdf
4969336533SJames Hogan  */
5069336533SJames Hogan struct img_ir_decoder img_ir_jvc = {
516d741bfeSSean Young 	.type = RC_PROTO_BIT_JVC,
5269336533SJames Hogan 	.control = {
5369336533SJames Hogan 		.decoden = 1,
5469336533SJames Hogan 		.code_type = IMG_IR_CODETYPE_PULSEDIST,
5569336533SJames Hogan 	},
5669336533SJames Hogan 	/* main timings */
5769336533SJames Hogan 	.unit = 527500, /* 527.5 us */
5869336533SJames Hogan 	.timings = {
5969336533SJames Hogan 		/* leader symbol */
6069336533SJames Hogan 		.ldr = {
6169336533SJames Hogan 			.pulse = { 16	/* 8.44 ms */ },
6269336533SJames Hogan 			.space = { 8	/* 4.22 ms */ },
6369336533SJames Hogan 		},
6469336533SJames Hogan 		/* 0 symbol */
6569336533SJames Hogan 		.s00 = {
6669336533SJames Hogan 			.pulse = { 1	/* 527.5 us +-60 us */ },
6769336533SJames Hogan 			.space = { 1	/* 527.5 us */ },
6869336533SJames Hogan 		},
6969336533SJames Hogan 		/* 1 symbol */
7069336533SJames Hogan 		.s01 = {
7169336533SJames Hogan 			.pulse = { 1	/* 527.5 us +-60 us */ },
7269336533SJames Hogan 			.space = { 3	/* 1.5825 ms +-40 us */ },
7369336533SJames Hogan 		},
7469336533SJames Hogan 		/* free time */
7569336533SJames Hogan 		.ft = {
7669336533SJames Hogan 			.minlen = 16,
7769336533SJames Hogan 			.maxlen = 16,
7869336533SJames Hogan 			.ft_min = 10,	/* 5.275 ms */
7969336533SJames Hogan 		},
8069336533SJames Hogan 	},
8169336533SJames Hogan 	/* scancode logic */
8269336533SJames Hogan 	.scancode = img_ir_jvc_scancode,
8369336533SJames Hogan 	.filter = img_ir_jvc_filter,
8469336533SJames Hogan };
85