drivers/iio/temperature/max31865.c
Source file repositories/reference/linux-study-clean/drivers/iio/temperature/max31865.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/temperature/max31865.c- Extension
.c- Size
- 7893 bytes
- Lines
- 352
- Domain
- Driver Families
- Bucket
- drivers/iio
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ctype.hlinux/delay.hlinux/err.hlinux/init.hlinux/mod_devicetable.hlinux/module.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/property.hlinux/spi/spi.hlinux/unaligned.h
Detected Declarations
struct max31865_datafunction max31865_readfunction max31865_writefunction enable_biasfunction disable_biasfunction max31865_rtd_readfunction max31865_read_rawfunction max31865_initfunction show_faultfunction show_fault_ovuvfunction show_filterfunction set_filterfunction max31865_probe
Annotated Snippet
struct max31865_data {
struct spi_device *spi;
struct mutex lock;
bool filter_50hz;
bool three_wire;
u8 buf[2] __aligned(IIO_DMA_MINALIGN);
};
static int max31865_read(struct max31865_data *data, u8 reg,
unsigned int read_size)
{
return spi_write_then_read(data->spi, ®, 1, data->buf, read_size);
}
static int max31865_write(struct max31865_data *data, size_t len)
{
return spi_write(data->spi, data->buf, len);
}
static int enable_bias(struct max31865_data *data)
{
u8 cfg;
int ret;
ret = max31865_read(data, MAX31865_CFG_REG, 1);
if (ret)
return ret;
cfg = data->buf[0];
data->buf[0] = MAX31865_CFG_REG | MAX31865_RD_WR_BIT;
data->buf[1] = cfg | MAX31865_CFG_VBIAS;
return max31865_write(data, 2);
}
static int disable_bias(struct max31865_data *data)
{
u8 cfg;
int ret;
ret = max31865_read(data, MAX31865_CFG_REG, 1);
if (ret)
return ret;
cfg = data->buf[0];
cfg &= ~MAX31865_CFG_VBIAS;
data->buf[0] = MAX31865_CFG_REG | MAX31865_RD_WR_BIT;
data->buf[1] = cfg;
return max31865_write(data, 2);
}
static int max31865_rtd_read(struct max31865_data *data, int *val)
{
u8 reg;
int ret;
/* Enable BIAS to start the conversion */
ret = enable_bias(data);
if (ret)
return ret;
/* wait 10.5ms before initiating the conversion */
msleep(11);
ret = max31865_read(data, MAX31865_CFG_REG, 1);
if (ret)
return ret;
reg = data->buf[0];
reg |= MAX31865_CFG_1SHOT | MAX31865_FAULT_STATUS_CLEAR;
data->buf[0] = MAX31865_CFG_REG | MAX31865_RD_WR_BIT;
data->buf[1] = reg;
ret = max31865_write(data, 2);
if (ret)
return ret;
if (data->filter_50hz) {
/* 50Hz filter mode requires 62.5ms to complete */
msleep(63);
} else {
/* 60Hz filter mode requires 52ms to complete */
msleep(52);
}
ret = max31865_read(data, MAX31865_RTD_MSB, 2);
if (ret)
Annotation
- Immediate include surface: `linux/ctype.h`, `linux/delay.h`, `linux/err.h`, `linux/init.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct max31865_data`, `function max31865_read`, `function max31865_write`, `function enable_bias`, `function disable_bias`, `function max31865_rtd_read`, `function max31865_read_raw`, `function max31865_init`, `function show_fault`, `function show_fault_ovuv`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.