-
Notifications
You must be signed in to change notification settings - Fork 9.1k
drivers: regulator: add set callback API and driver for Nordic USB VBUS regulator #97642
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
Merged
MaureenHelm
merged 6 commits into
zephyrproject-rtos:main
from
jfischer-no:pr-nrf54lm20a-vregusb
Mar 18, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f10e4e2
soc: nordic: remove pointless usbhs nodelabel vs MDK name checks
jfischer-no aaec1df
dts: nordic: describe USB hardware wrapper in nRF54LM20A
jfischer-no 516e312
include: regulator: add set callback API
jfischer-no da1d3e1
drivers: regulator: add driver for Nordic USB VBUS regulator
jfischer-no 38fc85b
dts: nordic: use phandle to reference VREGUSB regulator
jfischer-no 92d213d
drivers: udc: use regulator driver in DWC2 nRF54LM20A vendor quirks
jfischer-no File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Copyright Nordic Semiconductor ASA | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config REGULATOR_NRF_VREGUSB | ||
| bool "Nordic USB VBUS regulator driver" | ||
| default y | ||
| depends on DT_HAS_NORDIC_VREGUSB_REGULATOR_ENABLED | ||
| help | ||
| Enable Nordic USB VBUS regulator driver. | ||
|
|
||
| config REGULATOR_NRF_VREGUSB_INIT_PRIORITY | ||
| int "Nordic VBUS regulator driver init priority" | ||
| default KERNEL_INIT_PRIORITY_DEVICE | ||
| depends on REGULATOR_NRF_VREGUSB | ||
| help | ||
| Init priority for the Nordic USB VBUS regulator driver. |
|
carlescufi marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| /* | ||
| * Copyright Nordic Semiconductor ASA | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <nrfx.h> | ||
| #include <errno.h> | ||
| #include <stdint.h> | ||
| #include <zephyr/drivers/regulator.h> | ||
| #include <zephyr/logging/log.h> | ||
| #include <hal/nrf_vregusb.h> | ||
|
|
||
| LOG_MODULE_REGISTER(vregusb, CONFIG_REGULATOR_LOG_LEVEL); | ||
|
|
||
| struct vregusb_config { | ||
| struct regulator_common_config common; | ||
| NRF_VREGUSB_Type *base; | ||
| void (*irq_enable_func)(const struct device *dev); | ||
| void (*irq_disable_func)(const struct device *dev); | ||
| }; | ||
|
|
||
| struct vregusb_data { | ||
| struct regulator_common_data data; | ||
| regulator_callback_t cb; | ||
| const void *user_data; | ||
| }; | ||
|
|
||
| static void vregusb_isr(void *const arg) | ||
| { | ||
| const struct device *const dev = arg; | ||
| const struct vregusb_config *const config = dev->config; | ||
| struct vregusb_data *const data = dev->data; | ||
| NRF_VREGUSB_Type *const base = config->base; | ||
| struct regulator_event event; | ||
|
|
||
| if (nrf_vregusb_event_check(base, NRF_VREGUSB_EVENT_VBUS_DETECTED)) { | ||
| LOG_DBG("VBUS detected"); | ||
| nrf_vregusb_event_clear(base, NRF_VREGUSB_EVENT_VBUS_DETECTED); | ||
| event.type = REGULATOR_VOLTAGE_DETECTED; | ||
| } | ||
|
|
||
| if (nrf_vregusb_event_check(base, NRF_VREGUSB_EVENT_VBUS_REMOVED)) { | ||
| LOG_DBG("VBUS removed"); | ||
| nrf_vregusb_event_clear(base, NRF_VREGUSB_EVENT_VBUS_REMOVED); | ||
| event.type = REGULATOR_VOLTAGE_REMOVED; | ||
| } | ||
|
|
||
| if (data->cb != NULL) { | ||
| data->cb(dev, &event, data->user_data); | ||
| } | ||
| } | ||
|
|
||
| static int vregusb_enable(const struct device *const dev) | ||
| { | ||
| const struct vregusb_config *const config = dev->config; | ||
| NRF_VREGUSB_Type *const base = config->base; | ||
|
|
||
| nrf_vregusb_int_enable(base, NRF_VREGUSB_INT_VBUS_DETECTED_MASK | | ||
| NRF_VREGUSB_INT_VBUS_REMOVED_MASK); | ||
| config->irq_enable_func(dev); | ||
|
|
||
| nrf_vregusb_task_trigger(base, NRF_VREGUSB_TASK_START); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int vregusb_disable(const struct device *const dev) | ||
| { | ||
| const struct vregusb_config *const config = dev->config; | ||
| NRF_VREGUSB_Type *const base = config->base; | ||
|
|
||
| config->irq_disable_func(dev); | ||
| nrf_vregusb_task_trigger(base, NRF_VREGUSB_TASK_STOP); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int vregusb_set_callback(const struct device *const dev, | ||
| regulator_callback_t cb, const void *const user_data) | ||
| { | ||
| struct vregusb_data *const data = dev->data; | ||
|
|
||
| data->cb = cb; | ||
| data->user_data = user_data; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int regulator_vregusb_init(const struct device *const dev) | ||
| { | ||
| regulator_common_data_init(dev); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static DEVICE_API(regulator, api) = { | ||
| .enable = vregusb_enable, | ||
| .disable = vregusb_disable, | ||
| .set_callback = vregusb_set_callback, | ||
| }; | ||
|
|
||
| #define DT_DRV_COMPAT nordic_vregusb_regulator | ||
|
|
||
| #define REGULATOR_VREGUSB_DEFINE(n) \ | ||
| static void irq_enable_func_##n(const struct device *const dev) \ | ||
| { \ | ||
| IRQ_CONNECT(DT_INST_IRQN(n), \ | ||
| DT_INST_IRQ(n, priority), \ | ||
| vregusb_isr, \ | ||
| DEVICE_DT_INST_GET(n), \ | ||
| 0); \ | ||
| \ | ||
| irq_enable(DT_INST_IRQN(n)); \ | ||
| } \ | ||
| \ | ||
| static void irq_disable_func_##n(const struct device *const dev) \ | ||
| { \ | ||
| irq_disable(DT_INST_IRQN(n)); \ | ||
| } \ | ||
| \ | ||
| static struct vregusb_data data_##n; \ | ||
| \ | ||
| static const struct vregusb_config config_##n = { \ | ||
| .base = (void *)(DT_INST_REG_ADDR(n)), \ | ||
| .common = REGULATOR_DT_INST_COMMON_CONFIG_INIT(n), \ | ||
| .irq_enable_func = irq_enable_func_##n, \ | ||
| .irq_disable_func = irq_disable_func_##n, \ | ||
| }; \ | ||
| \ | ||
| DEVICE_DT_INST_DEFINE(n, regulator_vregusb_init, NULL, \ | ||
| &data_##n, &config_##n, \ | ||
| POST_KERNEL, \ | ||
| CONFIG_REGULATOR_NRF_VREGUSB_INIT_PRIORITY, &api);\ | ||
|
|
||
| DT_INST_FOREACH_STATUS_OKAY(REGULATOR_VREGUSB_DEFINE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright Nordic Semiconductor ASA | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| description: | | ||
| Nordic VBUS regulator for USB peripheral | ||
|
|
||
| compatible: "nordic,vregusb-regulator" | ||
|
|
||
| include: | ||
| - name: base.yaml | ||
| - name: regulator.yaml | ||
| property-allowlist: | ||
| - regulator-name | ||
|
|
||
| properties: | ||
| reg: | ||
| required: true | ||
|
|
||
| regulator-name: | ||
| required: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| description: | | ||
| Nordic wrapper for USB controller and PHY hardware. The wrapper is used to | ||
| configure, control, and enable/disable the USB PHY, and to enable/disable USB | ||
| controller. | ||
|
|
||
| compatible: "nordic,nrf-usbhs-wrapper" | ||
|
|
||
| include: [base.yaml] | ||
|
|
||
| properties: | ||
| reg: | ||
| required: true | ||
|
|
||
| regulator: | ||
| required: true | ||
| type: phandle | ||
| description: | | ||
| USB PHY and controller function depends on the USB regulator VREGUSB. | ||
|
Comment on lines
+14
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.