162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright 2012 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#ifndef __NI_DPM_H__
2462306a36Sopenharmony_ci#define __NI_DPM_H__
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#include "cypress_dpm.h"
2762306a36Sopenharmony_ci#include "btc_dpm.h"
2862306a36Sopenharmony_ci#include "nislands_smc.h"
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_cistruct ni_clock_registers {
3162306a36Sopenharmony_ci	u32 cg_spll_func_cntl;
3262306a36Sopenharmony_ci	u32 cg_spll_func_cntl_2;
3362306a36Sopenharmony_ci	u32 cg_spll_func_cntl_3;
3462306a36Sopenharmony_ci	u32 cg_spll_func_cntl_4;
3562306a36Sopenharmony_ci	u32 cg_spll_spread_spectrum;
3662306a36Sopenharmony_ci	u32 cg_spll_spread_spectrum_2;
3762306a36Sopenharmony_ci	u32 mclk_pwrmgt_cntl;
3862306a36Sopenharmony_ci	u32 dll_cntl;
3962306a36Sopenharmony_ci	u32 mpll_ad_func_cntl;
4062306a36Sopenharmony_ci	u32 mpll_ad_func_cntl_2;
4162306a36Sopenharmony_ci	u32 mpll_dq_func_cntl;
4262306a36Sopenharmony_ci	u32 mpll_dq_func_cntl_2;
4362306a36Sopenharmony_ci	u32 mpll_ss1;
4462306a36Sopenharmony_ci	u32 mpll_ss2;
4562306a36Sopenharmony_ci};
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_cistruct ni_mc_reg_entry {
4862306a36Sopenharmony_ci	u32 mclk_max;
4962306a36Sopenharmony_ci	u32 mc_data[SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE];
5062306a36Sopenharmony_ci};
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_cistruct ni_mc_reg_table {
5362306a36Sopenharmony_ci	u8 last;
5462306a36Sopenharmony_ci	u8 num_entries;
5562306a36Sopenharmony_ci	u16 valid_flag;
5662306a36Sopenharmony_ci	struct ni_mc_reg_entry mc_reg_table_entry[MAX_AC_TIMING_ENTRIES];
5762306a36Sopenharmony_ci	SMC_NIslands_MCRegisterAddress mc_reg_address[SMC_NISLANDS_MC_REGISTER_ARRAY_SIZE];
5862306a36Sopenharmony_ci};
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define NISLANDS_MCREGISTERTABLE_FIRST_DRIVERSTATE_SLOT 2
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cienum ni_dc_cac_level
6362306a36Sopenharmony_ci{
6462306a36Sopenharmony_ci	NISLANDS_DCCAC_LEVEL_0 = 0,
6562306a36Sopenharmony_ci	NISLANDS_DCCAC_LEVEL_1,
6662306a36Sopenharmony_ci	NISLANDS_DCCAC_LEVEL_2,
6762306a36Sopenharmony_ci	NISLANDS_DCCAC_LEVEL_3,
6862306a36Sopenharmony_ci	NISLANDS_DCCAC_LEVEL_4,
6962306a36Sopenharmony_ci	NISLANDS_DCCAC_LEVEL_5,
7062306a36Sopenharmony_ci	NISLANDS_DCCAC_LEVEL_6,
7162306a36Sopenharmony_ci	NISLANDS_DCCAC_LEVEL_7,
7262306a36Sopenharmony_ci	NISLANDS_DCCAC_MAX_LEVELS
7362306a36Sopenharmony_ci};
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_cistruct ni_leakage_coeffients
7662306a36Sopenharmony_ci{
7762306a36Sopenharmony_ci	u32 at;
7862306a36Sopenharmony_ci	u32 bt;
7962306a36Sopenharmony_ci	u32 av;
8062306a36Sopenharmony_ci	u32 bv;
8162306a36Sopenharmony_ci	s32 t_slope;
8262306a36Sopenharmony_ci	s32 t_intercept;
8362306a36Sopenharmony_ci	u32 t_ref;
8462306a36Sopenharmony_ci};
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_cistruct ni_cac_data
8762306a36Sopenharmony_ci{
8862306a36Sopenharmony_ci	struct ni_leakage_coeffients leakage_coefficients;
8962306a36Sopenharmony_ci	u32 i_leakage;
9062306a36Sopenharmony_ci	s32 leakage_minimum_temperature;
9162306a36Sopenharmony_ci	u32 pwr_const;
9262306a36Sopenharmony_ci	u32 dc_cac_value;
9362306a36Sopenharmony_ci	u32 bif_cac_value;
9462306a36Sopenharmony_ci	u32 lkge_pwr;
9562306a36Sopenharmony_ci	u8 mc_wr_weight;
9662306a36Sopenharmony_ci	u8 mc_rd_weight;
9762306a36Sopenharmony_ci	u8 allow_ovrflw;
9862306a36Sopenharmony_ci	u8 num_win_tdp;
9962306a36Sopenharmony_ci	u8 l2num_win_tdp;
10062306a36Sopenharmony_ci	u8 lts_truncate_n;
10162306a36Sopenharmony_ci};
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_cistruct ni_cac_weights
10462306a36Sopenharmony_ci{
10562306a36Sopenharmony_ci	u32 weight_tcp_sig0;
10662306a36Sopenharmony_ci	u32 weight_tcp_sig1;
10762306a36Sopenharmony_ci	u32 weight_ta_sig;
10862306a36Sopenharmony_ci	u32 weight_tcc_en0;
10962306a36Sopenharmony_ci	u32 weight_tcc_en1;
11062306a36Sopenharmony_ci	u32 weight_tcc_en2;
11162306a36Sopenharmony_ci	u32 weight_cb_en0;
11262306a36Sopenharmony_ci	u32 weight_cb_en1;
11362306a36Sopenharmony_ci	u32 weight_cb_en2;
11462306a36Sopenharmony_ci	u32 weight_cb_en3;
11562306a36Sopenharmony_ci	u32 weight_db_sig0;
11662306a36Sopenharmony_ci	u32 weight_db_sig1;
11762306a36Sopenharmony_ci	u32 weight_db_sig2;
11862306a36Sopenharmony_ci	u32 weight_db_sig3;
11962306a36Sopenharmony_ci	u32 weight_sxm_sig0;
12062306a36Sopenharmony_ci	u32 weight_sxm_sig1;
12162306a36Sopenharmony_ci	u32 weight_sxm_sig2;
12262306a36Sopenharmony_ci	u32 weight_sxs_sig0;
12362306a36Sopenharmony_ci	u32 weight_sxs_sig1;
12462306a36Sopenharmony_ci	u32 weight_xbr_0;
12562306a36Sopenharmony_ci	u32 weight_xbr_1;
12662306a36Sopenharmony_ci	u32 weight_xbr_2;
12762306a36Sopenharmony_ci	u32 weight_spi_sig0;
12862306a36Sopenharmony_ci	u32 weight_spi_sig1;
12962306a36Sopenharmony_ci	u32 weight_spi_sig2;
13062306a36Sopenharmony_ci	u32 weight_spi_sig3;
13162306a36Sopenharmony_ci	u32 weight_spi_sig4;
13262306a36Sopenharmony_ci	u32 weight_spi_sig5;
13362306a36Sopenharmony_ci	u32 weight_lds_sig0;
13462306a36Sopenharmony_ci	u32 weight_lds_sig1;
13562306a36Sopenharmony_ci	u32 weight_sc;
13662306a36Sopenharmony_ci	u32 weight_bif;
13762306a36Sopenharmony_ci	u32 weight_cp;
13862306a36Sopenharmony_ci	u32 weight_pa_sig0;
13962306a36Sopenharmony_ci	u32 weight_pa_sig1;
14062306a36Sopenharmony_ci	u32 weight_vgt_sig0;
14162306a36Sopenharmony_ci	u32 weight_vgt_sig1;
14262306a36Sopenharmony_ci	u32 weight_vgt_sig2;
14362306a36Sopenharmony_ci	u32 weight_dc_sig0;
14462306a36Sopenharmony_ci	u32 weight_dc_sig1;
14562306a36Sopenharmony_ci	u32 weight_dc_sig2;
14662306a36Sopenharmony_ci	u32 weight_dc_sig3;
14762306a36Sopenharmony_ci	u32 weight_uvd_sig0;
14862306a36Sopenharmony_ci	u32 weight_uvd_sig1;
14962306a36Sopenharmony_ci	u32 weight_spare0;
15062306a36Sopenharmony_ci	u32 weight_spare1;
15162306a36Sopenharmony_ci	u32 weight_sq_vsp;
15262306a36Sopenharmony_ci	u32 weight_sq_vsp0;
15362306a36Sopenharmony_ci	u32 weight_sq_gpr;
15462306a36Sopenharmony_ci	u32 ovr_mode_spare_0;
15562306a36Sopenharmony_ci	u32 ovr_val_spare_0;
15662306a36Sopenharmony_ci	u32 ovr_mode_spare_1;
15762306a36Sopenharmony_ci	u32 ovr_val_spare_1;
15862306a36Sopenharmony_ci	u32 vsp;
15962306a36Sopenharmony_ci	u32 vsp0;
16062306a36Sopenharmony_ci	u32 gpr;
16162306a36Sopenharmony_ci	u8 mc_read_weight;
16262306a36Sopenharmony_ci	u8 mc_write_weight;
16362306a36Sopenharmony_ci	u32 tid_cnt;
16462306a36Sopenharmony_ci	u32 tid_unit;
16562306a36Sopenharmony_ci	u32 l2_lta_window_size;
16662306a36Sopenharmony_ci	u32 lts_truncate;
16762306a36Sopenharmony_ci	u32 dc_cac[NISLANDS_DCCAC_MAX_LEVELS];
16862306a36Sopenharmony_ci	u32 pcie_cac[SMC_NISLANDS_BIF_LUT_NUM_OF_ENTRIES];
16962306a36Sopenharmony_ci	bool enable_power_containment_by_default;
17062306a36Sopenharmony_ci};
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_cistruct ni_ps {
17362306a36Sopenharmony_ci	u16 performance_level_count;
17462306a36Sopenharmony_ci	bool dc_compatible;
17562306a36Sopenharmony_ci	struct rv7xx_pl performance_levels[NISLANDS_MAX_SMC_PERFORMANCE_LEVELS_PER_SWSTATE];
17662306a36Sopenharmony_ci};
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_cistruct ni_power_info {
17962306a36Sopenharmony_ci	/* must be first! */
18062306a36Sopenharmony_ci	struct evergreen_power_info eg;
18162306a36Sopenharmony_ci	struct ni_clock_registers clock_registers;
18262306a36Sopenharmony_ci	struct ni_mc_reg_table mc_reg_table;
18362306a36Sopenharmony_ci	u32 mclk_rtt_mode_threshold;
18462306a36Sopenharmony_ci	/* flags */
18562306a36Sopenharmony_ci	bool use_power_boost_limit;
18662306a36Sopenharmony_ci	bool support_cac_long_term_average;
18762306a36Sopenharmony_ci	bool cac_enabled;
18862306a36Sopenharmony_ci	bool cac_configuration_required;
18962306a36Sopenharmony_ci	bool driver_calculate_cac_leakage;
19062306a36Sopenharmony_ci	bool pc_enabled;
19162306a36Sopenharmony_ci	bool enable_power_containment;
19262306a36Sopenharmony_ci	bool enable_cac;
19362306a36Sopenharmony_ci	bool enable_sq_ramping;
19462306a36Sopenharmony_ci	/* smc offsets */
19562306a36Sopenharmony_ci	u16 arb_table_start;
19662306a36Sopenharmony_ci	u16 fan_table_start;
19762306a36Sopenharmony_ci	u16 cac_table_start;
19862306a36Sopenharmony_ci	u16 spll_table_start;
19962306a36Sopenharmony_ci	/* CAC stuff */
20062306a36Sopenharmony_ci	struct ni_cac_data cac_data;
20162306a36Sopenharmony_ci	u32 dc_cac_table[NISLANDS_DCCAC_MAX_LEVELS];
20262306a36Sopenharmony_ci	const struct ni_cac_weights *cac_weights;
20362306a36Sopenharmony_ci	u8 lta_window_size;
20462306a36Sopenharmony_ci	u8 lts_truncate;
20562306a36Sopenharmony_ci	struct ni_ps current_ps;
20662306a36Sopenharmony_ci	struct ni_ps requested_ps;
20762306a36Sopenharmony_ci	/* scratch structs */
20862306a36Sopenharmony_ci	SMC_NIslands_MCRegisters smc_mc_reg_table;
20962306a36Sopenharmony_ci	NISLANDS_SMC_STATETABLE smc_statetable;
21062306a36Sopenharmony_ci};
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci#define NISLANDS_INITIAL_STATE_ARB_INDEX    0
21362306a36Sopenharmony_ci#define NISLANDS_ACPI_STATE_ARB_INDEX       1
21462306a36Sopenharmony_ci#define NISLANDS_ULV_STATE_ARB_INDEX        2
21562306a36Sopenharmony_ci#define NISLANDS_DRIVER_STATE_ARB_INDEX     3
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci#define NISLANDS_DPM2_MAX_PULSE_SKIP        256
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci#define NISLANDS_DPM2_NEAR_TDP_DEC          10
22062306a36Sopenharmony_ci#define NISLANDS_DPM2_ABOVE_SAFE_INC        5
22162306a36Sopenharmony_ci#define NISLANDS_DPM2_BELOW_SAFE_INC        20
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci#define NISLANDS_DPM2_TDP_SAFE_LIMIT_PERCENT            80
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ci#define NISLANDS_DPM2_MAXPS_PERCENT_H                   90
22662306a36Sopenharmony_ci#define NISLANDS_DPM2_MAXPS_PERCENT_M                   0
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_ci#define NISLANDS_DPM2_SQ_RAMP_MAX_POWER                 0x3FFF
22962306a36Sopenharmony_ci#define NISLANDS_DPM2_SQ_RAMP_MIN_POWER                 0x12
23062306a36Sopenharmony_ci#define NISLANDS_DPM2_SQ_RAMP_MAX_POWER_DELTA           0x15
23162306a36Sopenharmony_ci#define NISLANDS_DPM2_SQ_RAMP_STI_SIZE                  0x1E
23262306a36Sopenharmony_ci#define NISLANDS_DPM2_SQ_RAMP_LTI_RATIO                 0xF
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ciint ni_copy_and_switch_arb_sets(struct radeon_device *rdev,
23562306a36Sopenharmony_ci				u32 arb_freq_src, u32 arb_freq_dest);
23662306a36Sopenharmony_civoid ni_update_current_ps(struct radeon_device *rdev,
23762306a36Sopenharmony_ci			  struct radeon_ps *rps);
23862306a36Sopenharmony_civoid ni_update_requested_ps(struct radeon_device *rdev,
23962306a36Sopenharmony_ci			    struct radeon_ps *rps);
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_civoid ni_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev,
24262306a36Sopenharmony_ci					   struct radeon_ps *new_ps,
24362306a36Sopenharmony_ci					   struct radeon_ps *old_ps);
24462306a36Sopenharmony_civoid ni_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev,
24562306a36Sopenharmony_ci					  struct radeon_ps *new_ps,
24662306a36Sopenharmony_ci					  struct radeon_ps *old_ps);
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_cibool ni_dpm_vblank_too_short(struct radeon_device *rdev);
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_cistruct ni_power_info *ni_get_pi(struct radeon_device *rdev);
25162306a36Sopenharmony_cistruct ni_ps *ni_get_ps(struct radeon_ps *rps);
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci#endif
254