18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2011 Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci#ifndef __RV770_SMC_H__
248c2ecf20Sopenharmony_ci#define __RV770_SMC_H__
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include "ppsmc.h"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#pragma pack(push, 1)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define RV770_SMC_TABLE_ADDRESS 0xB000
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE    3
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistruct RV770_SMC_SCLK_VALUE
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci    uint32_t        vCG_SPLL_FUNC_CNTL;
378c2ecf20Sopenharmony_ci    uint32_t        vCG_SPLL_FUNC_CNTL_2;
388c2ecf20Sopenharmony_ci    uint32_t        vCG_SPLL_FUNC_CNTL_3;
398c2ecf20Sopenharmony_ci    uint32_t        vCG_SPLL_SPREAD_SPECTRUM;
408c2ecf20Sopenharmony_ci    uint32_t        vCG_SPLL_SPREAD_SPECTRUM_2;
418c2ecf20Sopenharmony_ci    uint32_t        sclk_value;
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_citypedef struct RV770_SMC_SCLK_VALUE RV770_SMC_SCLK_VALUE;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct RV770_SMC_MCLK_VALUE
478c2ecf20Sopenharmony_ci{
488c2ecf20Sopenharmony_ci    uint32_t        vMPLL_AD_FUNC_CNTL;
498c2ecf20Sopenharmony_ci    uint32_t        vMPLL_AD_FUNC_CNTL_2;
508c2ecf20Sopenharmony_ci    uint32_t        vMPLL_DQ_FUNC_CNTL;
518c2ecf20Sopenharmony_ci    uint32_t        vMPLL_DQ_FUNC_CNTL_2;
528c2ecf20Sopenharmony_ci    uint32_t        vMCLK_PWRMGT_CNTL;
538c2ecf20Sopenharmony_ci    uint32_t        vDLL_CNTL;
548c2ecf20Sopenharmony_ci    uint32_t        vMPLL_SS;
558c2ecf20Sopenharmony_ci    uint32_t        vMPLL_SS2;
568c2ecf20Sopenharmony_ci    uint32_t        mclk_value;
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_citypedef struct RV770_SMC_MCLK_VALUE RV770_SMC_MCLK_VALUE;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct RV730_SMC_MCLK_VALUE
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci    uint32_t        vMCLK_PWRMGT_CNTL;
658c2ecf20Sopenharmony_ci    uint32_t        vDLL_CNTL;
668c2ecf20Sopenharmony_ci    uint32_t        vMPLL_FUNC_CNTL;
678c2ecf20Sopenharmony_ci    uint32_t        vMPLL_FUNC_CNTL2;
688c2ecf20Sopenharmony_ci    uint32_t        vMPLL_FUNC_CNTL3;
698c2ecf20Sopenharmony_ci    uint32_t        vMPLL_SS;
708c2ecf20Sopenharmony_ci    uint32_t        vMPLL_SS2;
718c2ecf20Sopenharmony_ci    uint32_t        mclk_value;
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_citypedef struct RV730_SMC_MCLK_VALUE RV730_SMC_MCLK_VALUE;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistruct RV770_SMC_VOLTAGE_VALUE
778c2ecf20Sopenharmony_ci{
788c2ecf20Sopenharmony_ci    uint16_t             value;
798c2ecf20Sopenharmony_ci    uint8_t              index;
808c2ecf20Sopenharmony_ci    uint8_t              padding;
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_citypedef struct RV770_SMC_VOLTAGE_VALUE RV770_SMC_VOLTAGE_VALUE;
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciunion RV7XX_SMC_MCLK_VALUE
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci    RV770_SMC_MCLK_VALUE    mclk770;
888c2ecf20Sopenharmony_ci    RV730_SMC_MCLK_VALUE    mclk730;
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_citypedef union RV7XX_SMC_MCLK_VALUE RV7XX_SMC_MCLK_VALUE, *LPRV7XX_SMC_MCLK_VALUE;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistruct RV770_SMC_HW_PERFORMANCE_LEVEL
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci    uint8_t                 arbValue;
968c2ecf20Sopenharmony_ci    union{
978c2ecf20Sopenharmony_ci        uint8_t             seqValue;
988c2ecf20Sopenharmony_ci        uint8_t             ACIndex;
998c2ecf20Sopenharmony_ci    };
1008c2ecf20Sopenharmony_ci    uint8_t                 displayWatermark;
1018c2ecf20Sopenharmony_ci    uint8_t                 gen2PCIE;
1028c2ecf20Sopenharmony_ci    uint8_t                 gen2XSP;
1038c2ecf20Sopenharmony_ci    uint8_t                 backbias;
1048c2ecf20Sopenharmony_ci    uint8_t                 strobeMode;
1058c2ecf20Sopenharmony_ci    uint8_t                 mcFlags;
1068c2ecf20Sopenharmony_ci    uint32_t                aT;
1078c2ecf20Sopenharmony_ci    uint32_t                bSP;
1088c2ecf20Sopenharmony_ci    RV770_SMC_SCLK_VALUE    sclk;
1098c2ecf20Sopenharmony_ci    RV7XX_SMC_MCLK_VALUE    mclk;
1108c2ecf20Sopenharmony_ci    RV770_SMC_VOLTAGE_VALUE vddc;
1118c2ecf20Sopenharmony_ci    RV770_SMC_VOLTAGE_VALUE mvdd;
1128c2ecf20Sopenharmony_ci    RV770_SMC_VOLTAGE_VALUE vddci;
1138c2ecf20Sopenharmony_ci    uint8_t                 reserved1;
1148c2ecf20Sopenharmony_ci    uint8_t                 reserved2;
1158c2ecf20Sopenharmony_ci    uint8_t                 stateFlags;
1168c2ecf20Sopenharmony_ci    uint8_t                 padding;
1178c2ecf20Sopenharmony_ci};
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci#define SMC_STROBE_RATIO    0x0F
1208c2ecf20Sopenharmony_ci#define SMC_STROBE_ENABLE   0x10
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci#define SMC_MC_EDC_RD_FLAG  0x01
1238c2ecf20Sopenharmony_ci#define SMC_MC_EDC_WR_FLAG  0x02
1248c2ecf20Sopenharmony_ci#define SMC_MC_RTT_ENABLE   0x04
1258c2ecf20Sopenharmony_ci#define SMC_MC_STUTTER_EN   0x08
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_citypedef struct RV770_SMC_HW_PERFORMANCE_LEVEL RV770_SMC_HW_PERFORMANCE_LEVEL;
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistruct RV770_SMC_SWSTATE
1308c2ecf20Sopenharmony_ci{
1318c2ecf20Sopenharmony_ci    uint8_t           flags;
1328c2ecf20Sopenharmony_ci    uint8_t           padding1;
1338c2ecf20Sopenharmony_ci    uint8_t           padding2;
1348c2ecf20Sopenharmony_ci    uint8_t           padding3;
1358c2ecf20Sopenharmony_ci    RV770_SMC_HW_PERFORMANCE_LEVEL levels[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE];
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_citypedef struct RV770_SMC_SWSTATE RV770_SMC_SWSTATE;
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci#define RV770_SMC_VOLTAGEMASK_VDDC 0
1418c2ecf20Sopenharmony_ci#define RV770_SMC_VOLTAGEMASK_MVDD 1
1428c2ecf20Sopenharmony_ci#define RV770_SMC_VOLTAGEMASK_VDDCI 2
1438c2ecf20Sopenharmony_ci#define RV770_SMC_VOLTAGEMASK_MAX  4
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistruct RV770_SMC_VOLTAGEMASKTABLE
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci    uint8_t  highMask[RV770_SMC_VOLTAGEMASK_MAX];
1488c2ecf20Sopenharmony_ci    uint32_t lowMask[RV770_SMC_VOLTAGEMASK_MAX];
1498c2ecf20Sopenharmony_ci};
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_citypedef struct RV770_SMC_VOLTAGEMASKTABLE RV770_SMC_VOLTAGEMASKTABLE;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#define MAX_NO_VREG_STEPS 32
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistruct RV770_SMC_STATETABLE
1568c2ecf20Sopenharmony_ci{
1578c2ecf20Sopenharmony_ci    uint8_t             thermalProtectType;
1588c2ecf20Sopenharmony_ci    uint8_t             systemFlags;
1598c2ecf20Sopenharmony_ci    uint8_t             maxVDDCIndexInPPTable;
1608c2ecf20Sopenharmony_ci    uint8_t             extraFlags;
1618c2ecf20Sopenharmony_ci    uint8_t             highSMIO[MAX_NO_VREG_STEPS];
1628c2ecf20Sopenharmony_ci    uint32_t            lowSMIO[MAX_NO_VREG_STEPS];
1638c2ecf20Sopenharmony_ci    RV770_SMC_VOLTAGEMASKTABLE voltageMaskTable;
1648c2ecf20Sopenharmony_ci    RV770_SMC_SWSTATE   initialState;
1658c2ecf20Sopenharmony_ci    RV770_SMC_SWSTATE   ACPIState;
1668c2ecf20Sopenharmony_ci    RV770_SMC_SWSTATE   driverState;
1678c2ecf20Sopenharmony_ci    RV770_SMC_SWSTATE   ULVState;
1688c2ecf20Sopenharmony_ci};
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_citypedef struct RV770_SMC_STATETABLE RV770_SMC_STATETABLE;
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#define PPSMC_STATEFLAG_AUTO_PULSE_SKIP 0x01
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci#pragma pack(pop)
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTERS_START        0x104
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_mclk_chg_timeout        0x0
1798c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_baby_step_timer         0x8
1808c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_delay_bbias             0xC
1818c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_delay_vreg              0x10
1828c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_delay_acpi              0x2C
1838c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_seq_index               0x64
1848c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_mvdd_chg_time           0x68
1858c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_mclk_switch_lim         0x78
1868c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_mc_block_delay          0x90
1878c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_uvd_enabled             0x9C
1888c2ecf20Sopenharmony_ci#define RV770_SMC_SOFT_REGISTER_is_asic_lombok          0xA0
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ciint rv770_copy_bytes_to_smc(struct radeon_device *rdev,
1918c2ecf20Sopenharmony_ci			    u16 smc_start_address, const u8 *src,
1928c2ecf20Sopenharmony_ci			    u16 byte_count, u16 limit);
1938c2ecf20Sopenharmony_civoid rv770_start_smc(struct radeon_device *rdev);
1948c2ecf20Sopenharmony_civoid rv770_reset_smc(struct radeon_device *rdev);
1958c2ecf20Sopenharmony_civoid rv770_stop_smc_clock(struct radeon_device *rdev);
1968c2ecf20Sopenharmony_civoid rv770_start_smc_clock(struct radeon_device *rdev);
1978c2ecf20Sopenharmony_cibool rv770_is_smc_running(struct radeon_device *rdev);
1988c2ecf20Sopenharmony_ciPPSMC_Result rv770_send_msg_to_smc(struct radeon_device *rdev, PPSMC_Msg msg);
1998c2ecf20Sopenharmony_ciPPSMC_Result rv770_wait_for_smc_inactive(struct radeon_device *rdev);
2008c2ecf20Sopenharmony_ciint rv770_read_smc_sram_dword(struct radeon_device *rdev,
2018c2ecf20Sopenharmony_ci			      u16 smc_address, u32 *value, u16 limit);
2028c2ecf20Sopenharmony_ciint rv770_write_smc_sram_dword(struct radeon_device *rdev,
2038c2ecf20Sopenharmony_ci			       u16 smc_address, u32 value, u16 limit);
2048c2ecf20Sopenharmony_ciint rv770_load_smc_ucode(struct radeon_device *rdev,
2058c2ecf20Sopenharmony_ci			 u16 limit);
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci#endif
208