drivers/hwmon/ltc2990.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/ltc2990.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/ltc2990.c- Extension
.c- Size
- 7462 bytes
- Lines
- 280
- 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/err.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/i2c.hlinux/kernel.hlinux/module.hlinux/property.h
Detected Declarations
struct ltc2990_datafunction ltc2990_get_valuefunction ltc2990_value_showfunction ltc2990_attrs_visiblefunction ltc2990_i2c_probe
Annotated Snippet
struct ltc2990_data {
struct i2c_client *i2c;
u32 mode[2];
};
/* Return the converted value from the given register in uV or mC */
static int ltc2990_get_value(struct i2c_client *i2c, int index, int *result)
{
int val;
u8 reg;
switch (index) {
case LTC2990_IN0:
reg = LTC2990_VCC_MSB;
break;
case LTC2990_IN1:
case LTC2990_CURR1:
case LTC2990_TEMP2:
reg = LTC2990_V1_MSB;
break;
case LTC2990_IN2:
reg = LTC2990_V2_MSB;
break;
case LTC2990_IN3:
case LTC2990_CURR2:
case LTC2990_TEMP3:
reg = LTC2990_V3_MSB;
break;
case LTC2990_IN4:
reg = LTC2990_V4_MSB;
break;
case LTC2990_TEMP1:
reg = LTC2990_TINT_MSB;
break;
default:
return -EINVAL;
}
val = i2c_smbus_read_word_swapped(i2c, reg);
if (unlikely(val < 0))
return val;
switch (index) {
case LTC2990_TEMP1:
case LTC2990_TEMP2:
case LTC2990_TEMP3:
/* temp, 0.0625 degrees/LSB */
*result = sign_extend32(val, 12) * 1000 / 16;
break;
case LTC2990_CURR1:
case LTC2990_CURR2:
/* Vx-Vy, 19.42uV/LSB */
*result = sign_extend32(val, 14) * 1942 / 100;
break;
case LTC2990_IN0:
/* Vcc, 305.18uV/LSB, 2.5V offset */
*result = sign_extend32(val, 14) * 30518 / (100 * 1000) + 2500;
break;
case LTC2990_IN1:
case LTC2990_IN2:
case LTC2990_IN3:
case LTC2990_IN4:
/* Vx, 305.18uV/LSB */
*result = sign_extend32(val, 14) * 30518 / (100 * 1000);
break;
default:
return -EINVAL; /* won't happen, keep compiler happy */
}
return 0;
}
static ssize_t ltc2990_value_show(struct device *dev,
struct device_attribute *da, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct ltc2990_data *data = dev_get_drvdata(dev);
int value;
int ret;
ret = ltc2990_get_value(data->i2c, attr->index, &value);
if (unlikely(ret < 0))
return ret;
return sysfs_emit(buf, "%d\n", value);
}
static umode_t ltc2990_attrs_visible(struct kobject *kobj,
struct attribute *a, int n)
{
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/err.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/i2c.h`, `linux/kernel.h`, `linux/module.h`, `linux/property.h`.
- Detected declarations: `struct ltc2990_data`, `function ltc2990_get_value`, `function ltc2990_value_show`, `function ltc2990_attrs_visible`, `function ltc2990_i2c_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.