Skip to contentSkip to conversation

8xx: timebase frequency should not depend on bus-frequency

PATCH In review Anton Vorontsov 4 participants 8 messages Feb 21, 2008 – Feb 22, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 8xx: timebase frequency should not depend on bus-frequency

m8xx_setup.c says:
/* Force all 8xx processors to use divide by 16 processor clock. */

And at the same time it is using bus-frequency for calculating timebase. It is okay for most setups because bus-frequency is equal to clock-frequency.

The problem emerges when cpu frequency is > 66MHz, quoting u-boot/cpu/mpc8xx/speed.c:

        if (gd->cpu_clk <= 66000000) {
                sccr_reg |= SCCR_EBDF00;        /* bus division factor = 1 */
                gd->bus_clk = gd->cpu_clk;
        } else {
                sccr_reg |= SCCR_EBDF01;        /* bus division factor = 2 */
                gd->bus_clk = gd->cpu_clk / 2;
        }

So in case of cpu clock > 66MHz, bus_clk = cpu_clk / 2. An then, from Linux, we calculate timebase frequency as tb_freq = bus_clk / 16, that is cpu_clk / 2 / 16, which is wrong.

This patch fixes system time drifting problem on the EP885C board running at 133MHz.

---
 arch/powerpc/platforms/8xx/m8xx_setup.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
arch/powerpc/platforms/8xx/m8xx_setup.c +1 -6
index 184f998..0d9f75c 100644
@@ -111,17 +111,12 @@ void __init mpc8xx_calibrate_decr(void)
 
 	/* Processor frequency is MHz.
 	 */
-	ppc_tb_freq = 50000000;
-	if (!get_freq("bus-frequency", &ppc_tb_freq)) {
-		printk(KERN_ERR "WARNING: Estimating decrementer frequency "
-		                "(not found)\n");
-	}
-	ppc_tb_freq /= 16;
 	ppc_proc_freq = 50000000;
 	if (!get_freq("clock-frequency", &ppc_proc_freq))
 		printk(KERN_ERR "WARNING: Estimating processor frequency "
 		                "(not found)\n");
 
+	ppc_tb_freq = ppc_proc_freq / 16;
 	printk("Decrementer Frequency = 0x%lx\n", ppc_tb_freq);
 
 	/* Perform some more timer/timebase initialization.  This used
Signature · 1 line
1.5.2.2
#1 lore raw
Quoted 10 lines · Anton Vorontsov
arch/powerpc/platforms/8xx/m8xx_setup.c +0 -2
index 184f998..0d9f75c 100644
@@ -111,17 +111,12 @@ void __init mpc8xx_calibrate_decr(void)
 
 	/* Processor frequency is MHz.
 	 */
-	ppc_tb_freq = 50000000;
-	if (!get_freq("bus-frequency", &ppc_tb_freq)) {

arch/powerpc/platforms/8xx/m8xx_setup.c void __init mpc8xx_calibrate_decr(void) · line 119

Quoted 10 lines
arch/powerpc/platforms/8xx/m8xx_setup.c +1 -4
-		printk(KERN_ERR "WARNING: Estimating decrementer frequency "
-		                "(not found)\n");
-	}
-	ppc_tb_freq /= 16;
 	ppc_proc_freq = 50000000;
 	if (!get_freq("clock-frequency", &ppc_proc_freq))
 		printk(KERN_ERR "WARNING: Estimating processor frequency "
 		                "(not found)\n");
 
+	ppc_tb_freq = ppc_proc_freq / 16;

Shouldn't we just use the timebase-frequency property?

-Scott

#2 lore raw
Quoted 21 lines · Scott Wood
Quoted 20 lines · Anton Vorontsov
arch/powerpc/platforms/8xx/m8xx_setup.c +0 -6
index 184f998..0d9f75c 100644
@@ -111,17 +111,12 @@ void __init mpc8xx_calibrate_decr(void)
 
 	/* Processor frequency is MHz.
 	 */
-	ppc_tb_freq = 50000000;
-	if (!get_freq("bus-frequency", &ppc_tb_freq)) {
-		printk(KERN_ERR "WARNING: Estimating decrementer frequency "
-		                "(not found)\n");
-	}
-	ppc_tb_freq /= 16;
 	ppc_proc_freq = 50000000;
 	if (!get_freq("clock-frequency", &ppc_proc_freq))
 		printk(KERN_ERR "WARNING: Estimating processor frequency "
 		                "(not found)\n");
 
Quoted 3 lines

arch/powerpc/platforms/8xx/m8xx_setup.c void __init mpc8xx_calibrate_decr(void) · line 119

Quoted 1 line
arch/powerpc/platforms/8xx/m8xx_setup.c +1 -0
+	ppc_tb_freq = ppc_proc_freq / 16;

Shouldn't we just use the timebase-frequency property?

Nope. Most u-boots currently do not setup timebase-frequency, and if they are setting it up, they're doing it wrong, in sense that Linux overwrites timebase setup (yeah, in this regard MPC8xx is special).

So, for MPC8xx, Linux doesn't care what timebase setup was used in the firmware.

Signature · 4 lines
Anton Vorontsov
email: [email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2
#3 lore raw
Quoted 21 lines · Anton Vorontsov
Quoted 20 lines · Scott Wood
Quoted 19 lines · Anton Vorontsov
arch/powerpc/platforms/8xx/m8xx_setup.c +0 -6
index 184f998..0d9f75c 100644
@@ -111,17 +111,12 @@ void __init mpc8xx_calibrate_decr(void)
 
 	/* Processor frequency is MHz.
 	 */
-	ppc_tb_freq = 50000000;
-	if (!get_freq("bus-frequency", &ppc_tb_freq)) {
-		printk(KERN_ERR "WARNING: Estimating decrementer frequency "
-		                "(not found)\n");
-	}
-	ppc_tb_freq /= 16;
 	ppc_proc_freq = 50000000;
 	if (!get_freq("clock-frequency", &ppc_proc_freq))
 		printk(KERN_ERR "WARNING: Estimating processor frequency "
 		                "(not found)\n");
 
Quoted 6 lines
Quoted 2 lines

arch/powerpc/platforms/8xx/m8xx_setup.c void __init mpc8xx_calibrate_decr(void) · line 119

Quoted 1 line
arch/powerpc/platforms/8xx/m8xx_setup.c +1 -0
+	ppc_tb_freq = ppc_proc_freq / 16;

Shouldn't we just use the timebase-frequency property?

Nope. Most u-boots currently do not setup timebase-frequency, and if they are setting it up, they're doing it wrong, in sense that Linux overwrites timebase setup (yeah, in this regard MPC8xx is special).

Current u-boots don't support device trees at all on 8xx. The most recent 8xx FDT patch I saw called get_tbclk() to fill in timebase-frequency; does get_tbclk() not work?

Obviously, when booting with a cuImage we can't use u-boot's value, since it's not in the bd_t. In that case, we should fix the wrapper's calculation of the timebase frequency.

-Scott

#4 lore raw

On Thu, Feb 21, 2008 at 02:06:58PM -0600, Scott Wood wrote:
[...]

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

+++ b/arch/powerpc/platforms/8xx/m8xx_setup.c

arch/powerpc/platforms/8xx/m8xx_setup.c +0 -6
@@ -111,17 +111,12 @@ void __init mpc8xx_calibrate_decr(void)
 
 	/* Processor frequency is MHz.
 	 */
-	ppc_tb_freq = 50000000;
-	if (!get_freq("bus-frequency", &ppc_tb_freq)) {
-		printk(KERN_ERR "WARNING: Estimating decrementer frequency "
-		                "(not found)\n");
-	}
-	ppc_tb_freq /= 16;
 	ppc_proc_freq = 50000000;
 	if (!get_freq("clock-frequency", &ppc_proc_freq))
 		printk(KERN_ERR "WARNING: Estimating processor frequency "
 		                "(not found)\n");
 
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

arch/powerpc/platforms/8xx/m8xx_setup.c void __init mpc8xx_calibrate_decr(void) · line 119

Quoted 1 line
arch/powerpc/platforms/8xx/m8xx_setup.c +1 -0
+	ppc_tb_freq = ppc_proc_freq / 16;

Shouldn't we just use the timebase-frequency property?

Nope. Most u-boots currently do not setup timebase-frequency, and if they are setting it up, they're doing it wrong, in sense that Linux overwrites timebase setup (yeah, in this regard MPC8xx is special).

Current u-boots don't support device trees at all on 8xx.

Yes, vanilla u-boots. I assume many of us use some u-boot hacks to actually boot with the device tree (no, not cuboots)... ;-)

Quoted 3 lines

The most
recent 8xx FDT patch I saw called get_tbclk() to fill in timebase-frequency; does get_tbclk() not work?

I don't know. I didn't look at this, it isn't interesting because currently getting timebase-frequency from the device tree is meaningless on MPC8xx. Linux is doing timebase stuff on its own.

Surely, moving timebase setup code into the cuboot will solve backwards compatibility issues, so we'll setup timebase-frequency there, and will use generic_calibrate_decr(). And for FDT-aware u-boots we'll simply get fixed up timebase-frequency.

Unfortunately (or fortunately ;-) I don't have this 8xx board any longer, so I'd suggest to not expect such 8xx cleanups from me in near future...

If you have such patches pending... surely, they would be more correct way to solve the issue.

Thanks,

Signature · 4 lines
Anton Vorontsov
email: [email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2
#5 lore raw
Quoted 5 lines · Anton Vorontsov
Quoted 1 line · Scott Wood

Current u-boots don't support device trees at all on 8xx.

Yes, vanilla u-boots. I assume many of us use some u-boot hacks to actually boot with the device tree (no, not cuboots)... ;-)

Fine, but don't expect misbehavior from out-of-tree u-boots to be used as justification for the kernel ignoring device tree content. :-)

-Scott

#6 lore raw
Quoted 9 lines · Scott Wood
Quoted 5 lines · Anton Vorontsov
Quoted 1 line · Scott Wood

Current u-boots don't support device trees at all on 8xx.

Yes, vanilla u-boots. I assume many of us use some u-boot hacks to actually boot with the device tree (no, not cuboots)... ;-)

Fine, but don't expect misbehavior from out-of-tree u-boots to be used as justification for the kernel ignoring device tree content. :-)

You got me wrong, maybe I wasn't clear enough: it wasn't justification of any kind. It's was just a remark regarding u-boot still not supporting fdt for 8xx (20 lines of code we're lazy to cleanup, write annotation to the patch and send it ;-).

Regarding timebase issue. This issue isn't introduced by the u-boots. It is _Linux_ code that is buggy. I'm agree that ideally we should get timebase-frequency from the device tree, but if we'll start getting it from inside the current code, it will look like:

...linux setups tbfreq = cpu_clk / 16... tbfreq = of_get_property(.."timebase-frequency"..);

You see? This is illogical, error-prone, and whatnot. :-) I agree, to fix this right way, we should:
a) fix current u-boots;
b) rework 8xx/ Linux code; and
c) rework cuboot for compatibility;

Until that happen that tiny patch is a valid bug fix, right?

Signature · 4 lines
Anton Vorontsov
email: [email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2
#7 lore raw
Quoted 8 lines · On Fri, 22 Feb 2008 02:41:36 +0300 Anton Vorontsov <[email protected]>…
Quoted 7 lines · Scott Wood
Quoted 5 lines · Anton Vorontsov
Quoted 1 line · Scott Wood

Current u-boots don't support device trees at all on 8xx.

Yes, vanilla u-boots. I assume many of us use some u-boot hacks to actually boot with the device tree (no, not cuboots)... ;-)

Quoted 7 lines
Quoted 2 lines

Fine, but don't expect misbehavior from out-of-tree u-boots to be used as justification for the kernel ignoring device tree content. :-)

You got me wrong, maybe I wasn't clear enough: it wasn't justification of any kind. It's was just a remark regarding u-boot still not supporting fdt for 8xx (20 lines of code we're lazy to cleanup, write annotation to the patch and send it ;-).

Hey Anton.

I won't make any comment on what Linux should do with an older version of u-boot.

However, just to let you know, there are a couple of patches to do a more modern fdt on 8xx- sent to the u-boot list in the last <= ~ 10 days.

Using those patches - which incorporate the changes suggested by Scott re:
get_tbclk()- the timebase-frequency field is indeed stuffed with u-boot's get_tbclk(); - see below.

u-boot/cpu/mpc8xx/fdt.c

void ft_cpu_setup(void *blob, bd_t *bd)

{
        do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
                "timebase-frequency", get_tbclk(), 1);
        do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
                "bus-frequency", bd->bi_busfreq, 1);
        do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
                "clock-frequency", bd->bi_intfreq, 1);
        do_fixup_by_compat_u32(blob, "fsl,cpm-brg", "clock-frequency",
                gd->brg_clk, 1);

        /* Fixup ethernet MAC addresses */
        fdt_fixup_ethernet(blob, bd);

        fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
}

Adding fdt support to an 8xx board is then as simple as defining

/* pass open firmware flat tree */
#define CONFIG_OF_LIBFDT 1
#define CONFIG_OF_BOARD_SETUP 1

In your u-boot/include/configs/MySuperBoard.h

Best,
Bryan