[v5,3/9] arm: add support for arch timer

Message ID 1396377869-15724-4-git-send-email-m-karicheri2@ti.com
State New
Headers show

Commit Message

Murali Karicheri April 1, 2014, 6:44 p.m.
From: Vitaly Andrianov <vitalya@ti.com>

This patch add basic support for the architecture timer found on recent
ARMv7 based SoCs.

Signed-off-by: Vitaly Andrianov <vitalya@ti.com>
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Acked-by: Tom Rini <trini@ti.com>
---
 arch/arm/lib/Makefile     |    1 +
 arch/arm/lib/arch_timer.c |   58 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
 create mode 100644 arch/arm/lib/arch_timer.c

Comments

Masahiro Yamada April 3, 2014, 1:46 a.m. | #1
Hi Murali,

On Tue, 1 Apr 2014 14:44:23 -0400
Murali Karicheri <m-karicheri2@ti.com> wrote:

> From: Vitaly Andrianov <vitalya@ti.com>
> 
> This patch add basic support for the architecture timer found on recent
> ARMv7 based SoCs.
> 
> Signed-off-by: Vitaly Andrianov <vitalya@ti.com>
> Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
> Acked-by: Tom Rini <trini@ti.com>
> ---
>  arch/arm/lib/Makefile     |    1 +
>  arch/arm/lib/arch_timer.c |   58 +++++++++++++++++++++++++++++++++++++++++++++



I am not familiar with this timer, but your commit description implies
it is specific to ARMv7.

If so, it looks like it should go to arch/arm/cpu/armv7/ .
Is this right?


Best Regards
Masahiro Yamada
Vitaly Andrianov April 3, 2014, 11:22 a.m. | #2
Hi Masahiro,

> -----Original Message-----
> From: u-boot-bounces@lists.denx.de [mailto:u-boot-
> bounces@lists.denx.de] On Behalf Of Masahiro Yamada
> Sent: Wednesday, April 02, 2014 9:46 PM
> To: Karicheri, Muralidharan
> Cc: Rini, Tom; u-boot@lists.denx.de
> Subject: Re: [U-Boot] [PATCH v5 3/9] arm: add support for arch timer
> 
> Hi Murali,
> 
> On Tue, 1 Apr 2014 14:44:23 -0400
> Murali Karicheri <m-karicheri2@ti.com> wrote:
> 
> > From: Vitaly Andrianov <vitalya@ti.com>
> >
> > This patch add basic support for the architecture timer found on
> > recent
> > ARMv7 based SoCs.
> >
> > Signed-off-by: Vitaly Andrianov <vitalya@ti.com>
> > Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
> > Acked-by: Tom Rini <trini@ti.com>
> > ---
> >  arch/arm/lib/Makefile     |    1 +
> >  arch/arm/lib/arch_timer.c |   58
> +++++++++++++++++++++++++++++++++++++++++++++
> 
> 
> 
> I am not familiar with this timer, but your commit description implies
> it is specific to ARMv7.
> 
> If so, it looks like it should go to arch/arm/cpu/armv7/ .
> Is this right?

This is for arch timer implemented in ARM Cortex-A15 which is ARMv7.
I believe the same arch timer is in ARMv8. So, it is not specific to
ARMv7 only. The commit description mentioned only ARMv7 because the
driver was designed and tested on ARMv7.    

> 
> 
> Best Regards
> Masahiro Yamada
> 
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot

Best Regards,
Vitaly Andrianov
fenghua@phytium.com.cn April 4, 2014, 10:12 a.m. | #3
> -----Original Messages-----
> From: "Andrianov, Vitaly" <vitalya@ti.com>
> Sent Time: 2014-04-03 19:22:34 (Thursday)
> To: "Masahiro Yamada" <yamada.m@jp.panasonic.com>, "Karicheri, Muralidharan" <m-karicheri2@ti.com>
> Cc: "Rini, Tom" <trini@ti.com>, "u-boot@lists.denx.de" <u-boot@lists.denx.de>
> Subject: Re: [U-Boot] [PATCH v5 3/9] arm: add support for arch timer
> 
> Hi Masahiro,
> 
> > -----Original Message-----
> > From: u-boot-bounces@lists.denx.de [mailto:u-boot-
> > bounces@lists.denx.de] On Behalf Of Masahiro Yamada
> > Sent: Wednesday, April 02, 2014 9:46 PM
> > To: Karicheri, Muralidharan
> > Cc: Rini, Tom; u-boot@lists.denx.de
> > Subject: Re: [U-Boot] [PATCH v5 3/9] arm: add support for arch timer
> > 
> > Hi Murali,
> > 
> > On Tue, 1 Apr 2014 14:44:23 -0400
> > Murali Karicheri <m-karicheri2@ti.com> wrote:
> > 
> > > From: Vitaly Andrianov <vitalya@ti.com>
> > >
> > > This patch add basic support for the architecture timer found on
> > > recent
> > > ARMv7 based SoCs.
> > >
> > > Signed-off-by: Vitaly Andrianov <vitalya@ti.com>
> > > Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
> > > Acked-by: Tom Rini <trini@ti.com>
> > > ---
> > >  arch/arm/lib/Makefile     |    1 +
> > >  arch/arm/lib/arch_timer.c |   58
> > +++++++++++++++++++++++++++++++++++++++++++++
> > 
> > 
> > 
> > I am not familiar with this timer, but your commit description implies
> > it is specific to ARMv7.
> > 
> > If so, it looks like it should go to arch/arm/cpu/armv7/ .
> > Is this right?
> 
> This is for arch timer implemented in ARM Cortex-A15 which is ARMv7.
> I believe the same arch timer is in ARMv8. So, it is not specific to
> ARMv7 only. The commit description mentioned only ARMv7 because the
> driver was designed and tested on ARMv7.    
> 
If we want to apply the arch_timer.c to armv8,  the get_ticks() function should be modified
due to mrrc instuction. 
Furthermore, armv8 now make use of timer infrastructure of lib/time.c. 
Only get_tbclk() and timer_read_counter() are architecture specific and declared in generic_timer.c.
We'd better construct a common arch timer structure across arm platform.

Best regards,
David
Murali Karicheri April 4, 2014, 5:20 p.m. | #4
On 4/4/2014 6:12 AM, FengHua wrote:
>
>
>> -----Original Messages-----
>> From: "Andrianov, Vitaly" <vitalya@ti.com>
>> Sent Time: 2014-04-03 19:22:34 (Thursday)
>> To: "Masahiro Yamada" <yamada.m@jp.panasonic.com>, "Karicheri, Muralidharan" <m-karicheri2@ti.com>
>> Cc: "Rini, Tom" <trini@ti.com>, "u-boot@lists.denx.de" <u-boot@lists.denx.de>
>> Subject: Re: [U-Boot] [PATCH v5 3/9] arm: add support for arch timer
>>
>> Hi Masahiro,
>>
>>> -----Original Message-----
>>> From: u-boot-bounces@lists.denx.de [mailto:u-boot-
>>> bounces@lists.denx.de] On Behalf Of Masahiro Yamada
>>> Sent: Wednesday, April 02, 2014 9:46 PM
>>> To: Karicheri, Muralidharan
>>> Cc: Rini, Tom; u-boot@lists.denx.de
>>> Subject: Re: [U-Boot] [PATCH v5 3/9] arm: add support for arch timer
>>>
>>> Hi Murali,
>>>
>>> On Tue, 1 Apr 2014 14:44:23 -0400
>>> Murali Karicheri <m-karicheri2@ti.com> wrote:
>>>
>>>> From: Vitaly Andrianov <vitalya@ti.com>
>>>>
>>>> This patch add basic support for the architecture timer found on
>>>> recent
>>>> ARMv7 based SoCs.
>>>>
>>>> Signed-off-by: Vitaly Andrianov <vitalya@ti.com>
>>>> Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
>>>> Acked-by: Tom Rini <trini@ti.com>
>>>> ---
>>>>   arch/arm/lib/Makefile     |    1 +
>>>>   arch/arm/lib/arch_timer.c |   58
>>> +++++++++++++++++++++++++++++++++++++++++++++
>>>
>>>
>>>
>>> I am not familiar with this timer, but your commit description implies
>>> it is specific to ARMv7.
>>>
>>> If so, it looks like it should go to arch/arm/cpu/armv7/ .
>>> Is this right?
>> This is for arch timer implemented in ARM Cortex-A15 which is ARMv7.
>> I believe the same arch timer is in ARMv8. So, it is not specific to
>> ARMv7 only. The commit description mentioned only ARMv7 because the
>> driver was designed and tested on ARMv7.
>>
> If we want to apply the arch_timer.c to armv8,  the get_ticks() function should be modified
> due to mrrc instuction.
> Furthermore, armv8 now make use of timer infrastructure of lib/time.c.
> Only get_tbclk() and timer_read_counter() are architecture specific and declared in generic_timer.c.
> We'd better construct a common arch timer structure across arm platform.
>
> Best regards,
> David
>
>
>
>
>
The v6 of the series just posted has moved the arch_timer.c to 
arch/arm/cpu/armv7 folder
as requested by you.

Regards,

Murali

Patch

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 9fc81cd..5860814 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -32,6 +32,7 @@  obj-$(CONFIG_USE_ARCH_MEMCPY) += memcpy.o
 else
 obj-$(CONFIG_SPL_FRAMEWORK) += spl.o
 endif
+obj-$(CONFIG_SYS_ARCH_TIMER) += arch_timer.o
 
 obj-y	+= sections.o
 ifdef CONFIG_ARM64
diff --git a/arch/arm/lib/arch_timer.c b/arch/arm/lib/arch_timer.c
new file mode 100644
index 0000000..0588e2b
--- /dev/null
+++ b/arch/arm/lib/arch_timer.c
@@ -0,0 +1,58 @@ 
+/*
+ * (C) Copyright 2012-2014
+ *     Texas Instruments Incorporated, <www.ti.com>
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <div64.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int timer_init(void)
+{
+	gd->arch.tbl = 0;
+	gd->arch.tbu = 0;
+
+	gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ;
+
+	return 0;
+}
+
+unsigned long long get_ticks(void)
+{
+	ulong nowl, nowu;
+
+	asm volatile("mrrc p15, 0, %0, %1, c14" : "=r" (nowl), "=r" (nowu));
+
+	gd->arch.tbl = nowl;
+	gd->arch.tbu = nowu;
+
+	return (((unsigned long long)gd->arch.tbu) << 32) | gd->arch.tbl;
+}
+
+
+ulong get_timer(ulong base)
+{
+	return lldiv(get_ticks(), gd->arch.timer_rate_hz) - base;
+}
+
+void __udelay(unsigned long usec)
+{
+	unsigned long long endtime;
+
+	endtime = lldiv((unsigned long long)usec * gd->arch.timer_rate_hz,
+			1000UL);
+
+	endtime += get_ticks();
+
+	while (get_ticks() < endtime)
+		;
+}
+
+ulong get_tbclk(void)
+{
+	return gd->arch.timer_rate_hz;
+}