Lines Matching +full:scaled +full:- +full:sync
1 // SPDX-License-Identifier: GPL-2.0
66 /* max of 4000 SPS in scale sync */
140 /* Calculate crc4 over four-bit nibbles, starting at the MSbit */ in spi_crc4()
141 for (i = bits - 4; i >= 0; i -= 4) in spi_crc4()
159 dev_err(&adis->spi->dev, in adis16550_spi_validate()
162 return -EIO; in adis16550_spi_validate()
166 dev_err(&adis->spi->dev, in adis16550_spi_validate()
168 return -EIO; in adis16550_spi_validate()
201 struct spi_device *spi = adis->spi; in adis16550_spi_xfer()
205 .tx_buf = &st->din[0], in adis16550_spi_xfer()
209 .tx_buf = &st->din[1], in adis16550_spi_xfer()
212 .rx_buf = st->dout, in adis16550_spi_xfer()
214 .tx_buf = &st->din[1], in adis16550_spi_xfer()
215 .rx_buf = &st->dout[1], in adis16550_spi_xfer()
225 &st->din[0]); in adis16550_spi_xfer()
229 adis16550_spi_msg_prepare(reg, wr, writeval, &st->din[1]); in adis16550_spi_xfer()
234 return -EINVAL; in adis16550_spi_xfer()
239 dev_err(&spi->dev, "Spi failure %d\n", ret); in adis16550_spi_xfer()
248 ret = adis16550_spi_validate(adis, st->dout[0], &data); in adis16550_spi_xfer()
255 dev_err(&spi->dev, in adis16550_spi_xfer()
258 return -EIO; in adis16550_spi_xfer()
263 ret = adis16550_spi_validate(adis, st->dout[1], &data); in adis16550_spi_xfer()
270 dev_err(&spi->dev, in adis16550_spi_xfer()
273 return -EIO; in adis16550_spi_xfer()
296 struct adis16550 *st = file->private_data; in adis16550_show_firmware_revision()
302 ret = adis_read_reg_16(&st->adis, ADIS16550_REG_FW_REV, &rev); in adis16550_show_firmware_revision()
322 struct adis16550 *st = file->private_data; in adis16550_show_firmware_date()
328 ret = adis_read_reg_32(&st->adis, ADIS16550_REG_FW_DATE, &date); in adis16550_show_firmware_date()
332 len = scnprintf(buf, sizeof(buf), "%.2x-%.2x-%.4x\n", date & 0xff, in adis16550_show_firmware_date()
351 ret = adis_read_reg_32(&st->adis, ADIS16550_REG_SERIAL_NUM, &serial); in adis16550_show_serial_number()
368 ret = adis_read_reg_16(&st->adis, ADIS16550_REG_PROD_ID, &prod_id); in adis16550_show_product_id()
385 ret = adis_read_reg_16(&st->adis, ADIS16550_REG_FLASH_CNT, &flash_count); in adis16550_show_flash_count()
422 u32 sample_rate = st->clk_freq_hz; in adis16550_get_freq()
424 adis_dev_auto_lock(&st->adis); in adis16550_get_freq()
426 if (st->sync_mode == ADIS16550_SYNC_MODE_SCALED) { in adis16550_get_freq()
429 ret = __adis_read_reg_16(&st->adis, ADIS16550_REG_SYNC_SCALE, &sync_scale); in adis16550_get_freq()
433 sample_rate = st->clk_freq_hz * sync_scale; in adis16550_get_freq()
436 ret = __adis_read_reg_16(&st->adis, ADIS16550_REG_DEC_RATE, &dec); in adis16550_get_freq()
438 return -EINVAL; in adis16550_get_freq()
448 u32 sample_rate = st->clk_freq_hz; in adis16550_set_freq_hz()
451 * int_clk - 1000 and int_clk + 500. in adis16550_set_freq_hz()
453 u32 max_sample_rate = st->info->int_clk * 1000 + 500000; in adis16550_set_freq_hz()
454 u32 min_sample_rate = st->info->int_clk * 1000 - 1000000; in adis16550_set_freq_hz()
457 return -EINVAL; in adis16550_set_freq_hz()
459 adis_dev_auto_lock(&st->adis); in adis16550_set_freq_hz()
461 if (st->sync_mode == ADIS16550_SYNC_MODE_SCALED) { in adis16550_set_freq_hz()
462 unsigned long scaled_rate = lcm(st->clk_freq_hz, freq_hz); in adis16550_set_freq_hz()
466 scaled_rate = max_sample_rate / st->clk_freq_hz * st->clk_freq_hz; in adis16550_set_freq_hz()
471 scaled_rate = roundup(min_sample_rate, st->clk_freq_hz); in adis16550_set_freq_hz()
473 sync_scale = scaled_rate / st->clk_freq_hz; in adis16550_set_freq_hz()
474 ret = __adis_write_reg_16(&st->adis, ADIS16550_REG_SYNC_SCALE, in adis16550_set_freq_hz()
485 dec--; in adis16550_set_freq_hz()
487 dec = min(dec, st->info->max_dec); in adis16550_set_freq_hz()
489 return __adis_write_reg_16(&st->adis, ADIS16550_REG_DEC_RATE, dec); in adis16550_set_freq_hz()
497 ret = adis_read_reg_16(&st->adis, ADIS16550_REG_CONFIG, &config); in adis16550_get_accl_filter_freq()
499 return -EINVAL; in adis16550_get_accl_filter_freq()
514 return __adis_update_bits(&st->adis, ADIS16550_REG_CONFIG, in adis16550_set_accl_filter_freq()
523 ret = adis_read_reg_16(&st->adis, ADIS16550_REG_CONFIG, &config); in adis16550_get_gyro_filter_freq()
525 return -EINVAL; in adis16550_get_gyro_filter_freq()
540 return __adis_update_bits(&st->adis, ADIS16550_REG_CONFIG, in adis16550_set_gyro_filter_freq()
584 const int idx = chan->scan_index; in adis16550_read_raw()
593 switch (chan->type) { in adis16550_read_raw()
595 *val = st->info->gyro_max_val; in adis16550_read_raw()
596 *val2 = st->info->gyro_max_scale; in adis16550_read_raw()
599 *val = st->info->accel_max_val; in adis16550_read_raw()
600 *val2 = st->info->accel_max_scale; in adis16550_read_raw()
603 *val = st->info->temp_scale; in adis16550_read_raw()
606 *val = st->info->deltang_max_val; in adis16550_read_raw()
610 *val = st->info->deltvel_max_val; in adis16550_read_raw()
614 return -EINVAL; in adis16550_read_raw()
618 *val = DIV_ROUND_CLOSEST(25000, st->info->temp_scale); in adis16550_read_raw()
621 ret = adis_read_reg_32(&st->adis, in adis16550_read_raw()
628 ret = adis_read_reg_16(&st->adis, in adis16550_read_raw()
644 switch (chan->type) { in adis16550_read_raw()
656 return -EINVAL; in adis16550_read_raw()
659 return -EINVAL; in adis16550_read_raw()
668 const int idx = chan->scan_index; in adis16550_write_raw()
676 return adis_write_reg_32(&st->adis, adis16550_calib_bias[idx], in adis16550_write_raw()
679 return adis_write_reg_16(&st->adis, adis16550_calib_scale[idx], in adis16550_write_raw()
682 switch (chan->type) { in adis16550_write_raw()
688 return -EINVAL; in adis16550_write_raw()
691 return -EINVAL; in adis16550_write_raw()
768 ADIS16550_REG_ ## _mod ## _DELTANG_L, -1)
772 ADIS16550_REG_ ## _mod ## _DELTVEL_L, -1)
817 u32 crc_buf[ADIS16550_BURST_N_ELEM - 2]; in adis16550_validate_crc()
818 u32 crc = be32_to_cpu(buffer[ADIS16550_BURST_N_ELEM - 1]); in adis16550_validate_crc()
840 struct iio_dev *indio_dev = pf->indio_dev; in adis16550_trigger_handler()
843 __be32 *buffer = (__be32 *)st->buffer; in adis16550_trigger_handler()
845 ret = spi_sync(adis->spi, &adis->msg); in adis16550_trigger_handler()
852 ret = adis16550_spi_validate(&st->adis, buffer[0], &dummy); in adis16550_trigger_handler()
857 valid = adis16550_validate_crc(buffer, ADIS16550_BURST_N_ELEM - 2); in adis16550_trigger_handler()
859 dev_err(&adis->spi->dev, "Burst Invalid crc!\n"); in adis16550_trigger_handler()
865 (ADIS16550_SCAN_ACCEL_Z - ADIS16550_SCAN_GYRO_X + 2) * in adis16550_trigger_handler()
867 iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp); in adis16550_trigger_handler()
869 iio_trigger_notify_done(indio_dev->trig); in adis16550_trigger_handler()
887 memset(st->buffer, 0, burst_length + sizeof(u32)); in adis16550_update_scan_mode()
894 tx = st->buffer + burst_length; in adis16550_update_scan_mode()
911 struct device *dev = &st->adis.spi->dev; in adis16550_config_sync()
921 st->clk_freq_hz = st->info->int_clk * 1000; in adis16550_config_sync()
925 st->clk_freq_hz = clk_get_rate(clk); in adis16550_config_sync()
927 for (i = 0; i < st->info->num_sync; i++) { in adis16550_config_sync()
928 if (st->clk_freq_hz >= st->info->sync_mode[i].min_rate && in adis16550_config_sync()
929 st->clk_freq_hz <= st->info->sync_mode[i].max_rate) { in adis16550_config_sync()
930 sync_mode_data = &st->info->sync_mode[i]; in adis16550_config_sync()
935 if (i == st->info->num_sync) in adis16550_config_sync()
936 return dev_err_probe(dev, -EINVAL, "Clk rate: %lu not in a valid range", in adis16550_config_sync()
937 st->clk_freq_hz); in adis16550_config_sync()
939 if (sync_mode_data->sync_mode == ADIS16550_SYNC_MODE_SCALED) { in adis16550_config_sync()
942 * In sps scaled sync we must scale the input clock to a range in adis16550_config_sync()
946 sync_scale = DIV_ROUND_CLOSEST(st->info->int_clk, st->clk_freq_hz); in adis16550_config_sync()
949 return dev_err_probe(dev, -EINVAL, in adis16550_config_sync()
953 ret = adis_write_reg_16(&st->adis, ADIS16550_REG_SYNC_SCALE, in adis16550_config_sync()
958 st->clk_freq_hz = st->info->int_clk; in adis16550_config_sync()
961 st->clk_freq_hz *= 1000; in adis16550_config_sync()
963 mode = FIELD_PREP(ADIS16550_SYNC_MODE_MASK, sync_mode_data->sync_mode) | in adis16550_config_sync()
966 return __adis_update_bits(&st->adis, ADIS16550_REG_CONFIG, in adis16550_config_sync()
1056 struct device *dev = &spi->dev; in adis16550_probe()
1064 return -ENOMEM; in adis16550_probe()
1067 st->info = spi_get_device_match_data(spi); in adis16550_probe()
1068 if (!st->info) in adis16550_probe()
1069 return -EINVAL; in adis16550_probe()
1070 adis = &st->adis; in adis16550_probe()
1071 indio_dev->name = st->info->name; in adis16550_probe()
1072 indio_dev->channels = st->info->channels; in adis16550_probe()
1073 indio_dev->num_channels = st->info->num_channels; in adis16550_probe()
1074 indio_dev->available_scan_masks = adis16550_channel_masks; in adis16550_probe()
1075 indio_dev->info = &adis16550_info; in adis16550_probe()
1076 indio_dev->modes = INDIO_DIRECT_MODE; in adis16550_probe()
1078 st->adis.ops = &adis16550_ops; in adis16550_probe()
1079 st->xfer[0].tx_buf = st->buffer + burst_length; in adis16550_probe()
1080 st->xfer[0].len = 4; in adis16550_probe()
1081 st->xfer[0].cs_change = 1; in adis16550_probe()
1082 st->xfer[0].delay.value = 8; in adis16550_probe()
1083 st->xfer[0].delay.unit = SPI_DELAY_UNIT_USECS; in adis16550_probe()
1084 st->xfer[1].rx_buf = st->buffer; in adis16550_probe()
1085 st->xfer[1].len = burst_length; in adis16550_probe()
1087 spi_message_init_with_transfers(&adis->msg, st->xfer, 2); in adis16550_probe()
1093 ret = adis_init(&st->adis, indio_dev, spi, &adis16550_data); in adis16550_probe()
1097 ret = __adis_initial_startup(&st->adis); in adis16550_probe()
1105 ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev, in adis16550_probe()