Skip to content

Commit 23904f7

Browse files
Stefan Bindingtiwai
authored andcommitted
ALSA: hda: cs35l41: Remove suspend/resume hda hooks
The current code uses calls from the HDA Codec driver to determine when to suspend/resume by calling hooks via the hda_component binding. However, this means the cs35l41 driver relies on the HDA Codec driver to tell it when to suspend or resume, creating an additional external dependency, and potentially creating race conditions in the future. It is better for the cs35l41 hda driver to decide for itself when the part should be suspended or resumed. This makes supporting system suspend easier. Signed-off-by: Stefan Binding <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 2176c6b commit 23904f7

File tree

3 files changed

+13
-39
lines changed

3 files changed

+13
-39
lines changed

sound/pci/hda/cs35l41_hda.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,10 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
487487
struct regmap *reg = cs35l41->regmap;
488488
int ret = 0;
489489

490-
mutex_lock(&cs35l41->fw_mutex);
491-
492490
switch (action) {
493491
case HDA_GEN_PCM_ACT_OPEN:
492+
pm_runtime_get_sync(dev);
493+
mutex_lock(&cs35l41->fw_mutex);
494494
cs35l41->playback_started = true;
495495
if (cs35l41->firmware_running) {
496496
regmap_multi_reg_write(reg, cs35l41_hda_config_dsp,
@@ -508,15 +508,21 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
508508
CS35L41_AMP_EN_MASK, 1 << CS35L41_AMP_EN_SHIFT);
509509
if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST)
510510
regmap_write(reg, CS35L41_GPIO1_CTRL1, 0x00008001);
511+
mutex_unlock(&cs35l41->fw_mutex);
511512
break;
512513
case HDA_GEN_PCM_ACT_PREPARE:
514+
mutex_lock(&cs35l41->fw_mutex);
513515
ret = cs35l41_global_enable(reg, cs35l41->hw_cfg.bst_type, 1);
516+
mutex_unlock(&cs35l41->fw_mutex);
514517
break;
515518
case HDA_GEN_PCM_ACT_CLEANUP:
519+
mutex_lock(&cs35l41->fw_mutex);
516520
regmap_multi_reg_write(reg, cs35l41_hda_mute, ARRAY_SIZE(cs35l41_hda_mute));
517521
ret = cs35l41_global_enable(reg, cs35l41->hw_cfg.bst_type, 0);
522+
mutex_unlock(&cs35l41->fw_mutex);
518523
break;
519524
case HDA_GEN_PCM_ACT_CLOSE:
525+
mutex_lock(&cs35l41->fw_mutex);
520526
ret = regmap_update_bits(reg, CS35L41_PWR_CTRL2,
521527
CS35L41_AMP_EN_MASK, 0 << CS35L41_AMP_EN_SHIFT);
522528
if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST)
@@ -530,14 +536,16 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
530536
}
531537
cs35l41_irq_release(cs35l41);
532538
cs35l41->playback_started = false;
539+
mutex_unlock(&cs35l41->fw_mutex);
540+
541+
pm_runtime_mark_last_busy(dev);
542+
pm_runtime_put_autosuspend(dev);
533543
break;
534544
default:
535545
dev_warn(cs35l41->dev, "Playback action not supported: %d\n", action);
536546
break;
537547
}
538548

539-
mutex_unlock(&cs35l41->fw_mutex);
540-
541549
if (ret)
542550
dev_err(cs35l41->dev, "Regmap access fail: %d\n", ret);
543551
}
@@ -618,19 +626,6 @@ static int cs35l41_runtime_resume(struct device *dev)
618626
return 0;
619627
}
620628

621-
static int cs35l41_hda_suspend_hook(struct device *dev)
622-
{
623-
dev_dbg(dev, "Request Suspend\n");
624-
pm_runtime_mark_last_busy(dev);
625-
return pm_runtime_put_autosuspend(dev);
626-
}
627-
628-
static int cs35l41_hda_resume_hook(struct device *dev)
629-
{
630-
dev_dbg(dev, "Request Resume\n");
631-
return pm_runtime_get_sync(dev);
632-
}
633-
634629
static int cs35l41_smart_amp(struct cs35l41_hda *cs35l41)
635630
{
636631
int halo_sts;
@@ -863,8 +858,6 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
863858
ret = cs35l41_create_controls(cs35l41);
864859

865860
comps->playback_hook = cs35l41_hda_playback_hook;
866-
comps->suspend_hook = cs35l41_hda_suspend_hook;
867-
comps->resume_hook = cs35l41_hda_resume_hook;
868861

869862
pm_runtime_mark_last_busy(dev);
870863
pm_runtime_put_autosuspend(dev);

sound/pci/hda/hda_component.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ struct hda_component {
1616
char name[HDA_MAX_NAME_SIZE];
1717
struct hda_codec *codec;
1818
void (*playback_hook)(struct device *dev, int action);
19-
int (*suspend_hook)(struct device *dev);
20-
int (*resume_hook)(struct device *dev);
2119
};

sound/pci/hda/patch_realtek.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4022,22 +4022,16 @@ static void alc5505_dsp_init(struct hda_codec *codec)
40224022
static int alc269_suspend(struct hda_codec *codec)
40234023
{
40244024
struct alc_spec *spec = codec->spec;
4025-
int i;
40264025

40274026
if (spec->has_alc5505_dsp)
40284027
alc5505_dsp_suspend(codec);
40294028

4030-
for (i = 0; i < HDA_MAX_COMPONENTS; i++)
4031-
if (spec->comps[i].suspend_hook)
4032-
spec->comps[i].suspend_hook(spec->comps[i].dev);
4033-
40344029
return alc_suspend(codec);
40354030
}
40364031

40374032
static int alc269_resume(struct hda_codec *codec)
40384033
{
40394034
struct alc_spec *spec = codec->spec;
4040-
int i;
40414035

40424036
if (spec->codec_variant == ALC269_TYPE_ALC269VB)
40434037
alc269vb_toggle_power_output(codec, 0);
@@ -4068,10 +4062,6 @@ static int alc269_resume(struct hda_codec *codec)
40684062
if (spec->has_alc5505_dsp)
40694063
alc5505_dsp_resume(codec);
40704064

4071-
for (i = 0; i < HDA_MAX_COMPONENTS; i++)
4072-
if (spec->comps[i].resume_hook)
4073-
spec->comps[i].resume_hook(spec->comps[i].dev);
4074-
40754065
return 0;
40764066
}
40774067
#endif /* CONFIG_PM */
@@ -6664,19 +6654,12 @@ static int comp_bind(struct device *dev)
66646654
{
66656655
struct hda_codec *cdc = dev_to_hda_codec(dev);
66666656
struct alc_spec *spec = cdc->spec;
6667-
int ret, i;
6657+
int ret;
66686658

66696659
ret = component_bind_all(dev, spec->comps);
66706660
if (ret)
66716661
return ret;
66726662

6673-
if (snd_hdac_is_power_on(&cdc->core)) {
6674-
codec_dbg(cdc, "Resuming after bind.\n");
6675-
for (i = 0; i < HDA_MAX_COMPONENTS; i++)
6676-
if (spec->comps[i].resume_hook)
6677-
spec->comps[i].resume_hook(spec->comps[i].dev);
6678-
}
6679-
66806663
return 0;
66816664
}
66826665

0 commit comments

Comments
 (0)