]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ALSA: hda: Add a simple GPIO setup helper function
authorTakashi Iwai <tiwai@suse.de>
Thu, 9 Apr 2026 09:38:15 +0000 (11:38 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 9 Apr 2026 10:05:54 +0000 (12:05 +0200)
Introduce a common GPIO setup helper function, so that we can clean up
the open code found in many codec drivers later.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20260409093826.1317626-3-tiwai@suse.de
include/sound/hda_codec.h
sound/hda/common/codec.c

index 292d6024388b3e1a209cd126c683d87c5ec8de81..24581080e26a04498bb9a8465b0f597688b6487c 100644 (file)
@@ -481,6 +481,10 @@ void snd_hda_unlock_devices(struct hda_bus *bus);
 void snd_hda_bus_reset(struct hda_bus *bus);
 void snd_hda_bus_reset_codecs(struct hda_bus *bus);
 
+void snd_hda_codec_set_gpio(struct hda_codec *codec, unsigned int mask,
+                           unsigned int dir, unsigned int data,
+                           unsigned int delay);
+
 int snd_hda_codec_set_name(struct hda_codec *codec, const char *name);
 
 /*
index 3ac4bf6005d60d11dda2e7530ab8c9d185aea4fe..c2af2511a83160def89b9dceac1f4259438ae46b 100644 (file)
@@ -4052,6 +4052,35 @@ void snd_hda_bus_reset_codecs(struct hda_bus *bus)
        }
 }
 
+/**
+ * snd_hda_codec_set_gpio - Set up GPIO bits for AFG
+ * @codec: the HDA codec
+ * @mask: GPIO bitmask
+ * @dir: GPIO direction bits
+ * @data: GPIO data bits
+ * @delay: the delay in msec before writing GPIO data bits
+ */
+void snd_hda_codec_set_gpio(struct hda_codec *codec, unsigned int mask,
+                           unsigned int dir, unsigned int data,
+                           unsigned int delay)
+{
+       snd_hda_codec_write(codec, codec->core.afg, 0,
+                           AC_VERB_SET_GPIO_MASK, mask);
+       if (delay) {
+               snd_hda_codec_write_sync(codec, codec->core.afg, 0,
+                                        AC_VERB_SET_GPIO_DIRECTION, dir);
+               msleep(delay);
+               snd_hda_codec_write_sync(codec, codec->core.afg, 0,
+                                        AC_VERB_SET_GPIO_DATA, data);
+       } else {
+               snd_hda_codec_write(codec, codec->core.afg, 0,
+                                   AC_VERB_SET_GPIO_DIRECTION, dir);
+               snd_hda_codec_write(codec, codec->core.afg, 0,
+                                   AC_VERB_SET_GPIO_DATA, data);
+       }
+}
+EXPORT_SYMBOL_GPL(snd_hda_codec_set_gpio);
+
 /**
  * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
  * @pcm: PCM caps bits