drivers/iio/adc/ad7280a.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/ad7280a.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/ad7280a.c- Extension
.c- Size
- 30763 bytes
- Lines
- 1110
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/bits.hlinux/cleanup.hlinux/crc8.hlinux/delay.hlinux/device.hlinux/err.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/mutex.hlinux/slab.hlinux/sysfs.hlinux/spi/spi.hlinux/iio/events.hlinux/iio/iio.h
Detected Declarations
struct ad7280_statefunction ad7280a_devaddrfunction ad7280_calc_crc8function ad7280_check_crcfunction ad7280_delayfunction __ad7280_read32function ad7280_writefunction ad7280_read_regfunction ad7280_read_channelfunction ad7280_read_all_channelsfunction ad7280_sw_power_downfunction ad7280_chain_setupfunction ad7280_show_balance_swfunction ad7280_store_balance_swfunction ad7280_show_balance_timerfunction ad7280_store_balance_timerfunction ad7280_voltage_channel_initfunction ad7280_temp_channel_initfunction ad7280_common_fields_initfunction ad7280_total_voltage_channel_initfunction ad7280_init_dev_channelsfunction ad7280_channel_initfunction ad7280a_read_threshfunction ad7280a_write_threshfunction ad7280_event_handlerfunction ad7280_update_delayfunction ad7280_read_rawfunction ad7280_write_rawfunction ad7280_probe
Annotated Snippet
struct ad7280_state {
struct spi_device *spi;
struct iio_chan_spec *channels;
unsigned int chain_last_alert_ignore;
bool thermistor_term_en;
int slave_num;
int scan_cnt;
int readback_delay_us;
unsigned char crc_tab[CRC8_TABLE_SIZE];
u8 oversampling_ratio;
u8 acquisition_time;
unsigned char ctrl_lb;
unsigned char cell_threshhigh;
unsigned char cell_threshlow;
unsigned char aux_threshhigh;
unsigned char aux_threshlow;
unsigned char cb_mask[AD7280A_MAX_CHAIN];
struct mutex lock; /* protect sensor state */
__be32 tx __aligned(IIO_DMA_MINALIGN);
__be32 rx;
};
static unsigned char ad7280_calc_crc8(unsigned char *crc_tab, unsigned int val)
{
unsigned char crc;
crc = crc_tab[val >> 16 & 0xFF];
crc = crc_tab[crc ^ (val >> 8 & 0xFF)];
return crc ^ (val & 0xFF);
}
static int ad7280_check_crc(struct ad7280_state *st, unsigned int val)
{
unsigned char crc = ad7280_calc_crc8(st->crc_tab, val >> 10);
if (crc != ((val >> 2) & 0xFF))
return -EIO;
return 0;
}
/*
* After initiating a conversion sequence we need to wait until the conversion
* is done. The delay is typically in the range of 15..30us however depending on
* the number of devices in the daisy chain, the number of averages taken,
* conversion delays and acquisition time options it may take up to 250us, in
* this case we better sleep instead of busy wait.
*/
static void ad7280_delay(struct ad7280_state *st)
{
if (st->readback_delay_us < 50)
udelay(st->readback_delay_us);
else
usleep_range(250, 500);
}
static int __ad7280_read32(struct ad7280_state *st, unsigned int *val)
{
int ret;
struct spi_transfer t = {
.tx_buf = &st->tx,
.rx_buf = &st->rx,
.len = sizeof(st->tx),
};
st->tx = cpu_to_be32(AD7280A_READ_TXVAL);
ret = spi_sync_transfer(st->spi, &t, 1);
if (ret)
return ret;
*val = be32_to_cpu(st->rx);
return 0;
}
static int ad7280_write(struct ad7280_state *st, unsigned int devaddr,
unsigned int addr, bool all, unsigned int val)
{
unsigned int reg = FIELD_PREP(AD7280A_TRANS_WRITE_DEVADDR_MSK, devaddr) |
FIELD_PREP(AD7280A_TRANS_WRITE_ADDR_MSK, addr) |
FIELD_PREP(AD7280A_TRANS_WRITE_VAL_MSK, val) |
FIELD_PREP(AD7280A_TRANS_WRITE_ALL_MSK, all);
reg |= FIELD_PREP(AD7280A_TRANS_WRITE_CRC_MSK,
ad7280_calc_crc8(st->crc_tab, reg >> 11));
/* Reserved b010 pattern not included crc calc */
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bits.h`, `linux/cleanup.h`, `linux/crc8.h`, `linux/delay.h`, `linux/device.h`, `linux/err.h`, `linux/interrupt.h`.
- Detected declarations: `struct ad7280_state`, `function ad7280a_devaddr`, `function ad7280_calc_crc8`, `function ad7280_check_crc`, `function ad7280_delay`, `function __ad7280_read32`, `function ad7280_write`, `function ad7280_read_reg`, `function ad7280_read_channel`, `function ad7280_read_all_channels`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.