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"
29 #include "fiji_smumgr.h"
31 #include "hardwaremanager.h"
32 #include "ppatomctrl.h"
34 #include "cgs_common.h"
35 #include "fiji_dyn_defaults.h"
36 #include "fiji_powertune.h"
38 #include "smu/smu_7_1_3_d.h"
39 #include "smu/smu_7_1_3_sh_mask.h"
40 #include "gmc/gmc_8_1_d.h"
41 #include "gmc/gmc_8_1_sh_mask.h"
42 #include "bif/bif_5_0_d.h"
43 #include "bif/bif_5_0_sh_mask.h"
44 #include "dce/dce_10_0_d.h"
45 #include "dce/dce_10_0_sh_mask.h"
46 #include "pppcielanes.h"
47 #include "fiji_hwmgr.h"
48 #include "tonga_processpptables.h"
49 #include "tonga_pptable.h"
52 #include "amd_pcie_helpers.h"
54 #define VOLTAGE_SCALE 4
55 #define SMC_RAM_END 0x40000
56 #define VDDC_VDDCI_DELTA 300
58 #define MC_SEQ_MISC0_GDDR5_SHIFT 28
59 #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
60 #define MC_SEQ_MISC0_GDDR5_VALUE 5
62 #define MC_CG_ARB_FREQ_F0 0x0a /* boot-up default */
63 #define MC_CG_ARB_FREQ_F1 0x0b
64 #define MC_CG_ARB_FREQ_F2 0x0c
65 #define MC_CG_ARB_FREQ_F3 0x0d
68 #define SMC_CG_IND_START 0xc0030000
69 #define SMC_CG_IND_END 0xc0040000 /* First byte after SMC_CG_IND */
71 #define VOLTAGE_SCALE 4
72 #define VOLTAGE_VID_OFFSET_SCALE1 625
73 #define VOLTAGE_VID_OFFSET_SCALE2 100
75 #define VDDC_VDDCI_DELTA 300
77 #define ixSWRST_COMMAND_1 0x1400103
78 #define MC_SEQ_CNTL__CAC_EN_MASK 0x40000000
80 /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
82 DPM_EVENT_SRC_ANALOG = 0, /* Internal analog trip point */
83 DPM_EVENT_SRC_EXTERNAL = 1, /* External (GPIO 17) signal */
84 DPM_EVENT_SRC_DIGITAL = 2, /* Internal digital trip point (DIG_THERM_DPM) */
85 DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3, /* Internal analog or external */
86 DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4 /* Internal digital or external */
90 DISPLAY_GAP_VBLANK_OR_WM = 0, /* Wait for vblank or MCHG watermark. */
91 DISPLAY_GAP_VBLANK = 1, /* Wait for vblank. */
92 DISPLAY_GAP_WATERMARK = 2, /* Wait for MCHG watermark. */
93 DISPLAY_GAP_IGNORE = 3 /* Do not wait. */
96 /* [2.5%,~2.5%] Clock stretched is multiple of 2.5% vs
97 * not and [Fmin, Fmax, LDO_REFSEL, USE_FOR_LOW_FREQ]
99 uint16_t fiji_clock_stretcher_lookup_table[2][4] = { {600, 1050, 3, 0},
102 /* [FF, SS] type, [] 4 voltage ranges, and
103 * [Floor Freq, Boundary Freq, VID min , VID max]
105 uint32_t fiji_clock_stretcher_ddt_table[2][4][4] =
106 { { {265, 529, 120, 128}, {325, 650, 96, 119}, {430, 860, 32, 95}, {0, 0, 0, 31} },
107 { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} } };
109 /* [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%]
110 * (coming from PWR_CKS_CNTL.stretch_amount reg spec)
112 uint8_t fiji_clock_stretch_amount_conversion[2][6] = { {0, 1, 3, 2, 4, 5},
113 {0, 2, 4, 5, 6, 5} };
115 const unsigned long PhwFiji_Magic = (unsigned long)(PHM_VIslands_Magic);
117 struct fiji_power_state *cast_phw_fiji_power_state(
118 struct pp_hw_power_state *hw_ps)
120 PP_ASSERT_WITH_CODE((PhwFiji_Magic == hw_ps->magic),
121 "Invalid Powerstate Type!",
124 return (struct fiji_power_state *)hw_ps;
127 const struct fiji_power_state *cast_const_phw_fiji_power_state(
128 const struct pp_hw_power_state *hw_ps)
130 PP_ASSERT_WITH_CODE((PhwFiji_Magic == hw_ps->magic),
131 "Invalid Powerstate Type!",
134 return (const struct fiji_power_state *)hw_ps;
137 static bool fiji_is_dpm_running(struct pp_hwmgr *hwmgr)
139 return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
140 CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON))
144 static void fiji_init_dpm_defaults(struct pp_hwmgr *hwmgr)
146 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
147 struct fiji_ulv_parm *ulv = &data->ulv;
149 ulv->cg_ulv_parameter = PPFIJI_CGULVPARAMETER_DFLT;
150 data->voting_rights_clients0 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT0;
151 data->voting_rights_clients1 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT1;
152 data->voting_rights_clients2 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT2;
153 data->voting_rights_clients3 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT3;
154 data->voting_rights_clients4 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT4;
155 data->voting_rights_clients5 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT5;
156 data->voting_rights_clients6 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT6;
157 data->voting_rights_clients7 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT7;
159 data->static_screen_threshold_unit =
160 PPFIJI_STATICSCREENTHRESHOLDUNIT_DFLT;
161 data->static_screen_threshold =
162 PPFIJI_STATICSCREENTHRESHOLD_DFLT;
164 /* Unset ABM cap as it moved to DAL.
165 * Add PHM_PlatformCaps_NonABMSupportInPPLib
166 * for re-direct ABM related request to DAL
168 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
169 PHM_PlatformCaps_ABM);
170 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
171 PHM_PlatformCaps_NonABMSupportInPPLib);
173 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
174 PHM_PlatformCaps_DynamicACTiming);
176 fiji_initialize_power_tune_defaults(hwmgr);
178 data->mclk_stutter_mode_threshold = 60000;
179 data->pcie_gen_performance.max = PP_PCIEGen1;
180 data->pcie_gen_performance.min = PP_PCIEGen3;
181 data->pcie_gen_power_saving.max = PP_PCIEGen1;
182 data->pcie_gen_power_saving.min = PP_PCIEGen3;
183 data->pcie_lane_performance.max = 0;
184 data->pcie_lane_performance.min = 16;
185 data->pcie_lane_power_saving.max = 0;
186 data->pcie_lane_power_saving.min = 16;
188 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
189 PHM_PlatformCaps_DynamicUVDState);
192 static int fiji_get_sclk_for_voltage_evv(struct pp_hwmgr *hwmgr,
193 phm_ppt_v1_voltage_lookup_table *lookup_table,
194 uint16_t virtual_voltage_id, int32_t *sclk)
198 struct phm_ppt_v1_information *table_info =
199 (struct phm_ppt_v1_information *)(hwmgr->pptable);
201 PP_ASSERT_WITH_CODE(lookup_table->count != 0, "Lookup table is empty", return -EINVAL);
203 /* search for leakage voltage ID 0xff01 ~ 0xff08 and sckl */
204 for (entryId = 0; entryId < table_info->vdd_dep_on_sclk->count; entryId++) {
205 voltageId = table_info->vdd_dep_on_sclk->entries[entryId].vddInd;
206 if (lookup_table->entries[voltageId].us_vdd == virtual_voltage_id)
210 PP_ASSERT_WITH_CODE(entryId < table_info->vdd_dep_on_sclk->count,
211 "Can't find requested voltage id in vdd_dep_on_sclk table!",
215 *sclk = table_info->vdd_dep_on_sclk->entries[entryId].clk;
221 * Get Leakage VDDC based on leakage ID.
223 * @param hwmgr the address of the powerplay hardware manager.
226 static int fiji_get_evv_voltages(struct pp_hwmgr *hwmgr)
228 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
231 uint16_t evv_default = 1150;
234 struct phm_ppt_v1_information *table_info =
235 (struct phm_ppt_v1_information *)hwmgr->pptable;
236 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
237 table_info->vdd_dep_on_sclk;
240 for (i = 0; i < FIJI_MAX_LEAKAGE_COUNT; i++) {
241 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
242 if (!fiji_get_sclk_for_voltage_evv(hwmgr,
243 table_info->vddc_lookup_table, vv_id, &sclk)) {
244 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
245 PHM_PlatformCaps_ClockStretcher)) {
246 for (j = 1; j < sclk_table->count; j++) {
247 if (sclk_table->entries[j].clk == sclk &&
248 sclk_table->entries[j].cks_enable == 0) {
255 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
256 PHM_PlatformCaps_EnableDriverEVV))
257 result = atomctrl_calculate_voltage_evv_on_sclk(hwmgr,
258 VOLTAGE_TYPE_VDDC, sclk, vv_id, &vddc, i, true);
263 result = atomctrl_get_voltage_evv_on_sclk(hwmgr,
264 VOLTAGE_TYPE_VDDC, sclk,vv_id, &vddc);
266 /* need to make sure vddc is less than 2v or else, it could burn the ASIC. */
267 PP_ASSERT_WITH_CODE((vddc < 2000),
268 "Invalid VDDC value, greater than 2v!", result = -EINVAL;);
271 /* 1.15V is the default safe value for Fiji */
274 /* the voltage should not be zero nor equal to leakage ID */
275 if (vddc != 0 && vddc != vv_id) {
276 data->vddc_leakage.actual_voltage
277 [data->vddc_leakage.count] = vddc;
278 data->vddc_leakage.leakage_id
279 [data->vddc_leakage.count] = vv_id;
280 data->vddc_leakage.count++;
288 * Change virtual leakage voltage to actual value.
290 * @param hwmgr the address of the powerplay hardware manager.
291 * @param pointer to changing voltage
292 * @param pointer to leakage table
294 static void fiji_patch_with_vdd_leakage(struct pp_hwmgr *hwmgr,
295 uint16_t *voltage, struct fiji_leakage_voltage *leakage_table)
299 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
300 for (index = 0; index < leakage_table->count; index++) {
301 /* if this voltage matches a leakage voltage ID */
302 /* patch with actual leakage voltage */
303 if (leakage_table->leakage_id[index] == *voltage) {
304 *voltage = leakage_table->actual_voltage[index];
309 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
310 printk(KERN_ERR "Voltage value looks like a Leakage ID but it's not patched \n");
314 * Patch voltage lookup table by EVV leakages.
316 * @param hwmgr the address of the powerplay hardware manager.
317 * @param pointer to voltage lookup table
318 * @param pointer to leakage table
321 static int fiji_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
322 phm_ppt_v1_voltage_lookup_table *lookup_table,
323 struct fiji_leakage_voltage *leakage_table)
327 for (i = 0; i < lookup_table->count; i++)
328 fiji_patch_with_vdd_leakage(hwmgr,
329 &lookup_table->entries[i].us_vdd, leakage_table);
334 static int fiji_patch_clock_voltage_limits_with_vddc_leakage(
335 struct pp_hwmgr *hwmgr, struct fiji_leakage_voltage *leakage_table,
338 struct phm_ppt_v1_information *table_info =
339 (struct phm_ppt_v1_information *)(hwmgr->pptable);
340 fiji_patch_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
341 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
342 table_info->max_clock_voltage_on_dc.vddc;
346 static int fiji_patch_voltage_dependency_tables_with_lookup_table(
347 struct pp_hwmgr *hwmgr)
351 struct phm_ppt_v1_information *table_info =
352 (struct phm_ppt_v1_information *)(hwmgr->pptable);
354 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
355 table_info->vdd_dep_on_sclk;
356 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
357 table_info->vdd_dep_on_mclk;
358 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
359 table_info->mm_dep_table;
361 for (entryId = 0; entryId < sclk_table->count; ++entryId) {
362 voltageId = sclk_table->entries[entryId].vddInd;
363 sclk_table->entries[entryId].vddc =
364 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
367 for (entryId = 0; entryId < mclk_table->count; ++entryId) {
368 voltageId = mclk_table->entries[entryId].vddInd;
369 mclk_table->entries[entryId].vddc =
370 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
373 for (entryId = 0; entryId < mm_table->count; ++entryId) {
374 voltageId = mm_table->entries[entryId].vddcInd;
375 mm_table->entries[entryId].vddc =
376 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
383 static int fiji_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
385 /* Need to determine if we need calculated voltage. */
389 static int fiji_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
391 /* Need to determine if we need calculated voltage from mm table. */
395 static int fiji_sort_lookup_table(struct pp_hwmgr *hwmgr,
396 struct phm_ppt_v1_voltage_lookup_table *lookup_table)
398 uint32_t table_size, i, j;
399 struct phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record;
400 table_size = lookup_table->count;
402 PP_ASSERT_WITH_CODE(0 != lookup_table->count,
403 "Lookup table is empty", return -EINVAL);
405 /* Sorting voltages */
406 for (i = 0; i < table_size - 1; i++) {
407 for (j = i + 1; j > 0; j--) {
408 if (lookup_table->entries[j].us_vdd <
409 lookup_table->entries[j - 1].us_vdd) {
410 tmp_voltage_lookup_record = lookup_table->entries[j - 1];
411 lookup_table->entries[j - 1] = lookup_table->entries[j];
412 lookup_table->entries[j] = tmp_voltage_lookup_record;
420 static int fiji_complete_dependency_tables(struct pp_hwmgr *hwmgr)
424 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
425 struct phm_ppt_v1_information *table_info =
426 (struct phm_ppt_v1_information *)(hwmgr->pptable);
428 tmp_result = fiji_patch_lookup_table_with_leakage(hwmgr,
429 table_info->vddc_lookup_table, &(data->vddc_leakage));
433 tmp_result = fiji_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
434 &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
438 tmp_result = fiji_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
442 tmp_result = fiji_calc_voltage_dependency_tables(hwmgr);
446 tmp_result = fiji_calc_mm_voltage_dependency_table(hwmgr);
450 tmp_result = fiji_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
457 static int fiji_set_private_data_based_on_pptable(struct pp_hwmgr *hwmgr)
459 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
460 struct phm_ppt_v1_information *table_info =
461 (struct phm_ppt_v1_information *)(hwmgr->pptable);
463 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
464 table_info->vdd_dep_on_sclk;
465 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
466 table_info->vdd_dep_on_mclk;
468 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
469 "VDD dependency on SCLK table is missing. \
470 This table is mandatory", return -EINVAL);
471 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
472 "VDD dependency on SCLK table has to have is missing. \
473 This table is mandatory", return -EINVAL);
475 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
476 "VDD dependency on MCLK table is missing. \
477 This table is mandatory", return -EINVAL);
478 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
479 "VDD dependency on MCLK table has to have is missing. \
480 This table is mandatory", return -EINVAL);
482 data->min_vddc_in_pptable = (uint16_t)allowed_sclk_vdd_table->entries[0].vddc;
483 data->max_vddc_in_pptable = (uint16_t)allowed_sclk_vdd_table->
484 entries[allowed_sclk_vdd_table->count - 1].vddc;
486 table_info->max_clock_voltage_on_ac.sclk =
487 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
488 table_info->max_clock_voltage_on_ac.mclk =
489 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
490 table_info->max_clock_voltage_on_ac.vddc =
491 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
492 table_info->max_clock_voltage_on_ac.vddci =
493 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
495 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
496 table_info->max_clock_voltage_on_ac.sclk;
497 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
498 table_info->max_clock_voltage_on_ac.mclk;
499 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
500 table_info->max_clock_voltage_on_ac.vddc;
501 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci =
502 table_info->max_clock_voltage_on_ac.vddci;
507 static uint16_t fiji_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
509 uint32_t speedCntl = 0;
511 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
512 speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
513 ixPCIE_LC_SPEED_CNTL);
514 return((uint16_t)PHM_GET_FIELD(speedCntl,
515 PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
518 static int fiji_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr)
522 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
523 link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
524 PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD);
526 PP_ASSERT_WITH_CODE((7 >= link_width),
527 "Invalid PCIe lane width!", return 0);
529 return decode_pcie_lane_width(link_width);
532 /** Patch the Boot State to match VBIOS boot clocks and voltage.
534 * @param hwmgr Pointer to the hardware manager.
535 * @param pPowerState The address of the PowerState instance being created.
538 static int fiji_patch_boot_state(struct pp_hwmgr *hwmgr,
539 struct pp_hw_power_state *hw_ps)
541 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
542 struct fiji_power_state *ps = (struct fiji_power_state *)hw_ps;
543 ATOM_FIRMWARE_INFO_V2_2 *fw_info;
546 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
548 /* First retrieve the Boot clocks and VDDC from the firmware info table.
549 * We assume here that fw_info is unchanged if this call fails.
551 fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table(
552 hwmgr->device, index,
553 &size, &frev, &crev);
555 /* During a test, there is no firmware info table. */
558 /* Patch the state. */
559 data->vbios_boot_state.sclk_bootup_value =
560 le32_to_cpu(fw_info->ulDefaultEngineClock);
561 data->vbios_boot_state.mclk_bootup_value =
562 le32_to_cpu(fw_info->ulDefaultMemoryClock);
563 data->vbios_boot_state.mvdd_bootup_value =
564 le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
565 data->vbios_boot_state.vddc_bootup_value =
566 le16_to_cpu(fw_info->usBootUpVDDCVoltage);
567 data->vbios_boot_state.vddci_bootup_value =
568 le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
569 data->vbios_boot_state.pcie_gen_bootup_value =
570 fiji_get_current_pcie_speed(hwmgr);
571 data->vbios_boot_state.pcie_lane_bootup_value =
572 (uint16_t)fiji_get_current_pcie_lane_number(hwmgr);
574 /* set boot power state */
575 ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
576 ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
577 ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
578 ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
583 static int fiji_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
585 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
587 struct phm_ppt_v1_information *table_info =
588 (struct phm_ppt_v1_information *)(hwmgr->pptable);
592 data->dll_default_on = false;
593 data->sram_end = SMC_RAM_END;
595 for (i = 0; i < SMU73_MAX_LEVELS_GRAPHICS; i++)
596 data->activity_target[i] = FIJI_AT_DFLT;
598 data->vddc_vddci_delta = VDDC_VDDCI_DELTA;
600 data->mclk_activity_target = PPFIJI_MCLK_TARGETACTIVITY_DFLT;
601 data->mclk_dpm0_activity_target = 0xa;
603 data->sclk_dpm_key_disabled = 0;
604 data->mclk_dpm_key_disabled = 0;
605 data->pcie_dpm_key_disabled = 0;
607 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
608 PHM_PlatformCaps_UnTabledHardwareInterface);
609 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
610 PHM_PlatformCaps_TablelessHardwareInterface);
612 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
613 PHM_PlatformCaps_SclkDeepSleep);
615 data->gpio_debug = 0;
617 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
618 PHM_PlatformCaps_DynamicPatchPowerState);
620 /* need to set voltage control types before EVV patching */
621 data->voltage_control = FIJI_VOLTAGE_CONTROL_NONE;
622 data->vddci_control = FIJI_VOLTAGE_CONTROL_NONE;
623 data->mvdd_control = FIJI_VOLTAGE_CONTROL_NONE;
625 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
626 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
627 data->voltage_control = FIJI_VOLTAGE_CONTROL_BY_SVID2;
629 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
630 PHM_PlatformCaps_EnableMVDDControl))
631 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
632 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
633 data->mvdd_control = FIJI_VOLTAGE_CONTROL_BY_GPIO;
635 if (data->mvdd_control == FIJI_VOLTAGE_CONTROL_NONE)
636 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
637 PHM_PlatformCaps_EnableMVDDControl);
639 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
640 PHM_PlatformCaps_ControlVDDCI)) {
641 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
642 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
643 data->vddci_control = FIJI_VOLTAGE_CONTROL_BY_GPIO;
644 else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
645 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
646 data->vddci_control = FIJI_VOLTAGE_CONTROL_BY_SVID2;
649 if (data->vddci_control == FIJI_VOLTAGE_CONTROL_NONE)
650 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
651 PHM_PlatformCaps_ControlVDDCI);
653 if (table_info && table_info->cac_dtp_table->usClockStretchAmount)
654 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
655 PHM_PlatformCaps_ClockStretcher);
657 fiji_init_dpm_defaults(hwmgr);
659 /* Get leakage voltage based on leakage ID. */
660 fiji_get_evv_voltages(hwmgr);
662 /* Patch our voltage dependency table with actual leakage voltage
663 * We need to perform leakage translation before it's used by other functions
665 fiji_complete_dependency_tables(hwmgr);
667 /* Parse pptable data read from VBIOS */
668 fiji_set_private_data_based_on_pptable(hwmgr);
671 data->ulv.ulv_supported = true; /* ULV feature is enabled by default */
673 /* Initalize Dynamic State Adjustment Rule Settings */
674 result = tonga_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
677 data->uvd_enabled = false;
678 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
679 PHM_PlatformCaps_EnableSMU7ThermalManagement);
680 data->vddc_phase_shed_control = false;
683 stay_in_boot = phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
684 PHM_PlatformCaps_StayInBootState);
687 data->is_tlu_enabled = 0;
688 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
689 FIJI_MAX_HARDWARE_POWERLEVELS;
690 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
691 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
693 data->pcie_gen_cap = 0x30007;
694 data->pcie_lane_cap = 0x2f0000;
696 /* Ignore return value in here, we are cleaning up a mess. */
697 tonga_hwmgr_backend_fini(hwmgr);
704 * Read clock related registers.
706 * @param hwmgr the address of the powerplay hardware manager.
709 static int fiji_read_clock_registers(struct pp_hwmgr *hwmgr)
711 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
713 data->clock_registers.vCG_SPLL_FUNC_CNTL =
714 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
715 ixCG_SPLL_FUNC_CNTL);
716 data->clock_registers.vCG_SPLL_FUNC_CNTL_2 =
717 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
718 ixCG_SPLL_FUNC_CNTL_2);
719 data->clock_registers.vCG_SPLL_FUNC_CNTL_3 =
720 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
721 ixCG_SPLL_FUNC_CNTL_3);
722 data->clock_registers.vCG_SPLL_FUNC_CNTL_4 =
723 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
724 ixCG_SPLL_FUNC_CNTL_4);
725 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM =
726 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
727 ixCG_SPLL_SPREAD_SPECTRUM);
728 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 =
729 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
730 ixCG_SPLL_SPREAD_SPECTRUM_2);
736 * Find out if memory is GDDR5.
738 * @param hwmgr the address of the powerplay hardware manager.
741 static int fiji_get_memory_type(struct pp_hwmgr *hwmgr)
743 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
746 temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0);
748 data->is_memory_gddr5 = (MC_SEQ_MISC0_GDDR5_VALUE ==
749 ((temp & MC_SEQ_MISC0_GDDR5_MASK) >>
750 MC_SEQ_MISC0_GDDR5_SHIFT));
756 * Enables Dynamic Power Management by SMC
758 * @param hwmgr the address of the powerplay hardware manager.
761 static int fiji_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
763 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
764 GENERAL_PWRMGT, STATIC_PM_EN, 1);
770 * Initialize PowerGating States for different engines
772 * @param hwmgr the address of the powerplay hardware manager.
775 static int fiji_init_power_gate_state(struct pp_hwmgr *hwmgr)
777 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
779 data->uvd_power_gated = false;
780 data->vce_power_gated = false;
781 data->samu_power_gated = false;
782 data->acp_power_gated = false;
783 data->pg_acp_init = true;
788 static int fiji_init_sclk_threshold(struct pp_hwmgr *hwmgr)
790 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
791 data->low_sclk_interrupt_threshold = 0;
796 static int fiji_setup_asic_task(struct pp_hwmgr *hwmgr)
798 int tmp_result, result = 0;
800 tmp_result = fiji_read_clock_registers(hwmgr);
801 PP_ASSERT_WITH_CODE((0 == tmp_result),
802 "Failed to read clock registers!", result = tmp_result);
804 tmp_result = fiji_get_memory_type(hwmgr);
805 PP_ASSERT_WITH_CODE((0 == tmp_result),
806 "Failed to get memory type!", result = tmp_result);
808 tmp_result = fiji_enable_acpi_power_management(hwmgr);
809 PP_ASSERT_WITH_CODE((0 == tmp_result),
810 "Failed to enable ACPI power management!", result = tmp_result);
812 tmp_result = fiji_init_power_gate_state(hwmgr);
813 PP_ASSERT_WITH_CODE((0 == tmp_result),
814 "Failed to init power gate state!", result = tmp_result);
816 tmp_result = tonga_get_mc_microcode_version(hwmgr);
817 PP_ASSERT_WITH_CODE((0 == tmp_result),
818 "Failed to get MC microcode version!", result = tmp_result);
820 tmp_result = fiji_init_sclk_threshold(hwmgr);
821 PP_ASSERT_WITH_CODE((0 == tmp_result),
822 "Failed to init sclk threshold!", result = tmp_result);
828 * Checks if we want to support voltage control
830 * @param hwmgr the address of the powerplay hardware manager.
832 static bool fiji_voltage_control(const struct pp_hwmgr *hwmgr)
834 const struct fiji_hwmgr *data =
835 (const struct fiji_hwmgr *)(hwmgr->backend);
837 return (FIJI_VOLTAGE_CONTROL_NONE != data->voltage_control);
841 * Enable voltage control
843 * @param hwmgr the address of the powerplay hardware manager.
846 static int fiji_enable_voltage_control(struct pp_hwmgr *hwmgr)
848 /* enable voltage control */
849 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
850 GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
856 * Remove repeated voltage values and create table with unique values.
858 * @param hwmgr the address of the powerplay hardware manager.
859 * @param vol_table the pointer to changing voltage table
860 * @return 0 in success
863 static int fiji_trim_voltage_table(struct pp_hwmgr *hwmgr,
864 struct pp_atomctrl_voltage_table *vol_table)
869 struct pp_atomctrl_voltage_table *table;
871 PP_ASSERT_WITH_CODE((NULL != vol_table),
872 "Voltage Table empty.", return -EINVAL);
873 table = kzalloc(sizeof(struct pp_atomctrl_voltage_table),
879 table->mask_low = vol_table->mask_low;
880 table->phase_delay = vol_table->phase_delay;
882 for (i = 0; i < vol_table->count; i++) {
883 vvalue = vol_table->entries[i].value;
886 for (j = 0; j < table->count; j++) {
887 if (vvalue == table->entries[j].value) {
894 table->entries[table->count].value = vvalue;
895 table->entries[table->count].smio_low =
896 vol_table->entries[i].smio_low;
901 memcpy(vol_table, table, sizeof(struct pp_atomctrl_voltage_table));
906 static int fiji_get_svi2_mvdd_voltage_table(struct pp_hwmgr *hwmgr,
907 phm_ppt_v1_clock_voltage_dependency_table *dep_table)
911 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
912 struct pp_atomctrl_voltage_table *vol_table = &(data->mvdd_voltage_table);
914 PP_ASSERT_WITH_CODE((0 != dep_table->count),
915 "Voltage Dependency Table empty.", return -EINVAL);
917 vol_table->mask_low = 0;
918 vol_table->phase_delay = 0;
919 vol_table->count = dep_table->count;
921 for (i = 0; i < dep_table->count; i++) {
922 vol_table->entries[i].value = dep_table->entries[i].mvdd;
923 vol_table->entries[i].smio_low = 0;
926 result = fiji_trim_voltage_table(hwmgr, vol_table);
927 PP_ASSERT_WITH_CODE((0 == result),
928 "Failed to trim MVDD table.", return result);
933 static int fiji_get_svi2_vddci_voltage_table(struct pp_hwmgr *hwmgr,
934 phm_ppt_v1_clock_voltage_dependency_table *dep_table)
938 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
939 struct pp_atomctrl_voltage_table *vol_table = &(data->vddci_voltage_table);
941 PP_ASSERT_WITH_CODE((0 != dep_table->count),
942 "Voltage Dependency Table empty.", return -EINVAL);
944 vol_table->mask_low = 0;
945 vol_table->phase_delay = 0;
946 vol_table->count = dep_table->count;
948 for (i = 0; i < dep_table->count; i++) {
949 vol_table->entries[i].value = dep_table->entries[i].vddci;
950 vol_table->entries[i].smio_low = 0;
953 result = fiji_trim_voltage_table(hwmgr, vol_table);
954 PP_ASSERT_WITH_CODE((0 == result),
955 "Failed to trim VDDCI table.", return result);
960 static int fiji_get_svi2_vdd_voltage_table(struct pp_hwmgr *hwmgr,
961 phm_ppt_v1_voltage_lookup_table *lookup_table)
964 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
965 struct pp_atomctrl_voltage_table *vol_table = &(data->vddc_voltage_table);
967 PP_ASSERT_WITH_CODE((0 != lookup_table->count),
968 "Voltage Lookup Table empty.", return -EINVAL);
970 vol_table->mask_low = 0;
971 vol_table->phase_delay = 0;
973 vol_table->count = lookup_table->count;
975 for (i = 0; i < vol_table->count; i++) {
976 vol_table->entries[i].value = lookup_table->entries[i].us_vdd;
977 vol_table->entries[i].smio_low = 0;
983 /* ---- Voltage Tables ----
984 * If the voltage table would be bigger than
985 * what will fit into the state table on
986 * the SMC keep only the higher entries.
988 static void fiji_trim_voltage_table_to_fit_state_table(struct pp_hwmgr *hwmgr,
989 uint32_t max_vol_steps, struct pp_atomctrl_voltage_table *vol_table)
991 unsigned int i, diff;
993 if (vol_table->count <= max_vol_steps)
996 diff = vol_table->count - max_vol_steps;
998 for (i = 0; i < max_vol_steps; i++)
999 vol_table->entries[i] = vol_table->entries[i + diff];
1001 vol_table->count = max_vol_steps;
1007 * Create Voltage Tables.
1009 * @param hwmgr the address of the powerplay hardware manager.
1012 static int fiji_construct_voltage_tables(struct pp_hwmgr *hwmgr)
1014 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1015 struct phm_ppt_v1_information *table_info =
1016 (struct phm_ppt_v1_information *)hwmgr->pptable;
1019 if (FIJI_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
1020 result = atomctrl_get_voltage_table_v3(hwmgr,
1021 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT,
1022 &(data->mvdd_voltage_table));
1023 PP_ASSERT_WITH_CODE((0 == result),
1024 "Failed to retrieve MVDD table.",
1026 } else if (FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
1027 result = fiji_get_svi2_mvdd_voltage_table(hwmgr,
1028 table_info->vdd_dep_on_mclk);
1029 PP_ASSERT_WITH_CODE((0 == result),
1030 "Failed to retrieve SVI2 MVDD table from dependancy table.",
1034 if (FIJI_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
1035 result = atomctrl_get_voltage_table_v3(hwmgr,
1036 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT,
1037 &(data->vddci_voltage_table));
1038 PP_ASSERT_WITH_CODE((0 == result),
1039 "Failed to retrieve VDDCI table.",
1041 } else if (FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
1042 result = fiji_get_svi2_vddci_voltage_table(hwmgr,
1043 table_info->vdd_dep_on_mclk);
1044 PP_ASSERT_WITH_CODE((0 == result),
1045 "Failed to retrieve SVI2 VDDCI table from dependancy table.",
1049 if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
1050 result = fiji_get_svi2_vdd_voltage_table(hwmgr,
1051 table_info->vddc_lookup_table);
1052 PP_ASSERT_WITH_CODE((0 == result),
1053 "Failed to retrieve SVI2 VDDC table from lookup table.",
1057 PP_ASSERT_WITH_CODE(
1058 (data->vddc_voltage_table.count <= (SMU73_MAX_LEVELS_VDDC)),
1059 "Too many voltage values for VDDC. Trimming to fit state table.",
1060 fiji_trim_voltage_table_to_fit_state_table(hwmgr,
1061 SMU73_MAX_LEVELS_VDDC, &(data->vddc_voltage_table)));
1063 PP_ASSERT_WITH_CODE(
1064 (data->vddci_voltage_table.count <= (SMU73_MAX_LEVELS_VDDCI)),
1065 "Too many voltage values for VDDCI. Trimming to fit state table.",
1066 fiji_trim_voltage_table_to_fit_state_table(hwmgr,
1067 SMU73_MAX_LEVELS_VDDCI, &(data->vddci_voltage_table)));
1069 PP_ASSERT_WITH_CODE(
1070 (data->mvdd_voltage_table.count <= (SMU73_MAX_LEVELS_MVDD)),
1071 "Too many voltage values for MVDD. Trimming to fit state table.",
1072 fiji_trim_voltage_table_to_fit_state_table(hwmgr,
1073 SMU73_MAX_LEVELS_MVDD, &(data->mvdd_voltage_table)));
1078 static int fiji_initialize_mc_reg_table(struct pp_hwmgr *hwmgr)
1080 /* Program additional LP registers
1081 * that are no longer programmed by VBIOS
1083 cgs_write_register(hwmgr->device, mmMC_SEQ_RAS_TIMING_LP,
1084 cgs_read_register(hwmgr->device, mmMC_SEQ_RAS_TIMING));
1085 cgs_write_register(hwmgr->device, mmMC_SEQ_CAS_TIMING_LP,
1086 cgs_read_register(hwmgr->device, mmMC_SEQ_CAS_TIMING));
1087 cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2_LP,
1088 cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2));
1089 cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1_LP,
1090 cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1));
1091 cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0_LP,
1092 cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0));
1093 cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1_LP,
1094 cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1));
1095 cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_TIMING_LP,
1096 cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_TIMING));
1102 * Programs static screed detection parameters
1104 * @param hwmgr the address of the powerplay hardware manager.
1107 static int fiji_program_static_screen_threshold_parameters(
1108 struct pp_hwmgr *hwmgr)
1110 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1112 /* Set static screen threshold unit */
1113 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1114 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
1115 data->static_screen_threshold_unit);
1116 /* Set static screen threshold */
1117 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1118 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
1119 data->static_screen_threshold);
1125 * Setup display gap for glitch free memory clock switching.
1127 * @param hwmgr the address of the powerplay hardware manager.
1130 static int fiji_enable_display_gap(struct pp_hwmgr *hwmgr)
1132 uint32_t displayGap =
1133 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1134 ixCG_DISPLAY_GAP_CNTL);
1136 displayGap = PHM_SET_FIELD(displayGap, CG_DISPLAY_GAP_CNTL,
1137 DISP_GAP, DISPLAY_GAP_IGNORE);
1139 displayGap = PHM_SET_FIELD(displayGap, CG_DISPLAY_GAP_CNTL,
1140 DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
1142 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1143 ixCG_DISPLAY_GAP_CNTL, displayGap);
1149 * Programs activity state transition voting clients
1151 * @param hwmgr the address of the powerplay hardware manager.
1154 static int fiji_program_voting_clients(struct pp_hwmgr *hwmgr)
1156 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1158 /* Clear reset for voting clients before enabling DPM */
1159 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1160 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
1161 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1162 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
1164 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1165 ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0);
1166 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1167 ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1);
1168 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1169 ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2);
1170 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1171 ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3);
1172 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1173 ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4);
1174 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1175 ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5);
1176 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1177 ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6);
1178 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1179 ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7);
1185 * Get the location of various tables inside the FW image.
1187 * @param hwmgr the address of the powerplay hardware manager.
1190 static int fiji_process_firmware_header(struct pp_hwmgr *hwmgr)
1192 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1193 struct fiji_smumgr *smu_data = (struct fiji_smumgr *)(hwmgr->smumgr->backend);
1198 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1199 SMU7_FIRMWARE_HEADER_LOCATION +
1200 offsetof(SMU73_Firmware_Header, DpmTable),
1201 &tmp, data->sram_end);
1204 data->dpm_table_start = tmp;
1206 error |= (0 != result);
1208 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1209 SMU7_FIRMWARE_HEADER_LOCATION +
1210 offsetof(SMU73_Firmware_Header, SoftRegisters),
1211 &tmp, data->sram_end);
1214 data->soft_regs_start = tmp;
1215 smu_data->soft_regs_start = tmp;
1218 error |= (0 != result);
1220 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1221 SMU7_FIRMWARE_HEADER_LOCATION +
1222 offsetof(SMU73_Firmware_Header, mcRegisterTable),
1223 &tmp, data->sram_end);
1226 data->mc_reg_table_start = tmp;
1228 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1229 SMU7_FIRMWARE_HEADER_LOCATION +
1230 offsetof(SMU73_Firmware_Header, FanTable),
1231 &tmp, data->sram_end);
1234 data->fan_table_start = tmp;
1236 error |= (0 != result);
1238 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1239 SMU7_FIRMWARE_HEADER_LOCATION +
1240 offsetof(SMU73_Firmware_Header, mcArbDramTimingTable),
1241 &tmp, data->sram_end);
1244 data->arb_table_start = tmp;
1246 error |= (0 != result);
1248 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1249 SMU7_FIRMWARE_HEADER_LOCATION +
1250 offsetof(SMU73_Firmware_Header, Version),
1251 &tmp, data->sram_end);
1254 hwmgr->microcode_version_info.SMC = tmp;
1256 error |= (0 != result);
1258 return error ? -1 : 0;
1261 /* Copy one arb setting to another and then switch the active set.
1262 * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
1264 static int fiji_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
1265 uint32_t arb_src, uint32_t arb_dest)
1267 uint32_t mc_arb_dram_timing;
1268 uint32_t mc_arb_dram_timing2;
1269 uint32_t burst_time;
1270 uint32_t mc_cg_config;
1273 case MC_CG_ARB_FREQ_F0:
1274 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
1275 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
1276 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
1278 case MC_CG_ARB_FREQ_F1:
1279 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
1280 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
1281 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
1288 case MC_CG_ARB_FREQ_F0:
1289 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
1290 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
1291 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
1293 case MC_CG_ARB_FREQ_F1:
1294 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
1295 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
1296 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
1302 mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
1303 mc_cg_config |= 0x0000000F;
1304 cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
1305 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest);
1311 * Initial switch from ARB F0->F1
1313 * @param hwmgr the address of the powerplay hardware manager.
1315 * This function is to be called from the SetPowerState table.
1317 static int fiji_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr)
1319 return fiji_copy_and_switch_arb_sets(hwmgr,
1320 MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
1323 static int fiji_reset_single_dpm_table(struct pp_hwmgr *hwmgr,
1324 struct fiji_single_dpm_table *dpm_table, uint32_t count)
1327 PP_ASSERT_WITH_CODE(count <= MAX_REGULAR_DPM_NUMBER,
1328 "Fatal error, can not set up single DPM table entries "
1329 "to exceed max number!",);
1331 dpm_table->count = count;
1332 for (i = 0; i < MAX_REGULAR_DPM_NUMBER; i++)
1333 dpm_table->dpm_levels[i].enabled = false;
1338 static void fiji_setup_pcie_table_entry(
1339 struct fiji_single_dpm_table *dpm_table,
1340 uint32_t index, uint32_t pcie_gen,
1341 uint32_t pcie_lanes)
1343 dpm_table->dpm_levels[index].value = pcie_gen;
1344 dpm_table->dpm_levels[index].param1 = pcie_lanes;
1345 dpm_table->dpm_levels[index].enabled = 1;
1348 static int fiji_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
1350 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1351 struct phm_ppt_v1_information *table_info =
1352 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1353 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
1354 uint32_t i, max_entry;
1356 PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
1357 data->use_pcie_power_saving_levels), "No pcie performance levels!",
1360 if (data->use_pcie_performance_levels &&
1361 !data->use_pcie_power_saving_levels) {
1362 data->pcie_gen_power_saving = data->pcie_gen_performance;
1363 data->pcie_lane_power_saving = data->pcie_lane_performance;
1364 } else if (!data->use_pcie_performance_levels &&
1365 data->use_pcie_power_saving_levels) {
1366 data->pcie_gen_performance = data->pcie_gen_power_saving;
1367 data->pcie_lane_performance = data->pcie_lane_power_saving;
1370 fiji_reset_single_dpm_table(hwmgr,
1371 &data->dpm_table.pcie_speed_table, SMU73_MAX_LEVELS_LINK);
1373 if (pcie_table != NULL) {
1374 /* max_entry is used to make sure we reserve one PCIE level
1375 * for boot level (fix for A+A PSPP issue).
1376 * If PCIE table from PPTable have ULV entry + 8 entries,
1377 * then ignore the last entry.*/
1378 max_entry = (SMU73_MAX_LEVELS_LINK < pcie_table->count) ?
1379 SMU73_MAX_LEVELS_LINK : pcie_table->count;
1380 for (i = 1; i < max_entry; i++) {
1381 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
1382 get_pcie_gen_support(data->pcie_gen_cap,
1383 pcie_table->entries[i].gen_speed),
1384 get_pcie_lane_support(data->pcie_lane_cap,
1385 pcie_table->entries[i].lane_width));
1387 data->dpm_table.pcie_speed_table.count = max_entry - 1;
1389 /* Hardcode Pcie Table */
1390 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
1391 get_pcie_gen_support(data->pcie_gen_cap,
1393 get_pcie_lane_support(data->pcie_lane_cap,
1395 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
1396 get_pcie_gen_support(data->pcie_gen_cap,
1398 get_pcie_lane_support(data->pcie_lane_cap,
1400 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
1401 get_pcie_gen_support(data->pcie_gen_cap,
1403 get_pcie_lane_support(data->pcie_lane_cap,
1405 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
1406 get_pcie_gen_support(data->pcie_gen_cap,
1408 get_pcie_lane_support(data->pcie_lane_cap,
1410 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
1411 get_pcie_gen_support(data->pcie_gen_cap,
1413 get_pcie_lane_support(data->pcie_lane_cap,
1415 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
1416 get_pcie_gen_support(data->pcie_gen_cap,
1418 get_pcie_lane_support(data->pcie_lane_cap,
1421 data->dpm_table.pcie_speed_table.count = 6;
1423 /* Populate last level for boot PCIE level, but do not increment count. */
1424 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
1425 data->dpm_table.pcie_speed_table.count,
1426 get_pcie_gen_support(data->pcie_gen_cap,
1428 get_pcie_lane_support(data->pcie_lane_cap,
1435 * This function is to initalize all DPM state tables
1436 * for SMU7 based on the dependency table.
1437 * Dynamic state patching function will then trim these
1438 * state tables to the allowed range based
1439 * on the power policy or external client requests,
1440 * such as UVD request, etc.
1442 static int fiji_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
1444 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1445 struct phm_ppt_v1_information *table_info =
1446 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1449 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
1450 table_info->vdd_dep_on_sclk;
1451 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
1452 table_info->vdd_dep_on_mclk;
1454 PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
1455 "SCLK dependency table is missing. This table is mandatory",
1457 PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
1458 "SCLK dependency table has to have is missing. "
1459 "This table is mandatory",
1462 PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
1463 "MCLK dependency table is missing. This table is mandatory",
1465 PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
1466 "MCLK dependency table has to have is missing. "
1467 "This table is mandatory",
1470 /* clear the state table to reset everything to default */
1471 fiji_reset_single_dpm_table(hwmgr,
1472 &data->dpm_table.sclk_table, SMU73_MAX_LEVELS_GRAPHICS);
1473 fiji_reset_single_dpm_table(hwmgr,
1474 &data->dpm_table.mclk_table, SMU73_MAX_LEVELS_MEMORY);
1476 /* Initialize Sclk DPM table based on allow Sclk values */
1477 data->dpm_table.sclk_table.count = 0;
1478 for (i = 0; i < dep_sclk_table->count; i++) {
1479 if (i == 0 || data->dpm_table.sclk_table.dpm_levels
1480 [data->dpm_table.sclk_table.count - 1].value !=
1481 dep_sclk_table->entries[i].clk) {
1482 data->dpm_table.sclk_table.dpm_levels
1483 [data->dpm_table.sclk_table.count].value =
1484 dep_sclk_table->entries[i].clk;
1485 data->dpm_table.sclk_table.dpm_levels
1486 [data->dpm_table.sclk_table.count].enabled =
1487 (i == 0) ? true : false;
1488 data->dpm_table.sclk_table.count++;
1492 /* Initialize Mclk DPM table based on allow Mclk values */
1493 data->dpm_table.mclk_table.count = 0;
1494 for (i=0; i<dep_mclk_table->count; i++) {
1495 if ( i==0 || data->dpm_table.mclk_table.dpm_levels
1496 [data->dpm_table.mclk_table.count - 1].value !=
1497 dep_mclk_table->entries[i].clk) {
1498 data->dpm_table.mclk_table.dpm_levels
1499 [data->dpm_table.mclk_table.count].value =
1500 dep_mclk_table->entries[i].clk;
1501 data->dpm_table.mclk_table.dpm_levels
1502 [data->dpm_table.mclk_table.count].enabled =
1503 (i == 0) ? true : false;
1504 data->dpm_table.mclk_table.count++;
1508 /* setup PCIE gen speed levels */
1509 fiji_setup_default_pcie_table(hwmgr);
1511 /* save a copy of the default DPM table */
1512 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
1513 sizeof(struct fiji_dpm_table));
1519 * @brief PhwFiji_GetVoltageOrder
1520 * Returns index of requested voltage record in lookup(table)
1521 * @param lookup_table - lookup list to search in
1522 * @param voltage - voltage to look for
1523 * @return 0 on success
1525 uint8_t fiji_get_voltage_index(
1526 struct phm_ppt_v1_voltage_lookup_table *lookup_table, uint16_t voltage)
1528 uint8_t count = (uint8_t) (lookup_table->count);
1531 PP_ASSERT_WITH_CODE((NULL != lookup_table),
1532 "Lookup Table empty.", return 0);
1533 PP_ASSERT_WITH_CODE((0 != count),
1534 "Lookup Table empty.", return 0);
1536 for (i = 0; i < lookup_table->count; i++) {
1537 /* find first voltage equal or bigger than requested */
1538 if (lookup_table->entries[i].us_vdd >= voltage)
1541 /* voltage is bigger than max voltage in the table */
1546 * Preparation of vddc and vddgfx CAC tables for SMC.
1548 * @param hwmgr the address of the hardware manager
1549 * @param table the SMC DPM table structure to be populated
1552 static int fiji_populate_cac_table(struct pp_hwmgr *hwmgr,
1553 struct SMU73_Discrete_DpmTable *table)
1558 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1559 struct phm_ppt_v1_information *table_info =
1560 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1561 struct phm_ppt_v1_voltage_lookup_table *lookup_table =
1562 table_info->vddc_lookup_table;
1563 /* tables is already swapped, so in order to use the value from it,
1564 * we need to swap it back.
1565 * We are populating vddc CAC data to BapmVddc table
1566 * in split and merged mode
1568 for( count = 0; count<lookup_table->count; count++) {
1569 index = fiji_get_voltage_index(lookup_table,
1570 data->vddc_voltage_table.entries[count].value);
1571 table->BapmVddcVidLoSidd[count] = (uint8_t) ((6200 -
1572 (lookup_table->entries[index].us_cac_low *
1573 VOLTAGE_SCALE)) / 25);
1574 table->BapmVddcVidHiSidd[count] = (uint8_t) ((6200 -
1575 (lookup_table->entries[index].us_cac_high *
1576 VOLTAGE_SCALE)) / 25);
1583 * Preparation of voltage tables for SMC.
1585 * @param hwmgr the address of the hardware manager
1586 * @param table the SMC DPM table structure to be populated
1590 int fiji_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
1591 struct SMU73_Discrete_DpmTable *table)
1595 result = fiji_populate_cac_table(hwmgr, table);
1596 PP_ASSERT_WITH_CODE(0 == result,
1597 "can not populate CAC voltage tables to SMC",
1603 static int fiji_populate_ulv_level(struct pp_hwmgr *hwmgr,
1604 struct SMU73_Discrete_Ulv *state)
1607 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1608 struct phm_ppt_v1_information *table_info =
1609 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1611 state->CcPwrDynRm = 0;
1612 state->CcPwrDynRm1 = 0;
1614 state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset;
1615 state->VddcOffsetVid = (uint8_t)( table_info->us_ulv_voltage_offset *
1616 VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1 );
1618 state->VddcPhase = (data->vddc_phase_shed_control) ? 0 : 1;
1621 CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm);
1622 CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1);
1623 CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset);
1628 static int fiji_populate_ulv_state(struct pp_hwmgr *hwmgr,
1629 struct SMU73_Discrete_DpmTable *table)
1631 return fiji_populate_ulv_level(hwmgr, &table->Ulv);
1634 static int32_t fiji_get_dpm_level_enable_mask_value(
1635 struct fiji_single_dpm_table* dpm_table)
1640 for (i = dpm_table->count; i > 0; i--) {
1642 if (dpm_table->dpm_levels[i - 1].enabled)
1650 static int fiji_populate_smc_link_level(struct pp_hwmgr *hwmgr,
1651 struct SMU73_Discrete_DpmTable *table)
1653 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1654 struct fiji_dpm_table *dpm_table = &data->dpm_table;
1657 /* Index (dpm_table->pcie_speed_table.count)
1658 * is reserved for PCIE boot level. */
1659 for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
1660 table->LinkLevel[i].PcieGenSpeed =
1661 (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
1662 table->LinkLevel[i].PcieLaneCount = (uint8_t)encode_pcie_lane_width(
1663 dpm_table->pcie_speed_table.dpm_levels[i].param1);
1664 table->LinkLevel[i].EnabledForActivity = 1;
1665 table->LinkLevel[i].SPC = (uint8_t)(data->pcie_spc_cap & 0xff);
1666 table->LinkLevel[i].DownThreshold = PP_HOST_TO_SMC_UL(5);
1667 table->LinkLevel[i].UpThreshold = PP_HOST_TO_SMC_UL(30);
1670 data->smc_state_table.LinkLevelCount =
1671 (uint8_t)dpm_table->pcie_speed_table.count;
1672 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
1673 fiji_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
1679 * Calculates the SCLK dividers using the provided engine clock
1681 * @param hwmgr the address of the hardware manager
1682 * @param clock the engine clock to use to populate the structure
1683 * @param sclk the SMC SCLK structure to be populated
1685 static int fiji_calculate_sclk_params(struct pp_hwmgr *hwmgr,
1686 uint32_t clock, struct SMU73_Discrete_GraphicsLevel *sclk)
1688 const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1689 struct pp_atomctrl_clock_dividers_vi dividers;
1690 uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
1691 uint32_t spll_func_cntl_3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
1692 uint32_t spll_func_cntl_4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
1693 uint32_t cg_spll_spread_spectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
1694 uint32_t cg_spll_spread_spectrum_2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
1696 uint32_t ref_divider;
1700 /* get the engine clock dividers for this clock value */
1701 result = atomctrl_get_engine_pll_dividers_vi(hwmgr, clock, ÷rs);
1703 PP_ASSERT_WITH_CODE(result == 0,
1704 "Error retrieving Engine Clock dividers from VBIOS.",
1707 /* To get FBDIV we need to multiply this by 16384 and divide it by Fref. */
1708 ref_clock = atomctrl_get_reference_clock(hwmgr);
1709 ref_divider = 1 + dividers.uc_pll_ref_div;
1711 /* low 14 bits is fraction and high 12 bits is divider */
1712 fbdiv = dividers.ul_fb_div.ul_fb_divider & 0x3FFFFFF;
1714 /* SPLL_FUNC_CNTL setup */
1715 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
1716 SPLL_REF_DIV, dividers.uc_pll_ref_div);
1717 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
1718 SPLL_PDIV_A, dividers.uc_pll_post_div);
1720 /* SPLL_FUNC_CNTL_3 setup*/
1721 spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3, CG_SPLL_FUNC_CNTL_3,
1722 SPLL_FB_DIV, fbdiv);
1724 /* set to use fractional accumulation*/
1725 spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3, CG_SPLL_FUNC_CNTL_3,
1728 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1729 PHM_PlatformCaps_EngineSpreadSpectrumSupport)) {
1730 struct pp_atomctrl_internal_ss_info ssInfo;
1732 uint32_t vco_freq = clock * dividers.uc_pll_post_div;
1733 if (!atomctrl_get_engine_clock_spread_spectrum(hwmgr,
1734 vco_freq, &ssInfo)) {
1736 * ss_info.speed_spectrum_percentage -- in unit of 0.01%
1737 * ss_info.speed_spectrum_rate -- in unit of khz
1739 * clks = reference_clock * 10 / (REFDIV + 1) / speed_spectrum_rate / 2
1741 uint32_t clk_s = ref_clock * 5 /
1742 (ref_divider * ssInfo.speed_spectrum_rate);
1743 /* clkv = 2 * D * fbdiv / NS */
1744 uint32_t clk_v = 4 * ssInfo.speed_spectrum_percentage *
1745 fbdiv / (clk_s * 10000);
1747 cg_spll_spread_spectrum = PHM_SET_FIELD(cg_spll_spread_spectrum,
1748 CG_SPLL_SPREAD_SPECTRUM, CLKS, clk_s);
1749 cg_spll_spread_spectrum = PHM_SET_FIELD(cg_spll_spread_spectrum,
1750 CG_SPLL_SPREAD_SPECTRUM, SSEN, 1);
1751 cg_spll_spread_spectrum_2 = PHM_SET_FIELD(cg_spll_spread_spectrum_2,
1752 CG_SPLL_SPREAD_SPECTRUM_2, CLKV, clk_v);
1756 sclk->SclkFrequency = clock;
1757 sclk->CgSpllFuncCntl3 = spll_func_cntl_3;
1758 sclk->CgSpllFuncCntl4 = spll_func_cntl_4;
1759 sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum;
1760 sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2;
1761 sclk->SclkDid = (uint8_t)dividers.pll_post_divider;
1766 static uint16_t fiji_find_closest_vddci(struct pp_hwmgr *hwmgr, uint16_t vddci)
1769 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1770 struct pp_atomctrl_voltage_table *vddci_table =
1771 &(data->vddci_voltage_table);
1773 for (i = 0; i < vddci_table->count; i++) {
1774 if (vddci_table->entries[i].value >= vddci)
1775 return vddci_table->entries[i].value;
1778 PP_ASSERT_WITH_CODE(false,
1779 "VDDCI is larger than max VDDCI in VDDCI Voltage Table!",
1780 return vddci_table->entries[i].value);
1783 static int fiji_get_dependency_volt_by_clk(struct pp_hwmgr *hwmgr,
1784 struct phm_ppt_v1_clock_voltage_dependency_table* dep_table,
1785 uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
1789 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1791 *voltage = *mvdd = 0;
1793 /* clock - voltage dependency table is empty table */
1794 if (dep_table->count == 0)
1797 for (i = 0; i < dep_table->count; i++) {
1798 /* find first sclk bigger than request */
1799 if (dep_table->entries[i].clk >= clock) {
1800 *voltage |= (dep_table->entries[i].vddc *
1801 VOLTAGE_SCALE) << VDDC_SHIFT;
1802 if (FIJI_VOLTAGE_CONTROL_NONE == data->vddci_control)
1803 *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1804 VOLTAGE_SCALE) << VDDCI_SHIFT;
1805 else if (dep_table->entries[i].vddci)
1806 *voltage |= (dep_table->entries[i].vddci *
1807 VOLTAGE_SCALE) << VDDCI_SHIFT;
1809 vddci = fiji_find_closest_vddci(hwmgr,
1810 (dep_table->entries[i].vddc -
1811 (uint16_t)data->vddc_vddci_delta));
1812 *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1815 if (FIJI_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1816 *mvdd = data->vbios_boot_state.mvdd_bootup_value *
1818 else if (dep_table->entries[i].mvdd)
1819 *mvdd = (uint32_t) dep_table->entries[i].mvdd *
1822 *voltage |= 1 << PHASES_SHIFT;
1827 /* sclk is bigger than max sclk in the dependence table */
1828 *voltage |= (dep_table->entries[i - 1].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
1830 if (FIJI_VOLTAGE_CONTROL_NONE == data->vddci_control)
1831 *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1832 VOLTAGE_SCALE) << VDDCI_SHIFT;
1833 else if (dep_table->entries[i-1].vddci) {
1834 vddci = fiji_find_closest_vddci(hwmgr,
1835 (dep_table->entries[i].vddc -
1836 (uint16_t)data->vddc_vddci_delta));
1837 *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1840 if (FIJI_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1841 *mvdd = data->vbios_boot_state.mvdd_bootup_value * VOLTAGE_SCALE;
1842 else if (dep_table->entries[i].mvdd)
1843 *mvdd = (uint32_t) dep_table->entries[i - 1].mvdd * VOLTAGE_SCALE;
1848 * Populates single SMC SCLK structure using the provided engine clock
1850 * @param hwmgr the address of the hardware manager
1851 * @param clock the engine clock to use to populate the structure
1852 * @param sclk the SMC SCLK structure to be populated
1855 static int fiji_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
1856 uint32_t clock, uint16_t sclk_al_threshold,
1857 struct SMU73_Discrete_GraphicsLevel *level)
1860 /* PP_Clocks minClocks; */
1861 uint32_t threshold, mvdd;
1862 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1863 struct phm_ppt_v1_information *table_info =
1864 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1866 result = fiji_calculate_sclk_params(hwmgr, clock, level);
1868 /* populate graphics levels */
1869 result = fiji_get_dependency_volt_by_clk(hwmgr,
1870 table_info->vdd_dep_on_sclk, clock,
1871 &level->MinVoltage, &mvdd);
1872 PP_ASSERT_WITH_CODE((0 == result),
1873 "can not find VDDC voltage value for "
1874 "VDDC engine clock dependency table",
1877 level->SclkFrequency = clock;
1878 level->ActivityLevel = sclk_al_threshold;
1879 level->CcPwrDynRm = 0;
1880 level->CcPwrDynRm1 = 0;
1881 level->EnabledForActivity = 0;
1882 level->EnabledForThrottle = 1;
1884 level->DownHyst = 0;
1885 level->VoltageDownHyst = 0;
1886 level->PowerThrottle = 0;
1888 threshold = clock * data->fast_watermark_threshold / 100;
1891 * TODO: get minimum clocks from dal configaration
1892 * PECI_GetMinClockSettings(hwmgr->pPECI, &minClocks);
1894 /* data->DisplayTiming.minClockInSR = minClocks.engineClockInSR; */
1896 /* get level->DeepSleepDivId
1897 if (phm_cap_enabled(hwmgr->platformDescriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
1899 level->DeepSleepDivId = PhwFiji_GetSleepDividerIdFromClock(hwmgr, clock, minClocks.engineClockInSR);
1902 /* Default to slow, highest DPM level will be
1903 * set to PPSMC_DISPLAY_WATERMARK_LOW later.
1905 level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
1907 CONVERT_FROM_HOST_TO_SMC_UL(level->MinVoltage);
1908 CONVERT_FROM_HOST_TO_SMC_UL(level->SclkFrequency);
1909 CONVERT_FROM_HOST_TO_SMC_US(level->ActivityLevel);
1910 CONVERT_FROM_HOST_TO_SMC_UL(level->CgSpllFuncCntl3);
1911 CONVERT_FROM_HOST_TO_SMC_UL(level->CgSpllFuncCntl4);
1912 CONVERT_FROM_HOST_TO_SMC_UL(level->SpllSpreadSpectrum);
1913 CONVERT_FROM_HOST_TO_SMC_UL(level->SpllSpreadSpectrum2);
1914 CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm);
1915 CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm1);
1920 * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
1922 * @param hwmgr the address of the hardware manager
1924 static int fiji_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
1926 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1927 struct fiji_dpm_table *dpm_table = &data->dpm_table;
1928 struct phm_ppt_v1_information *table_info =
1929 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1930 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
1931 uint8_t pcie_entry_cnt = (uint8_t) data->dpm_table.pcie_speed_table.count;
1933 uint32_t array = data->dpm_table_start +
1934 offsetof(SMU73_Discrete_DpmTable, GraphicsLevel);
1935 uint32_t array_size = sizeof(struct SMU73_Discrete_GraphicsLevel) *
1936 SMU73_MAX_LEVELS_GRAPHICS;
1937 struct SMU73_Discrete_GraphicsLevel *levels =
1938 data->smc_state_table.GraphicsLevel;
1939 uint32_t i, max_entry;
1940 uint8_t hightest_pcie_level_enabled = 0,
1941 lowest_pcie_level_enabled = 0,
1942 mid_pcie_level_enabled = 0,
1945 for (i = 0; i < dpm_table->sclk_table.count; i++) {
1946 result = fiji_populate_single_graphic_level(hwmgr,
1947 dpm_table->sclk_table.dpm_levels[i].value,
1948 (uint16_t)data->activity_target[i],
1953 /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
1955 levels[i].DeepSleepDivId = 0;
1958 /* Only enable level 0 for now.*/
1959 levels[0].EnabledForActivity = 1;
1961 /* set highest level watermark to high */
1962 levels[dpm_table->sclk_table.count - 1].DisplayWatermark =
1963 PPSMC_DISPLAY_WATERMARK_HIGH;
1965 data->smc_state_table.GraphicsDpmLevelCount =
1966 (uint8_t)dpm_table->sclk_table.count;
1967 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
1968 fiji_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
1970 if (pcie_table != NULL) {
1971 PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt),
1972 "There must be 1 or more PCIE levels defined in PPTable.",
1974 max_entry = pcie_entry_cnt - 1;
1975 for (i = 0; i < dpm_table->sclk_table.count; i++)
1976 levels[i].pcieDpmLevel =
1977 (uint8_t) ((i < max_entry)? i : max_entry);
1979 while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
1980 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1981 (1 << (hightest_pcie_level_enabled + 1))) != 0 ))
1982 hightest_pcie_level_enabled++;
1984 while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
1985 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1986 (1 << lowest_pcie_level_enabled)) == 0 ))
1987 lowest_pcie_level_enabled++;
1989 while ((count < hightest_pcie_level_enabled) &&
1990 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
1991 (1 << (lowest_pcie_level_enabled + 1 + count))) == 0 ))
1994 mid_pcie_level_enabled = (lowest_pcie_level_enabled + 1+ count) <
1995 hightest_pcie_level_enabled?
1996 (lowest_pcie_level_enabled + 1 + count) :
1997 hightest_pcie_level_enabled;
1999 /* set pcieDpmLevel to hightest_pcie_level_enabled */
2000 for(i = 2; i < dpm_table->sclk_table.count; i++)
2001 levels[i].pcieDpmLevel = hightest_pcie_level_enabled;
2003 /* set pcieDpmLevel to lowest_pcie_level_enabled */
2004 levels[0].pcieDpmLevel = lowest_pcie_level_enabled;
2006 /* set pcieDpmLevel to mid_pcie_level_enabled */
2007 levels[1].pcieDpmLevel = mid_pcie_level_enabled;
2009 /* level count will send to smc once at init smc table and never change */
2010 result = fiji_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
2011 (uint32_t)array_size, data->sram_end);
2017 * MCLK Frequency Ratio
2018 * SEQ_CG_RESP Bit[31:24] - 0x0
2019 * Bit[27:24] \96 DDR3 Frequency ratio
2020 * 0x0 <= 100MHz, 450 < 0x8 <= 500MHz
2021 * 100 < 0x1 <= 150MHz, 500 < 0x9 <= 550MHz
2022 * 150 < 0x2 <= 200MHz, 550 < 0xA <= 600MHz
2023 * 200 < 0x3 <= 250MHz, 600 < 0xB <= 650MHz
2024 * 250 < 0x4 <= 300MHz, 650 < 0xC <= 700MHz
2025 * 300 < 0x5 <= 350MHz, 700 < 0xD <= 750MHz
2026 * 350 < 0x6 <= 400MHz, 750 < 0xE <= 800MHz
2027 * 400 < 0x7 <= 450MHz, 800 < 0xF
2029 static uint8_t fiji_get_mclk_frequency_ratio(uint32_t mem_clock)
2031 if (mem_clock <= 10000) return 0x0;
2032 if (mem_clock <= 15000) return 0x1;
2033 if (mem_clock <= 20000) return 0x2;
2034 if (mem_clock <= 25000) return 0x3;
2035 if (mem_clock <= 30000) return 0x4;
2036 if (mem_clock <= 35000) return 0x5;
2037 if (mem_clock <= 40000) return 0x6;
2038 if (mem_clock <= 45000) return 0x7;
2039 if (mem_clock <= 50000) return 0x8;
2040 if (mem_clock <= 55000) return 0x9;
2041 if (mem_clock <= 60000) return 0xa;
2042 if (mem_clock <= 65000) return 0xb;
2043 if (mem_clock <= 70000) return 0xc;
2044 if (mem_clock <= 75000) return 0xd;
2045 if (mem_clock <= 80000) return 0xe;
2046 /* mem_clock > 800MHz */
2051 * Populates the SMC MCLK structure using the provided memory clock
2053 * @param hwmgr the address of the hardware manager
2054 * @param clock the memory clock to use to populate the structure
2055 * @param sclk the SMC SCLK structure to be populated
2057 static int fiji_calculate_mclk_params(struct pp_hwmgr *hwmgr,
2058 uint32_t clock, struct SMU73_Discrete_MemoryLevel *mclk)
2060 struct pp_atomctrl_memory_clock_param mem_param;
2063 result = atomctrl_get_memory_pll_dividers_vi(hwmgr, clock, &mem_param);
2064 PP_ASSERT_WITH_CODE((0 == result),
2065 "Failed to get Memory PLL Dividers.",);
2067 /* Save the result data to outpupt memory level structure */
2068 mclk->MclkFrequency = clock;
2069 mclk->MclkDivider = (uint8_t)mem_param.mpll_post_divider;
2070 mclk->FreqRange = fiji_get_mclk_frequency_ratio(clock);
2075 static int fiji_populate_single_memory_level(struct pp_hwmgr *hwmgr,
2076 uint32_t clock, struct SMU73_Discrete_MemoryLevel *mem_level)
2078 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2079 struct phm_ppt_v1_information *table_info =
2080 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2083 if (table_info->vdd_dep_on_mclk) {
2084 result = fiji_get_dependency_volt_by_clk(hwmgr,
2085 table_info->vdd_dep_on_mclk, clock,
2086 &mem_level->MinVoltage, &mem_level->MinMvdd);
2087 PP_ASSERT_WITH_CODE((0 == result),
2088 "can not find MinVddc voltage value from memory "
2089 "VDDC voltage dependency table", return result);
2092 mem_level->EnabledForThrottle = 1;
2093 mem_level->EnabledForActivity = 0;
2094 mem_level->UpHyst = 0;
2095 mem_level->DownHyst = 100;
2096 mem_level->VoltageDownHyst = 0;
2097 mem_level->ActivityLevel = (uint16_t)data->mclk_activity_target;
2098 mem_level->StutterEnable = false;
2100 mem_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2102 /* enable stutter mode if all the follow condition applied
2103 * PECI_GetNumberOfActiveDisplays(hwmgr->pPECI,
2104 * &(data->DisplayTiming.numExistingDisplays));
2106 data->display_timing.num_existing_displays = 1;
2108 if ((data->mclk_stutter_mode_threshold) &&
2109 (clock <= data->mclk_stutter_mode_threshold) &&
2110 (!data->is_uvd_enabled) &&
2111 (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL,
2112 STUTTER_ENABLE) & 0x1))
2113 mem_level->StutterEnable = true;
2115 result = fiji_calculate_mclk_params(hwmgr, clock, mem_level);
2117 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinMvdd);
2118 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MclkFrequency);
2119 CONVERT_FROM_HOST_TO_SMC_US(mem_level->ActivityLevel);
2120 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinVoltage);
2126 * Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states
2128 * @param hwmgr the address of the hardware manager
2130 static int fiji_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
2132 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2133 struct fiji_dpm_table *dpm_table = &data->dpm_table;
2135 /* populate MCLK dpm table to SMU7 */
2136 uint32_t array = data->dpm_table_start +
2137 offsetof(SMU73_Discrete_DpmTable, MemoryLevel);
2138 uint32_t array_size = sizeof(SMU73_Discrete_MemoryLevel) *
2139 SMU73_MAX_LEVELS_MEMORY;
2140 struct SMU73_Discrete_MemoryLevel *levels =
2141 data->smc_state_table.MemoryLevel;
2144 for (i = 0; i < dpm_table->mclk_table.count; i++) {
2145 PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
2146 "can not populate memory level as memory clock is zero",
2148 result = fiji_populate_single_memory_level(hwmgr,
2149 dpm_table->mclk_table.dpm_levels[i].value,
2155 /* Only enable level 0 for now. */
2156 levels[0].EnabledForActivity = 1;
2158 /* in order to prevent MC activity from stutter mode to push DPM up.
2159 * the UVD change complements this by putting the MCLK in
2160 * a higher state by default such that we are not effected by
2161 * up threshold or and MCLK DPM latency.
2163 levels[0].ActivityLevel = (uint16_t)data->mclk_dpm0_activity_target;
2164 CONVERT_FROM_HOST_TO_SMC_US(levels[0].ActivityLevel);
2166 data->smc_state_table.MemoryDpmLevelCount =
2167 (uint8_t)dpm_table->mclk_table.count;
2168 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
2169 fiji_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
2170 /* set highest level watermark to high */
2171 levels[dpm_table->mclk_table.count - 1].DisplayWatermark =
2172 PPSMC_DISPLAY_WATERMARK_HIGH;
2174 /* level count will send to smc once at init smc table and never change */
2175 result = fiji_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
2176 (uint32_t)array_size, data->sram_end);
2182 * Populates the SMC MVDD structure using the provided memory clock.
2184 * @param hwmgr the address of the hardware manager
2185 * @param mclk the MCLK value to be used in the decision if MVDD should be high or low.
2186 * @param voltage the SMC VOLTAGE structure to be populated
2188 int fiji_populate_mvdd_value(struct pp_hwmgr *hwmgr,
2189 uint32_t mclk, SMIO_Pattern *smio_pat)
2191 const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2192 struct phm_ppt_v1_information *table_info =
2193 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2196 if (FIJI_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
2197 /* find mvdd value which clock is more than request */
2198 for (i = 0; i < table_info->vdd_dep_on_mclk->count; i++) {
2199 if (mclk <= table_info->vdd_dep_on_mclk->entries[i].clk) {
2200 smio_pat->Voltage = data->mvdd_voltage_table.entries[i].value;
2204 PP_ASSERT_WITH_CODE(i < table_info->vdd_dep_on_mclk->count,
2205 "MVDD Voltage is outside the supported range.",
2213 static int fiji_populate_smc_acpi_level(struct pp_hwmgr *hwmgr,
2214 SMU73_Discrete_DpmTable *table)
2217 const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2218 struct phm_ppt_v1_information *table_info =
2219 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2220 struct pp_atomctrl_clock_dividers_vi dividers;
2221 SMIO_Pattern vol_level;
2224 uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
2225 uint32_t spll_func_cntl_2 = data->clock_registers.vCG_SPLL_FUNC_CNTL_2;
2227 table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
2229 if (!data->sclk_dpm_key_disabled) {
2230 /* Get MinVoltage and Frequency from DPM0,
2231 * already converted to SMC_UL */
2232 table->ACPILevel.SclkFrequency =
2233 data->dpm_table.sclk_table.dpm_levels[0].value;
2234 result = fiji_get_dependency_volt_by_clk(hwmgr,
2235 table_info->vdd_dep_on_sclk,
2236 table->ACPILevel.SclkFrequency,
2237 &table->ACPILevel.MinVoltage, &mvdd);
2238 PP_ASSERT_WITH_CODE((0 == result),
2239 "Cannot find ACPI VDDC voltage value "
2240 "in Clock Dependency Table",);
2242 table->ACPILevel.SclkFrequency =
2243 data->vbios_boot_state.sclk_bootup_value;
2244 table->ACPILevel.MinVoltage =
2245 data->vbios_boot_state.vddc_bootup_value * VOLTAGE_SCALE;
2248 /* get the engine clock dividers for this clock value */
2249 result = atomctrl_get_engine_pll_dividers_vi(hwmgr,
2250 table->ACPILevel.SclkFrequency, ÷rs);
2251 PP_ASSERT_WITH_CODE(result == 0,
2252 "Error retrieving Engine Clock dividers from VBIOS.",
2255 table->ACPILevel.SclkDid = (uint8_t)dividers.pll_post_divider;
2256 table->ACPILevel.DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2257 table->ACPILevel.DeepSleepDivId = 0;
2259 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
2261 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
2263 spll_func_cntl_2 = PHM_SET_FIELD(spll_func_cntl_2, CG_SPLL_FUNC_CNTL_2,
2266 table->ACPILevel.CgSpllFuncCntl = spll_func_cntl;
2267 table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2;
2268 table->ACPILevel.CgSpllFuncCntl3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
2269 table->ACPILevel.CgSpllFuncCntl4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
2270 table->ACPILevel.SpllSpreadSpectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
2271 table->ACPILevel.SpllSpreadSpectrum2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
2272 table->ACPILevel.CcPwrDynRm = 0;
2273 table->ACPILevel.CcPwrDynRm1 = 0;
2275 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
2276 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkFrequency);
2277 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.MinVoltage);
2278 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl);
2279 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl2);
2280 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl3);
2281 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl4);
2282 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum);
2283 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum2);
2284 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
2285 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
2287 if (!data->mclk_dpm_key_disabled) {
2288 /* Get MinVoltage and Frequency from DPM0, already converted to SMC_UL */
2289 table->MemoryACPILevel.MclkFrequency =
2290 data->dpm_table.mclk_table.dpm_levels[0].value;
2291 result = fiji_get_dependency_volt_by_clk(hwmgr,
2292 table_info->vdd_dep_on_mclk,
2293 table->MemoryACPILevel.MclkFrequency,
2294 &table->MemoryACPILevel.MinVoltage, &mvdd);
2295 PP_ASSERT_WITH_CODE((0 == result),
2296 "Cannot find ACPI VDDCI voltage value "
2297 "in Clock Dependency Table",);
2299 table->MemoryACPILevel.MclkFrequency =
2300 data->vbios_boot_state.mclk_bootup_value;
2301 table->MemoryACPILevel.MinVoltage =
2302 data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE;
2306 if ((FIJI_VOLTAGE_CONTROL_NONE == data->mvdd_control) ||
2307 (data->mclk_dpm_key_disabled))
2308 us_mvdd = data->vbios_boot_state.mvdd_bootup_value;
2310 if (!fiji_populate_mvdd_value(hwmgr,
2311 data->dpm_table.mclk_table.dpm_levels[0].value,
2313 us_mvdd = vol_level.Voltage;
2316 table->MemoryACPILevel.MinMvdd =
2317 PP_HOST_TO_SMC_UL(us_mvdd * VOLTAGE_SCALE);
2319 table->MemoryACPILevel.EnabledForThrottle = 0;
2320 table->MemoryACPILevel.EnabledForActivity = 0;
2321 table->MemoryACPILevel.UpHyst = 0;
2322 table->MemoryACPILevel.DownHyst = 100;
2323 table->MemoryACPILevel.VoltageDownHyst = 0;
2324 table->MemoryACPILevel.ActivityLevel =
2325 PP_HOST_TO_SMC_US((uint16_t)data->mclk_activity_target);
2327 table->MemoryACPILevel.StutterEnable = false;
2328 CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MclkFrequency);
2329 CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);
2334 static int fiji_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
2335 SMU73_Discrete_DpmTable *table)
2337 int result = -EINVAL;
2339 struct pp_atomctrl_clock_dividers_vi dividers;
2340 struct phm_ppt_v1_information *table_info =
2341 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2342 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2343 table_info->mm_dep_table;
2344 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2346 table->VceLevelCount = (uint8_t)(mm_table->count);
2347 table->VceBootLevel = 0;
2349 for(count = 0; count < table->VceLevelCount; count++) {
2350 table->VceLevel[count].Frequency = mm_table->entries[count].eclk;
2351 table->VceLevel[count].MinVoltage |=
2352 (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
2353 table->VceLevel[count].MinVoltage |=
2354 ((mm_table->entries[count].vddc - data->vddc_vddci_delta) *
2355 VOLTAGE_SCALE) << VDDCI_SHIFT;
2356 table->VceLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2358 /*retrieve divider value for VBIOS */
2359 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2360 table->VceLevel[count].Frequency, ÷rs);
2361 PP_ASSERT_WITH_CODE((0 == result),
2362 "can not find divide id for VCE engine clock",
2365 table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
2367 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency);
2368 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].MinVoltage);
2373 static int fiji_populate_smc_acp_level(struct pp_hwmgr *hwmgr,
2374 SMU73_Discrete_DpmTable *table)
2376 int result = -EINVAL;
2378 struct pp_atomctrl_clock_dividers_vi dividers;
2379 struct phm_ppt_v1_information *table_info =
2380 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2381 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2382 table_info->mm_dep_table;
2383 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2385 table->AcpLevelCount = (uint8_t)(mm_table->count);
2386 table->AcpBootLevel = 0;
2388 for (count = 0; count < table->AcpLevelCount; count++) {
2389 table->AcpLevel[count].Frequency = mm_table->entries[count].aclk;
2390 table->AcpLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
2391 VOLTAGE_SCALE) << VDDC_SHIFT;
2392 table->AcpLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
2393 data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
2394 table->AcpLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2396 /* retrieve divider value for VBIOS */
2397 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2398 table->AcpLevel[count].Frequency, ÷rs);
2399 PP_ASSERT_WITH_CODE((0 == result),
2400 "can not find divide id for engine clock", return result);
2402 table->AcpLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
2404 CONVERT_FROM_HOST_TO_SMC_UL(table->AcpLevel[count].Frequency);
2405 CONVERT_FROM_HOST_TO_SMC_UL(table->AcpLevel[count].MinVoltage);
2410 static int fiji_populate_smc_samu_level(struct pp_hwmgr *hwmgr,
2411 SMU73_Discrete_DpmTable *table)
2413 int result = -EINVAL;
2415 struct pp_atomctrl_clock_dividers_vi dividers;
2416 struct phm_ppt_v1_information *table_info =
2417 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2418 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2419 table_info->mm_dep_table;
2420 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2422 table->SamuBootLevel = 0;
2423 table->SamuLevelCount = (uint8_t)(mm_table->count);
2425 for (count = 0; count < table->SamuLevelCount; count++) {
2426 /* not sure whether we need evclk or not */
2427 table->SamuLevel[count].Frequency = mm_table->entries[count].samclock;
2428 table->SamuLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
2429 VOLTAGE_SCALE) << VDDC_SHIFT;
2430 table->SamuLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
2431 data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
2432 table->SamuLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2434 /* retrieve divider value for VBIOS */
2435 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2436 table->SamuLevel[count].Frequency, ÷rs);
2437 PP_ASSERT_WITH_CODE((0 == result),
2438 "can not find divide id for samu clock", return result);
2440 table->SamuLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
2442 CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].Frequency);
2443 CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].MinVoltage);
2448 static int fiji_populate_memory_timing_parameters(struct pp_hwmgr *hwmgr,
2449 int32_t eng_clock, int32_t mem_clock,
2450 struct SMU73_Discrete_MCArbDramTimingTableEntry *arb_regs)
2452 uint32_t dram_timing;
2453 uint32_t dram_timing2;
2455 ULONG state, trrds, trrdl;
2458 result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
2459 eng_clock, mem_clock);
2460 PP_ASSERT_WITH_CODE(result == 0,
2461 "Error calling VBIOS to set DRAM_TIMING.", return result);
2463 dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
2464 dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
2465 burstTime = cgs_read_register(hwmgr->device, mmMC_ARB_BURST_TIME);
2467 state = PHM_GET_FIELD(burstTime, MC_ARB_BURST_TIME, STATE0);
2468 trrds = PHM_GET_FIELD(burstTime, MC_ARB_BURST_TIME, TRRDS0);
2469 trrdl = PHM_GET_FIELD(burstTime, MC_ARB_BURST_TIME, TRRDL0);
2471 arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dram_timing);
2472 arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dram_timing2);
2473 arb_regs->McArbBurstTime = (uint8_t)burstTime;
2474 arb_regs->TRRDS = (uint8_t)trrds;
2475 arb_regs->TRRDL = (uint8_t)trrdl;
2480 static int fiji_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
2482 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2483 struct SMU73_Discrete_MCArbDramTimingTable arb_regs;
2487 for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
2488 for (j = 0; j < data->dpm_table.mclk_table.count; j++) {
2489 result = fiji_populate_memory_timing_parameters(hwmgr,
2490 data->dpm_table.sclk_table.dpm_levels[i].value,
2491 data->dpm_table.mclk_table.dpm_levels[j].value,
2492 &arb_regs.entries[i][j]);
2499 result = fiji_copy_bytes_to_smc(
2501 data->arb_table_start,
2502 (uint8_t *)&arb_regs,
2503 sizeof(SMU73_Discrete_MCArbDramTimingTable),
2508 static int fiji_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
2509 struct SMU73_Discrete_DpmTable *table)
2511 int result = -EINVAL;
2513 struct pp_atomctrl_clock_dividers_vi dividers;
2514 struct phm_ppt_v1_information *table_info =
2515 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2516 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2517 table_info->mm_dep_table;
2518 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2520 table->UvdLevelCount = (uint8_t)(mm_table->count);
2521 table->UvdBootLevel = 0;
2523 for (count = 0; count < table->UvdLevelCount; count++) {
2524 table->UvdLevel[count].VclkFrequency = mm_table->entries[count].vclk;
2525 table->UvdLevel[count].DclkFrequency = mm_table->entries[count].dclk;
2526 table->UvdLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
2527 VOLTAGE_SCALE) << VDDC_SHIFT;
2528 table->UvdLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
2529 data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
2530 table->UvdLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2532 /* retrieve divider value for VBIOS */
2533 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2534 table->UvdLevel[count].VclkFrequency, ÷rs);
2535 PP_ASSERT_WITH_CODE((0 == result),
2536 "can not find divide id for Vclk clock", return result);
2538 table->UvdLevel[count].VclkDivider = (uint8_t)dividers.pll_post_divider;
2540 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2541 table->UvdLevel[count].DclkFrequency, ÷rs);
2542 PP_ASSERT_WITH_CODE((0 == result),
2543 "can not find divide id for Dclk clock", return result);
2545 table->UvdLevel[count].DclkDivider = (uint8_t)dividers.pll_post_divider;
2547 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].VclkFrequency);
2548 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].DclkFrequency);
2549 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].MinVoltage);
2555 static int fiji_find_boot_level(struct fiji_single_dpm_table *table,
2556 uint32_t value, uint32_t *boot_level)
2558 int result = -EINVAL;
2561 for (i = 0; i < table->count; i++) {
2562 if (value == table->dpm_levels[i].value) {
2570 static int fiji_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
2571 struct SMU73_Discrete_DpmTable *table)
2574 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2576 table->GraphicsBootLevel = 0;
2577 table->MemoryBootLevel = 0;
2579 /* find boot level from dpm table */
2580 result = fiji_find_boot_level(&(data->dpm_table.sclk_table),
2581 data->vbios_boot_state.sclk_bootup_value,
2582 (uint32_t *)&(table->GraphicsBootLevel));
2584 result = fiji_find_boot_level(&(data->dpm_table.mclk_table),
2585 data->vbios_boot_state.mclk_bootup_value,
2586 (uint32_t *)&(table->MemoryBootLevel));
2588 table->BootVddc = data->vbios_boot_state.vddc_bootup_value *
2590 table->BootVddci = data->vbios_boot_state.vddci_bootup_value *
2592 table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value *
2595 CONVERT_FROM_HOST_TO_SMC_US(table->BootVddc);
2596 CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci);
2597 CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
2602 static int fiji_populate_smc_initailial_state(struct pp_hwmgr *hwmgr)
2604 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2605 struct phm_ppt_v1_information *table_info =
2606 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2607 uint8_t count, level;
2609 count = (uint8_t)(table_info->vdd_dep_on_sclk->count);
2610 for (level = 0; level < count; level++) {
2611 if(table_info->vdd_dep_on_sclk->entries[level].clk >=
2612 data->vbios_boot_state.sclk_bootup_value) {
2613 data->smc_state_table.GraphicsBootLevel = level;
2618 count = (uint8_t)(table_info->vdd_dep_on_mclk->count);
2619 for (level = 0; level < count; level++) {
2620 if(table_info->vdd_dep_on_mclk->entries[level].clk >=
2621 data->vbios_boot_state.mclk_bootup_value) {
2622 data->smc_state_table.MemoryBootLevel = level;
2630 static int fiji_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr)
2632 uint32_t ro, efuse, efuse2, clock_freq, volt_without_cks,
2633 volt_with_cks, value;
2634 uint16_t clock_freq_u16;
2635 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2636 uint8_t type, i, j, cks_setting, stretch_amount, stretch_amount2,
2638 struct phm_ppt_v1_information *table_info =
2639 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2640 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
2641 table_info->vdd_dep_on_sclk;
2643 stretch_amount = (uint8_t)table_info->cac_dtp_table->usClockStretchAmount;
2645 /* Read SMU_Eefuse to read and calculate RO and determine
2646 * if the part is SS or FF. if RO >= 1660MHz, part is FF.
2648 efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2649 ixSMU_EFUSE_0 + (146 * 4));
2650 efuse2 = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2651 ixSMU_EFUSE_0 + (148 * 4));
2652 efuse &= 0xFF000000;
2653 efuse = efuse >> 24;
2657 ro = (2300 - 1350) * efuse / 255 + 1350;
2659 ro = (2500 - 1000) * efuse / 255 + 1000;
2666 /* Populate Stretch amount */
2667 data->smc_state_table.ClockStretcherAmount = stretch_amount;
2669 /* Populate Sclk_CKS_masterEn0_7 and Sclk_voltageOffset */
2670 for (i = 0; i < sclk_table->count; i++) {
2671 data->smc_state_table.Sclk_CKS_masterEn0_7 |=
2672 sclk_table->entries[i].cks_enable << i;
2673 volt_without_cks = (uint32_t)((14041 *
2674 (sclk_table->entries[i].clk/100) / 10000 + 3571 + 75 - ro) * 1000 /
2675 (4026 - (13924 * (sclk_table->entries[i].clk/100) / 10000)));
2676 volt_with_cks = (uint32_t)((13946 *
2677 (sclk_table->entries[i].clk/100) / 10000 + 3320 + 45 - ro) * 1000 /
2678 (3664 - (11454 * (sclk_table->entries[i].clk/100) / 10000)));
2679 if (volt_without_cks >= volt_with_cks)
2680 volt_offset = (uint8_t)(((volt_without_cks - volt_with_cks +
2681 sclk_table->entries[i].cks_voffset) * 100 / 625) + 1);
2682 data->smc_state_table.Sclk_voltageOffset[i] = volt_offset;
2685 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2686 STRETCH_ENABLE, 0x0);
2687 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2689 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2691 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2694 /* Populate CKS Lookup Table */
2695 if (stretch_amount == 1 || stretch_amount == 2 || stretch_amount == 5)
2696 stretch_amount2 = 0;
2697 else if (stretch_amount == 3 || stretch_amount == 4)
2698 stretch_amount2 = 1;
2700 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2701 PHM_PlatformCaps_ClockStretcher);
2702 PP_ASSERT_WITH_CODE(false,
2703 "Stretch Amount in PPTable not supported\n",
2707 value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2709 value &= 0xFFC2FF87;
2710 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].minFreq =
2711 fiji_clock_stretcher_lookup_table[stretch_amount2][0];
2712 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].maxFreq =
2713 fiji_clock_stretcher_lookup_table[stretch_amount2][1];
2714 clock_freq_u16 = (uint16_t)(PP_SMC_TO_HOST_UL(data->smc_state_table.
2715 GraphicsLevel[data->smc_state_table.GraphicsDpmLevelCount - 1].
2716 SclkFrequency) / 100);
2717 if (fiji_clock_stretcher_lookup_table[stretch_amount2][0] <
2719 fiji_clock_stretcher_lookup_table[stretch_amount2][1] >
2721 /* Program PWR_CKS_CNTL. CKS_USE_FOR_LOW_FREQ */
2722 value |= (fiji_clock_stretcher_lookup_table[stretch_amount2][3]) << 16;
2723 /* Program PWR_CKS_CNTL. CKS_LDO_REFSEL */
2724 value |= (fiji_clock_stretcher_lookup_table[stretch_amount2][2]) << 18;
2725 /* Program PWR_CKS_CNTL. CKS_STRETCH_AMOUNT */
2726 value |= (fiji_clock_stretch_amount_conversion
2727 [fiji_clock_stretcher_lookup_table[stretch_amount2][3]]
2728 [stretch_amount]) << 3;
2730 CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.CKS_LOOKUPTable.
2731 CKS_LOOKUPTableEntry[0].minFreq);
2732 CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.CKS_LOOKUPTable.
2733 CKS_LOOKUPTableEntry[0].maxFreq);
2734 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting =
2735 fiji_clock_stretcher_lookup_table[stretch_amount2][2] & 0x7F;
2736 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting |=
2737 (fiji_clock_stretcher_lookup_table[stretch_amount2][3]) << 7;
2739 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2740 ixPWR_CKS_CNTL, value);
2742 /* Populate DDT Lookup Table */
2743 for (i = 0; i < 4; i++) {
2744 /* Assign the minimum and maximum VID stored
2745 * in the last row of Clock Stretcher Voltage Table.
2747 data->smc_state_table.ClockStretcherDataTable.
2748 ClockStretcherDataTableEntry[i].minVID =
2749 (uint8_t) fiji_clock_stretcher_ddt_table[type][i][2];
2750 data->smc_state_table.ClockStretcherDataTable.
2751 ClockStretcherDataTableEntry[i].maxVID =
2752 (uint8_t) fiji_clock_stretcher_ddt_table[type][i][3];
2753 /* Loop through each SCLK and check the frequency
2754 * to see if it lies within the frequency for clock stretcher.
2756 for (j = 0; j < data->smc_state_table.GraphicsDpmLevelCount; j++) {
2758 clock_freq = PP_SMC_TO_HOST_UL(
2759 data->smc_state_table.GraphicsLevel[j].SclkFrequency);
2760 /* Check the allowed frequency against the sclk level[j].
2761 * Sclk's endianness has already been converted,
2762 * and it's in 10Khz unit,
2763 * as opposed to Data table, which is in Mhz unit.
2766 (fiji_clock_stretcher_ddt_table[type][i][0]) * 100) {
2769 (fiji_clock_stretcher_ddt_table[type][i][1]) * 100)
2772 data->smc_state_table.ClockStretcherDataTable.
2773 ClockStretcherDataTableEntry[i].setting |= cks_setting << (j * 2);
2775 CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.
2776 ClockStretcherDataTable.
2777 ClockStretcherDataTableEntry[i].setting);
2780 value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL);
2781 value &= 0xFFFFFFFE;
2782 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL, value);
2788 * Populates the SMC VRConfig field in DPM table.
2790 * @param hwmgr the address of the hardware manager
2791 * @param table the SMC DPM table structure to be populated
2794 static int fiji_populate_vr_config(struct pp_hwmgr *hwmgr,
2795 struct SMU73_Discrete_DpmTable *table)
2797 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2800 config = VR_MERGED_WITH_VDDC;
2801 table->VRConfig |= (config << VRCONF_VDDGFX_SHIFT);
2803 /* Set Vddc Voltage Controller */
2804 if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
2805 config = VR_SVI2_PLANE_1;
2806 table->VRConfig |= config;
2808 PP_ASSERT_WITH_CODE(false,
2809 "VDDC should be on SVI2 control in merged mode!",);
2811 /* Set Vddci Voltage Controller */
2812 if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
2813 config = VR_SVI2_PLANE_2; /* only in merged mode */
2814 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
2815 } else if (FIJI_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
2816 config = VR_SMIO_PATTERN_1;
2817 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
2819 config = VR_STATIC_VOLTAGE;
2820 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
2822 /* Set Mvdd Voltage Controller */
2823 if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
2824 config = VR_SVI2_PLANE_2;
2825 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
2826 } else if(FIJI_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
2827 config = VR_SMIO_PATTERN_2;
2828 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
2830 config = VR_STATIC_VOLTAGE;
2831 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
2838 * Initializes the SMC table and uploads it
2840 * @param hwmgr the address of the powerplay hardware manager.
2841 * @param pInput the pointer to input data (PowerState)
2844 static int fiji_init_smc_table(struct pp_hwmgr *hwmgr)
2847 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2848 struct phm_ppt_v1_information *table_info =
2849 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2850 struct SMU73_Discrete_DpmTable *table = &(data->smc_state_table);
2851 const struct fiji_ulv_parm *ulv = &(data->ulv);
2853 struct pp_atomctrl_gpio_pin_assignment gpio_pin;
2855 result = fiji_setup_default_dpm_tables(hwmgr);
2856 PP_ASSERT_WITH_CODE(0 == result,
2857 "Failed to setup default DPM tables!", return result);
2859 if(FIJI_VOLTAGE_CONTROL_NONE != data->voltage_control)
2860 fiji_populate_smc_voltage_tables(hwmgr, table);
2862 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2863 PHM_PlatformCaps_AutomaticDCTransition))
2864 table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
2866 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2867 PHM_PlatformCaps_StepVddc))
2868 table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
2870 if (data->is_memory_gddr5)
2871 table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
2873 if (ulv->ulv_supported && table_info->us_ulv_voltage_offset) {
2874 result = fiji_populate_ulv_state(hwmgr, table);
2875 PP_ASSERT_WITH_CODE(0 == result,
2876 "Failed to initialize ULV state!", return result);
2877 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2878 ixCG_ULV_PARAMETER, ulv->cg_ulv_parameter);
2881 result = fiji_populate_smc_link_level(hwmgr, table);
2882 PP_ASSERT_WITH_CODE(0 == result,
2883 "Failed to initialize Link Level!", return result);
2885 result = fiji_populate_all_graphic_levels(hwmgr);
2886 PP_ASSERT_WITH_CODE(0 == result,
2887 "Failed to initialize Graphics Level!", return result);
2889 result = fiji_populate_all_memory_levels(hwmgr);
2890 PP_ASSERT_WITH_CODE(0 == result,
2891 "Failed to initialize Memory Level!", return result);
2893 result = fiji_populate_smc_acpi_level(hwmgr, table);
2894 PP_ASSERT_WITH_CODE(0 == result,
2895 "Failed to initialize ACPI Level!", return result);
2897 result = fiji_populate_smc_vce_level(hwmgr, table);
2898 PP_ASSERT_WITH_CODE(0 == result,
2899 "Failed to initialize VCE Level!", return result);
2901 result = fiji_populate_smc_acp_level(hwmgr, table);
2902 PP_ASSERT_WITH_CODE(0 == result,
2903 "Failed to initialize ACP Level!", return result);
2905 result = fiji_populate_smc_samu_level(hwmgr, table);
2906 PP_ASSERT_WITH_CODE(0 == result,
2907 "Failed to initialize SAMU Level!", return result);
2909 /* Since only the initial state is completely set up at this point
2910 * (the other states are just copies of the boot state) we only
2911 * need to populate the ARB settings for the initial state.
2913 result = fiji_program_memory_timing_parameters(hwmgr);
2914 PP_ASSERT_WITH_CODE(0 == result,
2915 "Failed to Write ARB settings for the initial state.", return result);
2917 result = fiji_populate_smc_uvd_level(hwmgr, table);
2918 PP_ASSERT_WITH_CODE(0 == result,
2919 "Failed to initialize UVD Level!", return result);
2921 result = fiji_populate_smc_boot_level(hwmgr, table);
2922 PP_ASSERT_WITH_CODE(0 == result,
2923 "Failed to initialize Boot Level!", return result);
2925 result = fiji_populate_smc_initailial_state(hwmgr);
2926 PP_ASSERT_WITH_CODE(0 == result,
2927 "Failed to initialize Boot State!", return result);
2929 result = fiji_populate_bapm_parameters_in_dpm_table(hwmgr);
2930 PP_ASSERT_WITH_CODE(0 == result,
2931 "Failed to populate BAPM Parameters!", return result);
2933 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2934 PHM_PlatformCaps_ClockStretcher)) {
2935 result = fiji_populate_clock_stretcher_data_table(hwmgr);
2936 PP_ASSERT_WITH_CODE(0 == result,
2937 "Failed to populate Clock Stretcher Data Table!",
2941 table->GraphicsVoltageChangeEnable = 1;
2942 table->GraphicsThermThrottleEnable = 1;
2943 table->GraphicsInterval = 1;
2944 table->VoltageInterval = 1;
2945 table->ThermalInterval = 1;
2946 table->TemperatureLimitHigh =
2947 table_info->cac_dtp_table->usTargetOperatingTemp *
2948 FIJI_Q88_FORMAT_CONVERSION_UNIT;
2949 table->TemperatureLimitLow =
2950 (table_info->cac_dtp_table->usTargetOperatingTemp - 1) *
2951 FIJI_Q88_FORMAT_CONVERSION_UNIT;
2952 table->MemoryVoltageChangeEnable = 1;
2953 table->MemoryInterval = 1;
2954 table->VoltageResponseTime = 0;
2955 table->PhaseResponseTime = 0;
2956 table->MemoryThermThrottleEnable = 1;
2957 table->PCIeBootLinkLevel = 0; /* 0:Gen1 1:Gen2 2:Gen3*/
2958 table->PCIeGenInterval = 1;
2960 result = fiji_populate_vr_config(hwmgr, table);
2961 PP_ASSERT_WITH_CODE(0 == result,
2962 "Failed to populate VRConfig setting!", return result);
2964 table->ThermGpio = 17;
2965 table->SclkStepSize = 0x4000;
2967 if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_VRHOT_GPIO_PINID, &gpio_pin)) {
2968 table->VRHotGpio = gpio_pin.uc_gpio_pin_bit_shift;
2969 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2970 PHM_PlatformCaps_RegulatorHot);
2972 table->VRHotGpio = FIJI_UNUSED_GPIO_PIN;
2973 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2974 PHM_PlatformCaps_RegulatorHot);
2977 if (atomctrl_get_pp_assign_pin(hwmgr, PP_AC_DC_SWITCH_GPIO_PINID,
2979 table->AcDcGpio = gpio_pin.uc_gpio_pin_bit_shift;
2980 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2981 PHM_PlatformCaps_AutomaticDCTransition);
2983 table->AcDcGpio = FIJI_UNUSED_GPIO_PIN;
2984 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2985 PHM_PlatformCaps_AutomaticDCTransition);
2988 /* Thermal Output GPIO */
2989 if (atomctrl_get_pp_assign_pin(hwmgr, THERMAL_INT_OUTPUT_GPIO_PINID,
2991 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2992 PHM_PlatformCaps_ThermalOutGPIO);
2994 table->ThermOutGpio = gpio_pin.uc_gpio_pin_bit_shift;
2996 /* For porlarity read GPIOPAD_A with assigned Gpio pin
2997 * since VBIOS will program this register to set 'inactive state',
2998 * driver can then determine 'active state' from this and
2999 * program SMU with correct polarity
3001 table->ThermOutPolarity = (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A) &
3002 (1 << gpio_pin.uc_gpio_pin_bit_shift))) ? 1:0;
3003 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY;
3005 /* if required, combine VRHot/PCC with thermal out GPIO */
3006 if(phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3007 PHM_PlatformCaps_RegulatorHot) &&
3008 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3009 PHM_PlatformCaps_CombinePCCWithThermalSignal))
3010 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT;
3012 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3013 PHM_PlatformCaps_ThermalOutGPIO);
3014 table->ThermOutGpio = 17;
3015 table->ThermOutPolarity = 1;
3016 table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE;
3019 for (i = 0; i < SMU73_MAX_ENTRIES_SMIO; i++)
3020 table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]);
3022 CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
3023 CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig);
3024 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1);
3025 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2);
3026 CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
3027 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
3028 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
3029 CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
3030 CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
3032 /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
3033 result = fiji_copy_bytes_to_smc(hwmgr->smumgr,
3034 data->dpm_table_start +
3035 offsetof(SMU73_Discrete_DpmTable, SystemFlags),
3036 (uint8_t *)&(table->SystemFlags),
3037 sizeof(SMU73_Discrete_DpmTable) - 3 * sizeof(SMU73_PIDController),
3039 PP_ASSERT_WITH_CODE(0 == result,
3040 "Failed to upload dpm data to SMC memory!", return result);
3046 * Initialize the ARB DRAM timing table's index field.
3048 * @param hwmgr the address of the powerplay hardware manager.
3051 static int fiji_init_arb_table_index(struct pp_hwmgr *hwmgr)
3053 const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3057 /* This is a read-modify-write on the first byte of the ARB table.
3058 * The first byte in the SMU73_Discrete_MCArbDramTimingTable structure
3059 * is the field 'current'.
3060 * This solution is ugly, but we never write the whole table only
3061 * individual fields in it.
3062 * In reality this field should not be in that structure
3063 * but in a soft register.
3065 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
3066 data->arb_table_start, &tmp, data->sram_end);
3072 tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24;
3074 return fiji_write_smc_sram_dword(hwmgr->smumgr,
3075 data->arb_table_start, tmp, data->sram_end);
3078 static int fiji_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr)
3080 if(phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3081 PHM_PlatformCaps_RegulatorHot))
3082 return smum_send_msg_to_smc(hwmgr->smumgr,
3083 PPSMC_MSG_EnableVRHotGPIOInterrupt);
3088 static int fiji_enable_sclk_control(struct pp_hwmgr *hwmgr)
3090 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
3091 SCLK_PWRMGT_OFF, 0);
3095 static int fiji_enable_ulv(struct pp_hwmgr *hwmgr)
3097 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3098 struct fiji_ulv_parm *ulv = &(data->ulv);
3100 if (ulv->ulv_supported)
3101 return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_EnableULV);
3106 static int fiji_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
3108 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3109 PHM_PlatformCaps_SclkDeepSleep)) {
3110 if (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MASTER_DeepSleep_ON))
3111 PP_ASSERT_WITH_CODE(false,
3112 "Attempt to enable Master Deep Sleep switch failed!",
3115 if (smum_send_msg_to_smc(hwmgr->smumgr,
3116 PPSMC_MSG_MASTER_DeepSleep_OFF)) {
3117 PP_ASSERT_WITH_CODE(false,
3118 "Attempt to disable Master Deep Sleep switch failed!",
3126 static int fiji_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
3128 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3129 uint32_t val, val0, val2;
3130 uint32_t i, cpl_cntl, cpl_threshold, mc_threshold;
3132 /* enable SCLK dpm */
3133 if(!data->sclk_dpm_key_disabled)
3134 PP_ASSERT_WITH_CODE(
3135 (0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Enable)),
3136 "Failed to enable SCLK DPM during DPM Start Function!",
3139 /* enable MCLK dpm */
3140 if(0 == data->mclk_dpm_key_disabled) {
3144 /* Read per MCD tile (0 - 7) */
3145 for (i = 0; i < 8; i++) {
3146 PHM_WRITE_FIELD(hwmgr->device, MC_CONFIG_MCD, MC_RD_ENABLE, i);
3147 val = cgs_read_register(hwmgr->device, mmMC_SEQ_RESERVE_0_S) & 0xf0000000;
3148 if (0xf0000000 != val) {
3149 /* count number of MCQ that has channel(s) enabled */
3151 /* only harvest 3 or full 4 supported */
3152 mc_threshold = val ? 3 : 4;
3155 PP_ASSERT_WITH_CODE(0 != cpl_threshold,
3156 "Number of MCQ is zero!", return -EINVAL;);
3158 mc_threshold = ((mc_threshold & LCAC_MC0_CNTL__MC0_THRESHOLD_MASK) <<
3159 LCAC_MC0_CNTL__MC0_THRESHOLD__SHIFT) |
3160 LCAC_MC0_CNTL__MC0_ENABLE_MASK;
3161 cpl_cntl = ((cpl_threshold & LCAC_CPL_CNTL__CPL_THRESHOLD_MASK) <<
3162 LCAC_CPL_CNTL__CPL_THRESHOLD__SHIFT) |
3163 LCAC_CPL_CNTL__CPL_ENABLE_MASK;
3164 cpl_cntl = (cpl_cntl | (8 << LCAC_CPL_CNTL__CPL_BLOCK_ID__SHIFT));
3165 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3166 ixLCAC_MC0_CNTL, mc_threshold);
3167 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3168 ixLCAC_MC1_CNTL, mc_threshold);
3169 if (8 == cpl_threshold) {
3170 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3171 ixLCAC_MC2_CNTL, mc_threshold);
3172 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3173 ixLCAC_MC3_CNTL, mc_threshold);
3174 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3175 ixLCAC_MC4_CNTL, mc_threshold);
3176 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3177 ixLCAC_MC5_CNTL, mc_threshold);
3178 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3179 ixLCAC_MC6_CNTL, mc_threshold);
3180 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3181 ixLCAC_MC7_CNTL, mc_threshold);
3183 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3184 ixLCAC_CPL_CNTL, cpl_cntl);
3188 mc_threshold = mc_threshold |
3189 (1 << LCAC_MC0_CNTL__MC0_SIGNAL_ID__SHIFT);
3190 cpl_cntl = cpl_cntl | (1 << LCAC_CPL_CNTL__CPL_SIGNAL_ID__SHIFT);
3191 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3192 ixLCAC_MC0_CNTL, mc_threshold);
3193 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3194 ixLCAC_MC1_CNTL, mc_threshold);
3195 if (8 == cpl_threshold) {
3196 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3197 ixLCAC_MC2_CNTL, mc_threshold);
3198 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3199 ixLCAC_MC3_CNTL, mc_threshold);
3200 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3201 ixLCAC_MC4_CNTL, mc_threshold);
3202 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3203 ixLCAC_MC5_CNTL, mc_threshold);
3204 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3205 ixLCAC_MC6_CNTL, mc_threshold);
3206 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3207 ixLCAC_MC7_CNTL, mc_threshold);
3209 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3210 ixLCAC_CPL_CNTL, cpl_cntl);
3212 /* Program CAC_EN per MCD (0-7) Tile */
3213 val0 = val = cgs_read_register(hwmgr->device, mmMC_CONFIG_MCD);
3214 val &= ~(MC_CONFIG_MCD__MCD0_WR_ENABLE_MASK |
3215 MC_CONFIG_MCD__MCD1_WR_ENABLE_MASK |
3216 MC_CONFIG_MCD__MCD2_WR_ENABLE_MASK |
3217 MC_CONFIG_MCD__MCD3_WR_ENABLE_MASK |
3218 MC_CONFIG_MCD__MCD4_WR_ENABLE_MASK |
3219 MC_CONFIG_MCD__MCD5_WR_ENABLE_MASK |
3220 MC_CONFIG_MCD__MCD6_WR_ENABLE_MASK |
3221 MC_CONFIG_MCD__MCD7_WR_ENABLE_MASK |
3222 MC_CONFIG_MCD__MC_RD_ENABLE_MASK);
3224 for (i = 0; i < 8; i++) {
3225 /* Enable MCD i Tile read & write */
3226 val2 = (val | (i << MC_CONFIG_MCD__MC_RD_ENABLE__SHIFT) |
3228 cgs_write_register(hwmgr->device, mmMC_CONFIG_MCD, val2);
3229 /* Enbale CAC_ON MCD i Tile */
3230 val2 = cgs_read_register(hwmgr->device, mmMC_SEQ_CNTL);
3231 val2 |= MC_SEQ_CNTL__CAC_EN_MASK;
3232 cgs_write_register(hwmgr->device, mmMC_SEQ_CNTL, val2);
3234 /* Set MC_CONFIG_MCD back to its default setting val0 */
3235 cgs_write_register(hwmgr->device, mmMC_CONFIG_MCD, val0);
3237 PP_ASSERT_WITH_CODE(
3238 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
3239 PPSMC_MSG_MCLKDPM_Enable)),
3240 "Failed to enable MCLK DPM during DPM Start Function!",
3246 static int fiji_start_dpm(struct pp_hwmgr *hwmgr)
3248 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3250 /*enable general power management */
3251 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3252 GLOBAL_PWRMGT_EN, 1);
3253 /* enable sclk deep sleep */
3254 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
3256 /* prepare for PCIE DPM */
3257 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3258 data->soft_regs_start + offsetof(SMU73_SoftRegisters,
3259 VoltageChangeTimeout), 0x1000);
3260 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
3261 SWRST_COMMAND_1, RESETLC, 0x0);
3263 PP_ASSERT_WITH_CODE(
3264 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
3265 PPSMC_MSG_Voltage_Cntl_Enable)),
3266 "Failed to enable voltage DPM during DPM Start Function!",
3269 if (fiji_enable_sclk_mclk_dpm(hwmgr)) {
3270 printk(KERN_ERR "Failed to enable Sclk DPM and Mclk DPM!");
3274 /* enable PCIE dpm */
3275 if(!data->pcie_dpm_key_disabled) {
3276 PP_ASSERT_WITH_CODE(
3277 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
3278 PPSMC_MSG_PCIeDPM_Enable)),
3279 "Failed to enable pcie DPM during DPM Start Function!",
3286 static void fiji_set_dpm_event_sources(struct pp_hwmgr *hwmgr,
3290 enum DPM_EVENT_SRC src;
3294 printk(KERN_ERR "Unknown throttling event sources.");
3300 case (1 << PHM_AutoThrottleSource_Thermal):
3302 src = DPM_EVENT_SRC_DIGITAL;
3304 case (1 << PHM_AutoThrottleSource_External):
3306 src = DPM_EVENT_SRC_EXTERNAL;
3308 case (1 << PHM_AutoThrottleSource_External) |
3309 (1 << PHM_AutoThrottleSource_Thermal):
3311 src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
3314 /* Order matters - don't enable thermal protection for the wrong source. */
3316 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
3317 DPM_EVENT_SRC, src);
3318 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3319 THERMAL_PROTECTION_DIS,
3320 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3321 PHM_PlatformCaps_ThermalController));
3323 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3324 THERMAL_PROTECTION_DIS, 1);
3327 static int fiji_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
3328 PHM_AutoThrottleSource source)
3330 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3332 if (!(data->active_auto_throttle_sources & (1 << source))) {
3333 data->active_auto_throttle_sources |= 1 << source;
3334 fiji_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
3339 static int fiji_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
3341 return fiji_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
3344 static int fiji_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
3346 int tmp_result, result = 0;
3348 tmp_result = (!fiji_is_dpm_running(hwmgr))? 0 : -1;
3349 PP_ASSERT_WITH_CODE(result == 0,
3350 "DPM is already running right now, no need to enable DPM!",
3353 if (fiji_voltage_control(hwmgr)) {
3354 tmp_result = fiji_enable_voltage_control(hwmgr);
3355 PP_ASSERT_WITH_CODE(tmp_result == 0,
3356 "Failed to enable voltage control!",
3357 result = tmp_result);
3360 if (fiji_voltage_control(hwmgr)) {
3361 tmp_result = fiji_construct_voltage_tables(hwmgr);
3362 PP_ASSERT_WITH_CODE((0 == tmp_result),
3363 "Failed to contruct voltage tables!",
3364 result = tmp_result);
3367 tmp_result = fiji_initialize_mc_reg_table(hwmgr);
3368 PP_ASSERT_WITH_CODE((0 == tmp_result),
3369 "Failed to initialize MC reg table!", result = tmp_result);
3371 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3372 PHM_PlatformCaps_EngineSpreadSpectrumSupport))
3373 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3374 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1);
3376 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3377 PHM_PlatformCaps_ThermalController))
3378 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3379 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0);
3381 tmp_result = fiji_program_static_screen_threshold_parameters(hwmgr);
3382 PP_ASSERT_WITH_CODE((0 == tmp_result),
3383 "Failed to program static screen threshold parameters!",
3384 result = tmp_result);
3386 tmp_result = fiji_enable_display_gap(hwmgr);
3387 PP_ASSERT_WITH_CODE((0 == tmp_result),
3388 "Failed to enable display gap!", result = tmp_result);
3390 tmp_result = fiji_program_voting_clients(hwmgr);
3391 PP_ASSERT_WITH_CODE((0 == tmp_result),
3392 "Failed to program voting clients!", result = tmp_result);
3394 tmp_result = fiji_process_firmware_header(hwmgr);
3395 PP_ASSERT_WITH_CODE((0 == tmp_result),
3396 "Failed to process firmware header!", result = tmp_result);
3398 tmp_result = fiji_initial_switch_from_arbf0_to_f1(hwmgr);
3399 PP_ASSERT_WITH_CODE((0 == tmp_result),
3400 "Failed to initialize switch from ArbF0 to F1!",
3401 result = tmp_result);
3403 tmp_result = fiji_init_smc_table(hwmgr);
3404 PP_ASSERT_WITH_CODE((0 == tmp_result),
3405 "Failed to initialize SMC table!", result = tmp_result);
3407 tmp_result = fiji_init_arb_table_index(hwmgr);
3408 PP_ASSERT_WITH_CODE((0 == tmp_result),
3409 "Failed to initialize ARB table index!", result = tmp_result);
3411 tmp_result = fiji_populate_pm_fuses(hwmgr);
3412 PP_ASSERT_WITH_CODE((0 == tmp_result),
3413 "Failed to populate PM fuses!", result = tmp_result);
3415 tmp_result = fiji_enable_vrhot_gpio_interrupt(hwmgr);
3416 PP_ASSERT_WITH_CODE((0 == tmp_result),
3417 "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
3419 tmp_result = fiji_enable_sclk_control(hwmgr);
3420 PP_ASSERT_WITH_CODE((0 == tmp_result),
3421 "Failed to enable SCLK control!", result = tmp_result);
3423 tmp_result = fiji_enable_ulv(hwmgr);
3424 PP_ASSERT_WITH_CODE((0 == tmp_result),
3425 "Failed to enable ULV!", result = tmp_result);
3427 tmp_result = fiji_enable_deep_sleep_master_switch(hwmgr);
3428 PP_ASSERT_WITH_CODE((0 == tmp_result),
3429 "Failed to enable deep sleep master switch!", result = tmp_result);
3431 tmp_result = fiji_start_dpm(hwmgr);
3432 PP_ASSERT_WITH_CODE((0 == tmp_result),
3433 "Failed to start DPM!", result = tmp_result);
3435 tmp_result = fiji_enable_smc_cac(hwmgr);
3436 PP_ASSERT_WITH_CODE((0 == tmp_result),
3437 "Failed to enable SMC CAC!", result = tmp_result);
3439 tmp_result = fiji_enable_power_containment(hwmgr);
3440 PP_ASSERT_WITH_CODE((0 == tmp_result),
3441 "Failed to enable power containment!", result = tmp_result);
3443 tmp_result = fiji_power_control_set_level(hwmgr);
3444 PP_ASSERT_WITH_CODE((0 == tmp_result),
3445 "Failed to power control set level!", result = tmp_result);
3447 tmp_result = fiji_enable_thermal_auto_throttle(hwmgr);
3448 PP_ASSERT_WITH_CODE((0 == tmp_result),
3449 "Failed to enable thermal auto throttle!", result = tmp_result);
3454 static int fiji_force_dpm_highest(struct pp_hwmgr *hwmgr)
3456 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3457 uint32_t level, tmp;
3459 if (!data->sclk_dpm_key_disabled) {
3460 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3462 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
3466 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3467 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3472 if (!data->mclk_dpm_key_disabled) {
3473 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3475 tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
3479 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3480 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3485 if (!data->pcie_dpm_key_disabled) {
3486 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3488 tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
3492 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3493 PPSMC_MSG_PCIeDPM_ForceLevel,
3500 static void fiji_apply_dal_min_voltage_request(struct pp_hwmgr *hwmgr)
3502 struct phm_ppt_v1_information *table_info =
3503 (struct phm_ppt_v1_information *)hwmgr->pptable;
3504 struct phm_clock_voltage_dependency_table *table =
3505 table_info->vddc_dep_on_dal_pwrl;
3506 struct phm_ppt_v1_clock_voltage_dependency_table *vddc_table;
3507 enum PP_DAL_POWERLEVEL dal_power_level = hwmgr->dal_power_level;
3508 uint32_t req_vddc = 0, req_volt, i;
3510 if (!table && !(dal_power_level >= PP_DAL_POWERLEVEL_ULTRALOW &&
3511 dal_power_level <= PP_DAL_POWERLEVEL_PERFORMANCE))
3514 for (i= 0; i < table->count; i++) {
3515 if (dal_power_level == table->entries[i].clk) {
3516 req_vddc = table->entries[i].v;
3521 vddc_table = table_info->vdd_dep_on_sclk;
3522 for (i= 0; i < vddc_table->count; i++) {
3523 if (req_vddc <= vddc_table->entries[i].vddc) {
3524 req_volt = (((uint32_t)vddc_table->entries[i].vddc) * VOLTAGE_SCALE)
3526 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3527 PPSMC_MSG_VddC_Request, req_volt);
3531 printk(KERN_ERR "DAL requested level can not"
3532 " found a available voltage in VDDC DPM Table \n");
3535 static int fiji_upload_dpmlevel_enable_mask(struct pp_hwmgr *hwmgr)
3537 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3539 fiji_apply_dal_min_voltage_request(hwmgr);
3541 if (!data->sclk_dpm_key_disabled) {
3542 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask)
3543 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3544 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3545 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3550 static int fiji_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
3552 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3554 if (!fiji_is_dpm_running(hwmgr))
3557 if (!data->pcie_dpm_key_disabled) {
3558 smum_send_msg_to_smc(hwmgr->smumgr,
3559 PPSMC_MSG_PCIeDPM_UnForceLevel);
3562 return fiji_upload_dpmlevel_enable_mask(hwmgr);
3565 static uint32_t fiji_get_lowest_enabled_level(
3566 struct pp_hwmgr *hwmgr, uint32_t mask)
3570 while(0 == (mask & (1 << level)))
3576 static int fiji_force_dpm_lowest(struct pp_hwmgr *hwmgr)
3578 struct fiji_hwmgr *data =
3579 (struct fiji_hwmgr *)(hwmgr->backend);
3582 if (!data->sclk_dpm_key_disabled)
3583 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3584 level = fiji_get_lowest_enabled_level(hwmgr,
3585 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3586 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3587 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3592 if (!data->mclk_dpm_key_disabled) {
3593 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3594 level = fiji_get_lowest_enabled_level(hwmgr,
3595 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3596 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3597 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3602 if (!data->pcie_dpm_key_disabled) {
3603 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3604 level = fiji_get_lowest_enabled_level(hwmgr,
3605 data->dpm_level_enable_mask.pcie_dpm_enable_mask);
3606 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3607 PPSMC_MSG_PCIeDPM_ForceLevel,
3615 static int fiji_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
3616 enum amd_dpm_forced_level level)
3621 case AMD_DPM_FORCED_LEVEL_HIGH:
3622 ret = fiji_force_dpm_highest(hwmgr);
3626 case AMD_DPM_FORCED_LEVEL_LOW:
3627 ret = fiji_force_dpm_lowest(hwmgr);
3631 case AMD_DPM_FORCED_LEVEL_AUTO:
3632 ret = fiji_unforce_dpm_levels(hwmgr);
3640 hwmgr->dpm_level = level;
3645 static int fiji_get_power_state_size(struct pp_hwmgr *hwmgr)
3647 return sizeof(struct fiji_power_state);
3650 static int fiji_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr,
3651 void *state, struct pp_power_state *power_state,
3652 void *pp_table, uint32_t classification_flag)
3654 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3655 struct fiji_power_state *fiji_power_state =
3656 (struct fiji_power_state *)(&(power_state->hardware));
3657 struct fiji_performance_level *performance_level;
3658 ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
3659 ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
3660 (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
3661 ATOM_Tonga_SCLK_Dependency_Table *sclk_dep_table =
3662 (ATOM_Tonga_SCLK_Dependency_Table *)
3663 (((unsigned long)powerplay_table) +
3664 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
3665 ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
3666 (ATOM_Tonga_MCLK_Dependency_Table *)
3667 (((unsigned long)powerplay_table) +
3668 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
3670 /* The following fields are not initialized here: id orderedList allStatesList */
3671 power_state->classification.ui_label =
3672 (le16_to_cpu(state_entry->usClassification) &
3673 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
3674 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
3675 power_state->classification.flags = classification_flag;
3676 /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
3678 power_state->classification.temporary_state = false;
3679 power_state->classification.to_be_deleted = false;
3681 power_state->validation.disallowOnDC =
3682 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3683 ATOM_Tonga_DISALLOW_ON_DC));
3685 power_state->pcie.lanes = 0;
3687 power_state->display.disableFrameModulation = false;
3688 power_state->display.limitRefreshrate = false;
3689 power_state->display.enableVariBright =
3690 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3691 ATOM_Tonga_ENABLE_VARIBRIGHT));
3693 power_state->validation.supportedPowerLevels = 0;
3694 power_state->uvd_clocks.VCLK = 0;
3695 power_state->uvd_clocks.DCLK = 0;
3696 power_state->temperatures.min = 0;
3697 power_state->temperatures.max = 0;
3699 performance_level = &(fiji_power_state->performance_levels
3700 [fiji_power_state->performance_level_count++]);
3702 PP_ASSERT_WITH_CODE(
3703 (fiji_power_state->performance_level_count < SMU73_MAX_LEVELS_GRAPHICS),
3704 "Performance levels exceeds SMC limit!",
3707 PP_ASSERT_WITH_CODE(
3708 (fiji_power_state->performance_level_count <=
3709 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3710 "Performance levels exceeds Driver limit!",
3713 /* Performance levels are arranged from low to high. */
3714 performance_level->memory_clock = mclk_dep_table->entries
3715 [state_entry->ucMemoryClockIndexLow].ulMclk;
3716 performance_level->engine_clock = sclk_dep_table->entries
3717 [state_entry->ucEngineClockIndexLow].ulSclk;
3718 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3719 state_entry->ucPCIEGenLow);
3720 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3721 state_entry->ucPCIELaneHigh);
3723 performance_level = &(fiji_power_state->performance_levels
3724 [fiji_power_state->performance_level_count++]);
3725 performance_level->memory_clock = mclk_dep_table->entries
3726 [state_entry->ucMemoryClockIndexHigh].ulMclk;
3727 performance_level->engine_clock = sclk_dep_table->entries
3728 [state_entry->ucEngineClockIndexHigh].ulSclk;
3729 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3730 state_entry->ucPCIEGenHigh);
3731 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3732 state_entry->ucPCIELaneHigh);
3737 static int fiji_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3738 unsigned long entry_index, struct pp_power_state *state)
3741 struct fiji_power_state *ps;
3742 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3743 struct phm_ppt_v1_information *table_info =
3744 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3745 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
3746 table_info->vdd_dep_on_mclk;
3748 state->hardware.magic = PHM_VIslands_Magic;
3750 ps = (struct fiji_power_state *)(&state->hardware);
3752 result = tonga_get_powerplay_table_entry(hwmgr, entry_index, state,
3753 fiji_get_pp_table_entry_callback_func);
3755 /* This is the earliest time we have all the dependency table and the VBIOS boot state
3756 * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
3757 * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
3759 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3760 if (dep_mclk_table->entries[0].clk !=
3761 data->vbios_boot_state.mclk_bootup_value)
3762 printk(KERN_ERR "Single MCLK entry VDDCI/MCLK dependency table "
3763 "does not match VBIOS boot MCLK level");
3764 if (dep_mclk_table->entries[0].vddci !=
3765 data->vbios_boot_state.vddci_bootup_value)
3766 printk(KERN_ERR "Single VDDCI entry VDDCI/MCLK dependency table "
3767 "does not match VBIOS boot VDDCI level");
3770 /* set DC compatible flag if this state supports DC */
3771 if (!state->validation.disallowOnDC)
3772 ps->dc_compatible = true;
3774 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3775 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3777 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3778 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3783 switch (state->classification.ui_label) {
3784 case PP_StateUILabel_Performance:
3785 data->use_pcie_performance_levels = true;
3787 for (i = 0; i < ps->performance_level_count; i++) {
3788 if (data->pcie_gen_performance.max <
3789 ps->performance_levels[i].pcie_gen)
3790 data->pcie_gen_performance.max =
3791 ps->performance_levels[i].pcie_gen;
3793 if (data->pcie_gen_performance.min >
3794 ps->performance_levels[i].pcie_gen)
3795 data->pcie_gen_performance.min =
3796 ps->performance_levels[i].pcie_gen;
3798 if (data->pcie_lane_performance.max <
3799 ps->performance_levels[i].pcie_lane)
3800 data->pcie_lane_performance.max =
3801 ps->performance_levels[i].pcie_lane;
3803 if (data->pcie_lane_performance.min >
3804 ps->performance_levels[i].pcie_lane)
3805 data->pcie_lane_performance.min =
3806 ps->performance_levels[i].pcie_lane;
3809 case PP_StateUILabel_Battery:
3810 data->use_pcie_power_saving_levels = true;
3812 for (i = 0; i < ps->performance_level_count; i++) {
3813 if (data->pcie_gen_power_saving.max <
3814 ps->performance_levels[i].pcie_gen)
3815 data->pcie_gen_power_saving.max =
3816 ps->performance_levels[i].pcie_gen;
3818 if (data->pcie_gen_power_saving.min >
3819 ps->performance_levels[i].pcie_gen)
3820 data->pcie_gen_power_saving.min =
3821 ps->performance_levels[i].pcie_gen;
3823 if (data->pcie_lane_power_saving.max <
3824 ps->performance_levels[i].pcie_lane)
3825 data->pcie_lane_power_saving.max =
3826 ps->performance_levels[i].pcie_lane;
3828 if (data->pcie_lane_power_saving.min >
3829 ps->performance_levels[i].pcie_lane)
3830 data->pcie_lane_power_saving.min =
3831 ps->performance_levels[i].pcie_lane;
3841 static int fiji_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
3842 struct pp_power_state *request_ps,
3843 const struct pp_power_state *current_ps)
3845 struct fiji_power_state *fiji_ps =
3846 cast_phw_fiji_power_state(&request_ps->hardware);
3849 struct PP_Clocks minimum_clocks = {0};
3850 bool disable_mclk_switching;
3851 bool disable_mclk_switching_for_frame_lock;
3852 struct cgs_display_info info = {0};
3853 const struct phm_clock_and_voltage_limits *max_limits;
3855 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3856 struct phm_ppt_v1_information *table_info =
3857 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3859 int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
3861 data->battery_state = (PP_StateUILabel_Battery ==
3862 request_ps->classification.ui_label);
3864 PP_ASSERT_WITH_CODE(fiji_ps->performance_level_count == 2,
3865 "VI should always have 2 performance levels",);
3867 max_limits = (PP_PowerSource_AC == hwmgr->power_source) ?
3868 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
3869 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
3871 /* Cap clock DPM tables at DC MAX if it is in DC. */
3872 if (PP_PowerSource_DC == hwmgr->power_source) {
3873 for (i = 0; i < fiji_ps->performance_level_count; i++) {
3874 if (fiji_ps->performance_levels[i].memory_clock > max_limits->mclk)
3875 fiji_ps->performance_levels[i].memory_clock = max_limits->mclk;
3876 if (fiji_ps->performance_levels[i].engine_clock > max_limits->sclk)
3877 fiji_ps->performance_levels[i].engine_clock = max_limits->sclk;
3881 fiji_ps->vce_clks.evclk = hwmgr->vce_arbiter.evclk;
3882 fiji_ps->vce_clks.ecclk = hwmgr->vce_arbiter.ecclk;
3884 fiji_ps->acp_clk = hwmgr->acp_arbiter.acpclk;
3886 cgs_get_active_displays_info(hwmgr->device, &info);
3888 /*TO DO result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/
3890 /* TO DO GetMinClockSettings(hwmgr->pPECI, &minimum_clocks); */
3892 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3893 PHM_PlatformCaps_StablePState)) {
3894 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
3895 stable_pstate_sclk = (max_limits->sclk * 75) / 100;
3897 for (count = table_info->vdd_dep_on_sclk->count - 1;
3898 count >= 0; count--) {
3899 if (stable_pstate_sclk >=
3900 table_info->vdd_dep_on_sclk->entries[count].clk) {
3901 stable_pstate_sclk =
3902 table_info->vdd_dep_on_sclk->entries[count].clk;
3908 stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3910 stable_pstate_mclk = max_limits->mclk;
3912 minimum_clocks.engineClock = stable_pstate_sclk;
3913 minimum_clocks.memoryClock = stable_pstate_mclk;
3916 if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk)
3917 minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk;
3919 if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
3920 minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
3922 fiji_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold;
3924 if (0 != hwmgr->gfx_arbiter.sclk_over_drive) {
3925 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <=
3926 hwmgr->platform_descriptor.overdriveLimit.engineClock),
3927 "Overdrive sclk exceeds limit",
3928 hwmgr->gfx_arbiter.sclk_over_drive =
3929 hwmgr->platform_descriptor.overdriveLimit.engineClock);
3931 if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk)
3932 fiji_ps->performance_levels[1].engine_clock =
3933 hwmgr->gfx_arbiter.sclk_over_drive;
3936 if (0 != hwmgr->gfx_arbiter.mclk_over_drive) {
3937 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <=
3938 hwmgr->platform_descriptor.overdriveLimit.memoryClock),
3939 "Overdrive mclk exceeds limit",
3940 hwmgr->gfx_arbiter.mclk_over_drive =
3941 hwmgr->platform_descriptor.overdriveLimit.memoryClock);
3943 if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk)
3944 fiji_ps->performance_levels[1].memory_clock =
3945 hwmgr->gfx_arbiter.mclk_over_drive;
3948 disable_mclk_switching_for_frame_lock = phm_cap_enabled(
3949 hwmgr->platform_descriptor.platformCaps,
3950 PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
3952 disable_mclk_switching = (1 < info.display_count) ||
3953 disable_mclk_switching_for_frame_lock;
3955 sclk = fiji_ps->performance_levels[0].engine_clock;
3956 mclk = fiji_ps->performance_levels[0].memory_clock;
3958 if (disable_mclk_switching)
3959 mclk = fiji_ps->performance_levels
3960 [fiji_ps->performance_level_count - 1].memory_clock;
3962 if (sclk < minimum_clocks.engineClock)
3963 sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
3964 max_limits->sclk : minimum_clocks.engineClock;
3966 if (mclk < minimum_clocks.memoryClock)
3967 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
3968 max_limits->mclk : minimum_clocks.memoryClock;
3970 fiji_ps->performance_levels[0].engine_clock = sclk;
3971 fiji_ps->performance_levels[0].memory_clock = mclk;
3973 fiji_ps->performance_levels[1].engine_clock =
3974 (fiji_ps->performance_levels[1].engine_clock >=
3975 fiji_ps->performance_levels[0].engine_clock) ?
3976 fiji_ps->performance_levels[1].engine_clock :
3977 fiji_ps->performance_levels[0].engine_clock;
3979 if (disable_mclk_switching) {
3980 if (mclk < fiji_ps->performance_levels[1].memory_clock)
3981 mclk = fiji_ps->performance_levels[1].memory_clock;
3983 fiji_ps->performance_levels[0].memory_clock = mclk;
3984 fiji_ps->performance_levels[1].memory_clock = mclk;
3986 if (fiji_ps->performance_levels[1].memory_clock <
3987 fiji_ps->performance_levels[0].memory_clock)
3988 fiji_ps->performance_levels[1].memory_clock =
3989 fiji_ps->performance_levels[0].memory_clock;
3992 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3993 PHM_PlatformCaps_StablePState)) {
3994 for (i = 0; i < fiji_ps->performance_level_count; i++) {
3995 fiji_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
3996 fiji_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
3997 fiji_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
3998 fiji_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
4005 static int fiji_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
4007 const struct phm_set_power_state_input *states =
4008 (const struct phm_set_power_state_input *)input;
4009 const struct fiji_power_state *fiji_ps =
4010 cast_const_phw_fiji_power_state(states->pnew_state);
4011 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4012 struct fiji_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4013 uint32_t sclk = fiji_ps->performance_levels
4014 [fiji_ps->performance_level_count - 1].engine_clock;
4015 struct fiji_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4016 uint32_t mclk = fiji_ps->performance_levels
4017 [fiji_ps->performance_level_count - 1].memory_clock;
4018 struct PP_Clocks min_clocks = {0};
4020 struct cgs_display_info info = {0};
4022 data->need_update_smu7_dpm_table = 0;
4024 for (i = 0; i < sclk_table->count; i++) {
4025 if (sclk == sclk_table->dpm_levels[i].value)
4029 if (i >= sclk_table->count)
4030 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
4032 /* TODO: Check SCLK in DAL's minimum clocks
4033 * in case DeepSleep divider update is required.
4035 if(data->display_timing.min_clock_in_sr != min_clocks.engineClockInSR)
4036 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
4039 for (i = 0; i < mclk_table->count; i++) {
4040 if (mclk == mclk_table->dpm_levels[i].value)
4044 if (i >= mclk_table->count)
4045 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
4047 cgs_get_active_displays_info(hwmgr->device, &info);
4049 if (data->display_timing.num_existing_displays != info.display_count)
4050 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
4055 static uint16_t fiji_get_maximum_link_speed(struct pp_hwmgr *hwmgr,
4056 const struct fiji_power_state *fiji_ps)
4059 uint32_t sclk, max_sclk = 0;
4060 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4061 struct fiji_dpm_table *dpm_table = &data->dpm_table;
4063 for (i = 0; i < fiji_ps->performance_level_count; i++) {
4064 sclk = fiji_ps->performance_levels[i].engine_clock;
4065 if (max_sclk < sclk)
4069 for (i = 0; i < dpm_table->sclk_table.count; i++) {
4070 if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk)
4071 return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ?
4072 dpm_table->pcie_speed_table.dpm_levels
4073 [dpm_table->pcie_speed_table.count - 1].value :
4074 dpm_table->pcie_speed_table.dpm_levels[i].value);
4080 static int fiji_request_link_speed_change_before_state_change(
4081 struct pp_hwmgr *hwmgr, const void *input)
4083 const struct phm_set_power_state_input *states =
4084 (const struct phm_set_power_state_input *)input;
4085 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4086 const struct fiji_power_state *fiji_nps =
4087 cast_const_phw_fiji_power_state(states->pnew_state);
4088 const struct fiji_power_state *fiji_cps =
4089 cast_const_phw_fiji_power_state(states->pcurrent_state);
4091 uint16_t target_link_speed = fiji_get_maximum_link_speed(hwmgr, fiji_nps);
4092 uint16_t current_link_speed;
4094 if (data->force_pcie_gen == PP_PCIEGenInvalid)
4095 current_link_speed = fiji_get_maximum_link_speed(hwmgr, fiji_cps);
4097 current_link_speed = data->force_pcie_gen;
4099 data->force_pcie_gen = PP_PCIEGenInvalid;
4100 data->pspp_notify_required = false;
4101 if (target_link_speed > current_link_speed) {
4102 switch(target_link_speed) {
4104 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false))
4106 data->force_pcie_gen = PP_PCIEGen2;
4107 if (current_link_speed == PP_PCIEGen2)
4110 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false))
4113 data->force_pcie_gen = fiji_get_current_pcie_speed(hwmgr);
4117 if (target_link_speed < current_link_speed)
4118 data->pspp_notify_required = true;
4124 static int fiji_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4126 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4128 if (0 == data->need_update_smu7_dpm_table)
4131 if ((0 == data->sclk_dpm_key_disabled) &&
4132 (data->need_update_smu7_dpm_table &
4133 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4134 PP_ASSERT_WITH_CODE(true == fiji_is_dpm_running(hwmgr),
4135 "Trying to freeze SCLK DPM when DPM is disabled",);
4136 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4137 PPSMC_MSG_SCLKDPM_FreezeLevel),
4138 "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
4142 if ((0 == data->mclk_dpm_key_disabled) &&
4143 (data->need_update_smu7_dpm_table &
4144 DPMTABLE_OD_UPDATE_MCLK)) {
4145 PP_ASSERT_WITH_CODE(true == fiji_is_dpm_running(hwmgr),
4146 "Trying to freeze MCLK DPM when DPM is disabled",);
4147 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4148 PPSMC_MSG_MCLKDPM_FreezeLevel),
4149 "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
4156 static int fiji_populate_and_upload_sclk_mclk_dpm_levels(
4157 struct pp_hwmgr *hwmgr, const void *input)
4160 const struct phm_set_power_state_input *states =
4161 (const struct phm_set_power_state_input *)input;
4162 const struct fiji_power_state *fiji_ps =
4163 cast_const_phw_fiji_power_state(states->pnew_state);
4164 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4165 uint32_t sclk = fiji_ps->performance_levels
4166 [fiji_ps->performance_level_count - 1].engine_clock;
4167 uint32_t mclk = fiji_ps->performance_levels
4168 [fiji_ps->performance_level_count - 1].memory_clock;
4169 struct fiji_dpm_table *dpm_table = &data->dpm_table;
4171 struct fiji_dpm_table *golden_dpm_table = &data->golden_dpm_table;
4172 uint32_t dpm_count, clock_percent;
4175 if (0 == data->need_update_smu7_dpm_table)
4178 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
4179 dpm_table->sclk_table.dpm_levels
4180 [dpm_table->sclk_table.count - 1].value = sclk;
4182 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4183 PHM_PlatformCaps_OD6PlusinACSupport) ||
4184 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4185 PHM_PlatformCaps_OD6PlusinDCSupport)) {
4186 /* Need to do calculation based on the golden DPM table
4187 * as the Heatmap GPU Clock axis is also based on the default values
4189 PP_ASSERT_WITH_CODE(
4190 (golden_dpm_table->sclk_table.dpm_levels
4191 [golden_dpm_table->sclk_table.count - 1].value != 0),
4194 dpm_count = dpm_table->sclk_table.count < 2 ?
4195 0 : dpm_table->sclk_table.count - 2;
4196 for (i = dpm_count; i > 1; i--) {
4197 if (sclk > golden_dpm_table->sclk_table.dpm_levels
4198 [golden_dpm_table->sclk_table.count-1].value) {
4200 ((sclk - golden_dpm_table->sclk_table.dpm_levels
4201 [golden_dpm_table->sclk_table.count-1].value) * 100) /
4202 golden_dpm_table->sclk_table.dpm_levels
4203 [golden_dpm_table->sclk_table.count-1].value;
4205 dpm_table->sclk_table.dpm_levels[i].value =
4206 golden_dpm_table->sclk_table.dpm_levels[i].value +
4207 (golden_dpm_table->sclk_table.dpm_levels[i].value *
4210 } else if (golden_dpm_table->sclk_table.dpm_levels
4211 [dpm_table->sclk_table.count-1].value > sclk) {
4213 ((golden_dpm_table->sclk_table.dpm_levels
4214 [golden_dpm_table->sclk_table.count - 1].value - sclk) *
4216 golden_dpm_table->sclk_table.dpm_levels
4217 [golden_dpm_table->sclk_table.count-1].value;
4219 dpm_table->sclk_table.dpm_levels[i].value =
4220 golden_dpm_table->sclk_table.dpm_levels[i].value -
4221 (golden_dpm_table->sclk_table.dpm_levels[i].value *
4222 clock_percent) / 100;
4224 dpm_table->sclk_table.dpm_levels[i].value =
4225 golden_dpm_table->sclk_table.dpm_levels[i].value;
4230 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
4231 dpm_table->mclk_table.dpm_levels
4232 [dpm_table->mclk_table.count - 1].value = mclk;
4234 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4235 PHM_PlatformCaps_OD6PlusinACSupport) ||
4236 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4237 PHM_PlatformCaps_OD6PlusinDCSupport)) {
4239 PP_ASSERT_WITH_CODE(
4240 (golden_dpm_table->mclk_table.dpm_levels
4241 [golden_dpm_table->mclk_table.count-1].value != 0),
4244 dpm_count = dpm_table->mclk_table.count < 2 ?
4245 0 : dpm_table->mclk_table.count - 2;
4246 for (i = dpm_count; i > 1; i--) {
4247 if (mclk > golden_dpm_table->mclk_table.dpm_levels
4248 [golden_dpm_table->mclk_table.count-1].value) {
4249 clock_percent = ((mclk -
4250 golden_dpm_table->mclk_table.dpm_levels
4251 [golden_dpm_table->mclk_table.count-1].value) * 100) /
4252 golden_dpm_table->mclk_table.dpm_levels
4253 [golden_dpm_table->mclk_table.count-1].value;
4255 dpm_table->mclk_table.dpm_levels[i].value =
4256 golden_dpm_table->mclk_table.dpm_levels[i].value +
4257 (golden_dpm_table->mclk_table.dpm_levels[i].value *
4258 clock_percent) / 100;
4260 } else if (golden_dpm_table->mclk_table.dpm_levels
4261 [dpm_table->mclk_table.count-1].value > mclk) {
4262 clock_percent = ((golden_dpm_table->mclk_table.dpm_levels
4263 [golden_dpm_table->mclk_table.count-1].value - mclk) * 100) /
4264 golden_dpm_table->mclk_table.dpm_levels
4265 [golden_dpm_table->mclk_table.count-1].value;
4267 dpm_table->mclk_table.dpm_levels[i].value =
4268 golden_dpm_table->mclk_table.dpm_levels[i].value -
4269 (golden_dpm_table->mclk_table.dpm_levels[i].value *
4270 clock_percent) / 100;
4272 dpm_table->mclk_table.dpm_levels[i].value =
4273 golden_dpm_table->mclk_table.dpm_levels[i].value;
4278 if (data->need_update_smu7_dpm_table &
4279 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
4280 result = fiji_populate_all_memory_levels(hwmgr);
4281 PP_ASSERT_WITH_CODE((0 == result),
4282 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
4286 if (data->need_update_smu7_dpm_table &
4287 (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
4288 /*populate MCLK dpm table to SMU7 */
4289 result = fiji_populate_all_memory_levels(hwmgr);
4290 PP_ASSERT_WITH_CODE((0 == result),
4291 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
4298 static int fiji_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
4299 struct fiji_single_dpm_table * dpm_table,
4300 uint32_t low_limit, uint32_t high_limit)
4304 for (i = 0; i < dpm_table->count; i++) {
4305 if ((dpm_table->dpm_levels[i].value < low_limit) ||
4306 (dpm_table->dpm_levels[i].value > high_limit))
4307 dpm_table->dpm_levels[i].enabled = false;
4309 dpm_table->dpm_levels[i].enabled = true;
4314 static int fiji_trim_dpm_states(struct pp_hwmgr *hwmgr,
4315 const struct fiji_power_state *fiji_ps)
4318 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4319 uint32_t high_limit_count;
4321 PP_ASSERT_WITH_CODE((fiji_ps->performance_level_count >= 1),
4322 "power state did not have any performance level",
4325 high_limit_count = (1 == fiji_ps->performance_level_count) ? 0 : 1;
4327 fiji_trim_single_dpm_states(hwmgr,
4328 &(data->dpm_table.sclk_table),
4329 fiji_ps->performance_levels[0].engine_clock,
4330 fiji_ps->performance_levels[high_limit_count].engine_clock);
4332 fiji_trim_single_dpm_states(hwmgr,
4333 &(data->dpm_table.mclk_table),
4334 fiji_ps->performance_levels[0].memory_clock,
4335 fiji_ps->performance_levels[high_limit_count].memory_clock);
4340 static int fiji_generate_dpm_level_enable_mask(
4341 struct pp_hwmgr *hwmgr, const void *input)
4344 const struct phm_set_power_state_input *states =
4345 (const struct phm_set_power_state_input *)input;
4346 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4347 const struct fiji_power_state *fiji_ps =
4348 cast_const_phw_fiji_power_state(states->pnew_state);
4350 result = fiji_trim_dpm_states(hwmgr, fiji_ps);
4354 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
4355 fiji_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
4356 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
4357 fiji_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
4358 data->last_mclk_dpm_enable_mask =
4359 data->dpm_level_enable_mask.mclk_dpm_enable_mask;
4361 if (data->uvd_enabled) {
4362 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask & 1)
4363 data->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE;
4366 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
4367 fiji_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
4372 static int fiji_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
4374 return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4375 PPSMC_MSG_VCEDPM_Enable :
4376 PPSMC_MSG_VCEDPM_Disable);
4379 static int fiji_update_vce_dpm(struct pp_hwmgr *hwmgr, const void *input)
4381 const struct phm_set_power_state_input *states =
4382 (const struct phm_set_power_state_input *)input;
4383 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4384 const struct fiji_power_state *fiji_nps =
4385 cast_const_phw_fiji_power_state(states->pnew_state);
4386 const struct fiji_power_state *fiji_cps =
4387 cast_const_phw_fiji_power_state(states->pcurrent_state);
4389 uint32_t mm_boot_level_offset, mm_boot_level_value;
4390 struct phm_ppt_v1_information *table_info =
4391 (struct phm_ppt_v1_information *)(hwmgr->pptable);
4393 if (fiji_nps->vce_clks.evclk >0 &&
4394 (fiji_cps == NULL || fiji_cps->vce_clks.evclk == 0)) {
4395 data->smc_state_table.VceBootLevel =
4396 (uint8_t) (table_info->mm_dep_table->count - 1);
4398 mm_boot_level_offset = data->dpm_table_start +
4399 offsetof(SMU73_Discrete_DpmTable, VceBootLevel);
4400 mm_boot_level_offset /= 4;
4401 mm_boot_level_offset *= 4;
4402 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4403 CGS_IND_REG__SMC, mm_boot_level_offset);
4404 mm_boot_level_value &= 0xFF00FFFF;
4405 mm_boot_level_value |= data->smc_state_table.VceBootLevel << 16;
4406 cgs_write_ind_register(hwmgr->device,
4407 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4409 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4410 PHM_PlatformCaps_StablePState)) {
4411 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4412 PPSMC_MSG_VCEDPM_SetEnabledMask,
4413 (uint32_t)1 << data->smc_state_table.VceBootLevel);
4415 fiji_enable_disable_vce_dpm(hwmgr, true);
4416 } else if (fiji_nps->vce_clks.evclk == 0 &&
4418 fiji_cps->vce_clks.evclk > 0)
4419 fiji_enable_disable_vce_dpm(hwmgr, false);
4425 static int fiji_update_sclk_threshold(struct pp_hwmgr *hwmgr)
4427 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4430 uint32_t low_sclk_interrupt_threshold = 0;
4432 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4433 PHM_PlatformCaps_SclkThrottleLowNotification)
4434 && (hwmgr->gfx_arbiter.sclk_threshold !=
4435 data->low_sclk_interrupt_threshold)) {
4436 data->low_sclk_interrupt_threshold =
4437 hwmgr->gfx_arbiter.sclk_threshold;
4438 low_sclk_interrupt_threshold =
4439 data->low_sclk_interrupt_threshold;
4441 CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
4443 result = fiji_copy_bytes_to_smc(
4445 data->dpm_table_start +
4446 offsetof(SMU73_Discrete_DpmTable,
4447 LowSclkInterruptThreshold),
4448 (uint8_t *)&low_sclk_interrupt_threshold,
4456 static int fiji_program_mem_timing_parameters(struct pp_hwmgr *hwmgr)
4458 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4460 if (data->need_update_smu7_dpm_table &
4461 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK))
4462 return fiji_program_memory_timing_parameters(hwmgr);
4467 static int fiji_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4469 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4471 if (0 == data->need_update_smu7_dpm_table)
4474 if ((0 == data->sclk_dpm_key_disabled) &&
4475 (data->need_update_smu7_dpm_table &
4476 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4478 PP_ASSERT_WITH_CODE(true == fiji_is_dpm_running(hwmgr),
4479 "Trying to Unfreeze SCLK DPM when DPM is disabled",);
4480 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4481 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4482 "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
4486 if ((0 == data->mclk_dpm_key_disabled) &&
4487 (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
4489 PP_ASSERT_WITH_CODE(true == fiji_is_dpm_running(hwmgr),
4490 "Trying to Unfreeze MCLK DPM when DPM is disabled",);
4491 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4492 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4493 "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
4497 data->need_update_smu7_dpm_table = 0;
4502 /* Look up the voltaged based on DAL's requested level.
4503 * and then send the requested VDDC voltage to SMC
4505 static void fiji_apply_dal_minimum_voltage_request(struct pp_hwmgr *hwmgr)
4510 int fiji_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
4513 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4515 /* Apply minimum voltage based on DAL's request level */
4516 fiji_apply_dal_minimum_voltage_request(hwmgr);
4518 if (0 == data->sclk_dpm_key_disabled) {
4519 /* Checking if DPM is running. If we discover hang because of this,
4520 * we should skip this message.
4522 if (!fiji_is_dpm_running(hwmgr))
4523 printk(KERN_ERR "[ powerplay ] "
4524 "Trying to set Enable Mask when DPM is disabled \n");
4526 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
4527 result = smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4528 PPSMC_MSG_SCLKDPM_SetEnabledMask,
4529 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
4530 PP_ASSERT_WITH_CODE((0 == result),
4531 "Set Sclk Dpm enable Mask failed", return -1);
4535 if (0 == data->mclk_dpm_key_disabled) {
4536 /* Checking if DPM is running. If we discover hang because of this,
4537 * we should skip this message.
4539 if (!fiji_is_dpm_running(hwmgr))
4540 printk(KERN_ERR "[ powerplay ]"
4541 " Trying to set Enable Mask when DPM is disabled \n");
4543 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
4544 result = smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4545 PPSMC_MSG_MCLKDPM_SetEnabledMask,
4546 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
4547 PP_ASSERT_WITH_CODE((0 == result),
4548 "Set Mclk Dpm enable Mask failed", return -1);
4555 static int fiji_notify_link_speed_change_after_state_change(
4556 struct pp_hwmgr *hwmgr, const void *input)
4558 const struct phm_set_power_state_input *states =
4559 (const struct phm_set_power_state_input *)input;
4560 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4561 const struct fiji_power_state *fiji_ps =
4562 cast_const_phw_fiji_power_state(states->pnew_state);
4563 uint16_t target_link_speed = fiji_get_maximum_link_speed(hwmgr, fiji_ps);
4566 if (data->pspp_notify_required) {
4567 if (target_link_speed == PP_PCIEGen3)
4568 request = PCIE_PERF_REQ_GEN3;
4569 else if (target_link_speed == PP_PCIEGen2)
4570 request = PCIE_PERF_REQ_GEN2;
4572 request = PCIE_PERF_REQ_GEN1;
4574 if(request == PCIE_PERF_REQ_GEN1 &&
4575 fiji_get_current_pcie_speed(hwmgr) > 0)
4578 if (acpi_pcie_perf_request(hwmgr->device, request, false)) {
4579 if (PP_PCIEGen2 == target_link_speed)
4580 printk("PSPP request to switch to Gen2 from Gen3 Failed!");
4582 printk("PSPP request to switch to Gen1 from Gen2 Failed!");
4589 static int fiji_set_power_state_tasks(struct pp_hwmgr *hwmgr,
4592 int tmp_result, result = 0;
4594 tmp_result = fiji_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
4595 PP_ASSERT_WITH_CODE((0 == tmp_result),
4596 "Failed to find DPM states clocks in DPM table!",
4597 result = tmp_result);
4599 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4600 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4602 fiji_request_link_speed_change_before_state_change(hwmgr, input);
4603 PP_ASSERT_WITH_CODE((0 == tmp_result),
4604 "Failed to request link speed change before state change!",
4605 result = tmp_result);
4608 tmp_result = fiji_freeze_sclk_mclk_dpm(hwmgr);
4609 PP_ASSERT_WITH_CODE((0 == tmp_result),
4610 "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
4612 tmp_result = fiji_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
4613 PP_ASSERT_WITH_CODE((0 == tmp_result),
4614 "Failed to populate and upload SCLK MCLK DPM levels!",
4615 result = tmp_result);
4617 tmp_result = fiji_generate_dpm_level_enable_mask(hwmgr, input);
4618 PP_ASSERT_WITH_CODE((0 == tmp_result),
4619 "Failed to generate DPM level enabled mask!",
4620 result = tmp_result);
4622 tmp_result = fiji_update_vce_dpm(hwmgr, input);
4623 PP_ASSERT_WITH_CODE((0 == tmp_result),
4624 "Failed to update VCE DPM!",
4625 result = tmp_result);
4627 tmp_result = fiji_update_sclk_threshold(hwmgr);
4628 PP_ASSERT_WITH_CODE((0 == tmp_result),
4629 "Failed to update SCLK threshold!",
4630 result = tmp_result);
4632 tmp_result = fiji_program_mem_timing_parameters(hwmgr);
4633 PP_ASSERT_WITH_CODE((0 == tmp_result),
4634 "Failed to program memory timing parameters!",
4635 result = tmp_result);
4637 tmp_result = fiji_unfreeze_sclk_mclk_dpm(hwmgr);
4638 PP_ASSERT_WITH_CODE((0 == tmp_result),
4639 "Failed to unfreeze SCLK MCLK DPM!",
4640 result = tmp_result);
4642 tmp_result = fiji_upload_dpm_level_enable_mask(hwmgr);
4643 PP_ASSERT_WITH_CODE((0 == tmp_result),
4644 "Failed to upload DPM level enabled mask!",
4645 result = tmp_result);
4647 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4648 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4650 fiji_notify_link_speed_change_after_state_change(hwmgr, input);
4651 PP_ASSERT_WITH_CODE((0 == tmp_result),
4652 "Failed to notify link speed change after state change!",
4653 result = tmp_result);
4659 static int fiji_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
4661 struct pp_power_state *ps;
4662 struct fiji_power_state *fiji_ps;
4667 ps = hwmgr->request_ps;
4672 fiji_ps = cast_phw_fiji_power_state(&ps->hardware);
4675 return fiji_ps->performance_levels[0].engine_clock;
4677 return fiji_ps->performance_levels
4678 [fiji_ps->performance_level_count-1].engine_clock;
4681 static int fiji_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
4683 struct pp_power_state *ps;
4684 struct fiji_power_state *fiji_ps;
4689 ps = hwmgr->request_ps;
4694 fiji_ps = cast_phw_fiji_power_state(&ps->hardware);
4697 return fiji_ps->performance_levels[0].memory_clock;
4699 return fiji_ps->performance_levels
4700 [fiji_ps->performance_level_count-1].memory_clock;
4703 static void fiji_print_current_perforce_level(
4704 struct pp_hwmgr *hwmgr, struct seq_file *m)
4706 uint32_t sclk, mclk;
4708 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
4710 sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
4712 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
4714 mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
4715 seq_printf(m, "\n [ mclk ]: %u MHz\n\n [ sclk ]: %u MHz\n",
4716 mclk / 100, sclk / 100);
4719 static const struct pp_hwmgr_func fiji_hwmgr_funcs = {
4720 .backend_init = &fiji_hwmgr_backend_init,
4721 .backend_fini = &tonga_hwmgr_backend_fini,
4722 .asic_setup = &fiji_setup_asic_task,
4723 .dynamic_state_management_enable = &fiji_enable_dpm_tasks,
4724 .force_dpm_level = &fiji_dpm_force_dpm_level,
4725 .get_num_of_pp_table_entries = &tonga_get_number_of_powerplay_table_entries,
4726 .get_power_state_size = &fiji_get_power_state_size,
4727 .get_pp_table_entry = &fiji_get_pp_table_entry,
4728 .patch_boot_state = &fiji_patch_boot_state,
4729 .apply_state_adjust_rules = &fiji_apply_state_adjust_rules,
4730 .power_state_set = &fiji_set_power_state_tasks,
4731 .get_sclk = &fiji_dpm_get_sclk,
4732 .get_mclk = &fiji_dpm_get_mclk,
4733 .print_current_perforce_level = &fiji_print_current_perforce_level,
4736 int fiji_hwmgr_init(struct pp_hwmgr *hwmgr)
4738 struct fiji_hwmgr *data;
4741 data = kzalloc(sizeof(struct fiji_hwmgr), GFP_KERNEL);
4745 hwmgr->backend = data;
4746 hwmgr->hwmgr_func = &fiji_hwmgr_funcs;
4747 hwmgr->pptable_func = &tonga_pptable_funcs;