🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Christian Marangi Wed, 04 Nov 2026 07:29
[PATCH RFC net-next] net: airoha: npu: attach passive devfreq scaling
#10836
Author: Christian Marangi
Date: Wed, 04 Nov 2026 07:29
126 lines
14313 bytes
The NPU can scale to different operating state from idle to normal to
turbo. Attach a passive devfreq that will scale the NPU frequency with the
CPU with the use of OPP table and opp-required properties.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---

Posted as RFC to understand if it's the correct way to handle this...

DT patch will come later.

 drivers/net/ethernet/airoha/airoha_npu.c  | 61 ++++++++++++++++++++++-
 include/linux/soc/airoha/airoha_offload.h |  3 ++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/airoha/airoha_npu.c b/drivers/net/ethernet/airoha/airoha_npu.c
index 4d3195eb00f7..f8055ca65ec4 100644
--- a/drivers/net/ethernet/airoha/airoha_npu.c
+++ b/drivers/net/ethernet/airoha/airoha_npu.c
@@ -12,6 +12,8 @@
 #include <linux/of_platform.h>
 #include <linux/of_reserved_mem.h>
 #include <linux/regmap.h>
+#include <linux/pm_opp.h>
+#include <linux/clk.h>
 
 #include "airoha_eth.h"
 
@@ -656,6 +658,62 @@ void airoha_npu_put(struct airoha_npu *npu)
 }
 EXPORT_SYMBOL_GPL(airoha_npu_put);
 
+static int airoha_npu_devfreq_get_cur_freq(struct device *dev, unsigned long *freq)
+{
+	struct airoha_npu *npu = dev_get_drvdata(dev);
+
+	*freq = clk_get_rate(npu->clk);
+
+	return 0;
+}
+
+static int airoha_npu_devfreq_target(struct device *dev, unsigned long *freq,
+				     u32 flags)
+{
+	struct airoha_npu *npu = dev_get_drvdata(dev);
+
+	return clk_set_rate(npu->clk, *freq);
+}
+
+static int airoha_npu_devfreq_get_dev_status(struct device *dev,
+					     struct devfreq_dev_status *stat)
+{
+	struct airoha_npu *npu = dev_get_drvdata(dev);
+
+	stat->busy_time = 0;
+	stat->total_time = 0;
+	stat->current_frequency = clk_get_rate(npu->clk);
+
+	return 0;
+}
+
+static struct devfreq_dev_profile airoha_npu_devfreq_profile = {
+	.target = airoha_npu_devfreq_target,
+	.get_dev_status = airoha_npu_devfreq_get_dev_status,
+	.get_cur_freq = airoha_npu_devfreq_get_cur_freq
+};
+
+static int airoha_npu_devfreq_probe(struct device *dev)
+{
+	struct airoha_npu *npu = dev_get_drvdata(dev);
+	struct devfreq *devfreq;
+	int ret;
+
+	npu->clk = devm_clk_get_enabled(dev, NULL);
+	if (IS_ERR(npu->clk))
+		return dev_err_probe(dev, PTR_ERR(npu->clk), "failed to get clk\n");
+
+	ret = devm_pm_opp_of_add_table(dev);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to parse NPU freq thresholds\n");
+
+	npu->gov_data.parent_type = CPUFREQ_PARENT_DEV;
+	devfreq = devm_devfreq_add_device(dev, &airoha_npu_devfreq_profile,
+					  DEVFREQ_GOV_PASSIVE, &npu->gov_data);
+
+	return PTR_ERR_OR_ZERO(devfreq);
+}
+
 static const struct airoha_npu_soc_data en7581_npu_soc_data = {
 	.fw_rv32 = {
 		.name = NPU_EN7581_FIRMWARE_RV32,
@@ -803,8 +861,9 @@ static int airoha_npu_probe(struct platform_device *pdev)
 			 (val >> 16) & 0xffff, val & 0xffff);
 
 	platform_set_drvdata(pdev, npu);
+	dev_set_drvdata(dev, npu);
 
-	return 0;
+	return airoha_npu_devfreq_probe(dev);
 }
 
 static struct platform_driver airoha_npu_driver = {
diff --git a/include/linux/soc/airoha/airoha_offload.h b/include/linux/soc/airoha/airoha_offload.h
index 7589fccfeef6..ac776dc31487 100644
--- a/include/linux/soc/airoha/airoha_offload.h
+++ b/include/linux/soc/airoha/airoha_offload.h
@@ -6,6 +6,7 @@
 #ifndef AIROHA_OFFLOAD_H
 #define AIROHA_OFFLOAD_H
 
+#include <linux/devfreq.h>
 #include <linux/skbuff.h>
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
@@ -167,6 +168,8 @@ struct airoha_npu {
 #if (IS_BUILTIN(CONFIG_NET_AIROHA_NPU) || IS_MODULE(CONFIG_NET_AIROHA_NPU))
 	struct device *dev;
 	struct regmap *regmap;
+	struct clk *clk;
+	struct devfreq_passive_data gov_data;
 
 	struct airoha_npu_core {
 		struct airoha_npu *npu;
-- 
2.55.0
Re: [PATCH RFC net-next] net: airoha: npu: attach passive devfreq scaling
#10851
Author: Lorenzo Bianconi
Date: Wed, 04 Nov 2026 08:22
166 lines
12815 bytes
--GXeSiHAEIfQDVlvR
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Nov 04, Christian Marangi wrote:
> The NPU can scale to different operating state from idle to normal to
> turbo. Attach a passive devfreq that will scale the NPU frequency with the
> CPU with the use of OPP table and opp-required properties.
>=20
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> ---
>=20
> Posted as RFC to understand if it's the correct way to handle this...
>=20
> DT patch will come later.
>=20
>  drivers/net/ethernet/airoha/airoha_npu.c  | 61 ++++++++++++++++++++++-
>  include/linux/soc/airoha/airoha_offload.h |  3 ++
>  2 files changed, 63 insertions(+), 1 deletion(-)
>=20
> diff --git a/drivers/net/ethernet/airoha/airoha_npu.c b/drivers/net/ether=
net/airoha/airoha_npu.c
> index 4d3195eb00f7..f8055ca65ec4 100644
> --- a/drivers/net/ethernet/airoha/airoha_npu.c
> +++ b/drivers/net/ethernet/airoha/airoha_npu.c
> @@ -12,6 +12,8 @@
>  #include <linux/of_platform.h>
>  #include <linux/of_reserved_mem.h>
>  #include <linux/regmap.h>
> +#include <linux/pm_opp.h>
> +#include <linux/clk.h>
> =20
>  #include "airoha_eth.h"
> =20
> @@ -656,6 +658,62 @@ void airoha_npu_put(struct airoha_npu *npu)
>  }
>  EXPORT_SYMBOL_GPL(airoha_npu_put);
> =20
> +static int airoha_npu_devfreq_get_cur_freq(struct device *dev, unsigned =
long *freq)
> +{
> +	struct airoha_npu *npu =3D dev_get_drvdata(dev);
> +
> +	*freq =3D clk_get_rate(npu->clk);
> +
> +	return 0;
> +}
> +
> +static int airoha_npu_devfreq_target(struct device *dev, unsigned long *=
freq,
> +				     u32 flags)
> +{
> +	struct airoha_npu *npu =3D dev_get_drvdata(dev);
> +
> +	return clk_set_rate(npu->clk, *freq);
> +}
> +
> +static int airoha_npu_devfreq_get_dev_status(struct device *dev,
> +					     struct devfreq_dev_status *stat)
> +{
> +	struct airoha_npu *npu =3D dev_get_drvdata(dev);
> +
> +	stat->busy_time =3D 0;
> +	stat->total_time =3D 0;
> +	stat->current_frequency =3D clk_get_rate(npu->clk);
> +
> +	return 0;
> +}
> +
> +static struct devfreq_dev_profile airoha_npu_devfreq_profile =3D {
> +	.target =3D airoha_npu_devfreq_target,
> +	.get_dev_status =3D airoha_npu_devfreq_get_dev_status,
> +	.get_cur_freq =3D airoha_npu_devfreq_get_cur_freq
> +};
> +
> +static int airoha_npu_devfreq_probe(struct device *dev)
> +{
> +	struct airoha_npu *npu =3D dev_get_drvdata(dev);
> +	struct devfreq *devfreq;
> +	int ret;
> +
> +	npu->clk =3D devm_clk_get_enabled(dev, NULL);

I guess this should be devm_clk_get_optional_enabled() otherwise this patch
will break backward compatibility. Moreover, we should bail out early if
npu->clk is NULL.

> +	if (IS_ERR(npu->clk))
> +		return dev_err_probe(dev, PTR_ERR(npu->clk), "failed to get clk\n");
> +
> +	ret =3D devm_pm_opp_of_add_table(dev);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to parse NPU freq thresholds\n"=
);
> +
> +	npu->gov_data.parent_type =3D CPUFREQ_PARENT_DEV;
> +	devfreq =3D devm_devfreq_add_device(dev, &airoha_npu_devfreq_profile,
> +					  DEVFREQ_GOV_PASSIVE, &npu->gov_data);
> +
> +	return PTR_ERR_OR_ZERO(devfreq);
> +}
> +
>  static const struct airoha_npu_soc_data en7581_npu_soc_data =3D {
>  	.fw_rv32 =3D {
>  		.name =3D NPU_EN7581_FIRMWARE_RV32,
> @@ -803,8 +861,9 @@ static int airoha_npu_probe(struct platform_device *p=
dev)
>  			 (val >> 16) & 0xffff, val & 0xffff);
> =20
>  	platform_set_drvdata(pdev, npu);
> +	dev_set_drvdata(dev, npu);

why do we need that one? I guess this is exactly what platform_set_drvdata(=
) is
doing, right?

Regards,
Lorenzo

> =20
> -	return 0;
> +	return airoha_npu_devfreq_probe(dev);
>  }
> =20
>  static struct platform_driver airoha_npu_driver =3D {
> diff --git a/include/linux/soc/airoha/airoha_offload.h b/include/linux/so=
c/airoha/airoha_offload.h
> index 7589fccfeef6..ac776dc31487 100644
> --- a/include/linux/soc/airoha/airoha_offload.h
> +++ b/include/linux/soc/airoha/airoha_offload.h
> @@ -6,6 +6,7 @@
>  #ifndef AIROHA_OFFLOAD_H
>  #define AIROHA_OFFLOAD_H
> =20
> +#include <linux/devfreq.h>
>  #include <linux/skbuff.h>
>  #include <linux/spinlock.h>
>  #include <linux/workqueue.h>
> @@ -167,6 +168,8 @@ struct airoha_npu {
>  #if (IS_BUILTIN(CONFIG_NET_AIROHA_NPU) || IS_MODULE(CONFIG_NET_AIROHA_NP=
U))
>  	struct device *dev;
>  	struct regmap *regmap;
> +	struct clk *clk;
> +	struct devfreq_passive_data gov_data;
> =20
>  	struct airoha_npu_core {
>  		struct airoha_npu *npu;
> --=20
> 2.55.0
>=20

--GXeSiHAEIfQDVlvR
Content-Type: application/pgp-signature; name=signature.asc

-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQTquNwa3Txd3rGGn7Y6cBh0uS2trAUCaurrNwAKCRA6cBh0uS2t
rELpAPwI9Nyf59rcUT+dErD/iejg4G1NiCfVcWRFwPmERqWr2QD/dKM7AqI7pn1A
Ju7qDHM8TiXXoQDNkpgJgPGDMOaVXgw=
=UYLH
-----END PGP SIGNATURE-----

--GXeSiHAEIfQDVlvR--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads