From fe8b112efd34c4feae67e7d42385827ecec4a8ed Mon Sep 17 00:00:00 2001 From: Declan Snyder Date: Wed, 12 Apr 2023 20:21:10 +0000 Subject: [PATCH] dts: bindings: lpadc: Add regulator phandle prop 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 --- drivers/adc/Kconfig.mcux | 1 + drivers/adc/adc_mcux_lpadc.c | 25 ++++++++++++++++++++++++- dts/arm/nxp/nxp_lpc55S3x_common.dtsi | 1 + dts/bindings/adc/nxp,lpc-lpadc.yaml | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/adc/Kconfig.mcux b/drivers/adc/Kconfig.mcux index c53ffeee468..725ec32c2c8 100644 --- a/drivers/adc/Kconfig.mcux +++ b/drivers/adc/Kconfig.mcux @@ -30,6 +30,7 @@ config ADC_MCUX_LPADC bool "MCUX LPADC driver" default y select ADC_CONFIGURABLE_INPUTS + select REGULATOR depends on DT_HAS_NXP_LPC_LPADC_ENABLED help Enable the MCUX LPADC driver. diff --git a/drivers/adc/adc_mcux_lpadc.c b/drivers/adc/adc_mcux_lpadc.c index c9ea7197c2b..b15790ccb9d 100644 --- a/drivers/adc/adc_mcux_lpadc.c +++ b/drivers/adc/adc_mcux_lpadc.c @@ -13,7 +13,9 @@ #include #include +#include #include +#include #include @@ -43,6 +45,7 @@ struct mcux_lpadc_config { uint32_t offset_b; void (*irq_config_func)(const struct device *dev); const struct pinctrl_dev_config *pincfg; + const struct device **ref_supplies; }; struct mcux_lpadc_data { @@ -392,6 +395,16 @@ static int mcux_lpadc_init(const struct device *dev) return err; } + /* Enable necessary regulators */ + const struct device **regulator = config->ref_supplies; + + while (*regulator != NULL) { + err = regulator_enable(*(regulator++)); + if (err) { + return err; + } + } + LPADC_GetDefaultConfig(&adc_config); adc_config.enableAnalogPreliminary = true; @@ -455,8 +468,18 @@ static const struct adc_driver_api mcux_lpadc_driver_api = { #endif }; +#define LPADC_REGULATOR_DEPENDENCY(node_id, prop, idx) \ + DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), + +#define LPADC_REGULATORS_DEFINE(inst) \ + static const struct device *mcux_lpadc_ref_supplies_##inst[] = { \ + COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, nxp_reference_supply), \ + (DT_INST_FOREACH_PROP_ELEM(inst, nxp_reference_supply, \ + LPADC_REGULATOR_DEPENDENCY)), ()) NULL}; #define LPADC_MCUX_INIT(n) \ + LPADC_REGULATORS_DEFINE(n) \ + \ static void mcux_lpadc_config_func_##n(const struct device *dev); \ \ PINCTRL_DT_INST_DEFINE(n); \ @@ -469,8 +492,8 @@ static const struct adc_driver_api mcux_lpadc_driver_api = { .offset_b = DT_INST_PROP(n, offset_value_b), \ .irq_config_func = mcux_lpadc_config_func_##n, \ .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ + .ref_supplies = mcux_lpadc_ref_supplies_##n, \ }; \ - \ static struct mcux_lpadc_data mcux_lpadc_data_##n = { \ ADC_CONTEXT_INIT_TIMER(mcux_lpadc_data_##n, ctx), \ ADC_CONTEXT_INIT_LOCK(mcux_lpadc_data_##n, ctx), \ diff --git a/dts/arm/nxp/nxp_lpc55S3x_common.dtsi b/dts/arm/nxp/nxp_lpc55S3x_common.dtsi index 99b105fbf81..24b326f2ce8 100644 --- a/dts/arm/nxp/nxp_lpc55S3x_common.dtsi +++ b/dts/arm/nxp/nxp_lpc55S3x_common.dtsi @@ -292,6 +292,7 @@ #io-channel-cells = <1>; dmas = <&dma0 21>, <&dma0 22>; dma-names = "adc0-dma0", "adc0-dma1"; + nxp,reference-supply = <&vref0>; }; dac0: dac@b2000 { diff --git a/dts/bindings/adc/nxp,lpc-lpadc.yaml b/dts/bindings/adc/nxp,lpc-lpadc.yaml index 0a8c2c74783..75b9c7fa357 100644 --- a/dts/bindings/adc/nxp,lpc-lpadc.yaml +++ b/dts/bindings/adc/nxp,lpc-lpadc.yaml @@ -71,6 +71,10 @@ properties: required: true description: Offset value B to use if CONFIG_LPADC_DO_OFFSET_CALIBRATION is false + nxp,reference-supply: + type: phandles + description: References to required regulators which must be enabled for LPADC to function + "#io-channel-cells": const: 1