LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Re: Accelerometer driver for HP laptops
       [not found]   ` <48CAD89F.1050806@tremplin-utc.net>
@ 2008-10-15  7:25     ` Pavel Machek
  2008-10-15  7:50       ` Eric Piel
  2008-10-16  9:10       ` Driver for HP harddisk protection LED Pavel Machek
  0 siblings, 2 replies; 7+ messages in thread
From: Pavel Machek @ 2008-10-15  7:25 UTC (permalink / raw)
  To: Eric Piel, lm-sensors, kernel list
  Cc: Thomas Renninger, Tejun Heo, Yan Burman

Hi!

I took a look at the driver, and it seems to work for me... I'd like
to get it to the mainline...

> >>Attached is our work-in-progress version of the driver for a fourth take
> >>on the LKML (it used to be mdps). It works really fine, with lots of
> >>"goodies" (like automatically convert the axes to fit to a standard,
> >>automatic power-off of the device when not in used) excepted the
> >>interrupt support for free-fall detection.

I wonder if mdps was really a better name? Driver is HP-specific
(because of the ACPI usage), not really chip specific... and lis3lv02d
looks like an alphabet soup to me...

Ok, it is a bit chip-specific, too...

What are the next plans... lm_sensors is listed as orphan in
MAINTAINERS, so I guess I'll clean it up a tiny bit then submit to akpm?

>  Documentation/hwmon/lis3lv02d      |   92 ++++
>  drivers/hwmon/Kconfig              |   23 +
>  drivers/hwmon/Makefile             |    1 +
>  drivers/hwmon/lis3lv02d.c          |  865 ++++++++++++++++++++++++++++++++++++
>  drivers/hwmon/lis3lv02d.h          |  149 ++++++
>  5 files changed, 1145 insertions(+), 16 deletions(-)

									Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Accelerometer driver for HP laptops
  2008-10-15  7:25     ` Accelerometer driver for HP laptops Pavel Machek
@ 2008-10-15  7:50       ` Eric Piel
  2008-10-15 10:58         ` Pavel Machek
  2008-10-16  9:10       ` Driver for HP harddisk protection LED Pavel Machek
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Piel @ 2008-10-15  7:50 UTC (permalink / raw)
  To: Pavel Machek
  Cc: lm-sensors, kernel list, Thomas Renninger, Tejun Heo, Yan Burman

Pavel Machek schreef:
> Hi!
> 
> I took a look at the driver, and it seems to work for me... I'd like
> to get it to the mainline...
> 
>>>> Attached is our work-in-progress version of the driver for a fourth take
>>>> on the LKML (it used to be mdps). It works really fine, with lots of
>>>> "goodies" (like automatically convert the axes to fit to a standard,
>>>> automatic power-off of the device when not in used) excepted the
>>>> interrupt support for free-fall detection.
> 
> I wonder if mdps was really a better name? Driver is HP-specific
> (because of the ACPI usage), not really chip specific... and lis3lv02d
> looks like an alphabet soup to me...
> 
> Ok, it is a bit chip-specific, too...
Yes, the point is that several people got interested in adding to the
driver SPI and I²C support last time I submitted the driver. I did my
best to concentrate the ACPI stuff only to some 3 or 4 small functions,
so that it can be be easily done.

> 
> What are the next plans... lm_sensors is listed as orphan in
> MAINTAINERS, so I guess I'll clean it up a tiny bit then submit to akpm?
Yes I've hold things up because I can't get the free-fall detection
working correctly on my laptop. However here is the merge window (not
that it matters that much with new drivers), free-fall is "just" not
always detected, and there are lots of people who have showed interest
in the driver. Fixing the last small things can be done once in Linus'
tree as well!

I've got already a changelog ready. Give me a couple of days to clean
things up and I'll send it to akpm myself :-)

See you,
Eric

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Accelerometer driver for HP laptops
  2008-10-15  7:50       ` Eric Piel
@ 2008-10-15 10:58         ` Pavel Machek
  2008-10-15 11:20           ` Eric Piel
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2008-10-15 10:58 UTC (permalink / raw)
  To: Eric Piel
  Cc: lm-sensors, kernel list, Thomas Renninger, Tejun Heo, Yan Burman

Hi!

> > I took a look at the driver, and it seems to work for me... I'd like
> > to get it to the mainline...
> > 
> >>>> Attached is our work-in-progress version of the driver for a fourth take
> >>>> on the LKML (it used to be mdps). It works really fine, with lots of
> >>>> "goodies" (like automatically convert the axes to fit to a standard,
> >>>> automatic power-off of the device when not in used) excepted the
> >>>> interrupt support for free-fall detection.
> > 
> > I wonder if mdps was really a better name? Driver is HP-specific
> > (because of the ACPI usage), not really chip specific... and lis3lv02d
> > looks like an alphabet soup to me...
> > 
> > Ok, it is a bit chip-specific, too...
> Yes, the point is that several people got interested in adding to the
> driver SPI and I?C support last time I submitted the driver. I did my
> best to concentrate the ACPI stuff only to some 3 or 4 small functions,
> so that it can be be easily done.

Yes, I seen that. Nice.

> I've got already a changelog ready. Give me a couple of days to clean
> things up and I'll send it to akpm myself :-)

Ok, I'd like to help with cleaning... let me know if I can help some more.

* whitelist hp2133

* the driver has different name now.

* remove /** from comments that are not linuxdoc compliant.

* remove /dev/accel. We can reintroduce it when it works

Signed-off-by: Pavel Machek <pavel@suse.cz>
									Pavel

diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index 3cdfb52..1d6ca17 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -1,5 +1,6 @@
 /*
- *  mdps.c - ST LIS3LV02DL accelerometer driver
+ *  lis3lv02d.c - ST LIS3LV02DL accelerometer driver used for HDD protection
+ *		  in HP notebooks
  *
  *  Copyright (C) 2007-2008 Yan Burman
  *  Copyright (C) 2008 Eric Piel
@@ -106,7 +107,7 @@ static struct acpi_device_id lis3lv02d_d
 };
 MODULE_DEVICE_TABLE(acpi, lis3lv02d_device_ids);
 
-/**
+/*
  * acpi_init - ACPI _INI method: initialize the device.
  * @handle the handle of the device
  *
@@ -161,7 +162,7 @@ static acpi_status lis3lv02d_acpi_write(
 	return acpi_evaluate_integer(handle, "ALWR", &args, &ret);
 }
 
-/**
+/*
  * Write a 16 bit word on a pair of registers
  * @handle the handle of the device
  * @reg the low register to write to
@@ -187,15 +188,8 @@ static s16 lis3lv02d_read_16(acpi_handle
 	return (s16)((hi << 8) | lo);
 }
 
-static void lis3lv02d_display_reg(int reg)
-{
-	u8 val;
-	lis3lv02d_acpi_read(adev.device->handle, reg, &val);
-	printk(DRIVER_NAME " reg %x : %.2x\n", reg, val);
-}
-
 /**
- * For the given axis, give the value converted
+ * lis3lv02d_get_axis For the given axis, give the value converted
  * @param axis 1,2,3 - can also be negative
  * @param hw_values raw values returned by the hardware
  *
@@ -277,12 +271,6 @@ #endif
 static int lis3lv02d_resume(struct acpi_device *device)
 {
 	/* make sure the device went online */
-	// TODO: check if the device could be automatically turned on by acpi
-	// If so, put the power_off timer back
-//	down(&adev.poff_sem);
-//	if (adev.usage > 0)
-//		lis3lv02d_poweron(device->handle);
-//	up(&adev.poff_sem);
 	printk(KERN_INFO DRIVER_NAME " Resuming device\n");
 	return 0;
 }
@@ -326,192 +314,6 @@ static void lis3lv02d_poweroff_timeout(u
 	printk(KERN_DEBUG DRIVER_NAME ": Turning off the device\n");
 }
 
-static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
-{
-	/*
-	 * Be careful: on some HP laptops the bios force DD when on battery and
-	 * the lid is closed. This leads to interrupts as soon as a little move
-	 * is done.
-	 */
-	atomic_inc(&adev.count);
-
-	wake_up_interruptible(&adev.misc_wait);
-	kill_fasync(&adev.async_queue, SIGIO, POLL_IN);
-
-//	//lis3lv02d_display_reg(STATUS_REG);
-//	lis3lv02d_display_reg(FF_WU_SRC);
-//	lis3lv02d_display_reg(DD_SRC);
-//	//lis3lv02d_display_reg(CTRL_REG1);
-//	//lis3lv02d_display_reg(CTRL_REG2);
-//	//lis3lv02d_display_reg(CTRL_REG3);
-//	lis3lv02d_display_reg(FF_WU_ACK);
-//	lis3lv02d_display_reg(FF_WU_CFG);
-//	lis3lv02d_display_reg(DD_CFG);
-//	//lis3lv02d_display_reg(FF_WU_THS_L);
-//	//lis3lv02d_display_reg(FF_WU_THS_H);
-//	//lis3lv02d_display_reg(FF_WU_DURATION);
-//	//lis3lv02d_acpi_write(adev.device->handle, FF_WU_SRC, 0);
-//	printk(KERN_DEBUG DRIVER_NAME ": irq received\n");
-
-	return IRQ_HANDLED;
-}
-
-static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
-{
-	int ret;
-
-	if (test_and_set_bit(0, &adev.misc_opened))
-		return -EBUSY; /* already open */
-
-	atomic_set(&adev.count, 0);
-
-	/*
-	 * The sensor can generate interrupts for free-fall and direction
-	 * detection (distinguishable with FF_WU_SRC and DD_SRC) but to keep
-	 * the things simple and _fast_ we activate it only for free-fall, so
-	 * no need to read register (very slow with ACPI). For the same reason,
-	 * we forbid shared interrupts.
-	 *
-	 * IRQF_TRIGGER_RISING seems pointless on HP laptops because the
-	 * io-apic is not configurable (and generates a warning) but I keep it
-	 * in case of support for other hardware.
-	 */
-	ret = request_irq(adev.irq, lis302dl_interrupt, IRQF_TRIGGER_RISING,
-			  DRIVER_NAME, &adev);
-	if (ret) {
-		clear_bit(0, &adev.misc_opened);
-		printk(KERN_ERR DRIVER_NAME ": IRQ%d allocation failed\n", adev.irq);
-		return -EBUSY;
-	}
-	lis3lv02d_increase_use(&adev);
-	// TODO: set up the registers correctly
-//	lis3lv02d_display_reg(STATUS_REG);
-//	lis3lv02d_display_reg(CTRL_REG1);
-//	lis3lv02d_display_reg(CTRL_REG2);
-//	lis3lv02d_display_reg(CTRL_REG3);
-	lis3lv02d_display_reg(FF_WU_CFG);
-//	lis3lv02d_display_reg(FF_WU_SRC);
-//	lis3lv02d_display_reg(FF_WU_THS_L);
-//	lis3lv02d_display_reg(FF_WU_THS_H);
-//	lis3lv02d_display_reg(FF_WU_DURATION);
-//	lis3lv02d_display_reg(DD_CFG);
-//	lis3lv02d_display_reg(DD_SRC);
-//	lis3lv02d_display_reg(DD_THSI_L);
-//	lis3lv02d_display_reg(DD_THSI_H);
-//	lis3lv02d_display_reg(DD_THSE_L);
-//	lis3lv02d_display_reg(DD_THSE_H);
-//	lis3lv02d_acpi_write(adev.device->handle, FF_WU_SRC, 0);
-	/* Threshold not too big (10) */
-//	lis3lv02d_write_16(adev.device->handle, FF_WU_THS_L, 10);
-//	/* 2 samples in a row before activation */
-//	lis3lv02d_acpi_write(adev.device->handle, FF_WU_DURATION, 2);
-//	/* detect every direction, don't wait for validation */
-	lis3lv02d_acpi_write(adev.device->handle, FF_WU_CFG, 0);
-//	lis3lv02d_acpi_write(adev.device->handle, FF_WU_CFG, FF_WU_CFG_XLIE | FF_WU_CFG_XHIE
-//					| FF_WU_CFG_YLIE | FF_WU_CFG_YHIE
-//					| FF_WU_CFG_ZLIE | FF_WU_CFG_ZHIE);
-	// TODO after turning on, this generates one useless interrupt just after set up, it shouldn't be passed to userspace
-//	lis3lv02d_display_reg(STATUS_REG);
-//	lis3lv02d_display_reg(CTRL_REG1);
-//	lis3lv02d_display_reg(CTRL_REG2);
-//	lis3lv02d_display_reg(CTRL_REG3);
-	lis3lv02d_display_reg(FF_WU_CFG);
-//	lis3lv02d_display_reg(FF_WU_SRC);
-//	lis3lv02d_display_reg(FF_WU_THS_L);
-//	lis3lv02d_display_reg(FF_WU_THS_H);
-//	lis3lv02d_display_reg(FF_WU_DURATION);
-//	lis3lv02d_display_reg(DD_CFG);
-//	lis3lv02d_display_reg(DD_SRC);
-//	lis3lv02d_display_reg(DD_THSI_L);
-//	lis3lv02d_display_reg(DD_THSI_H);
-//	lis3lv02d_display_reg(DD_THSE_L);
-//	lis3lv02d_display_reg(DD_THSE_H);
-
-	return 0;
-}
-
-static int lis3lv02d_misc_release(struct inode *inode, struct file *file)
-{
-	fasync_helper(-1, file, 0, &adev.async_queue);
-	lis3lv02d_acpi_write(adev.device->handle, FF_WU_CFG, 0);
-	lis3lv02d_decrease_use(&adev);
-	free_irq(adev.irq, &adev);
-	clear_bit(0, &adev.misc_opened); /* release the device */
-	return 0;
-}
-
-static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
-				size_t count, loff_t *pos)
-{
-	DECLARE_WAITQUEUE(wait, current);
-	u32 data;
-	ssize_t retval = count;
-
-	if (count != sizeof(u32))
-		return -EINVAL;
-
-	add_wait_queue(&adev.misc_wait, &wait);
-	while (true) {
-		set_current_state(TASK_INTERRUPTIBLE);
-		data = atomic_xchg(&adev.count, 0);
-		if (data)
-			break;
-
-		if (file->f_flags & O_NONBLOCK) {
-			retval = -EAGAIN;
-			goto out;
-		}
-
-		if (signal_pending(current)) {
-			retval = -ERESTARTSYS;
-			goto out;
-		}
-
-		schedule();
-	}
-
-	/* make sure we are not going into copy_to_user() with
-	 * TASK_INTERRUPTIBLE state */
-	set_current_state(TASK_RUNNING);
-	if (copy_to_user(buf, &data, sizeof(data)))
-		retval = -EFAULT;
-
-out:
-	__set_current_state(TASK_RUNNING);
-	remove_wait_queue(&adev.misc_wait, &wait);
-
-	return retval;
-}
-
-static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
-{
-	poll_wait(file, &adev.misc_wait, wait);
-	if (atomic_read(&adev.count))
-		return POLLIN | POLLRDNORM;
-	return 0;
-}
-
-static int lis3lv02d_misc_fasync(int fd, struct file *file, int on)
-{
-	return fasync_helper(fd, file, on, &adev.async_queue);
-}
-
-static const struct file_operations lis3lv02d_misc_fops = {
-	.owner   = THIS_MODULE,
-	.llseek  = no_llseek,
-	.read    = lis3lv02d_misc_read,
-	.open    = lis3lv02d_misc_open,
-	.release = lis3lv02d_misc_release,
-	.poll    = lis3lv02d_misc_poll,
-	.fasync  = lis3lv02d_misc_fasync,
-};
-
-static struct miscdevice lis3lv02d_misc_device = {
-	.minor   = MISC_DYNAMIC_MINOR,
-	.name    = "accel",
-	.fops    = &lis3lv02d_misc_fops,
-};
-
 /**
  * lis3lv02d_joystick_kthread - Kthread polling function
  * @param data unused - here to conform to threadfn prototype
@@ -644,16 +446,6 @@ static int lis3lv02d_init_device(struct 
 	/* obtain IRQ number of our device from ACPI */
 	lis3lv02d_enum_resources(dev->device);
 
-	/* if we did not get an IRQ from ACPI - we have nothing more to do */
-	if (!dev->irq) {
-		printk(KERN_ERR DRIVER_NAME
-			": No IRQ in ACPI. Disabling /dev/accel\n");
-		goto out;
-	}
-
-	if (misc_register(&lis3lv02d_misc_device))
-		printk(KERN_ERR DRIVER_NAME ": misc_register failed\n");
-out:
 	lis3lv02d_decrease_use(dev);
 	return 0;
 }
@@ -673,6 +465,7 @@ static struct axis_conversion lis3lv02d_
 static struct axis_conversion lis3lv02d_axis_x_inverted = {-1, 2, 3};
 static struct axis_conversion lis3lv02d_axis_z_inverted = {1, 2, -3};
 static struct axis_conversion lis3lv02d_axis_xy_swap_inverted = {-2, -1, 3};
+static struct axis_conversion lis3lv02d_axis_xy_swap_x_inverted = {-2, 1, 3};
 
 #define AXIS_DMI_MATCH(_ident, _name, _axis) {		\
 	.ident = _ident,				\
@@ -690,6 +483,7 @@ static struct dmi_system_id lis3lv02d_dm
 	AXIS_DMI_MATCH("NW9440", "HP Compaq nw9440", x_inverted),
 	AXIS_DMI_MATCH("NC2510", "HP Compaq 2510", y_inverted),
 	AXIS_DMI_MATCH("NC8510", "HP Compaq 8510", xy_swap_inverted),
+	AXIS_DMI_MATCH("HP2133", "HP 2133", xy_swap_x_inverted ),
 	{ NULL, }
 /* Laptop models without axis info (yet):
  * "NC651xx" "HP Compaq 651"
@@ -738,7 +532,6 @@ static int lis3lv02d_remove(struct acpi_
 	if (!device)
 		return -EINVAL;
 
-	misc_deregister(&lis3lv02d_misc_device);
 	lis3lv02d_joystick_disable();
 	del_timer(&adev.poff_timer);
 	lis3lv02d_poweroff(device->handle);


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Accelerometer driver for HP laptops
  2008-10-15 10:58         ` Pavel Machek
@ 2008-10-15 11:20           ` Eric Piel
  2008-10-15 12:03             ` Pavel Machek
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Piel @ 2008-10-15 11:20 UTC (permalink / raw)
  To: Pavel Machek
  Cc: lm-sensors, kernel list, Thomas Renninger, Tejun Heo, Yan Burman

Pavel Machek schreef:

> 
>> I've got already a changelog ready. Give me a couple of days to clean
>> things up and I'll send it to akpm myself :-)
> 
> Ok, I'd like to help with cleaning... let me know if I can help some more.
Hi,
Thanks a lot for this patch.
> 
> * whitelist hp2133
Great!
> 
> * the driver has different name now.
That was too obvious for me to notice ;-)
> 
> * remove /** from comments that are not linuxdoc compliant.
Hum... I'll try to fix the comments to make them linuxdoc compliant. I
must be missing something obvious, but do you know where is the doc
about linuxdoc?
> 
> * remove /dev/accel. We can reintroduce it when it works
Right, that's probably the safest for now.

See you,
Eric

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Accelerometer driver for HP laptops
  2008-10-15 11:20           ` Eric Piel
@ 2008-10-15 12:03             ` Pavel Machek
  0 siblings, 0 replies; 7+ messages in thread
From: Pavel Machek @ 2008-10-15 12:03 UTC (permalink / raw)
  To: Eric Piel
  Cc: lm-sensors, kernel list, Thomas Renninger, Tejun Heo, Yan Burman

Hi!

> >> I've got already a changelog ready. Give me a couple of days to clean
> >> things up and I'll send it to akpm myself :-)
> > 
> > Ok, I'd like to help with cleaning... let me know if I can help some more.
> Hi,
> Thanks a lot for this patch.

You are welcome.

> > * remove /** from comments that are not linuxdoc compliant.
> Hum... I'll try to fix the comments to make them linuxdoc compliant. I
> must be missing something obvious, but do you know where is the doc
> about linuxdoc?

Documentation/kernel-doc-nano-HOWTO.txt, AFAICT. It took me a while to
find.
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Driver for HP harddisk protection LED
  2008-10-15  7:25     ` Accelerometer driver for HP laptops Pavel Machek
  2008-10-15  7:50       ` Eric Piel
@ 2008-10-16  9:10       ` Pavel Machek
  2008-10-16 22:55         ` Andrew Morton
  1 sibling, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2008-10-16  9:10 UTC (permalink / raw)
  To: Eric Piel, lm-sensors, kernel list, rpurdie, Andrew Morton
  Cc: Thomas Renninger, Yan Burman

Hi!

HP notebooks contain accelerometer-based disk protection subsystem,
and LED that indicates hard disk is protected. This is driver for the
LED part.

Signed-off-by: Pavel Machek <pavel@suse.cz>

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 27fe7be..d7b789f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -132,6 +132,13 @@ config LEDS_CM_X270
 	help
 	  This option enables support for the CM-X270 LEDs.
 
+config LEDS_HP_DISK
+	tristate "LED Support for disk protection LED on HP notebooks"
+	depends on LEDS_CLASS && ACPI
+	help
+	  This option enable support for disk protection LED, found on
+	  newer HP notebooks.
+
 config LEDS_CLEVO_MAIL
 	tristate "Mail LED on Clevo notebook (EXPERIMENTAL)"
 	depends on LEDS_CLASS && X86 && SERIO_I8042 && DMI && EXPERIMENTAL
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index a18e762..b0ed3d2 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_LEDS_CLEVO_MAIL)		+= leds-c
 obj-$(CONFIG_LEDS_HP6XX)		+= leds-hp6xx.o
 obj-$(CONFIG_LEDS_FSG)			+= leds-fsg.o
 obj-$(CONFIG_LEDS_PCA955X)		+= leds-pca955x.o
+obj-$(CONFIG_LEDS_HP_DISK)		+= leds-hp-disk.o
 
 # LED Triggers
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
diff --git a/drivers/leds/leds-hp-disk.c b/drivers/leds/leds-hp-disk.c
new file mode 100644
index 0000000..6ca97e4
--- /dev/null
+++ b/drivers/leds/leds-hp-disk.c
@@ -0,0 +1,155 @@
+/*
+ *  leds-hp-disk.c - driver for HP "hard disk protection" LED
+ *
+ *  Copyright (C) 2008 Pavel Machek
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/dmi.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/kthread.h>
+#include <linux/version.h>
+#include <linux/leds.h>
+#include <acpi/acpi_drivers.h>
+
+#define DRIVER_NAME     "leds-hp-disk"
+#define ACPI_MDPS_CLASS "led"
+
+/* For automatic insertion of the module */
+static struct acpi_device_id hpled_device_ids[] = {
+	{"HPQ0004", 0}, /* HP Mobile Data Protection System PNP */
+	{"", 0},
+};
+MODULE_DEVICE_TABLE(acpi, hpled_device_ids);
+
+struct acpi_hpled {
+	struct acpi_device	*device;   /* The ACPI device */
+};
+
+static struct acpi_hpled adev;
+
+static acpi_status hpled_acpi_write(acpi_handle handle, int reg)
+{
+	unsigned long ret; /* Not used when writting */
+	union acpi_object in_obj[1];
+	struct acpi_object_list args = { 1, in_obj };
+
+	in_obj[0].type          = ACPI_TYPE_INTEGER;
+	in_obj[0].integer.value = reg;
+
+	return acpi_evaluate_integer(handle, "ALED", &args, &ret);
+}
+
+static void hpled_set(struct led_classdev *led_cdev,
+			       enum led_brightness value)
+{
+	hpled_acpi_write(adev.device->handle, !!value);
+}
+
+static struct led_classdev hpled_led = {
+	.name			= "hp:red:hddprotection",
+	.default_trigger	= "heartbeat",
+	.brightness_set		= hpled_set,
+};
+
+#ifdef CONFIG_PM
+static int hpled_suspend(struct acpi_device *dev, pm_message_t state)
+{
+	led_classdev_suspend(&hpled_led);
+	return 0;
+}
+
+static int hpled_resume(struct acpi_device *dev)
+{
+	led_classdev_resume(&hpled_led);
+	return 0;
+}
+#endif
+
+static int hpled_add(struct acpi_device *device)
+{
+	int ret;
+
+	if (!device)
+		return -EINVAL;
+
+	adev.device = device;
+	strcpy(acpi_device_name(device), DRIVER_NAME);
+	strcpy(acpi_device_class(device), ACPI_MDPS_CLASS);
+	acpi_driver_data(device) = &adev;
+
+	ret = led_classdev_register(NULL, &hpled_led);
+	return ret;
+}
+
+static int hpled_remove(struct acpi_device *device, int type)
+{
+	if (!device)
+		return -EINVAL;
+
+	led_classdev_unregister(&hpled_led);
+	return 0;
+}
+
+
+
+static struct acpi_driver leds_hp_driver = {
+	.name  = DRIVER_NAME,
+	.class = ACPI_MDPS_CLASS,
+	.ids   = hpled_device_ids,
+	.ops = {
+		.add     = hpled_add,
+		.remove  = hpled_remove,
+#ifdef CONFIG_PM
+		.suspend = hpled_suspend,
+		.resume  = hpled_resume,
+#endif
+	}
+};
+
+static int __init hpled_init_module(void)
+{
+	int ret;
+
+	if (acpi_disabled)
+		return -ENODEV;
+
+	ret = acpi_bus_register_driver(&leds_hp_driver);
+	if (ret < 0)
+		return ret;
+
+	printk(KERN_INFO DRIVER_NAME " driver loaded.\n");
+
+	return 0;
+}
+
+static void __exit hpled_exit_module(void)
+{
+	acpi_bus_unregister_driver(&leds_hp_driver);
+}
+
+MODULE_DESCRIPTION("Driver for HP disk protection LED");
+MODULE_AUTHOR("Pavel Machek <pavel@suse.cz>");
+MODULE_LICENSE("GPL");
+
+module_init(hpled_init_module);
+module_exit(hpled_exit_module);


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Driver for HP harddisk protection LED
  2008-10-16  9:10       ` Driver for HP harddisk protection LED Pavel Machek
@ 2008-10-16 22:55         ` Andrew Morton
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew Morton @ 2008-10-16 22:55 UTC (permalink / raw)
  To: Pavel Machek
  Cc: eric.piel, lm-sensors, linux-kernel, rpurdie, trenn, burman.yan

On Thu, 16 Oct 2008 11:10:16 +0200
Pavel Machek <pavel@suse.cz> wrote:

> HP notebooks contain accelerometer-based disk protection subsystem,
> and LED that indicates hard disk is protected. This is driver for the
> LED part.

- fix comment typo

- use standard suspend/resume ifdef avoidance trick


 drivers/leds/leds-hp-disk.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

--- a/drivers/leds/leds-hp-disk.c~leds-driver-for-hp-harddisk-protection-led-fix
+++ a/drivers/leds/leds-hp-disk.c
@@ -49,7 +49,7 @@ static struct acpi_hpled adev;
 
 static acpi_status hpled_acpi_write(acpi_handle handle, int reg)
 {
-	unsigned long ret; /* Not used when writting */
+	unsigned long ret; /* Not used when writing */
 	union acpi_object in_obj[1];
 	struct acpi_object_list args = { 1, in_obj };
 
@@ -83,6 +83,9 @@ static int hpled_resume(struct acpi_devi
 	led_classdev_resume(&hpled_led);
 	return 0;
 }
+#else
+#define hpled_suspend NULL
+#define hpled_resume NULL
 #endif
 
 static int hpled_add(struct acpi_device *device)
@@ -119,10 +122,8 @@ static struct acpi_driver leds_hp_driver
 	.ops = {
 		.add     = hpled_add,
 		.remove  = hpled_remove,
-#ifdef CONFIG_PM
 		.suspend = hpled_suspend,
 		.resume  = hpled_resume,
-#endif
 	}
 };
 
_


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-10-16 22:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <48C984F5.5000804@tudelft.nl>
     [not found] ` <200809120736.06594.trenn@suse.de>
     [not found]   ` <48CAD89F.1050806@tremplin-utc.net>
2008-10-15  7:25     ` Accelerometer driver for HP laptops Pavel Machek
2008-10-15  7:50       ` Eric Piel
2008-10-15 10:58         ` Pavel Machek
2008-10-15 11:20           ` Eric Piel
2008-10-15 12:03             ` Pavel Machek
2008-10-16  9:10       ` Driver for HP harddisk protection LED Pavel Machek
2008-10-16 22:55         ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).