]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ALSA: hda: Add sync version of snd_hda_codec_write()
authorTakashi Iwai <tiwai@suse.de>
Thu, 9 Apr 2026 09:38:14 +0000 (11:38 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 9 Apr 2026 10:05:54 +0000 (12:05 +0200)
We used snd_hda_codec_read() for the verb write when a synchronization
is needed after the write, e.g. for the power state toggle or such
cases.  It works in principle, but it looks rather confusing and too
hackish.

For improving the code readability, introduce a new helper function,
snd_hda_codec_write_sync(), which is another variant of
snd_hda_codec_write(), and replace the existing snd_hda_codec_read()
calls with this one.

No behavior change but just the code refactoring.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20260409093826.1317626-2-tiwai@suse.de
include/sound/hda_codec.h
sound/hda/codecs/generic.c
sound/hda/codecs/hdmi/intelhdmi.c
sound/hda/codecs/realtek/realtek.c
sound/hda/codecs/sigmatel.c
sound/hda/common/codec.c

index 5d9f0ef228af10d8db8f9af4eedc3023783f47a0..292d6024388b3e1a209cd126c683d87c5ec8de81 100644 (file)
@@ -336,6 +336,17 @@ snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
        return snd_hdac_codec_write(&codec->core, nid, flags, verb, parm);
 }
 
+/* sync after write */
+static inline int
+snd_hda_codec_write_sync(struct hda_codec *codec, hda_nid_t nid, int flags,
+                        unsigned int verb, unsigned int parm)
+{
+       /* use snd_hda_codec_read() for writing;
+        * the returned value is usually discarded
+        */
+       return snd_hdac_codec_read(&codec->core, nid, flags, verb, parm);
+}
+
 #define snd_hda_param_read(codec, nid, param) \
        snd_hdac_read_parm(&(codec)->core, nid, param)
 #define snd_hda_get_sub_nodes(codec, nid, start_nid) \
index 092428ada29d3e20b5180bcf2deaa99fb2d6d641..660a9f2c0dedcfd18cca3f597a6f7136267a1866 100644 (file)
@@ -863,7 +863,7 @@ static void sync_power_state_change(struct hda_codec *codec, hda_nid_t nid)
 {
        if (nid) {
                msleep(10);
-               snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
+               snd_hda_codec_write_sync(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
        }
 }
 
index 9460c8db39a93e8191c037a9ba92925644e5c7d2..6a7882544ab77668e4fad066c0b98627c19aca94 100644 (file)
@@ -85,7 +85,7 @@ static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
                }
        }
 
-       snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
+       snd_hda_codec_write_sync(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
        snd_hda_codec_set_power_to_all(codec, fg, power_state);
 }
 
index b240f13b043872b90898467546f690694bc7a7a1..39a1ead3b743668640d25f514fd43a32c1de0c10 100644 (file)
@@ -411,9 +411,8 @@ void alc_headset_mic_no_shutup(struct hda_codec *codec)
                return;
 
        snd_array_for_each(&codec->init_pins, i, pin) {
-               /* use read here for syncing after issuing each verb */
                if (pin->nid != mic_pin)
-                       snd_hda_codec_read(codec, pin->nid, 0,
+                       snd_hda_codec_write_sync(codec, pin->nid, 0,
                                        AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
        }
 
index acbbc7c3508be1bbc28850b2d07327755f6a4484..4ff80a65168fdbd8c039871c255b277cbd2d2567 100644 (file)
@@ -311,12 +311,12 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
 
        snd_hda_codec_write(codec, fg, 0,
                            AC_VERB_SET_GPIO_MASK, gpiomask);
-       snd_hda_codec_read(codec, fg, 0,
+       snd_hda_codec_write_sync(codec, fg, 0,
                           AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
 
        msleep(1);
 
-       snd_hda_codec_read(codec, fg, 0,
+       snd_hda_codec_write_sync(codec, fg, 0,
                           AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
 }
 
index 5123df32ad89f5a134994f63fa54eb050392f44f..3ac4bf6005d60d11dda2e7530ab8c9d185aea4fe 100644 (file)
@@ -606,9 +606,8 @@ void snd_hda_shutup_pins(struct hda_codec *codec)
        if (codec->bus->shutdown)
                return;
        snd_array_for_each(&codec->init_pins, i, pin) {
-               /* use read here for syncing after issuing each verb */
-               snd_hda_codec_read(codec, pin->nid, 0,
-                                  AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
+               snd_hda_codec_write_sync(codec, pin->nid, 0,
+                                        AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
        }
        codec->pins_shutup = 1;
 }
@@ -2794,9 +2793,9 @@ static unsigned int hda_set_power_state(struct hda_codec *codec,
                        if (codec->power_filter)
                                state = codec->power_filter(codec, fg, state);
                        if (state == power_state || power_state != AC_PWRST_D3)
-                               snd_hda_codec_read(codec, fg, flags,
-                                                  AC_VERB_SET_POWER_STATE,
-                                                  state);
+                               snd_hda_codec_write_sync(codec, fg, flags,
+                                                        AC_VERB_SET_POWER_STATE,
+                                                        state);
                        snd_hda_codec_set_power_to_all(codec, fg, power_state);
                }
                state = snd_hda_sync_power_state(codec, fg, power_state);