static u16 ad7616_spi_rd_wr_cmd(int addr, char is_write_op)
{ /* * The address of register consist of one w/r bit * 6 bits of address followed by one reserved bit.
*/ return ((addr & 0x7F) << 1) | ((is_write_op & 0x1) << 7);
}
static u16 ad7606b_spi_rd_wr_cmd(int addr, char is_write_op)
{ /* * The address of register consists of one bit which * specifies a read command placed in bit 6, followed by * 6 bits of address.
*/ return (addr & 0x3F) | (((~is_write_op) & 0x1) << 6);
}
staticint ad7606_spi_read_block(struct device *dev, int count, void *buf)
{ struct spi_device *spi = to_spi_device(dev); int i, ret; unsignedshort *data = buf;
__be16 *bdata = buf;
ret = spi_read(spi, buf, count * 2); if (ret < 0) {
dev_err(&spi->dev, "SPI read error\n"); return ret;
}
for (i = 0; i < count; i++)
data[i] = be16_to_cpu(bdata[i]);
xfer->bits_per_word = scan_type->realbits;
xfer->offload_flags = SPI_OFFLOAD_XFER_RX_STREAM; /* * Using SPI offload, storagebits are related to the spi-engine * hw implementation, can be 16 or 32, so can't be used to compute * struct spi_transfer.len. Using realbits instead.
*/
xfer->len = (scan_type->realbits > 16 ? 4 : 2) *
st->chip_info->num_adc_channels;
/* * Requires 1 arg: * args[0] is the trigger event.
*/ if (nargs != 1 || args[0] != AD7606_TRIGGER_EVENT_BUSY) returnfalse;
returntrue;
}
staticint ad7606_spi_offload_trigger_request( struct spi_offload_trigger *trigger, enum spi_offload_trigger_type type,
u64 *args, u32 nargs)
{ /* Should already be validated by match, but just in case. */ if (nargs != 1) return -EINVAL;
bus_data->offload = devm_spi_offload_get(dev, spi,
&ad7606_spi_offload_config);
ret = PTR_ERR_OR_ZERO(bus_data->offload); if (ret && ret != -ENODEV) return dev_err_probe(dev, ret, "failed to get SPI offload\n"); /* Allow main ad7606_probe function to continue. */ if (ret == -ENODEV) return 0;
ret = devm_spi_offload_trigger_register(dev, &trigger_info); if (ret) return dev_err_probe(dev, ret, "failed to register offload trigger\n");
bus_data->offload_trigger = devm_spi_offload_trigger_get(dev,
bus_data->offload, SPI_OFFLOAD_TRIGGER_DATA_READY); if (IS_ERR(bus_data->offload_trigger)) return dev_err_probe(dev, PTR_ERR(bus_data->offload_trigger), "failed to get offload trigger\n");
/* TODO: PWM setup should be ok, done for the backend. PWM mutex ? */
rx_dma = devm_spi_offload_rx_stream_request_dma_chan(dev,
bus_data->offload); if (IS_ERR(rx_dma)) return dev_err_probe(dev, PTR_ERR(rx_dma), "failed to get offload RX DMA\n");
ret = devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev,
rx_dma, IIO_BUFFER_DIRECTION_IN); if (ret) return dev_err_probe(dev, ret, "failed to setup offload RX DMA\n");
/* Use offload ops. */
indio_dev->setup_ops = &ad7606_offload_buffer_setup_ops;
if (st->offload_en) { unsignedint num_adc_ch = st->chip_info->num_adc_channels;
/* * SPI offload requires that all channels are enabled since * there isn't a way to selectively disable channels that get * read (this is simultaneous sampling ADC) and the DMA buffer * has no way of demuxing the data to filter out unwanted * channels.
*/ if (bitmap_weight(scan_mask, num_adc_ch) != num_adc_ch) return -EINVAL;
}
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.