Skip to contentSkip to conversation

MST DP audio support

RFC PATCH In review [email protected] 3 participants 13 messages Mar 7, 2016 – Mar 8, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover MST DP audio support

From: Libin Yang <[email protected]>

The patchset are tmp patches. The API between audio and gfx is still in discussion.

Libin Yang (4):
ALSA: hda - codec add DP MST support for connection list
ALSA: hda - add DP mst verb support
ALSA - hda: add devid support in acom
ALSA - hda: add DP MST support

 drivers/gpu/drm/i915/intel_audio.c |   2 +-
 include/drm/i915_component.h       |   2 +-
 include/sound/hda_i915.h           |   6 +-
 sound/hda/hdac_i915.c              |   7 +-
 sound/pci/hda/hda_codec.c          | 217 ++++++++++++++++++++++++++++++++++---
 sound/pci/hda/hda_codec.h          |   8 ++
 sound/pci/hda/patch_hdmi.c         | 172 ++++++++++++++++++++---------
 7 files changed, 340 insertions(+), 74 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

RFC PATCH 1/4 ALSA: hda - codec add DP MST support for connection list

From: Libin Yang <[email protected]>

This patches adds the support of connection list for DP MST. With this, hdmi driver in DP MST mode can easily reuse the connection list mechanism.

---
 sound/pci/hda/hda_codec.c | 134 ++++++++++++++++++++++++++++++++++++++++++----
 sound/pci/hda/hda_codec.h |   5 ++
 2 files changed, 128 insertions(+), 11 deletions(-)
sound/pci/hda/hda_codec.c +123 -11
index 8374188..d4c81f7 100644
@@ -110,23 +110,24 @@ struct hda_conn_list {
 	struct list_head list;
 	int len;
 	hda_nid_t nid;
+	int dev_id;
 	hda_nid_t conns[0];
 };
 
 /* look up the cached results */
 static struct hda_conn_list *
-lookup_conn_list(struct hda_codec *codec, hda_nid_t nid)
+lookup_conn_list(struct hda_codec *codec, hda_nid_t nid, int dev_id)
 {
 	struct hda_conn_list *p;
 	list_for_each_entry(p, &codec->conn_list, list) {
-		if (p->nid == nid)
+		if ((p->nid == nid) && (p->dev_id == dev_id))
 			return p;
 	}
 	return NULL;
 }
 
-static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
-			 const hda_nid_t *list)
+static int add_conn_list(struct hda_codec *codec, hda_nid_t nid,
+			 int dev_id, int len, const hda_nid_t *list)
 {
 	struct hda_conn_list *p;
 
@@ -135,6 +136,7 @@ static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
 		return -ENOMEM;
 	p->len = len;
 	p->nid = nid;
+	p->dev_id = dev_id;
 	memcpy(p->conns, list, len * sizeof(hda_nid_t));
 	list_add(&p->list, &codec->conn_list);
 	return 0;
@@ -150,8 +152,13 @@ static void remove_conn_list(struct hda_codec *codec)
 	}
 }
 
-/* read the connection and add to the cache */
-static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
+/*
+ * read the connection and add to the cache
+ * the caller should select the device entry by sending the
+ * corresponding verb if necessary before calling this function
+ */
+static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid,
+				  int dev_id)
 {
 	hda_nid_t list[32];
 	hda_nid_t *result = list;
@@ -166,7 +173,8 @@ static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
 		len = snd_hda_get_raw_connections(codec, nid, result, len);
 	}
 	if (len >= 0)
-		len = snd_hda_override_conn_list(codec, nid, len, result);
+		len = snd_hda_override_conn_list_mst(codec, nid,
+					     dev_id, len, result);
 	if (result != list)
 		kfree(result);
 	return len;
@@ -197,7 +205,7 @@ int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
 		const struct hda_conn_list *p;
 
 		/* if the connection-list is already cached, read it */
-		p = lookup_conn_list(codec, nid);
+		p = lookup_conn_list(codec, nid, 0);
 		if (p) {
 			if (listp)
 				*listp = p->conns;
@@ -206,7 +214,7 @@ int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
 		if (snd_BUG_ON(added))
 			return -EINVAL;
 
-		err = read_and_add_raw_conns(codec, nid);
+		err = read_and_add_raw_conns(codec, nid, 0);
 		if (err < 0)
 			return err;
 		added = true;
@@ -215,6 +223,49 @@ int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
 EXPORT_SYMBOL_GPL(snd_hda_get_conn_list);
 
 /**
+ * snd_hda_get_conn_list_mst - get connection list in mst mode
+ * @codec: the HDA codec
+ * @nid: NID to parse
+ * @dev_id: device entry id
+ * @listp: the pointer to store NID list
+ *
+ * Parses the connection list of the given widget and stores the pointer
+ * to the list of NIDs.
+ *
+ * Returns the number of connections, or a negative error code.
+ *
+ * Note that the returned pointer isn't protected against the list
+ * modification.  If snd_hda_override_conn_list() might be called
+ * concurrently, protect with a mutex appropriately.
+ */
+int snd_hda_get_conn_list_mst(struct hda_codec *codec, hda_nid_t nid,
+			      int dev_id, const hda_nid_t **listp)
+{
+	bool added = false;
+
+	for (;;) {
+		int err;
+		const struct hda_conn_list *p;
+
+		/* if the connection-list is already cached, read it */
+		p = lookup_conn_list(codec, nid, dev_id);
+		if (p) {
+			if (listp)
+				*listp = p->conns;
+			return p->len;
+		}
+		if (snd_BUG_ON(added))
+			return -EINVAL;
+
+		err = read_and_add_raw_conns(codec, nid, dev_id);
+		if (err < 0)
+			return err;
+		added = true;
+	}
+}
+EXPORT_SYMBOL_GPL(snd_hda_get_conn_list_mst);
+
+/**
  * snd_hda_get_connections - copy connection list
  * @codec: the HDA codec
  * @nid: NID to parse
@@ -246,6 +297,39 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
 EXPORT_SYMBOL_GPL(snd_hda_get_connections);
 
 /**
+ * snd_hda_get_connections_mst - copy connection list in mst mode
+ * @codec: the HDA codec
+ * @nid: NID to parse
+ * @dev_id: device entry id
+ * @conn_list: connection list array; when NULL, checks only the size
+ * @max_conns: max. number of connections to store
+ *
+ * Parses the connection list of the given widget and stores the list
+ * of NIDs.
+ *
+ * Returns the number of connections, or a negative error code.
+ */
+int snd_hda_get_connections_mst(struct hda_codec *codec, hda_nid_t nid,
+				int dev_id, hda_nid_t *conn_list,
+				int max_conns)
+{
+	const hda_nid_t *list;
+	int len = snd_hda_get_conn_list_mst(codec, nid, dev_id, &list);
+
+	if (len > 0 && conn_list) {
+		if (len > max_conns) {
+			codec_err(codec, "Too many connections %d for NID 0x%x\n",
+				   len, nid);
+			return -EINVAL;
+		}
+		memcpy(conn_list, list, len * sizeof(hda_nid_t));
+	}
+
+	return len;
+}
+EXPORT_SYMBOL_GPL(snd_hda_get_connections_mst);
+
+/**
  * snd_hda_override_conn_list - add/modify the connection-list to cache
  * @codec: the HDA codec
  * @nid: NID to parse
@@ -262,17 +346,45 @@ int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
 {
 	struct hda_conn_list *p;
 
-	p = lookup_conn_list(codec, nid);
+	p = lookup_conn_list(codec, nid, 0);
 	if (p) {
 		list_del(&p->list);
 		kfree(p);
 	}
 
-	return add_conn_list(codec, nid, len, list);
+	return add_conn_list(codec, nid, 0, len, list);
 }
 EXPORT_SYMBOL_GPL(snd_hda_override_conn_list);
 
 /**
+ * snd_hda_override_conn_list_mst - add/modify the connection-list to cache
+ * @codec: the HDA codec
+ * @nid: NID to parse
+ * @dev_id: device entry id
+ * @len: number of connection list entries
+ * @list: the list of connection entries
+ *
+ * Add or modify the given connection-list to the cache.  If the corresponding
+ * cache already exists, invalidate it and append a new one.
+ *
+ * Returns zero or a negative error code.
+ */
+int snd_hda_override_conn_list_mst(struct hda_codec *codec, hda_nid_t nid,
+			   int dev_id, int len, const hda_nid_t *list)
+{
+	struct hda_conn_list *p;
+
+	p = lookup_conn_list(codec, nid, dev_id);
+	if (p) {
+		list_del(&p->list);
+		kfree(p);
+	}
+
+	return add_conn_list(codec, nid, dev_id, len, list);
+}
+EXPORT_SYMBOL_GPL(snd_hda_override_conn_list_mst);
+
+/**
  * snd_hda_get_conn_index - get the connection index of the given NID
  * @codec: the HDA codec
  * @mux: NID containing the list
sound/pci/hda/hda_codec.h +5 -0
index 373fcad..deeed35 100644
@@ -330,6 +330,9 @@ snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
 	snd_hdac_get_sub_nodes(&(codec)->core, nid, start_nid)
 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
 			    hda_nid_t *conn_list, int max_conns);
+int snd_hda_get_connections_mst(struct hda_codec *codec, hda_nid_t nid,
+				int dev_id, hda_nid_t *conn_list,
+				int max_conns);
 static inline int
 snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid)
 {
@@ -345,6 +348,8 @@ int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
 			  const hda_nid_t **listp);
 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums,
 			  const hda_nid_t *list);
+int snd_hda_override_conn_list_mst(struct hda_codec *codec, hda_nid_t nid,
+			   int dev_id, int len, const hda_nid_t *list);
 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
 			   hda_nid_t nid, int recursive);
 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
Signature · 1 line
1.9.1
#4 lore raw

PATCH 2/4 ALSA: hda - add DP mst verb support

In reply to [email protected]

From: Libin Yang <[email protected]>

Add snd_hda_get_dev_select() and snd_hda_set_dev_select() functions for DP MST audio support.

---
 sound/pci/hda/hda_codec.c | 80 +++++++++++++++++++++++++++++++++++++++++++++--
 sound/pci/hda/hda_codec.h |  3 ++
 2 files changed, 80 insertions(+), 3 deletions(-)
sound/pci/hda/hda_codec.c +77 -3
index d4c81f7..1a42c51 100644
@@ -424,8 +424,16 @@ int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
 EXPORT_SYMBOL_GPL(snd_hda_get_conn_index);
 
 
-/* return DEVLIST_LEN parameter of the given widget */
-static unsigned int get_num_devices(struct hda_codec *codec, hda_nid_t nid)
+/**
+ * snd_hda_get_num_devices - get DEVLIST_LEN parameter of the given widget
+ *  @codec: the HDA codec
+ *  @nid: NID of the pin to parse
+ *
+ * Get the device entry number on the given widget.
+ * This is a feature of DP MST audio. Each pin can
+ * have several device entries in it.
+ */
+unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid)
 {
 	unsigned int wcaps = get_wcaps(codec, nid);
 	unsigned int parm;
@@ -439,6 +447,7 @@ static unsigned int get_num_devices(struct hda_codec *codec, hda_nid_t nid)
 		parm = 0;
 	return parm & AC_DEV_LIST_LEN_MASK;
 }
+EXPORT_SYMBOL_GPL(snd_hda_get_num_devices);
 
 /**
  * snd_hda_get_devices - copy device list without cache
@@ -456,7 +465,7 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
 	unsigned int parm;
 	int i, dev_len, devices;
 
-	parm = get_num_devices(codec, nid);
+	parm = snd_hda_get_num_devices(codec, nid);
 	if (!parm)	/* not multi-stream capable */
 		return 0;
 
@@ -480,6 +489,71 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
 	return devices;
 }
 
+/**
+ * snd_hda_get_dev_select - get device entry select on the pin
+ * @codec: the HDA codec
+ * @nid: NID of the pin to get device entry select
+ *
+ * Get the devcie entry select on the pin. Return the device entry
+ * id selected on the pin. Return 0 means the first device entry
+ * is selected or MST is not supported.
+ */
+int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid)
+{
+	/* not support dp_mst will always return 0, using first dev_entry */
+	if (!codec->dp_mst)
+		return 0;
+
+	return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_DEVICE_SEL, 0);
+}
+EXPORT_SYMBOL_GPL(snd_hda_get_dev_select);
+
+/**
+ * snd_hda_set_dev_select - set device entry select on the pin
+ * @codec: the HDA codec
+ * @nid: NID of the pin to set device entry select
+ * @dev_id: device entry id to be set
+ *
+ * Set the device entry select on the pin nid.
+ */
+int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id)
+{
+	int ret, dev;
+	unsigned long timeout;
+
+	/* not support dp_mst will always return 0, using first dev_entry */
+	if (!codec->dp_mst)
+		return 0;
+
+	/* If Device List Length is 0, the pin is not multi stream capable.
+	 */
+	if ((snd_hda_get_num_devices(codec, nid) + 1) == 0)
+		return 0;
+
+	/* Behavior of setting index being equal to or greater than
+	 * Device List Length is not predictable
+	 */
+	if ((snd_hda_get_num_devices(codec, nid) + 1) <= dev_id)
+		return 0;
+
+	timeout = jiffies + msecs_to_jiffies(500);
+
+	/* make sure the device entry selection takes effect */
+	do {
+		ret = snd_hda_codec_write(codec, nid, 0,
+			AC_VERB_SET_DEVICE_SEL, dev_id);
+		udelay(20);
+
+		dev = snd_hda_get_dev_select(codec, nid);
+		if (dev == dev_id)
+			break;
+		msleep(20);
+	} while (time_before(jiffies, timeout));
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_hda_set_dev_select);
+
 /*
  * read widget caps for each widget and store in cache
  */
sound/pci/hda/hda_codec.h +3 -0
index deeed35..8362cb6 100644
@@ -352,8 +352,11 @@ int snd_hda_override_conn_list_mst(struct hda_codec *codec, hda_nid_t nid,
 			   int dev_id, int len, const hda_nid_t *list);
 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
 			   hda_nid_t nid, int recursive);
+unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid);
 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
 			u8 *dev_list, int max_devices);
+int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid);
+int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id);
 
 struct hda_verb {
 	hda_nid_t nid;
Signature · 1 line
1.9.1
#9 lore raw

RFC PATCH 3/4 ALSA - hda: add devid support in acom

In reply to [email protected]

From: Libin Yang <[email protected]>

This is a tmp API patch for gfx. Detail is still in discussion

---
 drivers/gpu/drm/i915/intel_audio.c | 2 +-
 include/drm/i915_component.h       | 2 +-
 include/sound/hda_i915.h           | 6 +++---
 sound/hda/hdac_i915.c              | 7 ++++---
 sound/pci/hda/patch_hdmi.c         | 5 +++--
 5 files changed, 12 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/intel_audio.c +1 -1
index 31f6d21..3fdb6d9 100644
@@ -710,7 +710,7 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
 }
 
 static int i915_audio_component_get_eld(struct device *dev, int port,
-					bool *enabled,
+					int dev_id, bool *enabled,
 					unsigned char *buf, int max_bytes)
 {
 	struct drm_i915_private *dev_priv = dev_to_i915(dev);
include/drm/i915_component.h +1 -1
index b46fa0e..3c4475a 100644
@@ -77,7 +77,7 @@ struct i915_audio_component_ops {
 	 * Note that the returned size may be over @max_bytes.  Then it
 	 * implies that only a part of ELD has been copied to the buffer.
 	 */
-	int (*get_eld)(struct device *, int port, bool *enabled,
+	int (*get_eld)(struct device *, int port, int dev_id, bool *enabled,
 		       unsigned char *buf, int max_bytes);
 };
 
include/sound/hda_i915.h +3 -3
index fa341fc..07403f7 100644
@@ -11,7 +11,7 @@ int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable);
 int snd_hdac_display_power(struct hdac_bus *bus, bool enable);
 int snd_hdac_get_display_clk(struct hdac_bus *bus);
 int snd_hdac_sync_audio_rate(struct hdac_bus *bus, hda_nid_t nid, int rate);
-int snd_hdac_acomp_get_eld(struct hdac_bus *bus, hda_nid_t nid,
+int snd_hdac_acomp_get_eld(struct hdac_bus *bus, hda_nid_t nid, int dev_id,
 			   bool *audio_enabled, char *buffer, int max_bytes);
 int snd_hdac_i915_init(struct hdac_bus *bus);
 int snd_hdac_i915_exit(struct hdac_bus *bus);
@@ -35,8 +35,8 @@ static inline int snd_hdac_sync_audio_rate(struct hdac_bus *bus, hda_nid_t nid,
 	return 0;
 }
 static inline int snd_hdac_acomp_get_eld(struct hdac_bus *bus, hda_nid_t nid,
-					 bool *audio_enabled, char *buffer,
-					 int max_bytes)
+					 int dev_id, bool *audio_enabled,
+					 char *buffer, int max_bytes)
 {
 	return -ENODEV;
 }
sound/hda/hdac_i915.c +4 -3
index f6854db..18173c7 100644
@@ -155,6 +155,7 @@ EXPORT_SYMBOL_GPL(snd_hdac_sync_audio_rate);
  * snd_hdac_acomp_get_eld - Get the audio state and ELD via component
  * @bus: HDA core bus
  * @nid: the pin widget NID
+ * @dev_id: the device entry id
  * @audio_enabled: the pointer to store the current audio state
  * @buffer: the buffer pointer to store ELD bytes
  * @max_bytes: the max bytes to be stored on @buffer
@@ -171,7 +172,7 @@ EXPORT_SYMBOL_GPL(snd_hdac_sync_audio_rate);
  * thus it may be over @max_bytes.  If it's over @max_bytes, it implies
  * that only a part of ELD bytes have been fetched.
  */
-int snd_hdac_acomp_get_eld(struct hdac_bus *bus, hda_nid_t nid,
+int snd_hdac_acomp_get_eld(struct hdac_bus *bus, hda_nid_t nid, int dev_id,
 			   bool *audio_enabled, char *buffer, int max_bytes)
 {
 	struct i915_audio_component *acomp = bus->audio_component;
@@ -179,8 +180,8 @@ int snd_hdac_acomp_get_eld(struct hdac_bus *bus, hda_nid_t nid,
 	if (!acomp || !acomp->ops || !acomp->ops->get_eld)
 		return -ENODEV;
 
-	return acomp->ops->get_eld(acomp->dev, pin2port(nid), audio_enabled,
-				   buffer, max_bytes);
+	return acomp->ops->get_eld(acomp->dev, pin2port(nid), dev_id,
+				   audio_enabled, buffer, max_bytes);
 }
 EXPORT_SYMBOL_GPL(snd_hdac_acomp_get_eld);
 
sound/pci/hda/patch_hdmi.c +3 -2
index fe4141c..11be04a 100644
@@ -75,6 +75,7 @@ struct hdmi_spec_per_cvt {
 
 struct hdmi_spec_per_pin {
 	hda_nid_t pin_nid;
+	int dev_id;
 	/* pin idx, different device entries on the same pin use the same idx */
 	int pin_nid_idx;
 	int num_mux_nids;
@@ -2013,8 +2014,8 @@ static void sync_eld_via_acomp(struct hda_codec *codec,
 
 	mutex_lock(&per_pin->lock);
 	size = snd_hdac_acomp_get_eld(&codec->bus->core, per_pin->pin_nid,
-				      &eld->monitor_present, eld->eld_buffer,
-				      ELD_MAX_SIZE);
+				      per_pin->dev_id, &eld->monitor_present,
+				      eld->eld_buffer, ELD_MAX_SIZE);
 	if (size < 0)
 		goto unlock;
 	if (size > 0) {
Signature · 1 line
1.9.1
#10 lore raw

RFC PATCH 4/4 ALSA - hda: add DP MST support

In reply to [email protected]

From: Libin Yang <[email protected]>

This patch adds the DP MST support in hdmi audio driver.

---
 sound/pci/hda/hda_codec.c  |   3 +
 sound/pci/hda/patch_hdmi.c | 167 +++++++++++++++++++++++++++++++--------------
 2 files changed, 120 insertions(+), 50 deletions(-)
sound/pci/hda/hda_codec.c +3 -0
index 1a42c51..7244f87 100644
@@ -589,6 +589,9 @@ static int read_pin_defaults(struct hda_codec *codec)
 		pin->nid = nid;
 		pin->cfg = snd_hda_codec_read(codec, nid, 0,
 					      AC_VERB_GET_CONFIG_DEFAULT, 0);
+		/* all device entries are the same widget control so far
+		 * fixme: if any codec is different, need fix here
+		 */
 		pin->ctrl = snd_hda_codec_read(codec, nid, 0,
 					       AC_VERB_GET_PIN_WIDGET_CONTROL,
 					       0);
sound/pci/hda/patch_hdmi.c +117 -50

383 lines not on this page · raw message

Signature · 1 line
1.9.1
#11 lore raw

Re: [RFC PATCH 4/4] ALSA - hda: add DP MST support

Quoted 28 lines · On Mon, 07 Mar 2016 15:57:46 +0100, [email protected] wrote:

From: Libin Yang <[email protected]>

This patch adds the DP MST support in hdmi audio driver.

---
 sound/pci/hda/hda_codec.c  |   3 +
 sound/pci/hda/patch_hdmi.c | 167 +++++++++++++++++++++++++++++++--------------
 2 files changed, 120 insertions(+), 50 deletions(-)
sound/pci/hda/hda_codec.c +3 -0
index 1a42c51..7244f87 100644
@@ -589,6 +589,9 @@ static int read_pin_defaults(struct hda_codec *codec)
 		pin->nid = nid;
 		pin->cfg = snd_hda_codec_read(codec, nid, 0,
 					      AC_VERB_GET_CONFIG_DEFAULT, 0);
+		/* all device entries are the same widget control so far
+		 * fixme: if any codec is different, need fix here
+		 */
 		pin->ctrl = snd_hda_codec_read(codec, nid, 0,
 					       AC_VERB_GET_PIN_WIDGET_CONTROL,
 					       0);
sound/pci/hda/patch_hdmi.c +0 -0
index 11be04a..26f5efd 100644

sound/pci/hda/patch_hdmi.c struct hdmi_spec { · line 149

Quoted 7 lines
sound/pci/hda/patch_hdmi.c +3 -1
@@ -144,7 +144,9 @@ struct hdmi_spec {
 	struct snd_array cvts; /* struct hdmi_spec_per_cvt */
 	hda_nid_t cvt_nids[4]; /* only for haswell fix */
 
-	int num_pins;
+	int num_pins; /* number of pins (including device entries) */
+	int num_nids; /* number of pin nids*/
+	int dev_num;

These new definitions are unclear to me. Please give a bit more detailed comments there. e.g. what actually means "including device entries"? You can give some example there. I suppose num_nids is the actual number of pins, right? Also what is dev_num? It's not an index, right?

thanks,

Takashi

#2 lore raw

Re: [RFC PATCH 1/4] ALSA: hda - codec add DP MST support for connection list

In reply to [email protected]
Quoted 8 lines · On Mon, 07 Mar 2016 15:57:43 +0100, [email protected] wrote:

From: Libin Yang <[email protected]>

This patches adds the support of connection list for DP MST. With this, hdmi driver in DP MST mode can easily reuse the connection list mechanism.

I would just replace the function with *_mst() and provide the old ones via static inline wrappers instead of having two copies.

Takashi

Quoted 254 lines
---
 sound/pci/hda/hda_codec.c | 134 ++++++++++++++++++++++++++++++++++++++++++----
 sound/pci/hda/hda_codec.h |   5 ++
 2 files changed, 128 insertions(+), 11 deletions(-)
sound/pci/hda/hda_codec.c +123 -11
index 8374188..d4c81f7 100644
@@ -110,23 +110,24 @@ struct hda_conn_list {
 	struct list_head list;
 	int len;
 	hda_nid_t nid;
+	int dev_id;
 	hda_nid_t conns[0];
 };
 
 /* look up the cached results */
 static struct hda_conn_list *
-lookup_conn_list(struct hda_codec *codec, hda_nid_t nid)
+lookup_conn_list(struct hda_codec *codec, hda_nid_t nid, int dev_id)
 {
 	struct hda_conn_list *p;
 	list_for_each_entry(p, &codec->conn_list, list) {
-		if (p->nid == nid)
+		if ((p->nid == nid) && (p->dev_id == dev_id))
 			return p;
 	}
 	return NULL;
 }
 
-static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
-			 const hda_nid_t *list)
+static int add_conn_list(struct hda_codec *codec, hda_nid_t nid,
+			 int dev_id, int len, const hda_nid_t *list)
 {
 	struct hda_conn_list *p;
 
@@ -135,6 +136,7 @@ static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
 		return -ENOMEM;
 	p->len = len;
 	p->nid = nid;
+	p->dev_id = dev_id;
 	memcpy(p->conns, list, len * sizeof(hda_nid_t));
 	list_add(&p->list, &codec->conn_list);
 	return 0;
@@ -150,8 +152,13 @@ static void remove_conn_list(struct hda_codec *codec)
 	}
 }
 
-/* read the connection and add to the cache */
-static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
+/*
+ * read the connection and add to the cache
+ * the caller should select the device entry by sending the
+ * corresponding verb if necessary before calling this function
+ */
+static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid,
+				  int dev_id)
 {
 	hda_nid_t list[32];
 	hda_nid_t *result = list;
@@ -166,7 +173,8 @@ static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
 		len = snd_hda_get_raw_connections(codec, nid, result, len);
 	}
 	if (len >= 0)
-		len = snd_hda_override_conn_list(codec, nid, len, result);
+		len = snd_hda_override_conn_list_mst(codec, nid,
+					     dev_id, len, result);
 	if (result != list)
 		kfree(result);
 	return len;
@@ -197,7 +205,7 @@ int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
 		const struct hda_conn_list *p;
 
 		/* if the connection-list is already cached, read it */
-		p = lookup_conn_list(codec, nid);
+		p = lookup_conn_list(codec, nid, 0);
 		if (p) {
 			if (listp)
 				*listp = p->conns;
@@ -206,7 +214,7 @@ int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
 		if (snd_BUG_ON(added))
 			return -EINVAL;
 
-		err = read_and_add_raw_conns(codec, nid);
+		err = read_and_add_raw_conns(codec, nid, 0);
 		if (err < 0)
 			return err;
 		added = true;
@@ -215,6 +223,49 @@ int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
 EXPORT_SYMBOL_GPL(snd_hda_get_conn_list);
 
 /**
+ * snd_hda_get_conn_list_mst - get connection list in mst mode
+ * @codec: the HDA codec
+ * @nid: NID to parse
+ * @dev_id: device entry id
+ * @listp: the pointer to store NID list
+ *
+ * Parses the connection list of the given widget and stores the pointer
+ * to the list of NIDs.
+ *
+ * Returns the number of connections, or a negative error code.
+ *
+ * Note that the returned pointer isn't protected against the list
+ * modification.  If snd_hda_override_conn_list() might be called
+ * concurrently, protect with a mutex appropriately.
+ */
+int snd_hda_get_conn_list_mst(struct hda_codec *codec, hda_nid_t nid,
+			      int dev_id, const hda_nid_t **listp)
+{
+	bool added = false;
+
+	for (;;) {
+		int err;
+		const struct hda_conn_list *p;
+
+		/* if the connection-list is already cached, read it */
+		p = lookup_conn_list(codec, nid, dev_id);
+		if (p) {
+			if (listp)
+				*listp = p->conns;
+			return p->len;
+		}
+		if (snd_BUG_ON(added))
+			return -EINVAL;
+
+		err = read_and_add_raw_conns(codec, nid, dev_id);
+		if (err < 0)
+			return err;
+		added = true;
+	}
+}
+EXPORT_SYMBOL_GPL(snd_hda_get_conn_list_mst);
+
+/**
  * snd_hda_get_connections - copy connection list
  * @codec: the HDA codec
  * @nid: NID to parse
@@ -246,6 +297,39 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
 EXPORT_SYMBOL_GPL(snd_hda_get_connections);
 
 /**
+ * snd_hda_get_connections_mst - copy connection list in mst mode
+ * @codec: the HDA codec
+ * @nid: NID to parse
+ * @dev_id: device entry id
+ * @conn_list: connection list array; when NULL, checks only the size
+ * @max_conns: max. number of connections to store
+ *
+ * Parses the connection list of the given widget and stores the list
+ * of NIDs.
+ *
+ * Returns the number of connections, or a negative error code.
+ */
+int snd_hda_get_connections_mst(struct hda_codec *codec, hda_nid_t nid,
+				int dev_id, hda_nid_t *conn_list,
+				int max_conns)
+{
+	const hda_nid_t *list;
+	int len = snd_hda_get_conn_list_mst(codec, nid, dev_id, &list);
+
+	if (len > 0 && conn_list) {
+		if (len > max_conns) {
+			codec_err(codec, "Too many connections %d for NID 0x%x\n",
+				   len, nid);
+			return -EINVAL;
+		}
+		memcpy(conn_list, list, len * sizeof(hda_nid_t));
+	}
+
+	return len;
+}
+EXPORT_SYMBOL_GPL(snd_hda_get_connections_mst);
+
+/**
  * snd_hda_override_conn_list - add/modify the connection-list to cache
  * @codec: the HDA codec
  * @nid: NID to parse
@@ -262,17 +346,45 @@ int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
 {
 	struct hda_conn_list *p;
 
-	p = lookup_conn_list(codec, nid);
+	p = lookup_conn_list(codec, nid, 0);
 	if (p) {
 		list_del(&p->list);
 		kfree(p);
 	}
 
-	return add_conn_list(codec, nid, len, list);
+	return add_conn_list(codec, nid, 0, len, list);
 }
 EXPORT_SYMBOL_GPL(snd_hda_override_conn_list);
 
 /**
+ * snd_hda_override_conn_list_mst - add/modify the connection-list to cache
+ * @codec: the HDA codec
+ * @nid: NID to parse
+ * @dev_id: device entry id
+ * @len: number of connection list entries
+ * @list: the list of connection entries
+ *
+ * Add or modify the given connection-list to the cache.  If the corresponding
+ * cache already exists, invalidate it and append a new one.
+ *
+ * Returns zero or a negative error code.
+ */
+int snd_hda_override_conn_list_mst(struct hda_codec *codec, hda_nid_t nid,
+			   int dev_id, int len, const hda_nid_t *list)
+{
+	struct hda_conn_list *p;
+
+	p = lookup_conn_list(codec, nid, dev_id);
+	if (p) {
+		list_del(&p->list);
+		kfree(p);
+	}
+
+	return add_conn_list(codec, nid, dev_id, len, list);
+}
+EXPORT_SYMBOL_GPL(snd_hda_override_conn_list_mst);
+
+/**
  * snd_hda_get_conn_index - get the connection index of the given NID
  * @codec: the HDA codec
  * @mux: NID containing the list
sound/pci/hda/hda_codec.h +5 -0
index 373fcad..deeed35 100644
@@ -330,6 +330,9 @@ snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
 	snd_hdac_get_sub_nodes(&(codec)->core, nid, start_nid)
 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
 			    hda_nid_t *conn_list, int max_conns);
+int snd_hda_get_connections_mst(struct hda_codec *codec, hda_nid_t nid,
+				int dev_id, hda_nid_t *conn_list,
+				int max_conns);
 static inline int
 snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid)
 {
@@ -345,6 +348,8 @@ int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
 			  const hda_nid_t **listp);
 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums,
 			  const hda_nid_t *list);
+int snd_hda_override_conn_list_mst(struct hda_codec *codec, hda_nid_t nid,
+			   int dev_id, int len, const hda_nid_t *list);
 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
 			   hda_nid_t nid, int recursive);
 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
Signature · 1 line
1.9.1
#5 lore raw

Re: [PATCH 2/4] ALSA: hda - add DP mst verb support

In reply to [email protected]
Quoted 4 lines · On Mon, 07 Mar 2016 15:57:44 +0100, [email protected] wrote:
sound/pci/hda/hda_codec.c +3 -0
+int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id)
+{
+	int ret, dev;

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, · line 531

Quoted 10 lines
sound/pci/hda/hda_codec.c +10 -0
+	unsigned long timeout;
+
+	/* not support dp_mst will always return 0, using first dev_entry */
+	if (!codec->dp_mst)
+		return 0;
+
+	/* If Device List Length is 0, the pin is not multi stream capable.
+	 */
+	if ((snd_hda_get_num_devices(codec, nid) + 1) == 0)
+		return 0;

I don't understand what this code is for. Why +1?

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, · line 537

Quoted 6 lines
sound/pci/hda/hda_codec.c +6 -0
+
+	/* Behavior of setting index being equal to or greater than
+	 * Device List Length is not predictable
+	 */
+	if ((snd_hda_get_num_devices(codec, nid) + 1) <= dev_id)
+		return 0;

Ditto. And, calling the same function twice?

thanks,

Takashi

#12 lore raw

Re: [RFC PATCH 4/4] ALSA - hda: add DP MST support

In reply to Takashi Iwai

Hi Takashi,

Quoted 46 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Monday, March 07, 2016 11:19 PM
To: [email protected]
Cc: [email protected]; Lin, Mengdong; Yang, Libin
Subject: Re: [alsa-devel] [RFC PATCH 4/4] ALSA - hda: add DP MST support

Quoted 7 lines · On Mon, 07 Mar 2016 15:57:46 +0100, [email protected] wrote:

From: Libin Yang <[email protected]>

This patch adds the DP MST support in hdmi audio driver.

---
 sound/pci/hda/hda_codec.c  |   3 +
 sound/pci/hda/patch_hdmi.c | 167

+++++++++++++++++++++++++++++++--------------

sound/pci/hda/hda_codec.c static int read_pin_defaults(struct hda_codec

Quoted 7 lines
 2 files changed, 120 insertions(+), 50 deletions(-)
sound/pci/hda/hda_codec.c +0 -0
index 1a42c51..7244f87 100644
@@ -589,6 +589,9 @@ static int read_pin_defaults(struct hda_codec

*codec)

sound/pci/hda/hda_codec.c static int read_pin_defaults(struct hda_codec *codec)

Quoted 3 lines
sound/pci/hda/hda_codec.c +0 -0
 		pin->nid = nid;
 		pin->cfg = snd_hda_codec_read(codec, nid, 0,
 

AC_VERB_GET_CONFIG_DEFAULT, 0);

sound/pci/hda/hda_codec.c static int read_pin_defaults(struct hda_codec *codec)

Quoted 5 lines
sound/pci/hda/hda_codec.c +3 -0
+		/* all device entries are the same widget control so far
+		 * fixme: if any codec is different, need fix here
+		 */
 		pin->ctrl = snd_hda_codec_read(codec, nid, 0,
 

AC_VERB_GET_PIN_WIDGET_CONTROL,

Review

Quoted 2 lines
sound/pci/hda/hda_codec.c +0 -0
 					       0);
(quoted diff) +0 -0

b/sound/pci/hda/patch_hdmi.c

Quoted 7 lines

index 11be04a..26f5efd 100644

sound/pci/hda/patch_hdmi.c +0 -0
@@ -144,7 +144,9 @@ struct hdmi_spec {
 	struct snd_array cvts; /* struct hdmi_spec_per_cvt */
 	hda_nid_t cvt_nids[4]; /* only for haswell fix */
 
Quoted 10 lines

sound/pci/hda/patch_hdmi.c struct hdmi_spec { · line 149

Quoted 4 lines
sound/pci/hda/patch_hdmi.c +3 -1
-	int num_pins;
+	int num_pins; /* number of pins (including device entries) */
+	int num_nids; /* number of pin nids*/
+	int dev_num;

These new definitions are unclear to me. Please give a bit more detailed comments there. e.g. what actually means "including device entries"? You can give some example there. I suppose num_nids is the actual number of pins, right? Also what is dev_num? It's not an index, right?

OK. I will add more comments in the code. For this case:
1. num_pins is the virtual pin number. For example,
there are 3 pins and each pin has 4 device entry, the num_pins will be 12.
2. num_nids is the actual number of pins. For the above case it will be 3
3. dev_num is the device entry number on each pin. For the above case, it is 4. dev_num is used to decide to create how many pcms (as we talked before, num_nids + dev_num - 1, on Intel platform, it is 5 pcms)
For more complex case (not sure there is such case in reality), pin 1 has 2 device entries, pin 2 and pin 3 has 3 device entries. The dev_num is 3. And 5 pcms will be created.

For device entry index, the index is located in per_pin struct.

Regards,
Libin

Quoted 5 lines

thanks,

Takashi

#3 lore raw

Re: [RFC PATCH 1/4] ALSA: hda - codec add DP MST support for connection list

In reply to Takashi Iwai

Hi Takashi,

Quoted 13 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, March 08, 2016 12:41 AM
To: [email protected]
Cc: [email protected]; Lin, Mengdong; Yang, Libin
Subject: Re: [alsa-devel] [RFC PATCH 1/4] ALSA: hda - codec add DP MST support for connection list

Quoted 3 lines · On Mon, 07 Mar 2016 15:57:43 +0100, [email protected] wrote:

From: Libin Yang <[email protected]>

Quoted 8 lines
Quoted 5 lines

This patches adds the support of connection list for DP MST. With this, hdmi driver in DP MST mode can easily reuse the connection list mechanism.

I would just replace the function with *_mst() and provide the old ones via static inline wrappers instead of having two copies.

I see. I will change it.

Regards,
Libin

Quoted 283 lines

Takashi

Quoted 2 lines
---
 sound/pci/hda/hda_codec.c | 134

++++++++++++++++++++++++++++++++++++++++++----

Quoted 20 lines
 sound/pci/hda/hda_codec.h |   5 ++
 2 files changed, 128 insertions(+), 11 deletions(-)
sound/pci/hda/hda_codec.c +2 -1
index 8374188..d4c81f7 100644
@@ -110,23 +110,24 @@ struct hda_conn_list {
 	struct list_head list;
 	int len;
 	hda_nid_t nid;
+	int dev_id;
 	hda_nid_t conns[0];
 };
 
 /* look up the cached results */
 static struct hda_conn_list *
-lookup_conn_list(struct hda_codec *codec, hda_nid_t nid)
+lookup_conn_list(struct hda_codec *codec, hda_nid_t nid, int dev_id)
 {

sound/pci/hda/hda_codec.c struct hda_conn_list { · line 128

Quoted 10 lines
sound/pci/hda/hda_codec.c +1 -2
 	struct hda_conn_list *p;
 	list_for_each_entry(p, &codec->conn_list, list) {
-		if (p->nid == nid)
+		if ((p->nid == nid) && (p->dev_id == dev_id))
 			return p;
 	}
 	return NULL;
 }
 
-static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int

len,

sound/pci/hda/hda_codec.c static int add_conn_list(struct hda_codec

Quoted 7 lines
sound/pci/hda/hda_codec.c +2 -1
-			 const hda_nid_t *list)
+static int add_conn_list(struct hda_codec *codec, hda_nid_t nid,
+			 int dev_id, int len, const hda_nid_t *list)
 {
 	struct hda_conn_list *p;
 
@@ -135,6 +136,7 @@ static int add_conn_list(struct hda_codec

*codec, hda_nid_t nid, int len,

sound/pci/hda/hda_codec.c static void remove_conn_list(struct

Quoted 8 lines
sound/pci/hda/hda_codec.c +1 -0
 		return -ENOMEM;
 	p->len = len;
 	p->nid = nid;
+	p->dev_id = dev_id;
 	memcpy(p->conns, list, len * sizeof(hda_nid_t));
 	list_add(&p->list, &codec->conn_list);
 	return 0;
@@ -150,8 +152,13 @@ static void remove_conn_list(struct

hda_codec *codec)

sound/pci/hda/hda_codec.c static void remove_conn_list(struct hda_codec *codec)

Quoted 5 lines
sound/pci/hda/hda_codec.c +0 -2
 	}
 }
 
-/* read the connection and add to the cache */
-static int read_and_add_raw_conns(struct hda_codec *codec,

hda_nid_t nid)

sound/pci/hda/hda_codec.c static void remove_conn_list(struct hda_codec *codec)

Quoted 6 lines
sound/pci/hda/hda_codec.c +6 -0
+/*
+ * read the connection and add to the cache
+ * the caller should select the device entry by sending the
+ * corresponding verb if necessary before calling this function
+ */
+static int read_and_add_raw_conns(struct hda_codec *codec,

hda_nid_t nid,

sound/pci/hda/hda_codec.c static int read_and_add_raw_conns(struct

Quoted 5 lines
sound/pci/hda/hda_codec.c +1 -0
+				  int dev_id)
 {
 	hda_nid_t list[32];
 	hda_nid_t *result = list;
@@ -166,7 +173,8 @@ static int read_and_add_raw_conns(struct

hda_codec *codec, hda_nid_t nid)

sound/pci/hda/hda_codec.c static int read_and_add_raw_conns(struct · line 173

Quoted 1 line
sound/pci/hda/hda_codec.c +0 -0
 		len = snd_hda_get_raw_connections(codec, nid, result,

len);

sound/pci/hda/hda_codec.c int snd_hda_get_conn_list(struct hda_codec

Quoted 9 lines
sound/pci/hda/hda_codec.c +2 -1
 	}
 	if (len >= 0)
-		len = snd_hda_override_conn_list(codec, nid, len, result);
+		len = snd_hda_override_conn_list_mst(codec, nid,
+					     dev_id, len, result);
 	if (result != list)
 		kfree(result);
 	return len;
@@ -197,7 +205,7 @@ int snd_hda_get_conn_list(struct hda_codec

*codec, hda_nid_t nid,

sound/pci/hda/hda_codec.c int snd_hda_get_conn_list(struct hda_codec

Quoted 9 lines
sound/pci/hda/hda_codec.c +1 -1
 		const struct hda_conn_list *p;
 
 		/* if the connection-list is already cached, read it */
-		p = lookup_conn_list(codec, nid);
+		p = lookup_conn_list(codec, nid, 0);
 		if (p) {
 			if (listp)
 				*listp = p->conns;
@@ -206,7 +214,7 @@ int snd_hda_get_conn_list(struct hda_codec

*codec, hda_nid_t nid,

sound/pci/hda/hda_codec.c int snd_hda_get_conn_list(struct hda_codec

Quoted 9 lines
sound/pci/hda/hda_codec.c +1 -1
 		if (snd_BUG_ON(added))
 			return -EINVAL;
 
-		err = read_and_add_raw_conns(codec, nid);
+		err = read_and_add_raw_conns(codec, nid, 0);
 		if (err < 0)
 			return err;
 		added = true;
@@ -215,6 +223,49 @@ int snd_hda_get_conn_list(struct hda_codec

*codec, hda_nid_t nid,

Quoted 9 lines
sound/pci/hda/hda_codec.c +6 -0
 EXPORT_SYMBOL_GPL(snd_hda_get_conn_list);
 
 /**
+ * snd_hda_get_conn_list_mst - get connection list in mst mode
+ * @codec: the HDA codec
+ * @nid: NID to parse
+ * @dev_id: device entry id
+ * @listp: the pointer to store NID list
+ *

sound/pci/hda/hda_codec.c int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,

Quoted 10 lines
sound/pci/hda/hda_codec.c +10 -0
+ * Parses the connection list of the given widget and stores the pointer
+ * to the list of NIDs.
+ *
+ * Returns the number of connections, or a negative error code.
+ *
+ * Note that the returned pointer isn't protected against the list
+ * modification.  If snd_hda_override_conn_list() might be called
+ * concurrently, protect with a mutex appropriately.
+ */
+int snd_hda_get_conn_list_mst(struct hda_codec *codec, hda_nid_t

nid,

sound/pci/hda/hda_codec.c int snd_hda_get_connections(struct

Quoted 31 lines
sound/pci/hda/hda_codec.c +27 -0
+			      int dev_id, const hda_nid_t **listp)
+{
+	bool added = false;
+
+	for (;;) {
+		int err;
+		const struct hda_conn_list *p;
+
+		/* if the connection-list is already cached, read it */
+		p = lookup_conn_list(codec, nid, dev_id);
+		if (p) {
+			if (listp)
+				*listp = p->conns;
+			return p->len;
+		}
+		if (snd_BUG_ON(added))
+			return -EINVAL;
+
+		err = read_and_add_raw_conns(codec, nid, dev_id);
+		if (err < 0)
+			return err;
+		added = true;
+	}
+}
+EXPORT_SYMBOL_GPL(snd_hda_get_conn_list_mst);
+
+/**
  * snd_hda_get_connections - copy connection list
  * @codec: the HDA codec
  * @nid: NID to parse
@@ -246,6 +297,39 @@ int snd_hda_get_connections(struct

hda_codec *codec, hda_nid_t nid,

Quoted 6 lines
sound/pci/hda/hda_codec.c +3 -0
 EXPORT_SYMBOL_GPL(snd_hda_get_connections);
 
 /**
+ * snd_hda_get_connections_mst - copy connection list in mst mode
+ * @codec: the HDA codec
+ * @nid: NID to parse

sound/pci/hda/hda_codec.c int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,

Quoted 10 lines
sound/pci/hda/hda_codec.c +10 -0
+ * @dev_id: device entry id
+ * @conn_list: connection list array; when NULL, checks only the size
+ * @max_conns: max. number of connections to store
+ *
+ * Parses the connection list of the given widget and stores the list
+ * of NIDs.
+ *
+ * Returns the number of connections, or a negative error code.
+ */
+int snd_hda_get_connections_mst(struct hda_codec *codec,

hda_nid_t nid,

sound/pci/hda/hda_codec.c int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,

Quoted 9 lines
sound/pci/hda/hda_codec.c +9 -0
+				int dev_id, hda_nid_t *conn_list,
+				int max_conns)
+{
+	const hda_nid_t *list;
+	int len = snd_hda_get_conn_list_mst(codec, nid, dev_id, &list);
+
+	if (len > 0 && conn_list) {
+		if (len > max_conns) {
+			codec_err(codec, "Too many connections %d for

NID 0x%x\n",

sound/pci/hda/hda_codec.c int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,

Quoted 12 lines
sound/pci/hda/hda_codec.c +11 -0
+				   len, nid);
+			return -EINVAL;
+		}
+		memcpy(conn_list, list, len * sizeof(hda_nid_t));
+	}
+
+	return len;
+}
+EXPORT_SYMBOL_GPL(snd_hda_get_connections_mst);
+
+/**
  * snd_hda_override_conn_list - add/modify the connection-list to

cache

sound/pci/hda/hda_codec.c int snd_hda_override_conn_list(struct

Quoted 3 lines
sound/pci/hda/hda_codec.c +0 -0
  * @codec: the HDA codec
  * @nid: NID to parse
@@ -262,17 +346,45 @@ int snd_hda_override_conn_list(struct

hda_codec *codec, hda_nid_t nid, int len,

Quoted 7 lines
sound/pci/hda/hda_codec.c +1 -1
 {
 	struct hda_conn_list *p;
 
-	p = lookup_conn_list(codec, nid);
+	p = lookup_conn_list(codec, nid, 0);
 	if (p) {
 		list_del(&p->list);

sound/pci/hda/hda_codec.c int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,

Quoted 10 lines
sound/pci/hda/hda_codec.c +2 -1
 		kfree(p);
 	}
 
-	return add_conn_list(codec, nid, len, list);
+	return add_conn_list(codec, nid, 0, len, list);
 }
 EXPORT_SYMBOL_GPL(snd_hda_override_conn_list);
 
 /**
+ * snd_hda_override_conn_list_mst - add/modify the connection-list

to cache

sound/pci/hda/hda_codec.c int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,

Quoted 7 lines
sound/pci/hda/hda_codec.c +7 -0
+ * @codec: the HDA codec
+ * @nid: NID to parse
+ * @dev_id: device entry id
+ * @len: number of connection list entries
+ * @list: the list of connection entries
+ *
+ * Add or modify the given connection-list to the cache.  If the

corresponding

sound/pci/hda/hda_codec.c int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,

Quoted 5 lines
sound/pci/hda/hda_codec.c +5 -0
+ * cache already exists, invalidate it and append a new one.
+ *
+ * Returns zero or a negative error code.
+ */
+int snd_hda_override_conn_list_mst(struct hda_codec *codec,

hda_nid_t nid,

sound/pci/hda/hda_codec.h snd_hda_codec_write(struct hda_codec

Quoted 23 lines
sound/pci/hda/hda_codec.c +15 -0
+			   int dev_id, int len, const hda_nid_t *list)
+{
+	struct hda_conn_list *p;
+
+	p = lookup_conn_list(codec, nid, dev_id);
+	if (p) {
+		list_del(&p->list);
+		kfree(p);
+	}
+
+	return add_conn_list(codec, nid, dev_id, len, list);
+}
+EXPORT_SYMBOL_GPL(snd_hda_override_conn_list_mst);
+
+/**
  * snd_hda_get_conn_index - get the connection index of the given NID
  * @codec: the HDA codec
  * @mux: NID containing the list
sound/pci/hda/hda_codec.h +0 -0
index 373fcad..deeed35 100644
@@ -330,6 +330,9 @@ snd_hda_codec_write(struct hda_codec

*codec, hda_nid_t nid, int flags,

sound/pci/hda/hda_codec.h snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,

Quoted 4 lines
sound/pci/hda/hda_codec.h +1 -0
 	snd_hdac_get_sub_nodes(&(codec)->core, nid, start_nid)
 int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
 			    hda_nid_t *conn_list, int max_conns);
+int snd_hda_get_connections_mst(struct hda_codec *codec,

hda_nid_t nid,

sound/pci/hda/hda_codec.h int snd_hda_get_conn_list(struct hda_codec

Quoted 6 lines
sound/pci/hda/hda_codec.h +2 -0
+				int dev_id, hda_nid_t *conn_list,
+				int max_conns);
 static inline int
 snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid)
 {
@@ -345,6 +348,8 @@ int snd_hda_get_conn_list(struct hda_codec

*codec, hda_nid_t nid,

sound/pci/hda/hda_codec.h int snd_hda_get_conn_list(struct hda_codec · line 349

Quoted 2 lines
sound/pci/hda/hda_codec.h +0 -0
 			  const hda_nid_t **listp);
 int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t

nid, int nums,

sound/pci/hda/hda_codec.h int snd_hda_get_conn_list(struct hda_codec · line 351

Quoted 2 lines
sound/pci/hda/hda_codec.h +1 -0
 			  const hda_nid_t *list);
+int snd_hda_override_conn_list_mst(struct hda_codec *codec,

hda_nid_t nid,

Quoted 7 lines
sound/pci/hda/hda_codec.h +1 -1
+			   int dev_id, int len, const hda_nid_t *list);
 int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
 			   hda_nid_t nid, int recursive);
 int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
--

1.9.1

#6 lore raw

Re: [PATCH 2/4] ALSA: hda - add DP mst verb support

In reply to Takashi Iwai

Hi Takashi,

Quoted 19 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, March 08, 2016 12:46 AM
To: [email protected]
Cc: [email protected]; Lin, Mengdong; Yang, Libin
Subject: Re: [alsa-devel] [PATCH 2/4] ALSA: hda - add DP mst verb support

Quoted 2 lines · On Mon, 07 Mar 2016 15:57:44 +0100, [email protected] wrote:

+int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid,

int dev_id)

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,

Quoted 5 lines
sound/pci/hda/hda_codec.c +5 -0
+{
+	int ret, dev;
+	unsigned long timeout;
+
+	/* not support dp_mst will always return 0, using first dev_entry

*/

Quoted 9 lines

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, · line 531

Quoted 7 lines
sound/pci/hda/hda_codec.c +7 -0
+	if (!codec->dp_mst)
+		return 0;
+
+	/* If Device List Length is 0, the pin is not multi stream capable.
+	 */
+	if ((snd_hda_get_num_devices(codec, nid) + 1) == 0)
+		return 0;

I don't understand what this code is for. Why +1?

Sorry, it should be if ((snd_hda_get_num_devices(codec, nid)) == 0). 0 means not MST capable. Thanks for point it out.

Quoted 9 lines

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, · line 537

Quoted 7 lines
sound/pci/hda/hda_codec.c +6 -0
+
+	/* Behavior of setting index being equal to or greater than
+	 * Device List Length is not predictable
+	 */
+	if ((snd_hda_get_num_devices(codec, nid) + 1) <= dev_id)
+		return 0;

Ditto. And, calling the same function twice?

(snd_hda_get_num_devices(codec, nid) + 1) means the device entry number. If the (snd_hda_get_num_devices(codec, nid) + 1) == 3, it means there are only 3 device entries. And dev_id being 0, 1, 2 is legal. It dev_id is 3 or greater, it is illegal.

Regards,
Libin

Quoted 5 lines

thanks,

Takashi

#7 lore raw

Re: [PATCH 2/4] ALSA: hda - add DP mst verb support

Quoted 45 lines · Libin

Hi Takashi,

Quoted 19 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, March 08, 2016 12:46 AM
To: [email protected]
Cc: [email protected]; Lin, Mengdong; Yang, Libin
Subject: Re: [alsa-devel] [PATCH 2/4] ALSA: hda - add DP mst verb support

Quoted 2 lines · On Mon, 07 Mar 2016 15:57:44 +0100, [email protected] wrote:

+int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid,

int dev_id)

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,

Quoted 5 lines
sound/pci/hda/hda_codec.c +5 -0
+{
+	int ret, dev;
+	unsigned long timeout;
+
+	/* not support dp_mst will always return 0, using first dev_entry

*/

Quoted 9 lines

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, · line 531

Quoted 7 lines
sound/pci/hda/hda_codec.c +7 -0
+	if (!codec->dp_mst)
+		return 0;
+
+	/* If Device List Length is 0, the pin is not multi stream capable.
+	 */
+	if ((snd_hda_get_num_devices(codec, nid) + 1) == 0)
+		return 0;

I don't understand what this code is for. Why +1?

Sorry, it should be if ((snd_hda_get_num_devices(codec, nid)) == 0). 0 means not MST capable. Thanks for point it out.

Quoted 9 lines

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, · line 537

Quoted 7 lines
sound/pci/hda/hda_codec.c +6 -0
+
+	/* Behavior of setting index being equal to or greater than
+	 * Device List Length is not predictable
+	 */
+	if ((snd_hda_get_num_devices(codec, nid) + 1) <= dev_id)
+		return 0;

Ditto. And, calling the same function twice?

Quoted 4 lines

(snd_hda_get_num_devices(codec, nid) + 1) means the device entry number. If the (snd_hda_get_num_devices(codec, nid) + 1) == 3, it means there are only 3 device entries. And dev_id being 0, 1, 2 is legal. It dev_id is 3 or greater, it is illegal.

So, shouldn't it be like below?
if (dev_id >= num_devices)
return 0;

Also my point is that you don't need to call snd_hda_get_num_devices() twice. It can be stored locally.

Takashi

#8 lore raw

Re: [PATCH 2/4] ALSA: hda - add DP mst verb support

Quoted 64 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, March 08, 2016 3:39 PM
To: Yang, Libin
Cc: [email protected]; [email protected]; Lin, Mengdong
Subject: Re: [alsa-devel] [PATCH 2/4] ALSA: hda - add DP mst verb support

Quoted 15 lines · Libin

Hi Takashi,

Quoted 12 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, March 08, 2016 12:46 AM
To: [email protected]
Cc: [email protected]; Lin, Mengdong; Yang, Libin
Subject: Re: [alsa-devel] [PATCH 2/4] ALSA: hda - add DP mst verb support

Quoted 2 lines · On Mon, 07 Mar 2016 15:57:44 +0100, [email protected] wrote:

+int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t

nid,

Quoted 30 lines
Quoted 7 lines

int dev_id)

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,

Quoted 5 lines
sound/pci/hda/hda_codec.c +5 -0
+{
+	int ret, dev;
+	unsigned long timeout;
+
+	/* not support dp_mst will always return 0, using first dev_entry

*/

Quoted 9 lines

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, · line 531

Quoted 7 lines
sound/pci/hda/hda_codec.c +7 -0
+	if (!codec->dp_mst)
+		return 0;
+
+	/* If Device List Length is 0, the pin is not multi stream capable.
+	 */
+	if ((snd_hda_get_num_devices(codec, nid) + 1) == 0)
+		return 0;

I don't understand what this code is for. Why +1?

Sorry, it should be if ((snd_hda_get_num_devices(codec, nid)) == 0). 0 means not MST capable. Thanks for point it out.

Quoted 9 lines

sound/pci/hda/hda_codec.c int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid, · line 537

Quoted 7 lines
sound/pci/hda/hda_codec.c +6 -0
+
+	/* Behavior of setting index being equal to or greater than
+	 * Device List Length is not predictable
+	 */
+	if ((snd_hda_get_num_devices(codec, nid) + 1) <= dev_id)
+		return 0;

Ditto. And, calling the same function twice?

Quoted 1 line

(snd_hda_get_num_devices(codec, nid) + 1) means the device entry

number.

Quoted 1 line

If the (snd_hda_get_num_devices(codec, nid) + 1) == 3, it means there

are

Quoted 1 line

only 3 device entries. And dev_id being 0, 1, 2 is legal. It dev_id is 3 or

greater,

Quoted 8 lines
Quoted 1 line

it is illegal.

So, shouldn't it be like below?
if (dev_id >= num_devices)
return 0;

Also my point is that you don't need to call snd_hda_get_num_devices() twice. It can be stored locally.

Get it. I will store it locally.

Regards,
Libin

Quoted 3 lines

Takashi