diff options
author | Jinjie Ruan <ruanjinjie@huawei.com> | 2023-08-25 17:56:12 +0800 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2023-09-11 20:12:40 +0100 |
commit | 5ff46635e4c51a2aeafb50a06c36bfdd0cda4203 (patch) | |
tree | c89529e84435cc1300743979348490b6074da47b | |
parent | a2d518fbe3760f66576a5c4f627aa3f126271c8b (diff) | |
download | linux-5ff46635e4c51a2aeafb50a06c36bfdd0cda4203.tar.gz linux-5ff46635e4c51a2aeafb50a06c36bfdd0cda4203.tar.bz2 linux-5ff46635e4c51a2aeafb50a06c36bfdd0cda4203.zip |
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: Jinjie Ruan <ruanjinjie@huawei.com>
Link: https://lore.kernel.org/r/20230825095612.2972892-1-ruanjinjie@huawei.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r-- | drivers/staging/iio/frequency/ad9832.c | 15 | ||||
-rw-r--r-- | drivers/staging/iio/frequency/ad9834.c | 21 | ||||
-rw-r--r-- | drivers/staging/iio/impedance-analyzer/ad5933.c | 22 |
3 files changed, 5 insertions, 53 deletions
diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c index 6f9eebd6c7ee..6c390c4eb26d 100644 --- a/drivers/staging/iio/frequency/ad9832.c +++ b/drivers/staging/iio/frequency/ad9832.c @@ -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); diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c index 285df0e489a6..a7a5cdcc6590 100644 --- a/drivers/staging/iio/frequency/ad9834.c +++ b/drivers/staging/iio/frequency/ad9834.c @@ -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; diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index 46db6d91542a..e748a5d04e97 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -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; |