Skip to contentSkip to conversation

lis3: clean up and updates

PATCH In review Éric Piel 3 participants 13 messages May 21, 2009 1 message not in the archive Hardware monitoring

lore
Share & tools
lore

Éric Piel

author
#0 lore raw

cover lis3: clean up and updates

Hello,
Here is a patch series for the lis3lv02d accelerometer driver. The main goal was to clean up the driver by removing non-necessary code. However, during the process a few minor bugs were discovered and fixed. Also the usual share of new axis conversion for known laptop models has been added.

Andrew, would you mind queuing this for 2.6.31?

Eric

 drivers/hwmon/hp_accel.c  |   21 ++----
 drivers/hwmon/lis3lv02d.c |  169 +++++++++++++++------------------------------
 drivers/hwmon/lis3lv02d.h |   10 +--
 3 files changed, 67 insertions(+), 133 deletions(-)
author
#1 lore raw

PATCH 1/4 lis3: fix misc device unregistering and printk

Can only unregister the misc device if it was registered before. Also remove debugging messages, which in addition were not properly formated.

---
 drivers/hwmon/lis3lv02d.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
drivers/hwmon/lis3lv02d.c +2 -5
index 778eb77..17f2003 100644
@@ -199,7 +199,6 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
 		return -EBUSY;
 	}
 	lis3lv02d_increase_use(&lis3_dev);
-	printk("lis3: registered interrupt %d\n", lis3_dev.irq);
 	return 0;
 }
 
@@ -378,7 +377,8 @@ void lis3lv02d_joystick_disable(void)
 	if (!lis3_dev.idev)
 		return;
 
-	misc_deregister(&lis3lv02d_misc_device);
+	if (lis3_dev.irq)
+		misc_deregister(&lis3lv02d_misc_device);
 	input_unregister_device(lis3_dev.idev);
 	lis3_dev.idev = NULL;
 }
@@ -493,8 +493,6 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
 	if (lis3lv02d_joystick_enable())
 		printk(KERN_ERR DRIVER_NAME ": joystick initialization failed\n");
 
-	printk("lis3_init_device: irq %d\n", dev->irq);
-
 	/* bail if we did not get an IRQ from the bus layer */
 	if (!dev->irq) {
 		printk(KERN_ERR DRIVER_NAME
@@ -502,7 +500,6 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
 		goto out;
 	}
 
-	printk("lis3: registering device\n");
 	if (misc_register(&lis3lv02d_misc_device))
 		printk(KERN_ERR DRIVER_NAME ": misc_register failed\n");
 out:
Signature · 1 line
1.6.2.4
Acked-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] lis3: fix misc device unregistering and printk

Quoted 5 lines · Éric Piel

Can only unregister the misc device if it was registered before. Also remove debugging messages, which in addition were not properly formated.

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

PATCH 2/4 lis3: remove automatic shutdown of the device

In reply to Éric Piel

After measurement on my laptop, it seems that turning off the device does not bring any energy saving (within 0.1W precision). So let's keep the device always on. It simplifies the code, and it avoids the problem of reading a wrong value sometimes just after turning the device on.

Moreover, since commit ef2cfc790bf5f0ff189b01eabc0f4feb5e8524df had been too zealous, the device was actually never turned off anyway. This patch also restores the damages done by this commit concerning the initialisation/poweroff.

Also do more clean up with the usage of the lis3_dev global variable.

---
 drivers/hwmon/hp_accel.c  |   10 +----
 drivers/hwmon/lis3lv02d.c |   88 +++++++++++++++------------------------------
 drivers/hwmon/lis3lv02d.h |    5 +--
 3 files changed, 32 insertions(+), 71 deletions(-)
drivers/hwmon/hp_accel.c +2 -8
index abca7e9..0ebd009 100644
@@ -324,7 +324,7 @@ static int lis3lv02d_remove(struct acpi_device *device, int type)
 	flush_work(&hpled_led.work);
 	led_classdev_unregister(&hpled_led.led_classdev);
 
-	return lis3lv02d_remove_fs();
+	return lis3lv02d_remove_fs(&lis3_dev);
 }
 
 
@@ -338,13 +338,7 @@ static int lis3lv02d_suspend(struct acpi_device *device, pm_message_t state)
 
 static int lis3lv02d_resume(struct acpi_device *device)
 {
-	/* put back the device in the right state (ACPI might turn it on) */
-	mutex_lock(&lis3_dev.lock);
-	if (lis3_dev.usage > 0)
-		lis3lv02d_poweron(&lis3_dev);
-	else
-		lis3lv02d_poweroff(&lis3_dev);
-	mutex_unlock(&lis3_dev.lock);
+	lis3lv02d_poweron(&lis3_dev);
 	return 0;
 }
 #else
drivers/hwmon/lis3lv02d.c +29 -59

180 lines not on this page · raw message

drivers/hwmon/lis3lv02d.h +1 -4
index 745ec96..b007d81 100644
@@ -171,14 +171,11 @@ struct lis3lv02d {
 
 	struct input_dev	*idev;     /* input device */
 	struct task_struct	*kthread;  /* kthread for input */
-	struct mutex            lock;
 	struct platform_device	*pdev;     /* platform device */
 	atomic_t		count;     /* interrupt count after last read */
 	int			xcalib;    /* calibrated null value for x */
 	int			ycalib;    /* calibrated null value for y */
 	int			zcalib;    /* calibrated null value for z */
-	unsigned char		is_on;     /* whether the device is on or off */
-	unsigned char		usage;     /* usage counter */
 	struct axis_conversion	ac;        /* hw -> logical axis */
 
 	u32			irq;       /* IRQ number */
@@ -192,6 +189,6 @@ int lis3lv02d_joystick_enable(void);
 void lis3lv02d_joystick_disable(void);
 void lis3lv02d_poweroff(struct lis3lv02d *lis3);
 void lis3lv02d_poweron(struct lis3lv02d *lis3);
-int lis3lv02d_remove_fs(void);
+int lis3lv02d_remove_fs(struct lis3lv02d *lis3);
 
 extern struct lis3lv02d lis3_dev;
Signature · 1 line
1.6.2.4
#4 lore raw

Re: [PATCH 2/4] lis3: remove automatic shutdown of the device

Hi!

Quoted 4 lines

After measurement on my laptop, it seems that turning off the device does not bring any energy saving (within 0.1W precision). So let's keep the device always on. It simplifies the code, and it avoids the problem of reading a wrong value sometimes just after turning the device on.

Well, 0.1W is still quite much for cellphone etc... but as we do not have any such small users in the tree, I guess this can go in...

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

Re: [PATCH 2/4] lis3: remove automatic shutdown of the device

Op 21-05-09 13:36, Pavel Machek schreef:

Quoted 10 lines

Hi!

Quoted 4 lines

After measurement on my laptop, it seems that turning off the device does not bring any energy saving (within 0.1W precision). So let's keep the device always on. It simplifies the code, and it avoids the problem of reading a wrong value sometimes just after turning the device on.

Well, 0.1W is still quite much for cellphone etc... but as we do not have any such small users in the tree, I guess this can go in...

Yes. BTW, what I meant is that the power consumption on my laptop can be read with 0.1W precision. Turning on and off the device showed 0.0W variations. The device should using even much less than 0.1W. According to the documentation, it's about 2.2mW when on and 3µW when off.

Eric

#6 lore raw

Re: [PATCH 2/4] lis3: remove automatic shutdown of the device

Hi!

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

After measurement on my laptop, it seems that turning off the device does not bring any energy saving (within 0.1W precision). So let's keep the device always on. It simplifies the code, and it avoids the problem of reading a wrong value sometimes just after turning the device on.

Quoted 7 lines
Quoted 3 lines

Well, 0.1W is still quite much for cellphone etc... but as we do not have any such small users in the tree, I guess this can go in...

Yes. BTW, what I meant is that the power consumption on my laptop can be read with 0.1W precision. Turning on and off the device showed 0.0W variations. The device should using even much less than 0.1W. According to the documentation, it's about 2.2mW when on and 3?W when off.

2mW would be still significant on a cellphone, draining battery in cca 20 days (which is about as bad as GSM radio), but...

If cellphone user comes, he can simply recreate powersaving code...

Feel free to add

to 2,3/4. ... And btw 4/4 probably could be pushed to 2.6.30. It is trivial enough... and "new hw" support is okay even late in cycle.
Pavel

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

PATCH 3/4 lis3: use input_polled_device

In reply to Éric Piel

Now that there is no need to hookup on the open/close of the joystick, it's possible to use the simplified interface input_polled_device, instead of creating our own kthread.

---
 drivers/hwmon/hp_accel.c  |    3 --
 drivers/hwmon/lis3lv02d.c |   74 ++++++++++++++------------------------------
 drivers/hwmon/lis3lv02d.h |    5 ++-
 3 files changed, 27 insertions(+), 55 deletions(-)
drivers/hwmon/hp_accel.c +0 -3
index 0ebd009..92db68e 100644
@@ -27,9 +27,6 @@
 #include <linux/types.h>
 #include <linux/platform_device.h>
 #include <linux/interrupt.h>
-#include <linux/input.h>
-#include <linux/kthread.h>
-#include <linux/semaphore.h>
 #include <linux/delay.h>
 #include <linux/wait.h>
 #include <linux/poll.h>
drivers/hwmon/lis3lv02d.c +24 -50

116 lines not on this page · raw message

drivers/hwmon/lis3lv02d.h +3 -2
index b007d81..5a5a196 100644
@@ -18,6 +18,8 @@
  *  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/platform_device.h>
+#include <linux/input-polldev.h>
 
 /*
  * The actual chip is STMicroelectronics LIS3LV02DL or LIS3LV02DQ that seems to
@@ -169,8 +171,7 @@ struct lis3lv02d {
 	s16 (*read_data) (struct lis3lv02d *lis3, int reg);
 	int			mdps_max_val;
 
-	struct input_dev	*idev;     /* input device */
-	struct task_struct	*kthread;  /* kthread for input */
+	struct input_polled_dev	*idev;     /* input device */
 	struct platform_device	*pdev;     /* platform device */
 	atomic_t		count;     /* interrupt count after last read */
 	int			xcalib;    /* calibrated null value for x */
Signature · 1 line
1.6.2.4
author
#8 lore raw

PATCH 4/4 lis3: Add three new laptop models

In reply to Éric Piel

Separate the 6710 and 6715, and set the right axis information for the 6715.

Add the 6930.

Add the 2710.

---
 drivers/hwmon/hp_accel.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/hwmon/hp_accel.c +6 -2
index 92db68e..8dcb152 100644
@@ -158,9 +158,11 @@ static struct axis_conversion lis3lv02d_axis_normal = {1, 2, 3};
 static struct axis_conversion lis3lv02d_axis_y_inverted = {1, -2, 3};
 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 = {2, 1, 3};
 static struct axis_conversion lis3lv02d_axis_xy_rotated_left = {-2, 1, 3};
 static struct axis_conversion lis3lv02d_axis_xy_rotated_left_usd = {-2, 1, -3};
 static struct axis_conversion lis3lv02d_axis_xy_swap_inverted = {-2, -1, 3};
+static struct axis_conversion lis3lv02d_axis_xy_swap_all_inverted = {-2, -1, -3};
 static struct axis_conversion lis3lv02d_axis_xy_rotated_right = {2, -1, 3};
 static struct axis_conversion lis3lv02d_axis_xy_swap_yz_inverted = {2, -1, -3};
 
@@ -191,13 +193,16 @@ static struct dmi_system_id lis3lv02d_dmi_ids[] = {
 	AXIS_DMI_MATCH("NX9420", "HP Compaq nx9420", x_inverted),
 	AXIS_DMI_MATCH("NW9440", "HP Compaq nw9440", x_inverted),
 	AXIS_DMI_MATCH("NC2510", "HP Compaq 2510", y_inverted),
+	AXIS_DMI_MATCH("NC2710", "HP Compaq 2710", xy_swap),
 	AXIS_DMI_MATCH("NC8510", "HP Compaq 8510", xy_swap_inverted),
 	AXIS_DMI_MATCH("HP2133", "HP 2133", xy_rotated_left),
 	AXIS_DMI_MATCH("HP2140", "HP 2140", xy_swap_inverted),
 	AXIS_DMI_MATCH("NC653x", "HP Compaq 653", xy_rotated_left_usd),
 	AXIS_DMI_MATCH("NC673x", "HP Compaq 673", xy_rotated_left_usd),
 	AXIS_DMI_MATCH("NC651xx", "HP Compaq 651", xy_rotated_right),
-	AXIS_DMI_MATCH("NC671xx", "HP Compaq 671", xy_swap_yz_inverted),
+	AXIS_DMI_MATCH("NC6710x", "HP Compaq 6710", xy_swap_yz_inverted),
+	AXIS_DMI_MATCH("NC6715x", "HP Compaq 6715", xy_swap_all_inverted),
+	AXIS_DMI_MATCH("NC693xx", "HP EliteBook 693", xy_rotated_right),
 	/* Intel-based HP Pavilion dv5 */
 	AXIS_DMI_MATCH2("HPDV5_I",
 			PRODUCT_NAME, "HP Pavilion dv5",
@@ -213,7 +218,6 @@ static struct dmi_system_id lis3lv02d_dmi_ids[] = {
 	{ NULL, }
 /* Laptop models without axis info (yet):
  * "NC6910" "HP Compaq 6910"
- * HP Compaq 8710x Notebook PC / Mobile Workstation
  * "NC2400" "HP Compaq nc2400"
  * "NX74x0" "HP Compaq nx74"
  * "NX6325" "HP Compaq nx6325"
Signature · 1 line
1.6.2.4
Acked-by on v1 4/4
#9 lore raw

Re: [PATCH 4/4] lis3: Add three new laptop models

Quoted 11 lines · Éric Piel

Separate the 6710 and 6715, and set the right axis information for the 6715.

Add the 6930.

Add the 2710.

Actually, I guess this should go before 2/4 and 3/4, as it is really trivial.

Pavel

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

Re: [PATCH 4/4] lis3: Add three new laptop models

Op 21-05-09 12:49, Pavel Machek schreef:

Quoted 11 lines · Éric Piel
Quoted 10 lines

Separate the 6710 and 6715, and set the right axis information for the 6715.

Add the 6930.

Add the 2710.

Quoted 6 lines
Quoted 1 line

Actually, I guess this should go before 2/4 and 3/4, as it is really trivial.

Indeed. Actually, it probably also applies cleanly on Linus' tree. So it could be queued for 2.6.30... but I guess it's getting too late.

Eric

#11 lore raw

Re: [PATCH 4/4] lis3: Add three new laptop models

I apologize however when I reported that I was still using the 6710 settings. When the normal axis settings were used the results showed the 6715 should be using "y_inverted" to behave normally. I'm sorry for reporting this incorrectly in the beginning.

Quoted 24 lines · Éric Piel

Op 21-05-09 12:49, Pavel Machek schreef:

Quoted 11 lines · Éric Piel
Quoted 10 lines

Separate the 6710 and 6715, and set the right axis information for the 6715.

Add the 6930.

Add the 2710.

Quoted 6 lines
Quoted 1 line

Actually, I guess this should go before 2/4 and 3/4, as it is really trivial.

Indeed. Actually, it probably also applies cleanly on Linus' tree. So it could be queued for 2.6.30... but I guess it's getting too late.

Eric

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

author
#13 lore raw

Re: [PATCH 4/4] lis3: Add three new laptop models

Op 21-05-09 13:24, Isaac702 schreef:

Quoted 5 lines

I apologize however when I reported that I was still using the 6710 settings. When the normal axis settings were used the results showed the 6715 should be using "y_inverted" to behave normally.
I'm sorry for reporting this incorrectly in the beginning.

Thank you for noticing this so quickly. Here is an updated patch.

Eric

==

Separate the 6710 and 6715, and set the right axis information for the 6715.

Add the 6930.

Add the 2710.

---
 drivers/hwmon/hp_accel.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/hwmon/hp_accel.c +5 -2
index 92db68e..6679854 100644
@@ -158,6 +158,7 @@ static struct axis_conversion lis3lv02d_axis_normal = {1, 2, 3};
 static struct axis_conversion lis3lv02d_axis_y_inverted = {1, -2, 3};
 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 = {2, 1, 3};
 static struct axis_conversion lis3lv02d_axis_xy_rotated_left = {-2, 1, 3};
 static struct axis_conversion lis3lv02d_axis_xy_rotated_left_usd = {-2, 1, -3};
 static struct axis_conversion lis3lv02d_axis_xy_swap_inverted = {-2, -1, 3};
@@ -191,13 +192,16 @@ static struct dmi_system_id lis3lv02d_dmi_ids[] = {
 	AXIS_DMI_MATCH("NX9420", "HP Compaq nx9420", x_inverted),
 	AXIS_DMI_MATCH("NW9440", "HP Compaq nw9440", x_inverted),
 	AXIS_DMI_MATCH("NC2510", "HP Compaq 2510", y_inverted),
+	AXIS_DMI_MATCH("NC2710", "HP Compaq 2710", xy_swap),
 	AXIS_DMI_MATCH("NC8510", "HP Compaq 8510", xy_swap_inverted),
 	AXIS_DMI_MATCH("HP2133", "HP 2133", xy_rotated_left),
 	AXIS_DMI_MATCH("HP2140", "HP 2140", xy_swap_inverted),
 	AXIS_DMI_MATCH("NC653x", "HP Compaq 653", xy_rotated_left_usd),
 	AXIS_DMI_MATCH("NC673x", "HP Compaq 673", xy_rotated_left_usd),
 	AXIS_DMI_MATCH("NC651xx", "HP Compaq 651", xy_rotated_right),
-	AXIS_DMI_MATCH("NC671xx", "HP Compaq 671", xy_swap_yz_inverted),
+	AXIS_DMI_MATCH("NC6710x", "HP Compaq 6710", xy_swap_yz_inverted),
+	AXIS_DMI_MATCH("NC6715x", "HP Compaq 6715", y_inverted),
+	AXIS_DMI_MATCH("NC693xx", "HP EliteBook 693", xy_rotated_right),
 	/* Intel-based HP Pavilion dv5 */
 	AXIS_DMI_MATCH2("HPDV5_I",
 			PRODUCT_NAME, "HP Pavilion dv5",
@@ -213,7 +217,6 @@ static struct dmi_system_id lis3lv02d_dmi_ids[] = {
 	{ NULL, }
 /* Laptop models without axis info (yet):
  * "NC6910" "HP Compaq 6910"
- * HP Compaq 8710x Notebook PC / Mobile Workstation
  * "NC2400" "HP Compaq nc2400"
  * "NX74x0" "HP Compaq nx74"
  * "NX6325" "HP Compaq nx6325"
Signature · 1 line
1.6.2.4