From 7e3a925bd29297f435ad75ae56432a3228197746 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 | 26 +++++++++++++++++++++++++- dts/arm/nxp/nxp_lpc55S3x_common.dtsi | 1 + dts/bindings/adc/nxp,lpc-lpadc.yaml | 4 ++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/adc/Kconfig.mcux b/drivers/adc/Kconfig.mcux index c53ffeee468c1b1..725ec32c2c89264 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 4640155b419a258..322a82b0848e861 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 **req_regulators; }; struct mcux_lpadc_data { @@ -387,10 +390,22 @@ static int mcux_lpadc_init(const struct device *dev) lpadc_config_t adc_config; int err; +#ifdef CONFIG_PINCTRL err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); if (err) { return err; } +#endif + + /* Enable necessary regulators */ + const struct device **regulator = config->req_regulators; + + while (*regulator != NULL) { + err = regulator_enable(*(regulator++)); + if (err) { + return err; + } + } LPADC_GetDefaultConfig(&adc_config); @@ -455,8 +470,17 @@ 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_req_regulators_##inst[] = { \ + DT_INST_FOREACH_PROP_ELEM(inst, required_regulators, \ + 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 +493,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), \ + .req_regulators = mcux_lpadc_req_regulators_##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 d6bed2f89b81926..fa07bdaa4734ca1 100644 --- a/dts/arm/nxp/nxp_lpc55S3x_common.dtsi +++ b/dts/arm/nxp/nxp_lpc55S3x_common.dtsi @@ -247,6 +247,7 @@ offset-value-a = <10>; offset-value-b = <10>; #io-channel-cells = <1>; + required-regulators = <&vref0>; }; can0: can@4009d000 { diff --git a/dts/bindings/adc/nxp,lpc-lpadc.yaml b/dts/bindings/adc/nxp,lpc-lpadc.yaml index 0a8c2c74783ee19..d26b0305a34810e 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 + required-regulators: + type: phandles + description: References to required regulators which must be enabled for LPADC to function + "#io-channel-cells": const: 1