2 * Copyright 2017 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.
24 #include "vega12_thermal.h"
25 #include "vega12_hwmgr.h"
26 #include "vega12_smumgr.h"
27 #include "vega12_ppsmc.h"
28 #include "vega12_inc.h"
32 static int vega12_get_current_rpm(struct pp_hwmgr *hwmgr, uint32_t *current_rpm)
34 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(hwmgr,
35 PPSMC_MSG_GetCurrentRpm),
36 "Attempt to get current RPM from SMC Failed!",
38 PP_ASSERT_WITH_CODE(!vega12_read_arg_from_smc(hwmgr,
40 "Attempt to read current RPM from SMC Failed!",
45 int vega12_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr,
46 struct phm_fan_speed_info *fan_speed_info)
48 memset(fan_speed_info, 0, sizeof(*fan_speed_info));
49 fan_speed_info->supports_percent_read = false;
50 fan_speed_info->supports_percent_write = false;
51 fan_speed_info->supports_rpm_read = true;
52 fan_speed_info->supports_rpm_write = true;
57 int vega12_fan_ctrl_get_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t *speed)
61 return vega12_get_current_rpm(hwmgr, speed);
65 * @fn vega12_enable_fan_control_feature
66 * @brief Enables the SMC Fan Control Feature.
68 * @param hwmgr - the address of the powerplay hardware manager.
69 * @return 0 on success. -1 otherwise.
71 static int vega12_enable_fan_control_feature(struct pp_hwmgr *hwmgr)
74 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
76 if (data->smu_features[GNLD_FAN_CONTROL].supported) {
77 PP_ASSERT_WITH_CODE(!vega12_enable_smc_features(
79 data->smu_features[GNLD_FAN_CONTROL].
81 "Attempt to Enable FAN CONTROL feature Failed!",
83 data->smu_features[GNLD_FAN_CONTROL].enabled = true;
89 static int vega12_disable_fan_control_feature(struct pp_hwmgr *hwmgr)
92 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
94 if (data->smu_features[GNLD_FAN_CONTROL].supported) {
95 PP_ASSERT_WITH_CODE(!vega12_enable_smc_features(
97 data->smu_features[GNLD_FAN_CONTROL].
99 "Attempt to Enable FAN CONTROL feature Failed!",
101 data->smu_features[GNLD_FAN_CONTROL].enabled = false;
107 int vega12_fan_ctrl_start_smc_fan_control(struct pp_hwmgr *hwmgr)
109 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
111 if (data->smu_features[GNLD_FAN_CONTROL].supported)
113 !vega12_enable_fan_control_feature(hwmgr),
114 "Attempt to Enable SMC FAN CONTROL Feature Failed!",
121 int vega12_fan_ctrl_stop_smc_fan_control(struct pp_hwmgr *hwmgr)
123 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
125 if (data->smu_features[GNLD_FAN_CONTROL].supported)
126 PP_ASSERT_WITH_CODE(!vega12_disable_fan_control_feature(hwmgr),
127 "Attempt to Disable SMC FAN CONTROL Feature Failed!",
134 * Reset Fan Speed to default.
135 * @param hwmgr the address of the powerplay hardware manager.
136 * @exception Always succeeds.
138 int vega12_fan_ctrl_reset_fan_speed_to_default(struct pp_hwmgr *hwmgr)
140 return vega12_fan_ctrl_start_smc_fan_control(hwmgr);
144 * Reads the remote temperature from the SIslands thermal controller.
146 * @param hwmgr The address of the hardware manager.
148 int vega12_thermal_get_temperature(struct pp_hwmgr *hwmgr)
153 reg = soc15_get_register_offset(THM_HWID, 0,
154 mmCG_MULT_THERMAL_STATUS_BASE_IDX, mmCG_MULT_THERMAL_STATUS);
156 temp = cgs_read_register(hwmgr->device, reg);
158 temp = (temp & CG_MULT_THERMAL_STATUS__CTF_TEMP_MASK) >>
159 CG_MULT_THERMAL_STATUS__CTF_TEMP__SHIFT;
163 temp *= PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
168 * Set the requested temperature range for high and low alert signals
170 * @param hwmgr The address of the hardware manager.
171 * @param range Temperature range to be programmed for
172 * high and low alert signals
173 * @exception PP_Result_BadInput if the input data is not valid.
175 static int vega12_thermal_set_temperature_range(struct pp_hwmgr *hwmgr,
176 struct PP_TemperatureRange *range)
178 int low = VEGA12_THERMAL_MINIMUM_ALERT_TEMP *
179 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
180 int high = VEGA12_THERMAL_MAXIMUM_ALERT_TEMP *
181 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
184 if (low < range->min)
186 if (high > range->max)
192 reg = soc15_get_register_offset(THM_HWID, 0,
193 mmTHM_THERMAL_INT_CTRL_BASE_IDX, mmTHM_THERMAL_INT_CTRL);
195 val = cgs_read_register(hwmgr->device, reg);
197 val = CGS_REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, MAX_IH_CREDIT, 5);
198 val = CGS_REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_IH_HW_ENA, 1);
199 val = CGS_REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTH, (high / PP_TEMPERATURE_UNITS_PER_CENTIGRADES));
200 val = CGS_REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTL, (low / PP_TEMPERATURE_UNITS_PER_CENTIGRADES));
201 val = val & (~THM_THERMAL_INT_CTRL__THERM_TRIGGER_MASK_MASK);
203 cgs_write_register(hwmgr->device, reg, val);
209 * Enable thermal alerts on the RV770 thermal controller.
211 * @param hwmgr The address of the hardware manager.
213 static int vega12_thermal_enable_alert(struct pp_hwmgr *hwmgr)
218 val |= (1 << THM_THERMAL_INT_ENA__THERM_INTH_CLR__SHIFT);
219 val |= (1 << THM_THERMAL_INT_ENA__THERM_INTL_CLR__SHIFT);
220 val |= (1 << THM_THERMAL_INT_ENA__THERM_TRIGGER_CLR__SHIFT);
222 reg = soc15_get_register_offset(THM_HWID, 0, mmTHM_THERMAL_INT_ENA_BASE_IDX, mmTHM_THERMAL_INT_ENA);
223 cgs_write_register(hwmgr->device, reg, val);
229 * Disable thermal alerts on the RV770 thermal controller.
230 * @param hwmgr The address of the hardware manager.
232 int vega12_thermal_disable_alert(struct pp_hwmgr *hwmgr)
236 reg = soc15_get_register_offset(THM_HWID, 0, mmTHM_THERMAL_INT_ENA_BASE_IDX, mmTHM_THERMAL_INT_ENA);
237 cgs_write_register(hwmgr->device, reg, 0);
243 * Uninitialize the thermal controller.
244 * Currently just disables alerts.
245 * @param hwmgr The address of the hardware manager.
247 int vega12_thermal_stop_thermal_controller(struct pp_hwmgr *hwmgr)
249 int result = vega12_thermal_disable_alert(hwmgr);
255 * Set up the fan table to control the fan using the SMC.
256 * @param hwmgr the address of the powerplay hardware manager.
257 * @param pInput the pointer to input data
258 * @param pOutput the pointer to output data
259 * @param pStorage the pointer to temporary storage
260 * @param Result the last failure code
261 * @return result from set temperature range routine
263 int vega12_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)
266 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
267 PPTable_t *table = &(data->smc_state_table.pp_table);
269 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
270 PPSMC_MSG_SetFanTemperatureTarget,
271 (uint32_t)table->FanTargetTemperature);
277 * Start the fan control on the SMC.
278 * @param hwmgr the address of the powerplay hardware manager.
279 * @param pInput the pointer to input data
280 * @param pOutput the pointer to output data
281 * @param pStorage the pointer to temporary storage
282 * @param Result the last failure code
283 * @return result from set temperature range routine
285 int vega12_thermal_start_smc_fan_control(struct pp_hwmgr *hwmgr)
287 /* If the fantable setup has failed we could have disabled
288 * PHM_PlatformCaps_MicrocodeFanControl even after
289 * this function was included in the table.
290 * Make sure that we still think controlling the fan is OK.
292 if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
293 vega12_fan_ctrl_start_smc_fan_control(hwmgr);
299 int vega12_start_thermal_controller(struct pp_hwmgr *hwmgr,
300 struct PP_TemperatureRange *range)
307 ret = vega12_thermal_set_temperature_range(hwmgr, range);
311 vega12_thermal_enable_alert(hwmgr);
312 /* We should restrict performance levels to low before we halt the SMC.
313 * On the other hand we are still in boot state when we do this
314 * so it would be pointless.
315 * If this assumption changes we have to revisit this table.
317 ret = vega12_thermal_setup_fan_table(hwmgr);
321 vega12_thermal_start_smc_fan_control(hwmgr);