Skip to contentSkip to conversation

mpc85xx: add function prototypes for sys and ddr clocks to speed.c

PATCH New Timur Tabi 3 participants 8 messages May 21, 2010 PowerPC

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH 1/1 mpc85xx: add function prototypes for sys and ddr clocks to speed.c

On most Freescale 85xx boards, the CONFIG_SYS_CLK_FREQ and CONFIG_DDR_CLK_FREQ macros are defined like this:

This means that in order to use these macros, the callers must have prototypes for the corresponding functions. On 85xx, only speed.c uses these macros, so let's define the prototypes there. This eliminates the need to define the prototypes in the board config files.

---

I'm posting the patch for review, and if everyone likes it, inclusion in the 85xx repo. Comments welcome.

 arch/powerpc/cpu/mpc85xx/speed.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
arch/powerpc/cpu/mpc85xx/speed.c +4 -0
index 8132115..724ce9d 100644
@@ -31,6 +31,10 @@
 #include <asm/processor.h>
 #include <asm/io.h>
 
+/* Board-specific clock frequency functions. */
+unsigned long calculate_board_sys_clk(void);
+unsigned long calculate_board_ddr_clk(void);
+
 DECLARE_GLOBAL_DATA_PTR;
 
 /* --------------------------------------------------------------- */
Signature · 1 line
1.6.5
#1 lore raw

PATCH 1/1 mpc85xx: add function prototypes for sys and ddr clocks to speed.c

Quoted 2 lines · Timur Tabi

On most Freescale 85xx boards, the CONFIG_SYS_CLK_FREQ and CONFIG_DDR_CLK_FREQ macros are defined like this:

Like what?

Quoted 4 lines

This means that in order to use these macros, the callers must have prototypes for the corresponding functions. On 85xx, only speed.c uses these macros, so let's define the prototypes there. This eliminates the need to define the prototypes in the board config files.

It also eliminates the utility of the prototype in making sure usage matches the definition, and requires that the user of the macros provide implementation prerequisites.

-Scott

author
#2 lore raw

PATCH 1/1 mpc85xx: add function prototypes for sys and ddr clocks to speed.c

Quoted 5 lines · Scott Wood
Quoted 2 lines · Timur Tabi

On most Freescale 85xx boards, the CONFIG_SYS_CLK_FREQ and CONFIG_DDR_CLK_FREQ macros are defined like this:

Like what?

Doh. Git commit delete those lines because they began with a "#".

This was supposed to be there:

#define CONFIG_SYS_CLK_FREQ calculate_board_sys_clk()
#define CONFIG_DDR_CLK_FREQ calculate_board_ddr_clk()

Quoted 8 lines
Quoted 4 lines

This means that in order to use these macros, the callers must have prototypes for the corresponding functions. On 85xx, only speed.c uses these macros, so let's define the prototypes there. This eliminates the need to define the prototypes in the board config files.

It also eliminates the utility of the prototype in making sure usage matches the definition, and requires that the user of the macros provide implementation prerequisites.

Hmm... Looks like calculate_board_sys_clk() is defined only on the p2020 currently. Everyone else uses get_board_sys_clk(). So perhaps we need to fix p2020ds to use get_board_sys_clk() instead of calculate_board_sys_clk().
But that's a different problem.

Well, I'm open to suggestions. Wolfgang asked me to find a solution to this:

#ifndef __ASSEMBLY__
unsigned long calculate_board_sys_clk(void);
unsigned long calculate_board_ddr_clk(void);
#endif
#define CONFIG_SYS_CLK_FREQ calculate_board_sys_clk()
#define CONFIG_DDR_CLK_FREQ calculate_board_ddr_clk()

He doesn't want the prototypes in the board header file.

Quoted 2 lines

-Scott

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#3 lore raw

PATCH 1/1 mpc85xx: add function prototypes for sys and ddr clocks to speed.c

Quoted 8 lines · Timur Tabi
Quoted 5 lines · Scott Wood
Quoted 2 lines · Timur Tabi

On most Freescale 85xx boards, the CONFIG_SYS_CLK_FREQ and CONFIG_DDR_CLK_FREQ macros are defined like this:

Like what?

Doh. Git commit delete those lines because they began with a "#".

Hmm... is there any way to override that and insert such a line into a git commit?

Quoted 10 lines

Well, I'm open to suggestions. Wolfgang asked me to find a solution to this:

#ifndef __ASSEMBLY__
unsigned long calculate_board_sys_clk(void);
unsigned long calculate_board_ddr_clk(void);
#endif
#define CONFIG_SYS_CLK_FREQ calculate_board_sys_clk()
#define CONFIG_DDR_CLK_FREQ calculate_board_ddr_clk()

He doesn't want the prototypes in the board header file.

I think the board header file (or some header factored out from a set of similar boards, which the board header includes) is exactly where it belongs, given that it's implemented in a board C file, and the C call is not a public API. Some boards just hard code it as a constant. Others might want to call some other function, maybe with arguments (in fact, I see a dummy argument of zero passed in many if not all existing calls to these functions -- why?).

Duplicating large chunks of code is bad, but extremism in avoiding anything that even looks similar to something else, and breaking the logical isolation of said things in the process, is bad as well.

-Scott

author
#4 lore raw

PATCH 1/1 mpc85xx: add function prototypes for sys and ddr clocks to speed.c

Quoted 4 lines · Scott Wood
Quoted 1 line

Doh. Git commit delete those lines because they began with a "#".

Hmm... is there any way to override that and insert such a line into a git commit?

I was going to just insert a blank space or some other character before the #.

Quoted 4 lines

I think the board header file (or some header factored out from a set of similar boards, which the board header includes) is exactly where it belongs, given that it's implemented in a board C file, and the C call is not a public API.

Well, you'll have to convince Wolfgang of that, not me. He won't accept my P1022DS board patch until I fix this "problem".

Quoted 4 lines

Some boards just hard code it as a constant.
Others might want to call some other function, maybe with arguments (in fact, I see a dummy argument of zero passed in many if not all existing calls to these functions -- why?).

Probably some legacy stuff. Once this issue is resolved, I'll probably post a patch that unifies the functions in some way.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
author
#5 lore raw

PATCH 1/1 mpc85xx: add function prototypes for sys and ddr clocks to speed.c

Quoted 2 lines · Timur Tabi

Well, you'll have to convince Wolfgang of that, not me. He won't accept my P1022DS board patch until I fix this "problem".

Actually, if you look at Kumar's ICS307 patch, you'll see he fixes this problem for any board that uses the ICS307:

Quoted 13 lines
(quoted diff) +2 -10
-#ifndef __ASSEMBLY__
-extern unsigned long calculate_board_sys_clk(unsigned long dummy);
-extern unsigned long calculate_board_ddr_clk(unsigned long dummy);
-/* extern unsigned long get_board_sys_clk(unsigned long dummy); */
-/* extern unsigned long get_board_ddr_clk(unsigned long dummy); */
-#endif
-#define CONFIG_SYS_CLK_FREQ	calculate_board_sys_clk(0) /* sysclk for MPC85xx */
-#define CONFIG_DDR_CLK_FREQ	calculate_board_ddr_clk(0) /* ddrclk for MPC85xx */
+#define CONFIG_SYS_CLK_FREQ	get_board_sys_clk() /* sysclk for MPC85xx */
+#define CONFIG_DDR_CLK_FREQ	get_board_ddr_clk() /* ddrclk for MPC85xx */
 #define CONFIG_ICS307_REFCLK_HZ	33333000  /* ICS307 clock chip ref freq */
-#define CONFIG_GET_CLK_FROM_ICS307	  /* decode sysclk and ddrclk freq
-					     from ICS307 instead of switches */
Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#6 lore raw

PATCH 1/1 mpc85xx: add function prototypes for sys and ddr clocks to speed.c

In reply to Timur Tabi
Quoted 9 lines · Timur Tabi
Quoted 4 lines · Scott Wood
Quoted 1 line

Doh. Git commit delete those lines because they began with a "#".

Hmm... is there any way to override that and insert such a line into a git commit?

I was going to just insert a blank space or some other character before the #.

Quoted 7 lines
Quoted 4 lines

I think the board header file (or some header factored out from a set of similar boards, which the board header includes) is exactly where it belongs, given that it's implemented in a board C file, and the C call is not a public API.

Well, you'll have to convince Wolfgang of that, not me. He won't accept my P1022DS board patch until I fix this "problem".

I think the "some header factored out from a set of similar boards" (or possibly similar board support idioms) approach would meet his request, though doing that at too fine-grained a level could lead to an unreadable tangle of header files and/or ifdefs.

-Scott

#7 lore raw

PATCH 1/1 mpc85xx: add function prototypes for sys and ddr clocks to speed.c

In reply to Scott Wood
Quoted 6 lines · Scott Wood
Quoted 5 lines · Timur Tabi
Quoted 4 lines · Scott Wood
Quoted 2 lines · Timur Tabi

On most Freescale 85xx boards, the CONFIG_SYS_CLK_FREQ and CONFIG_DDR_CLK_FREQ macros are defined like this:

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Like what?

Doh. Git commit delete those lines because they began with a "#".

Hmm... is there any way to override that and insert such a line into a git commit?

'git commit --cleanup=verbatim' should do it. I think "--cleanup=whitespace" should also work.

Best,
Peter