Commit 33fe9c63 authored by Ryder Lee's avatar Ryder Lee Committed by Felix Fietkau

mt76: mt7915: add thermal sensor device support

This provides userspace with a unified interface, hwmon sysfs, to monitor
temperature in the hardware and can be adapted to system monitoring tools.

For reading temperature, cat /sys/class/ieee80211/phy*/hwmon*/temp1_input
Signed-off-by: default avatarRyder Lee <ryder.lee@mediatek.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 10de032a
...@@ -224,18 +224,6 @@ mt7915_tx_stats_show(struct seq_file *file, void *data) ...@@ -224,18 +224,6 @@ mt7915_tx_stats_show(struct seq_file *file, void *data)
DEFINE_SHOW_ATTRIBUTE(mt7915_tx_stats); DEFINE_SHOW_ATTRIBUTE(mt7915_tx_stats);
static int mt7915_read_temperature(struct seq_file *s, void *data)
{
struct mt7915_dev *dev = dev_get_drvdata(s->private);
int temp;
/* cpu */
temp = mt7915_mcu_get_temperature(dev, 0);
seq_printf(s, "Temperature: %d\n", temp);
return 0;
}
static int static int
mt7915_queues_acq(struct seq_file *s, void *data) mt7915_queues_acq(struct seq_file *s, void *data)
{ {
...@@ -390,8 +378,6 @@ int mt7915_init_debugfs(struct mt7915_dev *dev) ...@@ -390,8 +378,6 @@ int mt7915_init_debugfs(struct mt7915_dev *dev)
debugfs_create_file("radar_trigger", 0200, dir, dev, debugfs_create_file("radar_trigger", 0200, dir, dev,
&fops_radar_trigger); &fops_radar_trigger);
debugfs_create_file("ser_trigger", 0200, dir, dev, &fops_ser_trigger); debugfs_create_file("ser_trigger", 0200, dir, dev, &fops_ser_trigger);
debugfs_create_devm_seqfile(dev->mt76.dev, "temperature", dir,
mt7915_read_temperature);
debugfs_create_devm_seqfile(dev->mt76.dev, "txpower_sku", dir, debugfs_create_devm_seqfile(dev->mt76.dev, "txpower_sku", dir,
mt7915_read_rate_txpower); mt7915_read_rate_txpower);
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
/* Copyright (C) 2020 MediaTek Inc. */ /* Copyright (C) 2020 MediaTek Inc. */
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include "mt7915.h" #include "mt7915.h"
#include "mac.h" #include "mac.h"
#include "mcu.h" #include "mcu.h"
...@@ -39,6 +41,47 @@ static const struct ieee80211_iface_combination if_comb[] = { ...@@ -39,6 +41,47 @@ static const struct ieee80211_iface_combination if_comb[] = {
} }
}; };
static ssize_t mt7915_thermal_show_temp(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct mt7915_phy *phy = dev_get_drvdata(dev);
int temperature;
temperature = mt7915_mcu_get_temperature(phy);
if (temperature < 0)
return temperature;
/* display in millidegree celcius */
return sprintf(buf, "%u\n", temperature * 1000);
}
static SENSOR_DEVICE_ATTR(temp1_input, 0444, mt7915_thermal_show_temp,
NULL, 0);
static struct attribute *mt7915_hwmon_attrs[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr,
NULL,
};
ATTRIBUTE_GROUPS(mt7915_hwmon);
static int mt7915_thermal_init(struct mt7915_phy *phy)
{
struct wiphy *wiphy = phy->mt76->hw->wiphy;
struct device *hwmon;
if (!IS_REACHABLE(CONFIG_HWMON))
return 0;
hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev,
wiphy_name(wiphy), phy,
mt7915_hwmon_groups);
if (IS_ERR(hwmon))
return PTR_ERR(hwmon);
return 0;
}
static void static void
mt7915_init_txpower(struct mt7915_dev *dev, mt7915_init_txpower(struct mt7915_dev *dev,
struct ieee80211_supported_band *sband) struct ieee80211_supported_band *sband)
...@@ -258,6 +301,10 @@ static int mt7915_register_ext_phy(struct mt7915_dev *dev) ...@@ -258,6 +301,10 @@ static int mt7915_register_ext_phy(struct mt7915_dev *dev)
if (ret) if (ret)
goto error; goto error;
ret = mt7915_thermal_init(phy);
if (ret)
goto error;
return 0; return 0;
error: error:
...@@ -708,6 +755,10 @@ int mt7915_register_device(struct mt7915_dev *dev) ...@@ -708,6 +755,10 @@ int mt7915_register_device(struct mt7915_dev *dev)
if (ret) if (ret)
return ret; return ret;
ret = mt7915_thermal_init(&dev->phy);
if (ret)
return ret;
ieee80211_queue_work(mt76_hw(dev), &dev->init_work); ieee80211_queue_work(mt76_hw(dev), &dev->init_work);
ret = mt7915_register_ext_phy(dev); ret = mt7915_register_ext_phy(dev);
......
...@@ -3559,16 +3559,17 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy) ...@@ -3559,16 +3559,17 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
return 0; return 0;
} }
int mt7915_mcu_get_temperature(struct mt7915_dev *dev, int index) int mt7915_mcu_get_temperature(struct mt7915_phy *phy)
{ {
struct mt7915_dev *dev = phy->dev;
struct { struct {
u8 ctrl_id; u8 ctrl_id;
u8 action; u8 action;
u8 band; u8 dbdc_idx;
u8 rsv[5]; u8 rsv[5];
} req = { } req = {
.ctrl_id = THERMAL_SENSOR_TEMP_QUERY, .ctrl_id = THERMAL_SENSOR_TEMP_QUERY,
.action = index, .dbdc_idx = phy != &dev->phy,
}; };
return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_CTRL), &req, return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_CTRL), &req,
......
...@@ -356,7 +356,7 @@ int mt7915_mcu_set_radar_th(struct mt7915_dev *dev, int index, ...@@ -356,7 +356,7 @@ int mt7915_mcu_set_radar_th(struct mt7915_dev *dev, int index,
const struct mt7915_dfs_pattern *pattern); const struct mt7915_dfs_pattern *pattern);
int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev); int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev);
int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy); int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy);
int mt7915_mcu_get_temperature(struct mt7915_dev *dev, int index); int mt7915_mcu_get_temperature(struct mt7915_phy *phy);
int mt7915_mcu_get_tx_rate(struct mt7915_dev *dev, u32 cmd, u16 wlan_idx); int mt7915_mcu_get_tx_rate(struct mt7915_dev *dev, u32 cmd, u16 wlan_idx);
int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif, int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
struct ieee80211_sta *sta, struct rate_info *rate); struct ieee80211_sta *sta, struct rate_info *rate);
......
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