drivers/iio/imu/smi330/smi330_spi.c
Source file repositories/reference/linux-study-clean/drivers/iio/imu/smi330/smi330_spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/imu/smi330/smi330_spi.c- Extension
.c- Size
- 2233 bytes
- Lines
- 86
- 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/mod_devicetable.hlinux/module.hlinux/regmap.hlinux/spi/spi.hsmi330.h
Detected Declarations
function Copyrightfunction smi330_regmap_spi_writefunction smi330_spi_probe
Annotated Snippet
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
/*
* Copyright (c) 2025 Robert Bosch GmbH.
*/
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/spi/spi.h>
#include "smi330.h"
static int smi330_regmap_spi_read(void *context, const void *reg_buf,
size_t reg_size, void *val_buf,
size_t val_size)
{
struct spi_device *spi = context;
/* Insert pad byte for reading */
u8 reg[] = { *(u8 *)reg_buf, 0 };
if (reg_size + 1 != ARRAY_SIZE(reg)) {
dev_err(&spi->dev, "Invalid register size %zu\n", reg_size);
return -EINVAL;
}
return spi_write_then_read(spi, reg, ARRAY_SIZE(reg), val_buf,
val_size);
}
static int smi330_regmap_spi_write(void *context, const void *data,
size_t count)
{
struct spi_device *spi = context;
return spi_write(spi, data, count);
}
static const struct regmap_bus smi330_regmap_bus = {
.read = smi330_regmap_spi_read,
.write = smi330_regmap_spi_write,
.read_flag_mask = 0x80,
};
static int smi330_spi_probe(struct spi_device *spi)
{
struct regmap *regmap;
regmap = devm_regmap_init(&spi->dev, &smi330_regmap_bus, &spi->dev,
&smi330_regmap_config);
if (IS_ERR(regmap))
return dev_err_probe(&spi->dev, PTR_ERR(regmap),
"Failed to initialize SPI Regmap\n");
return smi330_core_probe(&spi->dev, regmap);
}
static const struct spi_device_id smi330_spi_device_id[] = {
{ .name = "smi330" },
{ }
};
MODULE_DEVICE_TABLE(spi, smi330_spi_device_id);
static const struct of_device_id smi330_of_match[] = {
{ .compatible = "bosch,smi330" },
{ }
};
MODULE_DEVICE_TABLE(of, smi330_of_match);
static struct spi_driver smi330_spi_driver = {
.probe = smi330_spi_probe,
.id_table = smi330_spi_device_id,
.driver = {
.of_match_table = smi330_of_match,
.name = "smi330_spi",
},
};
module_spi_driver(smi330_spi_driver);
MODULE_AUTHOR("Stefan Gutmann <stefan.gutmann@de.bosch.com>");
MODULE_AUTHOR("Roman Huber <roman.huber@de.bosch.com>");
MODULE_AUTHOR("Filip Andrei <Andrei.Filip@ro.bosch.com>");
MODULE_AUTHOR("Drimbarean Avram Andrei <Avram-Andrei.Drimbarean@ro.bosch.com>");
MODULE_DESCRIPTION("Bosch SMI330 SPI driver");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_IMPORT_NS("IIO_SMI330");
Annotation
- Immediate include surface: `linux/mod_devicetable.h`, `linux/module.h`, `linux/regmap.h`, `linux/spi/spi.h`, `smi330.h`.
- Detected declarations: `function Copyright`, `function smi330_regmap_spi_write`, `function smi330_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.