drivers/hwmon/adt7411.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/adt7411.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/adt7411.c- Extension
.c- Size
- 17526 bytes
- Lines
- 694
- 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.
- 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/kernel.hlinux/module.hlinux/init.hlinux/err.hlinux/jiffies.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/slab.h
Detected Declarations
struct adt7411_datafunction containingfunction adt7411_modify_bitfunction adt7411_show_bitfunction adt7411_set_bitfunction scoped_guardfunction adt7411_read_in_alarmfunction adt7411_read_in_vddfunction adt7411_update_vreffunction adt7411_read_in_chanfunction adt7411_read_infunction adt7411_read_temp_alarmfunction adt7411_read_tempfunction adt7411_readfunction adt7411_write_in_vddfunction adt7411_write_in_chanfunction adt7411_write_infunction adt7411_write_tempfunction adt7411_writefunction adt7411_is_visiblefunction adt7411_detectfunction adt7411_init_devicefunction adt7411_probe
Annotated Snippet
struct adt7411_data {
unsigned long next_update;
long vref_cached;
struct i2c_client *client;
bool use_ext_temp;
};
/*
* When reading a register containing (up to 4) lsb, all associated
* msb-registers get locked by the hardware. After _one_ of those msb is read,
* _all_ are unlocked.
*/
static int adt7411_read_10_bit(struct i2c_client *client, u8 lsb_reg,
u8 msb_reg, u8 lsb_shift)
{
int val, tmp;
val = i2c_smbus_read_byte_data(client, lsb_reg);
if (val < 0)
return val;
tmp = (val >> lsb_shift) & 3;
val = i2c_smbus_read_byte_data(client, msb_reg);
if (val < 0)
return val;
val = (val << 2) | tmp;
return val;
}
static int adt7411_modify_bit(struct i2c_client *client, u8 reg, u8 bit,
bool flag)
{
int ret, val;
ret = i2c_smbus_read_byte_data(client, reg);
if (ret < 0)
return ret;
if (flag)
val = ret | bit;
else
val = ret & ~bit;
return i2c_smbus_write_byte_data(client, reg, val);
}
static ssize_t adt7411_show_bit(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr);
struct adt7411_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
int ret = i2c_smbus_read_byte_data(client, attr2->index);
return ret < 0 ? ret : sprintf(buf, "%u\n", !!(ret & attr2->nr));
}
static ssize_t adt7411_set_bit(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
struct sensor_device_attribute_2 *s_attr2 = to_sensor_dev_attr_2(attr);
struct adt7411_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
int ret;
unsigned long flag;
ret = kstrtoul(buf, 0, &flag);
if (ret || flag > 1)
return -EINVAL;
scoped_guard(hwmon_lock, dev) {
ret = adt7411_modify_bit(client, s_attr2->index, s_attr2->nr, flag);
/* force update */
data->next_update = jiffies;
}
return ret < 0 ? ret : count;
}
#define ADT7411_BIT_ATTR(__name, __reg, __bit) \
SENSOR_DEVICE_ATTR_2(__name, S_IRUGO | S_IWUSR, adt7411_show_bit, \
adt7411_set_bit, __bit, __reg)
static ADT7411_BIT_ATTR(no_average, ADT7411_REG_CFG2, ADT7411_CFG2_DISABLE_AVG);
static ADT7411_BIT_ATTR(fast_sampling, ADT7411_REG_CFG3, ADT7411_CFG3_ADC_CLK_225);
static ADT7411_BIT_ATTR(adc_ref_vdd, ADT7411_REG_CFG3, ADT7411_CFG3_REF_VDD);
static struct attribute *adt7411_attrs[] = {
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/init.h`, `linux/err.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`.
- Detected declarations: `struct adt7411_data`, `function containing`, `function adt7411_modify_bit`, `function adt7411_show_bit`, `function adt7411_set_bit`, `function scoped_guard`, `function adt7411_read_in_alarm`, `function adt7411_read_in_vdd`, `function adt7411_update_vref`, `function adt7411_read_in_chan`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.