1 /* 2 * Copyright (c) 2023 - 2024 Intel Corporation 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <sedi_driver_rtc.h> 8 9 /* driver version */ 10 #define SEDI_RTC_DRIVER_VERSION SEDI_DRIVER_VERSION_MAJOR_MINOR(0, 1) 11 12 /* driver version */ 13 static const sedi_driver_version_t driver_version = { SEDI_RTC_API_VERSION, 14 SEDI_RTC_DRIVER_VERSION }; 15 16 /* driver capabilities */ 17 static const sedi_rtc_capabilities_t driver_capabilities = { .support_alarm = 0, 18 .support_callback = 0, 19 .reserved = 0 }; 20 sedi_rtc_to_us(uint64_t rtc_ticks)21static inline uint64_t sedi_rtc_to_us(uint64_t rtc_ticks) 22 { 23 return SEDI_RTC_TICKS2US(rtc_ticks); 24 } 25 sedi_rtc_get_version(void)26sedi_driver_version_t sedi_rtc_get_version(void) 27 { 28 return driver_version; 29 } 30 sedi_rtc_get_capabilities(sedi_rtc_capabilities_t * cap)31int sedi_rtc_get_capabilities(sedi_rtc_capabilities_t *cap) 32 { 33 SEDI_ASSERT(cap); 34 35 cap->support_alarm = driver_capabilities.support_alarm; 36 cap->support_callback = driver_capabilities.support_callback; 37 38 return SEDI_DRIVER_OK; 39 } 40 sedi_rtc_init(void)41int sedi_rtc_init(void) 42 { 43 return SEDI_DRIVER_OK; 44 } 45 sedi_rtc_uninit(void)46int sedi_rtc_uninit(void) 47 { 48 return SEDI_DRIVER_OK; 49 } 50 sedi_rtc_set_power(sedi_power_state_t state)51int sedi_rtc_set_power(sedi_power_state_t state) 52 { 53 PARAM_UNUSED(state); 54 55 return SEDI_DRIVER_OK; 56 } 57 sedi_rtc_get(void)58uint64_t sedi_rtc_get(void) 59 { 60 uint32_t lower; 61 uint32_t upper; 62 63 do { 64 upper = read32(SEDI_RTC_COUNTER1); 65 lower = read32(SEDI_RTC_COUNTER0); 66 } while (upper != read32(SEDI_RTC_COUNTER1)); 67 68 return ((uint64_t)upper << 32U) | lower; 69 } 70 sedi_rtc_get_us(void)71uint64_t sedi_rtc_get_us(void) 72 { 73 uint64_t rtc = sedi_rtc_get(); 74 75 return sedi_rtc_to_us(rtc); 76 } 77