Skip to content
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

drivers: regulator: Add NXP VREF driver #56822

Merged
merged 4 commits into from Sep 21, 2023

Conversation

decsny
Copy link
Member

@decsny decsny commented Apr 13, 2023

VREF is a peripheral on NXP's LPC55S36 which generates a reference voltage and can take advantage of an internal regulator to keep the signal stable. This SOC peripheral fits nicely into the Zephyr regulator API, so in this PR I am adding a Zephyr native driver for this peripheral. To show that it is somewhat functional, I replaced the VREF SDK code in init for LPC55S36, which is needed to use LPADC, with a call to enable the regulator(s) in the LPADC driver that it needs to function.

dts/bindings/regulator/nxp,vref.yaml Outdated Show resolved Hide resolved
dts/bindings/regulator/nxp,vref.yaml Outdated Show resolved Hide resolved
dts/bindings/regulator/nxp,vref.yaml Show resolved Hide resolved
dts/bindings/regulator/nxp,vref.yaml Outdated Show resolved Hide resolved
drivers/regulator/regulator_nxp_vref.c Outdated Show resolved Hide resolved
drivers/regulator/regulator_nxp_vref.c Outdated Show resolved Hide resolved
boards/arm/lpcxpresso55s36/lpcxpresso55s36_defconfig Outdated Show resolved Hide resolved
dts/bindings/iio/adc/nxp,lpc-lpadc.yaml Outdated Show resolved Hide resolved
drivers/adc/adc_mcux_lpadc.c Outdated Show resolved Hide resolved
drivers/adc/adc_mcux_lpadc.c Outdated Show resolved Hide resolved
drivers/regulator/regulator_nxp_vref.c Show resolved Hide resolved
const struct regulator_nxp_vref_config *config = dev->config;
const VREF_Type *base = (VREF_Type *) config->base;

volatile uint32_t *const csr = (volatile uint32_t *const) &base->CSR;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why declare this? You can just reference base->CSR in the function. I guess compiler should optimize this anyways, just not sure why we add it.

drivers/regulator/regulator_nxp_vref.c Outdated Show resolved Hide resolved
* Disable HC Bandgap, LP Bandgap, and Buf21
* to achieve "Off" mode of VREF
*/
*csr &= ~VREF_CSR_HCBGEN_MASK;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't seen like the VREF_CSR_BUF21EN_MASK is being cleared here, contrary to what comment suggests.

drivers/regulator/regulator_nxp_vref.c Show resolved Hide resolved
dts/bindings/iio/adc/nxp,lpc-lpadc.yaml Outdated Show resolved Hide resolved
@decsny decsny force-pushed the feature/nxp_vref branch 3 times, most recently from 4d1f4a7 to 658e052 Compare April 19, 2023 16:57
@github-actions github-actions bot added the Stale label Jun 25, 2023
@DerekSnell DerekSnell removed the Stale label Jun 25, 2023
@zephyrproject-rtos zephyrproject-rtos deleted a comment from github-actions bot Jun 25, 2023
@decsny decsny force-pushed the feature/nxp_vref branch 2 times, most recently from 0659acb to a5759a6 Compare July 6, 2023 20:01
drivers/adc/adc_mcux_lpadc.c Outdated Show resolved Hide resolved
drivers/adc/adc_mcux_lpadc.c Show resolved Hide resolved
@decsny
Copy link
Member Author

decsny commented Aug 21, 2023

@gmarull can you revisit this PR? I marked your comments as resolved if I thought I addressed them just to navigate the thread easier, but feel free to unresolve if needed. I would like to make progress on this because there are multiple platforms and multiple other IP blocks that depend on this one.

soc/arm/nxp_lpc/lpc55xxx/soc.c Show resolved Hide resolved
dts/arm/nxp/nxp_lpc55S3x_common.dtsi Show resolved Hide resolved
drivers/regulator/regulator_nxp_vref.c Outdated Show resolved Hide resolved
drivers/regulator/regulator_nxp_vref.c Outdated Show resolved Hide resolved
drivers/regulator/regulator_nxp_vref.c Outdated Show resolved Hide resolved
include/zephyr/dt-bindings/regulator/nxp_vref.h Outdated Show resolved Hide resolved
dts/arm/nxp/nxp_lpc55S3x_common.dtsi Outdated Show resolved Hide resolved
@decsny
Copy link
Member Author

decsny commented Sep 18, 2023

@gmarull I think I addressed your comments, can you check?

Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

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

lgtm, a few nitpicks

drivers/adc/adc_mcux_lpadc.c Outdated Show resolved Hide resolved
drivers/regulator/regulator_nxp_vref.c Outdated Show resolved Hide resolved
drivers/regulator/regulator_nxp_vref.c Outdated Show resolved Hide resolved
Add binding, include header, and driver for NXP VREF IP block.

NXP VREF is an internal voltage reference generator on some SOCs
that fits well with the regulator API in zephyr.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Add node for VREF0 peripheral to LPC55S3X SOC DT

Clock VREF peripheral if status = okay in DT

Enable VREF on lpcxpresso55s36

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Add phandle prop to reference any regulator that must
be enabled in order for the LPADC to function as intended.

Change LPADC driver to use this property if present.

LPADC on LPC55S36 depends on VREF peripheral, enable for this platform.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Support lpcxpresso55s36 on regulator voltage test using VREF

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
@gmarull
Copy link
Member

gmarull commented Sep 20, 2023

@danieldegrasse @aasinclair review ping

@carlescufi carlescufi merged commit a9750d4 into zephyrproject-rtos:main Sep 21, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ADC Analog-to-Digital Converter (ADC) area: Devicetree Binding PR modifies or adds a Device Tree binding area: Regulators platform: NXP NXP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants