mirror of
https://github.com/adulau/aha.git
synced 2024-12-29 12:16:20 +00:00
V4L/DVB (13615): ir-core: create ir_input_register
Move non-V4L specific stuff from ir-functions ir_input_init() into a new function to register ir devices: ir_input_register(). Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
parent
865fbf20be
commit
75543cce0c
4 changed files with 48 additions and 31 deletions
|
@ -56,24 +56,11 @@ int ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
|
||||||
{
|
{
|
||||||
ir->ir_type = ir_type;
|
ir->ir_type = ir_type;
|
||||||
|
|
||||||
ir->keytable.size = ir_roundup_tablesize(ir_codes->size);
|
|
||||||
ir->keytable.scan = kzalloc(ir->keytable.size *
|
|
||||||
sizeof(struct ir_scancode), GFP_KERNEL);
|
|
||||||
if (!ir->keytable.scan)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
IR_dprintk(1, "Allocated space for %d keycode entries (%zd bytes)\n",
|
|
||||||
ir->keytable.size,
|
|
||||||
ir->keytable.size * sizeof(ir->keytable.scan));
|
|
||||||
|
|
||||||
ir_copy_table(&ir->keytable, ir_codes);
|
|
||||||
ir_set_keycode_table(dev, &ir->keytable);
|
|
||||||
|
|
||||||
clear_bit(0, dev->keybit);
|
|
||||||
set_bit(EV_KEY, dev->evbit);
|
|
||||||
if (repeat)
|
if (repeat)
|
||||||
set_bit(EV_REP, dev->evbit);
|
set_bit(EV_REP, dev->evbit);
|
||||||
|
|
||||||
|
ir_input_register(dev, ir_codes);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(ir_input_init);
|
EXPORT_SYMBOL_GPL(ir_input_init);
|
||||||
|
|
|
@ -125,7 +125,8 @@ static int ir_getkeycode(struct input_dev *dev,
|
||||||
int scancode, int *keycode)
|
int scancode, int *keycode)
|
||||||
{
|
{
|
||||||
int elem;
|
int elem;
|
||||||
struct ir_scancode_table *rc_tab = input_get_drvdata(dev);
|
struct ir_input_dev *ir_dev = input_get_drvdata(dev);
|
||||||
|
struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
|
||||||
|
|
||||||
elem = ir_seek_table(rc_tab, scancode);
|
elem = ir_seek_table(rc_tab, scancode);
|
||||||
if (elem >= 0) {
|
if (elem >= 0) {
|
||||||
|
@ -296,7 +297,8 @@ static int ir_setkeycode(struct input_dev *dev,
|
||||||
int scancode, int keycode)
|
int scancode, int keycode)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct ir_scancode_table *rc_tab = input_get_drvdata(dev);
|
struct ir_input_dev *ir_dev = input_get_drvdata(dev);
|
||||||
|
struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
|
||||||
struct ir_scancode *keymap = rc_tab->scan;
|
struct ir_scancode *keymap = rc_tab->scan;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
|
@ -370,7 +372,8 @@ static int ir_setkeycode(struct input_dev *dev,
|
||||||
*/
|
*/
|
||||||
u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode)
|
u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode)
|
||||||
{
|
{
|
||||||
struct ir_scancode_table *rc_tab = input_get_drvdata(dev);
|
struct ir_input_dev *ir_dev = input_get_drvdata(dev);
|
||||||
|
struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
|
||||||
struct ir_scancode *keymap = rc_tab->scan;
|
struct ir_scancode *keymap = rc_tab->scan;
|
||||||
int elem;
|
int elem;
|
||||||
|
|
||||||
|
@ -391,7 +394,7 @@ u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode)
|
||||||
EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
|
EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ir_set_keycode_table() - sets the IR keycode table and add the handlers
|
* ir_input_register() - sets the IR keycode table and add the handlers
|
||||||
* for keymap table get/set
|
* for keymap table get/set
|
||||||
* @input_dev: the struct input_dev descriptor of the device
|
* @input_dev: the struct input_dev descriptor of the device
|
||||||
* @rc_tab: the struct ir_scancode_table table of scancode/keymap
|
* @rc_tab: the struct ir_scancode_table table of scancode/keymap
|
||||||
|
@ -400,17 +403,34 @@ EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
|
||||||
* an IR.
|
* an IR.
|
||||||
* It should be called before registering the IR device.
|
* It should be called before registering the IR device.
|
||||||
*/
|
*/
|
||||||
int ir_set_keycode_table(struct input_dev *input_dev,
|
int ir_input_register(struct input_dev *input_dev,
|
||||||
struct ir_scancode_table *rc_tab)
|
struct ir_scancode_table *rc_tab)
|
||||||
{
|
{
|
||||||
|
struct ir_input_dev *ir_dev;
|
||||||
struct ir_scancode *keymap = rc_tab->scan;
|
struct ir_scancode *keymap = rc_tab->scan;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
spin_lock_init(&rc_tab->lock);
|
|
||||||
|
|
||||||
if (rc_tab->scan == NULL || !rc_tab->size)
|
if (rc_tab->scan == NULL || !rc_tab->size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
ir_dev = kzalloc(sizeof(*ir_dev), GFP_KERNEL);
|
||||||
|
if (!ir_dev)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
spin_lock_init(&rc_tab->lock);
|
||||||
|
|
||||||
|
ir_dev->rc_tab.size = ir_roundup_tablesize(rc_tab->size);
|
||||||
|
ir_dev->rc_tab.scan = kzalloc(ir_dev->rc_tab.size *
|
||||||
|
sizeof(struct ir_scancode), GFP_KERNEL);
|
||||||
|
if (!ir_dev->rc_tab.scan)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
IR_dprintk(1, "Allocated space for %d keycode entries (%zd bytes)\n",
|
||||||
|
ir_dev->rc_tab.size,
|
||||||
|
ir_dev->rc_tab.size * sizeof(ir_dev->rc_tab.scan));
|
||||||
|
|
||||||
|
ir_copy_table(&ir_dev->rc_tab, rc_tab);
|
||||||
|
|
||||||
/* set the bits for the keys */
|
/* set the bits for the keys */
|
||||||
IR_dprintk(1, "key map size: %d\n", rc_tab->size);
|
IR_dprintk(1, "key map size: %d\n", rc_tab->size);
|
||||||
for (i = 0; i < rc_tab->size; i++) {
|
for (i = 0; i < rc_tab->size; i++) {
|
||||||
|
@ -418,18 +438,22 @@ int ir_set_keycode_table(struct input_dev *input_dev,
|
||||||
i, keymap[i].keycode);
|
i, keymap[i].keycode);
|
||||||
set_bit(keymap[i].keycode, input_dev->keybit);
|
set_bit(keymap[i].keycode, input_dev->keybit);
|
||||||
}
|
}
|
||||||
|
clear_bit(0, input_dev->keybit);
|
||||||
|
|
||||||
|
set_bit(EV_KEY, input_dev->evbit);
|
||||||
|
|
||||||
input_dev->getkeycode = ir_getkeycode;
|
input_dev->getkeycode = ir_getkeycode;
|
||||||
input_dev->setkeycode = ir_setkeycode;
|
input_dev->setkeycode = ir_setkeycode;
|
||||||
input_set_drvdata(input_dev, rc_tab);
|
input_set_drvdata(input_dev, ir_dev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(ir_set_keycode_table);
|
EXPORT_SYMBOL_GPL(ir_input_register);
|
||||||
|
|
||||||
void ir_input_free(struct input_dev *dev)
|
void ir_input_free(struct input_dev *dev)
|
||||||
{
|
{
|
||||||
struct ir_scancode_table *rc_tab = input_get_drvdata(dev);
|
struct ir_input_dev *ir_dev = input_get_drvdata(dev);
|
||||||
|
struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
|
||||||
|
|
||||||
if (!rc_tab)
|
if (!rc_tab)
|
||||||
return;
|
return;
|
||||||
|
@ -439,6 +463,9 @@ void ir_input_free(struct input_dev *dev)
|
||||||
rc_tab->size = 0;
|
rc_tab->size = 0;
|
||||||
kfree(rc_tab->scan);
|
kfree(rc_tab->scan);
|
||||||
rc_tab->scan = NULL;
|
rc_tab->scan = NULL;
|
||||||
|
|
||||||
|
kfree(ir_dev);
|
||||||
|
input_set_drvdata(dev, NULL);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(ir_input_free);
|
EXPORT_SYMBOL_GPL(ir_input_free);
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,6 @@ struct ir_input_state {
|
||||||
/* configuration */
|
/* configuration */
|
||||||
int ir_type;
|
int ir_type;
|
||||||
|
|
||||||
struct ir_scancode_table keytable;
|
|
||||||
|
|
||||||
/* key info */
|
/* key info */
|
||||||
u32 ir_key; /* ir scancode */
|
u32 ir_key; /* ir scancode */
|
||||||
u32 keycode; /* linux key code */
|
u32 keycode; /* linux key code */
|
||||||
|
|
|
@ -41,6 +41,11 @@ struct ir_scancode_table {
|
||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ir_input_dev {
|
||||||
|
struct input_dev *dev;
|
||||||
|
struct ir_scancode_table rc_tab;
|
||||||
|
};
|
||||||
|
|
||||||
/* Routines from ir-keytable.c */
|
/* Routines from ir-keytable.c */
|
||||||
|
|
||||||
u32 ir_g_keycode_from_table(struct input_dev *input_dev,
|
u32 ir_g_keycode_from_table(struct input_dev *input_dev,
|
||||||
|
@ -50,8 +55,8 @@ int ir_set_keycode_table(struct input_dev *input_dev,
|
||||||
struct ir_scancode_table *rc_tab);
|
struct ir_scancode_table *rc_tab);
|
||||||
|
|
||||||
int ir_roundup_tablesize(int n_elems);
|
int ir_roundup_tablesize(int n_elems);
|
||||||
int ir_copy_table(struct ir_scancode_table *destin,
|
int ir_input_register(struct input_dev *dev,
|
||||||
const struct ir_scancode_table *origin);
|
struct ir_scancode_table *ir_codes);
|
||||||
void ir_input_free(struct input_dev *input_dev);
|
void ir_input_free(struct input_dev *input_dev);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue