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 __TRINITY_DPM_H__
2462306a36Sopenharmony_ci#define __TRINITY_DPM_H__
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#include "sumo_dpm.h"
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define TRINITY_SIZEOF_DPM_STATE_TABLE (SMU_SCLK_DPM_STATE_1_CNTL_0 - SMU_SCLK_DPM_STATE_0_CNTL_0)
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_cistruct trinity_pl {
3162306a36Sopenharmony_ci	u32 sclk;
3262306a36Sopenharmony_ci	u8 vddc_index;
3362306a36Sopenharmony_ci	u8 ds_divider_index;
3462306a36Sopenharmony_ci	u8 ss_divider_index;
3562306a36Sopenharmony_ci	u8 allow_gnb_slow;
3662306a36Sopenharmony_ci	u8 force_nbp_state;
3762306a36Sopenharmony_ci	u8 display_wm;
3862306a36Sopenharmony_ci	u8 vce_wm;
3962306a36Sopenharmony_ci};
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define TRINITY_POWERSTATE_FLAGS_NBPS_FORCEHIGH  (1 << 0)
4262306a36Sopenharmony_ci#define TRINITY_POWERSTATE_FLAGS_NBPS_LOCKTOHIGH (1 << 1)
4362306a36Sopenharmony_ci#define TRINITY_POWERSTATE_FLAGS_NBPS_LOCKTOLOW  (1 << 2)
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#define TRINITY_POWERSTATE_FLAGS_BAPM_DISABLE    (1 << 0)
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_cistruct trinity_ps {
4862306a36Sopenharmony_ci	u32 num_levels;
4962306a36Sopenharmony_ci	struct trinity_pl levels[SUMO_MAX_HARDWARE_POWERLEVELS];
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci	u32 nbps_flags;
5262306a36Sopenharmony_ci	u32 bapm_flags;
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci	u8 Dpm0PgNbPsLo;
5562306a36Sopenharmony_ci	u8 Dpm0PgNbPsHi;
5662306a36Sopenharmony_ci	u8 DpmXNbPsLo;
5762306a36Sopenharmony_ci	u8 DpmXNbPsHi;
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	u32 vclk_low_divider;
6062306a36Sopenharmony_ci	u32 vclk_high_divider;
6162306a36Sopenharmony_ci	u32 dclk_low_divider;
6262306a36Sopenharmony_ci	u32 dclk_high_divider;
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define TRINITY_NUM_NBPSTATES   4
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_cistruct trinity_uvd_clock_table_entry
6862306a36Sopenharmony_ci{
6962306a36Sopenharmony_ci	u32 vclk;
7062306a36Sopenharmony_ci	u32 dclk;
7162306a36Sopenharmony_ci	u8 vclk_did;
7262306a36Sopenharmony_ci	u8 dclk_did;
7362306a36Sopenharmony_ci	u8 rsv[2];
7462306a36Sopenharmony_ci};
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_cistruct trinity_sys_info {
7762306a36Sopenharmony_ci	u32 bootup_uma_clk;
7862306a36Sopenharmony_ci	u32 bootup_sclk;
7962306a36Sopenharmony_ci	u32 min_sclk;
8062306a36Sopenharmony_ci	u32 dentist_vco_freq;
8162306a36Sopenharmony_ci	u32 nb_dpm_enable;
8262306a36Sopenharmony_ci	u32 nbp_mclk[TRINITY_NUM_NBPSTATES];
8362306a36Sopenharmony_ci	u32 nbp_nclk[TRINITY_NUM_NBPSTATES];
8462306a36Sopenharmony_ci	u16 nbp_voltage_index[TRINITY_NUM_NBPSTATES];
8562306a36Sopenharmony_ci	u16 bootup_nb_voltage_index;
8662306a36Sopenharmony_ci	u8 htc_tmp_lmt;
8762306a36Sopenharmony_ci	u8 htc_hyst_lmt;
8862306a36Sopenharmony_ci	struct sumo_sclk_voltage_mapping_table sclk_voltage_mapping_table;
8962306a36Sopenharmony_ci	struct sumo_vid_mapping_table vid_mapping_table;
9062306a36Sopenharmony_ci	u32 uma_channel_number;
9162306a36Sopenharmony_ci	struct trinity_uvd_clock_table_entry uvd_clock_table_entries[4];
9262306a36Sopenharmony_ci};
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_cistruct trinity_power_info {
9562306a36Sopenharmony_ci	u32 at[SUMO_MAX_HARDWARE_POWERLEVELS];
9662306a36Sopenharmony_ci	u32 dpm_interval;
9762306a36Sopenharmony_ci	u32 thermal_auto_throttling;
9862306a36Sopenharmony_ci	struct trinity_sys_info sys_info;
9962306a36Sopenharmony_ci	struct trinity_pl boot_pl;
10062306a36Sopenharmony_ci	u32 min_sclk_did;
10162306a36Sopenharmony_ci	bool enable_nbps_policy;
10262306a36Sopenharmony_ci	bool voltage_drop_in_dce;
10362306a36Sopenharmony_ci	bool override_dynamic_mgpg;
10462306a36Sopenharmony_ci	bool enable_gfx_clock_gating;
10562306a36Sopenharmony_ci	bool enable_gfx_power_gating;
10662306a36Sopenharmony_ci	bool enable_mg_clock_gating;
10762306a36Sopenharmony_ci	bool enable_gfx_dynamic_mgpg;
10862306a36Sopenharmony_ci	bool enable_auto_thermal_throttling;
10962306a36Sopenharmony_ci	bool enable_dpm;
11062306a36Sopenharmony_ci	bool enable_sclk_ds;
11162306a36Sopenharmony_ci	bool enable_bapm;
11262306a36Sopenharmony_ci	bool uvd_dpm;
11362306a36Sopenharmony_ci	struct radeon_ps current_rps;
11462306a36Sopenharmony_ci	struct trinity_ps current_ps;
11562306a36Sopenharmony_ci	struct radeon_ps requested_rps;
11662306a36Sopenharmony_ci	struct trinity_ps requested_ps;
11762306a36Sopenharmony_ci};
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci#define TRINITY_AT_DFLT            30
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci/* trinity_smc.c */
12262306a36Sopenharmony_ciint trinity_dpm_bapm_enable(struct radeon_device *rdev, bool enable);
12362306a36Sopenharmony_ciint trinity_dpm_config(struct radeon_device *rdev, bool enable);
12462306a36Sopenharmony_ciint trinity_uvd_dpm_config(struct radeon_device *rdev);
12562306a36Sopenharmony_ciint trinity_dpm_force_state(struct radeon_device *rdev, u32 n);
12662306a36Sopenharmony_ciint trinity_dpm_n_levels_disabled(struct radeon_device *rdev, u32 n);
12762306a36Sopenharmony_ciint trinity_dpm_no_forced_level(struct radeon_device *rdev);
12862306a36Sopenharmony_ciint trinity_dce_enable_voltage_adjustment(struct radeon_device *rdev,
12962306a36Sopenharmony_ci					  bool enable);
13062306a36Sopenharmony_ciint trinity_gfx_dynamic_mgpg_config(struct radeon_device *rdev);
13162306a36Sopenharmony_civoid trinity_acquire_mutex(struct radeon_device *rdev);
13262306a36Sopenharmony_civoid trinity_release_mutex(struct radeon_device *rdev);
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci#endif
135