summaryrefslogtreecommitdiff
path: root/hwmon.c
diff options
context:
space:
mode:
Diffstat (limited to 'hwmon.c')
-rw-r--r--hwmon.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/hwmon.c b/hwmon.c
new file mode 100644
index 0000000..05bb5c7
--- /dev/null
+++ b/hwmon.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 Bjørn Mork <bjorn@mork.no>
+ *
+ * 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 <linux/hwmon.h>
+#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);
+
+ /* '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);
+
+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 */
+