public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH resend] at91: Enable slow master clock on meesc board
@ 2009-11-23  9:04 Daniel Gorsulowski
  2009-11-25 21:02 ` Tom
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Gorsulowski @ 2009-11-23  9:04 UTC (permalink / raw)
  To: u-boot

In some cases, we need low speed master clock. So depending on the
"mdiv" variable, the processor clock is divided by 2 (default) or 4.

Signed-off-by: Daniel Gorsulowski <Daniel.Gorsulowski@esd.eu>
---
 board/esd/meesc/meesc.c |   24 ++++++++++++++++++++++++
 include/configs/meesc.h |    1 +
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/board/esd/meesc/meesc.c b/board/esd/meesc/meesc.c
index efba60d..4f6c5b7 100644
--- a/board/esd/meesc/meesc.c
+++ b/board/esd/meesc/meesc.c
@@ -219,6 +219,30 @@ u32 get_board_rev(void)
 }
 #endif
 
+#ifdef CONFIG_MISC_INIT_R
+int misc_init_r(void)
+{
+	char *str;
+	char buf[32];
+
+	/*
+	 * In some cases, we need low speed master clock. So depending on the
+	 * "mdiv" variable, the processor clock is divided by 2 (default) or 4.
+	 */
+	if ((str = getenv("mdiv")) && (!strcmp(str, "4"))) {
+		at91_sys_write(AT91_PMC_MCKR,
+			(at91_sys_read(AT91_PMC_MCKR) & ~AT91_PMC_MDIV) |
+			AT91SAM9_PMC_MDIV_4);
+		at91_clock_init(0);
+		serial_setbrg();
+		printf("Setting master clock to %s MHz\n",
+			strmhz(buf, get_mck_clk_rate()));
+	}
+
+	return 0;
+}
+#endif /* CONFIG_MISC_INIT_R */
+
 int board_init(void)
 {
 	/* Peripheral Clock Enable Register */
diff --git a/include/configs/meesc.h b/include/configs/meesc.h
index b996854..034e81c 100644
--- a/include/configs/meesc.h
+++ b/include/configs/meesc.h
@@ -48,6 +48,7 @@
 
 #define CONFIG_SKIP_LOWLEVEL_INIT
 #define CONFIG_SKIP_RELOCATE_UBOOT
+#define CONFIG_MISC_INIT_R			/* Call misc_init_r */
 
 #define CONFIG_ARCH_CPU_INIT
 
-- 
1.5.3

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

* [U-Boot] [PATCH resend] at91: Enable slow master clock on meesc board
  2009-11-23  9:04 [U-Boot] [PATCH resend] " Daniel Gorsulowski
@ 2009-11-25 21:02 ` Tom
  0 siblings, 0 replies; 4+ messages in thread
From: Tom @ 2009-11-25 21:02 UTC (permalink / raw)
  To: u-boot

Daniel Gorsulowski wrote:
> In some cases, we need low speed master clock. So depending on the
> "mdiv" variable, the processor clock is divided by 2 (default) or 4.
> 
> Signed-off-by: Daniel Gorsulowski <Daniel.Gorsulowski@esd.eu>
> ---
>  board/esd/meesc/meesc.c |   24 ++++++++++++++++++++++++
>  include/configs/meesc.h |    1 +
>  2 files changed, 25 insertions(+), 0 deletions(-)
> 
> diff --git a/board/esd/meesc/meesc.c b/board/esd/meesc/meesc.c
> index efba60d..4f6c5b7 100644
> --- a/board/esd/meesc/meesc.c
> +++ b/board/esd/meesc/meesc.c
> @@ -219,6 +219,30 @@ u32 get_board_rev(void)
>  }
>  #endif
>  
> +#ifdef CONFIG_MISC_INIT_R
> +int misc_init_r(void)
> +{
> +	char *str;
> +	char buf[32];
> +
> +	/*
> +	 * In some cases, we need low speed master clock. So depending on the
> +	 * "mdiv" variable, the processor clock is divided by 2 (default) or 4.
> +	 */
This comment does not follow what is done.
 From the comment there should be an 'else' branch where the mdiv_2 is
done.

> +	if ((str = getenv("mdiv")) && (!strcmp(str, "4"))) {

Move the getenv out of the if-check.
The string comparision should be strengthened. str = "44" would be valid.
Perhaps warn if the expected 2 or 4 is not set.

There are more that 2 and 4 possible clk divisors.
Do you want to make this function more general?

> +		at91_sys_write(AT91_PMC_MCKR,
> +			(at91_sys_read(AT91_PMC_MCKR) & ~AT91_PMC_MDIV) |
> +			AT91SAM9_PMC_MDIV_4);
> +		at91_clock_init(0);
> +		serial_setbrg();
> +		printf("Setting master clock to %s MHz\n",
> +			strmhz(buf, get_mck_clk_rate()));
This printf should be moved outside of the if check so the default
case also gets the printout.

Tom

> +	}
> +
> +	return 0;
> +}
> +#endif /* CONFIG_MISC_INIT_R */
> +
>  int board_init(void)
>  {
>  	/* Peripheral Clock Enable Register */
> diff --git a/include/configs/meesc.h b/include/configs/meesc.h
> index b996854..034e81c 100644
> --- a/include/configs/meesc.h
> +++ b/include/configs/meesc.h
> @@ -48,6 +48,7 @@
>  
>  #define CONFIG_SKIP_LOWLEVEL_INIT
>  #define CONFIG_SKIP_RELOCATE_UBOOT
> +#define CONFIG_MISC_INIT_R			/* Call misc_init_r */
>  
>  #define CONFIG_ARCH_CPU_INIT
>  

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

* [U-Boot] [PATCH][RESEND] at91: Enable slow master clock on meesc board
@ 2010-01-20  7:00 Daniel Gorsulowski
  2010-01-22 13:42 ` Tom
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Gorsulowski @ 2010-01-20  7:00 UTC (permalink / raw)
  To: u-boot

Normally the processor clock has a divisor of 2.
In some cases this this needs to be set to 4.
Check the user has set environment mdiv to 4 to change the divisor.

Signed-off-by: Daniel Gorsulowski <Daniel.Gorsulowski@esd.eu>
---
v2: - changed and add additional comments
    - strengthened string comparision

 board/esd/meesc/meesc.c | 26 ++++++++++++++++++++++++++
 include/configs/meesc.h |    1 +
 2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/board/esd/meesc/meesc.c b/board/esd/meesc/meesc.c
index efba60d..a1b66cb 100644
--- a/board/esd/meesc/meesc.c
+++ b/board/esd/meesc/meesc.c
@@ -219,6 +219,32 @@ u32 get_board_rev(void)
 }
 #endif
 
+#ifdef CONFIG_MISC_INIT_R
+int misc_init_r(void)
+{
+	char *str;
+	char buf[32];
+
+	/*
+	 * Normally the processor clock has a divisor of 2.
+	 * In some cases this this needs to be set to 4.
+	 * Check the user has set environment mdiv to 4 to change the divisor.
+	 */
+	if ((str = getenv("mdiv")) && (strcmp(str, "4") == 0)) {
+		at91_sys_write(AT91_PMC_MCKR,
+			(at91_sys_read(AT91_PMC_MCKR) & ~AT91_PMC_MDIV) |
+			AT91SAM9_PMC_MDIV_4);
+		at91_clock_init(0);
+		serial_setbrg();
+		/* Notify the user that the clock is not default */
+		printf("Setting master clock to %s MHz\n",
+			strmhz(buf, get_mck_clk_rate()));
+	}
+
+	return 0;
+}
+#endif /* CONFIG_MISC_INIT_R */
+
 int board_init(void)
 {
 	/* Peripheral Clock Enable Register */
diff --git a/include/configs/meesc.h b/include/configs/meesc.h
index b996854..034e81c 100644
--- a/include/configs/meesc.h
+++ b/include/configs/meesc.h
@@ -48,6 +48,7 @@
 
 #define CONFIG_SKIP_LOWLEVEL_INIT
 #define CONFIG_SKIP_RELOCATE_UBOOT
+#define CONFIG_MISC_INIT_R			/* Call misc_init_r */
 
 #define CONFIG_ARCH_CPU_INIT
 
-- 
1.6.1

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

* [U-Boot] [PATCH][RESEND] at91: Enable slow master clock on meesc board
  2010-01-20  7:00 [U-Boot] [PATCH][RESEND] at91: Enable slow master clock on meesc board Daniel Gorsulowski
@ 2010-01-22 13:42 ` Tom
  0 siblings, 0 replies; 4+ messages in thread
From: Tom @ 2010-01-22 13:42 UTC (permalink / raw)
  To: u-boot

Daniel Gorsulowski wrote:
> Normally the processor clock has a divisor of 2.
> In some cases this this needs to be set to 4.
> Check the user has set environment mdiv to 4 to change the divisor.
> 
> Signed-off-by: Daniel Gorsulowski <Daniel.Gorsulowski@esd.eu>

Applied to u-boot-arm/master
Thanks
Tom

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

end of thread, other threads:[~2010-01-22 13:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-20  7:00 [U-Boot] [PATCH][RESEND] at91: Enable slow master clock on meesc board Daniel Gorsulowski
2010-01-22 13:42 ` Tom
  -- strict thread matches above, loose matches on Subject: below --
2009-11-23  9:04 [U-Boot] [PATCH resend] " Daniel Gorsulowski
2009-11-25 21:02 ` Tom

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