mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 03/11] regmap: port regmap_init_spi
Date: Wed, 11 Jan 2023 14:29:48 +0100	[thread overview]
Message-ID: <20230111132956.1153359-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230111132956.1153359-1-a.fatoum@pengutronix.de>

We already have regmap_init_i2c, so add regmap_init_spi as well. Unlike
regmap_init_i2c, this one makes full use of the formatted regmap API.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/base/regmap/Kconfig      |  5 ++++
 drivers/base/regmap/Makefile     |  1 +
 drivers/base/regmap/regmap-spi.c | 42 ++++++++++++++++++++++++++++++++
 include/regmap.h                 | 13 ++++++++++
 4 files changed, 61 insertions(+)
 create mode 100644 drivers/base/regmap/regmap-spi.c

diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig
index 4fb6b6bcecf8..afe59a538c87 100644
--- a/drivers/base/regmap/Kconfig
+++ b/drivers/base/regmap/Kconfig
@@ -2,3 +2,8 @@
 
 config REGMAP_FORMATTED
 	bool
+
+config REGMAP_SPI
+	bool "SPI regmaps" if COMPILE_TEST
+	depends on SPI
+	select REGMAP_FORMATTED
diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile
index ef6814a50277..d99db4277149 100644
--- a/drivers/base/regmap/Makefile
+++ b/drivers/base/regmap/Makefile
@@ -3,3 +3,4 @@ obj-y	+= regmap.o
 obj-y	+= regmap-mmio.o
 obj-$(CONFIG_REGMAP_FORMATTED)	+= regmap-fmt.o
 obj-$(CONFIG_I2C)	+= regmap-i2c.o
+obj-$(CONFIG_REGMAP_SPI)	+= regmap-spi.o
diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c
new file mode 100644
index 000000000000..5a0e418065b8
--- /dev/null
+++ b/drivers/base/regmap/regmap-spi.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Register map access API - SPI support
+//
+// Copyright 2011 Wolfson Microelectronics plc
+//
+// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+
+#include <regmap.h>
+#include <spi/spi.h>
+
+static int regmap_spi_write(void *context, const void *data, size_t count)
+{
+	struct device_d *dev = context;
+	struct spi_device *spi = to_spi_device(dev);
+
+	return spi_write(spi, data, count);
+}
+
+static int regmap_spi_read(void *context,
+			   const void *reg, size_t reg_size,
+			   void *val, size_t val_size)
+{
+	struct device_d *dev = context;
+	struct spi_device *spi = to_spi_device(dev);
+
+	return spi_write_then_read(spi, reg, reg_size, val, val_size);
+}
+
+static const struct regmap_bus regmap_spi = {
+	.write = regmap_spi_write,
+	.read = regmap_spi_read,
+	.read_flag_mask = 0x80,
+	.reg_format_endian_default = REGMAP_ENDIAN_BIG,
+	.val_format_endian_default = REGMAP_ENDIAN_BIG,
+};
+
+struct regmap *regmap_init_spi(struct spi_device *spi,
+			       const struct regmap_config *config)
+{
+	return regmap_init(&spi->dev, &regmap_spi, &spi->dev, config);
+}
diff --git a/include/regmap.h b/include/regmap.h
index 36a75eb34e03..8f191c87cfcb 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -138,6 +138,19 @@ struct regmap *regmap_init_i2c(struct i2c_client *i2c,
 struct regmap *regmap_init_i2c_smbus(struct i2c_client *client,
 			       const struct regmap_config *config);
 
+/**
+ * regmap_init_spi() - Initialise spi register map
+ *
+ * @spi: Device that will be interacted with
+ * @config: Configuration for register map
+ *
+ * The return value will be an ERR_PTR() on error or a valid pointer
+ * to a struct regmap.
+ */
+struct spi_device;
+struct regmap *regmap_init_spi(struct spi_device *dev,
+			       const struct regmap_config *config);
+
 /**
  * regmap_init_mmio() - Initialise register map
  *
-- 
2.30.2




  parent reply	other threads:[~2023-01-11 13:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-11 13:29 [PATCH v2 00/11] net: dsa: ksz9477: use regmap to add I2C support next to SPI Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 01/11] regmap: consolidate reg/val format into regmap_format Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 02/11] regmap: support formatted read and write Ahmad Fatoum
2023-01-11 13:29 ` Ahmad Fatoum [this message]
2023-01-11 13:29 ` [PATCH v2 04/11] regmap: factor out regmap cdev size calculation Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 05/11] net: dsa: ksz9477: switch to regmap_init_spi Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 06/11] net: dsa: ksz9477: create regmap cdev for switch registers Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 07/11] drivers: base: regmap: introduce REGMAP_I2C Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 08/11] dev: add dev_bus_is_spi/i2c helpers Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 09/11] net: dsa: ksz9477: refactor to prepare i2c support Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 10/11] regmap: i2c: use formatted I/O Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 11/11] net: ksz9477: add I2C support Ahmad Fatoum
2023-01-12 14:58 ` [PATCH v2 00/11] net: dsa: ksz9477: use regmap to add I2C support next to SPI Sascha Hauer

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=20230111132956.1153359-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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