drivers/hwmon/ad7418.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/ad7418.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/ad7418.c- Extension
.c- Size
- 7770 bytes
- Lines
- 314
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/jiffies.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/mutex.hlinux/of.hlinux/delay.hlinux/slab.hlm75.h
Detected Declarations
struct ad7418_dataenum chipsfunction ad7418_update_devicefunction temp_showfunction adc_showfunction temp_storefunction ad7418_init_clientfunction ad7418_probe
Annotated Snippet
struct ad7418_data {
struct i2c_client *client;
enum chips type;
struct mutex lock;
int adc_max; /* number of ADC channels */
bool valid;
unsigned long last_updated; /* In jiffies */
s16 temp[3]; /* Register values */
u16 in[4];
};
static int ad7418_update_device(struct device *dev)
{
struct ad7418_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
s32 val;
mutex_lock(&data->lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) {
u8 cfg;
int i, ch;
/* read config register and clear channel bits */
val = i2c_smbus_read_byte_data(client, AD7418_REG_CONF);
if (val < 0)
goto abort;
cfg = val;
cfg &= 0x1F;
val = i2c_smbus_write_byte_data(client, AD7418_REG_CONF,
cfg | AD7418_CH_TEMP);
if (val < 0)
goto abort;
udelay(30);
for (i = 0; i < 3; i++) {
val = i2c_smbus_read_word_swapped(client,
AD7418_REG_TEMP[i]);
if (val < 0)
goto abort;
data->temp[i] = val;
}
for (i = 0, ch = 4; i < data->adc_max; i++, ch--) {
val = i2c_smbus_write_byte_data(client, AD7418_REG_CONF,
cfg | AD7418_REG_ADC_CH(ch));
if (val < 0)
goto abort;
udelay(15);
val = i2c_smbus_read_word_swapped(client,
AD7418_REG_ADC);
if (val < 0)
goto abort;
data->in[data->adc_max - 1 - i] = val;
}
/* restore old configuration value */
val = i2c_smbus_write_word_swapped(client, AD7418_REG_CONF,
cfg);
if (val < 0)
goto abort;
data->last_updated = jiffies;
data->valid = true;
}
mutex_unlock(&data->lock);
return 0;
abort:
data->valid = false;
mutex_unlock(&data->lock);
return val;
}
static ssize_t temp_show(struct device *dev, struct device_attribute *devattr,
char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct ad7418_data *data = dev_get_drvdata(dev);
int ret;
ret = ad7418_update_device(dev);
Annotation
- Immediate include surface: `linux/module.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`, `linux/mutex.h`, `linux/of.h`.
- Detected declarations: `struct ad7418_data`, `enum chips`, `function ad7418_update_device`, `function temp_show`, `function adc_show`, `function temp_store`, `function ad7418_init_client`, `function ad7418_probe`.
- Atlas domain: Driver Families / drivers/hwmon.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.