ret = spi_sync(adis->spi, &msg); if (ret) {
dev_err(&adis->spi->dev, "Failed to read register 0x%02X: %d\n",
reg, ret); return ret;
}
adis->current_page = page;
switch (size) { case 4:
*val = get_unaligned_be32(adis->rx); break; case 2:
*val = get_unaligned_be16(adis->rx + 2); break;
}
return ret;
}
EXPORT_SYMBOL_NS_GPL(__adis_read_reg, "IIO_ADISLIB"); /** * __adis_update_bits_base() - ADIS Update bits function - Unlocked version * @adis: The adis device * @reg: The address of the lower of the two registers * @mask: Bitmask to change * @val: Value to be written * @size: Size of the register to update * * Updates the desired bits of @reg in accordance with @mask and @val.
*/ int __adis_update_bits_base(struct adis *adis, unsignedint reg, const u32 mask, const u32 val, u8 size)
{ int ret;
u32 __val;
ret = adis->ops->read(adis, reg, &__val, size); if (ret) return ret;
/** * __adis_check_status() - Check the device for error conditions (unlocked) * @adis: The adis device * * Returns 0 on success, a negative error code otherwise
*/ int __adis_check_status(struct adis *adis)
{ unsignedint status; int diag_stat_bits;
u16 status_16 = 0; int ret; int i;
if (adis->data->diag_stat_size) {
ret = adis->ops->read(adis, adis->data->diag_stat_reg, &status,
adis->data->diag_stat_size);
} else {
ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg,
&status_16);
status = status_16;
} if (ret) return ret;
ret = __adis_write_reg_16(adis, adis->data->self_test_reg,
adis->data->self_test_mask); if (ret) {
dev_err(&adis->spi->dev, "Failed to initiate self test: %d\n",
ret); return ret;
}
msleep(timeouts->self_test_ms);
ret = __adis_check_status(adis);
if (adis->data->self_test_no_autoclear)
__adis_write_reg_16(adis, adis->data->self_test_reg, 0x00);
return ret;
}
/** * __adis_initial_startup() - Device initial setup * @adis: The adis device * * The function performs a HW reset via a reset pin that should be specified * via GPIOLIB. If no pin is configured a SW reset will be performed. * The RST pin for the ADIS devices should be configured as ACTIVE_LOW. * * After the self-test operation is performed, the function will also check * that the product ID is as expected. This assumes that drivers providing * 'prod_id_reg' will also provide the 'prod_id'. * * Returns 0 if the device is operational, a negative error code otherwise. * * This function should be called early on in the device initialization sequence * to ensure that the device is in a sane and known state and that it is usable.
*/ int __adis_initial_startup(struct adis *adis)
{ conststruct adis_timeout *timeouts = adis->data->timeouts; struct gpio_desc *gpio;
u16 prod_id; int ret;
/* check if the device has rst pin low */
gpio = devm_gpiod_get_optional(&adis->spi->dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(gpio)) return PTR_ERR(gpio);
if (gpio) {
usleep_range(10, 12); /* bring device out of reset */
gpiod_set_value_cansleep(gpio, 0);
msleep(timeouts->reset_ms);
} else {
ret = __adis_reset(adis); if (ret) return ret;
}
ret = adis_self_test(adis); if (ret) return ret;
/* * don't bother calling this if we can't unmask the IRQ as in this case * the IRQ is most likely not yet requested and we will request it * with 'IRQF_NO_AUTOEN' anyways.
*/ if (!adis->data->unmasked_drdy)
__adis_enable_irq(adis, false);
if (!adis->data->prod_id_reg) return 0;
ret = adis_read_reg_16(adis, adis->data->prod_id_reg, &prod_id); if (ret) return ret;
if (prod_id != adis->data->prod_id)
dev_warn(&adis->spi->dev, "Device ID(%u) and product ID(%u) do not match.\n",
adis->data->prod_id, prod_id);
/** * adis_single_conversion() - Performs a single sample conversion * @indio_dev: The IIO device * @chan: The IIO channel * @error_mask: Mask for the error bit * @val: Result of the conversion * * Returns IIO_VAL_INT on success, a negative error code otherwise. * * The function performs a single conversion on a given channel and post * processes the value accordingly to the channel spec. If a error_mask is given * the function will check if the mask is set in the returned raw value. If it * is set the function will perform a self-check. If the device does not report * a error bit in the channels raw value set error_mask to 0.
*/ int adis_single_conversion(struct iio_dev *indio_dev, conststruct iio_chan_spec *chan, unsignedint error_mask, int *val)
{ struct adis *adis = iio_device_get_drvdata(indio_dev); unsignedint uval; int ret;
guard(mutex)(&adis->state_lock);
ret = adis->ops->read(adis, chan->address, &uval,
chan->scan_type.storagebits / 8); if (ret) return ret;
if (uval & error_mask) {
ret = __adis_check_status(adis); if (ret) return ret;
}
/** * adis_init() - Initialize adis device structure * @adis: The adis device * @indio_dev: The iio device * @spi: The spi device * @data: Chip specific data * * Returns 0 on success, a negative error code otherwise. * * This function must be called, before any other adis helper function may be * called.
*/ int adis_init(struct adis *adis, struct iio_dev *indio_dev, struct spi_device *spi, conststruct adis_data *data)
{ if (!data || !data->timeouts) {
dev_err(&spi->dev, "No config data or timeouts not defined!\n"); return -EINVAL;
}
mutex_init(&adis->state_lock);
if (!spi->cs_inactive.value) {
spi->cs_inactive.value = data->cs_change_delay;
spi->cs_inactive.unit = SPI_DELAY_UNIT_USECS;
}
if (data->has_paging) { /* Need to set the page before first read/write */
adis->current_page = -1;
} else { /* Page will always be 0 */
adis->current_page = 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.