Skip to content

Commit

Permalink
dts: bindings: lpadc: Add regulator phandle prop
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
decsny committed Jul 6, 2023
1 parent 8526af4 commit 7e3a925
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions drivers/adc/Kconfig.mcux
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 25 additions & 1 deletion drivers/adc/adc_mcux_lpadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

#include <errno.h>
#include <zephyr/drivers/adc.h>
#include <zephyr/sys/util.h>
#include <fsl_lpadc.h>
#include <zephyr/drivers/regulator.h>

#include <zephyr/drivers/pinctrl.h>

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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); \
Expand All @@ -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), \
Expand Down
1 change: 1 addition & 0 deletions dts/arm/nxp/nxp_lpc55S3x_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
offset-value-a = <10>;
offset-value-b = <10>;
#io-channel-cells = <1>;
required-regulators = <&vref0>;
};

can0: can@4009d000 {
Expand Down
4 changes: 4 additions & 0 deletions dts/bindings/adc/nxp,lpc-lpadc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7e3a925

Please sign in to comment.