Commit 71f49a8b authored by Sean Young's avatar Sean Young Committed by Mauro Carvalho Chehab

media: ttpci: use rc-core for the IR receiver

The IR protocol can now only be set via the rc protocols sysfs file rather
than via module parameters or a custom procfs file. So, it is no longer
necessary to periodically check for protocol changes.

The IR_RCMM protocol does not decode the Philips RC-MM protocol (12, 24 or
32 bit variants) or any protocol rc-core can encode, so this is marked
RC_PROTO_UNKNOWN.

Tested on Technotrend/Hauppauge WinTV Nexus-S rev2.1, which comes
with a small black hauppauge remote.
Signed-off-by: default avatarSean Young <sean@mess.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent eb5005df
...@@ -218,7 +218,7 @@ static void recover_arm(struct av7110 *av7110) ...@@ -218,7 +218,7 @@ static void recover_arm(struct av7110 *av7110)
restart_feeds(av7110); restart_feeds(av7110);
#if IS_ENABLED(CONFIG_DVB_AV7110_IR) #if IS_ENABLED(CONFIG_DVB_AV7110_IR)
av7110_check_ir_config(av7110, true); av7110_set_ir_config(av7110);
#endif #endif
} }
...@@ -250,10 +250,6 @@ static int arm_thread(void *data) ...@@ -250,10 +250,6 @@ static int arm_thread(void *data)
if (!av7110->arm_ready) if (!av7110->arm_ready)
continue; continue;
#if IS_ENABLED(CONFIG_DVB_AV7110_IR)
av7110_check_ir_config(av7110, false);
#endif
if (mutex_lock_interruptible(&av7110->dcomlock)) if (mutex_lock_interruptible(&av7110->dcomlock))
break; break;
newloops = rdebi(av7110, DEBINOSWAP, STATUS_LOOPS, 0, 2); newloops = rdebi(av7110, DEBINOSWAP, STATUS_LOOPS, 0, 2);
...@@ -659,9 +655,11 @@ static void gpioirq(unsigned long cookie) ...@@ -659,9 +655,11 @@ static void gpioirq(unsigned long cookie)
return; return;
case DATA_IRCOMMAND: case DATA_IRCOMMAND:
if (av7110->ir.ir_handler) #if IS_ENABLED(CONFIG_DVB_AV7110_IR)
av7110->ir.ir_handler(av7110, av7110_ir_handler(av7110,
swahw32(irdebi(av7110, DEBINOSWAP, Reserved, 0, 4))); swahw32(irdebi(av7110, DEBINOSWAP, Reserved,
0, 4)));
#endif
iwdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2); iwdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2);
break; break;
......
...@@ -81,23 +81,11 @@ struct av7110; ...@@ -81,23 +81,11 @@ struct av7110;
/* infrared remote control */ /* infrared remote control */
struct infrared { struct infrared {
u16 key_map[256]; struct rc_dev *rcdev;
struct input_dev *input_dev;
char input_phys[32]; char input_phys[32];
struct timer_list keyup_timer;
struct tasklet_struct ir_tasklet;
void (*ir_handler)(struct av7110 *av7110, u32 ircom);
u32 ir_command;
u32 ir_config; u32 ir_config;
u32 device_mask;
u8 protocol;
u8 inversion;
u16 last_key;
u16 last_toggle;
bool keypressed;
}; };
/* place to store all the necessary device information */ /* place to store all the necessary device information */
struct av7110 { struct av7110 {
...@@ -304,9 +292,10 @@ struct av7110 { ...@@ -304,9 +292,10 @@ struct av7110 {
extern int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid, extern int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
u16 subpid, u16 pcrpid); u16 subpid, u16 pcrpid);
extern int av7110_check_ir_config(struct av7110 *av7110, int force); void av7110_ir_handler(struct av7110 *av7110, u32 ircom);
extern int av7110_ir_init(struct av7110 *av7110); int av7110_set_ir_config(struct av7110 *av7110);
extern void av7110_ir_exit(struct av7110 *av7110); int av7110_ir_init(struct av7110 *av7110);
void av7110_ir_exit(struct av7110 *av7110);
/* msp3400 i2c subaddresses */ /* msp3400 i2c subaddresses */
#define MSP_WR_DEM 0x10 #define MSP_WR_DEM 0x10
......
...@@ -4,379 +4,156 @@ ...@@ -4,379 +4,156 @@
* *
* Copyright (C) 1999-2003 Holger Waechtler <holger@convergence.de> * Copyright (C) 1999-2003 Holger Waechtler <holger@convergence.de>
* Copyright (C) 2003-2007 Oliver Endriss <o.endriss@gmx.de> * Copyright (C) 2003-2007 Oliver Endriss <o.endriss@gmx.de>
* Copyright (C) 2019 Sean Young <sean@mess.org>
*/ */
#include <linux/types.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/bitops.h> #include <media/rc-core.h>
#include "av7110.h" #include "av7110.h"
#include "av7110_hw.h" #include "av7110_hw.h"
#define AV_CNT 4
#define IR_RC5 0 #define IR_RC5 0
#define IR_RCMM 1 #define IR_RCMM 1
#define IR_RC5_EXT 2 /* internal only */ #define IR_RC5_EXT 2 /* internal only */
#define IR_ALL 0xffffffff /* interrupt handler */
void av7110_ir_handler(struct av7110 *av7110, u32 ircom)
#define UP_TIMEOUT (HZ*7/25)
/* Note: enable ir debugging by or'ing debug with 16 */
static int ir_protocol[AV_CNT] = { IR_RCMM, IR_RCMM, IR_RCMM, IR_RCMM};
module_param_array(ir_protocol, int, NULL, 0644);
MODULE_PARM_DESC(ir_protocol, "Infrared protocol: 0 RC5, 1 RCMM (default)");
static int ir_inversion[AV_CNT];
module_param_array(ir_inversion, int, NULL, 0644);
MODULE_PARM_DESC(ir_inversion, "Inversion of infrared signal: 0 not inverted (default), 1 inverted");
static uint ir_device_mask[AV_CNT] = { IR_ALL, IR_ALL, IR_ALL, IR_ALL };
module_param_array(ir_device_mask, uint, NULL, 0644);
MODULE_PARM_DESC(ir_device_mask, "Bitmask of infrared devices: bit 0..31 = device 0..31 (default: all)");
static int av_cnt;
static struct av7110 *av_list[AV_CNT];
static u16 default_key_map [256] = {
KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7,
KEY_8, KEY_9, KEY_BACK, 0, KEY_POWER, KEY_MUTE, 0, KEY_INFO,
KEY_VOLUMEUP, KEY_VOLUMEDOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
KEY_CHANNELUP, KEY_CHANNELDOWN, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, KEY_TEXT, 0, 0, KEY_TV, 0, 0, 0, 0, 0, KEY_SETUP, 0, 0,
0, 0, 0, KEY_SUBTITLE, 0, 0, KEY_LANGUAGE, 0,
KEY_RADIO, 0, 0, 0, 0, KEY_EXIT, 0, 0,
KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_OK, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RED, KEY_GREEN, KEY_YELLOW,
KEY_BLUE, 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_LIST, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, KEY_UP, KEY_UP, KEY_DOWN, KEY_DOWN,
0, 0, 0, 0, KEY_EPG, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_VCR
};
/* key-up timer */
static void av7110_emit_keyup(struct timer_list *t)
{
struct infrared *ir = from_timer(ir, t, keyup_timer);
if (!ir || !ir->keypressed)
return;
input_report_key(ir->input_dev, ir->last_key, 0);
input_sync(ir->input_dev);
ir->keypressed = false;
}
/* tasklet */
static void av7110_emit_key(unsigned long parm)
{ {
struct infrared *ir = (struct infrared *) parm; struct rc_dev *rcdev = av7110->ir.rcdev;
u32 ircom = ir->ir_command; enum rc_proto proto;
u8 data; u32 command, addr, scancode;
u8 addr; u32 toggle;
u16 toggle;
u16 keycode;
/* extract device address and data */
switch (ir->protocol) {
case IR_RC5: /* RC5: 5 bits device address, 6 bits data */
data = ircom & 0x3f;
addr = (ircom >> 6) & 0x1f;
toggle = ircom & 0x0800;
break;
case IR_RCMM: /* RCMM: ? bits device address, ? bits data */ dprintk(4, "ir command = %08x\n", ircom);
data = ircom & 0xff;
addr = (ircom >> 8) & 0x1f;
toggle = ircom & 0x8000;
break;
case IR_RC5_EXT: /* extended RC5: 5 bits device address, 7 bits data */
data = ircom & 0x3f;
addr = (ircom >> 6) & 0x1f;
/* invert 7th data bit for backward compatibility with RC5 keymaps */
if (!(ircom & 0x1000))
data |= 0x40;
toggle = ircom & 0x0800;
break;
default:
printk("%s invalid protocol %x\n", __func__, ir->protocol);
return;
}
input_event(ir->input_dev, EV_MSC, MSC_RAW, (addr << 16) | data);
input_event(ir->input_dev, EV_MSC, MSC_SCAN, data);
keycode = ir->key_map[data];
dprintk(16, "%s: code %08x -> addr %i data 0x%02x -> keycode %i\n",
__func__, ircom, addr, data, keycode);
/* check device address */
if (!(ir->device_mask & (1 << addr)))
return;
if (!keycode) {
printk ("%s: code %08x -> addr %i data 0x%02x -> unknown key!\n",
__func__, ircom, addr, data);
return;
}
if (ir->keypressed &&
(ir->last_key != keycode || toggle != ir->last_toggle))
input_event(ir->input_dev, EV_KEY, ir->last_key, 0);
input_event(ir->input_dev, EV_KEY, keycode, 1);
input_sync(ir->input_dev);
ir->keypressed = true;
ir->last_key = keycode;
ir->last_toggle = toggle;
mod_timer(&ir->keyup_timer, jiffies + UP_TIMEOUT);
}
/* register with input layer */
static void input_register_keys(struct infrared *ir)
{
int i;
set_bit(EV_KEY, ir->input_dev->evbit); if (rcdev) {
set_bit(EV_REP, ir->input_dev->evbit); switch (av7110->ir.ir_config) {
set_bit(EV_MSC, ir->input_dev->evbit); case IR_RC5: /* RC5: 5 bits device address, 6 bits command */
command = ircom & 0x3f;
addr = (ircom >> 6) & 0x1f;
scancode = RC_SCANCODE_RC5(addr, command);
toggle = ircom & 0x0800;
proto = RC_PROTO_RC5;
break;
set_bit(MSC_RAW, ir->input_dev->mscbit); case IR_RCMM: /* RCMM: ? bits device address, ? bits command */
set_bit(MSC_SCAN, ir->input_dev->mscbit); command = ircom & 0xff;
addr = (ircom >> 8) & 0x1f;
scancode = ircom;
toggle = ircom & 0x8000;
proto = RC_PROTO_UNKNOWN;
break;
memset(ir->input_dev->keybit, 0, sizeof(ir->input_dev->keybit)); case IR_RC5_EXT:
/*
* extended RC5: 5 bits device address, 7 bits command
*
* Extended RC5 uses only one start bit. The second
* start bit is re-assigned bit 6 of the command bit.
*/
command = ircom & 0x3f;
addr = (ircom >> 6) & 0x1f;
if (!(ircom & 0x1000))
command |= 0x40;
scancode = RC_SCANCODE_RC5(addr, command);
toggle = ircom & 0x0800;
proto = RC_PROTO_RC5;
break;
default:
dprintk(2, "unknown ir config %d\n",
av7110->ir.ir_config);
return;
}
for (i = 0; i < ARRAY_SIZE(ir->key_map); i++) { rc_keydown(rcdev, proto, scancode, toggle != 0);
if (ir->key_map[i] > KEY_MAX)
ir->key_map[i] = 0;
else if (ir->key_map[i] > KEY_RESERVED)
set_bit(ir->key_map[i], ir->input_dev->keybit);
} }
ir->input_dev->keycode = ir->key_map;
ir->input_dev->keycodesize = sizeof(ir->key_map[0]);
ir->input_dev->keycodemax = ARRAY_SIZE(ir->key_map);
} }
/* check for configuration changes */ int av7110_set_ir_config(struct av7110 *av7110)
int av7110_check_ir_config(struct av7110 *av7110, int force)
{ {
int i; dprintk(4, "ir config = %08x\n", av7110->ir.ir_config);
int modified = force;
int ret = -ENODEV;
for (i = 0; i < av_cnt; i++)
if (av7110 == av_list[i])
break;
if (i < av_cnt && av7110) {
if ((av7110->ir.protocol & 1) != ir_protocol[i] ||
av7110->ir.inversion != ir_inversion[i])
modified = true;
if (modified) {
/* protocol */
if (ir_protocol[i]) {
ir_protocol[i] = 1;
av7110->ir.protocol = IR_RCMM;
av7110->ir.ir_config = 0x0001;
} else if (FW_VERSION(av7110->arm_app) >= 0x2620) {
av7110->ir.protocol = IR_RC5_EXT;
av7110->ir.ir_config = 0x0002;
} else {
av7110->ir.protocol = IR_RC5;
av7110->ir.ir_config = 0x0000;
}
/* inversion */
if (ir_inversion[i]) {
ir_inversion[i] = 1;
av7110->ir.ir_config |= 0x8000;
}
av7110->ir.inversion = ir_inversion[i];
/* update ARM */
ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetIR, 1,
av7110->ir.ir_config);
} else
ret = 0;
/* address */ return av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetIR, 1,
if (av7110->ir.device_mask != ir_device_mask[i]) av7110->ir.ir_config);
av7110->ir.device_mask = ir_device_mask[i];
}
return ret;
} }
static int change_protocol(struct rc_dev *rcdev, u64 *rc_type)
/* /proc/av7110_ir interface */
static ssize_t av7110_ir_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *pos)
{ {
char *page; struct av7110 *av7110 = rcdev->priv;
u32 ir_config; u32 ir_config;
int size = sizeof ir_config + sizeof av_list[0]->ir.key_map;
int i;
if (count < size) if (*rc_type & RC_PROTO_BIT_UNKNOWN) {
ir_config = IR_RCMM;
*rc_type = RC_PROTO_UNKNOWN;
} else if (*rc_type & RC_PROTO_BIT_RC5) {
if (FW_VERSION(av7110->arm_app) >= 0x2620)
ir_config = IR_RC5_EXT;
else
ir_config = IR_RC5;
*rc_type = RC_PROTO_BIT_RC5;
} else {
return -EINVAL; return -EINVAL;
page = vmalloc(size);
if (!page)
return -ENOMEM;
if (copy_from_user(page, buffer, size)) {
vfree(page);
return -EFAULT;
} }
memcpy(&ir_config, page, sizeof ir_config); if (ir_config == av7110->ir.ir_config)
return 0;
for (i = 0; i < av_cnt; i++) {
/* keymap */
memcpy(av_list[i]->ir.key_map, page + sizeof ir_config,
sizeof(av_list[i]->ir.key_map));
/* protocol, inversion, address */
ir_protocol[i] = ir_config & 0x0001;
ir_inversion[i] = ir_config & 0x8000 ? 1 : 0;
if (ir_config & 0x4000)
ir_device_mask[i] = 1 << ((ir_config >> 16) & 0x1f);
else
ir_device_mask[i] = IR_ALL;
/* update configuration */
av7110_check_ir_config(av_list[i], false);
input_register_keys(&av_list[i]->ir);
}
vfree(page);
return count;
}
static const struct file_operations av7110_ir_proc_fops = { av7110->ir.ir_config = ir_config;
.owner = THIS_MODULE,
.write = av7110_ir_proc_write,
.llseek = noop_llseek,
};
/* interrupt handler */ return av7110_set_ir_config(av7110);
static void ir_handler(struct av7110 *av7110, u32 ircom)
{
dprintk(4, "ir command = %08x\n", ircom);
av7110->ir.ir_command = ircom;
tasklet_schedule(&av7110->ir.ir_tasklet);
} }
int av7110_ir_init(struct av7110 *av7110) int av7110_ir_init(struct av7110 *av7110)
{ {
struct input_dev *input_dev; struct rc_dev *rcdev;
static struct proc_dir_entry *e; struct pci_dev *pci;
int err; int ret;
if (av_cnt >= ARRAY_SIZE(av_list))
return -ENOSPC;
av_list[av_cnt++] = av7110; rcdev = rc_allocate_device(RC_DRIVER_SCANCODE);
av7110_check_ir_config(av7110, true); if (!rcdev)
timer_setup(&av7110->ir.keyup_timer, av7110_emit_keyup, 0);
input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM; return -ENOMEM;
av7110->ir.input_dev = input_dev; pci = av7110->dev->pci;
snprintf(av7110->ir.input_phys, sizeof(av7110->ir.input_phys),
"pci-%s/ir0", pci_name(av7110->dev->pci));
input_dev->name = "DVB on-card IR receiver"; snprintf(av7110->ir.input_phys, sizeof(av7110->ir.input_phys),
"pci-%s/ir0", pci_name(pci));
input_dev->phys = av7110->ir.input_phys;
input_dev->id.bustype = BUS_PCI; rcdev->device_name = av7110->card_name;
input_dev->id.version = 2; rcdev->driver_name = KBUILD_MODNAME;
if (av7110->dev->pci->subsystem_vendor) { rcdev->input_phys = av7110->ir.input_phys;
input_dev->id.vendor = av7110->dev->pci->subsystem_vendor; rcdev->input_id.bustype = BUS_PCI;
input_dev->id.product = av7110->dev->pci->subsystem_device; rcdev->input_id.version = 2;
if (pci->subsystem_vendor) {
rcdev->input_id.vendor = pci->subsystem_vendor;
rcdev->input_id.product = pci->subsystem_device;
} else { } else {
input_dev->id.vendor = av7110->dev->pci->vendor; rcdev->input_id.vendor = pci->vendor;
input_dev->id.product = av7110->dev->pci->device; rcdev->input_id.product = pci->device;
}
input_dev->dev.parent = &av7110->dev->pci->dev;
/* initial keymap */
memcpy(av7110->ir.key_map, default_key_map, sizeof av7110->ir.key_map);
input_register_keys(&av7110->ir);
err = input_register_device(input_dev);
if (err) {
input_free_device(input_dev);
return err;
} }
/* rcdev->dev.parent = &pci->dev;
* Input core's default autorepeat is 33 cps with 250 msec rcdev->allowed_protocols = RC_PROTO_BIT_RC5 | RC_PROTO_BIT_UNKNOWN;
* delay, let's adjust to numbers more suitable for remote rcdev->change_protocol = change_protocol;
* control. rcdev->map_name = RC_MAP_HAUPPAUGE;
*/ rcdev->priv = av7110;
input_enable_softrepeat(input_dev, 250, 125);
if (av_cnt == 1) { av7110->ir.rcdev = rcdev;
e = proc_create("av7110_ir", S_IWUSR, NULL, &av7110_ir_proc_fops); av7110->ir.ir_config = IR_RC5;
if (e) av7110_set_ir_config(av7110);
proc_set_size(e, 4 + 256 * sizeof(u16));
}
tasklet_init(&av7110->ir.ir_tasklet, av7110_emit_key, (unsigned long) &av7110->ir); ret = rc_register_device(rcdev);
av7110->ir.ir_handler = ir_handler; if (ret) {
av7110->ir.rcdev = NULL;
rc_free_device(rcdev);
}
return 0; return ret;
} }
void av7110_ir_exit(struct av7110 *av7110) void av7110_ir_exit(struct av7110 *av7110)
{ {
int i; rc_unregister_device(av7110->ir.rcdev);
if (av_cnt == 0)
return;
del_timer_sync(&av7110->ir.keyup_timer);
av7110->ir.ir_handler = NULL;
tasklet_kill(&av7110->ir.ir_tasklet);
for (i = 0; i < av_cnt; i++)
if (av_list[i] == av7110) {
av_list[i] = av_list[av_cnt-1];
av_list[av_cnt-1] = NULL;
break;
}
if (av_cnt == 1)
remove_proc_entry("av7110_ir", NULL);
input_unregister_device(av7110->ir.input_dev);
av_cnt--;
} }
//MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>, Oliver Endriss <o.endriss@gmx.de>"); //MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>, Oliver Endriss <o.endriss@gmx.de>");
......
...@@ -233,6 +233,7 @@ static struct rc_map_table rc5_hauppauge_new[] = { ...@@ -233,6 +233,7 @@ static struct rc_map_table rc5_hauppauge_new[] = {
* This one also uses RC-5 protocol * This one also uses RC-5 protocol
* Keycodes start with address = 0x00 * Keycodes start with address = 0x00
*/ */
{ 0x000f, KEY_TV },
{ 0x001f, KEY_TV }, { 0x001f, KEY_TV },
{ 0x0020, KEY_CHANNELUP }, { 0x0020, KEY_CHANNELUP },
{ 0x000c, KEY_RADIO }, { 0x000c, KEY_RADIO },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment