From 6357d52c9eca2f53b5f461e186fcf2646c9973c0 Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Wed, 6 Jan 2016 14:52:53 +0100 Subject: mwlwifi: add hwmon device for temp monitoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This implements a simple hwmon temperature monitoring device. The scale looks way off, but this is the "celcius" temperature as it is read from the firmware: root@wrt1900ac-1:~# sensors phy0-pci-0200 Adapter: PCI adapter temp1: +131.0°C phy1-pci-0300 Adapter: PCI adapter temp1: +130.0°C tmp421-i2c-0-4c Adapter: mv64xxx_i2c adapter temp1: +36.6°C temp2: +39.6°C armada_thermal-virtual-0 Adapter: Virtual device temp1: +48.7°C Signed-off-by: Bjørn Mork --- Makefile | 1 + dev.h | 4 ++++ hwmon.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ hwmon.h | 16 ++++++++++++++++ main.c | 5 +++++ 5 files changed, 77 insertions(+) create mode 100644 hwmon.c create mode 100644 hwmon.h diff --git a/Makefile b/Makefile index 11b812c..fa0391f 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ mwlwifi-objs += fwcmd.o mwlwifi-objs += tx.o mwlwifi-objs += rx.o mwlwifi-objs += isr.o +mwlwifi-objs += hwmon.o mwlwifi-$(CONFIG_DEBUG_FS) += debugfs.o ifeq (1, $(BUILD_MFG)) mwlwifi-objs += mfg.o diff --git a/dev.h b/dev.h index f97330f..a167767 100644 --- a/dev.h +++ b/dev.h @@ -376,6 +376,10 @@ struct mwl_priv { bool mfg_mode; +#if IS_ENABLED(CONFIG_HWMON) + struct device *hwmon; +#endif + #ifdef CONFIG_DEBUG_FS struct dentry *debugfs_phy; u32 reg_type; diff --git a/hwmon.c b/hwmon.c new file mode 100644 index 0000000..535d7aa --- /dev/null +++ b/hwmon.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 Bjørn Mork + */ + +#include +#include "sysadpt.h" +#include "dev.h" +#include "fwcmd.h" +#include "hwmon.h" + +#if IS_ENABLED(CONFIG_HWMON) +static ssize_t temp1_input_show(struct device *device, + struct device_attribute *devattr, + char *buf) +{ + u32 temp; + struct ieee80211_hw *hw = dev_get_drvdata(device); + int ret = mwl_fwcmd_get_temp(hw, &temp); + + return ret < 0 ? ret : snprintf(buf, PAGE_SIZE, "%d\n", temp * 1000); +} +static DEVICE_ATTR_RO(temp1_input); + +static struct attribute *mwl_hwmon_attrs[] = { + &dev_attr_temp1_input.attr, + NULL, +}; +ATTRIBUTE_GROUPS(mwl_hwmon); + +int mwl_hwmon_register(struct ieee80211_hw *hw) +{ + struct mwl_priv *priv = hw->priv; + struct device *hwmon; + + hwmon = hwmon_device_register_with_groups(priv->dev, wiphy_name(hw->wiphy), + hw, mwl_hwmon_groups); + if (!IS_ERR(hwmon)) + priv->hwmon = hwmon; + return PTR_ERR_OR_ZERO(hwmon); +} + +void mwl_hwmon_unregister(struct ieee80211_hw *hw) +{ + struct mwl_priv *priv = hw->priv; + + if (priv->hwmon) + hwmon_device_unregister(priv->hwmon); + priv->hwmon = NULL; +} +#endif /* CONFIG_HWMON */ + diff --git a/hwmon.h b/hwmon.h new file mode 100644 index 0000000..edcdb2f --- /dev/null +++ b/hwmon.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2016 Bjørn Mork + */ + +#ifndef _MWL_HWMON_H_ +#define _MWL_HWMON_H_ + +#if IS_ENABLED(CONFIG_HWMON) +int mwl_hwmon_register(struct ieee80211_hw *hw); +void mwl_hwmon_unregister(struct ieee80211_hw *hw); +#else +static inline int mwl_hwmon_register(struct ieee80211_hw *hw) { return 0; } +static inline void mwl_hwmon_unregister(struct ieee80211_hw *hw) {} +#endif + +#endif /* _MWL_HWMON_H_ */ diff --git a/main.c b/main.c index 3fbd596..4425ce3 100644 --- a/main.c +++ b/main.c @@ -30,6 +30,7 @@ #ifdef SUPPORT_MFG #include "mfg.h" #endif +#include "hwmon.h" #ifdef CONFIG_DEBUG_FS #include "debugfs.h" #endif @@ -822,6 +823,8 @@ static int mwl_probe(struct pci_dev *pdev, const struct pci_device_id *id) (priv->antenna_tx == ANTENNA_TX_4_AUTO) ? "4" : "2", (priv->antenna_rx == ANTENNA_RX_4_AUTO) ? "4" : "2"); + mwl_hwmon_register(hw); + #ifdef CONFIG_DEBUG_FS mwl_debugfs_init(hw); #endif @@ -853,6 +856,8 @@ static void mwl_remove(struct pci_dev *pdev) if (!hw) return; + mwl_hwmon_unregister(hw); + priv = hw->priv; mwl_wl_deinit(priv); -- cgit v1.2.3 From 6123ec023e30a4f16f4294207d97f7dfe00b047e Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Fri, 8 Jan 2016 22:34:39 +0100 Subject: mwlwifi: convert from Fahrenheit to Celcius MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Empirical testing indicates that the values reported by the firmware are in Fahrenheit despite the 'celcius' field name. Convert firmware value to millidegree Celcius as required by the hwmon sysfs ABI. Signed-off-by: Bjørn Mork --- hwmon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hwmon.c b/hwmon.c index 535d7aa..31ba2e9 100644 --- a/hwmon.c +++ b/hwmon.c @@ -17,7 +17,8 @@ static ssize_t temp1_input_show(struct device *device, struct ieee80211_hw *hw = dev_get_drvdata(device); int ret = mwl_fwcmd_get_temp(hw, &temp); - return ret < 0 ? ret : snprintf(buf, PAGE_SIZE, "%d\n", temp * 1000); + /* 'temp' appears to be Fahrenheit despite the 'celcius' field name */ + return ret < 0 ? ret : snprintf(buf, PAGE_SIZE, "%d\n", (temp - 32) * 1000 * 5 / 9); } static DEVICE_ATTR_RO(temp1_input); -- cgit v1.2.3 From b7392cfb3a759535043125fc20e12b00b7d953c3 Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Fri, 8 Jan 2016 22:51:14 +0100 Subject: mwlwifi: add GPLv2 blob to hwmon files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bjørn Mork --- hwmon.c | 4 ++++ hwmon.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/hwmon.c b/hwmon.c index 31ba2e9..05bb5c7 100644 --- a/hwmon.c +++ b/hwmon.c @@ -1,5 +1,9 @@ /* * Copyright (C) 2016 Bjørn Mork + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. */ #include diff --git a/hwmon.h b/hwmon.h index edcdb2f..73bc5a1 100644 --- a/hwmon.h +++ b/hwmon.h @@ -1,5 +1,9 @@ /* * Copyright (C) 2016 Bjørn Mork + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. */ #ifndef _MWL_HWMON_H_ -- cgit v1.2.3