1*9961a0b6SThomas Chou /* 2*9961a0b6SThomas Chou * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw> 3*9961a0b6SThomas Chou * 4*9961a0b6SThomas Chou * SPDX-License-Identifier: GPL-2.0+ 5*9961a0b6SThomas Chou */ 6*9961a0b6SThomas Chou 7*9961a0b6SThomas Chou #include <common.h> 8*9961a0b6SThomas Chou #include <dm.h> 9*9961a0b6SThomas Chou #include <errno.h> 10*9961a0b6SThomas Chou #include <timer.h> 11*9961a0b6SThomas Chou #include <os.h> 12*9961a0b6SThomas Chou 13*9961a0b6SThomas Chou /* system timer offset in ms */ 14*9961a0b6SThomas Chou static unsigned long sandbox_timer_offset; 15*9961a0b6SThomas Chou 16*9961a0b6SThomas Chou void sandbox_timer_add_offset(unsigned long offset) 17*9961a0b6SThomas Chou { 18*9961a0b6SThomas Chou sandbox_timer_offset += offset; 19*9961a0b6SThomas Chou } 20*9961a0b6SThomas Chou 21*9961a0b6SThomas Chou static int sandbox_timer_get_count(struct udevice *dev, unsigned long *count) 22*9961a0b6SThomas Chou { 23*9961a0b6SThomas Chou *count = os_get_nsec() / 1000 + sandbox_timer_offset * 1000; 24*9961a0b6SThomas Chou 25*9961a0b6SThomas Chou return 0; 26*9961a0b6SThomas Chou } 27*9961a0b6SThomas Chou 28*9961a0b6SThomas Chou static int sandbox_timer_probe(struct udevice *dev) 29*9961a0b6SThomas Chou { 30*9961a0b6SThomas Chou struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); 31*9961a0b6SThomas Chou 32*9961a0b6SThomas Chou uc_priv->clock_rate = 1000000; 33*9961a0b6SThomas Chou 34*9961a0b6SThomas Chou return 0; 35*9961a0b6SThomas Chou } 36*9961a0b6SThomas Chou 37*9961a0b6SThomas Chou static const struct timer_ops sandbox_timer_ops = { 38*9961a0b6SThomas Chou .get_count = sandbox_timer_get_count, 39*9961a0b6SThomas Chou }; 40*9961a0b6SThomas Chou 41*9961a0b6SThomas Chou static const struct udevice_id sandbox_timer_ids[] = { 42*9961a0b6SThomas Chou { .compatible = "sandbox,timer" }, 43*9961a0b6SThomas Chou { } 44*9961a0b6SThomas Chou }; 45*9961a0b6SThomas Chou 46*9961a0b6SThomas Chou U_BOOT_DRIVER(sandbox_timer) = { 47*9961a0b6SThomas Chou .name = "sandbox_timer", 48*9961a0b6SThomas Chou .id = UCLASS_TIMER, 49*9961a0b6SThomas Chou .of_match = sandbox_timer_ids, 50*9961a0b6SThomas Chou .probe = sandbox_timer_probe, 51*9961a0b6SThomas Chou .ops = &sandbox_timer_ops, 52*9961a0b6SThomas Chou .flags = DM_FLAG_PRE_RELOC, 53*9961a0b6SThomas Chou }; 54