Skip to contentSkip to conversation

vf610: fix GPIO output and console input

PATCH New Mehmet Fide 1 participant 3 messages Aug 6 GPIO

lore
Share & tools
lore
#0 lore raw

cover vf610: fix GPIO output and console input

From: Mehmet Fide <[email protected]>

Two independent vf610 fixes found while moving a Colibri VF50 product from the Toradex 2015.04 fork to mainline U-Boot.

Both are long standing and both fail silently, which is why they are easy to miss: the gpio command reports success on a pin whose level never changes, and the console keeps printing while it accepts no input at all. On a current mainline the module therefore drives no GPIO and cannot have its autoboot interrupted.

Tested on a Colibri VF50 (vf610, VF500 SoC) booting from NAND, with the display reset, data/command and backlight lines on GPIOs and the console on UART0.

Mehmet Fide (2):
gpio: vybrid: read and write the GPIO block, not the PORT block
serial: lpuart: test the receive flag, not the FIFO counter

 drivers/gpio/vybrid_gpio.c     | 8 +++++++-
 drivers/serial/serial_lpuart.c | 9 +++++----
 2 files changed, 12 insertions(+), 5 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/2 gpio: vybrid: read and write the GPIO block, not the PORT block

From: Mehmet Fide <[email protected]>

The Vybrid GPIO node describes two register ranges: the PORT block, which holds the pin control and interrupt registers, and the GPIO block, which holds the registers this driver touches (PDOR, PSOR, PCOR, PTOR, PDIR):

	gpio0: gpio@40049000 {
		compatible = "fsl,vf610-gpio";
		reg = <0x40049000 0x1000 0x400ff000 0x40>;

vybrid_gpio_odata_to_plat() takes the first range, so every set, clear and read goes to the PORT block: an output never changes level, an input returns a pin control register, and the write lands on the pin control register of an unrelated pad. The gpio command reports success either way.

The direction is not affected. imx_iomux_gpio_set_direction() applies IOMUXC itself, so a pin requested as an output is driven, but always to the reset value of PDOR.

The single range device tree this driver was written against described the GPIO block alone:

	gpio1: gpio@400ff000 {
		compatible = "fsl,vf610-gpio";
		reg = <0x400ff000 0x40>;

so the first range was the right one until the device trees were synchronised with Linux. Take the second range when the node has one and keep the first as the fallback, which is what the Linux driver does for the single range imx7ulp binding.

Tested on a Colibri VF50: with the fix "gpio set 50" sets bit 18 of PDOR in the GPIO block at 0x400ff040 and the pin drives its load, and the display reset and backlight lines the board wires to GPIOs work again. Without it the register never changes.

Fixes e8a9521e649f ("vf500/vf610: synchronise device trees with linux")
---
 drivers/gpio/vybrid_gpio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpio/vybrid_gpio.c +7 -1
index 5b4bba96da7..3d2e16e8ef3 100644
@@ -109,7 +109,13 @@ static int vybrid_gpio_odata_to_plat(struct udevice *dev)
 	struct vybrid_gpio_plat *plat = dev_get_plat(dev);
 	fdt_addr_t base_addr;
 
-	base_addr = dev_read_addr(dev);
+	/*
+	 * The first reg range is the PORT block (pin control), the second one
+	 * the GPIO block this driver reads and writes.
+	 */
+	base_addr = dev_read_addr_index(dev, 1);
+	if (base_addr == FDT_ADDR_T_NONE)
+		base_addr = dev_read_addr(dev);
 	if (base_addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
 
Signature · 1 line
2.54.0
#2 lore raw

PATCH 2/2 serial: lpuart: test the receive flag, not the FIFO counter

In reply to Mehmet Fide

From: Mehmet Fide <[email protected]>

On the 8 bit register variant, the only user of which is fsl,vf610-lpuart, _lpuart_serial_init() disables the FIFO:

	/* Disable FIFO and flush buffer */
	__raw_writeb(0x0, &base->upfifo);

while _lpuart_serial_tstc() asks the receive FIFO counter whether a character arrived:

	if (__raw_readb(&base->urcfifo) == 0)
		return 0;

With the FIFO disabled the dataword lands in the data register and raises S1[RDRF], but RCFIFO stays zero, so tstc() never reports a character. The console is then output only: autoboot cannot be interrupted, ctrlc() never fires, and anything polling for a key waits forever.

_lpuart_serial_getc() in the same driver already tests S1, and the 32 bit variant enables its FIFO in _lpuart32_serial_init() before reading the RXCOUNT field of WATER, so only this path is inconsistent. Test S1 the way getc() does.

Tested on a Colibri VF50: U-Boot printed its whole log over UART0 but accepted no input at all, neither a key during the boot delay nor Ctrl-C during a sleep, while Linux received on the same pads with the same pin mux. With the fix the boot delay can be interrupted, including with bootdelay=0, where the key is already buffered when abortboot_single_key() checks.

---
 drivers/serial/serial_lpuart.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/serial/serial_lpuart.c +5 -4
index 9fdb6503085..9c02b3a77ca 100644
@@ -198,10 +198,11 @@ static int _lpuart_serial_tstc(struct lpuart_serial_plat *plat)
 {
 	struct lpuart_fsl *base = plat->reg;
 
-	if (__raw_readb(&base->urcfifo) == 0)
-		return 0;
-
-	return 1;
+	/*
+	 * The receive FIFO counter stays at zero because _lpuart_serial_init()
+	 * disables the FIFO, so ask the status register, the way getc() does.
+	 */
+	return __raw_readb(&base->us1) & (US1_RDRF | US1_OR) ? 1 : 0;
 }
 
 /*
Signature · 1 line
2.54.0