From e2cb72d28740516cb03fa072e14b2f1a6eceef61 Mon Sep 17 00:00:00 2001 From: Cezary Rojewski Date: Wed, 21 Feb 2024 16:25:11 +0100 Subject: [PATCH 1/6] ASoC: codecs: da7213: Simplify mclk initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most of clk_xxx() functions do check if provided clk-pointer is non-NULL. These do not check if the pointer is an error-pointer. Providing such to a clk_xxx() results in a panic. By utilizing _optional() variant of devm_clk_get() the driver code is both simplified and more robust. There is no need to remember about IS_ERR(clk) checks each time mclk is accessed. Reviewed-by: Amadeusz Sławiński Signed-off-by: Cezary Rojewski Link: https://msgid.link/r/20240221152516.852353-2-cezary.rojewski@intel.com Signed-off-by: Mark Brown --- sound/soc/codecs/da7213.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/da7213.c b/sound/soc/codecs/da7213.c index 0e5c527687a27..369c620787800 100644 --- a/sound/soc/codecs/da7213.c +++ b/sound/soc/codecs/da7213.c @@ -2101,18 +2101,14 @@ static int da7213_probe(struct snd_soc_component *component) pm_runtime_put_sync(component->dev); /* Check if MCLK provided */ - da7213->mclk = devm_clk_get(component->dev, "mclk"); - if (IS_ERR(da7213->mclk)) { - if (PTR_ERR(da7213->mclk) != -ENOENT) - return PTR_ERR(da7213->mclk); - else - da7213->mclk = NULL; - } else { + da7213->mclk = devm_clk_get_optional(component->dev, "mclk"); + if (IS_ERR(da7213->mclk)) + return PTR_ERR(da7213->mclk); + if (da7213->mclk) /* Do automatic PLL handling assuming fixed clock until * set_pll() has been called. This makes the codec usable * with the simple-audio-card driver. */ da7213->fixed_clk_auto_pll = true; - } /* Default infinite tone gen, start/stop by Kcontrol */ snd_soc_component_write(component, DA7213_TONE_GEN_CYCLES, DA7213_BEEP_CYCLES_MASK); From 71d322fd16a3a62d32a9e6a8d08f48e8a945a515 Mon Sep 17 00:00:00 2001 From: Cezary Rojewski Date: Wed, 21 Feb 2024 16:25:12 +0100 Subject: [PATCH 2/6] ASoC: codecs: nau8825: Simplify mclk initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most of clk_xxx() functions do check if provided clk-pointer is non-NULL. These do not check if the pointer is an error-pointer. Providing such to a clk_xxx() results in a panic. By utilizing _optional() variant of devm_clk_get() the driver code is both simplified and more robust. There is no need to remember about IS_ERR(clk) checks each time mclk is accessed. Reviewed-by: Amadeusz Sławiński Signed-off-by: Cezary Rojewski Link: https://msgid.link/r/20240221152516.852353-3-cezary.rojewski@intel.com Signed-off-by: Mark Brown --- sound/soc/codecs/nau8825.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/nau8825.c b/sound/soc/codecs/nau8825.c index 5cb0de648bd3c..cd30ad649bae0 100644 --- a/sound/soc/codecs/nau8825.c +++ b/sound/soc/codecs/nau8825.c @@ -2836,16 +2836,12 @@ static int nau8825_read_device_properties(struct device *dev, if (nau8825->adc_delay < 125 || nau8825->adc_delay > 500) dev_warn(dev, "Please set the suitable delay time!\n"); - nau8825->mclk = devm_clk_get(dev, "mclk"); - if (PTR_ERR(nau8825->mclk) == -EPROBE_DEFER) { - return -EPROBE_DEFER; - } else if (PTR_ERR(nau8825->mclk) == -ENOENT) { + nau8825->mclk = devm_clk_get_optional(dev, "mclk"); + if (IS_ERR(nau8825->mclk)) + return PTR_ERR(nau8825->mclk); + if (!nau8825->mclk) /* The MCLK is managed externally or not used at all */ - nau8825->mclk = NULL; dev_info(dev, "No 'mclk' clock found, assume MCLK is managed externally"); - } else if (IS_ERR(nau8825->mclk)) { - return -EINVAL; - } return 0; } From 67e9bf093372a070f67f85a6ffceb6a44d4cfcf4 Mon Sep 17 00:00:00 2001 From: Cezary Rojewski Date: Wed, 21 Feb 2024 16:25:13 +0100 Subject: [PATCH 3/6] ASoC: codecs: rt5514: Simplify mclk initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most of clk_xxx() functions do check if provided clk-pointer is non-NULL. These do not check if the pointer is an error-pointer. Providing such to a clk_xxx() results in a panic. By utilizing _optional() variant of devm_clk_get() the driver code is both simplified and more robust. There is no need to remember about IS_ERR(clk) checks each time mclk is accessed. Reviewed-by: Amadeusz Sławiński Signed-off-by: Cezary Rojewski Link: https://msgid.link/r/20240221152516.852353-4-cezary.rojewski@intel.com Signed-off-by: Mark Brown --- sound/soc/codecs/rt5514.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index 43fc7814fddeb..a8cdc3d6994d5 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -1054,9 +1054,6 @@ static int rt5514_set_bias_level(struct snd_soc_component *component, switch (level) { case SND_SOC_BIAS_PREPARE: - if (IS_ERR(rt5514->mclk)) - break; - if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { clk_disable_unprepare(rt5514->mclk); } else { @@ -1097,9 +1094,9 @@ static int rt5514_probe(struct snd_soc_component *component) struct platform_device *pdev = container_of(component->dev, struct platform_device, dev); - rt5514->mclk = devm_clk_get(component->dev, "mclk"); - if (PTR_ERR(rt5514->mclk) == -EPROBE_DEFER) - return -EPROBE_DEFER; + rt5514->mclk = devm_clk_get_optional(component->dev, "mclk"); + if (IS_ERR(rt5514->mclk)) + return PTR_ERR(rt5514->mclk); if (rt5514->pdata.dsp_calib_clk_name) { rt5514->dsp_calib_clk = devm_clk_get(&pdev->dev, From f76de61ad1eb725cc05727377ccd4adda336b822 Mon Sep 17 00:00:00 2001 From: Cezary Rojewski Date: Wed, 21 Feb 2024 16:25:14 +0100 Subject: [PATCH 4/6] ASoC: codecs: rt5616: Simplify mclk initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most of clk_xxx() functions do check if provided clk-pointer is non-NULL. These do not check if the pointer is an error-pointer. Providing such to a clk_xxx() results in a panic. By utilizing _optional() variant of devm_clk_get() the driver code is both simplified and more robust. There is no need to remember about IS_ERR(clk) checks each time mclk is accessed. Reviewed-by: Amadeusz Sławiński Signed-off-by: Cezary Rojewski Link: https://msgid.link/r/20240221152516.852353-5-cezary.rojewski@intel.com Signed-off-by: Mark Brown --- sound/soc/codecs/rt5616.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/rt5616.c b/sound/soc/codecs/rt5616.c index c13108b51eaf6..e7aa60e73961c 100644 --- a/sound/soc/codecs/rt5616.c +++ b/sound/soc/codecs/rt5616.c @@ -1174,9 +1174,6 @@ static int rt5616_set_bias_level(struct snd_soc_component *component, * away from ON. Disable the clock in that case, otherwise * enable it. */ - if (IS_ERR(rt5616->mclk)) - break; - if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { clk_disable_unprepare(rt5616->mclk); } else { @@ -1225,9 +1222,9 @@ static int rt5616_probe(struct snd_soc_component *component) struct rt5616_priv *rt5616 = snd_soc_component_get_drvdata(component); /* Check if MCLK provided */ - rt5616->mclk = devm_clk_get(component->dev, "mclk"); - if (PTR_ERR(rt5616->mclk) == -EPROBE_DEFER) - return -EPROBE_DEFER; + rt5616->mclk = devm_clk_get_optional(component->dev, "mclk"); + if (IS_ERR(rt5616->mclk)) + return PTR_ERR(rt5616->mclk); rt5616->component = component; From 6413849b678b04e30b5c938e344e653c31a5f73b Mon Sep 17 00:00:00 2001 From: Cezary Rojewski Date: Wed, 21 Feb 2024 16:25:15 +0100 Subject: [PATCH 5/6] ASoC: codecs: rt5640: Simplify mclk initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most of clk_xxx() functions do check if provided clk-pointer is non-NULL. These do not check if the pointer is an error-pointer. Providing such to a clk_xxx() results in a panic. rt5640_set_dai_sysclk() is an example of that - clk_set_rate() is not guarded by IS_ERR(). By utilizing _optional() variant of devm_clk_get() the driver code is both simplified and more robust. There is no need to remember about IS_ERR(clk) checks each time mclk is accessed. Reviewed-by: Amadeusz Sławiński Signed-off-by: Cezary Rojewski Link: https://msgid.link/r/20240221152516.852353-6-cezary.rojewski@intel.com Signed-off-by: Mark Brown --- sound/soc/codecs/rt5640.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c index e8cdc166bdaa9..174872ef35d25 100644 --- a/sound/soc/codecs/rt5640.c +++ b/sound/soc/codecs/rt5640.c @@ -1949,9 +1949,6 @@ static int rt5640_set_bias_level(struct snd_soc_component *component, * away from ON. Disable the clock in that case, otherwise * enable it. */ - if (IS_ERR(rt5640->mclk)) - break; - if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { clk_disable_unprepare(rt5640->mclk); } else { @@ -2661,9 +2658,9 @@ static int rt5640_probe(struct snd_soc_component *component) u32 val; /* Check if MCLK provided */ - rt5640->mclk = devm_clk_get(component->dev, "mclk"); - if (PTR_ERR(rt5640->mclk) == -EPROBE_DEFER) - return -EPROBE_DEFER; + rt5640->mclk = devm_clk_get_optional(component->dev, "mclk"); + if (IS_ERR(rt5640->mclk)) + return PTR_ERR(rt5640->mclk); rt5640->component = component; From bf900c85f8a4ef47b868b6345879e35826a4fec1 Mon Sep 17 00:00:00 2001 From: Cezary Rojewski Date: Wed, 21 Feb 2024 16:25:16 +0100 Subject: [PATCH 6/6] ASoC: codecs: rt5660: Simplify mclk initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most of clk_xxx() functions do check if provided clk-pointer is non-NULL. These do not check if the pointer is an error-pointer. Providing such to a clk_xxx() results in a panic. By utilizing _optional() variant of devm_clk_get() the driver code is both simplified and more robust. There is no need to remember about IS_ERR(clk) checks each time mclk is accessed. Reviewed-by: Amadeusz Sławiński Signed-off-by: Cezary Rojewski Link: https://msgid.link/r/20240221152516.852353-7-cezary.rojewski@intel.com Signed-off-by: Mark Brown --- sound/soc/codecs/rt5660.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/rt5660.c b/sound/soc/codecs/rt5660.c index 0cecfd6024158..d5c2f0f2df983 100644 --- a/sound/soc/codecs/rt5660.c +++ b/sound/soc/codecs/rt5660.c @@ -1079,9 +1079,6 @@ static int rt5660_set_bias_level(struct snd_soc_component *component, snd_soc_component_update_bits(component, RT5660_GEN_CTRL1, RT5660_DIG_GATE_CTRL, RT5660_DIG_GATE_CTRL); - if (IS_ERR(rt5660->mclk)) - break; - if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { clk_disable_unprepare(rt5660->mclk); } else { @@ -1277,9 +1274,9 @@ static int rt5660_i2c_probe(struct i2c_client *i2c) return -ENOMEM; /* Check if MCLK provided */ - rt5660->mclk = devm_clk_get(&i2c->dev, "mclk"); - if (PTR_ERR(rt5660->mclk) == -EPROBE_DEFER) - return -EPROBE_DEFER; + rt5660->mclk = devm_clk_get_optional(&i2c->dev, "mclk"); + if (IS_ERR(rt5660->mclk)) + return PTR_ERR(rt5660->mclk); i2c_set_clientdata(i2c, rt5660);