drivers/iio/pressure/ms5611_spi.c
Source file repositories/reference/linux-study-clean/drivers/iio/pressure/ms5611_spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/pressure/ms5611_spi.c- Extension
.c- Size
- 3109 bytes
- Lines
- 137
- 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/delay.hlinux/module.hlinux/spi/spi.hlinux/mod_devicetable.hlinux/unaligned.hms5611.h
Detected Declarations
function driverfunction ms5611_spi_read_prom_wordfunction ms5611_spi_read_adcfunction ms5611_spi_read_adc_temp_and_pressurefunction ms5611_spi_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* MS5611 pressure and temperature sensor driver (SPI bus)
*
* Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
*
*/
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/spi/spi.h>
#include <linux/mod_devicetable.h>
#include <linux/unaligned.h>
#include "ms5611.h"
static int ms5611_spi_reset(struct ms5611_state *st)
{
u8 cmd = MS5611_RESET;
return spi_write_then_read(st->client, &cmd, 1, NULL, 0);
}
static int ms5611_spi_read_prom_word(struct ms5611_state *st, int index,
u16 *word)
{
int ret;
ret = spi_w8r16be(st->client, MS5611_READ_PROM_WORD + (index << 1));
if (ret < 0)
return ret;
*word = ret;
return 0;
}
static int ms5611_spi_read_adc(struct ms5611_state *st, s32 *val)
{
int ret;
u8 buf[3] = { MS5611_READ_ADC };
ret = spi_write_then_read(st->client, buf, 1, buf, 3);
if (ret < 0)
return ret;
*val = get_unaligned_be24(&buf[0]);
return 0;
}
static int ms5611_spi_read_adc_temp_and_pressure(struct ms5611_state *st,
s32 *temp, s32 *pressure)
{
int ret;
const struct ms5611_osr *osr = st->temp_osr;
/*
* Warning: &osr->cmd MUST be aligned on a word boundary since used as
* 2nd argument (void*) of spi_write_then_read.
*/
ret = spi_write_then_read(st->client, &osr->cmd, 1, NULL, 0);
if (ret < 0)
return ret;
usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL));
ret = ms5611_spi_read_adc(st, temp);
if (ret < 0)
return ret;
osr = st->pressure_osr;
ret = spi_write_then_read(st->client, &osr->cmd, 1, NULL, 0);
if (ret < 0)
return ret;
usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL));
return ms5611_spi_read_adc(st, pressure);
}
static int ms5611_spi_probe(struct spi_device *spi)
{
int ret;
struct ms5611_state *st;
struct iio_dev *indio_dev;
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (!indio_dev)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/module.h`, `linux/spi/spi.h`, `linux/mod_devicetable.h`, `linux/unaligned.h`, `ms5611.h`.
- Detected declarations: `function driver`, `function ms5611_spi_read_prom_word`, `function ms5611_spi_read_adc`, `function ms5611_spi_read_adc_temp_and_pressure`, `function ms5611_spi_probe`.
- 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.