summaryrefslogtreecommitdiff
path: root/hwmon.c
blob: 7332023ce46f299672ab32054f8c303e4a340820 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright (C) 2016  Bjørn Mork <bjorn@mork.no>
 */

#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);
	
	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),
						  priv, 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 */