/*
*
* keyboard input driver for i2c IR remote controls
*
* Copyright (c) 2000-2003 Gerd Knorr <kraxel@bytesex.org>
* modified for PixelView (BT878P+W/FM) by
* Michal Kochanowicz <mkochano@pld.org.pl>
* Christoph Bartelmus <lirc@bartelmus.de>
* modified for KNC ONE TV Station/Anubis Typhoon TView Tuner by
* Ulrich Mueller <ulrich.mueller42@web.de>
* modified for em2820 based USB TV tuners by
* Markus Rechberger <mrechberger@gmail.com>
* modified for DViCO Fusion HDTV 5 RT GOLD by
* Chaogui Zhang <czhang1974@gmail.com>
* modified for MSI TV@nywhere Plus by
* Henry Wong <henry@stuffedcow.net>
* Mark Schultz <n9xmj@yahoo.com>
* Brian Rogers <brian_rogers@comcast.net>
* modified for AVerMedia Cardbus by
* Oldrich Jedlicka <oldium.pro@seznam.cz>
* Zilog Transmitter portions/ideas were derived from GPLv2+ sources:
* - drivers/char/pctv_zilogir.[ch] from Hauppauge Broadway product
* Copyright 2011 Hauppauge Computer works
* - drivers/staging/media/lirc/lirc_zilog.c
* Copyright (c) 2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
* Michal Kochanowicz <mkochano@pld.org.pl>
* Christoph Bartelmus <lirc@bartelmus.de>
* Ulrich Mueller <ulrich.mueller42@web.de>
* Stefan Jahn <stefan@lkcc.org>
* Jerome Brock <jbrock@users.sourceforge.net>
* Thomas Reitmayr (treitmayr@yahoo.com)
* Mark Weaver <mark@npsl.co.uk>
* Jarod Wilson <jarod@redhat.com>
* Copyright (C) 2011 Andy Walls <awalls@md.metrocast.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <asm/unaligned.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/workqueue.h>
#include <media/rc-core.h>
#include <media/i2c/ir-kbd-i2c.h>
#define FLAG_TX 1
#define FLAG_HDPVR 2
static bool enable_hdpvr;
module_param(enable_hdpvr, bool, 0644);
static int get_key_haup_common(struct IR_i2c *ir, enum rc_proto *protocol,
u32 *scancode, u8 *ptoggle, int size)
{
unsigned char buf[6];
int start, range, toggle, dev, code, ircode, vendor;
/* poll IR chip */
if (size != i2c_master_recv(ir->c, buf, size))
return -EIO;
if (buf[0] & 0x80) {
int offset = (size == 6) ? 3 : 0;
/* split rc5 data block ... */
start = (buf[offset] >> 7) & 1;
range = (buf[offset] >> 6) & 1;
toggle = (buf[offset] >> 5) & 1;
dev = buf[offset] & 0x1f;
code = (buf[offset+1] >> 2) & 0x3f;
/* rc5 has two start bits
* the first bit must be one
* the second bit defines the command range:
* 1 = 0-63, 0 = 64 - 127
*/
if (!start)
/* no key pressed */
return 0;
/* filter out invalid key presses */
ircode = (start << 12) | (toggle << 11) | (dev << 6) | code;
if ((ircode & 0x1fff) == 0x1fff)
return 0;
if (!range)
code += 64;
dev_dbg(&ir->rc->dev,
"ir hauppauge (rc5): s%d r%d t%d dev=%d code=%d\n",
start, range, toggle, dev, code);
*protocol = RC_PROTO_RC5;
*scancode = RC_SCANCODE_RC5(dev, code);
*ptoggle = toggle;
return 1;
} else if (size == 6 && (buf[0] & 0x40)) {
code = buf[4];
dev = buf[3];
vendor = get_unaligned_be16(buf + 1);
if (vendor == 0x800f) {
*ptoggle = (dev & 0x80) != 0;
*protocol = RC_PROTO_RC6_MCE;
dev &= 0x7f;
dev_dbg(&ir->rc->dev,
"ir hauppauge (rc6-mce): t%d vendor=%d dev=%d code=%d\n",
*ptoggle, vendor, dev, code);
} else {
*ptoggle = 0;
*protocol = RC_PROTO_RC6_6A_32;
dev_dbg(&ir->rc->dev,
"ir hauppauge (rc6-6a-32): vendor=%d dev=%d code=%d\n",
vendor, dev, code);
}
*scancode = RC_SCANCODE_RC6_6A(vendor, dev, code);
return 1;
}
return 0;
}
static int get_key_haup(struct IR_i2c *ir, enum rc_proto *protocol,
u32 *scancode, u8 *toggle)
{
return get_key_haup_common(ir, protocol, scancode, toggle, 3);
}
static int get_key_haup_xvr(struct IR_i2c *ir, enum rc_proto *protocol,
u32 *scancode, u8 *toggle)
{
int ret;
unsigned char buf[1] = { 0 };
/*
* This is the same apparent "are you ready?" poll command observed
* watching Windows driver traffic and implemented in lirc_zilog. With
* this added, we get far saner remote behav