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 guard(mutex)(&ac->mutex); in adxl34x_get_triple()
246 ac->saved.x = (s16) le16_to_cpu(buf[0]); in adxl34x_get_triple()
247 axis->x = ac->saved.x; in adxl34x_get_triple()
249 ac->saved.y = (s16) le16_to_cpu(buf[1]); in adxl34x_get_triple()
250 axis->y = ac->saved.y; in adxl34x_get_triple()
252 ac->saved.z = (s16) le16_to_cpu(buf[2]); in adxl34x_get_triple()
253 axis->z = ac->saved.z; 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 guard(mutex)(&ac->mutex); in adxl34x_suspend()
421 if (!ac->suspended && !ac->disabled && ac->opened) in adxl34x_suspend()
424 ac->suspended = true; in adxl34x_suspend()
433 guard(mutex)(&ac->mutex); in adxl34x_resume()
435 if (ac->suspended && !ac->disabled && ac->opened) in adxl34x_resume()
438 ac->suspended = false; in adxl34x_resume()
448 return sprintf(buf, "%u\n", ac->disabled); in adxl34x_disable_show()
463 guard(mutex)(&ac->mutex); in adxl34x_disable_store()
465 if (!ac->suspended && ac->opened) { in adxl34x_disable_store()
467 if (!ac->disabled) in adxl34x_disable_store()
470 if (ac->disabled) in adxl34x_disable_store()
475 ac->disabled = !!val; in adxl34x_disable_store()
487 guard(mutex)(&ac->mutex); in adxl34x_calibrate_show()
490 ac->hwcal.x * 4 + ac->swcal.x, in adxl34x_calibrate_show()
491 ac->hwcal.y * 4 + ac->swcal.y, in adxl34x_calibrate_show()
492 ac->hwcal.z * 4 + ac->swcal.z); in adxl34x_calibrate_show()
506 guard(mutex)(&ac->mutex); in adxl34x_calibrate_store()
508 ac->hwcal.x -= (ac->saved.x / 4); in adxl34x_calibrate_store()
509 ac->swcal.x = ac->saved.x % 4; in adxl34x_calibrate_store()
511 ac->hwcal.y -= (ac->saved.y / 4); in adxl34x_calibrate_store()
512 ac->swcal.y = ac->saved.y % 4; in adxl34x_calibrate_store()
514 ac->hwcal.z -= (ac->saved.z / 4); in adxl34x_calibrate_store()
515 ac->swcal.z = ac->saved.z % 4; in adxl34x_calibrate_store()
517 AC_WRITE(ac, OFSX, (s8) ac->hwcal.x); in adxl34x_calibrate_store()
518 AC_WRITE(ac, OFSY, (s8) ac->hwcal.y); in adxl34x_calibrate_store()
519 AC_WRITE(ac, OFSZ, (s8) ac->hwcal.z); in adxl34x_calibrate_store()
532 return sprintf(buf, "%u\n", RATE(ac->pdata.data_rate)); in adxl34x_rate_show()
547 guard(mutex)(&ac->mutex); in adxl34x_rate_store()
549 ac->pdata.data_rate = RATE(val); in adxl34x_rate_store()
551 ac->pdata.data_rate | in adxl34x_rate_store()
552 (ac->pdata.low_power_mode ? LOW_POWER : 0)); in adxl34x_rate_store()
565 ac->pdata.power_mode & (PCTL_AUTO_SLEEP | PCTL_LINK) ? 1 : 0); in adxl34x_autosleep_show()
580 guard(mutex)(&ac->mutex); in adxl34x_autosleep_store()
583 ac->pdata.power_mode |= (PCTL_AUTO_SLEEP | PCTL_LINK); in adxl34x_autosleep_store()
585 ac->pdata.power_mode &= ~(PCTL_AUTO_SLEEP | PCTL_LINK); in adxl34x_autosleep_store()
587 if (!ac->disabled && !ac->suspended && ac->opened) in adxl34x_autosleep_store()
588 AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE); in adxl34x_autosleep_store()
601 guard(mutex)(&ac->mutex); in adxl34x_position_show()
604 ac->saved.x, ac->saved.y, ac->saved.z); in adxl34x_position_show()
625 guard(mutex)(&ac->mutex); in adxl34x_write_store()
660 guard(mutex)(&ac->mutex); in adxl34x_input_open()
662 if (!ac->suspended && !ac->disabled) in adxl34x_input_open()
665 ac->opened = true; in adxl34x_input_open()
674 guard(mutex)(&ac->mutex); in adxl34x_input_close()
676 if (!ac->suspended && !ac->disabled) in adxl34x_input_close()
679 ac->opened = false; in adxl34x_input_close()
694 return ERR_PTR(-ENODEV); in adxl34x_probe()
699 return ERR_PTR(-ENOMEM); in adxl34x_probe()
703 return ERR_PTR(-ENOMEM); in adxl34x_probe()
705 ac->fifo_delay = fifo_delay_default; in adxl34x_probe()
714 ac->pdata = *pdata; in adxl34x_probe()
715 pdata = &ac->pdata; in adxl34x_probe()
717 ac->input = input_dev; in adxl34x_probe()
718 ac->dev = dev; in adxl34x_probe()
719 ac->irq = irq; in adxl34x_probe()
720 ac->bops = bops; in adxl34x_probe()
722 mutex_init(&ac->mutex); in adxl34x_probe()
724 input_dev->name = "ADXL34x accelerometer"; in adxl34x_probe()
729 ac->model = 345; in adxl34x_probe()
732 ac->model = 346; in adxl34x_probe()
735 dev_err(dev, "Failed to probe %s\n", input_dev->name); in adxl34x_probe()
736 return ERR_PTR(-ENODEV); in adxl34x_probe()
739 snprintf(ac->phys, sizeof(ac->phys), "%s/input0", dev_name(dev)); in adxl34x_probe()
741 input_dev->phys = ac->phys; in adxl34x_probe()
742 input_dev->id.product = ac->model; in adxl34x_probe()
743 input_dev->id.bustype = bops->bustype; in adxl34x_probe()
744 input_dev->open = adxl34x_input_open; in adxl34x_probe()
745 input_dev->close = adxl34x_input_close; in adxl34x_probe()
749 if (ac->pdata.ev_type == EV_REL) { in adxl34x_probe()
755 if (pdata->data_range & FULL_RES) in adxl34x_probe()
756 range = ADXL_FULLRES_MAX_VAL; /* Signed 13-bit */ in adxl34x_probe()
758 range = ADXL_FIXEDRES_MAX_VAL; /* Signed 10-bit */ in adxl34x_probe()
760 input_set_abs_params(input_dev, ABS_X, -range, range, 3, 3); in adxl34x_probe()
761 input_set_abs_params(input_dev, ABS_Y, -range, range, 3, 3); in adxl34x_probe()
762 input_set_abs_params(input_dev, ABS_Z, -range, range, 3, 3); in adxl34x_probe()
765 input_set_capability(input_dev, EV_KEY, pdata->ev_code_tap[ADXL_X_AXIS]); in adxl34x_probe()
766 input_set_capability(input_dev, EV_KEY, pdata->ev_code_tap[ADXL_Y_AXIS]); in adxl34x_probe()
767 input_set_capability(input_dev, EV_KEY, pdata->ev_code_tap[ADXL_Z_AXIS]); in adxl34x_probe()
769 if (pdata->ev_code_ff) { in adxl34x_probe()
770 ac->int_mask = FREE_FALL; in adxl34x_probe()
771 input_set_capability(input_dev, EV_KEY, pdata->ev_code_ff); in adxl34x_probe()
774 if (pdata->ev_code_act_inactivity) in adxl34x_probe()
776 pdata->ev_code_act_inactivity); in adxl34x_probe()
778 ac->int_mask |= ACTIVITY | INACTIVITY; in adxl34x_probe()
780 if (pdata->watermark) { in adxl34x_probe()
781 ac->int_mask |= WATERMARK; in adxl34x_probe()
782 if (FIFO_MODE(pdata->fifo_mode) == FIFO_BYPASS) in adxl34x_probe()
783 ac->pdata.fifo_mode |= FIFO_STREAM; in adxl34x_probe()
785 ac->int_mask |= DATA_READY; in adxl34x_probe()
788 if (pdata->tap_axis_control & (TAP_X_EN | TAP_Y_EN | TAP_Z_EN)) in adxl34x_probe()
789 ac->int_mask |= SINGLE_TAP | DOUBLE_TAP; in adxl34x_probe()
791 if (FIFO_MODE(pdata->fifo_mode) == FIFO_BYPASS) in adxl34x_probe()
792 ac->fifo_delay = false; in adxl34x_probe()
796 error = devm_request_threaded_irq(dev, ac->irq, NULL, adxl34x_irq, in adxl34x_probe()
799 dev_err(dev, "irq %d busy?\n", ac->irq); in adxl34x_probe()
807 AC_WRITE(ac, OFSX, pdata->x_axis_offset); in adxl34x_probe()
808 ac->hwcal.x = pdata->x_axis_offset; in adxl34x_probe()
809 AC_WRITE(ac, OFSY, pdata->y_axis_offset); in adxl34x_probe()
810 ac->hwcal.y = pdata->y_axis_offset; in adxl34x_probe()
811 AC_WRITE(ac, OFSZ, pdata->z_axis_offset); in adxl34x_probe()
812 ac->hwcal.z = pdata->z_axis_offset; in adxl34x_probe()
813 AC_WRITE(ac, THRESH_TAP, pdata->tap_threshold); in adxl34x_probe()
814 AC_WRITE(ac, DUR, pdata->tap_duration); in adxl34x_probe()
815 AC_WRITE(ac, LATENT, pdata->tap_latency); in adxl34x_probe()
816 AC_WRITE(ac, WINDOW, pdata->tap_window); in adxl34x_probe()
817 AC_WRITE(ac, THRESH_ACT, pdata->activity_threshold); in adxl34x_probe()
818 AC_WRITE(ac, THRESH_INACT, pdata->inactivity_threshold); in adxl34x_probe()
819 AC_WRITE(ac, TIME_INACT, pdata->inactivity_time); in adxl34x_probe()
820 AC_WRITE(ac, THRESH_FF, pdata->free_fall_threshold); in adxl34x_probe()
821 AC_WRITE(ac, TIME_FF, pdata->free_fall_time); in adxl34x_probe()
822 AC_WRITE(ac, TAP_AXES, pdata->tap_axis_control); in adxl34x_probe()
823 AC_WRITE(ac, ACT_INACT_CTL, pdata->act_axis_control); in adxl34x_probe()
824 AC_WRITE(ac, BW_RATE, RATE(ac->pdata.data_rate) | in adxl34x_probe()
825 (pdata->low_power_mode ? LOW_POWER : 0)); in adxl34x_probe()
826 AC_WRITE(ac, DATA_FORMAT, pdata->data_range); in adxl34x_probe()
827 AC_WRITE(ac, FIFO_CTL, FIFO_MODE(pdata->fifo_mode) | in adxl34x_probe()
828 SAMPLES(pdata->watermark)); in adxl34x_probe()
830 if (pdata->use_int2) { in adxl34x_probe()
832 AC_WRITE(ac, INT_MAP, ac->int_mask | OVERRUN); in adxl34x_probe()
838 if (ac->model == 346 && ac->pdata.orientation_enable) { in adxl34x_probe()
840 ORIENT_DEADZONE(ac->pdata.deadzone_angle) | in adxl34x_probe()
841 ORIENT_DIVISOR(ac->pdata.divisor_length)); in adxl34x_probe()
843 ac->orient2d_saved = 1234; in adxl34x_probe()
844 ac->orient3d_saved = 1234; in adxl34x_probe()
846 if (pdata->orientation_enable & ADXL_EN_ORIENTATION_3D) in adxl34x_probe()
847 for (i = 0; i < ARRAY_SIZE(pdata->ev_codes_orient_3d); i++) in adxl34x_probe()
849 pdata->ev_codes_orient_3d[i]); in adxl34x_probe()
851 if (pdata->orientation_enable & ADXL_EN_ORIENTATION_2D) in adxl34x_probe()
852 for (i = 0; i < ARRAY_SIZE(pdata->ev_codes_orient_2d); i++) in adxl34x_probe()
854 pdata->ev_codes_orient_2d[i]); in adxl34x_probe()
856 ac->pdata.orientation_enable = 0; in adxl34x_probe()
859 AC_WRITE(ac, INT_ENABLE, ac->int_mask | OVERRUN); in adxl34x_probe()
861 ac->pdata.power_mode &= (PCTL_AUTO_SLEEP | PCTL_LINK); in adxl34x_probe()
870 MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer Driver");