2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Gerd Knorr
|
|
|
|
* Copyright (c) 2003 Pavel Machek
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-08-22 06:56:48 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/input.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "bttv.h"
|
2006-01-10 01:25:25 +08:00
|
|
|
#include "bttvp.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-14 08:07:52 +08:00
|
|
|
|
2008-08-05 21:14:13 +08:00
|
|
|
static int ir_debug;
|
|
|
|
module_param(ir_debug, int, 0644);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-28 23:47:47 +08:00
|
|
|
static int ir_rc5_remote_gap = 885;
|
2006-12-08 08:45:28 +08:00
|
|
|
module_param(ir_rc5_remote_gap, int, 0644);
|
|
|
|
|
2008-08-05 21:14:13 +08:00
|
|
|
#undef dprintk
|
2011-08-22 06:56:48 +08:00
|
|
|
#define dprintk(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (ir_debug >= 1) \
|
|
|
|
pr_info(fmt, ##__VA_ARGS__); \
|
2008-08-05 21:14:13 +08:00
|
|
|
} while (0)
|
|
|
|
|
2006-01-10 01:25:25 +08:00
|
|
|
#define DEVNAME "bttv-input"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-03-13 08:18:14 +08:00
|
|
|
#define MODULE_NAME "bttv"
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2006-01-10 01:25:25 +08:00
|
|
|
static void ir_handle_key(struct bttv *btv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-11-20 07:43:12 +08:00
|
|
|
struct bttv_ir *ir = btv->remote;
|
2005-04-17 06:20:36 +08:00
|
|
|
u32 gpio,data;
|
|
|
|
|
|
|
|
/* read gpio value */
|
2006-01-10 01:25:25 +08:00
|
|
|
gpio = bttv_gpio_read(&btv->c);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ir->polling) {
|
|
|
|
if (ir->last_gpio == gpio)
|
|
|
|
return;
|
|
|
|
ir->last_gpio = gpio;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* extract data */
|
|
|
|
data = ir_extract_bits(gpio, ir->mask_keycode);
|
2011-08-22 06:56:48 +08:00
|
|
|
dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
gpio, data,
|
|
|
|
ir->polling ? "poll" : "irq",
|
|
|
|
(gpio & ir->mask_keydown) ? " down" : "",
|
|
|
|
(gpio & ir->mask_keyup) ? " up" : "");
|
|
|
|
|
2010-10-30 03:08:07 +08:00
|
|
|
if ((ir->mask_keydown && (gpio & ir->mask_keydown)) ||
|
|
|
|
(ir->mask_keyup && !(gpio & ir->mask_keyup))) {
|
2017-08-08 04:20:58 +08:00
|
|
|
rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2008-01-07 20:30:31 +08:00
|
|
|
/* HACK: Probably, ir->mask_keydown is missing
|
|
|
|
for this board */
|
|
|
|
if (btv->c.type == BTTV_BOARD_WINFAST2000)
|
2017-08-08 04:20:58 +08:00
|
|
|
rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data,
|
|
|
|
0);
|
2008-01-07 20:30:31 +08:00
|
|
|
|
2010-11-18 00:53:11 +08:00
|
|
|
rc_keyup(ir->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-05 21:14:13 +08:00
|
|
|
static void ir_enltv_handle_key(struct bttv *btv)
|
|
|
|
{
|
2010-11-20 07:43:12 +08:00
|
|
|
struct bttv_ir *ir = btv->remote;
|
2008-08-05 21:14:13 +08:00
|
|
|
u32 gpio, data, keyup;
|
|
|
|
|
|
|
|
/* read gpio value */
|
|
|
|
gpio = bttv_gpio_read(&btv->c);
|
|
|
|
|
|
|
|
/* extract data */
|
|
|
|
data = ir_extract_bits(gpio, ir->mask_keycode);
|
|
|
|
|
|
|
|
/* Check if it is keyup */
|
|
|
|
keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
|
|
|
|
|
|
|
|
if ((ir->last_gpio & 0x7f) != data) {
|
2011-08-22 06:56:48 +08:00
|
|
|
dprintk("gpio=0x%x code=%d | %s\n",
|
2008-08-05 21:14:13 +08:00
|
|
|
gpio, data,
|
|
|
|
(gpio & ir->mask_keyup) ? " up" : "up/down");
|
|
|
|
|
2017-08-08 04:20:58 +08:00
|
|
|
rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data, 0);
|
2008-08-05 21:14:13 +08:00
|
|
|
if (keyup)
|
2010-11-18 00:53:11 +08:00
|
|
|
rc_keyup(ir->dev);
|
2008-08-05 21:14:13 +08:00
|
|
|
} else {
|
|
|
|
if ((ir->last_gpio & 1 << 31) == keyup)
|
|
|
|
return;
|
|
|
|
|
2011-08-22 06:56:48 +08:00
|
|
|
dprintk("(cnt) gpio=0x%x code=%d | %s\n",
|
2008-08-05 21:14:13 +08:00
|
|
|
gpio, data,
|
|
|
|
(gpio & ir->mask_keyup) ? " up" : "down");
|
|
|
|
|
|
|
|
if (keyup)
|
2010-11-18 00:53:11 +08:00
|
|
|
rc_keyup(ir->dev);
|
2008-08-05 21:14:13 +08:00
|
|
|
else
|
2017-08-08 04:20:58 +08:00
|
|
|
rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data,
|
|
|
|
0);
|
2008-08-05 21:14:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ir->last_gpio = data | keyup;
|
|
|
|
}
|
|
|
|
|
2010-11-28 22:48:26 +08:00
|
|
|
static int bttv_rc5_irq(struct bttv *btv);
|
|
|
|
|
2006-01-10 01:25:25 +08:00
|
|
|
void bttv_input_irq(struct bttv *btv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-11-20 07:43:12 +08:00
|
|
|
struct bttv_ir *ir = btv->remote;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-11-28 22:48:26 +08:00
|
|
|
if (ir->rc5_gpio)
|
|
|
|
bttv_rc5_irq(btv);
|
|
|
|
else if (!ir->polling)
|
2006-01-10 01:25:25 +08:00
|
|
|
ir_handle_key(btv);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2017-10-24 23:22:42 +08:00
|
|
|
static void bttv_input_timer(struct timer_list *t)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-10-24 23:22:42 +08:00
|
|
|
struct bttv_ir *ir = from_timer(ir, t, timer);
|
|
|
|
struct bttv *btv = ir->btv;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-05 21:14:13 +08:00
|
|
|
if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
|
|
|
|
ir_enltv_handle_key(btv);
|
|
|
|
else
|
|
|
|
ir_handle_key(btv);
|
2007-01-02 14:29:48 +08:00
|
|
|
mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-11-17 20:58:09 +08:00
|
|
|
/*
|
|
|
|
* FIXME: Nebula digi uses the legacy way to decode RC5, instead of relying
|
|
|
|
* on the rc-core way. As we need to be sure that both IRQ transitions are
|
|
|
|
* properly triggered, Better to touch it only with this hardware for
|
|
|
|
* testing.
|
|
|
|
*/
|
|
|
|
|
2014-04-04 07:31:20 +08:00
|
|
|
#define RC5_START(x) (((x) >> 12) & 0x03)
|
|
|
|
#define RC5_TOGGLE(x) (((x) >> 11) & 0x01)
|
|
|
|
#define RC5_ADDR(x) (((x) >> 6) & 0x1f)
|
|
|
|
#define RC5_INSTR(x) (((x) >> 0) & 0x3f)
|
2010-11-17 21:05:29 +08:00
|
|
|
|
2010-11-17 20:58:09 +08:00
|
|
|
/* decode raw bit pattern to RC5 code */
|
|
|
|
static u32 bttv_rc5_decode(unsigned int code)
|
|
|
|
{
|
|
|
|
unsigned int org_code = code;
|
|
|
|
unsigned int pair;
|
|
|
|
unsigned int rc5 = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 14; ++i) {
|
|
|
|
pair = code & 0x3;
|
|
|
|
code >>= 2;
|
|
|
|
|
|
|
|
rc5 <<= 1;
|
|
|
|
switch (pair) {
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
rc5 |= 1;
|
|
|
|
break;
|
|
|
|
case 3:
|
2011-08-22 06:56:48 +08:00
|
|
|
dprintk("rc5_decode(%x) bad code\n",
|
2010-11-17 20:58:09 +08:00
|
|
|
org_code);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
[media] bt8xx: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-19 03:44:02 +08:00
|
|
|
dprintk("code=%x, rc5=%x, start=%x, toggle=%x, address=%x, instr=%x\n",
|
|
|
|
rc5, org_code, RC5_START(rc5),
|
2010-11-17 20:58:09 +08:00
|
|
|
RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
|
|
|
|
return rc5;
|
|
|
|
}
|
|
|
|
|
2017-10-24 23:22:42 +08:00
|
|
|
static void bttv_rc5_timer_end(struct timer_list *t)
|
2010-11-17 20:58:09 +08:00
|
|
|
{
|
2017-10-24 23:22:42 +08:00
|
|
|
struct bttv_ir *ir = from_timer(ir, t, timer);
|
2015-08-11 23:22:57 +08:00
|
|
|
ktime_t tv;
|
2014-04-04 07:31:20 +08:00
|
|
|
u32 gap, rc5, scancode;
|
|
|
|
u8 toggle, command, system;
|
2010-11-17 20:58:09 +08:00
|
|
|
|
|
|
|
/* get time */
|
2015-08-11 23:22:57 +08:00
|
|
|
tv = ktime_get();
|
2010-11-17 20:58:09 +08:00
|
|
|
|
2015-08-11 23:22:57 +08:00
|
|
|
gap = ktime_to_us(ktime_sub(tv, ir->base_time));
|
2010-11-17 20:58:09 +08:00
|
|
|
/* avoid overflow with gap >1s */
|
2015-08-11 23:22:57 +08:00
|
|
|
if (gap > USEC_PER_SEC) {
|
2010-11-17 20:58:09 +08:00
|
|
|
gap = 200000;
|
|
|
|
}
|
|
|
|
/* signal we're ready to start a new code */
|
2010-11-20 07:43:12 +08:00
|
|
|
ir->active = false;
|
2010-11-17 20:58:09 +08:00
|
|
|
|
|
|
|
/* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
|
|
|
|
if (gap < 28000) {
|
2011-08-22 06:56:48 +08:00
|
|
|
dprintk("spurious timer_end\n");
|
2010-11-17 20:58:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ir->last_bit < 20) {
|
|
|
|
/* ignore spurious codes (caused by light/other remotes) */
|
2011-08-22 06:56:48 +08:00
|
|
|
dprintk("short code: %x\n", ir->code);
|
2014-04-04 07:31:20 +08:00
|
|
|
return;
|
2010-11-17 20:58:09 +08:00
|
|
|
}
|
2014-04-04 07:31:20 +08:00
|
|
|
|
|
|
|
ir->code = (ir->code << ir->shift_by) | 1;
|
|
|
|
rc5 = bttv_rc5_decode(ir->code);
|
|
|
|
|
|
|
|
toggle = RC5_TOGGLE(rc5);
|
|
|
|
system = RC5_ADDR(rc5);
|
|
|
|
command = RC5_INSTR(rc5);
|
|
|
|
|
|
|
|
switch (RC5_START(rc5)) {
|
|
|
|
case 0x3:
|
|
|
|
break;
|
|
|
|
case 0x2:
|
|
|
|
command += 0x40;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-04 07:31:30 +08:00
|
|
|
scancode = RC_SCANCODE_RC5(system, command);
|
2017-08-08 04:20:58 +08:00
|
|
|
rc_keydown(ir->dev, RC_PROTO_RC5, scancode, toggle);
|
2014-04-04 07:31:20 +08:00
|
|
|
dprintk("scancode %x, toggle %x\n", scancode, toggle);
|
2010-11-17 20:58:09 +08:00
|
|
|
}
|
2005-11-14 08:07:52 +08:00
|
|
|
|
2006-01-10 01:25:25 +08:00
|
|
|
static int bttv_rc5_irq(struct bttv *btv)
|
2005-11-14 08:07:52 +08:00
|
|
|
{
|
2010-11-20 07:43:12 +08:00
|
|
|
struct bttv_ir *ir = btv->remote;
|
2015-08-11 23:22:57 +08:00
|
|
|
ktime_t tv;
|
2005-11-14 08:07:52 +08:00
|
|
|
u32 gpio;
|
|
|
|
u32 gap;
|
2007-01-02 14:29:48 +08:00
|
|
|
unsigned long current_jiffies;
|
2005-11-14 08:07:52 +08:00
|
|
|
|
|
|
|
/* read gpio port */
|
2006-01-10 01:25:25 +08:00
|
|
|
gpio = bttv_gpio_read(&btv->c);
|
2005-11-14 08:07:52 +08:00
|
|
|
|
|
|
|
/* get time of bit */
|
|
|
|
current_jiffies = jiffies;
|
2015-08-11 23:22:57 +08:00
|
|
|
tv = ktime_get();
|
2005-11-14 08:07:52 +08:00
|
|
|
|
2015-08-11 23:22:57 +08:00
|
|
|
gap = ktime_to_us(ktime_sub(tv, ir->base_time));
|
2005-11-14 08:07:52 +08:00
|
|
|
/* avoid overflow with gap >1s */
|
2015-08-11 23:22:57 +08:00
|
|
|
if (gap > USEC_PER_SEC) {
|
2005-11-14 08:07:52 +08:00
|
|
|
gap = 200000;
|
|
|
|
}
|
|
|
|
|
2011-08-22 06:56:48 +08:00
|
|
|
dprintk("RC5 IRQ: gap %d us for %s\n",
|
2010-11-28 22:48:26 +08:00
|
|
|
gap, (gpio & 0x20) ? "mark" : "space");
|
|
|
|
|
|
|
|
/* remote IRQ? */
|
|
|
|
if (!(gpio & 0x20))
|
|
|
|
return 0;
|
|
|
|
|
2005-11-14 08:07:52 +08:00
|
|
|
/* active code => add bit */
|
|
|
|
if (ir->active) {
|
|
|
|
/* only if in the code (otherwise spurious IRQ or timer
|
|
|
|
late) */
|
|
|
|
if (ir->last_bit < 28) {
|
2006-12-08 08:45:28 +08:00
|
|
|
ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
|
|
|
|
ir_rc5_remote_gap;
|
2005-11-14 08:07:52 +08:00
|
|
|
ir->code |= 1 << ir->last_bit;
|
|
|
|
}
|
|
|
|
/* starting new code */
|
|
|
|
} else {
|
2010-11-20 07:43:12 +08:00
|
|
|
ir->active = true;
|
2005-11-14 08:07:52 +08:00
|
|
|
ir->code = 0;
|
|
|
|
ir->base_time = tv;
|
|
|
|
ir->last_bit = 0;
|
|
|
|
|
2010-11-20 07:43:17 +08:00
|
|
|
mod_timer(&ir->timer, current_jiffies + msecs_to_jiffies(30));
|
2005-11-14 08:07:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* toggle GPIO pin 4 to reset the irq */
|
2006-01-10 01:25:25 +08:00
|
|
|
bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
|
|
|
|
bttv_gpio_write(&btv->c, gpio | (1 << 4));
|
2005-11-14 08:07:52 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2017-10-24 23:22:42 +08:00
|
|
|
static void bttv_ir_start(struct bttv_ir *ir)
|
2006-11-20 21:23:04 +08:00
|
|
|
{
|
|
|
|
if (ir->polling) {
|
2017-10-24 23:22:42 +08:00
|
|
|
timer_setup(&ir->timer, bttv_input_timer, 0);
|
2007-07-18 03:36:20 +08:00
|
|
|
ir->timer.expires = jiffies + msecs_to_jiffies(1000);
|
2006-11-20 21:23:04 +08:00
|
|
|
add_timer(&ir->timer);
|
|
|
|
} else if (ir->rc5_gpio) {
|
|
|
|
/* set timer_end for code completion */
|
2017-10-24 23:22:42 +08:00
|
|
|
timer_setup(&ir->timer, bttv_rc5_timer_end, 0);
|
2006-12-08 08:45:28 +08:00
|
|
|
ir->shift_by = 1;
|
|
|
|
ir->rc5_remote_gap = ir_rc5_remote_gap;
|
2006-11-20 21:23:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bttv_ir_stop(struct bttv *btv)
|
|
|
|
{
|
2010-12-24 23:14:20 +08:00
|
|
|
if (btv->remote->polling)
|
2006-11-20 21:23:04 +08:00
|
|
|
del_timer_sync(&btv->remote->timer);
|
|
|
|
|
|
|
|
if (btv->remote->rc5_gpio) {
|
|
|
|
u32 gpio;
|
|
|
|
|
2010-11-20 07:43:17 +08:00
|
|
|
del_timer_sync(&btv->remote->timer);
|
2006-11-20 21:23:04 +08:00
|
|
|
|
|
|
|
gpio = bttv_gpio_read(&btv->c);
|
|
|
|
bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-23 10:24:04 +08:00
|
|
|
/*
|
|
|
|
* Get_key functions used by I2C remotes
|
|
|
|
*/
|
|
|
|
|
2017-08-08 04:20:58 +08:00
|
|
|
static int get_key_pv951(struct IR_i2c *ir, enum rc_proto *protocol,
|
2014-04-04 07:31:25 +08:00
|
|
|
u32 *scancode, u8 *toggle)
|
2010-09-23 10:24:04 +08:00
|
|
|
{
|
2018-03-23 18:36:26 +08:00
|
|
|
int rc;
|
2010-09-23 10:24:04 +08:00
|
|
|
unsigned char b;
|
|
|
|
|
|
|
|
/* poll IR chip */
|
2018-03-23 18:36:26 +08:00
|
|
|
rc = i2c_master_recv(ir->c, &b, 1);
|
|
|
|
if (rc != 1) {
|
2011-08-22 06:56:48 +08:00
|
|
|
dprintk("read error\n");
|
2018-03-23 18:36:26 +08:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
2010-09-23 10:24:04 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ignore 0xaa */
|
|
|
|
if (b==0xaa)
|
|
|
|
return 0;
|
2011-08-22 06:56:48 +08:00
|
|
|
dprintk("key %02x\n", b);
|
2010-09-23 10:24:04 +08:00
|
|
|
|
2010-12-30 19:01:01 +08:00
|
|
|
/*
|
|
|
|
* NOTE:
|
|
|
|
* lirc_i2c maps the pv951 code as:
|
|
|
|
* addr = 0x61D6
|
2018-01-05 02:08:56 +08:00
|
|
|
* cmd = bit_reverse (b)
|
2010-12-30 19:01:01 +08:00
|
|
|
* So, it seems that this device uses NEC extended
|
|
|
|
* I decided to not fix the table, due to two reasons:
|
2018-01-05 02:08:56 +08:00
|
|
|
* 1) Without the actual device, this is only a guess;
|
|
|
|
* 2) As the addr is not reported via I2C, nor can be changed,
|
|
|
|
* the device is bound to the vendor-provided RC.
|
2010-12-30 19:01:01 +08:00
|
|
|
*/
|
|
|
|
|
2017-08-08 04:20:58 +08:00
|
|
|
*protocol = RC_PROTO_UNKNOWN;
|
2014-04-04 07:31:25 +08:00
|
|
|
*scancode = b;
|
|
|
|
*toggle = 0;
|
2010-09-23 10:24:04 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Instantiate the I2C IR receiver device, if present */
|
2012-12-22 05:17:53 +08:00
|
|
|
void init_bttv_i2c_ir(struct bttv *btv)
|
2010-09-23 10:24:04 +08:00
|
|
|
{
|
2018-10-04 21:59:06 +08:00
|
|
|
static const unsigned short addr_list[] = {
|
2010-09-23 10:24:04 +08:00
|
|
|
0x1a, 0x18, 0x64, 0x30, 0x71,
|
|
|
|
I2C_CLIENT_END
|
|
|
|
};
|
|
|
|
struct i2c_board_info info;
|
2013-02-17 20:40:05 +08:00
|
|
|
struct i2c_client *i2c_dev;
|
2010-09-23 10:24:04 +08:00
|
|
|
|
|
|
|
if (0 != btv->i2c_rc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(struct i2c_board_info));
|
|
|
|
memset(&btv->init_data, 0, sizeof(btv->init_data));
|
2018-09-10 20:19:14 +08:00
|
|
|
strscpy(info.type, "ir_video", I2C_NAME_SIZE);
|
2010-09-23 10:24:04 +08:00
|
|
|
|
|
|
|
switch (btv->c.type) {
|
|
|
|
case BTTV_BOARD_PV951:
|
|
|
|
btv->init_data.name = "PV951";
|
|
|
|
btv->init_data.get_key = get_key_pv951;
|
|
|
|
btv->init_data.ir_codes = RC_MAP_PV951;
|
|
|
|
info.addr = 0x4b;
|
|
|
|
break;
|
2013-02-17 20:40:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (btv->init_data.name) {
|
|
|
|
info.platform_data = &btv->init_data;
|
|
|
|
i2c_dev = i2c_new_device(&btv->c.i2c_adap, &info);
|
|
|
|
} else {
|
2010-09-23 10:24:04 +08:00
|
|
|
/*
|
|
|
|
* The external IR receiver is at i2c address 0x34 (0x35 for
|
2010-11-17 20:58:09 +08:00
|
|
|
* reads). Future Hauppauge cards will have an internal
|
|
|
|
* receiver at 0x30 (0x31 for reads). In theory, both can be
|
|
|
|
* fitted, and Hauppauge suggest an external overrides an
|
|
|
|
* internal.
|
2010-09-23 10:24:04 +08:00
|
|
|
* That's why we probe 0x1a (~0x34) first. CB
|
|
|
|
*/
|
2013-02-17 20:40:05 +08:00
|
|
|
i2c_dev = i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
|
2010-09-23 10:24:04 +08:00
|
|
|
}
|
2013-02-17 20:40:05 +08:00
|
|
|
if (NULL == i2c_dev)
|
|
|
|
return;
|
2010-09-23 10:24:04 +08:00
|
|
|
|
2013-02-17 20:40:05 +08:00
|
|
|
#if defined(CONFIG_MODULES) && defined(MODULE)
|
|
|
|
request_module("ir-kbd-i2c");
|
|
|
|
#endif
|
2010-09-23 10:24:04 +08:00
|
|
|
}
|
|
|
|
|
2006-01-10 01:25:25 +08:00
|
|
|
int bttv_input_init(struct bttv *btv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-11-20 07:43:12 +08:00
|
|
|
struct bttv_ir *ir;
|
2010-04-03 07:01:00 +08:00
|
|
|
char *ir_codes = NULL;
|
2010-10-30 03:08:23 +08:00
|
|
|
struct rc_dev *rc;
|
2006-11-20 21:23:04 +08:00
|
|
|
int err = -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-10 01:25:25 +08:00
|
|
|
if (!btv->has_remote)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ir = kzalloc(sizeof(*ir),GFP_KERNEL);
|
2016-12-16 16:50:58 +08:00
|
|
|
rc = rc_allocate_device(RC_DRIVER_SCANCODE);
|
2010-10-30 03:08:23 +08:00
|
|
|
if (!ir || !rc)
|
2006-11-20 21:23:04 +08:00
|
|
|
goto err_out_free;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* detect & configure */
|
2006-01-10 01:25:25 +08:00
|
|
|
switch (btv->c.type) {
|
2005-11-09 13:36:52 +08:00
|
|
|
case BTTV_BOARD_AVERMEDIA:
|
|
|
|
case BTTV_BOARD_AVPHONE98:
|
|
|
|
case BTTV_BOARD_AVERMEDIA98:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_AVERMEDIA;
|
2005-04-17 06:20:36 +08:00
|
|
|
ir->mask_keycode = 0xf88000;
|
|
|
|
ir->mask_keydown = 0x010000;
|
|
|
|
ir->polling = 50; // ms
|
|
|
|
break;
|
|
|
|
|
2005-11-09 13:36:52 +08:00
|
|
|
case BTTV_BOARD_AVDVBT_761:
|
|
|
|
case BTTV_BOARD_AVDVBT_771:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_AVERMEDIA_DVBT;
|
2005-04-17 06:20:36 +08:00
|
|
|
ir->mask_keycode = 0x0f00c0;
|
|
|
|
ir->mask_keydown = 0x000020;
|
|
|
|
ir->polling = 50; // ms
|
|
|
|
break;
|
|
|
|
|
2005-11-09 13:36:52 +08:00
|
|
|
case BTTV_BOARD_PXELVWPLTVPAK:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_PIXELVIEW;
|
2005-04-17 06:20:36 +08:00
|
|
|
ir->mask_keycode = 0x003e00;
|
|
|
|
ir->mask_keyup = 0x010000;
|
|
|
|
ir->polling = 50; // ms
|
2005-11-09 13:37:43 +08:00
|
|
|
break;
|
2006-08-23 22:17:30 +08:00
|
|
|
case BTTV_BOARD_PV_M4900:
|
2005-11-09 13:36:52 +08:00
|
|
|
case BTTV_BOARD_PV_BT878P_9B:
|
|
|
|
case BTTV_BOARD_PV_BT878P_PLUS:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_PIXELVIEW;
|
2005-04-17 06:20:36 +08:00
|
|
|
ir->mask_keycode = 0x001f00;
|
|
|
|
ir->mask_keyup = 0x008000;
|
|
|
|
ir->polling = 50; // ms
|
2005-11-09 13:37:43 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-09 13:36:52 +08:00
|
|
|
case BTTV_BOARD_WINFAST2000:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_WINFAST;
|
2005-04-17 06:20:36 +08:00
|
|
|
ir->mask_keycode = 0x1f8;
|
|
|
|
break;
|
2005-11-09 13:36:52 +08:00
|
|
|
case BTTV_BOARD_MAGICTVIEW061:
|
|
|
|
case BTTV_BOARD_MAGICTVIEW063:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_WINFAST;
|
2005-04-17 06:20:36 +08:00
|
|
|
ir->mask_keycode = 0x0008e000;
|
|
|
|
ir->mask_keydown = 0x00200000;
|
|
|
|
break;
|
2005-11-09 13:36:52 +08:00
|
|
|
case BTTV_BOARD_APAC_VIEWCOMP:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_APAC_VIEWCOMP;
|
2005-04-17 06:20:36 +08:00
|
|
|
ir->mask_keycode = 0x001f00;
|
|
|
|
ir->mask_keyup = 0x008000;
|
|
|
|
ir->polling = 50; // ms
|
|
|
|
break;
|
2009-08-23 01:43:50 +08:00
|
|
|
case BTTV_BOARD_ASKEY_CPH03X:
|
2005-11-09 13:36:52 +08:00
|
|
|
case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
|
2006-02-27 11:08:15 +08:00
|
|
|
case BTTV_BOARD_CONTVFMI:
|
2014-02-08 01:56:17 +08:00
|
|
|
case BTTV_BOARD_KWORLD_VSTREAM_XPERT:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_PIXELVIEW;
|
2005-11-09 13:36:20 +08:00
|
|
|
ir->mask_keycode = 0x001F00;
|
|
|
|
ir->mask_keyup = 0x006000;
|
|
|
|
ir->polling = 50; // ms
|
|
|
|
break;
|
2005-11-14 08:07:52 +08:00
|
|
|
case BTTV_BOARD_NEBULA_DIGITV:
|
2014-04-04 07:31:20 +08:00
|
|
|
ir_codes = RC_MAP_NEBULA;
|
|
|
|
ir->rc5_gpio = true;
|
2005-12-12 16:37:28 +08:00
|
|
|
break;
|
2006-01-12 05:40:09 +08:00
|
|
|
case BTTV_BOARD_MACHTV_MAGICTV:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_APAC_VIEWCOMP;
|
2006-01-12 05:40:09 +08:00
|
|
|
ir->mask_keycode = 0x001F00;
|
|
|
|
ir->mask_keyup = 0x004000;
|
|
|
|
ir->polling = 50; /* ms */
|
|
|
|
break;
|
2008-04-23 01:45:58 +08:00
|
|
|
case BTTV_BOARD_KOZUMI_KTV_01C:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_PCTV_SEDNA;
|
2008-04-23 01:45:58 +08:00
|
|
|
ir->mask_keycode = 0x001f00;
|
|
|
|
ir->mask_keyup = 0x006000;
|
|
|
|
ir->polling = 50; /* ms */
|
|
|
|
break;
|
2008-08-05 21:14:13 +08:00
|
|
|
case BTTV_BOARD_ENLTV_FM_2:
|
2010-04-03 07:01:00 +08:00
|
|
|
ir_codes = RC_MAP_ENCORE_ENLTV2;
|
2008-08-05 21:14:13 +08:00
|
|
|
ir->mask_keycode = 0x00fd00;
|
|
|
|
ir->mask_keyup = 0x000080;
|
|
|
|
ir->polling = 1; /* ms */
|
|
|
|
ir->last_gpio = ir_extract_bits(bttv_gpio_read(&btv->c),
|
|
|
|
ir->mask_keycode);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2014-04-04 07:31:20 +08:00
|
|
|
|
|
|
|
if (!ir_codes) {
|
2011-08-22 06:56:48 +08:00
|
|
|
dprintk("Ooops: IR config error [card=%d]\n", btv->c.type);
|
2006-11-20 21:23:04 +08:00
|
|
|
err = -ENODEV;
|
|
|
|
goto err_out_free;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-11-14 08:07:52 +08:00
|
|
|
if (ir->rc5_gpio) {
|
|
|
|
u32 gpio;
|
2006-06-20 11:30:57 +08:00
|
|
|
/* enable remote irq */
|
2006-01-10 01:25:25 +08:00
|
|
|
bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4);
|
|
|
|
gpio = bttv_gpio_read(&btv->c);
|
|
|
|
bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
|
|
|
|
bttv_gpio_write(&btv->c, gpio | (1 << 4));
|
2005-11-14 08:07:52 +08:00
|
|
|
} else {
|
|
|
|
/* init hardware-specific stuff */
|
2006-01-10 01:25:25 +08:00
|
|
|
bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0);
|
2005-11-14 08:07:52 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* init input device */
|
2010-10-30 03:08:23 +08:00
|
|
|
ir->dev = rc;
|
2017-10-24 23:22:42 +08:00
|
|
|
ir->btv = btv;
|
2006-01-10 01:25:25 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
|
2006-01-10 01:25:25 +08:00
|
|
|
btv->c.type);
|
2005-04-17 06:20:36 +08:00
|
|
|
snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
|
2006-01-10 01:25:25 +08:00
|
|
|
pci_name(btv->c.pci));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-07-02 00:13:19 +08:00
|
|
|
rc->device_name = ir->name;
|
2010-10-30 03:08:23 +08:00
|
|
|
rc->input_phys = ir->phys;
|
|
|
|
rc->input_id.bustype = BUS_PCI;
|
|
|
|
rc->input_id.version = 1;
|
2006-01-10 01:25:25 +08:00
|
|
|
if (btv->c.pci->subsystem_vendor) {
|
2010-10-30 03:08:23 +08:00
|
|
|
rc->input_id.vendor = btv->c.pci->subsystem_vendor;
|
|
|
|
rc->input_id.product = btv->c.pci->subsystem_device;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2010-10-30 03:08:23 +08:00
|
|
|
rc->input_id.vendor = btv->c.pci->vendor;
|
|
|
|
rc->input_id.product = btv->c.pci->device;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-10-30 03:08:23 +08:00
|
|
|
rc->dev.parent = &btv->c.pci->dev;
|
|
|
|
rc->map_name = ir_codes;
|
|
|
|
rc->driver_name = MODULE_NAME;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-10 01:25:25 +08:00
|
|
|
btv->remote = ir;
|
2017-10-24 23:22:42 +08:00
|
|
|
bttv_ir_start(ir);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* all done */
|
2010-10-30 03:08:23 +08:00
|
|
|
err = rc_register_device(rc);
|
2006-11-20 21:23:04 +08:00
|
|
|
if (err)
|
|
|
|
goto err_out_stop;
|
2005-11-14 08:07:52 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2006-11-20 21:23:04 +08:00
|
|
|
|
|
|
|
err_out_stop:
|
|
|
|
bttv_ir_stop(btv);
|
|
|
|
btv->remote = NULL;
|
|
|
|
err_out_free:
|
2010-10-30 03:08:23 +08:00
|
|
|
rc_free_device(rc);
|
2006-11-20 21:23:04 +08:00
|
|
|
kfree(ir);
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-01-10 01:25:25 +08:00
|
|
|
void bttv_input_fini(struct bttv *btv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-01-10 01:25:25 +08:00
|
|
|
if (btv->remote == NULL)
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-11-20 21:23:04 +08:00
|
|
|
bttv_ir_stop(btv);
|
2010-10-30 03:08:23 +08:00
|
|
|
rc_unregister_device(btv->remote->dev);
|
2006-01-10 01:25:25 +08:00
|
|
|
kfree(btv->remote);
|
|
|
|
btv->remote = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|