drivers/hwmon/lm83.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/lm83.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/lm83.c- Extension
.c- Size
- 11607 bytes
- Lines
- 468
- 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/bits.hlinux/err.hlinux/i2c.hlinux/init.hlinux/hwmon.hlinux/module.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct lm83_dataenum chipsfunction lm83_regmap_reg_readfunction lm83_regmap_reg_writefunction lm83_regmap_is_volatilefunction lm83_temp_readfunction lm83_temp_writefunction lm83_chip_readfunction lm83_readfunction lm83_writefunction lm83_is_visiblefunction lm83_detectfunction lm83_probe
Annotated Snippet
struct lm83_data {
struct regmap *regmap;
enum chips type;
};
/* regmap code */
static int lm83_regmap_reg_read(void *context, unsigned int reg, unsigned int *val)
{
struct i2c_client *client = context;
int ret;
ret = i2c_smbus_read_byte_data(client, reg);
if (ret < 0)
return ret;
*val = ret;
return 0;
}
/*
* The regmap write function maps read register addresses to write register
* addresses. This is necessary for regmap register caching to work.
* An alternative would be to clear the regmap cache whenever a register is
* written, but that would be much more expensive.
*/
static int lm83_regmap_reg_write(void *context, unsigned int reg, unsigned int val)
{
struct i2c_client *client = context;
switch (reg) {
case LM83_REG_R_CONFIG:
case LM83_REG_R_LOCAL_HIGH:
case LM83_REG_R_REMOTE2_HIGH:
reg += 0x06;
break;
case LM83_REG_R_REMOTE1_HIGH:
case LM83_REG_R_REMOTE3_HIGH:
case LM83_REG_R_TCRIT:
reg += 0x18;
break;
default:
break;
}
return i2c_smbus_write_byte_data(client, reg, val);
}
static bool lm83_regmap_is_volatile(struct device *dev, unsigned int reg)
{
switch (reg) {
case LM83_REG_R_LOCAL_TEMP:
case LM83_REG_R_REMOTE1_TEMP:
case LM83_REG_R_REMOTE2_TEMP:
case LM83_REG_R_REMOTE3_TEMP:
case LM83_REG_R_STATUS1:
case LM83_REG_R_STATUS2:
return true;
default:
return false;
}
}
static const struct regmap_config lm83_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.cache_type = REGCACHE_MAPLE,
.volatile_reg = lm83_regmap_is_volatile,
.reg_read = lm83_regmap_reg_read,
.reg_write = lm83_regmap_reg_write,
};
/* hwmon API */
static int lm83_temp_read(struct device *dev, u32 attr, int channel, long *val)
{
struct lm83_data *data = dev_get_drvdata(dev);
unsigned int regval;
int err;
switch (attr) {
case hwmon_temp_input:
err = regmap_read(data->regmap, LM83_REG_TEMP[channel], ®val);
if (err < 0)
return err;
*val = (s8)regval * 1000;
break;
case hwmon_temp_max:
err = regmap_read(data->regmap, LM83_REG_MAX[channel], ®val);
if (err < 0)
Annotation
- Immediate include surface: `linux/bits.h`, `linux/err.h`, `linux/i2c.h`, `linux/init.h`, `linux/hwmon.h`, `linux/module.h`, `linux/regmap.h`, `linux/slab.h`.
- Detected declarations: `struct lm83_data`, `enum chips`, `function lm83_regmap_reg_read`, `function lm83_regmap_reg_write`, `function lm83_regmap_is_volatile`, `function lm83_temp_read`, `function lm83_temp_write`, `function lm83_chip_read`, `function lm83_read`, `function lm83_write`.
- 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.