diff mbox series

[12/16] board: stm32mp1: add timeout for I/O compensation ready

Message ID 20200331180330.12.Ia5fd6d6f4787d69ef9b4b5cebb334e5f2dc81ed3@changeid
State Superseded
Delegated to: Patrick Delaunay
Headers show
Series [01/16] arm: stm32mp: update dependency for STM32_ETZPC | expand

Commit Message

Patrick Delaunay March 31, 2020, 4:04 p.m. UTC
This patch avoids infinite loop when I/O compensation failed,
it adds a 1s timeout to detect error.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

 board/st/stm32mp1/stm32mp1.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Patrice CHOTARD April 1, 2020, 8:07 a.m. UTC | #1
Hi Patrick

On 3/31/20 6:04 PM, Patrick Delaunay wrote:
> This patch avoids infinite loop when I/O compensation failed,
> it adds a 1s timeout to detect error.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>
>  board/st/stm32mp1/stm32mp1.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
> index fff4cef2c2..75aac6d66c 100644
> --- a/board/st/stm32mp1/stm32mp1.c
> +++ b/board/st/stm32mp1/stm32mp1.c
> @@ -35,6 +35,7 @@
>  #include <asm/arch/sys_proto.h>
>  #include <jffs2/load_kernel.h>
>  #include <linux/err.h>
> +#include <linux/iopoll.h>
>  #include <power/regulator.h>
>  #include <usb/dwc2_udc.h>
>  
> @@ -473,10 +474,10 @@ static void sysconf_init(void)
>  	struct udevice *pwr_dev;
>  	struct udevice *pwr_reg;
>  	struct udevice *dev;
> -	int ret;
>  	u32 otp = 0;
>  #endif
> -	u32 bootr;
> +	int ret;
> +	u32 bootr, val;
>  
>  	syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
>  
> @@ -553,8 +554,15 @@ static void sysconf_init(void)
>  	 */
>  	writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
>  
> -	while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
> -		;
> +	/* poll until ready (1s timeout) */
> +	ret = readl_poll_timeout(syscfg + SYSCFG_CMPCR, val,
> +				 val & SYSCFG_CMPCR_READY,
> +				 1000000);
> +	if (ret) {
> +		pr_err("SYSCFG: I/O compensation failed, timeout.\n");
> +		led_error_blink(10);
> +	}
> +
>  	clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
>  #endif
>  }

Reviewed-by: Patrice Chotard <patrice.chotard@st.com>

Thanks
diff mbox series

Patch

diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
index fff4cef2c2..75aac6d66c 100644
--- a/board/st/stm32mp1/stm32mp1.c
+++ b/board/st/stm32mp1/stm32mp1.c
@@ -35,6 +35,7 @@ 
 #include <asm/arch/sys_proto.h>
 #include <jffs2/load_kernel.h>
 #include <linux/err.h>
+#include <linux/iopoll.h>
 #include <power/regulator.h>
 #include <usb/dwc2_udc.h>
 
@@ -473,10 +474,10 @@  static void sysconf_init(void)
 	struct udevice *pwr_dev;
 	struct udevice *pwr_reg;
 	struct udevice *dev;
-	int ret;
 	u32 otp = 0;
 #endif
-	u32 bootr;
+	int ret;
+	u32 bootr, val;
 
 	syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
 
@@ -553,8 +554,15 @@  static void sysconf_init(void)
 	 */
 	writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
 
-	while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
-		;
+	/* poll until ready (1s timeout) */
+	ret = readl_poll_timeout(syscfg + SYSCFG_CMPCR, val,
+				 val & SYSCFG_CMPCR_READY,
+				 1000000);
+	if (ret) {
+		pr_err("SYSCFG: I/O compensation failed, timeout.\n");
+		led_error_blink(10);
+	}
+
 	clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
 #endif
 }