[PATCH 1/2] mt76: mt7915: add thermal sensor device support
Lorenzo Bianconi
lorenzo.bianconi at redhat.com
Sun Apr 18 22:26:12 BST 2021
[...]
>
> +static ssize_t mt7915_thermal_show_temp(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + struct mt7915_phy *phy = dev_get_drvdata(dev);
> + int temperature;
> +
> + mutex_lock(&phy->dev->mt76.mutex);
> + temperature = mt7915_mcu_get_temperature(phy);
> + mutex_unlock(&phy->dev->mt76.mutex);
I guess we do not need this lock here since mcu already has its own lock (mcu
mutex) and mt7915 does not support runtime-pm.
Regards,
Lorenzo
> +
> + if (temperature < 0)
> + return temperature;
> +
> + /* display in millidegree celcius */
> + return sprintf(buf, "%u\n", temperature * 1000);
> +}
> +
> +static SENSOR_DEVICE_ATTR(temp1_input, 0444, mt7915_thermal_show_temp,
> + NULL, 0);
> +
> +static struct attribute *mt7915_hwmon_attrs[] = {
> + &sensor_dev_attr_temp1_input.dev_attr.attr,
> + NULL,
> +};
> +ATTRIBUTE_GROUPS(mt7915_hwmon);
> +
> +static int mt7915_thermal_init(struct mt7915_phy *phy)
> +{
> + struct wiphy *wiphy = phy->mt76->hw->wiphy;
> + struct device *hwmon;
> +
> + /* TODO: add cooling device for throttling */
> +
> + if (!IS_REACHABLE(CONFIG_HWMON))
> + return 0;
> +
> + hwmon = devm_hwmon_device_register_with_groups(&wiphy->dev,
> + wiphy_name(wiphy), phy,
> + mt7915_hwmon_groups);
> + if (IS_ERR(hwmon))
> + return PTR_ERR(hwmon);
> +
> + return 0;
> +}
> +
> static void
> mt7915_init_txpower(struct mt7915_dev *dev,
> struct ieee80211_supported_band *sband)
> @@ -286,6 +334,10 @@ static int mt7915_register_ext_phy(struct mt7915_dev *dev)
> if (ret)
> goto error;
>
> + ret = mt7915_thermal_init(phy);
> + if (ret)
> + goto error;
> +
> return 0;
>
> error:
> @@ -739,6 +791,10 @@ int mt7915_register_device(struct mt7915_dev *dev)
> if (ret)
> return ret;
>
> + ret = mt7915_thermal_init(&dev->phy);
> + if (ret)
> + return ret;
> +
> ieee80211_queue_work(mt76_hw(dev), &dev->init_work);
>
> ret = mt7915_register_ext_phy(dev);
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> index 559ad230eabe..17a617df6dba 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
> @@ -3469,16 +3469,17 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
> return 0;
> }
>
> -int mt7915_mcu_get_temperature(struct mt7915_dev *dev, int index)
> +int mt7915_mcu_get_temperature(struct mt7915_phy *phy)
> {
> + struct mt7915_dev *dev = phy->dev;
> struct {
> u8 ctrl_id;
> u8 action;
> - u8 band;
> + u8 dbdc_idx;
> u8 rsv[5];
> } req = {
> .ctrl_id = THERMAL_SENSOR_TEMP_QUERY,
> - .action = index,
> + .dbdc_idx = phy != &dev->phy,
> };
>
> return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_CTRL), &req,
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
> index 80eb35231a1a..d5296e2d481b 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
> @@ -357,7 +357,7 @@ int mt7915_mcu_set_radar_th(struct mt7915_dev *dev, int index,
> const struct mt7915_dfs_pattern *pattern);
> int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev);
> int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy);
> -int mt7915_mcu_get_temperature(struct mt7915_dev *dev, int index);
> +int mt7915_mcu_get_temperature(struct mt7915_phy *phy);
> int mt7915_mcu_get_tx_rate(struct mt7915_dev *dev, u32 cmd, u16 wlan_idx);
> int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
> struct ieee80211_sta *sta, struct rate_info *rate);
> --
> 2.18.0
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-mediatek/attachments/20210418/51cf29f3/attachment.sig>
More information about the Linux-mediatek
mailing list