Lines Matching +full:3 +full:- +full:axis
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ADXL345/346 Three-Axis Digital Accelerometers
25 #define OFSX 0x1E /* R/W X-axis offset */
26 #define OFSY 0x1F /* R/W Y-axis offset */
27 #define OFSZ 0x20 /* R/W Z-axis offset */
34 #define ACT_INACT_CTL 0x27 /* R/W Axis enable control for activity and */
36 #define THRESH_FF 0x28 /* R/W Free-fall threshold */
37 #define TIME_FF 0x29 /* R/W Free-fall time */
38 #define TAP_AXES 0x2A /* R/W Axis control for tap/double tap */
46 #define DATAX0 0x32 /* R X-Axis Data 0 */
47 #define DATAX1 0x33 /* R X-Axis Data 1 */
48 #define DATAY0 0x34 /* R Y-Axis Data 0 */
49 #define DATAY1 0x35 /* R Y-Axis Data 1 */
50 #define DATAZ0 0x36 /* R Z-Axis Data 0 */
51 #define DATAZ1 0x37 /* R Z-Axis Data 1 */
68 #define INACTIVITY (1 << 3)
78 #define INACT_ACDC (1 << 3)
84 #define SUPPRESS (1 << 3)
93 #define ASLEEP (1 << 3)
105 #define PCTL_MEASURE (1 << 3)
113 #define FULL_RES (1 << 3)
119 #define RANGE_PM_16g 3
122 * Maximum value our axis may get in full res mode for the input device
128 * Maximum value our axis may get in fixed res mode for the input device
138 #define FIFO_TRIGGER 3
150 #define XTAP (1 << 3)
161 #define ADXL346_3D_VALID (1 << 3)
164 #define ADXL346_2D_PORTRAIT_NEG 1 /* -X */
166 #define ADXL346_2D_LANDSCAPE_NEG 3 /* -Y */
168 #define ADXL346_3D_FRONT 3 /* +X */
169 #define ADXL346_3D_BACK 4 /* -X */
171 #define ADXL346_3D_LEFT 5 /* -Y */
173 #define ADXL346_3D_BOTTOM 6 /* -Z */
181 #define AC_READ(ac, reg) ((ac)->bops->read((ac)->dev, reg))
182 #define AC_WRITE(ac, reg, val) ((ac)->bops->write((ac)->dev, reg, val))
214 .tap_duration = 3,
221 .inactivity_time = 3,
238 static void adxl34x_get_triple(struct adxl34x *ac, struct axis_triple *axis) in adxl34x_get_triple() argument
240 __le16 buf[3]; in adxl34x_get_triple()
242 ac->bops->read_block(ac->dev, DATAX0, DATAZ1 - DATAX0 + 1, buf); in adxl34x_get_triple()
244 mutex_lock(&ac->mutex); in adxl34x_get_triple()
245 ac->saved.x = (s16) le16_to_cpu(buf[0]); in adxl34x_get_triple()
246 axis->x = ac->saved.x; in adxl34x_get_triple()
248 ac->saved.y = (s16) le16_to_cpu(buf[1]); in adxl34x_get_triple()
249 axis->y = ac->saved.y; in adxl34x_get_triple()
251 ac->saved.z = (s16) le16_to_cpu(buf[2]); in adxl34x_get_triple()
252 axis->z = ac->saved.z; in adxl34x_get_triple()
253 mutex_unlock(&ac->mutex); in adxl34x_get_triple()
258 struct adxl34x_platform_data *pdata = &ac->pdata; in adxl34x_service_ev_fifo()
259 struct axis_triple axis; in adxl34x_service_ev_fifo() local
261 adxl34x_get_triple(ac, &axis); in adxl34x_service_ev_fifo()
263 input_event(ac->input, pdata->ev_type, pdata->ev_code_x, in adxl34x_service_ev_fifo()
264 axis.x - ac->swcal.x); in adxl34x_service_ev_fifo()
265 input_event(ac->input, pdata->ev_type, pdata->ev_code_y, in adxl34x_service_ev_fifo()
266 axis.y - ac->swcal.y); in adxl34x_service_ev_fifo()
267 input_event(ac->input, pdata->ev_type, pdata->ev_code_z, in adxl34x_service_ev_fifo()
268 axis.z - ac->swcal.z); in adxl34x_service_ev_fifo()
284 if (status & (1 << (ADXL_Z_AXIS - i))) in adxl34x_send_key_events()
285 input_report_key(ac->input, in adxl34x_send_key_events()
286 pdata->ev_code_tap[i], press); in adxl34x_send_key_events()
294 input_sync(ac->input); in adxl34x_do_tap()
301 struct adxl34x_platform_data *pdata = &ac->pdata; in adxl34x_irq()
309 if (pdata->tap_axis_control & (TAP_X_EN | TAP_Y_EN | TAP_Z_EN)) in adxl34x_irq()
317 adxl34x_report_key_single(ac->input, pdata->ev_code_ff); in adxl34x_irq()
320 dev_dbg(ac->dev, "OVERRUN\n"); in adxl34x_irq()
329 if (pdata->ev_code_act_inactivity) { in adxl34x_irq()
331 input_report_key(ac->input, in adxl34x_irq()
332 pdata->ev_code_act_inactivity, 1); in adxl34x_irq()
334 input_report_key(ac->input, in adxl34x_irq()
335 pdata->ev_code_act_inactivity, 0); in adxl34x_irq()
341 if (pdata->orientation_enable) { in adxl34x_irq()
343 if ((pdata->orientation_enable & ADXL_EN_ORIENTATION_2D) && in adxl34x_irq()
348 if (ac->orient2d_saved != orient_code) { in adxl34x_irq()
349 ac->orient2d_saved = orient_code; in adxl34x_irq()
350 adxl34x_report_key_single(ac->input, in adxl34x_irq()
351 pdata->ev_codes_orient_2d[orient_code]); in adxl34x_irq()
355 if ((pdata->orientation_enable & ADXL_EN_ORIENTATION_3D) && in adxl34x_irq()
358 orient_code = ADXL346_3D_ORIENT(orient) - 1; in adxl34x_irq()
360 if (ac->orient3d_saved != orient_code) { in adxl34x_irq()
361 ac->orient3d_saved = orient_code; in adxl34x_irq()
362 adxl34x_report_key_single(ac->input, in adxl34x_irq()
363 pdata->ev_codes_orient_3d[orient_code]); in adxl34x_irq()
370 if (pdata->fifo_mode) in adxl34x_irq()
375 for (; samples > 0; samples--) { in adxl34x_irq()
387 * greater than 1.5 MHz to de-assert the CS pin to ensure a in adxl34x_irq()
391 if (ac->fifo_delay && (samples > 1)) in adxl34x_irq()
392 udelay(3); in adxl34x_irq()
396 input_sync(ac->input); in adxl34x_irq()
412 AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE); in __adxl34x_enable()
419 mutex_lock(&ac->mutex); in adxl34x_suspend()
421 if (!ac->suspended && !ac->disabled && ac->opened) in adxl34x_suspend()
424 ac->suspended = true; in adxl34x_suspend()
426 mutex_unlock(&ac->mutex); in adxl34x_suspend()
435 mutex_lock(&ac->mutex); in adxl34x_resume()
437 if (ac->suspended && !ac->disabled && ac->opened) in adxl34x_resume()
440 ac->suspended = false; in adxl34x_resume()
442 mutex_unlock(&ac->mutex); in adxl34x_resume()
452 return sprintf(buf, "%u\n", ac->disabled); in adxl34x_disable_show()
467 mutex_lock(&ac->mutex); in adxl34x_disable_store()
469 if (!ac->suspended && ac->opened) { in adxl34x_disable_store()
471 if (!ac->disabled) in adxl34x_disable_store()
474 if (ac->disabled) in adxl34x_disable_store()
479 ac->disabled = !!val; in adxl34x_disable_store()
481 mutex_unlock(&ac->mutex); in adxl34x_disable_store()
494 mutex_lock(&ac->mutex); in adxl34x_calibrate_show()
496 ac->hwcal.x * 4 + ac->swcal.x, in adxl34x_calibrate_show()
497 ac->hwcal.y * 4 + ac->swcal.y, in adxl34x_calibrate_show()
498 ac->hwcal.z * 4 + ac->swcal.z); in adxl34x_calibrate_show()
499 mutex_unlock(&ac->mutex); in adxl34x_calibrate_show()
515 mutex_lock(&ac->mutex); in adxl34x_calibrate_store()
516 ac->hwcal.x -= (ac->saved.x / 4); in adxl34x_calibrate_store()
517 ac->swcal.x = ac->saved.x % 4; in adxl34x_calibrate_store()
519 ac->hwcal.y -= (ac->saved.y / 4); in adxl34x_calibrate_store()
520 ac->swcal.y = ac->saved.y % 4; in adxl34x_calibrate_store()
522 ac->hwcal.z -= (ac->saved.z / 4); in adxl34x_calibrate_store()
523 ac->swcal.z = ac->saved.z % 4; in adxl34x_calibrate_store()
525 AC_WRITE(ac, OFSX, (s8) ac->hwcal.x); in adxl34x_calibrate_store()
526 AC_WRITE(ac, OFSY, (s8) ac->hwcal.y); in adxl34x_calibrate_store()
527 AC_WRITE(ac, OFSZ, (s8) ac->hwcal.z); in adxl34x_calibrate_store()
528 mutex_unlock(&ac->mutex); in adxl34x_calibrate_store()
541 return sprintf(buf, "%u\n", RATE(ac->pdata.data_rate)); in adxl34x_rate_show()
556 mutex_lock(&ac->mutex); in adxl34x_rate_store()
558 ac->pdata.data_rate = RATE(val); in adxl34x_rate_store()
560 ac->pdata.data_rate | in adxl34x_rate_store()
561 (ac->pdata.low_power_mode ? LOW_POWER : 0)); in adxl34x_rate_store()
563 mutex_unlock(&ac->mutex); in adxl34x_rate_store()
576 ac->pdata.power_mode & (PCTL_AUTO_SLEEP | PCTL_LINK) ? 1 : 0); in adxl34x_autosleep_show()
591 mutex_lock(&ac->mutex); in adxl34x_autosleep_store()
594 ac->pdata.power_mode |= (PCTL_AUTO_SLEEP | PCTL_LINK); in adxl34x_autosleep_store()
596 ac->pdata.power_mode &= ~(PCTL_AUTO_SLEEP | PCTL_LINK); in adxl34x_autosleep_store()
598 if (!ac->disabled && !ac->suspended && ac->opened) in adxl34x_autosleep_store()
599 AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE); in adxl34x_autosleep_store()
601 mutex_unlock(&ac->mutex); in adxl34x_autosleep_store()
615 mutex_lock(&ac->mutex); in adxl34x_position_show()
617 ac->saved.x, ac->saved.y, ac->saved.z); in adxl34x_position_show()
618 mutex_unlock(&ac->mutex); in adxl34x_position_show()
641 mutex_lock(&ac->mutex); in adxl34x_write_store()
643 mutex_unlock(&ac->mutex); in adxl34x_write_store()
671 mutex_lock(&ac->mutex); in adxl34x_input_open()
673 if (!ac->suspended && !ac->disabled) in adxl34x_input_open()
676 ac->opened = true; in adxl34x_input_open()
678 mutex_unlock(&ac->mutex); in adxl34x_input_open()
687 mutex_lock(&ac->mutex); in adxl34x_input_close()
689 if (!ac->suspended && !ac->disabled) in adxl34x_input_close()
692 ac->opened = false; in adxl34x_input_close()
694 mutex_unlock(&ac->mutex); in adxl34x_input_close()
709 err = -ENODEV; in adxl34x_probe()
716 err = -ENOMEM; in adxl34x_probe()
720 ac->fifo_delay = fifo_delay_default; in adxl34x_probe()
729 ac->pdata = *pdata; in adxl34x_probe()
730 pdata = &ac->pdata; in adxl34x_probe()
732 ac->input = input_dev; in adxl34x_probe()
733 ac->dev = dev; in adxl34x_probe()
734 ac->irq = irq; in adxl34x_probe()
735 ac->bops = bops; in adxl34x_probe()
737 mutex_init(&ac->mutex); in adxl34x_probe()
739 input_dev->name = "ADXL34x accelerometer"; in adxl34x_probe()
744 ac->model = 345; in adxl34x_probe()
747 ac->model = 346; in adxl34x_probe()
750 dev_err(dev, "Failed to probe %s\n", input_dev->name); in adxl34x_probe()
751 err = -ENODEV; in adxl34x_probe()
755 snprintf(ac->phys, sizeof(ac->phys), "%s/input0", dev_name(dev)); in adxl34x_probe()
757 input_dev->phys = ac->phys; in adxl34x_probe()
758 input_dev->dev.parent = dev; in adxl34x_probe()
759 input_dev->id.product = ac->model; in adxl34x_probe()
760 input_dev->id.bustype = bops->bustype; in adxl34x_probe()
761 input_dev->open = adxl34x_input_open; in adxl34x_probe()
762 input_dev->close = adxl34x_input_close; in adxl34x_probe()
766 __set_bit(ac->pdata.ev_type, input_dev->evbit); in adxl34x_probe()
768 if (ac->pdata.ev_type == EV_REL) { in adxl34x_probe()
769 __set_bit(REL_X, input_dev->relbit); in adxl34x_probe()
770 __set_bit(REL_Y, input_dev->relbit); in adxl34x_probe()
771 __set_bit(REL_Z, input_dev->relbit); in adxl34x_probe()
774 __set_bit(ABS_X, input_dev->absbit); in adxl34x_probe()
775 __set_bit(ABS_Y, input_dev->absbit); in adxl34x_probe()
776 __set_bit(ABS_Z, input_dev->absbit); in adxl34x_probe()
778 if (pdata->data_range & FULL_RES) in adxl34x_probe()
779 range = ADXL_FULLRES_MAX_VAL; /* Signed 13-bit */ in adxl34x_probe()
781 range = ADXL_FIXEDRES_MAX_VAL; /* Signed 10-bit */ in adxl34x_probe()
783 input_set_abs_params(input_dev, ABS_X, -range, range, 3, 3); in adxl34x_probe()
784 input_set_abs_params(input_dev, ABS_Y, -range, range, 3, 3); in adxl34x_probe()
785 input_set_abs_params(input_dev, ABS_Z, -range, range, 3, 3); in adxl34x_probe()
788 __set_bit(EV_KEY, input_dev->evbit); in adxl34x_probe()
789 __set_bit(pdata->ev_code_tap[ADXL_X_AXIS], input_dev->keybit); in adxl34x_probe()
790 __set_bit(pdata->ev_code_tap[ADXL_Y_AXIS], input_dev->keybit); in adxl34x_probe()
791 __set_bit(pdata->ev_code_tap[ADXL_Z_AXIS], input_dev->keybit); in adxl34x_probe()
793 if (pdata->ev_code_ff) { in adxl34x_probe()
794 ac->int_mask = FREE_FALL; in adxl34x_probe()
795 __set_bit(pdata->ev_code_ff, input_dev->keybit); in adxl34x_probe()
798 if (pdata->ev_code_act_inactivity) in adxl34x_probe()
799 __set_bit(pdata->ev_code_act_inactivity, input_dev->keybit); in adxl34x_probe()
801 ac->int_mask |= ACTIVITY | INACTIVITY; in adxl34x_probe()
803 if (pdata->watermark) { in adxl34x_probe()
804 ac->int_mask |= WATERMARK; in adxl34x_probe()
805 if (FIFO_MODE(pdata->fifo_mode) == FIFO_BYPASS) in adxl34x_probe()
806 ac->pdata.fifo_mode |= FIFO_STREAM; in adxl34x_probe()
808 ac->int_mask |= DATA_READY; in adxl34x_probe()
811 if (pdata->tap_axis_control & (TAP_X_EN | TAP_Y_EN | TAP_Z_EN)) in adxl34x_probe()
812 ac->int_mask |= SINGLE_TAP | DOUBLE_TAP; in adxl34x_probe()
814 if (FIFO_MODE(pdata->fifo_mode) == FIFO_BYPASS) in adxl34x_probe()
815 ac->fifo_delay = false; in adxl34x_probe()
819 err = request_threaded_irq(ac->irq, NULL, adxl34x_irq, in adxl34x_probe()
822 dev_err(dev, "irq %d busy?\n", ac->irq); in adxl34x_probe()
826 err = sysfs_create_group(&dev->kobj, &adxl34x_attr_group); in adxl34x_probe()
834 AC_WRITE(ac, OFSX, pdata->x_axis_offset); in adxl34x_probe()
835 ac->hwcal.x = pdata->x_axis_offset; in adxl34x_probe()
836 AC_WRITE(ac, OFSY, pdata->y_axis_offset); in adxl34x_probe()
837 ac->hwcal.y = pdata->y_axis_offset; in adxl34x_probe()
838 AC_WRITE(ac, OFSZ, pdata->z_axis_offset); in adxl34x_probe()
839 ac->hwcal.z = pdata->z_axis_offset; in adxl34x_probe()
840 AC_WRITE(ac, THRESH_TAP, pdata->tap_threshold); in adxl34x_probe()
841 AC_WRITE(ac, DUR, pdata->tap_duration); in adxl34x_probe()
842 AC_WRITE(ac, LATENT, pdata->tap_latency); in adxl34x_probe()
843 AC_WRITE(ac, WINDOW, pdata->tap_window); in adxl34x_probe()
844 AC_WRITE(ac, THRESH_ACT, pdata->activity_threshold); in adxl34x_probe()
845 AC_WRITE(ac, THRESH_INACT, pdata->inactivity_threshold); in adxl34x_probe()
846 AC_WRITE(ac, TIME_INACT, pdata->inactivity_time); in adxl34x_probe()
847 AC_WRITE(ac, THRESH_FF, pdata->free_fall_threshold); in adxl34x_probe()
848 AC_WRITE(ac, TIME_FF, pdata->free_fall_time); in adxl34x_probe()
849 AC_WRITE(ac, TAP_AXES, pdata->tap_axis_control); in adxl34x_probe()
850 AC_WRITE(ac, ACT_INACT_CTL, pdata->act_axis_control); in adxl34x_probe()
851 AC_WRITE(ac, BW_RATE, RATE(ac->pdata.data_rate) | in adxl34x_probe()
852 (pdata->low_power_mode ? LOW_POWER : 0)); in adxl34x_probe()
853 AC_WRITE(ac, DATA_FORMAT, pdata->data_range); in adxl34x_probe()
854 AC_WRITE(ac, FIFO_CTL, FIFO_MODE(pdata->fifo_mode) | in adxl34x_probe()
855 SAMPLES(pdata->watermark)); in adxl34x_probe()
857 if (pdata->use_int2) { in adxl34x_probe()
859 AC_WRITE(ac, INT_MAP, ac->int_mask | OVERRUN); in adxl34x_probe()
865 if (ac->model == 346 && ac->pdata.orientation_enable) { in adxl34x_probe()
867 ORIENT_DEADZONE(ac->pdata.deadzone_angle) | in adxl34x_probe()
868 ORIENT_DIVISOR(ac->pdata.divisor_length)); in adxl34x_probe()
870 ac->orient2d_saved = 1234; in adxl34x_probe()
871 ac->orient3d_saved = 1234; in adxl34x_probe()
873 if (pdata->orientation_enable & ADXL_EN_ORIENTATION_3D) in adxl34x_probe()
874 for (i = 0; i < ARRAY_SIZE(pdata->ev_codes_orient_3d); i++) in adxl34x_probe()
875 __set_bit(pdata->ev_codes_orient_3d[i], in adxl34x_probe()
876 input_dev->keybit); in adxl34x_probe()
878 if (pdata->orientation_enable & ADXL_EN_ORIENTATION_2D) in adxl34x_probe()
879 for (i = 0; i < ARRAY_SIZE(pdata->ev_codes_orient_2d); i++) in adxl34x_probe()
880 __set_bit(pdata->ev_codes_orient_2d[i], in adxl34x_probe()
881 input_dev->keybit); in adxl34x_probe()
883 ac->pdata.orientation_enable = 0; in adxl34x_probe()
886 AC_WRITE(ac, INT_ENABLE, ac->int_mask | OVERRUN); in adxl34x_probe()
888 ac->pdata.power_mode &= (PCTL_AUTO_SLEEP | PCTL_LINK); in adxl34x_probe()
893 sysfs_remove_group(&dev->kobj, &adxl34x_attr_group); in adxl34x_probe()
895 free_irq(ac->irq, ac); in adxl34x_probe()
906 sysfs_remove_group(&ac->dev->kobj, &adxl34x_attr_group); in adxl34x_remove()
907 free_irq(ac->irq, ac); in adxl34x_remove()
908 input_unregister_device(ac->input); in adxl34x_remove()
909 dev_dbg(ac->dev, "unregistered accelerometer\n"); in adxl34x_remove()
917 MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer Driver");