2 * lis3lv02d.c - ST LIS3LV02DL accelerometer driver
4 * Copyright (C) 2007-2008 Yan Burman
5 * Copyright (C) 2008 Eric Piel
6 * Copyright (C) 2008-2009 Pavel Machek
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/dmi.h>
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/platform_device.h>
29 #include <linux/interrupt.h>
30 #include <linux/input-polldev.h>
31 #include <linux/delay.h>
32 #include <linux/wait.h>
33 #include <linux/poll.h>
34 #include <linux/freezer.h>
35 #include <linux/uaccess.h>
36 #include <linux/miscdevice.h>
37 #include <linux/pm_runtime.h>
38 #include <asm/atomic.h>
39 #include "lis3lv02d.h"
41 #define DRIVER_NAME "lis3lv02d"
43 /* joystick device poll interval in milliseconds */
44 #define MDPS_POLL_INTERVAL 50
45 #define MDPS_POLL_MIN 0
46 #define MDPS_POLL_MAX 2000
48 #define LIS3_SYSFS_POWERDOWN_DELAY 5000 /* In milliseconds */
51 * The sensor can also generate interrupts (DRDY) but it's pretty pointless
52 * because they are generated even if the data do not change. So it's better
53 * to keep the interrupt for the free-fall event. The values are updated at
54 * 40Hz (at the lowest frequency), but as it can be pretty time consuming on
55 * some low processor, we poll the sensor only at 20Hz... enough for the
59 #define LIS3_PWRON_DELAY_WAI_12B (5000)
60 #define LIS3_PWRON_DELAY_WAI_8B (3000)
63 * LIS3LV02D spec says 1024 LSBs corresponds 1 G -> 1LSB is 1000/1024 mG
64 * LIS302D spec says: 18 mG / digit
65 * LIS3_ACCURACY is used to increase accuracy of the intermediate
66 * calculation results.
68 #define LIS3_ACCURACY 1024
69 /* Sensitivity values for -2G +2G scale */
70 #define LIS3_SENSITIVITY_12B ((LIS3_ACCURACY * 1000) / 1024)
71 #define LIS3_SENSITIVITY_8B (18 * LIS3_ACCURACY)
73 #define LIS3_DEFAULT_FUZZ 3
74 #define LIS3_DEFAULT_FLAT 3
76 struct lis3lv02d lis3_dev = {
77 .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait),
80 EXPORT_SYMBOL_GPL(lis3_dev);
82 /* just like param_set_int() but does sanity-check so that it won't point
83 * over the axis array size
85 static int param_set_axis(const char *val, const struct kernel_param *kp)
87 int ret = param_set_int(val, kp);
89 int val = *(int *)kp->arg;
98 static struct kernel_param_ops param_ops_axis = {
99 .set = param_set_axis,
100 .get = param_get_int,
103 module_param_array_named(axes, lis3_dev.ac.as_array, axis, NULL, 0644);
104 MODULE_PARM_DESC(axes, "Axis-mapping for x,y,z directions");
106 static s16 lis3lv02d_read_8(struct lis3lv02d *lis3, int reg)
109 if (lis3->read(lis3, reg, &lo) < 0)
115 static s16 lis3lv02d_read_12(struct lis3lv02d *lis3, int reg)
119 lis3->read(lis3, reg - 1, &lo);
120 lis3->read(lis3, reg, &hi);
121 /* In "12 bit right justified" mode, bit 6, bit 7, bit 8 = bit 5 */
122 return (s16)((hi << 8) | lo);
126 * lis3lv02d_get_axis - For the given axis, give the value converted
127 * @axis: 1,2,3 - can also be negative
128 * @hw_values: raw values returned by the hardware
130 * Returns the converted value.
132 static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3])
135 return hw_values[axis - 1];
137 return -hw_values[-axis - 1];
141 * lis3lv02d_get_xyz - Get X, Y and Z axis values from the accelerometer
142 * @lis3: pointer to the device struct
143 * @x: where to store the X axis value
144 * @y: where to store the Y axis value
145 * @z: where to store the Z axis value
147 * Note that 40Hz input device can eat up about 10% CPU at 800MHZ
149 static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z)
154 position[0] = lis3->read_data(lis3, OUTX);
155 position[1] = lis3->read_data(lis3, OUTY);
156 position[2] = lis3->read_data(lis3, OUTZ);
158 for (i = 0; i < 3; i++)
159 position[i] = (position[i] * lis3->scale) / LIS3_ACCURACY;
161 *x = lis3lv02d_get_axis(lis3->ac.x, position);
162 *y = lis3lv02d_get_axis(lis3->ac.y, position);
163 *z = lis3lv02d_get_axis(lis3->ac.z, position);
166 /* conversion btw sampling rate and the register values */
167 static int lis3_12_rates[4] = {40, 160, 640, 2560};
168 static int lis3_8_rates[2] = {100, 400};
169 static int lis3_3dc_rates[16] = {0, 1, 10, 25, 50, 100, 200, 400, 1600, 5000};
171 /* ODR is Output Data Rate */
172 static int lis3lv02d_get_odr(void)
177 lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl);
178 ctrl &= lis3_dev.odr_mask;
179 shift = ffs(lis3_dev.odr_mask) - 1;
180 return lis3_dev.odrs[(ctrl >> shift)];
183 static int lis3lv02d_set_odr(int rate)
191 lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl);
192 ctrl &= ~lis3_dev.odr_mask;
193 len = 1 << hweight_long(lis3_dev.odr_mask); /* # of possible values */
194 shift = ffs(lis3_dev.odr_mask) - 1;
196 for (i = 0; i < len; i++)
197 if (lis3_dev.odrs[i] == rate) {
198 lis3_dev.write(&lis3_dev, CTRL_REG1,
199 ctrl | (i << shift));
205 static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
212 mutex_lock(&lis3->mutex);
213 if (lis3_dev.whoami == WAI_3DC) {
215 selftest = CTRL4_ST0;
218 if (lis3_dev.whoami == WAI_12B)
221 selftest = CTRL1_STP;
224 lis3->read(lis3, ctlreg, ®);
225 lis3->write(lis3, ctlreg, (reg | selftest));
226 msleep(lis3->pwron_delay / lis3lv02d_get_odr());
228 /* Read directly to avoid axis remap */
229 x = lis3->read_data(lis3, OUTX);
230 y = lis3->read_data(lis3, OUTY);
231 z = lis3->read_data(lis3, OUTZ);
233 /* back to normal settings */
234 lis3->write(lis3, ctlreg, reg);
235 msleep(lis3->pwron_delay / lis3lv02d_get_odr());
237 results[0] = x - lis3->read_data(lis3, OUTX);
238 results[1] = y - lis3->read_data(lis3, OUTY);
239 results[2] = z - lis3->read_data(lis3, OUTZ);
244 for (i = 0; i < 3; i++) {
245 /* Check against selftest acceptance limits */
246 if ((results[i] < lis3->pdata->st_min_limits[i]) ||
247 (results[i] > lis3->pdata->st_max_limits[i])) {
256 mutex_unlock(&lis3->mutex);
260 void lis3lv02d_poweroff(struct lis3lv02d *lis3)
262 /* disable X,Y,Z axis and power down */
263 lis3->write(lis3, CTRL_REG1, 0x00);
265 EXPORT_SYMBOL_GPL(lis3lv02d_poweroff);
267 void lis3lv02d_poweron(struct lis3lv02d *lis3)
273 /* LIS3 power on delay is quite long */
274 msleep(lis3->pwron_delay / lis3lv02d_get_odr());
277 * Common configuration
278 * BDU: (12 bits sensors only) LSB and MSB values are not updated until
279 * both have been read. So the value read will always be correct.
281 if (lis3->whoami == WAI_12B) {
282 lis3->read(lis3, CTRL_REG2, ®);
284 lis3->write(lis3, CTRL_REG2, reg);
287 EXPORT_SYMBOL_GPL(lis3lv02d_poweron);
290 static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev)
294 mutex_lock(&lis3_dev.mutex);
295 lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z);
296 input_report_abs(pidev->input, ABS_X, x);
297 input_report_abs(pidev->input, ABS_Y, y);
298 input_report_abs(pidev->input, ABS_Z, z);
299 input_sync(pidev->input);
300 mutex_unlock(&lis3_dev.mutex);
303 static void lis3lv02d_joystick_open(struct input_polled_dev *pidev)
306 pm_runtime_get_sync(lis3_dev.pm_dev);
309 static void lis3lv02d_joystick_close(struct input_polled_dev *pidev)
312 pm_runtime_put(lis3_dev.pm_dev);
315 static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
317 if (!test_bit(0, &lis3_dev.misc_opened))
321 * Be careful: on some HP laptops the bios force DD when on battery and
322 * the lid is closed. This leads to interrupts as soon as a little move
325 atomic_inc(&lis3_dev.count);
327 wake_up_interruptible(&lis3_dev.misc_wait);
328 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
330 if (lis3_dev.pdata && lis3_dev.whoami == WAI_8B && lis3_dev.idev &&
331 lis3_dev.idev->input->users)
332 return IRQ_WAKE_THREAD;
336 static void lis302dl_interrupt_handle_click(struct lis3lv02d *lis3)
338 struct input_dev *dev = lis3->idev->input;
341 mutex_lock(&lis3->mutex);
342 lis3->read(lis3, CLICK_SRC, &click_src);
344 if (click_src & CLICK_SINGLE_X) {
345 input_report_key(dev, lis3->mapped_btns[0], 1);
346 input_report_key(dev, lis3->mapped_btns[0], 0);
349 if (click_src & CLICK_SINGLE_Y) {
350 input_report_key(dev, lis3->mapped_btns[1], 1);
351 input_report_key(dev, lis3->mapped_btns[1], 0);
354 if (click_src & CLICK_SINGLE_Z) {
355 input_report_key(dev, lis3->mapped_btns[2], 1);
356 input_report_key(dev, lis3->mapped_btns[2], 0);
359 mutex_unlock(&lis3->mutex);
362 static void lis302dl_interrupt_handle_ff_wu(struct lis3lv02d *lis3)
367 lis3->read(lis3, FF_WU_SRC_1, &wu1_src);
368 lis3->read(lis3, FF_WU_SRC_2, &wu2_src);
370 wu1_src = wu1_src & FF_WU_SRC_IA ? wu1_src : 0;
371 wu2_src = wu2_src & FF_WU_SRC_IA ? wu2_src : 0;
373 /* joystick poll is internally protected by the lis3->mutex. */
374 if (wu1_src || wu2_src)
375 lis3lv02d_joystick_poll(lis3_dev.idev);
378 static irqreturn_t lis302dl_interrupt_thread1_8b(int irq, void *data)
381 struct lis3lv02d *lis3 = data;
383 if ((lis3->pdata->irq_cfg & LIS3_IRQ1_MASK) == LIS3_IRQ1_CLICK)
384 lis302dl_interrupt_handle_click(lis3);
386 lis302dl_interrupt_handle_ff_wu(lis3);
391 static irqreturn_t lis302dl_interrupt_thread2_8b(int irq, void *data)
394 struct lis3lv02d *lis3 = data;
396 if ((lis3->pdata->irq_cfg & LIS3_IRQ2_MASK) == LIS3_IRQ2_CLICK)
397 lis302dl_interrupt_handle_click(lis3);
399 lis302dl_interrupt_handle_ff_wu(lis3);
404 static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
406 if (test_and_set_bit(0, &lis3_dev.misc_opened))
407 return -EBUSY; /* already open */
410 pm_runtime_get_sync(lis3_dev.pm_dev);
412 atomic_set(&lis3_dev.count, 0);
416 static int lis3lv02d_misc_release(struct inode *inode, struct file *file)
418 fasync_helper(-1, file, 0, &lis3_dev.async_queue);
419 clear_bit(0, &lis3_dev.misc_opened); /* release the device */
421 pm_runtime_put(lis3_dev.pm_dev);
425 static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
426 size_t count, loff_t *pos)
428 DECLARE_WAITQUEUE(wait, current);
430 unsigned char byte_data;
436 add_wait_queue(&lis3_dev.misc_wait, &wait);
438 set_current_state(TASK_INTERRUPTIBLE);
439 data = atomic_xchg(&lis3_dev.count, 0);
443 if (file->f_flags & O_NONBLOCK) {
448 if (signal_pending(current)) {
449 retval = -ERESTARTSYS;
461 /* make sure we are not going into copy_to_user() with
462 * TASK_INTERRUPTIBLE state */
463 set_current_state(TASK_RUNNING);
464 if (copy_to_user(buf, &byte_data, sizeof(byte_data)))
468 __set_current_state(TASK_RUNNING);
469 remove_wait_queue(&lis3_dev.misc_wait, &wait);
474 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
476 poll_wait(file, &lis3_dev.misc_wait, wait);
477 if (atomic_read(&lis3_dev.count))
478 return POLLIN | POLLRDNORM;
482 static int lis3lv02d_misc_fasync(int fd, struct file *file, int on)
484 return fasync_helper(fd, file, on, &lis3_dev.async_queue);
487 static const struct file_operations lis3lv02d_misc_fops = {
488 .owner = THIS_MODULE,
490 .read = lis3lv02d_misc_read,
491 .open = lis3lv02d_misc_open,
492 .release = lis3lv02d_misc_release,
493 .poll = lis3lv02d_misc_poll,
494 .fasync = lis3lv02d_misc_fasync,
497 static struct miscdevice lis3lv02d_misc_device = {
498 .minor = MISC_DYNAMIC_MINOR,
500 .fops = &lis3lv02d_misc_fops,
503 int lis3lv02d_joystick_enable(void)
505 struct input_dev *input_dev;
507 int max_val, fuzz, flat;
508 int btns[] = {BTN_X, BTN_Y, BTN_Z};
513 lis3_dev.idev = input_allocate_polled_device();
517 lis3_dev.idev->poll = lis3lv02d_joystick_poll;
518 lis3_dev.idev->open = lis3lv02d_joystick_open;
519 lis3_dev.idev->close = lis3lv02d_joystick_close;
520 lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL;
521 lis3_dev.idev->poll_interval_min = MDPS_POLL_MIN;
522 lis3_dev.idev->poll_interval_max = MDPS_POLL_MAX;
523 input_dev = lis3_dev.idev->input;
525 input_dev->name = "ST LIS3LV02DL Accelerometer";
526 input_dev->phys = DRIVER_NAME "/input0";
527 input_dev->id.bustype = BUS_HOST;
528 input_dev->id.vendor = 0;
529 input_dev->dev.parent = &lis3_dev.pdev->dev;
531 set_bit(EV_ABS, input_dev->evbit);
532 max_val = (lis3_dev.mdps_max_val * lis3_dev.scale) / LIS3_ACCURACY;
533 fuzz = (LIS3_DEFAULT_FUZZ * lis3_dev.scale) / LIS3_ACCURACY;
534 flat = (LIS3_DEFAULT_FLAT * lis3_dev.scale) / LIS3_ACCURACY;
535 input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat);
536 input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat);
537 input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat);
539 lis3_dev.mapped_btns[0] = lis3lv02d_get_axis(abs(lis3_dev.ac.x), btns);
540 lis3_dev.mapped_btns[1] = lis3lv02d_get_axis(abs(lis3_dev.ac.y), btns);
541 lis3_dev.mapped_btns[2] = lis3lv02d_get_axis(abs(lis3_dev.ac.z), btns);
543 err = input_register_polled_device(lis3_dev.idev);
545 input_free_polled_device(lis3_dev.idev);
546 lis3_dev.idev = NULL;
551 EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable);
553 void lis3lv02d_joystick_disable(void)
556 free_irq(lis3_dev.irq, &lis3_dev);
557 if (lis3_dev.pdata && lis3_dev.pdata->irq2)
558 free_irq(lis3_dev.pdata->irq2, &lis3_dev);
564 misc_deregister(&lis3lv02d_misc_device);
565 input_unregister_polled_device(lis3_dev.idev);
566 input_free_polled_device(lis3_dev.idev);
567 lis3_dev.idev = NULL;
569 EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable);
572 static void lis3lv02d_sysfs_poweron(struct lis3lv02d *lis3)
575 * SYSFS functions are fast visitors so put-call
576 * immediately after the get-call. However, keep
577 * chip running for a while and schedule delayed
578 * suspend. This way periodic sysfs calls doesn't
579 * suffer from relatively long power up time.
583 pm_runtime_get_sync(lis3->pm_dev);
584 pm_runtime_put_noidle(lis3->pm_dev);
585 pm_schedule_suspend(lis3->pm_dev, LIS3_SYSFS_POWERDOWN_DELAY);
589 static ssize_t lis3lv02d_selftest_show(struct device *dev,
590 struct device_attribute *attr, char *buf)
595 lis3lv02d_sysfs_poweron(&lis3_dev);
596 result = lis3lv02d_selftest(&lis3_dev, values);
597 return sprintf(buf, "%s %d %d %d\n", result == 0 ? "OK" : "FAIL",
598 values[0], values[1], values[2]);
601 static ssize_t lis3lv02d_position_show(struct device *dev,
602 struct device_attribute *attr, char *buf)
606 lis3lv02d_sysfs_poweron(&lis3_dev);
607 mutex_lock(&lis3_dev.mutex);
608 lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z);
609 mutex_unlock(&lis3_dev.mutex);
610 return sprintf(buf, "(%d,%d,%d)\n", x, y, z);
613 static ssize_t lis3lv02d_rate_show(struct device *dev,
614 struct device_attribute *attr, char *buf)
616 lis3lv02d_sysfs_poweron(&lis3_dev);
617 return sprintf(buf, "%d\n", lis3lv02d_get_odr());
620 static ssize_t lis3lv02d_rate_set(struct device *dev,
621 struct device_attribute *attr, const char *buf,
626 if (strict_strtoul(buf, 0, &rate))
629 lis3lv02d_sysfs_poweron(&lis3_dev);
630 if (lis3lv02d_set_odr(rate))
636 static DEVICE_ATTR(selftest, S_IRUSR, lis3lv02d_selftest_show, NULL);
637 static DEVICE_ATTR(position, S_IRUGO, lis3lv02d_position_show, NULL);
638 static DEVICE_ATTR(rate, S_IRUGO | S_IWUSR, lis3lv02d_rate_show,
641 static struct attribute *lis3lv02d_attributes[] = {
642 &dev_attr_selftest.attr,
643 &dev_attr_position.attr,
648 static struct attribute_group lis3lv02d_attribute_group = {
649 .attrs = lis3lv02d_attributes
653 static int lis3lv02d_add_fs(struct lis3lv02d *lis3)
655 lis3->pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
656 if (IS_ERR(lis3->pdev))
657 return PTR_ERR(lis3->pdev);
659 return sysfs_create_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group);
662 int lis3lv02d_remove_fs(struct lis3lv02d *lis3)
664 sysfs_remove_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group);
665 platform_device_unregister(lis3->pdev);
667 /* Barrier after the sysfs remove */
668 pm_runtime_barrier(lis3->pm_dev);
670 /* SYSFS may have left chip running. Turn off if necessary */
671 if (!pm_runtime_suspended(lis3->pm_dev))
672 lis3lv02d_poweroff(&lis3_dev);
674 pm_runtime_disable(lis3->pm_dev);
675 pm_runtime_set_suspended(lis3->pm_dev);
679 EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs);
681 static void lis3lv02d_8b_configure(struct lis3lv02d *dev,
682 struct lis3lv02d_platform_data *p)
685 int ctrl2 = p->hipass_ctrl;
687 if (p->click_flags) {
688 dev->write(dev, CLICK_CFG, p->click_flags);
689 dev->write(dev, CLICK_TIMELIMIT, p->click_time_limit);
690 dev->write(dev, CLICK_LATENCY, p->click_latency);
691 dev->write(dev, CLICK_WINDOW, p->click_window);
692 dev->write(dev, CLICK_THSZ, p->click_thresh_z & 0xf);
693 dev->write(dev, CLICK_THSY_X,
694 (p->click_thresh_x & 0xf) |
695 (p->click_thresh_y << 4));
698 struct input_dev *input_dev = lis3_dev.idev->input;
699 input_set_capability(input_dev, EV_KEY, BTN_X);
700 input_set_capability(input_dev, EV_KEY, BTN_Y);
701 input_set_capability(input_dev, EV_KEY, BTN_Z);
705 if (p->wakeup_flags) {
706 dev->write(dev, FF_WU_CFG_1, p->wakeup_flags);
707 dev->write(dev, FF_WU_THS_1, p->wakeup_thresh & 0x7f);
708 /* default to 2.5ms for now */
709 dev->write(dev, FF_WU_DURATION_1, 1);
710 ctrl2 ^= HP_FF_WU1; /* Xor to keep compatible with old pdata*/
713 if (p->wakeup_flags2) {
714 dev->write(dev, FF_WU_CFG_2, p->wakeup_flags2);
715 dev->write(dev, FF_WU_THS_2, p->wakeup_thresh2 & 0x7f);
716 /* default to 2.5ms for now */
717 dev->write(dev, FF_WU_DURATION_2, 1);
718 ctrl2 ^= HP_FF_WU2; /* Xor to keep compatible with old pdata*/
720 /* Configure hipass filters */
721 dev->write(dev, CTRL_REG2, ctrl2);
724 err = request_threaded_irq(p->irq2,
726 lis302dl_interrupt_thread2_8b,
727 IRQF_TRIGGER_RISING |
729 DRIVER_NAME, &lis3_dev);
731 printk(KERN_ERR DRIVER_NAME
732 "No second IRQ. Limited functionality\n");
737 * Initialise the accelerometer and the various subsystems.
738 * Should be rather independent of the bus system.
740 int lis3lv02d_init_device(struct lis3lv02d *dev)
743 irq_handler_t thread_fn;
745 dev->whoami = lis3lv02d_read_8(dev, WHO_AM_I);
747 switch (dev->whoami) {
749 printk(KERN_INFO DRIVER_NAME ": 12 bits sensor found\n");
750 dev->read_data = lis3lv02d_read_12;
751 dev->mdps_max_val = 2048;
752 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B;
753 dev->odrs = lis3_12_rates;
754 dev->odr_mask = CTRL1_DF0 | CTRL1_DF1;
755 dev->scale = LIS3_SENSITIVITY_12B;
758 printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n");
759 dev->read_data = lis3lv02d_read_8;
760 dev->mdps_max_val = 128;
761 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
762 dev->odrs = lis3_8_rates;
763 dev->odr_mask = CTRL1_DR;
764 dev->scale = LIS3_SENSITIVITY_8B;
767 printk(KERN_INFO DRIVER_NAME ": 8 bits 3DC sensor found\n");
768 dev->read_data = lis3lv02d_read_8;
769 dev->mdps_max_val = 128;
770 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
771 dev->odrs = lis3_3dc_rates;
772 dev->odr_mask = CTRL1_ODR0|CTRL1_ODR1|CTRL1_ODR2|CTRL1_ODR3;
773 dev->scale = LIS3_SENSITIVITY_8B;
776 printk(KERN_ERR DRIVER_NAME
777 ": unknown sensor type 0x%X\n", dev->whoami);
781 mutex_init(&dev->mutex);
783 lis3lv02d_add_fs(dev);
784 lis3lv02d_poweron(dev);
787 pm_runtime_set_active(dev->pm_dev);
788 pm_runtime_enable(dev->pm_dev);
791 if (lis3lv02d_joystick_enable())
792 printk(KERN_ERR DRIVER_NAME ": joystick initialization failed\n");
794 /* passing in platform specific data is purely optional and only
795 * used by the SPI transport layer at the moment */
797 struct lis3lv02d_platform_data *p = dev->pdata;
799 if (dev->whoami == WAI_8B)
800 lis3lv02d_8b_configure(dev, p);
803 dev->write(dev, CTRL_REG3, p->irq_cfg);
806 /* bail if we did not get an IRQ from the bus layer */
808 printk(KERN_ERR DRIVER_NAME
809 ": No IRQ. Disabling /dev/freefall\n");
814 * The sensor can generate interrupts for free-fall and direction
815 * detection (distinguishable with FF_WU_SRC and DD_SRC) but to keep
816 * the things simple and _fast_ we activate it only for free-fall, so
817 * no need to read register (very slow with ACPI). For the same reason,
818 * we forbid shared interrupts.
820 * IRQF_TRIGGER_RISING seems pointless on HP laptops because the
821 * io-apic is not configurable (and generates a warning) but I keep it
822 * in case of support for other hardware.
824 if (dev->pdata && dev->whoami == WAI_8B)
825 thread_fn = lis302dl_interrupt_thread1_8b;
829 err = request_threaded_irq(dev->irq, lis302dl_interrupt,
831 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
832 DRIVER_NAME, &lis3_dev);
835 printk(KERN_ERR DRIVER_NAME "Cannot get IRQ\n");
839 if (misc_register(&lis3lv02d_misc_device))
840 printk(KERN_ERR DRIVER_NAME ": misc_register failed\n");
844 EXPORT_SYMBOL_GPL(lis3lv02d_init_device);
846 MODULE_DESCRIPTION("ST LIS3LV02Dx three-axis digital accelerometer driver");
847 MODULE_AUTHOR("Yan Burman, Eric Piel, Pavel Machek");
848 MODULE_LICENSE("GPL");