1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (C) 2022, Microchip 4 */ 5 #ifndef __PTA_RTC_H 6 #define __PTA_RTC_H 7 8 #include <tee_api_types.h> 9 10 #define PTA_RTC_UUID { 0xf389f8c8, 0x845f, 0x496c, \ 11 { 0x8b, 0xbe, 0xd6, 0x4b, 0xd2, 0x4c, 0x92, 0xfd } } 12 13 #define PTA_RTC_INFO_VERSION 0x1 14 15 /* 16 * RTC provides set/get offset and thus command PTA_CMD_RTC_GET_OFFSET and 17 * PTA_CMD_RTC_SET_OFFSET might be called 18 */ 19 #define PTA_RTC_FEATURE_CORRECTION BIT(0) 20 21 /* 22 * RTC provides set/read/enable/wait alarm and thus 23 * commands: 24 * PTA_CMD_RTC_SET_ALARM, PTA_CMD_RTC_READ_ALARM, 25 * PTA_CMD_RTC_WAIT_ALARM, PTA_CMD_RTC_ENABLE_ALARM 26 * might be called 27 */ 28 #define PTA_RTC_FEATURE_ALARM BIT(1) 29 30 /* 31 * Command PTA_CMD_RTC_SET_WAKE_ALARM_STATUS can be used to enable/disable the 32 * alarm wake-up capability. 33 */ 34 #define PTA_RTC_FEATURE_WAKEUP_ALARM BIT(2) 35 36 struct pta_rtc_time { 37 uint32_t tm_sec; 38 uint32_t tm_min; 39 uint32_t tm_hour; 40 uint32_t tm_mday; 41 uint32_t tm_mon; 42 uint32_t tm_year; 43 uint32_t tm_wday; 44 }; 45 46 /* 47 * struct pta_rtc_alarm - State of an RTC alarm 48 * @enabled - 1 if alarm is enabled, 0 if disabled 49 * @pending - 1 if alarm event is pending, 0 if not 50 * @time: Alarm elapsure time 51 */ 52 struct pta_rtc_alarm { 53 uint8_t enabled; 54 uint8_t pending; 55 struct pta_rtc_time time; 56 }; 57 58 /* 59 * struct pta_rtc_info - RTC service information 60 * @version - 1st 64bit cell, version of the structure: PTA_RTC_INFO_VERSION 61 * @features - 64bit flag mask related to PTA_RTC_FEATURE_* 62 * @range_min - Minima time reference the RTC can be programmed to 63 * @range_max - Maxima time reference the RTC can reach 64 */ 65 struct pta_rtc_info { 66 uint64_t version; 67 uint64_t features; 68 struct pta_rtc_time range_min; 69 struct pta_rtc_time range_max; 70 }; 71 72 /* 73 * PTA_CMD_RTC_GET_INFO - Get RTC information 74 * 75 * [out] memref[0] RTC buffer memory reference containing a struct 76 * pta_rtc_info 77 * 78 * Return codes: 79 * TEE_SUCCESS - Invoke command success 80 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 81 */ 82 #define PTA_CMD_RTC_GET_INFO 0x0 83 84 /* 85 * PTA_CMD_RTC_GET_TIME - Get time from RTC 86 * 87 * [out] memref[0] RTC buffer memory reference containing a struct 88 * pta_rtc_time 89 * 90 * Return codes: 91 * TEE_SUCCESS - Invoke command success 92 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 93 */ 94 #define PTA_CMD_RTC_GET_TIME 0x1 95 96 /* 97 * PTA_CMD_RTC_SET_TIME - Set time from RTC 98 * 99 * [in] memref[0] RTC buffer memory reference containing a struct 100 * pta_rtc_time to be used as RTC time 101 * 102 * Return codes: 103 * TEE_SUCCESS - Invoke command success 104 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 105 */ 106 #define PTA_CMD_RTC_SET_TIME 0x2 107 108 /* 109 * PTA_CMD_RTC_GET_OFFSET - Get RTC offset 110 * 111 * [out] value[0].a RTC offset (signed 32bit value) 112 * 113 * Return codes: 114 * TEE_SUCCESS - Invoke command success 115 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 116 */ 117 #define PTA_CMD_RTC_GET_OFFSET 0x3 118 119 /* 120 * PTA_CMD_RTC_SET_OFFSET - Set RTC offset 121 * 122 * [in] value[0].a RTC offset to be set (signed 32bit value) 123 * 124 * Return codes: 125 * TEE_SUCCESS - Invoke command success 126 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 127 */ 128 #define PTA_CMD_RTC_SET_OFFSET 0x4 129 130 /* 131 * PTA_CMD_RTC_READ_ALARM - Read RTC alarm 132 * 133 * [out] memref[0] RTC buffer memory reference containing a struct 134 * pta_rtc_alarm 135 * 136 * Return codes: 137 * TEE_SUCCESS - Invoke command success 138 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 139 */ 140 #define PTA_CMD_RTC_READ_ALARM 0x5 141 142 /* 143 * PTA_CMD_RTC_SET_ALARM - Set RTC alarm 144 * 145 * [in] memref[0] RTC buffer memory reference containing a struct 146 * pta_rtc_alarm to be used as RTC alarm 147 * 148 * Return codes: 149 * TEE_SUCCESS - Invoke command success 150 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 151 */ 152 #define PTA_CMD_RTC_SET_ALARM 0x6 153 154 /* 155 * PTA_CMD_RTC_ENABLE_ALARM - Enable Alarm 156 * 157 * [in] value[0].a RTC IRQ flag (uint32_t), 0 to disable the alarm, 1 to 158 * enable 159 * 160 * Return codes: 161 * TEE_SUCCESS - Invoke command success 162 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 163 */ 164 #define PTA_CMD_RTC_ENABLE_ALARM 0x7 165 166 /* 167 * PTA_CMD_RTC_WAIT_ALARM - Get alarm event 168 * 169 * [out] value[0].a RTC wait alarm return status (uint32_t): 170 * - 0: No alarm event 171 * - 1: Alarm event occurred 172 * - 2: Alarm event canceled 173 * 174 * Return codes: 175 * TEE_SUCCESS - Invoke command success 176 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 177 */ 178 #define PTA_CMD_RTC_WAIT_ALARM 0x8 179 180 /* 181 * PTA_CMD_RTC_CANCEL_WAIT_ALARM - Cancel wait for alarm event 182 * 183 * Return codes: 184 * TEE_SUCCESS - Invoke command success 185 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 186 */ 187 #define PTA_CMD_RTC_CANCEL_WAIT_ALARM 0x9 188 189 /* 190 * PTA_CMD_RTC_SET_WAKE_ALARM_STATUS - Set RTC wake alarm status flag 191 * 192 * [in] value[0].a RTC IRQ wake alarm flag (uint32_t), 0 to disable the wake 193 * up capability, 1 to enable. 194 * 195 * Return codes: 196 * TEE_SUCCESS - Invoke command success 197 * TEE_ERROR_BAD_PARAMETERS - Incorrect input param 198 */ 199 #define PTA_CMD_RTC_SET_WAKE_ALARM_STATUS 0xA 200 201 #endif /* __PTA_RTC_H */ 202