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