Skip to content

Refactor nordic socs/drivers to remove GPD and decouple pin retention. #90754

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bjarki-andreasen
Copy link
Contributor

@bjarki-andreasen bjarki-andreasen commented May 28, 2025

Replace highly coupled use of GPD (gpd.h) from device drivers, with power domain device drivers using zephyr's PM_DEVICE_POWER_DOMAIN infrastructure.

The gpd.h currently is used for two things:

  • Manually requests power domains like fast_active_main and slow_active_main on the H20
  • Manually applies pin state retention on individual pins, or pins found in a pinctrl config.

Nordic device drivers currently have to do this manually, conditionally, which is adding immense complexity to them, only relevant for certain SoCs, and which is in theory duplicate code. In reality, device drivers do their best, but since gpd is not well understood, device drivers implement it slightly differently, in some cases working by design, some cases working by accident, and in some cases working, but breaking something else.

No more!

Both pin retention and power domains are actually designed in a way that is entirely logical, and can be expressed using power domains and the devicetree. So, using pinctrl and power domains, we can entirely decouple devices from this complexity :)

What does the refactor do?

  1. Rework the nrfh54h power domains to match zephyr's power domains. This means every power domain is represented as a node, not an index in a phandle. This does two things, it allows us to use zephyr's power domain framework, and it stops our misuse of the base power-domains property from breaking user's applications if they "dare" to use zephyrs power domain framework. See first commit.
  2. Introduce the gpio pads to the devicetree. GPIO pads are the SoCs pins, which peripherals like UARTE or GPIO can be muxed to. These can be in different power domains than the peripheral connected to them, and they need to be retained if the power domain they are in may be shut down, which only happens if no peripheral, including GPIO, is active while muxed to any pad in that pad group (a pad group is 1-1 mapped to the GPIO controller, so GPIO0 will own pad group 0). See second commit.
  3. Refactor pinctrl and device drivers to use the new power domains, and remove all usage of gpd.h
  4. Remove gpd.h
  5. Success

Copy link
Contributor

@karstenkoenig karstenkoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look at SWEXT changes, but the gpio port/pad power domain handling looks good.

Will this trigger more power domain requests/releases?

@bjarki-andreasen bjarki-andreasen force-pushed the nrfs-swext-pd branch 2 times, most recently from 95015ed to 1de2f64 Compare July 3, 2025 00:30
@bjarki-andreasen bjarki-andreasen added the platform: nRF Nordic nRFx label Jul 3, 2025
@bjarki-andreasen bjarki-andreasen force-pushed the nrfs-swext-pd branch 12 times, most recently from 3acab47 to 9163316 Compare July 14, 2025 12:49
@bjarki-andreasen bjarki-andreasen force-pushed the nrfs-swext-pd branch 2 times, most recently from 126e8cb to 3e4dca4 Compare July 14, 2025 16:00
@bjarki-andreasen bjarki-andreasen marked this pull request as ready for review July 14, 2025 17:12
@github-actions github-actions bot added manifest manifest-mcuboot DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Jul 17, 2025
@github-actions github-actions bot removed manifest manifest-mcuboot DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Jul 22, 2025
@bjarki-andreasen bjarki-andreasen changed the title Power domain: NRFS SWEXT driver Refactor nordic socs/drivers to remove GPD and decouple pin retention. Jul 22, 2025
@wearyzen wearyzen removed their assignment Jul 22, 2025
@wearyzen wearyzen removed their request for review July 22, 2025 10:52
Copy link
Contributor

@masz-nordic masz-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! :)

const struct nrf_port_retain_config *dev_config = dev->config;

LOG_DBG("%s pads 0x%08x retain %s", dev->name, dev_config->retain_mask, "enable");
nrf_gpio_port_retain_enable(dev_config->regs, dev_config->retain_mask);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: comment here with what is written in commit massage would be nice:
If no ACTIVE device is using any of the pads in the pad group, the pad groups power domain may be SUSPENDED. Before the pad groups power domain is SUSPENDED, pad config retention must be enabled to prevent the pads from loosing their state.

masz-nordic
masz-nordic previously approved these changes Jul 24, 2025
Introduce the NRFS GDPWR (Global Domain Power Request) device
driver and devicetree binding.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
Introduce the NRF GPIO Pad Group device driver and binding. The
pad group device represents the GPIO pads (pins), contrary to a
GPIO controller, which is one of the many devices which can be
muxed to pads in the pad group.

The pad group belong to a power domain, which is not neccesarily the
same power domain as devices being muxed to the pads, like GPIO or
UART. If no ACTIVE device is using any of the pads in the pad
group, the pad groups power domain may be SUSPENDED. Before the pad
groups power domain is SUSPENDED, pad config retention must be
enabled to prevent the pads from loosing their state. That's what
this device driver manages. Once retained, the pad configs and
outputs are locked, even when their power domain is SUSPENDED.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
Transition nrf54h away from the soc specific gpd
(global power domain) driver which mixed power domains, pinctrl
and gpio pin retention into a non scalable solution, forcing soc
specific logic to bleed into nrf drivers.

The new solution uses zephyrs PM_DEVICE based power domains to
properly model the hardware layout of device and pin power domains,
and moves pin retention logic out of drivers into pinctrl and
gpio, which are the components which manage pins (pads).

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
Remove the deprecated GPD (Global Power Domain) driver.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
@bjarki-andreasen
Copy link
Contributor Author

Rebased to solve merge conflict

@bjarki-andreasen
Copy link
Contributor Author

ping @anangl @nika-nordic

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants