Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: GPL-2.0
#
# BMI270 IMU driver
#
config BMI270
tristate
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
config BMI270_I2C
tristate "Bosch BMI270 I2C driver"
depends on I2C
select BMI270
select REGMAP_I2C
help
Enable support for the Bosch BMI270 6-Axis IMU connected to I2C
interface.
This driver can also be built as a module. If so, the module will be
called bmi270_i2c.
config BMI270_SPI
tristate "Bosch BMI270 SPI driver"
depends on SPI
select BMI270
select REGMAP_SPI
help
Enable support for the Bosch BMI270 6-Axis IMU connected to SPI
interface.
This driver can also be built as a module. If so, the module will be
called bmi270_spi.
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
#
# Makefile for Bosch BMI270 IMU
#
obj-$(CONFIG_BMI270) += bmi270_core.o
obj-$(CONFIG_BMI270_I2C) += bmi270_i2c.o
obj-$(CONFIG_BMI270_SPI) += bmi270_spi.o
@@ -0,0 +1,25 @@
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
#ifndef BMI270_H_
#define BMI270_H_
#include <linux/regmap.h>
#include <linux/iio/iio.h>
struct bmi270_chip_info {
const char *name;
int chip_id;
const char *fw_name;
};
extern const struct regmap_config bmi270_regmap_config;
extern const struct bmi270_chip_info bmi260_chip_info;
extern const struct bmi270_chip_info bmi270_chip_info;
struct device;
int bmi270_core_probe(struct device *dev, struct regmap *regmap,
const struct bmi270_chip_info *chip_info);
extern const struct dev_pm_ops bmi270_core_pm_ops;
#endif /* BMI270_H_ */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
#include <linux/i2c.h>
#include <linux/iio/iio.h>
#include <linux/module.h>
#include <linux/pm.h>
#include <linux/regmap.h>
#include "bmi270.h"
static const struct regmap_config bmi270_i2c_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
};
static int bmi270_i2c_probe(struct i2c_client *client)
{
struct regmap *regmap;
struct device *dev = &client->dev;
const struct bmi270_chip_info *chip_info;
chip_info = i2c_get_match_data(client);
if (!chip_info)
return -ENODEV;
regmap = devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config);
if (IS_ERR(regmap))
return dev_err_probe(dev, PTR_ERR(regmap),
"Failed to init i2c regmap");
return bmi270_core_probe(dev, regmap, chip_info);
}
static const struct i2c_device_id bmi270_i2c_id[] = {
{ .name = "bmi260", .driver_data = (kernel_ulong_t)&bmi260_chip_info },
{ .name = "bmi270", .driver_data = (kernel_ulong_t)&bmi270_chip_info },
{ }
};
MODULE_DEVICE_TABLE(i2c, bmi270_i2c_id);
static const struct acpi_device_id bmi270_acpi_match[] = {
/* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */
{ "BMI0160", (kernel_ulong_t)&bmi260_chip_info },
/* GPD Win Max 2 2023(sincice BIOS v0.40), etc. */
{ "BMI0260", (kernel_ulong_t)&bmi260_chip_info },
{ }
};
MODULE_DEVICE_TABLE(acpi, bmi270_acpi_match);
static const struct of_device_id bmi270_of_match[] = {
{ .compatible = "bosch,bmi260", .data = &bmi260_chip_info },
{ .compatible = "bosch,bmi270", .data = &bmi270_chip_info },
{ }
};
MODULE_DEVICE_TABLE(of, bmi270_of_match);
static struct i2c_driver bmi270_i2c_driver = {
.driver = {
.name = "bmi270_i2c",
.pm = pm_ptr(&bmi270_core_pm_ops),
.acpi_match_table = bmi270_acpi_match,
.of_match_table = bmi270_of_match,
},
.probe = bmi270_i2c_probe,
.id_table = bmi270_i2c_id,
};
module_i2c_driver(bmi270_i2c_driver);
MODULE_AUTHOR("Alex Lanzano");
MODULE_DESCRIPTION("BMI270 driver");
MODULE_LICENSE("GPL");
MODULE_IMPORT_NS("IIO_BMI270");
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
#include <linux/iio/iio.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);
MODULE_AUTHOR("Alex Lanzano");
MODULE_DESCRIPTION("BMI270 driver");
MODULE_LICENSE("GPL");
MODULE_IMPORT_NS("IIO_BMI270");