xref: /dflybsd-src/sys/dev/drm/radeon/rv770_smc.h (revision c6f73aab61fac8c404b25589bb53548913079bc6)
1*57e252bfSMichael Neumann /*
2*57e252bfSMichael Neumann  * Copyright 2011 Advanced Micro Devices, Inc.
3*57e252bfSMichael Neumann  *
4*57e252bfSMichael Neumann  * Permission is hereby granted, free of charge, to any person obtaining a
5*57e252bfSMichael Neumann  * copy of this software and associated documentation files (the "Software"),
6*57e252bfSMichael Neumann  * to deal in the Software without restriction, including without limitation
7*57e252bfSMichael Neumann  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*57e252bfSMichael Neumann  * and/or sell copies of the Software, and to permit persons to whom the
9*57e252bfSMichael Neumann  * Software is furnished to do so, subject to the following conditions:
10*57e252bfSMichael Neumann  *
11*57e252bfSMichael Neumann  * The above copyright notice and this permission notice shall be included in
12*57e252bfSMichael Neumann  * all copies or substantial portions of the Software.
13*57e252bfSMichael Neumann  *
14*57e252bfSMichael Neumann  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*57e252bfSMichael Neumann  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*57e252bfSMichael Neumann  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17*57e252bfSMichael Neumann  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*57e252bfSMichael Neumann  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*57e252bfSMichael Neumann  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*57e252bfSMichael Neumann  * OTHER DEALINGS IN THE SOFTWARE.
21*57e252bfSMichael Neumann  *
22*57e252bfSMichael Neumann  */
23*57e252bfSMichael Neumann #ifndef __RV770_SMC_H__
24*57e252bfSMichael Neumann #define __RV770_SMC_H__
25*57e252bfSMichael Neumann 
26*57e252bfSMichael Neumann #include "ppsmc.h"
27*57e252bfSMichael Neumann 
28*57e252bfSMichael Neumann #pragma pack(push, 1)
29*57e252bfSMichael Neumann 
30*57e252bfSMichael Neumann #define RV770_SMC_TABLE_ADDRESS 0xB000
31*57e252bfSMichael Neumann 
32*57e252bfSMichael Neumann #define RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE    3
33*57e252bfSMichael Neumann 
34*57e252bfSMichael Neumann struct RV770_SMC_SCLK_VALUE
35*57e252bfSMichael Neumann {
36*57e252bfSMichael Neumann     uint32_t        vCG_SPLL_FUNC_CNTL;
37*57e252bfSMichael Neumann     uint32_t        vCG_SPLL_FUNC_CNTL_2;
38*57e252bfSMichael Neumann     uint32_t        vCG_SPLL_FUNC_CNTL_3;
39*57e252bfSMichael Neumann     uint32_t        vCG_SPLL_SPREAD_SPECTRUM;
40*57e252bfSMichael Neumann     uint32_t        vCG_SPLL_SPREAD_SPECTRUM_2;
41*57e252bfSMichael Neumann     uint32_t        sclk_value;
42*57e252bfSMichael Neumann };
43*57e252bfSMichael Neumann 
44*57e252bfSMichael Neumann typedef struct RV770_SMC_SCLK_VALUE RV770_SMC_SCLK_VALUE;
45*57e252bfSMichael Neumann 
46*57e252bfSMichael Neumann struct RV770_SMC_MCLK_VALUE
47*57e252bfSMichael Neumann {
48*57e252bfSMichael Neumann     uint32_t        vMPLL_AD_FUNC_CNTL;
49*57e252bfSMichael Neumann     uint32_t        vMPLL_AD_FUNC_CNTL_2;
50*57e252bfSMichael Neumann     uint32_t        vMPLL_DQ_FUNC_CNTL;
51*57e252bfSMichael Neumann     uint32_t        vMPLL_DQ_FUNC_CNTL_2;
52*57e252bfSMichael Neumann     uint32_t        vMCLK_PWRMGT_CNTL;
53*57e252bfSMichael Neumann     uint32_t        vDLL_CNTL;
54*57e252bfSMichael Neumann     uint32_t        vMPLL_SS;
55*57e252bfSMichael Neumann     uint32_t        vMPLL_SS2;
56*57e252bfSMichael Neumann     uint32_t        mclk_value;
57*57e252bfSMichael Neumann };
58*57e252bfSMichael Neumann 
59*57e252bfSMichael Neumann typedef struct RV770_SMC_MCLK_VALUE RV770_SMC_MCLK_VALUE;
60*57e252bfSMichael Neumann 
61*57e252bfSMichael Neumann 
62*57e252bfSMichael Neumann struct RV730_SMC_MCLK_VALUE
63*57e252bfSMichael Neumann {
64*57e252bfSMichael Neumann     uint32_t        vMCLK_PWRMGT_CNTL;
65*57e252bfSMichael Neumann     uint32_t        vDLL_CNTL;
66*57e252bfSMichael Neumann     uint32_t        vMPLL_FUNC_CNTL;
67*57e252bfSMichael Neumann     uint32_t        vMPLL_FUNC_CNTL2;
68*57e252bfSMichael Neumann     uint32_t        vMPLL_FUNC_CNTL3;
69*57e252bfSMichael Neumann     uint32_t        vMPLL_SS;
70*57e252bfSMichael Neumann     uint32_t        vMPLL_SS2;
71*57e252bfSMichael Neumann     uint32_t        mclk_value;
72*57e252bfSMichael Neumann };
73*57e252bfSMichael Neumann 
74*57e252bfSMichael Neumann typedef struct RV730_SMC_MCLK_VALUE RV730_SMC_MCLK_VALUE;
75*57e252bfSMichael Neumann 
76*57e252bfSMichael Neumann struct RV770_SMC_VOLTAGE_VALUE
77*57e252bfSMichael Neumann {
78*57e252bfSMichael Neumann     uint16_t             value;
79*57e252bfSMichael Neumann     uint8_t              index;
80*57e252bfSMichael Neumann     uint8_t              padding;
81*57e252bfSMichael Neumann };
82*57e252bfSMichael Neumann 
83*57e252bfSMichael Neumann typedef struct RV770_SMC_VOLTAGE_VALUE RV770_SMC_VOLTAGE_VALUE;
84*57e252bfSMichael Neumann 
85*57e252bfSMichael Neumann union RV7XX_SMC_MCLK_VALUE
86*57e252bfSMichael Neumann {
87*57e252bfSMichael Neumann     RV770_SMC_MCLK_VALUE    mclk770;
88*57e252bfSMichael Neumann     RV730_SMC_MCLK_VALUE    mclk730;
89*57e252bfSMichael Neumann };
90*57e252bfSMichael Neumann 
91*57e252bfSMichael Neumann typedef union RV7XX_SMC_MCLK_VALUE RV7XX_SMC_MCLK_VALUE, *LPRV7XX_SMC_MCLK_VALUE;
92*57e252bfSMichael Neumann 
93*57e252bfSMichael Neumann struct RV770_SMC_HW_PERFORMANCE_LEVEL
94*57e252bfSMichael Neumann {
95*57e252bfSMichael Neumann     uint8_t                 arbValue;
96*57e252bfSMichael Neumann     union{
97*57e252bfSMichael Neumann         uint8_t             seqValue;
98*57e252bfSMichael Neumann         uint8_t             ACIndex;
99*57e252bfSMichael Neumann     };
100*57e252bfSMichael Neumann     uint8_t                 displayWatermark;
101*57e252bfSMichael Neumann     uint8_t                 gen2PCIE;
102*57e252bfSMichael Neumann     uint8_t                 gen2XSP;
103*57e252bfSMichael Neumann     uint8_t                 backbias;
104*57e252bfSMichael Neumann     uint8_t                 strobeMode;
105*57e252bfSMichael Neumann     uint8_t                 mcFlags;
106*57e252bfSMichael Neumann     uint32_t                aT;
107*57e252bfSMichael Neumann     uint32_t                bSP;
108*57e252bfSMichael Neumann     RV770_SMC_SCLK_VALUE    sclk;
109*57e252bfSMichael Neumann     RV7XX_SMC_MCLK_VALUE    mclk;
110*57e252bfSMichael Neumann     RV770_SMC_VOLTAGE_VALUE vddc;
111*57e252bfSMichael Neumann     RV770_SMC_VOLTAGE_VALUE mvdd;
112*57e252bfSMichael Neumann     RV770_SMC_VOLTAGE_VALUE vddci;
113*57e252bfSMichael Neumann     uint8_t                 reserved1;
114*57e252bfSMichael Neumann     uint8_t                 reserved2;
115*57e252bfSMichael Neumann     uint8_t                 stateFlags;
116*57e252bfSMichael Neumann     uint8_t                 padding;
117*57e252bfSMichael Neumann };
118*57e252bfSMichael Neumann 
119*57e252bfSMichael Neumann #define SMC_STROBE_RATIO    0x0F
120*57e252bfSMichael Neumann #define SMC_STROBE_ENABLE   0x10
121*57e252bfSMichael Neumann 
122*57e252bfSMichael Neumann #define SMC_MC_EDC_RD_FLAG  0x01
123*57e252bfSMichael Neumann #define SMC_MC_EDC_WR_FLAG  0x02
124*57e252bfSMichael Neumann #define SMC_MC_RTT_ENABLE   0x04
125*57e252bfSMichael Neumann #define SMC_MC_STUTTER_EN   0x08
126*57e252bfSMichael Neumann 
127*57e252bfSMichael Neumann typedef struct RV770_SMC_HW_PERFORMANCE_LEVEL RV770_SMC_HW_PERFORMANCE_LEVEL;
128*57e252bfSMichael Neumann 
129*57e252bfSMichael Neumann struct RV770_SMC_SWSTATE
130*57e252bfSMichael Neumann {
131*57e252bfSMichael Neumann     uint8_t           flags;
132*57e252bfSMichael Neumann     uint8_t           padding1;
133*57e252bfSMichael Neumann     uint8_t           padding2;
134*57e252bfSMichael Neumann     uint8_t           padding3;
135*57e252bfSMichael Neumann     RV770_SMC_HW_PERFORMANCE_LEVEL levels[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE];
136*57e252bfSMichael Neumann };
137*57e252bfSMichael Neumann 
138*57e252bfSMichael Neumann typedef struct RV770_SMC_SWSTATE RV770_SMC_SWSTATE;
139*57e252bfSMichael Neumann 
140*57e252bfSMichael Neumann #define RV770_SMC_VOLTAGEMASK_VDDC 0
141*57e252bfSMichael Neumann #define RV770_SMC_VOLTAGEMASK_MVDD 1
142*57e252bfSMichael Neumann #define RV770_SMC_VOLTAGEMASK_VDDCI 2
143*57e252bfSMichael Neumann #define RV770_SMC_VOLTAGEMASK_MAX  4
144*57e252bfSMichael Neumann 
145*57e252bfSMichael Neumann struct RV770_SMC_VOLTAGEMASKTABLE
146*57e252bfSMichael Neumann {
147*57e252bfSMichael Neumann     uint8_t  highMask[RV770_SMC_VOLTAGEMASK_MAX];
148*57e252bfSMichael Neumann     uint32_t lowMask[RV770_SMC_VOLTAGEMASK_MAX];
149*57e252bfSMichael Neumann };
150*57e252bfSMichael Neumann 
151*57e252bfSMichael Neumann typedef struct RV770_SMC_VOLTAGEMASKTABLE RV770_SMC_VOLTAGEMASKTABLE;
152*57e252bfSMichael Neumann 
153*57e252bfSMichael Neumann #define MAX_NO_VREG_STEPS 32
154*57e252bfSMichael Neumann 
155*57e252bfSMichael Neumann struct RV770_SMC_STATETABLE
156*57e252bfSMichael Neumann {
157*57e252bfSMichael Neumann     uint8_t             thermalProtectType;
158*57e252bfSMichael Neumann     uint8_t             systemFlags;
159*57e252bfSMichael Neumann     uint8_t             maxVDDCIndexInPPTable;
160*57e252bfSMichael Neumann     uint8_t             extraFlags;
161*57e252bfSMichael Neumann     uint8_t             highSMIO[MAX_NO_VREG_STEPS];
162*57e252bfSMichael Neumann     uint32_t            lowSMIO[MAX_NO_VREG_STEPS];
163*57e252bfSMichael Neumann     RV770_SMC_VOLTAGEMASKTABLE voltageMaskTable;
164*57e252bfSMichael Neumann     RV770_SMC_SWSTATE   initialState;
165*57e252bfSMichael Neumann     RV770_SMC_SWSTATE   ACPIState;
166*57e252bfSMichael Neumann     RV770_SMC_SWSTATE   driverState;
167*57e252bfSMichael Neumann     RV770_SMC_SWSTATE   ULVState;
168*57e252bfSMichael Neumann };
169*57e252bfSMichael Neumann 
170*57e252bfSMichael Neumann typedef struct RV770_SMC_STATETABLE RV770_SMC_STATETABLE;
171*57e252bfSMichael Neumann 
172*57e252bfSMichael Neumann #define PPSMC_STATEFLAG_AUTO_PULSE_SKIP 0x01
173*57e252bfSMichael Neumann 
174*57e252bfSMichael Neumann #pragma pack(pop)
175*57e252bfSMichael Neumann 
176*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTERS_START        0x104
177*57e252bfSMichael Neumann 
178*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_mclk_chg_timeout        0x0
179*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_baby_step_timer         0x8
180*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_delay_bbias             0xC
181*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_delay_vreg              0x10
182*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_delay_acpi              0x2C
183*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_seq_index               0x64
184*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_mvdd_chg_time           0x68
185*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_mclk_switch_lim         0x78
186*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_mc_block_delay          0x90
187*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_uvd_enabled             0x9C
188*57e252bfSMichael Neumann #define RV770_SMC_SOFT_REGISTER_is_asic_lombok          0xA0
189*57e252bfSMichael Neumann 
190*57e252bfSMichael Neumann int rv770_copy_bytes_to_smc(struct radeon_device *rdev,
191*57e252bfSMichael Neumann 			    u16 smc_start_address, const u8 *src,
192*57e252bfSMichael Neumann 			    u16 byte_count, u16 limit);
193*57e252bfSMichael Neumann void rv770_start_smc(struct radeon_device *rdev);
194*57e252bfSMichael Neumann void rv770_reset_smc(struct radeon_device *rdev);
195*57e252bfSMichael Neumann void rv770_stop_smc_clock(struct radeon_device *rdev);
196*57e252bfSMichael Neumann void rv770_start_smc_clock(struct radeon_device *rdev);
197*57e252bfSMichael Neumann bool rv770_is_smc_running(struct radeon_device *rdev);
198*57e252bfSMichael Neumann PPSMC_Result rv770_send_msg_to_smc(struct radeon_device *rdev, PPSMC_Msg msg);
199*57e252bfSMichael Neumann PPSMC_Result rv770_wait_for_smc_inactive(struct radeon_device *rdev);
200*57e252bfSMichael Neumann int rv770_read_smc_sram_dword(struct radeon_device *rdev,
201*57e252bfSMichael Neumann 			      u16 smc_address, u32 *value, u16 limit);
202*57e252bfSMichael Neumann int rv770_write_smc_sram_dword(struct radeon_device *rdev,
203*57e252bfSMichael Neumann 			       u16 smc_address, u32 value, u16 limit);
204*57e252bfSMichael Neumann int rv770_load_smc_ucode(struct radeon_device *rdev,
205*57e252bfSMichael Neumann 			 u16 limit);
206*57e252bfSMichael Neumann 
207*57e252bfSMichael Neumann #endif
208