drivers/hwmon/menf21bmc_hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/menf21bmc_hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/menf21bmc_hwmon.c- Extension
.c- Size
- 6499 bytes
- Lines
- 232
- 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/module.hlinux/kernel.hlinux/platform_device.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/jiffies.hlinux/slab.hlinux/i2c.hlinux/err.h
Detected Declarations
struct menf21bmc_hwmonfunction menf21bmc_hwmon_get_volt_limitsfunction label_showfunction in_showfunction min_showfunction max_showfunction menf21bmc_hwmon_probe
Annotated Snippet
struct menf21bmc_hwmon {
bool valid;
struct i2c_client *i2c_client;
unsigned long last_update;
int in_val[BMC_VOLT_COUNT];
int in_min[BMC_VOLT_COUNT];
int in_max[BMC_VOLT_COUNT];
};
static const char *const input_names[] = {
[MENF21BMC_V33] = "MON_3_3V",
[MENF21BMC_V5] = "MON_5V",
[MENF21BMC_V12] = "MON_12V",
[MENF21BMC_V5_SB] = "5V_STANDBY",
[MENF21BMC_VBAT] = "VBAT"
};
static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
{
int i;
int val;
struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
struct menf21bmc_hwmon *data_ret = drv_data;
if (time_after(jiffies, drv_data->last_update + HZ)
|| !drv_data->valid) {
for (i = 0; i < BMC_VOLT_COUNT; i++) {
val = i2c_smbus_read_word_data(drv_data->i2c_client,
IDX_TO_VOLT_INP_CMD(i));
if (val < 0) {
data_ret = ERR_PTR(val);
goto abort;
}
drv_data->in_val[i] = val;
}
drv_data->last_update = jiffies;
drv_data->valid = true;
}
abort:
return data_ret;
}
static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
{
int i, val;
for (i = 0; i < BMC_VOLT_COUNT; i++) {
val = i2c_smbus_read_word_data(drv_data->i2c_client,
IDX_TO_VOLT_MIN_CMD(i));
if (val < 0)
return val;
drv_data->in_min[i] = val;
val = i2c_smbus_read_word_data(drv_data->i2c_client,
IDX_TO_VOLT_MAX_CMD(i));
if (val < 0)
return val;
drv_data->in_max[i] = val;
}
return 0;
}
static ssize_t
label_show(struct device *dev, struct device_attribute *devattr, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
return sprintf(buf, "%s\n", input_names[attr->index]);
}
static ssize_t
in_show(struct device *dev, struct device_attribute *devattr, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct menf21bmc_hwmon *drv_data = menf21bmc_hwmon_update(dev);
if (IS_ERR(drv_data))
return PTR_ERR(drv_data);
return sprintf(buf, "%d\n", drv_data->in_val[attr->index]);
}
static ssize_t
min_show(struct device *dev, struct device_attribute *devattr, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/platform_device.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/jiffies.h`, `linux/slab.h`, `linux/i2c.h`.
- Detected declarations: `struct menf21bmc_hwmon`, `function menf21bmc_hwmon_get_volt_limits`, `function label_show`, `function in_show`, `function min_show`, `function max_show`, `function menf21bmc_hwmon_probe`.
- 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.