Skip to content

Commit 09738cc

Browse files
geo-starkjic23
authored andcommitted
iio: adc: meson: fix core clock enable/disable moment
Enable core clock at probe stage and disable it at remove stage. Core clock is responsible for turning on/off the entire SoC module so it should be on before the first module register is touched and be off at very last moment. Fixes: 3adbf34 ("iio: adc: add a driver for the SAR ADC found in Amlogic Meson SoCs") Signed-off-by: George Stark <gnstark@sberdevices.ru> Link: https://lore.kernel.org/r/20230721102413.255726-2-gnstark@sberdevices.ru Cc: <stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent b2a6996 commit 09738cc

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

drivers/iio/adc/meson_saradc.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,6 @@ static int meson_sar_adc_hw_enable(struct iio_dev *indio_dev)
916916
goto err_vref;
917917
}
918918

919-
ret = clk_prepare_enable(priv->core_clk);
920-
if (ret) {
921-
dev_err(dev, "failed to enable core clk\n");
922-
goto err_core_clk;
923-
}
924-
925919
regval = FIELD_PREP(MESON_SAR_ADC_REG0_FIFO_CNT_IRQ_MASK, 1);
926920
regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0,
927921
MESON_SAR_ADC_REG0_FIFO_CNT_IRQ_MASK, regval);
@@ -948,8 +942,6 @@ static int meson_sar_adc_hw_enable(struct iio_dev *indio_dev)
948942
regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3,
949943
MESON_SAR_ADC_REG3_ADC_EN, 0);
950944
meson_sar_adc_set_bandgap(indio_dev, false);
951-
clk_disable_unprepare(priv->core_clk);
952-
err_core_clk:
953945
regulator_disable(priv->vref);
954946
err_vref:
955947
meson_sar_adc_unlock(indio_dev);
@@ -977,8 +969,6 @@ static void meson_sar_adc_hw_disable(struct iio_dev *indio_dev)
977969

978970
meson_sar_adc_set_bandgap(indio_dev, false);
979971

980-
clk_disable_unprepare(priv->core_clk);
981-
982972
regulator_disable(priv->vref);
983973

984974
if (!ret)
@@ -1211,7 +1201,7 @@ static int meson_sar_adc_probe(struct platform_device *pdev)
12111201
if (IS_ERR(priv->clkin))
12121202
return dev_err_probe(dev, PTR_ERR(priv->clkin), "failed to get clkin\n");
12131203

1214-
priv->core_clk = devm_clk_get(dev, "core");
1204+
priv->core_clk = devm_clk_get_enabled(dev, "core");
12151205
if (IS_ERR(priv->core_clk))
12161206
return dev_err_probe(dev, PTR_ERR(priv->core_clk), "failed to get core clk\n");
12171207

@@ -1294,15 +1284,26 @@ static int meson_sar_adc_remove(struct platform_device *pdev)
12941284
static int meson_sar_adc_suspend(struct device *dev)
12951285
{
12961286
struct iio_dev *indio_dev = dev_get_drvdata(dev);
1287+
struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
12971288

12981289
meson_sar_adc_hw_disable(indio_dev);
12991290

1291+
clk_disable_unprepare(priv->core_clk);
1292+
13001293
return 0;
13011294
}
13021295

13031296
static int meson_sar_adc_resume(struct device *dev)
13041297
{
13051298
struct iio_dev *indio_dev = dev_get_drvdata(dev);
1299+
struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
1300+
int ret;
1301+
1302+
ret = clk_prepare_enable(priv->core_clk);
1303+
if (ret) {
1304+
dev_err(dev, "failed to enable core clk\n");
1305+
return ret;
1306+
}
13061307

13071308
return meson_sar_adc_hw_enable(indio_dev);
13081309
}

0 commit comments

Comments
 (0)