aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorSamu Onkalo <samu.p.onkalo@nokia.com>2009-12-14 21:01:41 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-15 11:53:36 -0500
commit641615abfac0b7c5e6f242a6db77f7690925b443 (patch)
treeab47ff8a53364cc912e177b98bf4c155aea35ab4 /drivers/hwmon
parent4b5d95b3809bcd77599122494aa3f575cd6ab1b9 (diff)
lis3lv02d: proper power on sequence
Lis3 accelerometer sensors have quite long power on delay (up to 125 ms). This patch adds necessary delay to power on sequence for currently supported lis3 chips. Signed-off-by: Samu Onkalo <samu.p.onkalo@nokia.com> Tested-by: Éric Piel <eric.piel@tremplin-utc.net> Acked-by: Éric Piel <eric.piel@tremplin-utc.net> Cc: Pavel Machek <pavel@ucw.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lis3lv02d.c41
-rw-r--r--drivers/hwmon/lis3lv02d.h1
2 files changed, 28 insertions, 14 deletions
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index b12ee359d90e..39b9ac8e18ed 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -50,6 +50,9 @@
50 * joystick. 50 * joystick.
51 */ 51 */
52 52
53#define LIS3_PWRON_DELAY_WAI_12B (5000)
54#define LIS3_PWRON_DELAY_WAI_8B (3000)
55
53struct lis3lv02d lis3_dev = { 56struct lis3lv02d lis3_dev = {
54 .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait), 57 .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait),
55}; 58};
@@ -112,6 +115,24 @@ static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z)
112 *z = lis3lv02d_get_axis(lis3->ac.z, position); 115 *z = lis3lv02d_get_axis(lis3->ac.z, position);
113} 116}
114 117
118/* conversion btw sampling rate and the register values */
119static int lis3_12_rates[4] = {40, 160, 640, 2560};
120static int lis3_8_rates[2] = {100, 400};
121
122static int lis3lv02d_get_odr(void)
123{
124 u8 ctrl;
125 int val;
126
127 lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl);
128
129 if (lis3_dev.whoami == WAI_12B)
130 val = lis3_12_rates[(ctrl & (CTRL1_DF0 | CTRL1_DF1)) >> 4];
131 else
132 val = lis3_8_rates[(ctrl & CTRL1_DR) >> 7];
133 return val;
134}
135
115void lis3lv02d_poweroff(struct lis3lv02d *lis3) 136void lis3lv02d_poweroff(struct lis3lv02d *lis3)
116{ 137{
117 /* disable X,Y,Z axis and power down */ 138 /* disable X,Y,Z axis and power down */
@@ -125,6 +146,9 @@ void lis3lv02d_poweron(struct lis3lv02d *lis3)
125 146
126 lis3->init(lis3); 147 lis3->init(lis3);
127 148
149 /* LIS3 power on delay is quite long */
150 msleep(lis3->pwron_delay / lis3lv02d_get_odr());
151
128 /* 152 /*
129 * Common configuration 153 * Common configuration
130 * BDU: (12 bits sensors only) LSB and MSB values are not updated until 154 * BDU: (12 bits sensors only) LSB and MSB values are not updated until
@@ -364,23 +388,10 @@ static ssize_t lis3lv02d_calibrate_store(struct device *dev,
364 return count; 388 return count;
365} 389}
366 390
367/* conversion btw sampling rate and the register values */
368static int lis3_12_rates[4] = {40, 160, 640, 2560};
369static int lis3_8_rates[2] = {100, 400};
370static ssize_t lis3lv02d_rate_show(struct device *dev, 391static ssize_t lis3lv02d_rate_show(struct device *dev,
371 struct device_attribute *attr, char *buf) 392 struct device_attribute *attr, char *buf)
372{ 393{
373 u8 ctrl; 394 return sprintf(buf, "%d\n", lis3lv02d_get_odr());
374 int val;
375
376 lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl);
377
378 if (lis3_dev.whoami == WAI_12B)
379 val = lis3_12_rates[(ctrl & (CTRL1_DF0 | CTRL1_DF1)) >> 4];
380 else
381 val = lis3_8_rates[(ctrl & CTRL1_DR) >> 7];
382
383 return sprintf(buf, "%d\n", val);
384} 395}
385 396
386static DEVICE_ATTR(position, S_IRUGO, lis3lv02d_position_show, NULL); 397static DEVICE_ATTR(position, S_IRUGO, lis3lv02d_position_show, NULL);
@@ -430,11 +441,13 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
430 printk(KERN_INFO DRIVER_NAME ": 12 bits sensor found\n"); 441 printk(KERN_INFO DRIVER_NAME ": 12 bits sensor found\n");
431 dev->read_data = lis3lv02d_read_12; 442 dev->read_data = lis3lv02d_read_12;
432 dev->mdps_max_val = 2048; 443 dev->mdps_max_val = 2048;
444 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B;
433 break; 445 break;
434 case WAI_8B: 446 case WAI_8B:
435 printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n"); 447 printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n");
436 dev->read_data = lis3lv02d_read_8; 448 dev->read_data = lis3lv02d_read_8;
437 dev->mdps_max_val = 128; 449 dev->mdps_max_val = 128;
450 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
438 break; 451 break;
439 default: 452 default:
440 printk(KERN_ERR DRIVER_NAME 453 printk(KERN_ERR DRIVER_NAME
diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
index c6ae507e4f1e..c57f21f45676 100644
--- a/drivers/hwmon/lis3lv02d.h
+++ b/drivers/hwmon/lis3lv02d.h
@@ -202,6 +202,7 @@ struct lis3lv02d {
202 u8 whoami; /* indicates measurement precision */ 202 u8 whoami; /* indicates measurement precision */
203 s16 (*read_data) (struct lis3lv02d *lis3, int reg); 203 s16 (*read_data) (struct lis3lv02d *lis3, int reg);
204 int mdps_max_val; 204 int mdps_max_val;
205 int pwron_delay;
205 206
206 struct input_polled_dev *idev; /* input device */ 207 struct input_polled_dev *idev; /* input device */
207 struct platform_device *pdev; /* platform device */ 208 struct platform_device *pdev; /* platform device */