* [PATCH v3 0/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity
@ 2026-08-18 13:38 Praveen Talari
2026-08-18 13:38 ` [PATCH v3 1/2] spi: dt-bindings: Document ready-gpios property Praveen Talari
2026-08-18 13:38 ` [PATCH v3 2/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity Praveen Talari
0 siblings, 2 replies; 4+ messages in thread
From: Praveen Talari @ 2026-08-18 13:38 UTC (permalink / raw)
To: konrad.dybcio, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Andy Gross, Bjorn Andersson
Cc: chandana.chiluveru, Krzysztof Kozlowski, linux-arm-msm, linux-spi,
devicetree, linux-kernel, Praveen Talari
When operating in SPI target mode, the GENI controller relies on an
external GPIO to notify the SPI master about the target's active state.
Add support for an optional device GPIO that is asserted when a target
transfer begins and deasserted when the transfer completes, is aborted,
or hits a timeout. This allows the target to explicitly signal its
availability to the master and ensures the GPIO is released in all error
and completion paths, preventing the master from observing a stale or
incorrect target ready indication.
The ready GPIO is intentionally made optional and is requested only
when target mode is enabled. This preserves existing behaviour for
systems that do not require the signal and avoids regressions on
deployed platforms where the GPIO is already controlled from userspace.
Targets without a ready GPIO continue to operate unchanged by using
devm_gpiod_get_index_optional().
Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
---
Changes in v3:
- Rebased on linux-next tip.
- Link to v2: https://patch.msgid.link/20260817-use_gpio_to_notify_master_of_spi_target_activity-v2-0-94d1eff3175f@oss.qualcomm.com
Changes in v2:
- Used ready-gpio instead of target-gpio.
- Updated commit text.
- Link to v1: https://patch.msgid.link/20260806-use_gpio_to_notify_master_of_spi_target_activity-v1-0-c363a9b5df69@oss.qualcomm.com
---
Praveen Talari (2):
spi: dt-bindings: Document ready-gpios property
spi: qcom-geni: Use GPIO to notify master of SPI target activity
.../bindings/spi/qcom,sa8255p-geni-spi.yaml | 9 ++++++++
.../bindings/spi/qcom,spi-geni-qcom.yaml | 9 ++++++++
drivers/spi/spi-geni-qcom.c | 25 ++++++++++++++++++++--
3 files changed, 41 insertions(+), 2 deletions(-)
---
base-commit: e6664f2b33db9b6811eb4cec109f06cb2b4f458d
change-id: 20260729-use_gpio_to_notify_master_of_spi_target_activity-5f62a9e14875
Best regards,
--
Praveen Talari <praveen.talari@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v3 1/2] spi: dt-bindings: Document ready-gpios property 2026-08-18 13:38 [PATCH v3 0/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity Praveen Talari @ 2026-08-18 13:38 ` Praveen Talari 2026-08-18 13:38 ` [PATCH v3 2/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity Praveen Talari 1 sibling, 0 replies; 4+ messages in thread From: Praveen Talari @ 2026-08-18 13:38 UTC (permalink / raw) To: konrad.dybcio, Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Andy Gross, Bjorn Andersson Cc: chandana.chiluveru, Krzysztof Kozlowski, linux-arm-msm, linux-spi, devicetree, linux-kernel, Praveen Talari When operating in SPI target (slave) mode, the GENI SPI controller can use an external GPIO to notify the SPI master about the target's active state. Document the optional ready-gpios property for the qcom,spi-geni-qcom and qcom,sa8255p-geni-spi bindings, restricted to spi-slave nodes. Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- Documentation/devicetree/bindings/spi/qcom,sa8255p-geni-spi.yaml | 9 +++++++++ Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.yaml | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/Documentation/devicetree/bindings/spi/qcom,sa8255p-geni-spi.yaml b/Documentation/devicetree/bindings/spi/qcom,sa8255p-geni-spi.yaml index 6552303a4f52..33eddb395a0a 100644 --- a/Documentation/devicetree/bindings/spi/qcom,sa8255p-geni-spi.yaml +++ b/Documentation/devicetree/bindings/spi/qcom,sa8255p-geni-spi.yaml @@ -39,6 +39,12 @@ properties: - const: power - const: perf + ready-gpios: + description: + GPIO used by the SPI target to notify the SPI master when it is + ready to service a transfer. Only applicable in target (slave) mode. + maxItems: 1 + required: - compatible - reg @@ -46,6 +52,9 @@ required: - power-domains - power-domain-names +dependencies: + ready-gpios: [ spi-slave ] + allOf: - $ref: /schemas/spi/spi-controller.yaml# diff --git a/Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.yaml b/Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.yaml index edf399681d7a..8d1c78701657 100644 --- a/Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.yaml +++ b/Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.yaml @@ -67,6 +67,12 @@ properties: reg: maxItems: 1 + ready-gpios: + description: + GPIO used by the SPI target to notify the SPI master when it is + ready to service a transfer. Only applicable in target (slave) mode. + maxItems: 1 + required: - compatible - clocks @@ -74,6 +80,9 @@ required: - interrupts - reg +dependencies: + ready-gpios: [ spi-slave ] + unevaluatedProperties: false examples: -- 2.34.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 2/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity 2026-08-18 13:38 [PATCH v3 0/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity Praveen Talari 2026-08-18 13:38 ` [PATCH v3 1/2] spi: dt-bindings: Document ready-gpios property Praveen Talari @ 2026-08-18 13:38 ` Praveen Talari 2026-08-18 13:48 ` sashiko-bot 1 sibling, 1 reply; 4+ messages in thread From: Praveen Talari @ 2026-08-18 13:38 UTC (permalink / raw) To: konrad.dybcio, Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Andy Gross, Bjorn Andersson Cc: chandana.chiluveru, Krzysztof Kozlowski, linux-arm-msm, linux-spi, devicetree, linux-kernel, Praveen Talari When operating in SPI target mode, the GENI controller relies on an external GPIO to notify the SPI master about the target's active state. Add support for an optional ready GPIO that is asserted when a target transfer begins and deasserted when the transfer completes, is aborted, or hits a timeout. This allows the target to explicitly signal its availability to the master and ensures the GPIO is released in all error and completion paths, preventing the master from observing a stale or incorrect target-ready indication. The ready GPIO is intentionally made optional and is requested only when target mode is enabled. This preserves existing behaviour for systems that do not require the signal and avoids regressions on deployed platforms where the GPIO is already controlled from userspace. Targets without a ready GPIO continue to operate unchanged by using devm_gpiod_get_index_optional(). Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- drivers/spi/spi-geni-qcom.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c index 6c57f8309a3b..bbe040383d53 100644 --- a/drivers/spi/spi-geni-qcom.c +++ b/drivers/spi/spi-geni-qcom.c @@ -10,6 +10,7 @@ #include <linux/dmaengine.h> #include <linux/dma-mapping.h> #include <linux/dma/qcom-gpi-dma.h> +#include <linux/gpio/consumer.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/log2.h> @@ -115,6 +116,7 @@ struct spi_geni_master { struct dma_chan *rx; int cur_xfer_mode; const struct geni_spi_desc *dev_data; + struct gpio_desc *target_gpio; }; static void spi_slv_setup(struct spi_geni_master *mas) @@ -173,6 +175,9 @@ static void handle_se_timeout(struct spi_controller *spi) xfer = mas->cur_xfer; mas->cur_xfer = NULL; + if (spi->target && mas->target_gpio) + gpiod_set_value(mas->target_gpio, 0); + /* The controller doesn't support the Cancel commnand in target mode */ if (!spi->target) { reinit_completion(&mas->cancel_done); @@ -938,8 +943,12 @@ static int spi_geni_transfer_one(struct spi_controller *spi, if (mas->cur_xfer_mode == GENI_SE_FIFO || mas->cur_xfer_mode == GENI_SE_DMA) { ret = setup_se_xfer(xfer, mas, slv->mode, spi); /* SPI framework expects +ve ret code to wait for transfer complete */ - if (!ret) + if (!ret) { + if (spi->target && mas->target_gpio) + gpiod_set_value(mas->target_gpio, 1); ret = 1; + } + return ret; } return setup_gsi_xfer(xfer, mas, slv, spi); @@ -981,6 +990,8 @@ static irqreturn_t geni_spi_isr(int irq, void *data) if (mas->cur_xfer) { spi_finalize_current_transfer(spi); mas->cur_xfer = NULL; + if (spi->target && mas->target_gpio) + gpiod_set_value(mas->target_gpio, 0); /* * If this happens, then a CMD_DONE came before all the * Tx buffer bytes were sent out. This is unusual, log @@ -1027,6 +1038,8 @@ static irqreturn_t geni_spi_isr(int irq, void *data) if (!mas->tx_rem_bytes && !mas->rx_rem_bytes && xfer) { spi_finalize_current_transfer(spi); mas->cur_xfer = NULL; + if (spi->target && mas->target_gpio) + gpiod_set_value(mas->target_gpio, 0); } } @@ -1131,8 +1144,16 @@ static int spi_geni_probe(struct platform_device *pdev) init_completion(&mas->rx_reset_done); spin_lock_init(&mas->lock); - if (spi->target) + if (spi->target) { spi->target_abort = spi_geni_target_abort; + mas->target_gpio = devm_gpiod_get_index_optional(dev, "ready", 0, + GPIOD_OUT_LOW); + if (IS_ERR(mas->target_gpio)) { + dev_err(dev, "Failed to request GPIO: %ld\n", + PTR_ERR(mas->target_gpio)); + mas->target_gpio = NULL; + } + } pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, 250); -- 2.34.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 2/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity 2026-08-18 13:38 ` [PATCH v3 2/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity Praveen Talari @ 2026-08-18 13:48 ` sashiko-bot 0 siblings, 0 replies; 4+ messages in thread From: sashiko-bot @ 2026-08-18 13:48 UTC (permalink / raw) To: Praveen Talari; +Cc: robh, conor+dt, devicetree Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Masking of legitimate errors (such as -EPROBE_DEFER) from devm_gpiod_get_index_optional() breaks probe deferral. - [High] A race condition between hardware transfer setup and completion can leave the target ready GPIO permanently asserted. - [High] The target_gpio is manipulated from hard IRQ handlers and under spinlocks without verifying it is safe for atomic access. - [Medium] The target ready GPIO is never asserted or deasserted when the controller operates in GENI_GPI_DMA mode. -- --- Patch [2]: [PATCH v3 2/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity --- commit 53485a3ab9e87d880b4b4561671fdbf7ecc3b9cf Author: Praveen Talari <praveen.talari@oss.qualcomm.com> spi: qcom-geni: Use GPIO to notify master of SPI target activity This commit adds support for an optional ready GPIO to notify the SPI master of target activity. The GPIO is asserted when a transfer begins and deasserted on completion or error. > diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c > --- a/drivers/spi/spi-geni-qcom.c > +++ b/drivers/spi/spi-geni-qcom.c [ ... ] > @@ -938,8 +943,12 @@ static int spi_geni_transfer_one(struct spi_controller *spi, > if (mas->cur_xfer_mode == GENI_SE_FIFO || mas->cur_xfer_mode == GENI_SE_DMA) { > ret = setup_se_xfer(xfer, mas, slv->mode, spi); > /* SPI framework expects +ve ret code to wait for transfer complete */ > - if (!ret) > + if (!ret) { > + if (spi->target && mas->target_gpio) > + gpiod_set_value(mas->target_gpio, 1); [Severity: High] Is it possible for the hardware to complete the transfer and trigger the ISR before this GPIO assertion occurs? Since setup_se_xfer() drops the mas->lock spinlock before returning, a fast SPI master or immediate hardware error could trigger the interrupt. If the ISR runs first and deasserts the GPIO: geni_spi_isr() if (mas->cur_xfer) { ... if (spi->target && mas->target_gpio) gpiod_set_value(mas->target_gpio, 0); } Would this code then unconditionally overwrite the GPIO to 1, leaving it permanently asserted and falsely signaling readiness to the master? > + ret = 1; > + } > + > return ret; > } > return setup_gsi_xfer(xfer, mas, slv, spi); [Severity: Medium] Does the target ready GPIO need to be managed when operating in GENI_GPI_DMA mode? If mas->cur_xfer_mode is GENI_GPI_DMA, this path is taken, bypassing the new GPIO assertion logic entirely. Could this leave the external SPI master waiting indefinitely for the readiness signal? [ ... ] > @@ -981,6 +990,8 @@ static irqreturn_t geni_spi_isr(int irq, void *data) > if (mas->cur_xfer) { > spi_finalize_current_transfer(spi); > mas->cur_xfer = NULL; > + if (spi->target && mas->target_gpio) > + gpiod_set_value(mas->target_gpio, 0); [Severity: High] Could this cause a scheduling while atomic panic if the GPIO assigned in the device tree is behind a sleeping controller, such as an I2C or SPI expander? The GPIO is requested during probe without checking gpiod_cansleep() to explicitly reject sleeping GPIOs, and is being manipulated here directly inside a hardirq handler. [ ... ] > @@ -1131,8 +1144,16 @@ static int spi_geni_probe(struct platform_device *pdev) > init_completion(&mas->rx_reset_done); > spin_lock_init(&mas->lock); > > - if (spi->target) > + if (spi->target) { > spi->target_abort = spi_geni_target_abort; > + mas->target_gpio = devm_gpiod_get_index_optional(dev, "ready", 0, > + GPIOD_OUT_LOW); > + if (IS_ERR(mas->target_gpio)) { > + dev_err(dev, "Failed to request GPIO: %ld\n", > + PTR_ERR(mas->target_gpio)); > + mas->target_gpio = NULL; > + } [Severity: High] Does this error handling block probe deferral? By catching all errors from devm_gpiod_get_index_optional() and replacing them with NULL, legitimate errors like -EPROBE_DEFER will be masked. If the GPIO provider has not probed yet, will the SPI controller permanently fail to acquire the GPIO for this boot rather than properly deferring? > + } > > pm_runtime_use_autosuspend(&pdev->dev); > pm_runtime_set_autosuspend_delay(&pdev->dev, 250); -- Sashiko AI review · https://sashiko.dev/#/patchset/20260818-use_gpio_to_notify_master_of_spi_target_activity-v3-0-e1c9e0dabbda@oss.qualcomm.com?part=2 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-18 13:48 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-08-18 13:38 [PATCH v3 0/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity Praveen Talari 2026-08-18 13:38 ` [PATCH v3 1/2] spi: dt-bindings: Document ready-gpios property Praveen Talari 2026-08-18 13:38 ` [PATCH v3 2/2] spi: qcom-geni: Use GPIO to notify master of SPI target activity Praveen Talari 2026-08-18 13:48 ` sashiko-bot
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.