xref: /haiku/src/system/kernel/arch/arm/arch_timer.cpp (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
1 /*
2  * Copyright 2007-2022, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		François Revol <revol@free.fr>
7  *		Ithamar R. Adema <ithamar@upgrade-android.com>
8  *
9  * Copyright 2001, Travis Geiselbrecht. All rights reserved.
10  * Distributed under the terms of the NewOS License.
11  */
12 
13 
14 #include <boot/stage2.h>
15 #include <kernel.h>
16 #include <debug.h>
17 
18 #include <timer.h>
19 #include <arch/timer.h>
20 #include <arch/cpu.h>
21 
22 #include <drivers/bus/FDT.h>
23 #include "arch_timer_generic.h"
24 #include "soc.h"
25 
26 #include "soc_pxa.h"
27 #include "soc_omap3.h"
28 
29 //#define TRACE_ARCH_TIMER
30 #ifdef TRACE_ARCH_TIMER
31 #	define TRACE(x...) dprintf(x)
32 #else
33 #	define TRACE(x...) ;
34 #endif
35 
36 
37 void
38 arch_timer_set_hardware_timer(bigtime_t timeout)
39 {
40 	HardwareTimer *timer = HardwareTimer::Get();
41 	if (timer != NULL)
42 		timer->SetTimeout(timeout);
43 }
44 
45 
46 void
47 arch_timer_clear_hardware_timer()
48 {
49 	HardwareTimer *timer = HardwareTimer::Get();
50 	if (timer != NULL)
51 		timer->Clear();
52 }
53 
54 int
55 arch_init_timer(kernel_args *args)
56 {
57 	TRACE("%s\n", __func__);
58 
59 	if (ARMGenericTimer::IsAvailable()) {
60 		TRACE("init ARMv7 generic timer\n");
61 		ARMGenericTimer::Init();
62 	} else if (strncmp(args->arch_args.timer.kind, TIMER_KIND_OMAP3,
63 		sizeof(args->arch_args.timer.kind)) == 0) {
64 		OMAP3Timer::Init(args->arch_args.timer.regs.start,
65 			args->arch_args.timer.interrupt);
66 	} else if (strncmp(args->arch_args.timer.kind, TIMER_KIND_PXA,
67 		sizeof(args->arch_args.timer.kind)) == 0) {
68 		PXATimer::Init(args->arch_args.timer.regs.start);
69 	} else {
70 		panic("No hardware timer found!\n");
71 	}
72 
73 	return B_OK;
74 }
75 
76 
77 bigtime_t
78 system_time(void)
79 {
80 	HardwareTimer *timer = HardwareTimer::Get();
81 	if (timer != NULL)
82 		return timer->Time();
83 
84 	return 0;
85 }
86