Skip to contentSkip to conversation

spi: dw: configure CPOL/CPHA for each message before sending

PATCH In review Jisheng Zhang 2 participants 2 messages Nov 7 – Nov 16 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: dw: configure CPOL/CPHA for each message before sending

From: Michael Drobot <[email protected]>

Configure CPOL and CPHA in CTRLR0 before starting the message sending procedure. Without this preconfiguration step CPOL and CPHA will be set in dw_spi_update_config(), which runs after CS is asserted when using GPIO-controlled CS. This causes framing errors on any SPI mode other than 0.

---
 drivers/spi/spi-dw-core.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/spi/spi-dw-core.c +28 -0
index 90af2cc9e17d..2bd4ad0f13ad 100644
@@ -507,6 +507,33 @@ static int dw_spi_poll_transfer(struct dw_spi *dws,
 	return 0;
 }
 
+static int dw_spi_prepare_message(struct spi_controller *ctlr,
+				  struct spi_message *msg)
+{
+	struct dw_spi *dws = spi_controller_get_devdata(ctlr);
+	struct spi_device *spi = msg->spi;
+	struct dw_spi_cfg cfg = {
+		.tmode = DW_SPI_CTRLR0_TMOD_TR,
+		.dfs = spi->bits_per_word,
+		.freq = spi->max_speed_hz,
+		.spi_frf = DW_SPI_CTRLR0_SPI_FRF_STD_SPI,
+	};
+
+	/*
+	 * For GPIO CS case, set CPOL/CPHA before the SPI core asserts GPIO CS.
+	 * transfer_one() will configure any per-transfer word size or speed
+	 * overrides.
+	 */
+	if (spi_is_csgpiod(spi)) {
+		dw_spi_enable_chip(dws, 0);
+		dw_spi_update_config(dws, spi, &cfg, NULL);
+		dw_spi_mask_intr(dws, 0xff);
+		dw_spi_enable_chip(dws, 1);
+	}
+
+	return 0;
+}
+
 static int dw_spi_transfer_one(struct spi_controller *ctlr,
 			       struct spi_device *spi,
 			       struct spi_transfer *transfer)
@@ -1382,6 +1409,7 @@ int dw_spi_add_controller(struct device *dev, struct dw_spi *dws)
 
 	if (!target) {
 		ctlr->use_gpio_descriptors = true;
+		ctlr->prepare_message = dw_spi_prepare_message;
 		ctlr->mode_bits |= SPI_LOOP;
 		if (dws->set_cs)
 			ctlr->set_cs = dws->set_cs;
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 1 line · Jisheng Zhang

spi: dw: configure CPOL/CPHA for each message before sending

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.5

Thanks!

[1/1] spi: dw: configure CPOL/CPHA for each message before sending

      https://git.kernel.org/broonie/spi/c/0877b0b54a4c

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark