Lines Matching +full:sync +full:- +full:2

1 // SPDX-License-Identifier: GPL-2.0
47 #define ADIS16475_FILT_CTRL_MASK GENMASK(2, 0)
53 #define ADIS16475_SYNC_MODE_MASK GENMASK(4, 2)
93 const struct adis16475_sync *sync; member
149 struct adis16475 *st = file->private_data; in adis16475_show_firmware_revision()
155 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIRM_REV, &rev); in adis16475_show_firmware_revision()
175 struct adis16475 *st = file->private_data; in adis16475_show_firmware_date()
181 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIRM_Y, &year); in adis16475_show_firmware_date()
185 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIRM_DM, &md); in adis16475_show_firmware_date()
189 len = snprintf(buf, sizeof(buf), "%.2x-%.2x-%.4x\n", md >> 8, md & 0xff, in adis16475_show_firmware_date()
208 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_SERIAL_NUM, &serial); in adis16475_show_serial_number()
225 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_PROD_ID, &prod_id); in adis16475_show_product_id()
242 ret = adis_read_reg_32(&st->adis, ADIS16475_REG_FLASH_CNT, in adis16475_show_flash_count()
280 u32 sample_rate = st->clk_freq; in adis16475_get_freq()
282 adis_dev_lock(&st->adis); in adis16475_get_freq()
284 if (st->sync_mode == ADIS16475_SYNC_SCALED) { in adis16475_get_freq()
287 ret = __adis_read_reg_16(&st->adis, ADIS16475_REG_UP_SCALE, &sync_scale); in adis16475_get_freq()
291 sample_rate = st->clk_freq * sync_scale; in adis16475_get_freq()
294 ret = __adis_read_reg_16(&st->adis, ADIS16475_REG_DEC_RATE, &dec); in adis16475_get_freq()
298 adis_dev_unlock(&st->adis); in adis16475_get_freq()
304 adis_dev_unlock(&st->adis); in adis16475_get_freq()
312 u32 sample_rate = st->clk_freq; in adis16475_set_freq()
315 return -EINVAL; in adis16475_set_freq()
317 adis_dev_lock(&st->adis); in adis16475_set_freq()
319 * When using sync scaled mode, the input clock needs to be scaled so that we have in adis16475_set_freq()
326 * 2. get the highest multiple of the previous result lower than the adis max rate. in adis16475_set_freq()
330 if (st->sync_mode == ADIS16475_SYNC_SCALED) { in adis16475_set_freq()
331 unsigned long scaled_rate = lcm(st->clk_freq, freq); in adis16475_set_freq()
340 scaled_rate = 2100000 / st->clk_freq * st->clk_freq; in adis16475_set_freq()
355 scaled_rate = roundup(1900000, st->clk_freq); in adis16475_set_freq()
357 sync_scale = scaled_rate / st->clk_freq; in adis16475_set_freq()
358 ret = __adis_write_reg_16(&st->adis, ADIS16475_REG_UP_SCALE, sync_scale); in adis16475_set_freq()
368 dec--; in adis16475_set_freq()
370 if (dec > st->info->max_dec) in adis16475_set_freq()
371 dec = st->info->max_dec; in adis16475_set_freq()
373 ret = __adis_write_reg_16(&st->adis, ADIS16475_REG_DEC_RATE, dec); in adis16475_set_freq()
377 adis_dev_unlock(&st->adis); in adis16475_set_freq()
382 assign_bit(ADIS16475_LSB_DEC_MASK, &st->lsb_flag, dec); in adis16475_set_freq()
386 adis_dev_unlock(&st->adis); in adis16475_set_freq()
394 [2] = 164,
407 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FILT_CTRL, &filter_sz); in adis16475_get_filter()
421 while (--i) { in adis16475_set_filter()
426 ret = adis_write_reg_16(&st->adis, ADIS16475_REG_FILT_CTRL, in adis16475_set_filter()
435 assign_bit(ADIS16475_LSB_FIR_MASK, &st->lsb_flag, i); in adis16475_set_filter()
461 switch (chan->type) { in adis16475_read_raw()
463 *val = st->info->gyro_max_val; in adis16475_read_raw()
464 *val2 = st->info->gyro_max_scale; in adis16475_read_raw()
467 *val = st->info->accel_max_val; in adis16475_read_raw()
468 *val2 = st->info->accel_max_scale; in adis16475_read_raw()
471 *val = st->info->temp_scale; in adis16475_read_raw()
474 *val = st->info->deltang_max_val; in adis16475_read_raw()
478 *val = st->info->deltvel_max_val; in adis16475_read_raw()
482 return -EINVAL; in adis16475_read_raw()
485 ret = adis_read_reg_32(&st->adis, in adis16475_read_raw()
486 adis16475_calib_regs[chan->scan_index], in adis16475_read_raw()
507 return -EINVAL; in adis16475_read_raw()
525 return adis_write_reg_32(&st->adis, in adis16475_write_raw()
526 adis16475_calib_regs[chan->scan_index], in adis16475_write_raw()
529 return -EINVAL; in adis16475_write_raw()
609 ADIS16475_REG_ ## _mod ## _DELTANG_L, -1, 32, 32)
613 ADIS16475_REG_ ## _mod ## _DELTVEL_L, -1, 32, 32)
699 .self_test_mask = BIT(2), \
753 .sync = adis16475_sync_mode,
758 .name = "adis16475-1",
770 .sync = adis16475_sync_mode,
775 .name = "adis16475-2",
787 .sync = adis16475_sync_mode,
792 .name = "adis16475-3",
804 .sync = adis16475_sync_mode,
809 .name = "adis16477-1",
821 .sync = adis16475_sync_mode,
827 .name = "adis16477-2",
839 .sync = adis16475_sync_mode,
845 .name = "adis16477-3",
857 .sync = adis16475_sync_mode,
863 .name = "adis16465-1",
875 .sync = adis16475_sync_mode,
880 .name = "adis16465-2",
892 .sync = adis16475_sync_mode,
897 .name = "adis16465-3",
909 .sync = adis16475_sync_mode,
914 .name = "adis16467-1",
926 .sync = adis16475_sync_mode,
931 .name = "adis16467-2",
943 .sync = adis16475_sync_mode,
948 .name = "adis16467-3",
960 .sync = adis16475_sync_mode,
977 .sync = adis16475_sync_mode,
978 /* pulse sync not supported */
979 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
984 .name = "adis16505-1",
996 .sync = adis16475_sync_mode,
997 /* pulse sync not supported */
998 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
1003 .name = "adis16505-2",
1015 .sync = adis16475_sync_mode,
1016 /* pulse sync not supported */
1017 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
1022 .name = "adis16505-3",
1034 .sync = adis16475_sync_mode,
1035 /* pulse sync not supported */
1036 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
1041 .name = "adis16507-1",
1053 .sync = adis16475_sync_mode,
1054 /* pulse sync not supported */
1055 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
1060 .name = "adis16507-2",
1072 .sync = adis16475_sync_mode,
1073 /* pulse sync not supported */
1074 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
1079 .name = "adis16507-3",
1091 .sync = adis16475_sync_mode,
1092 /* pulse sync not supported */
1093 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
1106 if (st->info->flags & ADIS16475_HAS_BURST_DELTA_DATA) { in adis16475_update_scan_mode()
1109 return -EINVAL; in adis16475_update_scan_mode()
1115 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_update_scan_mode()
1139 for (i = 0; i < sz - 2; i++) in adis16475_validate_crc()
1140 crc -= buffer[i]; in adis16475_validate_crc()
1148 struct adis *adis = &st->adis; in adis16475_burst32_check()
1150 if (!(st->info->flags & ADIS16475_HAS_BURST32)) in adis16475_burst32_check()
1153 if (st->lsb_flag && !st->burst32) { in adis16475_burst32_check()
1156 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_burst32_check()
1161 st->burst32 = true; in adis16475_burst32_check()
1164 * In 32-bit mode we need extra 2 bytes for all gyro in adis16475_burst32_check()
1167 adis->burst_extra_len = 6 * sizeof(u16); in adis16475_burst32_check()
1168 adis->xfer[1].len += 6 * sizeof(u16); in adis16475_burst32_check()
1169 dev_dbg(&adis->spi->dev, "Enable burst32 mode, xfer:%d", in adis16475_burst32_check()
1170 adis->xfer[1].len); in adis16475_burst32_check()
1172 } else if (!st->lsb_flag && st->burst32) { in adis16475_burst32_check()
1175 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_burst32_check()
1180 st->burst32 = false; in adis16475_burst32_check()
1183 adis->burst_extra_len = 0; in adis16475_burst32_check()
1184 adis->xfer[1].len -= 6 * sizeof(u16); in adis16475_burst32_check()
1185 dev_dbg(&adis->spi->dev, "Disable burst32 mode, xfer:%d\n", in adis16475_burst32_check()
1186 adis->xfer[1].len); in adis16475_burst32_check()
1193 struct iio_dev *indio_dev = pf->indio_dev; in adis16475_trigger_handler()
1195 struct adis *adis = &st->adis; in adis16475_trigger_handler()
1201 const u8 offset = st->burst32 ? 13 : 7; in adis16475_trigger_handler()
1203 ret = spi_sync(adis->spi, &adis->msg); in adis16475_trigger_handler()
1207 buffer = adis->buffer; in adis16475_trigger_handler()
1209 crc = be16_to_cpu(buffer[offset + 2]); in adis16475_trigger_handler()
1210 valid = adis16475_validate_crc(adis->buffer, crc, st->burst32); in adis16475_trigger_handler()
1212 dev_err(&adis->spi->dev, "Invalid crc\n"); in adis16475_trigger_handler()
1216 for_each_set_bit(bit, indio_dev->active_scan_mask, in adis16475_trigger_handler()
1217 indio_dev->masklength) { in adis16475_trigger_handler()
1224 st->data[i++] = buffer[offset]; in adis16475_trigger_handler()
1226 * The temperature channel has 16-bit storage size. in adis16475_trigger_handler()
1229 * 32-bit storage size channels enabled which have a in adis16475_trigger_handler()
1233 if (*indio_dev->active_scan_mask & GENMASK(ADIS16475_SCAN_DELTVEL_Z, ADIS16475_SCAN_DELTANG_X)) in adis16475_trigger_handler()
1234 st->data[i++] = 0; in adis16475_trigger_handler()
1241 * The first 2 bytes on the received data are the in adis16475_trigger_handler()
1244 if (st->burst32) { in adis16475_trigger_handler()
1246 st->data[i++] = buffer[(bit - buff_offset) * 2 + 2]; in adis16475_trigger_handler()
1248 st->data[i++] = buffer[(bit - buff_offset) * 2 + 1]; in adis16475_trigger_handler()
1250 st->data[i++] = buffer[(bit - buff_offset) + 1]; in adis16475_trigger_handler()
1257 if (st->lsb_flag && !(st->info->flags & ADIS16475_HAS_BURST32)) { in adis16475_trigger_handler()
1263 st->data[i++] = cpu_to_be16(val); in adis16475_trigger_handler()
1266 st->data[i++] = 0; in adis16475_trigger_handler()
1273 iio_push_to_buffers_with_timestamp(indio_dev, st->data, pf->timestamp); in adis16475_trigger_handler()
1281 iio_trigger_notify_done(indio_dev->trig); in adis16475_trigger_handler()
1289 struct device *dev = &st->adis.spi->dev; in adis16475_config_sync_mode()
1290 const struct adis16475_sync *sync; in adis16475_config_sync_mode() local
1294 st->clk_freq = st->info->int_clk * 1000; in adis16475_config_sync_mode()
1296 ret = device_property_read_u32(dev, "adi,sync-mode", &sync_mode); in adis16475_config_sync_mode()
1300 if (sync_mode >= st->info->num_sync) { in adis16475_config_sync_mode()
1301 dev_err(dev, "Invalid sync mode: %u for %s\n", sync_mode, in adis16475_config_sync_mode()
1302 st->info->name); in adis16475_config_sync_mode()
1303 return -EINVAL; in adis16475_config_sync_mode()
1306 sync = &st->info->sync[sync_mode]; in adis16475_config_sync_mode()
1307 st->sync_mode = sync->sync_mode; in adis16475_config_sync_mode()
1310 if (sync->sync_mode != ADIS16475_SYNC_OUTPUT) { in adis16475_config_sync_mode()
1316 st->clk_freq = clk_get_rate(clk); in adis16475_config_sync_mode()
1317 if (st->clk_freq < sync->min_rate || in adis16475_config_sync_mode()
1318 st->clk_freq > sync->max_rate) { in adis16475_config_sync_mode()
1321 st->clk_freq, sync->min_rate, sync->max_rate); in adis16475_config_sync_mode()
1322 return -EINVAL; in adis16475_config_sync_mode()
1325 if (sync->sync_mode == ADIS16475_SYNC_SCALED) { in adis16475_config_sync_mode()
1329 * In sync scaled mode, the IMU sample rate is the clk_freq * sync_scale. in adis16475_config_sync_mode()
1332 * 1900-2100 sps... in adis16475_config_sync_mode()
1334 up_scale = 2100 / st->clk_freq; in adis16475_config_sync_mode()
1336 ret = __adis_write_reg_16(&st->adis, in adis16475_config_sync_mode()
1343 st->clk_freq *= 1000; in adis16475_config_sync_mode()
1353 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_config_sync_mode()
1354 ADIS16475_SYNC_MODE_MASK, sync->sync_mode); in adis16475_config_sync_mode()
1370 struct spi_device *spi = st->adis.spi; in adis16475_config_irq_pin()
1372 desc = irq_get_irq_data(spi->irq); in adis16475_config_irq_pin()
1374 dev_err(&spi->dev, "Could not find IRQ %d\n", spi->irq); in adis16475_config_irq_pin()
1375 return -EINVAL; in adis16475_config_irq_pin()
1384 st->adis.irq_flag = IRQF_TRIGGER_RISING; in adis16475_config_irq_pin()
1387 st->adis.irq_flag = IRQF_TRIGGER_FALLING; in adis16475_config_irq_pin()
1389 dev_err(&spi->dev, "Invalid interrupt type 0x%x specified\n", in adis16475_config_irq_pin()
1391 return -EINVAL; in adis16475_config_irq_pin()
1395 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_config_irq_pin()
1416 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in adis16475_probe()
1418 return -ENOMEM; in adis16475_probe()
1422 st->info = spi_get_device_match_data(spi); in adis16475_probe()
1423 if (!st->info) in adis16475_probe()
1424 return -EINVAL; in adis16475_probe()
1426 ret = adis_init(&st->adis, indio_dev, spi, &st->info->adis_data); in adis16475_probe()
1430 indio_dev->name = st->info->name; in adis16475_probe()
1431 indio_dev->channels = st->info->channels; in adis16475_probe()
1432 indio_dev->num_channels = st->info->num_channels; in adis16475_probe()
1433 indio_dev->info = &adis16475_info; in adis16475_probe()
1434 indio_dev->modes = INDIO_DIRECT_MODE; in adis16475_probe()
1436 ret = __adis_initial_startup(&st->adis); in adis16475_probe()
1448 ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev, in adis16475_probe()
1453 ret = devm_iio_device_register(&spi->dev, indio_dev); in adis16475_probe()
1465 { .compatible = "adi,adis16475-1",
1467 { .compatible = "adi,adis16475-2",
1469 { .compatible = "adi,adis16475-3",
1471 { .compatible = "adi,adis16477-1",
1473 { .compatible = "adi,adis16477-2",
1475 { .compatible = "adi,adis16477-3",
1477 { .compatible = "adi,adis16465-1",
1479 { .compatible = "adi,adis16465-2",
1481 { .compatible = "adi,adis16465-3",
1483 { .compatible = "adi,adis16467-1",
1485 { .compatible = "adi,adis16467-2",
1487 { .compatible = "adi,adis16467-3",
1491 { .compatible = "adi,adis16505-1",
1493 { .compatible = "adi,adis16505-2",
1495 { .compatible = "adi,adis16505-3",
1497 { .compatible = "adi,adis16507-1",
1499 { .compatible = "adi,adis16507-2",
1501 { .compatible = "adi,adis16507-3",
1509 { "adis16475-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16475_1] },
1510 { "adis16475-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16475_2] },
1511 { "adis16475-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16475_3] },
1512 { "adis16477-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16477_1] },
1513 { "adis16477-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16477_2] },
1514 { "adis16477-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16477_3] },
1515 { "adis16465-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16465_1] },
1516 { "adis16465-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16465_2] },
1517 { "adis16465-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16465_3] },
1518 { "adis16467-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16467_1] },
1519 { "adis16467-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16467_2] },
1520 { "adis16467-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16467_3] },
1522 { "adis16505-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16505_1] },
1523 { "adis16505-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16505_2] },
1524 { "adis16505-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16505_3] },
1525 { "adis16507-1", (kernel_ulong_t)&adis16475_chip_info[ADIS16507_1] },
1526 { "adis16507-2", (kernel_ulong_t)&adis16475_chip_info[ADIS16507_2] },
1527 { "adis16507-3", (kernel_ulong_t)&adis16475_chip_info[ADIS16507_3] },