From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 10/12] spi: add support for spi_controller::set_cs_timing
Date: Mon, 16 Dec 2024 14:03:22 +0100 [thread overview]
Message-ID: <20241216130324.1592755-10-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20241216130324.1592755-1-m.felsch@pengutronix.de>
Import the spi_controller set_cs_timing() hook to make it easier to port
Linux spi drivers.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
Changelog:
v2:
- add spi_set_cs_timing()
drivers/spi/spi.c | 20 ++++++++++++++++++++
include/spi/spi.h | 12 ++++++++++++
2 files changed, 32 insertions(+)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 78569301776f..425c35759045 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -34,6 +34,22 @@ struct boardinfo {
static LIST_HEAD(board_list);
static LIST_HEAD(spi_controller_list);
+/**
+ * spi_set_cs_timing - configure CS setup, hold, and inactive delays
+ * @spi: the device that requires specific CS timing configuration
+ *
+ * Return: zero on success, else a negative error code.
+ */
+static int spi_set_cs_timing(struct spi_device *spi)
+{
+ int status = 0;
+
+ if (spi->controller->set_cs_timing && !spi->cs_gpiod)
+ status = spi->controller->set_cs_timing(spi);
+
+ return status;
+}
+
/**
* spi_new_device - instantiate one new SPI device
* @master: Controller to which device is connected
@@ -101,6 +117,10 @@ struct spi_device *spi_new_device(struct spi_controller *ctrl,
goto fail;
}
+ status = spi_set_cs_timing(proxy);
+ if (status)
+ goto fail;
+
status = register_device(&proxy->dev);
if (status)
goto fail;
diff --git a/include/spi/spi.h b/include/spi/spi.h
index a8bbf55e0a5a..106cca664068 100644
--- a/include/spi/spi.h
+++ b/include/spi/spi.h
@@ -179,6 +179,9 @@ static inline void spi_set_ctldata(struct spi_device *spi, void *state)
* must fail if an unrecognized or unsupported mode is requested.
* It's always safe to call this unless transfers are pending on
* the device whose settings are being modified.
+ * @set_cs_timing: optional hook for SPI devices to request SPI master
+ * controller for configuring specific CS setup time, hold time and inactive
+ * delay interms of clock counts
* @transfer: adds a message to the controller's transfer queue.
* @cleanup: frees controller-specific state
* @cs_gpiods: Array of GPIO descriptors to use as chip select lines; one per CS
@@ -249,6 +252,15 @@ struct spi_controller {
/* setup mode and clock, etc (spi driver may call many times) */
int (*setup)(struct spi_device *spi);
+ /*
+ * set_cs_timing() method is for SPI controllers that supports
+ * configuring CS timing.
+ *
+ * This hook allows SPI client drivers to request SPI controllers
+ * to configure specific CS timing through spi_set_cs_timing().
+ */
+ int (*set_cs_timing)(struct spi_device *spi);
+
/* bidirectional bulk transfers
*
* + The transfer() method may not sleep; its main role is
--
2.39.5
next prev 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 ` [PATCH v2 07/12] spi: add support to setup spi-cs-{setup,hold,inactive}-delay-ns Marco Felsch
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 ` Marco Felsch [this message]
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-10-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