Lines Matching +full:max +full:- +full:sample +full:- +full:rate +full:- +full:hz

1 // SPDX-License-Identifier: GPL-2.0
64 /* spi max speed in brust mode */
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()
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()
303 * an IMU sample rate between (optimally) 1900 and 2100. After this, we can use the in adis16475_set_freq()
304 * decimation filter to lower the sampling rate in order to get what the user wants. in adis16475_set_freq()
305 * Optimally, the user sample rate is a multiple of both the IMU sample rate and in adis16475_set_freq()
308 * 1. lcm of the input clock and the desired output rate. in adis16475_set_freq()
309 * 2. get the highest multiple of the previous result lower than the adis max rate. in adis16475_set_freq()
310 * 3. The last result becomes the IMU sample rate. Use that to calculate SYNC_SCALE in adis16475_set_freq()
311 * and DEC_RATE (to get the user 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()
318 * If lcm is bigger than the IMU maximum sampling rate there's no perfect in adis16475_set_freq()
320 * lower than the IMU max sample rate. in adis16475_set_freq()
323 scaled_rate = 2100000 / st->clk_freq * st->clk_freq; in adis16475_set_freq()
329 * with a sample rate lower than 4000Hz due to possible undersampling in adis16475_set_freq()
331 * Hence, we provide a module parameter for them. If set, we allow sample in adis16475_set_freq()
333 * the rate to the next multiple of the input clock bigger than 4KHz. This 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()
375 [0] = 720, /* Filter disabled, full BW (~720Hz) */
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()
613 * There is no way to gate the data-ready signal internally inside the in adis16475_enable_irq()
617 enable_irq(adis->spi->irq); in adis16475_enable_irq()
619 disable_irq(adis->spi->irq); in adis16475_enable_irq()
688 .name = "adis16475-1",
703 .name = "adis16475-2",
718 .name = "adis16475-3",
733 .name = "adis16477-1",
748 .name = "adis16477-2",
763 .name = "adis16477-3",
778 .name = "adis16465-1",
793 .name = "adis16465-2",
808 .name = "adis16465-3",
823 .name = "adis16467-1",
838 .name = "adis16467-2",
853 .name = "adis16467-3",
880 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
885 .name = "adis16505-1",
897 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
902 .name = "adis16505-2",
914 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
919 .name = "adis16505-3",
931 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
936 .name = "adis16507-1",
948 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
953 .name = "adis16507-2",
965 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
970 .name = "adis16507-3",
982 .num_sync = ARRAY_SIZE(adis16475_sync_mode) - 1,
1003 for (i = 0; i < sz - 2; i++) in adis16475_validate_crc()
1004 crc -= buffer[i]; in adis16475_validate_crc()
1012 struct adis *adis = &st->adis; in adis16475_burst32_check()
1014 if (!st->info->has_burst32) in adis16475_burst32_check()
1017 if (st->lsb_flag && !st->burst32) { in adis16475_burst32_check()
1020 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_burst32_check()
1025 st->burst32 = true; in adis16475_burst32_check()
1028 * In 32-bit mode we need extra 2 bytes for all gyro in adis16475_burst32_check()
1031 adis->burst_extra_len = 6 * sizeof(u16); in adis16475_burst32_check()
1032 adis->xfer[1].len += 6 * sizeof(u16); in adis16475_burst32_check()
1033 dev_dbg(&adis->spi->dev, "Enable burst32 mode, xfer:%d", in adis16475_burst32_check()
1034 adis->xfer[1].len); in adis16475_burst32_check()
1036 } else if (!st->lsb_flag && st->burst32) { in adis16475_burst32_check()
1039 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_burst32_check()
1044 st->burst32 = false; in adis16475_burst32_check()
1047 adis->burst_extra_len = 0; in adis16475_burst32_check()
1048 adis->xfer[1].len -= 6 * sizeof(u16); in adis16475_burst32_check()
1049 dev_dbg(&adis->spi->dev, "Disable burst32 mode, xfer:%d\n", in adis16475_burst32_check()
1050 adis->xfer[1].len); in adis16475_burst32_check()
1057 struct iio_dev *indio_dev = pf->indio_dev; in adis16475_trigger_handler()
1059 struct adis *adis = &st->adis; in adis16475_trigger_handler()
1065 const u8 offset = st->burst32 ? 13 : 7; in adis16475_trigger_handler()
1067 ret = spi_sync(adis->spi, &adis->msg); in adis16475_trigger_handler()
1071 buffer = adis->buffer; in adis16475_trigger_handler()
1074 valid = adis16475_validate_crc(adis->buffer, crc, st->burst32); in adis16475_trigger_handler()
1076 dev_err(&adis->spi->dev, "Invalid crc\n"); in adis16475_trigger_handler()
1080 for_each_set_bit(bit, indio_dev->active_scan_mask, in adis16475_trigger_handler()
1081 indio_dev->masklength) { in adis16475_trigger_handler()
1088 st->data[i++] = buffer[offset]; in adis16475_trigger_handler()
1095 if (st->burst32) { in adis16475_trigger_handler()
1097 st->data[i++] = buffer[bit * 2 + 2]; in adis16475_trigger_handler()
1099 st->data[i++] = buffer[bit * 2 + 1]; in adis16475_trigger_handler()
1101 st->data[i++] = buffer[bit + 1]; in adis16475_trigger_handler()
1108 if (st->lsb_flag && !st->info->has_burst32) { in adis16475_trigger_handler()
1114 st->data[i++] = cpu_to_be16(val); in adis16475_trigger_handler()
1117 st->data[i++] = 0; in adis16475_trigger_handler()
1124 iio_push_to_buffers_with_timestamp(indio_dev, st->data, pf->timestamp); in adis16475_trigger_handler()
1132 iio_trigger_notify_done(indio_dev->trig); in adis16475_trigger_handler()
1145 struct device *dev = &st->adis.spi->dev; in adis16475_config_sync_mode()
1150 st->clk_freq = st->info->int_clk * 1000; in adis16475_config_sync_mode()
1152 ret = device_property_read_u32(dev, "adi,sync-mode", &sync_mode); in adis16475_config_sync_mode()
1156 if (sync_mode >= st->info->num_sync) { in adis16475_config_sync_mode()
1158 st->info->name); in adis16475_config_sync_mode()
1159 return -EINVAL; in adis16475_config_sync_mode()
1162 sync = &st->info->sync[sync_mode]; in adis16475_config_sync_mode()
1163 st->sync_mode = sync->sync_mode; in adis16475_config_sync_mode()
1166 if (sync->sync_mode != ADIS16475_SYNC_OUTPUT) { in adis16475_config_sync_mode()
1180 st->clk_freq = clk_get_rate(clk); in adis16475_config_sync_mode()
1181 if (st->clk_freq < sync->min_rate || in adis16475_config_sync_mode()
1182 st->clk_freq > sync->max_rate) { in adis16475_config_sync_mode()
1184 "Clk rate:%u not in a valid range:[%u %u]\n", in adis16475_config_sync_mode()
1185 st->clk_freq, sync->min_rate, sync->max_rate); in adis16475_config_sync_mode()
1186 return -EINVAL; in adis16475_config_sync_mode()
1189 if (sync->sync_mode == ADIS16475_SYNC_SCALED) { in adis16475_config_sync_mode()
1193 * In sync scaled mode, the IMU sample rate is the clk_freq * sync_scale. in adis16475_config_sync_mode()
1194 * Hence, default the IMU sample rate to the highest multiple of the input in adis16475_config_sync_mode()
1195 * clock lower than the IMU max sample rate. The optimal range is in adis16475_config_sync_mode()
1196 * 1900-2100 sps... in adis16475_config_sync_mode()
1198 up_scale = 2100 / st->clk_freq; in adis16475_config_sync_mode()
1200 ret = __adis_write_reg_16(&st->adis, in adis16475_config_sync_mode()
1207 st->clk_freq *= 1000; in adis16475_config_sync_mode()
1217 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_config_sync_mode()
1218 ADIS16475_SYNC_MODE_MASK, sync->sync_mode); in adis16475_config_sync_mode()
1234 struct spi_device *spi = st->adis.spi; in adis16475_config_irq_pin()
1236 desc = irq_get_irq_data(spi->irq); in adis16475_config_irq_pin()
1238 dev_err(&spi->dev, "Could not find IRQ %d\n", spi->irq); in adis16475_config_irq_pin()
1239 return -EINVAL; in adis16475_config_irq_pin()
1248 st->adis.irq_flag = IRQF_TRIGGER_RISING; in adis16475_config_irq_pin()
1251 st->adis.irq_flag = IRQF_TRIGGER_FALLING; in adis16475_config_irq_pin()
1253 dev_err(&spi->dev, "Invalid interrupt type 0x%x specified\n", in adis16475_config_irq_pin()
1255 return -EINVAL; in adis16475_config_irq_pin()
1259 st->adis.irq_flag |= IRQF_NO_AUTOEN; in adis16475_config_irq_pin()
1262 ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL, in adis16475_config_irq_pin()
1279 { .compatible = "adi,adis16475-1",
1281 { .compatible = "adi,adis16475-2",
1283 { .compatible = "adi,adis16475-3",
1285 { .compatible = "adi,adis16477-1",
1287 { .compatible = "adi,adis16477-2",
1289 { .compatible = "adi,adis16477-3",
1291 { .compatible = "adi,adis16465-1",
1293 { .compatible = "adi,adis16465-2",
1295 { .compatible = "adi,adis16465-3",
1297 { .compatible = "adi,adis16467-1",
1299 { .compatible = "adi,adis16467-2",
1301 { .compatible = "adi,adis16467-3",
1305 { .compatible = "adi,adis16505-1",
1307 { .compatible = "adi,adis16505-2",
1309 { .compatible = "adi,adis16505-3",
1311 { .compatible = "adi,adis16507-1",
1313 { .compatible = "adi,adis16507-2",
1315 { .compatible = "adi,adis16507-3",
1327 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in adis16475_probe()
1329 return -ENOMEM; in adis16475_probe()
1333 st->info = device_get_match_data(&spi->dev); in adis16475_probe()
1334 if (!st->info) in adis16475_probe()
1335 return -EINVAL; in adis16475_probe()
1337 ret = adis_init(&st->adis, indio_dev, spi, &st->info->adis_data); in adis16475_probe()
1341 indio_dev->name = st->info->name; in adis16475_probe()
1342 indio_dev->channels = st->info->channels; in adis16475_probe()
1343 indio_dev->num_channels = st->info->num_channels; in adis16475_probe()
1344 indio_dev->info = &adis16475_info; in adis16475_probe()
1345 indio_dev->modes = INDIO_DIRECT_MODE; in adis16475_probe()
1347 ret = __adis_initial_startup(&st->adis); in adis16475_probe()
1359 ret = devm_adis_setup_buffer_and_trigger(&st->adis, indio_dev, in adis16475_probe()
1364 ret = devm_iio_device_register(&spi->dev, indio_dev); in adis16475_probe()