linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Conor Dooley <conor.dooley@microchip.com>
To: <linux-spi@vger.kernel.org>
Cc: <conor@kernel.org>, <conor.dooley@microchip.com>,
	Steve Wilkins <steve.wilkins@raymarine.com>,
	Daire McNamara <daire.mcnamara@microchip.com>,
	Mark Brown <broonie@kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v1 4/6] spi: microchip-core: fix init function not setting the master and motorola modes
Date: Mon, 15 Jul 2024 12:13:55 +0100	[thread overview]
Message-ID: <20240715-designing-thus-05f7c26e1da7@wendy> (raw)
In-Reply-To: <20240715-retail-magnolia-bbd49a657a89@wendy>

From: Steve Wilkins <steve.wilkins@raymarine.com>

mchp_corespi_init() reads the CONTROL register, sets the master and
motorola bits, but doesn't write the value back to the register. The
function also doesn't ensure the controller is disabled at the start,
which may present a problem if the controller was used by an
earlier boot stage as some settings (including the mode) can only be
modified while the controller is disabled.

Fixes: 9ac8d17694b6 ("spi: add support for microchip fpga spi controllers")
Signed-off-by: Steve Wilkins <steve.wilkins@raymarine.com>
Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
---
 drivers/spi/spi-microchip-core.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-microchip-core.c b/drivers/spi/spi-microchip-core.c
index 24a728bde8fda..3d17018cedb08 100644
--- a/drivers/spi/spi-microchip-core.c
+++ b/drivers/spi/spi-microchip-core.c
@@ -292,17 +292,13 @@ static void mchp_corespi_init(struct spi_controller *host, struct mchp_corespi *
 	unsigned long clk_hz;
 	u32 control = mchp_corespi_read(spi, REG_CONTROL);
 
-	control |= CONTROL_MASTER;
+	control &= ~CONTROL_ENABLE;
+	mchp_corespi_write(spi, REG_CONTROL, control);
 
+	control |= CONTROL_MASTER;
 	control &= ~CONTROL_MODE_MASK;
 	control |= MOTOROLA_MODE;
 
-	mchp_corespi_set_framesize(spi, DEFAULT_FRAMESIZE);
-
-	/* max. possible spi clock rate is the apb clock rate */
-	clk_hz = clk_get_rate(spi->clk);
-	host->max_speed_hz = clk_hz;
-
 	/*
 	 * The controller must be configured so that it doesn't remove Chip
 	 * Select until the entire message has been transferred, even if at
@@ -311,11 +307,16 @@ static void mchp_corespi_init(struct spi_controller *host, struct mchp_corespi *
 	 * BIGFIFO mode is also enabled, which sets the fifo depth to 32 frames
 	 * for the 8 bit transfers that this driver uses.
 	 */
-	control = mchp_corespi_read(spi, REG_CONTROL);
 	control |= CONTROL_SPS | CONTROL_BIGFIFO;
 
 	mchp_corespi_write(spi, REG_CONTROL, control);
 
+	mchp_corespi_set_framesize(spi, DEFAULT_FRAMESIZE);
+
+	/* max. possible spi clock rate is the apb clock rate */
+	clk_hz = clk_get_rate(spi->clk);
+	host->max_speed_hz = clk_hz;
+
 	mchp_corespi_enable_ints(spi);
 
 	/*
-- 
2.43.2


  parent reply	other threads:[~2024-07-15 11:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15 11:13 [PATCH v1 0/6] spi-microchip-core fixes & variable word size support Conor Dooley
2024-07-15 11:13 ` [PATCH v1 1/6] spi: microchip-core: fix the issues in the isr Conor Dooley
2024-07-15 11:13 ` [PATCH v1 2/6] spi: microchip-core: defer asserting chip select until just before write to TX FIFO Conor Dooley
2024-07-15 11:13 ` [PATCH v1 3/6] spi: microchip-core: only disable SPI controller when register value change requires it Conor Dooley
2024-07-15 11:13 ` Conor Dooley [this message]
2024-07-15 11:13 ` [PATCH v1 5/6] spi: microchip-core: ensure TX and RX FIFOs are empty at start of a transfer Conor Dooley
2024-07-15 11:13 ` [PATCH v1 6/6] spi: microchip-core: add support for word sizes of 1 to 32 bits Conor Dooley
2024-07-16 13:26 ` [PATCH v1 0/6] spi-microchip-core fixes & variable word size support 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=20240715-designing-thus-05f7c26e1da7@wendy \
    --to=conor.dooley@microchip.com \
    --cc=broonie@kernel.org \
    --cc=conor@kernel.org \
    --cc=daire.mcnamara@microchip.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=steve.wilkins@raymarine.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).