2021-01-25 08:07:32 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* 3-axis accelerometer driver supporting following Bosch-Sensortec chips:
|
|
|
|
* - BMI088
|
2023-12-14 07:27:33 -07:00
|
|
|
* - BMI085
|
|
|
|
* - BMI090L
|
2021-01-25 08:07:32 -07:00
|
|
|
*
|
|
|
|
* Copyright (c) 2018-2020, Topic Embedded Products
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
|
|
|
|
#include "bmi088-accel.h"
|
|
|
|
|
|
|
|
static int bmi088_regmap_spi_write(void *context, const void *data, size_t count)
|
|
|
|
{
|
|
|
|
struct spi_device *spi = context;
|
|
|
|
|
|
|
|
/* Write register is same as generic SPI */
|
|
|
|
return spi_write(spi, data, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bmi088_regmap_spi_read(void *context, const void *reg,
|
|
|
|
size_t reg_size, void *val, size_t val_size)
|
|
|
|
{
|
|
|
|
struct spi_device *spi = context;
|
|
|
|
u8 addr[2];
|
|
|
|
|
|
|
|
addr[0] = *(u8 *)reg;
|
|
|
|
addr[0] |= BIT(7); /* Set RW = '1' */
|
|
|
|
addr[1] = 0; /* Read requires a dummy byte transfer */
|
|
|
|
|
|
|
|
return spi_write_then_read(spi, addr, sizeof(addr), val, val_size);
|
|
|
|
}
|
|
|
|
|
2024-07-03 14:04:46 -07:00
|
|
|
static const struct regmap_bus bmi088_regmap_bus = {
|
2021-01-25 08:07:32 -07:00
|
|
|
.write = bmi088_regmap_spi_write,
|
|
|
|
.read = bmi088_regmap_spi_read,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bmi088_accel_probe(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct regmap *regmap;
|
|
|
|
const struct spi_device_id *id = spi_get_device_id(spi);
|
|
|
|
|
|
|
|
regmap = devm_regmap_init(&spi->dev, &bmi088_regmap_bus,
|
|
|
|
spi, &bmi088_regmap_conf);
|
|
|
|
|
|
|
|
if (IS_ERR(regmap)) {
|
|
|
|
dev_err(&spi->dev, "Failed to initialize spi regmap\n");
|
|
|
|
return PTR_ERR(regmap);
|
|
|
|
}
|
|
|
|
|
2022-05-26 06:33:56 -07:00
|
|
|
return bmi088_accel_core_probe(&spi->dev, regmap, spi->irq,
|
|
|
|
id->driver_data);
|
2021-01-25 08:07:32 -07:00
|
|
|
}
|
|
|
|
|
2022-01-23 10:52:01 -07:00
|
|
|
static void bmi088_accel_remove(struct spi_device *spi)
|
2021-01-25 08:07:32 -07:00
|
|
|
{
|
2021-10-13 13:32:11 -07:00
|
|
|
bmi088_accel_core_remove(&spi->dev);
|
2021-01-25 08:07:32 -07:00
|
|
|
}
|
|
|
|
|
2022-05-26 06:33:56 -07:00
|
|
|
static const struct of_device_id bmi088_of_match[] = {
|
2022-05-26 06:33:57 -07:00
|
|
|
{ .compatible = "bosch,bmi085-accel" },
|
2022-05-26 06:33:56 -07:00
|
|
|
{ .compatible = "bosch,bmi088-accel" },
|
2022-05-26 06:33:58 -07:00
|
|
|
{ .compatible = "bosch,bmi090l-accel" },
|
2022-05-26 06:33:56 -07:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, bmi088_of_match);
|
|
|
|
|
2021-01-25 08:07:32 -07:00
|
|
|
static const struct spi_device_id bmi088_accel_id[] = {
|
2022-05-26 06:33:57 -07:00
|
|
|
{"bmi085-accel", BOSCH_BMI085},
|
2022-05-26 06:33:56 -07:00
|
|
|
{"bmi088-accel", BOSCH_BMI088},
|
2022-05-26 06:33:58 -07:00
|
|
|
{"bmi090l-accel", BOSCH_BMI090L},
|
2021-01-25 08:07:32 -07:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(spi, bmi088_accel_id);
|
|
|
|
|
|
|
|
static struct spi_driver bmi088_accel_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "bmi088_accel_spi",
|
2022-08-07 11:56:17 -07:00
|
|
|
.pm = pm_ptr(&bmi088_accel_pm_ops),
|
2022-05-26 06:33:56 -07:00
|
|
|
.of_match_table = bmi088_of_match,
|
2021-01-25 08:07:32 -07:00
|
|
|
},
|
|
|
|
.probe = bmi088_accel_probe,
|
|
|
|
.remove = bmi088_accel_remove,
|
|
|
|
.id_table = bmi088_accel_id,
|
|
|
|
};
|
|
|
|
module_spi_driver(bmi088_accel_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Niek van Agt <niek.van.agt@topicproducts.com>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_DESCRIPTION("BMI088 accelerometer driver (SPI)");
|
2022-01-16 11:05:32 -07:00
|
|
|
MODULE_IMPORT_NS(IIO_BMI088);
|