Commit 5ff46635 authored by Jinjie Ruan's avatar Jinjie Ruan Committed by Jonathan Cameron

staging: iio: Use devm_clk_get_enabled() helper function

The devm_clk_get_enabled() helper:
    - calls devm_clk_get()
    - calls clk_prepare_enable() and registers what is needed in order to
      call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the need of a dedicated function used
with devm_add_action_or_reset().
Signed-off-by: default avatarJinjie Ruan <ruanjinjie@huawei.com>
Link: https://lore.kernel.org/r/20230825095612.2972892-1-ruanjinjie@huawei.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent a2d518fb
......@@ -299,11 +299,6 @@ static void ad9832_reg_disable(void *reg)
regulator_disable(reg);
}
static void ad9832_clk_disable(void *clk)
{
clk_disable_unprepare(clk);
}
static int ad9832_probe(struct spi_device *spi)
{
struct ad9832_platform_data *pdata = dev_get_platdata(&spi->dev);
......@@ -350,18 +345,10 @@ static int ad9832_probe(struct spi_device *spi)
if (ret)
return ret;
st->mclk = devm_clk_get(&spi->dev, "mclk");
st->mclk = devm_clk_get_enabled(&spi->dev, "mclk");
if (IS_ERR(st->mclk))
return PTR_ERR(st->mclk);
ret = clk_prepare_enable(st->mclk);
if (ret < 0)
return ret;
ret = devm_add_action_or_reset(&spi->dev, ad9832_clk_disable, st->mclk);
if (ret)
return ret;
st->spi = spi;
mutex_init(&st->lock);
......
......@@ -394,13 +394,6 @@ static void ad9834_disable_reg(void *data)
regulator_disable(reg);
}
static void ad9834_disable_clk(void *data)
{
struct clk *clk = data;
clk_disable_unprepare(clk);
}
static int ad9834_probe(struct spi_device *spi)
{
struct ad9834_state *st;
......@@ -429,22 +422,12 @@ static int ad9834_probe(struct spi_device *spi)
}
st = iio_priv(indio_dev);
mutex_init(&st->lock);
st->mclk = devm_clk_get(&spi->dev, NULL);
st->mclk = devm_clk_get_enabled(&spi->dev, NULL);
if (IS_ERR(st->mclk)) {
ret = PTR_ERR(st->mclk);
return ret;
}
ret = clk_prepare_enable(st->mclk);
if (ret) {
dev_err(&spi->dev, "Failed to enable master clock\n");
return ret;
return PTR_ERR(st->mclk);
}
ret = devm_add_action_or_reset(&spi->dev, ad9834_disable_clk, st->mclk);
if (ret)
return ret;
st->spi = spi;
st->devid = spi_get_device_id(spi)->driver_data;
indio_dev->name = spi_get_device_id(spi)->name;
......
......@@ -667,13 +667,6 @@ static void ad5933_reg_disable(void *data)
regulator_disable(st->reg);
}
static void ad5933_clk_disable(void *data)
{
struct ad5933_state *st = data;
clk_disable_unprepare(st->mclk);
}
static int ad5933_probe(struct i2c_client *client)
{
const struct i2c_device_id *id = i2c_client_get_device_id(client);
......@@ -712,23 +705,12 @@ static int ad5933_probe(struct i2c_client *client)
st->vref_mv = ret / 1000;
st->mclk = devm_clk_get(&client->dev, "mclk");
st->mclk = devm_clk_get_enabled(&client->dev, "mclk");
if (IS_ERR(st->mclk) && PTR_ERR(st->mclk) != -ENOENT)
return PTR_ERR(st->mclk);
if (!IS_ERR(st->mclk)) {
ret = clk_prepare_enable(st->mclk);
if (ret < 0)
return ret;
ret = devm_add_action_or_reset(&client->dev,
ad5933_clk_disable,
st);
if (ret)
return ret;
if (!IS_ERR(st->mclk))
ext_clk_hz = clk_get_rate(st->mclk);
}
if (ext_clk_hz) {
st->mclk_hz = ext_clk_hz;
......
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