2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #include <linux/module.h>
24 #include <linux/slab.h>
26 #include "linux/delay.h"
30 #include "tonga_hwmgr.h"
32 #include "processpptables.h"
33 #include "tonga_processpptables.h"
34 #include "tonga_pptable.h"
36 #include "tonga_ppsmc.h"
37 #include "cgs_common.h"
38 #include "pppcielanes.h"
39 #include "tonga_dyn_defaults.h"
41 #include "tonga_smumgr.h"
42 #include "tonga_clockpowergating.h"
43 #include "tonga_thermal.h"
45 #include "smu/smu_7_1_2_d.h"
46 #include "smu/smu_7_1_2_sh_mask.h"
48 #include "gmc/gmc_8_1_d.h"
49 #include "gmc/gmc_8_1_sh_mask.h"
51 #include "bif/bif_5_0_d.h"
52 #include "bif/bif_5_0_sh_mask.h"
54 #include "cgs_linux.h"
57 #define MC_CG_ARB_FREQ_F0 0x0a
58 #define MC_CG_ARB_FREQ_F1 0x0b
59 #define MC_CG_ARB_FREQ_F2 0x0c
60 #define MC_CG_ARB_FREQ_F3 0x0d
62 #define MC_CG_SEQ_DRAMCONF_S0 0x05
63 #define MC_CG_SEQ_DRAMCONF_S1 0x06
64 #define MC_CG_SEQ_YCLK_SUSPEND 0x04
65 #define MC_CG_SEQ_YCLK_RESUME 0x0a
67 #define PCIE_BUS_CLK 10000
68 #define TCLK (PCIE_BUS_CLK / 10)
70 #define SMC_RAM_END 0x40000
71 #define SMC_CG_IND_START 0xc0030000
72 #define SMC_CG_IND_END 0xc0040000 /* First byte after SMC_CG_IND*/
74 #define VOLTAGE_SCALE 4
75 #define VOLTAGE_VID_OFFSET_SCALE1 625
76 #define VOLTAGE_VID_OFFSET_SCALE2 100
78 #define VDDC_VDDCI_DELTA 200
79 #define VDDC_VDDGFX_DELTA 300
81 #define MC_SEQ_MISC0_GDDR5_SHIFT 28
82 #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
83 #define MC_SEQ_MISC0_GDDR5_VALUE 5
85 typedef uint32_t PECI_RegistryValue;
87 /* [2.5%,~2.5%] Clock stretched is multiple of 2.5% vs not and [Fmin, Fmax, LDO_REFSEL, USE_FOR_LOW_FREQ] */
88 uint16_t PP_ClockStretcherLookupTable[2][4] = {
92 /* [FF, SS] type, [] 4 voltage ranges, and [Floor Freq, Boundary Freq, VID min , VID max] */
93 uint32_t PP_ClockStretcherDDTTable[2][4][4] = {
94 { {265, 529, 120, 128}, {325, 650, 96, 119}, {430, 860, 32, 95}, {0, 0, 0, 31} },
95 { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} } };
97 /* [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%] (coming from PWR_CKS_CNTL.stretch_amount reg spec) */
98 uint8_t PP_ClockStretchAmountConversion[2][6] = {
100 {0, 2, 4, 5, 6, 5} };
102 /* Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
104 DPM_EVENT_SRC_ANALOG = 0, /* Internal analog trip point */
105 DPM_EVENT_SRC_EXTERNAL = 1, /* External (GPIO 17) signal */
106 DPM_EVENT_SRC_DIGITAL = 2, /* Internal digital trip point (DIG_THERM_DPM) */
107 DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3, /* Internal analog or external */
108 DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4 /* Internal digital or external */
110 typedef enum DPM_EVENT_SRC DPM_EVENT_SRC;
113 DISPLAY_GAP_VBLANK_OR_WM = 0, /* Wait for vblank or MCHG watermark. */
114 DISPLAY_GAP_VBLANK = 1, /* Wait for vblank. */
115 DISPLAY_GAP_WATERMARK = 2, /* Wait for MCHG watermark. (Note that HW may deassert WM in VBI depending on DC_STUTTER_CNTL.) */
116 DISPLAY_GAP_IGNORE = 3 /* Do not wait. */
118 typedef enum DISPLAY_GAP DISPLAY_GAP;
120 const unsigned long PhwTonga_Magic = (unsigned long)(PHM_VIslands_Magic);
122 struct tonga_power_state *cast_phw_tonga_power_state(
123 struct pp_hw_power_state *hw_ps)
125 PP_ASSERT_WITH_CODE((PhwTonga_Magic == hw_ps->magic),
126 "Invalid Powerstate Type!",
129 return (struct tonga_power_state *)hw_ps;
132 const struct tonga_power_state *cast_const_phw_tonga_power_state(
133 const struct pp_hw_power_state *hw_ps)
135 PP_ASSERT_WITH_CODE((PhwTonga_Magic == hw_ps->magic),
136 "Invalid Powerstate Type!",
139 return (const struct tonga_power_state *)hw_ps;
142 int tonga_add_voltage(struct pp_hwmgr *hwmgr,
143 phm_ppt_v1_voltage_lookup_table *look_up_table,
144 phm_ppt_v1_voltage_lookup_record *record)
147 PP_ASSERT_WITH_CODE((NULL != look_up_table),
148 "Lookup Table empty.", return -1;);
149 PP_ASSERT_WITH_CODE((0 != look_up_table->count),
150 "Lookup Table empty.", return -1;);
151 PP_ASSERT_WITH_CODE((SMU72_MAX_LEVELS_VDDGFX >= look_up_table->count),
152 "Lookup Table is full.", return -1;);
154 /* This is to avoid entering duplicate calculated records. */
155 for (i = 0; i < look_up_table->count; i++) {
156 if (look_up_table->entries[i].us_vdd == record->us_vdd) {
157 if (look_up_table->entries[i].us_calculated == 1)
164 look_up_table->entries[i].us_calculated = 1;
165 look_up_table->entries[i].us_vdd = record->us_vdd;
166 look_up_table->entries[i].us_cac_low = record->us_cac_low;
167 look_up_table->entries[i].us_cac_mid = record->us_cac_mid;
168 look_up_table->entries[i].us_cac_high = record->us_cac_high;
169 /* Only increment the count when we're appending, not replacing duplicate entry. */
170 if (i == look_up_table->count)
171 look_up_table->count++;
176 int tonga_notify_smc_display_change(struct pp_hwmgr *hwmgr, bool has_display)
178 PPSMC_Msg msg = has_display? (PPSMC_Msg)PPSMC_HasDisplay : (PPSMC_Msg)PPSMC_NoDisplay;
180 return (smum_send_msg_to_smc(hwmgr->smumgr, msg) == 0) ? 0 : -1;
183 uint8_t tonga_get_voltage_id(pp_atomctrl_voltage_table *voltage_table,
186 uint8_t count = (uint8_t) (voltage_table->count);
189 PP_ASSERT_WITH_CODE((NULL != voltage_table),
190 "Voltage Table empty.", return 0;);
191 PP_ASSERT_WITH_CODE((0 != count),
192 "Voltage Table empty.", return 0;);
194 for (i = 0; i < count; i++) {
195 /* find first voltage bigger than requested */
196 if (voltage_table->entries[i].value >= voltage)
200 /* voltage is bigger than max voltage in the table */
205 * @brief PhwTonga_GetVoltageOrder
206 * Returns index of requested voltage record in lookup(table)
207 * @param hwmgr - pointer to hardware manager
208 * @param lookupTable - lookup list to search in
209 * @param voltage - voltage to look for
210 * @return 0 on success
212 uint8_t tonga_get_voltage_index(phm_ppt_v1_voltage_lookup_table *look_up_table,
215 uint8_t count = (uint8_t) (look_up_table->count);
218 PP_ASSERT_WITH_CODE((NULL != look_up_table), "Lookup Table empty.", return 0;);
219 PP_ASSERT_WITH_CODE((0 != count), "Lookup Table empty.", return 0;);
221 for (i = 0; i < count; i++) {
222 /* find first voltage equal or bigger than requested */
223 if (look_up_table->entries[i].us_vdd >= voltage)
227 /* voltage is bigger than max voltage in the table */
231 bool tonga_is_dpm_running(struct pp_hwmgr *hwmgr)
234 * We return the status of Voltage Control instead of checking SCLK/MCLK DPM
235 * because we may have test scenarios that need us intentionly disable SCLK/MCLK DPM,
236 * whereas voltage control is a fundemental change that will not be disabled
239 return (0 == PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
240 FEATURE_STATUS, VOLTAGE_CONTROLLER_ON) ? 1 : 0);
244 * Re-generate the DPM level mask value
245 * @param hwmgr the address of the hardware manager
247 static uint32_t tonga_get_dpm_level_enable_mask_value(
248 struct tonga_single_dpm_table * dpm_table)
251 uint32_t mask_value = 0;
253 for (i = dpm_table->count; i > 0; i--) {
254 mask_value = mask_value << 1;
256 if (dpm_table->dpm_levels[i-1].enabled)
259 mask_value &= 0xFFFFFFFE;
265 * Retrieve DPM default values from registry (if available)
267 * @param hwmgr the address of the powerplay hardware manager.
269 void tonga_initialize_dpm_defaults(struct pp_hwmgr *hwmgr)
271 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
272 phw_tonga_ulv_parm *ulv = &(data->ulv);
275 ulv->ch_ulv_parameter = PPTONGA_CGULVPARAMETER_DFLT;
276 data->voting_rights_clients0 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT0;
277 data->voting_rights_clients1 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT1;
278 data->voting_rights_clients2 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT2;
279 data->voting_rights_clients3 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT3;
280 data->voting_rights_clients4 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT4;
281 data->voting_rights_clients5 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT5;
282 data->voting_rights_clients6 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT6;
283 data->voting_rights_clients7 = PPTONGA_VOTINGRIGHTSCLIENTS_DFLT7;
285 data->static_screen_threshold_unit = PPTONGA_STATICSCREENTHRESHOLDUNIT_DFLT;
286 data->static_screen_threshold = PPTONGA_STATICSCREENTHRESHOLD_DFLT;
288 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
289 PHM_PlatformCaps_ABM);
290 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
291 PHM_PlatformCaps_NonABMSupportInPPLib);
295 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
296 PHM_PlatformCaps_DynamicACTiming);
300 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
301 PHM_PlatformCaps_DisableMemoryTransition);
303 data->mclk_strobe_mode_threshold = 40000;
304 data->mclk_stutter_mode_threshold = 30000;
305 data->mclk_edc_enable_threshold = 40000;
306 data->mclk_edc_wr_enable_threshold = 40000;
310 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
311 PHM_PlatformCaps_DisableMCLS);
313 data->pcie_gen_performance.max = PP_PCIEGen1;
314 data->pcie_gen_performance.min = PP_PCIEGen3;
315 data->pcie_gen_power_saving.max = PP_PCIEGen1;
316 data->pcie_gen_power_saving.min = PP_PCIEGen3;
318 data->pcie_lane_performance.max = 0;
319 data->pcie_lane_performance.min = 16;
320 data->pcie_lane_power_saving.max = 0;
321 data->pcie_lane_power_saving.min = 16;
326 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
327 PHM_PlatformCaps_SclkThrottleLowNotification);
329 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
330 PHM_PlatformCaps_DynamicUVDState);
334 int tonga_update_sclk_threshold(struct pp_hwmgr *hwmgr)
336 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
339 uint32_t low_sclk_interrupt_threshold = 0;
341 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
342 PHM_PlatformCaps_SclkThrottleLowNotification)
343 && (hwmgr->gfx_arbiter.sclk_threshold != data->low_sclk_interrupt_threshold)) {
344 data->low_sclk_interrupt_threshold = hwmgr->gfx_arbiter.sclk_threshold;
345 low_sclk_interrupt_threshold = data->low_sclk_interrupt_threshold;
347 CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
349 result = tonga_copy_bytes_to_smc(
351 data->dpm_table_start + offsetof(SMU72_Discrete_DpmTable,
352 LowSclkInterruptThreshold),
353 (uint8_t *)&low_sclk_interrupt_threshold,
363 * Find SCLK value that is associated with specified virtual_voltage_Id.
365 * @param hwmgr the address of the powerplay hardware manager.
366 * @param virtual_voltage_Id voltageId to look for.
367 * @param sclk output value .
368 * @return always 0 if success and 2 if association not found
370 static int tonga_get_sclk_for_voltage_evv(struct pp_hwmgr *hwmgr,
371 phm_ppt_v1_voltage_lookup_table *lookup_table,
372 uint16_t virtual_voltage_id, uint32_t *sclk)
376 struct phm_ppt_v1_information *pptable_info =
377 (struct phm_ppt_v1_information *)(hwmgr->pptable);
379 PP_ASSERT_WITH_CODE(lookup_table->count != 0, "Lookup table is empty", return -1);
381 /* search for leakage voltage ID 0xff01 ~ 0xff08 and sckl */
382 for (entryId = 0; entryId < pptable_info->vdd_dep_on_sclk->count; entryId++) {
383 voltageId = pptable_info->vdd_dep_on_sclk->entries[entryId].vddInd;
384 if (lookup_table->entries[voltageId].us_vdd == virtual_voltage_id)
388 PP_ASSERT_WITH_CODE(entryId < pptable_info->vdd_dep_on_sclk->count,
389 "Can't find requested voltage id in vdd_dep_on_sclk table!",
393 *sclk = pptable_info->vdd_dep_on_sclk->entries[entryId].clk;
399 * Get Leakage VDDC based on leakage ID.
401 * @param hwmgr the address of the powerplay hardware manager.
402 * @return 2 if vddgfx returned is greater than 2V or if BIOS
404 int tonga_get_evv_voltage(struct pp_hwmgr *hwmgr)
406 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
407 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
408 phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk;
409 uint16_t virtual_voltage_id;
415 /* retrieve voltage for leakage ID (0xff01 + i) */
416 for (i = 0; i < TONGA_MAX_LEAKAGE_COUNT; i++) {
417 virtual_voltage_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
419 /* in split mode we should have only vddgfx EVV leakages */
420 if (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) {
421 if (0 == tonga_get_sclk_for_voltage_evv(hwmgr,
422 pptable_info->vddgfx_lookup_table, virtual_voltage_id, &sclk)) {
423 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
424 PHM_PlatformCaps_ClockStretcher)) {
425 for (j = 1; j < sclk_table->count; j++) {
426 if (sclk_table->entries[j].clk == sclk &&
427 sclk_table->entries[j].cks_enable == 0) {
433 PP_ASSERT_WITH_CODE(0 == atomctrl_get_voltage_evv_on_sclk
434 (hwmgr, VOLTAGE_TYPE_VDDGFX, sclk,
435 virtual_voltage_id, &vddgfx),
436 "Error retrieving EVV voltage value!", continue);
438 /* need to make sure vddgfx is less than 2v or else, it could burn the ASIC. */
439 PP_ASSERT_WITH_CODE((vddgfx < 2000 && vddgfx != 0), "Invalid VDDGFX value!", return -1);
441 /* the voltage should not be zero nor equal to leakage ID */
442 if (vddgfx != 0 && vddgfx != virtual_voltage_id) {
443 data->vddcgfx_leakage.actual_voltage[data->vddcgfx_leakage.count] = vddgfx;
444 data->vddcgfx_leakage.leakage_id[data->vddcgfx_leakage.count] = virtual_voltage_id;
445 data->vddcgfx_leakage.count++;
449 /* in merged mode we have only vddc EVV leakages */
450 if (0 == tonga_get_sclk_for_voltage_evv(hwmgr,
451 pptable_info->vddc_lookup_table,
452 virtual_voltage_id, &sclk)) {
453 PP_ASSERT_WITH_CODE(0 == atomctrl_get_voltage_evv_on_sclk
454 (hwmgr, VOLTAGE_TYPE_VDDC, sclk,
455 virtual_voltage_id, &vddc),
456 "Error retrieving EVV voltage value!", continue);
458 /* need to make sure vddc is less than 2v or else, it could burn the ASIC. */
460 printk(KERN_ERR "[ powerplay ] Invalid VDDC value! \n");
462 /* the voltage should not be zero nor equal to leakage ID */
463 if (vddc != 0 && vddc != virtual_voltage_id) {
464 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = vddc;
465 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = virtual_voltage_id;
466 data->vddc_leakage.count++;
475 int tonga_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
477 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
479 /* enable SCLK dpm */
480 if (0 == data->sclk_dpm_key_disabled) {
482 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
483 PPSMC_MSG_DPM_Enable)),
484 "Failed to enable SCLK DPM during DPM Start Function!",
488 /* enable MCLK dpm */
489 if (0 == data->mclk_dpm_key_disabled) {
491 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
492 PPSMC_MSG_MCLKDPM_Enable)),
493 "Failed to enable MCLK DPM during DPM Start Function!",
496 PHM_WRITE_FIELD(hwmgr->device, MC_SEQ_CNTL_3, CAC_EN, 0x1);
498 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
499 ixLCAC_MC0_CNTL, 0x05);/* CH0,1 read */
500 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
501 ixLCAC_MC1_CNTL, 0x05);/* CH2,3 read */
502 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
503 ixLCAC_CPL_CNTL, 0x100005);/*Read */
507 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
508 ixLCAC_MC0_CNTL, 0x400005);/* CH0,1 write */
509 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
510 ixLCAC_MC1_CNTL, 0x400005);/* CH2,3 write */
511 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
512 ixLCAC_CPL_CNTL, 0x500005);/* write */
519 int tonga_start_dpm(struct pp_hwmgr *hwmgr)
521 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
523 /* enable general power management */
524 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, 1);
525 /* enable sclk deep sleep */
526 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL, DYNAMIC_PM_EN, 1);
528 /* prepare for PCIE DPM */
529 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, data->soft_regs_start +
530 offsetof(SMU72_SoftRegisters, VoltageChangeTimeout), 0x1000);
532 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE, SWRST_COMMAND_1, RESETLC, 0x0);
535 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
536 PPSMC_MSG_Voltage_Cntl_Enable)),
537 "Failed to enable voltage DPM during DPM Start Function!",
540 if (0 != tonga_enable_sclk_mclk_dpm(hwmgr)) {
541 PP_ASSERT_WITH_CODE(0, "Failed to enable Sclk DPM and Mclk DPM!", return -1);
544 /* enable PCIE dpm */
545 if (0 == data->pcie_dpm_key_disabled) {
547 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
548 PPSMC_MSG_PCIeDPM_Enable)),
549 "Failed to enable pcie DPM during DPM Start Function!",
554 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
555 PHM_PlatformCaps_Falcon_QuickTransition)) {
556 smum_send_msg_to_smc(hwmgr->smumgr,
557 PPSMC_MSG_EnableACDCGPIOInterrupt);
563 int tonga_disable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
565 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
567 /* disable SCLK dpm */
568 if (0 == data->sclk_dpm_key_disabled) {
569 /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/
571 (0 == tonga_is_dpm_running(hwmgr)),
572 "Trying to Disable SCLK DPM when DPM is disabled",
577 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
578 PPSMC_MSG_DPM_Disable)),
579 "Failed to disable SCLK DPM during DPM stop Function!",
583 /* disable MCLK dpm */
584 if (0 == data->mclk_dpm_key_disabled) {
585 /* Checking if DPM is running. If we discover hang because of this, we should skip this message. */
587 (0 == tonga_is_dpm_running(hwmgr)),
588 "Trying to Disable MCLK DPM when DPM is disabled",
593 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
594 PPSMC_MSG_MCLKDPM_Disable)),
595 "Failed to Disable MCLK DPM during DPM stop Function!",
602 int tonga_stop_dpm(struct pp_hwmgr *hwmgr)
604 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
606 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, 0);
607 /* disable sclk deep sleep*/
608 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL, DYNAMIC_PM_EN, 0);
610 /* disable PCIE dpm */
611 if (0 == data->pcie_dpm_key_disabled) {
612 /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/
614 (0 == tonga_is_dpm_running(hwmgr)),
615 "Trying to Disable PCIE DPM when DPM is disabled",
619 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
620 PPSMC_MSG_PCIeDPM_Disable)),
621 "Failed to disable pcie DPM during DPM stop Function!",
625 if (0 != tonga_disable_sclk_mclk_dpm(hwmgr))
626 PP_ASSERT_WITH_CODE(0, "Failed to disable Sclk DPM and Mclk DPM!", return -1);
628 /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/
630 (0 == tonga_is_dpm_running(hwmgr)),
631 "Trying to Disable Voltage CNTL when DPM is disabled",
636 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
637 PPSMC_MSG_Voltage_Cntl_Disable)),
638 "Failed to disable voltage DPM during DPM stop Function!",
644 int tonga_enable_sclk_control(struct pp_hwmgr *hwmgr)
646 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL, SCLK_PWRMGT_OFF, 0);
652 * Send a message to the SMC and return a parameter
654 * @param hwmgr: the address of the powerplay hardware manager.
655 * @param msg: the message to send.
656 * @param parameter: pointer to the received parameter
657 * @return The response that came from the SMC.
659 PPSMC_Result tonga_send_msg_to_smc_return_parameter(
660 struct pp_hwmgr *hwmgr,
666 result = smum_send_msg_to_smc(hwmgr->smumgr, msg);
668 if ((0 == result) && parameter) {
669 *parameter = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
676 * force DPM power State
678 * @param hwmgr: the address of the powerplay hardware manager.
679 * @param n : DPM level
680 * @return The response that came from the SMC.
682 int tonga_dpm_force_state(struct pp_hwmgr *hwmgr, uint32_t n)
684 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
685 uint32_t level_mask = 1 << n;
687 /* Checking if DPM is running. If we discover hang because of this, we should skip this message. */
688 PP_ASSERT_WITH_CODE(0 == tonga_is_dpm_running(hwmgr),
689 "Trying to force SCLK when DPM is disabled", return -1;);
690 if (0 == data->sclk_dpm_key_disabled)
691 return (0 == smum_send_msg_to_smc_with_parameter(
693 (PPSMC_Msg)(PPSMC_MSG_SCLKDPM_SetEnabledMask),
694 level_mask) ? 0 : 1);
700 * force DPM power State
702 * @param hwmgr: the address of the powerplay hardware manager.
703 * @param n : DPM level
704 * @return The response that came from the SMC.
706 int tonga_dpm_force_state_mclk(struct pp_hwmgr *hwmgr, uint32_t n)
708 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
709 uint32_t level_mask = 1 << n;
711 /* Checking if DPM is running. If we discover hang because of this, we should skip this message. */
712 PP_ASSERT_WITH_CODE(0 == tonga_is_dpm_running(hwmgr),
713 "Trying to Force MCLK when DPM is disabled", return -1;);
714 if (0 == data->mclk_dpm_key_disabled)
715 return (0 == smum_send_msg_to_smc_with_parameter(
717 (PPSMC_Msg)(PPSMC_MSG_MCLKDPM_SetEnabledMask),
718 level_mask) ? 0 : 1);
724 * force DPM power State
726 * @param hwmgr: the address of the powerplay hardware manager.
727 * @param n : DPM level
728 * @return The response that came from the SMC.
730 int tonga_dpm_force_state_pcie(struct pp_hwmgr *hwmgr, uint32_t n)
732 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
734 /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/
735 PP_ASSERT_WITH_CODE(0 == tonga_is_dpm_running(hwmgr),
736 "Trying to Force PCIE level when DPM is disabled", return -1;);
737 if (0 == data->pcie_dpm_key_disabled)
738 return (0 == smum_send_msg_to_smc_with_parameter(
740 (PPSMC_Msg)(PPSMC_MSG_PCIeDPM_ForceLevel),
747 * Set the initial state by calling SMC to switch to this state directly
749 * @param hwmgr the address of the powerplay hardware manager.
752 int tonga_set_boot_state(struct pp_hwmgr *hwmgr)
755 * SMC only stores one state that SW will ask to switch too,
756 * so we switch the the just uploaded one
758 return (0 == tonga_disable_sclk_mclk_dpm(hwmgr)) ? 0 : 1;
762 * Get the location of various tables inside the FW image.
764 * @param hwmgr the address of the powerplay hardware manager.
767 int tonga_process_firmware_header(struct pp_hwmgr *hwmgr)
769 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
770 struct tonga_smumgr *tonga_smu = (struct tonga_smumgr *)(hwmgr->smumgr->backend);
776 result = tonga_read_smc_sram_dword(hwmgr->smumgr,
777 SMU72_FIRMWARE_HEADER_LOCATION +
778 offsetof(SMU72_Firmware_Header, DpmTable),
779 &tmp, data->sram_end);
782 data->dpm_table_start = tmp;
785 error |= (0 != result);
787 result = tonga_read_smc_sram_dword(hwmgr->smumgr,
788 SMU72_FIRMWARE_HEADER_LOCATION +
789 offsetof(SMU72_Firmware_Header, SoftRegisters),
790 &tmp, data->sram_end);
793 data->soft_regs_start = tmp;
794 tonga_smu->ulSoftRegsStart = tmp;
797 error |= (0 != result);
800 result = tonga_read_smc_sram_dword(hwmgr->smumgr,
801 SMU72_FIRMWARE_HEADER_LOCATION +
802 offsetof(SMU72_Firmware_Header, mcRegisterTable),
803 &tmp, data->sram_end);
806 data->mc_reg_table_start = tmp;
809 result = tonga_read_smc_sram_dword(hwmgr->smumgr,
810 SMU72_FIRMWARE_HEADER_LOCATION +
811 offsetof(SMU72_Firmware_Header, FanTable),
812 &tmp, data->sram_end);
815 data->fan_table_start = tmp;
818 error |= (0 != result);
820 result = tonga_read_smc_sram_dword(hwmgr->smumgr,
821 SMU72_FIRMWARE_HEADER_LOCATION +
822 offsetof(SMU72_Firmware_Header, mcArbDramTimingTable),
823 &tmp, data->sram_end);
826 data->arb_table_start = tmp;
829 error |= (0 != result);
832 result = tonga_read_smc_sram_dword(hwmgr->smumgr,
833 SMU72_FIRMWARE_HEADER_LOCATION +
834 offsetof(SMU72_Firmware_Header, Version),
835 &tmp, data->sram_end);
838 hwmgr->microcode_version_info.SMC = tmp;
841 error |= (0 != result);
843 return error ? 1 : 0;
847 * Read clock related registers.
849 * @param hwmgr the address of the powerplay hardware manager.
852 int tonga_read_clock_registers(struct pp_hwmgr *hwmgr)
854 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
856 data->clock_registers.vCG_SPLL_FUNC_CNTL =
857 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL);
858 data->clock_registers.vCG_SPLL_FUNC_CNTL_2 =
859 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_2);
860 data->clock_registers.vCG_SPLL_FUNC_CNTL_3 =
861 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_3);
862 data->clock_registers.vCG_SPLL_FUNC_CNTL_4 =
863 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_FUNC_CNTL_4);
864 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM =
865 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM);
866 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 =
867 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_SPLL_SPREAD_SPECTRUM_2);
868 data->clock_registers.vDLL_CNTL =
869 cgs_read_register(hwmgr->device, mmDLL_CNTL);
870 data->clock_registers.vMCLK_PWRMGT_CNTL =
871 cgs_read_register(hwmgr->device, mmMCLK_PWRMGT_CNTL);
872 data->clock_registers.vMPLL_AD_FUNC_CNTL =
873 cgs_read_register(hwmgr->device, mmMPLL_AD_FUNC_CNTL);
874 data->clock_registers.vMPLL_DQ_FUNC_CNTL =
875 cgs_read_register(hwmgr->device, mmMPLL_DQ_FUNC_CNTL);
876 data->clock_registers.vMPLL_FUNC_CNTL =
877 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL);
878 data->clock_registers.vMPLL_FUNC_CNTL_1 =
879 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_1);
880 data->clock_registers.vMPLL_FUNC_CNTL_2 =
881 cgs_read_register(hwmgr->device, mmMPLL_FUNC_CNTL_2);
882 data->clock_registers.vMPLL_SS1 =
883 cgs_read_register(hwmgr->device, mmMPLL_SS1);
884 data->clock_registers.vMPLL_SS2 =
885 cgs_read_register(hwmgr->device, mmMPLL_SS2);
891 * Find out if memory is GDDR5.
893 * @param hwmgr the address of the powerplay hardware manager.
896 int tonga_get_memory_type(struct pp_hwmgr *hwmgr)
898 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
901 temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0);
903 data->is_memory_GDDR5 = (MC_SEQ_MISC0_GDDR5_VALUE ==
904 ((temp & MC_SEQ_MISC0_GDDR5_MASK) >>
905 MC_SEQ_MISC0_GDDR5_SHIFT));
911 * Enables Dynamic Power Management by SMC
913 * @param hwmgr the address of the powerplay hardware manager.
916 int tonga_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
918 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, STATIC_PM_EN, 1);
924 * Initialize PowerGating States for different engines
926 * @param hwmgr the address of the powerplay hardware manager.
929 int tonga_init_power_gate_state(struct pp_hwmgr *hwmgr)
931 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
933 data->uvd_power_gated = 0;
934 data->vce_power_gated = 0;
935 data->samu_power_gated = 0;
936 data->acp_power_gated = 0;
937 data->pg_acp_init = 1;
943 * Checks if DPM is enabled
945 * @param hwmgr the address of the powerplay hardware manager.
948 int tonga_check_for_dpm_running(struct pp_hwmgr *hwmgr)
951 * We return the status of Voltage Control instead of checking SCLK/MCLK DPM
952 * because we may have test scenarios that need us intentionly disable SCLK/MCLK DPM,
953 * whereas voltage control is a fundemental change that will not be disabled
955 return (0 == tonga_is_dpm_running(hwmgr) ? 0 : 1);
959 * Checks if DPM is stopped
961 * @param hwmgr the address of the powerplay hardware manager.
964 int tonga_check_for_dpm_stopped(struct pp_hwmgr *hwmgr)
966 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
968 if (0 != tonga_is_dpm_running(hwmgr)) {
969 /* If HW Virtualization is enabled, dpm_table_start will not have a valid value */
970 if (!data->dpm_table_start) {
979 * Remove repeated voltage values and create table with unique values.
981 * @param hwmgr the address of the powerplay hardware manager.
982 * @param voltage_table the pointer to changing voltage table
983 * @return 1 in success
986 static int tonga_trim_voltage_table(struct pp_hwmgr *hwmgr,
987 pp_atomctrl_voltage_table *voltage_table)
989 uint32_t table_size, i, j;
991 bool bVoltageFound = 0;
992 pp_atomctrl_voltage_table *table;
994 PP_ASSERT_WITH_CODE((NULL != voltage_table), "Voltage Table empty.", return -1;);
995 table_size = sizeof(pp_atomctrl_voltage_table);
996 table = kzalloc(table_size, GFP_KERNEL);
1001 memset(table, 0x00, table_size);
1002 table->mask_low = voltage_table->mask_low;
1003 table->phase_delay = voltage_table->phase_delay;
1005 for (i = 0; i < voltage_table->count; i++) {
1006 vvalue = voltage_table->entries[i].value;
1009 for (j = 0; j < table->count; j++) {
1010 if (vvalue == table->entries[j].value) {
1016 if (!bVoltageFound) {
1017 table->entries[table->count].value = vvalue;
1018 table->entries[table->count].smio_low =
1019 voltage_table->entries[i].smio_low;
1024 memcpy(table, voltage_table, sizeof(pp_atomctrl_voltage_table));
1031 static int tonga_get_svi2_vdd_ci_voltage_table(
1032 struct pp_hwmgr *hwmgr,
1033 phm_ppt_v1_clock_voltage_dependency_table *voltage_dependency_table)
1037 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1038 pp_atomctrl_voltage_table *vddci_voltage_table = &(data->vddci_voltage_table);
1040 PP_ASSERT_WITH_CODE((0 != voltage_dependency_table->count),
1041 "Voltage Dependency Table empty.", return -1;);
1043 vddci_voltage_table->mask_low = 0;
1044 vddci_voltage_table->phase_delay = 0;
1045 vddci_voltage_table->count = voltage_dependency_table->count;
1047 for (i = 0; i < voltage_dependency_table->count; i++) {
1048 vddci_voltage_table->entries[i].value =
1049 voltage_dependency_table->entries[i].vddci;
1050 vddci_voltage_table->entries[i].smio_low = 0;
1053 result = tonga_trim_voltage_table(hwmgr, vddci_voltage_table);
1054 PP_ASSERT_WITH_CODE((0 == result),
1055 "Failed to trim VDDCI table.", return result;);
1062 static int tonga_get_svi2_vdd_voltage_table(
1063 struct pp_hwmgr *hwmgr,
1064 phm_ppt_v1_voltage_lookup_table *look_up_table,
1065 pp_atomctrl_voltage_table *voltage_table)
1069 PP_ASSERT_WITH_CODE((0 != look_up_table->count),
1070 "Voltage Lookup Table empty.", return -1;);
1072 voltage_table->mask_low = 0;
1073 voltage_table->phase_delay = 0;
1075 voltage_table->count = look_up_table->count;
1077 for (i = 0; i < voltage_table->count; i++) {
1078 voltage_table->entries[i].value = look_up_table->entries[i].us_vdd;
1079 voltage_table->entries[i].smio_low = 0;
1086 * -------------------------------------------------------- Voltage Tables --------------------------------------------------------------------------
1087 * If the voltage table would be bigger than what will fit into the state table on the SMC keep only the higher entries.
1090 static void tonga_trim_voltage_table_to_fit_state_table(
1091 struct pp_hwmgr *hwmgr,
1092 uint32_t max_voltage_steps,
1093 pp_atomctrl_voltage_table *voltage_table)
1095 unsigned int i, diff;
1097 if (voltage_table->count <= max_voltage_steps) {
1101 diff = voltage_table->count - max_voltage_steps;
1103 for (i = 0; i < max_voltage_steps; i++) {
1104 voltage_table->entries[i] = voltage_table->entries[i + diff];
1107 voltage_table->count = max_voltage_steps;
1113 * Create Voltage Tables.
1115 * @param hwmgr the address of the powerplay hardware manager.
1118 int tonga_construct_voltage_tables(struct pp_hwmgr *hwmgr)
1120 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1121 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
1124 /* MVDD has only GPIO voltage control */
1125 if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
1126 result = atomctrl_get_voltage_table_v3(hwmgr,
1127 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT, &(data->mvdd_voltage_table));
1128 PP_ASSERT_WITH_CODE((0 == result),
1129 "Failed to retrieve MVDD table.", return result;);
1132 if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->vdd_ci_control) {
1134 result = atomctrl_get_voltage_table_v3(hwmgr,
1135 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT, &(data->vddci_voltage_table));
1136 PP_ASSERT_WITH_CODE((0 == result),
1137 "Failed to retrieve VDDCI table.", return result;);
1138 } else if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_ci_control) {
1140 result = tonga_get_svi2_vdd_ci_voltage_table(hwmgr,
1141 pptable_info->vdd_dep_on_mclk);
1142 PP_ASSERT_WITH_CODE((0 == result),
1143 "Failed to retrieve SVI2 VDDCI table from dependancy table.", return result;);
1146 if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) {
1147 /* VDDGFX has only SVI2 voltage control */
1148 result = tonga_get_svi2_vdd_voltage_table(hwmgr,
1149 pptable_info->vddgfx_lookup_table, &(data->vddgfx_voltage_table));
1150 PP_ASSERT_WITH_CODE((0 == result),
1151 "Failed to retrieve SVI2 VDDGFX table from lookup table.", return result;);
1154 if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
1155 /* VDDC has only SVI2 voltage control */
1156 result = tonga_get_svi2_vdd_voltage_table(hwmgr,
1157 pptable_info->vddc_lookup_table, &(data->vddc_voltage_table));
1158 PP_ASSERT_WITH_CODE((0 == result),
1159 "Failed to retrieve SVI2 VDDC table from lookup table.", return result;);
1162 PP_ASSERT_WITH_CODE(
1163 (data->vddc_voltage_table.count <= (SMU72_MAX_LEVELS_VDDC)),
1164 "Too many voltage values for VDDC. Trimming to fit state table.",
1165 tonga_trim_voltage_table_to_fit_state_table(hwmgr,
1166 SMU72_MAX_LEVELS_VDDC, &(data->vddc_voltage_table));
1169 PP_ASSERT_WITH_CODE(
1170 (data->vddgfx_voltage_table.count <= (SMU72_MAX_LEVELS_VDDGFX)),
1171 "Too many voltage values for VDDGFX. Trimming to fit state table.",
1172 tonga_trim_voltage_table_to_fit_state_table(hwmgr,
1173 SMU72_MAX_LEVELS_VDDGFX, &(data->vddgfx_voltage_table));
1176 PP_ASSERT_WITH_CODE(
1177 (data->vddci_voltage_table.count <= (SMU72_MAX_LEVELS_VDDCI)),
1178 "Too many voltage values for VDDCI. Trimming to fit state table.",
1179 tonga_trim_voltage_table_to_fit_state_table(hwmgr,
1180 SMU72_MAX_LEVELS_VDDCI, &(data->vddci_voltage_table));
1183 PP_ASSERT_WITH_CODE(
1184 (data->mvdd_voltage_table.count <= (SMU72_MAX_LEVELS_MVDD)),
1185 "Too many voltage values for MVDD. Trimming to fit state table.",
1186 tonga_trim_voltage_table_to_fit_state_table(hwmgr,
1187 SMU72_MAX_LEVELS_MVDD, &(data->mvdd_voltage_table));
1194 * Vddc table preparation for SMC.
1196 * @param hwmgr the address of the hardware manager
1197 * @param table the SMC DPM table structure to be populated
1200 static int tonga_populate_smc_vddc_table(struct pp_hwmgr *hwmgr,
1201 SMU72_Discrete_DpmTable *table)
1204 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1206 if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
1207 table->VddcLevelCount = data->vddc_voltage_table.count;
1208 for (count = 0; count < table->VddcLevelCount; count++) {
1209 table->VddcTable[count] =
1210 PP_HOST_TO_SMC_US(data->vddc_voltage_table.entries[count].value * VOLTAGE_SCALE);
1212 CONVERT_FROM_HOST_TO_SMC_UL(table->VddcLevelCount);
1218 * VddGfx table preparation for SMC.
1220 * @param hwmgr the address of the hardware manager
1221 * @param table the SMC DPM table structure to be populated
1224 static int tonga_populate_smc_vdd_gfx_table(struct pp_hwmgr *hwmgr,
1225 SMU72_Discrete_DpmTable *table)
1228 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1230 if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) {
1231 table->VddGfxLevelCount = data->vddgfx_voltage_table.count;
1232 for (count = 0; count < data->vddgfx_voltage_table.count; count++) {
1233 table->VddGfxTable[count] =
1234 PP_HOST_TO_SMC_US(data->vddgfx_voltage_table.entries[count].value * VOLTAGE_SCALE);
1236 CONVERT_FROM_HOST_TO_SMC_UL(table->VddGfxLevelCount);
1242 * Vddci table preparation for SMC.
1244 * @param *hwmgr The address of the hardware manager.
1245 * @param *table The SMC DPM table structure to be populated.
1248 static int tonga_populate_smc_vdd_ci_table(struct pp_hwmgr *hwmgr,
1249 SMU72_Discrete_DpmTable *table)
1251 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1254 table->VddciLevelCount = data->vddci_voltage_table.count;
1255 for (count = 0; count < table->VddciLevelCount; count++) {
1256 if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_ci_control) {
1257 table->VddciTable[count] =
1258 PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[count].value * VOLTAGE_SCALE);
1259 } else if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->vdd_ci_control) {
1260 table->SmioTable1.Pattern[count].Voltage =
1261 PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[count].value * VOLTAGE_SCALE);
1262 /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level. */
1263 table->SmioTable1.Pattern[count].Smio =
1265 table->Smio[count] |=
1266 data->vddci_voltage_table.entries[count].smio_low;
1267 table->VddciTable[count] =
1268 PP_HOST_TO_SMC_US(data->vddci_voltage_table.entries[count].value * VOLTAGE_SCALE);
1272 table->SmioMask1 = data->vddci_voltage_table.mask_low;
1273 CONVERT_FROM_HOST_TO_SMC_UL(table->VddciLevelCount);
1279 * Mvdd table preparation for SMC.
1281 * @param *hwmgr The address of the hardware manager.
1282 * @param *table The SMC DPM table structure to be populated.
1285 static int tonga_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
1286 SMU72_Discrete_DpmTable *table)
1288 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1291 if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
1292 table->MvddLevelCount = data->mvdd_voltage_table.count;
1293 for (count = 0; count < table->MvddLevelCount; count++) {
1294 table->SmioTable2.Pattern[count].Voltage =
1295 PP_HOST_TO_SMC_US(data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE);
1296 /* Index into DpmTable.Smio. Drive bits from Smio entry to get this voltage level.*/
1297 table->SmioTable2.Pattern[count].Smio =
1299 table->Smio[count] |=
1300 data->mvdd_voltage_table.entries[count].smio_low;
1302 table->SmioMask2 = data->vddci_voltage_table.mask_low;
1304 CONVERT_FROM_HOST_TO_SMC_UL(table->MvddLevelCount);
1311 * Convert a voltage value in mv unit to VID number required by SMU firmware
1313 static uint8_t convert_to_vid(uint16_t vddc)
1315 return (uint8_t) ((6200 - (vddc * VOLTAGE_SCALE)) / 25);
1320 * Preparation of vddc and vddgfx CAC tables for SMC.
1322 * @param hwmgr the address of the hardware manager
1323 * @param table the SMC DPM table structure to be populated
1326 static int tonga_populate_cac_tables(struct pp_hwmgr *hwmgr,
1327 SMU72_Discrete_DpmTable *table)
1332 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1333 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
1334 struct phm_ppt_v1_voltage_lookup_table *vddgfx_lookup_table = pptable_info->vddgfx_lookup_table;
1335 struct phm_ppt_v1_voltage_lookup_table *vddc_lookup_table = pptable_info->vddc_lookup_table;
1337 /* pTables is already swapped, so in order to use the value from it, we need to swap it back. */
1338 uint32_t vddcLevelCount = PP_SMC_TO_HOST_UL(table->VddcLevelCount);
1339 uint32_t vddgfxLevelCount = PP_SMC_TO_HOST_UL(table->VddGfxLevelCount);
1341 for (count = 0; count < vddcLevelCount; count++) {
1342 /* We are populating vddc CAC data to BapmVddc table in split and merged mode */
1343 index = tonga_get_voltage_index(vddc_lookup_table,
1344 data->vddc_voltage_table.entries[count].value);
1345 table->BapmVddcVidLoSidd[count] =
1346 convert_to_vid(vddc_lookup_table->entries[index].us_cac_low);
1347 table->BapmVddcVidHiSidd[count] =
1348 convert_to_vid(vddc_lookup_table->entries[index].us_cac_mid);
1349 table->BapmVddcVidHiSidd2[count] =
1350 convert_to_vid(vddc_lookup_table->entries[index].us_cac_high);
1353 if ((data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2)) {
1354 /* We are populating vddgfx CAC data to BapmVddgfx table in split mode */
1355 for (count = 0; count < vddgfxLevelCount; count++) {
1356 index = tonga_get_voltage_index(vddgfx_lookup_table,
1357 data->vddgfx_voltage_table.entries[count].value);
1358 table->BapmVddGfxVidLoSidd[count] =
1359 convert_to_vid(vddgfx_lookup_table->entries[index].us_cac_low);
1360 table->BapmVddGfxVidHiSidd[count] =
1361 convert_to_vid(vddgfx_lookup_table->entries[index].us_cac_mid);
1362 table->BapmVddGfxVidHiSidd2[count] =
1363 convert_to_vid(vddgfx_lookup_table->entries[index].us_cac_high);
1366 for (count = 0; count < vddcLevelCount; count++) {
1367 index = tonga_get_voltage_index(vddc_lookup_table,
1368 data->vddc_voltage_table.entries[count].value);
1369 table->BapmVddGfxVidLoSidd[count] =
1370 convert_to_vid(vddc_lookup_table->entries[index].us_cac_low);
1371 table->BapmVddGfxVidHiSidd[count] =
1372 convert_to_vid(vddc_lookup_table->entries[index].us_cac_mid);
1373 table->BapmVddGfxVidHiSidd2[count] =
1374 convert_to_vid(vddc_lookup_table->entries[index].us_cac_high);
1383 * Preparation of voltage tables for SMC.
1385 * @param hwmgr the address of the hardware manager
1386 * @param table the SMC DPM table structure to be populated
1390 int tonga_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
1391 SMU72_Discrete_DpmTable *table)
1395 result = tonga_populate_smc_vddc_table(hwmgr, table);
1396 PP_ASSERT_WITH_CODE(0 == result,
1397 "can not populate VDDC voltage table to SMC", return -1);
1399 result = tonga_populate_smc_vdd_ci_table(hwmgr, table);
1400 PP_ASSERT_WITH_CODE(0 == result,
1401 "can not populate VDDCI voltage table to SMC", return -1);
1403 result = tonga_populate_smc_vdd_gfx_table(hwmgr, table);
1404 PP_ASSERT_WITH_CODE(0 == result,
1405 "can not populate VDDGFX voltage table to SMC", return -1);
1407 result = tonga_populate_smc_mvdd_table(hwmgr, table);
1408 PP_ASSERT_WITH_CODE(0 == result,
1409 "can not populate MVDD voltage table to SMC", return -1);
1411 result = tonga_populate_cac_tables(hwmgr, table);
1412 PP_ASSERT_WITH_CODE(0 == result,
1413 "can not populate CAC voltage tables to SMC", return -1);
1419 * Populates the SMC VRConfig field in DPM table.
1421 * @param hwmgr the address of the hardware manager
1422 * @param table the SMC DPM table structure to be populated
1425 static int tonga_populate_vr_config(struct pp_hwmgr *hwmgr,
1426 SMU72_Discrete_DpmTable *table)
1428 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1431 if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_gfx_control) {
1433 config = VR_SVI2_PLANE_1;
1434 table->VRConfig |= (config<<VRCONF_VDDGFX_SHIFT);
1436 if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
1437 config = VR_SVI2_PLANE_2;
1438 table->VRConfig |= config;
1440 printk(KERN_ERR "[ powerplay ] VDDC and VDDGFX should be both on SVI2 control in splitted mode! \n");
1444 config = VR_MERGED_WITH_VDDC;
1445 table->VRConfig |= (config<<VRCONF_VDDGFX_SHIFT);
1447 /* Set Vddc Voltage Controller */
1448 if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
1449 config = VR_SVI2_PLANE_1;
1450 table->VRConfig |= config;
1452 printk(KERN_ERR "[ powerplay ] VDDC should be on SVI2 control in merged mode! \n");
1456 /* Set Vddci Voltage Controller */
1457 if (TONGA_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_ci_control) {
1458 config = VR_SVI2_PLANE_2; /* only in merged mode */
1459 table->VRConfig |= (config<<VRCONF_VDDCI_SHIFT);
1460 } else if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->vdd_ci_control) {
1461 config = VR_SMIO_PATTERN_1;
1462 table->VRConfig |= (config<<VRCONF_VDDCI_SHIFT);
1465 /* Set Mvdd Voltage Controller */
1466 if (TONGA_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
1467 config = VR_SMIO_PATTERN_2;
1468 table->VRConfig |= (config<<VRCONF_MVDD_SHIFT);
1474 static int tonga_get_dependecy_volt_by_clk(struct pp_hwmgr *hwmgr,
1475 phm_ppt_v1_clock_voltage_dependency_table *allowed_clock_voltage_table,
1476 uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
1479 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1480 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
1482 /* clock - voltage dependency table is empty table */
1483 if (allowed_clock_voltage_table->count == 0)
1486 for (i = 0; i < allowed_clock_voltage_table->count; i++) {
1487 /* find first sclk bigger than request */
1488 if (allowed_clock_voltage_table->entries[i].clk >= clock) {
1489 voltage->VddGfx = tonga_get_voltage_index(pptable_info->vddgfx_lookup_table,
1490 allowed_clock_voltage_table->entries[i].vddgfx);
1492 voltage->Vddc = tonga_get_voltage_index(pptable_info->vddc_lookup_table,
1493 allowed_clock_voltage_table->entries[i].vddc);
1495 if (allowed_clock_voltage_table->entries[i].vddci) {
1496 voltage->Vddci = tonga_get_voltage_id(&data->vddci_voltage_table,
1497 allowed_clock_voltage_table->entries[i].vddci);
1499 voltage->Vddci = tonga_get_voltage_id(&data->vddci_voltage_table,
1500 allowed_clock_voltage_table->entries[i].vddc - data->vddc_vddci_delta);
1503 if (allowed_clock_voltage_table->entries[i].mvdd) {
1504 *mvdd = (uint32_t) allowed_clock_voltage_table->entries[i].mvdd;
1507 voltage->Phases = 1;
1512 /* sclk is bigger than max sclk in the dependence table */
1513 voltage->VddGfx = tonga_get_voltage_index(pptable_info->vddgfx_lookup_table,
1514 allowed_clock_voltage_table->entries[i-1].vddgfx);
1515 voltage->Vddc = tonga_get_voltage_index(pptable_info->vddc_lookup_table,
1516 allowed_clock_voltage_table->entries[i-1].vddc);
1518 if (allowed_clock_voltage_table->entries[i-1].vddci) {
1519 voltage->Vddci = tonga_get_voltage_id(&data->vddci_voltage_table,
1520 allowed_clock_voltage_table->entries[i-1].vddci);
1522 if (allowed_clock_voltage_table->entries[i-1].mvdd) {
1523 *mvdd = (uint32_t) allowed_clock_voltage_table->entries[i-1].mvdd;
1530 * Call SMC to reset S0/S1 to S1 and Reset SMIO to initial value
1532 * @param hwmgr the address of the powerplay hardware manager.
1535 int tonga_reset_to_default(struct pp_hwmgr *hwmgr)
1537 return (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_ResetToDefaults) == 0) ? 0 : 1;
1540 int tonga_populate_memory_timing_parameters(
1541 struct pp_hwmgr *hwmgr,
1542 uint32_t engine_clock,
1543 uint32_t memory_clock,
1544 struct SMU72_Discrete_MCArbDramTimingTableEntry *arb_regs
1547 uint32_t dramTiming;
1548 uint32_t dramTiming2;
1552 result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
1553 engine_clock, memory_clock);
1555 PP_ASSERT_WITH_CODE(result == 0,
1556 "Error calling VBIOS to set DRAM_TIMING.", return result);
1558 dramTiming = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
1559 dramTiming2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
1560 burstTime = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
1562 arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dramTiming);
1563 arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dramTiming2);
1564 arb_regs->McArbBurstTime = (uint8_t)burstTime;
1570 * Setup parameters for the MC ARB.
1572 * @param hwmgr the address of the powerplay hardware manager.
1574 * This function is to be called from the SetPowerState table.
1576 int tonga_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
1578 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1580 SMU72_Discrete_MCArbDramTimingTable arb_regs;
1583 memset(&arb_regs, 0x00, sizeof(SMU72_Discrete_MCArbDramTimingTable));
1585 for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
1586 for (j = 0; j < data->dpm_table.mclk_table.count; j++) {
1587 result = tonga_populate_memory_timing_parameters
1588 (hwmgr, data->dpm_table.sclk_table.dpm_levels[i].value,
1589 data->dpm_table.mclk_table.dpm_levels[j].value,
1590 &arb_regs.entries[i][j]);
1599 result = tonga_copy_bytes_to_smc(
1601 data->arb_table_start,
1602 (uint8_t *)&arb_regs,
1603 sizeof(SMU72_Discrete_MCArbDramTimingTable),
1611 static int tonga_populate_smc_link_level(struct pp_hwmgr *hwmgr, SMU72_Discrete_DpmTable *table)
1613 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1614 struct tonga_dpm_table *dpm_table = &data->dpm_table;
1617 /* Index (dpm_table->pcie_speed_table.count) is reserved for PCIE boot level. */
1618 for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
1619 table->LinkLevel[i].PcieGenSpeed =
1620 (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
1621 table->LinkLevel[i].PcieLaneCount =
1622 (uint8_t)encode_pcie_lane_width(dpm_table->pcie_speed_table.dpm_levels[i].param1);
1623 table->LinkLevel[i].EnabledForActivity =
1625 table->LinkLevel[i].SPC =
1626 (uint8_t)(data->pcie_spc_cap & 0xff);
1627 table->LinkLevel[i].DownThreshold =
1628 PP_HOST_TO_SMC_UL(5);
1629 table->LinkLevel[i].UpThreshold =
1630 PP_HOST_TO_SMC_UL(30);
1633 data->smc_state_table.LinkLevelCount =
1634 (uint8_t)dpm_table->pcie_speed_table.count;
1635 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
1636 tonga_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
1642 static int tonga_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
1643 SMU72_Discrete_DpmTable *table)
1648 pp_atomctrl_clock_dividers_vi dividers;
1649 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1650 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
1651 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table;
1653 table->VceLevelCount = (uint8_t) (mm_table->count);
1654 table->VceBootLevel = 0;
1656 for (count = 0; count < table->VceLevelCount; count++) {
1657 table->VceLevel[count].Frequency =
1658 mm_table->entries[count].eclk;
1659 table->VceLevel[count].MinVoltage.Vddc =
1660 tonga_get_voltage_index(pptable_info->vddc_lookup_table,
1661 mm_table->entries[count].vddc);
1662 table->VceLevel[count].MinVoltage.VddGfx =
1663 (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) ?
1664 tonga_get_voltage_index(pptable_info->vddgfx_lookup_table,
1665 mm_table->entries[count].vddgfx) : 0;
1666 table->VceLevel[count].MinVoltage.Vddci =
1667 tonga_get_voltage_id(&data->vddci_voltage_table,
1668 mm_table->entries[count].vddc - data->vddc_vddci_delta);
1669 table->VceLevel[count].MinVoltage.Phases = 1;
1671 /* retrieve divider value for VBIOS */
1672 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1673 table->VceLevel[count].Frequency, ÷rs);
1674 PP_ASSERT_WITH_CODE((0 == result),
1675 "can not find divide id for VCE engine clock", return result);
1677 table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
1679 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency);
1685 static int tonga_populate_smc_acp_level(struct pp_hwmgr *hwmgr,
1686 SMU72_Discrete_DpmTable *table)
1690 pp_atomctrl_clock_dividers_vi dividers;
1691 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1692 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
1693 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table;
1695 table->AcpLevelCount = (uint8_t) (mm_table->count);
1696 table->AcpBootLevel = 0;
1698 for (count = 0; count < table->AcpLevelCount; count++) {
1699 table->AcpLevel[count].Frequency =
1700 pptable_info->mm_dep_table->entries[count].aclk;
1701 table->AcpLevel[count].MinVoltage.Vddc =
1702 tonga_get_voltage_index(pptable_info->vddc_lookup_table,
1703 mm_table->entries[count].vddc);
1704 table->AcpLevel[count].MinVoltage.VddGfx =
1705 (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) ?
1706 tonga_get_voltage_index(pptable_info->vddgfx_lookup_table,
1707 mm_table->entries[count].vddgfx) : 0;
1708 table->AcpLevel[count].MinVoltage.Vddci =
1709 tonga_get_voltage_id(&data->vddci_voltage_table,
1710 mm_table->entries[count].vddc - data->vddc_vddci_delta);
1711 table->AcpLevel[count].MinVoltage.Phases = 1;
1713 /* retrieve divider value for VBIOS */
1714 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1715 table->AcpLevel[count].Frequency, ÷rs);
1716 PP_ASSERT_WITH_CODE((0 == result),
1717 "can not find divide id for engine clock", return result);
1719 table->AcpLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
1721 CONVERT_FROM_HOST_TO_SMC_UL(table->AcpLevel[count].Frequency);
1727 static int tonga_populate_smc_samu_level(struct pp_hwmgr *hwmgr,
1728 SMU72_Discrete_DpmTable *table)
1732 pp_atomctrl_clock_dividers_vi dividers;
1733 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1734 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
1735 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table;
1737 table->SamuBootLevel = 0;
1738 table->SamuLevelCount = (uint8_t) (mm_table->count);
1740 for (count = 0; count < table->SamuLevelCount; count++) {
1741 /* not sure whether we need evclk or not */
1742 table->SamuLevel[count].Frequency =
1743 pptable_info->mm_dep_table->entries[count].samclock;
1744 table->SamuLevel[count].MinVoltage.Vddc =
1745 tonga_get_voltage_index(pptable_info->vddc_lookup_table,
1746 mm_table->entries[count].vddc);
1747 table->SamuLevel[count].MinVoltage.VddGfx =
1748 (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) ?
1749 tonga_get_voltage_index(pptable_info->vddgfx_lookup_table,
1750 mm_table->entries[count].vddgfx) : 0;
1751 table->SamuLevel[count].MinVoltage.Vddci =
1752 tonga_get_voltage_id(&data->vddci_voltage_table,
1753 mm_table->entries[count].vddc - data->vddc_vddci_delta);
1754 table->SamuLevel[count].MinVoltage.Phases = 1;
1756 /* retrieve divider value for VBIOS */
1757 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1758 table->SamuLevel[count].Frequency, ÷rs);
1759 PP_ASSERT_WITH_CODE((0 == result),
1760 "can not find divide id for samu clock", return result);
1762 table->SamuLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
1764 CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].Frequency);
1771 * Populates the SMC MCLK structure using the provided memory clock
1773 * @param hwmgr the address of the hardware manager
1774 * @param memory_clock the memory clock to use to populate the structure
1775 * @param sclk the SMC SCLK structure to be populated
1777 static int tonga_calculate_mclk_params(
1778 struct pp_hwmgr *hwmgr,
1779 uint32_t memory_clock,
1780 SMU72_Discrete_MemoryLevel *mclk,
1785 const tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1786 uint32_t dll_cntl = data->clock_registers.vDLL_CNTL;
1787 uint32_t mclk_pwrmgt_cntl = data->clock_registers.vMCLK_PWRMGT_CNTL;
1788 uint32_t mpll_ad_func_cntl = data->clock_registers.vMPLL_AD_FUNC_CNTL;
1789 uint32_t mpll_dq_func_cntl = data->clock_registers.vMPLL_DQ_FUNC_CNTL;
1790 uint32_t mpll_func_cntl = data->clock_registers.vMPLL_FUNC_CNTL;
1791 uint32_t mpll_func_cntl_1 = data->clock_registers.vMPLL_FUNC_CNTL_1;
1792 uint32_t mpll_func_cntl_2 = data->clock_registers.vMPLL_FUNC_CNTL_2;
1793 uint32_t mpll_ss1 = data->clock_registers.vMPLL_SS1;
1794 uint32_t mpll_ss2 = data->clock_registers.vMPLL_SS2;
1796 pp_atomctrl_memory_clock_param mpll_param;
1799 result = atomctrl_get_memory_pll_dividers_si(hwmgr,
1800 memory_clock, &mpll_param, strobe_mode);
1801 PP_ASSERT_WITH_CODE(0 == result,
1802 "Error retrieving Memory Clock Parameters from VBIOS.", return result);
1804 /* MPLL_FUNC_CNTL setup*/
1805 mpll_func_cntl = PHM_SET_FIELD(mpll_func_cntl, MPLL_FUNC_CNTL, BWCTRL, mpll_param.bw_ctrl);
1807 /* MPLL_FUNC_CNTL_1 setup*/
1808 mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1,
1809 MPLL_FUNC_CNTL_1, CLKF, mpll_param.mpll_fb_divider.cl_kf);
1810 mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1,
1811 MPLL_FUNC_CNTL_1, CLKFRAC, mpll_param.mpll_fb_divider.clk_frac);
1812 mpll_func_cntl_1 = PHM_SET_FIELD(mpll_func_cntl_1,
1813 MPLL_FUNC_CNTL_1, VCO_MODE, mpll_param.vco_mode);
1815 /* MPLL_AD_FUNC_CNTL setup*/
1816 mpll_ad_func_cntl = PHM_SET_FIELD(mpll_ad_func_cntl,
1817 MPLL_AD_FUNC_CNTL, YCLK_POST_DIV, mpll_param.mpll_post_divider);
1819 if (data->is_memory_GDDR5) {
1820 /* MPLL_DQ_FUNC_CNTL setup*/
1821 mpll_dq_func_cntl = PHM_SET_FIELD(mpll_dq_func_cntl,
1822 MPLL_DQ_FUNC_CNTL, YCLK_SEL, mpll_param.yclk_sel);
1823 mpll_dq_func_cntl = PHM_SET_FIELD(mpll_dq_func_cntl,
1824 MPLL_DQ_FUNC_CNTL, YCLK_POST_DIV, mpll_param.mpll_post_divider);
1827 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1828 PHM_PlatformCaps_MemorySpreadSpectrumSupport)) {
1830 ************************************
1831 Fref = Reference Frequency
1832 NF = Feedback divider ratio
1833 NR = Reference divider ratio
1834 Fnom = Nominal VCO output frequency = Fref * NF / NR
1836 D = Percentage down-spread / 2
1837 Fint = Reference input frequency to PFD = Fref / NR
1838 NS = Spreading rate divider ratio = int(Fint / (2 * Fs))
1839 CLKS = NS - 1 = ISS_STEP_NUM[11:0]
1840 NV = D * Fs / Fnom * 4 * ((Fnom/Fref * NR) ^ 2)
1841 CLKV = 65536 * NV = ISS_STEP_SIZE[25:0]
1842 *************************************
1844 pp_atomctrl_internal_ss_info ss_info;
1847 uint32_t reference_clock = atomctrl_get_mpll_reference_clock(hwmgr);
1849 /* for GDDR5 for all modes and DDR3 */
1850 if (1 == mpll_param.qdr)
1851 freq_nom = memory_clock * 4 * (1 << mpll_param.mpll_post_divider);
1853 freq_nom = memory_clock * 2 * (1 << mpll_param.mpll_post_divider);
1855 /* tmp = (freq_nom / reference_clock * reference_divider) ^ 2 Note: S.I. reference_divider = 1*/
1856 tmp = (freq_nom / reference_clock);
1859 if (0 == atomctrl_get_memory_clock_spread_spectrum(hwmgr, freq_nom, &ss_info)) {
1860 /* ss_info.speed_spectrum_percentage -- in unit of 0.01% */
1861 /* ss.Info.speed_spectrum_rate -- in unit of khz */
1862 /* CLKS = reference_clock / (2 * speed_spectrum_rate * reference_divider) * 10 */
1863 /* = reference_clock * 5 / speed_spectrum_rate */
1864 uint32_t clks = reference_clock * 5 / ss_info.speed_spectrum_rate;
1866 /* CLKV = 65536 * speed_spectrum_percentage / 2 * spreadSpecrumRate / freq_nom * 4 / 100000 * ((freq_nom / reference_clock) ^ 2) */
1867 /* = 131 * speed_spectrum_percentage * speed_spectrum_rate / 100 * ((freq_nom / reference_clock) ^ 2) / freq_nom */
1869 (uint32_t)((((131 * ss_info.speed_spectrum_percentage *
1870 ss_info.speed_spectrum_rate) / 100) * tmp) / freq_nom);
1872 mpll_ss1 = PHM_SET_FIELD(mpll_ss1, MPLL_SS1, CLKV, clkv);
1873 mpll_ss2 = PHM_SET_FIELD(mpll_ss2, MPLL_SS2, CLKS, clks);
1877 /* MCLK_PWRMGT_CNTL setup */
1878 mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
1879 MCLK_PWRMGT_CNTL, DLL_SPEED, mpll_param.dll_speed);
1880 mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
1881 MCLK_PWRMGT_CNTL, MRDCK0_PDNB, dllStateOn);
1882 mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
1883 MCLK_PWRMGT_CNTL, MRDCK1_PDNB, dllStateOn);
1886 /* Save the result data to outpupt memory level structure */
1887 mclk->MclkFrequency = memory_clock;
1888 mclk->MpllFuncCntl = mpll_func_cntl;
1889 mclk->MpllFuncCntl_1 = mpll_func_cntl_1;
1890 mclk->MpllFuncCntl_2 = mpll_func_cntl_2;
1891 mclk->MpllAdFuncCntl = mpll_ad_func_cntl;
1892 mclk->MpllDqFuncCntl = mpll_dq_func_cntl;
1893 mclk->MclkPwrmgtCntl = mclk_pwrmgt_cntl;
1894 mclk->DllCntl = dll_cntl;
1895 mclk->MpllSs1 = mpll_ss1;
1896 mclk->MpllSs2 = mpll_ss2;
1901 static uint8_t tonga_get_mclk_frequency_ratio(uint32_t memory_clock,
1904 uint8_t mc_para_index;
1907 if (memory_clock < 12500) {
1908 mc_para_index = 0x00;
1909 } else if (memory_clock > 47500) {
1910 mc_para_index = 0x0f;
1912 mc_para_index = (uint8_t)((memory_clock - 10000) / 2500);
1915 if (memory_clock < 65000) {
1916 mc_para_index = 0x00;
1917 } else if (memory_clock > 135000) {
1918 mc_para_index = 0x0f;
1920 mc_para_index = (uint8_t)((memory_clock - 60000) / 5000);
1924 return mc_para_index;
1927 static uint8_t tonga_get_ddr3_mclk_frequency_ratio(uint32_t memory_clock)
1929 uint8_t mc_para_index;
1931 if (memory_clock < 10000) {
1933 } else if (memory_clock >= 80000) {
1934 mc_para_index = 0x0f;
1936 mc_para_index = (uint8_t)((memory_clock - 10000) / 5000 + 1);
1939 return mc_para_index;
1942 static int tonga_populate_single_memory_level(
1943 struct pp_hwmgr *hwmgr,
1944 uint32_t memory_clock,
1945 SMU72_Discrete_MemoryLevel *memory_level
1948 uint32_t minMvdd = 0;
1949 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
1950 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
1953 struct cgs_display_info info = {0};
1956 if (NULL != pptable_info->vdd_dep_on_mclk) {
1957 result = tonga_get_dependecy_volt_by_clk(hwmgr,
1958 pptable_info->vdd_dep_on_mclk, memory_clock, &memory_level->MinVoltage, &minMvdd);
1959 PP_ASSERT_WITH_CODE((0 == result),
1960 "can not find MinVddc voltage value from memory VDDC voltage dependency table", return result);
1963 if (data->mvdd_control == TONGA_VOLTAGE_CONTROL_NONE) {
1964 memory_level->MinMvdd = data->vbios_boot_state.mvdd_bootup_value;
1966 memory_level->MinMvdd = minMvdd;
1968 memory_level->EnabledForThrottle = 1;
1969 memory_level->EnabledForActivity = 0;
1970 memory_level->UpHyst = 0;
1971 memory_level->DownHyst = 100;
1972 memory_level->VoltageDownHyst = 0;
1974 /* Indicates maximum activity level for this performance level.*/
1975 memory_level->ActivityLevel = (uint16_t)data->mclk_activity_target;
1976 memory_level->StutterEnable = 0;
1977 memory_level->StrobeEnable = 0;
1978 memory_level->EdcReadEnable = 0;
1979 memory_level->EdcWriteEnable = 0;
1980 memory_level->RttEnable = 0;
1982 /* default set to low watermark. Highest level will be set to high later.*/
1983 memory_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
1985 cgs_get_active_displays_info(hwmgr->device, &info);
1986 data->display_timing.num_existing_displays = info.display_count;
1988 if ((data->mclk_stutter_mode_threshold != 0) &&
1989 (memory_clock <= data->mclk_stutter_mode_threshold) &&
1990 (data->is_uvd_enabled == 0)
1992 && (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL, STUTTER_ENABLE) & 0x1)
1993 && (data->display_timing.num_existing_displays <= 2)
1994 && (data->display_timing.num_existing_displays != 0)
1997 memory_level->StutterEnable = 1;
1999 /* decide strobe mode*/
2000 memory_level->StrobeEnable = (data->mclk_strobe_mode_threshold != 0) &&
2001 (memory_clock <= data->mclk_strobe_mode_threshold);
2003 /* decide EDC mode and memory clock ratio*/
2004 if (data->is_memory_GDDR5) {
2005 memory_level->StrobeRatio = tonga_get_mclk_frequency_ratio(memory_clock,
2006 memory_level->StrobeEnable);
2008 if ((data->mclk_edc_enable_threshold != 0) &&
2009 (memory_clock > data->mclk_edc_enable_threshold)) {
2010 memory_level->EdcReadEnable = 1;
2013 if ((data->mclk_edc_wr_enable_threshold != 0) &&
2014 (memory_clock > data->mclk_edc_wr_enable_threshold)) {
2015 memory_level->EdcWriteEnable = 1;
2018 if (memory_level->StrobeEnable) {
2019 if (tonga_get_mclk_frequency_ratio(memory_clock, 1) >=
2020 ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC7) >> 16) & 0xf)) {
2021 dllStateOn = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC5) >> 1) & 0x1) ? 1 : 0;
2023 dllStateOn = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC6) >> 1) & 0x1) ? 1 : 0;
2027 dllStateOn = data->dll_defaule_on;
2030 memory_level->StrobeRatio =
2031 tonga_get_ddr3_mclk_frequency_ratio(memory_clock);
2032 dllStateOn = ((cgs_read_register(hwmgr->device, mmMC_SEQ_MISC5) >> 1) & 0x1) ? 1 : 0;
2035 result = tonga_calculate_mclk_params(hwmgr,
2036 memory_clock, memory_level, memory_level->StrobeEnable, dllStateOn);
2039 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MinMvdd);
2040 /* MCLK frequency in units of 10KHz*/
2041 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MclkFrequency);
2042 /* Indicates maximum activity level for this performance level.*/
2043 CONVERT_FROM_HOST_TO_SMC_US(memory_level->ActivityLevel);
2044 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl);
2045 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl_1);
2046 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllFuncCntl_2);
2047 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllAdFuncCntl);
2048 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllDqFuncCntl);
2049 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MclkPwrmgtCntl);
2050 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->DllCntl);
2051 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllSs1);
2052 CONVERT_FROM_HOST_TO_SMC_UL(memory_level->MpllSs2);
2059 * Populates the SMC MVDD structure using the provided memory clock.
2061 * @param hwmgr the address of the hardware manager
2062 * @param mclk the MCLK value to be used in the decision if MVDD should be high or low.
2063 * @param voltage the SMC VOLTAGE structure to be populated
2065 int tonga_populate_mvdd_value(struct pp_hwmgr *hwmgr, uint32_t mclk, SMIO_Pattern *smio_pattern)
2067 const tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2068 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2071 if (TONGA_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
2072 /* find mvdd value which clock is more than request */
2073 for (i = 0; i < pptable_info->vdd_dep_on_mclk->count; i++) {
2074 if (mclk <= pptable_info->vdd_dep_on_mclk->entries[i].clk) {
2075 /* Always round to higher voltage. */
2076 smio_pattern->Voltage = data->mvdd_voltage_table.entries[i].value;
2081 PP_ASSERT_WITH_CODE(i < pptable_info->vdd_dep_on_mclk->count,
2082 "MVDD Voltage is outside the supported range.", return -1);
2092 static int tonga_populate_smv_acpi_level(struct pp_hwmgr *hwmgr,
2093 SMU72_Discrete_DpmTable *table)
2096 const tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2097 pp_atomctrl_clock_dividers_vi dividers;
2098 SMIO_Pattern voltage_level;
2099 uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
2100 uint32_t spll_func_cntl_2 = data->clock_registers.vCG_SPLL_FUNC_CNTL_2;
2101 uint32_t dll_cntl = data->clock_registers.vDLL_CNTL;
2102 uint32_t mclk_pwrmgt_cntl = data->clock_registers.vMCLK_PWRMGT_CNTL;
2104 /* The ACPI state should not do DPM on DC (or ever).*/
2105 table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
2107 table->ACPILevel.MinVoltage = data->smc_state_table.GraphicsLevel[0].MinVoltage;
2109 /* assign zero for now*/
2110 table->ACPILevel.SclkFrequency = atomctrl_get_reference_clock(hwmgr);
2112 /* get the engine clock dividers for this clock value*/
2113 result = atomctrl_get_engine_pll_dividers_vi(hwmgr,
2114 table->ACPILevel.SclkFrequency, ÷rs);
2116 PP_ASSERT_WITH_CODE(result == 0,
2117 "Error retrieving Engine Clock dividers from VBIOS.", return result);
2119 /* divider ID for required SCLK*/
2120 table->ACPILevel.SclkDid = (uint8_t)dividers.pll_post_divider;
2121 table->ACPILevel.DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2122 table->ACPILevel.DeepSleepDivId = 0;
2124 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl,
2125 CG_SPLL_FUNC_CNTL, SPLL_PWRON, 0);
2126 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl,
2127 CG_SPLL_FUNC_CNTL, SPLL_RESET, 1);
2128 spll_func_cntl_2 = PHM_SET_FIELD(spll_func_cntl_2,
2129 CG_SPLL_FUNC_CNTL_2, SCLK_MUX_SEL, 4);
2131 table->ACPILevel.CgSpllFuncCntl = spll_func_cntl;
2132 table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2;
2133 table->ACPILevel.CgSpllFuncCntl3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
2134 table->ACPILevel.CgSpllFuncCntl4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
2135 table->ACPILevel.SpllSpreadSpectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
2136 table->ACPILevel.SpllSpreadSpectrum2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
2137 table->ACPILevel.CcPwrDynRm = 0;
2138 table->ACPILevel.CcPwrDynRm1 = 0;
2141 /* For various features to be enabled/disabled while this level is active.*/
2142 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
2143 /* SCLK frequency in units of 10KHz*/
2144 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkFrequency);
2145 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl);
2146 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl2);
2147 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl3);
2148 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl4);
2149 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum);
2150 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum2);
2151 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
2152 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
2154 /* table->MemoryACPILevel.MinVddcPhases = table->ACPILevel.MinVddcPhases;*/
2155 table->MemoryACPILevel.MinVoltage = data->smc_state_table.MemoryLevel[0].MinVoltage;
2157 /* CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);*/
2159 if (0 == tonga_populate_mvdd_value(hwmgr, 0, &voltage_level))
2160 table->MemoryACPILevel.MinMvdd =
2161 PP_HOST_TO_SMC_UL(voltage_level.Voltage * VOLTAGE_SCALE);
2163 table->MemoryACPILevel.MinMvdd = 0;
2165 /* Force reset on DLL*/
2166 mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
2167 MCLK_PWRMGT_CNTL, MRDCK0_RESET, 0x1);
2168 mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
2169 MCLK_PWRMGT_CNTL, MRDCK1_RESET, 0x1);
2171 /* Disable DLL in ACPIState*/
2172 mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
2173 MCLK_PWRMGT_CNTL, MRDCK0_PDNB, 0);
2174 mclk_pwrmgt_cntl = PHM_SET_FIELD(mclk_pwrmgt_cntl,
2175 MCLK_PWRMGT_CNTL, MRDCK1_PDNB, 0);
2177 /* Enable DLL bypass signal*/
2178 dll_cntl = PHM_SET_FIELD(dll_cntl,
2179 DLL_CNTL, MRDCK0_BYPASS, 0);
2180 dll_cntl = PHM_SET_FIELD(dll_cntl,
2181 DLL_CNTL, MRDCK1_BYPASS, 0);
2183 table->MemoryACPILevel.DllCntl =
2184 PP_HOST_TO_SMC_UL(dll_cntl);
2185 table->MemoryACPILevel.MclkPwrmgtCntl =
2186 PP_HOST_TO_SMC_UL(mclk_pwrmgt_cntl);
2187 table->MemoryACPILevel.MpllAdFuncCntl =
2188 PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_AD_FUNC_CNTL);
2189 table->MemoryACPILevel.MpllDqFuncCntl =
2190 PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_DQ_FUNC_CNTL);
2191 table->MemoryACPILevel.MpllFuncCntl =
2192 PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL);
2193 table->MemoryACPILevel.MpllFuncCntl_1 =
2194 PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL_1);
2195 table->MemoryACPILevel.MpllFuncCntl_2 =
2196 PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_FUNC_CNTL_2);
2197 table->MemoryACPILevel.MpllSs1 =
2198 PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_SS1);
2199 table->MemoryACPILevel.MpllSs2 =
2200 PP_HOST_TO_SMC_UL(data->clock_registers.vMPLL_SS2);
2202 table->MemoryACPILevel.EnabledForThrottle = 0;
2203 table->MemoryACPILevel.EnabledForActivity = 0;
2204 table->MemoryACPILevel.UpHyst = 0;
2205 table->MemoryACPILevel.DownHyst = 100;
2206 table->MemoryACPILevel.VoltageDownHyst = 0;
2207 /* Indicates maximum activity level for this performance level.*/
2208 table->MemoryACPILevel.ActivityLevel = PP_HOST_TO_SMC_US((uint16_t)data->mclk_activity_target);
2210 table->MemoryACPILevel.StutterEnable = 0;
2211 table->MemoryACPILevel.StrobeEnable = 0;
2212 table->MemoryACPILevel.EdcReadEnable = 0;
2213 table->MemoryACPILevel.EdcWriteEnable = 0;
2214 table->MemoryACPILevel.RttEnable = 0;
2219 static int tonga_find_boot_level(struct tonga_single_dpm_table *table, uint32_t value, uint32_t *boot_level)
2224 for (i = 0; i < table->count; i++) {
2225 if (value == table->dpm_levels[i].value) {
2233 static int tonga_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
2234 SMU72_Discrete_DpmTable *table)
2237 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2239 table->GraphicsBootLevel = 0; /* 0 == DPM[0] (low), etc. */
2240 table->MemoryBootLevel = 0; /* 0 == DPM[0] (low), etc. */
2242 /* find boot level from dpm table*/
2243 result = tonga_find_boot_level(&(data->dpm_table.sclk_table),
2244 data->vbios_boot_state.sclk_bootup_value,
2245 (uint32_t *)&(data->smc_state_table.GraphicsBootLevel));
2248 data->smc_state_table.GraphicsBootLevel = 0;
2249 printk(KERN_ERR "[ powerplay ] VBIOS did not find boot engine clock value \
2250 in dependency table. Using Graphics DPM level 0!");
2254 result = tonga_find_boot_level(&(data->dpm_table.mclk_table),
2255 data->vbios_boot_state.mclk_bootup_value,
2256 (uint32_t *)&(data->smc_state_table.MemoryBootLevel));
2259 data->smc_state_table.MemoryBootLevel = 0;
2260 printk(KERN_ERR "[ powerplay ] VBIOS did not find boot engine clock value \
2261 in dependency table. Using Memory DPM level 0!");
2265 table->BootVoltage.Vddc =
2266 tonga_get_voltage_id(&(data->vddc_voltage_table),
2267 data->vbios_boot_state.vddc_bootup_value);
2268 table->BootVoltage.VddGfx =
2269 tonga_get_voltage_id(&(data->vddgfx_voltage_table),
2270 data->vbios_boot_state.vddgfx_bootup_value);
2271 table->BootVoltage.Vddci =
2272 tonga_get_voltage_id(&(data->vddci_voltage_table),
2273 data->vbios_boot_state.vddci_bootup_value);
2274 table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value;
2276 CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
2283 * Calculates the SCLK dividers using the provided engine clock
2285 * @param hwmgr the address of the hardware manager
2286 * @param engine_clock the engine clock to use to populate the structure
2287 * @param sclk the SMC SCLK structure to be populated
2289 int tonga_calculate_sclk_params(struct pp_hwmgr *hwmgr,
2290 uint32_t engine_clock, SMU72_Discrete_GraphicsLevel *sclk)
2292 const tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2293 pp_atomctrl_clock_dividers_vi dividers;
2294 uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
2295 uint32_t spll_func_cntl_3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
2296 uint32_t spll_func_cntl_4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
2297 uint32_t cg_spll_spread_spectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
2298 uint32_t cg_spll_spread_spectrum_2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
2299 uint32_t reference_clock;
2300 uint32_t reference_divider;
2304 /* get the engine clock dividers for this clock value*/
2305 result = atomctrl_get_engine_pll_dividers_vi(hwmgr, engine_clock, ÷rs);
2307 PP_ASSERT_WITH_CODE(result == 0,
2308 "Error retrieving Engine Clock dividers from VBIOS.", return result);
2310 /* To get FBDIV we need to multiply this by 16384 and divide it by Fref.*/
2311 reference_clock = atomctrl_get_reference_clock(hwmgr);
2313 reference_divider = 1 + dividers.uc_pll_ref_div;
2315 /* low 14 bits is fraction and high 12 bits is divider*/
2316 fbdiv = dividers.ul_fb_div.ul_fb_divider & 0x3FFFFFF;
2318 /* SPLL_FUNC_CNTL setup*/
2319 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl,
2320 CG_SPLL_FUNC_CNTL, SPLL_REF_DIV, dividers.uc_pll_ref_div);
2321 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl,
2322 CG_SPLL_FUNC_CNTL, SPLL_PDIV_A, dividers.uc_pll_post_div);
2324 /* SPLL_FUNC_CNTL_3 setup*/
2325 spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3,
2326 CG_SPLL_FUNC_CNTL_3, SPLL_FB_DIV, fbdiv);
2328 /* set to use fractional accumulation*/
2329 spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3,
2330 CG_SPLL_FUNC_CNTL_3, SPLL_DITHEN, 1);
2332 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2333 PHM_PlatformCaps_EngineSpreadSpectrumSupport)) {
2334 pp_atomctrl_internal_ss_info ss_info;
2336 uint32_t vcoFreq = engine_clock * dividers.uc_pll_post_div;
2337 if (0 == atomctrl_get_engine_clock_spread_spectrum(hwmgr, vcoFreq, &ss_info)) {
2339 * ss_info.speed_spectrum_percentage -- in unit of 0.01%
2340 * ss_info.speed_spectrum_rate -- in unit of khz
2342 /* clks = reference_clock * 10 / (REFDIV + 1) / speed_spectrum_rate / 2 */
2343 uint32_t clkS = reference_clock * 5 / (reference_divider * ss_info.speed_spectrum_rate);
2345 /* clkv = 2 * D * fbdiv / NS */
2346 uint32_t clkV = 4 * ss_info.speed_spectrum_percentage * fbdiv / (clkS * 10000);
2348 cg_spll_spread_spectrum =
2349 PHM_SET_FIELD(cg_spll_spread_spectrum, CG_SPLL_SPREAD_SPECTRUM, CLKS, clkS);
2350 cg_spll_spread_spectrum =
2351 PHM_SET_FIELD(cg_spll_spread_spectrum, CG_SPLL_SPREAD_SPECTRUM, SSEN, 1);
2352 cg_spll_spread_spectrum_2 =
2353 PHM_SET_FIELD(cg_spll_spread_spectrum_2, CG_SPLL_SPREAD_SPECTRUM_2, CLKV, clkV);
2357 sclk->SclkFrequency = engine_clock;
2358 sclk->CgSpllFuncCntl3 = spll_func_cntl_3;
2359 sclk->CgSpllFuncCntl4 = spll_func_cntl_4;
2360 sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum;
2361 sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2;
2362 sclk->SclkDid = (uint8_t)dividers.pll_post_divider;
2368 * Populates single SMC SCLK structure using the provided engine clock
2370 * @param hwmgr the address of the hardware manager
2371 * @param engine_clock the engine clock to use to populate the structure
2372 * @param sclk the SMC SCLK structure to be populated
2374 static int tonga_populate_single_graphic_level(struct pp_hwmgr *hwmgr, uint32_t engine_clock, uint16_t sclk_activity_level_threshold, SMU72_Discrete_GraphicsLevel *graphic_level)
2379 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2380 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2382 result = tonga_calculate_sclk_params(hwmgr, engine_clock, graphic_level);
2385 /* populate graphics levels*/
2386 result = tonga_get_dependecy_volt_by_clk(hwmgr,
2387 pptable_info->vdd_dep_on_sclk, engine_clock,
2388 &graphic_level->MinVoltage, &mvdd);
2389 PP_ASSERT_WITH_CODE((0 == result),
2390 "can not find VDDC voltage value for VDDC \
2391 engine clock dependency table", return result);
2393 /* SCLK frequency in units of 10KHz*/
2394 graphic_level->SclkFrequency = engine_clock;
2396 /* Indicates maximum activity level for this performance level. 50% for now*/
2397 graphic_level->ActivityLevel = sclk_activity_level_threshold;
2399 graphic_level->CcPwrDynRm = 0;
2400 graphic_level->CcPwrDynRm1 = 0;
2401 /* this level can be used if activity is high enough.*/
2402 graphic_level->EnabledForActivity = 0;
2403 /* this level can be used for throttling.*/
2404 graphic_level->EnabledForThrottle = 1;
2405 graphic_level->UpHyst = 0;
2406 graphic_level->DownHyst = 0;
2407 graphic_level->VoltageDownHyst = 0;
2408 graphic_level->PowerThrottle = 0;
2410 threshold = engine_clock * data->fast_watemark_threshold / 100;
2412 *get the DAL clock. do it in funture.
2413 PECI_GetMinClockSettings(hwmgr->peci, &minClocks);
2414 data->display_timing.min_clock_insr = minClocks.engineClockInSR;
2416 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
2418 graphic_level->DeepSleepDivId = PhwTonga_GetSleepDividerIdFromClock(hwmgr, engine_clock, minClocks.engineClockInSR);
2422 /* Default to slow, highest DPM level will be set to PPSMC_DISPLAY_WATERMARK_LOW later.*/
2423 graphic_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2426 /* CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->MinVoltage);*/
2427 /* CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->MinVddcPhases);*/
2428 CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SclkFrequency);
2429 CONVERT_FROM_HOST_TO_SMC_US(graphic_level->ActivityLevel);
2430 CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CgSpllFuncCntl3);
2431 CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CgSpllFuncCntl4);
2432 CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SpllSpreadSpectrum);
2433 CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->SpllSpreadSpectrum2);
2434 CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CcPwrDynRm);
2435 CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->CcPwrDynRm1);
2442 * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
2444 * @param hwmgr the address of the hardware manager
2446 static int tonga_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
2448 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2449 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2450 struct tonga_dpm_table *dpm_table = &data->dpm_table;
2451 phm_ppt_v1_pcie_table *pcie_table = pptable_info->pcie_table;
2452 uint8_t pcie_entry_count = (uint8_t) data->dpm_table.pcie_speed_table.count;
2454 uint32_t level_array_adress = data->dpm_table_start +
2455 offsetof(SMU72_Discrete_DpmTable, GraphicsLevel);
2456 uint32_t level_array_size = sizeof(SMU72_Discrete_GraphicsLevel) *
2457 SMU72_MAX_LEVELS_GRAPHICS; /* 64 -> long; 32 -> int*/
2458 SMU72_Discrete_GraphicsLevel *levels = data->smc_state_table.GraphicsLevel;
2459 uint32_t i, maxEntry;
2460 uint8_t highest_pcie_level_enabled = 0, lowest_pcie_level_enabled = 0, mid_pcie_level_enabled = 0, count = 0;
2461 PECI_RegistryValue reg_value;
2462 memset(levels, 0x00, level_array_size);
2464 for (i = 0; i < dpm_table->sclk_table.count; i++) {
2465 result = tonga_populate_single_graphic_level(hwmgr,
2466 dpm_table->sclk_table.dpm_levels[i].value,
2467 (uint16_t)data->activity_target[i],
2468 &(data->smc_state_table.GraphicsLevel[i]));
2473 /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
2475 data->smc_state_table.GraphicsLevel[i].DeepSleepDivId = 0;
2480 data->smc_state_table.GraphicsLevel[0].UpHyst = (uint8_t)reg_value;
2486 data->smc_state_table.GraphicsLevel[1].UpHyst = (uint8_t)reg_value;
2490 /* Only enable level 0 for now. */
2491 data->smc_state_table.GraphicsLevel[0].EnabledForActivity = 1;
2493 /* set highest level watermark to high */
2494 if (dpm_table->sclk_table.count > 1)
2495 data->smc_state_table.GraphicsLevel[dpm_table->sclk_table.count-1].DisplayWatermark =
2496 PPSMC_DISPLAY_WATERMARK_HIGH;
2498 data->smc_state_table.GraphicsDpmLevelCount =
2499 (uint8_t)dpm_table->sclk_table.count;
2500 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
2501 tonga_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
2503 if (pcie_table != NULL) {
2504 PP_ASSERT_WITH_CODE((pcie_entry_count >= 1),
2505 "There must be 1 or more PCIE levels defined in PPTable.", return -1);
2506 maxEntry = pcie_entry_count - 1; /* for indexing, we need to decrement by 1.*/
2507 for (i = 0; i < dpm_table->sclk_table.count; i++) {
2508 data->smc_state_table.GraphicsLevel[i].pcieDpmLevel =
2509 (uint8_t) ((i < maxEntry) ? i : maxEntry);
2512 if (0 == data->dpm_level_enable_mask.pcie_dpm_enable_mask)
2513 printk(KERN_ERR "[ powerplay ] Pcie Dpm Enablemask is 0!");
2515 while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
2516 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2517 (1<<(highest_pcie_level_enabled+1))) != 0)) {
2518 highest_pcie_level_enabled++;
2521 while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
2522 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2523 (1<<lowest_pcie_level_enabled)) == 0)) {
2524 lowest_pcie_level_enabled++;
2527 while ((count < highest_pcie_level_enabled) &&
2528 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2529 (1<<(lowest_pcie_level_enabled+1+count))) == 0)) {
2532 mid_pcie_level_enabled = (lowest_pcie_level_enabled+1+count) < highest_pcie_level_enabled ?
2533 (lowest_pcie_level_enabled+1+count) : highest_pcie_level_enabled;
2536 /* set pcieDpmLevel to highest_pcie_level_enabled*/
2537 for (i = 2; i < dpm_table->sclk_table.count; i++) {
2538 data->smc_state_table.GraphicsLevel[i].pcieDpmLevel = highest_pcie_level_enabled;
2541 /* set pcieDpmLevel to lowest_pcie_level_enabled*/
2542 data->smc_state_table.GraphicsLevel[0].pcieDpmLevel = lowest_pcie_level_enabled;
2544 /* set pcieDpmLevel to mid_pcie_level_enabled*/
2545 data->smc_state_table.GraphicsLevel[1].pcieDpmLevel = mid_pcie_level_enabled;
2547 /* level count will send to smc once at init smc table and never change*/
2548 result = tonga_copy_bytes_to_smc(hwmgr->smumgr, level_array_adress, (uint8_t *)levels, (uint32_t)level_array_size, data->sram_end);
2557 * Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states
2559 * @param hwmgr the address of the hardware manager
2562 static int tonga_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
2564 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2565 struct tonga_dpm_table *dpm_table = &data->dpm_table;
2567 /* populate MCLK dpm table to SMU7 */
2568 uint32_t level_array_adress = data->dpm_table_start + offsetof(SMU72_Discrete_DpmTable, MemoryLevel);
2569 uint32_t level_array_size = sizeof(SMU72_Discrete_MemoryLevel) * SMU72_MAX_LEVELS_MEMORY;
2570 SMU72_Discrete_MemoryLevel *levels = data->smc_state_table.MemoryLevel;
2573 memset(levels, 0x00, level_array_size);
2575 for (i = 0; i < dpm_table->mclk_table.count; i++) {
2576 PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
2577 "can not populate memory level as memory clock is zero", return -1);
2578 result = tonga_populate_single_memory_level(hwmgr, dpm_table->mclk_table.dpm_levels[i].value,
2579 &(data->smc_state_table.MemoryLevel[i]));
2585 /* Only enable level 0 for now.*/
2586 data->smc_state_table.MemoryLevel[0].EnabledForActivity = 1;
2589 * in order to prevent MC activity from stutter mode to push DPM up.
2590 * the UVD change complements this by putting the MCLK in a higher state
2591 * by default such that we are not effected by up threshold or and MCLK DPM latency.
2593 data->smc_state_table.MemoryLevel[0].ActivityLevel = 0x1F;
2594 CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.MemoryLevel[0].ActivityLevel);
2596 data->smc_state_table.MemoryDpmLevelCount = (uint8_t)dpm_table->mclk_table.count;
2597 data->dpm_level_enable_mask.mclk_dpm_enable_mask = tonga_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
2598 /* set highest level watermark to high*/
2599 data->smc_state_table.MemoryLevel[dpm_table->mclk_table.count-1].DisplayWatermark = PPSMC_DISPLAY_WATERMARK_HIGH;
2601 /* level count will send to smc once at init smc table and never change*/
2602 result = tonga_copy_bytes_to_smc(hwmgr->smumgr,
2603 level_array_adress, (uint8_t *)levels, (uint32_t)level_array_size, data->sram_end);
2612 struct TONGA_DLL_SPEED_SETTING {
2613 uint16_t Min; /* Minimum Data Rate*/
2614 uint16_t Max; /* Maximum Data Rate*/
2615 uint32_t dll_speed; /* The desired DLL_SPEED setting*/
2618 static int tonga_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr)
2623 /* ---------------------------------------- ULV related functions ----------------------------------------------------*/
2626 static int tonga_reset_single_dpm_table(
2627 struct pp_hwmgr *hwmgr,
2628 struct tonga_single_dpm_table *dpm_table,
2632 if (!(count <= MAX_REGULAR_DPM_NUMBER))
2633 printk(KERN_ERR "[ powerplay ] Fatal error, can not set up single DPM \
2634 table entries to exceed max number! \n");
2636 dpm_table->count = count;
2637 for (i = 0; i < MAX_REGULAR_DPM_NUMBER; i++) {
2638 dpm_table->dpm_levels[i].enabled = 0;
2644 static void tonga_setup_pcie_table_entry(
2645 struct tonga_single_dpm_table *dpm_table,
2646 uint32_t index, uint32_t pcie_gen,
2647 uint32_t pcie_lanes)
2649 dpm_table->dpm_levels[index].value = pcie_gen;
2650 dpm_table->dpm_levels[index].param1 = pcie_lanes;
2651 dpm_table->dpm_levels[index].enabled = 1;
2654 bool is_pcie_gen3_supported(uint32_t pcie_link_speed_cap)
2656 if (pcie_link_speed_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
2662 bool is_pcie_gen2_supported(uint32_t pcie_link_speed_cap)
2664 if (pcie_link_speed_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2)
2670 /* Get the new PCIE speed given the ASIC PCIE Cap and the NewState's requested PCIE speed*/
2671 uint16_t get_pcie_gen_support(uint32_t pcie_link_speed_cap, uint16_t ns_pcie_gen)
2673 uint32_t asic_pcie_link_speed_cap = (pcie_link_speed_cap &
2674 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_MASK);
2675 uint32_t sys_pcie_link_speed_cap = (pcie_link_speed_cap &
2676 CAIL_PCIE_LINK_SPEED_SUPPORT_MASK);
2678 switch (asic_pcie_link_speed_cap) {
2679 case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1:
2682 case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2:
2685 case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3:
2689 if (is_pcie_gen3_supported(sys_pcie_link_speed_cap) &&
2690 (ns_pcie_gen == PP_PCIEGen3)) {
2692 } else if (is_pcie_gen2_supported(sys_pcie_link_speed_cap) &&
2693 ((ns_pcie_gen == PP_PCIEGen3) || (ns_pcie_gen == PP_PCIEGen2))) {
2701 uint16_t get_pcie_lane_support(uint32_t pcie_lane_width_cap, uint16_t ns_pcie_lanes)
2704 uint16_t new_pcie_lanes = ns_pcie_lanes;
2705 uint16_t pcie_lanes[7] = {1, 2, 4, 8, 12, 16, 32};
2707 switch (pcie_lane_width_cap) {
2709 printk(KERN_ERR "[ powerplay ] No valid PCIE lane width reported by CAIL!");
2711 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X1:
2714 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X2:
2717 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X4:
2720 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X8:
2723 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X12:
2724 new_pcie_lanes = 12;
2726 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X16:
2727 new_pcie_lanes = 16;
2729 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X32:
2730 new_pcie_lanes = 32;
2733 for (i = 0; i < 7; i++) {
2734 if (ns_pcie_lanes == pcie_lanes[i]) {
2735 if (pcie_lane_width_cap & (0x10000 << i)) {
2738 for (j = i - 1; j >= 0; j--) {
2739 if (pcie_lane_width_cap & (0x10000 << j)) {
2740 new_pcie_lanes = pcie_lanes[j];
2746 for (j = i + 1; j < 7; j++) {
2747 if (pcie_lane_width_cap & (0x10000 << j)) {
2748 new_pcie_lanes = pcie_lanes[j];
2753 printk(KERN_ERR "[ powerplay ] Cannot find a valid PCIE lane width!");
2762 return new_pcie_lanes;
2765 static int tonga_setup_default_pcie_tables(struct pp_hwmgr *hwmgr)
2767 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2768 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2769 phm_ppt_v1_pcie_table *pcie_table = pptable_info->pcie_table;
2770 uint32_t i, maxEntry;
2772 if (data->use_pcie_performance_levels && !data->use_pcie_power_saving_levels) {
2773 data->pcie_gen_power_saving = data->pcie_gen_performance;
2774 data->pcie_lane_power_saving = data->pcie_lane_performance;
2775 } else if (!data->use_pcie_performance_levels && data->use_pcie_power_saving_levels) {
2776 data->pcie_gen_performance = data->pcie_gen_power_saving;
2777 data->pcie_lane_performance = data->pcie_lane_power_saving;
2780 tonga_reset_single_dpm_table(hwmgr, &data->dpm_table.pcie_speed_table, SMU72_MAX_LEVELS_LINK);
2782 if (pcie_table != NULL) {
2784 * maxEntry is used to make sure we reserve one PCIE level for boot level (fix for A+A PSPP issue).
2785 * If PCIE table from PPTable have ULV entry + 8 entries, then ignore the last entry.
2787 maxEntry = (SMU72_MAX_LEVELS_LINK < pcie_table->count) ?
2788 SMU72_MAX_LEVELS_LINK : pcie_table->count;
2789 for (i = 1; i < maxEntry; i++) {
2790 tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i-1,
2791 get_pcie_gen_support(data->pcie_gen_cap, pcie_table->entries[i].gen_speed),
2792 get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
2794 data->dpm_table.pcie_speed_table.count = maxEntry - 1;
2796 /* Hardcode Pcie Table */
2797 tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
2798 get_pcie_gen_support(data->pcie_gen_cap, PP_Min_PCIEGen),
2799 get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
2800 tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
2801 get_pcie_gen_support(data->pcie_gen_cap, PP_Min_PCIEGen),
2802 get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
2803 tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
2804 get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen),
2805 get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
2806 tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
2807 get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen),
2808 get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
2809 tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
2810 get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen),
2811 get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
2812 tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
2813 get_pcie_gen_support(data->pcie_gen_cap, PP_Max_PCIEGen),
2814 get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
2815 data->dpm_table.pcie_speed_table.count = 6;
2817 /* Populate last level for boot PCIE level, but do not increment count. */
2818 tonga_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
2819 data->dpm_table.pcie_speed_table.count,
2820 get_pcie_gen_support(data->pcie_gen_cap, PP_Min_PCIEGen),
2821 get_pcie_lane_support(data->pcie_lane_cap, PP_Max_PCIELane));
2828 * This function is to initalize all DPM state tables for SMU7 based on the dependency table.
2829 * Dynamic state patching function will then trim these state tables to the allowed range based
2830 * on the power policy or external client requests, such as UVD request, etc.
2832 static int tonga_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
2834 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2835 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2838 phm_ppt_v1_clock_voltage_dependency_table *allowed_vdd_sclk_table =
2839 pptable_info->vdd_dep_on_sclk;
2840 phm_ppt_v1_clock_voltage_dependency_table *allowed_vdd_mclk_table =
2841 pptable_info->vdd_dep_on_mclk;
2843 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL,
2844 "SCLK dependency table is missing. This table is mandatory", return -1);
2845 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table->count >= 1,
2846 "SCLK dependency table has to have is missing. This table is mandatory", return -1);
2848 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
2849 "MCLK dependency table is missing. This table is mandatory", return -1);
2850 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table->count >= 1,
2851 "VMCLK dependency table has to have is missing. This table is mandatory", return -1);
2853 /* clear the state table to reset everything to default */
2854 memset(&(data->dpm_table), 0x00, sizeof(data->dpm_table));
2855 tonga_reset_single_dpm_table(hwmgr, &data->dpm_table.sclk_table, SMU72_MAX_LEVELS_GRAPHICS);
2856 tonga_reset_single_dpm_table(hwmgr, &data->dpm_table.mclk_table, SMU72_MAX_LEVELS_MEMORY);
2857 /* tonga_reset_single_dpm_table(hwmgr, &tonga_hwmgr->dpm_table.VddcTable, SMU72_MAX_LEVELS_VDDC); */
2858 /* tonga_reset_single_dpm_table(hwmgr, &tonga_hwmgr->dpm_table.vdd_gfx_table, SMU72_MAX_LEVELS_VDDGFX);*/
2859 /* tonga_reset_single_dpm_table(hwmgr, &tonga_hwmgr->dpm_table.vdd_ci_table, SMU72_MAX_LEVELS_VDDCI);*/
2860 /* tonga_reset_single_dpm_table(hwmgr, &tonga_hwmgr->dpm_table.mvdd_table, SMU72_MAX_LEVELS_MVDD);*/
2862 PP_ASSERT_WITH_CODE(allowed_vdd_sclk_table != NULL,
2863 "SCLK dependency table is missing. This table is mandatory", return -1);
2864 /* Initialize Sclk DPM table based on allow Sclk values*/
2865 data->dpm_table.sclk_table.count = 0;
2867 for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
2868 if (i == 0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count-1].value !=
2869 allowed_vdd_sclk_table->entries[i].clk) {
2870 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value =
2871 allowed_vdd_sclk_table->entries[i].clk;
2872 data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled = 1; /*(i==0) ? 1 : 0; to do */
2873 data->dpm_table.sclk_table.count++;
2877 PP_ASSERT_WITH_CODE(allowed_vdd_mclk_table != NULL,
2878 "MCLK dependency table is missing. This table is mandatory", return -1);
2879 /* Initialize Mclk DPM table based on allow Mclk values */
2880 data->dpm_table.mclk_table.count = 0;
2881 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
2882 if (i == 0 || data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count-1].value !=
2883 allowed_vdd_mclk_table->entries[i].clk) {
2884 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value =
2885 allowed_vdd_mclk_table->entries[i].clk;
2886 data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled = 1; /*(i==0) ? 1 : 0; */
2887 data->dpm_table.mclk_table.count++;
2891 /* Initialize Vddc DPM table based on allow Vddc values. And populate corresponding std values. */
2892 for (i = 0; i < allowed_vdd_sclk_table->count; i++) {
2893 data->dpm_table.vddc_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].vddc;
2894 /* tonga_hwmgr->dpm_table.VddcTable.dpm_levels[i].param1 = stdVoltageTable->entries[i].Leakage; */
2895 /* param1 is for corresponding std voltage */
2896 data->dpm_table.vddc_table.dpm_levels[i].enabled = 1;
2898 data->dpm_table.vddc_table.count = allowed_vdd_sclk_table->count;
2900 if (NULL != allowed_vdd_mclk_table) {
2901 /* Initialize Vddci DPM table based on allow Mclk values */
2902 for (i = 0; i < allowed_vdd_mclk_table->count; i++) {
2903 data->dpm_table.vdd_ci_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].vddci;
2904 data->dpm_table.vdd_ci_table.dpm_levels[i].enabled = 1;
2905 data->dpm_table.mvdd_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].mvdd;
2906 data->dpm_table.mvdd_table.dpm_levels[i].enabled = 1;
2908 data->dpm_table.vdd_ci_table.count = allowed_vdd_mclk_table->count;
2909 data->dpm_table.mvdd_table.count = allowed_vdd_mclk_table->count;
2912 /* setup PCIE gen speed levels*/
2913 tonga_setup_default_pcie_tables(hwmgr);
2915 /* save a copy of the default DPM table*/
2916 memcpy(&(data->golden_dpm_table), &(data->dpm_table), sizeof(struct tonga_dpm_table));
2921 int tonga_populate_smc_initial_state(struct pp_hwmgr *hwmgr,
2922 const struct tonga_power_state *bootState)
2924 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2925 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2926 uint8_t count, level;
2928 count = (uint8_t) (pptable_info->vdd_dep_on_sclk->count);
2929 for (level = 0; level < count; level++) {
2930 if (pptable_info->vdd_dep_on_sclk->entries[level].clk >=
2931 bootState->performance_levels[0].engine_clock) {
2932 data->smc_state_table.GraphicsBootLevel = level;
2937 count = (uint8_t) (pptable_info->vdd_dep_on_mclk->count);
2938 for (level = 0; level < count; level++) {
2939 if (pptable_info->vdd_dep_on_mclk->entries[level].clk >=
2940 bootState->performance_levels[0].memory_clock) {
2941 data->smc_state_table.MemoryBootLevel = level;
2950 * Initializes the SMC table and uploads it
2952 * @param hwmgr the address of the powerplay hardware manager.
2953 * @param pInput the pointer to input data (PowerState)
2956 int tonga_init_smc_table(struct pp_hwmgr *hwmgr)
2959 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
2960 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
2961 SMU72_Discrete_DpmTable *table = &(data->smc_state_table);
2962 const phw_tonga_ulv_parm *ulv = &(data->ulv);
2964 PECI_RegistryValue reg_value;
2965 pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
2967 result = tonga_setup_default_dpm_tables(hwmgr);
2968 PP_ASSERT_WITH_CODE(0 == result,
2969 "Failed to setup default DPM tables!", return result;);
2970 memset(&(data->smc_state_table), 0x00, sizeof(data->smc_state_table));
2971 if (TONGA_VOLTAGE_CONTROL_NONE != data->voltage_control) {
2972 tonga_populate_smc_voltage_tables(hwmgr, table);
2975 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2976 PHM_PlatformCaps_AutomaticDCTransition)) {
2977 table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
2980 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2981 PHM_PlatformCaps_StepVddc)) {
2982 table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
2985 if (data->is_memory_GDDR5) {
2986 table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
2989 i = PHM_READ_FIELD(hwmgr->device, CC_MC_MAX_CHANNEL, NOOFCHAN);
2991 if (i == 1 || i == 0) {
2992 table->SystemFlags |= PPSMC_SYSTEMFLAG_12CHANNEL;
2995 if (ulv->ulv_supported && pptable_info->us_ulv_voltage_offset) {
2996 PP_ASSERT_WITH_CODE(0 == result,
2997 "Failed to initialize ULV state!", return result;);
2999 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3000 ixCG_ULV_PARAMETER, ulv->ch_ulv_parameter);
3003 result = tonga_populate_smc_link_level(hwmgr, table);
3004 PP_ASSERT_WITH_CODE(0 == result,
3005 "Failed to initialize Link Level!", return result;);
3007 result = tonga_populate_all_graphic_levels(hwmgr);
3008 PP_ASSERT_WITH_CODE(0 == result,
3009 "Failed to initialize Graphics Level!", return result;);
3011 result = tonga_populate_all_memory_levels(hwmgr);
3012 PP_ASSERT_WITH_CODE(0 == result,
3013 "Failed to initialize Memory Level!", return result;);
3015 result = tonga_populate_smv_acpi_level(hwmgr, table);
3016 PP_ASSERT_WITH_CODE(0 == result,
3017 "Failed to initialize ACPI Level!", return result;);
3019 result = tonga_populate_smc_vce_level(hwmgr, table);
3020 PP_ASSERT_WITH_CODE(0 == result,
3021 "Failed to initialize VCE Level!", return result;);
3023 result = tonga_populate_smc_acp_level(hwmgr, table);
3024 PP_ASSERT_WITH_CODE(0 == result,
3025 "Failed to initialize ACP Level!", return result;);
3027 result = tonga_populate_smc_samu_level(hwmgr, table);
3028 PP_ASSERT_WITH_CODE(0 == result,
3029 "Failed to initialize SAMU Level!", return result;);
3031 /* Since only the initial state is completely set up at this point (the other states are just copies of the boot state) we only */
3032 /* need to populate the ARB settings for the initial state. */
3033 result = tonga_program_memory_timing_parameters(hwmgr);
3034 PP_ASSERT_WITH_CODE(0 == result,
3035 "Failed to Write ARB settings for the initial state.", return result;);
3037 result = tonga_populate_smc_boot_level(hwmgr, table);
3038 PP_ASSERT_WITH_CODE(0 == result,
3039 "Failed to initialize Boot Level!", return result;);
3041 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3042 PHM_PlatformCaps_ClockStretcher)) {
3043 result = tonga_populate_clock_stretcher_data_table(hwmgr);
3044 PP_ASSERT_WITH_CODE(0 == result,
3045 "Failed to populate Clock Stretcher Data Table!", return result;);
3047 table->GraphicsVoltageChangeEnable = 1;
3048 table->GraphicsThermThrottleEnable = 1;
3049 table->GraphicsInterval = 1;
3050 table->VoltageInterval = 1;
3051 table->ThermalInterval = 1;
3052 table->TemperatureLimitHigh =
3053 pptable_info->cac_dtp_table->usTargetOperatingTemp *
3054 TONGA_Q88_FORMAT_CONVERSION_UNIT;
3055 table->TemperatureLimitLow =
3056 (pptable_info->cac_dtp_table->usTargetOperatingTemp - 1) *
3057 TONGA_Q88_FORMAT_CONVERSION_UNIT;
3058 table->MemoryVoltageChangeEnable = 1;
3059 table->MemoryInterval = 1;
3060 table->VoltageResponseTime = 0;
3061 table->PhaseResponseTime = 0;
3062 table->MemoryThermThrottleEnable = 1;
3065 * Cail reads current link status and reports it as cap (we cannot change this due to some previous issues we had)
3066 * SMC drops the link status to lowest level after enabling DPM by PowerPlay. After pnp or toggling CF, driver gets reloaded again
3067 * but this time Cail reads current link status which was set to low by SMC and reports it as cap to powerplay
3068 * To avoid it, we set PCIeBootLinkLevel to highest dpm level
3070 PP_ASSERT_WITH_CODE((1 <= data->dpm_table.pcie_speed_table.count),
3071 "There must be 1 or more PCIE levels defined in PPTable.",
3074 table->PCIeBootLinkLevel = (uint8_t) (data->dpm_table.pcie_speed_table.count);
3076 table->PCIeGenInterval = 1;
3078 result = tonga_populate_vr_config(hwmgr, table);
3079 PP_ASSERT_WITH_CODE(0 == result,
3080 "Failed to populate VRConfig setting!", return result);
3082 table->ThermGpio = 17;
3083 table->SclkStepSize = 0x4000;
3086 if ((0 == reg_value) &&
3087 (0 == atomctrl_get_pp_assign_pin(hwmgr,
3088 VDDC_VRHOT_GPIO_PINID, &gpio_pin_assignment))) {
3089 table->VRHotGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift;
3090 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3091 PHM_PlatformCaps_RegulatorHot);
3093 table->VRHotGpio = TONGA_UNUSED_GPIO_PIN;
3094 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3095 PHM_PlatformCaps_RegulatorHot);
3098 /* ACDC Switch GPIO */
3100 if ((0 == reg_value) &&
3101 (0 == atomctrl_get_pp_assign_pin(hwmgr,
3102 PP_AC_DC_SWITCH_GPIO_PINID, &gpio_pin_assignment))) {
3103 table->AcDcGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift;
3104 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3105 PHM_PlatformCaps_AutomaticDCTransition);
3107 table->AcDcGpio = TONGA_UNUSED_GPIO_PIN;
3108 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3109 PHM_PlatformCaps_AutomaticDCTransition);
3112 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3113 PHM_PlatformCaps_Falcon_QuickTransition);
3116 if (1 == reg_value) {
3117 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3118 PHM_PlatformCaps_AutomaticDCTransition);
3119 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3120 PHM_PlatformCaps_Falcon_QuickTransition);
3124 if ((0 == reg_value) &&
3125 (0 == atomctrl_get_pp_assign_pin(hwmgr,
3126 THERMAL_INT_OUTPUT_GPIO_PINID, &gpio_pin_assignment))) {
3127 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3128 PHM_PlatformCaps_ThermalOutGPIO);
3130 table->ThermOutGpio = gpio_pin_assignment.uc_gpio_pin_bit_shift;
3132 table->ThermOutPolarity =
3133 (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A) &
3134 (1 << gpio_pin_assignment.uc_gpio_pin_bit_shift))) ? 1:0;
3136 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY;
3138 /* if required, combine VRHot/PCC with thermal out GPIO*/
3139 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3140 PHM_PlatformCaps_RegulatorHot) &&
3141 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3142 PHM_PlatformCaps_CombinePCCWithThermalSignal)){
3143 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT;
3146 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3147 PHM_PlatformCaps_ThermalOutGPIO);
3149 table->ThermOutGpio = 17;
3150 table->ThermOutPolarity = 1;
3151 table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE;
3154 for (i = 0; i < SMU72_MAX_ENTRIES_SMIO; i++) {
3155 table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]);
3157 CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
3158 CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig);
3159 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1);
3160 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2);
3161 CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
3162 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
3163 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
3164 CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
3165 CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
3167 /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
3168 result = tonga_copy_bytes_to_smc(hwmgr->smumgr, data->dpm_table_start +
3169 offsetof(SMU72_Discrete_DpmTable, SystemFlags),
3170 (uint8_t *)&(table->SystemFlags),
3171 sizeof(SMU72_Discrete_DpmTable)-3 * sizeof(SMU72_PIDController),
3174 PP_ASSERT_WITH_CODE(0 == result,
3175 "Failed to upload dpm data to SMC memory!", return result;);
3180 /* Look up the voltaged based on DAL's requested level. and then send the requested VDDC voltage to SMC*/
3181 static void tonga_apply_dal_minimum_voltage_request(struct pp_hwmgr *hwmgr)
3186 int tonga_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
3188 PPSMC_Result result;
3189 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
3191 /* Apply minimum voltage based on DAL's request level */
3192 tonga_apply_dal_minimum_voltage_request(hwmgr);
3194 if (0 == data->sclk_dpm_key_disabled) {
3195 /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/
3196 if (0 != tonga_is_dpm_running(hwmgr))
3197 printk(KERN_ERR "[ powerplay ] Trying to set Enable Mask when DPM is disabled \n");
3199 if (0 != data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3200 result = smum_send_msg_to_smc_with_parameter(
3202 (PPSMC_Msg)PPSMC_MSG_SCLKDPM_SetEnabledMask,
3203 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3204 PP_ASSERT_WITH_CODE((0 == result),
3205 "Set Sclk Dpm enable Mask failed", return -1);
3209 if (0 == data->mclk_dpm_key_disabled) {
3210 /* Checking if DPM is running. If we discover hang because of this, we should skip this message.*/
3211 if (0 != tonga_is_dpm_running(hwmgr))
3212 printk(KERN_ERR "[ powerplay ] Trying to set Enable Mask when DPM is disabled \n");
3214 if (0 != data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3215 result = smum_send_msg_to_smc_with_parameter(
3217 (PPSMC_Msg)PPSMC_MSG_MCLKDPM_SetEnabledMask,
3218 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3219 PP_ASSERT_WITH_CODE((0 == result),
3220 "Set Mclk Dpm enable Mask failed", return -1);
3228 int tonga_force_dpm_highest(struct pp_hwmgr *hwmgr)
3230 uint32_t level, tmp;
3231 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
3233 if (0 == data->pcie_dpm_key_disabled) {
3235 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask != 0) {
3237 tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
3242 PP_ASSERT_WITH_CODE((0 == tonga_dpm_force_state_pcie(hwmgr, level)),
3243 "force highest pcie dpm state failed!", return -1);
3248 if (0 == data->sclk_dpm_key_disabled) {
3250 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask != 0) {
3252 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
3257 PP_ASSERT_WITH_CODE((0 == tonga_dpm_force_state(hwmgr, level)),
3258 "force highest sclk dpm state failed!", return -1);
3259 if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
3260 CGS_IND_REG__SMC, TARGET_AND_CURRENT_PROFILE_INDEX, CURR_SCLK_INDEX) != level)
3261 printk(KERN_ERR "[ powerplay ] Target_and_current_Profile_Index. \
3262 Curr_Sclk_Index does not match the level \n");
3268 if (0 == data->mclk_dpm_key_disabled) {
3270 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask != 0) {
3272 tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
3277 PP_ASSERT_WITH_CODE((0 == tonga_dpm_force_state_mclk(hwmgr, level)),
3278 "force highest mclk dpm state failed!", return -1);
3279 if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3280 TARGET_AND_CURRENT_PROFILE_INDEX, CURR_MCLK_INDEX) != level)
3281 printk(KERN_ERR "[ powerplay ] Target_and_current_Profile_Index. \
3282 Curr_Mclk_Index does not match the level \n");
3291 * Find the MC microcode version and store it in the HwMgr struct
3293 * @param hwmgr the address of the powerplay hardware manager.
3296 int tonga_get_mc_microcode_version (struct pp_hwmgr *hwmgr)
3298 cgs_write_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX, 0x9F);
3300 hwmgr->microcode_version_info.MC = cgs_read_register(hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA);
3306 * Initialize Dynamic State Adjustment Rule Settings
3308 * @param hwmgr the address of the powerplay hardware manager.
3310 int tonga_initializa_dynamic_state_adjustment_rule_settings(struct pp_hwmgr *hwmgr)
3312 uint32_t table_size;
3313 struct phm_clock_voltage_dependency_table *table_clk_vlt;
3314 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
3316 hwmgr->dyn_state.mclk_sclk_ratio = 4;
3317 hwmgr->dyn_state.sclk_mclk_delta = 15000; /* 150 MHz */
3318 hwmgr->dyn_state.vddc_vddci_delta = 200; /* 200mV */
3320 /* initialize vddc_dep_on_dal_pwrl table */
3321 table_size = sizeof(uint32_t) + 4 * sizeof(struct phm_clock_voltage_dependency_record);
3322 table_clk_vlt = (struct phm_clock_voltage_dependency_table *)kzalloc(table_size, GFP_KERNEL);
3324 if (NULL == table_clk_vlt) {
3325 printk(KERN_ERR "[ powerplay ] Can not allocate space for vddc_dep_on_dal_pwrl! \n");
3328 table_clk_vlt->count = 4;
3329 table_clk_vlt->entries[0].clk = PP_DAL_POWERLEVEL_ULTRALOW;
3330 table_clk_vlt->entries[0].v = 0;
3331 table_clk_vlt->entries[1].clk = PP_DAL_POWERLEVEL_LOW;
3332 table_clk_vlt->entries[1].v = 720;
3333 table_clk_vlt->entries[2].clk = PP_DAL_POWERLEVEL_NOMINAL;
3334 table_clk_vlt->entries[2].v = 810;
3335 table_clk_vlt->entries[3].clk = PP_DAL_POWERLEVEL_PERFORMANCE;
3336 table_clk_vlt->entries[3].v = 900;
3337 pptable_info->vddc_dep_on_dal_pwrl = table_clk_vlt;
3338 hwmgr->dyn_state.vddc_dep_on_dal_pwrl = table_clk_vlt;
3344 static int tonga_set_private_var_based_on_pptale(struct pp_hwmgr *hwmgr)
3346 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
3347 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
3349 phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
3350 pptable_info->vdd_dep_on_sclk;
3351 phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
3352 pptable_info->vdd_dep_on_mclk;
3354 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
3355 "VDD dependency on SCLK table is missing. \
3356 This table is mandatory", return -1);
3357 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
3358 "VDD dependency on SCLK table has to have is missing. \
3359 This table is mandatory", return -1);
3361 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
3362 "VDD dependency on MCLK table is missing. \
3363 This table is mandatory", return -1);
3364 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
3365 "VDD dependency on MCLK table has to have is missing. \
3366 This table is mandatory", return -1);
3368 data->min_vddc_in_pp_table = (uint16_t)allowed_sclk_vdd_table->entries[0].vddc;
3369 data->max_vddc_in_pp_table = (uint16_t)allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
3371 pptable_info->max_clock_voltage_on_ac.sclk =
3372 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
3373 pptable_info->max_clock_voltage_on_ac.mclk =
3374 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
3375 pptable_info->max_clock_voltage_on_ac.vddc =
3376 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
3377 pptable_info->max_clock_voltage_on_ac.vddci =
3378 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
3380 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
3381 pptable_info->max_clock_voltage_on_ac.sclk;
3382 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
3383 pptable_info->max_clock_voltage_on_ac.mclk;
3384 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
3385 pptable_info->max_clock_voltage_on_ac.vddc;
3386 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci =
3387 pptable_info->max_clock_voltage_on_ac.vddci;
3392 int tonga_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
3394 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
3397 PP_ASSERT_WITH_CODE (0 == tonga_is_dpm_running(hwmgr),
3398 "Trying to Unforce DPM when DPM is disabled. Returning without sending SMC message.",
3401 if (0 == data->pcie_dpm_key_disabled) {
3402 PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(
3404 PPSMC_MSG_PCIeDPM_UnForceLevel)),
3405 "unforce pcie level failed!",
3409 result = tonga_upload_dpm_level_enable_mask(hwmgr);
3414 static uint32_t tonga_get_lowest_enable_level(
3415 struct pp_hwmgr *hwmgr, uint32_t level_mask)
3419 while (0 == (level_mask & (1 << level)))
3425 static int tonga_force_dpm_lowest(struct pp_hwmgr *hwmgr)
3428 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
3430 if (0 == data->pcie_dpm_key_disabled) {
3432 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask != 0) {
3433 level = tonga_get_lowest_enable_level(hwmgr,
3434 data->dpm_level_enable_mask.pcie_dpm_enable_mask);
3435 PP_ASSERT_WITH_CODE((0 == tonga_dpm_force_state_pcie(hwmgr, level)),
3436 "force lowest pcie dpm state failed!", return -1);
3440 if (0 == data->sclk_dpm_key_disabled) {
3442 if (0 != data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3443 level = tonga_get_lowest_enable_level(hwmgr,
3444 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3446 PP_ASSERT_WITH_CODE((0 == tonga_dpm_force_state(hwmgr, level)),
3447 "force sclk dpm state failed!", return -1);
3449 if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
3450 CGS_IND_REG__SMC, TARGET_AND_CURRENT_PROFILE_INDEX, CURR_SCLK_INDEX) != level)
3451 printk(KERN_ERR "[ powerplay ] Target_and_current_Profile_Index. \
3452 Curr_Sclk_Index does not match the level \n");
3456 if (0 == data->mclk_dpm_key_disabled) {
3458 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask != 0) {
3459 level = tonga_get_lowest_enable_level(hwmgr,
3460 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3461 PP_ASSERT_WITH_CODE((0 == tonga_dpm_force_state_mclk(hwmgr, level)),
3462 "force lowest mclk dpm state failed!", return -1);
3463 if (PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3464 TARGET_AND_CURRENT_PROFILE_INDEX, CURR_MCLK_INDEX) != level)
3465 printk(KERN_ERR "[ powerplay ] Target_and_current_Profile_Index. \
3466 Curr_Mclk_Index does not match the level \n");
3473 static int tonga_patch_voltage_dependency_tables_with_lookup_table(struct pp_hwmgr *hwmgr)
3477 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
3478 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
3480 phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk;
3481 phm_ppt_v1_clock_voltage_dependency_table *mclk_table = pptable_info->vdd_dep_on_mclk;
3482 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table;
3484 if (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) {
3485 for (entryId = 0; entryId < sclk_table->count; ++entryId) {
3486 voltageId = sclk_table->entries[entryId].vddInd;
3487 sclk_table->entries[entryId].vddgfx =
3488 pptable_info->vddgfx_lookup_table->entries[voltageId].us_vdd;
3491 for (entryId = 0; entryId < sclk_table->count; ++entryId) {
3492 voltageId = sclk_table->entries[entryId].vddInd;
3493 sclk_table->entries[entryId].vddc =
3494 pptable_info->vddc_lookup_table->entries[voltageId].us_vdd;
3498 for (entryId = 0; entryId < mclk_table->count; ++entryId) {
3499 voltageId = mclk_table->entries[entryId].vddInd;
3500 mclk_table->entries[entryId].vddc =
3501 pptable_info->vddc_lookup_table->entries[voltageId].us_vdd;
3504 for (entryId = 0; entryId < mm_table->count; ++entryId) {
3505 voltageId = mm_table->entries[entryId].vddcInd;
3506 mm_table->entries[entryId].vddc =
3507 pptable_info->vddc_lookup_table->entries[voltageId].us_vdd;
3514 static int tonga_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
3517 phm_ppt_v1_voltage_lookup_record v_record;
3518 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
3519 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
3521 phm_ppt_v1_clock_voltage_dependency_table *sclk_table = pptable_info->vdd_dep_on_sclk;
3522 phm_ppt_v1_clock_voltage_dependency_table *mclk_table = pptable_info->vdd_dep_on_mclk;
3524 if (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) {
3525 for (entryId = 0; entryId < sclk_table->count; ++entryId) {
3526 if (sclk_table->entries[entryId].vdd_offset & (1 << 15))
3527 v_record.us_vdd = sclk_table->entries[entryId].vddgfx +
3528 sclk_table->entries[entryId].vdd_offset - 0xFFFF;
3530 v_record.us_vdd = sclk_table->entries[entryId].vddgfx +
3531 sclk_table->entries[entryId].vdd_offset;
3533 sclk_table->entries[entryId].vddc =
3534 v_record.us_cac_low = v_record.us_cac_mid =
3535 v_record.us_cac_high = v_record.us_vdd;
3537 tonga_add_voltage(hwmgr, pptable_info->vddc_lookup_table, &v_record);
3540 for (entryId = 0; entryId < mclk_table->count; ++entryId) {
3541 if (mclk_table->entries[entryId].vdd_offset & (1 << 15))
3542 v_record.us_vdd = mclk_table->entries[entryId].vddc +
3543 mclk_table->entries[entryId].vdd_offset - 0xFFFF;
3545 v_record.us_vdd = mclk_table->entries[entryId].vddc +
3546 mclk_table->entries[entryId].vdd_offset;
3548 mclk_table->entries[entryId].vddgfx = v_record.us_cac_low =
3549 v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
3550 tonga_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
3558 static int tonga_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
3561 phm_ppt_v1_voltage_lookup_record v_record;
3562 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
3563 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
3564 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table = pptable_info->mm_dep_table;
3566 if (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) {
3567 for (entryId = 0; entryId < mm_table->count; entryId++) {
3568 if (mm_table->entries[entryId].vddgfx_offset & (1 << 15))
3569 v_record.us_vdd = mm_table->entries[entryId].vddc +
3570 mm_table->entries[entryId].vddgfx_offset - 0xFFFF;
3572 v_record.us_vdd = mm_table->entries[entryId].vddc +
3573 mm_table->entries[entryId].vddgfx_offset;
3575 /* Add the calculated VDDGFX to the VDDGFX lookup table */
3576 mm_table->entries[entryId].vddgfx = v_record.us_cac_low =
3577 v_record.us_cac_mid = v_record.us_cac_high = v_record.us_vdd;
3578 tonga_add_voltage(hwmgr, pptable_info->vddgfx_lookup_table, &v_record);
3586 * Change virtual leakage voltage to actual value.
3588 * @param hwmgr the address of the powerplay hardware manager.
3589 * @param pointer to changing voltage
3590 * @param pointer to leakage table
3592 static void tonga_patch_with_vdd_leakage(struct pp_hwmgr *hwmgr,
3593 uint16_t *voltage, phw_tonga_leakage_voltage *pLeakageTable)
3595 uint32_t leakage_index;
3597 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
3598 for (leakage_index = 0; leakage_index < pLeakageTable->count; leakage_index++) {
3599 /* if this voltage matches a leakage voltage ID */
3600 /* patch with actual leakage voltage */
3601 if (pLeakageTable->leakage_id[leakage_index] == *voltage) {
3602 *voltage = pLeakageTable->actual_voltage[leakage_index];
3607 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
3608 printk(KERN_ERR "[ powerplay ] Voltage value looks like a Leakage ID but it's not patched \n");
3612 * Patch voltage lookup table by EVV leakages.
3614 * @param hwmgr the address of the powerplay hardware manager.
3615 * @param pointer to voltage lookup table
3616 * @param pointer to leakage table
3619 static int tonga_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
3620 phm_ppt_v1_voltage_lookup_table *lookup_table,
3621 phw_tonga_leakage_voltage *pLeakageTable)
3625 for (i = 0; i < lookup_table->count; i++) {
3626 tonga_patch_with_vdd_leakage(hwmgr,
3627 &lookup_table->entries[i].us_vdd, pLeakageTable);
3633 static int tonga_patch_clock_voltage_lomits_with_vddc_leakage(struct pp_hwmgr *hwmgr,
3634 phw_tonga_leakage_voltage *pLeakageTable, uint16_t *Vddc)
3636 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
3638 tonga_patch_with_vdd_leakage(hwmgr, (uint16_t *)Vddc, pLeakageTable);
3639 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
3640 pptable_info->max_clock_voltage_on_dc.vddc;
3645 static int tonga_patch_clock_voltage_limits_with_vddgfx_leakage(
3646 struct pp_hwmgr *hwmgr, phw_tonga_leakage_voltage *pLeakageTable,
3649 tonga_patch_with_vdd_leakage(hwmgr, (uint16_t *)Vddgfx, pLeakageTable);
3653 int tonga_sort_lookup_table(struct pp_hwmgr *hwmgr,
3654 phm_ppt_v1_voltage_lookup_table *lookup_table)
3656 uint32_t table_size, i, j;
3657 phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record;
3658 table_size = lookup_table->count;
3660 PP_ASSERT_WITH_CODE(0 != lookup_table->count,
3661 "Lookup table is empty", return -1);
3663 /* Sorting voltages */
3664 for (i = 0; i < table_size - 1; i++) {
3665 for (j = i + 1; j > 0; j--) {
3666 if (lookup_table->entries[j].us_vdd < lookup_table->entries[j-1].us_vdd) {
3667 tmp_voltage_lookup_record = lookup_table->entries[j-1];
3668 lookup_table->entries[j-1] = lookup_table->entries[j];
3669 lookup_table->entries[j] = tmp_voltage_lookup_record;
3677 static int tonga_complete_dependency_tables(struct pp_hwmgr *hwmgr)
3681 tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
3682 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
3684 if (data->vdd_gfx_control == TONGA_VOLTAGE_CONTROL_BY_SVID2) {
3685 tmp_result = tonga_patch_lookup_table_with_leakage(hwmgr,
3686 pptable_info->vddgfx_lookup_table, &(data->vddcgfx_leakage));
3687 if (tmp_result != 0)
3688 result = tmp_result;
3690 tmp_result = tonga_patch_clock_voltage_limits_with_vddgfx_leakage(hwmgr,
3691 &(data->vddcgfx_leakage), &pptable_info->max_clock_voltage_on_dc.vddgfx);
3692 if (tmp_result != 0)
3693 result = tmp_result;
3695 tmp_result = tonga_patch_lookup_table_with_leakage(hwmgr,
3696 pptable_info->vddc_lookup_table, &(data->vddc_leakage));
3697 if (tmp_result != 0)
3698 result = tmp_result;
3700 tmp_result = tonga_patch_clock_voltage_lomits_with_vddc_leakage(hwmgr,
3701 &(data->vddc_leakage), &pptable_info->max_clock_voltage_on_dc.vddc);
3702 if (tmp_result != 0)
3703 result = tmp_result;
3706 tmp_result = tonga_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
3707 if (tmp_result != 0)
3708 result = tmp_result;
3710 tmp_result = tonga_calc_voltage_dependency_tables(hwmgr);
3711 if (tmp_result != 0)
3712 result = tmp_result;
3714 tmp_result = tonga_calc_mm_voltage_dependency_table(hwmgr);
3715 if (tmp_result != 0)
3716 result = tmp_result;
3718 tmp_result = tonga_sort_lookup_table(hwmgr, pptable_info->vddgfx_lookup_table);
3719 if (tmp_result != 0)
3720 result = tmp_result;
3722 tmp_result = tonga_sort_lookup_table(hwmgr, pptable_info->vddc_lookup_table);
3723 if (tmp_result != 0)
3724 result = tmp_result;
3729 int tonga_init_sclk_threshold(struct pp_hwmgr *hwmgr)
3731 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
3732 data->low_sclk_interrupt_threshold = 0;
3737 int tonga_setup_asic_task(struct pp_hwmgr *hwmgr)
3739 int tmp_result, result = 0;
3741 tmp_result = tonga_read_clock_registers(hwmgr);
3742 PP_ASSERT_WITH_CODE((0 == tmp_result),
3743 "Failed to read clock registers!", result = tmp_result);
3745 tmp_result = tonga_get_memory_type(hwmgr);
3746 PP_ASSERT_WITH_CODE((0 == tmp_result),
3747 "Failed to get memory type!", result = tmp_result);
3749 tmp_result = tonga_enable_acpi_power_management(hwmgr);
3750 PP_ASSERT_WITH_CODE((0 == tmp_result),
3751 "Failed to enable ACPI power management!", result = tmp_result);
3753 tmp_result = tonga_init_power_gate_state(hwmgr);
3754 PP_ASSERT_WITH_CODE((0 == tmp_result),
3755 "Failed to init power gate state!", result = tmp_result);
3757 tmp_result = tonga_get_mc_microcode_version(hwmgr);
3758 PP_ASSERT_WITH_CODE((0 == tmp_result),
3759 "Failed to get MC microcode version!", result = tmp_result);
3761 tmp_result = tonga_init_sclk_threshold(hwmgr);
3762 PP_ASSERT_WITH_CODE((0 == tmp_result),
3763 "Failed to init sclk threshold!", result = tmp_result);
3769 * Enable voltage control
3771 * @param hwmgr the address of the powerplay hardware manager.
3774 int tonga_enable_voltage_control(struct pp_hwmgr *hwmgr)
3776 /* enable voltage control */
3777 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
3783 * Checks if we want to support voltage control
3785 * @param hwmgr the address of the powerplay hardware manager.
3787 bool cf_tonga_voltage_control(const struct pp_hwmgr *hwmgr)
3789 const struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
3791 return(TONGA_VOLTAGE_CONTROL_NONE != data->voltage_control);
3794 /*---------------------------MC----------------------------*/
3796 uint8_t tonga_get_memory_modile_index(struct pp_hwmgr *hwmgr)
3798 return (uint8_t) (0xFF & (cgs_read_register(hwmgr->device, mmBIOS_SCRATCH_4) >> 16));
3801 bool tonga_check_s0_mc_reg_index(uint16_t inReg, uint16_t *outReg)
3806 case mmMC_SEQ_RAS_TIMING:
3807 *outReg = mmMC_SEQ_RAS_TIMING_LP;
3810 case mmMC_SEQ_DLL_STBY:
3811 *outReg = mmMC_SEQ_DLL_STBY_LP;
3814 case mmMC_SEQ_G5PDX_CMD0:
3815 *outReg = mmMC_SEQ_G5PDX_CMD0_LP;
3818 case mmMC_SEQ_G5PDX_CMD1:
3819 *outReg = mmMC_SEQ_G5PDX_CMD1_LP;
3822 case mmMC_SEQ_G5PDX_CTRL:
3823 *outReg = mmMC_SEQ_G5PDX_CTRL_LP;
3826 case mmMC_SEQ_CAS_TIMING:
3827 *outReg = mmMC_SEQ_CAS_TIMING_LP;
3830 case mmMC_SEQ_MISC_TIMING:
3831 *outReg = mmMC_SEQ_MISC_TIMING_LP;
3834 case mmMC_SEQ_MISC_TIMING2:
3835 *outReg = mmMC_SEQ_MISC_TIMING2_LP;
3838 case mmMC_SEQ_PMG_DVS_CMD:
3839 *outReg = mmMC_SEQ_PMG_DVS_CMD_LP;
3842 case mmMC_SEQ_PMG_DVS_CTL:
3843 *outReg = mmMC_SEQ_PMG_DVS_CTL_LP;
3846 case mmMC_SEQ_RD_CTL_D0:
3847 *outReg = mmMC_SEQ_RD_CTL_D0_LP;
3850 case mmMC_SEQ_RD_CTL_D1:
3851 *outReg = mmMC_SEQ_RD_CTL_D1_LP;
3854 case mmMC_SEQ_WR_CTL_D0:
3855 *outReg = mmMC_SEQ_WR_CTL_D0_LP;
3858 case mmMC_SEQ_WR_CTL_D1:
3859 *outReg = mmMC_SEQ_WR_CTL_D1_LP;
3862 case mmMC_PMG_CMD_EMRS:
3863 *outReg = mmMC_SEQ_PMG_CMD_EMRS_LP;
3866 case mmMC_PMG_CMD_MRS:
3867 *outReg = mmMC_SEQ_PMG_CMD_MRS_LP;
3870 case mmMC_PMG_CMD_MRS1:
3871 *outReg = mmMC_SEQ_PMG_CMD_MRS1_LP;
3874 case mmMC_SEQ_PMG_TIMING:
3875 *outReg = mmMC_SEQ_PMG_TIMING_LP;
3878 case mmMC_PMG_CMD_MRS2:
3879 *outReg = mmMC_SEQ_PMG_CMD_MRS2_LP;
3882 case mmMC_SEQ_WR_CTL_2:
3883 *outReg = mmMC_SEQ_WR_CTL_2_LP;
3894 int tonga_set_s0_mc_reg_index(phw_tonga_mc_reg_table *table)
3899 for (i = 0; i < table->last; i++) {
3900 table->mc_reg_address[i].s0 =
3901 tonga_check_s0_mc_reg_index(table->mc_reg_address[i].s1, &address)
3902 ? address : table->mc_reg_address[i].s1;
3907 int tonga_copy_vbios_smc_reg_table(const pp_atomctrl_mc_reg_table *table, phw_tonga_mc_reg_table *ni_table)
3911 PP_ASSERT_WITH_CODE((table->last <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
3912 "Invalid VramInfo table.", return -1);
3913 PP_ASSERT_WITH_CODE((table->num_entries <= MAX_AC_TIMING_ENTRIES),
3914 "Invalid VramInfo table.", return -1);
3916 for (i = 0; i < table->last; i++) {
3917 ni_table->mc_reg_address[i].s1 = table->mc_reg_address[i].s1;
3919 ni_table->last = table->last;
3921 for (i = 0; i < table->num_entries; i++) {
3922 ni_table->mc_reg_table_entry[i].mclk_max =
3923 table->mc_reg_table_entry[i].mclk_max;
3924 for (j = 0; j < table->last; j++) {
3925 ni_table->mc_reg_table_entry[i].mc_data[j] =
3926 table->mc_reg_table_entry[i].mc_data[j];
3929 ni_table->num_entries = table->num_entries;
3935 * VBIOS omits some information to reduce size, we need to recover them here.
3936 * 1. when we see mmMC_SEQ_MISC1, bit[31:16] EMRS1, need to be write to mmMC_PMG_CMD_EMRS /_LP[15:0].
3937 * Bit[15:0] MRS, need to be update mmMC_PMG_CMD_MRS/_LP[15:0]
3938 * 2. when we see mmMC_SEQ_RESERVE_M, bit[15:0] EMRS2, need to be write to mmMC_PMG_CMD_MRS1/_LP[15:0].
3939 * 3. need to set these data for each clock range
3941 * @param hwmgr the address of the powerplay hardware manager.
3942 * @param table the address of MCRegTable
3945 int tonga_set_mc_special_registers(struct pp_hwmgr *hwmgr, phw_tonga_mc_reg_table *table)
3949 const tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
3951 for (i = 0, j = table->last; i < table->last; i++) {
3952 PP_ASSERT_WITH_CODE((j < SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
3953 "Invalid VramInfo table.", return -1);
3954 switch (table->mc_reg_address[i].s1) {
3956 * mmMC_SEQ_MISC1, bit[31:16] EMRS1, need to be write to mmMC_PMG_CMD_EMRS /_LP[15:0].
3957 * Bit[15:0] MRS, need to be update mmMC_PMG_CMD_MRS/_LP[15:0]
3959 case mmMC_SEQ_MISC1:
3960 temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_EMRS);
3961 table->mc_reg_address[j].s1 = mmMC_PMG_CMD_EMRS;
3962 table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_EMRS_LP;
3963 for (k = 0; k < table->num_entries; k++) {
3964 table->mc_reg_table_entry[k].mc_data[j] =
3965 ((temp_reg & 0xffff0000)) |
3966 ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16);
3969 PP_ASSERT_WITH_CODE((j < SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
3970 "Invalid VramInfo table.", return -1);
3972 temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS);
3973 table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS;
3974 table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP;
3975 for (k = 0; k < table->num_entries; k++) {
3976 table->mc_reg_table_entry[k].mc_data[j] =
3977 (temp_reg & 0xffff0000) |
3978 (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
3980 if (!data->is_memory_GDDR5) {
3981 table->mc_reg_table_entry[k].mc_data[j] |= 0x100;
3985 PP_ASSERT_WITH_CODE((j <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
3986 "Invalid VramInfo table.", return -1);
3988 if (!data->is_memory_GDDR5) {
3989 table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD;
3990 table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD;
3991 for (k = 0; k < table->num_entries; k++) {
3992 table->mc_reg_table_entry[k].mc_data[j] =
3993 (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16;
3996 PP_ASSERT_WITH_CODE((j <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
3997 "Invalid VramInfo table.", return -1);
4002 case mmMC_SEQ_RESERVE_M:
4003 temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS1);
4004 table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS1;
4005 table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS1_LP;
4006 for (k = 0; k < table->num_entries; k++) {
4007 table->mc_reg_table_entry[k].mc_data[j] =
4008 (temp_reg & 0xffff0000) |
4009 (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
4012 PP_ASSERT_WITH_CODE((j <= SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE),
4013 "Invalid VramInfo table.", return -1);
4027 int tonga_set_valid_flag(phw_tonga_mc_reg_table *table)
4030 for (i = 0; i < table->last; i++) {
4031 for (j = 1; j < table->num_entries; j++) {
4032 if (table->mc_reg_table_entry[j-1].mc_data[i] !=
4033 table->mc_reg_table_entry[j].mc_data[i]) {
4034 table->validflag |= (1<<i);
4043 int tonga_initialize_mc_reg_table(struct pp_hwmgr *hwmgr)
4046 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
4047 pp_atomctrl_mc_reg_table *table;
4048 phw_tonga_mc_reg_table *ni_table = &data->tonga_mc_reg_table;
4049 uint8_t module_index = tonga_get_memory_modile_index(hwmgr);
4051 table = kzalloc(sizeof(pp_atomctrl_mc_reg_table), GFP_KERNEL);
4056 /* Program additional LP registers that are no longer programmed by VBIOS */
4057 cgs_write_register(hwmgr->device, mmMC_SEQ_RAS_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_RAS_TIMING));
4058 cgs_write_register(hwmgr->device, mmMC_SEQ_CAS_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_CAS_TIMING));
4059 cgs_write_register(hwmgr->device, mmMC_SEQ_DLL_STBY_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_DLL_STBY));
4060 cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD0_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD0));
4061 cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD1_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CMD1));
4062 cgs_write_register(hwmgr->device, mmMC_SEQ_G5PDX_CTRL_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_G5PDX_CTRL));
4063 cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CMD_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CMD));
4064 cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CTL_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_DVS_CTL));
4065 cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING));
4066 cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2));
4067 cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_EMRS_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_EMRS));
4068 cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS));
4069 cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS1_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS1));
4070 cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D0_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D0));
4071 cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1));
4072 cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0));
4073 cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1));
4074 cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_TIMING_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_TIMING));
4075 cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_CMD_MRS2_LP, cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS2));
4076 cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_2_LP, cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_2));
4078 memset(table, 0x00, sizeof(pp_atomctrl_mc_reg_table));
4080 result = atomctrl_initialize_mc_reg_table(hwmgr, module_index, table);
4083 result = tonga_copy_vbios_smc_reg_table(table, ni_table);
4086 tonga_set_s0_mc_reg_index(ni_table);
4087 result = tonga_set_mc_special_registers(hwmgr, ni_table);
4091 tonga_set_valid_flag(ni_table);
4098 * Copy one arb setting to another and then switch the active set.
4099 * arbFreqSrc and arbFreqDest is one of the MC_CG_ARB_FREQ_Fx constants.
4101 int tonga_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
4102 uint32_t arbFreqSrc, uint32_t arbFreqDest)
4104 uint32_t mc_arb_dram_timing;
4105 uint32_t mc_arb_dram_timing2;
4106 uint32_t burst_time;
4107 uint32_t mc_cg_config;
4109 switch (arbFreqSrc) {
4110 case MC_CG_ARB_FREQ_F0:
4111 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
4112 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
4113 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
4116 case MC_CG_ARB_FREQ_F1:
4117 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
4118 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
4119 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
4126 switch (arbFreqDest) {
4127 case MC_CG_ARB_FREQ_F0:
4128 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
4129 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
4130 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
4133 case MC_CG_ARB_FREQ_F1:
4134 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
4135 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
4136 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
4143 mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
4144 mc_cg_config |= 0x0000000F;
4145 cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
4146 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arbFreqDest);
4152 * Initial switch from ARB F0->F1
4154 * @param hwmgr the address of the powerplay hardware manager.
4156 * This function is to be called from the SetPowerState table.
4158 int tonga_initial_switch_from_arb_f0_to_f1(struct pp_hwmgr *hwmgr)
4160 return tonga_copy_and_switch_arb_sets(hwmgr, MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
4164 * Initialize the ARB DRAM timing table's index field.
4166 * @param hwmgr the address of the powerplay hardware manager.
4169 int tonga_init_arb_table_index(struct pp_hwmgr *hwmgr)
4171 const tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
4176 * This is a read-modify-write on the first byte of the ARB table.
4177 * The first byte in the SMU72_Discrete_MCArbDramTimingTable structure is the field 'current'.
4178 * This solution is ugly, but we never write the whole table only individual fields in it.
4179 * In reality this field should not be in that structure but in a soft register.
4181 result = tonga_read_smc_sram_dword(hwmgr->smumgr,
4182 data->arb_table_start, &tmp, data->sram_end);
4188 tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24;
4190 return tonga_write_smc_sram_dword(hwmgr->smumgr,
4191 data->arb_table_start, tmp, data->sram_end);
4194 int tonga_populate_mc_reg_address(struct pp_hwmgr *hwmgr, SMU72_Discrete_MCRegisters *mc_reg_table)
4196 const struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
4200 for (i = 0, j = 0; j < data->tonga_mc_reg_table.last; j++) {
4201 if (data->tonga_mc_reg_table.validflag & 1<<j) {
4202 PP_ASSERT_WITH_CODE(i < SMU72_DISCRETE_MC_REGISTER_ARRAY_SIZE,
4203 "Index of mc_reg_table->address[] array out of boundary", return -1);
4204 mc_reg_table->address[i].s0 =
4205 PP_HOST_TO_SMC_US(data->tonga_mc_reg_table.mc_reg_address[j].s0);
4206 mc_reg_table->address[i].s1 =
4207 PP_HOST_TO_SMC_US(data->tonga_mc_reg_table.mc_reg_address[j].s1);
4212 mc_reg_table->last = (uint8_t)i;
4217 /*convert register values from driver to SMC format */
4218 void tonga_convert_mc_registers(
4219 const phw_tonga_mc_reg_entry * pEntry,
4220 SMU72_Discrete_MCRegisterSet *pData,
4221 uint32_t numEntries, uint32_t validflag)
4225 for (i = 0, j = 0; j < numEntries; j++) {
4226 if (validflag & 1<<j) {
4227 pData->value[i] = PP_HOST_TO_SMC_UL(pEntry->mc_data[j]);
4233 /* find the entry in the memory range table, then populate the value to SMC's tonga_mc_reg_table */
4234 int tonga_convert_mc_reg_table_entry_to_smc(
4235 struct pp_hwmgr *hwmgr,
4236 const uint32_t memory_clock,
4237 SMU72_Discrete_MCRegisterSet *mc_reg_table_data
4240 const tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
4243 for (i = 0; i < data->tonga_mc_reg_table.num_entries; i++) {
4245 data->tonga_mc_reg_table.mc_reg_table_entry[i].mclk_max) {
4250 if ((i == data->tonga_mc_reg_table.num_entries) && (i > 0))
4253 tonga_convert_mc_registers(&data->tonga_mc_reg_table.mc_reg_table_entry[i],
4254 mc_reg_table_data, data->tonga_mc_reg_table.last, data->tonga_mc_reg_table.validflag);
4259 int tonga_convert_mc_reg_table_to_smc(struct pp_hwmgr *hwmgr,
4260 SMU72_Discrete_MCRegisters *mc_reg_table)
4263 tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
4267 for (i = 0; i < data->dpm_table.mclk_table.count; i++) {
4268 res = tonga_convert_mc_reg_table_entry_to_smc(
4270 data->dpm_table.mclk_table.dpm_levels[i].value,
4271 &mc_reg_table->data[i]
4281 int tonga_populate_initial_mc_reg_table(struct pp_hwmgr *hwmgr)
4284 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
4286 memset(&data->mc_reg_table, 0x00, sizeof(SMU72_Discrete_MCRegisters));
4287 result = tonga_populate_mc_reg_address(hwmgr, &(data->mc_reg_table));
4288 PP_ASSERT_WITH_CODE(0 == result,
4289 "Failed to initialize MCRegTable for the MC register addresses!", return result;);
4291 result = tonga_convert_mc_reg_table_to_smc(hwmgr, &data->mc_reg_table);
4292 PP_ASSERT_WITH_CODE(0 == result,
4293 "Failed to initialize MCRegTable for driver state!", return result;);
4295 return tonga_copy_bytes_to_smc(hwmgr->smumgr, data->mc_reg_table_start,
4296 (uint8_t *)&data->mc_reg_table, sizeof(SMU72_Discrete_MCRegisters), data->sram_end);
4300 * Programs static screed detection parameters
4302 * @param hwmgr the address of the powerplay hardware manager.
4305 int tonga_program_static_screen_threshold_parameters(struct pp_hwmgr *hwmgr)
4307 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
4309 /* Set static screen threshold unit*/
4310 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
4311 CGS_IND_REG__SMC, CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
4312 data->static_screen_threshold_unit);
4313 /* Set static screen threshold*/
4314 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device,
4315 CGS_IND_REG__SMC, CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
4316 data->static_screen_threshold);
4322 * Setup display gap for glitch free memory clock switching.
4324 * @param hwmgr the address of the powerplay hardware manager.
4327 int tonga_enable_display_gap(struct pp_hwmgr *hwmgr)
4329 uint32_t display_gap = cgs_read_ind_register(hwmgr->device,
4330 CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
4332 display_gap = PHM_SET_FIELD(display_gap,
4333 CG_DISPLAY_GAP_CNTL, DISP_GAP, DISPLAY_GAP_IGNORE);
4335 display_gap = PHM_SET_FIELD(display_gap,
4336 CG_DISPLAY_GAP_CNTL, DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
4338 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4339 ixCG_DISPLAY_GAP_CNTL, display_gap);
4345 * Programs activity state transition voting clients
4347 * @param hwmgr the address of the powerplay hardware manager.
4350 int tonga_program_voting_clients(struct pp_hwmgr *hwmgr)
4352 tonga_hwmgr *data = (tonga_hwmgr *)(hwmgr->backend);
4354 /* Clear reset for voting clients before enabling DPM */
4355 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
4356 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
4357 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
4358 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
4360 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4361 ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0);
4362 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4363 ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1);
4364 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4365 ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2);
4366 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4367 ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3);
4368 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4369 ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4);
4370 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4371 ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5);
4372 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4373 ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6);
4374 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4375 ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7);
4381 int tonga_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
4383 int tmp_result, result = 0;
4385 tmp_result = tonga_check_for_dpm_stopped(hwmgr);
4387 if (cf_tonga_voltage_control(hwmgr)) {
4388 tmp_result = tonga_enable_voltage_control(hwmgr);
4389 PP_ASSERT_WITH_CODE((0 == tmp_result),
4390 "Failed to enable voltage control!", result = tmp_result);
4392 tmp_result = tonga_construct_voltage_tables(hwmgr);
4393 PP_ASSERT_WITH_CODE((0 == tmp_result),
4394 "Failed to contruct voltage tables!", result = tmp_result);
4397 tmp_result = tonga_initialize_mc_reg_table(hwmgr);
4398 PP_ASSERT_WITH_CODE((0 == tmp_result),
4399 "Failed to initialize MC reg table!", result = tmp_result);
4401 tmp_result = tonga_program_static_screen_threshold_parameters(hwmgr);
4402 PP_ASSERT_WITH_CODE((0 == tmp_result),
4403 "Failed to program static screen threshold parameters!", result = tmp_result);
4405 tmp_result = tonga_enable_display_gap(hwmgr);
4406 PP_ASSERT_WITH_CODE((0 == tmp_result),
4407 "Failed to enable display gap!", result = tmp_result);
4409 tmp_result = tonga_program_voting_clients(hwmgr);
4410 PP_ASSERT_WITH_CODE((0 == tmp_result),
4411 "Failed to program voting clients!", result = tmp_result);
4413 tmp_result = tonga_process_firmware_header(hwmgr);
4414 PP_ASSERT_WITH_CODE((0 == tmp_result),
4415 "Failed to process firmware header!", result = tmp_result);
4417 tmp_result = tonga_initial_switch_from_arb_f0_to_f1(hwmgr);
4418 PP_ASSERT_WITH_CODE((0 == tmp_result),
4419 "Failed to initialize switch from ArbF0 to F1!", result = tmp_result);
4421 tmp_result = tonga_init_smc_table(hwmgr);
4422 PP_ASSERT_WITH_CODE((0 == tmp_result),
4423 "Failed to initialize SMC table!", result = tmp_result);
4425 tmp_result = tonga_init_arb_table_index(hwmgr);
4426 PP_ASSERT_WITH_CODE((0 == tmp_result),
4427 "Failed to initialize ARB table index!", result = tmp_result);
4429 tmp_result = tonga_populate_initial_mc_reg_table(hwmgr);
4430 PP_ASSERT_WITH_CODE((0 == tmp_result),
4431 "Failed to populate initialize MC Reg table!", result = tmp_result);
4433 tmp_result = tonga_notify_smc_display_change(hwmgr, false);
4434 PP_ASSERT_WITH_CODE((0 == tmp_result),
4435 "Failed to notify no display!", result = tmp_result);
4437 /* enable SCLK control */
4438 tmp_result = tonga_enable_sclk_control(hwmgr);
4439 PP_ASSERT_WITH_CODE((0 == tmp_result),
4440 "Failed to enable SCLK control!", result = tmp_result);
4443 tmp_result = tonga_start_dpm(hwmgr);
4444 PP_ASSERT_WITH_CODE((0 == tmp_result),
4445 "Failed to start DPM!", result = tmp_result);
4450 int tonga_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
4452 int tmp_result, result = 0;
4454 tmp_result = tonga_check_for_dpm_running(hwmgr);
4455 PP_ASSERT_WITH_CODE((0 == tmp_result),
4456 "SMC is still running!", return 0);
4458 tmp_result = tonga_stop_dpm(hwmgr);
4459 PP_ASSERT_WITH_CODE((0 == tmp_result),
4460 "Failed to stop DPM!", result = tmp_result);
4462 tmp_result = tonga_reset_to_default(hwmgr);
4463 PP_ASSERT_WITH_CODE((0 == tmp_result),
4464 "Failed to reset to default!", result = tmp_result);
4469 int tonga_reset_asic_tasks(struct pp_hwmgr *hwmgr)
4473 result = tonga_set_boot_state(hwmgr);
4475 printk(KERN_ERR "[ powerplay ] Failed to reset asic via set boot state! \n");
4480 int tonga_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
4482 if (NULL != hwmgr->dyn_state.vddc_dep_on_dal_pwrl) {
4483 kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
4484 hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
4487 if (NULL != hwmgr->backend) {
4488 kfree(hwmgr->backend);
4489 hwmgr->backend = NULL;
4496 * Initializes the Volcanic Islands Hardware Manager
4498 * @param hwmgr the address of the powerplay hardware manager.
4499 * @return 1 if success; otherwise appropriate error code.
4501 int tonga_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
4504 SMU72_Discrete_DpmTable *table = NULL;
4505 tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
4506 pp_atomctrl_gpio_pin_assignment gpio_pin_assignment;
4507 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
4508 phw_tonga_ulv_parm *ulv;
4510 PP_ASSERT_WITH_CODE((NULL != hwmgr),
4511 "Invalid Parameter!", return -1;);
4513 data->dll_defaule_on = 0;
4514 data->sram_end = SMC_RAM_END;
4516 data->activity_target[0] = PPTONGA_TARGETACTIVITY_DFLT;
4517 data->activity_target[1] = PPTONGA_TARGETACTIVITY_DFLT;
4518 data->activity_target[2] = PPTONGA_TARGETACTIVITY_DFLT;
4519 data->activity_target[3] = PPTONGA_TARGETACTIVITY_DFLT;
4520 data->activity_target[4] = PPTONGA_TARGETACTIVITY_DFLT;
4521 data->activity_target[5] = PPTONGA_TARGETACTIVITY_DFLT;
4522 data->activity_target[6] = PPTONGA_TARGETACTIVITY_DFLT;
4523 data->activity_target[7] = PPTONGA_TARGETACTIVITY_DFLT;
4525 data->vddc_vddci_delta = VDDC_VDDCI_DELTA;
4526 data->vddc_vddgfx_delta = VDDC_VDDGFX_DELTA;
4527 data->mclk_activity_target = PPTONGA_MCLK_TARGETACTIVITY_DFLT;
4529 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
4530 PHM_PlatformCaps_DisableVoltageIsland);
4532 data->sclk_dpm_key_disabled = 0;
4533 data->mclk_dpm_key_disabled = 0;
4534 data->pcie_dpm_key_disabled = 0;
4535 data->pcc_monitor_enabled = 0;
4537 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
4538 PHM_PlatformCaps_UnTabledHardwareInterface);
4540 data->gpio_debug = 0;
4541 data->engine_clock_data = 0;
4542 data->memory_clock_data = 0;
4543 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
4544 PHM_PlatformCaps_DynamicPatchPowerState);
4546 /* need to set voltage control types before EVV patching*/
4547 data->voltage_control = TONGA_VOLTAGE_CONTROL_NONE;
4548 data->vdd_ci_control = TONGA_VOLTAGE_CONTROL_NONE;
4549 data->vdd_gfx_control = TONGA_VOLTAGE_CONTROL_NONE;
4550 data->mvdd_control = TONGA_VOLTAGE_CONTROL_NONE;
4552 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
4553 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2)) {
4554 data->voltage_control = TONGA_VOLTAGE_CONTROL_BY_SVID2;
4557 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4558 PHM_PlatformCaps_ControlVDDGFX)) {
4559 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
4560 VOLTAGE_TYPE_VDDGFX, VOLTAGE_OBJ_SVID2)) {
4561 data->vdd_gfx_control = TONGA_VOLTAGE_CONTROL_BY_SVID2;
4565 if (TONGA_VOLTAGE_CONTROL_NONE == data->vdd_gfx_control) {
4566 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
4567 PHM_PlatformCaps_ControlVDDGFX);
4570 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4571 PHM_PlatformCaps_EnableMVDDControl)) {
4572 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
4573 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT)) {
4574 data->mvdd_control = TONGA_VOLTAGE_CONTROL_BY_GPIO;
4578 if (TONGA_VOLTAGE_CONTROL_NONE == data->mvdd_control) {
4579 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
4580 PHM_PlatformCaps_EnableMVDDControl);
4583 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4584 PHM_PlatformCaps_ControlVDDCI)) {
4585 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
4586 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
4587 data->vdd_ci_control = TONGA_VOLTAGE_CONTROL_BY_GPIO;
4588 else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
4589 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
4590 data->vdd_ci_control = TONGA_VOLTAGE_CONTROL_BY_SVID2;
4593 if (TONGA_VOLTAGE_CONTROL_NONE == data->vdd_ci_control)
4594 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
4595 PHM_PlatformCaps_ControlVDDCI);
4597 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
4598 PHM_PlatformCaps_TablelessHardwareInterface);
4600 if (pptable_info->cac_dtp_table->usClockStretchAmount != 0)
4601 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
4602 PHM_PlatformCaps_ClockStretcher);
4604 /* Initializes DPM default values*/
4605 tonga_initialize_dpm_defaults(hwmgr);
4607 /* Get leakage voltage based on leakage ID.*/
4608 PP_ASSERT_WITH_CODE((0 == tonga_get_evv_voltage(hwmgr)),
4609 "Get EVV Voltage Failed. Abort Driver loading!", return -1);
4611 tonga_complete_dependency_tables(hwmgr);
4613 /* Parse pptable data read from VBIOS*/
4614 tonga_set_private_var_based_on_pptale(hwmgr);
4618 ulv->ulv_supported = 0;
4620 /* Initalize Dynamic State Adjustment Rule Settings*/
4621 result = tonga_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
4622 data->uvd_enabled = 0;
4624 table = &(data->smc_state_table);
4627 * if ucGPIO_ID=VDDC_PCC_GPIO_PINID in GPIO_LUTable,
4628 * Peak Current Control feature is enabled and we should program PCC HW register
4630 if (0 == atomctrl_get_pp_assign_pin(hwmgr, VDDC_PCC_GPIO_PINID, &gpio_pin_assignment)) {
4631 uint32_t temp_reg = cgs_read_ind_register(hwmgr->device,
4632 CGS_IND_REG__SMC, ixCNB_PWRMGT_CNTL);
4634 switch (gpio_pin_assignment.uc_gpio_pin_bit_shift) {
4636 temp_reg = PHM_SET_FIELD(temp_reg,
4637 CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x1);
4640 temp_reg = PHM_SET_FIELD(temp_reg,
4641 CNB_PWRMGT_CNTL, GNB_SLOW_MODE, 0x2);
4644 temp_reg = PHM_SET_FIELD(temp_reg,
4645 CNB_PWRMGT_CNTL, GNB_SLOW, 0x1);
4648 temp_reg = PHM_SET_FIELD(temp_reg,
4649 CNB_PWRMGT_CNTL, FORCE_NB_PS1, 0x1);
4652 temp_reg = PHM_SET_FIELD(temp_reg,
4653 CNB_PWRMGT_CNTL, DPM_ENABLED, 0x1);
4656 printk(KERN_ERR "[ powerplay ] Failed to setup PCC HW register! \
4657 Wrong GPIO assigned for VDDC_PCC_GPIO_PINID! \n");
4660 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4661 ixCNB_PWRMGT_CNTL, temp_reg);
4664 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
4665 PHM_PlatformCaps_EnableSMU7ThermalManagement);
4666 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
4667 PHM_PlatformCaps_SMU7);
4669 data->vddc_phase_shed_control = 0;
4672 data->is_tlu_enabled = 0;
4673 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
4674 TONGA_MAX_HARDWARE_POWERLEVELS;
4675 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
4676 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
4678 data->pcie_gen_cap = 0x30007;
4679 data->pcie_lane_cap = 0x2f0000;
4681 /* Ignore return value in here, we are cleaning up a mess. */
4682 tonga_hwmgr_backend_fini(hwmgr);
4688 static int tonga_force_dpm_level(struct pp_hwmgr *hwmgr,
4689 enum amd_dpm_forced_level level)
4694 case AMD_DPM_FORCED_LEVEL_HIGH:
4695 ret = tonga_force_dpm_highest(hwmgr);
4699 case AMD_DPM_FORCED_LEVEL_LOW:
4700 ret = tonga_force_dpm_lowest(hwmgr);
4704 case AMD_DPM_FORCED_LEVEL_AUTO:
4705 ret = tonga_unforce_dpm_levels(hwmgr);
4713 hwmgr->dpm_level = level;
4717 static int tonga_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
4718 struct pp_power_state *prequest_ps,
4719 const struct pp_power_state *pcurrent_ps)
4721 struct tonga_power_state *tonga_ps =
4722 cast_phw_tonga_power_state(&prequest_ps->hardware);
4726 struct PP_Clocks minimum_clocks = {0};
4727 bool disable_mclk_switching;
4728 bool disable_mclk_switching_for_frame_lock;
4729 struct cgs_display_info info = {0};
4730 const struct phm_clock_and_voltage_limits *max_limits;
4732 tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
4733 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
4736 int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
4738 data->battery_state = (PP_StateUILabel_Battery == prequest_ps->classification.ui_label);
4740 PP_ASSERT_WITH_CODE(tonga_ps->performance_level_count == 2,
4741 "VI should always have 2 performance levels",
4744 max_limits = (PP_PowerSource_AC == hwmgr->power_source) ?
4745 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
4746 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
4748 if (PP_PowerSource_DC == hwmgr->power_source) {
4749 for (i = 0; i < tonga_ps->performance_level_count; i++) {
4750 if (tonga_ps->performance_levels[i].memory_clock > max_limits->mclk)
4751 tonga_ps->performance_levels[i].memory_clock = max_limits->mclk;
4752 if (tonga_ps->performance_levels[i].engine_clock > max_limits->sclk)
4753 tonga_ps->performance_levels[i].engine_clock = max_limits->sclk;
4757 tonga_ps->vce_clocks.EVCLK = hwmgr->vce_arbiter.evclk;
4758 tonga_ps->vce_clocks.ECCLK = hwmgr->vce_arbiter.ecclk;
4760 tonga_ps->acp_clk = hwmgr->acp_arbiter.acpclk;
4762 cgs_get_active_displays_info(hwmgr->device, &info);
4764 /*TO DO result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/
4766 /* TO DO GetMinClockSettings(hwmgr->pPECI, &minimum_clocks); */
4768 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState)) {
4770 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
4771 stable_pstate_sclk = (max_limits->sclk * 75) / 100;
4773 for (count = pptable_info->vdd_dep_on_sclk->count-1; count >= 0; count--) {
4774 if (stable_pstate_sclk >= pptable_info->vdd_dep_on_sclk->entries[count].clk) {
4775 stable_pstate_sclk = pptable_info->vdd_dep_on_sclk->entries[count].clk;
4781 stable_pstate_sclk = pptable_info->vdd_dep_on_sclk->entries[0].clk;
4783 stable_pstate_mclk = max_limits->mclk;
4785 minimum_clocks.engineClock = stable_pstate_sclk;
4786 minimum_clocks.memoryClock = stable_pstate_mclk;
4789 if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk)
4790 minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk;
4792 if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
4793 minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
4795 tonga_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold;
4797 if (0 != hwmgr->gfx_arbiter.sclk_over_drive) {
4798 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <= hwmgr->platform_descriptor.overdriveLimit.engineClock),
4799 "Overdrive sclk exceeds limit",
4800 hwmgr->gfx_arbiter.sclk_over_drive = hwmgr->platform_descriptor.overdriveLimit.engineClock);
4802 if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk)
4803 tonga_ps->performance_levels[1].engine_clock = hwmgr->gfx_arbiter.sclk_over_drive;
4806 if (0 != hwmgr->gfx_arbiter.mclk_over_drive) {
4807 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <= hwmgr->platform_descriptor.overdriveLimit.memoryClock),
4808 "Overdrive mclk exceeds limit",
4809 hwmgr->gfx_arbiter.mclk_over_drive = hwmgr->platform_descriptor.overdriveLimit.memoryClock);
4811 if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk)
4812 tonga_ps->performance_levels[1].memory_clock = hwmgr->gfx_arbiter.mclk_over_drive;
4815 disable_mclk_switching_for_frame_lock = phm_cap_enabled(
4816 hwmgr->platform_descriptor.platformCaps,
4817 PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
4819 disable_mclk_switching = (1 < info.display_count) ||
4820 disable_mclk_switching_for_frame_lock;
4822 sclk = tonga_ps->performance_levels[0].engine_clock;
4823 mclk = tonga_ps->performance_levels[0].memory_clock;
4825 if (disable_mclk_switching)
4826 mclk = tonga_ps->performance_levels[tonga_ps->performance_level_count - 1].memory_clock;
4828 if (sclk < minimum_clocks.engineClock)
4829 sclk = (minimum_clocks.engineClock > max_limits->sclk) ? max_limits->sclk : minimum_clocks.engineClock;
4831 if (mclk < minimum_clocks.memoryClock)
4832 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ? max_limits->mclk : minimum_clocks.memoryClock;
4834 tonga_ps->performance_levels[0].engine_clock = sclk;
4835 tonga_ps->performance_levels[0].memory_clock = mclk;
4837 tonga_ps->performance_levels[1].engine_clock =
4838 (tonga_ps->performance_levels[1].engine_clock >= tonga_ps->performance_levels[0].engine_clock) ?
4839 tonga_ps->performance_levels[1].engine_clock :
4840 tonga_ps->performance_levels[0].engine_clock;
4842 if (disable_mclk_switching) {
4843 if (mclk < tonga_ps->performance_levels[1].memory_clock)
4844 mclk = tonga_ps->performance_levels[1].memory_clock;
4846 tonga_ps->performance_levels[0].memory_clock = mclk;
4847 tonga_ps->performance_levels[1].memory_clock = mclk;
4849 if (tonga_ps->performance_levels[1].memory_clock < tonga_ps->performance_levels[0].memory_clock)
4850 tonga_ps->performance_levels[1].memory_clock = tonga_ps->performance_levels[0].memory_clock;
4853 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState)) {
4854 for (i=0; i < tonga_ps->performance_level_count; i++) {
4855 tonga_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
4856 tonga_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
4857 tonga_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
4858 tonga_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
4865 int tonga_get_power_state_size(struct pp_hwmgr *hwmgr)
4867 return sizeof(struct tonga_power_state);
4870 static int tonga_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
4872 struct pp_power_state *ps;
4873 struct tonga_power_state *tonga_ps;
4878 ps = hwmgr->request_ps;
4883 tonga_ps = cast_phw_tonga_power_state(&ps->hardware);
4886 return tonga_ps->performance_levels[0].memory_clock;
4888 return tonga_ps->performance_levels[tonga_ps->performance_level_count-1].memory_clock;
4891 static int tonga_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
4893 struct pp_power_state *ps;
4894 struct tonga_power_state *tonga_ps;
4899 ps = hwmgr->request_ps;
4904 tonga_ps = cast_phw_tonga_power_state(&ps->hardware);
4907 return tonga_ps->performance_levels[0].engine_clock;
4909 return tonga_ps->performance_levels[tonga_ps->performance_level_count-1].engine_clock;
4912 static uint16_t tonga_get_current_pcie_speed(
4913 struct pp_hwmgr *hwmgr)
4915 uint32_t speed_cntl = 0;
4917 speed_cntl = cgs_read_ind_register(hwmgr->device,
4919 ixPCIE_LC_SPEED_CNTL);
4920 return((uint16_t)PHM_GET_FIELD(speed_cntl,
4921 PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
4924 static int tonga_get_current_pcie_lane_number(
4925 struct pp_hwmgr *hwmgr)
4927 uint32_t link_width;
4929 link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device,
4931 PCIE_LC_LINK_WIDTH_CNTL,
4934 PP_ASSERT_WITH_CODE((7 >= link_width),
4935 "Invalid PCIe lane width!", return 0);
4937 return decode_pcie_lane_width(link_width);
4940 static int tonga_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
4941 struct pp_hw_power_state *hw_ps)
4943 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
4944 struct tonga_power_state *ps = (struct tonga_power_state *)hw_ps;
4945 ATOM_FIRMWARE_INFO_V2_2 *fw_info;
4948 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
4950 /* First retrieve the Boot clocks and VDDC from the firmware info table.
4951 * We assume here that fw_info is unchanged if this call fails.
4953 fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table(
4954 hwmgr->device, index,
4955 &size, &frev, &crev);
4957 /* During a test, there is no firmware info table. */
4960 /* Patch the state. */
4961 data->vbios_boot_state.sclk_bootup_value = le32_to_cpu(fw_info->ulDefaultEngineClock);
4962 data->vbios_boot_state.mclk_bootup_value = le32_to_cpu(fw_info->ulDefaultMemoryClock);
4963 data->vbios_boot_state.mvdd_bootup_value = le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
4964 data->vbios_boot_state.vddc_bootup_value = le16_to_cpu(fw_info->usBootUpVDDCVoltage);
4965 data->vbios_boot_state.vddci_bootup_value = le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
4966 data->vbios_boot_state.pcie_gen_bootup_value = tonga_get_current_pcie_speed(hwmgr);
4967 data->vbios_boot_state.pcie_lane_bootup_value =
4968 (uint16_t)tonga_get_current_pcie_lane_number(hwmgr);
4970 /* set boot power state */
4971 ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
4972 ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
4973 ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
4974 ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
4979 static int tonga_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr,
4980 void *state, struct pp_power_state *power_state,
4981 void *pp_table, uint32_t classification_flag)
4983 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
4985 struct tonga_power_state *tonga_ps =
4986 (struct tonga_power_state *)(&(power_state->hardware));
4988 struct tonga_performance_level *performance_level;
4990 ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
4992 ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
4993 (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
4995 ATOM_Tonga_SCLK_Dependency_Table *sclk_dep_table =
4996 (ATOM_Tonga_SCLK_Dependency_Table *)
4997 (((uint64_t)powerplay_table) +
4998 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
5000 ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
5001 (ATOM_Tonga_MCLK_Dependency_Table *)
5002 (((uint64_t)powerplay_table) +
5003 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
5005 /* The following fields are not initialized here: id orderedList allStatesList */
5006 power_state->classification.ui_label =
5007 (le16_to_cpu(state_entry->usClassification) &
5008 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
5009 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
5010 power_state->classification.flags = classification_flag;
5011 /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
5013 power_state->classification.temporary_state = false;
5014 power_state->classification.to_be_deleted = false;
5016 power_state->validation.disallowOnDC =
5017 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) & ATOM_Tonga_DISALLOW_ON_DC));
5019 power_state->pcie.lanes = 0;
5021 power_state->display.disableFrameModulation = false;
5022 power_state->display.limitRefreshrate = false;
5023 power_state->display.enableVariBright =
5024 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) & ATOM_Tonga_ENABLE_VARIBRIGHT));
5026 power_state->validation.supportedPowerLevels = 0;
5027 power_state->uvd_clocks.VCLK = 0;
5028 power_state->uvd_clocks.DCLK = 0;
5029 power_state->temperatures.min = 0;
5030 power_state->temperatures.max = 0;
5032 performance_level = &(tonga_ps->performance_levels
5033 [tonga_ps->performance_level_count++]);
5035 PP_ASSERT_WITH_CODE(
5036 (tonga_ps->performance_level_count < SMU72_MAX_LEVELS_GRAPHICS),
5037 "Performance levels exceeds SMC limit!",
5040 PP_ASSERT_WITH_CODE(
5041 (tonga_ps->performance_level_count <=
5042 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
5043 "Performance levels exceeds Driver limit!",
5046 /* Performance levels are arranged from low to high. */
5047 performance_level->memory_clock =
5048 le32_to_cpu(mclk_dep_table->entries[state_entry->ucMemoryClockIndexLow].ulMclk);
5050 performance_level->engine_clock =
5051 le32_to_cpu(sclk_dep_table->entries[state_entry->ucEngineClockIndexLow].ulSclk);
5053 performance_level->pcie_gen = get_pcie_gen_support(
5055 state_entry->ucPCIEGenLow);
5057 performance_level->pcie_lane = get_pcie_lane_support(
5058 data->pcie_lane_cap,
5059 state_entry->ucPCIELaneHigh);
5062 &(tonga_ps->performance_levels[tonga_ps->performance_level_count++]);
5064 performance_level->memory_clock =
5065 le32_to_cpu(mclk_dep_table->entries[state_entry->ucMemoryClockIndexHigh].ulMclk);
5067 performance_level->engine_clock =
5068 le32_to_cpu(sclk_dep_table->entries[state_entry->ucEngineClockIndexHigh].ulSclk);
5070 performance_level->pcie_gen = get_pcie_gen_support(
5072 state_entry->ucPCIEGenHigh);
5074 performance_level->pcie_lane = get_pcie_lane_support(
5075 data->pcie_lane_cap,
5076 state_entry->ucPCIELaneHigh);
5081 static int tonga_get_pp_table_entry(struct pp_hwmgr *hwmgr,
5082 unsigned long entry_index, struct pp_power_state *ps)
5085 struct tonga_power_state *tonga_ps;
5086 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5088 struct phm_ppt_v1_information *table_info =
5089 (struct phm_ppt_v1_information *)(hwmgr->pptable);
5091 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
5092 table_info->vdd_dep_on_mclk;
5094 ps->hardware.magic = PhwTonga_Magic;
5096 tonga_ps = cast_phw_tonga_power_state(&(ps->hardware));
5098 result = tonga_get_powerplay_table_entry(hwmgr, entry_index, ps,
5099 tonga_get_pp_table_entry_callback_func);
5101 /* This is the earliest time we have all the dependency table and the VBIOS boot state
5102 * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
5103 * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
5105 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
5106 if (dep_mclk_table->entries[0].clk !=
5107 data->vbios_boot_state.mclk_bootup_value)
5108 printk(KERN_ERR "Single MCLK entry VDDCI/MCLK dependency table "
5109 "does not match VBIOS boot MCLK level");
5110 if (dep_mclk_table->entries[0].vddci !=
5111 data->vbios_boot_state.vddci_bootup_value)
5112 printk(KERN_ERR "Single VDDCI entry VDDCI/MCLK dependency table "
5113 "does not match VBIOS boot VDDCI level");
5116 /* set DC compatible flag if this state supports DC */
5117 if (!ps->validation.disallowOnDC)
5118 tonga_ps->dc_compatible = true;
5120 if (ps->classification.flags & PP_StateClassificationFlag_ACPI)
5121 data->acpi_pcie_gen = tonga_ps->performance_levels[0].pcie_gen;
5122 else if (ps->classification.flags & PP_StateClassificationFlag_Boot) {
5123 if (data->bacos.best_match == 0xffff) {
5124 /* For V.I. use boot state as base BACO state */
5125 data->bacos.best_match = PP_StateClassificationFlag_Boot;
5126 data->bacos.performance_level = tonga_ps->performance_levels[0];
5130 tonga_ps->uvd_clocks.VCLK = ps->uvd_clocks.VCLK;
5131 tonga_ps->uvd_clocks.DCLK = ps->uvd_clocks.DCLK;
5136 switch (ps->classification.ui_label) {
5137 case PP_StateUILabel_Performance:
5138 data->use_pcie_performance_levels = true;
5140 for (i = 0; i < tonga_ps->performance_level_count; i++) {
5141 if (data->pcie_gen_performance.max <
5142 tonga_ps->performance_levels[i].pcie_gen)
5143 data->pcie_gen_performance.max =
5144 tonga_ps->performance_levels[i].pcie_gen;
5146 if (data->pcie_gen_performance.min >
5147 tonga_ps->performance_levels[i].pcie_gen)
5148 data->pcie_gen_performance.min =
5149 tonga_ps->performance_levels[i].pcie_gen;
5151 if (data->pcie_lane_performance.max <
5152 tonga_ps->performance_levels[i].pcie_lane)
5153 data->pcie_lane_performance.max =
5154 tonga_ps->performance_levels[i].pcie_lane;
5156 if (data->pcie_lane_performance.min >
5157 tonga_ps->performance_levels[i].pcie_lane)
5158 data->pcie_lane_performance.min =
5159 tonga_ps->performance_levels[i].pcie_lane;
5162 case PP_StateUILabel_Battery:
5163 data->use_pcie_power_saving_levels = true;
5165 for (i = 0; i < tonga_ps->performance_level_count; i++) {
5166 if (data->pcie_gen_power_saving.max <
5167 tonga_ps->performance_levels[i].pcie_gen)
5168 data->pcie_gen_power_saving.max =
5169 tonga_ps->performance_levels[i].pcie_gen;
5171 if (data->pcie_gen_power_saving.min >
5172 tonga_ps->performance_levels[i].pcie_gen)
5173 data->pcie_gen_power_saving.min =
5174 tonga_ps->performance_levels[i].pcie_gen;
5176 if (data->pcie_lane_power_saving.max <
5177 tonga_ps->performance_levels[i].pcie_lane)
5178 data->pcie_lane_power_saving.max =
5179 tonga_ps->performance_levels[i].pcie_lane;
5181 if (data->pcie_lane_power_saving.min >
5182 tonga_ps->performance_levels[i].pcie_lane)
5183 data->pcie_lane_power_saving.min =
5184 tonga_ps->performance_levels[i].pcie_lane;
5195 tonga_print_current_perforce_level(struct pp_hwmgr *hwmgr, struct seq_file *m)
5197 uint32_t sclk, mclk;
5199 smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)(PPSMC_MSG_API_GetSclkFrequency));
5201 sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
5203 smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)(PPSMC_MSG_API_GetMclkFrequency));
5205 mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
5206 seq_printf(m, "\n [ mclk ]: %u MHz\n\n [ sclk ]: %u MHz\n", mclk/100, sclk/100);
5209 static int tonga_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
5211 const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
5212 const struct tonga_power_state *tonga_ps = cast_const_phw_tonga_power_state(states->pnew_state);
5213 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5214 struct tonga_single_dpm_table *psclk_table = &(data->dpm_table.sclk_table);
5215 uint32_t sclk = tonga_ps->performance_levels[tonga_ps->performance_level_count-1].engine_clock;
5216 struct tonga_single_dpm_table *pmclk_table = &(data->dpm_table.mclk_table);
5217 uint32_t mclk = tonga_ps->performance_levels[tonga_ps->performance_level_count-1].memory_clock;
5218 struct PP_Clocks min_clocks = {0};
5220 struct cgs_display_info info = {0};
5222 data->need_update_smu7_dpm_table = 0;
5224 for (i = 0; i < psclk_table->count; i++) {
5225 if (sclk == psclk_table->dpm_levels[i].value)
5229 if (i >= psclk_table->count)
5230 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
5232 /* TODO: Check SCLK in DAL's minimum clocks in case DeepSleep divider update is required.*/
5233 if(data->display_timing.min_clock_insr != min_clocks.engineClockInSR)
5234 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
5237 for (i=0; i < pmclk_table->count; i++) {
5238 if (mclk == pmclk_table->dpm_levels[i].value)
5242 if (i >= pmclk_table->count)
5243 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
5245 cgs_get_active_displays_info(hwmgr->device, &info);
5247 if (data->display_timing.num_existing_displays != info.display_count)
5248 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
5253 static uint16_t tonga_get_maximum_link_speed(struct pp_hwmgr *hwmgr, const struct tonga_power_state *hw_ps)
5256 uint32_t sclk, max_sclk = 0;
5257 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5258 struct tonga_dpm_table *pdpm_table = &data->dpm_table;
5260 for (i = 0; i < hw_ps->performance_level_count; i++) {
5261 sclk = hw_ps->performance_levels[i].engine_clock;
5262 if (max_sclk < sclk)
5266 for (i = 0; i < pdpm_table->sclk_table.count; i++) {
5267 if (pdpm_table->sclk_table.dpm_levels[i].value == max_sclk)
5268 return (uint16_t) ((i >= pdpm_table->pcie_speed_table.count) ?
5269 pdpm_table->pcie_speed_table.dpm_levels[pdpm_table->pcie_speed_table.count-1].value :
5270 pdpm_table->pcie_speed_table.dpm_levels[i].value);
5276 static int tonga_request_link_speed_change_before_state_change(struct pp_hwmgr *hwmgr, const void *input)
5278 const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
5279 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5280 const struct tonga_power_state *tonga_nps = cast_const_phw_tonga_power_state(states->pnew_state);
5281 const struct tonga_power_state *tonga_cps = cast_const_phw_tonga_power_state(states->pcurrent_state);
5283 uint16_t target_link_speed = tonga_get_maximum_link_speed(hwmgr, tonga_nps);
5284 uint16_t current_link_speed;
5286 if (data->force_pcie_gen == PP_PCIEGenInvalid)
5287 current_link_speed = tonga_get_maximum_link_speed(hwmgr, tonga_cps);
5289 current_link_speed = data->force_pcie_gen;
5291 data->force_pcie_gen = PP_PCIEGenInvalid;
5292 data->pspp_notify_required = false;
5293 if (target_link_speed > current_link_speed) {
5294 switch(target_link_speed) {
5296 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false))
5298 data->force_pcie_gen = PP_PCIEGen2;
5299 if (current_link_speed == PP_PCIEGen2)
5302 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false))
5305 data->force_pcie_gen = tonga_get_current_pcie_speed(hwmgr);
5309 if (target_link_speed < current_link_speed)
5310 data->pspp_notify_required = true;
5316 static int tonga_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
5318 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5320 if (0 == data->need_update_smu7_dpm_table)
5323 if ((0 == data->sclk_dpm_key_disabled) &&
5324 (data->need_update_smu7_dpm_table &
5325 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
5326 PP_ASSERT_WITH_CODE(
5327 true == tonga_is_dpm_running(hwmgr),
5328 "Trying to freeze SCLK DPM when DPM is disabled",
5330 PP_ASSERT_WITH_CODE(
5331 0 == smum_send_msg_to_smc(hwmgr->smumgr,
5332 PPSMC_MSG_SCLKDPM_FreezeLevel),
5333 "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
5337 if ((0 == data->mclk_dpm_key_disabled) &&
5338 (data->need_update_smu7_dpm_table &
5339 DPMTABLE_OD_UPDATE_MCLK)) {
5340 PP_ASSERT_WITH_CODE(true == tonga_is_dpm_running(hwmgr),
5341 "Trying to freeze MCLK DPM when DPM is disabled",
5343 PP_ASSERT_WITH_CODE(
5344 0 == smum_send_msg_to_smc(hwmgr->smumgr,
5345 PPSMC_MSG_MCLKDPM_FreezeLevel),
5346 "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
5353 static int tonga_populate_and_upload_sclk_mclk_dpm_levels(struct pp_hwmgr *hwmgr, const void *input)
5357 const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
5358 const struct tonga_power_state *tonga_ps = cast_const_phw_tonga_power_state(states->pnew_state);
5359 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5360 uint32_t sclk = tonga_ps->performance_levels[tonga_ps->performance_level_count-1].engine_clock;
5361 uint32_t mclk = tonga_ps->performance_levels[tonga_ps->performance_level_count-1].memory_clock;
5362 struct tonga_dpm_table *pdpm_table = &data->dpm_table;
5364 struct tonga_dpm_table *pgolden_dpm_table = &data->golden_dpm_table;
5365 uint32_t dpm_count, clock_percent;
5368 if (0 == data->need_update_smu7_dpm_table)
5371 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
5372 pdpm_table->sclk_table.dpm_levels[pdpm_table->sclk_table.count-1].value = sclk;
5374 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
5375 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
5376 /* Need to do calculation based on the golden DPM table
5377 * as the Heatmap GPU Clock axis is also based on the default values
5379 PP_ASSERT_WITH_CODE(
5380 (pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value != 0),
5383 dpm_count = pdpm_table->sclk_table.count < 2 ? 0 : pdpm_table->sclk_table.count-2;
5384 for (i = dpm_count; i > 1; i--) {
5385 if (sclk > pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value) {
5386 clock_percent = ((sclk - pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value)*100) /
5387 pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value;
5389 pdpm_table->sclk_table.dpm_levels[i].value =
5390 pgolden_dpm_table->sclk_table.dpm_levels[i].value +
5391 (pgolden_dpm_table->sclk_table.dpm_levels[i].value * clock_percent)/100;
5393 } else if (pgolden_dpm_table->sclk_table.dpm_levels[pdpm_table->sclk_table.count-1].value > sclk) {
5394 clock_percent = ((pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value - sclk)*100) /
5395 pgolden_dpm_table->sclk_table.dpm_levels[pgolden_dpm_table->sclk_table.count-1].value;
5397 pdpm_table->sclk_table.dpm_levels[i].value =
5398 pgolden_dpm_table->sclk_table.dpm_levels[i].value -
5399 (pgolden_dpm_table->sclk_table.dpm_levels[i].value * clock_percent)/100;
5401 pdpm_table->sclk_table.dpm_levels[i].value =
5402 pgolden_dpm_table->sclk_table.dpm_levels[i].value;
5407 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
5408 pdpm_table->mclk_table.dpm_levels[pdpm_table->mclk_table.count-1].value = mclk;
5410 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinACSupport) ||
5411 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_OD6PlusinDCSupport)) {
5413 PP_ASSERT_WITH_CODE(
5414 (pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value != 0),
5417 dpm_count = pdpm_table->mclk_table.count < 2? 0 : pdpm_table->mclk_table.count-2;
5418 for (i = dpm_count; i > 1; i--) {
5419 if (mclk > pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value) {
5420 clock_percent = ((mclk - pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value)*100) /
5421 pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value;
5423 pdpm_table->mclk_table.dpm_levels[i].value =
5424 pgolden_dpm_table->mclk_table.dpm_levels[i].value +
5425 (pgolden_dpm_table->mclk_table.dpm_levels[i].value * clock_percent)/100;
5427 } else if (pgolden_dpm_table->mclk_table.dpm_levels[pdpm_table->mclk_table.count-1].value > mclk) {
5428 clock_percent = ((pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value - mclk)*100) /
5429 pgolden_dpm_table->mclk_table.dpm_levels[pgolden_dpm_table->mclk_table.count-1].value;
5431 pdpm_table->mclk_table.dpm_levels[i].value =
5432 pgolden_dpm_table->mclk_table.dpm_levels[i].value -
5433 (pgolden_dpm_table->mclk_table.dpm_levels[i].value * clock_percent)/100;
5435 pdpm_table->mclk_table.dpm_levels[i].value = pgolden_dpm_table->mclk_table.dpm_levels[i].value;
5440 if (data->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
5441 result = tonga_populate_all_memory_levels(hwmgr);
5442 PP_ASSERT_WITH_CODE((0 == result),
5443 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
5447 if (data->need_update_smu7_dpm_table & (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
5448 /*populate MCLK dpm table to SMU7 */
5449 result = tonga_populate_all_memory_levels(hwmgr);
5450 PP_ASSERT_WITH_CODE((0 == result),
5451 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
5458 static int tonga_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
5459 struct tonga_single_dpm_table * pdpm_table,
5460 uint32_t low_limit, uint32_t high_limit)
5464 for (i = 0; i < pdpm_table->count; i++) {
5465 if ((pdpm_table->dpm_levels[i].value < low_limit) ||
5466 (pdpm_table->dpm_levels[i].value > high_limit))
5467 pdpm_table->dpm_levels[i].enabled = false;
5469 pdpm_table->dpm_levels[i].enabled = true;
5474 static int tonga_trim_dpm_states(struct pp_hwmgr *hwmgr, const struct tonga_power_state *hw_state)
5477 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5478 uint32_t high_limit_count;
5480 PP_ASSERT_WITH_CODE((hw_state->performance_level_count >= 1),
5481 "power state did not have any performance level",
5484 high_limit_count = (1 == hw_state->performance_level_count) ? 0: 1;
5486 tonga_trim_single_dpm_states(hwmgr,
5487 &(data->dpm_table.sclk_table),
5488 hw_state->performance_levels[0].engine_clock,
5489 hw_state->performance_levels[high_limit_count].engine_clock);
5491 tonga_trim_single_dpm_states(hwmgr,
5492 &(data->dpm_table.mclk_table),
5493 hw_state->performance_levels[0].memory_clock,
5494 hw_state->performance_levels[high_limit_count].memory_clock);
5499 static int tonga_generate_dpm_level_enable_mask(struct pp_hwmgr *hwmgr, const void *input)
5502 const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
5503 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5504 const struct tonga_power_state *tonga_ps = cast_const_phw_tonga_power_state(states->pnew_state);
5507 result = tonga_trim_dpm_states(hwmgr, tonga_ps);
5511 data->dpm_level_enable_mask.sclk_dpm_enable_mask = tonga_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
5512 data->dpm_level_enable_mask.mclk_dpm_enable_mask = tonga_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
5513 data->last_mclk_dpm_enable_mask = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
5514 if (data->uvd_enabled)
5515 data->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE;
5517 data->dpm_level_enable_mask.pcie_dpm_enable_mask = tonga_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
5522 int tonga_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
5524 return smum_send_msg_to_smc(hwmgr->smumgr, enable ?
5525 (PPSMC_Msg)PPSMC_MSG_VCEDPM_Enable :
5526 (PPSMC_Msg)PPSMC_MSG_VCEDPM_Disable);
5529 int tonga_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable)
5531 return smum_send_msg_to_smc(hwmgr->smumgr, enable ?
5532 (PPSMC_Msg)PPSMC_MSG_UVDDPM_Enable :
5533 (PPSMC_Msg)PPSMC_MSG_UVDDPM_Disable);
5536 int tonga_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate)
5538 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5539 uint32_t mm_boot_level_offset, mm_boot_level_value;
5540 struct phm_ppt_v1_information *ptable_information = (struct phm_ppt_v1_information *)(hwmgr->pptable);
5543 data->smc_state_table.UvdBootLevel = (uint8_t) (ptable_information->mm_dep_table->count - 1);
5544 mm_boot_level_offset = data->dpm_table_start + offsetof(SMU72_Discrete_DpmTable, UvdBootLevel);
5545 mm_boot_level_offset /= 4;
5546 mm_boot_level_offset *= 4;
5547 mm_boot_level_value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, mm_boot_level_offset);
5548 mm_boot_level_value &= 0x00FFFFFF;
5549 mm_boot_level_value |= data->smc_state_table.UvdBootLevel << 24;
5550 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
5552 if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_UVDDPM) ||
5553 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState))
5554 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
5555 PPSMC_MSG_UVDDPM_SetEnabledMask,
5556 (uint32_t)(1 << data->smc_state_table.UvdBootLevel));
5559 return tonga_enable_disable_uvd_dpm(hwmgr, !bgate);
5562 int tonga_update_vce_dpm(struct pp_hwmgr *hwmgr, const void *input)
5564 const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
5565 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5566 const struct tonga_power_state *tonga_nps = cast_const_phw_tonga_power_state(states->pnew_state);
5567 const struct tonga_power_state *tonga_cps = cast_const_phw_tonga_power_state(states->pcurrent_state);
5569 uint32_t mm_boot_level_offset, mm_boot_level_value;
5570 struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
5572 if (tonga_nps->vce_clocks.EVCLK > 0 && (tonga_cps == NULL || tonga_cps->vce_clocks.EVCLK == 0)) {
5573 data->smc_state_table.VceBootLevel = (uint8_t) (pptable_info->mm_dep_table->count - 1);
5575 mm_boot_level_offset = data->dpm_table_start + offsetof(SMU72_Discrete_DpmTable, VceBootLevel);
5576 mm_boot_level_offset /= 4;
5577 mm_boot_level_offset *= 4;
5578 mm_boot_level_value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, mm_boot_level_offset);
5579 mm_boot_level_value &= 0xFF00FFFF;
5580 mm_boot_level_value |= data->smc_state_table.VceBootLevel << 16;
5581 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
5583 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState))
5584 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
5585 PPSMC_MSG_VCEDPM_SetEnabledMask,
5586 (uint32_t)(1 << data->smc_state_table.VceBootLevel));
5588 tonga_enable_disable_vce_dpm(hwmgr, true);
5589 } else if (tonga_nps->vce_clocks.EVCLK == 0 && tonga_cps != NULL && tonga_cps->vce_clocks.EVCLK > 0)
5590 tonga_enable_disable_vce_dpm(hwmgr, false);
5595 static int tonga_update_and_upload_mc_reg_table(struct pp_hwmgr *hwmgr)
5597 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5602 if (0 == (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK))
5606 memset(&data->mc_reg_table, 0, sizeof(SMU72_Discrete_MCRegisters));
5608 result = tonga_convert_mc_reg_table_to_smc(hwmgr, &(data->mc_reg_table));
5614 address = data->mc_reg_table_start + (uint32_t)offsetof(SMU72_Discrete_MCRegisters, data[0]);
5616 return tonga_copy_bytes_to_smc(hwmgr->smumgr, address,
5617 (uint8_t *)&data->mc_reg_table.data[0],
5618 sizeof(SMU72_Discrete_MCRegisterSet) * data->dpm_table.mclk_table.count,
5622 static int tonga_program_memory_timing_parameters_conditionally(struct pp_hwmgr *hwmgr)
5624 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5626 if (data->need_update_smu7_dpm_table &
5627 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK))
5628 return tonga_program_memory_timing_parameters(hwmgr);
5633 static int tonga_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
5635 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5637 if (0 == data->need_update_smu7_dpm_table)
5640 if ((0 == data->sclk_dpm_key_disabled) &&
5641 (data->need_update_smu7_dpm_table &
5642 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
5644 PP_ASSERT_WITH_CODE(true == tonga_is_dpm_running(hwmgr),
5645 "Trying to Unfreeze SCLK DPM when DPM is disabled",
5647 PP_ASSERT_WITH_CODE(
5648 0 == smum_send_msg_to_smc(hwmgr->smumgr,
5649 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
5650 "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
5654 if ((0 == data->mclk_dpm_key_disabled) &&
5655 (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
5657 PP_ASSERT_WITH_CODE(
5658 true == tonga_is_dpm_running(hwmgr),
5659 "Trying to Unfreeze MCLK DPM when DPM is disabled",
5661 PP_ASSERT_WITH_CODE(
5662 0 == smum_send_msg_to_smc(hwmgr->smumgr,
5663 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
5664 "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
5668 data->need_update_smu7_dpm_table = 0;
5673 static int tonga_notify_link_speed_change_after_state_change(struct pp_hwmgr *hwmgr, const void *input)
5675 const struct phm_set_power_state_input *states = (const struct phm_set_power_state_input *)input;
5676 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5677 const struct tonga_power_state *tonga_ps = cast_const_phw_tonga_power_state(states->pnew_state);
5678 uint16_t target_link_speed = tonga_get_maximum_link_speed(hwmgr, tonga_ps);
5681 if (data->pspp_notify_required ||
5682 data->pcie_performance_request) {
5683 if (target_link_speed == PP_PCIEGen3)
5684 request = PCIE_PERF_REQ_GEN3;
5685 else if (target_link_speed == PP_PCIEGen2)
5686 request = PCIE_PERF_REQ_GEN2;
5688 request = PCIE_PERF_REQ_GEN1;
5690 if(request == PCIE_PERF_REQ_GEN1 && tonga_get_current_pcie_speed(hwmgr) > 0) {
5691 data->pcie_performance_request = false;
5695 if (0 != acpi_pcie_perf_request(hwmgr->device, request, false)) {
5696 if (PP_PCIEGen2 == target_link_speed)
5697 printk("PSPP request to switch to Gen2 from Gen3 Failed!");
5699 printk("PSPP request to switch to Gen1 from Gen2 Failed!");
5703 data->pcie_performance_request = false;
5707 static int tonga_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
5709 int tmp_result, result = 0;
5711 tmp_result = tonga_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
5712 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to find DPM states clocks in DPM table!", result = tmp_result);
5714 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PCIEPerformanceRequest)) {
5715 tmp_result = tonga_request_link_speed_change_before_state_change(hwmgr, input);
5716 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to request link speed change before state change!", result = tmp_result);
5719 tmp_result = tonga_freeze_sclk_mclk_dpm(hwmgr);
5720 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
5722 tmp_result = tonga_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
5723 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to populate and upload SCLK MCLK DPM levels!", result = tmp_result);
5725 tmp_result = tonga_generate_dpm_level_enable_mask(hwmgr, input);
5726 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to generate DPM level enabled mask!", result = tmp_result);
5728 tmp_result = tonga_update_vce_dpm(hwmgr, input);
5729 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to update VCE DPM!", result = tmp_result);
5731 tmp_result = tonga_update_sclk_threshold(hwmgr);
5732 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to update SCLK threshold!", result = tmp_result);
5734 tmp_result = tonga_update_and_upload_mc_reg_table(hwmgr);
5735 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to upload MC reg table!", result = tmp_result);
5737 tmp_result = tonga_program_memory_timing_parameters_conditionally(hwmgr);
5738 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to program memory timing parameters!", result = tmp_result);
5740 tmp_result = tonga_unfreeze_sclk_mclk_dpm(hwmgr);
5741 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to unfreeze SCLK MCLK DPM!", result = tmp_result);
5743 tmp_result = tonga_upload_dpm_level_enable_mask(hwmgr);
5744 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to upload DPM level enabled mask!", result = tmp_result);
5746 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PCIEPerformanceRequest)) {
5747 tmp_result = tonga_notify_link_speed_change_after_state_change(hwmgr, input);
5748 PP_ASSERT_WITH_CODE((0 == tmp_result), "Failed to notify link speed change after state change!", result = tmp_result);
5755 * Set maximum target operating fan output PWM
5757 * @param pHwMgr: the address of the powerplay hardware manager.
5758 * @param usMaxFanPwm: max operating fan PWM in percents
5759 * @return The response that came from the SMC.
5761 static int tonga_set_max_fan_pwm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm)
5763 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanPWM = us_max_fan_pwm;
5765 if (phm_is_hw_access_blocked(hwmgr))
5768 return (0 == smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, PPSMC_MSG_SetFanPwmMax, us_max_fan_pwm) ? 0 : -EINVAL);
5771 int tonga_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr *hwmgr)
5773 uint32_t num_active_displays = 0;
5774 struct cgs_display_info info = {0};
5775 info.mode_info = NULL;
5777 cgs_get_active_displays_info(hwmgr->device, &info);
5779 num_active_displays = info.display_count;
5781 if (num_active_displays > 1) /* to do && (pHwMgr->pPECI->displayConfiguration.bMultiMonitorInSync != TRUE)) */
5782 tonga_notify_smc_display_change(hwmgr, false);
5784 tonga_notify_smc_display_change(hwmgr, true);
5790 * Programs the display gap
5792 * @param hwmgr the address of the powerplay hardware manager.
5795 int tonga_program_display_gap(struct pp_hwmgr *hwmgr)
5797 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5798 uint32_t num_active_displays = 0;
5799 uint32_t display_gap = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
5800 uint32_t display_gap2;
5801 uint32_t pre_vbi_time_in_us;
5802 uint32_t frame_time_in_us;
5804 uint32_t refresh_rate = 0;
5805 struct cgs_display_info info = {0};
5806 struct cgs_mode_info mode_info;
5808 info.mode_info = &mode_info;
5810 cgs_get_active_displays_info(hwmgr->device, &info);
5811 num_active_displays = info.display_count;
5813 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL, DISP_GAP, (num_active_displays > 0)? DISPLAY_GAP_VBLANK_OR_WM : DISPLAY_GAP_IGNORE);
5814 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL, display_gap);
5816 ref_clock = mode_info.ref_clock;
5817 refresh_rate = mode_info.refresh_rate;
5819 if(0 == refresh_rate)
5822 frame_time_in_us = 1000000 / refresh_rate;
5824 pre_vbi_time_in_us = frame_time_in_us - 200 - mode_info.vblank_time_us;
5825 display_gap2 = pre_vbi_time_in_us * (ref_clock / 100);
5827 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL2, display_gap2);
5829 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, data->soft_regs_start + offsetof(SMU72_SoftRegisters, PreVBlankGap), 0x64);
5831 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, data->soft_regs_start + offsetof(SMU72_SoftRegisters, VBlankTimeout), (frame_time_in_us - pre_vbi_time_in_us));
5833 if (num_active_displays == 1)
5834 tonga_notify_smc_display_change(hwmgr, true);
5839 int tonga_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
5842 tonga_program_display_gap(hwmgr);
5844 /* to do PhwTonga_CacUpdateDisplayConfiguration(pHwMgr); */
5849 * Set maximum target operating fan output RPM
5851 * @param pHwMgr: the address of the powerplay hardware manager.
5852 * @param usMaxFanRpm: max operating fan RPM value.
5853 * @return The response that came from the SMC.
5855 static int tonga_set_max_fan_rpm_output(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm)
5857 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM = us_max_fan_pwm;
5859 if (phm_is_hw_access_blocked(hwmgr))
5862 return (0 == smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, PPSMC_MSG_SetFanRpmMax, us_max_fan_pwm) ? 0 : -EINVAL);
5865 uint32_t tonga_get_xclk(struct pp_hwmgr *hwmgr)
5867 uint32_t reference_clock;
5871 ATOM_FIRMWARE_INFO *fw_info;
5874 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
5876 tc = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK);
5881 fw_info = (ATOM_FIRMWARE_INFO *)cgs_atom_get_data_table(hwmgr->device, index,
5882 &size, &frev, &crev);
5887 reference_clock = le16_to_cpu(fw_info->usMinPixelClockPLL_Output);
5889 divide = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_CLKPIN_CNTL, XTALIN_DIVIDE);
5892 return reference_clock / 4;
5894 return reference_clock;
5897 int tonga_dpm_set_interrupt_state(void *private_data,
5898 unsigned src_id, unsigned type,
5901 uint32_t cg_thermal_int;
5902 struct pp_hwmgr *hwmgr = ((struct pp_eventmgr *)private_data)->hwmgr;
5908 case AMD_THERMAL_IRQ_LOW_TO_HIGH:
5910 cg_thermal_int = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_THERMAL_INT);
5911 cg_thermal_int |= CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK;
5912 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_THERMAL_INT, cg_thermal_int);
5914 cg_thermal_int = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_THERMAL_INT);
5915 cg_thermal_int &= ~CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK;
5916 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_THERMAL_INT, cg_thermal_int);
5920 case AMD_THERMAL_IRQ_HIGH_TO_LOW:
5922 cg_thermal_int = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_THERMAL_INT);
5923 cg_thermal_int |= CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK;
5924 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_THERMAL_INT, cg_thermal_int);
5926 cg_thermal_int = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_THERMAL_INT);
5927 cg_thermal_int &= ~CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK;
5928 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixCG_THERMAL_INT, cg_thermal_int);
5937 int tonga_register_internal_thermal_interrupt(struct pp_hwmgr *hwmgr,
5938 const void *thermal_interrupt_info)
5941 const struct pp_interrupt_registration_info *info =
5942 (const struct pp_interrupt_registration_info *)thermal_interrupt_info;
5947 result = cgs_add_irq_source(hwmgr->device, 230, AMD_THERMAL_IRQ_LAST,
5948 tonga_dpm_set_interrupt_state,
5949 info->call_back, info->context);
5954 result = cgs_add_irq_source(hwmgr->device, 231, AMD_THERMAL_IRQ_LAST,
5955 tonga_dpm_set_interrupt_state,
5956 info->call_back, info->context);
5964 bool tonga_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
5966 struct tonga_hwmgr *data = (struct tonga_hwmgr *)(hwmgr->backend);
5967 bool is_update_required = false;
5968 struct cgs_display_info info = {0,0,NULL};
5970 cgs_get_active_displays_info(hwmgr->device, &info);
5972 if (data->display_timing.num_existing_displays != info.display_count)
5973 is_update_required = true;
5974 /* TO DO NEED TO GET DEEP SLEEP CLOCK FROM DAL
5975 if (phm_cap_enabled(hwmgr->hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
5976 cgs_get_min_clock_settings(hwmgr->device, &min_clocks);
5977 if(min_clocks.engineClockInSR != data->display_timing.minClockInSR)
5978 is_update_required = true;
5980 return is_update_required;
5983 static inline bool tonga_are_power_levels_equal(const struct tonga_performance_level *pl1,
5984 const struct tonga_performance_level *pl2)
5986 return ((pl1->memory_clock == pl2->memory_clock) &&
5987 (pl1->engine_clock == pl2->engine_clock) &&
5988 (pl1->pcie_gen == pl2->pcie_gen) &&
5989 (pl1->pcie_lane == pl2->pcie_lane));
5992 int tonga_check_states_equal(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *pstate1, const struct pp_hw_power_state *pstate2, bool *equal)
5994 const struct tonga_power_state *psa = cast_const_phw_tonga_power_state(pstate1);
5995 const struct tonga_power_state *psb = cast_const_phw_tonga_power_state(pstate2);
5998 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
6001 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
6002 if (psa->performance_level_count != psb->performance_level_count) {
6007 for (i = 0; i < psa->performance_level_count; i++) {
6008 if (!tonga_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) {
6009 /* If we have found even one performance level pair that is different the states are different. */
6015 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
6016 *equal = ((psa->uvd_clocks.VCLK == psb->uvd_clocks.VCLK) && (psa->uvd_clocks.DCLK == psb->uvd_clocks.DCLK));
6017 *equal &= ((psa->vce_clocks.EVCLK == psb->vce_clocks.EVCLK) && (psa->vce_clocks.ECCLK == psb->vce_clocks.ECCLK));
6018 *equal &= (psa->sclk_threshold == psb->sclk_threshold);
6019 *equal &= (psa->acp_clk == psb->acp_clk);
6024 static const struct pp_hwmgr_func tonga_hwmgr_funcs = {
6025 .backend_init = &tonga_hwmgr_backend_init,
6026 .backend_fini = &tonga_hwmgr_backend_fini,
6027 .asic_setup = &tonga_setup_asic_task,
6028 .dynamic_state_management_enable = &tonga_enable_dpm_tasks,
6029 .apply_state_adjust_rules = tonga_apply_state_adjust_rules,
6030 .force_dpm_level = &tonga_force_dpm_level,
6031 .power_state_set = tonga_set_power_state_tasks,
6032 .get_power_state_size = tonga_get_power_state_size,
6033 .get_mclk = tonga_dpm_get_mclk,
6034 .get_sclk = tonga_dpm_get_sclk,
6035 .patch_boot_state = tonga_dpm_patch_boot_state,
6036 .get_pp_table_entry = tonga_get_pp_table_entry,
6037 .get_num_of_pp_table_entries = tonga_get_number_of_powerplay_table_entries,
6038 .print_current_perforce_level = tonga_print_current_perforce_level,
6039 .powerdown_uvd = tonga_phm_powerdown_uvd,
6040 .powergate_uvd = tonga_phm_powergate_uvd,
6041 .powergate_vce = tonga_phm_powergate_vce,
6042 .disable_clock_power_gating = tonga_phm_disable_clock_power_gating,
6043 .notify_smc_display_config_after_ps_adjustment = tonga_notify_smc_display_config_after_ps_adjustment,
6044 .display_config_changed = tonga_display_configuration_changed_task,
6045 .set_max_fan_pwm_output = tonga_set_max_fan_pwm_output,
6046 .set_max_fan_rpm_output = tonga_set_max_fan_rpm_output,
6047 .get_temperature = tonga_thermal_get_temperature,
6048 .stop_thermal_controller = tonga_thermal_stop_thermal_controller,
6049 .get_fan_speed_info = tonga_fan_ctrl_get_fan_speed_info,
6050 .get_fan_speed_percent = tonga_fan_ctrl_get_fan_speed_percent,
6051 .set_fan_speed_percent = tonga_fan_ctrl_set_fan_speed_percent,
6052 .reset_fan_speed_to_default = tonga_fan_ctrl_reset_fan_speed_to_default,
6053 .get_fan_speed_rpm = tonga_fan_ctrl_get_fan_speed_rpm,
6054 .set_fan_speed_rpm = tonga_fan_ctrl_set_fan_speed_rpm,
6055 .uninitialize_thermal_controller = tonga_thermal_ctrl_uninitialize_thermal_controller,
6056 .register_internal_thermal_interrupt = tonga_register_internal_thermal_interrupt,
6057 .check_smc_update_required_for_display_configuration = tonga_check_smc_update_required_for_display_configuration,
6058 .check_states_equal = tonga_check_states_equal,
6061 int tonga_hwmgr_init(struct pp_hwmgr *hwmgr)
6065 data = kzalloc (sizeof(tonga_hwmgr), GFP_KERNEL);
6068 memset(data, 0x00, sizeof(tonga_hwmgr));
6070 hwmgr->backend = data;
6071 hwmgr->hwmgr_func = &tonga_hwmgr_funcs;
6072 hwmgr->pptable_func = &tonga_pptable_funcs;
6073 pp_tonga_thermal_initialize(hwmgr);