New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add regulator driver infrastructure #27360
Add regulator driver infrastructure #27360
Conversation
My current thought is to add a |
db783dc
to
4763e45
Compare
The latest push reveals another gap in dependency information: all regulators are included in the image even if only one (or no) device that depends on them is enabled. Yes, that could be addressed by marking some or all of them |
d520b90
to
8b3da4f
Compare
Should we be using |
API meeting 4th August 2020:
|
Looks like |
I'm going to add Edit: The documented purpose for |
8b3da4f
to
5bb9337
Compare
5bb9337
to
10187e1
Compare
Thank you, this is a good addition also for all SiLabs boards, since nearly every peripheral on the board must be enabled with a dedicated io pin.
I would prefer if there would be a more general approach, but i don't know how to implement it properly, maybe move Use cases: For (nearly all) SiLabs dev boards, there is a virtual serial port (via on-board Segger J-Link, named Board controller in source code) that must be enabled with a gpio pin, see https://github.com/zephyrproject-rtos/zephyr/blob/master/boards/arm/efm32gg_stk3701a/board.c#L20 Also the ethernet phy must be enabled via gpio pin a few lines further down, https://github.com/zephyrproject-rtos/zephyr/blob/master/boards/arm/efm32gg_stk3701a/board.c#L38 |
Yes, I have the sltb004a. It motivates a slightly different approach: there are many cases, these included, where we want a more efficient solution that doesn't involve a full on-off service that supports delayed startup and shutdown. Just controlling a GPIO based on whether a counter is zero or positive handles it. I'm thinking of having another compatible If there's only one thing that will ever control the signal, and it already knows the state without a counter, I don't think a full regulator API is appropriate. For that application using It should be possible to eliminate |
* | ||
* @param reg a regulator device | ||
* | ||
* @return non-negative on successful completion of the release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it wait for the regulator to actually be fully off?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. This was a design trade-off in the context of developing the on-off service. If it's necessary to detect when the transition completes that can be done in other ways.
I suspect it will be necessary, so this may have to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general you can only know that you have started to turn it off. Of course you can look at datasheets and some of them will have a 'ready' bit which tells you that the power is stable (or fully off).
IMO it is probably enough to know that we have completed 'asking' for it to turn off. A client could add a udelay if needed.
For turning on, I think we need to know that the power is fully stable, since until it is we cannot advance.
@pabigot Sorry I seem to have missed a step so that I could see them but not you. Can you see them now? |
c7aa4f9
to
23896bf
Compare
That seems OK to me for now |
return rc; | ||
} | ||
|
||
struct driver_data_sync { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we can start requiring that for internal implementation data structures that aren't processed to provide documentation. Do we want to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think we still want comments
const struct driver_config *cfg = dev->config; | ||
int rc = common_init(dev, &data->gpio); | ||
|
||
(void)regulator_fixed_init_onoff; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these three lines for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They eliminated "function defined but not referenced" in cases where only _sync
regulators are present.
I may be able to remove them with preprocessor conditional that prevent them from being defined, but I think I tried that and it got ugly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about __maybe_unused ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly; no precedent in zephyr.
23896bf
to
85c7925
Compare
# compatible = "regulator-fixed-sync", "regulator-fixed"; | ||
# | ||
|
||
compatible: "regulator-fixed" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we trying to be in sync with the linux binding for regulator-fixed
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To a reasonable degree, yes. We don't support external properties for the active level and open drain, for reasons described in the binding.
required: true | ||
description: Descriptive name for regulator outputs. | ||
|
||
enable-gpios: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like upstream just calls this gpio
for this property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's true. upstream uses gpio
, enable-active-high
, and gpio-open-drain
. This uses enable-gpios
to handle all three of those.
I though we'd discussed this and you agreed we shouldn't attempt to support the extra properties when proper use of a GPIO selector makes them unnecessary. Given that, I think we should use a different name, because gpio
would suggest the flags are ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need to name this zephyr,regulator-fixed
to avoid confusion I'm fine with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can leave things as is, but can we add a comment in the binding to explain how/why enable-gpios
differs from gpio
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@galak Rebased (since this hasn't been tested directly on master since August), and then updated the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with documentation text rather than comment, because if we're going to generate human-readable documentation for these things the comments are less visible than when we expect people to look at the binding file directly.
Provide a common set of properties for various ways of controlling power: * supply-gpios for a GPIO specifier acting like a switch * vin-supply for a reference to a regulator device Document the behavior expected when these properties are present. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This PR follows Linux in defining devicetree content for generic voltage and current regulators, and an initial driver API for controlling them. A regulator itself may depend on a power source, so it needs to support the properties that enable that power source. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
85c7925
to
577031a
Compare
This provides structure for the regulator device hierarchy and a driver for GPIO-controlled regulators along with its binding. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Add a page for the regulator API and introduce it as an experimental API. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Basic checks on core regulator functions. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This board has a multi-level power domain hierarchy where a sensor has its own power control that is accessed through an external GPIO peripheral that itself has a power control. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
577031a
to
1056280
Compare
To support runtime power management we need to be able to control voltage/current regulators. Although there are boards in-tree that use these, there is no devicetree support for describing them. This PR provides support based on Linux bindings.
The API is based on the Linux API but adapted for Zephyr. The enable operation is asynchronous as it may take time to turn a regulator on. The disable operation is synchronous as the caller doesn't need to know when the regulator transitions to off. (Power management infrastructure will, but that's not part of this API.)
On the theory that user space never needs to control system power the API requires supervisor privileges. This may be changed based on feedback. The API is also isr-ok and pre-kernel-ok.
A significant gap is the lack of any ability to configure the kernel init level and priority on a per-device level. Without that this infrastructure is fragile.
The thingy52_nrf52832 board has been updated to provide its two external power rails, but the pseudo-devices that currently control them cannot be replaced until device-specific init priority is supported.
Commit Contents
Blockers for merge:
power-supply