Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 6ae39b7

Browse files
greearbnbd168
authored andcommitted
wifi: mt76: mt7921: Support temp sensor
Allow sensors tool to read radio's temperature, example: mt7921_phy17-pci-1800 Adapter: PCI adapter temp1: +72.0°C Signed-off-by: Ben Greear <greearb@candelatech.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
1 parent 0e5911b commit 6ae39b7

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

drivers/net/wireless/mediatek/mt76/mt7921/init.c

+60
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/* Copyright (C) 2020 MediaTek Inc. */
33

44
#include <linux/etherdevice.h>
5+
#include <linux/hwmon.h>
6+
#include <linux/hwmon-sysfs.h>
7+
#include <linux/thermal.h>
58
#include <linux/firmware.h>
69
#include "mt7921.h"
710
#include "../mt76_connac2_mac.h"
@@ -51,6 +54,57 @@ static const struct ieee80211_iface_combination if_comb_chanctx[] = {
5154
}
5255
};
5356

57+
static ssize_t mt7921_thermal_temp_show(struct device *dev,
58+
struct device_attribute *attr,
59+
char *buf)
60+
{
61+
switch (to_sensor_dev_attr(attr)->index) {
62+
case 0: {
63+
struct mt7921_phy *phy = dev_get_drvdata(dev);
64+
struct mt7921_dev *mdev = phy->dev;
65+
int temperature;
66+
67+
mt7921_mutex_acquire(mdev);
68+
temperature = mt7921_mcu_get_temperature(phy);
69+
mt7921_mutex_release(mdev);
70+
71+
if (temperature < 0)
72+
return temperature;
73+
/* display in millidegree Celsius */
74+
return sprintf(buf, "%u\n", temperature * 1000);
75+
}
76+
default:
77+
return -EINVAL;
78+
}
79+
}
80+
static SENSOR_DEVICE_ATTR_RO(temp1_input, mt7921_thermal_temp, 0);
81+
82+
static struct attribute *mt7921_hwmon_attrs[] = {
83+
&sensor_dev_attr_temp1_input.dev_attr.attr,
84+
NULL,
85+
};
86+
ATTRIBUTE_GROUPS(mt7921_hwmon);
87+
88+
static int mt7921_thermal_init(struct mt7921_phy *phy)
89+
{
90+
struct wiphy *wiphy = phy->mt76->hw->wiphy;
91+
struct device *hwmon;
92+
const char *name;
93+
94+
if (!IS_REACHABLE(CONFIG_HWMON))
95+
return 0;
96+
97+
name = devm_kasprintf(&wiphy->dev, GFP_KERNEL, "mt7921_%s",
98+
wiphy_name(wiphy));
99+
100+
hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev, name, phy,
101+
mt7921_hwmon_groups);
102+
if (IS_ERR(hwmon))
103+
return PTR_ERR(hwmon);
104+
105+
return 0;
106+
}
107+
54108
static void
55109
mt7921_regd_notifier(struct wiphy *wiphy,
56110
struct regulatory_request *request)
@@ -363,6 +417,12 @@ static void mt7921_init_work(struct work_struct *work)
363417
return;
364418
}
365419

420+
ret = mt7921_thermal_init(&dev->phy);
421+
if (ret) {
422+
dev_err(dev->mt76.dev, "thermal init failed\n");
423+
return;
424+
}
425+
366426
/* we support chip reset now */
367427
dev->hw_init_done = true;
368428

drivers/net/wireless/mediatek/mt76/mt7921/mcu.c

+17
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,23 @@ int mt7921_mcu_set_clc(struct mt7921_dev *dev, u8 *alpha2,
13051305
return 0;
13061306
}
13071307

1308+
int mt7921_mcu_get_temperature(struct mt7921_phy *phy)
1309+
{
1310+
struct mt7921_dev *dev = phy->dev;
1311+
struct {
1312+
u8 ctrl_id;
1313+
u8 action;
1314+
u8 band_idx;
1315+
u8 rsv[5];
1316+
} req = {
1317+
.ctrl_id = THERMAL_SENSOR_TEMP_QUERY,
1318+
.band_idx = phy->mt76->band_idx,
1319+
};
1320+
1321+
return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_CTRL), &req,
1322+
sizeof(req), true);
1323+
}
1324+
13081325
int mt7921_mcu_set_rxfilter(struct mt7921_dev *dev, u32 fif,
13091326
u8 bit_op, u32 bit_map)
13101327
{

drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h

+1
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ int mt7921_mcu_set_sniffer(struct mt7921_dev *dev, struct ieee80211_vif *vif,
511511
bool enable);
512512
int mt7921_mcu_config_sniffer(struct mt7921_vif *vif,
513513
struct ieee80211_chanctx_conf *ctx);
514+
int mt7921_mcu_get_temperature(struct mt7921_phy *phy);
514515

515516
int mt7921_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
516517
enum mt76_txq_id qid, struct mt76_wcid *wcid,

0 commit comments

Comments
 (0)