drivers/iio/temperature/max31856.c
Source file repositories/reference/linux-study-clean/drivers/iio/temperature/max31856.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/temperature/max31856.c- Extension
.c- Size
- 12325 bytes
- Lines
- 490
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ctype.hlinux/mod_devicetable.hlinux/module.hlinux/init.hlinux/err.hlinux/property.hlinux/spi/spi.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/util_macros.hlinux/unaligned.hdt-bindings/iio/temperature/thermocouple.h
Detected Declarations
struct max31856_datafunction max31856_readfunction max31856_writefunction max31856_initfunction max31856_thermocouple_readfunction max31856_read_rawfunction max31856_write_raw_get_fmtfunction max31856_write_rawfunction show_faultfunction show_fault_ovuvfunction show_fault_ocfunction show_filterfunction set_filterfunction max31856_probe
Annotated Snippet
struct max31856_data {
struct spi_device *spi;
u32 thermocouple_type;
bool filter_50hz;
int averaging;
};
static const char max31856_tc_types[] = {
'B', 'E', 'J', 'K', 'N', 'R', 'S', 'T'
};
static int max31856_read(struct max31856_data *data, u8 reg,
u8 val[], unsigned int read_size)
{
return spi_write_then_read(data->spi, ®, 1, val, read_size);
}
static int max31856_write(struct max31856_data *data, u8 reg,
unsigned int val)
{
u8 buf[2];
buf[0] = reg | (MAX31856_RD_WR_BIT);
buf[1] = val;
return spi_write(data->spi, buf, 2);
}
static int max31856_init(struct max31856_data *data)
{
int ret;
u8 reg_cr0_val, reg_cr1_val;
/* Start by changing to Off mode before making changes as
* some settings are recommended to be set only when the device
* is off
*/
ret = max31856_read(data, MAX31856_CR0_REG, ®_cr0_val, 1);
if (ret)
return ret;
reg_cr0_val &= ~MAX31856_CR0_AUTOCONVERT;
ret = max31856_write(data, MAX31856_CR0_REG, reg_cr0_val);
if (ret)
return ret;
/* Set thermocouple type based on dts property */
ret = max31856_read(data, MAX31856_CR1_REG, ®_cr1_val, 1);
if (ret)
return ret;
reg_cr1_val &= ~MAX31856_TC_TYPE_MASK;
reg_cr1_val |= data->thermocouple_type;
reg_cr1_val &= ~MAX31856_AVERAGING_MASK;
reg_cr1_val |= data->averaging << MAX31856_AVERAGING_SHIFT;
ret = max31856_write(data, MAX31856_CR1_REG, reg_cr1_val);
if (ret)
return ret;
/*
* Enable Open circuit fault detection
* Read datasheet for more information: Table 4.
* Value 01 means : Enabled (Once every 16 conversions)
*/
reg_cr0_val &= ~MAX31856_CR0_OCFAULT_MASK;
reg_cr0_val |= MAX31856_CR0_OCFAULT;
/* Set Auto Conversion Mode */
reg_cr0_val &= ~MAX31856_CR0_1SHOT;
reg_cr0_val |= MAX31856_CR0_AUTOCONVERT;
if (data->filter_50hz)
reg_cr0_val |= MAX31856_CR0_FILTER_50HZ;
else
reg_cr0_val &= ~MAX31856_CR0_FILTER_50HZ;
return max31856_write(data, MAX31856_CR0_REG, reg_cr0_val);
}
static int max31856_thermocouple_read(struct max31856_data *data,
struct iio_chan_spec const *chan,
int *val)
{
int ret, offset_cjto;
u8 reg_val[3];
switch (chan->channel2) {
case IIO_NO_MOD:
Annotation
- Immediate include surface: `linux/ctype.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/init.h`, `linux/err.h`, `linux/property.h`, `linux/spi/spi.h`, `linux/iio/iio.h`.
- Detected declarations: `struct max31856_data`, `function max31856_read`, `function max31856_write`, `function max31856_init`, `function max31856_thermocouple_read`, `function max31856_read_raw`, `function max31856_write_raw_get_fmt`, `function max31856_write_raw`, `function show_fault`, `function show_fault_ovuv`.
- Atlas domain: Driver Families / drivers/iio.
- 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.