drm/amd/powerplay: add fan controller table v11 support.
authorRex Zhu <Rex.Zhu@amd.com>
Thu, 30 Mar 2017 09:58:05 +0000 (17:58 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 7 Apr 2017 19:15:44 +0000 (15:15 -0400)
Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/powerplay/hwmgr/vega10_pptable.h
drivers/gpu/drm/amd/powerplay/hwmgr/vega10_processpptables.c

index 63a03895b84efcb0af88041606618ed6477fe7b7..6a907c93fd9c40748e691494f12b43b4f853933a 100644 (file)
@@ -250,6 +250,29 @@ typedef struct _ATOM_Vega10_Fan_Table {
        USHORT  usFanStartTemperature;
 } ATOM_Vega10_Fan_Table;
 
+typedef struct _ATOM_Vega10_Fan_Table_V2 {
+       UCHAR   ucRevId;
+       USHORT  usFanOutputSensitivity;
+       USHORT  usFanAcousticLimitRpm;
+       USHORT  usThrottlingRPM;
+       USHORT  usTargetTemperature;
+       USHORT  usMinimumPWMLimit;
+       USHORT  usTargetGfxClk;
+       USHORT  usFanGainEdge;
+       USHORT  usFanGainHotspot;
+       USHORT  usFanGainLiquid;
+       USHORT  usFanGainVrVddc;
+       USHORT  usFanGainVrMvdd;
+       USHORT  usFanGainPlx;
+       USHORT  usFanGainHbm;
+       UCHAR   ucEnableZeroRPM;
+       USHORT  usFanStopTemperature;
+       USHORT  usFanStartTemperature;
+       UCHAR   ucFanParameters;
+       UCHAR   ucFanMinRPM;
+       UCHAR   ucFanMaxRPM;
+} ATOM_Vega10_Fan_Table_V2;
+
 typedef struct _ATOM_Vega10_Thermal_Controller {
        UCHAR ucRevId;
        UCHAR ucType;           /* one of ATOM_VEGA10_PP_THERMALCONTROLLER_*/
index d14d885c042e8f2cac240be725de67dc78103154..8b55ae01132d6ffdc4c3a7c63779e7f97124a8ea 100644 (file)
@@ -116,14 +116,16 @@ static int init_thermal_controller(
                const ATOM_Vega10_POWERPLAYTABLE *powerplay_table)
 {
        const ATOM_Vega10_Thermal_Controller *thermal_controller;
-       const ATOM_Vega10_Fan_Table *fan_table;
+       const Vega10_PPTable_Generic_SubTable_Header *header;
+       const ATOM_Vega10_Fan_Table *fan_table_v1;
+       const ATOM_Vega10_Fan_Table_V2 *fan_table_v2;
 
        thermal_controller = (ATOM_Vega10_Thermal_Controller *)
                        (((unsigned long)powerplay_table) +
                        le16_to_cpu(powerplay_table->usThermalControllerOffset));
 
        PP_ASSERT_WITH_CODE((powerplay_table->usThermalControllerOffset != 0),
-                       "Thermal controller table not set!", return -1);
+                       "Thermal controller table not set!", return -EINVAL);
 
        hwmgr->thermal_controller.ucType = thermal_controller->ucType;
        hwmgr->thermal_controller.ucI2cLine = thermal_controller->ucI2cLine;
@@ -142,6 +144,9 @@ static int init_thermal_controller(
        hwmgr->thermal_controller.fanInfo.ulMaxRPM =
                        thermal_controller->ucFanMaxRPM * 100UL;
 
+       hwmgr->thermal_controller.advanceFanControlParameters.ulCycleDelay
+                       = 100000;
+
        set_hw_cap(
                        hwmgr,
                        ATOM_VEGA10_PP_THERMALCONTROLLER_NONE != hwmgr->thermal_controller.ucType,
@@ -150,54 +155,101 @@ static int init_thermal_controller(
        if (!powerplay_table->usFanTableOffset)
                return 0;
 
-       fan_table = (const ATOM_Vega10_Fan_Table *)
+       header = (const Vega10_PPTable_Generic_SubTable_Header *)
                        (((unsigned long)powerplay_table) +
                        le16_to_cpu(powerplay_table->usFanTableOffset));
 
-       PP_ASSERT_WITH_CODE((fan_table->ucRevId >= 8),
-               "Invalid Input Fan Table!", return -1);
+       if (header->ucRevId == 10) {
+               fan_table_v1 = (ATOM_Vega10_Fan_Table *)header;
 
-       hwmgr->thermal_controller.advanceFanControlParameters.ulCycleDelay
-               = 100000;
-       phm_cap_set(hwmgr->platform_descriptor.platformCaps,
-               PHM_PlatformCaps_MicrocodeFanControl);
-
-       hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity =
-                       le16_to_cpu(fan_table->usFanOutputSensitivity);
-       hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
-                       le16_to_cpu(fan_table->usFanRPMMax);
-       hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit =
-                       le16_to_cpu(fan_table->usThrottlingRPM);
-       hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit =
-                       le32_to_cpu((uint32_t)(fan_table->usFanAcousticLimit));
-       hwmgr->thermal_controller.advanceFanControlParameters.usTMax =
-                       le16_to_cpu(fan_table->usTargetTemperature);
-       hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin =
-                       le16_to_cpu(fan_table->usMinimumPWMLimit);
-       hwmgr->thermal_controller.advanceFanControlParameters.ulTargetGfxClk =
-                       le32_to_cpu((uint32_t)(fan_table->usTargetGfxClk));
-       hwmgr->thermal_controller.advanceFanControlParameters.usFanGainEdge =
-                       le16_to_cpu(fan_table->usFanGainEdge);
-       hwmgr->thermal_controller.advanceFanControlParameters.usFanGainHotspot =
-                       le16_to_cpu(fan_table->usFanGainHotspot);
-       hwmgr->thermal_controller.advanceFanControlParameters.usFanGainLiquid =
-                       le16_to_cpu(fan_table->usFanGainLiquid);
-       hwmgr->thermal_controller.advanceFanControlParameters.usFanGainVrVddc =
-                       le16_to_cpu(fan_table->usFanGainVrVddc);
-       hwmgr->thermal_controller.advanceFanControlParameters.usFanGainVrMvdd =
-                       le16_to_cpu(fan_table->usFanGainVrMvdd);
-       hwmgr->thermal_controller.advanceFanControlParameters.usFanGainPlx =
-                       le16_to_cpu(fan_table->usFanGainPlx);
-       hwmgr->thermal_controller.advanceFanControlParameters.usFanGainHbm =
-                       le16_to_cpu(fan_table->usFanGainHbm);
-
-       hwmgr->thermal_controller.advanceFanControlParameters.ucEnableZeroRPM =
-                       fan_table->ucEnableZeroRPM;
-       hwmgr->thermal_controller.advanceFanControlParameters.usZeroRPMStopTemperature =
-                       le16_to_cpu(fan_table->usFanStopTemperature);
-       hwmgr->thermal_controller.advanceFanControlParameters.usZeroRPMStartTemperature =
-                       le16_to_cpu(fan_table->usFanStartTemperature);
+               PP_ASSERT_WITH_CODE((fan_table_v1->ucRevId >= 8),
+                               "Invalid Input Fan Table!", return -EINVAL);
 
+               phm_cap_set(hwmgr->platform_descriptor.platformCaps,
+                               PHM_PlatformCaps_MicrocodeFanControl);
+
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity =
+                               le16_to_cpu(fan_table_v1->usFanOutputSensitivity);
+               hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
+                               le16_to_cpu(fan_table_v1->usFanRPMMax);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit =
+                               le16_to_cpu(fan_table_v1->usThrottlingRPM);
+               hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit =
+                               le16_to_cpu(fan_table_v1->usFanAcousticLimit);
+               hwmgr->thermal_controller.advanceFanControlParameters.usTMax =
+                               le16_to_cpu(fan_table_v1->usTargetTemperature);
+               hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin =
+                               le16_to_cpu(fan_table_v1->usMinimumPWMLimit);
+               hwmgr->thermal_controller.advanceFanControlParameters.ulTargetGfxClk =
+                               le16_to_cpu(fan_table_v1->usTargetGfxClk);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainEdge =
+                               le16_to_cpu(fan_table_v1->usFanGainEdge);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainHotspot =
+                               le16_to_cpu(fan_table_v1->usFanGainHotspot);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainLiquid =
+                               le16_to_cpu(fan_table_v1->usFanGainLiquid);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainVrVddc =
+                               le16_to_cpu(fan_table_v1->usFanGainVrVddc);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainVrMvdd =
+                               le16_to_cpu(fan_table_v1->usFanGainVrMvdd);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainPlx =
+                               le16_to_cpu(fan_table_v1->usFanGainPlx);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainHbm =
+                               le16_to_cpu(fan_table_v1->usFanGainHbm);
+
+               hwmgr->thermal_controller.advanceFanControlParameters.ucEnableZeroRPM =
+                               fan_table_v1->ucEnableZeroRPM;
+               hwmgr->thermal_controller.advanceFanControlParameters.usZeroRPMStopTemperature =
+                               le16_to_cpu(fan_table_v1->usFanStopTemperature);
+               hwmgr->thermal_controller.advanceFanControlParameters.usZeroRPMStartTemperature =
+                               le16_to_cpu(fan_table_v1->usFanStartTemperature);
+       } else if (header->ucRevId > 10) {
+               fan_table_v2 = (ATOM_Vega10_Fan_Table_V2 *)header;
+
+               hwmgr->thermal_controller.fanInfo.ucTachometerPulsesPerRevolution =
+                               fan_table_v2->ucFanParameters & ATOM_VEGA10_PP_FANPARAMETERS_TACHOMETER_PULSES_PER_REVOLUTION_MASK;
+               hwmgr->thermal_controller.fanInfo.ulMinRPM = fan_table_v2->ucFanMinRPM * 100UL;
+               hwmgr->thermal_controller.fanInfo.ulMaxRPM = fan_table_v2->ucFanMaxRPM * 100UL;
+
+               phm_cap_set(hwmgr->platform_descriptor.platformCaps,
+                               PHM_PlatformCaps_MicrocodeFanControl);
+
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity =
+                               le16_to_cpu(fan_table_v2->usFanOutputSensitivity);
+               hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
+                               fan_table_v2->ucFanMaxRPM * 100UL;
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit =
+                               le16_to_cpu(fan_table_v2->usThrottlingRPM);
+               hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit =
+                               le16_to_cpu(fan_table_v2->usFanAcousticLimitRpm);
+               hwmgr->thermal_controller.advanceFanControlParameters.usTMax =
+                               le16_to_cpu(fan_table_v2->usTargetTemperature);
+               hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin =
+                               le16_to_cpu(fan_table_v2->usMinimumPWMLimit);
+               hwmgr->thermal_controller.advanceFanControlParameters.ulTargetGfxClk =
+                               le16_to_cpu(fan_table_v2->usTargetGfxClk);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainEdge =
+                               le16_to_cpu(fan_table_v2->usFanGainEdge);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainHotspot =
+                               le16_to_cpu(fan_table_v2->usFanGainHotspot);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainLiquid =
+                               le16_to_cpu(fan_table_v2->usFanGainLiquid);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainVrVddc =
+                               le16_to_cpu(fan_table_v2->usFanGainVrVddc);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainVrMvdd =
+                               le16_to_cpu(fan_table_v2->usFanGainVrMvdd);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainPlx =
+                               le16_to_cpu(fan_table_v2->usFanGainPlx);
+               hwmgr->thermal_controller.advanceFanControlParameters.usFanGainHbm =
+                               le16_to_cpu(fan_table_v2->usFanGainHbm);
+
+               hwmgr->thermal_controller.advanceFanControlParameters.ucEnableZeroRPM =
+                               fan_table_v2->ucEnableZeroRPM;
+               hwmgr->thermal_controller.advanceFanControlParameters.usZeroRPMStopTemperature =
+                               le16_to_cpu(fan_table_v2->usFanStopTemperature);
+               hwmgr->thermal_controller.advanceFanControlParameters.usZeroRPMStartTemperature =
+                               le16_to_cpu(fan_table_v2->usFanStartTemperature);
+       }
        return 0;
 }