Commit de5ff3c9 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: mt7615: introduce pm_power_save delayed work

Introduce runtime-pm power_save delayed work used to enable
low-power after an inactivity period
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 940a0c63
...@@ -436,6 +436,7 @@ void mt7615_init_device(struct mt7615_dev *dev) ...@@ -436,6 +436,7 @@ void mt7615_init_device(struct mt7615_dev *dev)
dev->phy.mt76 = &dev->mt76.phy; dev->phy.mt76 = &dev->mt76.phy;
dev->mt76.phy.priv = &dev->phy; dev->mt76.phy.priv = &dev->phy;
INIT_DELAYED_WORK(&dev->pm.ps_work, mt7615_pm_power_save_work);
INIT_WORK(&dev->pm.wake_work, mt7615_pm_wake_work); INIT_WORK(&dev->pm.wake_work, mt7615_pm_wake_work);
init_completion(&dev->pm.wake_cmpl); init_completion(&dev->pm.wake_cmpl);
INIT_DELAYED_WORK(&dev->phy.mac_work, mt7615_mac_work); INIT_DELAYED_WORK(&dev->phy.mac_work, mt7615_mac_work);
......
...@@ -1850,6 +1850,34 @@ int mt7615_pm_wake(struct mt7615_dev *dev) ...@@ -1850,6 +1850,34 @@ int mt7615_pm_wake(struct mt7615_dev *dev)
} }
EXPORT_SYMBOL_GPL(mt7615_pm_wake); EXPORT_SYMBOL_GPL(mt7615_pm_wake);
void mt7615_pm_power_save_sched(struct mt7615_dev *dev)
{
struct mt76_phy *mphy = dev->phy.mt76;
if (!mt7615_firmware_offload(dev) ||
!dev->pm.enable || !mt76_is_mmio(mphy->dev) ||
!test_bit(MT76_STATE_RUNNING, &mphy->state))
return;
dev->pm.last_activity = jiffies;
if (!test_bit(MT76_STATE_PM, &mphy->state))
queue_delayed_work(dev->mt76.wq, &dev->pm.ps_work,
MT7615_PM_TIMEOUT);
}
EXPORT_SYMBOL_GPL(mt7615_pm_power_save_sched);
void mt7615_pm_power_save_work(struct work_struct *work)
{
struct mt7615_dev *dev;
dev = (struct mt7615_dev *)container_of(work, struct mt7615_dev,
pm.ps_work.work);
if (mt7615_firmware_own(dev))
queue_delayed_work(dev->mt76.wq, &dev->pm.ps_work,
MT7615_PM_TIMEOUT);
}
void mt7615_mac_work(struct work_struct *work) void mt7615_mac_work(struct work_struct *work)
{ {
struct mt7615_phy *phy; struct mt7615_phy *phy;
......
...@@ -74,6 +74,7 @@ static void mt7615_stop(struct ieee80211_hw *hw) ...@@ -74,6 +74,7 @@ static void mt7615_stop(struct ieee80211_hw *hw)
del_timer_sync(&phy->roc_timer); del_timer_sync(&phy->roc_timer);
cancel_work_sync(&phy->roc_work); cancel_work_sync(&phy->roc_work);
cancel_delayed_work_sync(&dev->pm.ps_work);
cancel_work_sync(&dev->pm.wake_work); cancel_work_sync(&dev->pm.wake_work);
mt7615_mutex_acquire(dev); mt7615_mutex_acquire(dev);
...@@ -1003,6 +1004,8 @@ static int mt7615_suspend(struct ieee80211_hw *hw, ...@@ -1003,6 +1004,8 @@ static int mt7615_suspend(struct ieee80211_hw *hw,
bool ext_phy = phy != &dev->phy; bool ext_phy = phy != &dev->phy;
int err = 0; int err = 0;
cancel_delayed_work_sync(&dev->pm.ps_work);
mt7615_mutex_acquire(dev); mt7615_mutex_acquire(dev);
clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#define MT7615_WTBL_STA (MT7615_WTBL_RESERVED - \ #define MT7615_WTBL_STA (MT7615_WTBL_RESERVED - \
MT7615_MAX_INTERFACES) MT7615_MAX_INTERFACES)
#define MT7615_PM_TIMEOUT (HZ / 12)
#define MT7615_WATCHDOG_TIME (HZ / 10) #define MT7615_WATCHDOG_TIME (HZ / 10)
#define MT7615_HW_SCAN_TIMEOUT (HZ / 10) #define MT7615_HW_SCAN_TIMEOUT (HZ / 10)
#define MT7615_RESET_TIMEOUT (30 * HZ) #define MT7615_RESET_TIMEOUT (30 * HZ)
...@@ -299,9 +300,12 @@ struct mt7615_dev { ...@@ -299,9 +300,12 @@ struct mt7615_dev {
#endif #endif
struct { struct {
bool enable;
struct work_struct wake_work; struct work_struct wake_work;
struct completion wake_cmpl; struct completion wake_cmpl;
struct delayed_work ps_work;
unsigned long last_activity; unsigned long last_activity;
} pm; } pm;
}; };
...@@ -435,6 +439,8 @@ void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta, ...@@ -435,6 +439,8 @@ void mt7615_mac_set_rates(struct mt7615_phy *phy, struct mt7615_sta *sta,
struct ieee80211_tx_rate *rates); struct ieee80211_tx_rate *rates);
void mt7615_pm_wake_work(struct work_struct *work); void mt7615_pm_wake_work(struct work_struct *work);
int mt7615_pm_wake(struct mt7615_dev *dev); int mt7615_pm_wake(struct mt7615_dev *dev);
void mt7615_pm_power_save_sched(struct mt7615_dev *dev);
void mt7615_pm_power_save_work(struct work_struct *work);
int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev); int mt7615_mcu_del_wtbl_all(struct mt7615_dev *dev);
int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd); int mt7615_mcu_set_chan_info(struct mt7615_phy *phy, int cmd);
int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue, int mt7615_mcu_set_wmm(struct mt7615_dev *dev, u8 queue,
...@@ -499,7 +505,7 @@ static inline void mt7615_mutex_acquire(struct mt7615_dev *dev) ...@@ -499,7 +505,7 @@ static inline void mt7615_mutex_acquire(struct mt7615_dev *dev)
static inline void mt7615_mutex_release(struct mt7615_dev *dev) static inline void mt7615_mutex_release(struct mt7615_dev *dev)
__releases(&dev->mt76.mutex) __releases(&dev->mt76.mutex)
{ {
dev->pm.last_activity = jiffies; mt7615_pm_power_save_sched(dev);
mutex_unlock(&dev->mt76.mutex); mutex_unlock(&dev->mt76.mutex);
} }
......
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