Re: [PATCH] ALSA: hda/realtek: Add quirk for CSL Unity BF24B

From: Takashi Iwai

Date: Thu Apr 09 2026 - 03:24:37 EST


On Thu, 09 Apr 2026 09:00:59 +0200,
Zhang Heng wrote:
>
>
> >> + alc_update_gpio_data(codec, 0x03, true);
> >> + msleep(100);
> >> + alc_update_gpio_data(codec, 0x03, false);
>
> Is it possible to make these lines into another auxiliary function? I think so.

I had something like below in mind. This can be applied to clean up
many existing code.

With that change, the fixup becomes

snd_hda_codec_set_gpio(codec, 0x03, 0x03, 0x03, 0);
msleep(100);
snd_hda_codec_set_gpio(codec, 0x03, 0x03, 0x00, 0);

without setting spec->gpio_* fields.


Takashi

-- 8< --
diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h
index 5d9f0ef228af..cb1755d535f9 100644
--- a/include/sound/hda_codec.h
+++ b/include/sound/hda_codec.h
@@ -470,6 +470,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 5123df32ad89..6eb11e933606 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -4053,6 +4053,29 @@ 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);
+ snd_hda_codec_write(codec, codec->core.afg, 0,
+ AC_VERB_SET_GPIO_DIRECTION, dir);
+ if (delay)
+ msleep(delay);
+ 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