Skip to content

Commit

Permalink
V4L/DVB (13615): ir-core: create ir_input_register
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Mauro Carvalho Chehab committed Dec 16, 2009
1 parent 865fbf2 commit 75543cc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
17 changes: 2 additions & 15 deletions drivers/media/IR/ir-functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,11 @@ int ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
{
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)
set_bit(EV_REP, dev->evbit);

ir_input_register(dev, ir_codes);

return 0;
}
EXPORT_SYMBOL_GPL(ir_input_init);
Expand Down
51 changes: 39 additions & 12 deletions drivers/media/IR/ir-keytable.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ static int ir_getkeycode(struct input_dev *dev,
int scancode, int *keycode)
{
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);
if (elem >= 0) {
Expand Down Expand Up @@ -296,7 +297,8 @@ static int ir_setkeycode(struct input_dev *dev,
int scancode, int keycode)
{
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;
unsigned long flags;

Expand Down Expand Up @@ -370,7 +372,8 @@ static int ir_setkeycode(struct input_dev *dev,
*/
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;
int elem;

Expand All @@ -391,7 +394,7 @@ u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode)
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
* @input_dev: the struct input_dev descriptor of the device
* @rc_tab: the struct ir_scancode_table table of scancode/keymap
Expand All @@ -400,36 +403,57 @@ EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
* an IR.
* It should be called before registering the IR device.
*/
int ir_set_keycode_table(struct input_dev *input_dev,
struct ir_scancode_table *rc_tab)
int ir_input_register(struct input_dev *input_dev,
struct ir_scancode_table *rc_tab)
{
struct ir_scancode *keymap = rc_tab->scan;
struct ir_input_dev *ir_dev;
struct ir_scancode *keymap = rc_tab->scan;
int i;

spin_lock_init(&rc_tab->lock);

if (rc_tab->scan == NULL || !rc_tab->size)
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 */
IR_dprintk(1, "key map size: %d\n", rc_tab->size);
for (i = 0; i < rc_tab->size; i++) {
IR_dprintk(1, "#%d: setting bit for keycode 0x%04x\n",
i, keymap[i].keycode);
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->setkeycode = ir_setkeycode;
input_set_drvdata(input_dev, rc_tab);
input_set_drvdata(input_dev, ir_dev);

return 0;
}
EXPORT_SYMBOL_GPL(ir_set_keycode_table);
EXPORT_SYMBOL_GPL(ir_input_register);

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)
return;
Expand All @@ -439,6 +463,9 @@ void ir_input_free(struct input_dev *dev)
rc_tab->size = 0;
kfree(rc_tab->scan);
rc_tab->scan = NULL;

kfree(ir_dev);
input_set_drvdata(dev, NULL);
}
EXPORT_SYMBOL_GPL(ir_input_free);

Expand Down
2 changes: 0 additions & 2 deletions include/media/ir-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ struct ir_input_state {
/* configuration */
int ir_type;

struct ir_scancode_table keytable;

/* key info */
u32 ir_key; /* ir scancode */
u32 keycode; /* linux key code */
Expand Down
9 changes: 7 additions & 2 deletions include/media/ir-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ struct ir_scancode_table {
spinlock_t lock;
};

struct ir_input_dev {
struct input_dev *dev;
struct ir_scancode_table rc_tab;
};

/* Routines from ir-keytable.c */

u32 ir_g_keycode_from_table(struct input_dev *input_dev,
Expand All @@ -50,8 +55,8 @@ int ir_set_keycode_table(struct input_dev *input_dev,
struct ir_scancode_table *rc_tab);

int ir_roundup_tablesize(int n_elems);
int ir_copy_table(struct ir_scancode_table *destin,
const struct ir_scancode_table *origin);
int ir_input_register(struct input_dev *dev,
struct ir_scancode_table *ir_codes);
void ir_input_free(struct input_dev *input_dev);

#endif

0 comments on commit 75543cc

Please sign in to comment.