forked from Minki/linux
iio: adc: sc27xx_adc: Re-use generic struct u32_fract
Instead of a pair of u32 re-use generic struct u32_fract. No functional changes intended. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Cixi Geng <cixi.geng1@unisoc.com> Link: https://lore.kernel.org/r/20220530180910.2533-1-andriy.shevchenko@linux.intel.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
754d013433
commit
5a3ec28ada
@ -579,15 +579,14 @@ unlock_adc:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data,
|
static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, int channel, int scale,
|
||||||
int channel, int scale,
|
struct u32_fract *fract)
|
||||||
u32 *div_numerator, u32 *div_denominator)
|
|
||||||
{
|
{
|
||||||
u32 ratio;
|
u32 ratio;
|
||||||
|
|
||||||
ratio = data->var_data->get_ratio(channel, scale);
|
ratio = data->var_data->get_ratio(channel, scale);
|
||||||
*div_numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
|
fract->numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
|
||||||
*div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
|
fract->denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int adc_to_volt(struct sc27xx_adc_linear_graph *graph,
|
static int adc_to_volt(struct sc27xx_adc_linear_graph *graph,
|
||||||
@ -615,7 +614,7 @@ static int sc27xx_adc_to_volt(struct sc27xx_adc_linear_graph *graph,
|
|||||||
static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
|
static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
|
||||||
int scale, int raw_adc)
|
int scale, int raw_adc)
|
||||||
{
|
{
|
||||||
u32 numerator, denominator;
|
struct u32_fract fract;
|
||||||
u32 volt;
|
u32 volt;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -637,9 +636,9 @@ static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sc27xx_adc_volt_ratio(data, channel, scale, &numerator, &denominator);
|
sc27xx_adc_volt_ratio(data, channel, scale, &fract);
|
||||||
|
|
||||||
return DIV_ROUND_CLOSEST(volt * denominator, numerator);
|
return DIV_ROUND_CLOSEST(volt * fract.denominator, fract.numerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sc27xx_adc_read_processed(struct sc27xx_adc_data *data,
|
static int sc27xx_adc_read_processed(struct sc27xx_adc_data *data,
|
||||||
|
Loading…
Reference in New Issue
Block a user