[PATCH 2/2] mt76: mt7615: add thermal sensor device support

Felix Fietkau nbd at nbd.name
Wed Apr 21 11:32:11 BST 2021


On 2021-04-17 22:42, Ryder Lee wrote:
> 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 <ryder.lee at mediatek.com>
> ---
>  .../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/init.c b/drivers/net/wireless/mediatek/mt76/mt7615/init.c
> index d84662fb0304..22ccad43a13e 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7615/init.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7615/init.c
> @@ -8,11 +8,61 @@
>   */
>  
>  #include <linux/etherdevice.h>
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
>  #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), phy,
This does not compile (wrong variable name).

- Felix



More information about the Linux-mediatek mailing list