All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: turris_omnia_mcu: Fix usage of CMD_EXT_CONTROL
@ 2022-08-01 10:11 Pali Rohár
  2022-08-01 11:56 ` Stefan Roese
  2022-08-09 11:33 ` Stefan Roese
  0 siblings, 2 replies; 3+ messages in thread
From: Pali Rohár @ 2022-08-01 10:11 UTC (permalink / raw)
  To: Stefan Roese, Marek Behún; +Cc: u-boot

CMD_GENERAL_CONTROL takes two 8-bit arguments but CMD_EXT_CONTROL takes
two 16-bit arguments. Fix this issue and change CMD_EXT_CONTROL arguments
to 16-bit.

Fixes: 5e4d24ccc115 ("gpio: Add Turris Omnia MCU driver")
Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/gpio/turris_omnia_mcu.c | 56 +++++++++++++++------------------
 1 file changed, 26 insertions(+), 30 deletions(-)

diff --git a/drivers/gpio/turris_omnia_mcu.c b/drivers/gpio/turris_omnia_mcu.c
index 3e5d74e62cdb..986ccde6bc70 100644
--- a/drivers/gpio/turris_omnia_mcu.c
+++ b/drivers/gpio/turris_omnia_mcu.c
@@ -137,48 +137,44 @@ static int turris_omnia_mcu_get_value(struct udevice *dev, uint offset)
 static int turris_omnia_mcu_set_value(struct udevice *dev, uint offset, int value)
 {
 	struct turris_omnia_mcu_info *info = dev_get_plat(dev);
-	u8 val[2];
-	int ret;
-	u8 reg;
+	u8 val16[2];
+	u8 val32[4];
 
 	switch (offset) {
 	/* bank 0 */
-	case ilog2(STS_USB30_PWRON):
-		reg = CMD_GENERAL_CONTROL;
-		val[1] = CTL_USB30_PWRON;
-		break;
-	case ilog2(STS_USB31_PWRON):
-		reg = CMD_GENERAL_CONTROL;
-		val[1] = CTL_USB31_PWRON;
-		break;
-	case ilog2(STS_ENABLE_4V5):
-		reg = CMD_GENERAL_CONTROL;
-		val[1] = CTL_ENABLE_4V5;
-		break;
-	case ilog2(STS_BUTTON_MODE):
-		reg = CMD_GENERAL_CONTROL;
-		val[1] = CTL_BUTTON_MODE;
-		break;
+	case 0 ... 15:
+		switch (offset) {
+		case ilog2(STS_USB30_PWRON):
+			val16[1] = CTL_USB30_PWRON;
+			break;
+		case ilog2(STS_USB31_PWRON):
+			val16[1] = CTL_USB31_PWRON;
+			break;
+		case ilog2(STS_ENABLE_4V5):
+			val16[1] = CTL_ENABLE_4V5;
+			break;
+		case ilog2(STS_BUTTON_MODE):
+			val16[1] = CTL_BUTTON_MODE;
+			break;
+		default:
+			return -EINVAL;
+		}
+		val16[0] = value ? val16[1] : 0;
+		return dm_i2c_write(dev, CMD_GENERAL_CONTROL, val16, sizeof(val16));
 
 	/* bank 2 - supported only when FEAT_EXT_CMDS is set */
 	case (16 + 32 + 0) ... (16 + 32 + 15):
 		if (!(info->features & FEAT_EXT_CMDS))
 			return -EINVAL;
-		reg = CMD_EXT_CONTROL;
-		val[1] = BIT(offset - 16 - 32);
-		break;
+		val32[3] = BIT(offset - 16 - 32) >> 8;
+		val32[2] = BIT(offset - 16 - 32) & 0xff;
+		val32[1] = value ? val32[3] : 0;
+		val32[0] = value ? val32[2] : 0;
+		return dm_i2c_write(dev, CMD_EXT_CONTROL, val32, sizeof(val32));
 
 	default:
 		return -EINVAL;
 	}
-
-	val[0] = value ? val[1] : 0;
-
-	ret = dm_i2c_write(dev, reg, val, 2);
-	if (ret)
-		return ret;
-
-	return 0;
 }
 
 static int turris_omnia_mcu_direction_input(struct udevice *dev, uint offset)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] gpio: turris_omnia_mcu: Fix usage of CMD_EXT_CONTROL
  2022-08-01 10:11 [PATCH] gpio: turris_omnia_mcu: Fix usage of CMD_EXT_CONTROL Pali Rohár
@ 2022-08-01 11:56 ` Stefan Roese
  2022-08-09 11:33 ` Stefan Roese
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Roese @ 2022-08-01 11:56 UTC (permalink / raw)
  To: Pali Rohár, Marek Behún; +Cc: u-boot

On 01.08.22 12:11, Pali Rohár wrote:
> CMD_GENERAL_CONTROL takes two 8-bit arguments but CMD_EXT_CONTROL takes
> two 16-bit arguments. Fix this issue and change CMD_EXT_CONTROL arguments
> to 16-bit.
> 
> Fixes: 5e4d24ccc115 ("gpio: Add Turris Omnia MCU driver")
> Signed-off-by: Pali Rohár <pali@kernel.org>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
>   drivers/gpio/turris_omnia_mcu.c | 56 +++++++++++++++------------------
>   1 file changed, 26 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/gpio/turris_omnia_mcu.c b/drivers/gpio/turris_omnia_mcu.c
> index 3e5d74e62cdb..986ccde6bc70 100644
> --- a/drivers/gpio/turris_omnia_mcu.c
> +++ b/drivers/gpio/turris_omnia_mcu.c
> @@ -137,48 +137,44 @@ static int turris_omnia_mcu_get_value(struct udevice *dev, uint offset)
>   static int turris_omnia_mcu_set_value(struct udevice *dev, uint offset, int value)
>   {
>   	struct turris_omnia_mcu_info *info = dev_get_plat(dev);
> -	u8 val[2];
> -	int ret;
> -	u8 reg;
> +	u8 val16[2];
> +	u8 val32[4];
>   
>   	switch (offset) {
>   	/* bank 0 */
> -	case ilog2(STS_USB30_PWRON):
> -		reg = CMD_GENERAL_CONTROL;
> -		val[1] = CTL_USB30_PWRON;
> -		break;
> -	case ilog2(STS_USB31_PWRON):
> -		reg = CMD_GENERAL_CONTROL;
> -		val[1] = CTL_USB31_PWRON;
> -		break;
> -	case ilog2(STS_ENABLE_4V5):
> -		reg = CMD_GENERAL_CONTROL;
> -		val[1] = CTL_ENABLE_4V5;
> -		break;
> -	case ilog2(STS_BUTTON_MODE):
> -		reg = CMD_GENERAL_CONTROL;
> -		val[1] = CTL_BUTTON_MODE;
> -		break;
> +	case 0 ... 15:
> +		switch (offset) {
> +		case ilog2(STS_USB30_PWRON):
> +			val16[1] = CTL_USB30_PWRON;
> +			break;
> +		case ilog2(STS_USB31_PWRON):
> +			val16[1] = CTL_USB31_PWRON;
> +			break;
> +		case ilog2(STS_ENABLE_4V5):
> +			val16[1] = CTL_ENABLE_4V5;
> +			break;
> +		case ilog2(STS_BUTTON_MODE):
> +			val16[1] = CTL_BUTTON_MODE;
> +			break;
> +		default:
> +			return -EINVAL;
> +		}
> +		val16[0] = value ? val16[1] : 0;
> +		return dm_i2c_write(dev, CMD_GENERAL_CONTROL, val16, sizeof(val16));
>   
>   	/* bank 2 - supported only when FEAT_EXT_CMDS is set */
>   	case (16 + 32 + 0) ... (16 + 32 + 15):
>   		if (!(info->features & FEAT_EXT_CMDS))
>   			return -EINVAL;
> -		reg = CMD_EXT_CONTROL;
> -		val[1] = BIT(offset - 16 - 32);
> -		break;
> +		val32[3] = BIT(offset - 16 - 32) >> 8;
> +		val32[2] = BIT(offset - 16 - 32) & 0xff;
> +		val32[1] = value ? val32[3] : 0;
> +		val32[0] = value ? val32[2] : 0;
> +		return dm_i2c_write(dev, CMD_EXT_CONTROL, val32, sizeof(val32));
>   
>   	default:
>   		return -EINVAL;
>   	}
> -
> -	val[0] = value ? val[1] : 0;
> -
> -	ret = dm_i2c_write(dev, reg, val, 2);
> -	if (ret)
> -		return ret;
> -
> -	return 0;
>   }
>   
>   static int turris_omnia_mcu_direction_input(struct udevice *dev, uint offset)

Viele Grüße,
Stefan Roese

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gpio: turris_omnia_mcu: Fix usage of CMD_EXT_CONTROL
  2022-08-01 10:11 [PATCH] gpio: turris_omnia_mcu: Fix usage of CMD_EXT_CONTROL Pali Rohár
  2022-08-01 11:56 ` Stefan Roese
@ 2022-08-09 11:33 ` Stefan Roese
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Roese @ 2022-08-09 11:33 UTC (permalink / raw)
  To: Pali Rohár, Marek Behún; +Cc: u-boot

On 01.08.22 12:11, Pali Rohár wrote:
> CMD_GENERAL_CONTROL takes two 8-bit arguments but CMD_EXT_CONTROL takes
> two 16-bit arguments. Fix this issue and change CMD_EXT_CONTROL arguments
> to 16-bit.
> 
> Fixes: 5e4d24ccc115 ("gpio: Add Turris Omnia MCU driver")
> Signed-off-by: Pali Rohár <pali@kernel.org>

Applied to u-boot-marvell/master

Thanks,
Stefan

> ---
>   drivers/gpio/turris_omnia_mcu.c | 56 +++++++++++++++------------------
>   1 file changed, 26 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/gpio/turris_omnia_mcu.c b/drivers/gpio/turris_omnia_mcu.c
> index 3e5d74e62cdb..986ccde6bc70 100644
> --- a/drivers/gpio/turris_omnia_mcu.c
> +++ b/drivers/gpio/turris_omnia_mcu.c
> @@ -137,48 +137,44 @@ static int turris_omnia_mcu_get_value(struct udevice *dev, uint offset)
>   static int turris_omnia_mcu_set_value(struct udevice *dev, uint offset, int value)
>   {
>   	struct turris_omnia_mcu_info *info = dev_get_plat(dev);
> -	u8 val[2];
> -	int ret;
> -	u8 reg;
> +	u8 val16[2];
> +	u8 val32[4];
>   
>   	switch (offset) {
>   	/* bank 0 */
> -	case ilog2(STS_USB30_PWRON):
> -		reg = CMD_GENERAL_CONTROL;
> -		val[1] = CTL_USB30_PWRON;
> -		break;
> -	case ilog2(STS_USB31_PWRON):
> -		reg = CMD_GENERAL_CONTROL;
> -		val[1] = CTL_USB31_PWRON;
> -		break;
> -	case ilog2(STS_ENABLE_4V5):
> -		reg = CMD_GENERAL_CONTROL;
> -		val[1] = CTL_ENABLE_4V5;
> -		break;
> -	case ilog2(STS_BUTTON_MODE):
> -		reg = CMD_GENERAL_CONTROL;
> -		val[1] = CTL_BUTTON_MODE;
> -		break;
> +	case 0 ... 15:
> +		switch (offset) {
> +		case ilog2(STS_USB30_PWRON):
> +			val16[1] = CTL_USB30_PWRON;
> +			break;
> +		case ilog2(STS_USB31_PWRON):
> +			val16[1] = CTL_USB31_PWRON;
> +			break;
> +		case ilog2(STS_ENABLE_4V5):
> +			val16[1] = CTL_ENABLE_4V5;
> +			break;
> +		case ilog2(STS_BUTTON_MODE):
> +			val16[1] = CTL_BUTTON_MODE;
> +			break;
> +		default:
> +			return -EINVAL;
> +		}
> +		val16[0] = value ? val16[1] : 0;
> +		return dm_i2c_write(dev, CMD_GENERAL_CONTROL, val16, sizeof(val16));
>   
>   	/* bank 2 - supported only when FEAT_EXT_CMDS is set */
>   	case (16 + 32 + 0) ... (16 + 32 + 15):
>   		if (!(info->features & FEAT_EXT_CMDS))
>   			return -EINVAL;
> -		reg = CMD_EXT_CONTROL;
> -		val[1] = BIT(offset - 16 - 32);
> -		break;
> +		val32[3] = BIT(offset - 16 - 32) >> 8;
> +		val32[2] = BIT(offset - 16 - 32) & 0xff;
> +		val32[1] = value ? val32[3] : 0;
> +		val32[0] = value ? val32[2] : 0;
> +		return dm_i2c_write(dev, CMD_EXT_CONTROL, val32, sizeof(val32));
>   
>   	default:
>   		return -EINVAL;
>   	}
> -
> -	val[0] = value ? val[1] : 0;
> -
> -	ret = dm_i2c_write(dev, reg, val, 2);
> -	if (ret)
> -		return ret;
> -
> -	return 0;
>   }
>   
>   static int turris_omnia_mcu_direction_input(struct udevice *dev, uint offset)

Viele Grüße,
Stefan Roese

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-09 11:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-01 10:11 [PATCH] gpio: turris_omnia_mcu: Fix usage of CMD_EXT_CONTROL Pali Rohár
2022-08-01 11:56 ` Stefan Roese
2022-08-09 11:33 ` Stefan Roese

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.