Commit f2a227cd authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda/realtek - Optimize alc888_coef_init()

Just a refactoring using the existing helper functions.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent e52faba0
...@@ -128,6 +128,43 @@ struct alc_spec { ...@@ -128,6 +128,43 @@ struct alc_spec {
unsigned int coef0; unsigned int coef0;
}; };
/*
* COEF access helper functions
*/
static int alc_read_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
unsigned int coef_idx)
{
unsigned int val;
snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, coef_idx);
val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
return val;
}
#define alc_read_coef_idx(codec, coef_idx) \
alc_read_coefex_idx(codec, 0x20, coef_idx)
static void alc_write_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
unsigned int coef_idx, unsigned int coef_val)
{
snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, coef_idx);
snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PROC_COEF, coef_val);
}
#define alc_write_coef_idx(codec, coef_idx, coef_val) \
alc_write_coefex_idx(codec, 0x20, coef_idx, coef_val)
/* a special bypass for COEF 0; read the cached value at the second time */
static unsigned int alc_get_coef0(struct hda_codec *codec)
{
struct alc_spec *spec = codec->spec;
if (!spec->coef0)
spec->coef0 = alc_read_coef_idx(codec, 0);
return spec->coef0;
}
/* /*
* Append the given mixer and verb elements for the later use * Append the given mixer and verb elements for the later use
* The mixer array is referred in build_controls(), and init_verbs are * The mixer array is referred in build_controls(), and init_verbs are
...@@ -231,19 +268,12 @@ static void alc880_unsol_event(struct hda_codec *codec, unsigned int res) ...@@ -231,19 +268,12 @@ static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
/* additional initialization for ALC888 variants */ /* additional initialization for ALC888 variants */
static void alc888_coef_init(struct hda_codec *codec) static void alc888_coef_init(struct hda_codec *codec)
{ {
unsigned int tmp; if (alc_get_coef0(codec) == 0x20)
snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
if ((tmp & 0xf0) == 0x20)
/* alc888S-VC */ /* alc888S-VC */
snd_hda_codec_read(codec, 0x20, 0, alc_write_coef_idx(codec, 7, 0x830);
AC_VERB_SET_PROC_COEF, 0x830);
else else
/* alc888-VB */ /* alc888-VB */
snd_hda_codec_read(codec, 0x20, 0, alc_write_coef_idx(codec, 7, 0x3030);
AC_VERB_SET_PROC_COEF, 0x3030);
} }
/* additional initialization for ALC889 variants */ /* additional initialization for ALC889 variants */
...@@ -586,47 +616,6 @@ static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports) ...@@ -586,47 +616,6 @@ static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
} }
} }
/*
* COEF access helper functions
*/
static int alc_read_coefex_idx(struct hda_codec *codec,
hda_nid_t nid,
unsigned int coef_idx)
{
unsigned int val;
snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX,
coef_idx);
val = snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PROC_COEF, 0);
return val;
}
#define alc_read_coef_idx(codec, coef_idx) \
alc_read_coefex_idx(codec, 0x20, coef_idx)
static void alc_write_coefex_idx(struct hda_codec *codec, hda_nid_t nid,
unsigned int coef_idx,
unsigned int coef_val)
{
snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX,
coef_idx);
snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PROC_COEF,
coef_val);
}
#define alc_write_coef_idx(codec, coef_idx, coef_val) \
alc_write_coefex_idx(codec, 0x20, coef_idx, coef_val)
/* a special bypass for COEF 0; read the cached value at the second time */
static unsigned int alc_get_coef0(struct hda_codec *codec)
{
struct alc_spec *spec = codec->spec;
if (!spec->coef0)
spec->coef0 = alc_read_coef_idx(codec, 0);
return spec->coef0;
}
/* /*
*/ */
......
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