From 6ad1816ac68818eaa43d02afb41f907b7ffc8a5b Mon Sep 17 00:00:00 2001 From: Billy Tsai Date: Tue, 11 Jul 2023 19:29:05 +0800 Subject: [PATCH] adc: aspeed: Fix the order of adc engine init. The channel cannot be enabled before the engine is initiated. Signed-off-by: Billy Tsai Change-Id: I61b15a7f8c4d131be0e4bfe9cffe86be26cc3070 --- drivers/adc/aspeed/adc_aspeed.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/drivers/adc/aspeed/adc_aspeed.c b/drivers/adc/aspeed/adc_aspeed.c index 583285007ad..0dad98bd41f 100644 --- a/drivers/adc/aspeed/adc_aspeed.c +++ b/drivers/adc/aspeed/adc_aspeed.c @@ -447,22 +447,6 @@ static void aspeed_acquisition_thread(struct adc_aspeed_data *data) } } -static void adc_aspeed_channel_config(const struct device *dev) -{ - const struct adc_aspeed_cfg *config = DEV_CFG(dev); - struct adc_aspeed_data *priv = DEV_DATA(dev); - struct adc_register_s *adc_register = config->base; - union adc_engine_control_s engine_ctrl; - - engine_ctrl.value = adc_register->engine_ctrl.value; - engine_ctrl.fields.channel_enable = config->channels_used; - adc_register->engine_ctrl.value = engine_ctrl.value; - - priv->required_eoc_num = popcount(config->channels_used); - if (config->channels_used & BIT(ASPEED_ADC_CH_NUMBER - 1)) - priv->required_eoc_num += 12; -} - static int adc_aspeed_engine_init(const struct device *dev, uint32_t timeout_ms) { @@ -484,6 +468,10 @@ static int adc_aspeed_engine_init(const struct device *dev, return ret; } + engine_ctrl.value = adc_register->engine_ctrl.value; + engine_ctrl.fields.channel_enable = config->channels_used; + adc_register->engine_ctrl.value = engine_ctrl.value; + return 0; } @@ -507,7 +495,9 @@ static int adc_aspeed_init(const struct device *dev) return ret; } - adc_aspeed_channel_config(dev); + priv->required_eoc_num = popcount(config->channels_used); + if (config->channels_used & BIT(ASPEED_ADC_CH_NUMBER - 1)) + priv->required_eoc_num += 12; ret = adc_aspeed_set_rate(dev, ASPEED_SAMPLING_RATE_DEFAULT); if (ret) { return ret;