On Sunday 2010-03-28 03:58, Adam Nielsen wrote:
>>>
>>> I can post this again if you'd like to take a look. I also have a kernel
>>> module that makes your keyboard LEDs available as LED devices if you want to
>>> test it out too. (I could certainly use some feedback on that!)
>>
>> Yes that would be nice, as I don't have any other LED hardware around
>> other than a cramped WRT54 device.
>
>I've uploaded the kernel module to make your keyboard LEDs accessible as LED
>devices here: http://www.shikadi.net/files/kernel/leds-input-20100328.tar.bz2
I've got patches for that. (attached)
>It's still a bit rough, but if you can see any obvious mistakes I've made
>please let me know! There are a couple of minor issues I'm aware of listed at
>the top of the .c file.
>Due to the limited bandwidth available to most input devices, it's
>possible for a fast enough trigger (e.g. netfilter) to saturate the
>link with LED on/off messages, causing a delay between pressing a
>key and having it appear on the screen. With netfilter the
>"--led-delay 1" option solves the problem, but it might be worth
>implementing a delay here too so that it works with other LED
>trigger sources too.
And what I observed is that I get duplicated keypresses when there is
network activity. (UP with CONFIG_PREEMPT=y.) Most likely because the
i8042 keyboard is such a piece of legacy hardware that it is not
worth investigating. I don't have any USB keyboard handy right now,
so testing that needs to wait until after the holidays.
But other than that, does its job.
---
Makefile | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Index: leds-input/Makefile
===================================================================
--- leds-input.orig/Makefile
+++ leds-input/Makefile
@@ -1,4 +1,9 @@
+KERNEL_DIR := /lib/modules/$(shell uname -r)/build
+
obj-m := leds-input.o
all:
- $(MAKE) -C /usr/src/linux M=`pwd` modules
+ $(MAKE) -C ${KERNEL_DIR} M=$$PWD
+
+clean:
+ $(MAKE) -C ${KERNEL_DIR} M=$$PWD $@
---
leds-input.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
Index: leds-input/leds-input.c
===================================================================
--- leds-input.orig/leds-input.c
+++ leds-input/leds-input.c
@@ -55,12 +55,8 @@ struct leddev {
char led_name[20]; /* As per led_classdev.name */
};
-/* Figure out if a bit is set in an array of longs */
-#define IS_BIT_SET(buffer, bit) \
- ((((buffer)[BITS_TO_LONGS((bit) + 1) - 1] >> ((bit) % BITS_PER_LONG))) & 1)
-
/* The order of these mappings must match the LED_* constants in input.h */
-static const char *lednames[] = {
+static const char *const lednames[] = {
"num", /* LED_NUML */
"caps", /* LED_CAPSL */
"scroll", /* LED_SCROLL */
@@ -84,7 +80,7 @@ static const char *lednames[] = {
static void leds_input_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
- struct leddev *leddev;
+ const struct leddev *leddev;
leddev = container_of(led_cdev, struct leddev, led_cdev);
input_inject_event(&leddev->handler_data->handle,
@@ -98,14 +94,17 @@ static void leds_input_set(struct led_cl
/* Called when the LED class driver wants to know this LED's brightness */
static enum led_brightness leds_input_get(struct led_classdev *led_cdev)
{
- struct leddev *leddev = container_of(led_cdev, struct leddev, led_cdev);
+ const struct leddev *leddev =
+ container_of(led_cdev, struct leddev, led_cdev);
struct input_dev *indev;
- if (!leddev->handler_data) return LED_OFF; /* too early */
+ if (!leddev->handler_data)
+ return LED_OFF; /* too early */
indev = leddev->handler_data->handle.dev;
- if (!indev) return LED_OFF;
+ if (!indev)
+ return LED_OFF;
- if (IS_BIT_SET(indev->led, leddev->evdev_led_id))
+ if (test_bit(leddev->evdev_led_id, indev->led))
return LED_FULL;
return LED_OFF;
@@ -195,7 +194,7 @@ static int leddev_connect(struct input_h
/* Register a device in the LED class for each LED reported by the input layer */
newleds = 0;
for (i = 0; i < LED_CNT; i++) {
- if (IS_BIT_SET(dev->ledbit, i)) {
+ if (test_bit(i, dev->ledbit)) {
//printk(KERN_DEBUG DRVMSG "has led %d (%s)\n", i, lednames[i]);
error = leddev_create(handler_data, handler, dev, i);
if (!error)
@@ -283,7 +282,6 @@ static int __init leds_input_init(void)
static void __exit leds_input_exit(void)
{
input_unregister_handler(&leddev_handler);
- return;
}
module_init(leds_input_init);