2 * Copyright 2012-16 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #ifndef __DAL_CLK_MGR_H__
27 #define __DAL_CLK_MGR_H__
30 #include "dm_pp_smu.h"
32 #define DCN_MINIMUM_DISPCLK_Khz 100000
33 #define DCN_MINIMUM_DPPCLK_Khz 100000
36 #define DDR4_DRAM_WIDTH 64
41 #define WM_SET_COUNT 4
43 #define DCN_MINIMUM_DISPCLK_Khz 100000
44 #define DCN_MINIMUM_DPPCLK_Khz 100000
46 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
47 struct dcn3_clk_internal {
50 uint32_t CLK1_CLK0_CURRENT_CNT; //dispclk
51 uint32_t CLK1_CLK1_CURRENT_CNT; //dppclk
52 uint32_t CLK1_CLK2_CURRENT_CNT; //dprefclk
53 uint32_t CLK1_CLK3_CURRENT_CNT; //dcfclk
54 uint32_t CLK1_CLK3_DS_CNTL; //dcf_deep_sleep_divider
55 uint32_t CLK1_CLK3_ALLOW_DS; //dcf_deep_sleep_allow
57 uint32_t CLK1_CLK0_BYPASS_CNTL; //dispclk bypass
58 uint32_t CLK1_CLK1_BYPASS_CNTL; //dppclk bypass
59 uint32_t CLK1_CLK2_BYPASS_CNTL; //dprefclk bypass
60 uint32_t CLK1_CLK3_BYPASS_CNTL; //dcfclk bypass
65 /* Will these bw structures be ASIC specific? */
67 #define MAX_NUM_DPM_LVL 8
68 #define WM_SET_COUNT 4
71 struct clk_limit_table_entry {
72 unsigned int voltage; /* milivolts withh 2 fractional bits */
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;
85 /* This table is contiguous */
86 struct clk_limit_table {
87 struct clk_limit_table_entry entries[MAX_NUM_DPM_LVL];
88 unsigned int num_entries;
91 struct wm_range_table_entry {
94 double pstate_latency_us;
95 double sr_exit_time_us;
96 double sr_enter_plus_exit_time_us;
100 #ifdef CONFIG_DRM_AMD_DC_DCN3_0
102 struct nv_wm_range_entry {
114 double pstate_latency_us;
115 double sr_exit_time_us;
116 double sr_enter_plus_exit_time_us;
121 struct clk_log_info {
124 unsigned int bufSize;
125 unsigned int *sum_chars_printed;
128 struct clk_state_registers_and_bypass {
130 uint32_t dcf_deep_sleep_divider;
131 uint32_t dcf_deep_sleep_allow;
136 uint32_t dppclk_bypass;
137 uint32_t dcfclk_bypass;
138 uint32_t dprefclk_bypass;
139 uint32_t dispclk_bypass;
142 struct rv1_clk_internal {
143 uint32_t CLK0_CLK8_CURRENT_CNT; //dcfclk
144 uint32_t CLK0_CLK8_DS_CNTL; //dcf_deep_sleep_divider
145 uint32_t CLK0_CLK8_ALLOW_DS; //dcf_deep_sleep_allow
146 uint32_t CLK0_CLK10_CURRENT_CNT; //dprefclk
147 uint32_t CLK0_CLK11_CURRENT_CNT; //dispclk
149 uint32_t CLK0_CLK8_BYPASS_CNTL; //dcfclk bypass
150 uint32_t CLK0_CLK10_BYPASS_CNTL; //dprefclk bypass
151 uint32_t CLK0_CLK11_BYPASS_CNTL; //dispclk bypass
154 struct rn_clk_internal {
155 uint32_t CLK1_CLK0_CURRENT_CNT; //dispclk
156 uint32_t CLK1_CLK1_CURRENT_CNT; //dppclk
157 uint32_t CLK1_CLK2_CURRENT_CNT; //dprefclk
158 uint32_t CLK1_CLK3_CURRENT_CNT; //dcfclk
159 uint32_t CLK1_CLK3_DS_CNTL; //dcf_deep_sleep_divider
160 uint32_t CLK1_CLK3_ALLOW_DS; //dcf_deep_sleep_allow
162 uint32_t CLK1_CLK0_BYPASS_CNTL; //dispclk bypass
163 uint32_t CLK1_CLK1_BYPASS_CNTL; //dppclk bypass
164 uint32_t CLK1_CLK2_BYPASS_CNTL; //dprefclk bypass
165 uint32_t CLK1_CLK3_BYPASS_CNTL; //dcfclk bypass
169 /* For dtn logging and debugging */
170 struct clk_state_registers {
171 uint32_t CLK0_CLK8_CURRENT_CNT; //dcfclk
172 uint32_t CLK0_CLK8_DS_CNTL; //dcf_deep_sleep_divider
173 uint32_t CLK0_CLK8_ALLOW_DS; //dcf_deep_sleep_allow
174 uint32_t CLK0_CLK10_CURRENT_CNT; //dprefclk
175 uint32_t CLK0_CLK11_CURRENT_CNT; //dispclk
178 /* TODO: combine this with the above */
180 uint32_t dcfclk_bypass;
181 uint32_t dispclk_pypass;
182 uint32_t dprefclk_bypass;
185 * This table is not contiguous, can have holes, each
186 * entry correspond to one set of WM. For example if
187 * we have 2 DPM and LPDDR, we will WM set A, B and
188 * D occupied, C will be emptry.
191 #ifdef CONFIG_DRM_AMD_DC_DCN3_0
193 struct nv_wm_range_entry nv_entries[WM_SET_COUNT];
195 struct wm_range_table_entry entries[WM_SET_COUNT];
196 #ifdef CONFIG_DRM_AMD_DC_DCN3_0
201 struct dummy_pstate_entry {
202 unsigned int dram_speed_mts;
203 unsigned int dummy_pstate_latency_us;
206 struct 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];
213 /* Public interfaces */
216 uint32_t dprefclk_khz;
219 struct clk_mgr_funcs {
221 * This function should set new clocks based on the input "safe_to_lower".
222 * If safe_to_lower == false, then only clocks which are to be increased
224 * If safe_to_lower == true, then only clocks which are to be decreased
227 void (*update_clocks)(struct clk_mgr *clk_mgr,
228 struct dc_state *context,
231 int (*get_dp_ref_clk_frequency)(struct clk_mgr *clk_mgr);
233 void (*init_clocks)(struct clk_mgr *clk_mgr);
235 void (*enable_pme_wa) (struct clk_mgr *clk_mgr);
236 void (*get_clock)(struct clk_mgr *clk_mgr,
237 struct dc_state *context,
238 enum dc_clock_type clock_type,
239 struct dc_clock_config *clock_cfg);
241 bool (*are_clock_states_equal) (struct dc_clocks *a,
242 struct dc_clocks *b);
243 void (*notify_wm_ranges)(struct clk_mgr *clk_mgr);
245 /* Notify clk_mgr of a change in link rate, update phyclk frequency if necessary */
246 void (*notify_link_rate_change)(struct clk_mgr *clk_mgr, struct dc_link *link);
247 #ifdef CONFIG_DRM_AMD_DC_DCN3_0
249 * Send message to PMFW to set hard min memclk frequency
250 * When current_mode = false, set DPM0
251 * When current_mode = true, set required clock for current mode
253 void (*set_hard_min_memclk)(struct clk_mgr *clk_mgr, bool current_mode);
255 /* Send message to PMFW to set hard max memclk frequency to highest DPM */
256 void (*set_hard_max_memclk)(struct clk_mgr *clk_mgr);
258 /* Get current memclk states from PMFW, update relevant structures */
259 void (*get_memclk_states_from_smu)(struct clk_mgr *clk_mgr);
264 struct dc_context *ctx;
265 struct clk_mgr_funcs *funcs;
266 struct dc_clocks clks;
267 bool psr_allow_active_cache;
268 #ifdef CONFIG_DRM_AMD_DC_DCN3_0
269 bool force_smu_not_present;
271 int dprefclk_khz; // Used by program pixel clock in clock source funcs, need to figureout where this goes
272 int dentist_vco_freq_khz;
273 struct clk_state_registers_and_bypass boot_snapshot;
274 struct clk_bw_params *bw_params;
275 struct pp_smu_wm_range_sets ranges;
278 /* forward declarations */
281 struct clk_mgr *dc_clk_mgr_create(struct dc_context *ctx, struct pp_smu_funcs *pp_smu, struct dccg *dccg);
283 void dc_destroy_clk_mgr(struct clk_mgr *clk_mgr);
285 void clk_mgr_exit_optimized_pwr_state(const struct dc *dc, struct clk_mgr *clk_mgr);
287 void clk_mgr_optimize_pwr_state(const struct dc *dc, struct clk_mgr *clk_mgr);
289 #endif /* __DAL_CLK_MGR_H__ */