Skip to contentSkip to conversation

v2 - Add Dell Business Class Netbook LED driver

PATCH In review Bob Rodgers 2 participants 2 messages Feb 12, 2010 – Feb 17, 2010 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 v2 - Add Dell Business Class Netbook LED driver

This patch adds an LED driver to support the Dell Activity LED on the Dell Latitude 2100 netbook and future products to come. The Activity LED is visible externally in the lid so classroom instructors can observe it from a distance. The driver uses the sysfs led_class and provides a standard LED interface. This driver is ready for submission upstream.

Signed-off by: Bob Rodgers <[email protected]>

---
Description of changes in v2:
1) Added X86 and ACPI_WMI dependencies to the Kconfig file.
2) Removed platform_driver and platform_device as they are not needed in this driver.

 drivers/leds/Kconfig    |    7 ++
 drivers/leds/Makefile   |    1 +
 drivers/leds/dell-led.c |  200 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 208 insertions(+), 0 deletions(-)
 create mode 100644 drivers/leds/dell-led.c
drivers/leds/Kconfig +7 -0
index 8a0e1ec..ce8ca57 100644
@@ -269,6 +269,13 @@ config LEDS_ADP5520
 	  To compile this driver as a module, choose M here: the module will
 	  be called leds-adp5520.
 
+config LEDS_DELL_NETBOOKS
+	tristate "External LED on Dell Business Netbooks"
+	depends on LEDS_CLASS && X86 && ACPI_WMI
+	help
+	  This adds support for the Latitude 2100 and similar
+	  notebooks that have an external LED.
+
 comment "LED Triggers"
 
 config LEDS_TRIGGERS
drivers/leds/Makefile +1 -0
index 9e63869..327bfa0 100644
@@ -33,6 +33,7 @@ obj-$(CONFIG_LEDS_REGULATOR)		+= leds-regulator.o
 obj-$(CONFIG_LEDS_INTEL_SS4200)		+= leds-ss4200.o
 obj-$(CONFIG_LEDS_LT3593)		+= leds-lt3593.o
 obj-$(CONFIG_LEDS_ADP5520)		+= leds-adp5520.o
+obj-$(CONFIG_LEDS_DELL_NETBOOKS)	+= dell-led.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)		+= leds-dac124s085.o
drivers/leds/dell-led.c new file +200 -0

200 lines not on this page · raw message

Signature · 1 line
1.6.6.1
#1 lore raw

Hi Bob,

Quoted 7 lines · Bob Rodgers

This patch adds an LED driver to support the Dell Activity LED on the Dell Latitude 2100 netbook and future products to come. The Activity LED is visible externally in the lid so classroom instructors can observe it from a distance. The driver uses the sysfs led_class and provides a standard LED interface. This driver is ready for submission upstream.

Signed-off by: Bob Rodgers <[email protected]>

Quoted 9 lines

---
Description of changes in v2:
1) Added X86 and ACPI_WMI dependencies to the Kconfig file.
2) Removed platform_driver and platform_device as they are not needed in this driver.

With the platform device stiff gone it looks much better, still a few things:

drivers/leds/dell-led.c line 14

Quoted 2 lines
drivers/leds/dell-led.c new file +2 -0
+
+#include <linux/platform_device.h>

Do you still need platform_device.h?

Quoted 54 lines
drivers/leds/dell-led.c new file +54 -0
+#include <linux/acpi.h>
+#include <linux/leds.h>
+
+MODULE_AUTHOR("Louis Davis/Jim Dailey");
+MODULE_DESCRIPTION("Dell LED Control Driver");
+MODULE_LICENSE("GPL");
+
+#define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
+MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
+
+/* Error Result Codes: */
+#define INVALID_DEVICE_ID	250
+#define INVALID_PARAMETER	251
+#define INVALID_BUFFER		252
+#define INTERFACE_ERROR		253
+#define UNSUPPORTED_COMMAND	254
+#define UNSPECIFIED_ERROR	255
+
+/* Device ID */
+#define DEVICE_ID_PANEL_BACK	1
+
+/* LED Commands */
+#define CMD_LED_ON	16
+#define CMD_LED_OFF	17
+#define CMD_LED_BLINK	18
+
+struct bios_args {
+	unsigned char length;
+	unsigned char result_code;
+	unsigned char device_id;
+	unsigned char command;
+	unsigned char on_time;
+	unsigned char off_time;
+};
+
+static u8 dell_led_perform_fn(u8 length,
+		u8 result_code,
+		u8 device_id,
+		u8 command,
+		u8 on_time,
+		u8 off_time)
+{
+	struct bios_args *bios_return;
+	u8 return_code;
+	union acpi_object *obj;
+	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
+	struct acpi_buffer input;
+
+	struct bios_args args;
+	args.length = length;
+	args.result_code = result_code;
+	args.device_id = device_id;
+	args.command = command;
+	args.on_time = on_time;

drivers/leds/dell-led.c line 78

Quoted 10 lines
drivers/leds/dell-led.c new file +10 -0
+	args.off_time = off_time;
+
+	input.length = sizeof(struct bios_args);
+	input.pointer = &args;
+
+	wmi_evaluate_method(DELL_LED_BIOS_GUID,
+		1,
+		1,
+		&input,
+		&output);

This needs error handling.

drivers/leds/dell-led.c line 83

Quoted 5 lines
drivers/leds/dell-led.c new file +5 -0
+
+	obj = output.pointer;
+
+	if (!obj || obj->type != ACPI_TYPE_BUFFER)
+		return -EINVAL;

You are leaking obj when obj is not NULL and is not a buffer.

drivers/leds/dell-led.c line 177

Quoted 8 lines
drivers/leds/dell-led.c new file +8 -0
+
+static int __init dell_led_init(void)
+{
+	int error = 0;
+
+	if (!wmi_has_guid(DELL_LED_BIOS_GUID)) {
+		printk(KERN_DEBUG KBUILD_MODNAME
+			": could not find: DELL_LED_BIOS_GUID\n");

Please ocnsider using pr_xxx() family.

drivers/leds/dell-led.c line 183

Quoted 6 lines
drivers/leds/dell-led.c new file +6 -0
+		return -ENODEV;
+	}
+
+	error = led_off();
+	if (error != 0) {
+		printk(KERN_DEBUG KBUILD_MODNAME

This is a warning or an error, not a debug.

Thank you.

Signature · 1 line
Dmitry