Lines Matching +full:3 +full:- +full:axis
1 // SPDX-License-Identifier: GPL-2.0-only
4 * 3d 2g Linear Accelerometers,
5 * 3d Gyroscopes,
6 * 3d Magnetometers via SPI
38 #define ADIS16400_XGYRO_OUT 0x04 /* X-axis gyroscope output */
39 #define ADIS16400_YGYRO_OUT 0x06 /* Y-axis gyroscope output */
40 #define ADIS16400_ZGYRO_OUT 0x08 /* Z-axis gyroscope output */
41 #define ADIS16400_XACCL_OUT 0x0A /* X-axis accelerometer output */
42 #define ADIS16400_YACCL_OUT 0x0C /* Y-axis accelerometer output */
43 #define ADIS16400_ZACCL_OUT 0x0E /* Z-axis accelerometer output */
44 #define ADIS16400_XMAGN_OUT 0x10 /* X-axis magnetometer measurement */
45 #define ADIS16400_YMAGN_OUT 0x12 /* Y-axis magnetometer measurement */
46 #define ADIS16400_ZMAGN_OUT 0x14 /* Z-axis magnetometer measurement */
50 #define ADIS16350_XTEMP_OUT 0x10 /* X-axis gyroscope temperature measurement */
51 #define ADIS16350_YTEMP_OUT 0x12 /* Y-axis gyroscope temperature measurement */
52 #define ADIS16350_ZTEMP_OUT 0x14 /* Z-axis gyroscope temperature measurement */
54 #define ADIS16300_PITCH_OUT 0x12 /* X axis inclinometer output measurement */
55 #define ADIS16300_ROLL_OUT 0x14 /* Y axis inclinometer output measurement */
62 #define ADIS16400_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */
63 #define ADIS16400_YGYRO_OFF 0x1C /* Y-axis gyroscope bias offset factor */
64 #define ADIS16400_ZGYRO_OFF 0x1E /* Z-axis gyroscope bias offset factor */
65 #define ADIS16400_XACCL_OFF 0x20 /* X-axis acceleration bias offset factor */
66 #define ADIS16400_YACCL_OFF 0x22 /* Y-axis acceleration bias offset factor */
67 #define ADIS16400_ZACCL_OFF 0x24 /* Z-axis acceleration bias offset factor */
68 #define ADIS16400_XMAGN_HIF 0x26 /* X-axis magnetometer, hard-iron factor */
69 #define ADIS16400_YMAGN_HIF 0x28 /* Y-axis magnetometer, hard-iron factor */
70 #define ADIS16400_ZMAGN_HIF 0x2A /* Z-axis magnetometer, hard-iron factor */
71 #define ADIS16400_XMAGN_SIF 0x2C /* X-axis magnetometer, soft-iron factor */
72 #define ADIS16400_YMAGN_SIF 0x2E /* Y-axis magnetometer, soft-iron factor */
73 #define ADIS16400_ZMAGN_SIF 0x30 /* Z-axis magnetometer, soft-iron factor */
126 #define ADIS16400_DIAG_STAT_SPI_FAIL 3
134 #define ADIS16400_GLOB_CMD_FLASH_UPD (1<<3)
152 #define ADIS16400_HAS_SERIAL_NUMBER BIT(3)
172 * struct adis16400_state - device instance specific data
217 struct adis16400_state *st = file->private_data; in adis16400_show_serial_number()
223 ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID1, &lot1); in adis16400_show_serial_number()
227 ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID2, &lot2); in adis16400_show_serial_number()
231 ret = adis_read_reg_16(&st->adis, ADIS16334_SERIAL_NUMBER, in adis16400_show_serial_number()
236 len = snprintf(buf, sizeof(buf), "%.4x-%.4x-%.4x\n", lot1, lot2, in adis16400_show_serial_number()
255 ret = adis_read_reg_16(&st->adis, ADIS16400_PRODUCT_ID, &prod_id); in adis16400_show_product_id()
272 ret = adis_read_reg_16(&st->adis, ADIS16400_FLASH_CNT, &flash_count); in adis16400_show_flash_count()
288 if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER) in adis16400_debugfs_init()
291 if (st->variant->flags & ADIS16400_HAS_PROD_ID) in adis16400_debugfs_init()
327 ret = __adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); in adis16334_get_freq()
351 return __adis_write_reg_16(&st->adis, ADIS16400_SMPL_PRD, t); in adis16334_set_freq()
359 ret = __adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); in adis16400_get_freq()
381 t--; in adis16400_set_freq()
387 st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; in adis16400_set_freq()
389 st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; in adis16400_set_freq()
391 return __adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, val); in adis16400_set_freq()
398 [3] = 25,
411 for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 1; i--) { in __adis16400_set_filter()
416 ret = __adis_read_reg_16(&st->adis, ADIS16400_SENS_AVG, &val16); in __adis16400_set_filter()
420 ret = __adis_write_reg_16(&st->adis, ADIS16400_SENS_AVG, in __adis16400_set_filter()
431 ret = adis_write_reg_16(&st->adis, ADIS16400_SLP_CNT, in adis16400_stop_device()
434 dev_err(&indio_dev->dev, in adis16400_stop_device()
448 if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) in adis16400_initial_setup()
449 st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; in adis16400_initial_setup()
451 st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; in adis16400_initial_setup()
452 st->adis.spi->mode = SPI_MODE_3; in adis16400_initial_setup()
453 spi_setup(st->adis.spi); in adis16400_initial_setup()
455 ret = adis_initial_startup(&st->adis); in adis16400_initial_setup()
459 if (st->variant->flags & ADIS16400_HAS_PROD_ID) { in adis16400_initial_setup()
460 ret = adis_read_reg_16(&st->adis, in adis16400_initial_setup()
465 ret = sscanf(indio_dev->name, "adis%u\n", &device_id); in adis16400_initial_setup()
467 ret = -EINVAL; in adis16400_initial_setup()
472 dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.", in adis16400_initial_setup()
475 dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n", in adis16400_initial_setup()
476 indio_dev->name, prod_id, in adis16400_initial_setup()
477 st->adis.spi->chip_select, st->adis.spi->irq); in adis16400_initial_setup()
480 if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) { in adis16400_initial_setup()
481 ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &smp_prd); in adis16400_initial_setup()
486 st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; in adis16400_initial_setup()
487 spi_setup(st->adis.spi); in adis16400_initial_setup()
508 struct mutex *slock = &st->adis.state_lock; in adis16400_write_raw()
513 ret = adis_write_reg_16(&st->adis, in adis16400_write_raw()
514 adis16400_addresses[chan->scan_index], val); in adis16400_write_raw()
522 st->filt_int = val; in adis16400_write_raw()
524 sps = st->variant->get_freq(st); in adis16400_write_raw()
538 return -EINVAL; in adis16400_write_raw()
541 ret = st->variant->set_freq(st, sps); in adis16400_write_raw()
545 return -EINVAL; in adis16400_write_raw()
553 struct mutex *slock = &st->adis.state_lock; in adis16400_read_raw()
561 switch (chan->type) { in adis16400_read_raw()
564 *val2 = st->variant->gyro_scale_micro; in adis16400_read_raw()
568 if (chan->channel == 0) { in adis16400_read_raw()
578 *val2 = st->variant->accel_scale_micro; in adis16400_read_raw()
585 *val = st->variant->temp_scale_nano / 1000000; in adis16400_read_raw()
586 *val2 = (st->variant->temp_scale_nano % 1000000); in adis16400_read_raw()
594 return -EINVAL; in adis16400_read_raw()
597 ret = adis_read_reg_16(&st->adis, in adis16400_read_raw()
598 adis16400_addresses[chan->scan_index], &val16); in adis16400_read_raw()
606 *val = st->variant->temp_offset; in adis16400_read_raw()
611 ret = __adis_read_reg_16(&st->adis, in adis16400_read_raw()
618 ret = st->variant->get_freq(st); in adis16400_read_raw()
628 ret = st->variant->get_freq(st); in adis16400_read_raw()
636 return -EINVAL; in adis16400_read_raw()
644 struct iio_dev *indio_dev = pf->indio_dev; in adis16400_trigger_handler()
646 struct adis *adis = &st->adis; in adis16400_trigger_handler()
647 u32 old_speed_hz = st->adis.spi->max_speed_hz; in adis16400_trigger_handler()
651 if (!adis->buffer) in adis16400_trigger_handler()
652 return -ENOMEM; in adis16400_trigger_handler()
654 if (!(st->variant->flags & ADIS16400_NO_BURST) && in adis16400_trigger_handler()
655 st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) { in adis16400_trigger_handler()
656 st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST; in adis16400_trigger_handler()
657 spi_setup(st->adis.spi); in adis16400_trigger_handler()
660 ret = spi_sync(adis->spi, &adis->msg); in adis16400_trigger_handler()
662 dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret); in adis16400_trigger_handler()
664 if (!(st->variant->flags & ADIS16400_NO_BURST)) { in adis16400_trigger_handler()
665 st->adis.spi->max_speed_hz = old_speed_hz; in adis16400_trigger_handler()
666 spi_setup(st->adis.spi); in adis16400_trigger_handler()
669 if (st->variant->flags & ADIS16400_BURST_DIAG_STAT) in adis16400_trigger_handler()
670 buffer = adis->buffer + sizeof(u16); in adis16400_trigger_handler()
672 buffer = adis->buffer; in adis16400_trigger_handler()
675 pf->timestamp); in adis16400_trigger_handler()
677 iio_trigger_notify_done(indio_dev->trig); in adis16400_trigger_handler()
930 [ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure",
931 [ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure",
932 [ADIS16400_DIAG_STAT_XACCL_FAIL] = "X-axis accelerometer self-test failure",
933 [ADIS16400_DIAG_STAT_XGYRO_FAIL] = "X-axis gyroscope self-test failure",
934 [ADIS16400_DIAG_STAT_YGYRO_FAIL] = "Y-axis gyroscope self-test failure",
935 [ADIS16400_DIAG_STAT_ZGYRO_FAIL] = "Z-axis gyroscope self-test failure",
1155 const struct adis16400_chip_info *chip_info = st->variant; in adis16400_setup_chan_mask()
1158 for (i = 0; i < chip_info->num_channels; i++) { in adis16400_setup_chan_mask()
1159 const struct iio_chan_spec *ch = &chip_info->channels[i]; in adis16400_setup_chan_mask()
1161 if (ch->scan_index >= 0 && in adis16400_setup_chan_mask()
1162 ch->scan_index != ADIS16400_SCAN_TIMESTAMP) in adis16400_setup_chan_mask()
1163 st->avail_scan_mask[0] |= BIT(ch->scan_index); in adis16400_setup_chan_mask()
1179 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in adis16400_probe()
1181 return -ENOMEM; in adis16400_probe()
1188 st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data]; in adis16400_probe()
1189 indio_dev->name = spi_get_device_id(spi)->name; in adis16400_probe()
1190 indio_dev->channels = st->variant->channels; in adis16400_probe()
1191 indio_dev->num_channels = st->variant->num_channels; in adis16400_probe()
1192 indio_dev->info = &adis16400_info; in adis16400_probe()
1193 indio_dev->modes = INDIO_DIRECT_MODE; in adis16400_probe()
1195 if (!(st->variant->flags & ADIS16400_NO_BURST)) { in adis16400_probe()
1197 indio_dev->available_scan_masks = st->avail_scan_mask; in adis16400_probe()
1200 adis16400_data = &st->variant->adis_data; in adis16400_probe()
1202 ret = adis_init(&st->adis, indio_dev, spi, adis16400_data); in adis16400_probe()
1206 ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev, adis16400_trigger_handler); in adis16400_probe()
1215 ret = devm_add_action_or_reset(&spi->dev, adis16400_stop, indio_dev); in adis16400_probe()
1219 ret = devm_iio_device_register(&spi->dev, indio_dev); in adis16400_probe()