FILE
smi330_spi.c
File preview with syntax highlighting.
linux-6.19.14/drivers/iio/imu/smi330/smi330_spi.c
1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 2/* 3 * Copyright (c) 2025 Robert Bosch GmbH. 4 */ 5#include <linux/mod_devicetable.h> 6#include <linux/module.h> 7#include <linux/regmap.h> 8#include <linux/spi/spi.h> 9 10#include "smi330.h" 11 12static int smi330_regmap_spi_read(void *context, const void *reg_buf, 13 size_t reg_size, void *val_buf, 14 size_t val_size) 15{ 16 struct spi_device *spi = context; 17 18 /* Insert pad byte for reading */ 19 u8 reg[] = { *(u8 *)reg_buf, 0 }; 20 21 if (reg_size + 1 != ARRAY_SIZE(reg)) { 22 dev_err(&spi->dev, "Invalid register size %zu\n", reg_size); 23 return -EINVAL; 24 } 25 26 return spi_write_then_read(spi, reg, ARRAY_SIZE(reg), val_buf, 27 val_size); 28} 29 30static int smi330_regmap_spi_write(void *context, const void *data, 31 size_t count) 32{ 33 struct spi_device *spi = context; 34 35 return spi_write(spi, data, count); 36} 37 38static const struct regmap_bus smi330_regmap_bus = { 39 .read = smi330_regmap_spi_read, 40 .write = smi330_regmap_spi_write, 41 .read_flag_mask = 0x80, 42}; 43 44static int smi330_spi_probe(struct spi_device *spi) 45{ 46 struct regmap *regmap; 47 48 regmap = devm_regmap_init(&spi->dev, &smi330_regmap_bus, &spi->dev, 49 &smi330_regmap_config); 50 if (IS_ERR(regmap)) 51 return dev_err_probe(&spi->dev, PTR_ERR(regmap), 52 "Failed to initialize SPI Regmap\n"); 53 54 return smi330_core_probe(&spi->dev, regmap); 55} 56 57static const struct spi_device_id smi330_spi_device_id[] = { 58 { .name = "smi330" }, 59 { } 60}; 61MODULE_DEVICE_TABLE(spi, smi330_spi_device_id); 62 63static const struct of_device_id smi330_of_match[] = { 64 { .compatible = "bosch,smi330" }, 65 { } 66}; 67MODULE_DEVICE_TABLE(of, smi330_of_match); 68 69static struct spi_driver smi330_spi_driver = { 70 .probe = smi330_spi_probe, 71 .id_table = smi330_spi_device_id, 72 .driver = { 73 .of_match_table = smi330_of_match, 74 .name = "smi330_spi", 75 }, 76}; 77module_spi_driver(smi330_spi_driver); 78 79MODULE_AUTHOR("Stefan Gutmann <stefan.gutmann@de.bosch.com>"); 80MODULE_AUTHOR("Roman Huber <roman.huber@de.bosch.com>"); 81MODULE_AUTHOR("Filip Andrei <Andrei.Filip@ro.bosch.com>"); 82MODULE_AUTHOR("Drimbarean Avram Andrei <Avram-Andrei.Drimbarean@ro.bosch.com>"); 83MODULE_DESCRIPTION("Bosch SMI330 SPI driver"); 84MODULE_LICENSE("Dual BSD/GPL"); 85MODULE_IMPORT_NS("IIO_SMI330");
~/
Read-only file preview.