Skip to contentSkip to conversation

pmdomain: airoha: Add Airoha CPU PM Domain support

PATCH Superseded Christian Marangi 2 participants 5 messages Jan 4, 2025 – Jan 5, 2025

Subsystems (3)

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v8 1/2 pmdomain: airoha: Add Airoha CPU PM Domain support

Add Airoha CPU PM Domain support to control frequency and power of CPU present on Airoha EN7581 SoC.

Frequency and power can be controlled with the use of the SMC command by passing the performance state. The driver also expose a read-only clock that expose the current CPU frequency with SMC command.

---
Changes v8:
- Add this patch
- Use SMC invoke instead of 1.2

 drivers/pmdomain/mediatek/Kconfig             |  11 ++
 drivers/pmdomain/mediatek/Makefile            |   1 +
 .../pmdomain/mediatek/airoha-cpu-pmdomain.c   | 145 ++++++++++++++++++
 3 files changed, 157 insertions(+)
 create mode 100644 drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c
drivers/pmdomain/mediatek/Kconfig +11 -0
index 21305c4f17fe..049e599a5b57 100644
@@ -26,4 +26,15 @@ config MTK_SCPSYS_PM_DOMAINS
 	  Control Processor System (SCPSYS) has several power management related
 	  tasks in the system.
 
+config AIROHA_CPU_PM_DOMAIN
+	tristate "Airoha CPU power domain"
+	default ARCH_AIROHA
+	depends on PM
+	select PM_GENERIC_DOMAINS
+	help
+	  Say y here to enable CPU power domain support for Airoha SoC.
+
+	  CPU frequency and power is controlled by ATF with SMC command to
+	  set performance states.
+
 endmenu
drivers/pmdomain/mediatek/Makefile +1 -0
index 8cde09e654b3..0f6edce9239b 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_MTK_SCPSYS)		+= mtk-scpsys.o
 obj-$(CONFIG_MTK_SCPSYS_PM_DOMAINS) 	+= mtk-pm-domains.o
+obj-$(CONFIG_AIROHA_CPU_PM_DOMAIN) 	+= airoha-cpu-pmdomain.o
drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c new file +145 -0

145 lines not on this page · raw message

Signature · 1 line
2.45.2
#1 lore raw

PATCH v8 2/2 cpufreq: airoha: Add EN7581 CPUFreq SMCCC driver

Add simple CPU Freq driver for Airoha EN7581 SoC that control CPU frequency scaling with SMC APIs and register a generic "cpufreq-dt" device.

All CPU share the same frequency and can't be controlled independently. CPU frequency is controlled by the attached PM domain.

Add SoC compatible to cpufreq-dt-plat block list as a dedicated cpufreq driver is needed with OPP v2 nodes declared in DTS.

---
Changes v8:
- Split in dedicated PM domain driver
Changes v7:
- No changes
Changes v6:
- Improve Kconfig depends logic
- Select PM (PM_GENERIC_DOMAINS depends on it)
- Drop (int) cast for
Changes v5:
- Rename cpu_pd to perf for power domain name
- Use remove instead of remove_new
Changes v4:
- Rework to clk-only + PM set_performance_state implementation Changes v3:
- Adapt to new cpufreq-dt APIs
- Register cpufreq-dt instead of custom freq driver Changes v2:
- Fix kernel bot error with missing slab.h and bitfield.h header
- Limit COMPILE_TEST to ARM64 due to smcc 1.2

 drivers/cpufreq/Kconfig.arm          |  10 ++
 drivers/cpufreq/Makefile             |   1 +
 drivers/cpufreq/airoha-cpufreq.c     | 166 +++++++++++++++++++++++++++
 drivers/cpufreq/cpufreq-dt-platdev.c |   2 +
 4 files changed, 179 insertions(+)
 create mode 100644 drivers/cpufreq/airoha-cpufreq.c
drivers/cpufreq/Kconfig.arm +10 -0
index 5f7e13e60c80..8494faac58ae 100644
@@ -15,6 +15,16 @@ config ARM_ALLWINNER_SUN50I_CPUFREQ_NVMEM
 	  To compile this driver as a module, choose M here: the
 	  module will be called sun50i-cpufreq-nvmem.
 
+config ARM_AIROHA_SOC_CPUFREQ
+	tristate "Airoha EN7581 SoC CPUFreq support"
+	depends on ARM64 && (ARCH_AIROHA || COMPILE_TEST)
+	select PM
+	select PM_OPP
+	select PM_GENERIC_DOMAINS
+	default ARCH_AIROHA
+	help
+	  This adds the CPUFreq driver for Airoha EN7581 SoCs.
+
 config ARM_APPLE_SOC_CPUFREQ
 	tristate "Apple Silicon SoC CPUFreq support"
 	depends on ARCH_APPLE || (COMPILE_TEST && 64BIT)
drivers/cpufreq/Makefile +1 -0
index d35a28dd9463..890fff99f37d 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_X86_AMD_FREQ_SENSITIVITY)	+= amd_freq_sensitivity.o
 
 ##################################################################################
 # ARM SoC drivers
+obj-$(CONFIG_ARM_AIROHA_SOC_CPUFREQ)	+= airoha-cpufreq.o
 obj-$(CONFIG_ARM_APPLE_SOC_CPUFREQ)	+= apple-soc-cpufreq.o
 obj-$(CONFIG_ARM_ARMADA_37XX_CPUFREQ)	+= armada-37xx-cpufreq.o
 obj-$(CONFIG_ARM_ARMADA_8K_CPUFREQ)	+= armada-8k-cpufreq.o
drivers/cpufreq/airoha-cpufreq.c new file +166 -0

166 lines not on this page · raw message

drivers/cpufreq/cpufreq-dt-platdev.c +2 -0
index 9c198bd4f7e9..2aa00769cf09 100644
@@ -103,6 +103,8 @@ static const struct of_device_id allowlist[] __initconst = {
  * platforms using "operating-points-v2" property.
  */
 static const struct of_device_id blocklist[] __initconst = {
+	{ .compatible = "airoha,en7581", },
+
 	{ .compatible = "allwinner,sun50i-a100" },
 	{ .compatible = "allwinner,sun50i-h6", },
 	{ .compatible = "allwinner,sun50i-h616", },
Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH v8 2/2] cpufreq: airoha: Add EN7581 CPUFreq SMCCC driver

kernel test robot noticed the following build errors:

Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on rafael-pm/linux-next]
[also build test ERROR on rafael-pm/bleeding-edge linus/master v6.13-rc5 next-20241220] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/cpufreq-airoha-Add-EN7581-CPUFreq-SMCCC-driver/20250105-022153
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link:    https://lore.kernel.org/r/20250104181305.28185-2-ansuelsmth%40gmail.com
patch subject: [PATCH v8 2/2] cpufreq: airoha: Add EN7581 CPUFreq SMCCC driver
config: arm64-randconfig-001-20250105 (https://download.01.org/0day-ci/archive/20250105/[email protected]/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 096551537b2a747a3387726ca618ceeb3950e9bc)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250105/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/cpufreq/airoha-cpufreq.c:53:21: error: incompatible function pointer types assigning to 'config_clks_t' (aka 'int (*)(struct device *, struct opp_table *, struct dev_pm_opp *, void *, _Bool)') from 'int (struct device *, struct opp_table *, struct dev_pm_opp *, struct dev_pm_opp *, void *, bool)' (aka 'int (struct device *, struct opp_table *, struct dev_pm_opp *, struct dev_pm_opp *, void *, _Bool)') [-Wincompatible-function-pointer-types]
      53 |         config.config_clks = airoha_cpufreq_config_clks_nop;
         |                            ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/cpufreq/airoha-cpufreq.c:54:9: error: no member named 'genpd_names' in 'struct dev_pm_opp_config'
      54 |         config.genpd_names = airoha_cpufreq_genpd_names;
         |         ~~~~~~ ^
>> drivers/cpufreq/airoha-cpufreq.c:55:9: error: no member named 'virt_devs' in 'struct dev_pm_opp_config'
      55 |         config.virt_devs = &virt_devs;
         |         ~~~~~~ ^
   drivers/cpufreq/airoha-cpufreq.c:73:19: error: no member named 'genpd_names' in 'struct dev_pm_opp_config'
      73 |                                 name = config.genpd_names;
         |                                        ~~~~~~ ^
>> drivers/cpufreq/airoha-cpufreq.c:117:3: error: field designator 'remove_new' does not refer to any field in type 'struct platform_driver'
     117 |         .remove_new = airoha_cpufreq_remove,
         |         ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

5 errors generated.

vim +53 drivers/cpufreq/airoha-cpufreq.c

    32	
    33	static int airoha_cpufreq_probe(struct platform_device *pdev)
    34	{
    35		struct dev_pm_opp_config config = { };
    36		struct platform_device *cpufreq_dt;
    37		struct airoha_cpufreq_priv *priv;
    38		struct device *dev = &pdev->dev;
    39		struct device **virt_devs = NULL;
    40		struct device *cpu_dev;
    41		int ret;
    42	
    43		/* CPUs refer to the same OPP table */
    44		cpu_dev = get_cpu_device(0);
    45		if (!cpu_dev)
    46			return -ENODEV;
    47	
    48		priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
    49		if (!priv)
    50			return -ENOMEM;
    51	
    52		config.clk_names = airoha_cpufreq_clk_names;
  > 53		config.config_clks = airoha_cpufreq_config_clks_nop;
  > 54		config.genpd_names = airoha_cpufreq_genpd_names;
  > 55		config.virt_devs = &virt_devs;
    56	
    57		priv->opp_token = dev_pm_opp_set_config(cpu_dev, &config);
    58		if (priv->opp_token < 0)
    59			return dev_err_probe(dev, priv->opp_token, "Failed to set OPP config\n");
    60	
    61		/* Set Attached PM for OPP ACTIVE */
    62		if (virt_devs) {
    63			const char * const *name = airoha_cpufreq_genpd_names;
    64			int i, j;
    65	
    66			for (i = 0; *name; i++, name++) {
    67				ret = pm_runtime_resume_and_get(virt_devs[i]);
    68				if (ret) {
    69					dev_err(cpu_dev, "failed to resume %s: %d\n",
    70						*name, ret);
    71	
    72					/* Rollback previous PM runtime calls */
    73					name = config.genpd_names;
    74					for (j = 0; *name && j < i; j++, name++)
    75						pm_runtime_put(virt_devs[j]);
    76	
    77					goto err_register_cpufreq;
    78				}
    79			}
    80			priv->virt_devs = virt_devs;
    81		}
    82	
    83		cpufreq_dt = platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
    84		ret = PTR_ERR_OR_ZERO(cpufreq_dt);
    85		if (ret) {
    86			dev_err(dev, "failed to create cpufreq-dt device: %d\n", ret);
    87			goto err_register_cpufreq;
    88		}
    89	
    90		priv->cpufreq_dt = cpufreq_dt;
    91		platform_set_drvdata(pdev, priv);
    92	
    93		return 0;
    94	
    95	err_register_cpufreq:
    96		dev_pm_opp_clear_config(priv->opp_token);
    97	
    98		return ret;
    99	}
   100	
   101	static void airoha_cpufreq_remove(struct platform_device *pdev)
   102	{
   103		struct airoha_cpufreq_priv *priv = platform_get_drvdata(pdev);
   104		const char * const *name = airoha_cpufreq_genpd_names;
   105		int i;
   106	
   107		platform_device_unregister(priv->cpufreq_dt);
   108	
   109		dev_pm_opp_clear_config(priv->opp_token);
   110	
   111		for (i = 0; *name; i++, name++)
   112			pm_runtime_put(priv->virt_devs[i]);
   113	}
   114	
   115	static struct platform_driver airoha_cpufreq_driver = {
   116		.probe = airoha_cpufreq_probe,
 > 117		.remove_new = airoha_cpufreq_remove,

118 .driver = {
119 .name = "airoha-cpufreq",
120 },
121 };
122

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Christian Marangi
kernel test robot noticed the following build errors:

Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on rafael-pm/linux-next]
[also build test ERROR on rafael-pm/bleeding-edge linus/master v6.13-rc5 next-20241220] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/cpufreq-airoha-Add-EN7581-CPUFreq-SMCCC-driver/20250105-022153
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link:    https://lore.kernel.org/r/20250104181305.28185-1-ansuelsmth%40gmail.com
patch subject: [PATCH v8 1/2] pmdomain: airoha: Add Airoha CPU PM Domain support
config: arm-randconfig-004-20250105 (https://download.01.org/0day-ci/archive/20250105/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250105/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c:135:10: error: 'struct platform_driver' has no member named 'remove_new'; did you mean 'remove'?
     135 |         .remove_new = airoha_cpu_pmdomain_remove,
         |          ^~~~~~~~~~
         |          remove

vim +135 drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c

132
133 static struct platform_driver airoha_cpu_pmdomain_driver = {
134 .probe = airoha_cpu_pmdomain_probe,

 > 135		.remove_new = airoha_cpu_pmdomain_remove,

136 .driver = {
137 .name = "airoha-cpu-pmdomain",
138 .of_match_table = airoha_cpu_pmdomain_of_match,
139 },
140 };
141 module_platform_driver(airoha_cpu_pmdomain_driver);
142

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw
In reply to Christian Marangi
kernel test robot noticed the following build errors:

Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on rafael-pm/linux-next]
[also build test ERROR on rafael-pm/bleeding-edge linus/master v6.13-rc5 next-20241220] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/cpufreq-airoha-Add-EN7581-CPUFreq-SMCCC-driver/20250105-022153
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link:    https://lore.kernel.org/r/20250104181305.28185-1-ansuelsmth%40gmail.com
patch subject: [PATCH v8 1/2] pmdomain: airoha: Add Airoha CPU PM Domain support
config: arm64-randconfig-001-20250105 (https://download.01.org/0day-ci/archive/20250105/[email protected]/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 096551537b2a747a3387726ca618ceeb3950e9bc)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250105/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c:135:3: error: field designator 'remove_new' does not refer to any field in type 'struct platform_driver'
     135 |         .remove_new = airoha_cpu_pmdomain_remove,
         |         ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

vim +135 drivers/pmdomain/mediatek/airoha-cpu-pmdomain.c

132
133 static struct platform_driver airoha_cpu_pmdomain_driver = {
134 .probe = airoha_cpu_pmdomain_probe,

 > 135		.remove_new = airoha_cpu_pmdomain_remove,

136 .driver = {
137 .name = "airoha-cpu-pmdomain",
138 .of_match_table = airoha_cpu_pmdomain_of_match,
139 },
140 };
141 module_platform_driver(airoha_cpu_pmdomain_driver);
142

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki