diff mbox series

[RFC,net-next,v2,11/18] regulator: Add support for power budget description

Message ID 20241030-feature_poe_port_prio-v2-11-9559622ee47a@bootlin.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series Add support for PSE port priority | expand

Checks

Context Check Description
netdev/series_format fail Series longer than 15 patches
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; GEN HAS DIFF 2 files changed, 142 insertions(+);
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 133 this patch: 133
netdev/build_tools success Errors and warnings before: 0 (+0) this patch: 0 (+0)
netdev/cc_maintainers success CCed 2 of 2 maintainers
netdev/build_clang success Errors and warnings before: 157 this patch: 157
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3189 this patch: 3189
netdev/checkpatch warning CHECK: From:/Signed-off-by: email comments mismatch: 'From: Kory Maincent (Dent Project) <kory.maincent@bootlin.com>' != 'Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Kory Maincent Oct. 30, 2024, 4:53 p.m. UTC
From: Kory Maincent (Dent Project) <kory.maincent@bootlin.com>

In preparation for future support of PSE port priority and power
management, we need the power budget value of the power supply.
This addition allows the regulator to track the available power
capacity, which will be essential for prioritizing ports when
making power allocation decisions.

Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---

Changes in v2:
- new patch.
---
 drivers/regulator/core.c           | 11 +++++++++++
 drivers/regulator/of_regulator.c   |  3 +++
 include/linux/regulator/consumer.h |  6 ++++++
 include/linux/regulator/machine.h  |  2 ++
 4 files changed, 22 insertions(+)

Comments

Mark Brown Oct. 30, 2024, 5:03 p.m. UTC | #1
On Wed, Oct 30, 2024 at 05:53:13PM +0100, Kory Maincent wrote:

> +/**
> + * regulator_get_power_budget - get regulator total power budget
> + * @regulator: regulator source
> + *
> + * Return: Power budget of the regulator in mW.
> + */
> +int regulator_get_power_budget(struct regulator *regulator)
> +{
> +	return regulator->rdev->constraints->pw_budget;
> +}

This is going to go badly with multiple consumers...

> +static inline int regulator_get_power_budget(struct regulator *regulator)
> +{
> +	return 0;
> +}

We should probably default to INT_MAX here and in the case where we do
have support, that way consumers will fail gracefully when no budget is
specified.
Kory Maincent Oct. 30, 2024, 5:22 p.m. UTC | #2
On Wed, 30 Oct 2024 17:03:06 +0000
Mark Brown <broonie@kernel.org> wrote:

> On Wed, Oct 30, 2024 at 05:53:13PM +0100, Kory Maincent wrote:
> 
> > +/**
> > + * regulator_get_power_budget - get regulator total power budget
> > + * @regulator: regulator source
> > + *
> > + * Return: Power budget of the regulator in mW.
> > + */
> > +int regulator_get_power_budget(struct regulator *regulator)
> > +{
> > +	return regulator->rdev->constraints->pw_budget;
> > +}  
> 
> This is going to go badly with multiple consumers...

On my series the available power budget of the PIs (which are consumers) is
managed in the PSE core in the PSE power domain (patch 13). We could move it
directly to regulator API.

> > +static inline int regulator_get_power_budget(struct regulator *regulator)
> > +{
> > +	return 0;
> > +}  
> 
> We should probably default to INT_MAX here and in the case where we do
> have support, that way consumers will fail gracefully when no budget is
> specified.

That's true. Thanks!

Regards,
Mark Brown Oct. 30, 2024, 5:31 p.m. UTC | #3
On Wed, Oct 30, 2024 at 06:22:11PM +0100, Kory Maincent wrote:
> Mark Brown <broonie@kernel.org> wrote:
> > On Wed, Oct 30, 2024 at 05:53:13PM +0100, Kory Maincent wrote:

> > > +int regulator_get_power_budget(struct regulator *regulator)
> > > +{
> > > +	return regulator->rdev->constraints->pw_budget;
> > > +}  

> > This is going to go badly with multiple consumers...

> On my series the available power budget of the PIs (which are consumers) is
> managed in the PSE core in the PSE power domain (patch 13). We could move it
> directly to regulator API.

It feels like it's going to need joining up at some point.
diff mbox series

Patch

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 1179766811f5..cd7b26f77a8e 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -4622,6 +4622,17 @@  int regulator_get_current_limit(struct regulator *regulator)
 }
 EXPORT_SYMBOL_GPL(regulator_get_current_limit);
 
+/**
+ * regulator_get_power_budget - get regulator total power budget
+ * @regulator: regulator source
+ *
+ * Return: Power budget of the regulator in mW.
+ */
+int regulator_get_power_budget(struct regulator *regulator)
+{
+	return regulator->rdev->constraints->pw_budget;
+}
+
 /**
  * regulator_set_mode - set regulator operating mode
  * @regulator: regulator source
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 3f490d81abc2..a8996e7597d4 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -125,6 +125,9 @@  static int of_get_regulation_constraints(struct device *dev,
 	if (constraints->min_uA != constraints->max_uA)
 		constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT;
 
+	if (!of_property_read_u32(np, "regulator-power-budget", &pval))
+		constraints->pw_budget = pval;
+
 	constraints->boot_on = of_property_read_bool(np, "regulator-boot-on");
 	constraints->always_on = of_property_read_bool(np, "regulator-always-on");
 	if (!constraints->always_on) /* status change should be possible. */
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index b9ce521910a0..3e75d49d361f 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -235,6 +235,7 @@  int regulator_sync_voltage(struct regulator *regulator);
 int regulator_set_current_limit(struct regulator *regulator,
 			       int min_uA, int max_uA);
 int regulator_get_current_limit(struct regulator *regulator);
+int regulator_get_power_budget(struct regulator *regulator);
 
 int regulator_set_mode(struct regulator *regulator, unsigned int mode);
 unsigned int regulator_get_mode(struct regulator *regulator);
@@ -534,6 +535,11 @@  static inline int regulator_get_current_limit(struct regulator *regulator)
 	return 0;
 }
 
+static inline int regulator_get_power_budget(struct regulator *regulator)
+{
+	return 0;
+}
+
 static inline int regulator_set_mode(struct regulator *regulator,
 	unsigned int mode)
 {
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 0cd76d264727..3304cf8773b7 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -113,6 +113,7 @@  struct notification_limit {
  * @min_uA: Smallest current consumers may set.
  * @max_uA: Largest current consumers may set.
  * @ilim_uA: Maximum input current.
+ * @pw_budget: Power budget for the regulator in mW.
  * @system_load: Load that isn't captured by any consumer requests.
  *
  * @over_curr_limits:		Limits for acting on over current.
@@ -185,6 +186,7 @@  struct regulation_constraints {
 	int max_uA;
 	int ilim_uA;
 
+	int pw_budget;
 	int system_load;
 
 	/* used for coupled regulators */