Linux-SPI Archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Serge Semin <fancer.lancer@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Damien Le Moal <dlemoal@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-riscv@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH] spi: dw: Bail out early on unsupported target mode
Date: Wed,  8 May 2024 12:20:27 +0200	[thread overview]
Message-ID: <7ae28d83bff7351f34782658ae1bb69cc731693e.1715163113.git.geert+renesas@glider.be> (raw)

Currently, the DesignWare SPI controller driver supports only host mode.
However, spi2 on the Kendryte K210 SoC supports only target mode,
triggering an error message on e.g. SiPEED MAiXBiT since commit
98d75b9ef282f6b9 ("spi: dw: Drop default number of CS setting"):

    dw_spi_mmio 50240000.spi: error -22: problem registering spi host
    dw_spi_mmio 50240000.spi: probe with driver dw_spi_mmio failed with error -22

As spi2 rightfully has no "num-cs" property, num_chipselect is now zero,
causing spi_alloc_host() to fail to register the controller.  Before,
the driver silently registered an SPI host controller with 4 chip
selects.

Reject target mode early on and warn the user, getting rid of the
error message.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Commit 98d75b9ef282f6b9 is in spi/for-next (next-20240508 and later).

Overview of all SPI controllers on K210:

    spi0 (52000000.spi):
	num_cs = <4> in k210.dtsi
	num_cs = <1> override in sipeed_maix*.dts and canaan_kd233.dts
	DW_SPI_SER says 0xf (but value is unused)

    spi1 (53000000.spi):
	num_cs = <4> in k210.dtsi
	num_cs = <1> override in sipeed_maix*.dts and canaan_kd233.dts
	DW_SPI_SER says 0xf (but value is unused)

    spi2 (53000000.spi):
	spi-slave
	no num_cs property
	DW_SPI_SER says 0
	dw_spi_mmio 50240000.spi: error -22: problem registering spi host
	dw_spi_mmio 50240000.spi: probe with driver dw_spi_mmio failed with error -22

    spi3 (54000000.spi):
	num_cs = <4> in k210.dtsi
	DW_SPI_SER says 0x1 (but value is unused)
	Used in sipeed_maix*.dts, unused in canaan_kd233.dts

See also "[PATCH 2/2] riscv: dts: canaan: Disable I/O devices unless
used"
https://lore.kernel.org/r/f85d460efd7ad85ec59c9253c989b10a07f2ff24.1715163174.git.geert+renesas@glider.be
---
 drivers/spi/spi-dw-mmio.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index c56de35eca988ee4..819907e332c4b004 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -321,6 +321,11 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
 	struct dw_spi *dws;
 	int ret;
 
+	if (device_property_read_bool(&pdev->dev, "spi-slave")) {
+		dev_warn(&pdev->dev, "spi-slave is not yet supported\n");
+		return -ENODEV;
+	}
+
 	dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio),
 			GFP_KERNEL);
 	if (!dwsmmio)
-- 
2.34.1


             reply	other threads:[~2024-05-08 10:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 10:20 Geert Uytterhoeven [this message]
2024-05-09  6:55 ` [PATCH] spi: dw: Bail out early on unsupported target mode Damien Le Moal
2024-05-10  6:22 ` Mark Brown

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=7ae28d83bff7351f34782658ae1bb69cc731693e.1715163113.git.geert+renesas@glider.be \
    --to=geert+renesas@glider.be \
    --cc=broonie@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=fancer.lancer@gmail.com \
    --cc=linux-riscv@vger.kernel.org \
    --cc=linux-spi@vger.kernel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).