linux/drivers/net/wireless/morsemicro/mm81x/ps.c
Lachlan Hodges b1906cea00 wifi: mm81x: add mm81x Wi-Fi HaLow driver
mm81x is the first Wi-Fi HaLow driver to support the Morse Micro mm81x
chip family via USB and SDIO.

S1G support in the kernel is only new, and as a result this driver has
been scoped to be simple and only support station and AP interface.
The Wi-Fi specific features only cover the minimum required for basic
use such as powersave, aggregation, rate control and so on. The driver
will be extended into the future as S1G support for operations such as
ACS, channel switching and so on are added into the wireless stack.

The driver has been build tested on a long list of architectures and
compilers via Intels LKP.

The driver currently supports IEEE80211-2024 US channels only, with
AU 2020 also available. In order for this to be expanded additional
non-trivial kernel work is required which will begin once the
driver is upstream.

The driver has had many authors who are listed below in
alphabetical order:

Co-developed-by: Andrew Pope <andrew.pope@morsemicro.com>
Signed-off-by: Andrew Pope <andrew.pope@morsemicro.com>
Co-developed-by: Arien Judge <arien.judge@morsemicro.com>
Signed-off-by: Arien Judge <arien.judge@morsemicro.com>
Co-developed-by: Ayman Grais <ayman.grais@morsemicro.com>
Signed-off-by: Ayman Grais <ayman.grais@morsemicro.com>
Co-developed-by: Bassem Dawood <bassem@morsemicro.com>
Signed-off-by: Bassem Dawood <bassem@morsemicro.com>
Co-developed-by: Chetan Mistry <chetan.mistry@morsemicro.com>
Signed-off-by: Chetan Mistry <chetan.mistry@morsemicro.com>
Co-developed-by: Dan Callaghan <dan.callaghan@morsemicro.com>
Signed-off-by: Dan Callaghan <dan.callaghan@morsemicro.com>
Co-developed-by: James Herbert <james.herbert@morsemicro.com>
Signed-off-by: James Herbert <james.herbert@morsemicro.com>
Co-developed-by: Sahand Maleki <sahand.maleki@morsemicro.com>
Signed-off-by: Sahand Maleki <sahand.maleki@morsemicro.com>
Co-developed-by: Simon Wadsworth <simon@morsemicro.com>
Signed-off-by: Simon Wadsworth <simon@morsemicro.com>
Signed-off-by: Lachlan Hodges <lachlan.hodges@morsemicro.com>
2026-07-08 12:03:50 +10:00

121 lines
2.3 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2017-2026 Morse Micro
*/
#include <linux/types.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>
#include "hif.h"
#include "skbq.h"
#include "mac.h"
#include "bus.h"
#include "ps.h"
static void mm81x_ps_wakeup(struct mm81x_ps *mps)
{
struct mm81x *mors = container_of(mps, struct mm81x, ps);
if (!mps->enable || !mps->suspended)
return;
mm81x_set_bus_enable(mors, true);
mps->suspended = false;
}
static void mm81x_ps_sleep(struct mm81x_ps *mps)
{
struct mm81x *mors = container_of(mps, struct mm81x, ps);
if (!mps->enable || mps->suspended)
return;
mps->suspended = true;
mm81x_set_bus_enable(mors, false);
}
static void mm81x_ps_evaluate(struct mm81x_ps *mps)
{
struct mm81x *mors = container_of(mps, struct mm81x, ps);
bool needs_wake = false;
unsigned long flags_on_entry =
(mors->hif.event_flags &
~BIT(MM81X_HIF_EVT_DATA_TRAFFIC_PAUSE_PEND));
if (!mps->enable)
return;
needs_wake = (mps->wakers > 0);
needs_wake |= (flags_on_entry > 0);
needs_wake |= (mm81x_hif_get_tx_buffered_count(mors) > 0);
if (needs_wake) {
mm81x_ps_wakeup(mps);
return;
}
mm81x_ps_sleep(mps);
}
static void mm81x_ps_evaluate_work(struct work_struct *work)
{
struct mm81x_ps *mps =
container_of(work, struct mm81x_ps, delayed_eval_work.work);
if (mps->enable) {
mutex_lock(&mps->lock);
mm81x_ps_evaluate(mps);
mutex_unlock(&mps->lock);
}
}
void mm81x_ps_enable(struct mm81x *mors)
{
struct mm81x_ps *mps = &mors->ps;
if (mps->enable) {
mutex_lock(&mps->lock);
if (mps->wakers == 0) {
WARN_ON_ONCE(1);
} else {
mps->wakers--;
mm81x_ps_evaluate(mps);
}
mutex_unlock(&mps->lock);
}
}
void mm81x_ps_disable(struct mm81x *mors)
{
struct mm81x_ps *mps = &mors->ps;
if (mps->enable) {
mutex_lock(&mps->lock);
mps->wakers++;
mm81x_ps_evaluate(mps);
mutex_unlock(&mps->lock);
}
}
int mm81x_ps_init(struct mm81x *mors)
{
struct mm81x_ps *mps = &mors->ps;
mps->enable = (mors->bus_type == MM81X_BUS_TYPE_USB);
mps->suspended = true;
mps->wakers = 1; /* we default to being on */
mutex_init(&mps->lock);
INIT_DELAYED_WORK(&mps->delayed_eval_work, mm81x_ps_evaluate_work);
return 0;
}
void mm81x_ps_finish(struct mm81x *mors)
{
struct mm81x_ps *mps = &mors->ps;
if (mps->enable) {
mps->enable = false;
cancel_delayed_work_sync(&mps->delayed_eval_work);
}
}