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"
53 #include "cgs_linux.h"
54 #include "ppinterrupt.h"
56 #include "fiji_clockpowergating.h"
57 #include "fiji_thermal.h"
59 #define VOLTAGE_SCALE 4
60 #define SMC_RAM_END 0x40000
61 #define VDDC_VDDCI_DELTA 300
63 #define MC_SEQ_MISC0_GDDR5_SHIFT 28
64 #define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000
65 #define MC_SEQ_MISC0_GDDR5_VALUE 5
67 #define MC_CG_ARB_FREQ_F0 0x0a /* boot-up default */
68 #define MC_CG_ARB_FREQ_F1 0x0b
69 #define MC_CG_ARB_FREQ_F2 0x0c
70 #define MC_CG_ARB_FREQ_F3 0x0d
73 #define SMC_CG_IND_START 0xc0030000
74 #define SMC_CG_IND_END 0xc0040000 /* First byte after SMC_CG_IND */
76 #define VOLTAGE_SCALE 4
77 #define VOLTAGE_VID_OFFSET_SCALE1 625
78 #define VOLTAGE_VID_OFFSET_SCALE2 100
80 #define VDDC_VDDCI_DELTA 300
82 #define ixSWRST_COMMAND_1 0x1400103
83 #define MC_SEQ_CNTL__CAC_EN_MASK 0x40000000
85 /** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */
87 DPM_EVENT_SRC_ANALOG = 0, /* Internal analog trip point */
88 DPM_EVENT_SRC_EXTERNAL = 1, /* External (GPIO 17) signal */
89 DPM_EVENT_SRC_DIGITAL = 2, /* Internal digital trip point (DIG_THERM_DPM) */
90 DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3, /* Internal analog or external */
91 DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL = 4 /* Internal digital or external */
95 /* [2.5%,~2.5%] Clock stretched is multiple of 2.5% vs
96 * not and [Fmin, Fmax, LDO_REFSEL, USE_FOR_LOW_FREQ]
98 static const uint16_t fiji_clock_stretcher_lookup_table[2][4] =
99 { {600, 1050, 3, 0}, {600, 1050, 6, 1} };
101 /* [FF, SS] type, [] 4 voltage ranges, and
102 * [Floor Freq, Boundary Freq, VID min , VID max]
104 static const uint32_t fiji_clock_stretcher_ddt_table[2][4][4] =
105 { { {265, 529, 120, 128}, {325, 650, 96, 119}, {430, 860, 32, 95}, {0, 0, 0, 31} },
106 { {275, 550, 104, 112}, {319, 638, 96, 103}, {360, 720, 64, 95}, {384, 768, 32, 63} } };
108 /* [Use_For_Low_freq] value, [0%, 5%, 10%, 7.14%, 14.28%, 20%]
109 * (coming from PWR_CKS_CNTL.stretch_amount reg spec)
111 static const uint8_t fiji_clock_stretch_amount_conversion[2][6] =
112 { {0, 1, 3, 2, 4, 5}, {0, 2, 4, 5, 6, 5} };
114 static const unsigned long PhwFiji_Magic = (unsigned long)(PHM_VIslands_Magic);
116 struct fiji_power_state *cast_phw_fiji_power_state(
117 struct pp_hw_power_state *hw_ps)
119 PP_ASSERT_WITH_CODE((PhwFiji_Magic == hw_ps->magic),
120 "Invalid Powerstate Type!",
123 return (struct fiji_power_state *)hw_ps;
126 const struct fiji_power_state *cast_const_phw_fiji_power_state(
127 const struct pp_hw_power_state *hw_ps)
129 PP_ASSERT_WITH_CODE((PhwFiji_Magic == hw_ps->magic),
130 "Invalid Powerstate Type!",
133 return (const struct fiji_power_state *)hw_ps;
136 static bool fiji_is_dpm_running(struct pp_hwmgr *hwmgr)
138 return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
139 CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON))
143 static void fiji_init_dpm_defaults(struct pp_hwmgr *hwmgr)
145 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
146 struct fiji_ulv_parm *ulv = &data->ulv;
148 ulv->cg_ulv_parameter = PPFIJI_CGULVPARAMETER_DFLT;
149 data->voting_rights_clients0 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT0;
150 data->voting_rights_clients1 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT1;
151 data->voting_rights_clients2 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT2;
152 data->voting_rights_clients3 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT3;
153 data->voting_rights_clients4 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT4;
154 data->voting_rights_clients5 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT5;
155 data->voting_rights_clients6 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT6;
156 data->voting_rights_clients7 = PPFIJI_VOTINGRIGHTSCLIENTS_DFLT7;
158 data->static_screen_threshold_unit =
159 PPFIJI_STATICSCREENTHRESHOLDUNIT_DFLT;
160 data->static_screen_threshold =
161 PPFIJI_STATICSCREENTHRESHOLD_DFLT;
163 /* Unset ABM cap as it moved to DAL.
164 * Add PHM_PlatformCaps_NonABMSupportInPPLib
165 * for re-direct ABM related request to DAL
167 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
168 PHM_PlatformCaps_ABM);
169 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
170 PHM_PlatformCaps_NonABMSupportInPPLib);
172 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
173 PHM_PlatformCaps_DynamicACTiming);
175 fiji_initialize_power_tune_defaults(hwmgr);
177 data->mclk_stutter_mode_threshold = 60000;
178 data->pcie_gen_performance.max = PP_PCIEGen1;
179 data->pcie_gen_performance.min = PP_PCIEGen3;
180 data->pcie_gen_power_saving.max = PP_PCIEGen1;
181 data->pcie_gen_power_saving.min = PP_PCIEGen3;
182 data->pcie_lane_performance.max = 0;
183 data->pcie_lane_performance.min = 16;
184 data->pcie_lane_power_saving.max = 0;
185 data->pcie_lane_power_saving.min = 16;
187 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
188 PHM_PlatformCaps_DynamicUVDState);
191 static int fiji_get_sclk_for_voltage_evv(struct pp_hwmgr *hwmgr,
192 phm_ppt_v1_voltage_lookup_table *lookup_table,
193 uint16_t virtual_voltage_id, int32_t *sclk)
197 struct phm_ppt_v1_information *table_info =
198 (struct phm_ppt_v1_information *)(hwmgr->pptable);
200 PP_ASSERT_WITH_CODE(lookup_table->count != 0, "Lookup table is empty", return -EINVAL);
202 /* search for leakage voltage ID 0xff01 ~ 0xff08 and sckl */
203 for (entryId = 0; entryId < table_info->vdd_dep_on_sclk->count; entryId++) {
204 voltageId = table_info->vdd_dep_on_sclk->entries[entryId].vddInd;
205 if (lookup_table->entries[voltageId].us_vdd == virtual_voltage_id)
209 PP_ASSERT_WITH_CODE(entryId < table_info->vdd_dep_on_sclk->count,
210 "Can't find requested voltage id in vdd_dep_on_sclk table!",
214 *sclk = table_info->vdd_dep_on_sclk->entries[entryId].clk;
220 * Get Leakage VDDC based on leakage ID.
222 * @param hwmgr the address of the powerplay hardware manager.
225 static int fiji_get_evv_voltages(struct pp_hwmgr *hwmgr)
227 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
230 uint16_t evv_default = 1150;
233 struct phm_ppt_v1_information *table_info =
234 (struct phm_ppt_v1_information *)hwmgr->pptable;
235 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
236 table_info->vdd_dep_on_sclk;
239 for (i = 0; i < FIJI_MAX_LEAKAGE_COUNT; i++) {
240 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
241 if (!fiji_get_sclk_for_voltage_evv(hwmgr,
242 table_info->vddc_lookup_table, vv_id, &sclk)) {
243 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
244 PHM_PlatformCaps_ClockStretcher)) {
245 for (j = 1; j < sclk_table->count; j++) {
246 if (sclk_table->entries[j].clk == sclk &&
247 sclk_table->entries[j].cks_enable == 0) {
254 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
255 PHM_PlatformCaps_EnableDriverEVV))
256 result = atomctrl_calculate_voltage_evv_on_sclk(hwmgr,
257 VOLTAGE_TYPE_VDDC, sclk, vv_id, &vddc, i, true);
262 result = atomctrl_get_voltage_evv_on_sclk(hwmgr,
263 VOLTAGE_TYPE_VDDC, sclk,vv_id, &vddc);
265 /* need to make sure vddc is less than 2v or else, it could burn the ASIC. */
266 PP_ASSERT_WITH_CODE((vddc < 2000),
267 "Invalid VDDC value, greater than 2v!", result = -EINVAL;);
270 /* 1.15V is the default safe value for Fiji */
273 /* the voltage should not be zero nor equal to leakage ID */
274 if (vddc != 0 && vddc != vv_id) {
275 data->vddc_leakage.actual_voltage
276 [data->vddc_leakage.count] = vddc;
277 data->vddc_leakage.leakage_id
278 [data->vddc_leakage.count] = vv_id;
279 data->vddc_leakage.count++;
287 * Change virtual leakage voltage to actual value.
289 * @param hwmgr the address of the powerplay hardware manager.
290 * @param pointer to changing voltage
291 * @param pointer to leakage table
293 static void fiji_patch_with_vdd_leakage(struct pp_hwmgr *hwmgr,
294 uint16_t *voltage, struct fiji_leakage_voltage *leakage_table)
298 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
299 for (index = 0; index < leakage_table->count; index++) {
300 /* if this voltage matches a leakage voltage ID */
301 /* patch with actual leakage voltage */
302 if (leakage_table->leakage_id[index] == *voltage) {
303 *voltage = leakage_table->actual_voltage[index];
308 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
309 printk(KERN_ERR "Voltage value looks like a Leakage ID but it's not patched \n");
313 * Patch voltage lookup table by EVV leakages.
315 * @param hwmgr the address of the powerplay hardware manager.
316 * @param pointer to voltage lookup table
317 * @param pointer to leakage table
320 static int fiji_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
321 phm_ppt_v1_voltage_lookup_table *lookup_table,
322 struct fiji_leakage_voltage *leakage_table)
326 for (i = 0; i < lookup_table->count; i++)
327 fiji_patch_with_vdd_leakage(hwmgr,
328 &lookup_table->entries[i].us_vdd, leakage_table);
333 static int fiji_patch_clock_voltage_limits_with_vddc_leakage(
334 struct pp_hwmgr *hwmgr, struct fiji_leakage_voltage *leakage_table,
337 struct phm_ppt_v1_information *table_info =
338 (struct phm_ppt_v1_information *)(hwmgr->pptable);
339 fiji_patch_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
340 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
341 table_info->max_clock_voltage_on_dc.vddc;
345 static int fiji_patch_voltage_dependency_tables_with_lookup_table(
346 struct pp_hwmgr *hwmgr)
350 struct phm_ppt_v1_information *table_info =
351 (struct phm_ppt_v1_information *)(hwmgr->pptable);
353 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
354 table_info->vdd_dep_on_sclk;
355 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
356 table_info->vdd_dep_on_mclk;
357 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
358 table_info->mm_dep_table;
360 for (entryId = 0; entryId < sclk_table->count; ++entryId) {
361 voltageId = sclk_table->entries[entryId].vddInd;
362 sclk_table->entries[entryId].vddc =
363 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
366 for (entryId = 0; entryId < mclk_table->count; ++entryId) {
367 voltageId = mclk_table->entries[entryId].vddInd;
368 mclk_table->entries[entryId].vddc =
369 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
372 for (entryId = 0; entryId < mm_table->count; ++entryId) {
373 voltageId = mm_table->entries[entryId].vddcInd;
374 mm_table->entries[entryId].vddc =
375 table_info->vddc_lookup_table->entries[voltageId].us_vdd;
382 static int fiji_calc_voltage_dependency_tables(struct pp_hwmgr *hwmgr)
384 /* Need to determine if we need calculated voltage. */
388 static int fiji_calc_mm_voltage_dependency_table(struct pp_hwmgr *hwmgr)
390 /* Need to determine if we need calculated voltage from mm table. */
394 static int fiji_sort_lookup_table(struct pp_hwmgr *hwmgr,
395 struct phm_ppt_v1_voltage_lookup_table *lookup_table)
397 uint32_t table_size, i, j;
398 struct phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record;
399 table_size = lookup_table->count;
401 PP_ASSERT_WITH_CODE(0 != lookup_table->count,
402 "Lookup table is empty", return -EINVAL);
404 /* Sorting voltages */
405 for (i = 0; i < table_size - 1; i++) {
406 for (j = i + 1; j > 0; j--) {
407 if (lookup_table->entries[j].us_vdd <
408 lookup_table->entries[j - 1].us_vdd) {
409 tmp_voltage_lookup_record = lookup_table->entries[j - 1];
410 lookup_table->entries[j - 1] = lookup_table->entries[j];
411 lookup_table->entries[j] = tmp_voltage_lookup_record;
419 static int fiji_complete_dependency_tables(struct pp_hwmgr *hwmgr)
423 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
424 struct phm_ppt_v1_information *table_info =
425 (struct phm_ppt_v1_information *)(hwmgr->pptable);
427 tmp_result = fiji_patch_lookup_table_with_leakage(hwmgr,
428 table_info->vddc_lookup_table, &(data->vddc_leakage));
432 tmp_result = fiji_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
433 &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
437 tmp_result = fiji_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
441 tmp_result = fiji_calc_voltage_dependency_tables(hwmgr);
445 tmp_result = fiji_calc_mm_voltage_dependency_table(hwmgr);
449 tmp_result = fiji_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
456 static int fiji_set_private_data_based_on_pptable(struct pp_hwmgr *hwmgr)
458 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
459 struct phm_ppt_v1_information *table_info =
460 (struct phm_ppt_v1_information *)(hwmgr->pptable);
462 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
463 table_info->vdd_dep_on_sclk;
464 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
465 table_info->vdd_dep_on_mclk;
467 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table != NULL,
468 "VDD dependency on SCLK table is missing. \
469 This table is mandatory", return -EINVAL);
470 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
471 "VDD dependency on SCLK table has to have is missing. \
472 This table is mandatory", return -EINVAL);
474 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table != NULL,
475 "VDD dependency on MCLK table is missing. \
476 This table is mandatory", return -EINVAL);
477 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
478 "VDD dependency on MCLK table has to have is missing. \
479 This table is mandatory", return -EINVAL);
481 data->min_vddc_in_pptable = (uint16_t)allowed_sclk_vdd_table->entries[0].vddc;
482 data->max_vddc_in_pptable = (uint16_t)allowed_sclk_vdd_table->
483 entries[allowed_sclk_vdd_table->count - 1].vddc;
485 table_info->max_clock_voltage_on_ac.sclk =
486 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
487 table_info->max_clock_voltage_on_ac.mclk =
488 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
489 table_info->max_clock_voltage_on_ac.vddc =
490 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
491 table_info->max_clock_voltage_on_ac.vddci =
492 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
494 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
495 table_info->max_clock_voltage_on_ac.sclk;
496 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
497 table_info->max_clock_voltage_on_ac.mclk;
498 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
499 table_info->max_clock_voltage_on_ac.vddc;
500 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci =
501 table_info->max_clock_voltage_on_ac.vddci;
506 static uint16_t fiji_get_current_pcie_speed(struct pp_hwmgr *hwmgr)
508 uint32_t speedCntl = 0;
510 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
511 speedCntl = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__PCIE,
512 ixPCIE_LC_SPEED_CNTL);
513 return((uint16_t)PHM_GET_FIELD(speedCntl,
514 PCIE_LC_SPEED_CNTL, LC_CURRENT_DATA_RATE));
517 static int fiji_get_current_pcie_lane_number(struct pp_hwmgr *hwmgr)
521 /* mmPCIE_PORT_INDEX rename as mmPCIE_INDEX */
522 link_width = PHM_READ_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
523 PCIE_LC_LINK_WIDTH_CNTL, LC_LINK_WIDTH_RD);
525 PP_ASSERT_WITH_CODE((7 >= link_width),
526 "Invalid PCIe lane width!", return 0);
528 return decode_pcie_lane_width(link_width);
531 /** Patch the Boot State to match VBIOS boot clocks and voltage.
533 * @param hwmgr Pointer to the hardware manager.
534 * @param pPowerState The address of the PowerState instance being created.
537 static int fiji_patch_boot_state(struct pp_hwmgr *hwmgr,
538 struct pp_hw_power_state *hw_ps)
540 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
541 struct fiji_power_state *ps = (struct fiji_power_state *)hw_ps;
542 ATOM_FIRMWARE_INFO_V2_2 *fw_info;
545 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
547 /* First retrieve the Boot clocks and VDDC from the firmware info table.
548 * We assume here that fw_info is unchanged if this call fails.
550 fw_info = (ATOM_FIRMWARE_INFO_V2_2 *)cgs_atom_get_data_table(
551 hwmgr->device, index,
552 &size, &frev, &crev);
554 /* During a test, there is no firmware info table. */
557 /* Patch the state. */
558 data->vbios_boot_state.sclk_bootup_value =
559 le32_to_cpu(fw_info->ulDefaultEngineClock);
560 data->vbios_boot_state.mclk_bootup_value =
561 le32_to_cpu(fw_info->ulDefaultMemoryClock);
562 data->vbios_boot_state.mvdd_bootup_value =
563 le16_to_cpu(fw_info->usBootUpMVDDCVoltage);
564 data->vbios_boot_state.vddc_bootup_value =
565 le16_to_cpu(fw_info->usBootUpVDDCVoltage);
566 data->vbios_boot_state.vddci_bootup_value =
567 le16_to_cpu(fw_info->usBootUpVDDCIVoltage);
568 data->vbios_boot_state.pcie_gen_bootup_value =
569 fiji_get_current_pcie_speed(hwmgr);
570 data->vbios_boot_state.pcie_lane_bootup_value =
571 (uint16_t)fiji_get_current_pcie_lane_number(hwmgr);
573 /* set boot power state */
574 ps->performance_levels[0].memory_clock = data->vbios_boot_state.mclk_bootup_value;
575 ps->performance_levels[0].engine_clock = data->vbios_boot_state.sclk_bootup_value;
576 ps->performance_levels[0].pcie_gen = data->vbios_boot_state.pcie_gen_bootup_value;
577 ps->performance_levels[0].pcie_lane = data->vbios_boot_state.pcie_lane_bootup_value;
582 static int fiji_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
584 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
586 struct phm_ppt_v1_information *table_info =
587 (struct phm_ppt_v1_information *)(hwmgr->pptable);
591 data->dll_default_on = false;
592 data->sram_end = SMC_RAM_END;
594 for (i = 0; i < SMU73_MAX_LEVELS_GRAPHICS; i++)
595 data->activity_target[i] = FIJI_AT_DFLT;
597 data->vddc_vddci_delta = VDDC_VDDCI_DELTA;
599 data->mclk_activity_target = PPFIJI_MCLK_TARGETACTIVITY_DFLT;
600 data->mclk_dpm0_activity_target = 0xa;
602 data->sclk_dpm_key_disabled = 0;
603 data->mclk_dpm_key_disabled = 0;
604 data->pcie_dpm_key_disabled = 0;
606 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
607 PHM_PlatformCaps_UnTabledHardwareInterface);
608 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
609 PHM_PlatformCaps_TablelessHardwareInterface);
611 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
612 PHM_PlatformCaps_SclkDeepSleep);
614 data->gpio_debug = 0;
616 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
617 PHM_PlatformCaps_DynamicPatchPowerState);
619 /* need to set voltage control types before EVV patching */
620 data->voltage_control = FIJI_VOLTAGE_CONTROL_NONE;
621 data->vddci_control = FIJI_VOLTAGE_CONTROL_NONE;
622 data->mvdd_control = FIJI_VOLTAGE_CONTROL_NONE;
624 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
625 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2))
626 data->voltage_control = FIJI_VOLTAGE_CONTROL_BY_SVID2;
628 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
629 PHM_PlatformCaps_EnableMVDDControl))
630 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
631 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT))
632 data->mvdd_control = FIJI_VOLTAGE_CONTROL_BY_GPIO;
634 if (data->mvdd_control == FIJI_VOLTAGE_CONTROL_NONE)
635 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
636 PHM_PlatformCaps_EnableMVDDControl);
638 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
639 PHM_PlatformCaps_ControlVDDCI)) {
640 if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
641 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
642 data->vddci_control = FIJI_VOLTAGE_CONTROL_BY_GPIO;
643 else if (atomctrl_is_voltage_controled_by_gpio_v3(hwmgr,
644 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_SVID2))
645 data->vddci_control = FIJI_VOLTAGE_CONTROL_BY_SVID2;
648 if (data->vddci_control == FIJI_VOLTAGE_CONTROL_NONE)
649 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
650 PHM_PlatformCaps_ControlVDDCI);
652 if (table_info && table_info->cac_dtp_table->usClockStretchAmount)
653 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
654 PHM_PlatformCaps_ClockStretcher);
656 fiji_init_dpm_defaults(hwmgr);
658 /* Get leakage voltage based on leakage ID. */
659 fiji_get_evv_voltages(hwmgr);
661 /* Patch our voltage dependency table with actual leakage voltage
662 * We need to perform leakage translation before it's used by other functions
664 fiji_complete_dependency_tables(hwmgr);
666 /* Parse pptable data read from VBIOS */
667 fiji_set_private_data_based_on_pptable(hwmgr);
670 data->ulv.ulv_supported = true; /* ULV feature is enabled by default */
672 /* Initalize Dynamic State Adjustment Rule Settings */
673 result = tonga_initializa_dynamic_state_adjustment_rule_settings(hwmgr);
676 data->uvd_enabled = false;
677 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
678 PHM_PlatformCaps_EnableSMU7ThermalManagement);
679 data->vddc_phase_shed_control = false;
682 stay_in_boot = phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
683 PHM_PlatformCaps_StayInBootState);
686 struct cgs_system_info sys_info = {0};
688 data->is_tlu_enabled = 0;
689 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
690 FIJI_MAX_HARDWARE_POWERLEVELS;
691 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
692 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
694 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
695 PHM_PlatformCaps_FanSpeedInTableIsRPM);
697 if (table_info->cac_dtp_table->usDefaultTargetOperatingTemp &&
698 hwmgr->thermal_controller.
699 advanceFanControlParameters.ucFanControlMode) {
700 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanPWM =
701 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM;
702 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
703 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM;
704 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMinLimit =
705 table_info->cac_dtp_table->usOperatingTempMinLimit;
706 hwmgr->dyn_state.cac_dtp_table->usOperatingTempMaxLimit =
707 table_info->cac_dtp_table->usOperatingTempMaxLimit;
708 hwmgr->dyn_state.cac_dtp_table->usDefaultTargetOperatingTemp =
709 table_info->cac_dtp_table->usDefaultTargetOperatingTemp;
710 hwmgr->dyn_state.cac_dtp_table->usOperatingTempStep =
711 table_info->cac_dtp_table->usOperatingTempStep;
712 hwmgr->dyn_state.cac_dtp_table->usTargetOperatingTemp =
713 table_info->cac_dtp_table->usTargetOperatingTemp;
715 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
716 PHM_PlatformCaps_ODFuzzyFanControlSupport);
719 sys_info.size = sizeof(struct cgs_system_info);
720 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_GEN_INFO;
721 result = cgs_query_system_info(hwmgr->device, &sys_info);
723 data->pcie_gen_cap = 0x30007;
725 data->pcie_gen_cap = (uint32_t)sys_info.value;
726 if (data->pcie_gen_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
727 data->pcie_spc_cap = 20;
728 sys_info.size = sizeof(struct cgs_system_info);
729 sys_info.info_id = CGS_SYSTEM_INFO_PCIE_MLW;
730 result = cgs_query_system_info(hwmgr->device, &sys_info);
732 data->pcie_lane_cap = 0x2f0000;
734 data->pcie_lane_cap = (uint32_t)sys_info.value;
736 /* Ignore return value in here, we are cleaning up a mess. */
737 tonga_hwmgr_backend_fini(hwmgr);
744 * Read clock related registers.
746 * @param hwmgr the address of the powerplay hardware manager.
749 static int fiji_read_clock_registers(struct pp_hwmgr *hwmgr)
751 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
753 data->clock_registers.vCG_SPLL_FUNC_CNTL =
754 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
755 ixCG_SPLL_FUNC_CNTL);
756 data->clock_registers.vCG_SPLL_FUNC_CNTL_2 =
757 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
758 ixCG_SPLL_FUNC_CNTL_2);
759 data->clock_registers.vCG_SPLL_FUNC_CNTL_3 =
760 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
761 ixCG_SPLL_FUNC_CNTL_3);
762 data->clock_registers.vCG_SPLL_FUNC_CNTL_4 =
763 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
764 ixCG_SPLL_FUNC_CNTL_4);
765 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM =
766 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
767 ixCG_SPLL_SPREAD_SPECTRUM);
768 data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 =
769 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
770 ixCG_SPLL_SPREAD_SPECTRUM_2);
776 * Find out if memory is GDDR5.
778 * @param hwmgr the address of the powerplay hardware manager.
781 static int fiji_get_memory_type(struct pp_hwmgr *hwmgr)
783 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
786 temp = cgs_read_register(hwmgr->device, mmMC_SEQ_MISC0);
788 data->is_memory_gddr5 = (MC_SEQ_MISC0_GDDR5_VALUE ==
789 ((temp & MC_SEQ_MISC0_GDDR5_MASK) >>
790 MC_SEQ_MISC0_GDDR5_SHIFT));
796 * Enables Dynamic Power Management by SMC
798 * @param hwmgr the address of the powerplay hardware manager.
801 static int fiji_enable_acpi_power_management(struct pp_hwmgr *hwmgr)
803 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
804 GENERAL_PWRMGT, STATIC_PM_EN, 1);
810 * Initialize PowerGating States for different engines
812 * @param hwmgr the address of the powerplay hardware manager.
815 static int fiji_init_power_gate_state(struct pp_hwmgr *hwmgr)
817 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
819 data->uvd_power_gated = false;
820 data->vce_power_gated = false;
821 data->samu_power_gated = false;
822 data->acp_power_gated = false;
823 data->pg_acp_init = true;
828 static int fiji_init_sclk_threshold(struct pp_hwmgr *hwmgr)
830 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
831 data->low_sclk_interrupt_threshold = 0;
836 static int fiji_setup_asic_task(struct pp_hwmgr *hwmgr)
838 int tmp_result, result = 0;
840 tmp_result = fiji_read_clock_registers(hwmgr);
841 PP_ASSERT_WITH_CODE((0 == tmp_result),
842 "Failed to read clock registers!", result = tmp_result);
844 tmp_result = fiji_get_memory_type(hwmgr);
845 PP_ASSERT_WITH_CODE((0 == tmp_result),
846 "Failed to get memory type!", result = tmp_result);
848 tmp_result = fiji_enable_acpi_power_management(hwmgr);
849 PP_ASSERT_WITH_CODE((0 == tmp_result),
850 "Failed to enable ACPI power management!", result = tmp_result);
852 tmp_result = fiji_init_power_gate_state(hwmgr);
853 PP_ASSERT_WITH_CODE((0 == tmp_result),
854 "Failed to init power gate state!", result = tmp_result);
856 tmp_result = tonga_get_mc_microcode_version(hwmgr);
857 PP_ASSERT_WITH_CODE((0 == tmp_result),
858 "Failed to get MC microcode version!", result = tmp_result);
860 tmp_result = fiji_init_sclk_threshold(hwmgr);
861 PP_ASSERT_WITH_CODE((0 == tmp_result),
862 "Failed to init sclk threshold!", result = tmp_result);
868 * Checks if we want to support voltage control
870 * @param hwmgr the address of the powerplay hardware manager.
872 static bool fiji_voltage_control(const struct pp_hwmgr *hwmgr)
874 const struct fiji_hwmgr *data =
875 (const struct fiji_hwmgr *)(hwmgr->backend);
877 return (FIJI_VOLTAGE_CONTROL_NONE != data->voltage_control);
881 * Enable voltage control
883 * @param hwmgr the address of the powerplay hardware manager.
886 static int fiji_enable_voltage_control(struct pp_hwmgr *hwmgr)
888 /* enable voltage control */
889 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
890 GENERAL_PWRMGT, VOLT_PWRMGT_EN, 1);
896 * Remove repeated voltage values and create table with unique values.
898 * @param hwmgr the address of the powerplay hardware manager.
899 * @param vol_table the pointer to changing voltage table
900 * @return 0 in success
903 static int fiji_trim_voltage_table(struct pp_hwmgr *hwmgr,
904 struct pp_atomctrl_voltage_table *vol_table)
909 struct pp_atomctrl_voltage_table *table;
911 PP_ASSERT_WITH_CODE((NULL != vol_table),
912 "Voltage Table empty.", return -EINVAL);
913 table = kzalloc(sizeof(struct pp_atomctrl_voltage_table),
919 table->mask_low = vol_table->mask_low;
920 table->phase_delay = vol_table->phase_delay;
922 for (i = 0; i < vol_table->count; i++) {
923 vvalue = vol_table->entries[i].value;
926 for (j = 0; j < table->count; j++) {
927 if (vvalue == table->entries[j].value) {
934 table->entries[table->count].value = vvalue;
935 table->entries[table->count].smio_low =
936 vol_table->entries[i].smio_low;
941 memcpy(vol_table, table, sizeof(struct pp_atomctrl_voltage_table));
947 static int fiji_get_svi2_mvdd_voltage_table(struct pp_hwmgr *hwmgr,
948 phm_ppt_v1_clock_voltage_dependency_table *dep_table)
952 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
953 struct pp_atomctrl_voltage_table *vol_table = &(data->mvdd_voltage_table);
955 PP_ASSERT_WITH_CODE((0 != dep_table->count),
956 "Voltage Dependency Table empty.", return -EINVAL);
958 vol_table->mask_low = 0;
959 vol_table->phase_delay = 0;
960 vol_table->count = dep_table->count;
962 for (i = 0; i < dep_table->count; i++) {
963 vol_table->entries[i].value = dep_table->entries[i].mvdd;
964 vol_table->entries[i].smio_low = 0;
967 result = fiji_trim_voltage_table(hwmgr, vol_table);
968 PP_ASSERT_WITH_CODE((0 == result),
969 "Failed to trim MVDD table.", return result);
974 static int fiji_get_svi2_vddci_voltage_table(struct pp_hwmgr *hwmgr,
975 phm_ppt_v1_clock_voltage_dependency_table *dep_table)
979 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
980 struct pp_atomctrl_voltage_table *vol_table = &(data->vddci_voltage_table);
982 PP_ASSERT_WITH_CODE((0 != dep_table->count),
983 "Voltage Dependency Table empty.", return -EINVAL);
985 vol_table->mask_low = 0;
986 vol_table->phase_delay = 0;
987 vol_table->count = dep_table->count;
989 for (i = 0; i < dep_table->count; i++) {
990 vol_table->entries[i].value = dep_table->entries[i].vddci;
991 vol_table->entries[i].smio_low = 0;
994 result = fiji_trim_voltage_table(hwmgr, vol_table);
995 PP_ASSERT_WITH_CODE((0 == result),
996 "Failed to trim VDDCI table.", return result);
1001 static int fiji_get_svi2_vdd_voltage_table(struct pp_hwmgr *hwmgr,
1002 phm_ppt_v1_voltage_lookup_table *lookup_table)
1005 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1006 struct pp_atomctrl_voltage_table *vol_table = &(data->vddc_voltage_table);
1008 PP_ASSERT_WITH_CODE((0 != lookup_table->count),
1009 "Voltage Lookup Table empty.", return -EINVAL);
1011 vol_table->mask_low = 0;
1012 vol_table->phase_delay = 0;
1014 vol_table->count = lookup_table->count;
1016 for (i = 0; i < vol_table->count; i++) {
1017 vol_table->entries[i].value = lookup_table->entries[i].us_vdd;
1018 vol_table->entries[i].smio_low = 0;
1024 /* ---- Voltage Tables ----
1025 * If the voltage table would be bigger than
1026 * what will fit into the state table on
1027 * the SMC keep only the higher entries.
1029 static void fiji_trim_voltage_table_to_fit_state_table(struct pp_hwmgr *hwmgr,
1030 uint32_t max_vol_steps, struct pp_atomctrl_voltage_table *vol_table)
1032 unsigned int i, diff;
1034 if (vol_table->count <= max_vol_steps)
1037 diff = vol_table->count - max_vol_steps;
1039 for (i = 0; i < max_vol_steps; i++)
1040 vol_table->entries[i] = vol_table->entries[i + diff];
1042 vol_table->count = max_vol_steps;
1048 * Create Voltage Tables.
1050 * @param hwmgr the address of the powerplay hardware manager.
1053 static int fiji_construct_voltage_tables(struct pp_hwmgr *hwmgr)
1055 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1056 struct phm_ppt_v1_information *table_info =
1057 (struct phm_ppt_v1_information *)hwmgr->pptable;
1060 if (FIJI_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
1061 result = atomctrl_get_voltage_table_v3(hwmgr,
1062 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_GPIO_LUT,
1063 &(data->mvdd_voltage_table));
1064 PP_ASSERT_WITH_CODE((0 == result),
1065 "Failed to retrieve MVDD table.",
1067 } else if (FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
1068 result = fiji_get_svi2_mvdd_voltage_table(hwmgr,
1069 table_info->vdd_dep_on_mclk);
1070 PP_ASSERT_WITH_CODE((0 == result),
1071 "Failed to retrieve SVI2 MVDD table from dependancy table.",
1075 if (FIJI_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
1076 result = atomctrl_get_voltage_table_v3(hwmgr,
1077 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT,
1078 &(data->vddci_voltage_table));
1079 PP_ASSERT_WITH_CODE((0 == result),
1080 "Failed to retrieve VDDCI table.",
1082 } else if (FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
1083 result = fiji_get_svi2_vddci_voltage_table(hwmgr,
1084 table_info->vdd_dep_on_mclk);
1085 PP_ASSERT_WITH_CODE((0 == result),
1086 "Failed to retrieve SVI2 VDDCI table from dependancy table.",
1090 if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
1091 result = fiji_get_svi2_vdd_voltage_table(hwmgr,
1092 table_info->vddc_lookup_table);
1093 PP_ASSERT_WITH_CODE((0 == result),
1094 "Failed to retrieve SVI2 VDDC table from lookup table.",
1098 PP_ASSERT_WITH_CODE(
1099 (data->vddc_voltage_table.count <= (SMU73_MAX_LEVELS_VDDC)),
1100 "Too many voltage values for VDDC. Trimming to fit state table.",
1101 fiji_trim_voltage_table_to_fit_state_table(hwmgr,
1102 SMU73_MAX_LEVELS_VDDC, &(data->vddc_voltage_table)));
1104 PP_ASSERT_WITH_CODE(
1105 (data->vddci_voltage_table.count <= (SMU73_MAX_LEVELS_VDDCI)),
1106 "Too many voltage values for VDDCI. Trimming to fit state table.",
1107 fiji_trim_voltage_table_to_fit_state_table(hwmgr,
1108 SMU73_MAX_LEVELS_VDDCI, &(data->vddci_voltage_table)));
1110 PP_ASSERT_WITH_CODE(
1111 (data->mvdd_voltage_table.count <= (SMU73_MAX_LEVELS_MVDD)),
1112 "Too many voltage values for MVDD. Trimming to fit state table.",
1113 fiji_trim_voltage_table_to_fit_state_table(hwmgr,
1114 SMU73_MAX_LEVELS_MVDD, &(data->mvdd_voltage_table)));
1119 static int fiji_initialize_mc_reg_table(struct pp_hwmgr *hwmgr)
1121 /* Program additional LP registers
1122 * that are no longer programmed by VBIOS
1124 cgs_write_register(hwmgr->device, mmMC_SEQ_RAS_TIMING_LP,
1125 cgs_read_register(hwmgr->device, mmMC_SEQ_RAS_TIMING));
1126 cgs_write_register(hwmgr->device, mmMC_SEQ_CAS_TIMING_LP,
1127 cgs_read_register(hwmgr->device, mmMC_SEQ_CAS_TIMING));
1128 cgs_write_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2_LP,
1129 cgs_read_register(hwmgr->device, mmMC_SEQ_MISC_TIMING2));
1130 cgs_write_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1_LP,
1131 cgs_read_register(hwmgr->device, mmMC_SEQ_WR_CTL_D1));
1132 cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0_LP,
1133 cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D0));
1134 cgs_write_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1_LP,
1135 cgs_read_register(hwmgr->device, mmMC_SEQ_RD_CTL_D1));
1136 cgs_write_register(hwmgr->device, mmMC_SEQ_PMG_TIMING_LP,
1137 cgs_read_register(hwmgr->device, mmMC_SEQ_PMG_TIMING));
1143 * Programs static screed detection parameters
1145 * @param hwmgr the address of the powerplay hardware manager.
1148 static int fiji_program_static_screen_threshold_parameters(
1149 struct pp_hwmgr *hwmgr)
1151 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1153 /* Set static screen threshold unit */
1154 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1155 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD_UNIT,
1156 data->static_screen_threshold_unit);
1157 /* Set static screen threshold */
1158 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1159 CG_STATIC_SCREEN_PARAMETER, STATIC_SCREEN_THRESHOLD,
1160 data->static_screen_threshold);
1166 * Setup display gap for glitch free memory clock switching.
1168 * @param hwmgr the address of the powerplay hardware manager.
1171 static int fiji_enable_display_gap(struct pp_hwmgr *hwmgr)
1173 uint32_t displayGap =
1174 cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1175 ixCG_DISPLAY_GAP_CNTL);
1177 displayGap = PHM_SET_FIELD(displayGap, CG_DISPLAY_GAP_CNTL,
1178 DISP_GAP, DISPLAY_GAP_IGNORE);
1180 displayGap = PHM_SET_FIELD(displayGap, CG_DISPLAY_GAP_CNTL,
1181 DISP_GAP_MCHG, DISPLAY_GAP_VBLANK);
1183 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1184 ixCG_DISPLAY_GAP_CNTL, displayGap);
1190 * Programs activity state transition voting clients
1192 * @param hwmgr the address of the powerplay hardware manager.
1195 static int fiji_program_voting_clients(struct pp_hwmgr *hwmgr)
1197 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1199 /* Clear reset for voting clients before enabling DPM */
1200 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1201 SCLK_PWRMGT_CNTL, RESET_SCLK_CNT, 0);
1202 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
1203 SCLK_PWRMGT_CNTL, RESET_BUSY_CNT, 0);
1205 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1206 ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0);
1207 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1208 ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1);
1209 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1210 ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2);
1211 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1212 ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3);
1213 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1214 ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4);
1215 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1216 ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5);
1217 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1218 ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6);
1219 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1220 ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7);
1226 * Get the location of various tables inside the FW image.
1228 * @param hwmgr the address of the powerplay hardware manager.
1231 static int fiji_process_firmware_header(struct pp_hwmgr *hwmgr)
1233 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1234 struct fiji_smumgr *smu_data = (struct fiji_smumgr *)(hwmgr->smumgr->backend);
1239 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1240 SMU7_FIRMWARE_HEADER_LOCATION +
1241 offsetof(SMU73_Firmware_Header, DpmTable),
1242 &tmp, data->sram_end);
1245 data->dpm_table_start = tmp;
1247 error |= (0 != result);
1249 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1250 SMU7_FIRMWARE_HEADER_LOCATION +
1251 offsetof(SMU73_Firmware_Header, SoftRegisters),
1252 &tmp, data->sram_end);
1255 data->soft_regs_start = tmp;
1256 smu_data->soft_regs_start = tmp;
1259 error |= (0 != result);
1261 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1262 SMU7_FIRMWARE_HEADER_LOCATION +
1263 offsetof(SMU73_Firmware_Header, mcRegisterTable),
1264 &tmp, data->sram_end);
1267 data->mc_reg_table_start = tmp;
1269 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1270 SMU7_FIRMWARE_HEADER_LOCATION +
1271 offsetof(SMU73_Firmware_Header, FanTable),
1272 &tmp, data->sram_end);
1275 data->fan_table_start = tmp;
1277 error |= (0 != result);
1279 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1280 SMU7_FIRMWARE_HEADER_LOCATION +
1281 offsetof(SMU73_Firmware_Header, mcArbDramTimingTable),
1282 &tmp, data->sram_end);
1285 data->arb_table_start = tmp;
1287 error |= (0 != result);
1289 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
1290 SMU7_FIRMWARE_HEADER_LOCATION +
1291 offsetof(SMU73_Firmware_Header, Version),
1292 &tmp, data->sram_end);
1295 hwmgr->microcode_version_info.SMC = tmp;
1297 error |= (0 != result);
1299 return error ? -1 : 0;
1302 /* Copy one arb setting to another and then switch the active set.
1303 * arb_src and arb_dest is one of the MC_CG_ARB_FREQ_Fx constants.
1305 static int fiji_copy_and_switch_arb_sets(struct pp_hwmgr *hwmgr,
1306 uint32_t arb_src, uint32_t arb_dest)
1308 uint32_t mc_arb_dram_timing;
1309 uint32_t mc_arb_dram_timing2;
1310 uint32_t burst_time;
1311 uint32_t mc_cg_config;
1314 case MC_CG_ARB_FREQ_F0:
1315 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
1316 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
1317 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0);
1319 case MC_CG_ARB_FREQ_F1:
1320 mc_arb_dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1);
1321 mc_arb_dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1);
1322 burst_time = PHM_READ_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1);
1329 case MC_CG_ARB_FREQ_F0:
1330 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing);
1331 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2);
1332 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE0, burst_time);
1334 case MC_CG_ARB_FREQ_F1:
1335 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing);
1336 cgs_write_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2);
1337 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_BURST_TIME, STATE1, burst_time);
1343 mc_cg_config = cgs_read_register(hwmgr->device, mmMC_CG_CONFIG);
1344 mc_cg_config |= 0x0000000F;
1345 cgs_write_register(hwmgr->device, mmMC_CG_CONFIG, mc_cg_config);
1346 PHM_WRITE_FIELD(hwmgr->device, MC_ARB_CG, CG_ARB_REQ, arb_dest);
1352 * Initial switch from ARB F0->F1
1354 * @param hwmgr the address of the powerplay hardware manager.
1356 * This function is to be called from the SetPowerState table.
1358 static int fiji_initial_switch_from_arbf0_to_f1(struct pp_hwmgr *hwmgr)
1360 return fiji_copy_and_switch_arb_sets(hwmgr,
1361 MC_CG_ARB_FREQ_F0, MC_CG_ARB_FREQ_F1);
1364 static int fiji_reset_single_dpm_table(struct pp_hwmgr *hwmgr,
1365 struct fiji_single_dpm_table *dpm_table, uint32_t count)
1368 PP_ASSERT_WITH_CODE(count <= MAX_REGULAR_DPM_NUMBER,
1369 "Fatal error, can not set up single DPM table entries "
1370 "to exceed max number!",);
1372 dpm_table->count = count;
1373 for (i = 0; i < MAX_REGULAR_DPM_NUMBER; i++)
1374 dpm_table->dpm_levels[i].enabled = false;
1379 static void fiji_setup_pcie_table_entry(
1380 struct fiji_single_dpm_table *dpm_table,
1381 uint32_t index, uint32_t pcie_gen,
1382 uint32_t pcie_lanes)
1384 dpm_table->dpm_levels[index].value = pcie_gen;
1385 dpm_table->dpm_levels[index].param1 = pcie_lanes;
1386 dpm_table->dpm_levels[index].enabled = 1;
1389 static int fiji_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
1391 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1392 struct phm_ppt_v1_information *table_info =
1393 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1394 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
1395 uint32_t i, max_entry;
1397 PP_ASSERT_WITH_CODE((data->use_pcie_performance_levels ||
1398 data->use_pcie_power_saving_levels), "No pcie performance levels!",
1401 if (data->use_pcie_performance_levels &&
1402 !data->use_pcie_power_saving_levels) {
1403 data->pcie_gen_power_saving = data->pcie_gen_performance;
1404 data->pcie_lane_power_saving = data->pcie_lane_performance;
1405 } else if (!data->use_pcie_performance_levels &&
1406 data->use_pcie_power_saving_levels) {
1407 data->pcie_gen_performance = data->pcie_gen_power_saving;
1408 data->pcie_lane_performance = data->pcie_lane_power_saving;
1411 fiji_reset_single_dpm_table(hwmgr,
1412 &data->dpm_table.pcie_speed_table, SMU73_MAX_LEVELS_LINK);
1414 if (pcie_table != NULL) {
1415 /* max_entry is used to make sure we reserve one PCIE level
1416 * for boot level (fix for A+A PSPP issue).
1417 * If PCIE table from PPTable have ULV entry + 8 entries,
1418 * then ignore the last entry.*/
1419 max_entry = (SMU73_MAX_LEVELS_LINK < pcie_table->count) ?
1420 SMU73_MAX_LEVELS_LINK : pcie_table->count;
1421 for (i = 1; i < max_entry; i++) {
1422 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, i - 1,
1423 get_pcie_gen_support(data->pcie_gen_cap,
1424 pcie_table->entries[i].gen_speed),
1425 get_pcie_lane_support(data->pcie_lane_cap,
1426 pcie_table->entries[i].lane_width));
1428 data->dpm_table.pcie_speed_table.count = max_entry - 1;
1430 /* Hardcode Pcie Table */
1431 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 0,
1432 get_pcie_gen_support(data->pcie_gen_cap,
1434 get_pcie_lane_support(data->pcie_lane_cap,
1436 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 1,
1437 get_pcie_gen_support(data->pcie_gen_cap,
1439 get_pcie_lane_support(data->pcie_lane_cap,
1441 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 2,
1442 get_pcie_gen_support(data->pcie_gen_cap,
1444 get_pcie_lane_support(data->pcie_lane_cap,
1446 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 3,
1447 get_pcie_gen_support(data->pcie_gen_cap,
1449 get_pcie_lane_support(data->pcie_lane_cap,
1451 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 4,
1452 get_pcie_gen_support(data->pcie_gen_cap,
1454 get_pcie_lane_support(data->pcie_lane_cap,
1456 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table, 5,
1457 get_pcie_gen_support(data->pcie_gen_cap,
1459 get_pcie_lane_support(data->pcie_lane_cap,
1462 data->dpm_table.pcie_speed_table.count = 6;
1464 /* Populate last level for boot PCIE level, but do not increment count. */
1465 fiji_setup_pcie_table_entry(&data->dpm_table.pcie_speed_table,
1466 data->dpm_table.pcie_speed_table.count,
1467 get_pcie_gen_support(data->pcie_gen_cap,
1469 get_pcie_lane_support(data->pcie_lane_cap,
1476 * This function is to initalize all DPM state tables
1477 * for SMU7 based on the dependency table.
1478 * Dynamic state patching function will then trim these
1479 * state tables to the allowed range based
1480 * on the power policy or external client requests,
1481 * such as UVD request, etc.
1483 static int fiji_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
1485 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1486 struct phm_ppt_v1_information *table_info =
1487 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1490 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table =
1491 table_info->vdd_dep_on_sclk;
1492 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
1493 table_info->vdd_dep_on_mclk;
1495 PP_ASSERT_WITH_CODE(dep_sclk_table != NULL,
1496 "SCLK dependency table is missing. This table is mandatory",
1498 PP_ASSERT_WITH_CODE(dep_sclk_table->count >= 1,
1499 "SCLK dependency table has to have is missing. "
1500 "This table is mandatory",
1503 PP_ASSERT_WITH_CODE(dep_mclk_table != NULL,
1504 "MCLK dependency table is missing. This table is mandatory",
1506 PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
1507 "MCLK dependency table has to have is missing. "
1508 "This table is mandatory",
1511 /* clear the state table to reset everything to default */
1512 fiji_reset_single_dpm_table(hwmgr,
1513 &data->dpm_table.sclk_table, SMU73_MAX_LEVELS_GRAPHICS);
1514 fiji_reset_single_dpm_table(hwmgr,
1515 &data->dpm_table.mclk_table, SMU73_MAX_LEVELS_MEMORY);
1517 /* Initialize Sclk DPM table based on allow Sclk values */
1518 data->dpm_table.sclk_table.count = 0;
1519 for (i = 0; i < dep_sclk_table->count; i++) {
1520 if (i == 0 || data->dpm_table.sclk_table.dpm_levels
1521 [data->dpm_table.sclk_table.count - 1].value !=
1522 dep_sclk_table->entries[i].clk) {
1523 data->dpm_table.sclk_table.dpm_levels
1524 [data->dpm_table.sclk_table.count].value =
1525 dep_sclk_table->entries[i].clk;
1526 data->dpm_table.sclk_table.dpm_levels
1527 [data->dpm_table.sclk_table.count].enabled =
1528 (i == 0) ? true : false;
1529 data->dpm_table.sclk_table.count++;
1533 /* Initialize Mclk DPM table based on allow Mclk values */
1534 data->dpm_table.mclk_table.count = 0;
1535 for (i=0; i<dep_mclk_table->count; i++) {
1536 if ( i==0 || data->dpm_table.mclk_table.dpm_levels
1537 [data->dpm_table.mclk_table.count - 1].value !=
1538 dep_mclk_table->entries[i].clk) {
1539 data->dpm_table.mclk_table.dpm_levels
1540 [data->dpm_table.mclk_table.count].value =
1541 dep_mclk_table->entries[i].clk;
1542 data->dpm_table.mclk_table.dpm_levels
1543 [data->dpm_table.mclk_table.count].enabled =
1544 (i == 0) ? true : false;
1545 data->dpm_table.mclk_table.count++;
1549 /* setup PCIE gen speed levels */
1550 fiji_setup_default_pcie_table(hwmgr);
1552 /* save a copy of the default DPM table */
1553 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
1554 sizeof(struct fiji_dpm_table));
1560 * @brief PhwFiji_GetVoltageOrder
1561 * Returns index of requested voltage record in lookup(table)
1562 * @param lookup_table - lookup list to search in
1563 * @param voltage - voltage to look for
1564 * @return 0 on success
1566 uint8_t fiji_get_voltage_index(
1567 struct phm_ppt_v1_voltage_lookup_table *lookup_table, uint16_t voltage)
1569 uint8_t count = (uint8_t) (lookup_table->count);
1572 PP_ASSERT_WITH_CODE((NULL != lookup_table),
1573 "Lookup Table empty.", return 0);
1574 PP_ASSERT_WITH_CODE((0 != count),
1575 "Lookup Table empty.", return 0);
1577 for (i = 0; i < lookup_table->count; i++) {
1578 /* find first voltage equal or bigger than requested */
1579 if (lookup_table->entries[i].us_vdd >= voltage)
1582 /* voltage is bigger than max voltage in the table */
1587 * Preparation of vddc and vddgfx CAC tables for SMC.
1589 * @param hwmgr the address of the hardware manager
1590 * @param table the SMC DPM table structure to be populated
1593 static int fiji_populate_cac_table(struct pp_hwmgr *hwmgr,
1594 struct SMU73_Discrete_DpmTable *table)
1599 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1600 struct phm_ppt_v1_information *table_info =
1601 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1602 struct phm_ppt_v1_voltage_lookup_table *lookup_table =
1603 table_info->vddc_lookup_table;
1604 /* tables is already swapped, so in order to use the value from it,
1605 * we need to swap it back.
1606 * We are populating vddc CAC data to BapmVddc table
1607 * in split and merged mode
1609 for( count = 0; count<lookup_table->count; count++) {
1610 index = fiji_get_voltage_index(lookup_table,
1611 data->vddc_voltage_table.entries[count].value);
1612 table->BapmVddcVidLoSidd[count] = (uint8_t) ((6200 -
1613 (lookup_table->entries[index].us_cac_low *
1614 VOLTAGE_SCALE)) / 25);
1615 table->BapmVddcVidHiSidd[count] = (uint8_t) ((6200 -
1616 (lookup_table->entries[index].us_cac_high *
1617 VOLTAGE_SCALE)) / 25);
1624 * Preparation of voltage tables for SMC.
1626 * @param hwmgr the address of the hardware manager
1627 * @param table the SMC DPM table structure to be populated
1631 int fiji_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
1632 struct SMU73_Discrete_DpmTable *table)
1636 result = fiji_populate_cac_table(hwmgr, table);
1637 PP_ASSERT_WITH_CODE(0 == result,
1638 "can not populate CAC voltage tables to SMC",
1644 static int fiji_populate_ulv_level(struct pp_hwmgr *hwmgr,
1645 struct SMU73_Discrete_Ulv *state)
1648 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1649 struct phm_ppt_v1_information *table_info =
1650 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1652 state->CcPwrDynRm = 0;
1653 state->CcPwrDynRm1 = 0;
1655 state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset;
1656 state->VddcOffsetVid = (uint8_t)( table_info->us_ulv_voltage_offset *
1657 VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1 );
1659 state->VddcPhase = (data->vddc_phase_shed_control) ? 0 : 1;
1662 CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm);
1663 CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1);
1664 CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset);
1669 static int fiji_populate_ulv_state(struct pp_hwmgr *hwmgr,
1670 struct SMU73_Discrete_DpmTable *table)
1672 return fiji_populate_ulv_level(hwmgr, &table->Ulv);
1675 static int32_t fiji_get_dpm_level_enable_mask_value(
1676 struct fiji_single_dpm_table* dpm_table)
1681 for (i = dpm_table->count; i > 0; i--) {
1683 if (dpm_table->dpm_levels[i - 1].enabled)
1691 static int fiji_populate_smc_link_level(struct pp_hwmgr *hwmgr,
1692 struct SMU73_Discrete_DpmTable *table)
1694 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1695 struct fiji_dpm_table *dpm_table = &data->dpm_table;
1698 /* Index (dpm_table->pcie_speed_table.count)
1699 * is reserved for PCIE boot level. */
1700 for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
1701 table->LinkLevel[i].PcieGenSpeed =
1702 (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
1703 table->LinkLevel[i].PcieLaneCount = (uint8_t)encode_pcie_lane_width(
1704 dpm_table->pcie_speed_table.dpm_levels[i].param1);
1705 table->LinkLevel[i].EnabledForActivity = 1;
1706 table->LinkLevel[i].SPC = (uint8_t)(data->pcie_spc_cap & 0xff);
1707 table->LinkLevel[i].DownThreshold = PP_HOST_TO_SMC_UL(5);
1708 table->LinkLevel[i].UpThreshold = PP_HOST_TO_SMC_UL(30);
1711 data->smc_state_table.LinkLevelCount =
1712 (uint8_t)dpm_table->pcie_speed_table.count;
1713 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
1714 fiji_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
1720 * Calculates the SCLK dividers using the provided engine clock
1722 * @param hwmgr the address of the hardware manager
1723 * @param clock the engine clock to use to populate the structure
1724 * @param sclk the SMC SCLK structure to be populated
1726 static int fiji_calculate_sclk_params(struct pp_hwmgr *hwmgr,
1727 uint32_t clock, struct SMU73_Discrete_GraphicsLevel *sclk)
1729 const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1730 struct pp_atomctrl_clock_dividers_vi dividers;
1731 uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
1732 uint32_t spll_func_cntl_3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
1733 uint32_t spll_func_cntl_4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
1734 uint32_t cg_spll_spread_spectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
1735 uint32_t cg_spll_spread_spectrum_2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
1737 uint32_t ref_divider;
1741 /* get the engine clock dividers for this clock value */
1742 result = atomctrl_get_engine_pll_dividers_vi(hwmgr, clock, ÷rs);
1744 PP_ASSERT_WITH_CODE(result == 0,
1745 "Error retrieving Engine Clock dividers from VBIOS.",
1748 /* To get FBDIV we need to multiply this by 16384 and divide it by Fref. */
1749 ref_clock = atomctrl_get_reference_clock(hwmgr);
1750 ref_divider = 1 + dividers.uc_pll_ref_div;
1752 /* low 14 bits is fraction and high 12 bits is divider */
1753 fbdiv = dividers.ul_fb_div.ul_fb_divider & 0x3FFFFFF;
1755 /* SPLL_FUNC_CNTL setup */
1756 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
1757 SPLL_REF_DIV, dividers.uc_pll_ref_div);
1758 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
1759 SPLL_PDIV_A, dividers.uc_pll_post_div);
1761 /* SPLL_FUNC_CNTL_3 setup*/
1762 spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3, CG_SPLL_FUNC_CNTL_3,
1763 SPLL_FB_DIV, fbdiv);
1765 /* set to use fractional accumulation*/
1766 spll_func_cntl_3 = PHM_SET_FIELD(spll_func_cntl_3, CG_SPLL_FUNC_CNTL_3,
1769 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1770 PHM_PlatformCaps_EngineSpreadSpectrumSupport)) {
1771 struct pp_atomctrl_internal_ss_info ssInfo;
1773 uint32_t vco_freq = clock * dividers.uc_pll_post_div;
1774 if (!atomctrl_get_engine_clock_spread_spectrum(hwmgr,
1775 vco_freq, &ssInfo)) {
1777 * ss_info.speed_spectrum_percentage -- in unit of 0.01%
1778 * ss_info.speed_spectrum_rate -- in unit of khz
1780 * clks = reference_clock * 10 / (REFDIV + 1) / speed_spectrum_rate / 2
1782 uint32_t clk_s = ref_clock * 5 /
1783 (ref_divider * ssInfo.speed_spectrum_rate);
1784 /* clkv = 2 * D * fbdiv / NS */
1785 uint32_t clk_v = 4 * ssInfo.speed_spectrum_percentage *
1786 fbdiv / (clk_s * 10000);
1788 cg_spll_spread_spectrum = PHM_SET_FIELD(cg_spll_spread_spectrum,
1789 CG_SPLL_SPREAD_SPECTRUM, CLKS, clk_s);
1790 cg_spll_spread_spectrum = PHM_SET_FIELD(cg_spll_spread_spectrum,
1791 CG_SPLL_SPREAD_SPECTRUM, SSEN, 1);
1792 cg_spll_spread_spectrum_2 = PHM_SET_FIELD(cg_spll_spread_spectrum_2,
1793 CG_SPLL_SPREAD_SPECTRUM_2, CLKV, clk_v);
1797 sclk->SclkFrequency = clock;
1798 sclk->CgSpllFuncCntl3 = spll_func_cntl_3;
1799 sclk->CgSpllFuncCntl4 = spll_func_cntl_4;
1800 sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum;
1801 sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2;
1802 sclk->SclkDid = (uint8_t)dividers.pll_post_divider;
1807 static uint16_t fiji_find_closest_vddci(struct pp_hwmgr *hwmgr, uint16_t vddci)
1810 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1811 struct pp_atomctrl_voltage_table *vddci_table =
1812 &(data->vddci_voltage_table);
1814 for (i = 0; i < vddci_table->count; i++) {
1815 if (vddci_table->entries[i].value >= vddci)
1816 return vddci_table->entries[i].value;
1819 PP_ASSERT_WITH_CODE(false,
1820 "VDDCI is larger than max VDDCI in VDDCI Voltage Table!",
1821 return vddci_table->entries[i].value);
1824 static int fiji_get_dependency_volt_by_clk(struct pp_hwmgr *hwmgr,
1825 struct phm_ppt_v1_clock_voltage_dependency_table* dep_table,
1826 uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
1830 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1832 *voltage = *mvdd = 0;
1834 /* clock - voltage dependency table is empty table */
1835 if (dep_table->count == 0)
1838 for (i = 0; i < dep_table->count; i++) {
1839 /* find first sclk bigger than request */
1840 if (dep_table->entries[i].clk >= clock) {
1841 *voltage |= (dep_table->entries[i].vddc *
1842 VOLTAGE_SCALE) << VDDC_SHIFT;
1843 if (FIJI_VOLTAGE_CONTROL_NONE == data->vddci_control)
1844 *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1845 VOLTAGE_SCALE) << VDDCI_SHIFT;
1846 else if (dep_table->entries[i].vddci)
1847 *voltage |= (dep_table->entries[i].vddci *
1848 VOLTAGE_SCALE) << VDDCI_SHIFT;
1850 vddci = fiji_find_closest_vddci(hwmgr,
1851 (dep_table->entries[i].vddc -
1852 (uint16_t)data->vddc_vddci_delta));
1853 *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1856 if (FIJI_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1857 *mvdd = data->vbios_boot_state.mvdd_bootup_value *
1859 else if (dep_table->entries[i].mvdd)
1860 *mvdd = (uint32_t) dep_table->entries[i].mvdd *
1863 *voltage |= 1 << PHASES_SHIFT;
1868 /* sclk is bigger than max sclk in the dependence table */
1869 *voltage |= (dep_table->entries[i - 1].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
1871 if (FIJI_VOLTAGE_CONTROL_NONE == data->vddci_control)
1872 *voltage |= (data->vbios_boot_state.vddci_bootup_value *
1873 VOLTAGE_SCALE) << VDDCI_SHIFT;
1874 else if (dep_table->entries[i-1].vddci) {
1875 vddci = fiji_find_closest_vddci(hwmgr,
1876 (dep_table->entries[i].vddc -
1877 (uint16_t)data->vddc_vddci_delta));
1878 *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1881 if (FIJI_VOLTAGE_CONTROL_NONE == data->mvdd_control)
1882 *mvdd = data->vbios_boot_state.mvdd_bootup_value * VOLTAGE_SCALE;
1883 else if (dep_table->entries[i].mvdd)
1884 *mvdd = (uint32_t) dep_table->entries[i - 1].mvdd * VOLTAGE_SCALE;
1889 static uint8_t fiji_get_sleep_divider_id_from_clock(struct pp_hwmgr *hwmgr,
1890 uint32_t clock, uint32_t clock_insr)
1894 uint32_t min = clock_insr > 2500 ? clock_insr : 2500;
1896 PP_ASSERT_WITH_CODE((clock >= min), "Engine clock can't satisfy stutter requirement!", return 0);
1897 for (i = FIJI_MAX_DEEPSLEEP_DIVIDER_ID; ; i--) {
1898 temp = clock / (1UL << i);
1900 if (temp >= min || i == 0)
1906 * Populates single SMC SCLK structure using the provided engine clock
1908 * @param hwmgr the address of the hardware manager
1909 * @param clock the engine clock to use to populate the structure
1910 * @param sclk the SMC SCLK structure to be populated
1913 static int fiji_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
1914 uint32_t clock, uint16_t sclk_al_threshold,
1915 struct SMU73_Discrete_GraphicsLevel *level)
1918 /* PP_Clocks minClocks; */
1919 uint32_t threshold, mvdd;
1920 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1921 struct phm_ppt_v1_information *table_info =
1922 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1924 result = fiji_calculate_sclk_params(hwmgr, clock, level);
1926 /* populate graphics levels */
1927 result = fiji_get_dependency_volt_by_clk(hwmgr,
1928 table_info->vdd_dep_on_sclk, clock,
1929 &level->MinVoltage, &mvdd);
1930 PP_ASSERT_WITH_CODE((0 == result),
1931 "can not find VDDC voltage value for "
1932 "VDDC engine clock dependency table",
1935 level->SclkFrequency = clock;
1936 level->ActivityLevel = sclk_al_threshold;
1937 level->CcPwrDynRm = 0;
1938 level->CcPwrDynRm1 = 0;
1939 level->EnabledForActivity = 0;
1940 level->EnabledForThrottle = 1;
1942 level->DownHyst = 0;
1943 level->VoltageDownHyst = 0;
1944 level->PowerThrottle = 0;
1946 threshold = clock * data->fast_watermark_threshold / 100;
1949 data->display_timing.min_clock_in_sr = hwmgr->display_config.min_core_set_clock_in_sr;
1951 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
1952 level->DeepSleepDivId = fiji_get_sleep_divider_id_from_clock(hwmgr, clock,
1953 hwmgr->display_config.min_core_set_clock_in_sr);
1956 /* Default to slow, highest DPM level will be
1957 * set to PPSMC_DISPLAY_WATERMARK_LOW later.
1959 level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
1961 CONVERT_FROM_HOST_TO_SMC_UL(level->MinVoltage);
1962 CONVERT_FROM_HOST_TO_SMC_UL(level->SclkFrequency);
1963 CONVERT_FROM_HOST_TO_SMC_US(level->ActivityLevel);
1964 CONVERT_FROM_HOST_TO_SMC_UL(level->CgSpllFuncCntl3);
1965 CONVERT_FROM_HOST_TO_SMC_UL(level->CgSpllFuncCntl4);
1966 CONVERT_FROM_HOST_TO_SMC_UL(level->SpllSpreadSpectrum);
1967 CONVERT_FROM_HOST_TO_SMC_UL(level->SpllSpreadSpectrum2);
1968 CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm);
1969 CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm1);
1974 * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
1976 * @param hwmgr the address of the hardware manager
1978 static int fiji_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
1980 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
1981 struct fiji_dpm_table *dpm_table = &data->dpm_table;
1982 struct phm_ppt_v1_information *table_info =
1983 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1984 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
1985 uint8_t pcie_entry_cnt = (uint8_t) data->dpm_table.pcie_speed_table.count;
1987 uint32_t array = data->dpm_table_start +
1988 offsetof(SMU73_Discrete_DpmTable, GraphicsLevel);
1989 uint32_t array_size = sizeof(struct SMU73_Discrete_GraphicsLevel) *
1990 SMU73_MAX_LEVELS_GRAPHICS;
1991 struct SMU73_Discrete_GraphicsLevel *levels =
1992 data->smc_state_table.GraphicsLevel;
1993 uint32_t i, max_entry;
1994 uint8_t hightest_pcie_level_enabled = 0,
1995 lowest_pcie_level_enabled = 0,
1996 mid_pcie_level_enabled = 0,
1999 for (i = 0; i < dpm_table->sclk_table.count; i++) {
2000 result = fiji_populate_single_graphic_level(hwmgr,
2001 dpm_table->sclk_table.dpm_levels[i].value,
2002 (uint16_t)data->activity_target[i],
2007 /* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */
2009 levels[i].DeepSleepDivId = 0;
2012 /* Only enable level 0 for now.*/
2013 levels[0].EnabledForActivity = 1;
2015 /* set highest level watermark to high */
2016 levels[dpm_table->sclk_table.count - 1].DisplayWatermark =
2017 PPSMC_DISPLAY_WATERMARK_HIGH;
2019 data->smc_state_table.GraphicsDpmLevelCount =
2020 (uint8_t)dpm_table->sclk_table.count;
2021 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
2022 fiji_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
2024 if (pcie_table != NULL) {
2025 PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt),
2026 "There must be 1 or more PCIE levels defined in PPTable.",
2028 max_entry = pcie_entry_cnt - 1;
2029 for (i = 0; i < dpm_table->sclk_table.count; i++)
2030 levels[i].pcieDpmLevel =
2031 (uint8_t) ((i < max_entry)? i : max_entry);
2033 while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
2034 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2035 (1 << (hightest_pcie_level_enabled + 1))) != 0 ))
2036 hightest_pcie_level_enabled++;
2038 while (data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
2039 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2040 (1 << lowest_pcie_level_enabled)) == 0 ))
2041 lowest_pcie_level_enabled++;
2043 while ((count < hightest_pcie_level_enabled) &&
2044 ((data->dpm_level_enable_mask.pcie_dpm_enable_mask &
2045 (1 << (lowest_pcie_level_enabled + 1 + count))) == 0 ))
2048 mid_pcie_level_enabled = (lowest_pcie_level_enabled + 1+ count) <
2049 hightest_pcie_level_enabled?
2050 (lowest_pcie_level_enabled + 1 + count) :
2051 hightest_pcie_level_enabled;
2053 /* set pcieDpmLevel to hightest_pcie_level_enabled */
2054 for(i = 2; i < dpm_table->sclk_table.count; i++)
2055 levels[i].pcieDpmLevel = hightest_pcie_level_enabled;
2057 /* set pcieDpmLevel to lowest_pcie_level_enabled */
2058 levels[0].pcieDpmLevel = lowest_pcie_level_enabled;
2060 /* set pcieDpmLevel to mid_pcie_level_enabled */
2061 levels[1].pcieDpmLevel = mid_pcie_level_enabled;
2063 /* level count will send to smc once at init smc table and never change */
2064 result = fiji_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
2065 (uint32_t)array_size, data->sram_end);
2071 * MCLK Frequency Ratio
2072 * SEQ_CG_RESP Bit[31:24] - 0x0
2073 * Bit[27:24] \96 DDR3 Frequency ratio
2074 * 0x0 <= 100MHz, 450 < 0x8 <= 500MHz
2075 * 100 < 0x1 <= 150MHz, 500 < 0x9 <= 550MHz
2076 * 150 < 0x2 <= 200MHz, 550 < 0xA <= 600MHz
2077 * 200 < 0x3 <= 250MHz, 600 < 0xB <= 650MHz
2078 * 250 < 0x4 <= 300MHz, 650 < 0xC <= 700MHz
2079 * 300 < 0x5 <= 350MHz, 700 < 0xD <= 750MHz
2080 * 350 < 0x6 <= 400MHz, 750 < 0xE <= 800MHz
2081 * 400 < 0x7 <= 450MHz, 800 < 0xF
2083 static uint8_t fiji_get_mclk_frequency_ratio(uint32_t mem_clock)
2085 if (mem_clock <= 10000) return 0x0;
2086 if (mem_clock <= 15000) return 0x1;
2087 if (mem_clock <= 20000) return 0x2;
2088 if (mem_clock <= 25000) return 0x3;
2089 if (mem_clock <= 30000) return 0x4;
2090 if (mem_clock <= 35000) return 0x5;
2091 if (mem_clock <= 40000) return 0x6;
2092 if (mem_clock <= 45000) return 0x7;
2093 if (mem_clock <= 50000) return 0x8;
2094 if (mem_clock <= 55000) return 0x9;
2095 if (mem_clock <= 60000) return 0xa;
2096 if (mem_clock <= 65000) return 0xb;
2097 if (mem_clock <= 70000) return 0xc;
2098 if (mem_clock <= 75000) return 0xd;
2099 if (mem_clock <= 80000) return 0xe;
2100 /* mem_clock > 800MHz */
2105 * Populates the SMC MCLK structure using the provided memory clock
2107 * @param hwmgr the address of the hardware manager
2108 * @param clock the memory clock to use to populate the structure
2109 * @param sclk the SMC SCLK structure to be populated
2111 static int fiji_calculate_mclk_params(struct pp_hwmgr *hwmgr,
2112 uint32_t clock, struct SMU73_Discrete_MemoryLevel *mclk)
2114 struct pp_atomctrl_memory_clock_param mem_param;
2117 result = atomctrl_get_memory_pll_dividers_vi(hwmgr, clock, &mem_param);
2118 PP_ASSERT_WITH_CODE((0 == result),
2119 "Failed to get Memory PLL Dividers.",);
2121 /* Save the result data to outpupt memory level structure */
2122 mclk->MclkFrequency = clock;
2123 mclk->MclkDivider = (uint8_t)mem_param.mpll_post_divider;
2124 mclk->FreqRange = fiji_get_mclk_frequency_ratio(clock);
2129 static int fiji_populate_single_memory_level(struct pp_hwmgr *hwmgr,
2130 uint32_t clock, struct SMU73_Discrete_MemoryLevel *mem_level)
2132 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2133 struct phm_ppt_v1_information *table_info =
2134 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2137 if (table_info->vdd_dep_on_mclk) {
2138 result = fiji_get_dependency_volt_by_clk(hwmgr,
2139 table_info->vdd_dep_on_mclk, clock,
2140 &mem_level->MinVoltage, &mem_level->MinMvdd);
2141 PP_ASSERT_WITH_CODE((0 == result),
2142 "can not find MinVddc voltage value from memory "
2143 "VDDC voltage dependency table", return result);
2146 mem_level->EnabledForThrottle = 1;
2147 mem_level->EnabledForActivity = 0;
2148 mem_level->UpHyst = 0;
2149 mem_level->DownHyst = 100;
2150 mem_level->VoltageDownHyst = 0;
2151 mem_level->ActivityLevel = (uint16_t)data->mclk_activity_target;
2152 mem_level->StutterEnable = false;
2154 mem_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2156 /* enable stutter mode if all the follow condition applied
2157 * PECI_GetNumberOfActiveDisplays(hwmgr->pPECI,
2158 * &(data->DisplayTiming.numExistingDisplays));
2160 data->display_timing.num_existing_displays = 1;
2162 if ((data->mclk_stutter_mode_threshold) &&
2163 (clock <= data->mclk_stutter_mode_threshold) &&
2164 (!data->is_uvd_enabled) &&
2165 (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL,
2166 STUTTER_ENABLE) & 0x1))
2167 mem_level->StutterEnable = true;
2169 result = fiji_calculate_mclk_params(hwmgr, clock, mem_level);
2171 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinMvdd);
2172 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MclkFrequency);
2173 CONVERT_FROM_HOST_TO_SMC_US(mem_level->ActivityLevel);
2174 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinVoltage);
2180 * Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states
2182 * @param hwmgr the address of the hardware manager
2184 static int fiji_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
2186 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2187 struct fiji_dpm_table *dpm_table = &data->dpm_table;
2189 /* populate MCLK dpm table to SMU7 */
2190 uint32_t array = data->dpm_table_start +
2191 offsetof(SMU73_Discrete_DpmTable, MemoryLevel);
2192 uint32_t array_size = sizeof(SMU73_Discrete_MemoryLevel) *
2193 SMU73_MAX_LEVELS_MEMORY;
2194 struct SMU73_Discrete_MemoryLevel *levels =
2195 data->smc_state_table.MemoryLevel;
2198 for (i = 0; i < dpm_table->mclk_table.count; i++) {
2199 PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
2200 "can not populate memory level as memory clock is zero",
2202 result = fiji_populate_single_memory_level(hwmgr,
2203 dpm_table->mclk_table.dpm_levels[i].value,
2209 /* Only enable level 0 for now. */
2210 levels[0].EnabledForActivity = 1;
2212 /* in order to prevent MC activity from stutter mode to push DPM up.
2213 * the UVD change complements this by putting the MCLK in
2214 * a higher state by default such that we are not effected by
2215 * up threshold or and MCLK DPM latency.
2217 levels[0].ActivityLevel = (uint16_t)data->mclk_dpm0_activity_target;
2218 CONVERT_FROM_HOST_TO_SMC_US(levels[0].ActivityLevel);
2220 data->smc_state_table.MemoryDpmLevelCount =
2221 (uint8_t)dpm_table->mclk_table.count;
2222 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
2223 fiji_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
2224 /* set highest level watermark to high */
2225 levels[dpm_table->mclk_table.count - 1].DisplayWatermark =
2226 PPSMC_DISPLAY_WATERMARK_HIGH;
2228 /* level count will send to smc once at init smc table and never change */
2229 result = fiji_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
2230 (uint32_t)array_size, data->sram_end);
2236 * Populates the SMC MVDD structure using the provided memory clock.
2238 * @param hwmgr the address of the hardware manager
2239 * @param mclk the MCLK value to be used in the decision if MVDD should be high or low.
2240 * @param voltage the SMC VOLTAGE structure to be populated
2242 int fiji_populate_mvdd_value(struct pp_hwmgr *hwmgr,
2243 uint32_t mclk, SMIO_Pattern *smio_pat)
2245 const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2246 struct phm_ppt_v1_information *table_info =
2247 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2250 if (FIJI_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
2251 /* find mvdd value which clock is more than request */
2252 for (i = 0; i < table_info->vdd_dep_on_mclk->count; i++) {
2253 if (mclk <= table_info->vdd_dep_on_mclk->entries[i].clk) {
2254 smio_pat->Voltage = data->mvdd_voltage_table.entries[i].value;
2258 PP_ASSERT_WITH_CODE(i < table_info->vdd_dep_on_mclk->count,
2259 "MVDD Voltage is outside the supported range.",
2267 static int fiji_populate_smc_acpi_level(struct pp_hwmgr *hwmgr,
2268 SMU73_Discrete_DpmTable *table)
2271 const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2272 struct phm_ppt_v1_information *table_info =
2273 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2274 struct pp_atomctrl_clock_dividers_vi dividers;
2275 SMIO_Pattern vol_level;
2278 uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL;
2279 uint32_t spll_func_cntl_2 = data->clock_registers.vCG_SPLL_FUNC_CNTL_2;
2281 table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
2283 if (!data->sclk_dpm_key_disabled) {
2284 /* Get MinVoltage and Frequency from DPM0,
2285 * already converted to SMC_UL */
2286 table->ACPILevel.SclkFrequency =
2287 data->dpm_table.sclk_table.dpm_levels[0].value;
2288 result = fiji_get_dependency_volt_by_clk(hwmgr,
2289 table_info->vdd_dep_on_sclk,
2290 table->ACPILevel.SclkFrequency,
2291 &table->ACPILevel.MinVoltage, &mvdd);
2292 PP_ASSERT_WITH_CODE((0 == result),
2293 "Cannot find ACPI VDDC voltage value "
2294 "in Clock Dependency Table",);
2296 table->ACPILevel.SclkFrequency =
2297 data->vbios_boot_state.sclk_bootup_value;
2298 table->ACPILevel.MinVoltage =
2299 data->vbios_boot_state.vddc_bootup_value * VOLTAGE_SCALE;
2302 /* get the engine clock dividers for this clock value */
2303 result = atomctrl_get_engine_pll_dividers_vi(hwmgr,
2304 table->ACPILevel.SclkFrequency, ÷rs);
2305 PP_ASSERT_WITH_CODE(result == 0,
2306 "Error retrieving Engine Clock dividers from VBIOS.",
2309 table->ACPILevel.SclkDid = (uint8_t)dividers.pll_post_divider;
2310 table->ACPILevel.DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
2311 table->ACPILevel.DeepSleepDivId = 0;
2313 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
2315 spll_func_cntl = PHM_SET_FIELD(spll_func_cntl, CG_SPLL_FUNC_CNTL,
2317 spll_func_cntl_2 = PHM_SET_FIELD(spll_func_cntl_2, CG_SPLL_FUNC_CNTL_2,
2320 table->ACPILevel.CgSpllFuncCntl = spll_func_cntl;
2321 table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2;
2322 table->ACPILevel.CgSpllFuncCntl3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3;
2323 table->ACPILevel.CgSpllFuncCntl4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4;
2324 table->ACPILevel.SpllSpreadSpectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM;
2325 table->ACPILevel.SpllSpreadSpectrum2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2;
2326 table->ACPILevel.CcPwrDynRm = 0;
2327 table->ACPILevel.CcPwrDynRm1 = 0;
2329 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
2330 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkFrequency);
2331 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.MinVoltage);
2332 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl);
2333 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl2);
2334 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl3);
2335 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CgSpllFuncCntl4);
2336 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum);
2337 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SpllSpreadSpectrum2);
2338 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
2339 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
2341 if (!data->mclk_dpm_key_disabled) {
2342 /* Get MinVoltage and Frequency from DPM0, already converted to SMC_UL */
2343 table->MemoryACPILevel.MclkFrequency =
2344 data->dpm_table.mclk_table.dpm_levels[0].value;
2345 result = fiji_get_dependency_volt_by_clk(hwmgr,
2346 table_info->vdd_dep_on_mclk,
2347 table->MemoryACPILevel.MclkFrequency,
2348 &table->MemoryACPILevel.MinVoltage, &mvdd);
2349 PP_ASSERT_WITH_CODE((0 == result),
2350 "Cannot find ACPI VDDCI voltage value "
2351 "in Clock Dependency Table",);
2353 table->MemoryACPILevel.MclkFrequency =
2354 data->vbios_boot_state.mclk_bootup_value;
2355 table->MemoryACPILevel.MinVoltage =
2356 data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE;
2360 if ((FIJI_VOLTAGE_CONTROL_NONE == data->mvdd_control) ||
2361 (data->mclk_dpm_key_disabled))
2362 us_mvdd = data->vbios_boot_state.mvdd_bootup_value;
2364 if (!fiji_populate_mvdd_value(hwmgr,
2365 data->dpm_table.mclk_table.dpm_levels[0].value,
2367 us_mvdd = vol_level.Voltage;
2370 table->MemoryACPILevel.MinMvdd =
2371 PP_HOST_TO_SMC_UL(us_mvdd * VOLTAGE_SCALE);
2373 table->MemoryACPILevel.EnabledForThrottle = 0;
2374 table->MemoryACPILevel.EnabledForActivity = 0;
2375 table->MemoryACPILevel.UpHyst = 0;
2376 table->MemoryACPILevel.DownHyst = 100;
2377 table->MemoryACPILevel.VoltageDownHyst = 0;
2378 table->MemoryACPILevel.ActivityLevel =
2379 PP_HOST_TO_SMC_US((uint16_t)data->mclk_activity_target);
2381 table->MemoryACPILevel.StutterEnable = false;
2382 CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MclkFrequency);
2383 CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);
2388 static int fiji_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
2389 SMU73_Discrete_DpmTable *table)
2391 int result = -EINVAL;
2393 struct pp_atomctrl_clock_dividers_vi dividers;
2394 struct phm_ppt_v1_information *table_info =
2395 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2396 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2397 table_info->mm_dep_table;
2398 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2400 table->VceLevelCount = (uint8_t)(mm_table->count);
2401 table->VceBootLevel = 0;
2403 for(count = 0; count < table->VceLevelCount; count++) {
2404 table->VceLevel[count].Frequency = mm_table->entries[count].eclk;
2405 table->VceLevel[count].MinVoltage = 0;
2406 table->VceLevel[count].MinVoltage |=
2407 (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
2408 table->VceLevel[count].MinVoltage |=
2409 ((mm_table->entries[count].vddc - data->vddc_vddci_delta) *
2410 VOLTAGE_SCALE) << VDDCI_SHIFT;
2411 table->VceLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2413 /*retrieve divider value for VBIOS */
2414 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2415 table->VceLevel[count].Frequency, ÷rs);
2416 PP_ASSERT_WITH_CODE((0 == result),
2417 "can not find divide id for VCE engine clock",
2420 table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
2422 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency);
2423 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].MinVoltage);
2428 static int fiji_populate_smc_acp_level(struct pp_hwmgr *hwmgr,
2429 SMU73_Discrete_DpmTable *table)
2431 int result = -EINVAL;
2433 struct pp_atomctrl_clock_dividers_vi dividers;
2434 struct phm_ppt_v1_information *table_info =
2435 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2436 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2437 table_info->mm_dep_table;
2438 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2440 table->AcpLevelCount = (uint8_t)(mm_table->count);
2441 table->AcpBootLevel = 0;
2443 for (count = 0; count < table->AcpLevelCount; count++) {
2444 table->AcpLevel[count].Frequency = mm_table->entries[count].aclk;
2445 table->AcpLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
2446 VOLTAGE_SCALE) << VDDC_SHIFT;
2447 table->AcpLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
2448 data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
2449 table->AcpLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2451 /* retrieve divider value for VBIOS */
2452 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2453 table->AcpLevel[count].Frequency, ÷rs);
2454 PP_ASSERT_WITH_CODE((0 == result),
2455 "can not find divide id for engine clock", return result);
2457 table->AcpLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
2459 CONVERT_FROM_HOST_TO_SMC_UL(table->AcpLevel[count].Frequency);
2460 CONVERT_FROM_HOST_TO_SMC_UL(table->AcpLevel[count].MinVoltage);
2465 static int fiji_populate_smc_samu_level(struct pp_hwmgr *hwmgr,
2466 SMU73_Discrete_DpmTable *table)
2468 int result = -EINVAL;
2470 struct pp_atomctrl_clock_dividers_vi dividers;
2471 struct phm_ppt_v1_information *table_info =
2472 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2473 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2474 table_info->mm_dep_table;
2475 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2477 table->SamuBootLevel = 0;
2478 table->SamuLevelCount = (uint8_t)(mm_table->count);
2480 for (count = 0; count < table->SamuLevelCount; count++) {
2481 /* not sure whether we need evclk or not */
2482 table->SamuLevel[count].MinVoltage = 0;
2483 table->SamuLevel[count].Frequency = mm_table->entries[count].samclock;
2484 table->SamuLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
2485 VOLTAGE_SCALE) << VDDC_SHIFT;
2486 table->SamuLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
2487 data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
2488 table->SamuLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2490 /* retrieve divider value for VBIOS */
2491 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2492 table->SamuLevel[count].Frequency, ÷rs);
2493 PP_ASSERT_WITH_CODE((0 == result),
2494 "can not find divide id for samu clock", return result);
2496 table->SamuLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
2498 CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].Frequency);
2499 CONVERT_FROM_HOST_TO_SMC_UL(table->SamuLevel[count].MinVoltage);
2504 static int fiji_populate_memory_timing_parameters(struct pp_hwmgr *hwmgr,
2505 int32_t eng_clock, int32_t mem_clock,
2506 struct SMU73_Discrete_MCArbDramTimingTableEntry *arb_regs)
2508 uint32_t dram_timing;
2509 uint32_t dram_timing2;
2511 ULONG state, trrds, trrdl;
2514 result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
2515 eng_clock, mem_clock);
2516 PP_ASSERT_WITH_CODE(result == 0,
2517 "Error calling VBIOS to set DRAM_TIMING.", return result);
2519 dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
2520 dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
2521 burstTime = cgs_read_register(hwmgr->device, mmMC_ARB_BURST_TIME);
2523 state = PHM_GET_FIELD(burstTime, MC_ARB_BURST_TIME, STATE0);
2524 trrds = PHM_GET_FIELD(burstTime, MC_ARB_BURST_TIME, TRRDS0);
2525 trrdl = PHM_GET_FIELD(burstTime, MC_ARB_BURST_TIME, TRRDL0);
2527 arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dram_timing);
2528 arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dram_timing2);
2529 arb_regs->McArbBurstTime = (uint8_t)burstTime;
2530 arb_regs->TRRDS = (uint8_t)trrds;
2531 arb_regs->TRRDL = (uint8_t)trrdl;
2536 static int fiji_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
2538 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2539 struct SMU73_Discrete_MCArbDramTimingTable arb_regs;
2543 for (i = 0; i < data->dpm_table.sclk_table.count; i++) {
2544 for (j = 0; j < data->dpm_table.mclk_table.count; j++) {
2545 result = fiji_populate_memory_timing_parameters(hwmgr,
2546 data->dpm_table.sclk_table.dpm_levels[i].value,
2547 data->dpm_table.mclk_table.dpm_levels[j].value,
2548 &arb_regs.entries[i][j]);
2555 result = fiji_copy_bytes_to_smc(
2557 data->arb_table_start,
2558 (uint8_t *)&arb_regs,
2559 sizeof(SMU73_Discrete_MCArbDramTimingTable),
2564 static int fiji_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
2565 struct SMU73_Discrete_DpmTable *table)
2567 int result = -EINVAL;
2569 struct pp_atomctrl_clock_dividers_vi dividers;
2570 struct phm_ppt_v1_information *table_info =
2571 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2572 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
2573 table_info->mm_dep_table;
2574 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2576 table->UvdLevelCount = (uint8_t)(mm_table->count);
2577 table->UvdBootLevel = 0;
2579 for (count = 0; count < table->UvdLevelCount; count++) {
2580 table->UvdLevel[count].MinVoltage = 0;
2581 table->UvdLevel[count].VclkFrequency = mm_table->entries[count].vclk;
2582 table->UvdLevel[count].DclkFrequency = mm_table->entries[count].dclk;
2583 table->UvdLevel[count].MinVoltage |= (mm_table->entries[count].vddc *
2584 VOLTAGE_SCALE) << VDDC_SHIFT;
2585 table->UvdLevel[count].MinVoltage |= ((mm_table->entries[count].vddc -
2586 data->vddc_vddci_delta) * VOLTAGE_SCALE) << VDDCI_SHIFT;
2587 table->UvdLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
2589 /* retrieve divider value for VBIOS */
2590 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2591 table->UvdLevel[count].VclkFrequency, ÷rs);
2592 PP_ASSERT_WITH_CODE((0 == result),
2593 "can not find divide id for Vclk clock", return result);
2595 table->UvdLevel[count].VclkDivider = (uint8_t)dividers.pll_post_divider;
2597 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2598 table->UvdLevel[count].DclkFrequency, ÷rs);
2599 PP_ASSERT_WITH_CODE((0 == result),
2600 "can not find divide id for Dclk clock", return result);
2602 table->UvdLevel[count].DclkDivider = (uint8_t)dividers.pll_post_divider;
2604 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].VclkFrequency);
2605 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].DclkFrequency);
2606 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].MinVoltage);
2612 static int fiji_find_boot_level(struct fiji_single_dpm_table *table,
2613 uint32_t value, uint32_t *boot_level)
2615 int result = -EINVAL;
2618 for (i = 0; i < table->count; i++) {
2619 if (value == table->dpm_levels[i].value) {
2627 static int fiji_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
2628 struct SMU73_Discrete_DpmTable *table)
2631 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2633 table->GraphicsBootLevel = 0;
2634 table->MemoryBootLevel = 0;
2636 /* find boot level from dpm table */
2637 result = fiji_find_boot_level(&(data->dpm_table.sclk_table),
2638 data->vbios_boot_state.sclk_bootup_value,
2639 (uint32_t *)&(table->GraphicsBootLevel));
2641 result = fiji_find_boot_level(&(data->dpm_table.mclk_table),
2642 data->vbios_boot_state.mclk_bootup_value,
2643 (uint32_t *)&(table->MemoryBootLevel));
2645 table->BootVddc = data->vbios_boot_state.vddc_bootup_value *
2647 table->BootVddci = data->vbios_boot_state.vddci_bootup_value *
2649 table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value *
2652 CONVERT_FROM_HOST_TO_SMC_US(table->BootVddc);
2653 CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci);
2654 CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
2659 static int fiji_populate_smc_initailial_state(struct pp_hwmgr *hwmgr)
2661 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2662 struct phm_ppt_v1_information *table_info =
2663 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2664 uint8_t count, level;
2666 count = (uint8_t)(table_info->vdd_dep_on_sclk->count);
2667 for (level = 0; level < count; level++) {
2668 if(table_info->vdd_dep_on_sclk->entries[level].clk >=
2669 data->vbios_boot_state.sclk_bootup_value) {
2670 data->smc_state_table.GraphicsBootLevel = level;
2675 count = (uint8_t)(table_info->vdd_dep_on_mclk->count);
2676 for (level = 0; level < count; level++) {
2677 if(table_info->vdd_dep_on_mclk->entries[level].clk >=
2678 data->vbios_boot_state.mclk_bootup_value) {
2679 data->smc_state_table.MemoryBootLevel = level;
2687 static int fiji_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr)
2689 uint32_t ro, efuse, efuse2, clock_freq, volt_without_cks,
2690 volt_with_cks, value;
2691 uint16_t clock_freq_u16;
2692 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2693 uint8_t type, i, j, cks_setting, stretch_amount, stretch_amount2,
2695 struct phm_ppt_v1_information *table_info =
2696 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2697 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
2698 table_info->vdd_dep_on_sclk;
2700 stretch_amount = (uint8_t)table_info->cac_dtp_table->usClockStretchAmount;
2702 /* Read SMU_Eefuse to read and calculate RO and determine
2703 * if the part is SS or FF. if RO >= 1660MHz, part is FF.
2705 efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2706 ixSMU_EFUSE_0 + (146 * 4));
2707 efuse2 = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2708 ixSMU_EFUSE_0 + (148 * 4));
2709 efuse &= 0xFF000000;
2710 efuse = efuse >> 24;
2714 ro = (2300 - 1350) * efuse / 255 + 1350;
2716 ro = (2500 - 1000) * efuse / 255 + 1000;
2723 /* Populate Stretch amount */
2724 data->smc_state_table.ClockStretcherAmount = stretch_amount;
2726 /* Populate Sclk_CKS_masterEn0_7 and Sclk_voltageOffset */
2727 for (i = 0; i < sclk_table->count; i++) {
2728 data->smc_state_table.Sclk_CKS_masterEn0_7 |=
2729 sclk_table->entries[i].cks_enable << i;
2730 volt_without_cks = (uint32_t)((14041 *
2731 (sclk_table->entries[i].clk/100) / 10000 + 3571 + 75 - ro) * 1000 /
2732 (4026 - (13924 * (sclk_table->entries[i].clk/100) / 10000)));
2733 volt_with_cks = (uint32_t)((13946 *
2734 (sclk_table->entries[i].clk/100) / 10000 + 3320 + 45 - ro) * 1000 /
2735 (3664 - (11454 * (sclk_table->entries[i].clk/100) / 10000)));
2736 if (volt_without_cks >= volt_with_cks)
2737 volt_offset = (uint8_t)(((volt_without_cks - volt_with_cks +
2738 sclk_table->entries[i].cks_voffset) * 100 / 625) + 1);
2739 data->smc_state_table.Sclk_voltageOffset[i] = volt_offset;
2742 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2743 STRETCH_ENABLE, 0x0);
2744 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2746 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2748 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, PWR_CKS_ENABLE,
2751 /* Populate CKS Lookup Table */
2752 if (stretch_amount == 1 || stretch_amount == 2 || stretch_amount == 5)
2753 stretch_amount2 = 0;
2754 else if (stretch_amount == 3 || stretch_amount == 4)
2755 stretch_amount2 = 1;
2757 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2758 PHM_PlatformCaps_ClockStretcher);
2759 PP_ASSERT_WITH_CODE(false,
2760 "Stretch Amount in PPTable not supported\n",
2764 value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2766 value &= 0xFFC2FF87;
2767 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].minFreq =
2768 fiji_clock_stretcher_lookup_table[stretch_amount2][0];
2769 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].maxFreq =
2770 fiji_clock_stretcher_lookup_table[stretch_amount2][1];
2771 clock_freq_u16 = (uint16_t)(PP_SMC_TO_HOST_UL(data->smc_state_table.
2772 GraphicsLevel[data->smc_state_table.GraphicsDpmLevelCount - 1].
2773 SclkFrequency) / 100);
2774 if (fiji_clock_stretcher_lookup_table[stretch_amount2][0] <
2776 fiji_clock_stretcher_lookup_table[stretch_amount2][1] >
2778 /* Program PWR_CKS_CNTL. CKS_USE_FOR_LOW_FREQ */
2779 value |= (fiji_clock_stretcher_lookup_table[stretch_amount2][3]) << 16;
2780 /* Program PWR_CKS_CNTL. CKS_LDO_REFSEL */
2781 value |= (fiji_clock_stretcher_lookup_table[stretch_amount2][2]) << 18;
2782 /* Program PWR_CKS_CNTL. CKS_STRETCH_AMOUNT */
2783 value |= (fiji_clock_stretch_amount_conversion
2784 [fiji_clock_stretcher_lookup_table[stretch_amount2][3]]
2785 [stretch_amount]) << 3;
2787 CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.CKS_LOOKUPTable.
2788 CKS_LOOKUPTableEntry[0].minFreq);
2789 CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.CKS_LOOKUPTable.
2790 CKS_LOOKUPTableEntry[0].maxFreq);
2791 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting =
2792 fiji_clock_stretcher_lookup_table[stretch_amount2][2] & 0x7F;
2793 data->smc_state_table.CKS_LOOKUPTable.CKS_LOOKUPTableEntry[0].setting |=
2794 (fiji_clock_stretcher_lookup_table[stretch_amount2][3]) << 7;
2796 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2797 ixPWR_CKS_CNTL, value);
2799 /* Populate DDT Lookup Table */
2800 for (i = 0; i < 4; i++) {
2801 /* Assign the minimum and maximum VID stored
2802 * in the last row of Clock Stretcher Voltage Table.
2804 data->smc_state_table.ClockStretcherDataTable.
2805 ClockStretcherDataTableEntry[i].minVID =
2806 (uint8_t) fiji_clock_stretcher_ddt_table[type][i][2];
2807 data->smc_state_table.ClockStretcherDataTable.
2808 ClockStretcherDataTableEntry[i].maxVID =
2809 (uint8_t) fiji_clock_stretcher_ddt_table[type][i][3];
2810 /* Loop through each SCLK and check the frequency
2811 * to see if it lies within the frequency for clock stretcher.
2813 for (j = 0; j < data->smc_state_table.GraphicsDpmLevelCount; j++) {
2815 clock_freq = PP_SMC_TO_HOST_UL(
2816 data->smc_state_table.GraphicsLevel[j].SclkFrequency);
2817 /* Check the allowed frequency against the sclk level[j].
2818 * Sclk's endianness has already been converted,
2819 * and it's in 10Khz unit,
2820 * as opposed to Data table, which is in Mhz unit.
2823 (fiji_clock_stretcher_ddt_table[type][i][0]) * 100) {
2826 (fiji_clock_stretcher_ddt_table[type][i][1]) * 100)
2829 data->smc_state_table.ClockStretcherDataTable.
2830 ClockStretcherDataTableEntry[i].setting |= cks_setting << (j * 2);
2832 CONVERT_FROM_HOST_TO_SMC_US(data->smc_state_table.
2833 ClockStretcherDataTable.
2834 ClockStretcherDataTableEntry[i].setting);
2837 value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL);
2838 value &= 0xFFFFFFFE;
2839 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL, value);
2845 * Populates the SMC VRConfig field in DPM table.
2847 * @param hwmgr the address of the hardware manager
2848 * @param table the SMC DPM table structure to be populated
2851 static int fiji_populate_vr_config(struct pp_hwmgr *hwmgr,
2852 struct SMU73_Discrete_DpmTable *table)
2854 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2857 config = VR_MERGED_WITH_VDDC;
2858 table->VRConfig |= (config << VRCONF_VDDGFX_SHIFT);
2860 /* Set Vddc Voltage Controller */
2861 if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
2862 config = VR_SVI2_PLANE_1;
2863 table->VRConfig |= config;
2865 PP_ASSERT_WITH_CODE(false,
2866 "VDDC should be on SVI2 control in merged mode!",);
2868 /* Set Vddci Voltage Controller */
2869 if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
2870 config = VR_SVI2_PLANE_2; /* only in merged mode */
2871 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
2872 } else if (FIJI_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
2873 config = VR_SMIO_PATTERN_1;
2874 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
2876 config = VR_STATIC_VOLTAGE;
2877 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
2879 /* Set Mvdd Voltage Controller */
2880 if(FIJI_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
2881 config = VR_SVI2_PLANE_2;
2882 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
2883 } else if(FIJI_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
2884 config = VR_SMIO_PATTERN_2;
2885 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
2887 config = VR_STATIC_VOLTAGE;
2888 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
2895 * Initializes the SMC table and uploads it
2897 * @param hwmgr the address of the powerplay hardware manager.
2898 * @param pInput the pointer to input data (PowerState)
2901 static int fiji_init_smc_table(struct pp_hwmgr *hwmgr)
2904 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
2905 struct phm_ppt_v1_information *table_info =
2906 (struct phm_ppt_v1_information *)(hwmgr->pptable);
2907 struct SMU73_Discrete_DpmTable *table = &(data->smc_state_table);
2908 const struct fiji_ulv_parm *ulv = &(data->ulv);
2910 struct pp_atomctrl_gpio_pin_assignment gpio_pin;
2912 result = fiji_setup_default_dpm_tables(hwmgr);
2913 PP_ASSERT_WITH_CODE(0 == result,
2914 "Failed to setup default DPM tables!", return result);
2916 if(FIJI_VOLTAGE_CONTROL_NONE != data->voltage_control)
2917 fiji_populate_smc_voltage_tables(hwmgr, table);
2919 table->SystemFlags = 0;
2921 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2922 PHM_PlatformCaps_AutomaticDCTransition))
2923 table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
2925 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2926 PHM_PlatformCaps_StepVddc))
2927 table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
2929 if (data->is_memory_gddr5)
2930 table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
2932 if (ulv->ulv_supported && table_info->us_ulv_voltage_offset) {
2933 result = fiji_populate_ulv_state(hwmgr, table);
2934 PP_ASSERT_WITH_CODE(0 == result,
2935 "Failed to initialize ULV state!", return result);
2936 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
2937 ixCG_ULV_PARAMETER, ulv->cg_ulv_parameter);
2940 result = fiji_populate_smc_link_level(hwmgr, table);
2941 PP_ASSERT_WITH_CODE(0 == result,
2942 "Failed to initialize Link Level!", return result);
2944 result = fiji_populate_all_graphic_levels(hwmgr);
2945 PP_ASSERT_WITH_CODE(0 == result,
2946 "Failed to initialize Graphics Level!", return result);
2948 result = fiji_populate_all_memory_levels(hwmgr);
2949 PP_ASSERT_WITH_CODE(0 == result,
2950 "Failed to initialize Memory Level!", return result);
2952 result = fiji_populate_smc_acpi_level(hwmgr, table);
2953 PP_ASSERT_WITH_CODE(0 == result,
2954 "Failed to initialize ACPI Level!", return result);
2956 result = fiji_populate_smc_vce_level(hwmgr, table);
2957 PP_ASSERT_WITH_CODE(0 == result,
2958 "Failed to initialize VCE Level!", return result);
2960 result = fiji_populate_smc_acp_level(hwmgr, table);
2961 PP_ASSERT_WITH_CODE(0 == result,
2962 "Failed to initialize ACP Level!", return result);
2964 result = fiji_populate_smc_samu_level(hwmgr, table);
2965 PP_ASSERT_WITH_CODE(0 == result,
2966 "Failed to initialize SAMU Level!", return result);
2968 /* Since only the initial state is completely set up at this point
2969 * (the other states are just copies of the boot state) we only
2970 * need to populate the ARB settings for the initial state.
2972 result = fiji_program_memory_timing_parameters(hwmgr);
2973 PP_ASSERT_WITH_CODE(0 == result,
2974 "Failed to Write ARB settings for the initial state.", return result);
2976 result = fiji_populate_smc_uvd_level(hwmgr, table);
2977 PP_ASSERT_WITH_CODE(0 == result,
2978 "Failed to initialize UVD Level!", return result);
2980 result = fiji_populate_smc_boot_level(hwmgr, table);
2981 PP_ASSERT_WITH_CODE(0 == result,
2982 "Failed to initialize Boot Level!", return result);
2984 result = fiji_populate_smc_initailial_state(hwmgr);
2985 PP_ASSERT_WITH_CODE(0 == result,
2986 "Failed to initialize Boot State!", return result);
2988 result = fiji_populate_bapm_parameters_in_dpm_table(hwmgr);
2989 PP_ASSERT_WITH_CODE(0 == result,
2990 "Failed to populate BAPM Parameters!", return result);
2992 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2993 PHM_PlatformCaps_ClockStretcher)) {
2994 result = fiji_populate_clock_stretcher_data_table(hwmgr);
2995 PP_ASSERT_WITH_CODE(0 == result,
2996 "Failed to populate Clock Stretcher Data Table!",
3000 table->GraphicsVoltageChangeEnable = 1;
3001 table->GraphicsThermThrottleEnable = 1;
3002 table->GraphicsInterval = 1;
3003 table->VoltageInterval = 1;
3004 table->ThermalInterval = 1;
3005 table->TemperatureLimitHigh =
3006 table_info->cac_dtp_table->usTargetOperatingTemp *
3007 FIJI_Q88_FORMAT_CONVERSION_UNIT;
3008 table->TemperatureLimitLow =
3009 (table_info->cac_dtp_table->usTargetOperatingTemp - 1) *
3010 FIJI_Q88_FORMAT_CONVERSION_UNIT;
3011 table->MemoryVoltageChangeEnable = 1;
3012 table->MemoryInterval = 1;
3013 table->VoltageResponseTime = 0;
3014 table->PhaseResponseTime = 0;
3015 table->MemoryThermThrottleEnable = 1;
3016 table->PCIeBootLinkLevel = 0; /* 0:Gen1 1:Gen2 2:Gen3*/
3017 table->PCIeGenInterval = 1;
3018 table->VRConfig = 0;
3020 result = fiji_populate_vr_config(hwmgr, table);
3021 PP_ASSERT_WITH_CODE(0 == result,
3022 "Failed to populate VRConfig setting!", return result);
3024 table->ThermGpio = 17;
3025 table->SclkStepSize = 0x4000;
3027 if (atomctrl_get_pp_assign_pin(hwmgr, VDDC_VRHOT_GPIO_PINID, &gpio_pin)) {
3028 table->VRHotGpio = gpio_pin.uc_gpio_pin_bit_shift;
3029 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3030 PHM_PlatformCaps_RegulatorHot);
3032 table->VRHotGpio = FIJI_UNUSED_GPIO_PIN;
3033 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3034 PHM_PlatformCaps_RegulatorHot);
3037 if (atomctrl_get_pp_assign_pin(hwmgr, PP_AC_DC_SWITCH_GPIO_PINID,
3039 table->AcDcGpio = gpio_pin.uc_gpio_pin_bit_shift;
3040 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3041 PHM_PlatformCaps_AutomaticDCTransition);
3043 table->AcDcGpio = FIJI_UNUSED_GPIO_PIN;
3044 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3045 PHM_PlatformCaps_AutomaticDCTransition);
3048 /* Thermal Output GPIO */
3049 if (atomctrl_get_pp_assign_pin(hwmgr, THERMAL_INT_OUTPUT_GPIO_PINID,
3051 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
3052 PHM_PlatformCaps_ThermalOutGPIO);
3054 table->ThermOutGpio = gpio_pin.uc_gpio_pin_bit_shift;
3056 /* For porlarity read GPIOPAD_A with assigned Gpio pin
3057 * since VBIOS will program this register to set 'inactive state',
3058 * driver can then determine 'active state' from this and
3059 * program SMU with correct polarity
3061 table->ThermOutPolarity = (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A) &
3062 (1 << gpio_pin.uc_gpio_pin_bit_shift))) ? 1:0;
3063 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY;
3065 /* if required, combine VRHot/PCC with thermal out GPIO */
3066 if(phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3067 PHM_PlatformCaps_RegulatorHot) &&
3068 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3069 PHM_PlatformCaps_CombinePCCWithThermalSignal))
3070 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT;
3072 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
3073 PHM_PlatformCaps_ThermalOutGPIO);
3074 table->ThermOutGpio = 17;
3075 table->ThermOutPolarity = 1;
3076 table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE;
3079 for (i = 0; i < SMU73_MAX_ENTRIES_SMIO; i++)
3080 table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]);
3082 CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
3083 CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig);
3084 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1);
3085 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2);
3086 CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
3087 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
3088 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
3089 CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
3090 CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
3092 /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
3093 result = fiji_copy_bytes_to_smc(hwmgr->smumgr,
3094 data->dpm_table_start +
3095 offsetof(SMU73_Discrete_DpmTable, SystemFlags),
3096 (uint8_t *)&(table->SystemFlags),
3097 sizeof(SMU73_Discrete_DpmTable) - 3 * sizeof(SMU73_PIDController),
3099 PP_ASSERT_WITH_CODE(0 == result,
3100 "Failed to upload dpm data to SMC memory!", return result);
3106 * Initialize the ARB DRAM timing table's index field.
3108 * @param hwmgr the address of the powerplay hardware manager.
3111 static int fiji_init_arb_table_index(struct pp_hwmgr *hwmgr)
3113 const struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3117 /* This is a read-modify-write on the first byte of the ARB table.
3118 * The first byte in the SMU73_Discrete_MCArbDramTimingTable structure
3119 * is the field 'current'.
3120 * This solution is ugly, but we never write the whole table only
3121 * individual fields in it.
3122 * In reality this field should not be in that structure
3123 * but in a soft register.
3125 result = fiji_read_smc_sram_dword(hwmgr->smumgr,
3126 data->arb_table_start, &tmp, data->sram_end);
3132 tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24;
3134 return fiji_write_smc_sram_dword(hwmgr->smumgr,
3135 data->arb_table_start, tmp, data->sram_end);
3138 static int fiji_enable_vrhot_gpio_interrupt(struct pp_hwmgr *hwmgr)
3140 if(phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3141 PHM_PlatformCaps_RegulatorHot))
3142 return smum_send_msg_to_smc(hwmgr->smumgr,
3143 PPSMC_MSG_EnableVRHotGPIOInterrupt);
3148 static int fiji_enable_sclk_control(struct pp_hwmgr *hwmgr)
3150 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
3151 SCLK_PWRMGT_OFF, 0);
3155 static int fiji_enable_ulv(struct pp_hwmgr *hwmgr)
3157 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3158 struct fiji_ulv_parm *ulv = &(data->ulv);
3160 if (ulv->ulv_supported)
3161 return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_EnableULV);
3166 static int fiji_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
3168 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3169 PHM_PlatformCaps_SclkDeepSleep)) {
3170 if (smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MASTER_DeepSleep_ON))
3171 PP_ASSERT_WITH_CODE(false,
3172 "Attempt to enable Master Deep Sleep switch failed!",
3175 if (smum_send_msg_to_smc(hwmgr->smumgr,
3176 PPSMC_MSG_MASTER_DeepSleep_OFF)) {
3177 PP_ASSERT_WITH_CODE(false,
3178 "Attempt to disable Master Deep Sleep switch failed!",
3186 static int fiji_enable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
3188 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3189 uint32_t val, val0, val2;
3190 uint32_t i, cpl_cntl, cpl_threshold, mc_threshold;
3192 /* enable SCLK dpm */
3193 if(!data->sclk_dpm_key_disabled)
3194 PP_ASSERT_WITH_CODE(
3195 (0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Enable)),
3196 "Failed to enable SCLK DPM during DPM Start Function!",
3199 /* enable MCLK dpm */
3200 if(0 == data->mclk_dpm_key_disabled) {
3204 /* Read per MCD tile (0 - 7) */
3205 for (i = 0; i < 8; i++) {
3206 PHM_WRITE_FIELD(hwmgr->device, MC_CONFIG_MCD, MC_RD_ENABLE, i);
3207 val = cgs_read_register(hwmgr->device, mmMC_SEQ_RESERVE_0_S) & 0xf0000000;
3208 if (0xf0000000 != val) {
3209 /* count number of MCQ that has channel(s) enabled */
3211 /* only harvest 3 or full 4 supported */
3212 mc_threshold = val ? 3 : 4;
3215 PP_ASSERT_WITH_CODE(0 != cpl_threshold,
3216 "Number of MCQ is zero!", return -EINVAL;);
3218 mc_threshold = ((mc_threshold & LCAC_MC0_CNTL__MC0_THRESHOLD_MASK) <<
3219 LCAC_MC0_CNTL__MC0_THRESHOLD__SHIFT) |
3220 LCAC_MC0_CNTL__MC0_ENABLE_MASK;
3221 cpl_cntl = ((cpl_threshold & LCAC_CPL_CNTL__CPL_THRESHOLD_MASK) <<
3222 LCAC_CPL_CNTL__CPL_THRESHOLD__SHIFT) |
3223 LCAC_CPL_CNTL__CPL_ENABLE_MASK;
3224 cpl_cntl = (cpl_cntl | (8 << LCAC_CPL_CNTL__CPL_BLOCK_ID__SHIFT));
3225 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3226 ixLCAC_MC0_CNTL, mc_threshold);
3227 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3228 ixLCAC_MC1_CNTL, mc_threshold);
3229 if (8 == cpl_threshold) {
3230 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3231 ixLCAC_MC2_CNTL, mc_threshold);
3232 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3233 ixLCAC_MC3_CNTL, mc_threshold);
3234 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3235 ixLCAC_MC4_CNTL, mc_threshold);
3236 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3237 ixLCAC_MC5_CNTL, mc_threshold);
3238 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3239 ixLCAC_MC6_CNTL, mc_threshold);
3240 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3241 ixLCAC_MC7_CNTL, mc_threshold);
3243 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3244 ixLCAC_CPL_CNTL, cpl_cntl);
3248 mc_threshold = mc_threshold |
3249 (1 << LCAC_MC0_CNTL__MC0_SIGNAL_ID__SHIFT);
3250 cpl_cntl = cpl_cntl | (1 << LCAC_CPL_CNTL__CPL_SIGNAL_ID__SHIFT);
3251 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3252 ixLCAC_MC0_CNTL, mc_threshold);
3253 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3254 ixLCAC_MC1_CNTL, mc_threshold);
3255 if (8 == cpl_threshold) {
3256 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3257 ixLCAC_MC2_CNTL, mc_threshold);
3258 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3259 ixLCAC_MC3_CNTL, mc_threshold);
3260 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3261 ixLCAC_MC4_CNTL, mc_threshold);
3262 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3263 ixLCAC_MC5_CNTL, mc_threshold);
3264 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3265 ixLCAC_MC6_CNTL, mc_threshold);
3266 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3267 ixLCAC_MC7_CNTL, mc_threshold);
3269 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3270 ixLCAC_CPL_CNTL, cpl_cntl);
3272 /* Program CAC_EN per MCD (0-7) Tile */
3273 val0 = val = cgs_read_register(hwmgr->device, mmMC_CONFIG_MCD);
3274 val &= ~(MC_CONFIG_MCD__MCD0_WR_ENABLE_MASK |
3275 MC_CONFIG_MCD__MCD1_WR_ENABLE_MASK |
3276 MC_CONFIG_MCD__MCD2_WR_ENABLE_MASK |
3277 MC_CONFIG_MCD__MCD3_WR_ENABLE_MASK |
3278 MC_CONFIG_MCD__MCD4_WR_ENABLE_MASK |
3279 MC_CONFIG_MCD__MCD5_WR_ENABLE_MASK |
3280 MC_CONFIG_MCD__MCD6_WR_ENABLE_MASK |
3281 MC_CONFIG_MCD__MCD7_WR_ENABLE_MASK |
3282 MC_CONFIG_MCD__MC_RD_ENABLE_MASK);
3284 for (i = 0; i < 8; i++) {
3285 /* Enable MCD i Tile read & write */
3286 val2 = (val | (i << MC_CONFIG_MCD__MC_RD_ENABLE__SHIFT) |
3288 cgs_write_register(hwmgr->device, mmMC_CONFIG_MCD, val2);
3289 /* Enbale CAC_ON MCD i Tile */
3290 val2 = cgs_read_register(hwmgr->device, mmMC_SEQ_CNTL);
3291 val2 |= MC_SEQ_CNTL__CAC_EN_MASK;
3292 cgs_write_register(hwmgr->device, mmMC_SEQ_CNTL, val2);
3294 /* Set MC_CONFIG_MCD back to its default setting val0 */
3295 cgs_write_register(hwmgr->device, mmMC_CONFIG_MCD, val0);
3297 PP_ASSERT_WITH_CODE(
3298 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
3299 PPSMC_MSG_MCLKDPM_Enable)),
3300 "Failed to enable MCLK DPM during DPM Start Function!",
3306 static int fiji_start_dpm(struct pp_hwmgr *hwmgr)
3308 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3310 /*enable general power management */
3311 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3312 GLOBAL_PWRMGT_EN, 1);
3313 /* enable sclk deep sleep */
3314 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, SCLK_PWRMGT_CNTL,
3316 /* prepare for PCIE DPM */
3317 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
3318 data->soft_regs_start + offsetof(SMU73_SoftRegisters,
3319 VoltageChangeTimeout), 0x1000);
3320 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__PCIE,
3321 SWRST_COMMAND_1, RESETLC, 0x0);
3323 PP_ASSERT_WITH_CODE(
3324 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
3325 PPSMC_MSG_Voltage_Cntl_Enable)),
3326 "Failed to enable voltage DPM during DPM Start Function!",
3329 if (fiji_enable_sclk_mclk_dpm(hwmgr)) {
3330 printk(KERN_ERR "Failed to enable Sclk DPM and Mclk DPM!");
3334 /* enable PCIE dpm */
3335 if(!data->pcie_dpm_key_disabled) {
3336 PP_ASSERT_WITH_CODE(
3337 (0 == smum_send_msg_to_smc(hwmgr->smumgr,
3338 PPSMC_MSG_PCIeDPM_Enable)),
3339 "Failed to enable pcie DPM during DPM Start Function!",
3346 static void fiji_set_dpm_event_sources(struct pp_hwmgr *hwmgr,
3350 enum DPM_EVENT_SRC src;
3354 printk(KERN_ERR "Unknown throttling event sources.");
3360 case (1 << PHM_AutoThrottleSource_Thermal):
3362 src = DPM_EVENT_SRC_DIGITAL;
3364 case (1 << PHM_AutoThrottleSource_External):
3366 src = DPM_EVENT_SRC_EXTERNAL;
3368 case (1 << PHM_AutoThrottleSource_External) |
3369 (1 << PHM_AutoThrottleSource_Thermal):
3371 src = DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL;
3374 /* Order matters - don't enable thermal protection for the wrong source. */
3376 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, CG_THERMAL_CTRL,
3377 DPM_EVENT_SRC, src);
3378 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3379 THERMAL_PROTECTION_DIS,
3380 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3381 PHM_PlatformCaps_ThermalController));
3383 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, GENERAL_PWRMGT,
3384 THERMAL_PROTECTION_DIS, 1);
3387 static int fiji_enable_auto_throttle_source(struct pp_hwmgr *hwmgr,
3388 PHM_AutoThrottleSource source)
3390 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3392 if (!(data->active_auto_throttle_sources & (1 << source))) {
3393 data->active_auto_throttle_sources |= 1 << source;
3394 fiji_set_dpm_event_sources(hwmgr, data->active_auto_throttle_sources);
3399 static int fiji_enable_thermal_auto_throttle(struct pp_hwmgr *hwmgr)
3401 return fiji_enable_auto_throttle_source(hwmgr, PHM_AutoThrottleSource_Thermal);
3404 static int fiji_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
3406 int tmp_result, result = 0;
3408 tmp_result = (!fiji_is_dpm_running(hwmgr))? 0 : -1;
3409 PP_ASSERT_WITH_CODE(result == 0,
3410 "DPM is already running right now, no need to enable DPM!",
3413 if (fiji_voltage_control(hwmgr)) {
3414 tmp_result = fiji_enable_voltage_control(hwmgr);
3415 PP_ASSERT_WITH_CODE(tmp_result == 0,
3416 "Failed to enable voltage control!",
3417 result = tmp_result);
3420 if (fiji_voltage_control(hwmgr)) {
3421 tmp_result = fiji_construct_voltage_tables(hwmgr);
3422 PP_ASSERT_WITH_CODE((0 == tmp_result),
3423 "Failed to contruct voltage tables!",
3424 result = tmp_result);
3427 tmp_result = fiji_initialize_mc_reg_table(hwmgr);
3428 PP_ASSERT_WITH_CODE((0 == tmp_result),
3429 "Failed to initialize MC reg table!", result = tmp_result);
3431 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3432 PHM_PlatformCaps_EngineSpreadSpectrumSupport))
3433 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3434 GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, 1);
3436 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3437 PHM_PlatformCaps_ThermalController))
3438 PHM_WRITE_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
3439 GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, 0);
3441 tmp_result = fiji_program_static_screen_threshold_parameters(hwmgr);
3442 PP_ASSERT_WITH_CODE((0 == tmp_result),
3443 "Failed to program static screen threshold parameters!",
3444 result = tmp_result);
3446 tmp_result = fiji_enable_display_gap(hwmgr);
3447 PP_ASSERT_WITH_CODE((0 == tmp_result),
3448 "Failed to enable display gap!", result = tmp_result);
3450 tmp_result = fiji_program_voting_clients(hwmgr);
3451 PP_ASSERT_WITH_CODE((0 == tmp_result),
3452 "Failed to program voting clients!", result = tmp_result);
3454 tmp_result = fiji_process_firmware_header(hwmgr);
3455 PP_ASSERT_WITH_CODE((0 == tmp_result),
3456 "Failed to process firmware header!", result = tmp_result);
3458 tmp_result = fiji_initial_switch_from_arbf0_to_f1(hwmgr);
3459 PP_ASSERT_WITH_CODE((0 == tmp_result),
3460 "Failed to initialize switch from ArbF0 to F1!",
3461 result = tmp_result);
3463 tmp_result = fiji_init_smc_table(hwmgr);
3464 PP_ASSERT_WITH_CODE((0 == tmp_result),
3465 "Failed to initialize SMC table!", result = tmp_result);
3467 tmp_result = fiji_init_arb_table_index(hwmgr);
3468 PP_ASSERT_WITH_CODE((0 == tmp_result),
3469 "Failed to initialize ARB table index!", result = tmp_result);
3471 tmp_result = fiji_populate_pm_fuses(hwmgr);
3472 PP_ASSERT_WITH_CODE((0 == tmp_result),
3473 "Failed to populate PM fuses!", result = tmp_result);
3475 tmp_result = fiji_enable_vrhot_gpio_interrupt(hwmgr);
3476 PP_ASSERT_WITH_CODE((0 == tmp_result),
3477 "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
3479 tmp_result = tonga_notify_smc_display_change(hwmgr, false);
3480 PP_ASSERT_WITH_CODE((0 == tmp_result),
3481 "Failed to notify no display!", result = tmp_result);
3483 tmp_result = fiji_enable_sclk_control(hwmgr);
3484 PP_ASSERT_WITH_CODE((0 == tmp_result),
3485 "Failed to enable SCLK control!", result = tmp_result);
3487 tmp_result = fiji_enable_ulv(hwmgr);
3488 PP_ASSERT_WITH_CODE((0 == tmp_result),
3489 "Failed to enable ULV!", result = tmp_result);
3491 tmp_result = fiji_enable_deep_sleep_master_switch(hwmgr);
3492 PP_ASSERT_WITH_CODE((0 == tmp_result),
3493 "Failed to enable deep sleep master switch!", result = tmp_result);
3495 tmp_result = fiji_start_dpm(hwmgr);
3496 PP_ASSERT_WITH_CODE((0 == tmp_result),
3497 "Failed to start DPM!", result = tmp_result);
3499 tmp_result = fiji_enable_smc_cac(hwmgr);
3500 PP_ASSERT_WITH_CODE((0 == tmp_result),
3501 "Failed to enable SMC CAC!", result = tmp_result);
3503 tmp_result = fiji_enable_power_containment(hwmgr);
3504 PP_ASSERT_WITH_CODE((0 == tmp_result),
3505 "Failed to enable power containment!", result = tmp_result);
3507 tmp_result = fiji_power_control_set_level(hwmgr);
3508 PP_ASSERT_WITH_CODE((0 == tmp_result),
3509 "Failed to power control set level!", result = tmp_result);
3511 tmp_result = fiji_enable_thermal_auto_throttle(hwmgr);
3512 PP_ASSERT_WITH_CODE((0 == tmp_result),
3513 "Failed to enable thermal auto throttle!", result = tmp_result);
3518 static int fiji_force_dpm_highest(struct pp_hwmgr *hwmgr)
3520 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3521 uint32_t level, tmp;
3523 if (!data->sclk_dpm_key_disabled) {
3524 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3526 tmp = data->dpm_level_enable_mask.sclk_dpm_enable_mask;
3530 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3531 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3536 if (!data->mclk_dpm_key_disabled) {
3537 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3539 tmp = data->dpm_level_enable_mask.mclk_dpm_enable_mask;
3543 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3544 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3549 if (!data->pcie_dpm_key_disabled) {
3550 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3552 tmp = data->dpm_level_enable_mask.pcie_dpm_enable_mask;
3556 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3557 PPSMC_MSG_PCIeDPM_ForceLevel,
3564 static void fiji_apply_dal_min_voltage_request(struct pp_hwmgr *hwmgr)
3566 struct phm_ppt_v1_information *table_info =
3567 (struct phm_ppt_v1_information *)hwmgr->pptable;
3568 struct phm_clock_voltage_dependency_table *table =
3569 table_info->vddc_dep_on_dal_pwrl;
3570 struct phm_ppt_v1_clock_voltage_dependency_table *vddc_table;
3571 enum PP_DAL_POWERLEVEL dal_power_level = hwmgr->dal_power_level;
3572 uint32_t req_vddc = 0, req_volt, i;
3574 if (!table && !(dal_power_level >= PP_DAL_POWERLEVEL_ULTRALOW &&
3575 dal_power_level <= PP_DAL_POWERLEVEL_PERFORMANCE))
3578 for (i= 0; i < table->count; i++) {
3579 if (dal_power_level == table->entries[i].clk) {
3580 req_vddc = table->entries[i].v;
3585 vddc_table = table_info->vdd_dep_on_sclk;
3586 for (i= 0; i < vddc_table->count; i++) {
3587 if (req_vddc <= vddc_table->entries[i].vddc) {
3588 req_volt = (((uint32_t)vddc_table->entries[i].vddc) * VOLTAGE_SCALE)
3590 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3591 PPSMC_MSG_VddC_Request, req_volt);
3595 printk(KERN_ERR "DAL requested level can not"
3596 " found a available voltage in VDDC DPM Table \n");
3599 static int fiji_upload_dpmlevel_enable_mask(struct pp_hwmgr *hwmgr)
3601 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3603 fiji_apply_dal_min_voltage_request(hwmgr);
3605 if (!data->sclk_dpm_key_disabled) {
3606 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask)
3607 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3608 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3609 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3614 static int fiji_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
3616 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3618 if (!fiji_is_dpm_running(hwmgr))
3621 if (!data->pcie_dpm_key_disabled) {
3622 smum_send_msg_to_smc(hwmgr->smumgr,
3623 PPSMC_MSG_PCIeDPM_UnForceLevel);
3626 return fiji_upload_dpmlevel_enable_mask(hwmgr);
3629 static uint32_t fiji_get_lowest_enabled_level(
3630 struct pp_hwmgr *hwmgr, uint32_t mask)
3634 while(0 == (mask & (1 << level)))
3640 static int fiji_force_dpm_lowest(struct pp_hwmgr *hwmgr)
3642 struct fiji_hwmgr *data =
3643 (struct fiji_hwmgr *)(hwmgr->backend);
3646 if (!data->sclk_dpm_key_disabled)
3647 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
3648 level = fiji_get_lowest_enabled_level(hwmgr,
3649 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
3650 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3651 PPSMC_MSG_SCLKDPM_SetEnabledMask,
3656 if (!data->mclk_dpm_key_disabled) {
3657 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
3658 level = fiji_get_lowest_enabled_level(hwmgr,
3659 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
3660 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3661 PPSMC_MSG_MCLKDPM_SetEnabledMask,
3666 if (!data->pcie_dpm_key_disabled) {
3667 if (data->dpm_level_enable_mask.pcie_dpm_enable_mask) {
3668 level = fiji_get_lowest_enabled_level(hwmgr,
3669 data->dpm_level_enable_mask.pcie_dpm_enable_mask);
3670 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
3671 PPSMC_MSG_PCIeDPM_ForceLevel,
3679 static int fiji_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
3680 enum amd_dpm_forced_level level)
3685 case AMD_DPM_FORCED_LEVEL_HIGH:
3686 ret = fiji_force_dpm_highest(hwmgr);
3690 case AMD_DPM_FORCED_LEVEL_LOW:
3691 ret = fiji_force_dpm_lowest(hwmgr);
3695 case AMD_DPM_FORCED_LEVEL_AUTO:
3696 ret = fiji_unforce_dpm_levels(hwmgr);
3704 hwmgr->dpm_level = level;
3709 static int fiji_get_power_state_size(struct pp_hwmgr *hwmgr)
3711 return sizeof(struct fiji_power_state);
3714 static int fiji_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr,
3715 void *state, struct pp_power_state *power_state,
3716 void *pp_table, uint32_t classification_flag)
3718 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3719 struct fiji_power_state *fiji_power_state =
3720 (struct fiji_power_state *)(&(power_state->hardware));
3721 struct fiji_performance_level *performance_level;
3722 ATOM_Tonga_State *state_entry = (ATOM_Tonga_State *)state;
3723 ATOM_Tonga_POWERPLAYTABLE *powerplay_table =
3724 (ATOM_Tonga_POWERPLAYTABLE *)pp_table;
3725 ATOM_Tonga_SCLK_Dependency_Table *sclk_dep_table =
3726 (ATOM_Tonga_SCLK_Dependency_Table *)
3727 (((unsigned long)powerplay_table) +
3728 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
3729 ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
3730 (ATOM_Tonga_MCLK_Dependency_Table *)
3731 (((unsigned long)powerplay_table) +
3732 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
3734 /* The following fields are not initialized here: id orderedList allStatesList */
3735 power_state->classification.ui_label =
3736 (le16_to_cpu(state_entry->usClassification) &
3737 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
3738 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
3739 power_state->classification.flags = classification_flag;
3740 /* NOTE: There is a classification2 flag in BIOS that is not being used right now */
3742 power_state->classification.temporary_state = false;
3743 power_state->classification.to_be_deleted = false;
3745 power_state->validation.disallowOnDC =
3746 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3747 ATOM_Tonga_DISALLOW_ON_DC));
3749 power_state->pcie.lanes = 0;
3751 power_state->display.disableFrameModulation = false;
3752 power_state->display.limitRefreshrate = false;
3753 power_state->display.enableVariBright =
3754 (0 != (le32_to_cpu(state_entry->ulCapsAndSettings) &
3755 ATOM_Tonga_ENABLE_VARIBRIGHT));
3757 power_state->validation.supportedPowerLevels = 0;
3758 power_state->uvd_clocks.VCLK = 0;
3759 power_state->uvd_clocks.DCLK = 0;
3760 power_state->temperatures.min = 0;
3761 power_state->temperatures.max = 0;
3763 performance_level = &(fiji_power_state->performance_levels
3764 [fiji_power_state->performance_level_count++]);
3766 PP_ASSERT_WITH_CODE(
3767 (fiji_power_state->performance_level_count < SMU73_MAX_LEVELS_GRAPHICS),
3768 "Performance levels exceeds SMC limit!",
3771 PP_ASSERT_WITH_CODE(
3772 (fiji_power_state->performance_level_count <=
3773 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
3774 "Performance levels exceeds Driver limit!",
3777 /* Performance levels are arranged from low to high. */
3778 performance_level->memory_clock = mclk_dep_table->entries
3779 [state_entry->ucMemoryClockIndexLow].ulMclk;
3780 performance_level->engine_clock = sclk_dep_table->entries
3781 [state_entry->ucEngineClockIndexLow].ulSclk;
3782 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3783 state_entry->ucPCIEGenLow);
3784 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3785 state_entry->ucPCIELaneHigh);
3787 performance_level = &(fiji_power_state->performance_levels
3788 [fiji_power_state->performance_level_count++]);
3789 performance_level->memory_clock = mclk_dep_table->entries
3790 [state_entry->ucMemoryClockIndexHigh].ulMclk;
3791 performance_level->engine_clock = sclk_dep_table->entries
3792 [state_entry->ucEngineClockIndexHigh].ulSclk;
3793 performance_level->pcie_gen = get_pcie_gen_support(data->pcie_gen_cap,
3794 state_entry->ucPCIEGenHigh);
3795 performance_level->pcie_lane = get_pcie_lane_support(data->pcie_lane_cap,
3796 state_entry->ucPCIELaneHigh);
3801 static int fiji_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3802 unsigned long entry_index, struct pp_power_state *state)
3805 struct fiji_power_state *ps;
3806 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3807 struct phm_ppt_v1_information *table_info =
3808 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3809 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
3810 table_info->vdd_dep_on_mclk;
3812 state->hardware.magic = PHM_VIslands_Magic;
3814 ps = (struct fiji_power_state *)(&state->hardware);
3816 result = tonga_get_powerplay_table_entry(hwmgr, entry_index, state,
3817 fiji_get_pp_table_entry_callback_func);
3819 /* This is the earliest time we have all the dependency table and the VBIOS boot state
3820 * as PP_Tables_GetPowerPlayTableEntry retrieves the VBIOS boot state
3821 * if there is only one VDDCI/MCLK level, check if it's the same as VBIOS boot state
3823 if (dep_mclk_table != NULL && dep_mclk_table->count == 1) {
3824 if (dep_mclk_table->entries[0].clk !=
3825 data->vbios_boot_state.mclk_bootup_value)
3826 printk(KERN_ERR "Single MCLK entry VDDCI/MCLK dependency table "
3827 "does not match VBIOS boot MCLK level");
3828 if (dep_mclk_table->entries[0].vddci !=
3829 data->vbios_boot_state.vddci_bootup_value)
3830 printk(KERN_ERR "Single VDDCI entry VDDCI/MCLK dependency table "
3831 "does not match VBIOS boot VDDCI level");
3834 /* set DC compatible flag if this state supports DC */
3835 if (!state->validation.disallowOnDC)
3836 ps->dc_compatible = true;
3838 if (state->classification.flags & PP_StateClassificationFlag_ACPI)
3839 data->acpi_pcie_gen = ps->performance_levels[0].pcie_gen;
3841 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3842 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3847 switch (state->classification.ui_label) {
3848 case PP_StateUILabel_Performance:
3849 data->use_pcie_performance_levels = true;
3851 for (i = 0; i < ps->performance_level_count; i++) {
3852 if (data->pcie_gen_performance.max <
3853 ps->performance_levels[i].pcie_gen)
3854 data->pcie_gen_performance.max =
3855 ps->performance_levels[i].pcie_gen;
3857 if (data->pcie_gen_performance.min >
3858 ps->performance_levels[i].pcie_gen)
3859 data->pcie_gen_performance.min =
3860 ps->performance_levels[i].pcie_gen;
3862 if (data->pcie_lane_performance.max <
3863 ps->performance_levels[i].pcie_lane)
3864 data->pcie_lane_performance.max =
3865 ps->performance_levels[i].pcie_lane;
3867 if (data->pcie_lane_performance.min >
3868 ps->performance_levels[i].pcie_lane)
3869 data->pcie_lane_performance.min =
3870 ps->performance_levels[i].pcie_lane;
3873 case PP_StateUILabel_Battery:
3874 data->use_pcie_power_saving_levels = true;
3876 for (i = 0; i < ps->performance_level_count; i++) {
3877 if (data->pcie_gen_power_saving.max <
3878 ps->performance_levels[i].pcie_gen)
3879 data->pcie_gen_power_saving.max =
3880 ps->performance_levels[i].pcie_gen;
3882 if (data->pcie_gen_power_saving.min >
3883 ps->performance_levels[i].pcie_gen)
3884 data->pcie_gen_power_saving.min =
3885 ps->performance_levels[i].pcie_gen;
3887 if (data->pcie_lane_power_saving.max <
3888 ps->performance_levels[i].pcie_lane)
3889 data->pcie_lane_power_saving.max =
3890 ps->performance_levels[i].pcie_lane;
3892 if (data->pcie_lane_power_saving.min >
3893 ps->performance_levels[i].pcie_lane)
3894 data->pcie_lane_power_saving.min =
3895 ps->performance_levels[i].pcie_lane;
3905 static int fiji_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
3906 struct pp_power_state *request_ps,
3907 const struct pp_power_state *current_ps)
3909 struct fiji_power_state *fiji_ps =
3910 cast_phw_fiji_power_state(&request_ps->hardware);
3913 struct PP_Clocks minimum_clocks = {0};
3914 bool disable_mclk_switching;
3915 bool disable_mclk_switching_for_frame_lock;
3916 struct cgs_display_info info = {0};
3917 const struct phm_clock_and_voltage_limits *max_limits;
3919 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
3920 struct phm_ppt_v1_information *table_info =
3921 (struct phm_ppt_v1_information *)(hwmgr->pptable);
3923 int32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
3925 data->battery_state = (PP_StateUILabel_Battery ==
3926 request_ps->classification.ui_label);
3928 PP_ASSERT_WITH_CODE(fiji_ps->performance_level_count == 2,
3929 "VI should always have 2 performance levels",);
3931 max_limits = (PP_PowerSource_AC == hwmgr->power_source) ?
3932 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
3933 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
3935 /* Cap clock DPM tables at DC MAX if it is in DC. */
3936 if (PP_PowerSource_DC == hwmgr->power_source) {
3937 for (i = 0; i < fiji_ps->performance_level_count; i++) {
3938 if (fiji_ps->performance_levels[i].memory_clock > max_limits->mclk)
3939 fiji_ps->performance_levels[i].memory_clock = max_limits->mclk;
3940 if (fiji_ps->performance_levels[i].engine_clock > max_limits->sclk)
3941 fiji_ps->performance_levels[i].engine_clock = max_limits->sclk;
3945 fiji_ps->vce_clks.evclk = hwmgr->vce_arbiter.evclk;
3946 fiji_ps->vce_clks.ecclk = hwmgr->vce_arbiter.ecclk;
3948 fiji_ps->acp_clk = hwmgr->acp_arbiter.acpclk;
3950 cgs_get_active_displays_info(hwmgr->device, &info);
3952 /*TO DO result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/
3954 /* TO DO GetMinClockSettings(hwmgr->pPECI, &minimum_clocks); */
3956 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
3957 PHM_PlatformCaps_StablePState)) {
3958 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
3959 stable_pstate_sclk = (max_limits->sclk * 75) / 100;
3961 for (count = table_info->vdd_dep_on_sclk->count - 1;
3962 count >= 0; count--) {
3963 if (stable_pstate_sclk >=
3964 table_info->vdd_dep_on_sclk->entries[count].clk) {
3965 stable_pstate_sclk =
3966 table_info->vdd_dep_on_sclk->entries[count].clk;
3972 stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3974 stable_pstate_mclk = max_limits->mclk;
3976 minimum_clocks.engineClock = stable_pstate_sclk;
3977 minimum_clocks.memoryClock = stable_pstate_mclk;
3980 if (minimum_clocks.engineClock < hwmgr->gfx_arbiter.sclk)
3981 minimum_clocks.engineClock = hwmgr->gfx_arbiter.sclk;
3983 if (minimum_clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
3984 minimum_clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
3986 fiji_ps->sclk_threshold = hwmgr->gfx_arbiter.sclk_threshold;
3988 if (0 != hwmgr->gfx_arbiter.sclk_over_drive) {
3989 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.sclk_over_drive <=
3990 hwmgr->platform_descriptor.overdriveLimit.engineClock),
3991 "Overdrive sclk exceeds limit",
3992 hwmgr->gfx_arbiter.sclk_over_drive =
3993 hwmgr->platform_descriptor.overdriveLimit.engineClock);
3995 if (hwmgr->gfx_arbiter.sclk_over_drive >= hwmgr->gfx_arbiter.sclk)
3996 fiji_ps->performance_levels[1].engine_clock =
3997 hwmgr->gfx_arbiter.sclk_over_drive;
4000 if (0 != hwmgr->gfx_arbiter.mclk_over_drive) {
4001 PP_ASSERT_WITH_CODE((hwmgr->gfx_arbiter.mclk_over_drive <=
4002 hwmgr->platform_descriptor.overdriveLimit.memoryClock),
4003 "Overdrive mclk exceeds limit",
4004 hwmgr->gfx_arbiter.mclk_over_drive =
4005 hwmgr->platform_descriptor.overdriveLimit.memoryClock);
4007 if (hwmgr->gfx_arbiter.mclk_over_drive >= hwmgr->gfx_arbiter.mclk)
4008 fiji_ps->performance_levels[1].memory_clock =
4009 hwmgr->gfx_arbiter.mclk_over_drive;
4012 disable_mclk_switching_for_frame_lock = phm_cap_enabled(
4013 hwmgr->platform_descriptor.platformCaps,
4014 PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
4016 disable_mclk_switching = (1 < info.display_count) ||
4017 disable_mclk_switching_for_frame_lock;
4019 sclk = fiji_ps->performance_levels[0].engine_clock;
4020 mclk = fiji_ps->performance_levels[0].memory_clock;
4022 if (disable_mclk_switching)
4023 mclk = fiji_ps->performance_levels
4024 [fiji_ps->performance_level_count - 1].memory_clock;
4026 if (sclk < minimum_clocks.engineClock)
4027 sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
4028 max_limits->sclk : minimum_clocks.engineClock;
4030 if (mclk < minimum_clocks.memoryClock)
4031 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
4032 max_limits->mclk : minimum_clocks.memoryClock;
4034 fiji_ps->performance_levels[0].engine_clock = sclk;
4035 fiji_ps->performance_levels[0].memory_clock = mclk;
4037 fiji_ps->performance_levels[1].engine_clock =
4038 (fiji_ps->performance_levels[1].engine_clock >=
4039 fiji_ps->performance_levels[0].engine_clock) ?
4040 fiji_ps->performance_levels[1].engine_clock :
4041 fiji_ps->performance_levels[0].engine_clock;
4043 if (disable_mclk_switching) {
4044 if (mclk < fiji_ps->performance_levels[1].memory_clock)
4045 mclk = fiji_ps->performance_levels[1].memory_clock;
4047 fiji_ps->performance_levels[0].memory_clock = mclk;
4048 fiji_ps->performance_levels[1].memory_clock = mclk;
4050 if (fiji_ps->performance_levels[1].memory_clock <
4051 fiji_ps->performance_levels[0].memory_clock)
4052 fiji_ps->performance_levels[1].memory_clock =
4053 fiji_ps->performance_levels[0].memory_clock;
4056 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4057 PHM_PlatformCaps_StablePState)) {
4058 for (i = 0; i < fiji_ps->performance_level_count; i++) {
4059 fiji_ps->performance_levels[i].engine_clock = stable_pstate_sclk;
4060 fiji_ps->performance_levels[i].memory_clock = stable_pstate_mclk;
4061 fiji_ps->performance_levels[i].pcie_gen = data->pcie_gen_performance.max;
4062 fiji_ps->performance_levels[i].pcie_lane = data->pcie_gen_performance.max;
4069 static int fiji_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
4071 const struct phm_set_power_state_input *states =
4072 (const struct phm_set_power_state_input *)input;
4073 const struct fiji_power_state *fiji_ps =
4074 cast_const_phw_fiji_power_state(states->pnew_state);
4075 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4076 struct fiji_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
4077 uint32_t sclk = fiji_ps->performance_levels
4078 [fiji_ps->performance_level_count - 1].engine_clock;
4079 struct fiji_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
4080 uint32_t mclk = fiji_ps->performance_levels
4081 [fiji_ps->performance_level_count - 1].memory_clock;
4083 struct cgs_display_info info = {0};
4085 data->need_update_smu7_dpm_table = 0;
4087 for (i = 0; i < sclk_table->count; i++) {
4088 if (sclk == sclk_table->dpm_levels[i].value)
4092 if (i >= sclk_table->count)
4093 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
4095 if(data->display_timing.min_clock_in_sr !=
4096 hwmgr->display_config.min_core_set_clock_in_sr)
4097 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_SCLK;
4100 for (i = 0; i < mclk_table->count; i++) {
4101 if (mclk == mclk_table->dpm_levels[i].value)
4105 if (i >= mclk_table->count)
4106 data->need_update_smu7_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
4108 cgs_get_active_displays_info(hwmgr->device, &info);
4110 if (data->display_timing.num_existing_displays != info.display_count)
4111 data->need_update_smu7_dpm_table |= DPMTABLE_UPDATE_MCLK;
4116 static uint16_t fiji_get_maximum_link_speed(struct pp_hwmgr *hwmgr,
4117 const struct fiji_power_state *fiji_ps)
4120 uint32_t sclk, max_sclk = 0;
4121 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4122 struct fiji_dpm_table *dpm_table = &data->dpm_table;
4124 for (i = 0; i < fiji_ps->performance_level_count; i++) {
4125 sclk = fiji_ps->performance_levels[i].engine_clock;
4126 if (max_sclk < sclk)
4130 for (i = 0; i < dpm_table->sclk_table.count; i++) {
4131 if (dpm_table->sclk_table.dpm_levels[i].value == max_sclk)
4132 return (uint16_t) ((i >= dpm_table->pcie_speed_table.count) ?
4133 dpm_table->pcie_speed_table.dpm_levels
4134 [dpm_table->pcie_speed_table.count - 1].value :
4135 dpm_table->pcie_speed_table.dpm_levels[i].value);
4141 static int fiji_request_link_speed_change_before_state_change(
4142 struct pp_hwmgr *hwmgr, const void *input)
4144 const struct phm_set_power_state_input *states =
4145 (const struct phm_set_power_state_input *)input;
4146 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4147 const struct fiji_power_state *fiji_nps =
4148 cast_const_phw_fiji_power_state(states->pnew_state);
4149 const struct fiji_power_state *fiji_cps =
4150 cast_const_phw_fiji_power_state(states->pcurrent_state);
4152 uint16_t target_link_speed = fiji_get_maximum_link_speed(hwmgr, fiji_nps);
4153 uint16_t current_link_speed;
4155 if (data->force_pcie_gen == PP_PCIEGenInvalid)
4156 current_link_speed = fiji_get_maximum_link_speed(hwmgr, fiji_cps);
4158 current_link_speed = data->force_pcie_gen;
4160 data->force_pcie_gen = PP_PCIEGenInvalid;
4161 data->pspp_notify_required = false;
4162 if (target_link_speed > current_link_speed) {
4163 switch(target_link_speed) {
4165 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN3, false))
4167 data->force_pcie_gen = PP_PCIEGen2;
4168 if (current_link_speed == PP_PCIEGen2)
4171 if (0 == acpi_pcie_perf_request(hwmgr->device, PCIE_PERF_REQ_GEN2, false))
4174 data->force_pcie_gen = fiji_get_current_pcie_speed(hwmgr);
4178 if (target_link_speed < current_link_speed)
4179 data->pspp_notify_required = true;
4185 static int fiji_freeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4187 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4189 if (0 == data->need_update_smu7_dpm_table)
4192 if ((0 == data->sclk_dpm_key_disabled) &&
4193 (data->need_update_smu7_dpm_table &
4194 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4195 PP_ASSERT_WITH_CODE(true == fiji_is_dpm_running(hwmgr),
4196 "Trying to freeze SCLK DPM when DPM is disabled",);
4197 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4198 PPSMC_MSG_SCLKDPM_FreezeLevel),
4199 "Failed to freeze SCLK DPM during FreezeSclkMclkDPM Function!",
4203 if ((0 == data->mclk_dpm_key_disabled) &&
4204 (data->need_update_smu7_dpm_table &
4205 DPMTABLE_OD_UPDATE_MCLK)) {
4206 PP_ASSERT_WITH_CODE(true == fiji_is_dpm_running(hwmgr),
4207 "Trying to freeze MCLK DPM when DPM is disabled",);
4208 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4209 PPSMC_MSG_MCLKDPM_FreezeLevel),
4210 "Failed to freeze MCLK DPM during FreezeSclkMclkDPM Function!",
4217 static int fiji_populate_and_upload_sclk_mclk_dpm_levels(
4218 struct pp_hwmgr *hwmgr, const void *input)
4221 const struct phm_set_power_state_input *states =
4222 (const struct phm_set_power_state_input *)input;
4223 const struct fiji_power_state *fiji_ps =
4224 cast_const_phw_fiji_power_state(states->pnew_state);
4225 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4226 uint32_t sclk = fiji_ps->performance_levels
4227 [fiji_ps->performance_level_count - 1].engine_clock;
4228 uint32_t mclk = fiji_ps->performance_levels
4229 [fiji_ps->performance_level_count - 1].memory_clock;
4230 struct fiji_dpm_table *dpm_table = &data->dpm_table;
4232 struct fiji_dpm_table *golden_dpm_table = &data->golden_dpm_table;
4233 uint32_t dpm_count, clock_percent;
4236 if (0 == data->need_update_smu7_dpm_table)
4239 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
4240 dpm_table->sclk_table.dpm_levels
4241 [dpm_table->sclk_table.count - 1].value = sclk;
4243 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4244 PHM_PlatformCaps_OD6PlusinACSupport) ||
4245 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4246 PHM_PlatformCaps_OD6PlusinDCSupport)) {
4247 /* Need to do calculation based on the golden DPM table
4248 * as the Heatmap GPU Clock axis is also based on the default values
4250 PP_ASSERT_WITH_CODE(
4251 (golden_dpm_table->sclk_table.dpm_levels
4252 [golden_dpm_table->sclk_table.count - 1].value != 0),
4255 dpm_count = dpm_table->sclk_table.count < 2 ?
4256 0 : dpm_table->sclk_table.count - 2;
4257 for (i = dpm_count; i > 1; i--) {
4258 if (sclk > golden_dpm_table->sclk_table.dpm_levels
4259 [golden_dpm_table->sclk_table.count-1].value) {
4261 ((sclk - golden_dpm_table->sclk_table.dpm_levels
4262 [golden_dpm_table->sclk_table.count-1].value) * 100) /
4263 golden_dpm_table->sclk_table.dpm_levels
4264 [golden_dpm_table->sclk_table.count-1].value;
4266 dpm_table->sclk_table.dpm_levels[i].value =
4267 golden_dpm_table->sclk_table.dpm_levels[i].value +
4268 (golden_dpm_table->sclk_table.dpm_levels[i].value *
4271 } else if (golden_dpm_table->sclk_table.dpm_levels
4272 [dpm_table->sclk_table.count-1].value > sclk) {
4274 ((golden_dpm_table->sclk_table.dpm_levels
4275 [golden_dpm_table->sclk_table.count - 1].value - sclk) *
4277 golden_dpm_table->sclk_table.dpm_levels
4278 [golden_dpm_table->sclk_table.count-1].value;
4280 dpm_table->sclk_table.dpm_levels[i].value =
4281 golden_dpm_table->sclk_table.dpm_levels[i].value -
4282 (golden_dpm_table->sclk_table.dpm_levels[i].value *
4283 clock_percent) / 100;
4285 dpm_table->sclk_table.dpm_levels[i].value =
4286 golden_dpm_table->sclk_table.dpm_levels[i].value;
4291 if (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
4292 dpm_table->mclk_table.dpm_levels
4293 [dpm_table->mclk_table.count - 1].value = mclk;
4294 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4295 PHM_PlatformCaps_OD6PlusinACSupport) ||
4296 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4297 PHM_PlatformCaps_OD6PlusinDCSupport)) {
4299 PP_ASSERT_WITH_CODE(
4300 (golden_dpm_table->mclk_table.dpm_levels
4301 [golden_dpm_table->mclk_table.count-1].value != 0),
4304 dpm_count = dpm_table->mclk_table.count < 2 ?
4305 0 : dpm_table->mclk_table.count - 2;
4306 for (i = dpm_count; i > 1; i--) {
4307 if (mclk > golden_dpm_table->mclk_table.dpm_levels
4308 [golden_dpm_table->mclk_table.count-1].value) {
4309 clock_percent = ((mclk -
4310 golden_dpm_table->mclk_table.dpm_levels
4311 [golden_dpm_table->mclk_table.count-1].value) * 100) /
4312 golden_dpm_table->mclk_table.dpm_levels
4313 [golden_dpm_table->mclk_table.count-1].value;
4315 dpm_table->mclk_table.dpm_levels[i].value =
4316 golden_dpm_table->mclk_table.dpm_levels[i].value +
4317 (golden_dpm_table->mclk_table.dpm_levels[i].value *
4318 clock_percent) / 100;
4320 } else if (golden_dpm_table->mclk_table.dpm_levels
4321 [dpm_table->mclk_table.count-1].value > mclk) {
4322 clock_percent = ((golden_dpm_table->mclk_table.dpm_levels
4323 [golden_dpm_table->mclk_table.count-1].value - mclk) * 100) /
4324 golden_dpm_table->mclk_table.dpm_levels
4325 [golden_dpm_table->mclk_table.count-1].value;
4327 dpm_table->mclk_table.dpm_levels[i].value =
4328 golden_dpm_table->mclk_table.dpm_levels[i].value -
4329 (golden_dpm_table->mclk_table.dpm_levels[i].value *
4330 clock_percent) / 100;
4332 dpm_table->mclk_table.dpm_levels[i].value =
4333 golden_dpm_table->mclk_table.dpm_levels[i].value;
4338 if (data->need_update_smu7_dpm_table &
4339 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK)) {
4340 result = fiji_populate_all_memory_levels(hwmgr);
4341 PP_ASSERT_WITH_CODE((0 == result),
4342 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
4346 if (data->need_update_smu7_dpm_table &
4347 (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
4348 /*populate MCLK dpm table to SMU7 */
4349 result = fiji_populate_all_memory_levels(hwmgr);
4350 PP_ASSERT_WITH_CODE((0 == result),
4351 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
4358 static int fiji_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
4359 struct fiji_single_dpm_table * dpm_table,
4360 uint32_t low_limit, uint32_t high_limit)
4364 for (i = 0; i < dpm_table->count; i++) {
4365 if ((dpm_table->dpm_levels[i].value < low_limit) ||
4366 (dpm_table->dpm_levels[i].value > high_limit))
4367 dpm_table->dpm_levels[i].enabled = false;
4369 dpm_table->dpm_levels[i].enabled = true;
4374 static int fiji_trim_dpm_states(struct pp_hwmgr *hwmgr,
4375 const struct fiji_power_state *fiji_ps)
4378 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4379 uint32_t high_limit_count;
4381 PP_ASSERT_WITH_CODE((fiji_ps->performance_level_count >= 1),
4382 "power state did not have any performance level",
4385 high_limit_count = (1 == fiji_ps->performance_level_count) ? 0 : 1;
4387 fiji_trim_single_dpm_states(hwmgr,
4388 &(data->dpm_table.sclk_table),
4389 fiji_ps->performance_levels[0].engine_clock,
4390 fiji_ps->performance_levels[high_limit_count].engine_clock);
4392 fiji_trim_single_dpm_states(hwmgr,
4393 &(data->dpm_table.mclk_table),
4394 fiji_ps->performance_levels[0].memory_clock,
4395 fiji_ps->performance_levels[high_limit_count].memory_clock);
4400 static int fiji_generate_dpm_level_enable_mask(
4401 struct pp_hwmgr *hwmgr, const void *input)
4404 const struct phm_set_power_state_input *states =
4405 (const struct phm_set_power_state_input *)input;
4406 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4407 const struct fiji_power_state *fiji_ps =
4408 cast_const_phw_fiji_power_state(states->pnew_state);
4410 result = fiji_trim_dpm_states(hwmgr, fiji_ps);
4414 data->dpm_level_enable_mask.sclk_dpm_enable_mask =
4415 fiji_get_dpm_level_enable_mask_value(&data->dpm_table.sclk_table);
4416 data->dpm_level_enable_mask.mclk_dpm_enable_mask =
4417 fiji_get_dpm_level_enable_mask_value(&data->dpm_table.mclk_table);
4418 data->last_mclk_dpm_enable_mask =
4419 data->dpm_level_enable_mask.mclk_dpm_enable_mask;
4421 if (data->uvd_enabled) {
4422 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask & 1)
4423 data->dpm_level_enable_mask.mclk_dpm_enable_mask &= 0xFFFFFFFE;
4426 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
4427 fiji_get_dpm_level_enable_mask_value(&data->dpm_table.pcie_speed_table);
4432 int fiji_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable)
4434 return smum_send_msg_to_smc(hwmgr->smumgr, enable ?
4435 (PPSMC_Msg)PPSMC_MSG_UVDDPM_Enable :
4436 (PPSMC_Msg)PPSMC_MSG_UVDDPM_Disable);
4439 int fiji_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
4441 return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4442 PPSMC_MSG_VCEDPM_Enable :
4443 PPSMC_MSG_VCEDPM_Disable);
4446 int fiji_enable_disable_samu_dpm(struct pp_hwmgr *hwmgr, bool enable)
4448 return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4449 PPSMC_MSG_SAMUDPM_Enable :
4450 PPSMC_MSG_SAMUDPM_Disable);
4453 int fiji_enable_disable_acp_dpm(struct pp_hwmgr *hwmgr, bool enable)
4455 return smum_send_msg_to_smc(hwmgr->smumgr, enable?
4456 PPSMC_MSG_ACPDPM_Enable :
4457 PPSMC_MSG_ACPDPM_Disable);
4460 int fiji_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate)
4462 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4463 uint32_t mm_boot_level_offset, mm_boot_level_value;
4464 struct phm_ppt_v1_information *table_info =
4465 (struct phm_ppt_v1_information *)(hwmgr->pptable);
4468 data->smc_state_table.UvdBootLevel = 0;
4469 if (table_info->mm_dep_table->count > 0)
4470 data->smc_state_table.UvdBootLevel =
4471 (uint8_t) (table_info->mm_dep_table->count - 1);
4472 mm_boot_level_offset = data->dpm_table_start +
4473 offsetof(SMU73_Discrete_DpmTable, UvdBootLevel);
4474 mm_boot_level_offset /= 4;
4475 mm_boot_level_offset *= 4;
4476 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4477 CGS_IND_REG__SMC, mm_boot_level_offset);
4478 mm_boot_level_value &= 0x00FFFFFF;
4479 mm_boot_level_value |= data->smc_state_table.UvdBootLevel << 24;
4480 cgs_write_ind_register(hwmgr->device,
4481 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4483 if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4484 PHM_PlatformCaps_UVDDPM) ||
4485 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4486 PHM_PlatformCaps_StablePState))
4487 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4488 PPSMC_MSG_UVDDPM_SetEnabledMask,
4489 (uint32_t)(1 << data->smc_state_table.UvdBootLevel));
4492 return fiji_enable_disable_uvd_dpm(hwmgr, !bgate);
4495 int fiji_update_vce_dpm(struct pp_hwmgr *hwmgr, const void *input)
4497 const struct phm_set_power_state_input *states =
4498 (const struct phm_set_power_state_input *)input;
4499 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4500 const struct fiji_power_state *fiji_nps =
4501 cast_const_phw_fiji_power_state(states->pnew_state);
4502 const struct fiji_power_state *fiji_cps =
4503 cast_const_phw_fiji_power_state(states->pcurrent_state);
4505 uint32_t mm_boot_level_offset, mm_boot_level_value;
4506 struct phm_ppt_v1_information *table_info =
4507 (struct phm_ppt_v1_information *)(hwmgr->pptable);
4509 if (fiji_nps->vce_clks.evclk >0 &&
4510 (fiji_cps == NULL || fiji_cps->vce_clks.evclk == 0)) {
4511 data->smc_state_table.VceBootLevel =
4512 (uint8_t) (table_info->mm_dep_table->count - 1);
4514 mm_boot_level_offset = data->dpm_table_start +
4515 offsetof(SMU73_Discrete_DpmTable, VceBootLevel);
4516 mm_boot_level_offset /= 4;
4517 mm_boot_level_offset *= 4;
4518 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4519 CGS_IND_REG__SMC, mm_boot_level_offset);
4520 mm_boot_level_value &= 0xFF00FFFF;
4521 mm_boot_level_value |= data->smc_state_table.VceBootLevel << 16;
4522 cgs_write_ind_register(hwmgr->device,
4523 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4525 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4526 PHM_PlatformCaps_StablePState)) {
4527 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4528 PPSMC_MSG_VCEDPM_SetEnabledMask,
4529 (uint32_t)1 << data->smc_state_table.VceBootLevel);
4531 fiji_enable_disable_vce_dpm(hwmgr, true);
4532 } else if (fiji_nps->vce_clks.evclk == 0 &&
4534 fiji_cps->vce_clks.evclk > 0)
4535 fiji_enable_disable_vce_dpm(hwmgr, false);
4541 int fiji_update_samu_dpm(struct pp_hwmgr *hwmgr, bool bgate)
4543 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4544 uint32_t mm_boot_level_offset, mm_boot_level_value;
4545 struct phm_ppt_v1_information *table_info =
4546 (struct phm_ppt_v1_information *)(hwmgr->pptable);
4549 data->smc_state_table.SamuBootLevel =
4550 (uint8_t) (table_info->mm_dep_table->count - 1);
4551 mm_boot_level_offset = data->dpm_table_start +
4552 offsetof(SMU73_Discrete_DpmTable, SamuBootLevel);
4553 mm_boot_level_offset /= 4;
4554 mm_boot_level_offset *= 4;
4555 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4556 CGS_IND_REG__SMC, mm_boot_level_offset);
4557 mm_boot_level_value &= 0xFFFFFF00;
4558 mm_boot_level_value |= data->smc_state_table.SamuBootLevel << 0;
4559 cgs_write_ind_register(hwmgr->device,
4560 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4562 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4563 PHM_PlatformCaps_StablePState))
4564 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4565 PPSMC_MSG_SAMUDPM_SetEnabledMask,
4566 (uint32_t)(1 << data->smc_state_table.SamuBootLevel));
4569 return fiji_enable_disable_samu_dpm(hwmgr, !bgate);
4572 int fiji_update_acp_dpm(struct pp_hwmgr *hwmgr, bool bgate)
4574 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4575 uint32_t mm_boot_level_offset, mm_boot_level_value;
4576 struct phm_ppt_v1_information *table_info =
4577 (struct phm_ppt_v1_information *)(hwmgr->pptable);
4580 data->smc_state_table.AcpBootLevel =
4581 (uint8_t) (table_info->mm_dep_table->count - 1);
4582 mm_boot_level_offset = data->dpm_table_start +
4583 offsetof(SMU73_Discrete_DpmTable, AcpBootLevel);
4584 mm_boot_level_offset /= 4;
4585 mm_boot_level_offset *= 4;
4586 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
4587 CGS_IND_REG__SMC, mm_boot_level_offset);
4588 mm_boot_level_value &= 0xFFFF00FF;
4589 mm_boot_level_value |= data->smc_state_table.AcpBootLevel << 8;
4590 cgs_write_ind_register(hwmgr->device,
4591 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
4593 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4594 PHM_PlatformCaps_StablePState))
4595 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4596 PPSMC_MSG_ACPDPM_SetEnabledMask,
4597 (uint32_t)(1 << data->smc_state_table.AcpBootLevel));
4600 return fiji_enable_disable_acp_dpm(hwmgr, !bgate);
4603 static int fiji_update_sclk_threshold(struct pp_hwmgr *hwmgr)
4605 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4608 uint32_t low_sclk_interrupt_threshold = 0;
4610 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4611 PHM_PlatformCaps_SclkThrottleLowNotification)
4612 && (hwmgr->gfx_arbiter.sclk_threshold !=
4613 data->low_sclk_interrupt_threshold)) {
4614 data->low_sclk_interrupt_threshold =
4615 hwmgr->gfx_arbiter.sclk_threshold;
4616 low_sclk_interrupt_threshold =
4617 data->low_sclk_interrupt_threshold;
4619 CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
4621 result = fiji_copy_bytes_to_smc(
4623 data->dpm_table_start +
4624 offsetof(SMU73_Discrete_DpmTable,
4625 LowSclkInterruptThreshold),
4626 (uint8_t *)&low_sclk_interrupt_threshold,
4634 static int fiji_program_mem_timing_parameters(struct pp_hwmgr *hwmgr)
4636 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4638 if (data->need_update_smu7_dpm_table &
4639 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_OD_UPDATE_MCLK))
4640 return fiji_program_memory_timing_parameters(hwmgr);
4645 static int fiji_unfreeze_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
4647 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4649 if (0 == data->need_update_smu7_dpm_table)
4652 if ((0 == data->sclk_dpm_key_disabled) &&
4653 (data->need_update_smu7_dpm_table &
4654 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK))) {
4656 PP_ASSERT_WITH_CODE(true == fiji_is_dpm_running(hwmgr),
4657 "Trying to Unfreeze SCLK DPM when DPM is disabled",);
4658 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4659 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4660 "Failed to unfreeze SCLK DPM during UnFreezeSclkMclkDPM Function!",
4664 if ((0 == data->mclk_dpm_key_disabled) &&
4665 (data->need_update_smu7_dpm_table & DPMTABLE_OD_UPDATE_MCLK)) {
4667 PP_ASSERT_WITH_CODE(true == fiji_is_dpm_running(hwmgr),
4668 "Trying to Unfreeze MCLK DPM when DPM is disabled",);
4669 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(hwmgr->smumgr,
4670 PPSMC_MSG_SCLKDPM_UnfreezeLevel),
4671 "Failed to unfreeze MCLK DPM during UnFreezeSclkMclkDPM Function!",
4675 data->need_update_smu7_dpm_table = 0;
4680 /* Look up the voltaged based on DAL's requested level.
4681 * and then send the requested VDDC voltage to SMC
4683 static void fiji_apply_dal_minimum_voltage_request(struct pp_hwmgr *hwmgr)
4688 int fiji_upload_dpm_level_enable_mask(struct pp_hwmgr *hwmgr)
4691 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4693 /* Apply minimum voltage based on DAL's request level */
4694 fiji_apply_dal_minimum_voltage_request(hwmgr);
4696 if (0 == data->sclk_dpm_key_disabled) {
4697 /* Checking if DPM is running. If we discover hang because of this,
4698 * we should skip this message.
4700 if (!fiji_is_dpm_running(hwmgr))
4701 printk(KERN_ERR "[ powerplay ] "
4702 "Trying to set Enable Mask when DPM is disabled \n");
4704 if (data->dpm_level_enable_mask.sclk_dpm_enable_mask) {
4705 result = smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4706 PPSMC_MSG_SCLKDPM_SetEnabledMask,
4707 data->dpm_level_enable_mask.sclk_dpm_enable_mask);
4708 PP_ASSERT_WITH_CODE((0 == result),
4709 "Set Sclk Dpm enable Mask failed", return -1);
4713 if (0 == data->mclk_dpm_key_disabled) {
4714 /* Checking if DPM is running. If we discover hang because of this,
4715 * we should skip this message.
4717 if (!fiji_is_dpm_running(hwmgr))
4718 printk(KERN_ERR "[ powerplay ]"
4719 " Trying to set Enable Mask when DPM is disabled \n");
4721 if (data->dpm_level_enable_mask.mclk_dpm_enable_mask) {
4722 result = smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4723 PPSMC_MSG_MCLKDPM_SetEnabledMask,
4724 data->dpm_level_enable_mask.mclk_dpm_enable_mask);
4725 PP_ASSERT_WITH_CODE((0 == result),
4726 "Set Mclk Dpm enable Mask failed", return -1);
4733 static int fiji_notify_link_speed_change_after_state_change(
4734 struct pp_hwmgr *hwmgr, const void *input)
4736 const struct phm_set_power_state_input *states =
4737 (const struct phm_set_power_state_input *)input;
4738 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4739 const struct fiji_power_state *fiji_ps =
4740 cast_const_phw_fiji_power_state(states->pnew_state);
4741 uint16_t target_link_speed = fiji_get_maximum_link_speed(hwmgr, fiji_ps);
4744 if (data->pspp_notify_required) {
4745 if (target_link_speed == PP_PCIEGen3)
4746 request = PCIE_PERF_REQ_GEN3;
4747 else if (target_link_speed == PP_PCIEGen2)
4748 request = PCIE_PERF_REQ_GEN2;
4750 request = PCIE_PERF_REQ_GEN1;
4752 if(request == PCIE_PERF_REQ_GEN1 &&
4753 fiji_get_current_pcie_speed(hwmgr) > 0)
4756 if (acpi_pcie_perf_request(hwmgr->device, request, false)) {
4757 if (PP_PCIEGen2 == target_link_speed)
4758 printk("PSPP request to switch to Gen2 from Gen3 Failed!");
4760 printk("PSPP request to switch to Gen1 from Gen2 Failed!");
4767 static int fiji_set_power_state_tasks(struct pp_hwmgr *hwmgr,
4770 int tmp_result, result = 0;
4772 tmp_result = fiji_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
4773 PP_ASSERT_WITH_CODE((0 == tmp_result),
4774 "Failed to find DPM states clocks in DPM table!",
4775 result = tmp_result);
4777 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4778 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4780 fiji_request_link_speed_change_before_state_change(hwmgr, input);
4781 PP_ASSERT_WITH_CODE((0 == tmp_result),
4782 "Failed to request link speed change before state change!",
4783 result = tmp_result);
4786 tmp_result = fiji_freeze_sclk_mclk_dpm(hwmgr);
4787 PP_ASSERT_WITH_CODE((0 == tmp_result),
4788 "Failed to freeze SCLK MCLK DPM!", result = tmp_result);
4790 tmp_result = fiji_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
4791 PP_ASSERT_WITH_CODE((0 == tmp_result),
4792 "Failed to populate and upload SCLK MCLK DPM levels!",
4793 result = tmp_result);
4795 tmp_result = fiji_generate_dpm_level_enable_mask(hwmgr, input);
4796 PP_ASSERT_WITH_CODE((0 == tmp_result),
4797 "Failed to generate DPM level enabled mask!",
4798 result = tmp_result);
4800 tmp_result = fiji_update_vce_dpm(hwmgr, input);
4801 PP_ASSERT_WITH_CODE((0 == tmp_result),
4802 "Failed to update VCE DPM!",
4803 result = tmp_result);
4805 tmp_result = fiji_update_sclk_threshold(hwmgr);
4806 PP_ASSERT_WITH_CODE((0 == tmp_result),
4807 "Failed to update SCLK threshold!",
4808 result = tmp_result);
4810 tmp_result = fiji_program_mem_timing_parameters(hwmgr);
4811 PP_ASSERT_WITH_CODE((0 == tmp_result),
4812 "Failed to program memory timing parameters!",
4813 result = tmp_result);
4815 tmp_result = fiji_unfreeze_sclk_mclk_dpm(hwmgr);
4816 PP_ASSERT_WITH_CODE((0 == tmp_result),
4817 "Failed to unfreeze SCLK MCLK DPM!",
4818 result = tmp_result);
4820 tmp_result = fiji_upload_dpm_level_enable_mask(hwmgr);
4821 PP_ASSERT_WITH_CODE((0 == tmp_result),
4822 "Failed to upload DPM level enabled mask!",
4823 result = tmp_result);
4825 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
4826 PHM_PlatformCaps_PCIEPerformanceRequest)) {
4828 fiji_notify_link_speed_change_after_state_change(hwmgr, input);
4829 PP_ASSERT_WITH_CODE((0 == tmp_result),
4830 "Failed to notify link speed change after state change!",
4831 result = tmp_result);
4837 static int fiji_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
4839 struct pp_power_state *ps;
4840 struct fiji_power_state *fiji_ps;
4845 ps = hwmgr->request_ps;
4850 fiji_ps = cast_phw_fiji_power_state(&ps->hardware);
4853 return fiji_ps->performance_levels[0].engine_clock;
4855 return fiji_ps->performance_levels
4856 [fiji_ps->performance_level_count-1].engine_clock;
4859 static int fiji_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
4861 struct pp_power_state *ps;
4862 struct fiji_power_state *fiji_ps;
4867 ps = hwmgr->request_ps;
4872 fiji_ps = cast_phw_fiji_power_state(&ps->hardware);
4875 return fiji_ps->performance_levels[0].memory_clock;
4877 return fiji_ps->performance_levels
4878 [fiji_ps->performance_level_count-1].memory_clock;
4881 static void fiji_print_current_perforce_level(
4882 struct pp_hwmgr *hwmgr, struct seq_file *m)
4884 uint32_t sclk, mclk, activity_percent = 0;
4886 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4888 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
4890 sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
4892 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
4894 mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
4895 seq_printf(m, "\n [ mclk ]: %u MHz\n\n [ sclk ]: %u MHz\n",
4896 mclk / 100, sclk / 100);
4898 offset = data->soft_regs_start + offsetof(SMU73_SoftRegisters, AverageGraphicsActivity);
4899 activity_percent = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset);
4900 activity_percent += 0x80;
4901 activity_percent >>= 8;
4903 seq_printf(m, "\n [GPU load]: %u%%\n\n", activity_percent > 100 ? 100 : activity_percent);
4905 seq_printf(m, "uvd %sabled\n", data->uvd_power_gated ? "dis" : "en");
4907 seq_printf(m, "vce %sabled\n", data->vce_power_gated ? "dis" : "en");
4910 static int fiji_program_display_gap(struct pp_hwmgr *hwmgr)
4912 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
4913 uint32_t num_active_displays = 0;
4914 uint32_t display_gap = cgs_read_ind_register(hwmgr->device,
4915 CGS_IND_REG__SMC, ixCG_DISPLAY_GAP_CNTL);
4916 uint32_t display_gap2;
4917 uint32_t pre_vbi_time_in_us;
4918 uint32_t frame_time_in_us;
4920 uint32_t refresh_rate = 0;
4921 struct cgs_display_info info = {0};
4922 struct cgs_mode_info mode_info;
4924 info.mode_info = &mode_info;
4926 cgs_get_active_displays_info(hwmgr->device, &info);
4927 num_active_displays = info.display_count;
4929 display_gap = PHM_SET_FIELD(display_gap, CG_DISPLAY_GAP_CNTL,
4930 DISP_GAP, (num_active_displays > 0)?
4931 DISPLAY_GAP_VBLANK_OR_WM : DISPLAY_GAP_IGNORE);
4932 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4933 ixCG_DISPLAY_GAP_CNTL, display_gap);
4935 ref_clock = mode_info.ref_clock;
4936 refresh_rate = mode_info.refresh_rate;
4938 if (refresh_rate == 0)
4941 frame_time_in_us = 1000000 / refresh_rate;
4943 pre_vbi_time_in_us = frame_time_in_us - 200 - mode_info.vblank_time_us;
4944 display_gap2 = pre_vbi_time_in_us * (ref_clock / 100);
4946 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4947 ixCG_DISPLAY_GAP_CNTL2, display_gap2);
4949 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4950 data->soft_regs_start +
4951 offsetof(SMU73_SoftRegisters, PreVBlankGap), 0x64);
4953 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
4954 data->soft_regs_start +
4955 offsetof(SMU73_SoftRegisters, VBlankTimeout),
4956 (frame_time_in_us - pre_vbi_time_in_us));
4958 if (num_active_displays == 1)
4959 tonga_notify_smc_display_change(hwmgr, true);
4964 int fiji_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
4966 return fiji_program_display_gap(hwmgr);
4969 static int fiji_set_max_fan_pwm_output(struct pp_hwmgr *hwmgr,
4970 uint16_t us_max_fan_pwm)
4972 hwmgr->thermal_controller.
4973 advanceFanControlParameters.usMaxFanPWM = us_max_fan_pwm;
4975 if (phm_is_hw_access_blocked(hwmgr))
4978 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4979 PPSMC_MSG_SetFanPwmMax, us_max_fan_pwm);
4982 static int fiji_set_max_fan_rpm_output(struct pp_hwmgr *hwmgr,
4983 uint16_t us_max_fan_rpm)
4985 hwmgr->thermal_controller.
4986 advanceFanControlParameters.usMaxFanRPM = us_max_fan_rpm;
4988 if (phm_is_hw_access_blocked(hwmgr))
4991 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
4992 PPSMC_MSG_SetFanRpmMax, us_max_fan_rpm);
4995 int fiji_dpm_set_interrupt_state(void *private_data,
4996 unsigned src_id, unsigned type,
4999 uint32_t cg_thermal_int;
5000 struct pp_hwmgr *hwmgr = ((struct pp_eventmgr *)private_data)->hwmgr;
5006 case AMD_THERMAL_IRQ_LOW_TO_HIGH:
5008 cg_thermal_int = cgs_read_ind_register(hwmgr->device,
5009 CGS_IND_REG__SMC, ixCG_THERMAL_INT);
5010 cg_thermal_int |= CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK;
5011 cgs_write_ind_register(hwmgr->device,
5012 CGS_IND_REG__SMC, ixCG_THERMAL_INT, cg_thermal_int);
5014 cg_thermal_int = cgs_read_ind_register(hwmgr->device,
5015 CGS_IND_REG__SMC, ixCG_THERMAL_INT);
5016 cg_thermal_int &= ~CG_THERMAL_INT_CTRL__THERM_INTH_MASK_MASK;
5017 cgs_write_ind_register(hwmgr->device,
5018 CGS_IND_REG__SMC, ixCG_THERMAL_INT, cg_thermal_int);
5022 case AMD_THERMAL_IRQ_HIGH_TO_LOW:
5024 cg_thermal_int = cgs_read_ind_register(hwmgr->device,
5025 CGS_IND_REG__SMC, ixCG_THERMAL_INT);
5026 cg_thermal_int |= CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK;
5027 cgs_write_ind_register(hwmgr->device,
5028 CGS_IND_REG__SMC, ixCG_THERMAL_INT, cg_thermal_int);
5030 cg_thermal_int = cgs_read_ind_register(hwmgr->device,
5031 CGS_IND_REG__SMC, ixCG_THERMAL_INT);
5032 cg_thermal_int &= ~CG_THERMAL_INT_CTRL__THERM_INTL_MASK_MASK;
5033 cgs_write_ind_register(hwmgr->device,
5034 CGS_IND_REG__SMC, ixCG_THERMAL_INT, cg_thermal_int);
5043 int fiji_register_internal_thermal_interrupt(struct pp_hwmgr *hwmgr,
5044 const void *thermal_interrupt_info)
5047 const struct pp_interrupt_registration_info *info =
5048 (const struct pp_interrupt_registration_info *)
5049 thermal_interrupt_info;
5054 result = cgs_add_irq_source(hwmgr->device, 230, AMD_THERMAL_IRQ_LAST,
5055 fiji_dpm_set_interrupt_state,
5056 info->call_back, info->context);
5061 result = cgs_add_irq_source(hwmgr->device, 231, AMD_THERMAL_IRQ_LAST,
5062 fiji_dpm_set_interrupt_state,
5063 info->call_back, info->context);
5071 static int fiji_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
5074 /* stop auto-manage */
5075 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
5076 PHM_PlatformCaps_MicrocodeFanControl))
5077 fiji_fan_ctrl_stop_smc_fan_control(hwmgr);
5078 fiji_fan_ctrl_set_static_mode(hwmgr, mode);
5080 /* restart auto-manage */
5081 fiji_fan_ctrl_reset_fan_speed_to_default(hwmgr);
5086 static int fiji_get_fan_control_mode(struct pp_hwmgr *hwmgr)
5088 if (hwmgr->fan_ctrl_is_in_default_mode)
5089 return hwmgr->fan_ctrl_default_mode;
5091 return PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
5092 CG_FDO_CTRL2, FDO_PWM_MODE);
5095 static int fiji_get_pp_table(struct pp_hwmgr *hwmgr, char **table)
5097 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
5099 *table = (char *)&data->smc_state_table;
5101 return sizeof(struct SMU73_Discrete_DpmTable);
5104 static int fiji_set_pp_table(struct pp_hwmgr *hwmgr, const char *buf, size_t size)
5106 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
5108 void *table = (void *)&data->smc_state_table;
5110 memcpy(table, buf, size);
5115 static int fiji_force_clock_level(struct pp_hwmgr *hwmgr,
5116 enum pp_clock_type type, int level)
5118 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
5120 if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL)
5125 if (!data->sclk_dpm_key_disabled)
5126 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
5127 PPSMC_MSG_SCLKDPM_SetEnabledMask,
5131 if (!data->mclk_dpm_key_disabled)
5132 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
5133 PPSMC_MSG_MCLKDPM_SetEnabledMask,
5137 if (!data->pcie_dpm_key_disabled)
5138 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
5139 PPSMC_MSG_PCIeDPM_ForceLevel,
5149 static int fiji_print_clock_levels(struct pp_hwmgr *hwmgr,
5150 enum pp_clock_type type, char *buf)
5152 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
5153 struct fiji_single_dpm_table *sclk_table = &(data->dpm_table.sclk_table);
5154 struct fiji_single_dpm_table *mclk_table = &(data->dpm_table.mclk_table);
5155 struct fiji_single_dpm_table *pcie_table = &(data->dpm_table.pcie_speed_table);
5156 int i, now, size = 0;
5157 uint32_t clock, pcie_speed;
5161 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);
5162 clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
5164 for (i = 0; i < sclk_table->count; i++) {
5165 if (clock > sclk_table->dpm_levels[i].value)
5171 for (i = 0; i < sclk_table->count; i++)
5172 size += sprintf(buf + size, "%d: %uMhz %s\n",
5173 i, sclk_table->dpm_levels[i].value / 100,
5174 (i == now) ? "*" : "");
5177 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);
5178 clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
5180 for (i = 0; i < mclk_table->count; i++) {
5181 if (clock > mclk_table->dpm_levels[i].value)
5187 for (i = 0; i < mclk_table->count; i++)
5188 size += sprintf(buf + size, "%d: %uMhz %s\n",
5189 i, mclk_table->dpm_levels[i].value / 100,
5190 (i == now) ? "*" : "");
5193 pcie_speed = fiji_get_current_pcie_speed(hwmgr);
5194 for (i = 0; i < pcie_table->count; i++) {
5195 if (pcie_speed != pcie_table->dpm_levels[i].value)
5201 for (i = 0; i < pcie_table->count; i++)
5202 size += sprintf(buf + size, "%d: %s %s\n", i,
5203 (pcie_table->dpm_levels[i].value == 0) ? "2.5GB, x1" :
5204 (pcie_table->dpm_levels[i].value == 1) ? "5.0GB, x16" :
5205 (pcie_table->dpm_levels[i].value == 2) ? "8.0GB, x16" : "",
5206 (i == now) ? "*" : "");
5214 static inline bool fiji_are_power_levels_equal(const struct fiji_performance_level *pl1,
5215 const struct fiji_performance_level *pl2)
5217 return ((pl1->memory_clock == pl2->memory_clock) &&
5218 (pl1->engine_clock == pl2->engine_clock) &&
5219 (pl1->pcie_gen == pl2->pcie_gen) &&
5220 (pl1->pcie_lane == pl2->pcie_lane));
5223 int fiji_check_states_equal(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *pstate1, const struct pp_hw_power_state *pstate2, bool *equal)
5225 const struct fiji_power_state *psa = cast_const_phw_fiji_power_state(pstate1);
5226 const struct fiji_power_state *psb = cast_const_phw_fiji_power_state(pstate2);
5229 if (equal == NULL || psa == NULL || psb == NULL)
5232 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
5233 if (psa->performance_level_count != psb->performance_level_count) {
5238 for (i = 0; i < psa->performance_level_count; i++) {
5239 if (!fiji_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) {
5240 /* If we have found even one performance level pair that is different the states are different. */
5246 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
5247 *equal = ((psa->uvd_clks.vclk == psb->uvd_clks.vclk) && (psa->uvd_clks.dclk == psb->uvd_clks.dclk));
5248 *equal &= ((psa->vce_clks.evclk == psb->vce_clks.evclk) && (psa->vce_clks.ecclk == psb->vce_clks.ecclk));
5249 *equal &= (psa->sclk_threshold == psb->sclk_threshold);
5250 *equal &= (psa->acp_clk == psb->acp_clk);
5255 bool fiji_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
5257 struct fiji_hwmgr *data = (struct fiji_hwmgr *)(hwmgr->backend);
5258 bool is_update_required = false;
5259 struct cgs_display_info info = {0,0,NULL};
5261 cgs_get_active_displays_info(hwmgr->device, &info);
5263 if (data->display_timing.num_existing_displays != info.display_count)
5264 is_update_required = true;
5266 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
5267 if(hwmgr->display_config.min_core_set_clock_in_sr != data->display_timing.min_clock_in_sr)
5268 is_update_required = true;
5271 return is_update_required;
5275 static const struct pp_hwmgr_func fiji_hwmgr_funcs = {
5276 .backend_init = &fiji_hwmgr_backend_init,
5277 .backend_fini = &tonga_hwmgr_backend_fini,
5278 .asic_setup = &fiji_setup_asic_task,
5279 .dynamic_state_management_enable = &fiji_enable_dpm_tasks,
5280 .force_dpm_level = &fiji_dpm_force_dpm_level,
5281 .get_num_of_pp_table_entries = &tonga_get_number_of_powerplay_table_entries,
5282 .get_power_state_size = &fiji_get_power_state_size,
5283 .get_pp_table_entry = &fiji_get_pp_table_entry,
5284 .patch_boot_state = &fiji_patch_boot_state,
5285 .apply_state_adjust_rules = &fiji_apply_state_adjust_rules,
5286 .power_state_set = &fiji_set_power_state_tasks,
5287 .get_sclk = &fiji_dpm_get_sclk,
5288 .get_mclk = &fiji_dpm_get_mclk,
5289 .print_current_perforce_level = &fiji_print_current_perforce_level,
5290 .powergate_uvd = &fiji_phm_powergate_uvd,
5291 .powergate_vce = &fiji_phm_powergate_vce,
5292 .disable_clock_power_gating = &fiji_phm_disable_clock_power_gating,
5293 .notify_smc_display_config_after_ps_adjustment =
5294 &tonga_notify_smc_display_config_after_ps_adjustment,
5295 .display_config_changed = &fiji_display_configuration_changed_task,
5296 .set_max_fan_pwm_output = fiji_set_max_fan_pwm_output,
5297 .set_max_fan_rpm_output = fiji_set_max_fan_rpm_output,
5298 .get_temperature = fiji_thermal_get_temperature,
5299 .stop_thermal_controller = fiji_thermal_stop_thermal_controller,
5300 .get_fan_speed_info = fiji_fan_ctrl_get_fan_speed_info,
5301 .get_fan_speed_percent = fiji_fan_ctrl_get_fan_speed_percent,
5302 .set_fan_speed_percent = fiji_fan_ctrl_set_fan_speed_percent,
5303 .reset_fan_speed_to_default = fiji_fan_ctrl_reset_fan_speed_to_default,
5304 .get_fan_speed_rpm = fiji_fan_ctrl_get_fan_speed_rpm,
5305 .set_fan_speed_rpm = fiji_fan_ctrl_set_fan_speed_rpm,
5306 .uninitialize_thermal_controller = fiji_thermal_ctrl_uninitialize_thermal_controller,
5307 .register_internal_thermal_interrupt = fiji_register_internal_thermal_interrupt,
5308 .set_fan_control_mode = fiji_set_fan_control_mode,
5309 .get_fan_control_mode = fiji_get_fan_control_mode,
5310 .check_states_equal = fiji_check_states_equal,
5311 .check_smc_update_required_for_display_configuration = fiji_check_smc_update_required_for_display_configuration,
5312 .get_pp_table = fiji_get_pp_table,
5313 .set_pp_table = fiji_set_pp_table,
5314 .force_clock_level = fiji_force_clock_level,
5315 .print_clock_levels = fiji_print_clock_levels,
5318 int fiji_hwmgr_init(struct pp_hwmgr *hwmgr)
5320 struct fiji_hwmgr *data;
5323 data = kzalloc(sizeof(struct fiji_hwmgr), GFP_KERNEL);
5327 hwmgr->backend = data;
5328 hwmgr->hwmgr_func = &fiji_hwmgr_funcs;
5329 hwmgr->pptable_func = &tonga_pptable_funcs;
5330 pp_fiji_thermal_initialize(hwmgr);