Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp56278pxy; Wed, 21 Apr 2021 18:22:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3XCVXdP5q5x5RYOqRnmQ8IMCLsz099swt+GZmzIzDOIcTYT+qtn3DaN3lPdruuCCvhgvD X-Received: by 2002:a17:90b:4718:: with SMTP id jc24mr15253970pjb.210.1619054529803; Wed, 21 Apr 2021 18:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619054529; cv=none; d=google.com; s=arc-20160816; b=gEddGQiepzv5PWR1hTRnKWZdiAlfEczLKqLyYD+rj9ryguB5g4wzG64mxczOg8SbHy iMLgz7t3l0zu9cTp5qExqRxRMj1pFA02Q2vvLRQkmBGdhvukBc0Y7EFhNF3h1XwWx+4b Kbo5QWmAS/7xbvBzUohlCpKXz7VhEEHvAWefdxNDSh1NRVQ6umtA8C7IoOtCCiCQJCgq 7LfinzGyxAf0UEcnm07xN5NZe+xoo6cYvVVSVMnVUvXa3AqZG26ynOvQjvL9KXNNG8jd Ld8WX2nsi0/NOrMQXjUBwB/PlgHspJxppougdAOIzcUthJFZUMplmatA285DquFPTrHW ftmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=2m4LA9/XyQeLakAuFaCnlfb6CvcNSrmjDL5SUAKC5Kg=; b=hrWVkRFEFBP2/YnA7YkQZB1OAjvn1W6o8Cshx7HY6rO5jqSyqTXovDXwlh2LWBVmai 7LfYTLX9gd2OUBbOo8+ydj3ReZzPJ74Dm9U2qTa11NneTHH7Uh3bo54cRwutZwci9GGE JZvRUUpotyxuxJ8BSXOZN8EmCXAyMacaoh16ApR8Xyic3q3PmPv2SnIbe8ziUeOQQ6RP HVQFQkpOXePrpfdSfchunPQtA0bMiUcTRj3RN4nZnTGbHYq16gVf6Uo12YHtWGrOs/YS 0hN1zQN5WS4UxOBECDkcJ0g8h/Qdl3IymCnN40IsqjMYpUnDA1fEmGoDKOCjHBg0zLMM b7Ng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t24si4449717pjg.166.2021.04.21.18.21.58; Wed, 21 Apr 2021 18:22:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245565AbhDUTvz (ORCPT + 99 others); Wed, 21 Apr 2021 15:51:55 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:50405 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S235545AbhDUTvy (ORCPT ); Wed, 21 Apr 2021 15:51:54 -0400 X-UUID: 4ae8dfbef6c8487b96a602e9217d5edb-20210422 X-UUID: 4ae8dfbef6c8487b96a602e9217d5edb-20210422 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 93061916; Thu, 22 Apr 2021 03:51:18 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs06n2.mediatek.inc (172.21.101.130) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 22 Apr 2021 03:51:16 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 22 Apr 2021 03:51:16 +0800 From: Ryder Lee To: Felix Fietkau , Lorenzo Bianconi CC: Shayne Chen , , , Ryder Lee Subject: [PATCH v2 3/3] mt76: mt7615: add thermal sensor device support Date: Thu, 22 Apr 2021 03:51:11 +0800 Message-ID: <8e7057e048669d634b270fdd71a1de7527a5edb6.1619026557.git.ryder.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <202e3d430a232592c1194d4fdec1adb1b3703588.1619026557.git.ryder.lee@mediatek.com> References: <202e3d430a232592c1194d4fdec1adb1b3703588.1619026557.git.ryder.lee@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: AE777033FFC9BFF4D25E7F87C019A949BAC5EAABBB7740D87AFD516711FCF4DD2000:8 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Similar to mt7915, switching to use standard hwmon sysfs. For reading temperature, cat /sys/class/ieee80211/phy*/hwmon*/temp1_input Signed-off-by: Ryder Lee --- changes since v2 - fix build error --- .../wireless/mediatek/mt76/mt7615/debugfs.c | 20 -------- .../net/wireless/mediatek/mt76/mt7615/init.c | 50 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7615/mcu.c | 6 +-- .../wireless/mediatek/mt76/mt7615/mt7615.h | 3 +- .../wireless/mediatek/mt76/mt7615/pci_init.c | 4 ++ 5 files changed, 58 insertions(+), 25 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c index 1b414220521a..96b75f316071 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c @@ -291,24 +291,6 @@ mt7615_radio_read(struct seq_file *s, void *data) return 0; } -static int mt7615_read_temperature(struct seq_file *s, void *data) -{ - struct mt7615_dev *dev = dev_get_drvdata(s->private); - int temp; - - if (!mt7615_wait_for_mcu_init(dev)) - return 0; - - /* cpu */ - mt7615_mutex_acquire(dev); - temp = mt7615_mcu_get_temperature(dev, 0); - mt7615_mutex_release(dev); - - seq_printf(s, "Temperature: %d\n", temp); - - return 0; -} - static int mt7615_queues_acq(struct seq_file *s, void *data) { @@ -536,8 +518,6 @@ int mt7615_init_debugfs(struct mt7615_dev *dev) debugfs_create_file("reset_test", 0200, dir, dev, &fops_reset_test); - debugfs_create_devm_seqfile(dev->mt76.dev, "temperature", dir, - mt7615_read_temperature); debugfs_create_file("ext_mac_addr", 0600, dir, dev, &fops_ext_mac_addr); debugfs_create_u32("rf_wfidx", 0600, dir, &dev->debugfs_rf_wf); diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/init.c b/drivers/net/wireless/mediatek/mt76/mt7615/init.c index d84662fb0304..515933d239ba 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/init.c @@ -8,11 +8,61 @@ */ #include +#include +#include #include "mt7615.h" #include "mac.h" #include "mcu.h" #include "eeprom.h" +static ssize_t mt7615_thermal_show_temp(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct mt7615_dev *mdev = dev_get_drvdata(dev); + int temperature; + + if (!mt7615_wait_for_mcu_init(mdev)) + return 0; + + mt7615_mutex_acquire(mdev); + temperature = mt7615_mcu_get_temperature(mdev); + mt7615_mutex_release(mdev); + + if (temperature < 0) + return temperature; + + /* display in millidegree celcius */ + return sprintf(buf, "%u\n", temperature * 1000); +} + +static SENSOR_DEVICE_ATTR(temp1_input, 0444, mt7615_thermal_show_temp, + NULL, 0); + +static struct attribute *mt7615_hwmon_attrs[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(mt7615_hwmon); + +int mt7615_thermal_init(struct mt7615_dev *dev) +{ + struct wiphy *wiphy = mt76_hw(dev)->wiphy; + struct device *hwmon; + + if (!IS_REACHABLE(CONFIG_HWMON)) + return 0; + + hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev, + wiphy_name(wiphy), dev, + mt7615_hwmon_groups); + if (IS_ERR(hwmon)) + return PTR_ERR(hwmon); + + return 0; +} +EXPORT_SYMBOL_GPL(mt7615_thermal_init); + static void mt7615_phy_init(struct mt7615_dev *dev) { diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c index be976fe97290..67af2e2d4779 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c @@ -2301,14 +2301,12 @@ int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd) return mt76_mcu_send_msg(&dev->mt76, cmd, &req, sizeof(req), true); } -int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index) +int mt7615_mcu_get_temperature(struct mt7615_dev *dev) { struct { u8 action; u8 rsv[3]; - } req = { - .action = index, - }; + } req = {}; return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_GET_TEMP, &req, sizeof(req), true); diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h index 6a50338ec9f5..68c844527f65 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h @@ -359,6 +359,7 @@ static inline int mt7622_wmac_init(struct mt7615_dev *dev) } #endif +int mt7615_thermal_init(struct mt7615_dev *dev); int mt7615_mmio_probe(struct device *pdev, void __iomem *mem_base, int irq, const u32 *map); u32 mt7615_reg_map(struct mt7615_dev *dev, u32 addr); @@ -497,7 +498,7 @@ u32 mt7615_rf_rr(struct mt7615_dev *dev, u32 wf, u32 reg); int mt7615_rf_wr(struct mt7615_dev *dev, u32 wf, u32 reg, u32 val); int mt7615_mcu_set_dbdc(struct mt7615_dev *dev); int mt7615_mcu_set_eeprom(struct mt7615_dev *dev); -int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index); +int mt7615_mcu_get_temperature(struct mt7615_dev *dev); int mt7615_mcu_set_tx_power(struct mt7615_phy *phy); void mt7615_mcu_exit(struct mt7615_dev *dev); void mt7615_mcu_fill_msg(struct mt7615_dev *dev, struct sk_buff *skb, diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c b/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c index 49540b00519d..10bd2c2bbf1c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/pci_init.c @@ -153,6 +153,10 @@ int mt7615_register_device(struct mt7615_dev *dev) if (ret) return ret; + ret = mt7615_thermal_init(dev); + if (ret) + return ret; + ieee80211_queue_work(mt76_hw(dev), &dev->mcu_work); mt7615_init_txpower(dev, &dev->mphy.sband_2g.sband); mt7615_init_txpower(dev, &dev->mphy.sband_5g.sband); -- 2.18.0