drivers/iio/cdc/ad7150.c
Source file repositories/reference/linux-study-clean/drivers/iio/cdc/ad7150.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/cdc/ad7150.c- Extension
.c- Size
- 17856 bytes
- Lines
- 658
- 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/device.hlinux/interrupt.hlinux/irq.hlinux/i2c.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/regulator/consumer.hlinux/slab.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/events.h
Detected Declarations
struct ad7150_chip_infofunction ad7150_read_rawfunction ad7150_read_event_configfunction ad7150_write_event_paramsfunction ad7150_write_event_configfunction enable_irqfunction ad7150_read_event_valuefunction ad7150_write_event_valuefunction BITfunction __ad7150_event_handlerfunction ad7150_event_handler_ch1function ad7150_event_handler_ch2function ad7150_probe
Annotated Snippet
struct ad7150_chip_info {
struct i2c_client *client;
u16 threshold[2][2];
u8 thresh_sensitivity[2][2];
u8 thresh_timeout[2][2];
struct mutex state_lock;
int interrupts[2];
bool int_enabled[2];
enum iio_event_type type;
enum iio_event_direction dir;
};
static const u8 ad7150_addresses[][6] = {
{ AD7150_CH1_DATA_HIGH_REG, AD7150_CH1_AVG_HIGH_REG,
AD7150_CH1_SETUP_REG, AD7150_CH1_THR_HOLD_H_REG,
AD7150_CH1_SENSITIVITY_REG, AD7150_CH1_TIMEOUT_REG },
{ AD7150_CH2_DATA_HIGH_REG, AD7150_CH2_AVG_HIGH_REG,
AD7150_CH2_SETUP_REG, AD7150_CH2_THR_HOLD_H_REG,
AD7150_CH2_SENSITIVITY_REG, AD7150_CH2_TIMEOUT_REG },
};
static int ad7150_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
int *val2,
long mask)
{
struct ad7150_chip_info *chip = iio_priv(indio_dev);
int channel = chan->channel;
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = i2c_smbus_read_word_swapped(chip->client,
ad7150_addresses[channel][0]);
if (ret < 0)
return ret;
*val = ret >> 4;
return IIO_VAL_INT;
case IIO_CHAN_INFO_AVERAGE_RAW:
ret = i2c_smbus_read_word_swapped(chip->client,
ad7150_addresses[channel][1]);
if (ret < 0)
return ret;
*val = ret;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
/*
* Base units for capacitance are nano farads and the value
* calculated from the datasheet formula is in picofarad
* so multiply by 1000
*/
*val = 1000;
*val2 = 40944 >> 4; /* To match shift in _RAW */
return IIO_VAL_FRACTIONAL;
case IIO_CHAN_INFO_OFFSET:
*val = -(12288 >> 4); /* To match shift in _RAW */
return IIO_VAL_INT;
case IIO_CHAN_INFO_SAMP_FREQ:
/* Strangely same for both 1 and 2 chan parts */
*val = 100;
return IIO_VAL_INT;
default:
return -EINVAL;
}
}
static int ad7150_read_event_config(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan,
enum iio_event_type type,
enum iio_event_direction dir)
{
struct ad7150_chip_info *chip = iio_priv(indio_dev);
u8 threshtype;
bool thrfixed;
int ret;
ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG_REG);
if (ret < 0)
return ret;
threshtype = FIELD_GET(AD7150_CFG_THRESHTYPE_MSK, ret);
/*check if threshold mode is fixed or adaptive*/
thrfixed = FIELD_GET(AD7150_CFG_FIX, ret);
switch (type) {
case IIO_EV_TYPE_THRESH_ADAPTIVE:
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/device.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/i2c.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`.
- Detected declarations: `struct ad7150_chip_info`, `function ad7150_read_raw`, `function ad7150_read_event_config`, `function ad7150_write_event_params`, `function ad7150_write_event_config`, `function enable_irq`, `function ad7150_read_event_value`, `function ad7150_write_event_value`, `function BIT`, `function __ad7150_event_handler`.
- 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.