Commit 02ee68b9 authored by Ryder Lee's avatar Ryder Lee Committed by Felix Fietkau

mt76: mt7915: add control knobs for thermal throttling

With this patch, users can set the trigger/restore temperature for
thermal service according to their use cases.
Signed-off-by: default avatarRyder Lee <ryder.lee@mediatek.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 68808872
...@@ -42,13 +42,17 @@ static const struct ieee80211_iface_combination if_comb[] = { ...@@ -42,13 +42,17 @@ static const struct ieee80211_iface_combination if_comb[] = {
} }
}; };
static ssize_t mt7915_thermal_show_temp(struct device *dev, static ssize_t mt7915_thermal_temp_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct mt7915_phy *phy = dev_get_drvdata(dev); struct mt7915_phy *phy = dev_get_drvdata(dev);
int i = to_sensor_dev_attr(attr)->index;
int temperature; int temperature;
if (i)
return sprintf(buf, "%u\n", phy->throttle_temp[i - 1] * 1000);
temperature = mt7915_mcu_get_temperature(phy); temperature = mt7915_mcu_get_temperature(phy);
if (temperature < 0) if (temperature < 0)
return temperature; return temperature;
...@@ -57,11 +61,34 @@ static ssize_t mt7915_thermal_show_temp(struct device *dev, ...@@ -57,11 +61,34 @@ static ssize_t mt7915_thermal_show_temp(struct device *dev,
return sprintf(buf, "%u\n", temperature * 1000); return sprintf(buf, "%u\n", temperature * 1000);
} }
static SENSOR_DEVICE_ATTR(temp1_input, 0444, mt7915_thermal_show_temp, static ssize_t mt7915_thermal_temp_store(struct device *dev,
NULL, 0); struct device_attribute *attr,
const char *buf, size_t count)
{
struct mt7915_phy *phy = dev_get_drvdata(dev);
int ret, i = to_sensor_dev_attr(attr)->index;
long val;
ret = kstrtol(buf, 10, &val);
if (ret < 0)
return ret;
mutex_lock(&phy->dev->mt76.mutex);
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 60, 130);
phy->throttle_temp[i - 1] = val;
mutex_unlock(&phy->dev->mt76.mutex);
return count;
}
static SENSOR_DEVICE_ATTR_RO(temp1_input, mt7915_thermal_temp, 0);
static SENSOR_DEVICE_ATTR_RW(temp1_crit, mt7915_thermal_temp, 1);
static SENSOR_DEVICE_ATTR_RW(temp1_max, mt7915_thermal_temp, 2);
static struct attribute *mt7915_hwmon_attrs[] = { static struct attribute *mt7915_hwmon_attrs[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr, &sensor_dev_attr_temp1_input.dev_attr.attr,
&sensor_dev_attr_temp1_crit.dev_attr.attr,
&sensor_dev_attr_temp1_max.dev_attr.attr,
NULL, NULL,
}; };
ATTRIBUTE_GROUPS(mt7915_hwmon); ATTRIBUTE_GROUPS(mt7915_hwmon);
...@@ -96,6 +123,9 @@ mt7915_thermal_set_cur_throttle_state(struct thermal_cooling_device *cdev, ...@@ -96,6 +123,9 @@ mt7915_thermal_set_cur_throttle_state(struct thermal_cooling_device *cdev,
if (state > MT7915_THERMAL_THROTTLE_MAX) if (state > MT7915_THERMAL_THROTTLE_MAX)
return -EINVAL; return -EINVAL;
if (phy->throttle_temp[0] > phy->throttle_temp[1])
return 0;
if (state == phy->throttle_state) if (state == phy->throttle_state)
return 0; return 0;
...@@ -150,6 +180,10 @@ static int mt7915_thermal_init(struct mt7915_phy *phy) ...@@ -150,6 +180,10 @@ static int mt7915_thermal_init(struct mt7915_phy *phy)
if (IS_ERR(hwmon)) if (IS_ERR(hwmon))
return PTR_ERR(hwmon); return PTR_ERR(hwmon);
/* initialize critical/maximum high temperature */
phy->throttle_temp[0] = 110;
phy->throttle_temp[1] = 120;
return 0; return 0;
} }
......
...@@ -3544,10 +3544,6 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state) ...@@ -3544,10 +3544,6 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state)
}; };
int level; int level;
#define TRIGGER_TEMPERATURE 122
#define RESTORE_TEMPERATURE 116
#define SUSTAIN_PERIOD 10
if (!state) { if (!state) {
req.ctrl.ctrl_id = THERMAL_PROTECT_DISABLE; req.ctrl.ctrl_id = THERMAL_PROTECT_DISABLE;
goto out; goto out;
...@@ -3560,7 +3556,7 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state) ...@@ -3560,7 +3556,7 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state)
req.ctrl.ctrl_id = THERMAL_PROTECT_DUTY_CONFIG; req.ctrl.ctrl_id = THERMAL_PROTECT_DUTY_CONFIG;
req.ctrl.duty.duty_level = level; req.ctrl.duty.duty_level = level;
req.ctrl.duty.duty_cycle = state; req.ctrl.duty.duty_cycle = state;
state = state * 4 / 5; state /= 2;
ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT), ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT),
&req, sizeof(req.ctrl), false); &req, sizeof(req.ctrl), false);
...@@ -3568,15 +3564,12 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state) ...@@ -3568,15 +3564,12 @@ int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state)
return ret; return ret;
} }
/* currently use fixed values for throttling, and would be better
* to implement thermal zone for dynamic trip in the long run.
*/
/* set high-temperature trigger threshold */ /* set high-temperature trigger threshold */
req.ctrl.ctrl_id = THERMAL_PROTECT_ENABLE; req.ctrl.ctrl_id = THERMAL_PROTECT_ENABLE;
req.trigger_temp = cpu_to_le32(TRIGGER_TEMPERATURE); /* add a safety margin ~10 */
req.restore_temp = cpu_to_le32(RESTORE_TEMPERATURE); req.restore_temp = cpu_to_le32(phy->throttle_temp[0] - 10);
req.sustain_time = cpu_to_le16(SUSTAIN_PERIOD); req.trigger_temp = cpu_to_le32(phy->throttle_temp[1]);
req.sustain_time = cpu_to_le16(10);
out: out:
req.ctrl.type.protect_type = 1; req.ctrl.type.protect_type = 1;
......
...@@ -121,6 +121,7 @@ struct mt7915_phy { ...@@ -121,6 +121,7 @@ struct mt7915_phy {
struct thermal_cooling_device *cdev; struct thermal_cooling_device *cdev;
u8 throttle_state; u8 throttle_state;
u32 throttle_temp[2]; /* 0: critical high, 1: maximum */
u32 rxfilter; u32 rxfilter;
u64 omac_mask; u64 omac_mask;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment