diff options
| author | Takashi Iwai <tiwai@suse.de> | 2026-04-09 11:38:15 +0200 |
|---|---|---|
| committer | Takashi Iwai <tiwai@suse.de> | 2026-04-09 12:05:54 +0200 |
| commit | cd8fd5a0566e0d93fbd408e6b06ca484a78b5ccd (patch) | |
| tree | 87cd918441b325f4505f69196b22cb5bbdb219e9 | |
| parent | b0762dd2fcab5b8b4b953314f3f6eb9d92bc16bc (diff) | |
ALSA: hda: Add a simple GPIO setup helper function
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
| -rw-r--r-- | include/sound/hda_codec.h | 4 | ||||
| -rw-r--r-- | sound/hda/common/codec.c | 29 |
2 files changed, 33 insertions, 0 deletions
diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h index 292d6024388b..24581080e26a 100644 --- a/include/sound/hda_codec.h +++ b/include/sound/hda_codec.h @@ -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); /* diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c index 3ac4bf6005d6..c2af2511a831 100644 --- a/sound/hda/common/codec.c +++ b/sound/hda/common/codec.c @@ -4053,6 +4053,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 * @buf: the string buffer to write |
