Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b070a03f authored by Oskar Schirmer's avatar Oskar Schirmer Committed by Chris Zankel
Browse files

xtensa: implement ccount calibration for s6000



Calculate core frequency from timers at boot time
instead of assuming a fixed frequency. This is
useful as the true frequency is set up by the
boot loader, thus variable.

Signed-off-by: default avatarOskar Schirmer <os@emlix.com>
Signed-off-by: default avatarChris Zankel <chris@zankel.net>
parent d15f05eb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ config XTENSA_VARIANT_S6000
	bool "s6000 - Stretch software configurable processor"
	select VARIANT_IRQ_SWITCH
	select ARCH_REQUIRE_GPIOLIB
	select XTENSA_CALIBRATE_CCOUNT
endchoice

config XTENSA_UNALIGNED_USER
+1 −0
Original line number Diff line number Diff line
# s6000 Makefile

obj-y		+= irq.o gpio.o
obj-$(CONFIG_XTENSA_CALIBRATE_CCOUNT)	+= delay.o
+27 −0
Original line number Diff line number Diff line
#include <asm/delay.h>
#include <asm/timex.h>
#include <asm/io.h>
#include <variant/hardware.h>

#define LOOPS 10
void platform_calibrate_ccount(void)
{
	u32 uninitialized_var(a);
	u32 uninitialized_var(u);
	u32 b;
	u32 tstamp = S6_REG_GREG1 + S6_GREG1_GLOBAL_TIMER;
	int i = LOOPS+1;
	do {
		u32 t = u;
		asm volatile(
		"1:	l32i %0, %2, 0 ;"
		"	beq %0, %1, 1b ;"
		: "=&a"(u) : "a"(t), "a"(tstamp));
		b = xtensa_get_ccount();
		if (i == LOOPS)
			a = b;
	} while (--i >= 0);
	b -= a;
	nsec_per_ccount = (LOOPS * 10000) / b;
	ccount_per_jiffy = b * (100000UL / (LOOPS * HZ));
}