123eafdafSFrançois Revol /* 2bdce546cSDavid Karoly * Copyright 2007-2022, Haiku Inc. All rights reserved. 323eafdafSFrançois Revol * Distributed under the terms of the MIT License. 423eafdafSFrançois Revol * 523eafdafSFrançois Revol * Authors: 623eafdafSFrançois Revol * François Revol <revol@free.fr> 7be7195d0SIthamar R. Adema * Ithamar R. Adema <ithamar@upgrade-android.com> 823eafdafSFrançois Revol * 923eafdafSFrançois Revol * Copyright 2001, Travis Geiselbrecht. All rights reserved. 1023eafdafSFrançois Revol * Distributed under the terms of the NewOS License. 1123eafdafSFrançois Revol */ 1223eafdafSFrançois Revol 1323eafdafSFrançois Revol 1423eafdafSFrançois Revol #include <boot/stage2.h> 1523eafdafSFrançois Revol #include <kernel.h> 1623eafdafSFrançois Revol #include <debug.h> 1723eafdafSFrançois Revol 1823eafdafSFrançois Revol #include <timer.h> 1923eafdafSFrançois Revol #include <arch/timer.h> 20be7195d0SIthamar R. Adema #include <arch/cpu.h> 21be7195d0SIthamar R. Adema 22a52dd58dSIthamar R. Adema #include <drivers/bus/FDT.h> 23bdce546cSDavid Karoly #include "arch_timer_generic.h" 24a52dd58dSIthamar R. Adema #include "soc.h" 25a52dd58dSIthamar R. Adema 26a52dd58dSIthamar R. Adema #include "soc_pxa.h" 27a52dd58dSIthamar R. Adema #include "soc_omap3.h" 28f86b5828SIthamar R. Adema 29f86b5828SIthamar R. Adema //#define TRACE_ARCH_TIMER 30f86b5828SIthamar R. Adema #ifdef TRACE_ARCH_TIMER 31bdce546cSDavid Karoly # define TRACE(x...) dprintf(x) 32f86b5828SIthamar R. Adema #else 33bdce546cSDavid Karoly # define TRACE(x...) ; 34f86b5828SIthamar R. Adema #endif 35f86b5828SIthamar R. Adema 36f86b5828SIthamar R. Adema 3723eafdafSFrançois Revol void arch_timer_set_hardware_timer(bigtime_t timeout)3823eafdafSFrançois Revolarch_timer_set_hardware_timer(bigtime_t timeout) 3923eafdafSFrançois Revol { 40a52dd58dSIthamar R. Adema HardwareTimer *timer = HardwareTimer::Get(); 41a52dd58dSIthamar R. Adema if (timer != NULL) 42a52dd58dSIthamar R. Adema timer->SetTimeout(timeout); 43af1c0b55SIthamar R. Adema } 44af1c0b55SIthamar R. Adema 4523eafdafSFrançois Revol 4623eafdafSFrançois Revol void arch_timer_clear_hardware_timer()4723eafdafSFrançois Revolarch_timer_clear_hardware_timer() 4823eafdafSFrançois Revol { 49a52dd58dSIthamar R. Adema HardwareTimer *timer = HardwareTimer::Get(); 50a52dd58dSIthamar R. Adema if (timer != NULL) 51a52dd58dSIthamar R. Adema timer->Clear(); 52be7195d0SIthamar R. Adema } 5323eafdafSFrançois Revol 5423eafdafSFrançois Revol int arch_init_timer(kernel_args * args)5523eafdafSFrançois Revolarch_init_timer(kernel_args *args) 5623eafdafSFrançois Revol { 57bdce546cSDavid Karoly TRACE("%s\n", __func__); 58bdce546cSDavid Karoly 59bdce546cSDavid Karoly if (ARMGenericTimer::IsAvailable()) { 60bdce546cSDavid Karoly TRACE("init ARMv7 generic timer\n"); 61bdce546cSDavid Karoly ARMGenericTimer::Init(); 62*fe2b6d77SDavid Karoly } else if (strncmp(args->arch_args.timer.kind, TIMER_KIND_OMAP3, 63*fe2b6d77SDavid Karoly sizeof(args->arch_args.timer.kind)) == 0) { 64*fe2b6d77SDavid Karoly OMAP3Timer::Init(args->arch_args.timer.regs.start, 65*fe2b6d77SDavid Karoly args->arch_args.timer.interrupt); 66*fe2b6d77SDavid Karoly } else if (strncmp(args->arch_args.timer.kind, TIMER_KIND_PXA, 67*fe2b6d77SDavid Karoly sizeof(args->arch_args.timer.kind)) == 0) { 68*fe2b6d77SDavid Karoly PXATimer::Init(args->arch_args.timer.regs.start); 69*fe2b6d77SDavid Karoly } else { 70bdce546cSDavid Karoly panic("No hardware timer found!\n"); 71*fe2b6d77SDavid Karoly } 72be7195d0SIthamar R. Adema 73be7195d0SIthamar R. Adema return B_OK; 74be7195d0SIthamar R. Adema } 75af1c0b55SIthamar R. Adema 76bdce546cSDavid Karoly 77af1c0b55SIthamar R. Adema bigtime_t system_time(void)78af1c0b55SIthamar R. Ademasystem_time(void) 79af1c0b55SIthamar R. Adema { 80a52dd58dSIthamar R. Adema HardwareTimer *timer = HardwareTimer::Get(); 81a52dd58dSIthamar R. Adema if (timer != NULL) 82a52dd58dSIthamar R. Adema return timer->Time(); 8334ed0fe7SIthamar R. Adema 84a52dd58dSIthamar R. Adema return 0; 85af1c0b55SIthamar R. Adema } 86