Commit cabd6e9c authored by David Wu's avatar David Wu Committed by Jonathan Cameron

iio: adc: rockchip_saradc: add voltage notifier so get referenced voltage once at probe

Add voltage notifier, no need to query regulator voltage for
every saradc read, just get regulator voltage once at probe.
Signed-off-by: default avatarDavid Wu <david.wu@rock-chips.com>
Signed-off-by: default avatarSimon Xue <xxm@rock-chips.com>
Reviewed-by: default avatarHeiko Stuebner <heiko@sntech.de>
Link: https://lore.kernel.org/r/20210810011007.54066-1-xxm@rock-chips.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent b76d26d6
...@@ -49,10 +49,12 @@ struct rockchip_saradc { ...@@ -49,10 +49,12 @@ struct rockchip_saradc {
struct clk *clk; struct clk *clk;
struct completion completion; struct completion completion;
struct regulator *vref; struct regulator *vref;
int uv_vref;
struct reset_control *reset; struct reset_control *reset;
const struct rockchip_saradc_data *data; const struct rockchip_saradc_data *data;
u16 last_val; u16 last_val;
const struct iio_chan_spec *last_chan; const struct iio_chan_spec *last_chan;
struct notifier_block nb;
}; };
static void rockchip_saradc_power_down(struct rockchip_saradc *info) 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, ...@@ -105,13 +107,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
ret = regulator_get_voltage(info->vref); *val = info->uv_vref / 1000;
if (ret < 0) {
dev_err(&indio_dev->dev, "failed to get voltage\n");
return ret;
}
*val = ret / 1000;
*val2 = chan->scan_type.realbits; *val2 = chan->scan_type.realbits;
return IIO_VAL_FRACTIONAL_LOG2; return IIO_VAL_FRACTIONAL_LOG2;
default: default:
...@@ -298,6 +294,26 @@ static irqreturn_t rockchip_saradc_trigger_handler(int irq, void *p) ...@@ -298,6 +294,26 @@ static irqreturn_t rockchip_saradc_trigger_handler(int irq, void *p)
return IRQ_HANDLED; 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 & REGULATOR_EVENT_VOLTAGE_CHANGE)
info->uv_vref = (unsigned long)data;
return NOTIFY_OK;
}
static void rockchip_saradc_regulator_unreg_notifier(void *data)
{
struct rockchip_saradc *info = data;
regulator_unregister_notifier(info->vref, &info->nb);
}
static int rockchip_saradc_probe(struct platform_device *pdev) static int rockchip_saradc_probe(struct platform_device *pdev)
{ {
struct rockchip_saradc *info = NULL; struct rockchip_saradc *info = NULL;
...@@ -410,6 +426,12 @@ static int rockchip_saradc_probe(struct platform_device *pdev) ...@@ -410,6 +426,12 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
return ret; return ret;
} }
ret = regulator_get_voltage(info->vref);
if (ret < 0)
return ret;
info->uv_vref = ret;
ret = clk_prepare_enable(info->pclk); ret = clk_prepare_enable(info->pclk);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "failed to enable pclk\n"); dev_err(&pdev->dev, "failed to enable pclk\n");
...@@ -450,6 +472,17 @@ static int rockchip_saradc_probe(struct platform_device *pdev) ...@@ -450,6 +472,17 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
if (ret) if (ret)
return 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_unreg_notifier,
info);
if (ret)
return ret;
return devm_iio_device_register(&pdev->dev, indio_dev); return devm_iio_device_register(&pdev->dev, indio_dev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment