* [PATCH v2 0/2] Add support for power budget
@ 2025-01-15 14:41 Kory Maincent
2025-01-15 14:41 ` [PATCH v2 1/2] regulator: " Kory Maincent
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Kory Maincent @ 2025-01-15 14:41 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Thomas Petazzoni, linux-kernel, devicetree, Oleksij Rempel,
kernel, Kory Maincent
In preparation for future support of PSE budget evaluation strategy and
power management, we need the power budget value of the power supply.
This addition allows the regulator to track the available power
budget, which will be essential for prioritizing ports when
making power allocation decisions.
The related budget evaluation strategy patch series sent:
https://lore.kernel.org/netdev/20250104161622.7b82dfdf@kmaincent-XPS-13-7390/T/#t
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Changes in v2:
- Add event notifier in case of power request over budget.
- Track how much budget is used instead of free power budget.
- Link to v1: https://lore.kernel.org/r/20250113-feature_regulator_pw_budget-v1-0-01e1d95c2015@bootlin.com
---
Kory Maincent (2):
regulator: Add support for power budget
regulator: dt-bindings: Add regulator-power-budget-milliwatt property
.../devicetree/bindings/regulator/regulator.yaml | 3 +
drivers/regulator/core.c | 114 +++++++++++++++++++++
drivers/regulator/of_regulator.c | 3 +
include/linux/regulator/consumer.h | 21 ++++
include/linux/regulator/driver.h | 2 +
include/linux/regulator/machine.h | 2 +
6 files changed, 145 insertions(+)
---
base-commit: 36d9fc502ebc4dd56ea95de1e4f10a4ac5c1691c
change-id: 20250110-feature_regulator_pw_budget-f0e7396afa05
Best regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v2 1/2] regulator: Add support for power budget 2025-01-15 14:41 [PATCH v2 0/2] Add support for power budget Kory Maincent @ 2025-01-15 14:41 ` Kory Maincent 2025-01-15 14:41 ` [PATCH v2 2/2] regulator: dt-bindings: Add regulator-power-budget-milliwatt property Kory Maincent ` (2 subsequent siblings) 3 siblings, 0 replies; 8+ messages in thread From: Kory Maincent @ 2025-01-15 14:41 UTC (permalink / raw) To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: Thomas Petazzoni, linux-kernel, devicetree, Oleksij Rempel, kernel, Kory Maincent Introduce power budget management for the regulator device. Enable tracking of available power capacity by providing helpers to request and release power budget allocations. Signed-off-by: Kory Maincent <kory.maincent@bootlin.com> --- Change in v2: - Add event notifier in case of power request over budget. - Track how much budget is used instead of free power budget. --- drivers/regulator/core.c | 114 +++++++++++++++++++++++++++++++++++++ drivers/regulator/of_regulator.c | 3 + include/linux/regulator/consumer.h | 21 +++++++ include/linux/regulator/driver.h | 2 + include/linux/regulator/machine.h | 2 + 5 files changed, 142 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index c092b78c5f12..6c0ef1182248 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -917,6 +917,26 @@ static ssize_t bypass_show(struct device *dev, } static DEVICE_ATTR_RO(bypass); +static ssize_t power_budget_milliwatt_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct regulator_dev *rdev = dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", rdev->constraints->pw_budget_mW); +} +static DEVICE_ATTR_RO(power_budget_milliwatt); + +static ssize_t power_requested_milliwatt_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct regulator_dev *rdev = dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", rdev->pw_requested_mW); +} +static DEVICE_ATTR_RO(power_requested_milliwatt); + #define REGULATOR_ERROR_ATTR(name, bit) \ static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \ char *buf) \ @@ -1149,6 +1169,10 @@ static void print_constraints_debug(struct regulator_dev *rdev) if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) count += scnprintf(buf + count, len - count, "standby "); + if (constraints->pw_budget_mW) + count += scnprintf(buf + count, len - count, "%d mW budget", + constraints->pw_budget_mW); + if (!count) count = scnprintf(buf, len, "no parameters"); else @@ -1627,6 +1651,9 @@ static int set_machine_constraints(struct regulator_dev *rdev) rdev->last_off = ktime_get(); } + if (!rdev->constraints->pw_budget_mW) + rdev->constraints->pw_budget_mW = INT_MAX; + print_constraints(rdev); return 0; } @@ -4601,6 +4628,87 @@ int regulator_get_current_limit(struct regulator *regulator) } EXPORT_SYMBOL_GPL(regulator_get_current_limit); +/** + * regulator_get_unclaimed_power_budget - get regulator unclaimed power budget + * @regulator: regulator source + * + * Return: Unclaimed power budget of the regulator in mW. + */ +int regulator_get_unclaimed_power_budget(struct regulator *regulator) +{ + return regulator->rdev->constraints->pw_budget_mW - + regulator->rdev->pw_requested_mW; +} +EXPORT_SYMBOL_GPL(regulator_get_unclaimed_power_budget); + +/** + * regulator_request_power_budget - request power budget on a regulator + * @regulator: regulator source + * @pw_req: Power requested + * + * Return: 0 on success or a negative error number on failure. + */ +int regulator_request_power_budget(struct regulator *regulator, + unsigned int pw_req) +{ + struct regulator_dev *rdev = regulator->rdev; + int ret = 0, pw_tot_req; + + regulator_lock(rdev); + if (rdev->supply) { + ret = regulator_request_power_budget(rdev->supply, pw_req); + if (ret < 0) + goto out; + } + + pw_tot_req = rdev->pw_requested_mW + pw_req; + if (pw_tot_req > rdev->constraints->pw_budget_mW) { + rdev_warn(rdev, "power requested %d mW out of budget %d mW", + pw_req, + rdev->constraints->pw_budget_mW - rdev->pw_requested_mW); + regulator_notifier_call_chain(rdev, + REGULATOR_EVENT_OVER_CURRENT_WARN, + NULL); + ret = -ERANGE; + goto out; + } + + rdev->pw_requested_mW = pw_tot_req; +out: + regulator_unlock(rdev); + return ret; +} +EXPORT_SYMBOL_GPL(regulator_request_power_budget); + +/** + * regulator_free_power_budget - free power budget on a regulator + * @regulator: regulator source + * @pw: Power to be released. + * + * Return: Power budget of the regulator in mW. + */ +void regulator_free_power_budget(struct regulator *regulator, + unsigned int pw) +{ + struct regulator_dev *rdev = regulator->rdev; + int pw_tot_req; + + regulator_lock(rdev); + if (rdev->supply) + regulator_free_power_budget(rdev->supply, pw); + + pw_tot_req = rdev->pw_requested_mW - pw; + if (pw_tot_req >= 0) + rdev->pw_requested_mW = pw_tot_req; + else + rdev_warn(rdev, + "too much power freed %d mW (already requested %d mW)", + pw, rdev->pw_requested_mW); + + regulator_unlock(rdev); +} +EXPORT_SYMBOL_GPL(regulator_free_power_budget); + /** * regulator_set_mode - set regulator operating mode * @regulator: regulator source @@ -5239,6 +5347,8 @@ static struct attribute *regulator_dev_attrs[] = { &dev_attr_suspend_standby_mode.attr, &dev_attr_suspend_mem_mode.attr, &dev_attr_suspend_disk_mode.attr, + &dev_attr_power_budget_milliwatt.attr, + &dev_attr_power_requested_milliwatt.attr, NULL }; @@ -5320,6 +5430,10 @@ static umode_t regulator_attr_is_visible(struct kobject *kobj, attr == &dev_attr_suspend_disk_mode.attr) return ops->set_suspend_mode ? mode : 0; + if (attr == &dev_attr_power_budget_milliwatt.attr || + attr == &dev_attr_power_requested_milliwatt.attr) + return rdev->constraints->pw_budget_mW != INT_MAX ? mode : 0; + return mode; } diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 6af8411679c7..011088c57891 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-milliwatt", &pval)) + constraints->pw_budget_mW = 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 bcba3935c6f9..ffe912f345ae 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -233,6 +233,11 @@ 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_unclaimed_power_budget(struct regulator *regulator); +int regulator_request_power_budget(struct regulator *regulator, + unsigned int pw_req); +void regulator_free_power_budget(struct regulator *regulator, + unsigned int pw); int regulator_set_mode(struct regulator *regulator, unsigned int mode); unsigned int regulator_get_mode(struct regulator *regulator); @@ -526,6 +531,22 @@ static inline int regulator_get_current_limit(struct regulator *regulator) return 0; } +static inline int regulator_get_unclaimed_power_budget(struct regulator *regulator) +{ + return INT_MAX; +} + +static inline int regulator_request_power_budget(struct regulator *regulator, + unsigned int pw_req) +{ + return -EOPNOTSUPP; +} + +static inline void regulator_free_power_budget(struct regulator *regulator, + unsigned int pw) +{ +} + static inline int regulator_set_mode(struct regulator *regulator, unsigned int mode) { diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 5b66caf1695d..4a216fdba354 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -656,6 +656,8 @@ struct regulator_dev { int cached_err; bool use_cached_err; spinlock_t err_lock; + + int pw_requested_mW; }; /* diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index b3db09a7429b..1fc440c5c4c7 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_mW: 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_mW; int system_load; /* used for coupled regulators */ -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] regulator: dt-bindings: Add regulator-power-budget-milliwatt property 2025-01-15 14:41 [PATCH v2 0/2] Add support for power budget Kory Maincent 2025-01-15 14:41 ` [PATCH v2 1/2] regulator: " Kory Maincent @ 2025-01-15 14:41 ` Kory Maincent 2025-01-20 18:20 ` Conor Dooley 2025-01-17 12:09 ` [PATCH v2 0/2] Add support for power budget Kory Maincent 2025-01-17 22:52 ` Mark Brown 3 siblings, 1 reply; 8+ messages in thread From: Kory Maincent @ 2025-01-15 14:41 UTC (permalink / raw) To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: Thomas Petazzoni, linux-kernel, devicetree, Oleksij Rempel, kernel, Kory Maincent Introduce a new property to describe the power budget of the regulator. This property will allow power management support for regulator consumers like PSE controllers, enabling them to make decisions based on the available power capacity. Signed-off-by: Kory Maincent <kory.maincent@bootlin.com> --- Documentation/devicetree/bindings/regulator/regulator.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/regulator/regulator.yaml b/Documentation/devicetree/bindings/regulator/regulator.yaml index 1ef380d1515e..77573bcb6b79 100644 --- a/Documentation/devicetree/bindings/regulator/regulator.yaml +++ b/Documentation/devicetree/bindings/regulator/regulator.yaml @@ -34,6 +34,9 @@ properties: regulator-input-current-limit-microamp: description: maximum input current regulator allows + regulator-power-budget-milliwatt: + description: power budget of the regulator + regulator-always-on: description: boolean, regulator should never be disabled type: boolean -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] regulator: dt-bindings: Add regulator-power-budget-milliwatt property 2025-01-15 14:41 ` [PATCH v2 2/2] regulator: dt-bindings: Add regulator-power-budget-milliwatt property Kory Maincent @ 2025-01-20 18:20 ` Conor Dooley 0 siblings, 0 replies; 8+ messages in thread From: Conor Dooley @ 2025-01-20 18:20 UTC (permalink / raw) To: Kory Maincent Cc: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Thomas Petazzoni, linux-kernel, devicetree, Oleksij Rempel, kernel [-- Attachment #1: Type: text/plain, Size: 434 bytes --] On Wed, Jan 15, 2025 at 03:41:58PM +0100, Kory Maincent wrote: > Introduce a new property to describe the power budget of the regulator. > This property will allow power management support for regulator consumers > like PSE controllers, enabling them to make decisions based on the > available power capacity. > > Signed-off-by: Kory Maincent <kory.maincent@bootlin.com> Acked-by: Conor Dooley <conor.dooley@microchip.com> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] Add support for power budget 2025-01-15 14:41 [PATCH v2 0/2] Add support for power budget Kory Maincent 2025-01-15 14:41 ` [PATCH v2 1/2] regulator: " Kory Maincent 2025-01-15 14:41 ` [PATCH v2 2/2] regulator: dt-bindings: Add regulator-power-budget-milliwatt property Kory Maincent @ 2025-01-17 12:09 ` Kory Maincent 2025-01-17 13:48 ` Mark Brown 2025-01-17 22:52 ` Mark Brown 3 siblings, 1 reply; 8+ messages in thread From: Kory Maincent @ 2025-01-17 12:09 UTC (permalink / raw) To: Liam Girdwood, Mark Brown, Rob Herring, Krzysztof Kozlowski, Conor Dooley Cc: Thomas Petazzoni, linux-kernel, devicetree, Oleksij Rempel, kernel On Wed, 15 Jan 2025 15:41:56 +0100 Kory Maincent <kory.maincent@bootlin.com> wrote: > In preparation for future support of PSE budget evaluation strategy and > power management, we need the power budget value of the power supply. > > This addition allows the regulator to track the available power > budget, which will be essential for prioritizing ports when > making power allocation decisions. > > The related budget evaluation strategy patch series sent: > https://lore.kernel.org/netdev/20250104161622.7b82dfdf@kmaincent-XPS-13-7390/T/#t Hello, Is there hope this will be merged before the merge window? Regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] Add support for power budget 2025-01-17 12:09 ` [PATCH v2 0/2] Add support for power budget Kory Maincent @ 2025-01-17 13:48 ` Mark Brown 2025-01-17 13:57 ` Kory Maincent 0 siblings, 1 reply; 8+ messages in thread From: Mark Brown @ 2025-01-17 13:48 UTC (permalink / raw) To: Kory Maincent Cc: Liam Girdwood, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Thomas Petazzoni, linux-kernel, devicetree, Oleksij Rempel, kernel [-- Attachment #1: Type: text/plain, Size: 1085 bytes --] On Fri, Jan 17, 2025 at 01:09:36PM +0100, Kory Maincent wrote: > On Wed, 15 Jan 2025 15:41:56 +0100 > > In preparation for future support of PSE budget evaluation strategy and > > power management, we need the power budget value of the power supply. > Is there hope this will be merged before the merge window? Please don't send content free pings and please allow a reasonable time for review. People get busy, go on holiday, attend conferences and so on so unless there is some reason for urgency (like critical bug fixes) please allow at least a couple of weeks for review. If there have been review comments then people may be waiting for those to be addressed. Sending content free pings adds to the mail volume (if they are seen at all) which is often the problem and since they can't be reviewed directly if something has gone wrong you'll have to resend the patches anyway, so sending again is generally a better approach though there are some other maintainers who like them - if in doubt look at how patches for the subsystem are normally handled. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] Add support for power budget 2025-01-17 13:48 ` Mark Brown @ 2025-01-17 13:57 ` Kory Maincent 0 siblings, 0 replies; 8+ messages in thread From: Kory Maincent @ 2025-01-17 13:57 UTC (permalink / raw) To: Mark Brown Cc: Liam Girdwood, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Thomas Petazzoni, linux-kernel, devicetree, Oleksij Rempel, kernel On Fri, 17 Jan 2025 13:48:54 +0000 Mark Brown <broonie@kernel.org> wrote: > On Fri, Jan 17, 2025 at 01:09:36PM +0100, Kory Maincent wrote: > > On Wed, 15 Jan 2025 15:41:56 +0100 > > > > In preparation for future support of PSE budget evaluation strategy and > > > power management, we need the power budget value of the power supply. > > > Is there hope this will be merged before the merge window? > > Please don't send content free pings and please allow a reasonable time > for review. People get busy, go on holiday, attend conferences and so > on so unless there is some reason for urgency (like critical bug fixes) > please allow at least a couple of weeks for review. If there have been > review comments then people may be waiting for those to be addressed. > > Sending content free pings adds to the mail volume (if they are seen at > all) which is often the problem and since they can't be reviewed > directly if something has gone wrong you'll have to resend the patches > anyway, so sending again is generally a better approach though there are > some other maintainers who like them - if in doubt look at how patches > for the subsystem are normally handled. Ok, dully noted! Sorry for the noise! Regards, -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] Add support for power budget 2025-01-15 14:41 [PATCH v2 0/2] Add support for power budget Kory Maincent ` (2 preceding siblings ...) 2025-01-17 12:09 ` [PATCH v2 0/2] Add support for power budget Kory Maincent @ 2025-01-17 22:52 ` Mark Brown 3 siblings, 0 replies; 8+ messages in thread From: Mark Brown @ 2025-01-17 22:52 UTC (permalink / raw) To: Liam Girdwood, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Kory Maincent Cc: Thomas Petazzoni, linux-kernel, devicetree, Oleksij Rempel, kernel On Wed, 15 Jan 2025 15:41:56 +0100, Kory Maincent wrote: > In preparation for future support of PSE budget evaluation strategy and > power management, we need the power budget value of the power supply. > > This addition allows the regulator to track the available power > budget, which will be essential for prioritizing ports when > making power allocation decisions. > > [...] Applied to https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next Thanks! [1/2] regulator: Add support for power budget commit: 42d7c87b4e1251f36eceac987e74623e7cda8577 [2/2] regulator: dt-bindings: Add regulator-power-budget-milliwatt property commit: 367a8200a91025289f9664e468fbc2b67c95e70e All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-01-20 18:21 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-01-15 14:41 [PATCH v2 0/2] Add support for power budget Kory Maincent 2025-01-15 14:41 ` [PATCH v2 1/2] regulator: " Kory Maincent 2025-01-15 14:41 ` [PATCH v2 2/2] regulator: dt-bindings: Add regulator-power-budget-milliwatt property Kory Maincent 2025-01-20 18:20 ` Conor Dooley 2025-01-17 12:09 ` [PATCH v2 0/2] Add support for power budget Kory Maincent 2025-01-17 13:48 ` Mark Brown 2025-01-17 13:57 ` Kory Maincent 2025-01-17 22:52 ` Mark Brown
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox