drivers/iio/adc/nct7201.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/nct7201.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/nct7201.c- Extension
.c- Size
- 14326 bytes
- Lines
- 502
- 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/array_size.hlinux/bitfield.hlinux/bits.hlinux/delay.hlinux/dev_printk.hlinux/err.hlinux/i2c.hlinux/mod_devicetable.hlinux/module.hlinux/regmap.hlinux/time.hlinux/types.hlinux/unaligned.hlinux/iio/events.hlinux/iio/iio.h
Detected Declarations
struct nct7201_chip_infostruct nct7201_adc_model_datafunction nct7201_read_rawfunction nct7201_read_event_valuefunction nct7201_write_event_valuefunction nct7201_read_event_configfunction nct7201_write_event_configfunction nct7201_init_chipfunction nct7201_irq_handlerfunction nct7201_probe
Annotated Snippet
struct nct7201_chip_info {
struct regmap *regmap;
struct regmap *regmap16;
int num_vin_channels;
__le16 vin_mask;
};
struct nct7201_adc_model_data {
const char *model_name;
const struct iio_chan_spec *channels;
unsigned int num_channels;
int num_vin_channels;
};
static const struct iio_event_spec nct7201_events[] = {
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_RISING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_ENABLE),
}, {
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_FALLING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_ENABLE),
},
};
#define NCT7201_VOLTAGE_CHANNEL(num) \
{ \
.type = IIO_VOLTAGE, \
.indexed = 1, \
.channel = num + 1, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
.address = num, \
.event_spec = nct7201_events, \
.num_event_specs = ARRAY_SIZE(nct7201_events), \
}
static const struct iio_chan_spec nct7201_channels[] = {
NCT7201_VOLTAGE_CHANNEL(0),
NCT7201_VOLTAGE_CHANNEL(1),
NCT7201_VOLTAGE_CHANNEL(2),
NCT7201_VOLTAGE_CHANNEL(3),
NCT7201_VOLTAGE_CHANNEL(4),
NCT7201_VOLTAGE_CHANNEL(5),
NCT7201_VOLTAGE_CHANNEL(6),
NCT7201_VOLTAGE_CHANNEL(7),
};
static const struct iio_chan_spec nct7202_channels[] = {
NCT7201_VOLTAGE_CHANNEL(0),
NCT7201_VOLTAGE_CHANNEL(1),
NCT7201_VOLTAGE_CHANNEL(2),
NCT7201_VOLTAGE_CHANNEL(3),
NCT7201_VOLTAGE_CHANNEL(4),
NCT7201_VOLTAGE_CHANNEL(5),
NCT7201_VOLTAGE_CHANNEL(6),
NCT7201_VOLTAGE_CHANNEL(7),
NCT7201_VOLTAGE_CHANNEL(8),
NCT7201_VOLTAGE_CHANNEL(9),
NCT7201_VOLTAGE_CHANNEL(10),
NCT7201_VOLTAGE_CHANNEL(11),
};
static int nct7201_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct nct7201_chip_info *chip = iio_priv(indio_dev);
unsigned int value;
int err;
if (chan->type != IIO_VOLTAGE)
return -EOPNOTSUPP;
switch (mask) {
case IIO_CHAN_INFO_RAW:
err = regmap_read(chip->regmap16, NCT7201_REG_VIN(chan->address), &value);
if (err)
return err;
*val = FIELD_GET(NCT7201_REG_VIN_MASK, value);
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
/* From the datasheet, we have to multiply by 0.0004995 */
*val = 0;
*val2 = 499500;
return IIO_VAL_INT_PLUS_NANO;
default:
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bitfield.h`, `linux/bits.h`, `linux/delay.h`, `linux/dev_printk.h`, `linux/err.h`, `linux/i2c.h`, `linux/mod_devicetable.h`.
- Detected declarations: `struct nct7201_chip_info`, `struct nct7201_adc_model_data`, `function nct7201_read_raw`, `function nct7201_read_event_value`, `function nct7201_write_event_value`, `function nct7201_read_event_config`, `function nct7201_write_event_config`, `function nct7201_init_chip`, `function nct7201_irq_handler`, `function nct7201_probe`.
- 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.