Skip to contentSkip to conversation

at91: Enable slow master clock on meesc board

PATCH RESEND Superseded Daniel Gorsulowski 2 participants 2 messages Nov 23, 2009 – Nov 25, 2009

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 at91: Enable slow master clock on meesc board

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.

---
 board/esd/meesc/meesc.c |   24 ++++++++++++++++++++++++
 include/configs/meesc.h |    1 +
 2 files changed, 25 insertions(+), 0 deletions(-)
board/esd/meesc/meesc.c +24 -0
index efba60d..4f6c5b7 100644
@@ -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 */
include/configs/meesc.h +1 -0
index b996854..034e81c 100644
@@ -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
 
Signature · 1 line
1.5.3
#1 lore raw

PATCH RESEND 1/1 at91: Enable slow master clock on meesc board

Quoted 17 lines · Daniel Gorsulowski

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.

---
 board/esd/meesc/meesc.c |   24 ++++++++++++++++++++++++
 include/configs/meesc.h |    1 +
 2 files changed, 25 insertions(+), 0 deletions(-)
board/esd/meesc/meesc.c +0 -0
index efba60d..4f6c5b7 100644
@@ -219,6 +219,30 @@ u32 get_board_rev(void)
 }
 #endif
 

board/esd/meesc/meesc.c u32 get_board_rev(void) · line 231

Quoted 10 lines
board/esd/meesc/meesc.c +10 -0
+#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.

board/esd/meesc/meesc.c u32 get_board_rev(void) · line 232

Quoted 1 line
board/esd/meesc/meesc.c +1 -0
+	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?

board/esd/meesc/meesc.c u32 get_board_rev(void) · line 239

Quoted 7 lines
board/esd/meesc/meesc.c +7 -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();
+		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

Quoted 21 lines
board/esd/meesc/meesc.c +6 -0
+	}
+
+	return 0;
+}
+#endif /* CONFIG_MISC_INIT_R */
+
 int board_init(void)
 {
 	/* Peripheral Clock Enable Register */
include/configs/meesc.h +1 -0
index b996854..034e81c 100644
@@ -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