drivers/hwmon/ad7314.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/ad7314.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/ad7314.c- Extension
.c- Size
- 3373 bytes
- Lines
- 145
- 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/device.hlinux/kernel.hlinux/slab.hlinux/sysfs.hlinux/spi/spi.hlinux/module.hlinux/err.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/bitops.h
Detected Declarations
struct ad7314_dataenum ad7314_variantfunction ad7314_spi_readfunction ad7314_temperature_showfunction ad7314_probe
Annotated Snippet
struct ad7314_data {
struct spi_device *spi_dev;
u16 rx ____cacheline_aligned;
};
static int ad7314_spi_read(struct ad7314_data *chip)
{
int ret;
ret = spi_read(chip->spi_dev, (u8 *)&chip->rx, sizeof(chip->rx));
if (ret < 0) {
dev_err(&chip->spi_dev->dev, "SPI read error\n");
return ret;
}
return be16_to_cpu(chip->rx);
}
static ssize_t ad7314_temperature_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct ad7314_data *chip = dev_get_drvdata(dev);
s16 data;
int ret;
ret = ad7314_spi_read(chip);
if (ret < 0)
return ret;
switch (spi_get_device_id(chip->spi_dev)->driver_data) {
case ad7314:
if (ret & AD7314_LEADING_ZEROS_MASK) {
/* Invalid read-out, leading zero part is missing */
return -EIO;
}
data = (ret & AD7314_TEMP_MASK) >> AD7314_TEMP_SHIFT;
data = sign_extend32(data, 9);
return sprintf(buf, "%d\n", 250 * data);
case adt7301:
case adt7302:
if (ret & ADT7301_LEADING_ZEROS_MASK) {
/* Invalid read-out, leading zero part is missing */
return -EIO;
}
/*
* Documented as a 13 bit twos complement register
* with a sign bit - which is a 14 bit 2's complement
* register. 1lsb - 31.25 milli degrees centigrade
*/
data = ret & ADT7301_TEMP_MASK;
data = sign_extend32(data, 13);
return sprintf(buf, "%d\n",
DIV_ROUND_CLOSEST(data * 3125, 100));
default:
return -EINVAL;
}
}
static SENSOR_DEVICE_ATTR_RO(temp1_input, ad7314_temperature, 0);
static struct attribute *ad7314_attrs[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr,
NULL,
};
ATTRIBUTE_GROUPS(ad7314);
static int ad7314_probe(struct spi_device *spi_dev)
{
struct ad7314_data *chip;
struct device *hwmon_dev;
chip = devm_kzalloc(&spi_dev->dev, sizeof(*chip), GFP_KERNEL);
if (chip == NULL)
return -ENOMEM;
chip->spi_dev = spi_dev;
hwmon_dev = devm_hwmon_device_register_with_groups(&spi_dev->dev,
spi_dev->modalias,
chip, ad7314_groups);
return PTR_ERR_OR_ZERO(hwmon_dev);
}
static const struct spi_device_id ad7314_id[] = {
{ "adt7301", adt7301 },
{ "adt7302", adt7302 },
{ "ad7314", ad7314 },
{ }
Annotation
- Immediate include surface: `linux/device.h`, `linux/kernel.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/spi/spi.h`, `linux/module.h`, `linux/err.h`, `linux/hwmon.h`.
- Detected declarations: `struct ad7314_data`, `enum ad7314_variant`, `function ad7314_spi_read`, `function ad7314_temperature_show`, `function ad7314_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.