]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - arch/arm/include/asm/arch-armv7/generictimer.h
ARMv7: Factor out reusable timer_wait from sunxi/psci_sun7i.S
[karo-tx-uboot.git] / arch / arm / include / asm / arch-armv7 / generictimer.h
1 /*
2  * Copyright (C) 2013 - ARM Ltd
3  * Author: Marc Zyngier <marc.zyngier@arm.com>
4  *
5  * Based on code by Carl van Schaik <carl@ok-labs.com>.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef _GENERICTIMER_H_
21 #define _GENERICTIMER_H_
22
23 #ifdef __ASSEMBLY__
24
25 /*
26  * This macro provide a physical timer that can be used for delay in the code.
27  * The macro is moved from sunxi/psci_sun7i.S
28  *
29  * reg: is used in this macro.
30  * ticks: The freq is based on generic timer.
31  */
32 .macro  timer_wait      reg, ticks
33         movw    \reg, #(\ticks & 0xffff)
34         movt    \reg, #(\ticks >> 16)
35         mcr     p15, 0, \reg, c14, c2, 0
36         isb
37         mov     \reg, #3
38         mcr     p15, 0, \reg, c14, c2, 1
39 1 :     isb
40         mrc     p15, 0, \reg, c14, c2, 1
41         ands    \reg, \reg, #4
42         bne     1b
43         mov     \reg, #0
44         mcr     p15, 0, \reg, c14, c2, 1
45         isb
46 .endm
47
48 #endif /* __ASSEMBLY__ */
49
50 #endif /* _GENERICTIMER_H_ */