]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - arch/arm/cpu/armv7/ls102xa/timer.c
d5237d214a2e4b202cac653f0864f29f0b092254
2 * Copyright 2014 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/immap_ls102xa.h>
11 #include <asm/arch/clock.h>
13 DECLARE_GLOBAL_DATA_PTR
;
16 * This function is intended for SHORT delays only.
17 * It will overflow at around 10 seconds @ 400MHz,
18 * or 20 seconds @ 200MHz.
20 unsigned long usec2ticks(unsigned long usec
)
25 ticks
= ((usec
* (get_tbclk()/1000)) + 500) / 1000;
27 ticks
= ((usec
/ 10) * (get_tbclk() / 100000));
32 static inline unsigned long long tick_to_time(unsigned long long tick
)
36 asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (freq
));
38 tick
*= CONFIG_SYS_HZ
;
44 static inline unsigned long long us_to_tick(unsigned long long usec
)
48 asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (freq
));
50 usec
= usec
* freq
+ 999999;
51 do_div(usec
, 1000000);
58 struct sctr_regs
*sctr
= (struct sctr_regs
*)SCTR_BASE_ADDR
;
59 unsigned long ctrl
, freq
;
60 unsigned long long val
;
62 /* Enable System Counter */
63 writel(SYS_COUNTER_CTRL_ENABLE
, &sctr
->cntcr
);
65 freq
= COUNTER_FREQUENCY
;
66 asm("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq
));
68 /* Set PL1 Physical Timer Ctrl */
69 ctrl
= ARCH_TIMER_CTRL_ENABLE
;
70 asm("mcr p15, 0, %0, c14, c2, 1" : : "r" (ctrl
));
72 /* Set PL1 Physical Comp Value */
74 asm("mcrr p15, 2, %Q0, %R0, c14" : : "r" (val
));
82 unsigned long long get_ticks(void)
84 unsigned long long now
;
86 asm("mrrc p15, 0, %Q0, %R0, c14" : "=r" (now
));
88 gd
->arch
.tbl
= (unsigned long)(now
& 0xffffffff);
89 gd
->arch
.tbu
= (unsigned long)(now
>> 32);
94 unsigned long get_timer_masked(void)
96 return tick_to_time(get_ticks());
99 unsigned long get_timer(ulong base
)
101 return get_timer_masked() - base
;
104 /* delay x useconds and preserve advance timstamp value */
105 void __udelay(unsigned long usec
)
107 unsigned long long start
;
110 start
= get_ticks(); /* get current timestamp */
111 tmo
= us_to_tick(usec
); /* convert usecs to ticks */
113 while ((get_ticks() - start
) < tmo
)
114 ; /* loop till time has passed */
118 * This function is derived from PowerPC code (timebase clock frequency).
119 * On ARM it returns the number of timer ticks per second.
121 unsigned long get_tbclk(void)
125 asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (freq
));