drivers/hwmon/emc1403.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/emc1403.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/emc1403.c- Extension
.c- Size
- 17294 bytes
- Lines
- 701
- 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/init.hlinux/slab.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/sysfs.hlinux/regmap.hlinux/util_macros.h
Detected Declarations
struct thermal_dataenum emc1403_chipenum emc1403_reg_mapfunction power_state_showfunction power_state_storefunction emc1403_detectfunction emc1403_regmap_is_volatilefunction emc1403_get_tempfunction emc1403_get_hystfunction emc1403_temp_readfunction emc1403_get_convratefunction emc1403_chip_readfunction emc1403_readfunction emc1403_set_hystfunction emc1403_set_tempfunction emc1403_temp_writefunction emc1403_set_convratefunction emc1403_chip_writefunction emc1403_writefunction emc1403_temp_is_visiblefunction emc1403_chip_is_visiblefunction emc1403_is_visiblefunction emc1403_probe
Annotated Snippet
struct thermal_data {
enum emc1403_chip chip;
struct regmap *regmap;
};
static ssize_t power_state_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct thermal_data *data = dev_get_drvdata(dev);
unsigned int val;
int retval;
retval = regmap_read(data->regmap, 0x03, &val);
if (retval < 0)
return retval;
return sysfs_emit(buf, "%d\n", !!(val & BIT(6)));
}
static ssize_t power_state_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct thermal_data *data = dev_get_drvdata(dev);
unsigned long val;
int retval;
if (kstrtoul(buf, 10, &val))
return -EINVAL;
retval = regmap_update_bits(data->regmap, 0x03, BIT(6),
val ? BIT(6) : 0);
if (retval < 0)
return retval;
return count;
}
static DEVICE_ATTR_RW(power_state);
static struct attribute *emc1403_attrs[] = {
&dev_attr_power_state.attr,
NULL
};
ATTRIBUTE_GROUPS(emc1403);
static int emc1403_detect(struct i2c_client *client,
struct i2c_board_info *info)
{
int id;
/* Check if thermal chip is SMSC and EMC1403 or EMC1423 */
id = i2c_smbus_read_byte_data(client, THERMAL_SMSC_ID_REG);
if (id != 0x5d)
return -ENODEV;
id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG);
switch (id) {
case 0x20:
strscpy(info->type, "emc1402", I2C_NAME_SIZE);
break;
case 0x21:
strscpy(info->type, "emc1403", I2C_NAME_SIZE);
break;
case 0x22:
strscpy(info->type, "emc1422", I2C_NAME_SIZE);
break;
case 0x23:
strscpy(info->type, "emc1423", I2C_NAME_SIZE);
break;
case 0x25:
strscpy(info->type, "emc1404", I2C_NAME_SIZE);
break;
case 0x27:
strscpy(info->type, "emc1424", I2C_NAME_SIZE);
break;
case 0x29:
strscpy(info->type, "emc1428", I2C_NAME_SIZE);
break;
case 0x59:
strscpy(info->type, "emc1438", I2C_NAME_SIZE);
break;
case 0x60:
strscpy(info->type, "emc1442", I2C_NAME_SIZE);
break;
default:
return -ENODEV;
}
id = i2c_smbus_read_byte_data(client, THERMAL_REVISION_REG);
if (id < 0x01 || id > 0x04)
return -ENODEV;
return 0;
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`, `linux/sysfs.h`.
- Detected declarations: `struct thermal_data`, `enum emc1403_chip`, `enum emc1403_reg_map`, `function power_state_show`, `function power_state_store`, `function emc1403_detect`, `function emc1403_regmap_is_volatile`, `function emc1403_get_temp`, `function emc1403_get_hyst`, `function emc1403_temp_read`.
- 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.