Skip to contentSkip to conversation

iio: adc: sc27xx_adc: Re-use generic struct u32_fract

PATCH Applied Andy Shevchenko 3 participants 4 messages May 30, 2022 – Jun 12, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: sc27xx_adc: Re-use generic struct u32_fract

Instead of custom data type re-use generic struct u32_fract. No changes intended.

---
 drivers/iio/adc/sc27xx_adc.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/iio/adc/sc27xx_adc.c +7 -8
index e9ff2d6a8a57..f8421cbba8fa 100644
@@ -579,15 +579,14 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
 	return ret;
 }
 
-static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data,
-				  int channel, int scale,
-				  u32 *div_numerator, u32 *div_denominator)
+static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, int channel, int scale,
+				  struct u32_fract *fract)
 {
 	u32 ratio;
 
 	ratio = data->var_data->get_ratio(channel, scale);
-	*div_numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
-	*div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
+	fract->numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
+	fract->denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
 }
 
 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,
 				   int scale, int raw_adc)
 {
-	u32 numerator, denominator;
+	struct u32_fract fract;
 	u32 volt;
 
 	/*
@@ -637,9 +636,9 @@ static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
 		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,
Signature · 1 line
2.35.1
maintainer
#1 lore raw
Quoted 1 line · On Mon, 30 May 2022 21:09:10 +0300 Andy Shevchenko…

Instead of custom data type re-use generic struct u32_fract.

There isn't a custom data type - I'll reword this whilst applying if there is no reason for a v2.

Quoted 1 line

No changes intended.

functional changes

Quoted 2 lines

Given they have been active recently I'd ideally like Cixi Geng to take a quick glance at this before I apply it.

Thanks,

Jonathan

Quoted 49 lines
---
 drivers/iio/adc/sc27xx_adc.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/iio/adc/sc27xx_adc.c +7 -8
index e9ff2d6a8a57..f8421cbba8fa 100644
@@ -579,15 +579,14 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
 	return ret;
 }
 
-static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data,
-				  int channel, int scale,
-				  u32 *div_numerator, u32 *div_denominator)
+static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, int channel, int scale,
+				  struct u32_fract *fract)
 {
 	u32 ratio;
 
 	ratio = data->var_data->get_ratio(channel, scale);
-	*div_numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
-	*div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
+	fract->numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
+	fract->denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
 }
 
 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,
 				   int scale, int raw_adc)
 {
-	u32 numerator, denominator;
+	struct u32_fract fract;
 	u32 volt;
 
 	/*
@@ -637,9 +636,9 @@ static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
 		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,
Acked-by
#2 lore raw
Quoted 9 lines · Jonathan Cameron <[email protected]> 于2022年6月4日周六 01:44写道:
Quoted 1 line · On Mon, 30 May 2022 21:09:10 +0300 Andy Shevchenko…

Instead of custom data type re-use generic struct u32_fract.

There isn't a custom data type - I'll reword this whilst applying if there is no reason for a v2.

Quoted 8 lines
Quoted 1 line

No changes intended.

functional changes

Quoted 2 lines

Given they have been active recently I'd ideally like Cixi Geng to take a quick glance at this before I apply it.

Quoted 55 lines

Thanks,

Jonathan

Quoted 49 lines
---
 drivers/iio/adc/sc27xx_adc.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/iio/adc/sc27xx_adc.c +7 -8
index e9ff2d6a8a57..f8421cbba8fa 100644
@@ -579,15 +579,14 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
      return ret;
 }
 
-static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data,
-                               int channel, int scale,
-                               u32 *div_numerator, u32 *div_denominator)
+static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, int channel, int scale,
+                               struct u32_fract *fract)
 {
      u32 ratio;
 
      ratio = data->var_data->get_ratio(channel, scale);
-     *div_numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
-     *div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
+     fract->numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
+     fract->denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
 }
 
 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,
                                 int scale, int raw_adc)
 {
-     u32 numerator, denominator;
+     struct u32_fract fract;
      u32 volt;
 
      /*
@@ -637,9 +636,9 @@ static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
              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,
maintainer Applied
#3 lore raw
Quoted 12 lines · On Mon, 6 Jun 2022 11:12:15 +0800 Cixi Geng <[email protected]> wrote:
Quoted 11 lines · Jonathan Cameron <[email protected]> 于2022年6月4日周六 01:44写道:
Quoted 1 line · On Mon, 30 May 2022 21:09:10 +0300 Andy Shevchenko…

Instead of custom data type re-use generic struct u32_fract.

There isn't a custom data type - I'll reword this whilst applying if there is no reason for a v2.

Quoted 1 line

No changes intended.

Quoted 7 lines
Quoted 6 lines

functional changes

Quoted 2 lines

Given they have been active recently I'd ideally like Cixi Geng to take a quick glance at this before I apply it.

Applied to the togreg branch of iio.git and will be pushed out initially as testing for 0-day to take a look.

Thanks,

Jonathan

Quoted 55 lines
Quoted 55 lines

Thanks,

Jonathan

Quoted 49 lines
---
 drivers/iio/adc/sc27xx_adc.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/iio/adc/sc27xx_adc.c +7 -8
index e9ff2d6a8a57..f8421cbba8fa 100644
@@ -579,15 +579,14 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
      return ret;
 }
 
-static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data,
-                               int channel, int scale,
-                               u32 *div_numerator, u32 *div_denominator)
+static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, int channel, int scale,
+                               struct u32_fract *fract)
 {
      u32 ratio;
 
      ratio = data->var_data->get_ratio(channel, scale);
-     *div_numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
-     *div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
+     fract->numerator = ratio >> SC27XX_RATIO_NUMERATOR_OFFSET;
+     fract->denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
 }
 
 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,
                                 int scale, int raw_adc)
 {
-     u32 numerator, denominator;
+     struct u32_fract fract;
      u32 volt;
 
      /*
@@ -637,9 +636,9 @@ static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
              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,