1*b843c749SSergey Zigachev /* 2*b843c749SSergey Zigachev * Copyright 2014 Advanced Micro Devices, Inc. 3*b843c749SSergey Zigachev * 4*b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a 5*b843c749SSergey Zigachev * copy of this software and associated documentation files (the "Software"), 6*b843c749SSergey Zigachev * to deal in the Software without restriction, including without limitation 7*b843c749SSergey Zigachev * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8*b843c749SSergey Zigachev * and/or sell copies of the Software, and to permit persons to whom the 9*b843c749SSergey Zigachev * Software is furnished to do so, subject to the following conditions: 10*b843c749SSergey Zigachev * 11*b843c749SSergey Zigachev * The above copyright notice and this permission notice shall be included in 12*b843c749SSergey Zigachev * all copies or substantial portions of the Software. 13*b843c749SSergey Zigachev * 14*b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15*b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16*b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17*b843c749SSergey Zigachev * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18*b843c749SSergey Zigachev * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19*b843c749SSergey Zigachev * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20*b843c749SSergey Zigachev * OTHER DEALINGS IN THE SOFTWARE. 21*b843c749SSergey Zigachev * 22*b843c749SSergey Zigachev */ 23*b843c749SSergey Zigachev 24*b843c749SSergey Zigachev #ifndef __AMDGPU_ATOMBIOS_H__ 25*b843c749SSergey Zigachev #define __AMDGPU_ATOMBIOS_H__ 26*b843c749SSergey Zigachev 27*b843c749SSergey Zigachev struct atom_clock_dividers { 28*b843c749SSergey Zigachev u32 post_div; 29*b843c749SSergey Zigachev union { 30*b843c749SSergey Zigachev struct { 31*b843c749SSergey Zigachev #ifdef __BIG_ENDIAN 32*b843c749SSergey Zigachev u32 reserved : 6; 33*b843c749SSergey Zigachev u32 whole_fb_div : 12; 34*b843c749SSergey Zigachev u32 frac_fb_div : 14; 35*b843c749SSergey Zigachev #else 36*b843c749SSergey Zigachev u32 frac_fb_div : 14; 37*b843c749SSergey Zigachev u32 whole_fb_div : 12; 38*b843c749SSergey Zigachev u32 reserved : 6; 39*b843c749SSergey Zigachev #endif 40*b843c749SSergey Zigachev }; 41*b843c749SSergey Zigachev u32 fb_div; 42*b843c749SSergey Zigachev }; 43*b843c749SSergey Zigachev u32 ref_div; 44*b843c749SSergey Zigachev bool enable_post_div; 45*b843c749SSergey Zigachev bool enable_dithen; 46*b843c749SSergey Zigachev u32 vco_mode; 47*b843c749SSergey Zigachev u32 real_clock; 48*b843c749SSergey Zigachev /* added for CI */ 49*b843c749SSergey Zigachev u32 post_divider; 50*b843c749SSergey Zigachev u32 flags; 51*b843c749SSergey Zigachev }; 52*b843c749SSergey Zigachev 53*b843c749SSergey Zigachev struct atom_mpll_param { 54*b843c749SSergey Zigachev union { 55*b843c749SSergey Zigachev struct { 56*b843c749SSergey Zigachev #ifdef __BIG_ENDIAN 57*b843c749SSergey Zigachev u32 reserved : 8; 58*b843c749SSergey Zigachev u32 clkfrac : 12; 59*b843c749SSergey Zigachev u32 clkf : 12; 60*b843c749SSergey Zigachev #else 61*b843c749SSergey Zigachev u32 clkf : 12; 62*b843c749SSergey Zigachev u32 clkfrac : 12; 63*b843c749SSergey Zigachev u32 reserved : 8; 64*b843c749SSergey Zigachev #endif 65*b843c749SSergey Zigachev }; 66*b843c749SSergey Zigachev u32 fb_div; 67*b843c749SSergey Zigachev }; 68*b843c749SSergey Zigachev u32 post_div; 69*b843c749SSergey Zigachev u32 bwcntl; 70*b843c749SSergey Zigachev u32 dll_speed; 71*b843c749SSergey Zigachev u32 vco_mode; 72*b843c749SSergey Zigachev u32 yclk_sel; 73*b843c749SSergey Zigachev u32 qdr; 74*b843c749SSergey Zigachev u32 half_rate; 75*b843c749SSergey Zigachev }; 76*b843c749SSergey Zigachev 77*b843c749SSergey Zigachev #define MEM_TYPE_GDDR5 0x50 78*b843c749SSergey Zigachev #define MEM_TYPE_GDDR4 0x40 79*b843c749SSergey Zigachev #define MEM_TYPE_GDDR3 0x30 80*b843c749SSergey Zigachev #define MEM_TYPE_DDR2 0x20 81*b843c749SSergey Zigachev #define MEM_TYPE_GDDR1 0x10 82*b843c749SSergey Zigachev #define MEM_TYPE_DDR3 0xb0 83*b843c749SSergey Zigachev #define MEM_TYPE_MASK 0xf0 84*b843c749SSergey Zigachev 85*b843c749SSergey Zigachev struct atom_memory_info { 86*b843c749SSergey Zigachev u8 mem_vendor; 87*b843c749SSergey Zigachev u8 mem_type; 88*b843c749SSergey Zigachev }; 89*b843c749SSergey Zigachev 90*b843c749SSergey Zigachev #define MAX_AC_TIMING_ENTRIES 16 91*b843c749SSergey Zigachev 92*b843c749SSergey Zigachev struct atom_memory_clock_range_table 93*b843c749SSergey Zigachev { 94*b843c749SSergey Zigachev u8 num_entries; 95*b843c749SSergey Zigachev u8 rsv[3]; 96*b843c749SSergey Zigachev u32 mclk[MAX_AC_TIMING_ENTRIES]; 97*b843c749SSergey Zigachev }; 98*b843c749SSergey Zigachev 99*b843c749SSergey Zigachev #define VBIOS_MC_REGISTER_ARRAY_SIZE 32 100*b843c749SSergey Zigachev #define VBIOS_MAX_AC_TIMING_ENTRIES 20 101*b843c749SSergey Zigachev 102*b843c749SSergey Zigachev struct atom_mc_reg_entry { 103*b843c749SSergey Zigachev u32 mclk_max; 104*b843c749SSergey Zigachev u32 mc_data[VBIOS_MC_REGISTER_ARRAY_SIZE]; 105*b843c749SSergey Zigachev }; 106*b843c749SSergey Zigachev 107*b843c749SSergey Zigachev struct atom_mc_register_address { 108*b843c749SSergey Zigachev u16 s1; 109*b843c749SSergey Zigachev u8 pre_reg_data; 110*b843c749SSergey Zigachev }; 111*b843c749SSergey Zigachev 112*b843c749SSergey Zigachev struct atom_mc_reg_table { 113*b843c749SSergey Zigachev u8 last; 114*b843c749SSergey Zigachev u8 num_entries; 115*b843c749SSergey Zigachev struct atom_mc_reg_entry mc_reg_table_entry[VBIOS_MAX_AC_TIMING_ENTRIES]; 116*b843c749SSergey Zigachev struct atom_mc_register_address mc_reg_address[VBIOS_MC_REGISTER_ARRAY_SIZE]; 117*b843c749SSergey Zigachev }; 118*b843c749SSergey Zigachev 119*b843c749SSergey Zigachev #define MAX_VOLTAGE_ENTRIES 32 120*b843c749SSergey Zigachev 121*b843c749SSergey Zigachev struct atom_voltage_table_entry 122*b843c749SSergey Zigachev { 123*b843c749SSergey Zigachev u16 value; 124*b843c749SSergey Zigachev u32 smio_low; 125*b843c749SSergey Zigachev }; 126*b843c749SSergey Zigachev 127*b843c749SSergey Zigachev struct atom_voltage_table 128*b843c749SSergey Zigachev { 129*b843c749SSergey Zigachev u32 count; 130*b843c749SSergey Zigachev u32 mask_low; 131*b843c749SSergey Zigachev u32 phase_delay; 132*b843c749SSergey Zigachev struct atom_voltage_table_entry entries[MAX_VOLTAGE_ENTRIES]; 133*b843c749SSergey Zigachev }; 134*b843c749SSergey Zigachev 135*b843c749SSergey Zigachev struct amdgpu_gpio_rec 136*b843c749SSergey Zigachev amdgpu_atombios_lookup_gpio(struct amdgpu_device *adev, 137*b843c749SSergey Zigachev u8 id); 138*b843c749SSergey Zigachev 139*b843c749SSergey Zigachev struct amdgpu_i2c_bus_rec amdgpu_atombios_lookup_i2c_gpio(struct amdgpu_device *adev, 140*b843c749SSergey Zigachev uint8_t id); 141*b843c749SSergey Zigachev void amdgpu_atombios_i2c_init(struct amdgpu_device *adev); 142*b843c749SSergey Zigachev 143*b843c749SSergey Zigachev bool amdgpu_atombios_has_dce_engine_info(struct amdgpu_device *adev); 144*b843c749SSergey Zigachev 145*b843c749SSergey Zigachev bool amdgpu_atombios_get_connector_info_from_object_table(struct amdgpu_device *adev); 146*b843c749SSergey Zigachev 147*b843c749SSergey Zigachev int amdgpu_atombios_get_clock_info(struct amdgpu_device *adev); 148*b843c749SSergey Zigachev 149*b843c749SSergey Zigachev int amdgpu_atombios_get_gfx_info(struct amdgpu_device *adev); 150*b843c749SSergey Zigachev 151*b843c749SSergey Zigachev int amdgpu_atombios_get_vram_width(struct amdgpu_device *adev); 152*b843c749SSergey Zigachev 153*b843c749SSergey Zigachev bool amdgpu_atombios_get_asic_ss_info(struct amdgpu_device *adev, 154*b843c749SSergey Zigachev struct amdgpu_atom_ss *ss, 155*b843c749SSergey Zigachev int id, u32 clock); 156*b843c749SSergey Zigachev 157*b843c749SSergey Zigachev int amdgpu_atombios_get_clock_dividers(struct amdgpu_device *adev, 158*b843c749SSergey Zigachev u8 clock_type, 159*b843c749SSergey Zigachev u32 clock, 160*b843c749SSergey Zigachev bool strobe_mode, 161*b843c749SSergey Zigachev struct atom_clock_dividers *dividers); 162*b843c749SSergey Zigachev 163*b843c749SSergey Zigachev int amdgpu_atombios_get_memory_pll_dividers(struct amdgpu_device *adev, 164*b843c749SSergey Zigachev u32 clock, 165*b843c749SSergey Zigachev bool strobe_mode, 166*b843c749SSergey Zigachev struct atom_mpll_param *mpll_param); 167*b843c749SSergey Zigachev 168*b843c749SSergey Zigachev void amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev, 169*b843c749SSergey Zigachev u32 eng_clock, u32 mem_clock); 170*b843c749SSergey Zigachev 171*b843c749SSergey Zigachev int amdgpu_atombios_get_leakage_id_from_vbios(struct amdgpu_device *adev, 172*b843c749SSergey Zigachev u16 *leakage_id); 173*b843c749SSergey Zigachev 174*b843c749SSergey Zigachev int amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(struct amdgpu_device *adev, 175*b843c749SSergey Zigachev u16 *vddc, u16 *vddci, 176*b843c749SSergey Zigachev u16 virtual_voltage_id, 177*b843c749SSergey Zigachev u16 vbios_voltage_id); 178*b843c749SSergey Zigachev 179*b843c749SSergey Zigachev int amdgpu_atombios_get_voltage_evv(struct amdgpu_device *adev, 180*b843c749SSergey Zigachev u16 virtual_voltage_id, 181*b843c749SSergey Zigachev u16 *voltage); 182*b843c749SSergey Zigachev 183*b843c749SSergey Zigachev bool 184*b843c749SSergey Zigachev amdgpu_atombios_is_voltage_gpio(struct amdgpu_device *adev, 185*b843c749SSergey Zigachev u8 voltage_type, u8 voltage_mode); 186*b843c749SSergey Zigachev 187*b843c749SSergey Zigachev int amdgpu_atombios_get_voltage_table(struct amdgpu_device *adev, 188*b843c749SSergey Zigachev u8 voltage_type, u8 voltage_mode, 189*b843c749SSergey Zigachev struct atom_voltage_table *voltage_table); 190*b843c749SSergey Zigachev 191*b843c749SSergey Zigachev int amdgpu_atombios_init_mc_reg_table(struct amdgpu_device *adev, 192*b843c749SSergey Zigachev u8 module_index, 193*b843c749SSergey Zigachev struct atom_mc_reg_table *reg_table); 194*b843c749SSergey Zigachev 195*b843c749SSergey Zigachev bool amdgpu_atombios_has_gpu_virtualization_table(struct amdgpu_device *adev); 196*b843c749SSergey Zigachev 197*b843c749SSergey Zigachev void amdgpu_atombios_scratch_regs_lock(struct amdgpu_device *adev, bool lock); 198*b843c749SSergey Zigachev void amdgpu_atombios_scratch_regs_engine_hung(struct amdgpu_device *adev, 199*b843c749SSergey Zigachev bool hung); 200*b843c749SSergey Zigachev bool amdgpu_atombios_scratch_need_asic_init(struct amdgpu_device *adev); 201*b843c749SSergey Zigachev 202*b843c749SSergey Zigachev void amdgpu_atombios_copy_swap(u8 *dst, u8 *src, u8 num_bytes, bool to_le); 203*b843c749SSergey Zigachev int amdgpu_atombios_get_max_vddc(struct amdgpu_device *adev, u8 voltage_type, 204*b843c749SSergey Zigachev u16 voltage_id, u16 *voltage); 205*b843c749SSergey Zigachev int amdgpu_atombios_get_leakage_vddc_based_on_leakage_idx(struct amdgpu_device *adev, 206*b843c749SSergey Zigachev u16 *voltage, 207*b843c749SSergey Zigachev u16 leakage_idx); 208*b843c749SSergey Zigachev void amdgpu_atombios_get_default_voltages(struct amdgpu_device *adev, 209*b843c749SSergey Zigachev u16 *vddc, u16 *vddci, u16 *mvdd); 210*b843c749SSergey Zigachev int amdgpu_atombios_get_svi2_info(struct amdgpu_device *adev, 211*b843c749SSergey Zigachev u8 voltage_type, 212*b843c749SSergey Zigachev u8 *svd_gpio_id, u8 *svc_gpio_id); 213*b843c749SSergey Zigachev 214*b843c749SSergey Zigachev void amdgpu_atombios_fini(struct amdgpu_device *adev); 215*b843c749SSergey Zigachev int amdgpu_atombios_init(struct amdgpu_device *adev); 216*b843c749SSergey Zigachev 217*b843c749SSergey Zigachev #endif 218