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