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: Ryder Lee <ryder.lee@mediatek.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
10de032a31
commit
33fe9c639c
@ -224,18 +224,6 @@ mt7915_tx_stats_show(struct seq_file *file, void *data)
|
||||
|
||||
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
|
||||
mt7915_queues_acq(struct seq_file *s, void *data)
|
||||
{
|
||||
@ -390,8 +378,6 @@ int mt7915_init_debugfs(struct mt7915_dev *dev)
|
||||
debugfs_create_file("radar_trigger", 0200, dir, dev,
|
||||
&fops_radar_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,
|
||||
mt7915_read_rate_txpower);
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
/* Copyright (C) 2020 MediaTek Inc. */
|
||||
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include "mt7915.h"
|
||||
#include "mac.h"
|
||||
#include "mcu.h"
|
||||
@ -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
|
||||
mt7915_init_txpower(struct mt7915_dev *dev,
|
||||
struct ieee80211_supported_band *sband)
|
||||
@ -258,6 +301,10 @@ static int mt7915_register_ext_phy(struct mt7915_dev *dev)
|
||||
if (ret)
|
||||
goto error;
|
||||
|
||||
ret = mt7915_thermal_init(phy);
|
||||
if (ret)
|
||||
goto error;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
@ -708,6 +755,10 @@ int mt7915_register_device(struct mt7915_dev *dev)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = mt7915_thermal_init(&dev->phy);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ieee80211_queue_work(mt76_hw(dev), &dev->init_work);
|
||||
|
||||
ret = mt7915_register_ext_phy(dev);
|
||||
|
@ -3559,16 +3559,17 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
|
||||
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 {
|
||||
u8 ctrl_id;
|
||||
u8 action;
|
||||
u8 band;
|
||||
u8 dbdc_idx;
|
||||
u8 rsv[5];
|
||||
} req = {
|
||||
.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,
|
||||
|
@ -356,7 +356,7 @@ int mt7915_mcu_set_radar_th(struct mt7915_dev *dev, int index,
|
||||
const struct mt7915_dfs_pattern *pattern);
|
||||
int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev);
|
||||
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_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
|
||||
struct ieee80211_sta *sta, struct rate_info *rate);
|
||||
|
Loading…
Reference in New Issue
Block a user