diff mbox series

realtek: ensure output drivers are enabled in RTL8231

Message ID 20210929205241.11353-1-fercerpav@gmail.com
State Superseded
Headers show
Series realtek: ensure output drivers are enabled in RTL8231 | expand

Commit Message

Paul Fertser Sept. 29, 2021, 8:52 p.m. UTC
The bootloader can leave the GPIO expander in a state which doesn't have
output drivers enabled so GPIOs will properly work for input but output
operations will have no effect.

To avoid disrupting the boot in case the bootloader left direction and
data registers in an inconsistent state (e.g. pulling SoC's reset to 0)
reconfigure everything as input.

Thanks to Sander Vanheule for telling about LED_Start.

Signed-off-by: Paul Fertser <fercerpav@gmail.com>
---

My previous patch to this part of the code is marked Accepted in the
Patchwork so this one is on top of it. Feel free to squash them
together.

 .../realtek/files-5.4/drivers/gpio/gpio-rtl8231.c      | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Sander Vanheule Sept. 30, 2021, 6:59 a.m. UTC | #1
Hi Paul,

On Wed, 2021-09-29 at 23:52 +0300, Paul Fertser wrote:
> The bootloader can leave the GPIO expander in a state which doesn't have
> output drivers enabled so GPIOs will properly work for input but output
> operations will have no effect.
> 
> To avoid disrupting the boot in case the bootloader left direction and
> data registers in an inconsistent state (e.g. pulling SoC's reset to 0)
> reconfigure everything as input.
> 
> Thanks to Sander Vanheule for telling about LED_Start.
> 
> Signed-off-by: Paul Fertser <fercerpav@gmail.com>
> ---
> 
> My previous patch to this part of the code is marked Accepted in the
> Patchwork so this one is on top of it. Feel free to squash them
> together.

Already merged in commit 16ae56b4f9ec.

> 
>  .../realtek/files-5.4/drivers/gpio/gpio-rtl8231.c      | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/target/linux/realtek/files-5.4/drivers/gpio/gpio-rtl8231.c
> b/target/linux/realtek/files-5.4/drivers/gpio/gpio-rtl8231.c
> index a8ffcdc31368..405c2c151368 100644
> --- a/target/linux/realtek/files-5.4/drivers/gpio/gpio-rtl8231.c
> +++ b/target/linux/realtek/files-5.4/drivers/gpio/gpio-rtl8231.c
> @@ -254,11 +254,15 @@ int rtl8231_init(struct rtl8231_gpios *gpios)
>                 sw_w32_mask(3, 1, RTL838X_DMY_REG5);
>         }
>  
> -       /* Select GPIO functionality for pins 0-34 */
> +       /* Select GPIO functionality and force input direction for pins 0-34

You're now really configuring all 37 GPIOs, so the pin range in the comment
isn't quite correct any more.

> */
>         rtl8231_write(gpios, RTL8231_GPIO_PIN_SEL(0), 0xffff);
> +       rtl8231_write(gpios, RTL8231_GPIO_DIR(0), 0xffff);
>         rtl8231_write(gpios, RTL8231_GPIO_PIN_SEL(16), 0xffff);
> -       v = rtl8231_read(gpios, RTL8231_GPIO_PIN_SEL(32));
> -       rtl8231_write(gpios, RTL8231_GPIO_PIN_SEL(32), v | 0x7);

The previous patch added this variable 'v' for the RMW operation. I assume you
can now remove that variable's declaration too?

> +       rtl8231_write(gpios, RTL8231_GPIO_DIR(16), 0xffff);
> +       rtl8231_write(gpios, RTL8231_GPIO_PIN_SEL(32), 0x03ff);
> +
> +       /* Set LED_Start to enable drivers for output mode */
> +       rtl8231_write(gpios, RTL8231_LED_FUNC0, 1 << 1);

Unless you wanted to do a RMW to preserve the other bits in LED_FUNC0. Not that
it would make much of a difference, since the only other field that is changed
to a non-default value is En_bicolor (i.e. changing the LED matrix layout, which
isn't used anyway).

Best,
Sander
diff mbox series

Patch

diff --git a/target/linux/realtek/files-5.4/drivers/gpio/gpio-rtl8231.c b/target/linux/realtek/files-5.4/drivers/gpio/gpio-rtl8231.c
index a8ffcdc31368..405c2c151368 100644
--- a/target/linux/realtek/files-5.4/drivers/gpio/gpio-rtl8231.c
+++ b/target/linux/realtek/files-5.4/drivers/gpio/gpio-rtl8231.c
@@ -254,11 +254,15 @@  int rtl8231_init(struct rtl8231_gpios *gpios)
 		sw_w32_mask(3, 1, RTL838X_DMY_REG5);
 	}
 
-	/* Select GPIO functionality for pins 0-34 */
+	/* Select GPIO functionality and force input direction for pins 0-34 */
 	rtl8231_write(gpios, RTL8231_GPIO_PIN_SEL(0), 0xffff);
+	rtl8231_write(gpios, RTL8231_GPIO_DIR(0), 0xffff);
 	rtl8231_write(gpios, RTL8231_GPIO_PIN_SEL(16), 0xffff);
-	v = rtl8231_read(gpios, RTL8231_GPIO_PIN_SEL(32));
-	rtl8231_write(gpios, RTL8231_GPIO_PIN_SEL(32), v | 0x7);
+	rtl8231_write(gpios, RTL8231_GPIO_DIR(16), 0xffff);
+	rtl8231_write(gpios, RTL8231_GPIO_PIN_SEL(32), 0x03ff);
+
+	/* Set LED_Start to enable drivers for output mode */
+	rtl8231_write(gpios, RTL8231_LED_FUNC0, 1 << 1);
 
 	return 0;
 }