]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ALSA: hda: Move widget capability macros into hdaudio.h
authorTakashi Iwai <tiwai@suse.de>
Wed, 9 Jul 2025 16:04:04 +0000 (18:04 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 11 Jul 2025 07:55:36 +0000 (09:55 +0200)
The get_wcaps() and co are used not only by HD-audio core but also
other driver code, hence it'd be better to put into the common header
instead of local.h.

OTOH, there are macros of the same name like get_wcaps() that are
still used in sound/pci/hda/* locally, and those conflict with each
other.  So we need to rename get_wcaps() (to be moved from hda-core)
with the proper snd_hdac prefix for avoiding name conflicts, and
define in the common hdaudio.h.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250709160434.1859-2-tiwai@suse.de
include/sound/hdaudio.h
sound/hda/hdac_device.c
sound/hda/hdac_sysfs.c
sound/hda/local.h
sound/soc/codecs/hdac_hdmi.c

index 25668eee65cf3effd79888441750fa085f8bc83e..d38234f8fe4469b0aa808fe4a6b6bb6a991a2d43 100644 (file)
@@ -680,6 +680,30 @@ static inline void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev,
 }
 #endif /* CONFIG_SND_HDA_DSP_LOADER */
 
+/*
+ * Easy macros for widget capabilities
+ */
+#define snd_hdac_get_wcaps(codec, nid) \
+       snd_hdac_read_parm(codec, nid, AC_PAR_AUDIO_WIDGET_CAP)
+
+/* get the widget type from widget capability bits */
+static inline int snd_hdac_get_wcaps_type(unsigned int wcaps)
+{
+       if (!wcaps)
+               return -1; /* invalid type */
+       return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
+}
+
+/* get the number of supported channels */
+static inline unsigned int snd_hdac_get_wcaps_channels(u32 wcaps)
+{
+       unsigned int chans;
+
+       chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
+       chans = (chans + 1) * 2;
+
+       return chans;
+}
 
 /*
  * generic array helpers
index a02dce5f6a8897d044254457337ad55717cc97c7..018f9e176b1b8b7badf438178547179b5c0bdfd4 100644 (file)
@@ -436,11 +436,11 @@ EXPORT_SYMBOL_GPL(snd_hdac_refresh_widgets);
 /* return CONNLIST_LEN parameter of the given widget */
 static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid)
 {
-       unsigned int wcaps = get_wcaps(codec, nid);
+       unsigned int wcaps = snd_hdac_get_wcaps(codec, nid);
        unsigned int parm;
 
        if (!(wcaps & AC_WCAP_CONN_LIST) &&
-           get_wcaps_type(wcaps) != AC_WID_VOL_KNB)
+           snd_hdac_get_wcaps_type(wcaps) != AC_WID_VOL_KNB)
                return 0;
 
        parm = snd_hdac_read_parm(codec, nid, AC_PAR_CONNLIST_LEN);
@@ -854,7 +854,7 @@ static unsigned int query_pcm_param(struct hdac_device *codec, hda_nid_t nid)
        unsigned int val = 0;
 
        if (nid != codec->afg &&
-           (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD))
+           (snd_hdac_get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD))
                val = snd_hdac_read_parm(codec, nid, AC_PAR_PCM);
        if (!val || val == -1)
                val = snd_hdac_read_parm(codec, codec->afg, AC_PAR_PCM);
@@ -894,7 +894,7 @@ int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid,
 {
        unsigned int i, val, wcaps;
 
-       wcaps = get_wcaps(codec, nid);
+       wcaps = snd_hdac_get_wcaps(codec, nid);
        val = query_pcm_param(codec, nid);
 
        if (ratesp) {
index 60b0a70428d5687f067381c3a2a4524de5dc13d2..bffe52859dbaa1067044f9f32cfc167d315a040c 100644 (file)
@@ -161,13 +161,13 @@ static const struct kobj_type widget_ktype = {
 static ssize_t caps_show(struct hdac_device *codec, hda_nid_t nid,
                        struct widget_attribute *attr, char *buf)
 {
-       return sysfs_emit(buf, "0x%08x\n", get_wcaps(codec, nid));
+       return sysfs_emit(buf, "0x%08x\n", snd_hdac_get_wcaps(codec, nid));
 }
 
 static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid,
                             struct widget_attribute *attr, char *buf)
 {
-       if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
+       if (snd_hdac_get_wcaps_type(snd_hdac_get_wcaps(codec, nid)) != AC_WID_PIN)
                return 0;
        return sysfs_emit(buf, "0x%08x\n",
                          snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP));
@@ -178,7 +178,7 @@ static ssize_t pin_cfg_show(struct hdac_device *codec, hda_nid_t nid,
 {
        unsigned int val;
 
-       if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
+       if (snd_hdac_get_wcaps_type(snd_hdac_get_wcaps(codec, nid)) != AC_WID_PIN)
                return 0;
        if (snd_hdac_read(codec, nid, AC_VERB_GET_CONFIG_DEFAULT, 0, &val))
                return 0;
@@ -189,7 +189,7 @@ static bool has_pcm_cap(struct hdac_device *codec, hda_nid_t nid)
 {
        if (nid == codec->afg || nid == codec->mfg)
                return true;
-       switch (get_wcaps_type(get_wcaps(codec, nid))) {
+       switch (snd_hdac_get_wcaps_type(snd_hdac_get_wcaps(codec, nid))) {
        case AC_WID_AUD_OUT:
        case AC_WID_AUD_IN:
                return true;
@@ -219,7 +219,7 @@ static ssize_t pcm_formats_show(struct hdac_device *codec, hda_nid_t nid,
 static ssize_t amp_in_caps_show(struct hdac_device *codec, hda_nid_t nid,
                                struct widget_attribute *attr, char *buf)
 {
-       if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
+       if (nid != codec->afg && !(snd_hdac_get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
                return 0;
        return sysfs_emit(buf, "0x%08x\n",
                          snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP));
@@ -228,7 +228,7 @@ static ssize_t amp_in_caps_show(struct hdac_device *codec, hda_nid_t nid,
 static ssize_t amp_out_caps_show(struct hdac_device *codec, hda_nid_t nid,
                                 struct widget_attribute *attr, char *buf)
 {
-       if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
+       if (nid != codec->afg && !(snd_hdac_get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
                return 0;
        return sysfs_emit(buf, "0x%08x\n",
                          snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP));
@@ -237,7 +237,7 @@ static ssize_t amp_out_caps_show(struct hdac_device *codec, hda_nid_t nid,
 static ssize_t power_caps_show(struct hdac_device *codec, hda_nid_t nid,
                               struct widget_attribute *attr, char *buf)
 {
-       if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_POWER))
+       if (nid != codec->afg && !(snd_hdac_get_wcaps(codec, nid) & AC_WCAP_POWER))
                return 0;
        return sysfs_emit(buf, "0x%08x\n",
                          snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE));
index 896ba142e8bc05dd7d2ecd8c7156ad9e8e15342e..5f03b203c4163cb25bb0427841f0851f53ef6ca1 100644 (file)
@@ -6,27 +6,6 @@
 #ifndef __HDAC_LOCAL_H
 #define __HDAC_LOCAL_H
 
-#define get_wcaps(codec, nid) \
-       snd_hdac_read_parm(codec, nid, AC_PAR_AUDIO_WIDGET_CAP)
-
-/* get the widget type from widget capability bits */
-static inline int get_wcaps_type(unsigned int wcaps)
-{
-       if (!wcaps)
-               return -1; /* invalid type */
-       return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
-}
-
-static inline unsigned int get_wcaps_channels(u32 wcaps)
-{
-       unsigned int chans;
-
-       chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
-       chans = (chans + 1) * 2;
-
-       return chans;
-}
-
 extern const struct attribute_group *hdac_dev_attr_groups[];
 int hda_widget_sysfs_init(struct hdac_device *codec);
 int hda_widget_sysfs_reinit(struct hdac_device *codec, hda_nid_t start_nid,
index 1139a2754ca337fd08a1106aaec179f8e7fbcc21..b33cd5178008b1e347930f88d3f75aea2cef067b 100644 (file)
@@ -24,7 +24,6 @@
 #include <sound/hda_i915.h>
 #include <sound/pcm_drm_eld.h>
 #include <sound/hda_chmap.h>
-#include "../../hda/local.h"
 #include "hdac_hdmi.h"
 
 #define NAME_SIZE      32
@@ -221,8 +220,8 @@ static int hdac_hdmi_get_port_len(struct hdac_device *hdev, hda_nid_t nid)
        unsigned int caps;
        unsigned int type, param;
 
-       caps = get_wcaps(hdev, nid);
-       type = get_wcaps_type(caps);
+       caps = snd_hdac_get_wcaps(hdev, nid);
+       type = snd_hdac_get_wcaps_type(caps);
 
        if (!(caps & AC_WCAP_DIGITAL) || (type != AC_WID_PIN))
                return 0;
@@ -492,10 +491,10 @@ static int hdac_hdmi_query_port_connlist(struct hdac_device *hdev,
                                        struct hdac_hdmi_pin *pin,
                                        struct hdac_hdmi_port *port)
 {
-       if (!(get_wcaps(hdev, pin->nid) & AC_WCAP_CONN_LIST)) {
+       if (!(snd_hdac_get_wcaps(hdev, pin->nid) & AC_WCAP_CONN_LIST)) {
                dev_warn(&hdev->dev,
                        "HDMI: pin %d wcaps %#x does not support connection list\n",
-                       pin->nid, get_wcaps(hdev, pin->nid));
+                       pin->nid, snd_hdac_get_wcaps(hdev, pin->nid));
                return -EINVAL;
        }
 
@@ -660,8 +659,8 @@ hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
        struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
        int err;
 
-       chans = get_wcaps(hdev, cvt->nid);
-       chans = get_wcaps_channels(chans);
+       chans = snd_hdac_get_wcaps(hdev, cvt->nid);
+       chans = snd_hdac_get_wcaps_channels(chans);
 
        cvt->params.channels_min = 2;
 
@@ -743,7 +742,7 @@ static void hdac_hdmi_set_power_state(struct hdac_device *hdev,
        int count;
        unsigned int state;
 
-       if (get_wcaps(hdev, nid) & AC_WCAP_POWER) {
+       if (snd_hdac_get_wcaps(hdev, nid) & AC_WCAP_POWER) {
                if (!snd_hdac_check_power_state(hdev, nid, pwr_state)) {
                        for (count = 0; count < 10; count++) {
                                snd_hdac_codec_read(hdev, nid, 0,
@@ -761,7 +760,7 @@ static void hdac_hdmi_set_power_state(struct hdac_device *hdev,
 static void hdac_hdmi_set_amp(struct hdac_device *hdev,
                                   hda_nid_t nid, int val)
 {
-       if (get_wcaps(hdev, nid) & AC_WCAP_OUT_AMP)
+       if (snd_hdac_get_wcaps(hdev, nid) & AC_WCAP_OUT_AMP)
                snd_hdac_codec_write(hdev, nid, 0,
                                        AC_VERB_SET_AMP_GAIN_MUTE, val);
 }
@@ -1648,8 +1647,8 @@ static int hdac_hdmi_parse_and_map_nid(struct hdac_device *hdev,
                unsigned int caps;
                unsigned int type;
 
-               caps = get_wcaps(hdev, nid);
-               type = get_wcaps_type(caps);
+               caps = snd_hdac_get_wcaps(hdev, nid);
+               type = snd_hdac_get_wcaps_type(caps);
 
                if (!(caps & AC_WCAP_DIGITAL))
                        continue;