Commit 495cd981 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: mt7921: introduce dedicated control for deep_sleep

Introduce ds_enable switch to fully control fw deep_sleep capability
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 8225816d
......@@ -46,6 +46,7 @@ enum {
struct mt76_connac_pm {
bool enable;
bool ds_enable;
bool suspended;
spinlock_t txq_lock;
......
......@@ -251,7 +251,7 @@ mt7921_pm_set(void *data, u64 val)
IEEE80211_IFACE_ITER_RESUME_ALL,
mt7921_pm_interface_iter, mphy->priv);
mt76_connac_mcu_set_deep_sleep(&dev->mt76, !!pm->enable);
mt76_connac_mcu_set_deep_sleep(&dev->mt76, pm->ds_enable);
mt7921_mutex_release(dev);
......@@ -274,15 +274,31 @@ static int
mt7921_deep_sleep_set(void *data, u64 val)
{
struct mt7921_dev *dev = data;
struct mt76_connac_pm *pm = &dev->pm;
bool enable = !!val;
mt7921_mutex_acquire(dev);
mt76_connac_mcu_set_deep_sleep(&dev->mt76, !!val);
if (pm->ds_enable != enable) {
mt76_connac_mcu_set_deep_sleep(&dev->mt76, enable);
pm->ds_enable = enable;
}
mt7921_mutex_release(dev);
return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE(fops_ds, NULL, mt7921_deep_sleep_set, "%lld\n");
static int
mt7921_deep_sleep_get(void *data, u64 *val)
{
struct mt7921_dev *dev = data;
*val = dev->pm.ds_enable;
return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE(fops_ds, mt7921_deep_sleep_get,
mt7921_deep_sleep_set, "%lld\n");
static int
mt7921_pm_stats(struct seq_file *s, void *data)
......
......@@ -201,6 +201,7 @@ int mt7921_register_device(struct mt7921_dev *dev)
dev->pm.stats.last_wake_event = jiffies;
dev->pm.stats.last_doze_event = jiffies;
dev->pm.enable = true;
dev->pm.ds_enable = true;
ret = mt7921_init_hardware(dev);
if (ret)
......@@ -235,7 +236,7 @@ int mt7921_register_device(struct mt7921_dev *dev)
if (ret)
return ret;
return mt76_connac_mcu_set_deep_sleep(&dev->mt76, dev->pm.enable);
return mt76_connac_mcu_set_deep_sleep(&dev->mt76, dev->pm.ds_enable);
}
void mt7921_unregister_device(struct mt7921_dev *dev)
......
......@@ -820,7 +820,7 @@ static int mt7921_sta_state(struct ieee80211_hw *hw,
{
struct mt7921_dev *dev = mt7921_hw_dev(hw);
if (dev->pm.enable) {
if (dev->pm.ds_enable) {
mt7921_mutex_acquire(dev);
mt76_connac_sta_state_dp(&dev->mt76, old_state, new_state);
mt7921_mutex_release(dev);
......
......@@ -208,8 +208,10 @@ static int mt7921_pci_suspend(struct pci_dev *pdev, pm_message_t state)
goto restore_suspend;
}
if (!pm->enable)
mt76_connac_mcu_set_deep_sleep(&dev->mt76, true);
/* always enable deep sleep during suspend to reduce
* power consumption
*/
mt76_connac_mcu_set_deep_sleep(&dev->mt76, true);
napi_disable(&mdev->tx_napi);
mt76_worker_disable(&mdev->tx_worker);
......@@ -252,7 +254,7 @@ static int mt7921_pci_suspend(struct pci_dev *pdev, pm_message_t state)
}
napi_enable(&mdev->tx_napi);
if (!pm->enable)
if (!pm->ds_enable)
mt76_connac_mcu_set_deep_sleep(&dev->mt76, false);
if (hif_suspend)
......@@ -268,9 +270,10 @@ static int mt7921_pci_resume(struct pci_dev *pdev)
{
struct mt76_dev *mdev = pci_get_drvdata(pdev);
struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
struct mt76_connac_pm *pm = &dev->pm;
int i, err;
dev->pm.suspended = false;
pm->suspended = false;
err = pci_set_power_state(pdev, PCI_D0);
if (err)
return err;
......@@ -301,7 +304,8 @@ static int mt7921_pci_resume(struct pci_dev *pdev)
napi_enable(&mdev->tx_napi);
napi_schedule(&mdev->tx_napi);
if (!dev->pm.enable)
/* restore previous ds setting */
if (!pm->ds_enable)
mt76_connac_mcu_set_deep_sleep(&dev->mt76, false);
if (!test_bit(MT76_STATE_SUSPEND, &dev->mphy.state))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment