-
Notifications
You must be signed in to change notification settings - Fork 8.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
base: main
Are you sure you want to change the base?
Changes from all commits
9511d52
ee590b3
2948be3
9fe1890
7e1c491
3d7218b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. |
|
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. Implementation of this reg in nrfx may help reach USB support in NCS bare metal option. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /* | ||
| * Copyright Nordic Semiconductor ASA | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <nrf.h> | ||
| #include <errno.h> | ||
| #include <stdint.h> | ||
| #include <zephyr/drivers/regulator.h> | ||
| #include <zephyr/logging/log.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 (base->EVENTS_VBUSDETECTED) { | ||
| LOG_DBG("VBUS detected"); | ||
| base->EVENTS_VBUSDETECTED = 0; | ||
| event.type = REGULATOR_VOLTAGE_DETECTED; | ||
| } | ||
|
|
||
| if (base->EVENTS_VBUSREMOVED) { | ||
| LOG_DBG("VBUS removed"); | ||
| base->EVENTS_VBUSREMOVED = 0; | ||
| 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; | ||
|
|
||
| base->INTEN = VREGUSB_INTEN_VBUSDETECTED_Msk | VREGUSB_INTEN_VBUSREMOVED_Msk; | ||
| config->irq_enable_func(dev); | ||
|
|
||
| base->TASKS_START = 1; | ||
|
|
||
| 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); | ||
| base->TASKS_STOP = 1; | ||
|
|
||
| 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) |
| 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 |
| 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
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 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,17 +210,24 @@ | |
| prescaler = <0>; | ||
| }; | ||
|
|
||
| usbhs: usbhs@5a000 { | ||
| compatible = "nordic,nrf-usbhs-nrf54l", "snps,dwc2"; | ||
| reg = <0x5a000 0x1000>, <0x50020000 0x1a000>; | ||
| reg-names = "wrapper", "core"; | ||
| interrupts = <90 NRF_DEFAULT_IRQ_PRIORITY>; | ||
| num-in-eps = <16>; | ||
| num-out-eps = <16>; | ||
| ghwcfg1 = <0x0>; | ||
| ghwcfg2 = <0x22affc52>; | ||
| ghwcfg4 = <0x3e10aa60>; | ||
| status = "disabled"; | ||
| usbhs_wrapper: usbhs_wrapper@5a000 { | ||
| compatible = "nordic,nrf-usbhs-wrapper"; | ||
| reg = <0x5a000 0x1000>; | ||
| regulator = <&vregusb>; | ||
| #address-cells = <1>; | ||
| #size-cells = <1>; | ||
|
Comment on lines
+213
to
+218
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. Could you expand on what the wrapper does? 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. In short USBHS wrapper provides a way to enable underlying DWC2 controller (core), enable power to both core and USB PHY, configure USB PHY and make it possible to get core and USB PHY out of reset. |
||
|
|
||
| usbhs: usbhs@50020000 { | ||
| compatible = "nordic,nrf-usbhs-nrf54l", "snps,dwc2"; | ||
| reg = <0x50020000 0x1a000>; | ||
| interrupts = <90 NRF_DEFAULT_IRQ_PRIORITY>; | ||
| num-in-eps = <16>; | ||
| num-out-eps = <16>; | ||
| ghwcfg1 = <0x0>; | ||
| ghwcfg2 = <0x22affc52>; | ||
| ghwcfg4 = <0x3e10aa60>; | ||
| status = "disabled"; | ||
| }; | ||
| }; | ||
|
|
||
| dppic10: dppic@82000 { | ||
|
|
@@ -827,6 +834,14 @@ | |
| regulator-name = "VREGMAIN"; | ||
| regulator-initial-mode = <NRF5X_REG_MODE_LDO>; | ||
| }; | ||
|
|
||
| vregusb: regulator@50121000 { | ||
| compatible = "nordic,vregusb-regulator"; | ||
| reg = <0x50121000 0x1>; | ||
| interrupts = <289 NRF_DEFAULT_IRQ_PRIORITY>; | ||
| status = "disabled"; | ||
| regulator-name = "VREGUSB"; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
|
|
||
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.
This should be implemented on top of aligned/extended
nrfx_power_usb*API.