Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7504b6cd authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: hda - Move beep attach/detach calls in hda_generic.c



Instead of calling snd_hda_attach_beep_device() and
snd_hda_detach_beep_device() in each codec driver, move them to the
generic parser.  The codec driver just needs to set spec->beep_nid for
activating the digital beep.

Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent cf30f46a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include "hda_local.h"
#include "hda_auto_parser.h"
#include "hda_jack.h"
#include "hda_beep.h"
#include "hda_generic.h"


@@ -4238,6 +4239,12 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
	if (spec->power_down_unused)
		codec->power_filter = snd_hda_gen_path_power_filter;

	if (!spec->no_analog && spec->beep_nid) {
		err = snd_hda_attach_beep_device(codec, spec->beep_nid);
		if (err < 0)
			return err;
	}

	return 1;
}
EXPORT_SYMBOL_HDA(snd_hda_gen_parse_auto_config);
@@ -5063,6 +5070,7 @@ EXPORT_SYMBOL_HDA(snd_hda_gen_init);
 */
void snd_hda_gen_free(struct hda_codec *codec)
{
	snd_hda_detach_beep_device(codec);
	snd_hda_gen_spec_free(codec->spec);
	kfree(codec->spec);
	codec->spec = NULL;
+3 −0
Original line number Diff line number Diff line
@@ -226,6 +226,9 @@ struct hda_gen_spec {
	/* loopback mixing mode */
	bool aamix_mode;

	/* digital beep */
	hda_nid_t beep_nid;

	/* for virtual master */
	hda_nid_t vmaster_nid;
	unsigned int vmaster_tlv[4];
+13 −20
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ struct ad198x_spec {
	hda_nid_t eapd_nid;

	unsigned int beep_amp;	/* beep amp value, set via set_beep_amp() */
	hda_nid_t beep_dev_nid;

#ifdef ENABLE_AD_STATIC_QUIRKS
	const struct snd_kcontrol_new *mixers[6];
@@ -609,7 +608,7 @@ static const struct hda_codec_ops ad198x_auto_patch_ops = {
	.build_controls = ad198x_auto_build_controls,
	.build_pcms = snd_hda_gen_build_pcms,
	.init = snd_hda_gen_init,
	.free = ad198x_free,
	.free = snd_hda_gen_free,
	.unsol_event = snd_hda_jack_unsol_event,
#ifdef CONFIG_PM
	.check_power_status = snd_hda_gen_check_power_status,
@@ -638,12 +637,6 @@ static int ad198x_parse_auto_config(struct hda_codec *codec)
	if (err < 0)
		return err;

	if (spec->beep_dev_nid) {
		err = snd_hda_attach_beep_device(codec, spec->beep_dev_nid);
		if (err < 0)
			return err;
	}

	codec->patch_ops = ad198x_auto_patch_ops;

	return 0;
@@ -1240,7 +1233,7 @@ static int ad1986a_parse_auto_config(struct hda_codec *codec)
	codec->inv_eapd = 1;

	spec->gen.mixer_nid = 0x07;
	spec->beep_dev_nid = 0x19;
	spec->gen.beep_nid = 0x19;
	set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);

	/* AD1986A has a hardware problem that it can't share a stream
@@ -1256,7 +1249,7 @@ static int ad1986a_parse_auto_config(struct hda_codec *codec)

	err = ad198x_parse_auto_config(codec);
	if (err < 0) {
		ad198x_free(codec);
		snd_hda_gen_free(codec);
		return err;
	}

@@ -1673,7 +1666,7 @@ static int ad1983_parse_auto_config(struct hda_codec *codec)
		return err;
	spec = codec->spec;

	spec->beep_dev_nid = 0x10;
	spec->gen.beep_nid = 0x10;
	set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
	err = ad198x_parse_auto_config(codec);
	if (err < 0)
@@ -1684,7 +1677,7 @@ static int ad1983_parse_auto_config(struct hda_codec *codec)
	return 0;

 error:
	ad198x_free(codec);
	snd_hda_gen_free(codec);
	return err;
}

@@ -2187,7 +2180,7 @@ static int ad1981_parse_auto_config(struct hda_codec *codec)
	spec = codec->spec;

	spec->gen.mixer_nid = 0x0e;
	spec->beep_dev_nid = 0x10;
	spec->gen.beep_nid = 0x10;
	set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);

	snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
@@ -2205,7 +2198,7 @@ static int ad1981_parse_auto_config(struct hda_codec *codec)
	return 0;

 error:
	ad198x_free(codec);
	snd_hda_gen_free(codec);
	return err;
}

@@ -3236,7 +3229,7 @@ static int ad1988_parse_auto_config(struct hda_codec *codec)

	spec->gen.mixer_nid = 0x20;
	spec->gen.mixer_merge_nid = 0x21;
	spec->beep_dev_nid = 0x10;
	spec->gen.beep_nid = 0x10;
	set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
	err = ad198x_parse_auto_config(codec);
	if (err < 0)
@@ -3247,7 +3240,7 @@ static int ad1988_parse_auto_config(struct hda_codec *codec)
	return 0;

 error:
	ad198x_free(codec);
	snd_hda_gen_free(codec);
	return err;
}

@@ -3653,7 +3646,7 @@ static int ad1884_parse_auto_config(struct hda_codec *codec)
	spec = codec->spec;

	spec->gen.mixer_nid = 0x20;
	spec->beep_dev_nid = 0x10;
	spec->gen.beep_nid = 0x10;
	set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);

	snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
@@ -3671,7 +3664,7 @@ static int ad1884_parse_auto_config(struct hda_codec *codec)
	return 0;

 error:
	ad198x_free(codec);
	snd_hda_gen_free(codec);
	return err;
}

@@ -5155,7 +5148,7 @@ static int ad1882_parse_auto_config(struct hda_codec *codec)

	spec->gen.mixer_nid = 0x20;
	spec->gen.mixer_merge_nid = 0x21;
	spec->beep_dev_nid = 0x10;
	spec->gen.beep_nid = 0x10;
	set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
	err = ad198x_parse_auto_config(codec);
	if (err < 0)
@@ -5166,7 +5159,7 @@ static int ad1882_parse_auto_config(struct hda_codec *codec)
	return 0;

 error:
	ad198x_free(codec);
	snd_hda_gen_free(codec);
	return err;
}

+7 −11
Original line number Diff line number Diff line
@@ -139,8 +139,12 @@ struct conexant_spec {


#ifdef CONFIG_SND_HDA_INPUT_BEEP
#define set_beep_amp(spec, nid, idx, dir) \
	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
				int idx, int dir)
{
	spec->gen.beep_nid = nid;
	spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
}
/* additional beep mixers; the actual parameters are overwritten at build */
static const struct snd_kcontrol_new cxt_beep_mixer[] = {
	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
@@ -3191,17 +3195,11 @@ static int cx_auto_build_controls(struct hda_codec *codec)
	return 0;
}

static void cx_auto_free(struct hda_codec *codec)
{
	snd_hda_detach_beep_device(codec);
	snd_hda_gen_free(codec);
}

static const struct hda_codec_ops cx_auto_patch_ops = {
	.build_controls = cx_auto_build_controls,
	.build_pcms = snd_hda_gen_build_pcms,
	.init = snd_hda_gen_init,
	.free = cx_auto_free,
	.free = snd_hda_gen_free,
	.unsol_event = snd_hda_jack_unsol_event,
#ifdef CONFIG_PM
	.check_power_status = snd_hda_gen_check_power_status,
@@ -3395,8 +3393,6 @@ static int patch_conexant_auto(struct hda_codec *codec)
		goto error;

	codec->patch_ops = cx_auto_patch_ops;
	if (spec->beep_amp)
		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));

	/* Some laptops with Conexant chips show stalls in S3 resume,
	 * which falls into the single-cmd mode.
+32 −74
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
#include "hda_codec.h"
#include "hda_local.h"
#include "hda_auto_parser.h"
#include "hda_beep.h"
#include "hda_jack.h"
#include "hda_generic.h"

@@ -805,17 +804,7 @@ static inline void alc_shutup(struct hda_codec *codec)
	snd_hda_shutup_pins(codec);
}

static void alc_free(struct hda_codec *codec)
{
	struct alc_spec *spec = codec->spec;

	if (!spec)
		return;

	snd_hda_gen_spec_free(&spec->gen);
	snd_hda_detach_beep_device(codec);
	kfree(spec);
}
#define alc_free	snd_hda_gen_free

#ifdef CONFIG_PM
static void alc_power_eapd(struct hda_codec *codec)
@@ -1401,6 +1390,7 @@ static int patch_alc880(struct hda_codec *codec)

	spec = codec->spec;
	spec->gen.need_dac_fix = 1;
	spec->gen.beep_nid = 0x01;

	snd_hda_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
		       alc880_fixups);
@@ -1411,12 +1401,8 @@ static int patch_alc880(struct hda_codec *codec)
	if (err < 0)
		goto error;

	if (!spec->gen.no_analog) {
		err = snd_hda_attach_beep_device(codec, 0x1);
		if (err < 0)
			goto error;
	if (!spec->gen.no_analog)
		set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
	}

	codec->patch_ops = alc_patch_ops;
	codec->patch_ops.unsol_event = alc880_unsol_event;
@@ -1637,6 +1623,7 @@ static int patch_alc260(struct hda_codec *codec)
	 * it's almost harmless.
	 */
	spec->gen.prefer_hp_amp = 1;
	spec->gen.beep_nid = 0x01;

	snd_hda_pick_fixup(codec, alc260_fixup_models, alc260_fixup_tbl,
			   alc260_fixups);
@@ -1647,12 +1634,8 @@ static int patch_alc260(struct hda_codec *codec)
	if (err < 0)
		goto error;

	if (!spec->gen.no_analog) {
		err = snd_hda_attach_beep_device(codec, 0x1);
		if (err < 0)
			goto error;
	if (!spec->gen.no_analog)
		set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
	}

	codec->patch_ops = alc_patch_ops;
	spec->shutup = alc_eapd_shutup;
@@ -2151,17 +2134,16 @@ static int patch_alc882(struct hda_codec *codec)

	alc_auto_parse_customize_define(codec);

	if (has_cdefine_beep(codec))
		spec->gen.beep_nid = 0x01;

	/* automatic parse from the BIOS config */
	err = alc882_parse_auto_config(codec);
	if (err < 0)
		goto error;

	if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
		err = snd_hda_attach_beep_device(codec, 0x1);
		if (err < 0)
			goto error;
	if (!spec->gen.no_analog && spec->gen.beep_nid)
		set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
	}

	codec->patch_ops = alc_patch_ops;

@@ -2314,17 +2296,16 @@ static int patch_alc262(struct hda_codec *codec)

	alc_auto_parse_customize_define(codec);

	if (has_cdefine_beep(codec))
		spec->gen.beep_nid = 0x01;

	/* automatic parse from the BIOS config */
	err = alc262_parse_auto_config(codec);
	if (err < 0)
		goto error;

	if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
		err = snd_hda_attach_beep_device(codec, 0x1);
		if (err < 0)
			goto error;
	if (!spec->gen.no_analog && spec->gen.beep_nid)
		set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
	}

	codec->patch_ops = alc_patch_ops;
	spec->shutup = alc_eapd_shutup;
@@ -2405,16 +2386,7 @@ static const struct snd_pci_quirk alc268_fixup_tbl[] = {
static int alc268_parse_auto_config(struct hda_codec *codec)
{
	static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
	struct alc_spec *spec = codec->spec;
	int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
	if (err > 0) {
		if (!spec->gen.no_analog &&
		    spec->gen.autocfg.speaker_pins[0] != 0x1d) {
			add_mixer(spec, alc268_beep_mixer);
			snd_hda_add_verbs(codec, alc268_beep_init_verbs);
		}
	}
	return err;
	return alc_parse_auto_config(codec, NULL, alc268_ssids);
}

/*
@@ -2422,7 +2394,7 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
static int patch_alc268(struct hda_codec *codec)
{
	struct alc_spec *spec;
	int i, has_beep, err;
	int err;

	/* ALC268 has no aa-loopback mixer */
	err = alc_alloc_spec(codec, 0);
@@ -2430,6 +2402,7 @@ static int patch_alc268(struct hda_codec *codec)
		return err;

	spec = codec->spec;
	spec->gen.beep_nid = 0x01;

	snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
@@ -2439,18 +2412,10 @@ static int patch_alc268(struct hda_codec *codec)
	if (err < 0)
		goto error;

	has_beep = 0;
	for (i = 0; i < spec->num_mixers; i++) {
		if (spec->mixers[i] == alc268_beep_mixer) {
			has_beep = 1;
			break;
		}
	}

	if (has_beep) {
		err = snd_hda_attach_beep_device(codec, 0x1);
		if (err < 0)
			goto error;
	if (err > 0 && !spec->gen.no_analog &&
	    spec->gen.autocfg.speaker_pins[0] != 0x1d) {
		add_mixer(spec, alc268_beep_mixer);
		snd_hda_add_verbs(codec, alc268_beep_init_verbs);
		if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
			/* override the amp caps for beep generator */
			snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
@@ -3150,6 +3115,9 @@ static int patch_alc269(struct hda_codec *codec)

	alc_auto_parse_customize_define(codec);

	if (has_cdefine_beep(codec))
		spec->gen.beep_nid = 0x01;

	switch (codec->vendor_id) {
	case 0x10ec0269:
		spec->codec_variant = ALC269_TYPE_ALC269VA;
@@ -3198,12 +3166,8 @@ static int patch_alc269(struct hda_codec *codec)
	if (err < 0)
		goto error;

	if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
		err = snd_hda_attach_beep_device(codec, 0x1);
		if (err < 0)
			goto error;
	if (!spec->gen.no_analog && spec->gen.beep_nid)
		set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
	}

	codec->patch_ops = alc_patch_ops;
#ifdef CONFIG_PM
@@ -3311,6 +3275,7 @@ static int patch_alc861(struct hda_codec *codec)
		return err;

	spec = codec->spec;
	spec->gen.beep_nid = 0x23;

	snd_hda_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
@@ -3320,12 +3285,8 @@ static int patch_alc861(struct hda_codec *codec)
	if (err < 0)
		goto error;

	if (!spec->gen.no_analog) {
		err = snd_hda_attach_beep_device(codec, 0x23);
		if (err < 0)
			goto error;
	if (!spec->gen.no_analog)
		set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
	}

	codec->patch_ops = alc_patch_ops;
#ifdef CONFIG_PM
@@ -3406,6 +3367,7 @@ static int patch_alc861vd(struct hda_codec *codec)
		return err;

	spec = codec->spec;
	spec->gen.beep_nid = 0x23;

	snd_hda_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
@@ -3415,12 +3377,8 @@ static int patch_alc861vd(struct hda_codec *codec)
	if (err < 0)
		goto error;

	if (!spec->gen.no_analog) {
		err = snd_hda_attach_beep_device(codec, 0x23);
		if (err < 0)
			goto error;
	if (!spec->gen.no_analog)
		set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
	}

	codec->patch_ops = alc_patch_ops;

@@ -3802,6 +3760,9 @@ static int patch_alc662(struct hda_codec *codec)

	alc_auto_parse_customize_define(codec);

	if (has_cdefine_beep(codec))
		spec->gen.beep_nid = 0x01;

	if ((alc_get_coef0(codec) & (1 << 14)) &&
	    codec->bus->pci->subsystem_vendor == 0x1025 &&
	    spec->cdefine.platform_type == 1) {
@@ -3814,10 +3775,7 @@ static int patch_alc662(struct hda_codec *codec)
	if (err < 0)
		goto error;

	if (!spec->gen.no_analog && has_cdefine_beep(codec)) {
		err = snd_hda_attach_beep_device(codec, 0x1);
		if (err < 0)
			goto error;
	if (!spec->gen.no_analog && spec->gen.beep_nid) {
		switch (codec->vendor_id) {
		case 0x10ec0662:
			set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Loading