19b93eb47SEric Yang /*
29b93eb47SEric Yang  * Copyright 2012-16 Advanced Micro Devices, Inc.
39b93eb47SEric Yang  *
49b93eb47SEric Yang  * Permission is hereby granted, free of charge, to any person obtaining a
59b93eb47SEric Yang  * copy of this software and associated documentation files (the "Software"),
69b93eb47SEric Yang  * to deal in the Software without restriction, including without limitation
79b93eb47SEric Yang  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
89b93eb47SEric Yang  * and/or sell copies of the Software, and to permit persons to whom the
99b93eb47SEric Yang  * Software is furnished to do so, subject to the following conditions:
109b93eb47SEric Yang  *
119b93eb47SEric Yang  * The above copyright notice and this permission notice shall be included in
129b93eb47SEric Yang  * all copies or substantial portions of the Software.
139b93eb47SEric Yang  *
149b93eb47SEric Yang  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
159b93eb47SEric Yang  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
169b93eb47SEric Yang  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
179b93eb47SEric Yang  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
189b93eb47SEric Yang  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
199b93eb47SEric Yang  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
209b93eb47SEric Yang  * OTHER DEALINGS IN THE SOFTWARE.
219b93eb47SEric Yang  *
229b93eb47SEric Yang  * Authors: AMD
239b93eb47SEric Yang  *
249b93eb47SEric Yang  */
259b93eb47SEric Yang 
269b93eb47SEric Yang #include "reg_helper.h"
279b93eb47SEric Yang #include "clk_mgr_internal.h"
289b93eb47SEric Yang #include "rv1_clk_mgr_clk.h"
299b93eb47SEric Yang 
309b93eb47SEric Yang #include "ip/Discovery/hwid.h"
319b93eb47SEric Yang #include "ip/Discovery/v1/ip_offset_1.h"
329b93eb47SEric Yang #include "ip/CLK/clk_10_0_default.h"
339b93eb47SEric Yang #include "ip/CLK/clk_10_0_offset.h"
349b93eb47SEric Yang #include "ip/CLK/clk_10_0_reg.h"
359b93eb47SEric Yang #include "ip/CLK/clk_10_0_sh_mask.h"
369b93eb47SEric Yang 
379b93eb47SEric Yang #include "dce100/dce_clk_mgr.h"
389b93eb47SEric Yang 
399b93eb47SEric Yang #define CLK_BASE_INNER(inst) \
409b93eb47SEric Yang 	CLK_BASE__INST ## inst ## _SEG0
419b93eb47SEric Yang 
429b93eb47SEric Yang 
439b93eb47SEric Yang #define CLK_REG(reg_name, block, inst)\
449b93eb47SEric Yang 	CLK_BASE(mm ## block ## _ ## inst ## _ ## reg_name ## _BASE_IDX) + \
459b93eb47SEric Yang 					mm ## block ## _ ## inst ## _ ## reg_name
469b93eb47SEric Yang 
479b93eb47SEric Yang #define REG(reg_name) \
489b93eb47SEric Yang 	CLK_REG(reg_name, CLK0, 0)
499b93eb47SEric Yang 
509b93eb47SEric Yang 
519b93eb47SEric Yang /* Only used by testing framework*/
rv1_dump_clk_registers(struct clk_state_registers * regs,struct clk_bypass * bypass,struct clk_mgr * clk_mgr_base)529b93eb47SEric Yang void rv1_dump_clk_registers(struct clk_state_registers *regs, struct clk_bypass *bypass, struct clk_mgr *clk_mgr_base)
539b93eb47SEric Yang {
549b93eb47SEric Yang 	struct clk_mgr_internal *clk_mgr = TO_CLK_MGR_INTERNAL(clk_mgr_base);
559b93eb47SEric Yang 
569b93eb47SEric Yang 		regs->CLK0_CLK8_CURRENT_CNT = REG_READ(CLK0_CLK8_CURRENT_CNT) / 10; //dcf clk
579b93eb47SEric Yang 
589b93eb47SEric Yang 		bypass->dcfclk_bypass = REG_READ(CLK0_CLK8_BYPASS_CNTL) & 0x0007;
599b93eb47SEric Yang 		if (bypass->dcfclk_bypass < 0 || bypass->dcfclk_bypass > 4)
609b93eb47SEric Yang 			bypass->dcfclk_bypass = 0;
619b93eb47SEric Yang 
629b93eb47SEric Yang 
639b93eb47SEric Yang 		regs->CLK0_CLK8_DS_CNTL = REG_READ(CLK0_CLK8_DS_CNTL) / 10;	//dcf deep sleep divider
649b93eb47SEric Yang 
659b93eb47SEric Yang 		regs->CLK0_CLK8_ALLOW_DS = REG_READ(CLK0_CLK8_ALLOW_DS); //dcf deep sleep allow
669b93eb47SEric Yang 
679b93eb47SEric Yang 		regs->CLK0_CLK10_CURRENT_CNT = REG_READ(CLK0_CLK10_CURRENT_CNT) / 10; //dpref clk
689b93eb47SEric Yang 
699b93eb47SEric Yang 		bypass->dispclk_pypass = REG_READ(CLK0_CLK10_BYPASS_CNTL) & 0x0007;
709b93eb47SEric Yang 		if (bypass->dispclk_pypass < 0 || bypass->dispclk_pypass > 4)
719b93eb47SEric Yang 			bypass->dispclk_pypass = 0;
729b93eb47SEric Yang 
739b93eb47SEric Yang 		regs->CLK0_CLK11_CURRENT_CNT = REG_READ(CLK0_CLK11_CURRENT_CNT) / 10; //disp clk
749b93eb47SEric Yang 
759b93eb47SEric Yang 		bypass->dprefclk_bypass = REG_READ(CLK0_CLK11_BYPASS_CNTL) & 0x0007;
769b93eb47SEric Yang 		if (bypass->dprefclk_bypass < 0 || bypass->dprefclk_bypass > 4)
779b93eb47SEric Yang 			bypass->dprefclk_bypass = 0;
789b93eb47SEric Yang 
799b93eb47SEric Yang }
80