Skip to content

Commit

Permalink
ASoC: use pm_runtime_resume_and_get() when possible
Browse files Browse the repository at this point in the history
Merge series from Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>:

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.
  • Loading branch information
Mark Brown committed Jun 28, 2022
2 parents bd10b0d + cecc81d commit 1e0ec03
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 41 deletions.
2 changes: 1 addition & 1 deletion sound/soc/codecs/tas2552.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ static int tas2552_component_probe(struct snd_soc_component *component)

gpiod_set_value(tas2552->enable_gpio, 1);

ret = pm_runtime_get_sync(component->dev);
ret = pm_runtime_resume_and_get(component->dev);
if (ret < 0) {
dev_err(component->dev, "Enabling device failed: %d\n",
ret);
Expand Down
10 changes: 4 additions & 6 deletions sound/soc/codecs/wcd-mbhc-v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,11 @@ static int wcd_mbhc_initialise(struct wcd_mbhc *mbhc)
struct snd_soc_component *component = mbhc->component;
int ret;

ret = pm_runtime_get_sync(component->dev);
ret = pm_runtime_resume_and_get(component->dev);
if (ret < 0 && ret != -EACCES) {
dev_err_ratelimited(component->dev,
"pm_runtime_get_sync failed in %s, ret %d\n",
"pm_runtime_resume_and_get failed in %s, ret %d\n",
__func__, ret);
pm_runtime_put_noidle(component->dev);
return ret;
}

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

ret = pm_runtime_get_sync(component->dev);
ret = pm_runtime_resume_and_get(component->dev);
if (ret < 0 && ret != -EACCES) {
dev_err_ratelimited(component->dev,
"pm_runtime_get_sync failed in %s, ret %d\n",
"pm_runtime_resume_and_get failed in %s, ret %d\n",
__func__, ret);
pm_runtime_put_noidle(component->dev);
return;
}
micbias_mv = wcd_mbhc_get_micbias(mbhc);
Expand Down
6 changes: 2 additions & 4 deletions sound/soc/codecs/wsa881x.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,9 @@ static int wsa881x_put_pa_gain(struct snd_kcontrol *kc,
unsigned int mask = (1 << fls(max)) - 1;
int val, ret, min_gain, max_gain;

ret = pm_runtime_get_sync(comp->dev);
if (ret < 0 && ret != -EACCES) {
pm_runtime_put_noidle(comp->dev);
ret = pm_runtime_resume_and_get(comp->dev);
if (ret < 0 && ret != -EACCES)
return ret;
}

max_gain = (max - ucontrol->value.integer.value[0]) & mask;
/*
Expand Down
6 changes: 2 additions & 4 deletions sound/soc/fsl/fsl_sai.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,11 +1141,9 @@ static int fsl_sai_probe(struct platform_device *pdev)
goto err_pm_disable;
}

ret = pm_runtime_get_sync(dev);
if (ret < 0) {
pm_runtime_put_noidle(dev);
ret = pm_runtime_resume_and_get(dev);
if (ret < 0)
goto err_pm_get_sync;
}

/* Get sai version */
ret = fsl_sai_check_version(dev);
Expand Down
12 changes: 4 additions & 8 deletions sound/soc/img/img-i2s-out.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,9 @@ static int img_i2s_out_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)

chan_control_mask = IMG_I2S_OUT_CHAN_CTL_CLKT_MASK;

ret = pm_runtime_get_sync(i2s->dev);
if (ret < 0) {
pm_runtime_put_noidle(i2s->dev);
ret = pm_runtime_resume_and_get(i2s->dev);
if (ret < 0)
return ret;
}

img_i2s_out_disable(i2s);

Expand Down Expand Up @@ -482,11 +480,9 @@ static int img_i2s_out_probe(struct platform_device *pdev)
if (ret)
goto err_pm_disable;
}
ret = pm_runtime_get_sync(&pdev->dev);
if (ret < 0) {
pm_runtime_put_noidle(&pdev->dev);
ret = pm_runtime_resume_and_get(&pdev->dev);
if (ret < 0)
goto err_suspend;
}

reg = IMG_I2S_OUT_CTL_FRM_SIZE_MASK;
img_i2s_out_writel(i2s, reg, IMG_I2S_OUT_CTL);
Expand Down
26 changes: 20 additions & 6 deletions sound/soc/intel/catpt/pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,9 @@ static int catpt_dai_pcm_new(struct snd_soc_pcm_runtime *rtm,
if (!memcmp(&cdev->devfmt[devfmt.iface], &devfmt, sizeof(devfmt)))
return 0;

pm_runtime_get_sync(cdev->dev);
ret = pm_runtime_resume_and_get(cdev->dev);
if (ret < 0 && ret != -EACCES)
return ret;

ret = catpt_ipc_set_device_format(cdev, &devfmt);

Expand Down Expand Up @@ -853,9 +855,12 @@ static int catpt_mixer_volume_get(struct snd_kcontrol *kcontrol,
snd_soc_kcontrol_component(kcontrol);
struct catpt_dev *cdev = dev_get_drvdata(component->dev);
u32 dspvol;
int ret;
int i;

pm_runtime_get_sync(cdev->dev);
ret = pm_runtime_resume_and_get(cdev->dev);
if (ret < 0 && ret != -EACCES)
return ret;

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

pm_runtime_get_sync(cdev->dev);
ret = pm_runtime_resume_and_get(cdev->dev);
if (ret < 0 && ret != -EACCES)
return ret;

ret = catpt_set_dspvol(cdev, cdev->mixer.mixer_hw_id,
ucontrol->value.integer.value);
Expand All @@ -897,6 +904,7 @@ static int catpt_stream_volume_get(struct snd_kcontrol *kcontrol,
struct catpt_dev *cdev = dev_get_drvdata(component->dev);
long *ctlvol = (long *)kcontrol->private_value;
u32 dspvol;
int ret;
int i;

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

pm_runtime_get_sync(cdev->dev);
ret = pm_runtime_resume_and_get(cdev->dev);
if (ret < 0 && ret != -EACCES)
return ret;

for (i = 0; i < CATPT_CHANNELS_MAX; i++) {
dspvol = catpt_stream_volume(cdev, stream, i);
Expand Down Expand Up @@ -937,7 +947,9 @@ static int catpt_stream_volume_put(struct snd_kcontrol *kcontrol,
return 0;
}

pm_runtime_get_sync(cdev->dev);
ret = pm_runtime_resume_and_get(cdev->dev);
if (ret < 0 && ret != -EACCES)
return ret;

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

pm_runtime_get_sync(cdev->dev);
ret = pm_runtime_resume_and_get(cdev->dev);
if (ret < 0 && ret != -EACCES)
return ret;

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

Expand Down
4 changes: 3 additions & 1 deletion sound/soc/intel/catpt/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ static ssize_t fw_version_show(struct device *dev,
struct catpt_fw_version version;
int ret;

pm_runtime_get_sync(cdev->dev);
ret = pm_runtime_resume_and_get(cdev->dev);
if (ret < 0 && ret != -EACCES)
return ret;

ret = catpt_ipc_get_fw_version(cdev, &version);

Expand Down
5 changes: 4 additions & 1 deletion sound/soc/intel/skylake/skl-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,10 @@ static int skl_platform_soc_probe(struct snd_soc_component *component)
const struct skl_dsp_ops *ops;
int ret;

pm_runtime_get_sync(component->dev);
ret = pm_runtime_resume_and_get(component->dev);
if (ret < 0 && ret != -EACCES)
return ret;

if (bus->ppcap) {
skl->component = component;

Expand Down
6 changes: 2 additions & 4 deletions sound/soc/rockchip/rockchip_i2s_tdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,9 @@ static int rockchip_i2s_tdm_set_fmt(struct snd_soc_dai *cpu_dai,
int ret;
bool is_tdm = i2s_tdm->tdm_mode;

ret = pm_runtime_get_sync(cpu_dai->dev);
if (ret < 0 && ret != -EACCES) {
pm_runtime_put_noidle(cpu_dai->dev);
ret = pm_runtime_resume_and_get(cpu_dai->dev);
if (ret < 0 && ret != -EACCES)
return ret;
}

mask = I2S_CKR_MSS_MASK;
switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
Expand Down
6 changes: 2 additions & 4 deletions sound/soc/rockchip/rockchip_pdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,9 @@ static int rockchip_pdm_resume(struct device *dev)
struct rk_pdm_dev *pdm = dev_get_drvdata(dev);
int ret;

ret = pm_runtime_get_sync(dev);
if (ret < 0) {
pm_runtime_put(dev);
ret = pm_runtime_resume_and_get(dev);
if (ret < 0)
return ret;
}

ret = regcache_sync(pdm->regmap);

Expand Down
3 changes: 1 addition & 2 deletions sound/soc/ti/davinci-mcasp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2111,8 +2111,7 @@ static int davinci_mcasp_gpio_request(struct gpio_chip *chip, unsigned offset)
}

/* Do not change the PIN yet */

return pm_runtime_get_sync(mcasp->dev);
return pm_runtime_resume_and_get(mcasp->dev);
}

static void davinci_mcasp_gpio_free(struct gpio_chip *chip, unsigned offset)
Expand Down

0 comments on commit 1e0ec03

Please sign in to comment.