drivers/hwmon/adt7310.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/adt7310.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/adt7310.c- Extension
.c- Size
- 3768 bytes
- Lines
- 165
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/init.hlinux/regmap.hlinux/spi/spi.hlinux/unaligned.hadt7x10.h
Detected Declarations
function adt7310_spi_read_wordfunction adt7310_spi_write_wordfunction adt7310_spi_read_bytefunction adt7310_spi_write_bytefunction adt7310_regmap_is_volatilefunction adt7310_reg_readfunction adt7310_reg_writefunction adt7310_spi_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* ADT7310/ADT7310 digital temperature sensor driver
*
* Copyright 2012-2013 Analog Devices Inc.
* Author: Lars-Peter Clausen <lars@metafoo.de>
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/regmap.h>
#include <linux/spi/spi.h>
#include <linux/unaligned.h>
#include "adt7x10.h"
#define ADT7310_STATUS 0
#define ADT7310_CONFIG 1
#define ADT7310_TEMPERATURE 2
#define ADT7310_ID 3
#define ADT7310_T_CRIT 4
#define ADT7310_T_HYST 5
#define ADT7310_T_ALARM_HIGH 6
#define ADT7310_T_ALARM_LOW 7
static const u8 adt7310_reg_table[] = {
[ADT7X10_TEMPERATURE] = ADT7310_TEMPERATURE,
[ADT7X10_STATUS] = ADT7310_STATUS,
[ADT7X10_CONFIG] = ADT7310_CONFIG,
[ADT7X10_T_ALARM_HIGH] = ADT7310_T_ALARM_HIGH,
[ADT7X10_T_ALARM_LOW] = ADT7310_T_ALARM_LOW,
[ADT7X10_T_CRIT] = ADT7310_T_CRIT,
[ADT7X10_T_HYST] = ADT7310_T_HYST,
[ADT7X10_ID] = ADT7310_ID,
};
#define ADT7310_CMD_REG_OFFSET 3
#define ADT7310_CMD_READ 0x40
#define AD7310_COMMAND(reg) (adt7310_reg_table[(reg)] << ADT7310_CMD_REG_OFFSET)
static int adt7310_spi_read_word(struct spi_device *spi, u8 reg)
{
return spi_w8r16be(spi, AD7310_COMMAND(reg) | ADT7310_CMD_READ);
}
static int adt7310_spi_write_word(struct spi_device *spi, u8 reg, u16 data)
{
u8 buf[3];
buf[0] = AD7310_COMMAND(reg);
put_unaligned_be16(data, &buf[1]);
return spi_write(spi, buf, sizeof(buf));
}
static int adt7310_spi_read_byte(struct spi_device *spi, u8 reg)
{
return spi_w8r8(spi, AD7310_COMMAND(reg) | ADT7310_CMD_READ);
}
static int adt7310_spi_write_byte(struct spi_device *spi, u8 reg, u8 data)
{
u8 buf[2];
buf[0] = AD7310_COMMAND(reg);
buf[1] = data;
return spi_write(spi, buf, sizeof(buf));
}
static bool adt7310_regmap_is_volatile(struct device *dev, unsigned int reg)
{
switch (reg) {
case ADT7X10_TEMPERATURE:
case ADT7X10_STATUS:
return true;
default:
return false;
}
}
static int adt7310_reg_read(void *context, unsigned int reg, unsigned int *val)
{
struct spi_device *spi = context;
int regval;
switch (reg) {
case ADT7X10_TEMPERATURE:
case ADT7X10_T_ALARM_HIGH:
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/regmap.h`, `linux/spi/spi.h`, `linux/unaligned.h`, `adt7x10.h`.
- Detected declarations: `function adt7310_spi_read_word`, `function adt7310_spi_write_word`, `function adt7310_spi_read_byte`, `function adt7310_spi_write_byte`, `function adt7310_regmap_is_volatile`, `function adt7310_reg_read`, `function adt7310_reg_write`, `function adt7310_spi_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.