Skip to contentSkip to conversation

iio: adc: rockchip_saradc: just get referenced voltage once at probe

PATCH In review Simon Xue 4 participants 7 messages Aug 2, 2021 – Aug 6, 2021

Subsystems (2)
lore
Share & tools
lore

Simon Xue

author
#0 lore raw

PATCH 1/1 iio: adc: rockchip_saradc: just get referenced voltage once at probe

From: David Wu <[email protected]>

The referenced voltage is not changed after initiation, so just only get referenced voltage once.

---
 drivers/iio/adc/rockchip_saradc.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/iio/adc/rockchip_saradc.c +9 -7
index f3eb8d2e50dc..cd33c0b9d3eb 100644
@@ -49,6 +49,7 @@ struct rockchip_saradc {
 	struct clk		*clk;
 	struct completion	completion;
 	struct regulator	*vref;
+	int			uv_vref;
 	struct reset_control	*reset;
 	const struct rockchip_saradc_data *data;
 	u16			last_val;
@@ -105,13 +106,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
 		mutex_unlock(&indio_dev->mlock);
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
-		ret = regulator_get_voltage(info->vref);
-		if (ret < 0) {
-			dev_err(&indio_dev->dev, "failed to get voltage\n");
-			return ret;
-		}
-
-		*val = ret / 1000;
+		*val = info->uv_vref / 1000;
 		*val2 = chan->scan_type.realbits;
 		return IIO_VAL_FRACTIONAL_LOG2;
 	default:
@@ -410,6 +405,13 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	info->uv_vref = regulator_get_voltage(info->vref);
+	if (info->uv_vref < 0) {
+		dev_err(&pdev->dev, "failed to get voltage\n");
+		ret = info->uv_vref;
+		return ret;
+	}
+
 	ret = clk_prepare_enable(info->pclk);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to enable pclk\n");
Signature · 1 line
2.25.1
#1 lore raw
Quoted 4 lines · On Mon, 2 Aug 2021 17:09:29 +0800 Simon Xue <[email protected]> wrote:

From: David Wu <[email protected]>

The referenced voltage is not changed after initiation, so just only get referenced voltage once.

Hi David,

Isn't this an external reference voltage? If so how do you know it is not changed at runtime? It might be unlikely and not happen on particular platforms, but that's not he same as saying it can never happen. Clearly it's racey anyway if that does happen, but we definitely don't expect frequent voltage changes.

Jonathan

Quoted 48 lines
---
 drivers/iio/adc/rockchip_saradc.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/iio/adc/rockchip_saradc.c +9 -7
index f3eb8d2e50dc..cd33c0b9d3eb 100644
@@ -49,6 +49,7 @@ struct rockchip_saradc {
 	struct clk		*clk;
 	struct completion	completion;
 	struct regulator	*vref;
+	int			uv_vref;
 	struct reset_control	*reset;
 	const struct rockchip_saradc_data *data;
 	u16			last_val;
@@ -105,13 +106,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
 		mutex_unlock(&indio_dev->mlock);
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
-		ret = regulator_get_voltage(info->vref);
-		if (ret < 0) {
-			dev_err(&indio_dev->dev, "failed to get voltage\n");
-			return ret;
-		}
-
-		*val = ret / 1000;
+		*val = info->uv_vref / 1000;
 		*val2 = chan->scan_type.realbits;
 		return IIO_VAL_FRACTIONAL_LOG2;
 	default:
@@ -410,6 +405,13 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	info->uv_vref = regulator_get_voltage(info->vref);
+	if (info->uv_vref < 0) {
+		dev_err(&pdev->dev, "failed to get voltage\n");
+		ret = info->uv_vref;
+		return ret;
+	}
+
 	ret = clk_prepare_enable(info->pclk);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to enable pclk\n");
#2 lore raw

Hi Jonathan,

Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · On Mon, 2 Aug 2021 17:09:29 +0800 Simon Xue <[email protected]> wrote:

From: David Wu <[email protected]>

The referenced voltage is not changed after initiation, so just only get referenced voltage once.

Quoted 8 lines

Hi David,

Isn't this an external reference voltage? If so how do you know it is not changed at runtime? It might be unlikely and not happen on particular platforms, but that's not he same as saying it can never happen. Clearly it's racey anyway if that does happen, but we definitely don't expect frequent voltage changes.

The current regulator is not changed and not subject to external changes, this can reduce the getting voltage. Assuming that there will be changes in the future, we then add the notify of the regulator, so that the voltage change can be obtained.

Quoted 40 lines

Jonathan

Quoted 38 lines
---
  drivers/iio/adc/rockchip_saradc.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
drivers/iio/adc/rockchip_saradc.c +2 -7
index f3eb8d2e50dc..cd33c0b9d3eb 100644
@@ -49,6 +49,7 @@ struct rockchip_saradc {
  	struct clk		*clk;
  	struct completion	completion;
  	struct regulator	*vref;
+	int			uv_vref;
  	struct reset_control	*reset;
  	const struct rockchip_saradc_data *data;
  	u16			last_val;
@@ -105,13 +106,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
  		mutex_unlock(&indio_dev->mlock);
  		return IIO_VAL_INT;
  	case IIO_CHAN_INFO_SCALE:
-		ret = regulator_get_voltage(info->vref);
-		if (ret < 0) {
-			dev_err(&indio_dev->dev, "failed to get voltage\n");
-			return ret;
-		}
-
-		*val = ret / 1000;
+		*val = info->uv_vref / 1000;
  		*val2 = chan->scan_type.realbits;
  		return IIO_VAL_FRACTIONAL_LOG2;
  	default:
@@ -410,6 +405,13 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
  		return ret;
  	}
 
Quoted 14 lines

drivers/iio/adc/rockchip_saradc.c static int rockchip_saradc_probe(struct platform_device *pdev) · line 417

Quoted 10 lines
drivers/iio/adc/rockchip_saradc.c +7 -0
+	info->uv_vref = regulator_get_voltage(info->vref);
+	if (info->uv_vref < 0) {
+		dev_err(&pdev->dev, "failed to get voltage\n");
+		ret = info->uv_vref;
+		return ret;
+	}
+
  	ret = clk_prepare_enable(info->pclk);
  	if (ret < 0) {
  		dev_err(&pdev->dev, "failed to enable pclk\n");

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#3 lore raw
Quoted 19 lines · On Tue, 3 Aug 2021 11:09:47 +0800 David Wu <[email protected]> wrote:

Hi Jonathan,

Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · On Mon, 2 Aug 2021 17:09:29 +0800 Simon Xue <[email protected]> wrote:

From: David Wu <[email protected]>

The referenced voltage is not changed after initiation, so just only get referenced voltage once.

Quoted 8 lines

Hi David,

Isn't this an external reference voltage? If so how do you know it is not changed at runtime? It might be unlikely and not happen on particular platforms, but that's not he same as saying it can never happen. Clearly it's racey anyway if that does happen, but we definitely don't expect frequent voltage changes.

Quoted 4 lines

The current regulator is not changed and not subject to external changes, this can reduce the getting voltage. Assuming that there will be changes in the future, we then add the notify of the regulator, so that the voltage change can be obtained.

If this patch added the notifier that would be a nice solution, but right now it potentially introduced a regression. You have made me a little curious... Are you seeing a significant cost to querying that regulator voltage?
If so, I'd imagine it's a lack of caching in the regulator driver or similar. Scale readback via sysfs shouldn't be in a fast path anyway.

You can't depend on what boards today do, because someone with a board built tomorrow may well use an old kernel which supports the voltage changing, and then see a regression when they upgrade to the kernel containing this patch.

Jonathan

Quoted 57 lines
Quoted 55 lines

Jonathan

Quoted 48 lines
---
  drivers/iio/adc/rockchip_saradc.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
drivers/iio/adc/rockchip_saradc.c +9 -7
index f3eb8d2e50dc..cd33c0b9d3eb 100644
@@ -49,6 +49,7 @@ struct rockchip_saradc {
  	struct clk		*clk;
  	struct completion	completion;
  	struct regulator	*vref;
+	int			uv_vref;
  	struct reset_control	*reset;
  	const struct rockchip_saradc_data *data;
  	u16			last_val;
@@ -105,13 +106,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
  		mutex_unlock(&indio_dev->mlock);
  		return IIO_VAL_INT;
  	case IIO_CHAN_INFO_SCALE:
-		ret = regulator_get_voltage(info->vref);
-		if (ret < 0) {
-			dev_err(&indio_dev->dev, "failed to get voltage\n");
-			return ret;
-		}
-
-		*val = ret / 1000;
+		*val = info->uv_vref / 1000;
  		*val2 = chan->scan_type.realbits;
  		return IIO_VAL_FRACTIONAL_LOG2;
  	default:
@@ -410,6 +405,13 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
  		return ret;
  	}
 
+	info->uv_vref = regulator_get_voltage(info->vref);
+	if (info->uv_vref < 0) {
+		dev_err(&pdev->dev, "failed to get voltage\n");
+		ret = info->uv_vref;
+		return ret;
+	}
+
  	ret = clk_prepare_enable(info->pclk);
  	if (ret < 0) {
  		dev_err(&pdev->dev, "failed to enable pclk\n");  
#4 lore raw

Hi Jonathan,

Quoted 33 lines · Jonathan Cameron
Quoted 19 lines · On Tue, 3 Aug 2021 11:09:47 +0800 David Wu <[email protected]> wrote:

Hi Jonathan,

Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · On Mon, 2 Aug 2021 17:09:29 +0800 Simon Xue <[email protected]> wrote:

From: David Wu <[email protected]>

The referenced voltage is not changed after initiation, so just only get referenced voltage once.

Quoted 8 lines

Hi David,

Isn't this an external reference voltage? If so how do you know it is not changed at runtime? It might be unlikely and not happen on particular platforms, but that's not he same as saying it can never happen. Clearly it's racey anyway if that does happen, but we definitely don't expect frequent voltage changes.

Quoted 4 lines

The current regulator is not changed and not subject to external changes, this can reduce the getting voltage. Assuming that there will be changes in the future, we then add the notify of the regulator, so that the voltage change can be obtained.

If this patch added the notifier that would be a nice solution, but right now it potentially introduced a regression. You have made me a little curious... Are you seeing a significant cost to querying that regulator voltage?
If so, I'd imagine it's a lack of caching in the regulator driver or similar. Scale readback via sysfs shouldn't be in a fast path anyway.

Quoted 5 lines

You can't depend on what boards today do, because someone with a board built tomorrow may well use an old kernel which supports the voltage changing, and then see a regression when they upgrade to the kernel containing this patch.

For all current chips, the expected voltage is a fixed voltage, and don't want to change it in any process.:-)

So, if the voltage here does not change, then it can be obtained once in probe(), which can save the time of each acquisition. For example, the voltage of this regulator is obtained through i2c, which will increase some consumption every time.

Quoted 63 lines

Jonathan

Quoted 57 lines
Quoted 55 lines

Jonathan

Quoted 48 lines
---
   drivers/iio/adc/rockchip_saradc.c | 16 +++++++++-------
   1 file changed, 9 insertions(+), 7 deletions(-)
drivers/iio/adc/rockchip_saradc.c +9 -7
index f3eb8d2e50dc..cd33c0b9d3eb 100644
@@ -49,6 +49,7 @@ struct rockchip_saradc {
   	struct clk		*clk;
   	struct completion	completion;
   	struct regulator	*vref;
+	int			uv_vref;
   	struct reset_control	*reset;
   	const struct rockchip_saradc_data *data;
   	u16			last_val;
@@ -105,13 +106,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
   		mutex_unlock(&indio_dev->mlock);
   		return IIO_VAL_INT;
   	case IIO_CHAN_INFO_SCALE:
-		ret = regulator_get_voltage(info->vref);
-		if (ret < 0) {
-			dev_err(&indio_dev->dev, "failed to get voltage\n");
-			return ret;
-		}
-
-		*val = ret / 1000;
+		*val = info->uv_vref / 1000;
   		*val2 = chan->scan_type.realbits;
   		return IIO_VAL_FRACTIONAL_LOG2;
   	default:
@@ -410,6 +405,13 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
   		return ret;
   	}
 
+	info->uv_vref = regulator_get_voltage(info->vref);
+	if (info->uv_vref < 0) {
+		dev_err(&pdev->dev, "failed to get voltage\n");
+		ret = info->uv_vref;
+		return ret;
+	}
+
   	ret = clk_prepare_enable(info->pclk);
   	if (ret < 0) {
   		dev_err(&pdev->dev, "failed to enable pclk\n");
maintainer
#5 lore raw

Hi David,

Am Donnerstag, 5. August 2021, 13:56:18 CEST schrieb David Wu:

Quoted 42 lines

Hi Jonathan,

Quoted 33 lines · Jonathan Cameron
Quoted 19 lines · On Tue, 3 Aug 2021 11:09:47 +0800 David Wu <[email protected]> wrote:

Hi Jonathan,

Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · On Mon, 2 Aug 2021 17:09:29 +0800 Simon Xue <[email protected]> wrote:

From: David Wu <[email protected]>

The referenced voltage is not changed after initiation, so just only get referenced voltage once.

Quoted 8 lines

Hi David,

Isn't this an external reference voltage? If so how do you know it is not changed at runtime? It might be unlikely and not happen on particular platforms, but that's not he same as saying it can never happen. Clearly it's racey anyway if that does happen, but we definitely don't expect frequent voltage changes.

Quoted 4 lines

The current regulator is not changed and not subject to external changes, this can reduce the getting voltage. Assuming that there will be changes in the future, we then add the notify of the regulator, so that the voltage change can be obtained.

If this patch added the notifier that would be a nice solution, but right now it potentially introduced a regression. You have made me a little curious... Are you seeing a significant cost to querying that regulator voltage?
If so, I'd imagine it's a lack of caching in the regulator driver or similar. Scale readback via sysfs shouldn't be in a fast path anyway.

Quoted 5 lines

You can't depend on what boards today do, because someone with a board built tomorrow may well use an old kernel which supports the voltage changing, and then see a regression when they upgrade to the kernel containing this patch.

Quoted 7 lines

For all current chips, the expected voltage is a fixed voltage, and don't want to change it in any process.:-)

So, if the voltage here does not change, then it can be obtained once in probe(), which can save the time of each acquisition. For example, the voltage of this regulator is obtained through i2c, which will increase some consumption every time.

Jonathans request was to not think about "all current chips" but the general case, and as Jonathan said, adding that regulator notifier you already mentioned would be the nicest solution.

So I think the easiest way is to just add the voltage notifier to your patch to make everyone happy ;-) .

Heiko

Quoted 67 lines
Quoted 64 lines

Jonathan

Quoted 57 lines
Quoted 55 lines

Jonathan

Quoted 48 lines
---
   drivers/iio/adc/rockchip_saradc.c | 16 +++++++++-------
   1 file changed, 9 insertions(+), 7 deletions(-)
drivers/iio/adc/rockchip_saradc.c +9 -7
index f3eb8d2e50dc..cd33c0b9d3eb 100644
@@ -49,6 +49,7 @@ struct rockchip_saradc {
   	struct clk		*clk;
   	struct completion	completion;
   	struct regulator	*vref;
+	int			uv_vref;
   	struct reset_control	*reset;
   	const struct rockchip_saradc_data *data;
   	u16			last_val;
@@ -105,13 +106,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
   		mutex_unlock(&indio_dev->mlock);
   		return IIO_VAL_INT;
   	case IIO_CHAN_INFO_SCALE:
-		ret = regulator_get_voltage(info->vref);
-		if (ret < 0) {
-			dev_err(&indio_dev->dev, "failed to get voltage\n");
-			return ret;
-		}
-
-		*val = ret / 1000;
+		*val = info->uv_vref / 1000;
   		*val2 = chan->scan_type.realbits;
   		return IIO_VAL_FRACTIONAL_LOG2;
   	default:
@@ -410,6 +405,13 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
   		return ret;
   	}
 
+	info->uv_vref = regulator_get_voltage(info->vref);
+	if (info->uv_vref < 0) {
+		dev_err(&pdev->dev, "failed to get voltage\n");
+		ret = info->uv_vref;
+		return ret;
+	}
+
   	ret = clk_prepare_enable(info->pclk);
   	if (ret < 0) {
   		dev_err(&pdev->dev, "failed to enable pclk\n");
#6 lore raw

Hi Heiko, Jonathan

we are adding the notifier for this patch, indeed for future consideration.

Thanks.

Quoted 137 lines · Heiko Stübner

Hi David,

Am Donnerstag, 5. August 2021, 13:56:18 CEST schrieb David Wu:

Quoted 42 lines

Hi Jonathan,

Quoted 33 lines · Jonathan Cameron
Quoted 19 lines · On Tue, 3 Aug 2021 11:09:47 +0800 David Wu <[email protected]> wrote:

Hi Jonathan,

Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · On Mon, 2 Aug 2021 17:09:29 +0800 Simon Xue <[email protected]> wrote:

From: David Wu <[email protected]>

The referenced voltage is not changed after initiation, so just only get referenced voltage once.

Quoted 8 lines

Hi David,

Isn't this an external reference voltage? If so how do you know it is not changed at runtime? It might be unlikely and not happen on particular platforms, but that's not he same as saying it can never happen. Clearly it's racey anyway if that does happen, but we definitely don't expect frequent voltage changes.

Quoted 4 lines

The current regulator is not changed and not subject to external changes, this can reduce the getting voltage. Assuming that there will be changes in the future, we then add the notify of the regulator, so that the voltage change can be obtained.

If this patch added the notifier that would be a nice solution, but right now it potentially introduced a regression. You have made me a little curious... Are you seeing a significant cost to querying that regulator voltage?
If so, I'd imagine it's a lack of caching in the regulator driver or similar. Scale readback via sysfs shouldn't be in a fast path anyway.

Quoted 5 lines

You can't depend on what boards today do, because someone with a board built tomorrow may well use an old kernel which supports the voltage changing, and then see a regression when they upgrade to the kernel containing this patch.

Quoted 7 lines

For all current chips, the expected voltage is a fixed voltage, and don't want to change it in any process.:-)

So, if the voltage here does not change, then it can be obtained once in probe(), which can save the time of each acquisition. For example, the voltage of this regulator is obtained through i2c, which will increase some consumption every time.

Jonathans request was to not think about "all current chips" but the general case, and as Jonathan said, adding that regulator notifier you already mentioned would be the nicest solution.

So I think the easiest way is to just add the voltage notifier to your patch to make everyone happy ;-) .

Heiko

Quoted 67 lines
Quoted 64 lines

Jonathan

Quoted 57 lines
Quoted 55 lines

Jonathan

Quoted 48 lines
---
    drivers/iio/adc/rockchip_saradc.c | 16 +++++++++-------
    1 file changed, 9 insertions(+), 7 deletions(-)
drivers/iio/adc/rockchip_saradc.c +9 -7
index f3eb8d2e50dc..cd33c0b9d3eb 100644
@@ -49,6 +49,7 @@ struct rockchip_saradc {
    	struct clk		*clk;
    	struct completion	completion;
    	struct regulator	*vref;
+	int			uv_vref;
    	struct reset_control	*reset;
    	const struct rockchip_saradc_data *data;
    	u16			last_val;
@@ -105,13 +106,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
    		mutex_unlock(&indio_dev->mlock);
    		return IIO_VAL_INT;
    	case IIO_CHAN_INFO_SCALE:
-		ret = regulator_get_voltage(info->vref);
-		if (ret < 0) {
-			dev_err(&indio_dev->dev, "failed to get voltage\n");
-			return ret;
-		}
-
-		*val = ret / 1000;
+		*val = info->uv_vref / 1000;
    		*val2 = chan->scan_type.realbits;
    		return IIO_VAL_FRACTIONAL_LOG2;
    	default:
@@ -410,6 +405,13 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
    		return ret;
    	}
 
+	info->uv_vref = regulator_get_voltage(info->vref);
+	if (info->uv_vref < 0) {
+		dev_err(&pdev->dev, "failed to get voltage\n");
+		ret = info->uv_vref;
+		return ret;
+	}
+
    	ret = clk_prepare_enable(info->pclk);
    	if (ret < 0) {
    		dev_err(&pdev->dev, "failed to enable pclk\n");