Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
f6fc5049
Commit
f6fc5049
authored
Nov 29, 2009
by
Mauro Carvalho Chehab
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
V4L/DVB (13538): ir-common: Use a dynamic keycode table
Signed-off-by:
Mauro Carvalho Chehab
<
mchehab@redhat.com
>
parent
055cd556
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
8 deletions
+92
-8
drivers/media/common/ir-functions.c
drivers/media/common/ir-functions.c
+11
-8
drivers/media/common/ir-keytable.c
drivers/media/common/ir-keytable.c
+75
-0
include/media/ir-common.h
include/media/ir-common.h
+6
-0
No files found.
drivers/media/common/ir-functions.c
View file @
f6fc5049
...
...
@@ -59,12 +59,20 @@ int ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
{
ir
->
ir_type
=
ir_type
;
/* FIXME: Add the proper code to dynamically allocate IR table */
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_set_keycode_table
(
dev
,
ir_codes
);
IR_dprintk
(
1
,
"Allocated space for %d keycode entries (%zd bytes)
\n
"
,
ir
->
keytable
.
size
,
ir
->
keytable
.
size
*
sizeof
(
ir
->
keytable
.
scan
));
clear_bit
(
0
,
dev
->
keybit
);
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
);
...
...
@@ -73,11 +81,6 @@ int ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
}
EXPORT_SYMBOL_GPL
(
ir_input_init
);
void
ir_input_free
(
struct
input_dev
*
input_dev
)
{
/* FIXME: Add the proper code to free allocated resources */
}
EXPORT_SYMBOL_GPL
(
ir_input_free
);
void
ir_input_nokey
(
struct
input_dev
*
dev
,
struct
ir_input_state
*
ir
)
{
...
...
drivers/media/common/ir-keytable.c
View file @
f6fc5049
...
...
@@ -7,6 +7,68 @@
#include <media/ir-common.h>
#define IR_TAB_MIN_SIZE 32
/**
* ir_roundup_tablesize() - gets an optimum value for the table size
* @n_elems: minimum number of entries to store keycodes
*
* This routine is used to choose the keycode table size.
*
* In order to have some empty space for new keycodes,
* and knowing in advance that kmalloc allocates only power of two
* segments, it optimizes the allocated space to have some spare space
* for those new keycodes by using the maximum number of entries that
* will be effectively be allocated by kmalloc.
* In order to reduce the quantity of table resizes, it has a minimum
* table size of IR_TAB_MIN_SIZE.
*/
int
ir_roundup_tablesize
(
int
n_elems
)
{
size_t
size
;
if
(
n_elems
<
IR_TAB_MIN_SIZE
)
n_elems
=
IR_TAB_MIN_SIZE
;
/*
* As kmalloc only allocates sizes of power of two, get as
* much entries as possible for the allocated memory segment
*/
size
=
roundup_pow_of_two
(
n_elems
*
sizeof
(
struct
ir_scancode
));
n_elems
=
size
/
sizeof
(
struct
ir_scancode
);
return
n_elems
;
}
/**
* ir_copy_table() - copies a keytable, discarding the unused entries
* @destin: destin table
* @origin: origin table
*
* Copies all entries where the keycode is not KEY_UNKNOWN/KEY_RESERVED
*/
int
ir_copy_table
(
struct
ir_scancode_table
*
destin
,
const
struct
ir_scancode_table
*
origin
)
{
int
i
,
j
=
0
;
for
(
i
=
0
;
i
<
origin
->
size
;
i
++
)
{
if
(
origin
->
scan
[
i
].
keycode
!=
KEY_UNKNOWN
&&
origin
->
scan
[
i
].
keycode
!=
KEY_RESERVED
)
{
memcpy
(
&
destin
->
scan
[
j
],
&
origin
->
scan
[
i
],
sizeof
(
struct
ir_scancode
));
j
++
;
}
}
destin
->
size
=
j
;
IR_dprintk
(
1
,
"Copied %d scancodes to the new keycode table
\n
"
,
j
);
return
0
;
}
/**
* ir_getkeycode() - get a keycode at the evdev scancode ->keycode table
* @dev: the struct input_dev device descriptor
...
...
@@ -152,3 +214,16 @@ int ir_set_keycode_table(struct input_dev *input_dev,
return
0
;
}
void
ir_input_free
(
struct
input_dev
*
dev
)
{
struct
ir_scancode_table
*
rc_tab
=
input_get_drvdata
(
dev
);
IR_dprintk
(
1
,
"Freed keycode table
\n
"
);
rc_tab
->
size
=
0
;
kfree
(
rc_tab
->
scan
);
rc_tab
->
scan
=
NULL
;
}
EXPORT_SYMBOL_GPL
(
ir_input_free
);
include/media/ir-common.h
View file @
f6fc5049
...
...
@@ -54,6 +54,8 @@ 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 */
...
...
@@ -121,6 +123,10 @@ u32 ir_g_keycode_from_table(struct input_dev *input_dev,
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
);
void
ir_input_free
(
struct
input_dev
*
input_dev
);
/* scancode->keycode map tables from ir-keymaps.c */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment