drivers/hwmon/max1668.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/max1668.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/max1668.c- Extension
.c- Size
- 7985 bytes
- Lines
- 320
- 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/bitops.hlinux/bits.hlinux/err.hlinux/hwmon.hlinux/i2c.hlinux/init.hlinux/module.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct max1668_datafunction max1668_readfunction max1668_writefunction max1668_is_visiblefunction max1668_detectfunction max1668_reg_readfunction max1668_reg_writefunction max1668_regmap_is_volatilefunction max1668_regmap_is_writeablefunction max1668_probe
Annotated Snippet
struct max1668_data {
struct regmap *regmap;
int channels;
};
static int max1668_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
struct max1668_data *data = dev_get_drvdata(dev);
struct regmap *regmap = data->regmap;
u32 regs[2] = { MAX1668_REG_STAT1, MAX1668_REG_TEMP(channel) };
u8 regvals[2];
u32 regval;
int ret;
switch (attr) {
case hwmon_temp_input:
ret = regmap_read(regmap, MAX1668_REG_TEMP(channel), ®val);
if (ret)
return ret;
*val = sign_extend32(regval, 7) * 1000;
break;
case hwmon_temp_min:
ret = regmap_read(regmap, MAX1668_REG_LIML(channel), ®val);
if (ret)
return ret;
*val = sign_extend32(regval, 7) * 1000;
break;
case hwmon_temp_max:
ret = regmap_read(regmap, MAX1668_REG_LIMH(channel), ®val);
if (ret)
return ret;
*val = sign_extend32(regval, 7) * 1000;
break;
case hwmon_temp_min_alarm:
ret = regmap_read(regmap,
channel ? MAX1668_REG_STAT2 : MAX1668_REG_STAT1,
®val);
if (ret)
return ret;
if (channel)
*val = !!(regval & BIT(9 - channel * 2));
else
*val = !!(regval & BIT(5));
break;
case hwmon_temp_max_alarm:
ret = regmap_read(regmap,
channel ? MAX1668_REG_STAT2 : MAX1668_REG_STAT1,
®val);
if (ret)
return ret;
if (channel)
*val = !!(regval & BIT(8 - channel * 2));
else
*val = !!(regval & BIT(6));
break;
case hwmon_temp_fault:
ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret)
return ret;
*val = !!((regvals[0] & BIT(4)) && regvals[1] == 127);
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
static int max1668_write(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long val)
{
struct max1668_data *data = dev_get_drvdata(dev);
struct regmap *regmap = data->regmap;
val = clamp_val(val / 1000, -128, 127);
switch (attr) {
case hwmon_temp_min:
return regmap_write(regmap, MAX1668_REG_LIML(channel), val);
case hwmon_temp_max:
return regmap_write(regmap, MAX1668_REG_LIMH(channel), val);
default:
return -EOPNOTSUPP;
}
}
static umode_t max1668_is_visible(const void *_data, enum hwmon_sensor_types type,
u32 attr, int channel)
{
const struct max1668_data *data = _data;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/bits.h`, `linux/err.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/init.h`, `linux/module.h`, `linux/regmap.h`.
- Detected declarations: `struct max1668_data`, `function max1668_read`, `function max1668_write`, `function max1668_is_visible`, `function max1668_detect`, `function max1668_reg_read`, `function max1668_reg_write`, `function max1668_regmap_is_volatile`, `function max1668_regmap_is_writeable`, `function max1668_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.