^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * tm6000-input.c - driver for TM5600/TM6000/TM6010 USB video capture devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2010 Stefan Ringel <stefan.ringel@arcor.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <media/rc-core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "tm6000.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "tm6000-regs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static unsigned int ir_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) module_param(ir_debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) MODULE_PARM_DESC(ir_debug, "debug message level");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static unsigned int enable_ir = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) module_param(enable_ir, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) MODULE_PARM_DESC(enable_ir, "enable ir (default is enable)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static unsigned int ir_clock_mhz = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) module_param(ir_clock_mhz, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) MODULE_PARM_DESC(ir_clock_mhz, "ir clock, in MHz");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define URB_SUBMIT_DELAY 100 /* ms - Delay to submit an URB request on retrial and init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define URB_INT_LED_DELAY 100 /* ms - Delay to turn led on again on int mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #undef dprintk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define dprintk(level, fmt, arg...) do {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (ir_debug >= level) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct tm6000_ir_poll_result {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) u16 rc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct tm6000_IR {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct tm6000_core *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct rc_dev *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) char name[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* poll expernal decoder */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int polling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct delayed_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u8 wait:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u8 pwled:2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) u8 submit_urb:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct urb *int_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* IR device properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u64 rc_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) void tm6000_ir_wait(struct tm6000_core *dev, u8 state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct tm6000_IR *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (!dev->ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) dprintk(2, "%s: %i\n",__func__, ir->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ir->wait = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ir->wait = 0;
^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) static int tm6000_ir_config(struct tm6000_IR *ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct tm6000_core *dev = ir->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u32 pulse = 0, leader = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) dprintk(2, "%s\n",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * The IR decoder supports RC-5 or NEC, with a configurable timing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * The timing configuration there is not that accurate, as it uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * approximate values. The NEC spec mentions a 562.5 unit period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * and RC-5 uses a 888.8 period.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Currently, driver assumes a clock provided by a 12 MHz XTAL, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * a modprobe parameter can adjust it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * Adjustments are required for other timings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * It seems that the 900ms timing for NEC is used to detect a RC-5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * IR, in order to discard such decoding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) switch (ir->rc_proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) case RC_PROTO_BIT_NEC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) leader = 900; /* ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) pulse = 700; /* ms - the actual value would be 562 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) case RC_PROTO_BIT_RC5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) leader = 900; /* ms - from the NEC decoding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) pulse = 1780; /* ms - The actual value would be 1776 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) pulse = ir_clock_mhz * pulse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) leader = ir_clock_mhz * leader;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (ir->rc_proto == RC_PROTO_BIT_NEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) leader = leader | 0x8000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) dprintk(2, "%s: %s, %d MHz, leader = 0x%04x, pulse = 0x%06x \n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) (ir->rc_proto == RC_PROTO_BIT_NEC) ? "NEC" : "RC-5",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ir_clock_mhz, leader, pulse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* Remote WAKEUP = enable, normal mode, from IR decoder output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) tm6000_set_reg(dev, TM6010_REQ07_RE5_REMOTE_WAKEUP, 0xfe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* Enable IR reception on non-busrt mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) tm6000_set_reg(dev, TM6010_REQ07_RD8_IR, 0x2f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* IR_WKUP_SEL = Low byte in decoded IR data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) tm6000_set_reg(dev, TM6010_REQ07_RDA_IR_WAKEUP_SEL, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* IR_WKU_ADD code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) tm6000_set_reg(dev, TM6010_REQ07_RDB_IR_WAKEUP_ADD, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) tm6000_set_reg(dev, TM6010_REQ07_RDC_IR_LEADER1, leader >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) tm6000_set_reg(dev, TM6010_REQ07_RDD_IR_LEADER0, leader);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) tm6000_set_reg(dev, TM6010_REQ07_RDE_IR_PULSE_CNT1, pulse >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) tm6000_set_reg(dev, TM6010_REQ07_RDF_IR_PULSE_CNT0, pulse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!ir->polling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* Shows that IR is working via the LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) tm6000_flash_led(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) tm6000_flash_led(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ir->pwled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static void tm6000_ir_keydown(struct tm6000_IR *ir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) const char *buf, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) u8 device, command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) u32 scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) enum rc_proto protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (len < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) command = buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) device = (len > 1 ? buf[1] : 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) switch (ir->rc_proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) case RC_PROTO_BIT_RC5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) protocol = RC_PROTO_RC5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) scancode = RC_SCANCODE_RC5(device, command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) case RC_PROTO_BIT_NEC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) protocol = RC_PROTO_NEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) scancode = RC_SCANCODE_NEC(device, command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) protocol = RC_PROTO_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) scancode = RC_SCANCODE_OTHER(device << 8 | command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) dprintk(1, "%s, protocol: 0x%04x, scancode: 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) __func__, protocol, scancode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) rc_keydown(ir->rc, protocol, scancode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static void tm6000_ir_urb_received(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct tm6000_core *dev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct tm6000_IR *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) dprintk(2, "%s\n",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (urb->status < 0 || urb->actual_length <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) printk(KERN_INFO "tm6000: IR URB failure: status: %i, length %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) urb->status, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ir->submit_urb = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) schedule_delayed_work(&ir->work, msecs_to_jiffies(URB_SUBMIT_DELAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) buf = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (ir_debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) print_hex_dump(KERN_DEBUG, "tm6000: IR data: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) DUMP_PREFIX_OFFSET,16, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) buf, urb->actual_length, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) tm6000_ir_keydown(ir, urb->transfer_buffer, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * Flash the led. We can't do it here, as it is running on IRQ context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * So, use the scheduler to do it, in a few ms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ir->pwled = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) schedule_delayed_work(&ir->work, msecs_to_jiffies(10));
^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 tm6000_ir_handle_key(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 tm6000_IR *ir = container_of(work, struct tm6000_IR, work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct tm6000_core *dev = ir->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) u8 buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (ir->wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) dprintk(3, "%s\n",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) rc = tm6000_read_write_usb(dev, USB_DIR_IN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) USB_TYPE_VENDOR | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) REQ_02_GET_IR_CODE, 0, 0, buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* Check if something was read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if ((buf[0] & 0xff) == 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (!ir->pwled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) tm6000_flash_led(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) ir->pwled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) tm6000_ir_keydown(ir, buf, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) tm6000_flash_led(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ir->pwled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* Re-schedule polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static void tm6000_ir_int_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct tm6000_IR *ir = container_of(work, struct tm6000_IR, work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct tm6000_core *dev = ir->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) dprintk(3, "%s, submit_urb = %d, pwled = %d\n",__func__, ir->submit_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ir->pwled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (ir->submit_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) dprintk(3, "Resubmit urb\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) rc = usb_submit_urb(ir->int_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) printk(KERN_ERR "tm6000: Can't submit an IR interrupt. Error %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* Retry in 100 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) schedule_delayed_work(&ir->work, msecs_to_jiffies(URB_SUBMIT_DELAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ir->submit_urb = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* Led is enabled only if USB submit doesn't fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (ir->pwled == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) tm6000_flash_led(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ir->pwled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) schedule_delayed_work(&ir->work, msecs_to_jiffies(URB_INT_LED_DELAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) } else if (!ir->pwled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) tm6000_flash_led(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) ir->pwled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static int tm6000_ir_start(struct rc_dev *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct tm6000_IR *ir = rc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) dprintk(2, "%s\n",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) schedule_delayed_work(&ir->work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static void tm6000_ir_stop(struct rc_dev *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct tm6000_IR *ir = rc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) dprintk(2, "%s\n",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) cancel_delayed_work_sync(&ir->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int tm6000_ir_change_protocol(struct rc_dev *rc, u64 *rc_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct tm6000_IR *ir = rc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (!ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) dprintk(2, "%s\n",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ir->rc_proto = *rc_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) tm6000_ir_config(ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* TODO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int __tm6000_ir_int_start(struct rc_dev *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct tm6000_IR *ir = rc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct tm6000_core *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) int pipe, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (!ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dev = ir->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) dprintk(2, "%s\n",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) ir->int_urb = usb_alloc_urb(0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (!ir->int_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) pipe = usb_rcvintpipe(dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) dev->int_in.endp->desc.bEndpointAddress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) & USB_ENDPOINT_NUMBER_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) dprintk(1, "IR max size: %d\n", size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) ir->int_urb->transfer_buffer = kzalloc(size, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (!ir->int_urb->transfer_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) usb_free_urb(ir->int_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) dprintk(1, "int interval: %d\n", dev->int_in.endp->desc.bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) usb_fill_int_urb(ir->int_urb, dev->udev, pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) ir->int_urb->transfer_buffer, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) tm6000_ir_urb_received, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) dev->int_in.endp->desc.bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) ir->submit_urb = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) schedule_delayed_work(&ir->work, msecs_to_jiffies(URB_SUBMIT_DELAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) static void __tm6000_ir_int_stop(struct rc_dev *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct tm6000_IR *ir = rc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (!ir || !ir->int_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) dprintk(2, "%s\n",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) usb_kill_urb(ir->int_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) kfree(ir->int_urb->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) usb_free_urb(ir->int_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) ir->int_urb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) int tm6000_ir_int_start(struct tm6000_core *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct tm6000_IR *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (!ir)
^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) return __tm6000_ir_int_start(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) void tm6000_ir_int_stop(struct tm6000_core *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct tm6000_IR *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (!ir || !ir->rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) __tm6000_ir_int_stop(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int tm6000_ir_init(struct tm6000_core *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct tm6000_IR *ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct rc_dev *rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) u64 rc_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (!enable_ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (!dev->caps.has_remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (!dev->ir_codes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) ir = kzalloc(sizeof(*ir), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) rc = rc_allocate_device(RC_DRIVER_SCANCODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (!ir || !rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) dprintk(2, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) /* record handles to ourself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) ir->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) dev->ir = ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) ir->rc = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* input setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) rc->allowed_protocols = RC_PROTO_BIT_RC5 | RC_PROTO_BIT_NEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /* Needed, in order to support NEC remotes with 24 or 32 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) rc->scancode_mask = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) rc->priv = ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) rc->change_protocol = tm6000_ir_change_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (dev->int_in.endp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) rc->open = __tm6000_ir_int_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) rc->close = __tm6000_ir_int_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) INIT_DELAYED_WORK(&ir->work, tm6000_ir_int_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) rc->open = tm6000_ir_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) rc->close = tm6000_ir_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) ir->polling = 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) INIT_DELAYED_WORK(&ir->work, tm6000_ir_handle_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) snprintf(ir->name, sizeof(ir->name), "tm5600/60x0 IR (%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) strlcat(ir->phys, "/input0", sizeof(ir->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) rc_proto = RC_PROTO_BIT_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) tm6000_ir_change_protocol(rc, &rc_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) rc->device_name = ir->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) rc->input_phys = ir->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) rc->input_id.bustype = BUS_USB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) rc->input_id.version = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) rc->map_name = dev->ir_codes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) rc->driver_name = "tm6000";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) rc->dev.parent = &dev->udev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /* ir register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) err = rc_register_device(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) dev->ir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) rc_free_device(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) kfree(ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) int tm6000_ir_fini(struct tm6000_core *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct tm6000_IR *ir = dev->ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) /* skip detach on non attached board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (!ir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) dprintk(2, "%s\n",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (!ir->polling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) __tm6000_ir_int_stop(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) tm6000_ir_stop(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /* Turn off the led */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) tm6000_flash_led(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) ir->pwled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) rc_unregister_device(ir->rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) kfree(ir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) dev->ir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }