diff mbox series

[1/4] gpio: mvebu: Fix check for pwm support on non-A8K platforms

Message ID 20220714115515.5748-1-pali@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/4] gpio: mvebu: Fix check for pwm support on non-A8K platforms | expand

Commit Message

Pali Rohár July 14, 2022, 11:55 a.m. UTC
pwm support incompatible with Armada 80x0/70x0 API is not only in
Armada 370, but also in Armada XP, 38x and 39x. So basically every non-A8K
platform. Fix check for pwm support appropriately.

Fixes: 85b7d8abfec7 ("gpio: mvebu: add pwm support for Armada 8K/7K")
Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/gpio/gpio-mvebu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Baruch Siach July 14, 2022, 1:14 p.m. UTC | #1
Hi Pali,

On Thu, Jul 14 2022, Pali Rohár wrote:
> pwm support incompatible with Armada 80x0/70x0 API is not only in
> Armada 370, but also in Armada XP, 38x and 39x. So basically every non-A8K
> platform. Fix check for pwm support appropriately.
>
> Fixes: 85b7d8abfec7 ("gpio: mvebu: add pwm support for Armada 8K/7K")
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
>  drivers/gpio/gpio-mvebu.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> index 2db19cd640a4..70a22b68c034 100644
> --- a/drivers/gpio/gpio-mvebu.c
> +++ b/drivers/gpio/gpio-mvebu.c
> @@ -793,8 +793,7 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
>  	u32 offset;
>  	u32 set;
>  
> -	if (of_device_is_compatible(mvchip->chip.of_node,
> -				    "marvell,armada-370-gpio")) {
> +	if (mvchip->soc_variant != MVEBU_GPIO_SOC_VARIANT_A8K) {

The 'if' condition that follow the 'else' below become always true:

       } else if (mvchip->soc_variant == MVEBU_GPIO_SOC_VARIANT_A8K) {

I would suggest to keep the '== MVEBU_GPIO_SOC_VARIANT_A8K' condition,
and reverse the if/else order, because positive logic is more readable.

There is also another 'else' below that is dead code with this patch.

baruch

>  		/*
>  		 * There are only two sets of PWM configuration registers for
>  		 * all the GPIO lines on those SoCs which this driver reserves
Andrew Lunn July 14, 2022, 1:19 p.m. UTC | #2
On Thu, Jul 14, 2022 at 01:55:12PM +0200, Pali Rohár wrote:
> pwm support incompatible with Armada 80x0/70x0 API is not only in
> Armada 370, but also in Armada XP, 38x and 39x. So basically every non-A8K
> platform. Fix check for pwm support appropriately.
> 
> Fixes: 85b7d8abfec7 ("gpio: mvebu: add pwm support for Armada 8K/7K")
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
>  drivers/gpio/gpio-mvebu.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> index 2db19cd640a4..70a22b68c034 100644
> --- a/drivers/gpio/gpio-mvebu.c
> +++ b/drivers/gpio/gpio-mvebu.c
> @@ -793,8 +793,7 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
>  	u32 offset;
>  	u32 set;
>  
> -	if (of_device_is_compatible(mvchip->chip.of_node,
> -				    "marvell,armada-370-gpio")) {
> +	if (mvchip->soc_variant != MVEBU_GPIO_SOC_VARIANT_A8K) {
>  		/*
>  		 * There are only two sets of PWM configuration registers for
>  		 * all the GPIO lines on those SoCs which this driver reserves

The current code is:

        if (of_device_is_compatible(mvchip->chip.of_node,
                                    "marvell,armada-370-gpio")) {
                /*
                 * There are only two sets of PWM configuration registers for
                 * all the GPIO lines on those SoCs which this driver reserves
                 * for the first two GPIO chips. So if the resource is missing
                 * we can't treat it as an error.
                 */
                if (!platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwm"))
                        return 0;
                offset = 0;
        } else if (mvchip->soc_variant == MVEBU_GPIO_SOC_VARIANT_A8K) {
                int ret = of_property_read_u32(dev->of_node,
                                               "marvell,pwm-offset", &offset);
                if (ret < 0)
                        return 0;
        } else {
                return 0;
        }

With your change, don't we end up with:

	if (foo)
	    .....
	else if (!foo)
	    .....
	else
	    .....

The static analysers are going to complain about this.

    Andrew
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 2db19cd640a4..70a22b68c034 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -793,8 +793,7 @@  static int mvebu_pwm_probe(struct platform_device *pdev,
 	u32 offset;
 	u32 set;
 
-	if (of_device_is_compatible(mvchip->chip.of_node,
-				    "marvell,armada-370-gpio")) {
+	if (mvchip->soc_variant != MVEBU_GPIO_SOC_VARIANT_A8K) {
 		/*
 		 * There are only two sets of PWM configuration registers for
 		 * all the GPIO lines on those SoCs which this driver reserves