Skip to content

Commit

Permalink
adc: aspeed: Fix the order of adc engine init.
Browse files Browse the repository at this point in the history
The channel cannot be enabled before the engine is initiated.

Signed-off-by: Billy Tsai <[email protected]>
Change-Id: I61b15a7f8c4d131be0e4bfe9cffe86be26cc3070
  • Loading branch information
billy-tsai committed Jul 11, 2023
1 parent fa0e851 commit 6ad1816
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions drivers/adc/aspeed/adc_aspeed.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down

0 comments on commit 6ad1816

Please sign in to comment.