1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef NRFS_DVFS_H
8 #define NRFS_DVFS_H
9 
10 #include <internal/services/nrfs_dvfs.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /** @brief Dynamic Voltage and Frequency Scaling service event types. */
17 typedef enum __NRFS_PACKED {
18 	NRFS_DVFS_EVT_REJECT, /** General purpose event for rejected requests. */
19 	NRFS_DVFS_EVT_INIT_PREPARATION, /** ABB Oppoint has been set correctly. Ready for second step of initialization sequence. */
20 	NRFS_DVFS_EVT_INIT_DONE, /** ABB Oppoint has been set correctly. Initialization sequence completed. */
21 	NRFS_DVFS_EVT_OPPOINT_REQ_CONFIRMED, /** Request for operating frequency change has been registered. Please standby. */
22 	NRFS_DVFS_EVT_OPPOINT_SCALING_PREPARE, /** Prepare for voltage scaling. Awaiting the @p nrfs_dvfs_ready_to_scale response. */
23 	NRFS_DVFS_EVT_OPPOINT_SCALING_DONE, /** Voltage scaling done, new oppoint can be applied. */
24 } nrfs_dvfs_evt_type_t;
25 
26 /** @brief Dynamic Voltage and Frequency Scaling service event. */
27 typedef struct {
28 	nrfs_dvfs_evt_type_t type; /** Event type. */
29 	enum dvfs_frequency_setting freq;		   /** Maximum allowed HSFLL frequency oppoint.
30                                     *  For the @p NRFS_DVFS_EVT_OPPOINT_SCALING_PREPARE
31                                     *  this oppoint dictates, which oppoint needs to be prepared.  */
32 } nrfs_dvfs_evt_t;
33 
34 /** @brief Dynamic Voltage and Frequency Scaling service event handler type. */
35 typedef void (*nrfs_dvfs_evt_handler_t)(nrfs_dvfs_evt_t const * p_evt, void * context);
36 
37 /**
38  * @brief Function for initializing the Dynamic Voltage and Frequency Scaling service.
39  *
40  * @param[in] handler Function called as a response to the request.
41  *
42  * @retval NRFS_SUCCESS           Service initialized successfully.
43  * @retval NRFS_ERR_INVALID_STATE Service was already initialized.
44  */
45 nrfs_err_t nrfs_dvfs_init(nrfs_dvfs_evt_handler_t handler);
46 
47 /**
48  * @brief Function for uninitializing the Dynamic Voltage and Frequency Scaling service.
49  *
50  * @warning Notifications from previous requests are dropped after service uninitialization.
51  */
52 void nrfs_dvfs_uninit(void);
53 
54 /**
55  * @brief Function for requesting the first step of the init sequence. This will trigger proper ABB Oppoint setting.
56  *
57  * @param[in] p_context Opaque user data that will be passed to registered callback.
58  *
59  * @retval NRFS_SUCCESS           Request sent successfully.
60  * @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
61  * @retval NRFS_ERR_IPC           Backend returned error during request sending.
62  */
63 nrfs_err_t nrfs_dvfs_init_prepare_request(void * p_context);
64 
65 /**
66  * @brief Function for requesting the second step of the init sequence. This will trigger proper ABB Oppoint setting.
67  *
68  * @param[in] p_context Opaque user data that will be passed to registered callback.
69  *
70  * @retval NRFS_SUCCESS           Request sent successfully.
71  * @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
72  * @retval NRFS_ERR_IPC           Backend returned error during request sending.
73  */
74 nrfs_err_t nrfs_dvfs_init_complete_request(void * p_context);
75 
76 /**
77  * @brief Function for requesting an operating frequency change.
78  * @note The @p target_freq requirement might not be met by the system
79  * until the NRFS_DVFS_EVT_OPPOINT_REQ_CONFIRMED response is triggered.
80  *
81  * @param[in] target_freq  Minimal required frequency oppoint
82  * @param[in] p_context    Opaque user data that will be passed to registered callback.
83  *
84  * @retval NRFS_SUCCESS           Request sent successfully.
85  * @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
86  * @retval NRFS_ERR_IPC           Backend returned error during request sending.
87  */
88 nrfs_err_t nrfs_dvfs_oppoint_request(enum dvfs_frequency_setting target_freq, void * p_context);
89 
90 /**
91  * @brief Function for requesting an operating frequency change.
92  * @note The response @p NRFS_DVFS_EVT_OPPOINT_REQ_CONFIRMED will not be triggered.
93  *
94  * @param[in] target_freq  Minimal required frequency oppoint
95  * @param[in] p_context    Opaque user data that will be passed to registered callback.
96  *
97  * @retval NRFS_SUCCESS           Request sent successfully.
98  * @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
99  * @retval NRFS_ERR_IPC           Backend returned error during request sending.
100  */
101 nrfs_err_t nrfs_dvfs_oppoint_request_no_rsp(enum dvfs_frequency_setting target_freq, void * p_context);
102 
103 /**
104  * @brief Function for notifying that the requested oppoint has been prepared.
105  *
106  * @param[in] p_context    Opaque user data that will be passed to registered callback.
107  *
108  * @retval NRFS_SUCCESS           Request sent successfully.
109  * @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
110  * @retval NRFS_ERR_IPC           Backend returned error during request sending.
111  */
112 nrfs_err_t nrfs_dvfs_ready_to_scale(void * p_context);
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* NRFS_DVFS_H */
119