Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) // handle au0828 IR remotes via linux kernel input layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) // Copyright (c) 2014 Mauro Carvalho Chehab <mchehab@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) // Copyright (c) 2014 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) // Based on em28xx-input.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "au0828.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <media/rc-core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static int disable_ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) module_param(disable_ir,        int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) struct au0828_rc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct au0828_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct rc_dev *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	char name[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	/* poll decoder */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int polling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct delayed_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	/* i2c slave address of external device (if used) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	u16 i2c_dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int  (*get_key_i2c)(struct au0828_rc *ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * AU8522 has a builtin IR receiver. Add functions to get IR from it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int au8522_rc_write(struct au0828_rc *ir, u16 reg, u8 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	char buf[] = { (reg >> 8) | 0x80, reg & 0xff, data };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct i2c_msg msg = { .addr = ir->i2c_dev_addr, .flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			       .buf = buf, .len = sizeof(buf) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	rc = i2c_transfer(ir->dev->i2c_client.adapter, &msg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return (rc == 1) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static int au8522_rc_read(struct au0828_rc *ir, u16 reg, int val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 				 char *buf, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	char obuf[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct i2c_msg msg[2] = { { .addr = ir->i2c_dev_addr, .flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 				    .buf = obuf, .len = 2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				  { .addr = ir->i2c_dev_addr, .flags = I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				    .buf = buf, .len = size } };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	obuf[0] = 0x40 | reg >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	obuf[1] = reg & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (val >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		obuf[2] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		msg[0].len++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	rc = i2c_transfer(ir->dev->i2c_client.adapter, msg, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return (rc == 2) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int au8522_rc_andor(struct au0828_rc *ir, u16 reg, u8 mask, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	char buf, oldbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	rc = au8522_rc_read(ir, reg, -1, &buf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	oldbuf = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	buf = (buf & ~mask) | (value & mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	/* Nothing to do, just return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (buf == oldbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return au8522_rc_write(ir, reg, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define au8522_rc_set(ir, reg, bit) au8522_rc_andor(ir, (reg), (bit), (bit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define au8522_rc_clear(ir, reg, bit) au8522_rc_andor(ir, (reg), (bit), 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Remote Controller time units */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define AU8522_UNIT		200 /* us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define NEC_START_SPACE		(4500 / AU8522_UNIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define NEC_START_PULSE		(563 * 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define RC5_START_SPACE		(4 * AU8522_UNIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define RC5_START_PULSE		889
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int au0828_get_key_au8522(struct au0828_rc *ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	unsigned char buf[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct ir_raw_event rawir = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	int i, j, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int prv_bit, bit, width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	/* do nothing if device is disconnected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (test_bit(DEV_DISCONNECTED, &ir->dev->dev_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	/* Check IR int */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	rc = au8522_rc_read(ir, 0xe1, -1, buf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (rc < 0 || !(buf[0] & (1 << 4))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		/* Be sure that IR is enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		au8522_rc_set(ir, 0xe0, 1 << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	/* Something arrived. Get the data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	rc = au8522_rc_read(ir, 0xe3, 0x11, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	/* Disable IR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	au8522_rc_clear(ir, 0xe0, 1 << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* Enable IR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	au8522_rc_set(ir, 0xe0, 1 << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	dprintk(16, "RC data received: %*ph\n", 40, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	prv_bit = (buf[0] >> 7) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	width = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	for (i = 0; i < sizeof(buf); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		for (j = 7; j >= 0; j--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			bit = (buf[i] >> j) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			if (bit == prv_bit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				width++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			 * Fix an au8522 bug: the first pulse event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			 * is lost. So, we need to fake it, based on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			 * protocol. That means that not all raw decoders
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			 * will work, as we need to add a hack for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			 * protocol, based on the first space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			 * So, we only support RC5 and NEC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				rawir.pulse = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				if (width > NEC_START_SPACE - 2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				    width < NEC_START_SPACE + 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 					/* NEC protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 					rawir.duration = NEC_START_PULSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 					dprintk(16, "Storing NEC start %s with duration %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 						rawir.pulse ? "pulse" : "space",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 						rawir.duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 					/* RC5 protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 					rawir.duration = RC5_START_PULSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 					dprintk(16, "Storing RC5 start %s with duration %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 						rawir.pulse ? "pulse" : "space",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 						rawir.duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 				ir_raw_event_store(ir->rc, &rawir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			rawir.pulse = prv_bit ? false : true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			rawir.duration = AU8522_UNIT * width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			dprintk(16, "Storing %s with duration %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 				rawir.pulse ? "pulse" : "space",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				rawir.duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			ir_raw_event_store(ir->rc, &rawir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			width = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			prv_bit = bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	rawir.pulse = prv_bit ? false : true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	rawir.duration = AU8522_UNIT * width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	dprintk(16, "Storing end %s with duration %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		rawir.pulse ? "pulse" : "space",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		rawir.duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	ir_raw_event_store(ir->rc, &rawir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	ir_raw_event_handle(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * Generic IR code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static void au0828_rc_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct au0828_rc *ir = container_of(work, struct au0828_rc, work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	rc = ir->get_key_i2c(ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		pr_info("Error while getting RC scancode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static int au0828_rc_start(struct rc_dev *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	struct au0828_rc *ir = rc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	INIT_DELAYED_WORK(&ir->work, au0828_rc_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	/* Enable IR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	au8522_rc_set(ir, 0xe0, 1 << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static void au0828_rc_stop(struct rc_dev *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct au0828_rc *ir = rc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	cancel_delayed_work_sync(&ir->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	/* do nothing if device is disconnected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (!test_bit(DEV_DISCONNECTED, &ir->dev->dev_state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		/* Disable IR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		au8522_rc_clear(ir, 0xe0, 1 << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int au0828_probe_i2c_ir(struct au0828_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	static const unsigned short addr_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		 0x47, I2C_CLIENT_END
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	while (addr_list[i] != I2C_CLIENT_END) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		if (i2c_probe_func_quick_read(dev->i2c_client.adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 					      addr_list[i]) == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			return addr_list[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int au0828_rc_register(struct au0828_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	struct au0828_rc *ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct rc_dev *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	u16 i2c_rc_dev_addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (!dev->board.has_ir_i2c || disable_ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	i2c_rc_dev_addr = au0828_probe_i2c_ir(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (!i2c_rc_dev_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	rc = rc_allocate_device(RC_DRIVER_IR_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (!ir || !rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	/* record handles to ourself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	ir->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	dev->ir = ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	ir->rc = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	rc->priv = ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	rc->open = au0828_rc_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	rc->close = au0828_rc_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (dev->board.has_ir_i2c) {	/* external i2c device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		switch (dev->boardnr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		case AU0828_BOARD_HAUPPAUGE_HVR950Q:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			rc->map_name = RC_MAP_HAUPPAUGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			ir->get_key_i2c = au0828_get_key_au8522;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		ir->i2c_dev_addr = i2c_rc_dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	/* This is how often we ask the chip for IR information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	ir->polling = 100; /* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	/* init input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	snprintf(ir->name, sizeof(ir->name), "au0828 IR (%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		 dev->board.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	usb_make_path(dev->usbdev, ir->phys, sizeof(ir->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	strlcat(ir->phys, "/input0", sizeof(ir->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	rc->device_name = ir->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	rc->input_phys = ir->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	rc->input_id.bustype = BUS_USB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	rc->input_id.version = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	rc->input_id.vendor = le16_to_cpu(dev->usbdev->descriptor.idVendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	rc->input_id.product = le16_to_cpu(dev->usbdev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	rc->dev.parent = &dev->usbdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	rc->driver_name = "au0828-input";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	rc->allowed_protocols = RC_PROTO_BIT_NEC | RC_PROTO_BIT_NECX |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				RC_PROTO_BIT_NEC32 | RC_PROTO_BIT_RC5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	/* all done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	err = rc_register_device(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	pr_info("Remote controller %s initialized\n", ir->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	dev->ir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	rc_free_device(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	kfree(ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) void au0828_rc_unregister(struct au0828_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	struct au0828_rc *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	/* skip detach on non attached boards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	if (!ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	rc_unregister_device(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	/* done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	kfree(ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	dev->ir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) int au0828_rc_suspend(struct au0828_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	struct au0828_rc *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (!ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	pr_info("Stopping RC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	cancel_delayed_work_sync(&ir->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	/* Disable IR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	au8522_rc_clear(ir, 0xe0, 1 << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int au0828_rc_resume(struct au0828_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	struct au0828_rc *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (!ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	pr_info("Restarting RC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* Enable IR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	au8522_rc_set(ir, 0xe0, 1 << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }