Lines Matching +full:sync +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0
67 #define ADIS16475_LSB_FIR_MASK BIT(1)
70 ADIS16475_SYNC_DIRECT = 1,
84 const struct adis16475_sync *sync; member
132 struct adis16475 *st = file->private_data; in adis16475_show_firmware_revision()
138 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIRM_REV, &rev); in adis16475_show_firmware_revision()
158 struct adis16475 *st = file->private_data; in adis16475_show_firmware_date()
164 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIRM_Y, &year); in adis16475_show_firmware_date()
168 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FIRM_DM, &md); in adis16475_show_firmware_date()
172 len = snprintf(buf, sizeof(buf), "%.2x-%.2x-%.4x\n", md >> 8, md & 0xff, in adis16475_show_firmware_date()
191 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_SERIAL_NUM, &serial); in adis16475_show_serial_number()
208 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_PROD_ID, &prod_id); in adis16475_show_product_id()
225 ret = adis_read_reg_32(&st->adis, ADIS16475_REG_FLASH_CNT, in adis16475_show_flash_count()
263 u32 sample_rate = st->clk_freq; in adis16475_get_freq()
265 adis_dev_lock(&st->adis); in adis16475_get_freq()
267 if (st->sync_mode == ADIS16475_SYNC_SCALED) { in adis16475_get_freq()
270 ret = __adis_read_reg_16(&st->adis, ADIS16475_REG_UP_SCALE, &sync_scale); in adis16475_get_freq()
274 sample_rate = st->clk_freq * sync_scale; in adis16475_get_freq()
277 ret = __adis_read_reg_16(&st->adis, ADIS16475_REG_DEC_RATE, &dec); in adis16475_get_freq()
281 adis_dev_unlock(&st->adis); in adis16475_get_freq()
283 *freq = DIV_ROUND_CLOSEST(sample_rate, dec + 1); in adis16475_get_freq()
287 adis_dev_unlock(&st->adis); in adis16475_get_freq()
295 u32 sample_rate = st->clk_freq; in adis16475_set_freq()
298 return -EINVAL; in adis16475_set_freq()
300 adis_dev_lock(&st->adis); in adis16475_set_freq()
302 * When using sync scaled mode, the input clock needs to be scaled so that we have in adis16475_set_freq()
308 * 1. lcm of the input clock and the desired output rate. in adis16475_set_freq()
313 if (st->sync_mode == ADIS16475_SYNC_SCALED) { in adis16475_set_freq()
314 unsigned long scaled_rate = lcm(st->clk_freq, freq); in adis16475_set_freq()
323 scaled_rate = 2100000 / st->clk_freq * st->clk_freq; in adis16475_set_freq()
338 scaled_rate = roundup(1900000, st->clk_freq); in adis16475_set_freq()
340 sync_scale = scaled_rate / st->clk_freq; in adis16475_set_freq()
341 ret = __adis_write_reg_16(&st->adis, ADIS16475_REG_UP_SCALE, sync_scale); in adis16475_set_freq()
351 dec--; in adis16475_set_freq()
353 if (dec > st->info->max_dec) in adis16475_set_freq()
354 dec = st->info->max_dec; in adis16475_set_freq()
356 ret = __adis_write_reg_16(&st->adis, ADIS16475_REG_DEC_RATE, dec); in adis16475_set_freq()
360 adis_dev_unlock(&st->adis); in adis16475_set_freq()
365 assign_bit(ADIS16475_LSB_DEC_MASK, &st->lsb_flag, dec); in adis16475_set_freq()
369 adis_dev_unlock(&st->adis); in adis16475_set_freq()
376 [1] = 360,
390 ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FILT_CTRL, &filter_sz); in adis16475_get_filter()
404 while (--i) { in adis16475_set_filter()
409 ret = adis_write_reg_16(&st->adis, ADIS16475_REG_FILT_CTRL, in adis16475_set_filter()
418 assign_bit(ADIS16475_LSB_FIR_MASK, &st->lsb_flag, i); in adis16475_set_filter()
444 switch (chan->type) { in adis16475_read_raw()
446 *val = st->info->gyro_max_val; in adis16475_read_raw()
447 *val2 = st->info->gyro_max_scale; in adis16475_read_raw()
450 *val = st->info->accel_max_val; in adis16475_read_raw()
451 *val2 = st->info->accel_max_scale; in adis16475_read_raw()
454 *val = st->info->temp_scale; in adis16475_read_raw()
457 return -EINVAL; in adis16475_read_raw()
460 ret = adis_read_reg_32(&st->adis, in adis16475_read_raw()
461 adis16475_calib_regs[chan->scan_index], in adis16475_read_raw()
482 return -EINVAL; in adis16475_read_raw()
500 return adis_write_reg_32(&st->adis, in adis16475_write_raw()
501 adis16475_calib_regs[chan->scan_index], in adis16475_write_raw()
504 return -EINVAL; in adis16475_write_raw()
511 .modified = 1, \
540 .indexed = 1, \
591 ADIS16475_DIAG_STAT_DATA_PATH = 1,
641 { ADIS16475_SYNC_SCALED, 1, 128 },
662 .gyro_max_val = 1,
664 .accel_max_val = 1,
669 .sync = adis16475_sync_mode,
674 .name = "adis16475-1",
677 .gyro_max_val = 1,
679 .accel_max_val = 1,
684 .sync = adis16475_sync_mode,
689 .name = "adis16475-2",
692 .gyro_max_val = 1,
694 .accel_max_val = 1,
699 .sync = adis16475_sync_mode,
704 .name = "adis16475-3",
707 .gyro_max_val = 1,
709 .accel_max_val = 1,
714 .sync = adis16475_sync_mode,
719 .name = "adis16477-1",
722 .gyro_max_val = 1,
724 .accel_max_val = 1,
729 .sync = adis16475_sync_mode,
734 .name = "adis16477-2",
737 .gyro_max_val = 1,
739 .accel_max_val = 1,
744 .sync = adis16475_sync_mode,
749 .name = "adis16477-3",
752 .gyro_max_val = 1,
754 .accel_max_val = 1,
759 .sync = adis16475_sync_mode,
764 .name = "adis16465-1",
767 .gyro_max_val = 1,
769 .accel_max_val = 1,
774 .sync = adis16475_sync_mode,
779 .name = "adis16465-2",
782 .gyro_max_val = 1,
784 .accel_max_val = 1,
789 .sync = adis16475_sync_mode,
794 .name = "adis16465-3",
797 .gyro_max_val = 1,
799 .accel_max_val = 1,
804 .sync = adis16475_sync_mode,
809 .name = "adis16467-1",
812 .gyro_max_val = 1,
814 .accel_max_val = 1,
819 .sync = adis16475_sync_mode,
824 .name = "adis16467-2",
827 .gyro_max_val = 1,
829 .accel_max_val = 1,
834 .sync = adis16475_sync_mode,
839 .name = "adis16467-3",
842 .gyro_max_val = 1,
844 .accel_max_val = 1,
849 .sync = adis16475_sync_mode,
857 .gyro_max_val = 1,
864 .sync = adis16475_sync_mode,
865 /* pulse sync not supported */
866 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
871 .name = "adis16505-1",
874 .gyro_max_val = 1,
881 .sync = adis16475_sync_mode,
882 /* pulse sync not supported */
883 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
888 .name = "adis16505-2",
891 .gyro_max_val = 1,
898 .sync = adis16475_sync_mode,
899 /* pulse sync not supported */
900 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
905 .name = "adis16505-3",
908 .gyro_max_val = 1,
915 .sync = adis16475_sync_mode,
916 /* pulse sync not supported */
917 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
922 .name = "adis16507-1",
925 .gyro_max_val = 1,
932 .sync = adis16475_sync_mode,
933 /* pulse sync not supported */
934 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
939 .name = "adis16507-2",
942 .gyro_max_val = 1,
949 .sync = adis16475_sync_mode,
950 /* pulse sync not supported */
951 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
956 .name = "adis16507-3",
959 .gyro_max_val = 1,
966 .sync = adis16475_sync_mode,
967 /* pulse sync not supported */
968 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
989 for (i = 0; i < sz - 2; i++) in adis16475_validate_crc()
990 crc -= buffer[i]; in adis16475_validate_crc()
998 struct adis *adis = &st->adis; in adis16475_burst32_check()
1000 if (!st->info->has_burst32) in adis16475_burst32_check()
1003 if (st->lsb_flag && !st->burst32) { in adis16475_burst32_check()
1004 const u16 en = ADIS16500_BURST32(1); in adis16475_burst32_check()
1006 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_burst32_check()
1011 st->burst32 = true; in adis16475_burst32_check()
1014 * In 32-bit mode we need extra 2 bytes for all gyro in adis16475_burst32_check()
1017 adis->burst_extra_len = 6 * sizeof(u16); in adis16475_burst32_check()
1018 adis->xfer[1].len += 6 * sizeof(u16); in adis16475_burst32_check()
1019 dev_dbg(&adis->spi->dev, "Enable burst32 mode, xfer:%d", in adis16475_burst32_check()
1020 adis->xfer[1].len); in adis16475_burst32_check()
1022 } else if (!st->lsb_flag && st->burst32) { in adis16475_burst32_check()
1025 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_burst32_check()
1030 st->burst32 = false; in adis16475_burst32_check()
1033 adis->burst_extra_len = 0; in adis16475_burst32_check()
1034 adis->xfer[1].len -= 6 * sizeof(u16); in adis16475_burst32_check()
1035 dev_dbg(&adis->spi->dev, "Disable burst32 mode, xfer:%d\n", in adis16475_burst32_check()
1036 adis->xfer[1].len); in adis16475_burst32_check()
1043 struct iio_dev *indio_dev = pf->indio_dev; in adis16475_trigger_handler()
1045 struct adis *adis = &st->adis; in adis16475_trigger_handler()
1051 const u8 offset = st->burst32 ? 13 : 7; in adis16475_trigger_handler()
1053 ret = spi_sync(adis->spi, &adis->msg); in adis16475_trigger_handler()
1057 buffer = adis->buffer; in adis16475_trigger_handler()
1060 valid = adis16475_validate_crc(adis->buffer, crc, st->burst32); in adis16475_trigger_handler()
1062 dev_err(&adis->spi->dev, "Invalid crc\n"); in adis16475_trigger_handler()
1066 for_each_set_bit(bit, indio_dev->active_scan_mask, in adis16475_trigger_handler()
1067 indio_dev->masklength) { in adis16475_trigger_handler()
1074 st->data[i++] = buffer[offset]; in adis16475_trigger_handler()
1079 * DIAG_STAT reg, hence the +1 offset here... in adis16475_trigger_handler()
1081 if (st->burst32) { in adis16475_trigger_handler()
1083 st->data[i++] = buffer[bit * 2 + 2]; in adis16475_trigger_handler()
1085 st->data[i++] = buffer[bit * 2 + 1]; in adis16475_trigger_handler()
1087 st->data[i++] = buffer[bit + 1]; in adis16475_trigger_handler()
1094 if (st->lsb_flag && !st->info->has_burst32) { in adis16475_trigger_handler()
1100 st->data[i++] = cpu_to_be16(val); in adis16475_trigger_handler()
1103 st->data[i++] = 0; in adis16475_trigger_handler()
1110 iio_push_to_buffers_with_timestamp(indio_dev, st->data, pf->timestamp); in adis16475_trigger_handler()
1118 iio_trigger_notify_done(indio_dev->trig); in adis16475_trigger_handler()
1126 struct device *dev = &st->adis.spi->dev; in adis16475_config_sync_mode()
1127 const struct adis16475_sync *sync; in adis16475_config_sync_mode() local
1131 st->clk_freq = st->info->int_clk * 1000; in adis16475_config_sync_mode()
1133 ret = device_property_read_u32(dev, "adi,sync-mode", &sync_mode); in adis16475_config_sync_mode()
1137 if (sync_mode >= st->info->num_sync) { in adis16475_config_sync_mode()
1138 dev_err(dev, "Invalid sync mode: %u for %s\n", sync_mode, in adis16475_config_sync_mode()
1139 st->info->name); in adis16475_config_sync_mode()
1140 return -EINVAL; in adis16475_config_sync_mode()
1143 sync = &st->info->sync[sync_mode]; in adis16475_config_sync_mode()
1144 st->sync_mode = sync->sync_mode; in adis16475_config_sync_mode()
1147 if (sync->sync_mode != ADIS16475_SYNC_OUTPUT) { in adis16475_config_sync_mode()
1153 st->clk_freq = clk_get_rate(clk); in adis16475_config_sync_mode()
1154 if (st->clk_freq < sync->min_rate || in adis16475_config_sync_mode()
1155 st->clk_freq > sync->max_rate) { in adis16475_config_sync_mode()
1158 st->clk_freq, sync->min_rate, sync->max_rate); in adis16475_config_sync_mode()
1159 return -EINVAL; in adis16475_config_sync_mode()
1162 if (sync->sync_mode == ADIS16475_SYNC_SCALED) { in adis16475_config_sync_mode()
1166 * In sync scaled mode, the IMU sample rate is the clk_freq * sync_scale. in adis16475_config_sync_mode()
1169 * 1900-2100 sps... in adis16475_config_sync_mode()
1171 up_scale = 2100 / st->clk_freq; in adis16475_config_sync_mode()
1173 ret = __adis_write_reg_16(&st->adis, in adis16475_config_sync_mode()
1180 st->clk_freq *= 1000; in adis16475_config_sync_mode()
1190 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_config_sync_mode()
1191 ADIS16475_SYNC_MODE_MASK, sync->sync_mode); in adis16475_config_sync_mode()
1207 struct spi_device *spi = st->adis.spi; in adis16475_config_irq_pin()
1209 desc = irq_get_irq_data(spi->irq); in adis16475_config_irq_pin()
1211 dev_err(&spi->dev, "Could not find IRQ %d\n", spi->irq); in adis16475_config_irq_pin()
1212 return -EINVAL; in adis16475_config_irq_pin()
1220 polarity = 1; in adis16475_config_irq_pin()
1221 st->adis.irq_flag = IRQF_TRIGGER_RISING; in adis16475_config_irq_pin()
1224 st->adis.irq_flag = IRQF_TRIGGER_FALLING; in adis16475_config_irq_pin()
1226 dev_err(&spi->dev, "Invalid interrupt type 0x%x specified\n", in adis16475_config_irq_pin()
1228 return -EINVAL; in adis16475_config_irq_pin()
1232 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_config_irq_pin()
1249 { .compatible = "adi,adis16475-1",
1251 { .compatible = "adi,adis16475-2",
1253 { .compatible = "adi,adis16475-3",
1255 { .compatible = "adi,adis16477-1",
1257 { .compatible = "adi,adis16477-2",
1259 { .compatible = "adi,adis16477-3",
1261 { .compatible = "adi,adis16465-1",
1263 { .compatible = "adi,adis16465-2",
1265 { .compatible = "adi,adis16465-3",
1267 { .compatible = "adi,adis16467-1",
1269 { .compatible = "adi,adis16467-2",
1271 { .compatible = "adi,adis16467-3",
1275 { .compatible = "adi,adis16505-1",
1277 { .compatible = "adi,adis16505-2",
1279 { .compatible = "adi,adis16505-3",
1281 { .compatible = "adi,adis16507-1",
1283 { .compatible = "adi,adis16507-2",
1285 { .compatible = "adi,adis16507-3",
1297 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in adis16475_probe()
1299 return -ENOMEM; in adis16475_probe()
1303 st->info = device_get_match_data(&spi->dev); in adis16475_probe()
1304 if (!st->info) in adis16475_probe()
1305 return -EINVAL; in adis16475_probe()
1307 ret = adis_init(&st->adis, indio_dev, spi, &st->info->adis_data); in adis16475_probe()
1311 indio_dev->name = st->info->name; in adis16475_probe()
1312 indio_dev->channels = st->info->channels; in adis16475_probe()
1313 indio_dev->num_channels = st->info->num_channels; in adis16475_probe()
1314 indio_dev->info = &adis16475_info; in adis16475_probe()
1315 indio_dev->modes = INDIO_DIRECT_MODE; in adis16475_probe()
1317 ret = __adis_initial_startup(&st->adis); in adis16475_probe()
1329 ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev, in adis16475_probe()
1334 ret = devm_iio_device_register(&spi->dev, indio_dev); in adis16475_probe()