UPSTREAM: iio: adc: rockchip_saradc: move all of probe to devm-functions
Parts of the saradc probe rely on devm functions and later parts do not.
This makes it more difficult to for example enable triggers via their
devm-functions and would need more undo-work in remove.
So to make life easier for the driver, move the rest of probe calls
also to their devm-equivalents.
This includes moving the clk- and regulator-disabling to a devm_action
so that they gets disabled both during remove and in the error case
in probe, after the action is registered.
Change-Id: Icfab5091b6a988ed5a684fe800ff1cf8fa179a89
Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Tao Huang <huangtao@rock-chips.com>
(cherry picked from commit d0389d4ed3)
This commit is contained in:
parent
ec6c715c55
commit
679e5ec1ca
1 changed files with 45 additions and 29 deletions
|
|
@ -221,6 +221,27 @@ static void rockchip_saradc_reset_controller(struct reset_control *reset)
|
|||
reset_control_deassert(reset);
|
||||
}
|
||||
|
||||
static void rockchip_saradc_clk_disable(void *data)
|
||||
{
|
||||
struct rockchip_saradc *info = data;
|
||||
|
||||
clk_disable_unprepare(info->clk);
|
||||
}
|
||||
|
||||
static void rockchip_saradc_pclk_disable(void *data)
|
||||
{
|
||||
struct rockchip_saradc *info = data;
|
||||
|
||||
clk_disable_unprepare(info->pclk);
|
||||
}
|
||||
|
||||
static void rockchip_saradc_regulator_disable(void *data)
|
||||
{
|
||||
struct rockchip_saradc *info = data;
|
||||
|
||||
regulator_disable(info->vref);
|
||||
}
|
||||
|
||||
static int rockchip_saradc_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct rockchip_saradc *info = NULL;
|
||||
|
|
@ -321,19 +342,40 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
|
|||
dev_err(&pdev->dev, "failed to enable vref regulator\n");
|
||||
return ret;
|
||||
}
|
||||
ret = devm_add_action_or_reset(&pdev->dev,
|
||||
rockchip_saradc_regulator_disable, info);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "failed to register devm action, %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
info->uv_vref = regulator_get_voltage(info->vref);
|
||||
|
||||
ret = clk_prepare_enable(info->pclk);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "failed to enable pclk\n");
|
||||
goto err_reg_voltage;
|
||||
return ret;
|
||||
}
|
||||
ret = devm_add_action_or_reset(&pdev->dev,
|
||||
rockchip_saradc_pclk_disable, info);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "failed to register devm action, %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clk_prepare_enable(info->clk);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "failed to enable converter clock\n");
|
||||
goto err_pclk;
|
||||
return ret;
|
||||
}
|
||||
ret = devm_add_action_or_reset(&pdev->dev,
|
||||
rockchip_saradc_clk_disable, info);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "failed to register devm action, %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
platform_set_drvdata(pdev, indio_dev);
|
||||
|
|
@ -347,32 +389,7 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
|
|||
indio_dev->channels = info->data->channels;
|
||||
indio_dev->num_channels = info->data->num_channels;
|
||||
|
||||
ret = iio_device_register(indio_dev);
|
||||
if (ret)
|
||||
goto err_clk;
|
||||
|
||||
return 0;
|
||||
|
||||
err_clk:
|
||||
clk_disable_unprepare(info->clk);
|
||||
err_pclk:
|
||||
clk_disable_unprepare(info->pclk);
|
||||
err_reg_voltage:
|
||||
regulator_disable(info->vref);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rockchip_saradc_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
|
||||
struct rockchip_saradc *info = iio_priv(indio_dev);
|
||||
|
||||
iio_device_unregister(indio_dev);
|
||||
clk_disable_unprepare(info->clk);
|
||||
clk_disable_unprepare(info->pclk);
|
||||
regulator_disable(info->vref);
|
||||
|
||||
return 0;
|
||||
return devm_iio_device_register(&pdev->dev, indio_dev);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
|
|
@ -415,7 +432,6 @@ static SIMPLE_DEV_PM_OPS(rockchip_saradc_pm_ops,
|
|||
|
||||
static struct platform_driver rockchip_saradc_driver = {
|
||||
.probe = rockchip_saradc_probe,
|
||||
.remove = rockchip_saradc_remove,
|
||||
.driver = {
|
||||
.name = "rockchip-saradc",
|
||||
.of_match_table = rockchip_saradc_match,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue