Skip to contentSkip to conversation

Add SD card support to the Beagle-V-Fire

PATCH In review Eoin Dickson 3 participants 6 messages Jul 8, 2025 – Jul 24, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover Add SD card support to the Beagle-V-Fire

From: Eoin Dickson <[email protected]>

This series add SD card support for the Beagle-V-Fire. The Beagle-V-Fire uses the Microchip coreqspi xfer function and a gpio chip select, so this series adds gpio support for PolarFire SoC and the xfer function into the Microchip coreqspi driver.

Eoin Dickson (2):
gpio: add PolarFire SoC GPIO and Core GPIO driver
spi: coreqspi: add xfer function for PolarFire SoC

 drivers/gpio/Kconfig             |   5 +
 drivers/gpio/Makefile            |   1 +
 drivers/gpio/mpfs_gpio.c         | 198 +++++++++++++++++++++++++++++++
 drivers/spi/microchip_coreqspi.c | 113 +++++++++++++++++-
 4 files changed, 315 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpio/mpfs_gpio.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/2 gpio: add PolarFire SoC GPIO and Core GPIO driver

From: Eoin Dickson <[email protected]>

This driver adds GPIO support for PolarFire SoC family, this is required to add sd card support on the Beagle-V-Fire as it uses GPIO chip selects

---
 drivers/gpio/Kconfig     |   5 +
 drivers/gpio/Makefile    |   1 +
 drivers/gpio/mpfs_gpio.c | 198 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+)
 create mode 100644 drivers/gpio/mpfs_gpio.c
drivers/gpio/Kconfig +5 -0
index e11109fb56d..a47b4be09f7 100644
@@ -729,5 +729,10 @@ config SPL_ADP5585_GPIO
 	depends on SPL_DM_GPIO && SPL_I2C
 	help
 	  Support ADP5585 GPIO expander in SPL.
+config MPFS_GPIO
+	bool "Enable Polarfire SoC GPIO driver"
+	depends on DM_GPIO
+	help
+		Enable to support the GPIO driver on Polarfire SoC
 
 endif
drivers/gpio/Makefile +1 -0
index d64c14db5cf..222d51b6d89 100644
@@ -81,3 +81,4 @@ obj-$(CONFIG_SLG7XL45106_I2C_GPO)	+= gpio_slg7xl45106.o
 obj-$(CONFIG_FTGPIO010)		+= ftgpio010.o
 obj-$(CONFIG_$(PHASE_)ADP5585_GPIO)	+= adp5585_gpio.o
 obj-$(CONFIG_RZG2L_GPIO)	+= rzg2l-gpio.o
+obj-$(CONFIG_MPFS_GPIO)	+= mpfs_gpio.o
drivers/gpio/mpfs_gpio.c new file +198 -0

198 lines not on this page · raw message

Signature · 1 line
2.34.1
Acked-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] gpio: add PolarFire SoC GPIO and Core GPIO driver

Quoted 5 lines · Eoin Dickson

From: Eoin Dickson <[email protected]>

This driver adds GPIO support for PolarFire SoC family, this is required to add sd card support on the Beagle-V-Fire as it uses GPIO chip selects

Quoted 7 lines
---
 drivers/gpio/Kconfig     |   5 +
 drivers/gpio/Makefile    |   1 +
 drivers/gpio/mpfs_gpio.c | 198 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+)
 create mode 100644 drivers/gpio/mpfs_gpio.c
#3 lore raw

Re: [PATCH v3 1/2] gpio: add PolarFire SoC GPIO and Core GPIO driver

Quoted 14 lines · Leo Liang
Quoted 5 lines · Eoin Dickson

From: Eoin Dickson <[email protected]>

This driver adds GPIO support for PolarFire SoC family, this is required to add sd card support on the Beagle-V-Fire as it uses GPIO chip selects

Quoted 7 lines
---
 drivers/gpio/Kconfig     |   5 +
 drivers/gpio/Makefile    |   1 +
 drivers/gpio/mpfs_gpio.c | 198 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+)
 create mode 100644 drivers/gpio/mpfs_gpio.c
Quoted 1 line

Nothing enables this driver today. Enabling it on sandbox gives:
/home/trini/work/u-boot/u-boot/drivers/gpio/mpfs_gpio.c: In function ‘mchp_gpio_probe’:
/home/trini/work/u-boot/u-boot/drivers/gpio/mpfs_gpio.c:139:20: error: assignment to ‘const struct mpfs_gpio_reg_offsets *’ from ‘ulong’ {aka ‘long unsigned int’} makes pointer from integer without a cast [-Werror=int-conversion]
139 | plat->regs = dev_get_driver_data(dev);
| ^
/home/trini/work/u-boot/u-boot/drivers/gpio/mpfs_gpio.c: At top level:
/home/trini/work/u-boot/u-boot/drivers/gpio/mpfs_gpio.c:163:25: error: initialization of ‘long unsigned int’ from ‘const struct mpfs_gpio_reg_offsets *’ makes integer from pointer without a cast [-Werror=int-conversion]
163 | .data = &mpfs_reg_offsets,
| ^
/home/trini/work/u-boot/u-boot/drivers/gpio/mpfs_gpio.c:163:25: note: (near initialization for ‘mchp_gpio_match[0].data’)
/home/trini/work/u-boot/u-boot/drivers/gpio/mpfs_gpio.c:166:25: error: initialization of ‘long unsigned int’ from ‘const struct mpfs_gpio_reg_offsets *’ makes integer from pointer without a cast [-Werror=int-conversion]
166 | .data = &coregpio_reg_offsets,
| ^
/home/trini/work/u-boot/u-boot/drivers/gpio/mpfs_gpio.c:166:25: note: (near initialization for ‘mchp_gpio_match[1].data’)
/home/trini/work/u-boot/u-boot/drivers/gpio/mpfs_gpio.c:174:35: error: initialization of ‘int (*)(struct udevice *, unsigned int)’ from incompatible pointer type ‘_Bool (*)(struct udevice *, u32)’ {aka ‘_Bool (*)(struct udevice *, unsigned int)’} [-Werror=incompatible-pointer-types]
174 | .get_value = mchp_gpio_get_value,

      |                                   ^~~~~~~~~~~~~~~~~~~

/home/trini/work/u-boot/u-boot/drivers/gpio/mpfs_gpio.c:174:35: note: (near initialization for ‘mchp_gpio_ops.get_value’)
cc1: all warnings being treated as errors

Please fix, thanks.

Signature · 1 line
Tom
#4 lore raw

PATCH v3 2/2 spi: coreqspi: add xfer function for PolarFire SoC

In reply to Eoin Dickson

From: Eoin Dickson <[email protected]>

Add xfer function to PolarFire SoC coreqspi driver. The read and write operations are limited to one byte at a time instead of four as CMD18 (multiple block read) reads garbage when four byte ops are enabled.

---
 drivers/spi/microchip_coreqspi.c | 113 ++++++++++++++++++++++++++++++-
 1 file changed, 111 insertions(+), 2 deletions(-)
drivers/spi/microchip_coreqspi.c +111 -2
index 234b1688272..84b8965b7fc 100644
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/types.h>
 #include <linux/sizes.h>
+#include <asm/gpio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -97,6 +98,8 @@ DECLARE_GLOBAL_DATA_PTR;
 #define REG_X4_TX_DATA         (0x4c)
 #define REG_FRAMESUP           (0x50)
 
+#define MAX_CS_COUNT 1
+
 /**
  * struct mchp_coreqspi - Defines qspi driver instance
  * @regs:              Address of the QSPI controller registers
@@ -113,6 +116,7 @@ struct mchp_coreqspi {
 	u8 *rxbuf;
 	int tx_len;
 	int rx_len;
+	struct gpio_desc cs_gpios[MAX_CS_COUNT];
 };
 
 static void mchp_coreqspi_init_hw(struct mchp_coreqspi *qspi)
@@ -172,7 +176,7 @@ static inline void mchp_coreqspi_write_op(struct mchp_coreqspi *qspi, bool word)
 	while (qspi->tx_len >= 4) {
 		while (readl(qspi->regs + REG_STATUS) & STATUS_TXFIFOFULL)
 			;
-		data = *(u32 *)qspi->txbuf;
+		data = qspi->txbuf ? *((u32 *)qspi->txbuf) : 0xFF;
 		qspi->txbuf += 4;
 		qspi->tx_len -= 4;
 		writel(data, qspi->regs + REG_X4_TX_DATA);
@@ -184,7 +188,7 @@ static inline void mchp_coreqspi_write_op(struct mchp_coreqspi *qspi, bool word)
 	while (qspi->tx_len--) {
 		while (readl(qspi->regs + REG_STATUS) & STATUS_TXFIFOFULL)
 			;
-		data =  *qspi->txbuf++;
+		data = qspi->txbuf ? *qspi->txbuf++ : 0xFF;
 		writel(data, qspi->regs + REG_TX_DATA);
 	}
 }
@@ -471,6 +475,110 @@ static int mchp_coreqspi_probe(struct udevice *dev)
 	/* Init the mpfs qspi hw */
 	mchp_coreqspi_init_hw(qspi);
 
+	if (CONFIG_IS_ENABLED(DM_GPIO)) {
+		int i;
+
+		ret = gpio_request_list_by_name(dev, "cs-gpios", qspi->cs_gpios,
+							ARRAY_SIZE(qspi->cs_gpios), 0);
+
+		if (ret < 0) {
+			pr_err("Can't get %s gpios! Error: %d", dev->name, ret);
+			return ret;
+		}
+
+		for (i = 0; i < ARRAY_SIZE(qspi->cs_gpios); i++) {
+			if (!dm_gpio_is_valid(&qspi->cs_gpios[i]))
+				continue;
+			dm_gpio_set_dir_flags(&qspi->cs_gpios[i], GPIOD_IS_OUT);
+		}
+	}
+
+	u32 control = readl(qspi->regs + REG_CONTROL);
+
+	control |= (CONTROL_MASTER | CONTROL_ENABLE);
+	control &= ~CONTROL_CLKIDLE;
+	writel(control, qspi->regs + REG_CONTROL);
+
+	return 0;
+}
+
+static void mchp_coreqspi_cs_activate(struct udevice *dev)
+{
+	struct udevice *bus = dev_get_parent(dev);
+	struct mchp_coreqspi *qspi = dev_get_priv(bus);
+	struct dm_spi_slave_plat *slave_plat = dev_get_parent_plat(dev);
+	u32 cs = slave_plat->cs[0];
+
+	if (CONFIG_IS_ENABLED(DM_GPIO) && dm_gpio_is_valid(&qspi->cs_gpios[cs]))
+		dm_gpio_set_value(&qspi->cs_gpios[cs], 1);
+}
+
+static void mchp_coreqspi_cs_deactivate(struct udevice *dev)
+{
+	struct udevice *bus = dev_get_parent(dev);
+	struct mchp_coreqspi *qspi = dev_get_priv(bus);
+	struct dm_spi_slave_plat *slave_plat = dev_get_parent_plat(dev);
+	u32 cs = slave_plat->cs[0];
+
+	if (CONFIG_IS_ENABLED(DM_GPIO) && dm_gpio_is_valid(&qspi->cs_gpios[cs]))
+		dm_gpio_set_value(&qspi->cs_gpios[cs], 0);
+}
+
+static int mchp_coreqspi_xfer(struct udevice *dev, unsigned int bitlen,
+				const void *dout, void *din, unsigned long flags)
+{
+	struct udevice *bus = dev_get_parent(dev);
+	struct mchp_coreqspi *qspi = dev_get_priv(bus);
+	struct spi_slave *slave = dev_get_parent_priv(dev);
+	uint total_bytes = bitlen >> 3; /* fixed 8-bit word length */
+	u32 control, frames;
+
+	int err = 0;
+
+	err = mchp_coreqspi_wait_for_ready(slave);
+	if (err)
+		return err;
+
+	control = readl(qspi->regs + REG_CONTROL);
+	control &= ~(CONTROL_MODE12_MASK | CONTROL_MODE0);
+	writel(control, qspi->regs + REG_CONTROL);
+
+	frames = total_bytes & BYTESUPPER_MASK;
+	writel(frames, qspi->regs + REG_FRAMESUP);
+
+	frames |= FRAMES_FLAGBYTE;
+	writel(frames, qspi->regs + REG_FRAMES);
+
+	if (flags & SPI_XFER_BEGIN)
+		mchp_coreqspi_cs_activate(dev);
+
+	if (bitlen == 0)
+		goto out;
+
+	if (bitlen % 8) { // Non byte aligned SPI transfer
+		flags |= SPI_XFER_END;
+		goto out;
+	}
+
+	qspi->txbuf = (u8 *)dout;
+	qspi->rxbuf = (u8 *)din;
+
+	while (total_bytes) {
+		qspi->tx_len = 1;
+		qspi->rx_len = 1;
+		total_bytes--;
+
+		if (din) {
+			mchp_coreqspi_write_op(qspi, true);
+			mchp_coreqspi_read_op(qspi);
+		} else {
+			mchp_coreqspi_write_op(qspi, true);
+		}
+	}
+out:
+	if (flags & SPI_XFER_END)
+		mchp_coreqspi_cs_deactivate(dev);
+
 	return 0;
 }
 
@@ -483,6 +591,7 @@ static const struct spi_controller_mem_ops mchp_coreqspi_mem_ops = {
 static const struct dm_spi_ops mchp_coreqspi_ops = {
 	.claim_bus      = mchp_coreqspi_claim_bus,
 	.release_bus    = mchp_coreqspi_release_bus,
+	.xfer           = mchp_coreqspi_xfer,
 	.set_speed      = mchp_coreqspi_set_speed,
 	.set_mode       = mchp_coreqspi_set_mode,
 	.mem_ops        = &mchp_coreqspi_mem_ops,
Signature · 1 line
2.34.1
Acked-by on v3 2/2
#5 lore raw

Re: [PATCH v3 2/2] spi: coreqspi: add xfer function for PolarFire SoC

Quoted 10 lines · Eoin Dickson

From: Eoin Dickson <[email protected]>

Add xfer function to PolarFire SoC coreqspi driver. The read and write operations are limited to one byte at a time instead of four as CMD18 (multiple block read) reads garbage when four byte ops are enabled.

---
 drivers/spi/microchip_coreqspi.c | 113 ++++++++++++++++++++++++++++++-
 1 file changed, 111 insertions(+), 2 deletions(-)