[PATCH v3 09/12] gpio: rockchip: change the GPIO version judgment logic

Ye Zhang posted 12 patches 1 year, 3 months ago
Only 8 patches received!
There is a newer version of this series
[PATCH v3 09/12] gpio: rockchip: change the GPIO version judgment logic
Posted by Ye Zhang 1 year, 3 months ago
Have a list of valid V1 IDs and default to -ENODEV.

Signed-off-by: Ye Zhang <ye.zhang@rock-chips.com>
---
 drivers/gpio/gpio-rockchip.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 04a24f1d77eb..579701ad3c6f 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -658,13 +658,20 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 
 	id = readl(bank->reg_base + gpio_regs_v2.version_id);
 
-	/* If not gpio v2, that is default to v1. */
-	if (id == GPIO_TYPE_V2 || id == GPIO_TYPE_V2_1) {
-		bank->gpio_regs = &gpio_regs_v2;
-		bank->gpio_type = GPIO_TYPE_V2;
-	} else {
+	/* The GPIO version ID is incrementing. */
+	switch (id) {
+	case GPIO_TYPE_V1:
 		bank->gpio_regs = &gpio_regs_v1;
 		bank->gpio_type = GPIO_TYPE_V1;
+		break;
+	case GPIO_TYPE_V2:
+	case GPIO_TYPE_V2_1:
+		bank->gpio_regs = &gpio_regs_v2;
+		bank->gpio_type = GPIO_TYPE_V2;
+		break;
+	default:
+		dev_err(bank->dev, "cannot get the version ID\n");
+		return -ENODEV;
 	}
 
 	return 0;
-- 
2.34.1
Re: [PATCH v3 09/12] gpio: rockchip: change the GPIO version judgment logic
Posted by Andy Shevchenko 1 year, 3 months ago
On Tue, Sep 03, 2024 at 03:36:46PM +0800, Ye Zhang wrote:
> Have a list of valid V1 IDs and default to -ENODEV.

s/V1//

...

>  	id = readl(bank->reg_base + gpio_regs_v2.version_id);

>  

You may remove this blank line now...

> -	/* If not gpio v2, that is default to v1. */
> -	if (id == GPIO_TYPE_V2 || id == GPIO_TYPE_V2_1) {
> -		bank->gpio_regs = &gpio_regs_v2;
> -		bank->gpio_type = GPIO_TYPE_V2;
> -	} else {
> +	/* The GPIO version ID is incrementing. */
> +	switch (id) {

...basically to have

	/* The GPIO version ID is incrementing. */
	id = readl(bank->reg_base + gpio_regs_v2.version_id);
	switch (id) {

> +	case GPIO_TYPE_V1:
>  		bank->gpio_regs = &gpio_regs_v1;
>  		bank->gpio_type = GPIO_TYPE_V1;
> +		break;
> +	case GPIO_TYPE_V2:
> +	case GPIO_TYPE_V2_1:
> +		bank->gpio_regs = &gpio_regs_v2;
> +		bank->gpio_type = GPIO_TYPE_V2;
> +		break;
> +	default:
> +		dev_err(bank->dev, "cannot get the version ID\n");
> +		return -ENODEV;
>  	}

-- 
With Best Regards,
Andy Shevchenko