Commit 9160723e authored by Hermann Pitton's avatar Hermann Pitton Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (4961): Add support for the ASUS P7131 remote control



Besides adding the board specific code, this patch moves
the RC5 decoding code from bt8xx to ir-functions.c to make it available 
for all drivers.

Signed-off-by: Marc Fargas <telenieko.telenieko.com>
Signed-off-by: default avatarHermann Pitton <hermann-pitton@arcor.de>
Signed-off-by: default avatarHartmut Hackmann <hartmut.hackmann@t-online.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent c8f71b01
Loading
Loading
Loading
Loading
+110 −0
Original line number Diff line number Diff line
@@ -256,6 +256,112 @@ int ir_decode_biphase(u32 *samples, int count, int low, int high)
	return value;
}

/* RC5 decoding stuff, moved from bttv-input.c to share it with
 * saa7134 */

/* decode raw bit pattern to RC5 code */
u32 ir_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:
			dprintk(1, "ir-common: ir_rc5_decode(%x) bad code\n", org_code);
			return 0;
		}
	}
	dprintk(1, "ir-common: code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
		"instr=%x\n", rc5, org_code, RC5_START(rc5),
		RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
	return rc5;
}

void ir_rc5_timer_end(unsigned long data)
{
	struct card_ir *ir = (struct card_ir *)data;
	struct timeval tv;
	unsigned long current_jiffies, timeout;
	u32 gap;
	u32 rc5 = 0;

	/* get time */
	current_jiffies = jiffies;
	do_gettimeofday(&tv);

	/* avoid overflow with gap >1s */
	if (tv.tv_sec - ir->base_time.tv_sec > 1) {
		gap = 200000;
	} else {
		gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
		    tv.tv_usec - ir->base_time.tv_usec;
	}

	/* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */
	if (gap < 28000) {
		dprintk(1, "ir-common: spurious timer_end\n");
		return;
	}

	ir->active = 0;
	if (ir->last_bit < 20) {
		/* ignore spurious codes (caused by light/other remotes) */
		dprintk(1, "ir-common: short code: %x\n", ir->code);
	} else {
		ir->code = (ir->code << ir->shift_by) | 1;
		rc5 = ir_rc5_decode(ir->code);

		/* two start bits? */
		if (RC5_START(rc5) != ir->start) {
			dprintk(1, "ir-common: rc5 start bits invalid: %u\n", RC5_START(rc5));

			/* right address? */
		} else if (RC5_ADDR(rc5) == ir->addr) {
			u32 toggle = RC5_TOGGLE(rc5);
			u32 instr = RC5_INSTR(rc5);

			/* Good code, decide if repeat/repress */
			if (toggle != RC5_TOGGLE(ir->last_rc5) ||
			    instr != RC5_INSTR(ir->last_rc5)) {
				dprintk(1, "ir-common: instruction %x, toggle %x\n", instr,
					toggle);
				ir_input_nokey(ir->dev, &ir->ir);
				ir_input_keydown(ir->dev, &ir->ir, instr,
						 instr);
			}

			/* Set/reset key-up timer */
			timeout = current_jiffies + (500 + ir->rc5_key_timeout
						     * HZ) / 1000;
			mod_timer(&ir->timer_keyup, timeout);

			/* Save code for repeat test */
			ir->last_rc5 = rc5;
		}
	}
}

void ir_rc5_timer_keyup(unsigned long data)
{
	struct card_ir *ir = (struct card_ir *)data;

	dprintk(1, "ir-common: key released\n");
	ir_input_nokey(ir->dev, &ir->ir);
}

EXPORT_SYMBOL_GPL(ir_input_init);
EXPORT_SYMBOL_GPL(ir_input_nokey);
EXPORT_SYMBOL_GPL(ir_input_keydown);
@@ -265,6 +371,10 @@ EXPORT_SYMBOL_GPL(ir_dump_samples);
EXPORT_SYMBOL_GPL(ir_decode_biphase);
EXPORT_SYMBOL_GPL(ir_decode_pulsedistance);

EXPORT_SYMBOL_GPL(ir_rc5_decode);
EXPORT_SYMBOL_GPL(ir_rc5_timer_end);
EXPORT_SYMBOL_GPL(ir_rc5_timer_keyup);

/*
 * Local variables:
 * c-basic-offset: 8
+54 −0
Original line number Diff line number Diff line
@@ -1606,3 +1606,57 @@ IR_KEYTAB_TYPE ir_codes_budget_ci_old[IR_KEYTAB_SIZE] = {
};

EXPORT_SYMBOL_GPL(ir_codes_budget_ci_old);

/*
 * Marc Fargas <telenieko@telenieko.com>
 * this is the remote control that comes with the asus p7131
 * which has a label saying is "Model PC-39"
 */
IR_KEYTAB_TYPE ir_codes_asus_pc39[IR_KEYTAB_SIZE] = {
	/* Keys 0 to 9 */
	[ 0x15 ] = KEY_0,
	[ 0x29 ] = KEY_1,
	[ 0x2d ] = KEY_2,
	[ 0x2b ] = KEY_3,
	[ 0x09 ] = KEY_4,
	[ 0x0d ] = KEY_5,
	[ 0x0b ] = KEY_6,
	[ 0x31 ] = KEY_7,
	[ 0x35 ] = KEY_8,
	[ 0x33 ] = KEY_9,

	[ 0x3e ] = KEY_RADIO,		/* radio */
	[ 0x03 ] = KEY_MENU,		/* dvd/menu */
	[ 0x2a ] = KEY_VOLUMEUP,
	[ 0x19 ] = KEY_VOLUMEDOWN,
	[ 0x37 ] = KEY_UP,
	[ 0x3b ] = KEY_DOWN,
	[ 0x27 ] = KEY_LEFT,
	[ 0x2f ] = KEY_RIGHT,
	[ 0x25 ] = KEY_VIDEO,		/* video */
	[ 0x39 ] = KEY_AUDIO,		/* music */

	[ 0x21 ] = KEY_TV,		/* tv */
	[ 0x1d ] = KEY_EXIT,		/* back */
	[ 0x0a ] = KEY_CHANNELUP,	/* channel / program + */
	[ 0x1b ] = KEY_CHANNELDOWN,	/* channel / program - */
	[ 0x1a ] = KEY_ENTER,		/* enter */

	[ 0x06 ] = KEY_PAUSE,		/* play/pause */
	[ 0x1e ] = KEY_PREVIOUS,	/* rew */
	[ 0x26 ] = KEY_NEXT,		/* forward */
	[ 0x0e ] = KEY_REWIND,		/* backward << */
	[ 0x3a ] = KEY_FASTFORWARD,	/* forward >> */
	[ 0x36 ] = KEY_STOP,
	[ 0x2e ] = KEY_RECORD,		/* recording */
	[ 0x16 ] = KEY_POWER,		/* the button that reads "close" */

	[ 0x11 ] = KEY_ZOOM,		/* full screen */
	[ 0x13 ] = KEY_MACRO,		/* recall */
	[ 0x23 ] = KEY_HOME,		/* home */
	[ 0x05 ] = KEY_PVR,		/* picture */
	[ 0x3d ] = KEY_MUTE,		/* mute */
	[ 0x01 ] = KEY_DVD,		/* dvd */
};

EXPORT_SYMBOL_GPL(ir_codes_asus_pc39);
+20 −123
Original line number Diff line number Diff line
@@ -36,13 +36,18 @@ module_param(repeat_delay, int, 0644);
static int repeat_period = 33;
module_param(repeat_period, int, 0644);

int ir_rc5_remote_gap = 885;
module_param(ir_rc5_remote_gap, int, 0644);
int ir_rc5_key_timeout = 200;
module_param(ir_rc5_key_timeout, int, 0644);

#define DEVNAME "bttv-input"

/* ---------------------------------------------------------------------- */

static void ir_handle_key(struct bttv *btv)
{
	struct bttv_ir *ir = btv->remote;
	struct card_ir *ir = btv->remote;
	u32 gpio,data;

	/* read gpio value */
@@ -72,7 +77,7 @@ static void ir_handle_key(struct bttv *btv)

void bttv_input_irq(struct bttv *btv)
{
	struct bttv_ir *ir = btv->remote;
	struct card_ir *ir = btv->remote;

	if (!ir->polling)
		ir_handle_key(btv);
@@ -81,7 +86,7 @@ void bttv_input_irq(struct bttv *btv)
static void bttv_input_timer(unsigned long data)
{
	struct bttv *btv = (struct bttv*)data;
	struct bttv_ir *ir = btv->remote;
	struct card_ir *ir = btv->remote;
	unsigned long timeout;

	ir_handle_key(btv);
@@ -91,51 +96,9 @@ static void bttv_input_timer(unsigned long data)

/* ---------------------------------------------------------------*/

static int rc5_remote_gap = 885;
module_param(rc5_remote_gap, int, 0644);
static int rc5_key_timeout = 200;
module_param(rc5_key_timeout, int, 0644);

#define RC5_START(x)	(((x)>>12)&3)
#define RC5_TOGGLE(x)	(((x)>>11)&1)
#define RC5_ADDR(x)	(((x)>>6)&31)
#define RC5_INSTR(x)	((x)&63)

/* decode raw bit pattern to RC5 code */
static u32 rc5_decode(unsigned int code)
{
	unsigned int org_code = code;
	unsigned int pair;
	unsigned int rc5 = 0;
	int i;

	code = (code << 1) | 1;
	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:
			dprintk(KERN_WARNING "bad code: %x\n", org_code);
			return 0;
		}
	}
	dprintk(KERN_WARNING "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
		"instr=%x\n", rc5, org_code, RC5_START(rc5),
		RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
	return rc5;
}

static int bttv_rc5_irq(struct bttv *btv)
{
	struct bttv_ir *ir = btv->remote;
	struct card_ir *ir = btv->remote;
	struct timeval tv;
	u32 gpio;
	u32 gap;
@@ -165,8 +128,8 @@ static int bttv_rc5_irq(struct bttv *btv)
		/* only if in the code (otherwise spurious IRQ or timer
		   late) */
		if (ir->last_bit < 28) {
			ir->last_bit = (gap - rc5_remote_gap / 2) /
			    rc5_remote_gap;
			ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
			    ir_rc5_remote_gap;
			ir->code |= 1 << ir->last_bit;
		}
		/* starting new code */
@@ -186,80 +149,9 @@ static int bttv_rc5_irq(struct bttv *btv)
	return 1;
}


static void bttv_rc5_timer_end(unsigned long data)
{
	struct bttv_ir *ir = (struct bttv_ir *)data;
	struct timeval tv;
	unsigned long current_jiffies, timeout;
	u32 gap;

	/* get time */
	current_jiffies = jiffies;
	do_gettimeofday(&tv);

	/* avoid overflow with gap >1s */
	if (tv.tv_sec - ir->base_time.tv_sec > 1) {
		gap = 200000;
	} else {
		gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
		    tv.tv_usec - ir->base_time.tv_usec;
	}

	/* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */
	if (gap < 28000) {
		dprintk(KERN_WARNING "spurious timer_end\n");
		return;
	}

	ir->active = 0;
	if (ir->last_bit < 20) {
		/* ignore spurious codes (caused by light/other remotes) */
		dprintk(KERN_WARNING "short code: %x\n", ir->code);
	} else {
		u32 rc5 = rc5_decode(ir->code);

		/* two start bits? */
		if (RC5_START(rc5) != 3) {
			dprintk(KERN_WARNING "rc5 start bits invalid: %u\n", RC5_START(rc5));

			/* right address? */
		} else if (RC5_ADDR(rc5) == 0x0) {
			u32 toggle = RC5_TOGGLE(rc5);
			u32 instr = RC5_INSTR(rc5);

			/* Good code, decide if repeat/repress */
			if (toggle != RC5_TOGGLE(ir->last_rc5) ||
			    instr != RC5_INSTR(ir->last_rc5)) {
				dprintk(KERN_WARNING "instruction %x, toggle %x\n", instr,
					toggle);
				ir_input_nokey(ir->dev, &ir->ir);
				ir_input_keydown(ir->dev, &ir->ir, instr,
						 instr);
			}

			/* Set/reset key-up timer */
			timeout = current_jiffies + (500 + rc5_key_timeout
						     * HZ) / 1000;
			mod_timer(&ir->timer_keyup, timeout);

			/* Save code for repeat test */
			ir->last_rc5 = rc5;
		}
	}
}

static void bttv_rc5_timer_keyup(unsigned long data)
{
	struct bttv_ir *ir = (struct bttv_ir *)data;

	dprintk(KERN_DEBUG "key released\n");
	ir_input_nokey(ir->dev, &ir->ir);
}

/* ---------------------------------------------------------------------- */

static void bttv_ir_start(struct bttv *btv, struct bttv_ir *ir)
static void bttv_ir_start(struct bttv *btv, struct card_ir *ir)
{
	if (ir->polling) {
		init_timer(&ir->timer);
@@ -270,12 +162,17 @@ static void bttv_ir_start(struct bttv *btv, struct bttv_ir *ir)
	} else if (ir->rc5_gpio) {
		/* set timer_end for code completion */
		init_timer(&ir->timer_end);
		ir->timer_end.function = bttv_rc5_timer_end;
		ir->timer_end.function = ir_rc5_timer_end;
		ir->timer_end.data = (unsigned long)ir;

		init_timer(&ir->timer_keyup);
		ir->timer_keyup.function = bttv_rc5_timer_keyup;
		ir->timer_keyup.function = ir_rc5_timer_keyup;
		ir->timer_keyup.data = (unsigned long)ir;
		ir->shift_by = 1;
		ir->start = 3;
		ir->addr = 0x0;
		ir->rc5_key_timeout = ir_rc5_key_timeout;
		ir->rc5_remote_gap = ir_rc5_remote_gap;
	}
}

@@ -299,7 +196,7 @@ static void bttv_ir_stop(struct bttv *btv)

int bttv_input_init(struct bttv *btv)
{
	struct bttv_ir *ir;
	struct card_ir *ir;
	IR_KEYTAB_TYPE *ir_codes = NULL;
	struct input_dev *input_dev;
	int ir_type = IR_TYPE_OTHER;
+0 −27
Original line number Diff line number Diff line
@@ -197,33 +197,6 @@ struct bttv_core {
struct bttv;


struct bttv_ir {
	struct input_dev        *dev;
	struct ir_input_state   ir;
	char                    name[32];
	char                    phys[32];

	/* Usual gpio signalling */

	u32                     mask_keycode;
	u32                     mask_keydown;
	u32                     mask_keyup;
	u32                     polling;
	u32                     last_gpio;
	struct work_struct      work;
	struct timer_list       timer;

	/* RC5 gpio */
	u32 rc5_gpio;
	struct timer_list timer_end;	/* timer_end for code completion */
	struct timer_list timer_keyup;	/* timer_end for key release */
	u32 last_rc5;			/* last good rc5 code */
	u32 last_bit;			/* last raw bit seen */
	u32 code;			/* raw code under construction */
	struct timeval base_time;	/* time of last seen code */
	int active;			/* building raw code */
};

struct tvcard
{
	char *name;
+1 −1
Original line number Diff line number Diff line
@@ -308,7 +308,7 @@ struct bttv {

	/* infrared remote */
	int has_remote;
	struct bttv_ir *remote;
	struct card_ir *remote;

	/* locking */
	spinlock_t s_lock;
Loading