Lines Matching +full:x +full:- +full:axis

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * lis3lv02d.c - ST LIS3LV02DL accelerometer driver
5 * Copyright (C) 2007-2008 Yan Burman
7 * Copyright (C) 2008-2009 Pavel Machek
42 #define SELFTEST_FAIL -1
43 #define SELFTEST_IRQ -2
51 * to keep the interrupt for the free-fall event. The values are updated at
61 * LIS3LV02D spec says 1024 LSBs corresponds 1 G -> 1LSB is 1000/1024 mG
67 /* Sensitivity values for -2G +2G scale */
72 * LIS331DLH spec says 1LSBs corresponds 4G/4096 -> 1LSB is 1000/1024 mG.
73 * Below macros defines sensitivity values for +/-2G. Dataout bits for
74 * +/-2G range is 12 bits so 4 bits adjustment must be done to get 12bit
90 /* just like param_set_int() but does sanity-check so that it won't point
91 * over the axis array size
97 int val = *(int *)kp->arg; in param_set_axis()
99 val = -val; in param_set_axis()
101 return -EINVAL; in param_set_axis()
113 module_param_array_named(axes, lis3_dev.ac.as_array, axis, NULL, 0644);
114 MODULE_PARM_DESC(axes, "Axis-mapping for x,y,z directions");
119 if (lis3->read(lis3, reg, &lo) < 0) in lis3lv02d_read_8()
129 lis3->read(lis3, reg - 1, &lo); in lis3lv02d_read_12()
130 lis3->read(lis3, reg, &hi); in lis3lv02d_read_12()
141 lis3->read(lis3, reg - 1, &lo); in lis331dlh_read_data()
142 lis3->read(lis3, reg, &hi); in lis331dlh_read_data()
145 return (s16) v >> lis3->shift_adj; in lis331dlh_read_data()
149 * lis3lv02d_get_axis - For the given axis, give the value converted
150 * @axis: 1,2,3 - can also be negative
155 static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3]) in lis3lv02d_get_axis() argument
157 if (axis > 0) in lis3lv02d_get_axis()
158 return hw_values[axis - 1]; in lis3lv02d_get_axis()
160 return -hw_values[-axis - 1]; in lis3lv02d_get_axis()
164 * lis3lv02d_get_xyz - Get X, Y and Z axis values from the accelerometer
166 * @x: where to store the X axis value
167 * @y: where to store the Y axis value
168 * @z: where to store the Z axis value
172 static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z) in lis3lv02d_get_xyz() argument
177 if (lis3->blkread) { in lis3lv02d_get_xyz()
178 if (lis3->whoami == WAI_12B) { in lis3lv02d_get_xyz()
180 lis3->blkread(lis3, OUTX_L, 6, (u8 *)data); in lis3lv02d_get_xyz()
185 /* Data: x, dummy, y, dummy, z */ in lis3lv02d_get_xyz()
186 lis3->blkread(lis3, OUTX, 5, data); in lis3lv02d_get_xyz()
191 position[0] = lis3->read_data(lis3, OUTX); in lis3lv02d_get_xyz()
192 position[1] = lis3->read_data(lis3, OUTY); in lis3lv02d_get_xyz()
193 position[2] = lis3->read_data(lis3, OUTZ); in lis3lv02d_get_xyz()
197 position[i] = (position[i] * lis3->scale) / LIS3_ACCURACY; in lis3lv02d_get_xyz()
199 *x = lis3lv02d_get_axis(lis3->ac.x, position); in lis3lv02d_get_xyz()
200 *y = lis3lv02d_get_axis(lis3->ac.y, position); in lis3lv02d_get_xyz()
201 *z = lis3lv02d_get_axis(lis3->ac.z, position); in lis3lv02d_get_xyz()
216 lis3->read(lis3, CTRL_REG1, &ctrl); in lis3lv02d_get_odr_index()
217 ctrl &= lis3->odr_mask; in lis3lv02d_get_odr_index()
218 shift = ffs(lis3->odr_mask) - 1; in lis3lv02d_get_odr_index()
225 int div = lis3->odrs[odr_idx]; in lis3lv02d_get_pwron_wait()
229 /* Power-down mode, not sampling no need to sleep */ in lis3lv02d_get_pwron_wait()
233 dev_err(&lis3->pdev->dev, "Error unknown odrs-index: %d\n", odr_idx); in lis3lv02d_get_pwron_wait()
234 return -ENXIO; in lis3lv02d_get_pwron_wait()
238 msleep(lis3->pwron_delay / div); in lis3lv02d_get_pwron_wait()
248 return -EINVAL; in lis3lv02d_set_odr()
250 lis3->read(lis3, CTRL_REG1, &ctrl); in lis3lv02d_set_odr()
251 ctrl &= ~lis3->odr_mask; in lis3lv02d_set_odr()
252 len = 1 << hweight_long(lis3->odr_mask); /* # of possible values */ in lis3lv02d_set_odr()
253 shift = ffs(lis3->odr_mask) - 1; in lis3lv02d_set_odr()
256 if (lis3->odrs[i] == rate) { in lis3lv02d_set_odr()
257 lis3->write(lis3, CTRL_REG1, in lis3lv02d_set_odr()
261 return -EINVAL; in lis3lv02d_set_odr()
267 s16 x, y, z; in lis3lv02d_selftest() local
273 mutex_lock(&lis3->mutex); in lis3lv02d_selftest()
275 irq_cfg = lis3->irq_cfg; in lis3lv02d_selftest()
276 if (lis3->whoami == WAI_8B) { in lis3lv02d_selftest()
277 lis3->data_ready_count[IRQ_LINE0] = 0; in lis3lv02d_selftest()
278 lis3->data_ready_count[IRQ_LINE1] = 0; in lis3lv02d_selftest()
281 atomic_inc(&lis3->wake_thread); in lis3lv02d_selftest()
282 lis3->irq_cfg = LIS3_IRQ1_DATA_READY | LIS3_IRQ2_DATA_READY; in lis3lv02d_selftest()
283 lis3->read(lis3, CTRL_REG3, &ctrl_reg_data); in lis3lv02d_selftest()
284 lis3->write(lis3, CTRL_REG3, (ctrl_reg_data & in lis3lv02d_selftest()
289 if ((lis3->whoami == WAI_3DC) || (lis3->whoami == WAI_3DLH)) { in lis3lv02d_selftest()
294 if (lis3->whoami == WAI_12B) in lis3lv02d_selftest()
300 lis3->read(lis3, ctlreg, &reg); in lis3lv02d_selftest()
301 lis3->write(lis3, ctlreg, (reg | selftest)); in lis3lv02d_selftest()
306 /* Read directly to avoid axis remap */ in lis3lv02d_selftest()
307 x = lis3->read_data(lis3, OUTX); in lis3lv02d_selftest()
308 y = lis3->read_data(lis3, OUTY); in lis3lv02d_selftest()
309 z = lis3->read_data(lis3, OUTZ); in lis3lv02d_selftest()
312 lis3->write(lis3, ctlreg, reg); in lis3lv02d_selftest()
317 results[0] = x - lis3->read_data(lis3, OUTX); in lis3lv02d_selftest()
318 results[1] = y - lis3->read_data(lis3, OUTY); in lis3lv02d_selftest()
319 results[2] = z - lis3->read_data(lis3, OUTZ); in lis3lv02d_selftest()
323 if (lis3->whoami == WAI_8B) { in lis3lv02d_selftest()
325 atomic_dec(&lis3->wake_thread); in lis3lv02d_selftest()
326 lis3->write(lis3, CTRL_REG3, ctrl_reg_data); in lis3lv02d_selftest()
327 lis3->irq_cfg = irq_cfg; in lis3lv02d_selftest()
330 lis3->data_ready_count[IRQ_LINE0] < 2) { in lis3lv02d_selftest()
336 lis3->data_ready_count[IRQ_LINE1] < 2) { in lis3lv02d_selftest()
342 if (lis3->pdata) { in lis3lv02d_selftest()
346 if ((results[i] < lis3->pdata->st_min_limits[i]) || in lis3lv02d_selftest()
347 (results[i] > lis3->pdata->st_max_limits[i])) { in lis3lv02d_selftest()
356 mutex_unlock(&lis3->mutex); in lis3lv02d_selftest()
379 for (i = 0; i < lis3->regs_size; i++) in lis3_context_save()
380 lis3->read(lis3, lis3->regs[i], &lis3->reg_cache[i]); in lis3_context_save()
381 lis3->regs_stored = true; in lis3_context_save()
387 if (lis3->regs_stored) in lis3_context_restore()
388 for (i = 0; i < lis3->regs_size; i++) in lis3_context_restore()
389 lis3->write(lis3, lis3->regs[i], lis3->reg_cache[i]); in lis3_context_restore()
394 if (lis3->reg_ctrl) in lis3lv02d_poweroff()
396 /* disable X,Y,Z axis and power down */ in lis3lv02d_poweroff()
397 lis3->write(lis3, CTRL_REG1, 0x00); in lis3lv02d_poweroff()
398 if (lis3->reg_ctrl) in lis3lv02d_poweroff()
399 lis3->reg_ctrl(lis3, LIS3_REG_OFF); in lis3lv02d_poweroff()
408 lis3->init(lis3); in lis3lv02d_poweron()
416 if (lis3->pdata) { in lis3lv02d_poweron()
417 lis3->read(lis3, CTRL_REG2, &reg); in lis3lv02d_poweron()
418 if (lis3->whoami == WAI_12B) in lis3lv02d_poweron()
420 else if (lis3->whoami == WAI_3DLH) in lis3lv02d_poweron()
424 lis3->write(lis3, CTRL_REG2, reg); in lis3lv02d_poweron()
426 if (lis3->whoami == WAI_3DLH) { in lis3lv02d_poweron()
427 lis3->read(lis3, CTRL_REG4, &reg); in lis3lv02d_poweron()
429 lis3->write(lis3, CTRL_REG4, reg); in lis3lv02d_poweron()
437 if (lis3->reg_ctrl) in lis3lv02d_poweron()
448 int x, y, z; in lis3lv02d_joystick_poll() local
450 mutex_lock(&lis3->mutex); in lis3lv02d_joystick_poll()
451 lis3lv02d_get_xyz(lis3, &x, &y, &z); in lis3lv02d_joystick_poll()
452 input_report_abs(input, ABS_X, x); in lis3lv02d_joystick_poll()
456 mutex_unlock(&lis3->mutex); in lis3lv02d_joystick_poll()
463 if (lis3->pm_dev) in lis3lv02d_joystick_open()
464 pm_runtime_get_sync(lis3->pm_dev); in lis3lv02d_joystick_open()
466 if (lis3->pdata && lis3->whoami == WAI_8B && lis3->idev) in lis3lv02d_joystick_open()
467 atomic_set(&lis3->wake_thread, 1); in lis3lv02d_joystick_open()
481 atomic_set(&lis3->wake_thread, 0); in lis3lv02d_joystick_close()
482 if (lis3->pm_dev) in lis3lv02d_joystick_close()
483 pm_runtime_put(lis3->pm_dev); in lis3lv02d_joystick_close()
490 if (!test_bit(0, &lis3->misc_opened)) in lis302dl_interrupt()
498 atomic_inc(&lis3->count); in lis302dl_interrupt()
500 wake_up_interruptible(&lis3->misc_wait); in lis302dl_interrupt()
501 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN); in lis302dl_interrupt()
503 if (atomic_read(&lis3->wake_thread)) in lis302dl_interrupt()
510 struct input_dev *dev = lis3->idev; in lis302dl_interrupt_handle_click()
513 mutex_lock(&lis3->mutex); in lis302dl_interrupt_handle_click()
514 lis3->read(lis3, CLICK_SRC, &click_src); in lis302dl_interrupt_handle_click()
517 input_report_key(dev, lis3->mapped_btns[0], 1); in lis302dl_interrupt_handle_click()
518 input_report_key(dev, lis3->mapped_btns[0], 0); in lis302dl_interrupt_handle_click()
522 input_report_key(dev, lis3->mapped_btns[1], 1); in lis302dl_interrupt_handle_click()
523 input_report_key(dev, lis3->mapped_btns[1], 0); in lis302dl_interrupt_handle_click()
527 input_report_key(dev, lis3->mapped_btns[2], 1); in lis302dl_interrupt_handle_click()
528 input_report_key(dev, lis3->mapped_btns[2], 0); in lis302dl_interrupt_handle_click()
531 mutex_unlock(&lis3->mutex); in lis302dl_interrupt_handle_click()
540 lis3->data_ready_count[index]++; in lis302dl_data_ready()
546 u8 irq_cfg = lis3->irq_cfg & LIS3_IRQ1_MASK; in lis302dl_interrupt_thread1_8b()
553 lis3lv02d_joystick_poll(lis3->idev); in lis302dl_interrupt_thread1_8b()
561 u8 irq_cfg = lis3->irq_cfg & LIS3_IRQ2_MASK; in lis302dl_interrupt_thread2_8b()
568 lis3lv02d_joystick_poll(lis3->idev); in lis302dl_interrupt_thread2_8b()
575 struct lis3lv02d *lis3 = container_of(file->private_data, in lis3lv02d_misc_open()
578 if (test_and_set_bit(0, &lis3->misc_opened)) in lis3lv02d_misc_open()
579 return -EBUSY; /* already open */ in lis3lv02d_misc_open()
581 if (lis3->pm_dev) in lis3lv02d_misc_open()
582 pm_runtime_get_sync(lis3->pm_dev); in lis3lv02d_misc_open()
584 atomic_set(&lis3->count, 0); in lis3lv02d_misc_open()
590 struct lis3lv02d *lis3 = container_of(file->private_data, in lis3lv02d_misc_release()
593 clear_bit(0, &lis3->misc_opened); /* release the device */ in lis3lv02d_misc_release()
594 if (lis3->pm_dev) in lis3lv02d_misc_release()
595 pm_runtime_put(lis3->pm_dev); in lis3lv02d_misc_release()
602 struct lis3lv02d *lis3 = container_of(file->private_data, in lis3lv02d_misc_read()
611 return -EINVAL; in lis3lv02d_misc_read()
613 add_wait_queue(&lis3->misc_wait, &wait); in lis3lv02d_misc_read()
616 data = atomic_xchg(&lis3->count, 0); in lis3lv02d_misc_read()
620 if (file->f_flags & O_NONBLOCK) { in lis3lv02d_misc_read()
621 retval = -EAGAIN; in lis3lv02d_misc_read()
626 retval = -ERESTARTSYS; in lis3lv02d_misc_read()
642 retval = -EFAULT; in lis3lv02d_misc_read()
646 remove_wait_queue(&lis3->misc_wait, &wait); in lis3lv02d_misc_read()
653 struct lis3lv02d *lis3 = container_of(file->private_data, in lis3lv02d_misc_poll()
656 poll_wait(file, &lis3->misc_wait, wait); in lis3lv02d_misc_poll()
657 if (atomic_read(&lis3->count)) in lis3lv02d_misc_poll()
664 struct lis3lv02d *lis3 = container_of(file->private_data, in lis3lv02d_misc_fasync()
667 return fasync_helper(fd, file, on, &lis3->async_queue); in lis3lv02d_misc_fasync()
686 if (lis3->idev) in lis3lv02d_joystick_enable()
687 return -EINVAL; in lis3lv02d_joystick_enable()
691 return -ENOMEM; in lis3lv02d_joystick_enable()
693 input_dev->name = "ST LIS3LV02DL Accelerometer"; in lis3lv02d_joystick_enable()
694 input_dev->phys = DRIVER_NAME "/input0"; in lis3lv02d_joystick_enable()
695 input_dev->id.bustype = BUS_HOST; in lis3lv02d_joystick_enable()
696 input_dev->id.vendor = 0; in lis3lv02d_joystick_enable()
697 input_dev->dev.parent = &lis3->pdev->dev; in lis3lv02d_joystick_enable()
699 input_dev->open = lis3lv02d_joystick_open; in lis3lv02d_joystick_enable()
700 input_dev->close = lis3lv02d_joystick_close; in lis3lv02d_joystick_enable()
702 max_val = (lis3->mdps_max_val * lis3->scale) / LIS3_ACCURACY; in lis3lv02d_joystick_enable()
703 if (lis3->whoami == WAI_12B) { in lis3lv02d_joystick_enable()
710 fuzz = (fuzz * lis3->scale) / LIS3_ACCURACY; in lis3lv02d_joystick_enable()
711 flat = (flat * lis3->scale) / LIS3_ACCURACY; in lis3lv02d_joystick_enable()
713 input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat); in lis3lv02d_joystick_enable()
714 input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat); in lis3lv02d_joystick_enable()
715 input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat); in lis3lv02d_joystick_enable()
718 lis3->idev = input_dev; in lis3lv02d_joystick_enable()
728 lis3->mapped_btns[0] = lis3lv02d_get_axis(abs(lis3->ac.x), btns); in lis3lv02d_joystick_enable()
729 lis3->mapped_btns[1] = lis3lv02d_get_axis(abs(lis3->ac.y), btns); in lis3lv02d_joystick_enable()
730 lis3->mapped_btns[2] = lis3lv02d_get_axis(abs(lis3->ac.z), btns); in lis3lv02d_joystick_enable()
732 err = input_register_device(lis3->idev); in lis3lv02d_joystick_enable()
740 lis3->idev = NULL; in lis3lv02d_joystick_enable()
748 if (lis3->irq) in lis3lv02d_joystick_disable()
749 free_irq(lis3->irq, lis3); in lis3lv02d_joystick_disable()
750 if (lis3->pdata && lis3->pdata->irq2) in lis3lv02d_joystick_disable()
751 free_irq(lis3->pdata->irq2, lis3); in lis3lv02d_joystick_disable()
753 if (!lis3->idev) in lis3lv02d_joystick_disable()
756 if (lis3->irq) in lis3lv02d_joystick_disable()
757 misc_deregister(&lis3->miscdev); in lis3lv02d_joystick_disable()
758 input_unregister_device(lis3->idev); in lis3lv02d_joystick_disable()
759 lis3->idev = NULL; in lis3lv02d_joystick_disable()
767 * SYSFS functions are fast visitors so put-call in lis3lv02d_sysfs_poweron()
768 * immediately after the get-call. However, keep in lis3lv02d_sysfs_poweron()
774 if (lis3->pm_dev) { in lis3lv02d_sysfs_poweron()
775 pm_runtime_get_sync(lis3->pm_dev); in lis3lv02d_sysfs_poweron()
776 pm_runtime_put_noidle(lis3->pm_dev); in lis3lv02d_sysfs_poweron()
777 pm_schedule_suspend(lis3->pm_dev, LIS3_SYSFS_POWERDOWN_DELAY); in lis3lv02d_sysfs_poweron()
813 int x, y, z; in lis3lv02d_position_show() local
816 mutex_lock(&lis3->mutex); in lis3lv02d_position_show()
817 lis3lv02d_get_xyz(lis3, &x, &y, &z); in lis3lv02d_position_show()
818 mutex_unlock(&lis3->mutex); in lis3lv02d_position_show()
819 return sprintf(buf, "(%d,%d,%d)\n", x, y, z); in lis3lv02d_position_show()
831 return sprintf(buf, "%d\n", lis3->odrs[odr_idx]); in lis3lv02d_rate_show()
848 return -EINVAL; in lis3lv02d_rate_set()
872 lis3->pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); in lis3lv02d_add_fs()
873 if (IS_ERR(lis3->pdev)) in lis3lv02d_add_fs()
874 return PTR_ERR(lis3->pdev); in lis3lv02d_add_fs()
876 platform_set_drvdata(lis3->pdev, lis3); in lis3lv02d_add_fs()
877 return sysfs_create_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group); in lis3lv02d_add_fs()
882 sysfs_remove_group(&lis3->pdev->dev.kobj, &lis3lv02d_attribute_group); in lis3lv02d_remove_fs()
883 platform_device_unregister(lis3->pdev); in lis3lv02d_remove_fs()
884 if (lis3->pm_dev) { in lis3lv02d_remove_fs()
886 pm_runtime_barrier(lis3->pm_dev); in lis3lv02d_remove_fs()
889 if (!pm_runtime_suspended(lis3->pm_dev)) in lis3lv02d_remove_fs()
892 pm_runtime_disable(lis3->pm_dev); in lis3lv02d_remove_fs()
893 pm_runtime_set_suspended(lis3->pm_dev); in lis3lv02d_remove_fs()
895 kfree(lis3->reg_cache); in lis3lv02d_remove_fs()
903 int ctrl2 = p->hipass_ctrl; in lis3lv02d_8b_configure()
905 if (p->click_flags) { in lis3lv02d_8b_configure()
906 lis3->write(lis3, CLICK_CFG, p->click_flags); in lis3lv02d_8b_configure()
907 lis3->write(lis3, CLICK_TIMELIMIT, p->click_time_limit); in lis3lv02d_8b_configure()
908 lis3->write(lis3, CLICK_LATENCY, p->click_latency); in lis3lv02d_8b_configure()
909 lis3->write(lis3, CLICK_WINDOW, p->click_window); in lis3lv02d_8b_configure()
910 lis3->write(lis3, CLICK_THSZ, p->click_thresh_z & 0xf); in lis3lv02d_8b_configure()
911 lis3->write(lis3, CLICK_THSY_X, in lis3lv02d_8b_configure()
912 (p->click_thresh_x & 0xf) | in lis3lv02d_8b_configure()
913 (p->click_thresh_y << 4)); in lis3lv02d_8b_configure()
915 if (lis3->idev) { in lis3lv02d_8b_configure()
916 input_set_capability(lis3->idev, EV_KEY, BTN_X); in lis3lv02d_8b_configure()
917 input_set_capability(lis3->idev, EV_KEY, BTN_Y); in lis3lv02d_8b_configure()
918 input_set_capability(lis3->idev, EV_KEY, BTN_Z); in lis3lv02d_8b_configure()
922 if (p->wakeup_flags) { in lis3lv02d_8b_configure()
923 lis3->write(lis3, FF_WU_CFG_1, p->wakeup_flags); in lis3lv02d_8b_configure()
924 lis3->write(lis3, FF_WU_THS_1, p->wakeup_thresh & 0x7f); in lis3lv02d_8b_configure()
926 lis3->write(lis3, FF_WU_DURATION_1, p->duration1 + 1); in lis3lv02d_8b_configure()
930 if (p->wakeup_flags2) { in lis3lv02d_8b_configure()
931 lis3->write(lis3, FF_WU_CFG_2, p->wakeup_flags2); in lis3lv02d_8b_configure()
932 lis3->write(lis3, FF_WU_THS_2, p->wakeup_thresh2 & 0x7f); in lis3lv02d_8b_configure()
934 lis3->write(lis3, FF_WU_DURATION_2, p->duration2 + 1); in lis3lv02d_8b_configure()
938 lis3->write(lis3, CTRL_REG2, ctrl2); in lis3lv02d_8b_configure()
940 if (p->irq2) { in lis3lv02d_8b_configure()
941 err = request_threaded_irq(p->irq2, in lis3lv02d_8b_configure()
945 (p->irq_flags2 & IRQF_TRIGGER_MASK), in lis3lv02d_8b_configure()
956 struct device_node *np = lis3->of_node; in lis3lv02d_init_dt()
960 if (!lis3->of_node) in lis3lv02d_init_dt()
965 return -ENOMEM; in lis3lv02d_init_dt()
967 if (of_property_read_bool(np, "st,click-single-x")) in lis3lv02d_init_dt()
968 pdata->click_flags |= LIS3_CLICK_SINGLE_X; in lis3lv02d_init_dt()
969 if (of_property_read_bool(np, "st,click-double-x")) in lis3lv02d_init_dt()
970 pdata->click_flags |= LIS3_CLICK_DOUBLE_X; in lis3lv02d_init_dt()
972 if (of_property_read_bool(np, "st,click-single-y")) in lis3lv02d_init_dt()
973 pdata->click_flags |= LIS3_CLICK_SINGLE_Y; in lis3lv02d_init_dt()
974 if (of_property_read_bool(np, "st,click-double-y")) in lis3lv02d_init_dt()
975 pdata->click_flags |= LIS3_CLICK_DOUBLE_Y; in lis3lv02d_init_dt()
977 if (of_property_read_bool(np, "st,click-single-z")) in lis3lv02d_init_dt()
978 pdata->click_flags |= LIS3_CLICK_SINGLE_Z; in lis3lv02d_init_dt()
979 if (of_property_read_bool(np, "st,click-double-z")) in lis3lv02d_init_dt()
980 pdata->click_flags |= LIS3_CLICK_DOUBLE_Z; in lis3lv02d_init_dt()
982 if (!of_property_read_u32(np, "st,click-threshold-x", &val)) in lis3lv02d_init_dt()
983 pdata->click_thresh_x = val; in lis3lv02d_init_dt()
984 if (!of_property_read_u32(np, "st,click-threshold-y", &val)) in lis3lv02d_init_dt()
985 pdata->click_thresh_y = val; in lis3lv02d_init_dt()
986 if (!of_property_read_u32(np, "st,click-threshold-z", &val)) in lis3lv02d_init_dt()
987 pdata->click_thresh_z = val; in lis3lv02d_init_dt()
989 if (!of_property_read_u32(np, "st,click-time-limit", &val)) in lis3lv02d_init_dt()
990 pdata->click_time_limit = val; in lis3lv02d_init_dt()
991 if (!of_property_read_u32(np, "st,click-latency", &val)) in lis3lv02d_init_dt()
992 pdata->click_latency = val; in lis3lv02d_init_dt()
993 if (!of_property_read_u32(np, "st,click-window", &val)) in lis3lv02d_init_dt()
994 pdata->click_window = val; in lis3lv02d_init_dt()
996 if (of_property_read_bool(np, "st,irq1-disable")) in lis3lv02d_init_dt()
997 pdata->irq_cfg |= LIS3_IRQ1_DISABLE; in lis3lv02d_init_dt()
998 if (of_property_read_bool(np, "st,irq1-ff-wu-1")) in lis3lv02d_init_dt()
999 pdata->irq_cfg |= LIS3_IRQ1_FF_WU_1; in lis3lv02d_init_dt()
1000 if (of_property_read_bool(np, "st,irq1-ff-wu-2")) in lis3lv02d_init_dt()
1001 pdata->irq_cfg |= LIS3_IRQ1_FF_WU_2; in lis3lv02d_init_dt()
1002 if (of_property_read_bool(np, "st,irq1-data-ready")) in lis3lv02d_init_dt()
1003 pdata->irq_cfg |= LIS3_IRQ1_DATA_READY; in lis3lv02d_init_dt()
1004 if (of_property_read_bool(np, "st,irq1-click")) in lis3lv02d_init_dt()
1005 pdata->irq_cfg |= LIS3_IRQ1_CLICK; in lis3lv02d_init_dt()
1007 if (of_property_read_bool(np, "st,irq2-disable")) in lis3lv02d_init_dt()
1008 pdata->irq_cfg |= LIS3_IRQ2_DISABLE; in lis3lv02d_init_dt()
1009 if (of_property_read_bool(np, "st,irq2-ff-wu-1")) in lis3lv02d_init_dt()
1010 pdata->irq_cfg |= LIS3_IRQ2_FF_WU_1; in lis3lv02d_init_dt()
1011 if (of_property_read_bool(np, "st,irq2-ff-wu-2")) in lis3lv02d_init_dt()
1012 pdata->irq_cfg |= LIS3_IRQ2_FF_WU_2; in lis3lv02d_init_dt()
1013 if (of_property_read_bool(np, "st,irq2-data-ready")) in lis3lv02d_init_dt()
1014 pdata->irq_cfg |= LIS3_IRQ2_DATA_READY; in lis3lv02d_init_dt()
1015 if (of_property_read_bool(np, "st,irq2-click")) in lis3lv02d_init_dt()
1016 pdata->irq_cfg |= LIS3_IRQ2_CLICK; in lis3lv02d_init_dt()
1018 if (of_property_read_bool(np, "st,irq-open-drain")) in lis3lv02d_init_dt()
1019 pdata->irq_cfg |= LIS3_IRQ_OPEN_DRAIN; in lis3lv02d_init_dt()
1020 if (of_property_read_bool(np, "st,irq-active-low")) in lis3lv02d_init_dt()
1021 pdata->irq_cfg |= LIS3_IRQ_ACTIVE_LOW; in lis3lv02d_init_dt()
1023 if (!of_property_read_u32(np, "st,wu-duration-1", &val)) in lis3lv02d_init_dt()
1024 pdata->duration1 = val; in lis3lv02d_init_dt()
1025 if (!of_property_read_u32(np, "st,wu-duration-2", &val)) in lis3lv02d_init_dt()
1026 pdata->duration2 = val; in lis3lv02d_init_dt()
1028 if (of_property_read_bool(np, "st,wakeup-x-lo")) in lis3lv02d_init_dt()
1029 pdata->wakeup_flags |= LIS3_WAKEUP_X_LO; in lis3lv02d_init_dt()
1030 if (of_property_read_bool(np, "st,wakeup-x-hi")) in lis3lv02d_init_dt()
1031 pdata->wakeup_flags |= LIS3_WAKEUP_X_HI; in lis3lv02d_init_dt()
1032 if (of_property_read_bool(np, "st,wakeup-y-lo")) in lis3lv02d_init_dt()
1033 pdata->wakeup_flags |= LIS3_WAKEUP_Y_LO; in lis3lv02d_init_dt()
1034 if (of_property_read_bool(np, "st,wakeup-y-hi")) in lis3lv02d_init_dt()
1035 pdata->wakeup_flags |= LIS3_WAKEUP_Y_HI; in lis3lv02d_init_dt()
1036 if (of_property_read_bool(np, "st,wakeup-z-lo")) in lis3lv02d_init_dt()
1037 pdata->wakeup_flags |= LIS3_WAKEUP_Z_LO; in lis3lv02d_init_dt()
1038 if (of_property_read_bool(np, "st,wakeup-z-hi")) in lis3lv02d_init_dt()
1039 pdata->wakeup_flags |= LIS3_WAKEUP_Z_HI; in lis3lv02d_init_dt()
1040 if (!of_property_read_u32(np, "st,wakeup-threshold", &val)) in lis3lv02d_init_dt()
1041 pdata->wakeup_thresh = val; in lis3lv02d_init_dt()
1043 if (of_property_read_bool(np, "st,wakeup2-x-lo")) in lis3lv02d_init_dt()
1044 pdata->wakeup_flags2 |= LIS3_WAKEUP_X_LO; in lis3lv02d_init_dt()
1045 if (of_property_read_bool(np, "st,wakeup2-x-hi")) in lis3lv02d_init_dt()
1046 pdata->wakeup_flags2 |= LIS3_WAKEUP_X_HI; in lis3lv02d_init_dt()
1047 if (of_property_read_bool(np, "st,wakeup2-y-lo")) in lis3lv02d_init_dt()
1048 pdata->wakeup_flags2 |= LIS3_WAKEUP_Y_LO; in lis3lv02d_init_dt()
1049 if (of_property_read_bool(np, "st,wakeup2-y-hi")) in lis3lv02d_init_dt()
1050 pdata->wakeup_flags2 |= LIS3_WAKEUP_Y_HI; in lis3lv02d_init_dt()
1051 if (of_property_read_bool(np, "st,wakeup2-z-lo")) in lis3lv02d_init_dt()
1052 pdata->wakeup_flags2 |= LIS3_WAKEUP_Z_LO; in lis3lv02d_init_dt()
1053 if (of_property_read_bool(np, "st,wakeup2-z-hi")) in lis3lv02d_init_dt()
1054 pdata->wakeup_flags2 |= LIS3_WAKEUP_Z_HI; in lis3lv02d_init_dt()
1055 if (!of_property_read_u32(np, "st,wakeup2-threshold", &val)) in lis3lv02d_init_dt()
1056 pdata->wakeup_thresh2 = val; in lis3lv02d_init_dt()
1058 if (!of_property_read_u32(np, "st,highpass-cutoff-hz", &val)) { in lis3lv02d_init_dt()
1061 pdata->hipass_ctrl = LIS3_HIPASS_CUTFF_1HZ; in lis3lv02d_init_dt()
1064 pdata->hipass_ctrl = LIS3_HIPASS_CUTFF_2HZ; in lis3lv02d_init_dt()
1067 pdata->hipass_ctrl = LIS3_HIPASS_CUTFF_4HZ; in lis3lv02d_init_dt()
1070 pdata->hipass_ctrl = LIS3_HIPASS_CUTFF_8HZ; in lis3lv02d_init_dt()
1075 if (of_property_read_bool(np, "st,hipass1-disable")) in lis3lv02d_init_dt()
1076 pdata->hipass_ctrl |= LIS3_HIPASS1_DISABLE; in lis3lv02d_init_dt()
1077 if (of_property_read_bool(np, "st,hipass2-disable")) in lis3lv02d_init_dt()
1078 pdata->hipass_ctrl |= LIS3_HIPASS2_DISABLE; in lis3lv02d_init_dt()
1080 if (of_property_read_s32(np, "st,axis-x", &sval) == 0) in lis3lv02d_init_dt()
1081 pdata->axis_x = sval; in lis3lv02d_init_dt()
1082 if (of_property_read_s32(np, "st,axis-y", &sval) == 0) in lis3lv02d_init_dt()
1083 pdata->axis_y = sval; in lis3lv02d_init_dt()
1084 if (of_property_read_s32(np, "st,axis-z", &sval) == 0) in lis3lv02d_init_dt()
1085 pdata->axis_z = sval; in lis3lv02d_init_dt()
1087 if (of_property_read_u32(np, "st,default-rate", &val) == 0) in lis3lv02d_init_dt()
1088 pdata->default_rate = val; in lis3lv02d_init_dt()
1090 if (of_property_read_s32(np, "st,min-limit-x", &sval) == 0) in lis3lv02d_init_dt()
1091 pdata->st_min_limits[0] = sval; in lis3lv02d_init_dt()
1092 if (of_property_read_s32(np, "st,min-limit-y", &sval) == 0) in lis3lv02d_init_dt()
1093 pdata->st_min_limits[1] = sval; in lis3lv02d_init_dt()
1094 if (of_property_read_s32(np, "st,min-limit-z", &sval) == 0) in lis3lv02d_init_dt()
1095 pdata->st_min_limits[2] = sval; in lis3lv02d_init_dt()
1097 if (of_property_read_s32(np, "st,max-limit-x", &sval) == 0) in lis3lv02d_init_dt()
1098 pdata->st_max_limits[0] = sval; in lis3lv02d_init_dt()
1099 if (of_property_read_s32(np, "st,max-limit-y", &sval) == 0) in lis3lv02d_init_dt()
1100 pdata->st_max_limits[1] = sval; in lis3lv02d_init_dt()
1101 if (of_property_read_s32(np, "st,max-limit-z", &sval) == 0) in lis3lv02d_init_dt()
1102 pdata->st_max_limits[2] = sval; in lis3lv02d_init_dt()
1105 lis3->pdata = pdata; in lis3lv02d_init_dt()
1128 lis3->whoami = lis3lv02d_read_8(lis3, WHO_AM_I); in lis3lv02d_init_device()
1130 switch (lis3->whoami) { in lis3lv02d_init_device()
1133 lis3->read_data = lis3lv02d_read_12; in lis3lv02d_init_device()
1134 lis3->mdps_max_val = 2048; in lis3lv02d_init_device()
1135 lis3->pwron_delay = LIS3_PWRON_DELAY_WAI_12B; in lis3lv02d_init_device()
1136 lis3->odrs = lis3_12_rates; in lis3lv02d_init_device()
1137 lis3->odr_mask = CTRL1_DF0 | CTRL1_DF1; in lis3lv02d_init_device()
1138 lis3->scale = LIS3_SENSITIVITY_12B; in lis3lv02d_init_device()
1139 lis3->regs = lis3_wai12_regs; in lis3lv02d_init_device()
1140 lis3->regs_size = ARRAY_SIZE(lis3_wai12_regs); in lis3lv02d_init_device()
1144 lis3->read_data = lis3lv02d_read_8; in lis3lv02d_init_device()
1145 lis3->mdps_max_val = 128; in lis3lv02d_init_device()
1146 lis3->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; in lis3lv02d_init_device()
1147 lis3->odrs = lis3_8_rates; in lis3lv02d_init_device()
1148 lis3->odr_mask = CTRL1_DR; in lis3lv02d_init_device()
1149 lis3->scale = LIS3_SENSITIVITY_8B; in lis3lv02d_init_device()
1150 lis3->regs = lis3_wai8_regs; in lis3lv02d_init_device()
1151 lis3->regs_size = ARRAY_SIZE(lis3_wai8_regs); in lis3lv02d_init_device()
1155 lis3->read_data = lis3lv02d_read_8; in lis3lv02d_init_device()
1156 lis3->mdps_max_val = 128; in lis3lv02d_init_device()
1157 lis3->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; in lis3lv02d_init_device()
1158 lis3->odrs = lis3_3dc_rates; in lis3lv02d_init_device()
1159 lis3->odr_mask = CTRL1_ODR0|CTRL1_ODR1|CTRL1_ODR2|CTRL1_ODR3; in lis3lv02d_init_device()
1160 lis3->scale = LIS3_SENSITIVITY_8B; in lis3lv02d_init_device()
1164 lis3->read_data = lis331dlh_read_data; in lis3lv02d_init_device()
1165 lis3->mdps_max_val = 2048; /* 12 bits for 2G */ in lis3lv02d_init_device()
1166 lis3->shift_adj = SHIFT_ADJ_2G; in lis3lv02d_init_device()
1167 lis3->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; in lis3lv02d_init_device()
1168 lis3->odrs = lis3_3dlh_rates; in lis3lv02d_init_device()
1169 lis3->odr_mask = CTRL1_DR0 | CTRL1_DR1; in lis3lv02d_init_device()
1170 lis3->scale = LIS3DLH_SENSITIVITY_2G; in lis3lv02d_init_device()
1173 pr_err("unknown sensor type 0x%X\n", lis3->whoami); in lis3lv02d_init_device()
1174 return -ENODEV; in lis3lv02d_init_device()
1177 lis3->reg_cache = kzalloc(max(sizeof(lis3_wai8_regs), in lis3lv02d_init_device()
1180 if (lis3->reg_cache == NULL) in lis3lv02d_init_device()
1181 return -ENOMEM; in lis3lv02d_init_device()
1183 mutex_init(&lis3->mutex); in lis3lv02d_init_device()
1184 atomic_set(&lis3->wake_thread, 0); in lis3lv02d_init_device()
1193 if (lis3->pm_dev) { in lis3lv02d_init_device()
1194 pm_runtime_set_active(lis3->pm_dev); in lis3lv02d_init_device()
1195 pm_runtime_enable(lis3->pm_dev); in lis3lv02d_init_device()
1203 if (lis3->pdata) { in lis3lv02d_init_device()
1204 struct lis3lv02d_platform_data *p = lis3->pdata; in lis3lv02d_init_device()
1206 if (lis3->whoami == WAI_8B) in lis3lv02d_init_device()
1209 irq_flags = p->irq_flags1 & IRQF_TRIGGER_MASK; in lis3lv02d_init_device()
1211 lis3->irq_cfg = p->irq_cfg; in lis3lv02d_init_device()
1212 if (p->irq_cfg) in lis3lv02d_init_device()
1213 lis3->write(lis3, CTRL_REG3, p->irq_cfg); in lis3lv02d_init_device()
1215 if (p->default_rate) in lis3lv02d_init_device()
1216 lis3lv02d_set_odr(lis3, p->default_rate); in lis3lv02d_init_device()
1220 if (!lis3->irq) { in lis3lv02d_init_device()
1226 * The sensor can generate interrupts for free-fall and direction in lis3lv02d_init_device()
1228 * the things simple and _fast_ we activate it only for free-fall, so in lis3lv02d_init_device()
1233 * io-apic is not configurable (and generates a warning) but I keep it in lis3lv02d_init_device()
1236 if (lis3->pdata && lis3->whoami == WAI_8B) in lis3lv02d_init_device()
1241 err = request_threaded_irq(lis3->irq, lis302dl_interrupt, in lis3lv02d_init_device()
1252 lis3->miscdev.minor = MISC_DYNAMIC_MINOR; in lis3lv02d_init_device()
1253 lis3->miscdev.name = "freefall"; in lis3lv02d_init_device()
1254 lis3->miscdev.fops = &lis3lv02d_misc_fops; in lis3lv02d_init_device()
1256 if (misc_register(&lis3->miscdev)) in lis3lv02d_init_device()
1263 MODULE_DESCRIPTION("ST LIS3LV02Dx three-axis digital accelerometer driver");