drivers/iio/pressure/bmp280-spi.c
Source file repositories/reference/linux-study-clean/drivers/iio/pressure/bmp280-spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/pressure/bmp280-spi.c- Extension
.c- Size
- 4065 bytes
- Lines
- 146
- 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/bits.hlinux/err.hlinux/module.hlinux/regmap.hlinux/spi/spi.hbmp280.h
Detected Declarations
function bmp280_regmap_spi_writefunction bmp280_regmap_spi_readfunction bmp380_regmap_spi_readfunction bmp280_spi_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* SPI interface for the BMP280 driver
*
* Inspired by the older BMP085 driver drivers/misc/bmp085-spi.c
*/
#include <linux/bits.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/spi/spi.h>
#include "bmp280.h"
static int bmp280_regmap_spi_write(void *context, const void *data,
size_t count)
{
struct spi_device *spi = to_spi_device(context);
u8 buf[2];
memcpy(buf, data, 2);
/*
* The SPI register address (= full register address without bit 7) and
* the write command (bit7 = RW = '0')
*/
buf[0] &= ~0x80;
return spi_write_then_read(spi, buf, 2, NULL, 0);
}
static int bmp280_regmap_spi_read(void *context, const void *reg,
size_t reg_size, void *val, size_t val_size)
{
struct spi_device *spi = to_spi_device(context);
return spi_write_then_read(spi, reg, reg_size, val, val_size);
}
static int bmp380_regmap_spi_read(void *context, const void *reg,
size_t reg_size, void *val, size_t val_size)
{
struct spi_device *spi = to_spi_device(context);
u8 rx_buf[BME280_BURST_READ_BYTES + 1];
ssize_t status;
if (val_size > BME280_BURST_READ_BYTES)
return -EINVAL;
/*
* According to the BMP3xx datasheets, for a basic SPI read operation,
* the first byte needs to be dropped and the rest are the requested
* data.
*/
status = spi_write_then_read(spi, reg, 1, rx_buf, val_size + 1);
if (status)
return status;
memcpy(val, rx_buf + 1, val_size);
return 0;
}
static const struct regmap_bus bmp280_regmap_bus = {
.write = bmp280_regmap_spi_write,
.read = bmp280_regmap_spi_read,
.reg_format_endian_default = REGMAP_ENDIAN_BIG,
.val_format_endian_default = REGMAP_ENDIAN_BIG,
};
static const struct regmap_bus bmp380_regmap_bus = {
.write = bmp280_regmap_spi_write,
.read = bmp380_regmap_spi_read,
.read_flag_mask = BIT(7),
.reg_format_endian_default = REGMAP_ENDIAN_BIG,
.val_format_endian_default = REGMAP_ENDIAN_BIG,
};
static int bmp280_spi_probe(struct spi_device *spi)
{
const struct spi_device_id *id = spi_get_device_id(spi);
const struct bmp280_chip_info *chip_info;
struct regmap_bus const *bmp_regmap_bus;
struct regmap *regmap;
chip_info = spi_get_device_match_data(spi);
if (chip_info->spi_read_extra_byte)
bmp_regmap_bus = &bmp380_regmap_bus;
else
bmp_regmap_bus = &bmp280_regmap_bus;
Annotation
- Immediate include surface: `linux/bits.h`, `linux/err.h`, `linux/module.h`, `linux/regmap.h`, `linux/spi/spi.h`, `bmp280.h`.
- Detected declarations: `function bmp280_regmap_spi_write`, `function bmp280_regmap_spi_read`, `function bmp380_regmap_spi_read`, `function bmp280_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.