Skip to content

Commit 306904d

Browse files
committed
ASoC: codecs: Simplify mclk initialization
Merge series from Cezary Rojewski <[email protected]>: The patchset may not cover all codecs found in the codecs/ directory - noticed a possible improvement and grepped for similar pattern across C files found in the directory. Those addressed here seem pretty straightforward. 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.
2 parents d34f0c8 + bf900c8 commit 306904d

File tree

6 files changed

+20
-40
lines changed

6 files changed

+20
-40
lines changed

sound/soc/codecs/da7213.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,18 +2101,14 @@ static int da7213_probe(struct snd_soc_component *component)
21012101
pm_runtime_put_sync(component->dev);
21022102

21032103
/* Check if MCLK provided */
2104-
da7213->mclk = devm_clk_get(component->dev, "mclk");
2105-
if (IS_ERR(da7213->mclk)) {
2106-
if (PTR_ERR(da7213->mclk) != -ENOENT)
2107-
return PTR_ERR(da7213->mclk);
2108-
else
2109-
da7213->mclk = NULL;
2110-
} else {
2104+
da7213->mclk = devm_clk_get_optional(component->dev, "mclk");
2105+
if (IS_ERR(da7213->mclk))
2106+
return PTR_ERR(da7213->mclk);
2107+
if (da7213->mclk)
21112108
/* Do automatic PLL handling assuming fixed clock until
21122109
* set_pll() has been called. This makes the codec usable
21132110
* with the simple-audio-card driver. */
21142111
da7213->fixed_clk_auto_pll = true;
2115-
}
21162112

21172113
/* Default infinite tone gen, start/stop by Kcontrol */
21182114
snd_soc_component_write(component, DA7213_TONE_GEN_CYCLES, DA7213_BEEP_CYCLES_MASK);

sound/soc/codecs/nau8825.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,16 +2836,12 @@ static int nau8825_read_device_properties(struct device *dev,
28362836
if (nau8825->adc_delay < 125 || nau8825->adc_delay > 500)
28372837
dev_warn(dev, "Please set the suitable delay time!\n");
28382838

2839-
nau8825->mclk = devm_clk_get(dev, "mclk");
2840-
if (PTR_ERR(nau8825->mclk) == -EPROBE_DEFER) {
2841-
return -EPROBE_DEFER;
2842-
} else if (PTR_ERR(nau8825->mclk) == -ENOENT) {
2839+
nau8825->mclk = devm_clk_get_optional(dev, "mclk");
2840+
if (IS_ERR(nau8825->mclk))
2841+
return PTR_ERR(nau8825->mclk);
2842+
if (!nau8825->mclk)
28432843
/* The MCLK is managed externally or not used at all */
2844-
nau8825->mclk = NULL;
28452844
dev_info(dev, "No 'mclk' clock found, assume MCLK is managed externally");
2846-
} else if (IS_ERR(nau8825->mclk)) {
2847-
return -EINVAL;
2848-
}
28492845

28502846
return 0;
28512847
}

sound/soc/codecs/rt5514.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,9 +1054,6 @@ static int rt5514_set_bias_level(struct snd_soc_component *component,
10541054

10551055
switch (level) {
10561056
case SND_SOC_BIAS_PREPARE:
1057-
if (IS_ERR(rt5514->mclk))
1058-
break;
1059-
10601057
if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) {
10611058
clk_disable_unprepare(rt5514->mclk);
10621059
} else {
@@ -1097,9 +1094,9 @@ static int rt5514_probe(struct snd_soc_component *component)
10971094
struct platform_device *pdev = container_of(component->dev,
10981095
struct platform_device, dev);
10991096

1100-
rt5514->mclk = devm_clk_get(component->dev, "mclk");
1101-
if (PTR_ERR(rt5514->mclk) == -EPROBE_DEFER)
1102-
return -EPROBE_DEFER;
1097+
rt5514->mclk = devm_clk_get_optional(component->dev, "mclk");
1098+
if (IS_ERR(rt5514->mclk))
1099+
return PTR_ERR(rt5514->mclk);
11031100

11041101
if (rt5514->pdata.dsp_calib_clk_name) {
11051102
rt5514->dsp_calib_clk = devm_clk_get(&pdev->dev,

sound/soc/codecs/rt5616.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,6 @@ static int rt5616_set_bias_level(struct snd_soc_component *component,
11741174
* away from ON. Disable the clock in that case, otherwise
11751175
* enable it.
11761176
*/
1177-
if (IS_ERR(rt5616->mclk))
1178-
break;
1179-
11801177
if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) {
11811178
clk_disable_unprepare(rt5616->mclk);
11821179
} else {
@@ -1225,9 +1222,9 @@ static int rt5616_probe(struct snd_soc_component *component)
12251222
struct rt5616_priv *rt5616 = snd_soc_component_get_drvdata(component);
12261223

12271224
/* Check if MCLK provided */
1228-
rt5616->mclk = devm_clk_get(component->dev, "mclk");
1229-
if (PTR_ERR(rt5616->mclk) == -EPROBE_DEFER)
1230-
return -EPROBE_DEFER;
1225+
rt5616->mclk = devm_clk_get_optional(component->dev, "mclk");
1226+
if (IS_ERR(rt5616->mclk))
1227+
return PTR_ERR(rt5616->mclk);
12311228

12321229
rt5616->component = component;
12331230

sound/soc/codecs/rt5640.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,9 +1949,6 @@ static int rt5640_set_bias_level(struct snd_soc_component *component,
19491949
* away from ON. Disable the clock in that case, otherwise
19501950
* enable it.
19511951
*/
1952-
if (IS_ERR(rt5640->mclk))
1953-
break;
1954-
19551952
if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) {
19561953
clk_disable_unprepare(rt5640->mclk);
19571954
} else {
@@ -2661,9 +2658,9 @@ static int rt5640_probe(struct snd_soc_component *component)
26612658
u32 val;
26622659

26632660
/* Check if MCLK provided */
2664-
rt5640->mclk = devm_clk_get(component->dev, "mclk");
2665-
if (PTR_ERR(rt5640->mclk) == -EPROBE_DEFER)
2666-
return -EPROBE_DEFER;
2661+
rt5640->mclk = devm_clk_get_optional(component->dev, "mclk");
2662+
if (IS_ERR(rt5640->mclk))
2663+
return PTR_ERR(rt5640->mclk);
26672664

26682665
rt5640->component = component;
26692666

sound/soc/codecs/rt5660.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,9 +1079,6 @@ static int rt5660_set_bias_level(struct snd_soc_component *component,
10791079
snd_soc_component_update_bits(component, RT5660_GEN_CTRL1,
10801080
RT5660_DIG_GATE_CTRL, RT5660_DIG_GATE_CTRL);
10811081

1082-
if (IS_ERR(rt5660->mclk))
1083-
break;
1084-
10851082
if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) {
10861083
clk_disable_unprepare(rt5660->mclk);
10871084
} else {
@@ -1277,9 +1274,9 @@ static int rt5660_i2c_probe(struct i2c_client *i2c)
12771274
return -ENOMEM;
12781275

12791276
/* Check if MCLK provided */
1280-
rt5660->mclk = devm_clk_get(&i2c->dev, "mclk");
1281-
if (PTR_ERR(rt5660->mclk) == -EPROBE_DEFER)
1282-
return -EPROBE_DEFER;
1277+
rt5660->mclk = devm_clk_get_optional(&i2c->dev, "mclk");
1278+
if (IS_ERR(rt5660->mclk))
1279+
return PTR_ERR(rt5660->mclk);
12831280

12841281
i2c_set_clientdata(i2c, rt5660);
12851282

0 commit comments

Comments
 (0)