From patchwork Thu Apr 1 17:56:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 90236 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o31Hwsk4005885 for ; Thu, 1 Apr 2010 17:59:07 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758189Ab0DAR67 (ORCPT ); Thu, 1 Apr 2010 13:58:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44285 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758678Ab0DAR6K (ORCPT ); Thu, 1 Apr 2010 13:58:10 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o31HwAEs023770 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 1 Apr 2010 13:58:10 -0400 Received: from pedra (vpn-10-70.rdu.redhat.com [10.11.10.70]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o31HvftK005012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 Apr 2010 13:58:08 -0400 Date: Thu, 1 Apr 2010 14:56:32 -0300 From: Mauro Carvalho Chehab To: linux-input@vger.kernel.org, Linux Media Mailing List Subject: [PATCH 05/15] V4L/DVB: ir-core: add two functions to report keyup/keydown events Message-ID: <20100401145632.374ec6c9@pedra> In-Reply-To: References: Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 01 Apr 2010 17:59:08 +0000 (UTC) diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c index 2d9ba84..ab60730 100644 --- a/drivers/media/IR/ir-keytable.c +++ b/drivers/media/IR/ir-keytable.c @@ -364,7 +364,7 @@ static int ir_setkeycode(struct input_dev *dev, * * This routine is used by the input routines when a key is pressed at the * IR. The scancode is received and needs to be converted into a keycode. - * If the key is not found, it returns KEY_UNKNOWN. Otherwise, returns the + * If the key is not found, it returns KEY_RESERVED. Otherwise, returns the * corresponding keycode from the table. */ u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode) @@ -391,6 +391,61 @@ u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode) EXPORT_SYMBOL_GPL(ir_g_keycode_from_table); /** + * ir_keyup() - generates input event to cleanup a key press + * @input_dev: the struct input_dev descriptor of the device + * + * This routine is used by the input routines when a key is pressed at the + * IR. It reports a keyup input event via input_report_key(). + */ +void ir_keyup(struct input_dev *dev) +{ + struct ir_input_dev *ir = input_get_drvdata(dev); + + if (!ir->keypressed) + return; + + input_report_key(dev, ir->keycode, 0); + input_sync(dev); + ir->keypressed = 0; +} +EXPORT_SYMBOL_GPL(ir_keyup); + +/** + * ir_keydown() - generates input event for a key press + * @input_dev: the struct input_dev descriptor of the device + * @scancode: the scancode that we're seeking + * + * This routine is used by the input routines when a key is pressed at the + * IR. It gets the keycode for a scancode and reports an input event via + * input_report_key(). + */ +void ir_keydown(struct input_dev *dev, int scancode) +{ + struct ir_input_dev *ir = input_get_drvdata(dev); + + u32 keycode = ir_g_keycode_from_table(dev, scancode); + + /* If already sent a keydown, do a keyup */ + if (ir->keypressed) + ir_keyup(dev); + + if (KEY_RESERVED == keycode) + return; + + ir->keycode = keycode; + ir->keypressed = 1; + + IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n", + dev->name, keycode, scancode); + + input_report_key(dev, ir->keycode, 1); + input_sync(dev); + +} +EXPORT_SYMBOL_GPL(ir_keydown); + + +/** * ir_input_register() - sets the IR keycode table and add the handlers * for keymap table get/set * @input_dev: the struct input_dev descriptor of the device diff --git a/include/media/ir-core.h b/include/media/ir-core.h index 369969d..198fd61 100644 --- a/include/media/ir-core.h +++ b/include/media/ir-core.h @@ -72,6 +72,10 @@ struct ir_input_dev { unsigned long devno; /* device number */ const struct ir_dev_props *props; /* Device properties */ struct ir_raw_event_ctrl *raw; /* for raw pulse/space events */ + + /* key info - needed by IR keycode handlers */ + u32 keycode; /* linux key code */ + int keypressed; /* current state */ }; #define to_ir_input_dev(_attr) container_of(_attr, struct ir_input_dev, attr)