From: Petre Rodan <petre.rodan@subdimension.ro>
To: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 14/19] iio: accel: bma220: add i2c module
Date: Sun, 05 Oct 2025 16:12:23 +0300 [thread overview]
Message-ID: <20251005-b4-bma220_improvements-v4-14-0f449ba31585@subdimension.ro> (raw)
In-Reply-To: <20251005-b4-bma220_improvements-v4-0-0f449ba31585@subdimension.ro>
Add the bma220_i2c module.
Note that this kernel module transparently shifts all register addresses
1 bit to the left, so all functions will operate based on the SPI memory
map.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v1->v2 no change
v2->v3
- depends I2C || SPI (David)
- change extern const struct order (David)
- remove unused includes (David)
v4 no change
---
drivers/iio/accel/Kconfig | 11 ++++++--
drivers/iio/accel/Makefile | 1 +
drivers/iio/accel/bma220.h | 1 +
drivers/iio/accel/bma220_core.c | 18 +++++++++++++
drivers/iio/accel/bma220_i2c.c | 58 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 988fe4b1f9a52c2e671ea30d8590f25ee1685ac7..76911278fb217bd3e429c427b873fb7eae26420e 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -218,10 +218,11 @@ config BMA180
config BMA220
tristate "Bosch BMA220 3-Axis Accelerometer Driver"
- depends on SPI
+ depends on I2C || SPI
select REGMAP
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
+ select BMA220_I2C if I2C
select BMA220_SPI if SPI
help
Say yes here to add support for the Bosch BMA220 triaxial
@@ -229,7 +230,13 @@ config BMA220
To compile this driver as a module, choose M here: the
module will be called bma220_core and you will also get
- bma220_spi if SPI is enabled.
+ bma220_i2c if I2C is enabled and bma220_spi if SPI is
+ enabled.
+
+config BMA220_I2C
+ tristate
+ select REGMAP_I2C
+ depends on BMA220
config BMA220_SPI
tristate
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 56a9f848f7f913633bc2a628c1ac5c9190774b9d..fa440a85928398fee927081f605595ba9fbc4ad9 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_ADXL380_I2C) += adxl380_i2c.o
obj-$(CONFIG_ADXL380_SPI) += adxl380_spi.o
obj-$(CONFIG_BMA180) += bma180.o
obj-$(CONFIG_BMA220) += bma220_core.o
+obj-$(CONFIG_BMA220_I2C) += bma220_i2c.o
obj-$(CONFIG_BMA220_SPI) += bma220_spi.o
obj-$(CONFIG_BMA400) += bma400_core.o
obj-$(CONFIG_BMA400_I2C) += bma400_i2c.o
diff --git a/drivers/iio/accel/bma220.h b/drivers/iio/accel/bma220.h
index 695f491bc5a03008f26fe8602ba633456159fb1d..e53ca63de54b4e81df0908b11d0fb7f03a86dbdc 100644
--- a/drivers/iio/accel/bma220.h
+++ b/drivers/iio/accel/bma220.h
@@ -13,6 +13,7 @@
struct device;
+extern const struct regmap_config bma220_i2c_regmap_config;
extern const struct regmap_config bma220_spi_regmap_config;
extern const struct dev_pm_ops bma220_pm_ops;
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 42d5acce0a8387734d932c77fec9777a7a01f774..a3faf1f5ec6d79f2c6105697b404d6eb1f4501db 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -172,6 +172,24 @@ const struct regmap_config bma220_spi_regmap_config = {
};
EXPORT_SYMBOL_NS_GPL(bma220_spi_regmap_config, "IIO_BOSCH_BMA220");
+/*
+ * Based on the datasheet the memory map differs between the SPI and the I2C
+ * implementations. I2C register addresses are simply shifted to the left
+ * by 1 bit yet the register size remains unchanged.
+ * This driver employs the SPI memory map to correlate register names to
+ * addresses regardless of the bus type.
+ */
+
+const struct regmap_config bma220_i2c_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .reg_shift = -1,
+ .max_register = BMA220_REG_SOFTRESET,
+ .cache_type = REGCACHE_NONE,
+ .writeable_reg = bma220_is_writable_reg,
+};
+EXPORT_SYMBOL_NS_GPL(bma220_i2c_regmap_config, "IIO_BOSCH_BMA220");
+
static irqreturn_t bma220_trigger_handler(int irq, void *p)
{
int ret;
diff --git a/drivers/iio/accel/bma220_i2c.c b/drivers/iio/accel/bma220_i2c.c
new file mode 100644
index 0000000000000000000000000000000000000000..5dc7c38f53b3173ff43ca29b63132ec44e672cde
--- /dev/null
+++ b/drivers/iio/accel/bma220_i2c.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Bosch triaxial acceleration sensor
+ *
+ * Copyright (c) 2025 Petre Rodan <petre.rodan@subdimension.ro>
+ *
+ * Datasheet: https://media.digikey.com/pdf/Data%20Sheets/Bosch/BMA220.pdf
+ * I2C address is either 0x0b or 0x0a depending on CSB (pin 10)
+ */
+
+#include <linux/errno.h>
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/types.h>
+
+#include "bma220.h"
+
+static int bma220_i2c_probe(struct i2c_client *client)
+{
+ struct regmap *regmap;
+
+ regmap = devm_regmap_init_i2c(client, &bma220_i2c_regmap_config);
+ if (IS_ERR(regmap))
+ return dev_err_probe(&client->dev, PTR_ERR(regmap),
+ "failed to create regmap\n");
+
+ return bma220_common_probe(&client->dev, regmap, client->irq);
+}
+
+static const struct of_device_id bma220_i2c_match[] = {
+ { .compatible = "bosch,bma220" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, bma220_i2c_match);
+
+static const struct i2c_device_id bma220_i2c_id[] = {
+ { "bma220" },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, bma220_i2c_id);
+
+static struct i2c_driver bma220_i2c_driver = {
+ .driver = {
+ .name = "bma220_i2c",
+ .pm = pm_sleep_ptr(&bma220_pm_ops),
+ .of_match_table = bma220_i2c_match,
+ },
+ .probe = bma220_i2c_probe,
+ .id_table = bma220_i2c_id,
+};
+module_i2c_driver(bma220_i2c_driver);
+
+MODULE_AUTHOR("Petre Rodan <petre.rodan@subdimension.ro>");
+MODULE_DESCRIPTION("Bosch triaxial acceleration sensor i2c driver");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("IIO_BOSCH_BMA220");
--
2.49.1
next prev parent reply other threads:[~2025-10-05 13:13 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
2025-10-05 13:12 ` [PATCH v4 01/19] iio: accel: bma220: remove incorrect kernel-doc marking Petre Rodan
2025-10-12 14:21 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 02/19] iio: accel: bma220: relax constraints during probe() Petre Rodan
2025-10-12 14:22 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 03/19] iio: accel: bma220: cleanup license string Petre Rodan
2025-10-12 14:22 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 04/19] iio: accel: bma220: shorten spi->dev calls Petre Rodan
2025-10-12 14:23 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 05/19] iio: accel: bma220: move bma220_power function Petre Rodan
2025-10-12 14:24 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 06/19] iio: accel: bma220: cleanup includes Petre Rodan
2025-10-12 14:25 ` Jonathan Cameron
2025-10-12 14:34 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 07/19] iio: accel: bma220: split original driver Petre Rodan
2025-10-12 14:52 ` Jonathan Cameron
2025-10-14 16:52 ` Petre Rodan
2025-10-05 13:12 ` [PATCH v4 08/19] iio: accel: bma220: add open firmware table Petre Rodan
2025-10-12 14:54 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 09/19] iio: accel: bma220: turn power supplies on Petre Rodan
2025-10-12 14:55 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 10/19] iio: accel: bma220: reset registers during init stage Petre Rodan
2025-10-12 14:56 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 11/19] iio: accel: bma220: migrate to regmap API Petre Rodan
2025-10-12 15:04 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 12/19] iio: accel: bma220: populate buffer ts in trigger handler Petre Rodan
2025-10-12 15:06 ` Jonathan Cameron
2025-10-12 20:54 ` Petre Rodan
2025-10-05 13:12 ` [PATCH v4 13/19] iio: accel: bma220: use find_match_table fct Petre Rodan
2025-10-12 15:20 ` Jonathan Cameron
2025-10-05 13:12 ` Petre Rodan [this message]
2025-10-12 15:17 ` [PATCH v4 14/19] iio: accel: bma220: add i2c module Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature Petre Rodan
2025-10-12 15:20 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 16/19] iio: accel: bma220: add interrupt trigger Petre Rodan
2025-10-12 15:21 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 17/19] iio: accel: bma220: add LPF cut-off frequency mapping Petre Rodan
2025-10-12 15:23 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 18/19] iio: accel: bma220: add debugfs reg access Petre Rodan
2025-10-12 15:24 ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 19/19] iio: accel: bma220: add maintainer Petre Rodan
2025-10-12 15:24 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251005-b4-bma220_improvements-v4-14-0f449ba31585@subdimension.ro \
--to=petre.rodan@subdimension.ro \
--cc=Jonathan.Cameron@huawei.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).