1 /*
2 * Copyright (c) 2022 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/device.h>
8 #include <zephyr/devicetree.h>
9 #include <zephyr/drivers/counter.h>
10 #include <zephyr/kernel.h>
11 #include <soc.h>
12 #include <counter/counter_ace_v1x_rtc_regs.h>
13
counter_ace_v1x_rtc_get_value(const struct device * dev,uint64_t * value)14 static int counter_ace_v1x_rtc_get_value(const struct device *dev,
15 uint64_t *value)
16 {
17 ARG_UNUSED(dev);
18
19 uint32_t hi0, lo, hi1;
20 do {
21 hi0 = sys_read32(ACE_RTCWC_HI);
22 lo = sys_read32(ACE_RTCWC_LO);
23 hi1 = sys_read32(ACE_RTCWC_HI);
24 } while (hi0 != hi1);
25
26 *value = (((uint64_t)hi0) << 32) | lo;
27
28 return 0;
29 }
30
counter_ace_v1x_rtc_init(const struct device * dev)31 int counter_ace_v1x_rtc_init(const struct device *dev)
32 {
33 ARG_UNUSED(dev);
34
35 return 0;
36 }
37
38 static const struct counter_driver_api ace_v1x_rtc_counter_apis = {
39 .get_value_64 = counter_ace_v1x_rtc_get_value
40 };
41
42 DEVICE_DT_DEFINE(DT_NODELABEL(ace_rtc_counter), counter_ace_v1x_rtc_init, NULL, NULL, NULL,
43 PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
44 &ace_v1x_rtc_counter_apis);
45