Devicetree
 help / color / mirror / Atom feed
* [PATCH v4 0/3] Add Qualcomm SPEL powercap driver
@ 2026-12-06 11:56 Manaf Meethalavalappu Pallikunhi
  2026-12-06 11:56 ` [PATCH v4 1/3] dt-bindings: soc: qcom: Describe Qualcomm SPEL hardware Manaf Meethalavalappu Pallikunhi
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Manaf Meethalavalappu Pallikunhi @ 2026-12-06 11:56 UTC (permalink / raw)
  To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
	Daniel Lezcano
  Cc: linux-arm-msm, devicetree, linux-kernel, linux-pm,
	Manaf Meethalavalappu Pallikunhi

This patch series introduces support for Qualcomm's SPEL (SoC Power
and Electrical Limits) hardware, which provides power monitoring and
limiting capabilities for various power domains in Qualcomm SoCs.

The SPEL hardware enables:
- Real-time energy consumption monitoring across multiple power domains
- Hardware-enforced power limits with configurable time windows
- Support for up to 4 power limits (PL1-PL4) per domain
- Hierarchical power domain organization (SYS -> SOC -> subsystems)

The driver integrates with the Linux powercap framework, exposing SPEL
capabilities through standard sysfs interfaces. This allows userspace
applications and thermal management daemons to monitor energy consumption
and configure power limits for optimal power/performance balance.

This series is based on top of the powercap hierarchy patchset [1], which
is already part of linux-next.

[1] https://lore.kernel.org/all/cover.1793666444.git.daniel.lezcano@oss.qualcomm.com

Signed-off-by: Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>
---
Changes in v4:
- Reworked the driver onto that generic powercap hierarchy API.(Daniel)
- Single self-contained qcom,glymur-spel.yaml moved to Documentation/devicetree/bindings/soc/qcom/
  and dropped the separate power-limit-controller.yaml and the power/limits/ path.
- Moved the driver file under powercap/qcom path and added MAINTAINERS update.(Daniel)
- Added hibernation support: spel_domain_pm_freeze()/spel_domain_pm_restore() snapshot and
  replay per-domain power limits, time windows, and cumulative energy across a hibernation cycle.
- Fixed two use-after-free bugs: dangling released pointer in spel_create_zone()/spel_probe()
  after successful registration, plus a u64 overflow in spel_unit_xlate()'s unit conversion (Sashiko).
- Addressed v3 other review feedback from Daniel/Krzysztof/Konrad/Sashiko/Uwe.
- Preserved fractional unit precision.(Daniel)
- Updated glymur powercap hierarchy nodes and removed usb* nodes.
- Link to v3: https://lore.kernel.org/r/20260702-qcom_spel_driver_upstream-v3-0-434d50f0c5b0@oss.qualcomm.com

Changes in v3:
- Created common power-limit-controller schema under power/limits and described
  power-limit-controller device common capabilities.(Krzysztof)
- Created SoC-specific qcom,glymur-spel.yaml file instead of generic one and updated
  description and commit.(Krzysztof)
- Used FIELD_MODIFY() macro at different places.(Konrad)
- Updated glymur specific domain info table.(Konrad)
- Updated all for-loops iterator declaration to C99 style.(Konrad)
- Fixed use-after-free bugs.(Sashiko)
- Corrected time_unit documention to reflect the logic.(Sashiko)
- Link to v2: https://lore.kernel.org/r/20260620-qcom_spel_driver_upstream-v2-0-a3ee6837c18f@oss.qualcomm.com

Changes in v2:
- Fixed DT issues: corrected unit-address mismatch and made compatible
  platform-specific.(Konrad/Krzysztof)
- Cleaned up bitfield handling: switched to GENMASK, FIELD_* macros.(Konrad)
- Converted hex values to lowercase and simplified array definitions.(Konrad)
- used devm_platform_ioremap_resource_byname().(Konrad)
- Refactored data structures: merged domain data into spel_domain_info
  and removed hardcoded limits using ARRAY_SIZE().(Daniel)
- Added bounds checks (TIME_WINDOW_MAX) and fixed time window RMW
  handling (preserving reserved bits + firmware notify).(Sashiko)
- Resolved use-after-free, replaced allocation strategy, and
  added proper cleanup in .release().(Sashiko)
- Updated time window calculation logic.
- Removed cyclic dependency, improved validation logic, and aligned
  naming consistency.(Daniel)
- Link to v1: https://lore.kernel.org/r/20260519-qcom_spel_driver_upstream-v1-0-75356d1b7f94@oss.qualcomm.com

---
Manaf Meethalavalappu Pallikunhi (3):
      dt-bindings: soc: qcom: Describe Qualcomm SPEL hardware
      powercap: qcom: Add SPEL powercap driver
      arm64: dts: qcom: glymur: Enable SPEL powercap driver

 .../bindings/soc/qcom/qcom,glymur-spel.yaml        |  63 ++
 MAINTAINERS                                        |  13 +
 arch/arm64/boot/dts/qcom/glymur.dtsi               |  10 +
 drivers/powercap/Kconfig                           |   3 +
 drivers/powercap/Makefile                          |   1 +
 drivers/powercap/qcom/Kconfig                      |  13 +
 drivers/powercap/qcom/Makefile                     |   2 +
 drivers/powercap/qcom/spel.c                       | 949 +++++++++++++++++++++
 8 files changed, 1054 insertions(+)
---
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
change-id: 20261206-qcom_spel_driver_upstream-a5741cbe43ac

Best regards,
-- 
Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v4 1/3] dt-bindings: soc: qcom: Describe Qualcomm SPEL hardware
  2026-12-06 11:56 [PATCH v4 0/3] Add Qualcomm SPEL powercap driver Manaf Meethalavalappu Pallikunhi
@ 2026-12-06 11:56 ` Manaf Meethalavalappu Pallikunhi
  2026-12-06 11:56 ` [PATCH v4 2/3] powercap: qcom: Add SPEL powercap driver Manaf Meethalavalappu Pallikunhi
  2026-12-06 11:56 ` [PATCH v4 3/3] arm64: dts: qcom: glymur: Enable " Manaf Meethalavalappu Pallikunhi
  2 siblings, 0 replies; 6+ messages in thread
From: Manaf Meethalavalappu Pallikunhi @ 2026-12-06 11:56 UTC (permalink / raw)
  To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
	Daniel Lezcano
  Cc: linux-arm-msm, devicetree, linux-kernel, linux-pm,
	Manaf Meethalavalappu Pallikunhi

The Qualcomm SPEL (SoC Power and Electrical Limits) is a hardware block
that provides power monitoring and limiting capabilities for various
power domains in Qualcomm SoCs.

SPEL enforces power consumption limits to prevent thermal overload,
maintain system stability, and comply with platform power budgets.
It provides:
- Hardware-enforced power capping with configurable power limits
- Time window controls for power averaging
- Energy counter monitoring for each power domain
- Automatic throttling when power limits are exceeded

The hardware supports multiple power domains including system (SYS), SoC,
CPU clusters, GPU, memory, and peripheral subsystems. Each domain can have
independent power limits and monitoring.

Add a DeviceTree binding to describe the SPEL block on Qualcomm's SoC.

Signed-off-by: Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>
---
 .../bindings/soc/qcom/qcom,glymur-spel.yaml        | 63 ++++++++++++++++++++++
 MAINTAINERS                                        |  6 +++
 2 files changed, 69 insertions(+)

diff --git a/Documentation/devicetree/bindings/soc/qcom/qcom,glymur-spel.yaml b/Documentation/devicetree/bindings/soc/qcom/qcom,glymur-spel.yaml
new file mode 100644
index 000000000000..ebc77b47b01e
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/qcom/qcom,glymur-spel.yaml
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/qcom/qcom,glymur-spel.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Glymur SoC Power and Electrical Limits (SPEL)
+
+maintainers:
+  - Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>
+
+description: |
+  The Qualcomm SPEL (SoC Power and Electrical Limits) is a hardware block that
+  provides power monitoring and limiting capabilities for various power domains
+  in Qualcomm SoCs.
+
+  SPEL enforces power consumption limits to prevent thermal overload, maintain
+  system stability, and comply with platform power budgets. It provides
+    - Hardware-enforced power capping with configurable power limits
+    - Time window controls for power averaging
+    - Energy counter monitoring for each power domain
+    - Automatic throttling when power limits are exceeded
+
+  The hardware supports multiple power domains including system (SYS), SoC,
+  CPU clusters, GPU, memory, and peripheral subsystems. Each domain can have
+  independent power limits and monitoring.
+
+properties:
+  compatible:
+    const: qcom,glymur-spel
+
+  reg:
+    maxItems: 3
+
+  reg-names:
+    items:
+      - const: config
+      - const: constraints
+      - const: nodes
+
+required:
+  - compatible
+  - reg
+  - reg-names
+
+additionalProperties: false
+
+examples:
+  - |
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        power-limits@ef3b000 {
+            compatible = "qcom,glymur-spel";
+            reg = <0x0 0x0ef3b000 0x0 0x1000>,
+                  <0x0 0x0ef3d000 0x0 0x1000>,
+                  <0x0 0x0ef3e000 0x0 0x1000>;
+            reg-names = "config",
+                        "constraints",
+                        "nodes";
+        };
+    };
diff --git a/MAINTAINERS b/MAINTAINERS
index bb36b126e531..d256df53948d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23534,6 +23534,12 @@ F:	Documentation/networking/device_drivers/cellular/qualcomm/rmnet.rst
 F:	drivers/net/ethernet/qualcomm/rmnet/
 F:	include/linux/if_rmnet.h
 
+QUALCOMM SPEL POWERCAP DRIVER
+M:	Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>
+L:	linux-arm-msm@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/soc/qcom/qcom,glymur-spel.yaml
+
 QUALCOMM SPMI CONTROLLER (PMIC ARBITER) DRIVER
 M:	Abel Vesa <abelvesa@kernel.org>
 M:	David Collins <david.collins@oss.qualcomm.com>

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 2/3] powercap: qcom: Add SPEL powercap driver
  2026-12-06 11:56 [PATCH v4 0/3] Add Qualcomm SPEL powercap driver Manaf Meethalavalappu Pallikunhi
  2026-12-06 11:56 ` [PATCH v4 1/3] dt-bindings: soc: qcom: Describe Qualcomm SPEL hardware Manaf Meethalavalappu Pallikunhi
@ 2026-12-06 11:56 ` Manaf Meethalavalappu Pallikunhi
  2026-12-06 12:13   ` sashiko-bot
  2026-12-06 11:56 ` [PATCH v4 3/3] arm64: dts: qcom: glymur: Enable " Manaf Meethalavalappu Pallikunhi
  2 siblings, 1 reply; 6+ messages in thread
From: Manaf Meethalavalappu Pallikunhi @ 2026-12-06 11:56 UTC (permalink / raw)
  To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
	Daniel Lezcano
  Cc: linux-arm-msm, devicetree, linux-kernel, linux-pm,
	Manaf Meethalavalappu Pallikunhi

The Qualcomm SoC Power and Electrical Limits (SPEL) provides hardware
based power monitoring and limiting capabilities for various power
domains including System, SoC, CPU clusters, GPU, and various other
subsystems.

The driver integrates with the Linux powercap framework, exposing SPEL
capabilities through powercap sysfs interfaces.

Signed-off-by: Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>
---
 MAINTAINERS                    |   7 +
 drivers/powercap/Kconfig       |   3 +
 drivers/powercap/Makefile      |   1 +
 drivers/powercap/qcom/Kconfig  |  13 +
 drivers/powercap/qcom/Makefile |   2 +
 drivers/powercap/qcom/spel.c   | 949 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 975 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index d256df53948d..c4b700f0fb07 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23525,6 +23525,12 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git
 F:	Documentation/devicetree/bindings/pinctrl/qcom,*.yaml
 F:	drivers/pinctrl/qcom/
 
+QUALCOMM POWERCAP DRIVERS
+M:	Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
+L:	linux-arm-msm@vger.kernel.org
+S:	Maintained
+F:	drivers/powercap/qcom/
+
 QUALCOMM RMNET DRIVER
 M:	Subash Abhinov Kasiviswanathan <subash.a.kasiviswanathan@oss.qualcomm.com>
 M:	Sean Tranchetti <sean.tranchetti@oss.qualcomm.com>
@@ -23539,6 +23545,7 @@ M:	Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>
 L:	linux-arm-msm@vger.kernel.org
 S:	Maintained
 F:	Documentation/devicetree/bindings/soc/qcom/qcom,glymur-spel.yaml
+F:	drivers/powercap/qcom/spel.c
 
 QUALCOMM SPMI CONTROLLER (PMIC ARBITER) DRIVER
 M:	Abel Vesa <abelvesa@kernel.org>
diff --git a/drivers/powercap/Kconfig b/drivers/powercap/Kconfig
index 03c4c796d993..94b86b64146c 100644
--- a/drivers/powercap/Kconfig
+++ b/drivers/powercap/Kconfig
@@ -93,4 +93,7 @@ config DTPM_DEVFREQ
 	help
 	  This enables support for device power limitation based on
 	  energy model.
+
+source "drivers/powercap/qcom/Kconfig"
+
 endif
diff --git a/drivers/powercap/Makefile b/drivers/powercap/Makefile
index 5ab0dce565b9..48460c568427 100644
--- a/drivers/powercap/Makefile
+++ b/drivers/powercap/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_INTEL_RAPL) += intel_rapl_msr.o
 obj-$(CONFIG_INTEL_RAPL_TPMI) += intel_rapl_tpmi.o
 obj-$(CONFIG_IDLE_INJECT) += idle_inject.o
 obj-$(CONFIG_ARM_SCMI_POWERCAP) += arm_scmi_powercap.o
+obj-$(CONFIG_QCOM_SPEL) += qcom/
diff --git a/drivers/powercap/qcom/Kconfig b/drivers/powercap/qcom/Kconfig
new file mode 100644
index 000000000000..a870ac606b4d
--- /dev/null
+++ b/drivers/powercap/qcom/Kconfig
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config QCOM_SPEL
+	tristate "Qualcomm SPEL Powercap driver"
+	depends on ARCH_QCOM || COMPILE_TEST
+	help
+	  This enables support for the Qualcomm SoC Power and Electrical
+	  Limits (SPEL) hardware, which allows power limits to be
+	  enforced and monitored on Qualcomm SoCs.
+
+	  SPEL provides energy monitoring and power capping for multiple
+	  domains including system, SoC, CPU clusters, GPU, and various
+	  other subsystems.
diff --git a/drivers/powercap/qcom/Makefile b/drivers/powercap/qcom/Makefile
new file mode 100644
index 000000000000..496dcf6ae051
--- /dev/null
+++ b/drivers/powercap/qcom/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_QCOM_SPEL) += spel.o
diff --git a/drivers/powercap/qcom/spel.c b/drivers/powercap/qcom/spel.c
new file mode 100644
index 000000000000..56cf98bc5466
--- /dev/null
+++ b/drivers/powercap/qcom/spel.c
@@ -0,0 +1,949 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Qualcomm SPEL (SoC Power and Electrical Limits) Driver
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/device-id/of.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/overflow.h>
+#include <linux/platform_device.h>
+#include <linux/pm.h>
+#include <linux/powercap.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <linux/units.h>
+
+/* SPEL register bitmasks */
+#define ENERGY_STATUS_MASK		GENMASK(31, 0)
+
+#define POWER_LIMIT_MASK		GENMASK(14, 0)
+#define POWER_LIMIT_ENABLE		BIT(31)
+
+#define TIME_WINDOW_MASK_L		GENMASK(14, 0)
+#define TIME_WINDOW_MASK_H		GENMASK(22, 16)
+#define TIME_WINDOW_MAX			((FIELD_MAX(TIME_WINDOW_MASK_H) << 15) | \
+					 FIELD_MAX(TIME_WINDOW_MASK_L))
+
+#define ENERGY_UNIT_MASK		GENMASK(19, 16)
+#define TIME_UNIT_MASK			GENMASK(11, 8)
+#define POWER_UNIT_MASK			GENMASK(2, 0)
+
+#define LIMITS_CAPABILITY_OFFSET	0x20
+#define ENERGY_RPT_UNIT_OFFSET		0x04
+
+/* Domain types */
+enum spel_domain_type {
+	SPEL_DOMAIN_SYS,
+	SPEL_DOMAIN_SOC,
+	SPEL_DOMAIN_CL0,
+	SPEL_DOMAIN_CL1,
+	SPEL_DOMAIN_CL2,
+	SPEL_DOMAIN_IGPU,
+	SPEL_DOMAIN_DGPU,
+	SPEL_DOMAIN_NSP,
+	SPEL_DOMAIN_MMCX,
+	SPEL_DOMAIN_INFRA,
+	SPEL_DOMAIN_DRAM,
+	SPEL_DOMAIN_MDM,
+	SPEL_DOMAIN_WLAN,
+	SPEL_DOMAIN_MAX,
+};
+
+/* Power limit IDs */
+enum spel_power_limit_id {
+	POWER_LIMIT1,
+	POWER_LIMIT2,
+	POWER_LIMIT3,
+	POWER_LIMIT4,
+	POWER_LIMITS_MAX,
+};
+
+/* Unit types for conversion */
+enum unit_type {
+	POWER_UNIT,
+	ENERGY_UNIT,
+	TIME_UNIT,
+};
+
+/* Power limit operation types */
+enum pl_ops_type {
+	PL_LIMIT,
+	PL_TIME_WINDOW,
+};
+
+/**
+ * struct spel_domain_data - Domain-specific data for hierarchy nodes
+ * @reg_offset:		Register offset for energy counter
+ * @id:			Domain type ID
+ */
+struct spel_domain_data {
+	u32 reg_offset;
+	enum spel_domain_type id;
+};
+
+/**
+ * struct spel_constraint_info - Power limit constraint information
+ * @limit_offset:	Register offset for power limit value
+ * @time_window_offset:	Register offset for time window
+ * @supported_mask:	Bit mask in capability register
+ * @domain_id:		Domain this constraint applies to
+ * @pl_id:		Power limit ID (PL1, PL2, etc.)
+ */
+struct spel_constraint_info {
+	u32 limit_offset;
+	u32 time_window_offset;
+	u32 supported_mask;
+	enum spel_domain_type domain_id;
+	int pl_id;
+};
+
+/**
+ * struct spel_domain - SPEL power domain
+ * @power_zone:		Powercap zone
+ * @sp:			Pointer to parent spel_system
+ * @lock:		Mutex protecting register access
+ * @status_reg:		Energy counter register
+ * @id:			Domain type ID
+ * @limits:		Bitmask of power limit IDs supported by this domain
+ * @cached_power_limit: Per-PL limit and enable fields, snapshotted by
+ *			spel_domain_pm_freeze() across a hibernation cycle
+ *			and replayed by spel_domain_pm_restore().
+ * @cached_time_window: Per-PL time window fields, snapshotted and replayed
+ *			the same way as @cached_power_limit.
+ * @cumulative_energy_uj: Energy consumed up to the start of the hardware
+ *			counter's current epoch, i.e. before the live
+ *			readl(status_reg) value is added on top. Updated by
+ *			spel_domain_pm_restore() so that the counter reported
+ *			to userspace keeps increasing across a hibernation
+ *			cycle instead of dropping back to 0.
+ * @energy_snapshot_uj: Pre-freeze energy reading staged by
+ *			spel_domain_pm_freeze(); folded into
+ *			@cumulative_energy_uj only by spel_domain_pm_restore(),
+ *			so an aborted hibernation (thaw instead of restore)
+ *			never double-counts it.
+ * @last_raw:		Last raw @status_reg value observed by
+ *			spel_get_energy_counter(), used to detect when the
+ *			32-bit hardware counter has wrapped since the
+ *			previous read. Reset to 0 by spel_domain_pm_restore()
+ *			since the register itself restarts from 0 on power-on.
+ */
+struct spel_domain {
+	struct powercap_zone power_zone;
+	struct spel_system *sp;
+	struct mutex lock; /* Protects register read/write operations */
+	void __iomem *status_reg;
+	enum spel_domain_type id;
+	int limits;
+	u32 cached_power_limit[POWER_LIMITS_MAX];
+	u32 cached_time_window[POWER_LIMITS_MAX];
+	u64 cumulative_energy_uj;
+	u64 energy_snapshot_uj;
+	u32 last_raw;
+};
+
+/**
+ * struct spel_system - SPEL system
+ * @control_type:	Embedded powercap control type
+ * @hierarchy:		Powercap hierarchy
+ * @node_base:		Base address for node registers
+ * @constraint_base:	Base address for constraint registers
+ * @config_base:	Base address for config registers
+ * @dev:		Device pointer for logging
+ * @pl_capabilities:	Power limit capability bits, read once at init
+ * @power_unit_shift:	Power unit exponent (base unit: one watt)
+ * @energy_unit_shift:	Energy unit exponent (base unit: one joule)
+ * @time_unit_shift:	Time unit exponent (base unit: one millisecond)
+ */
+struct spel_system {
+	struct powercap_control_type control_type;
+	struct powercap_hierarchy *hierarchy;
+	void __iomem *node_base;
+	void __iomem *constraint_base;
+	void __iomem *config_base;
+	struct device *dev;
+	u32 pl_capabilities;
+	unsigned int power_unit_shift;
+	unsigned int energy_unit_shift;
+	unsigned int time_unit_shift;
+};
+
+#define power_zone_to_spel_domain(_zone) \
+	container_of(_zone, struct spel_domain, power_zone)
+
+#define spel_domain_to_system(sd) ((sd)->sp)
+
+#define control_type_to_spel_system(_pct) \
+	container_of((_pct), struct spel_system, control_type)
+
+/* Power limit names */
+static const char * const pl_names[] = {
+	[POWER_LIMIT1] = "pl1",
+	[POWER_LIMIT2] = "pl2",
+	[POWER_LIMIT3] = "pl3",
+	[POWER_LIMIT4] = "pl4",
+};
+
+/* Constraint configuration */
+static const struct spel_constraint_info constraints[] = {
+	/* SYS domain constraints */
+	{ 0x10, 0x70, BIT(0), SPEL_DOMAIN_SYS, POWER_LIMIT1 },
+	{ 0x14, 0x74, BIT(1), SPEL_DOMAIN_SYS, POWER_LIMIT2 },
+	{ 0x18, 0x78, BIT(2), SPEL_DOMAIN_SYS, POWER_LIMIT3 },
+	{ 0x1c, 0x7c, BIT(3), SPEL_DOMAIN_SYS, POWER_LIMIT4 },
+	/* SoC domain constraints */
+	{ 0x00, 0x60, BIT(4), SPEL_DOMAIN_SOC, POWER_LIMIT1 },
+	{ 0x04, 0x64, BIT(5), SPEL_DOMAIN_SOC, POWER_LIMIT2 },
+	{ 0x08, 0x68, BIT(6), SPEL_DOMAIN_SOC, POWER_LIMIT3 },
+	{ 0x0c, 0x6c, BIT(7), SPEL_DOMAIN_SOC, POWER_LIMIT4 },
+};
+
+/* Glymur SPEL hierarchy node definitions */
+static struct powercap_node glymur_spel_hierarchy_nodes[] = {
+	[0] = {
+		.name = "sys",
+		.parent = NULL,
+		.data = &(struct spel_domain_data) { .reg_offset = 0x40, .id = SPEL_DOMAIN_SYS },
+	},
+	[1] = {
+		.name = "soc",
+		.parent = &glymur_spel_hierarchy_nodes[0],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x00, .id = SPEL_DOMAIN_SOC },
+	},
+	[2] = {
+		.name = "cl0",
+		.parent = &glymur_spel_hierarchy_nodes[1],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x5c, .id = SPEL_DOMAIN_CL0 },
+	},
+	[3] = {
+		.name = "cl1",
+		.parent = &glymur_spel_hierarchy_nodes[1],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x60, .id = SPEL_DOMAIN_CL1 },
+	},
+	[4] = {
+		.name = "cl2",
+		.parent = &glymur_spel_hierarchy_nodes[1],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x64, .id = SPEL_DOMAIN_CL2 },
+	},
+	[5] = {
+		.name = "igpu",
+		.parent = &glymur_spel_hierarchy_nodes[1],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x08, .id = SPEL_DOMAIN_IGPU },
+	},
+	[6] = {
+		.name = "nsp",
+		.parent = &glymur_spel_hierarchy_nodes[1],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x0c, .id = SPEL_DOMAIN_NSP },
+	},
+	[7] = {
+		.name = "infra",
+		.parent = &glymur_spel_hierarchy_nodes[1],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x18, .id = SPEL_DOMAIN_INFRA },
+	},
+	[8] = {
+		.name = "mmcx",
+		.parent = &glymur_spel_hierarchy_nodes[7],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x10, .id = SPEL_DOMAIN_MMCX },
+	},
+	[9] = {
+		.name = "dram",
+		.parent = &glymur_spel_hierarchy_nodes[7],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x1c, .id = SPEL_DOMAIN_DRAM },
+	},
+	[10] = {
+		.name = "wlan",
+		.parent = &glymur_spel_hierarchy_nodes[0],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x4c, .id = SPEL_DOMAIN_WLAN },
+	},
+	[11] = {
+		.name = "mdm",
+		.parent = &glymur_spel_hierarchy_nodes[0],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x48, .id = SPEL_DOMAIN_MDM },
+	},
+	[12] = {
+		.name = "dgpu",
+		.parent = &glymur_spel_hierarchy_nodes[0],
+		.data = &(struct spel_domain_data) { .reg_offset = 0x44, .id = SPEL_DOMAIN_DGPU },
+	},
+};
+
+static struct powercap_hierarchy glymur_spel_hierarchy_template = {
+	.nodes = glymur_spel_hierarchy_nodes,
+	.nr_nodes = ARRAY_SIZE(glymur_spel_hierarchy_nodes),
+};
+
+static bool is_pl_valid(struct spel_domain *sd, int pl)
+{
+	return !!(sd->limits & BIT(pl));
+}
+
+static int get_pl_ops_offset(struct spel_domain *sd, int pl, enum pl_ops_type pl_op)
+{
+	for (int i = 0; i < ARRAY_SIZE(constraints); i++) {
+		const struct spel_constraint_info *ci = &constraints[i];
+
+		if (ci->domain_id == sd->id && ci->pl_id == pl) {
+			switch (pl_op) {
+			case PL_LIMIT:
+				return ci->limit_offset;
+			case PL_TIME_WINDOW:
+				return ci->time_window_offset;
+			default:
+				return -EOPNOTSUPP;
+			}
+		}
+	}
+
+	return -EOPNOTSUPP;
+}
+
+static u64 spel_unit_xlate(struct spel_domain *sd, enum unit_type type,
+			   u64 value, int to_raw)
+{
+	struct spel_system *sp = spel_domain_to_system(sd);
+	u32 shift, scale;
+
+	switch (type) {
+	case POWER_UNIT:
+		shift = sp->power_unit_shift;
+		scale = MEGA;
+		break;
+	case ENERGY_UNIT:
+		shift = sp->energy_unit_shift;
+		scale = MEGA;
+		break;
+	case TIME_UNIT:
+		shift = sp->time_unit_shift;
+		scale = MILLI;
+		break;
+	default:
+		return value;
+	}
+
+	if (to_raw) {
+		u64 numerator;
+
+		/*
+		 * value is an unclamped u64 from sysfs. Reject inputs that would
+		 * overflow the multiply, or the (numerator + scale / 2) rounding
+		 * add inside DIV_ROUND_CLOSEST_ULL(), instead of silently wrapping.
+		 */
+		if (check_mul_overflow(value, BIT_ULL(shift), &numerator) ||
+		    numerator > U64_MAX - scale / 2)
+			return U64_MAX;
+
+		return DIV_ROUND_CLOSEST_ULL(numerator, scale);
+	}
+
+	/* Hardware values are at most 32 bits, so the product fits in u64. */
+	return (value * scale) >> shift;
+}
+
+static int spel_read_pl_data(struct spel_domain *sd, int pl,
+			     enum pl_ops_type pl_op, bool xlate, u64 *data)
+{
+	struct spel_system *sp = spel_domain_to_system(sd);
+	void __iomem *reg_addr;
+	u64 value;
+	int offset;
+
+	if (!is_pl_valid(sd, pl))
+		return -EINVAL;
+
+	offset = get_pl_ops_offset(sd, pl, pl_op);
+	if (offset < 0)
+		return offset;
+
+	guard(mutex)(&sd->lock);
+
+	reg_addr = sp->constraint_base + offset;
+	value = readl(reg_addr);
+
+	switch (pl_op) {
+	case PL_LIMIT:
+		value = FIELD_GET(POWER_LIMIT_MASK, value);
+		if (xlate)
+			*data = spel_unit_xlate(sd, POWER_UNIT, value, 0);
+		else
+			*data = value;
+		break;
+	case PL_TIME_WINDOW:
+		/* Decode time window: bits [22:16] are upper 7 bits, [14:0] are lower 15 bits */
+		value = (FIELD_GET(TIME_WINDOW_MASK_H, value) << 15) |
+			FIELD_GET(TIME_WINDOW_MASK_L, value);
+		if (xlate)
+			*data = spel_unit_xlate(sd, TIME_UNIT, value, 0);
+		else
+			*data = value;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int spel_write_pl_data(struct spel_domain *sd, int pl,
+			      enum pl_ops_type pl_op, unsigned long long value)
+{
+	struct spel_system *sp = spel_domain_to_system(sd);
+	void __iomem *reg_addr;
+	u64 reg_val, new_val;
+	int offset;
+
+	if (!is_pl_valid(sd, pl))
+		return -EINVAL;
+
+	offset = get_pl_ops_offset(sd, pl, pl_op);
+	if (offset < 0)
+		return offset;
+
+	guard(mutex)(&sd->lock);
+
+	reg_addr = sp->constraint_base + offset;
+	reg_val = readl(reg_addr);
+
+	switch (pl_op) {
+	case PL_LIMIT:
+		new_val = spel_unit_xlate(sd, POWER_UNIT, value, 1);
+		if (new_val > FIELD_MAX(POWER_LIMIT_MASK))
+			return -EINVAL;
+
+		FIELD_MODIFY(POWER_LIMIT_MASK, &reg_val, new_val);
+
+		/*
+		 * Enable/Disable PL based on the value:
+		 * - If value is 0, disable the PL (clear enable bit)
+		 * - If value is non-zero, enable the PL (set enable bit)
+		 */
+		FIELD_MODIFY(POWER_LIMIT_ENABLE, &reg_val, !!new_val);
+
+		writel(reg_val, reg_addr);
+		return 0;
+
+	case PL_TIME_WINDOW:
+		/*
+		 * Encode time window: upper 7 bits to [22:16], lower 15 bits to [14:0]
+		 */
+		new_val = spel_unit_xlate(sd, TIME_UNIT, value, 1);
+		if (new_val > TIME_WINDOW_MAX)
+			return -EINVAL;
+
+		/* Read-modify-write to preserve other bits */
+		FIELD_MODIFY(TIME_WINDOW_MASK_H, &reg_val, new_val >> 15);
+		FIELD_MODIFY(TIME_WINDOW_MASK_L, &reg_val, new_val & FIELD_MAX(TIME_WINDOW_MASK_L));
+		writel(reg_val, reg_addr);
+
+		/*
+		 * Time window register update doesn't trigger firmware interrupt.
+		 * Write to the PL register with current value to trigger the interrupt.
+		 */
+		offset = get_pl_ops_offset(sd, pl, PL_LIMIT);
+		if (offset >= 0) {
+			reg_addr = sp->constraint_base + offset;
+			reg_val = readl(reg_addr);
+			writel(reg_val, reg_addr);
+		}
+		return 0;
+
+	default:
+		return -EINVAL;
+	}
+}
+
+/*
+ * Must be called with sd->lock held. Folds a full hardware range into
+ * @cumulative_energy_uj if the counter has wrapped since @last_raw was last
+ * updated, then refreshes @last_raw to the current register value.
+ */
+static void spel_domain_sync_energy(struct spel_domain *sd)
+{
+	u32 value = readl(sd->status_reg);
+
+	/* The 32-bit counter wrapped since the last read; fold a full range in. */
+	if (value < sd->last_raw)
+		sd->cumulative_energy_uj +=
+			spel_unit_xlate(sd, ENERGY_UNIT, ENERGY_STATUS_MASK + 1ULL, 0);
+
+	sd->last_raw = value;
+}
+
+static int spel_get_energy_counter(struct powercap_zone *power_zone, u64 *energy_raw)
+{
+	struct spel_domain *sd = power_zone_to_spel_domain(power_zone);
+
+	guard(mutex)(&sd->lock);
+
+	spel_domain_sync_energy(sd);
+
+	*energy_raw = sd->cumulative_energy_uj +
+		      spel_unit_xlate(sd, ENERGY_UNIT, sd->last_raw, 0);
+
+	return 0;
+}
+
+static int spel_get_max_energy_counter(struct powercap_zone *pcd_dev, u64 *energy)
+{
+	/*
+	 * energy_raw is a software accumulator that never wraps at the
+	 * hardware's 32-bit range; report the true u64 range instead of the
+	 * hardware wrap boundary.
+	 */
+	*energy = U64_MAX;
+
+	return 0;
+}
+
+static int spel_release_zone(struct powercap_zone *power_zone)
+{
+	struct spel_domain *sd = power_zone_to_spel_domain(power_zone);
+
+	/* Destroy mutex and free domain */
+	mutex_destroy(&sd->lock);
+	kfree(sd);
+
+	return 0;
+}
+
+static void spel_domain_pm_freeze(struct spel_domain *sd)
+{
+	struct spel_system *sp = spel_domain_to_system(sd);
+
+	guard(mutex)(&sd->lock);
+
+	for (int i = 0; i < ARRAY_SIZE(constraints); i++) {
+		const struct spel_constraint_info *ci = &constraints[i];
+
+		if (ci->domain_id != sd->id || !is_pl_valid(sd, ci->pl_id))
+			continue;
+
+		sd->cached_power_limit[ci->pl_id] =
+			readl(sp->constraint_base + ci->limit_offset) &
+			(POWER_LIMIT_MASK | POWER_LIMIT_ENABLE);
+		sd->cached_time_window[ci->pl_id] =
+			readl(sp->constraint_base + ci->time_window_offset) &
+			(TIME_WINDOW_MASK_H | TIME_WINDOW_MASK_L);
+	}
+
+	spel_domain_sync_energy(sd);
+	sd->energy_snapshot_uj = spel_unit_xlate(sd, ENERGY_UNIT, sd->last_raw, 0);
+}
+
+static void spel_domain_pm_restore(struct spel_domain *sd)
+{
+	struct spel_system *sp = spel_domain_to_system(sd);
+
+	guard(mutex)(&sd->lock);
+
+	for (int i = 0; i < ARRAY_SIZE(constraints); i++) {
+		const struct spel_constraint_info *ci = &constraints[i];
+		void __iomem *reg;
+		u32 value;
+
+		if (ci->domain_id != sd->id || !is_pl_valid(sd, ci->pl_id))
+			continue;
+
+		reg = sp->constraint_base + ci->time_window_offset;
+		value = readl(reg) & ~(TIME_WINDOW_MASK_H | TIME_WINDOW_MASK_L);
+		writel(value | sd->cached_time_window[ci->pl_id], reg);
+
+		/* Write the limit last to notify firmware of both updates. */
+		reg = sp->constraint_base + ci->limit_offset;
+		value = readl(reg) & ~(POWER_LIMIT_MASK | POWER_LIMIT_ENABLE);
+		writel(value | sd->cached_power_limit[ci->pl_id], reg);
+	}
+
+	sd->cumulative_energy_uj += sd->energy_snapshot_uj;
+	sd->last_raw = 0;
+}
+
+static int spel_find_nr_power_limit(struct spel_domain *sd)
+{
+	int nr_pl = 0;
+
+	for (int i = 0; i < ARRAY_SIZE(pl_names); i++) {
+		if (is_pl_valid(sd, i))
+			nr_pl++;
+	}
+
+	return nr_pl;
+}
+
+static const struct powercap_zone_ops zone_ops = {
+	.get_energy_uj = spel_get_energy_counter,
+	.get_max_energy_range_uj = spel_get_max_energy_counter,
+	.release = spel_release_zone,
+};
+
+static int spel_constraint_to_pl(struct spel_domain *sd, int cid)
+{
+	int id = 0;
+
+	for (int i = 0; i < ARRAY_SIZE(pl_names); i++) {
+		if (is_pl_valid(sd, i) && id++ == cid)
+			return i;
+	}
+
+	return -EINVAL;
+}
+
+static int spel_set_power_limit(struct powercap_zone *power_zone, int cid,
+				u64 power_limit)
+{
+	struct spel_domain *sd = power_zone_to_spel_domain(power_zone);
+	int id;
+
+	id = spel_constraint_to_pl(sd, cid);
+	if (id < 0)
+		return id;
+
+	return spel_write_pl_data(sd, id, PL_LIMIT, power_limit);
+}
+
+static int spel_get_power_limit(struct powercap_zone *power_zone, int cid,
+				u64 *data)
+{
+	struct spel_domain *sd = power_zone_to_spel_domain(power_zone);
+	u64 val;
+	int ret, id;
+
+	id = spel_constraint_to_pl(sd, cid);
+	if (id < 0)
+		return id;
+
+	ret = spel_read_pl_data(sd, id, PL_LIMIT, true, &val);
+	if (!ret)
+		*data = val;
+
+	return ret;
+}
+
+static int spel_set_time_window(struct powercap_zone *power_zone, int cid,
+				u64 window)
+{
+	struct spel_domain *sd = power_zone_to_spel_domain(power_zone);
+	int id;
+
+	id = spel_constraint_to_pl(sd, cid);
+	if (id < 0)
+		return id;
+
+	return spel_write_pl_data(sd, id, PL_TIME_WINDOW, window);
+}
+
+static int spel_get_time_window(struct powercap_zone *power_zone, int cid,
+				u64 *data)
+{
+	struct spel_domain *sd = power_zone_to_spel_domain(power_zone);
+	u64 val;
+	int ret, id;
+
+	id = spel_constraint_to_pl(sd, cid);
+	if (id < 0)
+		return id;
+
+	ret = spel_read_pl_data(sd, id, PL_TIME_WINDOW, true, &val);
+	if (!ret)
+		*data = val;
+
+	return ret;
+}
+
+static const char *spel_get_constraint_name(struct powercap_zone *power_zone,
+					    int cid)
+{
+	struct spel_domain *sd = power_zone_to_spel_domain(power_zone);
+	int id;
+
+	id = spel_constraint_to_pl(sd, cid);
+	if (id >= 0 && id < ARRAY_SIZE(pl_names))
+		return pl_names[id];
+
+	return NULL;
+}
+
+static const struct powercap_zone_constraint_ops constraint_ops = {
+	.set_power_limit_uw = spel_set_power_limit,
+	.get_power_limit_uw = spel_get_power_limit,
+	.set_time_window_us = spel_set_time_window,
+	.get_time_window_us = spel_get_time_window,
+	.get_name = spel_get_constraint_name,
+};
+
+static int spel_update_unit(struct spel_system *sp)
+{
+	u32 value;
+
+	/* Read power_unit and time_unit from offset 0x0 */
+	value = readl(sp->config_base);
+
+	/* Keep exponents to avoid truncating fractional units. */
+	sp->power_unit_shift = FIELD_GET(POWER_UNIT_MASK, value);
+	sp->time_unit_shift = FIELD_GET(TIME_UNIT_MASK, value);
+
+	/* Read energy_unit from ENERGY_RPT_UNIT_OFFSET */
+	value = readl(sp->config_base + ENERGY_RPT_UNIT_OFFSET);
+
+	sp->energy_unit_shift = FIELD_GET(ENERGY_UNIT_MASK, value);
+
+	dev_dbg(sp->dev, "Unit shifts: energy=%u, time=%u, power=%u\n",
+		sp->energy_unit_shift, sp->time_unit_shift, sp->power_unit_shift);
+
+	return 0;
+}
+
+static int spel_get_domain_limits(struct spel_system *sp, enum spel_domain_type domain_id)
+{
+	/* Enable minimum one constraint, detect the rest from hardware capabilities. */
+	int limits = BIT(POWER_LIMIT1);
+
+	for (int i = 0; i < ARRAY_SIZE(constraints); i++) {
+		const struct spel_constraint_info *ci = &constraints[i];
+
+		if (ci->domain_id == domain_id && sp->pl_capabilities & ci->supported_mask)
+			limits |= BIT(ci->pl_id);
+	}
+
+	return limits;
+}
+
+static int spel_control_type_release(struct powercap_control_type *pct)
+{
+	struct spel_system *sp = control_type_to_spel_system(pct);
+
+	/* Free system structure */
+	kfree(sp);
+
+	return 0;
+}
+
+static const struct powercap_control_type_ops spel_control_type_ops = {
+	.release = spel_control_type_release,
+};
+
+static int spel_init_system(struct spel_system *sp, struct device *dev)
+{
+	int ret;
+
+	/* Read unit configuration (common for all domains) */
+	ret = spel_update_unit(sp);
+	if (ret)
+		return ret;
+
+	/* Cache power limit capability bits; per-domain limits are derived in spel_create_zone() */
+	sp->pl_capabilities = readl(sp->config_base + LIMITS_CAPABILITY_OFFSET);
+
+	return 0;
+}
+
+static struct powercap_zone *spel_create_zone(struct powercap_control_type *pct,
+					      const char *name, void *data,
+					      struct powercap_zone *parent)
+{
+	struct spel_system *sp = control_type_to_spel_system(pct);
+	struct spel_domain_data *dd = data;
+	struct spel_domain *sd;
+	struct powercap_zone *pcz;
+	int nr_pl;
+
+	/* Allocate domain */
+	sd = kzalloc_obj(*sd, GFP_KERNEL);
+	if (!sd)
+		return ERR_PTR(-ENOMEM);
+
+	/* Initialize domain */
+	sd->sp = sp;
+	sd->id = dd->id;
+	sd->status_reg = sp->node_base + dd->reg_offset;
+	sd->limits = spel_get_domain_limits(sp, dd->id);
+	mutex_init(&sd->lock);
+
+	/* Get power limits for this domain */
+	nr_pl = spel_find_nr_power_limit(sd);
+
+	/* Register powercap zone */
+	pcz = powercap_register_zone(&sd->power_zone, pct, name, parent,
+				     &zone_ops, nr_pl, &constraint_ops);
+	if (IS_ERR(pcz)) {
+		dev_err_probe(sp->dev, PTR_ERR(pcz),
+			      "Failed to register power zone %s\n", name);
+		mutex_destroy(&sd->lock);
+		kfree(sd);
+		return pcz;
+	}
+
+	return pcz;
+}
+
+static void spel_destroy_zone(struct powercap_control_type *pct,
+			      struct powercap_zone *zone, void *data)
+{
+	powercap_unregister_zone(pct, zone);
+}
+
+static int spel_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct powercap_control_type *ct;
+	struct spel_system *sp;
+	int ret;
+
+	/* Allocate system structure */
+	sp = kzalloc_obj(*sp, GFP_KERNEL);
+	if (!sp)
+		return -ENOMEM;
+
+	sp->dev = dev;
+
+	/* Map config registers (units, capabilities) */
+	sp->config_base = devm_platform_ioremap_resource_byname(pdev, "config");
+	if (IS_ERR(sp->config_base)) {
+		ret = dev_err_probe(dev, PTR_ERR(sp->config_base),
+				    "Failed to map config registers\n");
+		goto err_free_sp;
+	}
+
+	/* Map constraint registers (power limits) */
+	sp->constraint_base = devm_platform_ioremap_resource_byname(pdev, "constraints");
+	if (IS_ERR(sp->constraint_base)) {
+		ret = dev_err_probe(dev, PTR_ERR(sp->constraint_base),
+				    "Failed to map constraint registers\n");
+		goto err_free_sp;
+	}
+
+	/* Map spel domain registers (energy counters) */
+	sp->node_base = devm_platform_ioremap_resource_byname(pdev, "nodes");
+	if (IS_ERR(sp->node_base)) {
+		ret = dev_err_probe(dev, PTR_ERR(sp->node_base),
+				    "Failed to map node registers\n");
+		goto err_free_sp;
+	}
+
+	ct = powercap_register_control_type(&sp->control_type, "qcom-spel",
+					    &spel_control_type_ops);
+	if (IS_ERR(ct))
+		return dev_err_probe(dev, PTR_ERR(ct),
+				    "Failed to register control type\n");
+
+	/* Initialize system and domains */
+	ret = spel_init_system(sp, dev);
+	if (ret) {
+		ret = dev_err_probe(dev, ret, "Failed to initialize system\n");
+		goto err_unregister_control;
+	}
+
+	/* Duplicate the hierarchy template */
+	sp->hierarchy = powercap_hierarchy_dup(&glymur_spel_hierarchy_template);
+	if (IS_ERR(sp->hierarchy)) {
+		ret = dev_err_probe(dev, PTR_ERR(sp->hierarchy),
+				    "Failed to duplicate hierarchy\n");
+		goto err_unregister_control;
+	}
+
+	/* Create the powercap hierarchy */
+	ret = powercap_hierarchy_create(ct, sp->hierarchy, spel_create_zone,
+					spel_destroy_zone);
+	if (ret) {
+		ret = dev_err_probe(dev, ret, "Failed to create powercap hierarchy\n");
+		goto err_free_hierarchy;
+	}
+
+	platform_set_drvdata(pdev, sp);
+
+	return 0;
+
+err_free_hierarchy:
+	powercap_hierarchy_free(sp->hierarchy);
+err_unregister_control:
+	/*
+	 * Unregister control type - this triggers the release callback
+	 * which will free the spel_system structure.
+	 * Return directly to avoid double free.
+	 */
+	powercap_unregister_control_type(ct);
+	return ret;
+err_free_sp:
+	kfree(sp);
+	return ret;
+}
+
+static void spel_remove(struct platform_device *pdev)
+{
+	struct spel_system *sp = platform_get_drvdata(pdev);
+
+	/* Destroy the hierarchy (unregisters all zones) */
+	powercap_hierarchy_destroy(&sp->control_type, sp->hierarchy, spel_destroy_zone);
+
+	/* Free the hierarchy */
+	powercap_hierarchy_free(sp->hierarchy);
+
+	/*
+	 * Unregister control type - this will trigger the release callback
+	 * which will cleanup domains and free the spel_system structure
+	 */
+	powercap_unregister_control_type(&sp->control_type);
+}
+
+static void spel_system_pm_freeze(struct spel_system *sp)
+{
+	for (size_t i = 0; i < sp->hierarchy->nr_nodes; i++) {
+		struct powercap_zone *zone = sp->hierarchy->nodes[i].zone;
+
+		if (zone)
+			spel_domain_pm_freeze(power_zone_to_spel_domain(zone));
+	}
+}
+
+static void spel_system_pm_restore(struct spel_system *sp)
+{
+	for (size_t i = 0; i < sp->hierarchy->nr_nodes; i++) {
+		struct powercap_zone *zone = sp->hierarchy->nodes[i].zone;
+
+		if (zone)
+			spel_domain_pm_restore(power_zone_to_spel_domain(zone));
+	}
+}
+
+static int spel_pm_freeze(struct device *dev)
+{
+	spel_system_pm_freeze(dev_get_drvdata(dev));
+	return 0;
+}
+
+static int spel_pm_restore(struct device *dev)
+{
+	spel_system_pm_restore(dev_get_drvdata(dev));
+	return 0;
+}
+
+static const struct dev_pm_ops spel_pm_ops = {
+	.freeze = spel_pm_freeze,
+	.restore = spel_pm_restore,
+};
+
+static const struct of_device_id spel_of_match[] = {
+	{ .compatible = "qcom,glymur-spel" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, spel_of_match);
+
+static struct platform_driver spel_driver = {
+	.probe = spel_probe,
+	.remove = spel_remove,
+	.driver = {
+		.name = "qcom_spel",
+		.of_match_table = spel_of_match,
+		.pm = pm_sleep_ptr(&spel_pm_ops),
+	},
+};
+
+module_platform_driver(spel_driver);
+
+MODULE_DESCRIPTION("Qualcomm SPEL Powercap Driver");
+MODULE_LICENSE("GPL");

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 3/3] arm64: dts: qcom: glymur: Enable SPEL powercap driver
  2026-12-06 11:56 [PATCH v4 0/3] Add Qualcomm SPEL powercap driver Manaf Meethalavalappu Pallikunhi
  2026-12-06 11:56 ` [PATCH v4 1/3] dt-bindings: soc: qcom: Describe Qualcomm SPEL hardware Manaf Meethalavalappu Pallikunhi
  2026-12-06 11:56 ` [PATCH v4 2/3] powercap: qcom: Add SPEL powercap driver Manaf Meethalavalappu Pallikunhi
@ 2026-12-06 11:56 ` Manaf Meethalavalappu Pallikunhi
  2026-12-06 12:04   ` sashiko-bot
  2 siblings, 1 reply; 6+ messages in thread
From: Manaf Meethalavalappu Pallikunhi @ 2026-12-06 11:56 UTC (permalink / raw)
  To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Rafael J. Wysocki,
	Daniel Lezcano
  Cc: linux-arm-msm, devicetree, linux-kernel, linux-pm,
	Manaf Meethalavalappu Pallikunhi

The Qualcomm SoC Power and Electrical Limits (SPEL) provides hardware
based power monitoring and limiting capabilities for various power
domains including System, SoC, CPU clusters, GPU, and various other
subsystems for glymur.

Signed-off-by: Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>
---
 arch/arm64/boot/dts/qcom/glymur.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/glymur.dtsi b/arch/arm64/boot/dts/qcom/glymur.dtsi
index 9cb7506656fb..a4dfa01e55f0 100644
--- a/arch/arm64/boot/dts/qcom/glymur.dtsi
+++ b/arch/arm64/boot/dts/qcom/glymur.dtsi
@@ -6302,6 +6302,16 @@ spmi_bus2: spmi@c448000 {
 			};
 		};
 
+		power-limits@ef3b000 {
+			compatible = "qcom,glymur-spel";
+			reg = <0x0 0x0ef3b000 0x0 0x1000>,
+			      <0x0 0x0ef3d000 0x0 0x1000>,
+			      <0x0 0x0ef3e000 0x0 0x1000>;
+			reg-names = "config",
+				    "constraints",
+				    "nodes";
+		};
+
 		tlmm: pinctrl@f100000 {
 			compatible = "qcom,glymur-tlmm";
 			reg = <0x0 0x0f100000 0x0 0xf00000>;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 3/3] arm64: dts: qcom: glymur: Enable SPEL powercap driver
  2026-12-06 11:56 ` [PATCH v4 3/3] arm64: dts: qcom: glymur: Enable " Manaf Meethalavalappu Pallikunhi
@ 2026-12-06 12:04   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-06 12:04 UTC (permalink / raw)
  To: Manaf Meethalavalappu Pallikunhi; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] arm64: dts: qcom: Mahua and Kalambo inherit Glymur 3-cluster
  SPEL node
- [Low] arm64: dts: qcom: commit title and body misdescribe adding SPEL
  DT node
--

commit 93629abacfb084bb47c17ce980cc267a7fbbec50
Author: Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>

> arm64: dts: qcom: glymur: Enable SPEL powercap driver
>
> The Qualcomm SoC Power and Electrical Limits (SPEL) provides hardware
> based power monitoring and limiting capabilities for various power
> domains including System, SoC, CPU clusters, GPU, and various other
> subsystems for glymur.
>
> Signed-off-by: Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>

[Severity: Low]
The subject talks about enabling the SPEL powercap driver, whereas this
patch adds a new SPEL hardware node to glymur.dtsi, and the body only
describes what SPEL is without stating what the patch changes.  Could the
subject and message be updated to describe adding the SPEL node?

> diff --git a/arch/arm64/boot/dts/qcom/glymur.dtsi b/arch/arm64/boot/dts/qcom/glymur.dtsi
> index 9cb7506656fba..a4dfa01e55f0f 100644
> --- a/arch/arm64/boot/dts/qcom/glymur.dtsi
> +++ b/arch/arm64/boot/dts/qcom/glymur.dtsi
> @@ -6302,6 +6302,16 @@ spmi_bus2: spmi@c448000 {
>  			};
>  		};
>  
> +		power-limits@ef3b000 {
> +			compatible = "qcom,glymur-spel";
> +			reg = <0x0 0x0ef3b000 0x0 0x1000>,
> +			      <0x0 0x0ef3d000 0x0 0x1000>,
> +			      <0x0 0x0ef3e000 0x0 0x1000>;
> +			reg-names = "config",
> +				    "constraints",
> +				    "nodes";
> +		};

[Severity: Medium]
Should power-limits@ef3b000 be labeled here and deleted or disabled in
mahua.dtsi?

mahua.dtsi includes glymur.dtsi via glymur-cob.dtsi and removes CPU
cluster 2, while kalambo.dtsi includes mahua.dtsi and also removes CPU
cluster 0.  Because this node is enabled and neither file overrides it,
spel_probe() in drivers/powercap/qcom/spel.c binds on both SoCs.

It then unconditionally registers all three CPU clusters (cl0, cl1, cl2)
from glymur_spel_hierarchy_nodes[], exposing nonexistent cluster domains
in sysfs with hardcoded offsets for absent clusters and risking invalid
MMIO reads at 0x0ef3b000 until Mahua and Kalambo have their own support.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-qcom_spel_driver_upstream-v4-0-168697736e95@oss.qualcomm.com?part=3

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 2/3] powercap: qcom: Add SPEL powercap driver
  2026-12-06 11:56 ` [PATCH v4 2/3] powercap: qcom: Add SPEL powercap driver Manaf Meethalavalappu Pallikunhi
@ 2026-12-06 12:13   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-06 12:13 UTC (permalink / raw)
  To: Manaf Meethalavalappu Pallikunhi; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] powercap: qcom: spel_get_max_energy_counter() returns U64_MAX,
  printing -1
- [Medium] powercap: qcom: unpolled 32-bit energy wraps missed and
  hidden by U64_MAX
- [Medium] powercap: qcom: spel_get_domain_limits() forces PL1 on all
  domains
- [Medium] powercap: qcom: spel_write_pl_data() disables limit on small
  non-zero values
- [Medium] powercap: qcom: spel_read_pl_data() ignores
  POWER_LIMIT_ENABLE bit
- [Low] powercap: qcom: commit message omits driver architecture context
--

commit 27c9fc242efc3e52d0b94409cc2a59891fe940ac
Author: Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>

> powercap: qcom: Add SPEL powercap driver
>
> The Qualcomm SoC Power and Electrical Limits (SPEL) provides hardware
> based power monitoring and limiting capabilities for various power
> domains including System, SoC, CPU clusters, GPU, and various other
> subsystems.
>
> The driver integrates with the Linux powercap framework, exposing SPEL
> capabilities through powercap sysfs interfaces.
>
> Signed-off-by: Manaf Meethalavalappu Pallikunhi <manaf.pallikunhi@oss.qualcomm.com>

[Severity: Low]
As reported by Daniel Lezcano on v3 [1], could the commit message be
expanded to describe the driver's architecture?

This adds a 949-line driver, yet the changelog omits the three MMIO
regions (config, constraints, nodes), unit exponent scaling, the Glymur
hierarchy, PL1-PL4 capability discovery, firmware notification on
time-window updates, 32-bit wraparound tracking, and hibernation support.

> diff --git a/drivers/powercap/qcom/spel.c b/drivers/powercap/qcom/spel.c
> new file mode 100644
> index 0000000000000..56cf98bc54669
> --- /dev/null
> +++ b/drivers/powercap/qcom/spel.c

[ ... ]

> +	reg_addr = sp->constraint_base + offset;
> +	value = readl(reg_addr);
> +
> +	switch (pl_op) {
> +	case PL_LIMIT:
> +		value = FIELD_GET(POWER_LIMIT_MASK, value);
> +		if (xlate)
> +			*data = spel_unit_xlate(sd, POWER_UNIT, value, 0);
> +		else
> +			*data = value;
> +		break;

[Severity: Medium]
Should spel_read_pl_data() check POWER_LIMIT_ENABLE before returning the
power limit?

zone_ops omits get_enable (so sysfs always reports enabled as 1), and
spel_write_pl_data() uses 0 to disable and non-zero to enable.  If
POWER_LIMIT_ENABLE is clear while POWER_LIMIT_MASK is non-zero, reads
report an active limit and saving/restoring it enables the constraint.

Returning 0 when !(value & POWER_LIMIT_ENABLE) would keep reads
consistent with writes.

[ ... ]

> +	switch (pl_op) {
> +	case PL_LIMIT:
> +		new_val = spel_unit_xlate(sd, POWER_UNIT, value, 1);
> +		if (new_val > FIELD_MAX(POWER_LIMIT_MASK))
> +			return -EINVAL;
> +
> +		FIELD_MODIFY(POWER_LIMIT_MASK, &reg_val, new_val);
> +
> +		/*
> +		 * Enable/Disable PL based on the value:
> +		 * - If value is 0, disable the PL (clear enable bit)
> +		 * - If value is non-zero, enable the PL (set enable bit)
> +		 */
> +		FIELD_MODIFY(POWER_LIMIT_ENABLE, &reg_val, !!new_val);
> +
> +		writel(reg_val, reg_addr);
> +		return 0;

[Severity: Medium]
Can a small non-zero power limit silently disable hardware limiting here?

spel_unit_xlate() uses DIV_ROUND_CLOSEST_ULL(), so any non-zero microwatt
value below half of one hardware quantum rounds down to new_val == 0.
FIELD_MODIFY(POWER_LIMIT_ENABLE, &reg_val, !!new_val) then clears the
enable bit and returns 0, removing the power cap instead of applying one.

When value is non-zero and new_val rounds to 0, returning -EINVAL or
clamping new_val to 1 would avoid disabling the limit.

[ ... ]

> +static void spel_domain_sync_energy(struct spel_domain *sd)
> +{
> +	u32 value = readl(sd->status_reg);
> +
> +	/* The 32-bit counter wrapped since the last read; fold a full range in. */
> +	if (value < sd->last_raw)
> +		sd->cumulative_energy_uj +=
> +			spel_unit_xlate(sd, ENERGY_UNIT, ENERGY_STATUS_MASK + 1ULL, 0);
> +
> +	sd->last_raw = value;
> +}

[Severity: Medium]
Can 32-bit energy counter wraps be silently dropped between reads?

Wrap detection only runs on demand during energy_uj reads or hibernation
freeze, with no periodic polling.  If reads are spaced further apart than
one 32-bit hardware wrap period, the missed wraps are permanently lost
from cumulative_energy_uj.

Because spel_get_max_energy_counter() reports U64_MAX instead of the
translated 32-bit hardware range, userspace pollers also cannot tell how
often they need to sample to avoid missing wraps.

[ ... ]

> +static int spel_get_max_energy_counter(struct powercap_zone *pcd_dev, u64 *energy)
> +{
> +	/*
> +	 * energy_raw is a software accumulator that never wraps at the
> +	 * hardware's 32-bit range; report the true u64 range instead of the
> +	 * hardware wrap boundary.
> +	 */
> +	*energy = U64_MAX;
> +
> +	return 0;
> +}

[Severity: High]
Will returning U64_MAX make max_energy_range_uj print -1 to userspace?

powercap_sys.c formats the u64 result as a signed 64-bit integer:

drivers/powercap/powercap_sys.c:define_power_zone_show() {
	...
	if (power_zone->ops->get_##_attr) {
		if (!power_zone->ops->get_##_attr(power_zone, &value))
			len = sysfs_emit(buf, "%lld\n", value);
	}
	...
}

Because U64_MAX has bit 63 set, every read of max_energy_range_uj emits
"-1\n", breaking tools that parse it as an unsigned range.  Either
powercap_sys.c needs to use %llu first, or this should return a value
within S64_MAX (such as the translated 32-bit hardware range).

[ ... ]

> +static int spel_get_domain_limits(struct spel_system *sp, enum spel_domain_type domain_id)
> +{
> +	/* Enable minimum one constraint, detect the rest from hardware capabilities. */
> +	int limits = BIT(POWER_LIMIT1);
> +
> +	for (int i = 0; i < ARRAY_SIZE(constraints); i++) {
> +		const struct spel_constraint_info *ci = &constraints[i];
> +
> +		if (ci->domain_id == domain_id && sp->pl_capabilities & ci->supported_mask)
> +			limits |= BIT(ci->pl_id);
> +	}
> +
> +	return limits;
> +}

[Severity: Medium]
Why is POWER_LIMIT1 unconditionally enabled on every domain?

constraints[] only defines registers for SPEL_DOMAIN_SYS and
SPEL_DOMAIN_SOC, so forcing BIT(POWER_LIMIT1) exposes broken constraint_0
(pl1) sysfs attributes on all 11 monitoring-only domains, where every
read or write fails in get_pl_ops_offset() with -EOPNOTSUPP (-ENODATA).

For SPEL_DOMAIN_SYS and SPEL_DOMAIN_SOC, it also bypasses the BIT(0) and
BIT(4) capability checks, causing sysfs handlers and hibernation
freeze/restore to access PL1 registers even if hardware leaves those
bits clear.

Initializing limits to 0 is supported by powercap_register_zone() when
&constraint_ops is passed.

[1] https://lore.kernel.org/r/92397fd7-e149-432c-9ec8-b2cd31af7f04@oss.qualcomm.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-qcom_spel_driver_upstream-v4-0-168697736e95@oss.qualcomm.com?part=2

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-06 12:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 11:56 [PATCH v4 0/3] Add Qualcomm SPEL powercap driver Manaf Meethalavalappu Pallikunhi
2026-12-06 11:56 ` [PATCH v4 1/3] dt-bindings: soc: qcom: Describe Qualcomm SPEL hardware Manaf Meethalavalappu Pallikunhi
2026-12-06 11:56 ` [PATCH v4 2/3] powercap: qcom: Add SPEL powercap driver Manaf Meethalavalappu Pallikunhi
2026-12-06 12:13   ` sashiko-bot
2026-12-06 11:56 ` [PATCH v4 3/3] arm64: dts: qcom: glymur: Enable " Manaf Meethalavalappu Pallikunhi
2026-12-06 12:04   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox