From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
To: Ryder Lee <ryder.lee@mediatek.com>
Cc: Felix Fietkau <nbd@nbd.name>,
Shayne Chen <shayne.chen@mediatek.com>,
linux-wireless@vger.kernel.org,
linux-mediatek@lists.infradead.org
Subject: Re: [PATCH 1/2] mt76: mt7915: add thermal sensor device support
Date: Sun, 18 Apr 2021 23:26:12 +0200 [thread overview]
Message-ID: <YHyj9H52zgoDXWbN@lore-desk> (raw)
In-Reply-To: <b51d79d257e150a09d51029e3465e2ce925d6cfe.1618691395.git.ryder.lee@mediatek.com>
[-- Attachment #1: Type: text/plain, Size: 3834 bytes --]
[...]
>
> +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
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
prev parent reply other threads:[~2021-04-18 21:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-17 20:42 [PATCH 1/2] mt76: mt7915: add thermal sensor device support Ryder Lee
2021-04-17 20:42 ` [PATCH 2/2] mt76: mt7615: " Ryder Lee
2021-04-21 10:32 ` Felix Fietkau
2021-04-18 21:26 ` Lorenzo Bianconi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YHyj9H52zgoDXWbN@lore-desk \
--to=lorenzo.bianconi@redhat.com \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=nbd@nbd.name \
--cc=ryder.lee@mediatek.com \
--cc=shayne.chen@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).