iio: adc: rockchip_saradc: add voltage notifier so get referenced voltage once at probe
Subsystems (2)
PATCH v2 1/1 iio: adc: rockchip_saradc: add voltage notifier so get referenced voltage once at probe
From: David Wu <[email protected]>
Add voltage notifier, no need to query regulator voltage for every saradc read, just get regulator voltage once at probe.
--- drivers/iio/adc/rockchip_saradc.c | 47 ++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-)
drivers/iio/adc/rockchip_saradc.c +40 -7
@@ -49,10 +49,12 @@ 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;const struct iio_chan_spec *last_chan; +struct notifier_block nb; };static void rockchip_saradc_power_down (struct rockchip_saradc *info)
@@ -105,13 +107,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 :
@@ -298,6 +294,26 @@ static irqreturn_t rockchip_saradc_trigger_handler(int irq, void *p)return IRQ_HANDLED ; } +static int rockchip_saradc_volt_notify (struct notifier_block *nb, +unsigned long event, +void *data) +{ +struct rockchip_saradc *info = + container_of(nb, struct rockchip_saradc, nb); + +if (event ®ULATOR_EVENT_VOLTAGE_CHANGE ) + info->uv_vref = (unsigned long )data; + +return NOTIFY_OK ; +} + +static void rockchip_saradc_regulator_action (void *data) +{ +struct rockchip_saradc *info = data; + +regulator_unregister_notifier (info->vref, &info->nb); +} +static int rockchip_saradc_probe (struct platform_device *pdev) {struct rockchip_saradc *info =NULL ;
@@ -410,6 +426,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" );
@@ -450,6 +473,16 @@ static int rockchip_saradc_probe(struct platform_device *pdev)if (ret)return ret; + info->nb.notifier_call = rockchip_saradc_volt_notify; + ret =regulator_register_notifier (info->vref, &info->nb); +if (ret) +return ret; + + ret =devm_add_action_or_reset (&pdev->dev, + rockchip_saradc_regulator_action, info); +if (ret) +return ret; +return devm_iio_device_register (&pdev->dev, indio_dev); }
Signature · 1 line
2.25.1
Heiko Stübner
maintainerAm Freitag, 6. August 2021, 12:55:24 CEST schrieb Simon Xue:
Quoted 8 lines
From: David Wu <[email protected]>
Add voltage notifier, no need to query regulator voltage for every saradc read, just get regulator voltage once at probe.
Signed-off-by Simon Xue <[email protected]>Signed-off-by David Wu <[email protected]>Reviewed-by Heiko Stuebner <[email protected]>
patch looks great to me now :-)
Thanks
Heiko
Quoted 95 lines
--- drivers/iio/adc/rockchip_saradc.c | 47 ++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-)drivers/iio/adc/rockchip_saradc.c +40
-7@@ -49,10 +49,12 @@ 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;const struct iio_chan_spec *last_chan; +struct notifier_block nb; };static void rockchip_saradc_power_down (struct rockchip_saradc *info)@@ -105,13 +107,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 :@@ -298,6 +294,26 @@ static irqreturn_t rockchip_saradc_trigger_handler(int irq, void *p)return IRQ_HANDLED ; } +static int rockchip_saradc_volt_notify (struct notifier_block *nb, +unsigned long event, +void *data) +{ +struct rockchip_saradc *info = + container_of(nb, struct rockchip_saradc, nb); + +if (event ®ULATOR_EVENT_VOLTAGE_CHANGE ) + info->uv_vref = (unsigned long )data; + +return NOTIFY_OK ; +} + +static void rockchip_saradc_regulator_action (void *data) +{ +struct rockchip_saradc *info = data; + +regulator_unregister_notifier (info->vref, &info->nb); +} +static int rockchip_saradc_probe (struct platform_device *pdev) {struct rockchip_saradc *info =NULL ;@@ -410,6 +426,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" );@@ -450,6 +473,16 @@ static int rockchip_saradc_probe(struct platform_device *pdev)if (ret)return ret; + info->nb.notifier_call = rockchip_saradc_volt_notify; + ret =regulator_register_notifier (info->vref, &info->nb); +if (ret) +return ret; + + ret =devm_add_action_or_reset (&pdev->dev, + rockchip_saradc_regulator_action, info); +if (ret) +return ret; +return devm_iio_device_register (&pdev->dev, indio_dev); }
Quoted 8 lines · Simon Xue
From: David Wu <[email protected]>
Add voltage notifier, no need to query regulator voltage for every saradc read, just get regulator voltage once at probe.
Signed-off-by Simon Xue <[email protected]>Signed-off-by David Wu <[email protected]>
The order of SoB tags seems wrong or Co-developed-by is missed.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerQuoted 8 lines · On Fri, 6 Aug 2021 18:55:24 +0800 Simon Xue <[email protected]> wrote:
From: David Wu <[email protected]>
Add voltage notifier, no need to query regulator voltage for every saradc read, just get regulator voltage once at probe.
Signed-off-by Simon Xue <[email protected]>Signed-off-by David Wu <[email protected]>Reviewed-by Heiko Stuebner <[email protected]>
Looks like Andy's v1 reviews crossed with your v2.
Given you are going to be doing a v3 because of signed-off-by ordering as per Andy's comments please tidy up the other thing he mentioned (repeated below).
Otherwise looks good to me.
Thanks,
Jonathan
Quoted 64 lines
--- drivers/iio/adc/rockchip_saradc.c | 47 ++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-)drivers/iio/adc/rockchip_saradc.c +23
-7@@ -49,10 +49,12 @@ 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;const struct iio_chan_spec *last_chan; +struct notifier_block nb; };static void rockchip_saradc_power_down (struct rockchip_saradc *info)@@ -105,13 +107,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 :@@ -298,6 +294,26 @@ static irqreturn_t rockchip_saradc_trigger_handler(int irq, void *p)return IRQ_HANDLED ; } +static int rockchip_saradc_volt_notify (struct notifier_block *nb, +unsigned long event, +void *data) +{ +struct rockchip_saradc *info = + container_of(nb, struct rockchip_saradc, nb); + +if (event ®ULATOR_EVENT_VOLTAGE_CHANGE ) + info->uv_vref = (unsigned long )data; + +return NOTIFY_OK ; +} + +static void rockchip_saradc_regulator_action (void *data) +{ +struct rockchip_saradc *info = data; + +regulator_unregister_notifier (info->vref, &info->nb); +} +static int rockchip_saradc_probe (struct platform_device *pdev) {struct rockchip_saradc *info =NULL ;
drivers/iio/adc/rockchip_saradc.c static int rockchip_saradc_probe(struct platform_device *pdev) · line 434
Quoted 9 lines
drivers/iio/adc/rockchip_saradc.c +6
-0@@ -410,6 +426,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; + }
Andy suggested a cleaner form of this (which I also prefer) is
ret = regulator_get_voltage(info->vref); if (ret < 0) return ret; info->uv_vref = ret;
Quoted 21 lines
drivers/iio/adc/rockchip_saradc.c +11
-0+ ret =clk_prepare_enable (info->pclk);if (ret <0 ) {dev_err (&pdev->dev,"failed to enable pclk\n" );@@ -450,6 +473,16 @@ static int rockchip_saradc_probe(struct platform_device *pdev)if (ret)return ret; + info->nb.notifier_call = rockchip_saradc_volt_notify; + ret =regulator_register_notifier (info->vref, &info->nb); +if (ret) +return ret; + + ret =devm_add_action_or_reset (&pdev->dev, + rockchip_saradc_regulator_action, info); +if (ret) +return ret; +return devm_iio_device_register (&pdev->dev, indio_dev); }