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__
31 #define DCN_MINIMUM_DISPCLK_Khz 100000
32 #define DCN_MINIMUM_DPPCLK_Khz 100000
34 #ifdef CONFIG_DRM_AMD_DC_DCN2_1
36 #define DDR4_DRAM_WIDTH 64
41 #define WM_SET_COUNT 4
44 #define DCN_MINIMUM_DISPCLK_Khz 100000
45 #define DCN_MINIMUM_DPPCLK_Khz 100000
47 #ifdef CONFIG_DRM_AMD_DC_DCN2_1
48 /* Will these bw structures be ASIC specific? */
50 #define MAX_NUM_DPM_LVL 8
51 #define WM_SET_COUNT 4
54 struct clk_limit_table_entry {
55 unsigned int voltage; /* milivolts withh 2 fractional bits */
56 unsigned int dcfclk_mhz;
57 unsigned int fclk_mhz;
58 unsigned int memclk_mhz;
59 unsigned int socclk_mhz;
62 /* This table is contiguous */
63 struct clk_limit_table {
64 struct clk_limit_table_entry entries[MAX_NUM_DPM_LVL];
65 unsigned int num_entries;
68 struct wm_range_table_entry {
71 double pstate_latency_us;
72 double sr_exit_time_us;
73 double sr_enter_plus_exit_time_us;
82 unsigned int *sum_chars_printed;
85 struct clk_state_registers_and_bypass {
87 uint32_t dcf_deep_sleep_divider;
88 uint32_t dcf_deep_sleep_allow;
93 uint32_t dppclk_bypass;
94 uint32_t dcfclk_bypass;
95 uint32_t dprefclk_bypass;
96 uint32_t dispclk_bypass;
99 struct rv1_clk_internal {
100 uint32_t CLK0_CLK8_CURRENT_CNT; //dcfclk
101 uint32_t CLK0_CLK8_DS_CNTL; //dcf_deep_sleep_divider
102 uint32_t CLK0_CLK8_ALLOW_DS; //dcf_deep_sleep_allow
103 uint32_t CLK0_CLK10_CURRENT_CNT; //dprefclk
104 uint32_t CLK0_CLK11_CURRENT_CNT; //dispclk
106 uint32_t CLK0_CLK8_BYPASS_CNTL; //dcfclk bypass
107 uint32_t CLK0_CLK10_BYPASS_CNTL; //dprefclk bypass
108 uint32_t CLK0_CLK11_BYPASS_CNTL; //dispclk bypass
111 struct rn_clk_internal {
112 uint32_t CLK1_CLK0_CURRENT_CNT; //dispclk
113 uint32_t CLK1_CLK1_CURRENT_CNT; //dppclk
114 uint32_t CLK1_CLK2_CURRENT_CNT; //dprefclk
115 uint32_t CLK1_CLK3_CURRENT_CNT; //dcfclk
116 uint32_t CLK1_CLK3_DS_CNTL; //dcf_deep_sleep_divider
117 uint32_t CLK1_CLK3_ALLOW_DS; //dcf_deep_sleep_allow
119 uint32_t CLK1_CLK0_BYPASS_CNTL; //dispclk bypass
120 uint32_t CLK1_CLK1_BYPASS_CNTL; //dppclk bypass
121 uint32_t CLK1_CLK2_BYPASS_CNTL; //dprefclk bypass
122 uint32_t CLK1_CLK3_BYPASS_CNTL; //dcfclk bypass
126 /* For dtn logging and debugging */
127 struct clk_state_registers {
128 uint32_t CLK0_CLK8_CURRENT_CNT; //dcfclk
129 uint32_t CLK0_CLK8_DS_CNTL; //dcf_deep_sleep_divider
130 uint32_t CLK0_CLK8_ALLOW_DS; //dcf_deep_sleep_allow
131 uint32_t CLK0_CLK10_CURRENT_CNT; //dprefclk
132 uint32_t CLK0_CLK11_CURRENT_CNT; //dispclk
135 /* TODO: combine this with the above */
137 uint32_t dcfclk_bypass;
138 uint32_t dispclk_pypass;
139 uint32_t dprefclk_bypass;
142 * This table is not contiguous, can have holes, each
143 * entry correspond to one set of WM. For example if
144 * we have 2 DPM and LPDDR, we will WM set A, B and
145 * D occupied, C will be emptry.
148 struct wm_range_table_entry entries[WM_SET_COUNT];
151 struct clk_bw_params {
152 unsigned int vram_type;
153 unsigned int num_channels;
154 struct clk_limit_table clk_table;
155 struct wm_table wm_table;
158 /* Public interfaces */
161 uint32_t dprefclk_khz;
164 struct clk_mgr_funcs {
166 * This function should set new clocks based on the input "safe_to_lower".
167 * If safe_to_lower == false, then only clocks which are to be increased
169 * If safe_to_lower == true, then only clocks which are to be decreased
172 void (*update_clocks)(struct clk_mgr *clk_mgr,
173 struct dc_state *context,
176 int (*get_dp_ref_clk_frequency)(struct clk_mgr *clk_mgr);
178 void (*init_clocks)(struct clk_mgr *clk_mgr);
180 void (*enable_pme_wa) (struct clk_mgr *clk_mgr);
181 void (*get_clock)(struct clk_mgr *clk_mgr,
182 struct dc_state *context,
183 enum dc_clock_type clock_type,
184 struct dc_clock_config *clock_cfg);
186 bool (*are_clock_states_equal) (struct dc_clocks *a,
187 struct dc_clocks *b);
188 void (*notify_wm_ranges)(struct clk_mgr *clk_mgr);
192 struct dc_context *ctx;
193 struct clk_mgr_funcs *funcs;
194 struct dc_clocks clks;
195 bool psr_allow_active_cache;
196 int dprefclk_khz; // Used by program pixel clock in clock source funcs, need to figureout where this goes
197 int dentist_vco_freq_khz;
198 #ifdef CONFIG_DRM_AMD_DC_DCN2_1
199 struct clk_bw_params *bw_params;
203 /* forward declarations */
206 struct clk_mgr *dc_clk_mgr_create(struct dc_context *ctx, struct pp_smu_funcs *pp_smu, struct dccg *dccg);
208 void dc_destroy_clk_mgr(struct clk_mgr *clk_mgr);
210 void clk_mgr_exit_optimized_pwr_state(const struct dc *dc, struct clk_mgr *clk_mgr);
212 void clk_mgr_optimize_pwr_state(const struct dc *dc, struct clk_mgr *clk_mgr);
214 #endif /* __DAL_CLK_MGR_H__ */