From 0728e6e0dd30ec346066778807c9cb0dad7964f3 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. 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