From: James Clark <james.clark@linaro.org>
To: Vladimir Oltean <olteanv@gmail.com>,
Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Matti Vaittinen <mazziesaccount@gmail.com>
Cc: Conor Dooley <conor+dt@kernel.org>, Frank Li <Frank.Li@nxp.com>,
Chester Lin <chester62515@gmail.com>,
Matthias Brugger <mbrugger@suse.com>,
Ghennadi Procopciuc <ghennadi.procopciuc@oss.nxp.com>,
NXP S32 Linux Team <s32@nxp.com>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Chao Fu <B44548@freescale.com>,
Xiubo Li <Li.Xiubo@freescale.com>,
Lukasz Majewski <lukma@denx.de>,
linux-spi@vger.kernel.org, imx@lists.linux.dev,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Vladimir Oltean <vladimir.oltean@nxp.com>,
Dan Carpenter <dan.carpenter@linaro.org>,
Andra-Teodora Ilie <andra.ilie@nxp.com>,
Bogdan-Gabriel Roman <bogdan-gabriel.roman@nxp.com>,
Larisa Grigore <larisa.grigore@nxp.com>,
James Clark <james.clark@linaro.org>
Subject: [PATCH v2 11/14] spi: spi-fsl-dspi: Enable modified transfer protocol on S32G
Date: Thu, 22 May 2025 15:51:40 +0100 [thread overview]
Message-ID: <20250522-james-nxp-spi-v2-11-bea884630cfb@linaro.org> (raw)
In-Reply-To: <20250522-james-nxp-spi-v2-0-bea884630cfb@linaro.org>
From: Andra-Teodora Ilie <andra.ilie@nxp.com>
S32G supports modified transfer protocol where both host and target
devices sample later in the SCK period than in Classic SPI mode to allow
the logic to tolerate more delays in device pads and board traces. Set
MTFE bit in MCR register for frequencies higher than 25MHz.
Signed-off-by: Andra-Teodora Ilie <andra.ilie@nxp.com>
Signed-off-by: Bogdan-Gabriel Roman <bogdan-gabriel.roman@nxp.com>
Signed-off-by: Larisa Grigore <larisa.grigore@nxp.com>
Signed-off-by: James Clark <james.clark@linaro.org>
---
drivers/spi/spi-fsl-dspi.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index a3efe1bd3b37..01af641fa757 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -24,6 +24,7 @@
#define SPI_MCR 0x00
#define SPI_MCR_HOST BIT(31)
+#define SPI_MCR_MTFE BIT(26)
#define SPI_MCR_PCSIS(x) ((x) << 16)
#define SPI_MCR_CLR_TXF BIT(11)
#define SPI_MCR_CLR_RXF BIT(10)
@@ -37,6 +38,7 @@
#define SPI_CTAR(x) (0x0c + (((x) & GENMASK(2, 0)) * 4))
#define SPI_CTAR_FMSZ(x) (((x) << 27) & GENMASK(30, 27))
+#define SPI_CTAR_DBR BIT(31)
#define SPI_CTAR_CPOL BIT(26)
#define SPI_CTAR_CPHA BIT(25)
#define SPI_CTAR_LSBFE BIT(24)
@@ -111,6 +113,8 @@
#define DMA_COMPLETION_TIMEOUT msecs_to_jiffies(3000)
+#define SPI_25MHZ 25000000
+
struct chip_data {
u32 ctar_val;
};
@@ -346,6 +350,7 @@ struct fsl_dspi {
const void *tx;
void *rx;
u16 tx_cmd;
+ bool mtf_enabled;
const struct fsl_dspi_devtype_data *devtype_data;
struct completion xfer_done;
@@ -722,7 +727,7 @@ static void dspi_release_dma(struct fsl_dspi *dspi)
}
static void hz_to_spi_baud(char *pbr, char *br, int speed_hz,
- unsigned long clkrate)
+ unsigned long clkrate, bool mtf_enabled)
{
/* Valid baud rate pre-scaler values */
int pbr_tbl[4] = {2, 3, 5, 7};
@@ -739,7 +744,13 @@ static void hz_to_spi_baud(char *pbr, char *br, int speed_hz,
for (i = 0; i < ARRAY_SIZE(brs); i++)
for (j = 0; j < ARRAY_SIZE(pbr_tbl); j++) {
- scale = brs[i] * pbr_tbl[j];
+ if (mtf_enabled) {
+ /* In MTF mode DBR=1 so frequency is doubled */
+ scale = (brs[i] * pbr_tbl[j]) / 2;
+ } else {
+ scale = brs[i] * pbr_tbl[j];
+ }
+
if (scale >= scale_needed) {
if (scale < minscale) {
minscale = scale;
@@ -1146,6 +1157,20 @@ static int dspi_transfer_one_message(struct spi_controller *ctlr,
return status;
}
+static int dspi_set_mtf(struct fsl_dspi *dspi)
+{
+ if (spi_controller_is_target(dspi->ctlr))
+ return 0;
+
+ if (dspi->mtf_enabled)
+ regmap_update_bits(dspi->regmap, SPI_MCR, SPI_MCR_MTFE,
+ SPI_MCR_MTFE);
+ else
+ regmap_update_bits(dspi->regmap, SPI_MCR, SPI_MCR_MTFE, 0);
+
+ return 0;
+}
+
static int dspi_setup(struct spi_device *spi)
{
struct fsl_dspi *dspi = spi_controller_get_devdata(spi->controller);
@@ -1204,7 +1229,16 @@ static int dspi_setup(struct spi_device *spi)
cs_sck_delay, sck_cs_delay);
clkrate = clk_get_rate(dspi->clk);
- hz_to_spi_baud(&pbr, &br, spi->max_speed_hz, clkrate);
+
+ if (is_s32g_dspi(dspi) && spi->max_speed_hz > SPI_25MHZ)
+ dspi->mtf_enabled = true;
+ else
+ dspi->mtf_enabled = false;
+
+ dspi_set_mtf(dspi);
+
+ hz_to_spi_baud(&pbr, &br, spi->max_speed_hz, clkrate,
+ dspi->mtf_enabled);
/* Set PCS to SCK delay scale values */
ns_delay_scale(&pcssck, &cssck, cs_sck_delay, clkrate);
@@ -1226,6 +1260,9 @@ static int dspi_setup(struct spi_device *spi)
SPI_CTAR_PBR(pbr) |
SPI_CTAR_BR(br);
+ if (dspi->mtf_enabled)
+ chip->ctar_val |= SPI_CTAR_DBR;
+
if (spi->mode & SPI_LSB_FIRST)
chip->ctar_val |= SPI_CTAR_LSBFE;
}
@@ -1352,6 +1389,8 @@ static int dspi_resume(struct device *dev)
return ret;
}
+ dspi_set_mtf(dspi);
+
if (dspi->irq)
enable_irq(dspi->irq);
--
2.34.1
next prev parent reply other threads:[~2025-05-22 14:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 14:51 [PATCH v2 00/14] spi: spi-fsl-dspi: DSPI support for NXP S32G platforms James Clark
2025-05-22 14:51 ` [PATCH v2 01/14] spi: spi-fsl-dspi: restrict register range for regmap access James Clark
2025-05-22 14:51 ` [PATCH v2 02/14] spi: spi-fsl-dspi: Halt the module after a new message transfer James Clark
2025-05-22 14:51 ` [PATCH v2 03/14] spi: spi-fsl-dspi: Reset SR flags before sending a new message James Clark
2025-05-22 14:51 ` [PATCH v2 04/14] spi: spi-fsl-dspi: Re-use one volatile regmap for both device types James Clark
2025-05-22 14:51 ` [PATCH v2 05/14] spi: spi-fsl-dspi: Define regmaps per device James Clark
2025-05-22 14:51 ` [PATCH v2 06/14] spi: spi-fsl-dspi: Add config and regmaps for S32G platforms James Clark
2025-05-22 14:51 ` [PATCH v2 07/14] spi: spi-fsl-dspi: Use spi_alloc_target for target James Clark
2025-05-22 14:51 ` [PATCH v2 08/14] spi: spi-fsl-dspi: Avoid setup_accel logic for DMA transfers James Clark
2025-05-22 14:51 ` [PATCH v2 09/14] spi: spi-fsl-dspi: Use DMA for S32G controller in target mode James Clark
2025-05-22 14:51 ` [PATCH v2 10/14] spi: spi-fsl-dspi: Reinitialize DSPI regs after resuming for S32G James Clark
2025-05-22 14:51 ` James Clark [this message]
2025-05-22 14:51 ` [PATCH v2 12/14] dt-bindings: spi: dspi: Add S32G support James Clark
2025-05-22 14:51 ` [PATCH v2 13/14] spi: spi-fsl-dspi: Enable support for S32G platforms James Clark
2025-05-22 14:51 ` [PATCH v2 14/14] arm64: dts: Add DSPI entries " James Clark
2025-06-19 7:38 ` Shawn Guo
2025-05-22 17:17 ` (subset) [PATCH v2 00/14] spi: spi-fsl-dspi: DSPI support for NXP " Mark Brown
2025-06-09 19:33 ` 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=20250522-james-nxp-spi-v2-11-bea884630cfb@linaro.org \
--to=james.clark@linaro.org \
--cc=B44548@freescale.com \
--cc=Frank.Li@nxp.com \
--cc=Li.Xiubo@freescale.com \
--cc=andra.ilie@nxp.com \
--cc=bogdan-gabriel.roman@nxp.com \
--cc=broonie@kernel.org \
--cc=chester62515@gmail.com \
--cc=conor+dt@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=ghennadi.procopciuc@oss.nxp.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=larisa.grigore@nxp.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=lukma@denx.de \
--cc=mazziesaccount@gmail.com \
--cc=mbrugger@suse.com \
--cc=olteanv@gmail.com \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=s32@nxp.com \
--cc=shawnguo@kernel.org \
--cc=vladimir.oltean@nxp.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).