drivers/iio/amplifiers/adl8113.c
Source file repositories/reference/linux-study-clean/drivers/iio/amplifiers/adl8113.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/amplifiers/adl8113.c- Extension
.c- Size
- 6417 bytes
- Lines
- 270
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/array_size.hlinux/bitmap.hlinux/device/driver.hlinux/dev_printk.hlinux/err.hlinux/gpio/consumer.hlinux/iio/iio.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/regulator/consumer.hlinux/types.h
Detected Declarations
struct adl8113_gain_configstruct adl8113_stateenum adl8113_signal_pathfunction adl8113_set_pathfunction adl8113_find_gain_configfunction adl8113_read_rawfunction adl8113_write_rawfunction adl8113_init_gain_configsfunction adl8113_probe
Annotated Snippet
struct adl8113_gain_config {
enum adl8113_signal_path path;
int gain_db;
};
struct adl8113_state {
struct gpio_descs *gpios;
struct adl8113_gain_config *gain_configs;
unsigned int num_gain_configs;
enum adl8113_signal_path current_path;
};
static const char * const adl8113_supply_names[] = {
"vdd1",
"vss2",
"vdd2",
};
static int adl8113_set_path(struct adl8113_state *st,
enum adl8113_signal_path path)
{
DECLARE_BITMAP(values, 2);
int ret;
/*
* Determine GPIO values based on signal path.
* Va: bit 0, Vb: bit 1.
*/
switch (path) {
case ADL8113_INTERNAL_AMP:
bitmap_write(values, 0x00, 0, 2);
break;
case ADL8113_INTERNAL_BYPASS:
bitmap_write(values, 0x03, 0, 2);
break;
case ADL8113_EXTERNAL_A:
bitmap_write(values, 0x02, 0, 2);
break;
case ADL8113_EXTERNAL_B:
bitmap_write(values, 0x01, 0, 2);
break;
default:
return -EINVAL;
}
ret = gpiod_set_array_value_cansleep(st->gpios->ndescs, st->gpios->desc,
st->gpios->info, values);
if (ret)
return ret;
st->current_path = path;
return 0;
}
static int adl8113_find_gain_config(struct adl8113_state *st, int gain_db)
{
unsigned int i;
for (i = 0; i < st->num_gain_configs; i++) {
if (st->gain_configs[i].gain_db == gain_db)
return i;
}
return -EINVAL;
}
static const struct iio_chan_spec adl8113_channels[] = {
{
.type = IIO_VOLTAGE,
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_HARDWAREGAIN),
},
};
static int adl8113_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct adl8113_state *st = iio_priv(indio_dev);
unsigned int i;
switch (mask) {
case IIO_CHAN_INFO_HARDWAREGAIN:
/* Find current gain configuration */
for (i = 0; i < st->num_gain_configs; i++) {
if (st->gain_configs[i].path == st->current_path) {
*val = st->gain_configs[i].gain_db;
*val2 = 0;
return IIO_VAL_INT_PLUS_MICRO_DB;
}
}
return -EINVAL;
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bitmap.h`, `linux/device/driver.h`, `linux/dev_printk.h`, `linux/err.h`, `linux/gpio/consumer.h`, `linux/iio/iio.h`, `linux/mod_devicetable.h`.
- Detected declarations: `struct adl8113_gain_config`, `struct adl8113_state`, `enum adl8113_signal_path`, `function adl8113_set_path`, `function adl8113_find_gain_config`, `function adl8113_read_raw`, `function adl8113_write_raw`, `function adl8113_init_gain_configs`, `function adl8113_probe`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
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.