public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH 0/2] CONFIG_EARLY_TIMER: Fix EAGAIN issue and use DM too
@ 2022-03-10 18:45 Johannes Krottmayer
  2022-03-10 18:45 ` [PATCH 1/2] common: board_f.c: Fix EAGAIN issue when CONFIG_TIMER_EARLY is selected Johannes Krottmayer
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Johannes Krottmayer @ 2022-03-10 18:45 UTC (permalink / raw)
  To: u-boot, trini; +Cc: Johannes Krottmayer

Hi,

I'm currently working on support for a STMicroelectronics board. I have
written a DM driver which implements the timer_early_* functions. But
noticed an issue when the configuration switch is set.

common/board_f.c
Here this leads in an EAGAIN issue, becaues the DM sub-system isn't
running at this point.

lib/time.c
I modified the routines here, because it's also could fail. An addintionl
feature is, that if CONFIG_EARLY_TIMER first it probes if, the DM timer
is present, if not it uses the timer_early_* functions.

Have compiled it in both configurations, and it works as accepted.

Kind regards,

Johannes


Signed-off-by: Johannes Krottmayer <krjdev@gmail.com>
Cc: Tom Rini <trini@konsulko.com>

---

Johannes Krottmayer (2):
  common: board_f.c: Fix EAGAIN issue when CONFIG_TIMER_EARLY is
    selected
  lib: time.c: Try also DM timer, when CONFIG_TIMER_EARLY is selected

 common/board_f.c |  6 ------
 lib/time.c       | 46 ++++++++++++++++++++++++++++++++--------------
 2 files changed, 32 insertions(+), 20 deletions(-)

-- 
2.34.1


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

* [PATCH 1/2] common: board_f.c: Fix EAGAIN issue when CONFIG_TIMER_EARLY is selected
  2022-03-10 18:45 [PATCH 0/2] CONFIG_EARLY_TIMER: Fix EAGAIN issue and use DM too Johannes Krottmayer
@ 2022-03-10 18:45 ` Johannes Krottmayer
  2022-03-11 16:35   ` Johannes (krjdev) Krottmayer
  2022-03-10 18:45 ` [PATCH 2/2] lib: time.c: Try also DM timer, " Johannes Krottmayer
  2022-03-11 16:35 ` [PATCH 0/2] CONFIG_EARLY_TIMER: Fix EAGAIN issue and use DM too Johannes (krjdev) Krottmayer
  2 siblings, 1 reply; 6+ messages in thread
From: Johannes Krottmayer @ 2022-03-10 18:45 UTC (permalink / raw)
  To: u-boot, trini; +Cc: Johannes Krottmayer

Description:

When CONFIG_TIMER_EARLY is selected and the timer driver implements
timer_early_get_count() and timer_early_get_rate() this leads to
an EAGAIN error in initf_dm() one some configurations.

Signed-off-by: Johannes Krottmayer <krjdev@gmail.com>
Cc: Tom Rini <trini@konsulko.com>
---
 common/board_f.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/common/board_f.c b/common/board_f.c
index a68760092a..fc883c1742 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -785,12 +785,6 @@ static int initf_dm(void)
 	bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_F);
 	if (ret)
 		return ret;
-
-	if (IS_ENABLED(CONFIG_TIMER_EARLY)) {
-		ret = dm_timer_init();
-		if (ret)
-			return ret;
-	}
 #endif
 
 	return 0;
-- 
2.34.1


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

* [PATCH 2/2] lib: time.c: Try also DM timer, when CONFIG_TIMER_EARLY is selected
  2022-03-10 18:45 [PATCH 0/2] CONFIG_EARLY_TIMER: Fix EAGAIN issue and use DM too Johannes Krottmayer
  2022-03-10 18:45 ` [PATCH 1/2] common: board_f.c: Fix EAGAIN issue when CONFIG_TIMER_EARLY is selected Johannes Krottmayer
@ 2022-03-10 18:45 ` Johannes Krottmayer
  2022-03-11 16:34   ` Johannes (krjdev) Krottmayer
  2022-03-11 16:35 ` [PATCH 0/2] CONFIG_EARLY_TIMER: Fix EAGAIN issue and use DM too Johannes (krjdev) Krottmayer
  2 siblings, 1 reply; 6+ messages in thread
From: Johannes Krottmayer @ 2022-03-10 18:45 UTC (permalink / raw)
  To: u-boot, trini; +Cc: Johannes Krottmayer

Description:

When CONFIG_TIMER_EARLY is selected only the timer_early_* functions
will be called. With this patch first gd->timer will be checked, if the
DM timer is available, it uses the DM timer. When gd->timer is empty,
the timer_early_* functions will be called.

Signed-off-by: Johannes Krottmayer <krjdev@gmail.com>
Cc: Tom Rini <trini@konsulko.com>
---
 lib/time.c | 46 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 14 deletions(-)

diff --git a/lib/time.c b/lib/time.c
index 96074b84af..85803d8ff5 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -5,7 +5,6 @@
  */
 
 #include <common.h>
-#include <clock_legacy.h>
 #include <bootstage.h>
 #include <dm.h>
 #include <errno.h>
@@ -66,17 +65,22 @@ extern unsigned long __weak timer_read_counter(void);
 #if CONFIG_IS_ENABLED(TIMER)
 ulong notrace get_tbclk(void)
 {
-	if (!gd->timer) {
+	int ret;
+
 #ifdef CONFIG_TIMER_EARLY
+	if (!gd->timer)
 		return timer_early_get_rate();
+
+	ret = dm_timer_init();
+
+	if (ret)
+		return ret;
 #else
-		int ret;
+	ret = dm_timer_init();
 
-		ret = dm_timer_init();
-		if (ret)
-			return ret;
+	if (ret)
+		return ret;
 #endif
-	}
 
 	return timer_get_rate(gd->timer);
 }
@@ -86,19 +90,32 @@ uint64_t notrace get_ticks(void)
 	u64 count;
 	int ret;
 
-	if (!gd->timer) {
 #ifdef CONFIG_TIMER_EARLY
+	if (!gd->timer)
 		return timer_early_get_count();
-#else
-		int ret;
 
-		ret = dm_timer_init();
-		if (ret)
-			panic("Could not initialize timer (err %d)\n", ret);
-#endif
+	ret = dm_timer_init();
+
+	if (ret)
+		panic("Could not initialize timer (err %d)\n", ret);
+
+	ret = timer_get_count(gd->timer, &count);
+
+	if (ret) {
+		if (spl_phase() > PHASE_TPL)
+			panic("Could not read count from timer (err %d)\n",
+			      ret);
+		else
+			panic("no timer (err %d)\n", ret);
 	}
+#else
+	ret = dm_timer_init();
+
+	if (ret)
+		panic("Could not initialize timer (err %d)\n", ret);
 
 	ret = timer_get_count(gd->timer, &count);
+
 	if (ret) {
 		if (spl_phase() > PHASE_TPL)
 			panic("Could not read count from timer (err %d)\n",
@@ -106,6 +123,7 @@ uint64_t notrace get_ticks(void)
 		else
 			panic("no timer (err %d)\n", ret);
 	}
+#endif
 
 	return count;
 }
-- 
2.34.1


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

* Re: [PATCH 2/2] lib: time.c: Try also DM timer, when CONFIG_TIMER_EARLY is selected
  2022-03-10 18:45 ` [PATCH 2/2] lib: time.c: Try also DM timer, " Johannes Krottmayer
@ 2022-03-11 16:34   ` Johannes (krjdev) Krottmayer
  0 siblings, 0 replies; 6+ messages in thread
From: Johannes (krjdev) Krottmayer @ 2022-03-11 16:34 UTC (permalink / raw)
  To: krjdev, u-boot, trini

Hi,

Ignore these patches. Have send them to the wrong maintainers...
There are also somm issues.

Thanks!

On 10.03.22 19:45, Johannes Krottmayer wrote:
> Description:
> 
> When CONFIG_TIMER_EARLY is selected only the timer_early_* functions
> will be called. With this patch first gd->timer will be checked, if the
> DM timer is available, it uses the DM timer. When gd->timer is empty,
> the timer_early_* functions will be called.
> 
> Signed-off-by: Johannes Krottmayer <krjdev@gmail.com>
> Cc: Tom Rini <trini@konsulko.com>
> ---
>  lib/time.c | 46 ++++++++++++++++++++++++++++++++--------------
>  1 file changed, 32 insertions(+), 14 deletions(-)
> 
> diff --git a/lib/time.c b/lib/time.c
> index 96074b84af..85803d8ff5 100644
> --- a/lib/time.c
> +++ b/lib/time.c
> @@ -5,7 +5,6 @@
>   */
>  
>  #include <common.h>
> -#include <clock_legacy.h>
>  #include <bootstage.h>
>  #include <dm.h>
>  #include <errno.h>
> @@ -66,17 +65,22 @@ extern unsigned long __weak timer_read_counter(void);
>  #if CONFIG_IS_ENABLED(TIMER)
>  ulong notrace get_tbclk(void)
>  {
> -	if (!gd->timer) {
> +	int ret;
> +
>  #ifdef CONFIG_TIMER_EARLY
> +	if (!gd->timer)
>  		return timer_early_get_rate();
> +
> +	ret = dm_timer_init();
> +
> +	if (ret)
> +		return ret;
>  #else
> -		int ret;
> +	ret = dm_timer_init();
>  
> -		ret = dm_timer_init();
> -		if (ret)
> -			return ret;
> +	if (ret)
> +		return ret;
>  #endif
> -	}
>  
>  	return timer_get_rate(gd->timer);
>  }
> @@ -86,19 +90,32 @@ uint64_t notrace get_ticks(void)
>  	u64 count;
>  	int ret;
>  
> -	if (!gd->timer) {
>  #ifdef CONFIG_TIMER_EARLY
> +	if (!gd->timer)
>  		return timer_early_get_count();
> -#else
> -		int ret;
>  
> -		ret = dm_timer_init();
> -		if (ret)
> -			panic("Could not initialize timer (err %d)\n", ret);
> -#endif
> +	ret = dm_timer_init();
> +
> +	if (ret)
> +		panic("Could not initialize timer (err %d)\n", ret);
> +
> +	ret = timer_get_count(gd->timer, &count);
> +
> +	if (ret) {
> +		if (spl_phase() > PHASE_TPL)
> +			panic("Could not read count from timer (err %d)\n",
> +			      ret);
> +		else
> +			panic("no timer (err %d)\n", ret);
>  	}
> +#else
> +	ret = dm_timer_init();
> +
> +	if (ret)
> +		panic("Could not initialize timer (err %d)\n", ret);
>  
>  	ret = timer_get_count(gd->timer, &count);
> +
>  	if (ret) {
>  		if (spl_phase() > PHASE_TPL)
>  			panic("Could not read count from timer (err %d)\n",
> @@ -106,6 +123,7 @@ uint64_t notrace get_ticks(void)
>  		else
>  			panic("no timer (err %d)\n", ret);
>  	}
> +#endif
>  
>  	return count;
>  }

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

* Re: [PATCH 1/2] common: board_f.c: Fix EAGAIN issue when CONFIG_TIMER_EARLY is selected
  2022-03-10 18:45 ` [PATCH 1/2] common: board_f.c: Fix EAGAIN issue when CONFIG_TIMER_EARLY is selected Johannes Krottmayer
@ 2022-03-11 16:35   ` Johannes (krjdev) Krottmayer
  0 siblings, 0 replies; 6+ messages in thread
From: Johannes (krjdev) Krottmayer @ 2022-03-11 16:35 UTC (permalink / raw)
  To: krjdev, u-boot, trini

Hi,

Ignore these patches. Have send them to the wrong maintainers...
There are also somm issues.

Thanks!

On 10.03.22 19:45, Johannes Krottmayer wrote:
> Description:
> 
> When CONFIG_TIMER_EARLY is selected and the timer driver implements
> timer_early_get_count() and timer_early_get_rate() this leads to
> an EAGAIN error in initf_dm() one some configurations.
> 
> Signed-off-by: Johannes Krottmayer <krjdev@gmail.com>
> Cc: Tom Rini <trini@konsulko.com>
> ---
>  common/board_f.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/common/board_f.c b/common/board_f.c
> index a68760092a..fc883c1742 100644
> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -785,12 +785,6 @@ static int initf_dm(void)
>  	bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_F);
>  	if (ret)
>  		return ret;
> -
> -	if (IS_ENABLED(CONFIG_TIMER_EARLY)) {
> -		ret = dm_timer_init();
> -		if (ret)
> -			return ret;
> -	}
>  #endif
>  
>  	return 0;

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

* Re: [PATCH 0/2] CONFIG_EARLY_TIMER: Fix EAGAIN issue and use DM too
  2022-03-10 18:45 [PATCH 0/2] CONFIG_EARLY_TIMER: Fix EAGAIN issue and use DM too Johannes Krottmayer
  2022-03-10 18:45 ` [PATCH 1/2] common: board_f.c: Fix EAGAIN issue when CONFIG_TIMER_EARLY is selected Johannes Krottmayer
  2022-03-10 18:45 ` [PATCH 2/2] lib: time.c: Try also DM timer, " Johannes Krottmayer
@ 2022-03-11 16:35 ` Johannes (krjdev) Krottmayer
  2 siblings, 0 replies; 6+ messages in thread
From: Johannes (krjdev) Krottmayer @ 2022-03-11 16:35 UTC (permalink / raw)
  To: krjdev, u-boot, trini

Hi,

Ignore these patches. Have send them to the wrong maintainers...
There are also somm issues.

Thanks!

On 10.03.22 19:45, Johannes Krottmayer wrote:
> Hi,
> 
> I'm currently working on support for a STMicroelectronics board. I have
> written a DM driver which implements the timer_early_* functions. But
> noticed an issue when the configuration switch is set.
> 
> common/board_f.c
> Here this leads in an EAGAIN issue, becaues the DM sub-system isn't
> running at this point.
> 
> lib/time.c
> I modified the routines here, because it's also could fail. An addintionl
> feature is, that if CONFIG_EARLY_TIMER first it probes if, the DM timer
> is present, if not it uses the timer_early_* functions.
> 
> Have compiled it in both configurations, and it works as accepted.
> 
> Kind regards,
> 
> Johannes
> 
> 
> Signed-off-by: Johannes Krottmayer <krjdev@gmail.com>
> Cc: Tom Rini <trini@konsulko.com>
> 
> ---
> 
> Johannes Krottmayer (2):
>   common: board_f.c: Fix EAGAIN issue when CONFIG_TIMER_EARLY is
>     selected
>   lib: time.c: Try also DM timer, when CONFIG_TIMER_EARLY is selected
> 
>  common/board_f.c |  6 ------
>  lib/time.c       | 46 ++++++++++++++++++++++++++++++++--------------
>  2 files changed, 32 insertions(+), 20 deletions(-)
> 

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

end of thread, other threads:[~2022-03-11 16:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-10 18:45 [PATCH 0/2] CONFIG_EARLY_TIMER: Fix EAGAIN issue and use DM too Johannes Krottmayer
2022-03-10 18:45 ` [PATCH 1/2] common: board_f.c: Fix EAGAIN issue when CONFIG_TIMER_EARLY is selected Johannes Krottmayer
2022-03-11 16:35   ` Johannes (krjdev) Krottmayer
2022-03-10 18:45 ` [PATCH 2/2] lib: time.c: Try also DM timer, " Johannes Krottmayer
2022-03-11 16:34   ` Johannes (krjdev) Krottmayer
2022-03-11 16:35 ` [PATCH 0/2] CONFIG_EARLY_TIMER: Fix EAGAIN issue and use DM too Johannes (krjdev) Krottmayer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox