162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright 2013 Advanced Micro Devices, Inc.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation
762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
1262306a36Sopenharmony_ci * all copies or substantial portions of the Software.
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1562306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1662306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1762306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1862306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1962306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2062306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci */
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#ifndef SMU7_H
2562306a36Sopenharmony_ci#define SMU7_H
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#pragma pack(push, 1)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define SMU7_CONTEXT_ID_SMC        1
3062306a36Sopenharmony_ci#define SMU7_CONTEXT_ID_VBIOS      2
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define SMU7_CONTEXT_ID_SMC        1
3462306a36Sopenharmony_ci#define SMU7_CONTEXT_ID_VBIOS      2
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_VDDC            8
3762306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_VDDCI           4
3862306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_MVDD            4
3962306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_VDDNB           8
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_GRAPHICS        SMU__NUM_SCLK_DPM_STATE   // SCLK + SQ DPM + ULV
4262306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_MEMORY          SMU__NUM_MCLK_DPM_LEVELS   // MCLK Levels DPM
4362306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_GIO             SMU__NUM_LCLK_DPM_LEVELS  // LCLK Levels
4462306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_LINK            SMU__NUM_PCIE_DPM_LEVELS  // PCIe speed and number of lanes.
4562306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_UVD             8   // VCLK/DCLK levels for UVD.
4662306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_VCE             8   // ECLK levels for VCE.
4762306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_ACP             8   // ACLK levels for ACP.
4862306a36Sopenharmony_ci#define SMU7_MAX_LEVELS_SAMU            8   // SAMCLK levels for SAMU.
4962306a36Sopenharmony_ci#define SMU7_MAX_ENTRIES_SMIO           32  // Number of entries in SMIO table.
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define DPM_NO_LIMIT 0
5262306a36Sopenharmony_ci#define DPM_NO_UP 1
5362306a36Sopenharmony_ci#define DPM_GO_DOWN 2
5462306a36Sopenharmony_ci#define DPM_GO_UP 3
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#define SMU7_FIRST_DPM_GRAPHICS_LEVEL    0
5762306a36Sopenharmony_ci#define SMU7_FIRST_DPM_MEMORY_LEVEL      0
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define GPIO_CLAMP_MODE_VRHOT      1
6062306a36Sopenharmony_ci#define GPIO_CLAMP_MODE_THERM      2
6162306a36Sopenharmony_ci#define GPIO_CLAMP_MODE_DC         4
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define SCRATCH_B_TARG_PCIE_INDEX_SHIFT 0
6462306a36Sopenharmony_ci#define SCRATCH_B_TARG_PCIE_INDEX_MASK  (0x7<<SCRATCH_B_TARG_PCIE_INDEX_SHIFT)
6562306a36Sopenharmony_ci#define SCRATCH_B_CURR_PCIE_INDEX_SHIFT 3
6662306a36Sopenharmony_ci#define SCRATCH_B_CURR_PCIE_INDEX_MASK  (0x7<<SCRATCH_B_CURR_PCIE_INDEX_SHIFT)
6762306a36Sopenharmony_ci#define SCRATCH_B_TARG_UVD_INDEX_SHIFT  6
6862306a36Sopenharmony_ci#define SCRATCH_B_TARG_UVD_INDEX_MASK   (0x7<<SCRATCH_B_TARG_UVD_INDEX_SHIFT)
6962306a36Sopenharmony_ci#define SCRATCH_B_CURR_UVD_INDEX_SHIFT  9
7062306a36Sopenharmony_ci#define SCRATCH_B_CURR_UVD_INDEX_MASK   (0x7<<SCRATCH_B_CURR_UVD_INDEX_SHIFT)
7162306a36Sopenharmony_ci#define SCRATCH_B_TARG_VCE_INDEX_SHIFT  12
7262306a36Sopenharmony_ci#define SCRATCH_B_TARG_VCE_INDEX_MASK   (0x7<<SCRATCH_B_TARG_VCE_INDEX_SHIFT)
7362306a36Sopenharmony_ci#define SCRATCH_B_CURR_VCE_INDEX_SHIFT  15
7462306a36Sopenharmony_ci#define SCRATCH_B_CURR_VCE_INDEX_MASK   (0x7<<SCRATCH_B_CURR_VCE_INDEX_SHIFT)
7562306a36Sopenharmony_ci#define SCRATCH_B_TARG_ACP_INDEX_SHIFT  18
7662306a36Sopenharmony_ci#define SCRATCH_B_TARG_ACP_INDEX_MASK   (0x7<<SCRATCH_B_TARG_ACP_INDEX_SHIFT)
7762306a36Sopenharmony_ci#define SCRATCH_B_CURR_ACP_INDEX_SHIFT  21
7862306a36Sopenharmony_ci#define SCRATCH_B_CURR_ACP_INDEX_MASK   (0x7<<SCRATCH_B_CURR_ACP_INDEX_SHIFT)
7962306a36Sopenharmony_ci#define SCRATCH_B_TARG_SAMU_INDEX_SHIFT 24
8062306a36Sopenharmony_ci#define SCRATCH_B_TARG_SAMU_INDEX_MASK  (0x7<<SCRATCH_B_TARG_SAMU_INDEX_SHIFT)
8162306a36Sopenharmony_ci#define SCRATCH_B_CURR_SAMU_INDEX_SHIFT 27
8262306a36Sopenharmony_ci#define SCRATCH_B_CURR_SAMU_INDEX_MASK  (0x7<<SCRATCH_B_CURR_SAMU_INDEX_SHIFT)
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_cistruct SMU7_PIDController
8662306a36Sopenharmony_ci{
8762306a36Sopenharmony_ci    uint32_t Ki;
8862306a36Sopenharmony_ci    int32_t LFWindupUL;
8962306a36Sopenharmony_ci    int32_t LFWindupLL;
9062306a36Sopenharmony_ci    uint32_t StatePrecision;
9162306a36Sopenharmony_ci    uint32_t LfPrecision;
9262306a36Sopenharmony_ci    uint32_t LfOffset;
9362306a36Sopenharmony_ci    uint32_t MaxState;
9462306a36Sopenharmony_ci    uint32_t MaxLfFraction;
9562306a36Sopenharmony_ci    uint32_t StateShift;
9662306a36Sopenharmony_ci};
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_citypedef struct SMU7_PIDController SMU7_PIDController;
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci// -------------------------------------------------------------------------------------------------------------------------
10162306a36Sopenharmony_ci#define SMU7_MAX_PCIE_LINK_SPEEDS 3 /* 0:Gen1 1:Gen2 2:Gen3 */
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci#define SMU7_SCLK_DPM_CONFIG_MASK                        0x01
10462306a36Sopenharmony_ci#define SMU7_VOLTAGE_CONTROLLER_CONFIG_MASK              0x02
10562306a36Sopenharmony_ci#define SMU7_THERMAL_CONTROLLER_CONFIG_MASK              0x04
10662306a36Sopenharmony_ci#define SMU7_MCLK_DPM_CONFIG_MASK                        0x08
10762306a36Sopenharmony_ci#define SMU7_UVD_DPM_CONFIG_MASK                         0x10
10862306a36Sopenharmony_ci#define SMU7_VCE_DPM_CONFIG_MASK                         0x20
10962306a36Sopenharmony_ci#define SMU7_ACP_DPM_CONFIG_MASK                         0x40
11062306a36Sopenharmony_ci#define SMU7_SAMU_DPM_CONFIG_MASK                        0x80
11162306a36Sopenharmony_ci#define SMU7_PCIEGEN_DPM_CONFIG_MASK                    0x100
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci#define SMU7_ACP_MCLK_HANDSHAKE_DISABLE                  0x00000001
11462306a36Sopenharmony_ci#define SMU7_ACP_SCLK_HANDSHAKE_DISABLE                  0x00000002
11562306a36Sopenharmony_ci#define SMU7_UVD_MCLK_HANDSHAKE_DISABLE                  0x00000100
11662306a36Sopenharmony_ci#define SMU7_UVD_SCLK_HANDSHAKE_DISABLE                  0x00000200
11762306a36Sopenharmony_ci#define SMU7_VCE_MCLK_HANDSHAKE_DISABLE                  0x00010000
11862306a36Sopenharmony_ci#define SMU7_VCE_SCLK_HANDSHAKE_DISABLE                  0x00020000
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_cistruct SMU7_Firmware_Header
12162306a36Sopenharmony_ci{
12262306a36Sopenharmony_ci    uint32_t Digest[5];
12362306a36Sopenharmony_ci    uint32_t Version;
12462306a36Sopenharmony_ci    uint32_t HeaderSize;
12562306a36Sopenharmony_ci    uint32_t Flags;
12662306a36Sopenharmony_ci    uint32_t EntryPoint;
12762306a36Sopenharmony_ci    uint32_t CodeSize;
12862306a36Sopenharmony_ci    uint32_t ImageSize;
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci    uint32_t Rtos;
13162306a36Sopenharmony_ci    uint32_t SoftRegisters;
13262306a36Sopenharmony_ci    uint32_t DpmTable;
13362306a36Sopenharmony_ci    uint32_t FanTable;
13462306a36Sopenharmony_ci    uint32_t CacConfigTable;
13562306a36Sopenharmony_ci    uint32_t CacStatusTable;
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci    uint32_t mcRegisterTable;
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci    uint32_t mcArbDramTimingTable;
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci    uint32_t PmFuseTable;
14262306a36Sopenharmony_ci    uint32_t Globals;
14362306a36Sopenharmony_ci    uint32_t Reserved[42];
14462306a36Sopenharmony_ci    uint32_t Signature;
14562306a36Sopenharmony_ci};
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_citypedef struct SMU7_Firmware_Header SMU7_Firmware_Header;
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci#define SMU7_FIRMWARE_HEADER_LOCATION 0x20000
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_cienum  DisplayConfig {
15262306a36Sopenharmony_ci    PowerDown = 1,
15362306a36Sopenharmony_ci    DP54x4,
15462306a36Sopenharmony_ci    DP54x2,
15562306a36Sopenharmony_ci    DP54x1,
15662306a36Sopenharmony_ci    DP27x4,
15762306a36Sopenharmony_ci    DP27x2,
15862306a36Sopenharmony_ci    DP27x1,
15962306a36Sopenharmony_ci    HDMI297,
16062306a36Sopenharmony_ci    HDMI162,
16162306a36Sopenharmony_ci    LVDS,
16262306a36Sopenharmony_ci    DP324x4,
16362306a36Sopenharmony_ci    DP324x2,
16462306a36Sopenharmony_ci    DP324x1
16562306a36Sopenharmony_ci};
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci#pragma pack(pop)
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci#endif
17062306a36Sopenharmony_ci
171