^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) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // handle em28xx IR remotes via linux kernel input layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Markus Rechberger <mrechberger@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) // Mauro Carvalho Chehab <mchehab@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // Sascha Sommer <saschasommer@freenet.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) // This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) // it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) // the Free Software Foundation; either version 2 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) // (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) // This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) // but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) // GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "em28xx.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/bitrev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define EM28XX_SNAPSHOT_KEY KEY_CAMERA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL 500 /* [ms] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL 100 /* [ms] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static unsigned int ir_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) module_param(ir_debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define MODULE_NAME "em28xx"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define dprintk(fmt, arg...) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if (ir_debug) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) dev_printk(KERN_DEBUG, &ir->dev->intf->dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) "input: %s: " fmt, __func__, ## arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * Polling structure used by em28xx IR's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct em28xx_ir_poll_result {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned int toggle_bit:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned int read_count:7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) enum rc_proto protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u32 scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct em28xx_IR {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct em28xx *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct rc_dev *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* poll decoder */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int polling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct delayed_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned int full_code:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned int last_readcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u64 rc_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct i2c_client *i2c_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int (*get_key_i2c)(struct i2c_client *ir, enum rc_proto *protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u32 *scancode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int (*get_key)(struct em28xx_IR *ir, struct em28xx_ir_poll_result *r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * I2C IR based get keycodes - should be used with ir-kbd-i2c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static int em28xx_get_key_terratec(struct i2c_client *i2c_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) enum rc_proto *protocol, u32 *scancode)
^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) unsigned char b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* poll IR chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) rc = i2c_master_recv(i2c_dev, &b, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (rc != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * it seems that 0xFE indicates that a button is still hold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * down, while 0xff indicates that no button is hold down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (b == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (b == 0xfe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* keep old data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *protocol = RC_PROTO_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *scancode = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int em28xx_get_key_em_haup(struct i2c_client *i2c_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) enum rc_proto *protocol, u32 *scancode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned char buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* poll IR chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) size = i2c_master_recv(i2c_dev, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (size != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* Does eliminate repeated parity code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (buf[1] == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * Rearranges bits to the right order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * The bit order were determined experimentally by using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * The original Hauppauge Grey IR and another RC5 that uses addr=0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * The RC5 code has 14 bits, but we've experimentally determined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * the meaning for only 11 bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * So, the code translation is not complete. Yet, it is enough to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * work with the provided RC5 IR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) *protocol = RC_PROTO_RC5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) *scancode = (bitrev8(buf[1]) & 0x1f) << 8 | bitrev8(buf[0]) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static int em28xx_get_key_pinnacle_usb_grey(struct i2c_client *i2c_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) enum rc_proto *protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) u32 *scancode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) unsigned char buf[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* poll IR chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (i2c_master_recv(i2c_dev, buf, 3) != 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (buf[0] != 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *protocol = RC_PROTO_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) *scancode = buf[2] & 0x3f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static int em28xx_get_key_winfast_usbii_deluxe(struct i2c_client *i2c_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) enum rc_proto *protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) u32 *scancode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) unsigned char subaddr, keydetect, key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct i2c_msg msg[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) .addr = i2c_dev->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) .flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) .buf = &subaddr, .len = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .addr = i2c_dev->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .flags = I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .buf = &keydetect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .len = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) subaddr = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (i2c_transfer(i2c_dev->adapter, msg, 2) != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (keydetect == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) subaddr = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) msg[1].buf = &key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (i2c_transfer(i2c_dev->adapter, msg, 2) != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (key == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) *protocol = RC_PROTO_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) *scancode = key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return 1;
^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) * Poll based get keycode functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /* This is for the em2860/em2880 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static int default_polling_getkey(struct em28xx_IR *ir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct em28xx_ir_poll_result *poll_result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct em28xx *dev = ir->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) u8 msg[3] = { 0, 0, 0 };
^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) * Read key toggle, brand, and key code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * on registers 0x45, 0x46 and 0x47
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) rc = dev->em28xx_read_reg_req_len(dev, 0, EM28XX_R45_IR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) msg, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /* Infrared toggle (Reg 0x45[7]) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) poll_result->toggle_bit = (msg[0] >> 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Infrared read count (Reg 0x45[6:0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) poll_result->read_count = (msg[0] & 0x7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* Remote Control Address/Data (Regs 0x46/0x47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) switch (ir->rc_proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) case RC_PROTO_BIT_RC5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) poll_result->protocol = RC_PROTO_RC5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) poll_result->scancode = RC_SCANCODE_RC5(msg[1], msg[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) case RC_PROTO_BIT_NEC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) poll_result->protocol = RC_PROTO_NEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) poll_result->scancode = RC_SCANCODE_NEC(msg[1], msg[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) poll_result->protocol = RC_PROTO_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) poll_result->scancode = msg[1] << 8 | msg[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int em2874_polling_getkey(struct em28xx_IR *ir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct em28xx_ir_poll_result *poll_result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct em28xx *dev = ir->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) u8 msg[5] = { 0, 0, 0, 0, 0 };
^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) * Read key toggle, brand, and key code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * on registers 0x51-55
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) rc = dev->em28xx_read_reg_req_len(dev, 0, EM2874_R51_IR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) msg, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* Infrared toggle (Reg 0x51[7]) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) poll_result->toggle_bit = (msg[0] >> 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Infrared read count (Reg 0x51[6:0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) poll_result->read_count = (msg[0] & 0x7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * Remote Control Address (Reg 0x52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * Remote Control Data (Reg 0x53-0x55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) switch (ir->rc_proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) case RC_PROTO_BIT_RC5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) poll_result->protocol = RC_PROTO_RC5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) poll_result->scancode = RC_SCANCODE_RC5(msg[1], msg[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) case RC_PROTO_BIT_NEC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) poll_result->scancode = ir_nec_bytes_to_scancode(msg[1], msg[2], msg[3], msg[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) &poll_result->protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) case RC_PROTO_BIT_RC6_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) poll_result->protocol = RC_PROTO_RC6_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) poll_result->scancode = RC_SCANCODE_RC6_0(msg[1], msg[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) poll_result->protocol = RC_PROTO_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) poll_result->scancode = (msg[1] << 24) | (msg[2] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) (msg[3] << 8) | msg[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * Polling code for em28xx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static u32 scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) enum rc_proto protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) rc = ir->get_key_i2c(ir->i2c_client, &protocol, &scancode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) dprintk("ir->get_key_i2c() failed: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) dprintk("%s: proto = 0x%04x, scancode = 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) __func__, protocol, scancode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) rc_keydown(ir->rc, protocol, scancode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static void em28xx_ir_handle_key(struct em28xx_IR *ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct em28xx_ir_poll_result poll_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /* read the registers containing the IR status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) result = ir->get_key(ir, &poll_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (unlikely(result < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dprintk("ir->get_key() failed: %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (unlikely(poll_result.read_count != ir->last_readcount)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) poll_result.toggle_bit, poll_result.read_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) poll_result.scancode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (ir->full_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) rc_keydown(ir->rc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) poll_result.protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) poll_result.scancode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) poll_result.toggle_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) rc_keydown(ir->rc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) RC_PROTO_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) poll_result.scancode & 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) poll_result.toggle_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (ir->dev->chip_id == CHIP_ID_EM2874 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ir->dev->chip_id == CHIP_ID_EM2884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * The em2874 clears the readcount field every time the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * register is read. The em2860/2880 datasheet says
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * that it is supposed to clear the readcount, but it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * doesn't. So with the em2874, we are looking for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * non-zero read count as opposed to a readcount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * that is incrementing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) ir->last_readcount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) ir->last_readcount = poll_result.read_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^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) static void em28xx_ir_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (ir->i2c_client) /* external i2c device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) em28xx_i2c_ir_handle_key(ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) else /* internal device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) em28xx_ir_handle_key(ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static int em28xx_ir_start(struct rc_dev *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct em28xx_IR *ir = rc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) schedule_delayed_work(&ir->work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static void em28xx_ir_stop(struct rc_dev *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct em28xx_IR *ir = rc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) cancel_delayed_work_sync(&ir->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static int em2860_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct em28xx_IR *ir = rc_dev->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct em28xx *dev = ir->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* Adjust xclk based on IR table for RC5/NEC tables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (*rc_proto & RC_PROTO_BIT_RC5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) ir->full_code = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) *rc_proto = RC_PROTO_BIT_RC5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) } else if (*rc_proto & RC_PROTO_BIT_NEC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) ir->full_code = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) *rc_proto = RC_PROTO_BIT_NEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) } else if (*rc_proto & RC_PROTO_BIT_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) *rc_proto = RC_PROTO_BIT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) *rc_proto = ir->rc_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) EM28XX_XCLK_IR_RC5_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) ir->rc_proto = *rc_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static int em2874_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct em28xx_IR *ir = rc_dev->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct em28xx *dev = ir->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) u8 ir_config = EM2874_IR_RC5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (*rc_proto & RC_PROTO_BIT_RC5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) ir->full_code = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) *rc_proto = RC_PROTO_BIT_RC5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) } else if (*rc_proto & RC_PROTO_BIT_NEC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) ir_config = EM2874_IR_NEC | EM2874_IR_NEC_NO_PARITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) ir->full_code = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) *rc_proto = RC_PROTO_BIT_NEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) } else if (*rc_proto & RC_PROTO_BIT_RC6_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) ir_config = EM2874_IR_RC6_MODE_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) ir->full_code = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) *rc_proto = RC_PROTO_BIT_RC6_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) } else if (*rc_proto & RC_PROTO_BIT_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) *rc_proto = RC_PROTO_BIT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) *rc_proto = ir->rc_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) EM28XX_XCLK_IR_RC5_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) ir->rc_proto = *rc_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) struct em28xx_IR *ir = rc_dev->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct em28xx *dev = ir->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /* Setup the proper handler based on the chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) switch (dev->chip_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) case CHIP_ID_EM2860:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) case CHIP_ID_EM2883:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return em2860_ir_change_protocol(rc_dev, rc_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) case CHIP_ID_EM2884:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) case CHIP_ID_EM2874:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) case CHIP_ID_EM28174:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) case CHIP_ID_EM28178:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) return em2874_ir_change_protocol(rc_dev, rc_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) dev_err(&ir->dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) "Unrecognized em28xx chip id 0x%02x: IR not supported\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) dev->chip_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static int em28xx_probe_i2c_ir(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * Leadtek winfast tv USBII deluxe can find a non working IR-device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * at address 0x18, so if that address is needed for another board in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) * the future, please put it after 0x1f.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static const unsigned short addr_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 0x1f, 0x30, 0x47, I2C_CLIENT_END
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) while (addr_list[i] != I2C_CLIENT_END) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (i2c_probe_func_quick_read(&dev->i2c_adap[dev->def_i2c_bus],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) addr_list[i]) == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return addr_list[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * Handle buttons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static void em28xx_query_buttons(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) struct em28xx *dev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) container_of(work, struct em28xx, buttons_query_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) u8 i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) int regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) bool is_pressed, was_pressed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) const struct em28xx_led *led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) /* Poll and evaluate all addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) for (i = 0; i < dev->num_button_polling_addresses; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) /* Read value from register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) regval = em28xx_read_reg(dev, dev->button_polling_addresses[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (regval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* Check states of the buttons and act */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) while (dev->board.buttons[j].role >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) dev->board.buttons[j].role < EM28XX_NUM_BUTTON_ROLES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) const struct em28xx_button *button;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) button = &dev->board.buttons[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /* Check if button uses the current address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (button->reg_r != dev->button_polling_addresses[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /* Determine if button is and was pressed last time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) is_pressed = regval & button->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) was_pressed = dev->button_polling_last_values[i]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) & button->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (button->inverted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) is_pressed = !is_pressed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) was_pressed = !was_pressed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /* Clear button state (if needed) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (is_pressed && button->reg_clearing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) em28xx_write_reg(dev, button->reg_clearing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) (~regval & button->mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) | (regval & ~button->mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /* Handle button state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (!is_pressed || was_pressed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) switch (button->role) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) case EM28XX_BUTTON_SNAPSHOT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) /* Emulate the keypress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) input_report_key(dev->sbutton_input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) EM28XX_SNAPSHOT_KEY, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /* Unpress the key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) input_report_key(dev->sbutton_input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) EM28XX_SNAPSHOT_KEY, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) case EM28XX_BUTTON_ILLUMINATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) led = em28xx_find_led(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) EM28XX_LED_ILLUMINATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) /* Switch illumination LED on/off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) if (led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) em28xx_toggle_reg_bits(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) led->gpio_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) led->gpio_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) WARN_ONCE(1, "BUG: unhandled button role.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /* Next button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) /* Save current value for comparison during the next polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) dev->button_polling_last_values[i] = regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /* Schedule next poll */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) schedule_delayed_work(&dev->buttons_query_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) msecs_to_jiffies(dev->button_polling_interval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static int em28xx_register_snapshot_button(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) struct usb_device *udev = interface_to_usbdev(dev->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) dev_info(&dev->intf->dev, "Registering snapshot button...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (!input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) usb_make_path(udev, dev->snapshot_button_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) sizeof(dev->snapshot_button_path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) strlcat(dev->snapshot_button_path, "/sbutton",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) sizeof(dev->snapshot_button_path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) input_dev->name = "em28xx snapshot button";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) input_dev->phys = dev->snapshot_button_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) set_bit(EM28XX_SNAPSHOT_KEY, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) input_dev->keycodesize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) input_dev->keycodemax = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) usb_to_input_id(udev, &input_dev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) input_dev->dev.parent = &dev->intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) err = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) dev_err(&dev->intf->dev, "input_register_device failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) dev->sbutton_input_dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) static void em28xx_init_buttons(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) u8 i = 0, j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) bool addr_new = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) dev->button_polling_interval = EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) while (dev->board.buttons[i].role >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) dev->board.buttons[i].role < EM28XX_NUM_BUTTON_ROLES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) const struct em28xx_button *button = &dev->board.buttons[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) /* Check if polling address is already on the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) addr_new = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) for (j = 0; j < dev->num_button_polling_addresses; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (button->reg_r == dev->button_polling_addresses[j]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) addr_new = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) /* Check if max. number of polling addresses is exceeded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (addr_new && dev->num_button_polling_addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) >= EM28XX_NUM_BUTTON_ADDRESSES_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) WARN_ONCE(1, "BUG: maximum number of button polling addresses exceeded.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) goto next_button;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) /* Button role specific checks and actions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) if (button->role == EM28XX_BUTTON_SNAPSHOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) /* Register input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (em28xx_register_snapshot_button(dev) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) goto next_button;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) } else if (button->role == EM28XX_BUTTON_ILLUMINATION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /* Check sanity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if (!em28xx_find_led(dev, EM28XX_LED_ILLUMINATION)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) dev_err(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) "BUG: illumination button defined, but no illumination LED.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) goto next_button;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) /* Add read address to list of polling addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (addr_new) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) unsigned int index = dev->num_button_polling_addresses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) dev->button_polling_addresses[index] = button->reg_r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) dev->num_button_polling_addresses++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) /* Reduce polling interval if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (!button->reg_clearing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) dev->button_polling_interval =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) next_button:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) /* Next button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) /* Start polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (dev->num_button_polling_addresses) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) memset(dev->button_polling_last_values, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) EM28XX_NUM_BUTTON_ADDRESSES_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) schedule_delayed_work(&dev->buttons_query_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) msecs_to_jiffies(dev->button_polling_interval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) static void em28xx_shutdown_buttons(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) /* Cancel polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) cancel_delayed_work_sync(&dev->buttons_query_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) /* Clear polling addresses list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) dev->num_button_polling_addresses = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) /* Deregister input devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) if (dev->sbutton_input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) dev_info(&dev->intf->dev, "Deregistering snapshot button\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) input_unregister_device(dev->sbutton_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) dev->sbutton_input_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) static int em28xx_ir_init(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) struct usb_device *udev = interface_to_usbdev(dev->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) struct em28xx_IR *ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) struct rc_dev *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) u64 rc_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) u16 i2c_rc_dev_addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) if (dev->is_audio_only) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) /* Shouldn't initialize IR for this interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) kref_get(&dev->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) INIT_DELAYED_WORK(&dev->buttons_query_work, em28xx_query_buttons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (dev->board.buttons)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) em28xx_init_buttons(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (dev->board.has_ir_i2c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) i2c_rc_dev_addr = em28xx_probe_i2c_ir(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (!i2c_rc_dev_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) dev->board.has_ir_i2c = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) dev_warn(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) "No i2c IR remote control device found.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) goto ref_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (!dev->board.ir_codes && !dev->board.has_ir_i2c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) /* No remote control support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) dev_warn(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) "Remote control support is not available for this card.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) dev_info(&dev->intf->dev, "Registering input extension\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) ir = kzalloc(sizeof(*ir), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (!ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) goto ref_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) rc = rc_allocate_device(RC_DRIVER_SCANCODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) /* record handles to ourself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) ir->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) dev->ir = ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) ir->rc = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) rc->priv = ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) rc->open = em28xx_ir_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) rc->close = em28xx_ir_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (dev->board.has_ir_i2c) { /* external i2c device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) switch (dev->model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) case EM2800_BOARD_TERRATEC_CINERGY_200:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) case EM2820_BOARD_TERRATEC_CINERGY_250:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) rc->map_name = RC_MAP_EM_TERRATEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) ir->get_key_i2c = em28xx_get_key_terratec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) case EM2820_BOARD_PINNACLE_USB_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) rc->map_name = RC_MAP_PINNACLE_GREY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) ir->get_key_i2c = em28xx_get_key_pinnacle_usb_grey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) rc->map_name = RC_MAP_HAUPPAUGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) ir->get_key_i2c = em28xx_get_key_em_haup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) rc->allowed_protocols = RC_PROTO_BIT_RC5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) rc->map_name = RC_MAP_WINFAST_USBII_DELUXE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) ir->get_key_i2c = em28xx_get_key_winfast_usbii_deluxe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) ir->i2c_client = kzalloc(sizeof(*ir->i2c_client), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) if (!ir->i2c_client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) ir->i2c_client->adapter = &ir->dev->i2c_adap[dev->def_i2c_bus];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) ir->i2c_client->addr = i2c_rc_dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) ir->i2c_client->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) /* NOTE: all other fields of i2c_client are unused */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) } else { /* internal device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) switch (dev->chip_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) case CHIP_ID_EM2860:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) case CHIP_ID_EM2883:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) rc->allowed_protocols = RC_PROTO_BIT_RC5 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) RC_PROTO_BIT_NEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) ir->get_key = default_polling_getkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) case CHIP_ID_EM2884:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) case CHIP_ID_EM2874:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) case CHIP_ID_EM28174:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) case CHIP_ID_EM28178:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) ir->get_key = em2874_polling_getkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) rc->allowed_protocols = RC_PROTO_BIT_RC5 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) RC_PROTO_BIT_NEC | RC_PROTO_BIT_NECX |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) RC_PROTO_BIT_NEC32 | RC_PROTO_BIT_RC6_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) rc->change_protocol = em28xx_ir_change_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) rc->map_name = dev->board.ir_codes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) /* By default, keep protocol field untouched */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) rc_proto = RC_PROTO_BIT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) err = em28xx_ir_change_protocol(rc, &rc_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /* This is how often we ask the chip for IR information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) ir->polling = 100; /* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) usb_make_path(udev, ir->phys, sizeof(ir->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) strlcat(ir->phys, "/input0", sizeof(ir->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) rc->device_name = em28xx_boards[dev->model].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) rc->input_phys = ir->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) usb_to_input_id(udev, &rc->input_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) rc->dev.parent = &dev->intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) rc->driver_name = MODULE_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) /* all done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) err = rc_register_device(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) dev_info(&dev->intf->dev, "Input extension successfully initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) kfree(ir->i2c_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) dev->ir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) rc_free_device(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) kfree(ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) ref_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) em28xx_shutdown_buttons(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) static int em28xx_ir_fini(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) struct em28xx_IR *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (dev->is_audio_only) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) /* Shouldn't initialize IR for this interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) dev_info(&dev->intf->dev, "Closing input extension\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) em28xx_shutdown_buttons(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) /* skip detach on non attached boards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) if (!ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) goto ref_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) rc_unregister_device(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) kfree(ir->i2c_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) /* done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) kfree(ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) dev->ir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) ref_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) kref_put(&dev->ref, em28xx_free_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) static int em28xx_ir_suspend(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) struct em28xx_IR *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if (dev->is_audio_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) dev_info(&dev->intf->dev, "Suspending input extension\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if (ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) cancel_delayed_work_sync(&ir->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) cancel_delayed_work_sync(&dev->buttons_query_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) * is canceling delayed work sufficient or does the rc event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) * kthread needs stopping? kthread is stopped in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) * ir_raw_event_unregister()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) static int em28xx_ir_resume(struct em28xx *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) struct em28xx_IR *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (dev->is_audio_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) dev_info(&dev->intf->dev, "Resuming input extension\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) * if suspend calls ir_raw_event_unregister(), the should call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) * ir_raw_event_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) if (dev->num_button_polling_addresses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) schedule_delayed_work(&dev->buttons_query_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) msecs_to_jiffies(dev->button_polling_interval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) static struct em28xx_ops rc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) .id = EM28XX_RC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) .name = "Em28xx Input Extension",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) .init = em28xx_ir_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) .fini = em28xx_ir_fini,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) .suspend = em28xx_ir_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) .resume = em28xx_ir_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) static int __init em28xx_rc_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) return em28xx_register_extension(&rc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) static void __exit em28xx_rc_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) em28xx_unregister_extension(&rc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) MODULE_AUTHOR("Mauro Carvalho Chehab");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) MODULE_DESCRIPTION(DRIVER_DESC " - input interface");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) MODULE_VERSION(EM28XX_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) module_init(em28xx_rc_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) module_exit(em28xx_rc_unregister);