1 /*
2 * Copyright 2020 GreenWaves Technologies
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 */
18
19 #ifndef HAL_INCLUDE_HAL_FLL_PI_H_
20 #define HAL_INCLUDE_HAL_FLL_PI_H_
21
22 //#include "pmsis/targets/target.h"
23 #include "core-v-mcu-target.h"
24
25 /*!
26 * @addtogroup fll
27 * @{
28 */
29
30 #define DCDC_OPER_POINTS (4)
31
32 #define DCDC_DEFAULT_NV (1200)
33 #define DCDC_DEFAULT_MV (1200)
34 #define DCDC_DEFAULT_LV (1000)
35 #define DCDC_DEFAULT_RET (800)
36 #define DCDC_RANGE (5)
37 #define DCDC_RANGE_MASK (0x1F)
38 #define DCDC_BASE_VALUE (550)
39 #define DCDC_STEP (50)
40
41 #define MAX_DCDC_VARIATION ((int32_t) (0.1*32767))
42
43 /*******************************************************************************
44 * Definitions
45 ******************************************************************************/
46 #define FLL_LV_MAX_FREQUENCY 150000000
47 #define FLL_NV_MAX_FREQUENCY 250000000
48 #define FLL_SOC_MIN_FREQUENCY 150000000
49 #define FLL_SOC_MAX_FREQUENCY 250000000
50 #define FLL_CLUSTER_MIN_FREQUENCY 87000000
51 #define FLL_CLUSTER_MAX_FREQUENCY 175000000
52
53 #define FLL_SOC_FV_SLOPE ((FLL_SOC_MAX_FREQUENCY - FLL_SOC_MIN_FREQUENCY) / (DCDC_DEFAULT_NV - DCDC_DEFAULT_LV))
54 #define FLL_CLUSTER_FV_SLOPE ((FLL_CLUSTER_MAX_FREQUENCY - FLL_CLUSTER_MIN_FREQUENCY) / (DCDC_DEFAULT_NV - DCDC_DEFAULT_LV))
55
56 typedef enum _fll_type
57 {
58 FLL_SOC = 0,
59 FLL_PERI = 1,
60 FLL_CLUSTER = 2
61 } fll_type_t;
62
63 /*******************************************************************************
64 * APIs
65 ******************************************************************************/
66 #if defined(__cplusplus)
67 extern "C" {
68 #endif /* __cplusplus */
69
70 /*!
71 * @brief Initialize one FLL.
72 *
73 * @param which_fll SoC's or Cluster's fll.
74 * @param ret_state Retention state.
75 *
76 * @note .
77 */
78 void pi_fll_init(fll_type_t which_fll, uint32_t ret_state);
79
80 /*!
81 * @brief Deinitalize one FLL.
82 *
83 * @param which_fll SoC's or Cluster's fll.
84 *
85 * @note .
86 */
87 void pi_fll_deinit(fll_type_t which_fll);
88
89 /*!
90 * @brief Clean all FLL configuration.
91 *
92 * @note .
93 */
94 void pi_fll_clear();
95
96
97 /*!
98 * @brief Set specific FLL to wanted frequency.
99 *
100 * @param which_fll SoC's or Cluster's fll.
101 * @param frequency The frequency value to set.
102 * @param check Check frequency.
103 *
104 * @note .
105 * @return check result of frequency.
106 */
107 int pi_fll_set_frequency(fll_type_t which_fll, uint32_t frequency, int check);
108
109 /*!
110 * @brief Get specific FLL's frequency.
111 *
112 * @param which_fll SoC's or Cluster's fll.
113 *
114 * @note .
115 * @return frequency value.
116 */
117 int pi_fll_get_frequency(fll_type_t which_fll, uint8_t real);
118
119 /*!
120 * @brief Calculate FC SOC domain's max frequency with certain voltage
121 *
122 * @param voltage Given voltage
123 *
124 * @return max frquency.
125 */
pi_fll_soc_max_freq_at_V(int voltage)126 static inline int pi_fll_soc_max_freq_at_V(int voltage)
127 {
128 return (FLL_SOC_MIN_FREQUENCY + (voltage - DCDC_DEFAULT_LV) * FLL_SOC_FV_SLOPE);
129 }
130
131 /*!
132 * @brief Calculate cluster domain's max frequency with certain voltage
133 *
134 * @param voltage Given voltage
135 *
136 * @return max frquency.
137 */
pi_fll_cluster_max_freq_at_V(int voltage)138 static inline int pi_fll_cluster_max_freq_at_V(int voltage)
139 {
140 return (FLL_CLUSTER_MIN_FREQUENCY + (voltage - DCDC_DEFAULT_LV) * FLL_CLUSTER_FV_SLOPE);
141 }
142
143 #if defined(__cplusplus)
144 }
145 #endif /* __cplusplus */
146
147 /* @} */
148
149
150
151 #endif /* HAL_INCLUDE_HAL_FLL_PI_H_ */
152