From: Sean Anderson <sean.anderson@linux.dev>
To: Mark Brown <broonie@kernel.org>,
Michal Simek <michal.simek@amd.com>,
linux-spi@vger.kernel.org
Cc: Jinjie Ruan <ruanjinjie@huawei.com>,
Miquel Raynal <miquel.raynal@bootlin.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
David Lechner <dlechner@baylibre.com>,
Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>,
Sean Anderson <sean.anderson@linux.dev>
Subject: [PATCH v2 8/9] spi: zynqmp-gqspi: Support GPIO chip selects
Date: Mon, 16 Jun 2025 18:00:53 -0400 [thread overview]
Message-ID: <20250616220054.3968946-9-sean.anderson@linux.dev> (raw)
In-Reply-To: <20250616220054.3968946-1-sean.anderson@linux.dev>
GPIO chipselects use the traditional SPI API instead of the SPIMEM API.
Implement it with transfer_one and set_cs (for non-GPIO chipselects). At
the moment we only support half-duplex transfers, which is good enough
to access SPI flashes.
Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
---
Changes in v2:
- Use ->buses instead of an upper/lower split
drivers/spi/spi-zynqmp-gqspi.c | 93 ++++++++++++++++++++++++++++++----
1 file changed, 84 insertions(+), 9 deletions(-)
diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
index b36159dbaff0..87d375fae653 100644
--- a/drivers/spi/spi-zynqmp-gqspi.c
+++ b/drivers/spi/spi-zynqmp-gqspi.c
@@ -499,6 +499,15 @@ static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high)
dev_err(xqspi->dev, "Chip select timed out\n");
}
+static void zynqmp_qspi_set_cs(struct spi_device *qspi, bool is_high)
+{
+ struct zynqmp_qspi *xqspi = spi_controller_get_devdata(qspi->controller);
+
+ mutex_lock(&xqspi->op_lock);
+ zynqmp_qspi_chipselect(qspi, is_high);
+ mutex_unlock(&xqspi->op_lock);
+}
+
/**
* zynqmp_qspi_selectspimode - Selects SPI mode - x1 or x2 or x4.
* @xqspi: xqspi is a pointer to the GQSPI instance
@@ -1197,6 +1206,73 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
return err;
}
+static int zynqmp_qspi_transfer_one(struct spi_controller *ctlr,
+ struct spi_device *spi,
+ struct spi_transfer *transfer)
+{
+ struct zynqmp_qspi *xqspi = spi_controller_get_devdata(ctlr);
+ unsigned long timeout;
+ u32 genfifoentry;
+ u32 mask = 0;
+ int ret;
+
+ dev_dbg(xqspi->dev, "xfer %u/%u %u\n", transfer->tx_nbits,
+ transfer->rx_nbits, transfer->len);
+
+ if (transfer->tx_nbits && transfer->rx_nbits)
+ return -EOPNOTSUPP;
+
+ guard(mutex)(&xqspi->op_lock);
+ zynqmp_qspi_config_op(xqspi, transfer->speed_hz, spi->mode);
+ if (spi_get_csgpiod(spi, 0)) {
+ xqspi->genfifobus =
+ FIELD_PREP(GQSPI_GENFIFO_BUS_MASK, spi->buses);
+ xqspi->genfifocs = 0;
+ }
+ genfifoentry = xqspi->genfifocs | xqspi->genfifobus;
+
+ reinit_completion(&xqspi->data_completion);
+ if (transfer->tx_nbits) {
+ xqspi->txbuf = transfer->tx_buf;
+ xqspi->rxbuf = NULL;
+ xqspi->bytes_to_transfer = transfer->len;
+ xqspi->bytes_to_receive = 0;
+ zynqmp_qspi_write_op(xqspi, transfer->tx_nbits, genfifoentry);
+ mask = GQSPI_IER_TXEMPTY_MASK | GQSPI_IER_GENFIFOEMPTY_MASK |
+ GQSPI_IER_TXNOT_FULL_MASK;
+ timeout = zynqmp_qspi_timeout(xqspi, transfer->tx_nbits,
+ transfer->len);
+ } else {
+ xqspi->txbuf = NULL;
+ xqspi->rxbuf = transfer->rx_buf;
+ xqspi->bytes_to_transfer = 0;
+ xqspi->bytes_to_receive = transfer->len;
+ ret = zynqmp_qspi_read_op(xqspi, transfer->rx_nbits,
+ genfifoentry);
+ if (ret)
+ return ret;
+
+ if (xqspi->mode != GQSPI_MODE_DMA)
+ mask = GQSPI_IER_GENFIFOEMPTY_MASK |
+ GQSPI_IER_RXNEMPTY_MASK | GQSPI_IER_RXEMPTY_MASK;
+ timeout = zynqmp_qspi_timeout(xqspi, transfer->rx_nbits,
+ transfer->len);
+ }
+
+ zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
+ zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST) |
+ GQSPI_CFG_START_GEN_FIFO_MASK);
+ if (mask)
+ zynqmp_gqspi_write(xqspi, GQSPI_IER_OFST, mask);
+ else
+ zynqmp_gqspi_write(xqspi, GQSPI_QSPIDMA_DST_I_EN_OFST,
+ GQSPI_QSPIDMA_DST_I_EN_DONE_MASK);
+
+ if (!wait_for_completion_timeout(&xqspi->data_completion, timeout))
+ return -ETIMEDOUT;
+ return 0;
+}
+
static const struct dev_pm_ops zynqmp_qspi_dev_pm_ops = {
SET_RUNTIME_PM_OPS(zynqmp_runtime_suspend,
zynqmp_runtime_resume, NULL)
@@ -1316,27 +1392,26 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
if (ret)
goto clk_dis_all;
+ ctlr->max_native_cs = 2;
ret = of_property_read_u32(np, "num-cs", &num_cs);
- if (ret < 0) {
+ if (ret < 0)
ctlr->num_chipselect = GQSPI_DEFAULT_NUM_CS;
- } else if (num_cs > GQSPI_MAX_NUM_CS) {
- ret = -EINVAL;
- dev_err(&pdev->dev, "only %d chip selects are available\n",
- GQSPI_MAX_NUM_CS);
- goto clk_dis_all;
- } else {
+ else
ctlr->num_chipselect = num_cs;
- }
ctlr->num_buses = 2;
- ctlr->flags = SPI_CONTROLLER_DEFAULT_BUS_IS_CS;
+ ctlr->flags = SPI_CONTROLLER_DEFAULT_BUS_IS_CS |
+ SPI_CONTROLLER_HALF_DUPLEX;
ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
ctlr->mem_ops = &zynqmp_qspi_mem_ops;
ctlr->mem_caps = &zynqmp_qspi_mem_caps;
ctlr->setup = zynqmp_qspi_setup_op;
+ ctlr->set_cs = zynqmp_qspi_set_cs;
+ ctlr->transfer_one = zynqmp_qspi_transfer_one;
ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
ctlr->dev.of_node = np;
ctlr->auto_runtime_pm = true;
+ ctlr->use_gpio_descriptors = true;
ret = devm_spi_register_controller(&pdev->dev, ctlr);
if (ret) {
--
2.35.1.1320.gc452695387.dirty
next prev parent reply other threads:[~2025-06-16 22:22 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-16 22:00 [PATCH v2 0/9] spi: zynqmp-gqspi: Support multiple buses and add GPIO support Sean Anderson
2025-06-16 22:00 ` [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property Sean Anderson
2025-06-17 6:05 ` Krzysztof Kozlowski
2025-08-14 20:55 ` David Lechner
2025-08-14 21:15 ` Sean Anderson
2025-08-14 21:17 ` David Lechner
2025-08-14 21:34 ` Sean Anderson
2025-08-14 22:08 ` Mark Brown
2025-08-15 15:49 ` David Lechner
2025-08-18 8:28 ` Miquel Raynal
2025-08-18 14:55 ` Sean Anderson
2025-08-18 15:22 ` David Lechner
2025-08-18 14:56 ` Sean Anderson
2025-08-18 15:26 ` David Lechner
2025-06-16 22:00 ` [PATCH v2 2/9] dt-bindings: spi: zynqmp-qspi: Add example dual upper/lower bus Sean Anderson
2025-06-17 1:59 ` Rob Herring (Arm)
2025-06-18 18:27 ` David Lechner
2025-06-19 16:20 ` Sean Anderson
2025-06-19 16:29 ` David Lechner
2025-06-16 22:00 ` [PATCH v2 3/9] spi: Support multi-bus controllers Sean Anderson
2025-06-16 22:00 ` [PATCH v2 4/9] spi: Add flag to determine default bus Sean Anderson
2025-06-16 22:00 ` [PATCH v2 5/9] spi: zynqmp-gqspi: Support multiple buses Sean Anderson
2025-06-16 23:10 ` David Lechner
2025-06-17 13:21 ` kernel test robot
2025-06-16 22:00 ` [PATCH v2 6/9] spi: zynqmp-gqspi: Pass speed directly to config_op Sean Anderson
2025-06-16 22:00 ` [PATCH v2 7/9] spi: zynqmp-gqspi: Configure SPI mode dynamically Sean Anderson
2025-06-16 22:00 ` Sean Anderson [this message]
2025-06-16 22:00 ` [PATCH v2 9/9] ARM64: xilinx: zynqmp: Add spi-buses property Sean Anderson
2025-06-17 6:07 ` Krzysztof Kozlowski
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=20250616220054.3968946-9-sean.anderson@linux.dev \
--to=sean.anderson@linux.dev \
--cc=amit.kumar-mahapatra@amd.com \
--cc=broonie@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=miquel.raynal@bootlin.com \
--cc=ruanjinjie@huawei.com \
/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).