Lines Matching +full:diff +full:- +full:channels
1 // SPDX-License-Identifier: GPL-2.0-only
115 ADIS16480_REG((page) + 1, (x) - 60 + 8))
137 const struct iio_chan_spec *channels; member
192 struct adis16480 *adis16480 = file->private_data; in adis16480_show_firmware_revision()
198 ret = adis_read_reg_16(&adis16480->adis, ADIS16480_REG_FIRM_REV, &rev); in adis16480_show_firmware_revision()
217 struct adis16480 *adis16480 = file->private_data; in adis16480_show_firmware_date()
223 ret = adis_read_reg_16(&adis16480->adis, ADIS16480_REG_FIRM_Y, &year); in adis16480_show_firmware_date()
227 ret = adis_read_reg_16(&adis16480->adis, ADIS16480_REG_FIRM_DM, &md); in adis16480_show_firmware_date()
231 len = snprintf(buf, sizeof(buf), "%.2x-%.2x-%.4x\n", in adis16480_show_firmware_date()
250 ret = adis_read_reg_16(&adis16480->adis, ADIS16480_REG_SERIAL_NUM, in adis16480_show_serial_number()
268 ret = adis_read_reg_16(&adis16480->adis, ADIS16480_REG_PROD_ID, in adis16480_show_product_id()
286 ret = adis_read_reg_32(&adis16480->adis, ADIS16480_REG_FLASH_CNT, in adis16480_show_flash_count()
329 unsigned int t, sample_rate = st->clk_freq; in adis16480_set_freq()
333 return -EINVAL; in adis16480_set_freq()
337 return -EINVAL; in adis16480_set_freq()
339 adis_dev_lock(&st->adis); in adis16480_set_freq()
352 if (st->clk_mode == ADIS16480_CLK_PPS) { in adis16480_set_freq()
353 unsigned long scaled_rate = lcm(st->clk_freq, t); in adis16480_set_freq()
361 if (scaled_rate > st->chip_info->int_clk) in adis16480_set_freq()
362 scaled_rate = st->chip_info->int_clk / st->clk_freq * st->clk_freq; in adis16480_set_freq()
364 scaled_rate = st->chip_info->int_clk / scaled_rate * scaled_rate; in adis16480_set_freq()
377 scaled_rate = roundup(4000000, st->clk_freq); in adis16480_set_freq()
379 sync_scale = scaled_rate / st->clk_freq; in adis16480_set_freq()
380 ret = __adis_write_reg_16(&st->adis, ADIS16495_REG_SYNC_SCALE, sync_scale); in adis16480_set_freq()
389 t--; in adis16480_set_freq()
391 if (t > st->chip_info->max_dec_rate) in adis16480_set_freq()
392 t = st->chip_info->max_dec_rate; in adis16480_set_freq()
394 ret = __adis_write_reg_16(&st->adis, ADIS16480_REG_DEC_RATE, t); in adis16480_set_freq()
396 adis_dev_unlock(&st->adis); in adis16480_set_freq()
405 unsigned int freq, sample_rate = st->clk_freq; in adis16480_get_freq()
407 adis_dev_lock(&st->adis); in adis16480_get_freq()
409 if (st->clk_mode == ADIS16480_CLK_PPS) { in adis16480_get_freq()
412 ret = __adis_read_reg_16(&st->adis, ADIS16495_REG_SYNC_SCALE, &sync_scale); in adis16480_get_freq()
416 sample_rate = st->clk_freq * sync_scale; in adis16480_get_freq()
419 ret = __adis_read_reg_16(&st->adis, ADIS16480_REG_DEC_RATE, &t); in adis16480_get_freq()
423 adis_dev_unlock(&st->adis); in adis16480_get_freq()
432 adis_dev_unlock(&st->adis); in adis16480_get_freq()
475 unsigned int reg = adis16480_calibbias_regs[chan->scan_index]; in adis16480_set_calibbias()
478 switch (chan->type) { in adis16480_set_calibbias()
481 if (bias < -0x8000 || bias >= 0x8000) in adis16480_set_calibbias()
482 return -EINVAL; in adis16480_set_calibbias()
483 return adis_write_reg_16(&st->adis, reg, bias); in adis16480_set_calibbias()
486 return adis_write_reg_32(&st->adis, reg, bias); in adis16480_set_calibbias()
491 return -EINVAL; in adis16480_set_calibbias()
497 unsigned int reg = adis16480_calibbias_regs[chan->scan_index]; in adis16480_get_calibbias()
503 switch (chan->type) { in adis16480_get_calibbias()
506 ret = adis_read_reg_16(&st->adis, reg, &val16); in adis16480_get_calibbias()
512 ret = adis_read_reg_32(&st->adis, reg, &val32); in adis16480_get_calibbias()
517 ret = -EINVAL; in adis16480_get_calibbias()
529 unsigned int reg = adis16480_calibscale_regs[chan->scan_index]; in adis16480_set_calibscale()
532 if (scale < -0x8000 || scale >= 0x8000) in adis16480_set_calibscale()
533 return -EINVAL; in adis16480_set_calibscale()
535 return adis_write_reg_16(&st->adis, reg, scale); in adis16480_set_calibscale()
541 unsigned int reg = adis16480_calibscale_regs[chan->scan_index]; in adis16480_get_calibscale()
546 ret = adis_read_reg_16(&st->adis, reg, &val16); in adis16480_get_calibscale()
588 reg = ad16480_filter_data[chan->scan_index][0]; in adis16480_get_filter_freq()
589 offset = ad16480_filter_data[chan->scan_index][1]; in adis16480_get_filter_freq()
592 ret = adis_read_reg_16(&st->adis, reg, &val); in adis16480_get_filter_freq()
599 *freq = st->chip_info->filter_freqs[(val >> offset) & 0x3]; in adis16480_get_filter_freq()
609 unsigned int diff, best_diff; in adis16480_set_filter_freq() local
614 reg = ad16480_filter_data[chan->scan_index][0]; in adis16480_set_filter_freq()
615 offset = ad16480_filter_data[chan->scan_index][1]; in adis16480_set_filter_freq()
618 adis_dev_lock(&st->adis); in adis16480_set_filter_freq()
620 ret = __adis_read_reg_16(&st->adis, reg, &val); in adis16480_set_filter_freq()
628 best_diff = st->chip_info->filter_freqs[0]; in adis16480_set_filter_freq()
630 if (st->chip_info->filter_freqs[i] >= freq) { in adis16480_set_filter_freq()
631 diff = st->chip_info->filter_freqs[i] - freq; in adis16480_set_filter_freq()
632 if (diff < best_diff) { in adis16480_set_filter_freq()
633 best_diff = diff; in adis16480_set_filter_freq()
644 ret = __adis_write_reg_16(&st->adis, reg, val); in adis16480_set_filter_freq()
646 adis_dev_unlock(&st->adis); in adis16480_set_filter_freq()
661 switch (chan->type) { in adis16480_read_raw()
663 *val = st->chip_info->gyro_max_scale; in adis16480_read_raw()
664 *val2 = st->chip_info->gyro_max_val; in adis16480_read_raw()
667 *val = st->chip_info->accel_max_scale; in adis16480_read_raw()
668 *val2 = st->chip_info->accel_max_val; in adis16480_read_raw()
680 *val = st->chip_info->temp_scale / 1000; in adis16480_read_raw()
681 *val2 = (st->chip_info->temp_scale % 1000) * 1000; in adis16480_read_raw()
692 return -EINVAL; in adis16480_read_raw()
697 *val = DIV_ROUND_CLOSEST_ULL(temp, st->chip_info->temp_scale); in adis16480_read_raw()
708 return -EINVAL; in adis16480_read_raw()
726 return -EINVAL; in adis16480_write_raw()
859 [ADIS16480_DIAG_STAT_XGYRO_FAIL] = "X-axis gyroscope self-test failure",
860 [ADIS16480_DIAG_STAT_YGYRO_FAIL] = "Y-axis gyroscope self-test failure",
861 [ADIS16480_DIAG_STAT_ZGYRO_FAIL] = "Z-axis gyroscope self-test failure",
862 [ADIS16480_DIAG_STAT_XACCL_FAIL] = "X-axis accelerometer self-test failure",
863 [ADIS16480_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure",
864 [ADIS16480_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure",
865 [ADIS16480_DIAG_STAT_XMAGN_FAIL] = "X-axis magnetometer self-test failure",
866 [ADIS16480_DIAG_STAT_YMAGN_FAIL] = "Y-axis magnetometer self-test failure",
867 [ADIS16480_DIAG_STAT_ZMAGN_FAIL] = "Z-axis magnetometer self-test failure",
868 [ADIS16480_DIAG_STAT_BARO_FAIL] = "Barometer self-test failure",
928 .channels = adis16485_channels,
948 .channels = adis16480_channels,
962 .channels = adis16485_channels,
976 .channels = adis16480_channels,
990 .channels = adis16485_channels,
1004 .channels = adis16485_channels,
1020 .channels = adis16485_channels,
1036 .channels = adis16485_channels,
1052 .channels = adis16485_channels,
1068 .channels = adis16485_channels,
1084 .channels = adis16485_channels,
1119 struct iio_dev *indio_dev = pf->indio_dev; in adis16480_trigger_handler()
1121 struct adis *adis = &st->adis; in adis16480_trigger_handler()
1128 if (adis->current_page != 0) { in adis16480_trigger_handler()
1129 adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID); in adis16480_trigger_handler()
1130 adis->tx[1] = 0; in adis16480_trigger_handler()
1131 ret = spi_write(adis->spi, adis->tx, 2); in adis16480_trigger_handler()
1133 dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret); in adis16480_trigger_handler()
1138 adis->current_page = 0; in adis16480_trigger_handler()
1141 ret = spi_sync(adis->spi, &adis->msg); in adis16480_trigger_handler()
1143 dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret); in adis16480_trigger_handler()
1152 * 16-bit responses containing the BURST_ID depending on the sclk. If in adis16480_trigger_handler()
1159 buffer = adis->buffer; in adis16480_trigger_handler()
1171 dev_err(&adis->spi->dev, "Invalid burst data\n"); in adis16480_trigger_handler()
1178 dev_err(&adis->spi->dev, "Invalid crc\n"); in adis16480_trigger_handler()
1182 for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->masklength) { in adis16480_trigger_handler()
1190 st->data[i++] = buffer[offset + 1]; in adis16480_trigger_handler()
1194 st->data[i++] = buffer[2 * bit + offset + 3]; in adis16480_trigger_handler()
1195 st->data[i++] = buffer[2 * bit + offset + 2]; in adis16480_trigger_handler()
1200 iio_push_to_buffers_with_timestamp(indio_dev, st->data, pf->timestamp); in adis16480_trigger_handler()
1202 iio_trigger_notify_done(indio_dev->trig); in adis16480_trigger_handler()
1219 ret = adis_write_reg_16(&st->adis, ADIS16480_REG_SLP_CNT, BIT(9)); in adis16480_stop_device()
1221 dev_err(&indio_dev->dev, in adis16480_stop_device()
1251 desc = irq_get_irq_data(st->adis.spi->irq); in adis16480_config_irq_pin()
1253 dev_err(&st->adis.spi->dev, "Could not find IRQ %d\n", irq); in adis16480_config_irq_pin()
1254 return -EINVAL; in adis16480_config_irq_pin()
1261 * Get the interrupt from the devicetre by reading the interrupt-names in adis16480_config_irq_pin()
1290 dev_err(&st->adis.spi->dev, in adis16480_config_irq_pin()
1292 return -EINVAL; in adis16480_config_irq_pin()
1295 return adis_write_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, val); in adis16480_config_irq_pin()
1306 if (of_property_read_string(of_node, "adi,ext-clk-pin", &ext_clk_pin)) in adis16480_of_get_ext_clk_pin()
1315 dev_info(&st->adis.spi->dev, in adis16480_of_get_ext_clk_pin()
1329 ret = adis_read_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, &val); in adis16480_ext_clk_config()
1340 dev_warn(&st->adis.spi->dev, in adis16480_ext_clk_config()
1347 if (st->chip_info->has_pps_clk_mode) { in adis16480_ext_clk_config()
1348 mode |= ADIS16480_SYNC_MODE(st->clk_mode); in adis16480_ext_clk_config()
1355 ret = adis_write_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, val); in adis16480_ext_clk_config()
1359 return clk_prepare_enable(st->ext_clk); in adis16480_ext_clk_config()
1364 st->clk_mode = ADIS16480_CLK_INT; in adis16480_get_ext_clocks()
1365 st->ext_clk = devm_clk_get(&st->adis.spi->dev, "sync"); in adis16480_get_ext_clocks()
1366 if (!IS_ERR_OR_NULL(st->ext_clk)) { in adis16480_get_ext_clocks()
1367 st->clk_mode = ADIS16480_CLK_SYNC; in adis16480_get_ext_clocks()
1371 if (PTR_ERR(st->ext_clk) != -ENOENT) { in adis16480_get_ext_clocks()
1372 dev_err(&st->adis.spi->dev, "failed to get ext clk\n"); in adis16480_get_ext_clocks()
1373 return PTR_ERR(st->ext_clk); in adis16480_get_ext_clocks()
1376 if (st->chip_info->has_pps_clk_mode) { in adis16480_get_ext_clocks()
1377 st->ext_clk = devm_clk_get(&st->adis.spi->dev, "pps"); in adis16480_get_ext_clocks()
1378 if (!IS_ERR_OR_NULL(st->ext_clk)) { in adis16480_get_ext_clocks()
1379 st->clk_mode = ADIS16480_CLK_PPS; in adis16480_get_ext_clocks()
1383 if (PTR_ERR(st->ext_clk) != -ENOENT) { in adis16480_get_ext_clocks()
1384 dev_err(&st->adis.spi->dev, "failed to get ext clk\n"); in adis16480_get_ext_clocks()
1385 return PTR_ERR(st->ext_clk); in adis16480_get_ext_clocks()
1410 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in adis16480_probe()
1412 return -ENOMEM; in adis16480_probe()
1416 st->chip_info = &adis16480_chip_info[id->driver_data]; in adis16480_probe()
1417 indio_dev->name = spi_get_device_id(spi)->name; in adis16480_probe()
1418 indio_dev->channels = st->chip_info->channels; in adis16480_probe()
1419 indio_dev->num_channels = st->chip_info->num_channels; in adis16480_probe()
1420 indio_dev->info = &adis16480_info; in adis16480_probe()
1421 indio_dev->modes = INDIO_DIRECT_MODE; in adis16480_probe()
1423 adis16480_data = &st->chip_info->adis_data; in adis16480_probe()
1425 ret = adis_init(&st->adis, indio_dev, spi, adis16480_data); in adis16480_probe()
1429 ret = __adis_initial_startup(&st->adis); in adis16480_probe()
1433 if (st->chip_info->has_sleep_cnt) { in adis16480_probe()
1434 ret = devm_add_action_or_reset(&spi->dev, adis16480_stop, in adis16480_probe()
1440 ret = adis16480_config_irq_pin(spi->dev.of_node, st); in adis16480_probe()
1448 if (!IS_ERR_OR_NULL(st->ext_clk)) { in adis16480_probe()
1449 ret = adis16480_ext_clk_config(st, spi->dev.of_node, true); in adis16480_probe()
1453 ret = devm_add_action_or_reset(&spi->dev, adis16480_clk_disable, st->ext_clk); in adis16480_probe()
1457 st->clk_freq = clk_get_rate(st->ext_clk); in adis16480_probe()
1458 st->clk_freq *= 1000; /* micro */ in adis16480_probe()
1459 if (st->clk_mode == ADIS16480_CLK_PPS) { in adis16480_probe()
1468 sync_scale = st->chip_info->int_clk / st->clk_freq; in adis16480_probe()
1469 ret = __adis_write_reg_16(&st->adis, ADIS16495_REG_SYNC_SCALE, sync_scale); in adis16480_probe()
1474 st->clk_freq = st->chip_info->int_clk; in adis16480_probe()
1477 ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev, in adis16480_probe()
1482 ret = devm_iio_device_register(&spi->dev, indio_dev); in adis16480_probe()
1497 { "adis16495-1", ADIS16495_1 },
1498 { "adis16495-2", ADIS16495_2 },
1499 { "adis16495-3", ADIS16495_3 },
1500 { "adis16497-1", ADIS16497_1 },
1501 { "adis16497-2", ADIS16497_2 },
1502 { "adis16497-3", ADIS16497_3 },
1513 { .compatible = "adi,adis16495-1" },
1514 { .compatible = "adi,adis16495-2" },
1515 { .compatible = "adi,adis16495-3" },
1516 { .compatible = "adi,adis16497-1" },
1517 { .compatible = "adi,adis16497-2" },
1518 { .compatible = "adi,adis16497-3" },
1533 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");