1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#ifndef __DAL_CLK_MGR_H__
27#define __DAL_CLK_MGR_H__
28
29#include "dc.h"
30#include "dm_pp_smu.h"
31
32#define DCN_MINIMUM_DISPCLK_Khz 100000
33#define DCN_MINIMUM_DPPCLK_Khz 100000
34
35
36#define DDR4_DRAM_WIDTH 64
37#define WM_A 0
38#define WM_B 1
39#define WM_C 2
40#define WM_D 3
41#define WM_SET_COUNT 4
42
43#define DCN_MINIMUM_DISPCLK_Khz 100000
44#define DCN_MINIMUM_DPPCLK_Khz 100000
45
46#if defined(CONFIG_DRM_AMD_DC_DCN3_0)
47struct dcn3_clk_internal {
48 int dummy;
49
50
51
52
53
54
55
56
57
58
59
60
61
62};
63
64#endif
65
66
67#define MAX_NUM_DPM_LVL 8
68#define WM_SET_COUNT 4
69
70
71struct clk_limit_table_entry {
72 unsigned int voltage;
73 unsigned int dcfclk_mhz;
74 unsigned int fclk_mhz;
75 unsigned int memclk_mhz;
76 unsigned int socclk_mhz;
77#ifdef CONFIG_DRM_AMD_DC_DCN3_0
78 unsigned int dtbclk_mhz;
79 unsigned int dispclk_mhz;
80 unsigned int dppclk_mhz;
81 unsigned int phyclk_mhz;
82#endif
83};
84
85
86struct clk_limit_table {
87 struct clk_limit_table_entry entries[MAX_NUM_DPM_LVL];
88 unsigned int num_entries;
89};
90
91struct wm_range_table_entry {
92 unsigned int wm_inst;
93 unsigned int wm_type;
94 double pstate_latency_us;
95 double sr_exit_time_us;
96 double sr_enter_plus_exit_time_us;
97 bool valid;
98};
99
100#ifdef CONFIG_DRM_AMD_DC_DCN3_0
101
102struct nv_wm_range_entry {
103 bool valid;
104
105 struct {
106 uint8_t wm_type;
107 uint16_t min_dcfclk;
108 uint16_t max_dcfclk;
109 uint16_t min_uclk;
110 uint16_t max_uclk;
111 } pmfw_breakdown;
112
113 struct {
114 double pstate_latency_us;
115 double sr_exit_time_us;
116 double sr_enter_plus_exit_time_us;
117 } dml_input;
118};
119#endif
120
121struct clk_log_info {
122 bool enabled;
123 char *pBuf;
124 unsigned int bufSize;
125 unsigned int *sum_chars_printed;
126};
127
128struct clk_state_registers_and_bypass {
129 uint32_t dcfclk;
130 uint32_t dcf_deep_sleep_divider;
131 uint32_t dcf_deep_sleep_allow;
132 uint32_t dprefclk;
133 uint32_t dispclk;
134 uint32_t dppclk;
135
136 uint32_t dppclk_bypass;
137 uint32_t dcfclk_bypass;
138 uint32_t dprefclk_bypass;
139 uint32_t dispclk_bypass;
140};
141
142struct rv1_clk_internal {
143 uint32_t CLK0_CLK8_CURRENT_CNT;
144 uint32_t CLK0_CLK8_DS_CNTL;
145 uint32_t CLK0_CLK8_ALLOW_DS;
146 uint32_t CLK0_CLK10_CURRENT_CNT;
147 uint32_t CLK0_CLK11_CURRENT_CNT;
148
149 uint32_t CLK0_CLK8_BYPASS_CNTL;
150 uint32_t CLK0_CLK10_BYPASS_CNTL;
151 uint32_t CLK0_CLK11_BYPASS_CNTL;
152};
153
154struct rn_clk_internal {
155 uint32_t CLK1_CLK0_CURRENT_CNT;
156 uint32_t CLK1_CLK1_CURRENT_CNT;
157 uint32_t CLK1_CLK2_CURRENT_CNT;
158 uint32_t CLK1_CLK3_CURRENT_CNT;
159 uint32_t CLK1_CLK3_DS_CNTL;
160 uint32_t CLK1_CLK3_ALLOW_DS;
161
162 uint32_t CLK1_CLK0_BYPASS_CNTL;
163 uint32_t CLK1_CLK1_BYPASS_CNTL;
164 uint32_t CLK1_CLK2_BYPASS_CNTL;
165 uint32_t CLK1_CLK3_BYPASS_CNTL;
166
167};
168
169
170struct clk_state_registers {
171 uint32_t CLK0_CLK8_CURRENT_CNT;
172 uint32_t CLK0_CLK8_DS_CNTL;
173 uint32_t CLK0_CLK8_ALLOW_DS;
174 uint32_t CLK0_CLK10_CURRENT_CNT;
175 uint32_t CLK0_CLK11_CURRENT_CNT;
176};
177
178
179struct clk_bypass {
180 uint32_t dcfclk_bypass;
181 uint32_t dispclk_pypass;
182 uint32_t dprefclk_bypass;
183};
184
185
186
187
188
189
190struct wm_table {
191#ifdef CONFIG_DRM_AMD_DC_DCN3_0
192 union {
193 struct nv_wm_range_entry nv_entries[WM_SET_COUNT];
194#endif
195 struct wm_range_table_entry entries[WM_SET_COUNT];
196#ifdef CONFIG_DRM_AMD_DC_DCN3_0
197 };
198#endif
199};
200
201struct dummy_pstate_entry {
202 unsigned int dram_speed_mts;
203 unsigned int dummy_pstate_latency_us;
204};
205
206struct clk_bw_params {
207 unsigned int vram_type;
208 unsigned int num_channels;
209 struct clk_limit_table clk_table;
210 struct wm_table wm_table;
211 struct dummy_pstate_entry dummy_pstate_table[4];
212};
213
214
215struct clk_states {
216 uint32_t dprefclk_khz;
217};
218
219struct clk_mgr_funcs {
220
221
222
223
224
225
226
227 void (*update_clocks)(struct clk_mgr *clk_mgr,
228 struct dc_state *context,
229 bool safe_to_lower);
230
231 int (*get_dp_ref_clk_frequency)(struct clk_mgr *clk_mgr);
232
233 void (*set_low_power_state)(struct clk_mgr *clk_mgr);
234
235 void (*init_clocks)(struct clk_mgr *clk_mgr);
236
237 void (*enable_pme_wa) (struct clk_mgr *clk_mgr);
238 void (*get_clock)(struct clk_mgr *clk_mgr,
239 struct dc_state *context,
240 enum dc_clock_type clock_type,
241 struct dc_clock_config *clock_cfg);
242
243 bool (*are_clock_states_equal) (struct dc_clocks *a,
244 struct dc_clocks *b);
245 void (*notify_wm_ranges)(struct clk_mgr *clk_mgr);
246
247
248 void (*notify_link_rate_change)(struct clk_mgr *clk_mgr, struct dc_link *link);
249#ifdef CONFIG_DRM_AMD_DC_DCN3_0
250
251
252
253
254
255 void (*set_hard_min_memclk)(struct clk_mgr *clk_mgr, bool current_mode);
256
257
258 void (*set_hard_max_memclk)(struct clk_mgr *clk_mgr);
259
260
261 void (*get_memclk_states_from_smu)(struct clk_mgr *clk_mgr);
262#endif
263};
264
265struct clk_mgr {
266 struct dc_context *ctx;
267 struct clk_mgr_funcs *funcs;
268 struct dc_clocks clks;
269 bool psr_allow_active_cache;
270#ifdef CONFIG_DRM_AMD_DC_DCN3_0
271 bool force_smu_not_present;
272#endif
273 int dprefclk_khz;
274 int dentist_vco_freq_khz;
275 struct clk_state_registers_and_bypass boot_snapshot;
276 struct clk_bw_params *bw_params;
277 struct pp_smu_wm_range_sets ranges;
278};
279
280
281struct dccg;
282
283struct clk_mgr *dc_clk_mgr_create(struct dc_context *ctx, struct pp_smu_funcs *pp_smu, struct dccg *dccg);
284
285void dc_destroy_clk_mgr(struct clk_mgr *clk_mgr);
286
287void clk_mgr_exit_optimized_pwr_state(const struct dc *dc, struct clk_mgr *clk_mgr);
288
289void clk_mgr_optimize_pwr_state(const struct dc *dc, struct clk_mgr *clk_mgr);
290
291#endif
292