drivers/iio/adc/ad4134.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/ad4134.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/ad4134.c- Extension
.c- Size
- 14485 bytes
- Lines
- 501
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/array_size.hlinux/bitfield.hlinux/bitops.hlinux/clk.hlinux/crc8.hlinux/delay.hlinux/dev_printk.hlinux/err.hlinux/export.hlinux/gpio/consumer.hlinux/iio/iio.hlinux/iio/types.hlinux/module.hlinux/mod_devicetable.hlinux/regmap.hlinux/regulator/consumer.hlinux/reset.hlinux/spi/spi.hlinux/time.hlinux/types.hlinux/unaligned.hlinux/units.h
Detected Declarations
struct ad4134_statefunction ad4134_calc_spi_crcfunction ad4134_prepare_spi_tx_buffunction ad4134_reg_writefunction ad4134_data_readfunction ad4134_register_readfunction ad4134_reg_readfunction ad4134_read_rawfunction ad4134_debugfs_reg_accessfunction ad4134_min_io_mode_setupfunction ad4134_regulator_setupfunction ad4134_clock_selectfunction ad4134_probe
Annotated Snippet
struct ad4134_state {
struct spi_device *spi;
struct regmap *regmap;
unsigned long sys_clk_hz;
struct gpio_desc *odr_gpio;
int refin_mv;
/*
* DMA (thus cache coherency maintenance) requires the transfer buffers
* to live in their own cache lines.
*/
u8 rx_buf[AD4134_SPI_MAX_XFER_LEN] __aligned(IIO_DMA_MINALIGN);
u8 tx_buf[AD4134_SPI_MAX_XFER_LEN];
};
static const struct regmap_range ad4134_regmap_rd_range[] = {
regmap_reg_range(AD4134_IFACE_CONFIG_A_REG, AD4134_SILICON_REV_REG),
regmap_reg_range(AD4134_SCRATCH_PAD_REG, AD4134_PW_DOWN_CTRL_REG),
regmap_reg_range(AD4134_DEVICE_STATUS_REG, AD4134_AIN_OR_ERROR_REG),
regmap_reg_range(AD4134_CH_VREG(0), AD4134_CH_VREG(AD4134_NUM_CHANNELS)),
};
static const struct regmap_range ad4134_regmap_wr_range[] = {
regmap_reg_range(AD4134_IFACE_CONFIG_A_REG, AD4134_DEVICE_CONFIG_REG),
regmap_reg_range(AD4134_SCRATCH_PAD_REG, AD4134_SCRATCH_PAD_REG),
regmap_reg_range(AD4134_STREAM_MODE_REG, AD4134_PW_DOWN_CTRL_REG),
regmap_reg_range(AD4134_ODR_VAL_INT_LSB_REG, AD4134_CH3_OFFSET_MSB_REG),
};
static const struct regmap_access_table ad4134_regmap_rd_table = {
.yes_ranges = ad4134_regmap_rd_range,
.n_yes_ranges = ARRAY_SIZE(ad4134_regmap_rd_range),
};
static const struct regmap_access_table ad4134_regmap_wr_table = {
.yes_ranges = ad4134_regmap_wr_range,
.n_yes_ranges = ARRAY_SIZE(ad4134_regmap_wr_range),
};
static int ad4134_calc_spi_crc(u8 inst, u8 data)
{
u8 buf[] = { inst, data };
return crc8(ad4134_spi_crc_table, buf, ARRAY_SIZE(buf),
AD4134_SPI_CRC_INIT_VALUE);
}
static void ad4134_prepare_spi_tx_buf(u8 inst, u8 data, u8 *buf)
{
buf[0] = inst;
buf[1] = data;
buf[2] = ad4134_calc_spi_crc(inst, data);
}
static int ad4134_reg_write(void *context, unsigned int reg, unsigned int val)
{
struct ad4134_state *st = context;
struct spi_transfer xfer = {
.tx_buf = st->tx_buf,
.rx_buf = st->rx_buf,
.len = AD4134_SPI_MAX_XFER_LEN,
};
int ret;
ad4134_prepare_spi_tx_buf(reg, val, st->tx_buf);
ret = spi_sync_transfer(st->spi, &xfer, 1);
if (ret)
return ret;
if (st->rx_buf[2] != st->tx_buf[2])
dev_dbg(&st->spi->dev, "reg write CRC check failed\n");
return 0;
}
static int ad4134_data_read(struct ad4134_state *st, unsigned int reg,
unsigned int *val)
{
unsigned int i;
int ret;
/*
* To be able to read data from all 4 channels through a single line, we
* set DOUTx output format to 0 in the digital interface config register
* (0x12). With that, data from all four channels is serialized and
* output on DOUT0. During the probe, we also set SDO_PIN_SRC_SEL in
* DEVICE_CONFIG_1 register to duplicate DOUT0 on the SDO pin. Combined,
* those configurations enable ADC data read through a conventional SPI
* interface. Now we read data from all channels but keep only the bits
* from the requested one.
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bitfield.h`, `linux/bitops.h`, `linux/clk.h`, `linux/crc8.h`, `linux/delay.h`, `linux/dev_printk.h`, `linux/err.h`.
- Detected declarations: `struct ad4134_state`, `function ad4134_calc_spi_crc`, `function ad4134_prepare_spi_tx_buf`, `function ad4134_reg_write`, `function ad4134_data_read`, `function ad4134_register_read`, `function ad4134_reg_read`, `function ad4134_read_raw`, `function ad4134_debugfs_reg_access`, `function ad4134_min_io_mode_setup`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.