drivers/iio/imu/bmi270/bmi270_spi.c
Source file repositories/reference/linux-study-clean/drivers/iio/imu/bmi270/bmi270_spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/imu/bmi270/bmi270_spi.c- Extension
.c- Size
- 2456 bytes
- Lines
- 95
- 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/iio/iio.hlinux/mod_devicetable.hlinux/module.hlinux/pm.hlinux/regmap.hlinux/spi/spi.hbmi270.h
Detected Declarations
function bmi270_regmap_spi_readfunction bmi270_regmap_spi_writefunction bmi270_spi_probe
Annotated Snippet
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
#include <linux/iio/iio.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/spi/spi.h>
#include "bmi270.h"
/*
* The following two functions are taken from the BMI323 spi driver code.
* In section 6.4 of the BMI270 data it specifies that after a read
* operation the first data byte from the device is a dummy byte
*/
static int bmi270_regmap_spi_read(void *spi, const void *reg_buf,
size_t reg_size, void *val_buf,
size_t val_size)
{
return spi_write_then_read(spi, reg_buf, reg_size, val_buf, val_size);
}
static int bmi270_regmap_spi_write(void *spi, const void *data,
size_t count)
{
u8 *data_buff = (u8 *)data;
/*
* Remove the extra pad byte since its only needed for the read
* operation
*/
data_buff[1] = data_buff[0];
return spi_write_then_read(spi, data_buff + 1, count - 1, NULL, 0);
}
static const struct regmap_bus bmi270_regmap_bus = {
.read = bmi270_regmap_spi_read,
.write = bmi270_regmap_spi_write,
};
static const struct regmap_config bmi270_spi_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.pad_bits = 8,
.read_flag_mask = BIT(7),
};
static int bmi270_spi_probe(struct spi_device *spi)
{
struct regmap *regmap;
struct device *dev = &spi->dev;
const struct bmi270_chip_info *chip_info;
chip_info = spi_get_device_match_data(spi);
if (!chip_info)
return -ENODEV;
regmap = devm_regmap_init(dev, &bmi270_regmap_bus, dev,
&bmi270_spi_regmap_config);
if (IS_ERR(regmap))
return dev_err_probe(dev, PTR_ERR(regmap),
"Failed to init spi regmap\n");
return bmi270_core_probe(dev, regmap, chip_info);
}
static const struct spi_device_id bmi270_spi_id[] = {
{ "bmi260", (kernel_ulong_t)&bmi260_chip_info },
{ "bmi270", (kernel_ulong_t)&bmi270_chip_info },
{ }
};
static const struct of_device_id bmi270_of_match[] = {
{ .compatible = "bosch,bmi260", .data = &bmi260_chip_info },
{ .compatible = "bosch,bmi270", .data = &bmi270_chip_info },
{ }
};
static struct spi_driver bmi270_spi_driver = {
.driver = {
.name = "bmi270",
.pm = pm_ptr(&bmi270_core_pm_ops),
.of_match_table = bmi270_of_match,
},
.probe = bmi270_spi_probe,
.id_table = bmi270_spi_id,
};
module_spi_driver(bmi270_spi_driver);
Annotation
- Immediate include surface: `linux/iio/iio.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/pm.h`, `linux/regmap.h`, `linux/spi/spi.h`, `bmi270.h`.
- Detected declarations: `function bmi270_regmap_spi_read`, `function bmi270_regmap_spi_write`, `function bmi270_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.