Skip to contentSkip to conversation

blink driver power saving

DISCUSSION Indan Zupancic 9 participants 26 messages Jul 2, 2007 – Jul 13, 2007 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Quoted 5 lines · Andi Kleen

Well only those that could be already hung from user space with setleds (that was also confirmed). Actually I thought they didn't hang completely, but just stopped reacting to the keyboard (which is actually pretty bad for every user to be able to trigger)

Pavel's lost key events, mine stopped reacting altogether.

Quoted 3 lines

I guess the better way to handle those would be to find out the minimum frequency of blinking that is still ok and rate limit it to that in the keyboard driver.

Dmitry already has a patch for that. He limited it to one event each 50 ms.

Quoted 3 lines

Anyways, Stephen's patch just doesn't make sense:
he clearly didn't understand the code at all. Before you apply it and cripple it better drop the driver completely.

CC'ing Dmitry, as I think he doesn't like the blink driver much either. ;-)

Greetings,

Indan

#1 lore raw
Quoted 8 lines · On Monday 02 July 2007 13:43:23 Indan Zupancic wrote:
Quoted 5 lines · Andi Kleen

Well only those that could be already hung from user space with setleds (that was also confirmed). Actually I thought they didn't hang completely, but just stopped reacting to the keyboard (which is actually pretty bad for every user to be able to trigger)

Pavel's lost key events, mine stopped reacting altogether.

Did you try if the network was still alive? Perhaps it was just a locked up keyboard.

Quoted 6 lines
Quoted 4 lines

I guess the better way to handle those would be to find out the minimum frequency of blinking that is still ok and rate limit it to that in the keyboard driver.

Dmitry already has a patch for that. He limited it to one event each 50 ms.

Great.

Quoted 6 lines
Quoted 4 lines

Anyways, Stephen's patch just doesn't make sense:
he clearly didn't understand the code at all. Before you apply it and cripple it better drop the driver completely.

CC'ing Dmitry, as I think he doesn't like the blink driver much either. ;-)

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

-Andi

#2 lore raw
Quoted 8 lines · Andi Kleen
Quoted 7 lines · On Monday 02 July 2007 13:43:23 Indan Zupancic wrote:
Quoted 5 lines · Andi Kleen

Well only those that could be already hung from user space with setleds (that was also confirmed). Actually I thought they didn't hang completely, but just stopped reacting to the keyboard (which is actually pretty bad for every user to be able to trigger)

Quoted 4 lines
Quoted 1 line

Pavel's lost key events, mine stopped reacting altogether.

Did you try if the network was still alive? Perhaps it was just a locked up keyboard.

No, it wasn't locked up, because the leds were blinking. I think if I waited long enough it eventually reacted to other key presses too, sometimes. At least flooding it with Ctrl+C stopped the setleds loop long after I had any hope left.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

Anyways, Stephen's patch just doesn't make sense:
he clearly didn't understand the code at all. Before you apply it and cripple it better drop the driver completely.

CC'ing Dmitry, as I think he doesn't like the blink driver much either. ;-)

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

While someone's at it, perhaps USB keyboards could be made working too. And make it generic infrastructure too so everyone can (ab)use it? What about adopting the approach here and share the code:
http://lkml.org/lkml/2007/6/19/112

At least it works with all keyboards...

Greetings,

Indan

#3 lore raw
In reply to Andi Kleen
Quoted 27 lines · Andi Kleen
Quoted 8 lines · On Monday 02 July 2007 13:43:23 Indan Zupancic wrote:
Quoted 5 lines · Andi Kleen

Well only those that could be already hung from user space with setleds (that was also confirmed). Actually I thought they didn't hang completely, but just stopped reacting to the keyboard (which is actually pretty bad for every user to be able to trigger)

Pavel's lost key events, mine stopped reacting altogether.

Did you try if the network was still alive? Perhaps it was just a locked up keyboard.

Quoted 6 lines
Quoted 4 lines

I guess the better way to handle those would be to find out the minimum frequency of blinking that is still ok and rate limit it to that in the keyboard driver.

Dmitry already has a patch for that. He limited it to one event each 50 ms.

Great.

Quoted 5 lines
Quoted 4 lines

Anyways, Stephen's patch just doesn't make sense:
he clearly didn't understand the code at all. Before you apply it and cripple it better drop the driver completely.

Quoted 6 lines
Quoted 1 line

CC'ing Dmitry, as I think he doesn't like the blink driver much either. ;-)

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

I don't don't like it ;) Unfortunately too many people end up enabling it and having issues with their keyboards. Can we have it depend on DEBUG_KERNEL? And probably KEXEC as well?

Another option would be for it not use panic_blink. Do your kexec kernels have atkbd support enabled? You could write an new "blink" input handler that would latch to keyboards supporting leds and blink by sending EV_LED events.

Signature · 1 line
Dmitry
#4 lore raw
Quoted 7 lines
Quoted 5 lines

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

I don't don't like it ;) Unfortunately too many people end up enabling

Yes that's pretty weird. I admit I hadn't expected
that problem. blink is equivalent to "annoy me" and it
is a mystery why so many people should willingly ask their computer to annoy them.

Or perhaps they update their configs with yes | make oldconfig?

User psychology can be mysterious.

I wonder if the kernel offered a CONFIG_FORMAT_FILESYSTEMS_AT_BOOT how many people would enable that @) Might be an interesting experiment for next April.

Quoted 1 line

it and having issues with their keyboards.

Forcing a suitable slow rate should fix that shouldn't it? We need that anyways to stop the "setleds DOS".

Quoted 2 lines

Can we have it depend on
DEBUG_KERNEL?

Yes that would be probably a good idea; even though it is technically not correct: the debug kernel doesn't try to debug itself. But anyways, it's probably the best place.

Quoted 1 line

And probably KEXEC as well?

The kcrash kernel doesn't necessarily need to have kexec enabled by itself.

Quoted 4 lines

Another option would be for it not use panic_blink. Do your kexec kernels have atkbd support enabled? You could write an new "blink" input handler that would latch to keyboards supporting leds and blink by sending EV_LED events.

Yes that would be probably a better implementation. Also hook something for USB keyboards. iirc Bernhard Walle (cc'ed) was looking at that.

-Andi

#5 lore raw
Quoted 8 lines · Andi Kleen
Quoted 5 lines

Another option would be for it not use panic_blink. Do your kexec kernels have atkbd support enabled? You could write an new "blink" input handler that would latch to keyboards supporting leds and blink by sending EV_LED events.

Yes that would be probably a better implementation. Also hook something for USB keyboards. iirc Bernhard Walle (cc'ed) was looking at that.

The problem is that most distributions use USB as module (in initrd, or later). If you're able to load modules, you're also able to run a userspace programs that blinks. That's the way I implemented it in SUSE now. In my tests it takes about < 5 seconds from the sysrq-c to the time the first blink. That's ok IMO.

And if a person compiles his kernel manually, he doesn't need keyboard LED blinking for kdump because he can look at the HDD LED to see what happens (or serial console). ... :)

I don't know if it's worth to apply a patch that uses the keyboard interface in the kernel, because there are several small changes necessary (see patch, that's what my thought was).

Thanks,
Bernhard

---
 drivers/char/keyboard.c  |    7 +++++++
 include/linux/keyboard.h |    7 +++++++
 2 files changed, 14 insertions(+)
drivers/char/keyboard.c +7 -0
Index: linux-2.6.21.1/drivers/char/keyboard.c
===================================================================
@@ -956,6 +956,13 @@ void setledstate(struct kbd_struct *kbd,
 	set_leds();
 }
 
+void setledstate_fgconsole(unsigned int led)
+{
+	struct kbd_struct *kbd = kbd_table + fg_console;
+	setledstate(kbd, led);
+}
+EXPORT_SYMBOL_GPL(setledstate_fgconsole);
+
 static inline unsigned char getleds(void)
 {
 	struct kbd_struct *kbd = kbd_table + fg_console;
include/linux/keyboard.h +7 -0
Index: linux-2.6.21.1/include/linux/keyboard.h
===================================================================
@@ -441,4 +441,11 @@ extern unsigned short plain_map[NR_KEYS]
 #define NR_BRL		9
 
 #define MAX_DIACR	256
+
+
+
+#ifdef __KERNEL__
+void setledstate_fgconsole(unsigned int led);
+#endif
+
 #endif
#6 lore raw
In reply to Andi Kleen
Quoted 13 lines · Andi Kleen
Quoted 7 lines
Quoted 5 lines

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

I don't don't like it ;) Unfortunately too many people end up enabling

Yes that's pretty weird. I admit I hadn't expected
that problem. blink is equivalent to "annoy me" and it
is a mystery why so many people should willingly ask their computer to annoy them.

Quoted 8 lines

Or perhaps they update their configs with yes | make oldconfig?

User psychology can be mysterious.

I wonder if the kernel offered a CONFIG_FORMAT_FILESYSTEMS_AT_BOOT how many people would enable that @) Might be an interesting experiment for next April.

Heh ;) That could be interesting.

Quoted 5 lines
Quoted 1 line

it and having issues with their keyboards.

Forcing a suitable slow rate should fix that shouldn't it? We need that anyways to stop the "setleds DOS".

I already have a patch that throttles AT keyboard when switching LED state. However there is another problem - i8042's interrupt hanler is racing with panic_blink polling the keyboar controller and they both don;t quite like that.

Quoted 12 lines
Quoted 2 lines

Can we have it depend on
DEBUG_KERNEL?

Yes that would be probably a good idea; even though it is technically not correct: the debug kernel doesn't try to debug itself. But anyways, it's probably the best place.

Quoted 1 line

And probably KEXEC as well?

The kcrash kernel doesn't necessarily need to have kexec enabled by itself.

OK.

Quoted 8 lines
Quoted 4 lines

Another option would be for it not use panic_blink. Do your kexec kernels have atkbd support enabled? You could write an new "blink" input handler that would latch to keyboards supporting leds and blink by sending EV_LED events.

Yes that would be probably a better implementation. Also hook something for USB keyboards. iirc Bernhard Walle (cc'ed) was looking at that.

I was thinking about something like the atached (untested and sorry for using attachment). It shoudl blink just one led (numLock) on any keyboard that has such LED (and allows to control it).

Signature · 1 line
Dmitry

/*
* Debug driver that continuosly blink LEDs on keyboards *
* Copyright (c) 2007 Dmitry Torokhov
*/

/*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/

#include <linux/module.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/init.h>

MODULE_AUTHOR("Dmitry Torokhov <[email protected]>");
MODULE_DESCRIPTION("Blink driver");
MODULE_LICENSE("GPL");

struct blinker {
	struct delayed_work work;
	struct input_handle handle;
	int state;
};

static void blink_task_handler(struct work_struct *work)

{
	struct blinker *blinker = container_of(work, struct blinker, work.work);

	blinker->state = !blinker->state;
	input_inject_event(&blinker->handle, EV_LED, LED_NUML, blinker->state);
	schedule_delayed_work(&blinker->work, msecs_to_jiffies(250));
}

static void blink_event(struct input_handle *handle, unsigned int type,
unsigned int code, int down)

{
	/*
	 * This is a very rare handler that does not process any input
	 * events; just injects them.
	 */
}

static int blink_connect(struct input_handler *handler, struct input_dev *dev,
const struct input_device_id *id)

{
	struct blinker *blinker;
	struct input_handle *handle;
	int error;

	blinker = kzalloc(sizeof(struct blinker), GFP_KERNEL);
	if (!blinker)
		return -ENOMEM;

	INIT_DELAYED_WORK(&blinker->work, blink_task_handler);

	handle = &blinker->handle;
	handle->dev = dev;
	handle->handler = handler;
	handle->name = "blink";
	handle->private = blinker;

	error = input_register_handle(handle);
	if (error)
		goto err_free_handle;

	error = input_open_device(handle);
	if (error)
		goto err_unregister_handle;

	schedule_delayed_work(&blinker->work, 0);

	return 0;

err_unregister_handle:

	input_unregister_handle(handle);
 err_free_handle:
	kfree(handle);
	return error;
}

static void blink_disconnect(struct input_handle *handle)

{
	struct blinker *blinker = handle->private;

	cancel_rearming_delayed_work(&blinker->work);
	input_close_device(handle);
	input_unregister_handle(handle);
	kfree(blinker);
}
static const struct input_device_id blink_ids[] = {
	{
		.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_LEDBIT,
		.evbit = { BIT(EV_LED) },
		.keybit = { [LONG(LED_NUML)] = BIT(LED_NUML) },
	},
	{ }
};
static struct input_handler blink_handler = {
	.event		= blink_event;
	.connect	= blink_connect,
	.disconnect	= blink_disconnect,
	.name		= "blink",
	.id_table	= blink_ids,
};

static int __init blink_handler_init(void)

{
	return input_register_handler(&blink_handler);
}

static void __exit blink_handler_exit(void)

{
	input_unregister_handler(&blink_handler);
	flush_scheduled_work();
}

module_init(blink_handler_init);
module_exit(blink_handler_exit);

#7 lore raw
Quoted 5 lines · Dmitry Torokhov

I was thinking about something like the atached (untested and sorry for using attachment). It shoudl blink just one led (numLock) on any keyboard that has such LED (and allows to control it).

Argh, bad one. This one shoudl be better.

Signature · 1 line
Dmitry

/*
* Debug driver that continuosly blink LEDs on keyboards *
* Copyright (c) 2007 Dmitry Torokhov
*/

/*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/

#include <linux/module.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/init.h>

MODULE_AUTHOR("Dmitry Torokhov <[email protected]>");
MODULE_DESCRIPTION("Blink driver");
MODULE_LICENSE("GPL");

struct blinker {
	struct delayed_work work;
	struct input_handle handle;
	int state;
};

static void blink_task_handler(struct work_struct *work)

{
	struct blinker *blinker = container_of(work, struct blinker, work.work);

	blinker->state = !blinker->state;
	input_inject_event(&blinker->handle, EV_LED, LED_NUML, blinker->state);
	schedule_delayed_work(&blinker->work, msecs_to_jiffies(250));
}

static void blink_event(struct input_handle *handle, unsigned int type,
unsigned int code, int down)

{
	/*
	 * This is a very rare handler that does not process any input
	 * events; just injects them.
	 */
}

static int blink_connect(struct input_handler *handler, struct input_dev *dev,
const struct input_device_id *id)

{
	struct blinker *blinker;
	struct input_handle *handle;
	int error;

	blinker = kzalloc(sizeof(struct blinker), GFP_KERNEL);
	if (!blinker)
		return -ENOMEM;

	INIT_DELAYED_WORK(&blinker->work, blink_task_handler);

	handle = &blinker->handle;
	handle->dev = dev;
	handle->handler = handler;
	handle->name = "blink";
	handle->private = blinker;

	error = input_register_handle(handle);
	if (error)
		goto err_free_handle;

	error = input_open_device(handle);
	if (error)
		goto err_unregister_handle;

	schedule_delayed_work(&blinker->work, 0);

	return 0;

err_unregister_handle:

	input_unregister_handle(handle);
 err_free_handle:
	kfree(handle);
	return error;
}

static void blink_disconnect(struct input_handle *handle)

{
	struct blinker *blinker = handle->private;

	cancel_rearming_delayed_work(&blinker->work);
	input_close_device(handle);
	input_unregister_handle(handle);
	kfree(blinker);
}
static const struct input_device_id blink_ids[] = {
	{
		.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_LEDBIT,
		.evbit = { BIT(EV_LED) },
		.ledbit = { [LONG(LED_NUML)] = BIT(LED_NUML) },
	},
	{ }
};
static struct input_handler blink_handler = {
	.event		= blink_event,
	.connect	= blink_connect,
	.disconnect	= blink_disconnect,
	.name		= "blink",
	.id_table	= blink_ids,
};

static int __init blink_handler_init(void)

{
	return input_register_handler(&blink_handler);
}

static void __exit blink_handler_exit(void)

{
	input_unregister_handler(&blink_handler);
	flush_scheduled_work();
}

module_init(blink_handler_init);
module_exit(blink_handler_exit);

#8 lore raw
Quoted 8 lines · Dmitry Torokhov
Quoted 5 lines · Dmitry Torokhov

I was thinking about something like the atached (untested and sorry for using attachment). It shoudl blink just one led (numLock) on any keyboard that has such LED (and allows to control it).

Argh, bad one. This one shoudl be better.

Ok, I didn't think of that possibility. That looks better than my attempt to modify low-level console stuff ... :)

Thanks,
Bernhard

#9 lore raw
In reply to Dmitry Torokhov

Hi!

Quoted 6 lines
Quoted 4 lines

I was thinking about something like the atached (untested and sorry for using attachment). It shoudl blink just one led (numLock) on any keyboard that has such LED (and allows to control it).

Argh, bad one. This one shoudl be better.

Does it blink for you? It does not seem to do anything here :-(.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#10 lore raw
Quoted 10 lines · Pavel Machek

Hi!

Quoted 6 lines
Quoted 4 lines

I was thinking about something like the atached (untested and sorry for using attachment). It shoudl blink just one led (numLock) on any keyboard that has such LED (and allows to control it).

Argh, bad one. This one shoudl be better.

Does it blink for you? It does not seem to do anything here :-(.

Yes it does. Just tested it and it blinks NumLock led just fine.

Signature · 1 line
Dmitry
#11 lore raw
In reply to Andi Kleen
Quoted 6 lines · Andi Kleen
Quoted 6 lines
Quoted 5 lines

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

Quoted 6 lines
Quoted 1 line

I don't don't like it ;) Unfortunately too many people end up enabling

Yes that's pretty weird. I admit I hadn't expected
that problem. blink is equivalent to "annoy me" and it
is a mystery why so many people should willingly ask their computer to annoy them.

tristate "Keyboard blink driver"

...drivers are not expected to act on their own. I was expecting to get nice /sys/class/led* interface to my keyboard leds.

BTW ... I still believe we should have /sys/class/led* interface to those leds. I'd like to make them blink with hdd activity on some machines... of course, that needs non-buggy KBC.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#12 lore raw
Quoted 14 lines · Pavel Machek
Quoted 6 lines · Andi Kleen
Quoted 6 lines
Quoted 5 lines

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

Quoted 6 lines
Quoted 1 line

I don't don't like it ;) Unfortunately too many people end up enabling

Yes that's pretty weird. I admit I hadn't expected
that problem. blink is equivalent to "annoy me" and it
is a mystery why so many people should willingly ask their computer to annoy them.

Quoted 8 lines

tristate "Keyboard blink driver"

...drivers are not expected to act on their own. I was expecting to get nice /sys/class/led* interface to my keyboard leds.

BTW ... I still believe we should have /sys/class/led* interface to those leds. I'd like to make them blink with hdd activity on some machines... of course, that needs non-buggy KBC.

I'll take patches. Ofcourse we'll have to keep the current EV_LED interface for compatibility.

Signature · 1 line
Dmitry
#13 lore raw

Hi!

Quoted 17 lines
Quoted 17 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

I don't don't like it ;) Unfortunately too many people end up enabling

Yes that's pretty weird. I admit I hadn't expected
that problem. blink is equivalent to "annoy me" and it
is a mystery why so many people should willingly ask their computer to annoy them.

tristate "Keyboard blink driver"

...drivers are not expected to act on their own. I was expecting to get nice /sys/class/led* interface to my keyboard leds.

Quoted 6 lines
Quoted 3 lines

BTW ... I still believe we should have /sys/class/led* interface to those leds. I'd like to make them blink with hdd activity on some machines... of course, that needs non-buggy KBC.

I'll take patches. Ofcourse we'll have to keep the current EV_LED interface for compatibility.

It was simpler then I thought... but it has one small problem. It does not actually work :-(..

it reaches the

        printk("Setting led to %d\n", blinker->state);
        input_inject_event(&blinker->handle, EV_LED, LED_NUML, blinker->state);

code, but my numlock led does not actually change. Any ideas?
Pavel

(leds-input.c:)

/*
* LED <-> input subsystem glue
*
* Copyright 2007 Pavel Machek <[email protected]>
* Copyright 2007 Dmitry Torokhov
* Copyright 2005-2006 Openedhand Ltd.
*
* Author: Pavel Machek <[email protected]>
* Based on code by: Richard Purdie <[email protected]> *
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/leds.h>

#include <linux/module.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/init.h>

struct blinker {
	struct delayed_work work;
	struct input_handle handle;
	int state;
};

struct blinker *blinker;

static void inputled_set(struct led_classdev *led_cdev, enum led_brightness value)

{
	blinker->state = value;
	schedule_delayed_work(&blinker->work, 0);
}

static struct led_classdev input_led = {
.name = "input",
.default_trigger = "sharpsl-charge",
.brightness_set = inputled_set,
};

static void blink_task_handler(struct work_struct *work)

{
	struct blinker *blinker = container_of(work, struct blinker, work.work);
	printk("Setting led to %d\n", blinker->state);
	input_inject_event(&blinker->handle, EV_LED, LED_NUML, blinker->state);
}

static void blink_event(struct input_handle *handle, unsigned int type,
unsigned int code, int down)

{
	/*
	 * This is a very rare handler that does not process any input
	 * events; just injects them.
	 */
}

static int blink_connect(struct input_handler *handler, struct input_dev *dev,
const struct input_device_id *id)

{
	struct input_handle *handle;
	int error;

	blinker = kzalloc(sizeof(struct blinker), GFP_KERNEL);
	if (!blinker)
		return -ENOMEM;

	INIT_DELAYED_WORK(&blinker->work, blink_task_handler);

	handle = &blinker->handle;
	handle->dev = dev;
	handle->handler = handler;
	handle->name = "blink";
	handle->private = blinker;

	error = input_register_handle(handle);
	if (error)
		goto err_free_handle;

	error = input_open_device(handle);
	if (error)
		goto err_unregister_handle;

	error = led_classdev_register(NULL, &input_led);
	if (error < 0)
		goto err_input_close_device;

	return 0;

err_input_close_device:

	input_close_device(handle);
 err_unregister_handle:
	input_unregister_handle(handle);
 err_free_handle:
	kfree(handle);
	return error;
}

static void blink_disconnect(struct input_handle *handle)

{
	struct blinker *blinker = handle->private;

	led_classdev_unregister(&input_led);
	cancel_rearming_delayed_work(&blinker->work);
	input_close_device(handle);
	input_unregister_handle(handle);
	kfree(blinker);
}
static const struct input_device_id blink_ids[] = {
	{
		.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_LEDBIT,
		.evbit = { BIT(EV_LED) },
		.ledbit = { [LONG(LED_NUML)] = BIT(LED_NUML) },
	},
	{ }
};
static struct input_handler blink_handler = {
	.event		= blink_event,
	.connect	= blink_connect,
	.disconnect	= blink_disconnect,
	.name		= "blink",
	.id_table	= blink_ids,
};

static int __init blink_handler_init(void)

{
	return input_register_handler(&blink_handler);
}

static void __exit blink_handler_exit(void)

{
	input_unregister_handler(&blink_handler);
	flush_scheduled_work();
}

module_init(blink_handler_init);
module_exit(blink_handler_exit);

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#14 lore raw
In reply to Dmitry Torokhov
Quoted 20 lines · Dmitry Torokhov
Quoted 19 lines · Pavel Machek
Quoted 6 lines · Andi Kleen
Quoted 6 lines
Quoted 5 lines

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

Quoted 6 lines
Quoted 1 line

I don't don't like it ;) Unfortunately too many people end up enabling

Yes that's pretty weird. I admit I hadn't expected
that problem. blink is equivalent to "annoy me" and it
is a mystery why so many people should willingly ask their computer to annoy them.

tristate "Keyboard blink driver"

...drivers are not expected to act on their own. I was expecting to get nice /sys/class/led* interface to my keyboard leds.

Quoted 6 lines
Quoted 3 lines

BTW ... I still believe we should have /sys/class/led* interface to those leds. I'd like to make them blink with hdd activity on some machines... of course, that needs non-buggy KBC.

I'll take patches. Ofcourse we'll have to keep the current EV_LED interface for compatibility.

Update.. both your and mine code seem to do something here -- but they only keep turning the led off. If I press numlock to turn it on, they will turn it off. Strange.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#15 lore raw
In reply to Dmitry Torokhov

Hi!

Quoted 17 lines
Quoted 17 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

I don't don't like it ;) Unfortunately too many people end up enabling

Yes that's pretty weird. I admit I hadn't expected
that problem. blink is equivalent to "annoy me" and it
is a mystery why so many people should willingly ask their computer to annoy them.

tristate "Keyboard blink driver"

...drivers are not expected to act on their own. I was expecting to get nice /sys/class/led* interface to my keyboard leds.

Quoted 6 lines
Quoted 3 lines

BTW ... I still believe we should have /sys/class/led* interface to those leds. I'd like to make them blink with hdd activity on some machines... of course, that needs non-buggy KBC.

I'll take patches. Ofcourse we'll have to keep the current EV_LED interface for compatibility.

Here's a working version. For some reason, it only works with capslock led. (But so does your code, is that thinkpad problem?)

Andi, by making default trigger "heartbeat", you can get very nice visual feedback :-).

/*
* LED <-> input subsystem glue
*
* Copyright 2007 Pavel Machek <[email protected]>
* Copyright 2007 Dmitry Torokhov
* Copyright 2005-2006 Openedhand Ltd.
*
* Author: Pavel Machek <[email protected]>
* Based on code by: Richard Purdie <[email protected]> *
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/leds.h>

#include <linux/module.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/init.h>

struct blinker {
	struct delayed_work work;
	struct input_handle handle;
	int state;
};

struct blinker *blinker;

static void inputled_set(struct led_classdev *led_cdev, enum led_brightness value)

{
	blinker->state = value;
	schedule_delayed_work(&blinker->work, 0);
}
static struct led_classdev input_led = {
	.name			= "input",
	.default_trigger	= "none",
	.brightness_set		= inputled_set,
};

static void blink_task_handler(struct work_struct *work)

{
	struct blinker *blinker = container_of(work, struct blinker, work.work);
	input_inject_event(&blinker->handle, EV_LED, LED_CAPSL, !!blinker->state);
}

static void blink_event(struct input_handle *handle, unsigned int type,
unsigned int code, int down)

{
	/*
	 * This is a very rare handler that does not process any input
	 * events; just injects them.
	 */
}

static int blink_connect(struct input_handler *handler, struct input_dev *dev,
const struct input_device_id *id)

{
	struct input_handle *handle;
	int error;

	blinker = kzalloc(sizeof(struct blinker), GFP_KERNEL);
	if (!blinker)
		return -ENOMEM;

	INIT_DELAYED_WORK(&blinker->work, blink_task_handler);

	handle = &blinker->handle;
	handle->dev = dev;
	handle->handler = handler;
	handle->name = "blink";
	handle->private = blinker;

	error = input_register_handle(handle);
	if (error)
		goto err_free_handle;

	error = input_open_device(handle);
	if (error)
		goto err_unregister_handle;

	error = led_classdev_register(NULL, &input_led);
	if (error < 0)
		goto err_input_close_device;

	return 0;

err_input_close_device:

	input_close_device(handle);
 err_unregister_handle:
	input_unregister_handle(handle);
 err_free_handle:
	kfree(handle);
	return error;
}

static void blink_disconnect(struct input_handle *handle)

{
	struct blinker *blinker = handle->private;

	led_classdev_unregister(&input_led);
	cancel_rearming_delayed_work(&blinker->work);
	input_close_device(handle);
	input_unregister_handle(handle);
	kfree(blinker);
}
static const struct input_device_id blink_ids[] = {
	{
		.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_LEDBIT,
		.evbit = { BIT(EV_LED) },
		.ledbit = { [LONG(LED_CAPSL)] = BIT(LED_CAPSL) },
	},
	{ }
};
static struct input_handler blink_handler = {
	.event		= blink_event,
	.connect	= blink_connect,
	.disconnect	= blink_disconnect,
	.name		= "blink",
	.id_table	= blink_ids,
};

static int __init blink_handler_init(void)

{
	return input_register_handler(&blink_handler);
}

static void __exit blink_handler_exit(void)

{
	input_unregister_handler(&blink_handler);
	flush_scheduled_work();
}

module_init(blink_handler_init);
module_exit(blink_handler_exit);

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#16 lore raw
Quoted 23 lines · Pavel Machek

Hi!

Quoted 21 lines
Quoted 20 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

I don't don't like it ;) Unfortunately too many people end up enabling

Yes that's pretty weird. I admit I hadn't expected
that problem. blink is equivalent to "annoy me" and it
is a mystery why so many people should willingly ask their computer to annoy them.

tristate "Keyboard blink driver"

...drivers are not expected to act on their own. I was expecting to get nice /sys/class/led* interface to my keyboard leds.

BTW ... I still believe we should have /sys/class/led* interface to those leds. I'd like to make them blink with hdd activity on some machines... of course, that needs non-buggy KBC.

Quoted 6 lines
Quoted 2 lines

I'll take patches. Ofcourse we'll have to keep the current EV_LED interface for compatibility.

Here's a working version. For some reason, it only works with capslock led. (But so does your code, is that thinkpad problem?)

My code does blink NumLock on my box (Dell) so I wonder why it does not on your box...

Anyway, as far as the patch goes - I don't think we want to do it this way for a couple of reasons:

1. It does not reflect the true device hierarchy - LEDs are not children of input devices, they are children of whatever device that owns input device. So in case of AT keyboard LEDs should grow from corresponding serio port, not input device and so atkbd should register all of its leds.

2. LEDs will stop working if input device is grabbed via EVIOCSGRAB. I think that grab should not cross subsystem boundaries.

Signature · 1 line
Dmitry
#17 lore raw

Hi!

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I'll take patches. Ofcourse we'll have to keep the current EV_LED interface for compatibility.

Here's a working version. For some reason, it only works with capslock led. (But so does your code, is that thinkpad problem?)

My code does blink NumLock on my box (Dell) so I wonder why it does not on your box...

setleds does not work here, either, so...

Quoted 8 lines

Anyway, as far as the patch goes - I don't think we want to do it this way for a couple of reasons:

1. It does not reflect the true device hierarchy - LEDs are not children of input devices, they are children of whatever device that owns input device. So in case of AT keyboard LEDs should grow from corresponding serio port, not input device and so atkbd should register all of its leds.

I'm not sure what you mean here. Should the code be moved to atkbd.c? ...and then duplicated to usbkbd.c?

Quoted 2 lines

2. LEDs will stop working if input device is grabbed via EVIOCSGRAB. I think that grab should not cross subsystem boundaries.

Well, if userspace grabbed a LED, it would make sense to stop blinking it from heartbeat, no?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#18 lore raw
Quoted 2 lines · Pavel Machek

I'm not sure what you mean here. Should the code be moved to atkbd.c? ...and then duplicated to usbkbd.c?

Hi Pavel,

just a sidenote - usbkbd.c is probably a confusing misnomer, renaming it to something more appropriate is on my todo for one day. It is not the driver that controls the USB keyboard on the majority of systems - see Kconfig help text, that explains it very clearly. USB keyboards are normally handled by usbhid module (drivers/hid/usbhid/*).

Signature · 1 line
Jiri Kosina
#19 lore raw
In reply to Dmitry Torokhov

Hi!

Quoted 11 lines
Quoted 8 lines

tristate "Keyboard blink driver"

...drivers are not expected to act on their own. I was expecting to get nice /sys/class/led* interface to my keyboard leds.

BTW ... I still believe we should have /sys/class/led* interface to those leds. I'd like to make them blink with hdd activity on some machines... of course, that needs non-buggy KBC.

I'll take patches. Ofcourse we'll have to keep the current EV_LED interface for compatibility.

Actually here's one that does not immediately oops when I plug USB keyboard in.

drivers/leds/Kconfig +7 -0
index 87d2046..716620c 100644
@@ -95,6 +95,13 @@ config LEDS_COBALT
 	help
 	  This option enables support for the front LED on Cobalt Server
 
+config LEDS_INPUT
+	tristate "LED Support for input layer keyboards"
+	depends on LEDS_CLASS
+	help
+	  This option enables support for LEDs on keyboards handled by
+	  input layer.
+
 comment "LED Triggers"
 
 config LEDS_TRIGGERS
drivers/leds/Makefile +2 -0
index aa2c18e..ea58020 100644
@@ -16,8 +16,10 @@ obj-$(CONFIG_LEDS_NET48XX)		+= leds-net4
 obj-$(CONFIG_LEDS_WRAP)			+= leds-wrap.o
 obj-$(CONFIG_LEDS_H1940)		+= leds-h1940.o
 obj-$(CONFIG_LEDS_COBALT)		+= leds-cobalt.o
+obj-$(CONFIG_LEDS_INPUT)		+= leds-input.o
 
 # LED Triggers
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
 obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK)	+= ledtrig-ide-disk.o
 obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT)	+= ledtrig-heartbeat.o
+
drivers/leds/leds-input.c new file +153 -0

153 lines not on this page · raw message

drivers/leds/leds-spitz.c +1 -1
index 126d09c..8d10274 100644
@@ -1,5 +1,5 @@
 /*
- * LED Triggers Core
+ * SPITZ LED Driver
  *
  * Copyright 2005-2006 Openedhand Ltd.
  *
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#20 lore raw
Quoted 3 lines · Pavel Machek

Actually here's one that does not immediately oops when I plug USB keyboard in.

Why do you use a delayed workqueue and then always use it without a delay? That seems silly.

Linus

#21 lore raw

Hi!

Quoted 5 lines
Quoted 2 lines

Actually here's one that does not immediately oops when I plug USB keyboard in.

Why do you use a delayed workqueue and then always use it without a delay? That seems silly.

I copied code from Dmitry :-); guess I copied too much. Here's updated version:

drivers/leds/Kconfig +7 -0
index 87d2046..716620c 100644
@@ -95,6 +95,13 @@ config LEDS_COBALT
 	help
 	  This option enables support for the front LED on Cobalt Server
 
+config LEDS_INPUT
+	tristate "LED Support for input layer keyboards"
+	depends on LEDS_CLASS
+	help
+	  This option enables support for LEDs on keyboards handled by
+	  input layer.
+
 comment "LED Triggers"
 
 config LEDS_TRIGGERS
drivers/leds/Makefile +2 -0
index aa2c18e..ea58020 100644
@@ -16,8 +16,10 @@ obj-$(CONFIG_LEDS_NET48XX)		+= leds-net4
 obj-$(CONFIG_LEDS_WRAP)			+= leds-wrap.o
 obj-$(CONFIG_LEDS_H1940)		+= leds-h1940.o
 obj-$(CONFIG_LEDS_COBALT)		+= leds-cobalt.o
+obj-$(CONFIG_LEDS_INPUT)		+= leds-input.o
 
 # LED Triggers
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
 obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK)	+= ledtrig-ide-disk.o
 obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT)	+= ledtrig-heartbeat.o
+
drivers/leds/leds-input.c new file +153 -0

153 lines not on this page · raw message

drivers/leds/leds-spitz.c +1 -1
index 126d09c..8d10274 100644
@@ -1,5 +1,5 @@
 /*
- * LED Triggers Core
+ * SPITZ LED Driver
  *
  * Copyright 2005-2006 Openedhand Ltd.
  *
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#23 lore raw

Hi!

Quoted 4 lines
Quoted 2 lines

I copied code from Dmitry :-); guess I copied too much. Here's updated version:

Umm, it's updated exactly how?

Sorry. I updated it in my tree but produced wrong patch. Here's updated updated version: (trimmed cc list).

Quoted 6 lines
Quoted 2 lines
(quoted diff) +2 -0
+struct blinker {
+	struct delayed_work work;

...

Quoted 1 line
(quoted diff) +1 -0
+	schedule_delayed_work(&blinker->work, 0);

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	INIT_DELAYED_WORK(&blinker->work, blink_task_handler);
drivers/leds/Kconfig +7 -0
index 87d2046..716620c 100644
@@ -95,6 +95,13 @@ config LEDS_COBALT
 	help
 	  This option enables support for the front LED on Cobalt Server
 
+config LEDS_INPUT
+	tristate "LED Support for input layer keyboards"
+	depends on LEDS_CLASS
+	help
+	  This option enables support for LEDs on keyboards handled by
+	  input layer.
+
 comment "LED Triggers"
 
 config LEDS_TRIGGERS
drivers/leds/Makefile +2 -0
index aa2c18e..ea58020 100644
@@ -16,8 +16,10 @@ obj-$(CONFIG_LEDS_NET48XX)		+= leds-net4
 obj-$(CONFIG_LEDS_WRAP)			+= leds-wrap.o
 obj-$(CONFIG_LEDS_H1940)		+= leds-h1940.o
 obj-$(CONFIG_LEDS_COBALT)		+= leds-cobalt.o
+obj-$(CONFIG_LEDS_INPUT)		+= leds-input.o
 
 # LED Triggers
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
 obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK)	+= ledtrig-ide-disk.o
 obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT)	+= ledtrig-heartbeat.o
+
drivers/leds/leds-input.c new file +151 -0

151 lines not on this page · raw message

drivers/leds/leds-spitz.c +1 -1
index 126d09c..8d10274 100644
@@ -1,5 +1,5 @@
 /*
- * LED Triggers Core
+ * SPITZ LED Driver
  *
  * Copyright 2005-2006 Openedhand Ltd.
  *
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#24 lore raw
In reply to Pavel Machek
Quoted 14 lines · Pavel Machek
Quoted 6 lines · Andi Kleen
Quoted 6 lines
Quoted 5 lines

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

Quoted 6 lines
Quoted 1 line

I don't don't like it ;) Unfortunately too many people end up enabling

Yes that's pretty weird. I admit I hadn't expected
that problem. blink is equivalent to "annoy me" and it
is a mystery why so many people should willingly ask their computer to annoy them.

Quoted 4 lines

tristate "Keyboard blink driver"

...drivers are not expected to act on their own. I was expecting to get nice /sys/class/led* interface to my keyboard leds.

What's the benefit of such an interface? If you're able to trigger keyboard LEDs via that interface, you're also able to use the ioctl() on /dev/console.

I think the intention of the blink driver was to have a *early* blink, i.e. before initrd (and on systems without intrd, before the first init script runs).

Thanks,
Bernhard

#25 lore raw

Hi!

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines

Perhaps one of you geniuses who all hate it can find a better way to solve the "video output dead after kexec; but need visual feedback to the user while crash dumping" problem. I'm waiting for your patches.

I don't don't like it ;) Unfortunately too many people end up enabling

Yes that's pretty weird. I admit I hadn't expected
that problem. blink is equivalent to "annoy me" and it
is a mystery why so many people should willingly ask their computer to annoy them.

Quoted 8 lines
Quoted 4 lines

tristate "Keyboard blink driver"

...drivers are not expected to act on their own. I was expecting to get nice /sys/class/led* interface to my keyboard leds.

What's the benefit of such an interface? If you're able to trigger keyboard LEDs via that interface, you're also able to use the ioctl() on /dev/console.

Well, at least it is standartized interface... plus it can do stuff like "blink that led on disk access".

Quoted 3 lines

I think the intention of the blink driver was to have a *early* blink, i.e. before initrd (and on systems without intrd, before the first init script runs).

...and yes, it can autoblink, too. It should be even possible to set default behaviour of led to blink, doing what the blink driver does, but in a clean way.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#26 lore raw
Quoted 9 lines · Pavel Machek
Quoted 5 lines
Quoted 2 lines

...drivers are not expected to act on their own. I was expecting to get nice /sys/class/led* interface to my keyboard leds.

What's the benefit of such an interface? If you're able to trigger keyboard LEDs via that interface, you're also able to use the ioctl() on /dev/console.

Well, at least it is standartized interface... plus it can do stuff like "blink that led on disk access".

One of many useful things for system without blinking lights, disk network, thermal alert, etc. And a cheap helper for handicapped folks who can't hear an audible alert.

Quoted 7 lines
Quoted 3 lines

I think the intention of the blink driver was to have a *early* blink, i.e. before initrd (and on systems without intrd, before the first init script runs).

...and yes, it can autoblink, too. It should be even possible to set default behaviour of led to blink, doing what the blink driver does, but in a clean way.

Endlessly useful, alarm clock, non-fatal errors on boot, etc.

<it would be nice>
If this were done, priority levels would be nice, so the "I'm taking a dump" or "panic" would block lower level system use like disk or network lights, and user applications would have some policy to put them higher or lower than the pseudo disk light (or not). </not nice>

Signature · 3 lines
Bill Davidsen <[email protected]>
  "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot