drivers/iio/resolver/ad2s1210.c
Source file repositories/reference/linux-study-clean/drivers/iio/resolver/ad2s1210.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/resolver/ad2s1210.c- Extension
.c- Size
- 45198 bytes
- Lines
- 1618
- 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.
- 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/bitmap.hlinux/bits.hlinux/cleanup.hlinux/clk.hlinux/delay.hlinux/device.hlinux/gpio/consumer.hlinux/module.hlinux/mutex.hlinux/regmap.hlinux/slab.hlinux/spi/spi.hlinux/sysfs.hlinux/types.hlinux/iio/buffer.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.h
Detected Declarations
struct ad2s1210_stateenum ad2s1210_modeenum ad2s1210_resolutionfunction ad2s1210_set_modefunction ad2s1210_regmap_reg_writefunction ad2s1210_regmap_reg_readfunction ad2s1210_toggle_sample_linefunction ad2s1210_reinit_excitation_frequencyfunction ad2s1210_push_eventsfunction ad2s1210_single_conversionfunction ad2s1210_get_hysteresisfunction ad2s1210_set_hysteresisfunction ad2s1210_get_phase_lock_rangefunction ad2s1210_set_phase_lock_rangefunction ad2s1210_get_voltage_thresholdfunction ad2s1210_set_voltage_thresholdfunction ad2s1210_get_lot_high_thresholdfunction ad2s1210_set_lot_high_thresholdfunction ad2s1210_get_lot_low_thresholdfunction ad2s1210_set_lot_low_thresholdfunction ad2s1210_get_excitation_frequencyfunction ad2s1210_set_excitation_frequencyfunction ad2s1210_read_rawfunction ad2s1210_read_availfunction ad2s1210_write_rawfunction event_attr_voltage_reg_showfunction event_attr_voltage_reg_storefunction in_angl1_thresh_rising_value_available_showfunction in_angl1_thresh_rising_hysteresis_available_showfunction ad2s1210_initialfunction ad2s1210_read_labelfunction ad2s1210_read_event_valuefunction ad2s1210_write_event_valuefunction ad2s1210_read_event_labelfunction ad2s1210_debugfs_reg_accessfunction ad2s1210_trigger_handlerfunction ad2s1210_setup_propertiesfunction ad2s1210_setup_clocksfunction ad2s1210_setup_gpiosfunction ad2s1210_setup_regmapfunction ad2s1210_probe
Annotated Snippet
struct ad2s1210_state {
struct mutex lock;
struct spi_device *sdev;
/** GPIO pin connected to SAMPLE line. */
struct gpio_desc *sample_gpio;
/** GPIO pins connected to A0 and A1 lines (optional). */
struct gpio_descs *mode_gpios;
/** Used to access config registers. */
struct regmap *regmap;
/** The external oscillator frequency in Hz. */
unsigned long clkin_hz;
/** Available raw hysteresis values based on resolution. */
int hysteresis_available[2];
/* adi,fixed-mode property - only valid when mode_gpios == NULL. */
enum ad2s1210_mode fixed_mode;
/** The selected resolution */
enum ad2s1210_resolution resolution;
/** Copy of fault register from the previous read. */
u8 prev_fault_flags;
/** For reading raw sample value via SPI. */
struct {
__be16 raw;
u8 fault;
} sample __aligned(IIO_DMA_MINALIGN);
/** Scan buffer */
struct {
__be16 chan[2];
/* Ensure timestamp is naturally aligned. */
aligned_s64 timestamp;
} scan;
/** SPI transmit buffer. */
u8 rx[2];
/** SPI receive buffer. */
u8 tx[2];
};
static int ad2s1210_set_mode(struct ad2s1210_state *st, enum ad2s1210_mode mode)
{
struct gpio_descs *gpios = st->mode_gpios;
DECLARE_BITMAP(bitmap, 2) = { };
if (!gpios)
return mode == st->fixed_mode ? 0 : -EOPNOTSUPP;
bitmap_write(bitmap, mode, 0, 2);
return gpiod_multi_set_value_cansleep(gpios, bitmap);
}
/*
* Writes the given data to the given register address.
*
* If the mode is configurable, the device will first be placed in
* configuration mode.
*/
static int ad2s1210_regmap_reg_write(void *context, unsigned int reg,
unsigned int val)
{
struct ad2s1210_state *st = context;
struct spi_transfer xfers[] = {
{
.len = 1,
.rx_buf = &st->rx[0],
.tx_buf = &st->tx[0],
.cs_change = 1,
}, {
.len = 1,
.rx_buf = &st->rx[1],
.tx_buf = &st->tx[1],
},
};
int ret;
/* values can only be 7 bits, the MSB indicates an address */
if (val & ~0x7F)
return -EINVAL;
st->tx[0] = reg;
st->tx[1] = val;
ret = ad2s1210_set_mode(st, MOD_CONFIG);
if (ret < 0)
return ret;
ret = spi_sync_transfer(st->sdev, xfers, ARRAY_SIZE(xfers));
if (ret < 0)
return ret;
/* soft reset also clears the fault register */
if (reg == AD2S1210_REG_SOFT_RESET)
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bitmap.h`, `linux/bits.h`, `linux/cleanup.h`, `linux/clk.h`, `linux/delay.h`, `linux/device.h`, `linux/gpio/consumer.h`.
- Detected declarations: `struct ad2s1210_state`, `enum ad2s1210_mode`, `enum ad2s1210_resolution`, `function ad2s1210_set_mode`, `function ad2s1210_regmap_reg_write`, `function ad2s1210_regmap_reg_read`, `function ad2s1210_toggle_sample_line`, `function ad2s1210_reinit_excitation_frequency`, `function ad2s1210_push_events`, `function ad2s1210_single_conversion`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- 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.