mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 07/12] spi: add support to setup spi-cs-{setup,hold,inactive}-delay-ns
Date: Mon, 16 Dec 2024 14:03:19 +0100	[thread overview]
Message-ID: <20241216130324.1592755-7-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20241216130324.1592755-1-m.felsch@pengutronix.de>

Add support to parse and setup the common OF properties. The parsing is
quite confusing since the kernel driver API decided to use a u16 for the
value. I kept it this way to be closer to the Linux code.

This prepares the core for the upcoming core based message handling.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
Changelog:
v2:
 - no changes

 drivers/spi/spi.c | 25 +++++++++++++++++++++++++
 include/spi/spi.h | 22 ++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index c239de9d8549..e8a0b1b84be5 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -70,6 +70,9 @@ struct spi_device *spi_new_device(struct spi_controller *ctrl,
 		proxy->cs_gpiod = ctrl->cs_gpiods[chip->chip_select];
 	proxy->max_speed_hz = chip->max_speed_hz;
 	proxy->mode = chip->mode;
+	proxy->cs_setup = chip->cs_setup;
+	proxy->cs_hold = chip->cs_hold;
+	proxy->cs_inactive = chip->cs_inactive;
 	proxy->bits_per_word = chip->bits_per_word ? chip->bits_per_word : 8;
 	proxy->dev.platform_data = chip->platform_data;
 	proxy->dev.bus = &spi_bus;
@@ -111,6 +114,22 @@ struct spi_device *spi_new_device(struct spi_controller *ctrl,
 }
 EXPORT_SYMBOL(spi_new_device);
 
+static void of_spi_parse_dt_cs_delay(struct device_node *nc,
+				     struct spi_delay *delay, const char *prop)
+{
+	u32 value;
+
+	if (!of_property_read_u32(nc, prop, &value)) {
+		if (value > U16_MAX) {
+			delay->value = DIV_ROUND_UP(value, 1000);
+			delay->unit = SPI_DELAY_UNIT_USECS;
+		} else {
+			delay->value = value;
+			delay->unit = SPI_DELAY_UNIT_NSECS;
+		}
+	}
+}
+
 static void spi_of_register_slaves(struct spi_controller *ctrl)
 {
 	struct device_node *n;
@@ -145,6 +164,12 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
 			chip.mode |= SPI_3WIRE;
 		of_property_read_u32(n, "spi-max-frequency",
 				&chip.max_speed_hz);
+
+		/* Device CS delays */
+		of_spi_parse_dt_cs_delay(n, &chip.cs_setup, "spi-cs-setup-delay-ns");
+		of_spi_parse_dt_cs_delay(n, &chip.cs_hold, "spi-cs-hold-delay-ns");
+		of_spi_parse_dt_cs_delay(n, &chip.cs_inactive, "spi-cs-inactive-delay-ns");
+
 		reg = of_find_property(n, "reg", NULL);
 		if (!reg)
 			continue;
diff --git a/include/spi/spi.h b/include/spi/spi.h
index d643b83a7dbb..2061a44134d0 100644
--- a/include/spi/spi.h
+++ b/include/spi/spi.h
@@ -13,6 +13,19 @@
 struct spi_controller_mem_ops;
 struct spi_message;
 
+/**
+ * struct spi_delay - SPI delay information
+ * @value: Value for the delay
+ * @unit: Unit for the delay
+ */
+struct spi_delay {
+#define SPI_DELAY_UNIT_USECS	0
+#define SPI_DELAY_UNIT_NSECS	1
+#define SPI_DELAY_UNIT_SCK	2
+	u16	value;
+	u8	unit;
+};
+
 struct spi_board_info {
 	char	*name;
 	int	max_speed_hz;
@@ -26,6 +39,11 @@ struct spi_board_info {
 	u8	bits_per_word;
 	void	*platform_data;
 	struct device_node *device_node;
+
+	/* CS delays */
+	struct spi_delay	cs_setup;
+	struct spi_delay	cs_hold;
+	struct spi_delay	cs_inactive;
 };
 
 /**
@@ -101,6 +119,10 @@ struct spi_device {
 	void			*controller_data;
 	const char		*modalias;
 	struct gpio_desc	*cs_gpiod;	/* Chip select gpio desc */
+	/* CS delays */
+	struct spi_delay	cs_setup;
+	struct spi_delay	cs_hold;
+	struct spi_delay	cs_inactive;
 
 	/*
 	 * likely need more hooks for more protocol options affecting how
-- 
2.39.5




  parent reply	other threads:[~2024-12-16 13:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-16 13:03 [PATCH v2 01/12] spi: cosmetic style fixes Marco Felsch
2024-12-16 13:03 ` [PATCH v2 02/12] spi: fix spi_message init during __spi_validate Marco Felsch
2024-12-16 13:03 ` [PATCH v2 03/12] spi: add spi_{set,get}_ctldata accessors Marco Felsch
2024-12-16 13:03 ` [PATCH v2 04/12] gpiolib: add support for gpiod_get_index and gpiod_get_index_optional Marco Felsch
2024-12-16 13:03 ` [PATCH v2 05/12] gpiolib: add support for gpiod_set_consumer_name Marco Felsch
2024-12-16 13:03 ` [PATCH v2 06/12] spi: add support to handle cs-gpios Marco Felsch
2024-12-20  9:51   ` Sascha Hauer
2024-12-16 13:03 ` Marco Felsch [this message]
2024-12-16 13:03 ` [PATCH v2 08/12] spi: allow reporting the effectivly used speed_hz for a transfer Marco Felsch
2024-12-16 13:03 ` [PATCH v2 09/12] spi: import spi_controller::flags Marco Felsch
2024-12-16 13:03 ` [PATCH v2 10/12] spi: add support for spi_controller::set_cs_timing Marco Felsch
2024-12-16 13:03 ` [PATCH v2 11/12] spi: Provide common spi_message processing loop Marco Felsch
2024-12-16 13:03 ` [PATCH v2 12/12] spi: add support for BCM2835 SPI controller Marco Felsch
2024-12-20  9:16 ` [PATCH v2 01/12] spi: cosmetic style fixes 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=20241216130324.1592755-7-m.felsch@pengutronix.de \
    --to=m.felsch@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