ALSA: hda/realtek - Optimize alc888_coef_init()
authorTakashi Iwai <tiwai@suse.de>
Mon, 18 Aug 2014 11:35:22 +0000 (13:35 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 19 Aug 2014 06:04:31 +0000 (08:04 +0200)
Just a refactoring using the existing helper functions.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/patch_realtek.c

index d71270a3f73f7ec1826397fe45c00e53fa143a1a..c9a7a2d237da46cd162c25d618f48c26342e3080 100644 (file)
@@ -128,6 +128,43 @@ struct alc_spec {
        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
  * 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)
 /* additional initialization for ALC888 variants */
 static void alc888_coef_init(struct hda_codec *codec)
 {
-       unsigned int tmp;
-
-       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)
+       if (alc_get_coef0(codec) == 0x20)
                /* alc888S-VC */
-               snd_hda_codec_read(codec, 0x20, 0,
-                                  AC_VERB_SET_PROC_COEF, 0x830);
+               alc_write_coef_idx(codec, 7, 0x830);
         else
                 /* alc888-VB */
-                snd_hda_codec_read(codec, 0x20, 0,
-                                   AC_VERB_SET_PROC_COEF, 0x3030);
+               alc_write_coef_idx(codec, 7, 0x3030);
 }
 
 /* additional initialization for ALC889 variants */
@@ -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;
-}
-
 /*
  */