drivers/hwmon/amc6821.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/amc6821.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/amc6821.c- Extension
.c- Size
- 28000 bytes
- Lines
- 1121
- 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/bitfield.hlinux/bitops.hlinux/bits.hlinux/err.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/i2c.hlinux/init.hlinux/minmax.hlinux/module.hlinux/mutex.hlinux/of_platform.hlinux/pwm.hlinux/regmap.hlinux/slab.hlinux/thermal.hdt-bindings/pwm/pwm.h
Detected Declarations
struct amc6821_datafunction amc6821_get_auto_point_tempsfunction amc6821_temp_read_valuesfunction amc6821_read_alarmsfunction amc6821_temp_readfunction amc6821_temp_writefunction amc6821_pwm_readfunction amc6821_pwm_writefunction amc6821_fan_read_rpmfunction amc6821_fan_readfunction amc6821_fan_writefunction temp_auto_point_temp_showfunction pwm1_auto_point_pwm_showfunction set_slope_registerfunction temp_auto_point_temp_storefunction pwm1_auto_point_pwm_storefunction amc6821_readfunction amc6821_writefunction amc6821_is_visiblefunction amc6821_set_sw_dcyfunction amc6821_get_max_statefunction amc6821_get_cur_statefunction amc6821_set_cur_statefunction amc6821_detectfunction amc6821_pwm_polarityfunction amc6821_of_fan_read_datafunction amc6821_init_clientfunction amc6821_volatile_regfunction amc6821_probe
Annotated Snippet
struct amc6821_data {
struct regmap *regmap;
struct mutex update_lock;
unsigned long fan_state;
unsigned long fan_max_state;
unsigned int *fan_cooling_levels;
enum pwm_polarity pwm_polarity;
};
/*
* Return 0 on success or negative error code.
*
* temps returns set of three temperatures, in °C:
* temps[0]: Passive cooling temperature, applies to both channels
* temps[1]: Low temperature, start slope calculations
* temps[2]: High temperature
*
* Channel 0: local, channel 1: remote.
*/
static int amc6821_get_auto_point_temps(struct regmap *regmap, int channel, u8 *temps)
{
u32 regs[] = {
AMC6821_REG_DCY_LOW_TEMP,
AMC6821_REG_PSV_TEMP,
channel ? AMC6821_REG_RTEMP_FAN_CTRL : AMC6821_REG_LTEMP_FAN_CTRL
};
u8 regvals[3];
int slope;
int err;
err = regmap_multi_reg_read(regmap, regs, regvals, 3);
if (err)
return err;
temps[0] = regvals[1];
temps[1] = FIELD_GET(AMC6821_TEMP_LIMIT_MASK, regvals[2]) * 4;
/* slope is 32 >> <slope bits> in °C */
slope = 32 >> FIELD_GET(AMC6821_TEMP_SLOPE_MASK, regvals[2]);
if (slope)
temps[2] = temps[1] + DIV_ROUND_CLOSEST(255 - regvals[0], slope);
else
temps[2] = 255;
return 0;
}
static int amc6821_temp_read_values(struct regmap *regmap, u32 attr, int channel, long *val)
{
int reg, err;
u32 regval;
switch (attr) {
case hwmon_temp_input:
reg = channel ? AMC6821_REG_RTEMP_HI : AMC6821_REG_LTEMP_HI;
break;
case hwmon_temp_min:
reg = channel ? AMC6821_REG_RTEMP_LIMIT_MIN : AMC6821_REG_LTEMP_LIMIT_MIN;
break;
case hwmon_temp_max:
reg = channel ? AMC6821_REG_RTEMP_LIMIT_MAX : AMC6821_REG_LTEMP_LIMIT_MAX;
break;
case hwmon_temp_crit:
reg = channel ? AMC6821_REG_RTEMP_CRIT : AMC6821_REG_LTEMP_CRIT;
break;
default:
return -EOPNOTSUPP;
}
err = regmap_read(regmap, reg, ®val);
if (err)
return err;
*val = sign_extend32(regval, 7) * 1000;
return 0;
}
static int amc6821_read_alarms(struct regmap *regmap, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
int reg, mask, err;
u32 regval;
switch (type) {
case hwmon_temp:
switch (attr) {
case hwmon_temp_min_alarm:
reg = AMC6821_REG_STAT1;
mask = channel ? AMC6821_STAT1_RTL : AMC6821_STAT1_LTL;
break;
case hwmon_temp_max_alarm:
reg = AMC6821_REG_STAT1;
mask = channel ? AMC6821_STAT1_RTH : AMC6821_STAT1_LTH;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bitops.h`, `linux/bits.h`, `linux/err.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/i2c.h`, `linux/init.h`.
- Detected declarations: `struct amc6821_data`, `function amc6821_get_auto_point_temps`, `function amc6821_temp_read_values`, `function amc6821_read_alarms`, `function amc6821_temp_read`, `function amc6821_temp_write`, `function amc6821_pwm_read`, `function amc6821_pwm_write`, `function amc6821_fan_read_rpm`, `function amc6821_fan_read`.
- 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.