Commit 1e0ec034 authored by Mark Brown's avatar Mark Brown

ASoC: use pm_runtime_resume_and_get() when possible

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.
parents bd10b0da cecc81d6
...@@ -581,7 +581,7 @@ static int tas2552_component_probe(struct snd_soc_component *component) ...@@ -581,7 +581,7 @@ static int tas2552_component_probe(struct snd_soc_component *component)
gpiod_set_value(tas2552->enable_gpio, 1); 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) { if (ret < 0) {
dev_err(component->dev, "Enabling device failed: %d\n", dev_err(component->dev, "Enabling device failed: %d\n",
ret); ret);
......
...@@ -714,12 +714,11 @@ static int wcd_mbhc_initialise(struct wcd_mbhc *mbhc) ...@@ -714,12 +714,11 @@ static int wcd_mbhc_initialise(struct wcd_mbhc *mbhc)
struct snd_soc_component *component = mbhc->component; struct snd_soc_component *component = mbhc->component;
int ret; int ret;
ret = pm_runtime_get_sync(component->dev); ret = pm_runtime_resume_and_get(component->dev);
if (ret < 0 && ret != -EACCES) { if (ret < 0 && ret != -EACCES) {
dev_err_ratelimited(component->dev, 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); __func__, ret);
pm_runtime_put_noidle(component->dev);
return ret; return ret;
} }
...@@ -1097,12 +1096,11 @@ static void wcd_correct_swch_plug(struct work_struct *work) ...@@ -1097,12 +1096,11 @@ static void wcd_correct_swch_plug(struct work_struct *work)
mbhc = container_of(work, struct wcd_mbhc, correct_plug_swch); mbhc = container_of(work, struct wcd_mbhc, correct_plug_swch);
component = mbhc->component; component = mbhc->component;
ret = pm_runtime_get_sync(component->dev); ret = pm_runtime_resume_and_get(component->dev);
if (ret < 0 && ret != -EACCES) { if (ret < 0 && ret != -EACCES) {
dev_err_ratelimited(component->dev, 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); __func__, ret);
pm_runtime_put_noidle(component->dev);
return; return;
} }
micbias_mv = wcd_mbhc_get_micbias(mbhc); micbias_mv = wcd_mbhc_get_micbias(mbhc);
......
...@@ -749,11 +749,9 @@ static int wsa881x_put_pa_gain(struct snd_kcontrol *kc, ...@@ -749,11 +749,9 @@ static int wsa881x_put_pa_gain(struct snd_kcontrol *kc,
unsigned int mask = (1 << fls(max)) - 1; unsigned int mask = (1 << fls(max)) - 1;
int val, ret, min_gain, max_gain; int val, ret, min_gain, max_gain;
ret = pm_runtime_get_sync(comp->dev); ret = pm_runtime_resume_and_get(comp->dev);
if (ret < 0 && ret != -EACCES) { if (ret < 0 && ret != -EACCES)
pm_runtime_put_noidle(comp->dev);
return ret; return ret;
}
max_gain = (max - ucontrol->value.integer.value[0]) & mask; max_gain = (max - ucontrol->value.integer.value[0]) & mask;
/* /*
......
...@@ -1141,11 +1141,9 @@ static int fsl_sai_probe(struct platform_device *pdev) ...@@ -1141,11 +1141,9 @@ static int fsl_sai_probe(struct platform_device *pdev)
goto err_pm_disable; goto err_pm_disable;
} }
ret = pm_runtime_get_sync(dev); ret = pm_runtime_resume_and_get(dev);
if (ret < 0) { if (ret < 0)
pm_runtime_put_noidle(dev);
goto err_pm_get_sync; goto err_pm_get_sync;
}
/* Get sai version */ /* Get sai version */
ret = fsl_sai_check_version(dev); ret = fsl_sai_check_version(dev);
......
...@@ -346,11 +346,9 @@ static int img_i2s_out_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) ...@@ -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; chan_control_mask = IMG_I2S_OUT_CHAN_CTL_CLKT_MASK;
ret = pm_runtime_get_sync(i2s->dev); ret = pm_runtime_resume_and_get(i2s->dev);
if (ret < 0) { if (ret < 0)
pm_runtime_put_noidle(i2s->dev);
return ret; return ret;
}
img_i2s_out_disable(i2s); img_i2s_out_disable(i2s);
...@@ -482,11 +480,9 @@ static int img_i2s_out_probe(struct platform_device *pdev) ...@@ -482,11 +480,9 @@ static int img_i2s_out_probe(struct platform_device *pdev)
if (ret) if (ret)
goto err_pm_disable; goto err_pm_disable;
} }
ret = pm_runtime_get_sync(&pdev->dev); ret = pm_runtime_resume_and_get(&pdev->dev);
if (ret < 0) { if (ret < 0)
pm_runtime_put_noidle(&pdev->dev);
goto err_suspend; goto err_suspend;
}
reg = IMG_I2S_OUT_CTL_FRM_SIZE_MASK; reg = IMG_I2S_OUT_CTL_FRM_SIZE_MASK;
img_i2s_out_writel(i2s, reg, IMG_I2S_OUT_CTL); img_i2s_out_writel(i2s, reg, IMG_I2S_OUT_CTL);
......
...@@ -667,7 +667,9 @@ static int catpt_dai_pcm_new(struct snd_soc_pcm_runtime *rtm, ...@@ -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))) if (!memcmp(&cdev->devfmt[devfmt.iface], &devfmt, sizeof(devfmt)))
return 0; 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); ret = catpt_ipc_set_device_format(cdev, &devfmt);
...@@ -853,9 +855,12 @@ static int catpt_mixer_volume_get(struct snd_kcontrol *kcontrol, ...@@ -853,9 +855,12 @@ static int catpt_mixer_volume_get(struct snd_kcontrol *kcontrol,
snd_soc_kcontrol_component(kcontrol); snd_soc_kcontrol_component(kcontrol);
struct catpt_dev *cdev = dev_get_drvdata(component->dev); struct catpt_dev *cdev = dev_get_drvdata(component->dev);
u32 dspvol; u32 dspvol;
int ret;
int i; 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++) { for (i = 0; i < CATPT_CHANNELS_MAX; i++) {
dspvol = catpt_mixer_volume(cdev, &cdev->mixer, i); dspvol = catpt_mixer_volume(cdev, &cdev->mixer, i);
...@@ -876,7 +881,9 @@ static int catpt_mixer_volume_put(struct snd_kcontrol *kcontrol, ...@@ -876,7 +881,9 @@ static int catpt_mixer_volume_put(struct snd_kcontrol *kcontrol,
struct catpt_dev *cdev = dev_get_drvdata(component->dev); struct catpt_dev *cdev = dev_get_drvdata(component->dev);
int ret; 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, ret = catpt_set_dspvol(cdev, cdev->mixer.mixer_hw_id,
ucontrol->value.integer.value); ucontrol->value.integer.value);
...@@ -897,6 +904,7 @@ static int catpt_stream_volume_get(struct snd_kcontrol *kcontrol, ...@@ -897,6 +904,7 @@ static int catpt_stream_volume_get(struct snd_kcontrol *kcontrol,
struct catpt_dev *cdev = dev_get_drvdata(component->dev); struct catpt_dev *cdev = dev_get_drvdata(component->dev);
long *ctlvol = (long *)kcontrol->private_value; long *ctlvol = (long *)kcontrol->private_value;
u32 dspvol; u32 dspvol;
int ret;
int i; int i;
stream = catpt_stream_find(cdev, pin_id); stream = catpt_stream_find(cdev, pin_id);
...@@ -906,7 +914,9 @@ static int catpt_stream_volume_get(struct snd_kcontrol *kcontrol, ...@@ -906,7 +914,9 @@ static int catpt_stream_volume_get(struct snd_kcontrol *kcontrol,
return 0; 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++) { for (i = 0; i < CATPT_CHANNELS_MAX; i++) {
dspvol = catpt_stream_volume(cdev, stream, i); dspvol = catpt_stream_volume(cdev, stream, i);
...@@ -937,7 +947,9 @@ static int catpt_stream_volume_put(struct snd_kcontrol *kcontrol, ...@@ -937,7 +947,9 @@ static int catpt_stream_volume_put(struct snd_kcontrol *kcontrol,
return 0; 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, ret = catpt_set_dspvol(cdev, stream->info.stream_hw_id,
ucontrol->value.integer.value); ucontrol->value.integer.value);
...@@ -1013,7 +1025,9 @@ static int catpt_loopback_switch_put(struct snd_kcontrol *kcontrol, ...@@ -1013,7 +1025,9 @@ static int catpt_loopback_switch_put(struct snd_kcontrol *kcontrol,
return 0; 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); ret = catpt_ipc_mute_loopback(cdev, stream->info.stream_hw_id, mute);
......
...@@ -15,7 +15,9 @@ static ssize_t fw_version_show(struct device *dev, ...@@ -15,7 +15,9 @@ static ssize_t fw_version_show(struct device *dev,
struct catpt_fw_version version; struct catpt_fw_version version;
int ret; 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); ret = catpt_ipc_get_fw_version(cdev, &version);
......
...@@ -1380,7 +1380,10 @@ static int skl_platform_soc_probe(struct snd_soc_component *component) ...@@ -1380,7 +1380,10 @@ static int skl_platform_soc_probe(struct snd_soc_component *component)
const struct skl_dsp_ops *ops; const struct skl_dsp_ops *ops;
int ret; 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) { if (bus->ppcap) {
skl->component = component; skl->component = component;
......
...@@ -404,11 +404,9 @@ static int rockchip_i2s_tdm_set_fmt(struct snd_soc_dai *cpu_dai, ...@@ -404,11 +404,9 @@ static int rockchip_i2s_tdm_set_fmt(struct snd_soc_dai *cpu_dai,
int ret; int ret;
bool is_tdm = i2s_tdm->tdm_mode; bool is_tdm = i2s_tdm->tdm_mode;
ret = pm_runtime_get_sync(cpu_dai->dev); ret = pm_runtime_resume_and_get(cpu_dai->dev);
if (ret < 0 && ret != -EACCES) { if (ret < 0 && ret != -EACCES)
pm_runtime_put_noidle(cpu_dai->dev);
return ret; return ret;
}
mask = I2S_CKR_MSS_MASK; mask = I2S_CKR_MSS_MASK;
switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
......
...@@ -688,11 +688,9 @@ static int rockchip_pdm_resume(struct device *dev) ...@@ -688,11 +688,9 @@ static int rockchip_pdm_resume(struct device *dev)
struct rk_pdm_dev *pdm = dev_get_drvdata(dev); struct rk_pdm_dev *pdm = dev_get_drvdata(dev);
int ret; int ret;
ret = pm_runtime_get_sync(dev); ret = pm_runtime_resume_and_get(dev);
if (ret < 0) { if (ret < 0)
pm_runtime_put(dev);
return ret; return ret;
}
ret = regcache_sync(pdm->regmap); ret = regcache_sync(pdm->regmap);
......
...@@ -2111,8 +2111,7 @@ static int davinci_mcasp_gpio_request(struct gpio_chip *chip, unsigned offset) ...@@ -2111,8 +2111,7 @@ static int davinci_mcasp_gpio_request(struct gpio_chip *chip, unsigned offset)
} }
/* Do not change the PIN yet */ /* Do not change the PIN yet */
return pm_runtime_resume_and_get(mcasp->dev);
return pm_runtime_get_sync(mcasp->dev);
} }
static void davinci_mcasp_gpio_free(struct gpio_chip *chip, unsigned offset) static void davinci_mcasp_gpio_free(struct gpio_chip *chip, unsigned offset)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment