Skip to content

Commit 1e0ec03

Browse files
committed
ASoC: use pm_runtime_resume_and_get() when possible
Merge series from Pierre-Louis Bossart <[email protected]>: After a set of SOF-specific changes, this patchset correct problematic uses of pm_runtime_get_sync() in ASoC, or simplifies the flow with no functional changes. Two patches for Intel platforms also add a test on resume success. Additional changes were initially suggested to completely remove the use of pm_runtime_get_sync(). These changes were dropped since they are way too invasive, specifically in cases where the return values were not tested, which would lead to duplicate pm_runtime_put(). The remaining uses of pm_runtime_get_sync() cannot really be blindly modified without context and knowledge of each driver.
2 parents bd10b0d + cecc81d commit 1e0ec03

File tree

11 files changed

+45
-41
lines changed

11 files changed

+45
-41
lines changed

sound/soc/codecs/tas2552.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static int tas2552_component_probe(struct snd_soc_component *component)
581581

582582
gpiod_set_value(tas2552->enable_gpio, 1);
583583

584-
ret = pm_runtime_get_sync(component->dev);
584+
ret = pm_runtime_resume_and_get(component->dev);
585585
if (ret < 0) {
586586
dev_err(component->dev, "Enabling device failed: %d\n",
587587
ret);

sound/soc/codecs/wcd-mbhc-v2.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,12 +714,11 @@ static int wcd_mbhc_initialise(struct wcd_mbhc *mbhc)
714714
struct snd_soc_component *component = mbhc->component;
715715
int ret;
716716

717-
ret = pm_runtime_get_sync(component->dev);
717+
ret = pm_runtime_resume_and_get(component->dev);
718718
if (ret < 0 && ret != -EACCES) {
719719
dev_err_ratelimited(component->dev,
720-
"pm_runtime_get_sync failed in %s, ret %d\n",
720+
"pm_runtime_resume_and_get failed in %s, ret %d\n",
721721
__func__, ret);
722-
pm_runtime_put_noidle(component->dev);
723722
return ret;
724723
}
725724

@@ -1097,12 +1096,11 @@ static void wcd_correct_swch_plug(struct work_struct *work)
10971096
mbhc = container_of(work, struct wcd_mbhc, correct_plug_swch);
10981097
component = mbhc->component;
10991098

1100-
ret = pm_runtime_get_sync(component->dev);
1099+
ret = pm_runtime_resume_and_get(component->dev);
11011100
if (ret < 0 && ret != -EACCES) {
11021101
dev_err_ratelimited(component->dev,
1103-
"pm_runtime_get_sync failed in %s, ret %d\n",
1102+
"pm_runtime_resume_and_get failed in %s, ret %d\n",
11041103
__func__, ret);
1105-
pm_runtime_put_noidle(component->dev);
11061104
return;
11071105
}
11081106
micbias_mv = wcd_mbhc_get_micbias(mbhc);

sound/soc/codecs/wsa881x.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,9 @@ static int wsa881x_put_pa_gain(struct snd_kcontrol *kc,
749749
unsigned int mask = (1 << fls(max)) - 1;
750750
int val, ret, min_gain, max_gain;
751751

752-
ret = pm_runtime_get_sync(comp->dev);
753-
if (ret < 0 && ret != -EACCES) {
754-
pm_runtime_put_noidle(comp->dev);
752+
ret = pm_runtime_resume_and_get(comp->dev);
753+
if (ret < 0 && ret != -EACCES)
755754
return ret;
756-
}
757755

758756
max_gain = (max - ucontrol->value.integer.value[0]) & mask;
759757
/*

sound/soc/fsl/fsl_sai.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,11 +1141,9 @@ static int fsl_sai_probe(struct platform_device *pdev)
11411141
goto err_pm_disable;
11421142
}
11431143

1144-
ret = pm_runtime_get_sync(dev);
1145-
if (ret < 0) {
1146-
pm_runtime_put_noidle(dev);
1144+
ret = pm_runtime_resume_and_get(dev);
1145+
if (ret < 0)
11471146
goto err_pm_get_sync;
1148-
}
11491147

11501148
/* Get sai version */
11511149
ret = fsl_sai_check_version(dev);

sound/soc/img/img-i2s-out.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,9 @@ static int img_i2s_out_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
346346

347347
chan_control_mask = IMG_I2S_OUT_CHAN_CTL_CLKT_MASK;
348348

349-
ret = pm_runtime_get_sync(i2s->dev);
350-
if (ret < 0) {
351-
pm_runtime_put_noidle(i2s->dev);
349+
ret = pm_runtime_resume_and_get(i2s->dev);
350+
if (ret < 0)
352351
return ret;
353-
}
354352

355353
img_i2s_out_disable(i2s);
356354

@@ -482,11 +480,9 @@ static int img_i2s_out_probe(struct platform_device *pdev)
482480
if (ret)
483481
goto err_pm_disable;
484482
}
485-
ret = pm_runtime_get_sync(&pdev->dev);
486-
if (ret < 0) {
487-
pm_runtime_put_noidle(&pdev->dev);
483+
ret = pm_runtime_resume_and_get(&pdev->dev);
484+
if (ret < 0)
488485
goto err_suspend;
489-
}
490486

491487
reg = IMG_I2S_OUT_CTL_FRM_SIZE_MASK;
492488
img_i2s_out_writel(i2s, reg, IMG_I2S_OUT_CTL);

sound/soc/intel/catpt/pcm.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,9 @@ static int catpt_dai_pcm_new(struct snd_soc_pcm_runtime *rtm,
667667
if (!memcmp(&cdev->devfmt[devfmt.iface], &devfmt, sizeof(devfmt)))
668668
return 0;
669669

670-
pm_runtime_get_sync(cdev->dev);
670+
ret = pm_runtime_resume_and_get(cdev->dev);
671+
if (ret < 0 && ret != -EACCES)
672+
return ret;
671673

672674
ret = catpt_ipc_set_device_format(cdev, &devfmt);
673675

@@ -853,9 +855,12 @@ static int catpt_mixer_volume_get(struct snd_kcontrol *kcontrol,
853855
snd_soc_kcontrol_component(kcontrol);
854856
struct catpt_dev *cdev = dev_get_drvdata(component->dev);
855857
u32 dspvol;
858+
int ret;
856859
int i;
857860

858-
pm_runtime_get_sync(cdev->dev);
861+
ret = pm_runtime_resume_and_get(cdev->dev);
862+
if (ret < 0 && ret != -EACCES)
863+
return ret;
859864

860865
for (i = 0; i < CATPT_CHANNELS_MAX; i++) {
861866
dspvol = catpt_mixer_volume(cdev, &cdev->mixer, i);
@@ -876,7 +881,9 @@ static int catpt_mixer_volume_put(struct snd_kcontrol *kcontrol,
876881
struct catpt_dev *cdev = dev_get_drvdata(component->dev);
877882
int ret;
878883

879-
pm_runtime_get_sync(cdev->dev);
884+
ret = pm_runtime_resume_and_get(cdev->dev);
885+
if (ret < 0 && ret != -EACCES)
886+
return ret;
880887

881888
ret = catpt_set_dspvol(cdev, cdev->mixer.mixer_hw_id,
882889
ucontrol->value.integer.value);
@@ -897,6 +904,7 @@ static int catpt_stream_volume_get(struct snd_kcontrol *kcontrol,
897904
struct catpt_dev *cdev = dev_get_drvdata(component->dev);
898905
long *ctlvol = (long *)kcontrol->private_value;
899906
u32 dspvol;
907+
int ret;
900908
int i;
901909

902910
stream = catpt_stream_find(cdev, pin_id);
@@ -906,7 +914,9 @@ static int catpt_stream_volume_get(struct snd_kcontrol *kcontrol,
906914
return 0;
907915
}
908916

909-
pm_runtime_get_sync(cdev->dev);
917+
ret = pm_runtime_resume_and_get(cdev->dev);
918+
if (ret < 0 && ret != -EACCES)
919+
return ret;
910920

911921
for (i = 0; i < CATPT_CHANNELS_MAX; i++) {
912922
dspvol = catpt_stream_volume(cdev, stream, i);
@@ -937,7 +947,9 @@ static int catpt_stream_volume_put(struct snd_kcontrol *kcontrol,
937947
return 0;
938948
}
939949

940-
pm_runtime_get_sync(cdev->dev);
950+
ret = pm_runtime_resume_and_get(cdev->dev);
951+
if (ret < 0 && ret != -EACCES)
952+
return ret;
941953

942954
ret = catpt_set_dspvol(cdev, stream->info.stream_hw_id,
943955
ucontrol->value.integer.value);
@@ -1013,7 +1025,9 @@ static int catpt_loopback_switch_put(struct snd_kcontrol *kcontrol,
10131025
return 0;
10141026
}
10151027

1016-
pm_runtime_get_sync(cdev->dev);
1028+
ret = pm_runtime_resume_and_get(cdev->dev);
1029+
if (ret < 0 && ret != -EACCES)
1030+
return ret;
10171031

10181032
ret = catpt_ipc_mute_loopback(cdev, stream->info.stream_hw_id, mute);
10191033

sound/soc/intel/catpt/sysfs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ static ssize_t fw_version_show(struct device *dev,
1515
struct catpt_fw_version version;
1616
int ret;
1717

18-
pm_runtime_get_sync(cdev->dev);
18+
ret = pm_runtime_resume_and_get(cdev->dev);
19+
if (ret < 0 && ret != -EACCES)
20+
return ret;
1921

2022
ret = catpt_ipc_get_fw_version(cdev, &version);
2123

sound/soc/intel/skylake/skl-pcm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,10 @@ static int skl_platform_soc_probe(struct snd_soc_component *component)
13801380
const struct skl_dsp_ops *ops;
13811381
int ret;
13821382

1383-
pm_runtime_get_sync(component->dev);
1383+
ret = pm_runtime_resume_and_get(component->dev);
1384+
if (ret < 0 && ret != -EACCES)
1385+
return ret;
1386+
13841387
if (bus->ppcap) {
13851388
skl->component = component;
13861389

sound/soc/rockchip/rockchip_i2s_tdm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,9 @@ static int rockchip_i2s_tdm_set_fmt(struct snd_soc_dai *cpu_dai,
404404
int ret;
405405
bool is_tdm = i2s_tdm->tdm_mode;
406406

407-
ret = pm_runtime_get_sync(cpu_dai->dev);
408-
if (ret < 0 && ret != -EACCES) {
409-
pm_runtime_put_noidle(cpu_dai->dev);
407+
ret = pm_runtime_resume_and_get(cpu_dai->dev);
408+
if (ret < 0 && ret != -EACCES)
410409
return ret;
411-
}
412410

413411
mask = I2S_CKR_MSS_MASK;
414412
switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {

sound/soc/rockchip/rockchip_pdm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,9 @@ static int rockchip_pdm_resume(struct device *dev)
688688
struct rk_pdm_dev *pdm = dev_get_drvdata(dev);
689689
int ret;
690690

691-
ret = pm_runtime_get_sync(dev);
692-
if (ret < 0) {
693-
pm_runtime_put(dev);
691+
ret = pm_runtime_resume_and_get(dev);
692+
if (ret < 0)
694693
return ret;
695-
}
696694

697695
ret = regcache_sync(pdm->regmap);
698696

0 commit comments

Comments
 (0)