drivers: lpadc: Update lpadc driver to use the latest feature

Updated nxp lpadc driver, because the phandle type property
'nxp,reference-supply' was removed, and a new phandle-array
type property 'nxp,references' added.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
This commit is contained in:
Zhaoxiang Jin 2024-06-27 17:28:34 +08:00 committed by Anas Nashif
parent 2eb61a82da
commit 630203de97

View File

@ -44,9 +44,10 @@ 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;
const struct device *ref_supplies;
const struct device *clock_dev;
clock_control_subsys_t clock_subsys;
int32_t ref_supply_val;
};
struct mcux_lpadc_data {
@ -123,9 +124,8 @@ static int mcux_lpadc_channel_setup(const struct device *dev,
const struct adc_channel_cfg *channel_cfg)
{
const struct mcux_lpadc_config *config = dev->config;
const struct device **regulator = config->ref_supplies;
uint16_t vref_mv = CONTAINER_OF(channel_cfg, struct adc_dt_spec, channel_cfg)->vref_mv;
int32_t vref_uv = (int32_t)((uint32_t)vref_mv * 1000);
const struct device *regulator = config->ref_supplies;
int32_t vref_uv = config->ref_supply_val * 1000;
struct mcux_lpadc_data *data = dev->data;
lpadc_conv_command_config_t *cmd;
uint8_t channel_side;
@ -212,8 +212,8 @@ static int mcux_lpadc_channel_setup(const struct device *dev,
*/
if (channel_cfg->reference == ADC_REF_EXTERNAL1) {
LOG_DBG("ref external1");
if (*regulator != NULL) {
err = regulator_set_voltage(*regulator, vref_uv, vref_uv);
if (regulator != NULL) {
err = regulator_set_voltage(regulator, vref_uv, vref_uv);
if (err < 0) {
return err;
}
@ -477,10 +477,10 @@ static int mcux_lpadc_init(const struct device *dev)
}
/* Enable necessary regulators */
const struct device **regulator = config->ref_supplies;
const struct device *regulator = config->ref_supplies;
while (*regulator != NULL) {
err = regulator_enable(*(regulator++));
if (regulator != NULL) {
err = regulator_enable(regulator);
if (err) {
return err;
}
@ -549,17 +549,7 @@ 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); \
\
@ -573,9 +563,15 @@ 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, \
.ref_supplies = COND_CODE_1(DT_INST_NODE_HAS_PROP(n, nxp_references),\
(DEVICE_DT_GET(DT_PHANDLE(DT_DRV_INST(n),\
nxp_references))), (NULL)),\
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
.clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name),\
.ref_supply_val = COND_CODE_1(\
DT_INST_NODE_HAS_PROP(n, nxp_references),\
(DT_PHA(DT_DRV_INST(n), nxp_references, vref_mv)), \
(0)),\
}; \
static struct mcux_lpadc_data mcux_lpadc_data_##n = { \
ADC_CONTEXT_INIT_TIMER(mcux_lpadc_data_##n, ctx), \