iio: adc: aspeed: Add divider flag to fix incorrect voltage reading.
Subsystems (2)
Billy Tsai
reviewerPATCH v2 1/1 iio: adc: aspeed: Add divider flag to fix incorrect voltage reading.
The formula for the ADC sampling period in ast2400/ast2500 is:
ADC clock period = PCLK * 2 * (ADC0C[31:17] + 1) * (ADC0C[9:0]) When ADC0C[9:0] is set to 0 the sampling voltage will be lower than expected, because the hardware may not have enough time to charge/discharge to a stable voltage. This patch use the flag CLK_DIVIDER_ONE_BASED which will use the raw value read from the register, with the value of zero considered invalid to conform to the corrected formula.
--- drivers/iio/adc/aspeed_adc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/aspeed_adc.c +3 -1
@@ -539,7 +539,9 @@ static int aspeed_adc_probe(struct platform_device *pdev) data->clk_scaler =devm_clk_hw_register_divider ( &pdev->dev, clk_name, clk_parent_name, scaler_flags, data->base +ASPEED_REG_CLOCK_CONTROL ,0 , - data->model_data->scaler_bit_width,0 , &data->clk_lock); + data->model_data->scaler_bit_width, + data->model_data->need_prescaler ?CLK_DIVIDER_ONE_BASED :0 , + &data->clk_lock);if (IS_ERR (data->clk_scaler))return PTR_ERR (data->clk_scaler);
Signature · 1 line
2.25.1
Quoted 9 lines · Billy Tsai
The formula for the ADC sampling period in ast2400/ast2500 is:
ADC clock period = PCLK * 2 * (ADC0C[31:17] + 1) * (ADC0C[9:0]) When ADC0C[9:0] is set to 0 the sampling voltage will be lower than expected, because the hardware may not have enough time to charge/discharge to a stable voltage. This patch use the flagCLK_DIVIDER_ONE_BASEDwhich will use the raw value read from the register, with the value of zero considered invalid to conform to the corrected formula.
(to answer my own question)
..and this is okay on the 2600, because we do not set need_prescaler = true on that platform.
Quoted 26 lines
Fixes 573803234e72 ("iio: Aspeed ADC")Reported-by Konstantin Klubnichkin <[email protected]>Signed-off-by Billy Tsai <[email protected]>--- drivers/iio/adc/aspeed_adc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/adc/aspeed_adc.c +3
-2@@ -539,7 +539,9 @@ static int aspeed_adc_probe(struct platform_device *pdev) data->clk_scaler =devm_clk_hw_register_divider ( &pdev->dev, clk_name, clk_parent_name, scaler_flags, data->base +ASPEED_REG_CLOCK_CONTROL ,0 , - data->model_data->scaler_bit_width,0 , &data->clk_lock); + data->model_data->scaler_bit_width, + data->model_data->need_prescaler ?CLK_DIVIDER_ONE_BASED :0 , + &data->clk_lock);if (IS_ERR (data->clk_scaler))return PTR_ERR (data->clk_scaler); --2.25.1
Quoted 11 lines · On Mon, 21 Feb 2022 05:45:16 +0000 Joel Stanley <[email protected]> wrote:
Quoted 9 lines · Billy Tsai
The formula for the ADC sampling period in ast2400/ast2500 is:
ADC clock period = PCLK * 2 * (ADC0C[31:17] + 1) * (ADC0C[9:0]) When ADC0C[9:0] is set to 0 the sampling voltage will be lower than expected, because the hardware may not have enough time to charge/discharge to a stable voltage. This patch use the flagCLK_DIVIDER_ONE_BASEDwhich will use the raw value read from the register, with the value of zero considered invalid to conform to the corrected formula.
Quoted 6 lines
(to answer my own question)
..and this is okay on the 2600, because we do not set
need_prescaler= true on that platform.Reviewed-by Joel Stanley <[email protected]>
Applied to the fixes-togreg branch of iio.git.
Depending on how timing works out in the coming week I might just pull all the fixes in for the next merge window rather than doing a separate pull request.
Thanks,
Jonathan
Quoted 27 lines
Quoted 27 lines
Fixes 573803234e72 ("iio: Aspeed ADC")Reported-by Konstantin Klubnichkin <[email protected]>Signed-off-by Billy Tsai <[email protected]>--- drivers/iio/adc/aspeed_adc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/iio/adc/aspeed_adc.c +3
-2@@ -539,7 +539,9 @@ static int aspeed_adc_probe(struct platform_device *pdev) data->clk_scaler =devm_clk_hw_register_divider ( &pdev->dev, clk_name, clk_parent_name, scaler_flags, data->base +ASPEED_REG_CLOCK_CONTROL ,0 , - data->model_data->scaler_bit_width,0 , &data->clk_lock); + data->model_data->scaler_bit_width, + data->model_data->need_prescaler ?CLK_DIVIDER_ONE_BASED :0 , + &data->clk_lock);if (IS_ERR (data->clk_scaler))return PTR_ERR (data->clk_scaler); --2.25.1