Skip to content

Commit dba4df0

Browse files
Alain VolmatPatrice Chotard
authored andcommitted
spi: stm32_spi: add stm32mp25 / limited-featured support
On STM32MP25 some SPI instances are limited-featured with smaller maximum transfer size. In order to support this, add a st,stm32mp25-spi new compatible and check a STM32MP25 specific register field which indicate if the instance has full or limited feature-set. Change-Id: I986c9f1bb0fbde9067627aee8b0cc29e1c854da9 Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/u-boot/+/523210 Domain-Review: Amelie DELAUNAY <amelie.delaunay@foss.st.com> Tested-by: Alain VOLMAT <alain.volmat@st.com> Reviewed-by: Patrice CHOTARD <patrice.chotard@foss.st.com> ACI: CITOOLS <MDG-smet-aci-reviews@list.st.com> ACI: CIBUILD <MDG-smet-aci-builds@list.st.com> Reviewed-by: Alain VOLMAT <alain.volmat@st.com>
1 parent 7fa945b commit dba4df0

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

drivers/spi/stm32_spi.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#define STM32_SPI_RXDR 0x30
3636
#define STM32_SPI_I2SCFGR 0x50
3737

38+
#define STM32MP25_SPI_HWCFGR1 0x3F0
39+
3840
/* STM32_SPI_CR1 bit fields */
3941
#define SPI_CR1_SPE BIT(0)
4042
#define SPI_CR1_MASRX BIT(8)
@@ -45,6 +47,7 @@
4547

4648
/* STM32_SPI_CR2 bit fields */
4749
#define SPI_CR2_TSIZE GENMASK(15, 0)
50+
#define SPI_CR2_TSIZE_LIMITED GENMASK(9, 0)
4851

4952
/* STM32_SPI_CFG1 bit fields */
5053
#define SPI_CFG1_DSIZE GENMASK(4, 0)
@@ -83,6 +86,11 @@
8386
/* STM32_SPI_I2SCFGR bit fields */
8487
#define SPI_I2SCFGR_I2SMOD BIT(0)
8588

89+
/* STM32MP25_SPI_HWCFGR1 */
90+
#define STM32MP25_SPI_HWCFGR1_FULLCFG GENMASK(27, 24)
91+
#define STM32MP25_SPI_HWCFGR1_FULLCFG_LIMITED 0x0
92+
#define STM32MP25_SPI_HWCFGR1_FULLCFG_FULL 0x1
93+
8694
#define MAX_CS_COUNT 4
8795

8896
/* SPI Master Baud Rate min/max divisor */
@@ -107,6 +115,7 @@ struct stm32_spi_plat {
107115
struct stm32_spi_priv {
108116
ulong bus_clk_rate;
109117
unsigned int fifo_size;
118+
unsigned int max_xferlen; /* maximum transfer length */
110119
unsigned int cur_bpw;
111120
unsigned int cur_hz;
112121
unsigned int cur_xferlen; /* current transfer length in bytes */
@@ -397,7 +406,7 @@ static int stm32_spi_xfer(struct udevice *slave, unsigned int bitlen,
397406

398407
xferlen = bitlen / 8;
399408

400-
if (xferlen <= SPI_CR2_TSIZE)
409+
if (xferlen <= priv->max_xferlen)
401410
writel(xferlen, base + STM32_SPI_CR2);
402411
else
403412
return -EMSGSIZE;
@@ -508,6 +517,31 @@ static int stm32_spi_get_fifo_size(struct udevice *dev)
508517
return count;
509518
}
510519

520+
static unsigned int stm32_spi_get_max_xferlen(struct udevice *dev)
521+
{
522+
struct stm32_spi_plat *plat = dev_get_plat(dev);
523+
void __iomem *base = plat->base;
524+
unsigned int max_xfer_len = SPI_CR2_TSIZE;
525+
526+
/*
527+
* On STM32MP2x, the maximum size depends on the capabilities
528+
* of the instance, which can be checked via FULLCFG of register
529+
* SPI_HWCFGR1
530+
*/
531+
if (device_is_compatible(dev, "st,stm32mp25-spi")) {
532+
unsigned int hwcfgr1 = readl(base + STM32MP25_SPI_HWCFGR1);
533+
534+
if (FIELD_GET(STM32MP25_SPI_HWCFGR1_FULLCFG, hwcfgr1) ==
535+
STM32MP25_SPI_HWCFGR1_FULLCFG_LIMITED) {
536+
max_xfer_len = SPI_CR2_TSIZE_LIMITED;
537+
dev_dbg(dev, "limited-featured, max xfer len = %ld\n",
538+
SPI_CR2_TSIZE_LIMITED);
539+
}
540+
}
541+
542+
return max_xfer_len;
543+
}
544+
511545
static int stm32_spi_of_to_plat(struct udevice *dev)
512546
{
513547
struct stm32_spi_plat *plat = dev_get_plat(dev);
@@ -571,6 +605,7 @@ static int stm32_spi_probe(struct udevice *dev)
571605
reset_deassert(&plat->rst_ctl);
572606

573607
priv->fifo_size = stm32_spi_get_fifo_size(dev);
608+
priv->max_xferlen = stm32_spi_get_max_xferlen(dev);
574609
priv->cur_mode = SPI_FULL_DUPLEX;
575610
priv->cur_xferlen = 0;
576611
priv->cur_bpw = SPI_DEFAULT_WORDLEN;
@@ -648,6 +683,7 @@ static const struct dm_spi_ops stm32_spi_ops = {
648683

649684
static const struct udevice_id stm32_spi_ids[] = {
650685
{ .compatible = "st,stm32h7-spi", },
686+
{ .compatible = "st,stm32mp25-spi", },
651687
{ }
652688
};
653689

0 commit comments

Comments
 (0)