drivers/hwmon/adc128d818.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/adc128d818.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/adc128d818.c- Extension
.c- Size
- 14545 bytes
- Lines
- 511
- 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/slab.hlinux/jiffies.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/regulator/consumer.hlinux/mutex.hlinux/bitops.hlinux/of.h
Detected Declarations
struct adc128_datafunction adc128_in_showfunction adc128_in_storefunction adc128_temp_showfunction adc128_temp_storefunction adc128_alarm_showfunction adc128_is_visiblefunction adc128_detectfunction adc128_init_clientfunction adc128_probe
Annotated Snippet
struct adc128_data {
struct i2c_client *client;
int vref; /* Reference voltage in mV */
struct mutex update_lock;
u8 mode; /* Operation mode */
bool valid; /* true if following fields are valid */
unsigned long last_updated; /* In jiffies */
u16 in[3][8]; /* Register value, normalized to 12 bit
* 0: input voltage
* 1: min limit
* 2: max limit
*/
s16 temp[3]; /* Register value, normalized to 9 bit
* 0: sensor 1: limit 2: hyst
*/
u8 alarms; /* alarm register value */
};
static struct adc128_data *adc128_update_device(struct device *dev)
{
struct adc128_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
struct adc128_data *ret = data;
int i, rv;
mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
for (i = 0; i < num_inputs[data->mode]; i++) {
rv = i2c_smbus_read_word_swapped(client,
ADC128_REG_IN(i));
if (rv < 0)
goto abort;
data->in[0][i] = rv >> 4;
rv = i2c_smbus_read_byte_data(client,
ADC128_REG_IN_MIN(i));
if (rv < 0)
goto abort;
data->in[1][i] = rv << 4;
rv = i2c_smbus_read_byte_data(client,
ADC128_REG_IN_MAX(i));
if (rv < 0)
goto abort;
data->in[2][i] = rv << 4;
}
if (data->mode != 1) {
rv = i2c_smbus_read_word_swapped(client,
ADC128_REG_TEMP);
if (rv < 0)
goto abort;
data->temp[0] = rv >> 7;
rv = i2c_smbus_read_byte_data(client,
ADC128_REG_TEMP_MAX);
if (rv < 0)
goto abort;
data->temp[1] = rv << 1;
rv = i2c_smbus_read_byte_data(client,
ADC128_REG_TEMP_HYST);
if (rv < 0)
goto abort;
data->temp[2] = rv << 1;
}
rv = i2c_smbus_read_byte_data(client, ADC128_REG_ALARM);
if (rv < 0)
goto abort;
data->alarms |= rv;
data->last_updated = jiffies;
data->valid = true;
}
goto done;
abort:
ret = ERR_PTR(rv);
data->valid = false;
done:
mutex_unlock(&data->update_lock);
return ret;
}
static ssize_t adc128_in_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct adc128_data`, `function adc128_in_show`, `function adc128_in_store`, `function adc128_temp_show`, `function adc128_temp_store`, `function adc128_alarm_show`, `function adc128_is_visible`, `function adc128_detect`, `function adc128_init_client`, `function adc128_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.