Skip to content

Commit

Permalink
mt76: mt7915: add thermal sensor device support
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ryderlee1110 authored and nbd168 committed Jun 19, 2021
1 parent 10de032 commit 33fe9c6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
14 changes: 0 additions & 14 deletions drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down
51 changes: 51 additions & 0 deletions drivers/net/wireless/mediatek/mt76/mt7915/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 33fe9c6

Please sign in to comment.