drivers/iio/adc/hi8435.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/hi8435.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/hi8435.c- Extension
.c- Size
- 13655 bytes
- Lines
- 548
- 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/delay.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_event.hlinux/interrupt.hlinux/module.hlinux/mod_devicetable.hlinux/spi/spi.hlinux/gpio/consumer.h
Detected Declarations
struct hi8435_privfunction hi8435_readbfunction hi8435_readwfunction hi8435_readlfunction hi8435_writebfunction hi8435_writewfunction hi8435_read_rawfunction hi8435_read_event_configfunction hi8435_write_event_configfunction hi8435_read_event_valuefunction hi8435_write_event_valuefunction hi8435_debugfs_reg_accessfunction hi8435_get_sensing_modefunction hi8435_set_sensing_modefunction hi8435_iio_push_eventfunction for_each_set_bitfunction hi8435_trigger_handlerfunction hi8435_triggered_event_cleanupfunction hi8435_probe
Annotated Snippet
struct hi8435_priv {
struct spi_device *spi;
struct mutex lock;
unsigned long event_scan_mask; /* soft mask/unmask channels events */
unsigned int event_prev_val;
unsigned threshold_lo[2]; /* GND-Open and Supply-Open thresholds */
unsigned threshold_hi[2]; /* GND-Open and Supply-Open thresholds */
u8 reg_buffer[3] __aligned(IIO_DMA_MINALIGN);
};
static int hi8435_readb(struct hi8435_priv *priv, u8 reg, u8 *val)
{
reg |= HI8435_READ_OPCODE;
return spi_write_then_read(priv->spi, ®, 1, val, 1);
}
static int hi8435_readw(struct hi8435_priv *priv, u8 reg, u16 *val)
{
int ret;
__be16 be_val;
reg |= HI8435_READ_OPCODE;
ret = spi_write_then_read(priv->spi, ®, 1, &be_val, 2);
*val = be16_to_cpu(be_val);
return ret;
}
static int hi8435_readl(struct hi8435_priv *priv, u8 reg, u32 *val)
{
int ret;
__be32 be_val;
reg |= HI8435_READ_OPCODE;
ret = spi_write_then_read(priv->spi, ®, 1, &be_val, 4);
*val = be32_to_cpu(be_val);
return ret;
}
static int hi8435_writeb(struct hi8435_priv *priv, u8 reg, u8 val)
{
priv->reg_buffer[0] = reg | HI8435_WRITE_OPCODE;
priv->reg_buffer[1] = val;
return spi_write(priv->spi, priv->reg_buffer, 2);
}
static int hi8435_writew(struct hi8435_priv *priv, u8 reg, u16 val)
{
priv->reg_buffer[0] = reg | HI8435_WRITE_OPCODE;
priv->reg_buffer[1] = (val >> 8) & 0xff;
priv->reg_buffer[2] = val & 0xff;
return spi_write(priv->spi, priv->reg_buffer, 3);
}
static int hi8435_read_raw(struct iio_dev *idev,
const struct iio_chan_spec *chan,
int *val, int *val2, long mask)
{
struct hi8435_priv *priv = iio_priv(idev);
u32 tmp;
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = hi8435_readl(priv, HI8435_SO31_0_REG, &tmp);
if (ret < 0)
return ret;
*val = !!(tmp & BIT(chan->channel));
return IIO_VAL_INT;
default:
return -EINVAL;
}
}
static int hi8435_read_event_config(struct iio_dev *idev,
const struct iio_chan_spec *chan,
enum iio_event_type type,
enum iio_event_direction dir)
{
struct hi8435_priv *priv = iio_priv(idev);
return !!(priv->event_scan_mask & BIT(chan->channel));
}
static int hi8435_write_event_config(struct iio_dev *idev,
Annotation
- Immediate include surface: `linux/delay.h`, `linux/iio/events.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/iio/trigger.h`, `linux/iio/trigger_consumer.h`, `linux/iio/triggered_event.h`, `linux/interrupt.h`.
- Detected declarations: `struct hi8435_priv`, `function hi8435_readb`, `function hi8435_readw`, `function hi8435_readl`, `function hi8435_writeb`, `function hi8435_writew`, `function hi8435_read_raw`, `function hi8435_read_event_config`, `function hi8435_write_event_config`, `function hi8435_read_event_value`.
- 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.