Skip to contentSkip to conversation

ucm: Automatically load the best config file based on the card long name

PATCH Superseded [email protected] 4 participants 12 messages Dec 21, 2016 – Dec 23, 2016

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ucm: Automatically load the best config file based on the card long name

From: Mengdong Lin <[email protected]>

Intel DSP platform drivers are used by many different devices. For user space to differentiate them, ASoC machine driver may include the DMI info (vendor, product and board) in card long name. Possible card long names are:
broadwell-rt286-Dell Inc.-XPS 13 9343-0310JH broadwell-rt286-Intel Corp.-Broadwell Client platform-Wilson Beach SDS bytcr-rt5640-ASUSTeK COMPUTER INC.-T100TA-T100TA bytcr-rt5651-Circuitco-Minnowboard Max D0 PLATFORM-MinnowBoard MAX
...

And user space can define configuration files including fields separated by '.' as below:
broadwell-rt286
broadwell-rt286.Dell.XPS
bytcr-rt5640
bytcr-rt5640.ASUS.T100
bytcr-rt5651.MinnowboardMax
...

When being asked to load configuration file of a card, UCM will try to find the card long name from the local machine, and then scan all available configuration file names, search every field of config file name in the card long name. The more characters match, the higher score the file has. Finally, the file with the highest score will be loaded to configure the sound card.

src/ucm/parser.c +210 -1
index c98373a..ff75da7 100644
@@ -55,6 +55,9 @@ static const char * const component_dir[] = {
 	NULL,		/* terminator */
 };
 
+static int filename_filter(const struct dirent *dirent);
+static int is_component_directory(const char *dir);
+
 static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
 			  struct list_head *base,
 			  snd_config_t *cfg);
@@ -1328,6 +1331,210 @@ static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)
 	return 0;
 }
 
+/* trim SPACE (0x20) from the string */
+static void trim_space(char *str)
+{
+	int i, j = 0;
+
+	for (i = 0; str[i] && i < MAX_FILE; i++) {
+		if (str[i] != 0x20)
+			str[j++] = str[i];
+	}
+
+	str[j] = '\0';
+}
+
+/* find and store the card long name if the card is in this machine */
+static int get_card_long_name(snd_use_case_mgr_t *mgr)
+{
+	const char *card_name = mgr->card_name;
+	snd_ctl_t *handle;
+	int card, err, dev, idx;
+	snd_ctl_card_info_t *info;
+	const char *_name, *_long_name;
+
+	snd_ctl_card_info_alloca(&info);
+
+	card = -1;
+	if (snd_card_next(&card) < 0 || card < 0) {
+		uc_error("no soundcards found...");
+		return -1;
+	}
+
+	while (card >= 0) {
+		char name[32];
+
+		sprintf(name, "hw:%d", card);
+		err = snd_ctl_open(&handle, name, 0);
+		if (err < 0) {
+			uc_error("control open (%i): %s", card,
+				 snd_strerror(err));
+			goto next_card;
+		}
+
+		err = snd_ctl_card_info(handle, info);
+		if (err < 0) {
+			uc_error("control hardware info (%i): %s", card,
+				 snd_strerror(err));
+			snd_ctl_close(handle);
+			goto next_card;
+		}
+
+		_name = snd_ctl_card_info_get_name(info);
+		if (!strncmp(card_name, _name, 32)) {
+			_long_name = snd_ctl_card_info_get_longname(info);
+			strncpy(mgr->card_long_name, _long_name,
+				MAX_CARD_LONG_NAME);
+			snd_ctl_close(handle);
+			return 0;
+		}
+
+		snd_ctl_close(handle);
+next_card:
+		if (snd_card_next(&card) < 0) {
+			uc_error("snd_card_next");
+			break;
+		}
+	}
+
+	return -1;
+}
+
+/* This function will find the best device-specific configuration file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus the same sound
+ * card name (short name), but they may still need different device-specific
+ * configurations. For user space to differentiate them, kernel drivers may
+ * include the DMI info (vendor, product and board) in the card long name.
+ * And user space can define configuration file names appending DMI keywords
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *
+ * When being asked to load the configuration file for a card, this function
+ * will try to find the card long name from the local machine, and then scan
+ * all available configuration file names, search every field of the config
+ * file name in the card long name. The more characters match, the higher
+ * score the file has. Finally, the file with the highest score will be loaded.
+ */
+static void find_best_config_file(snd_use_case_mgr_t *mgr)
+{
+	const char *card_name = mgr->card_name;
+	char name[MAX_FILE];
+	char *env = getenv(ALSA_CONFIG_UCM_VAR);
+	struct dirent **namelist;
+	char card_long_name[MAX_CARD_LONG_NAME];
+	char *lpos, *lpos_next, *lname_end;
+	char *d_name, *dpos, *dpos_next, *d_name_end;
+	int d_name_len, field_len, long_name_len;
+	int i, cnt, err;
+	int score, score_max = 0, d_index = -1;
+	int  is_first_field;
+
+	if (get_card_long_name(mgr) < 0) {
+		/* cannot get long name, use card name as the conf file name */
+		strcpy(mgr->conf_file_name, mgr->card_name);
+		return;
+	}
+
+	strncpy(card_long_name, mgr->card_long_name, MAX_CARD_LONG_NAME);
+	trim_space(card_long_name); /* trim SPACE for matching */
+	lname_end = card_long_name + strlen(card_long_name);
+
+	/* get list of card directories under /usr/share/alsa/ucm */
+	snprintf(name, sizeof(name)-1,
+		"%s", env ? env : ALSA_USE_CASE_DIR);
+	name[MAX_FILE-1] = '\0';
+
+	err = scandir(name, &namelist, filename_filter, alphasort);
+	if (err < 0) {
+		err = -errno;
+		uc_error("error: could not scan directory %s: %s",
+				name, strerror(-err));
+		return;
+	}
+	cnt = err;
+
+	/* scan the card directory names */
+	for (i = 0; i < cnt; i++) {
+
+		/* Skip the directories for component devices */
+		if (is_component_directory(namelist[i]->d_name))
+			continue;
+
+		score = 0;
+		lpos = card_long_name;
+
+		d_name = namelist[i]->d_name;
+		d_name_len = strlen(d_name);
+		d_name_end = d_name + d_name_len;
+		is_first_field = 1;
+		dpos = d_name;
+
+		/* scan fields in the card directory name, separated by '.' */
+		while (1) {
+			dpos_next = strchr(dpos, '.');
+			if (dpos_next == dpos)	/* start with '.' */
+				goto next_field;
+
+			if (!dpos_next) /* last field */
+				field_len = d_name_end - dpos;
+			else
+				field_len = dpos_next - dpos;
+
+			memcpy(name, dpos, field_len);
+			name[field_len] = '\0';
+
+			/* search the field in the given card long name */
+			lpos_next = strstr(lpos, name);
+			if (!lpos_next) {
+				/* first field is the card name, must match */
+				if (is_first_field)
+					break;
+				goto next_field;
+			} else {
+				/* The more characters match,
+				 * the higher the score is.
+				 */
+				score += field_len;
+				if (lpos_next + field_len >= lname_end)
+					break; /* reach end of long name */
+
+				/* Skip the matched field,
+				 * for searching next field.
+				 */
+				lpos = lpos_next + field_len;
+			}
+
+next_field:
+			if (!dpos_next)
+				break; /* no more fields */
+
+			dpos = dpos_next + 1; /* skip the separator '.' */
+			is_first_field = 0;
+			if (dpos >= d_name_end)
+				break;
+		}
+
+		if (score > score_max) {
+			score_max = score;
+			d_index = i;
+		} else if (score == 0 && score_max > 0) {
+			/* passed the card directories that can match,
+			 * since directories are in alphabetical order.
+			 */
+			break;
+		}
+	}
+
+	if (d_index >= 0)
+		strncpy(mgr->conf_file_name, namelist[d_index]->d_name,
+			MAX_CARD_LONG_NAME);
+	else
+		strncpy(mgr->conf_file_name, mgr->card_name,
+			MAX_CARD_LONG_NAME);
+}
+
 static int load_master_config(const char *card_name, snd_config_t **cfg)
 {
 	char filename[MAX_FILE];
@@ -1355,7 +1562,9 @@ int uc_mgr_import_master_config(snd_use_case_mgr_t *uc_mgr)
 	snd_config_t *cfg;
 	int err;
 
-	err = load_master_config(uc_mgr->card_name, &cfg);
+	find_best_config_file(uc_mgr);
+
+	err = load_master_config(uc_mgr->conf_file_name, &cfg);
 	if (err < 0)
 		return err;
 	err = parse_master_file(uc_mgr, cfg);
src/ucm/ucm_local.h +3 -0
index 6d3302f..299a5b9 100644
@@ -41,6 +41,7 @@
 #include "use-case.h"
 
 #define MAX_FILE		256
+#define MAX_CARD_LONG_NAME	80
 #define ALSA_USE_CASE_DIR	ALSA_CONFIG_DIR "/ucm"
 
 #define SEQUENCE_ELEMENT_TYPE_CDEV	1
@@ -190,6 +191,8 @@ struct use_case_verb {
  */
 struct snd_use_case_mgr {
 	char *card_name;
+	char card_long_name[MAX_CARD_LONG_NAME];
+	char conf_file_name[MAX_CARD_LONG_NAME];
 	char *comment;
 
 	/* use case verb, devices and modifier configs parsed from files */
Signature · 1 line
2.7.4
#1 lore raw
Quoted 7 lines · On Wed, 2016-12-21 at 21:09 +0800, [email protected] wrote:

From: Mengdong Lin <[email protected]>

Intel DSP platform drivers are used by many different devices. For user space to differentiate them, ASoC machine driver may include the DMI info (vendor, product and board) in card long name. Possible card long names are:
broadwell-rt286-Dell Inc.-XPS 13 9343-0310JH

See my previous comments on the kernel patch, but the longname should be like :-

"Dell Inc.-XPS 13"

Quoted 9 lines

broadwell-rt286-Intel Corp.-Broadwell Client platform-Wilson Beach SDS bytcr-rt5640-ASUSTeK COMPUTER INC.-T100TA-T100TA bytcr-rt5651-Circuitco-Minnowboard Max D0 PLATFORM-MinnowBoard MAX
...

And user space can define configuration files including fields separated by '.' as below:
broadwell-rt286
broadwell-rt286.Dell.XPS

Dont need to use a . as the names should be unique.

Quoted 108 lines

bytcr-rt5640
bytcr-rt5640.ASUS.T100
bytcr-rt5651.MinnowboardMax
...

When being asked to load configuration file of a card, UCM will try to find the card long name from the local machine, and then scan all available configuration file names, search every field of config file name in the card long name. The more characters match, the higher score the file has. Finally, the file with the highest score will be loaded to configure the sound card.

src/ucm/parser.c +79 -0
index c98373a..ff75da7 100644
@@ -55,6 +55,9 @@ static const char * const component_dir[] = {
 	NULL,		/* terminator */
 };
 
+static int filename_filter(const struct dirent *dirent);
+static int is_component_directory(const char *dir);
+
 static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
 			  struct list_head *base,
 			  snd_config_t *cfg);
@@ -1328,6 +1331,210 @@ static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)
 	return 0;
 }
 
+/* trim SPACE (0x20) from the string */
+static void trim_space(char *str)
+{
+	int i, j = 0;
+
+	for (i = 0; str[i] && i < MAX_FILE; i++) {
+		if (str[i] != 0x20)
+			str[j++] = str[i];
+	}
+
+	str[j] = '\0';
+}
+
+/* find and store the card long name if the card is in this machine */
+static int get_card_long_name(snd_use_case_mgr_t *mgr)
+{
+	const char *card_name = mgr->card_name;
+	snd_ctl_t *handle;
+	int card, err, dev, idx;
+	snd_ctl_card_info_t *info;
+	const char *_name, *_long_name;
+
+	snd_ctl_card_info_alloca(&info);
+
+	card = -1;
+	if (snd_card_next(&card) < 0 || card < 0) {
+		uc_error("no soundcards found...");
+		return -1;
+	}
+
+	while (card >= 0) {
+		char name[32];
+
+		sprintf(name, "hw:%d", card);
+		err = snd_ctl_open(&handle, name, 0);
+		if (err < 0) {
+			uc_error("control open (%i): %s", card,
+				 snd_strerror(err));
+			goto next_card;
+		}
+
+		err = snd_ctl_card_info(handle, info);
+		if (err < 0) {
+			uc_error("control hardware info (%i): %s", card,
+				 snd_strerror(err));
+			snd_ctl_close(handle);
+			goto next_card;
+		}
+
+		_name = snd_ctl_card_info_get_name(info);
+		if (!strncmp(card_name, _name, 32)) {
+			_long_name = snd_ctl_card_info_get_longname(info);
+			strncpy(mgr->card_long_name, _long_name,
+				MAX_CARD_LONG_NAME);
+			snd_ctl_close(handle);
+			return 0;
+		}
+
+		snd_ctl_close(handle);
+next_card:
+		if (snd_card_next(&card) < 0) {
+			uc_error("snd_card_next");
+			break;
+		}
+	}
+
+	return -1;
+}
+
+/* This function will find the best device-specific configuration file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus the same sound
+ * card name (short name), but they may still need different device-specific
+ * configurations. For user space to differentiate them, kernel drivers may
+ * include the DMI info (vendor, product and board) in the card long name.
+ * And user space can define configuration file names appending DMI keywords

src/ucm/parser.c static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg) · line 1419

Quoted 10 lines
src/ucm/parser.c +10 -0
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *
+ * When being asked to load the configuration file for a card, this function
+ * will try to find the card long name from the local machine, and then scan
+ * all available configuration file names, search every field of the config
+ * file name in the card long name. The more characters match, the higher
+ * score the file has. Finally, the file with the highest score will be loaded.
+ */

Id' expect this function to try and open card longname and then card name if longname is not found. So providing we use the exact same names as the DMI name we wont need any string formatting or scoring (i.e. file open("longname/longname.conf") will either succeed or fail)

Liam

Quoted 153 lines
src/ucm/parser.c +121 -1
+static void find_best_config_file(snd_use_case_mgr_t *mgr)
+{
+	const char *card_name = mgr->card_name;
+	char name[MAX_FILE];
+	char *env = getenv(ALSA_CONFIG_UCM_VAR);
+	struct dirent **namelist;
+	char card_long_name[MAX_CARD_LONG_NAME];
+	char *lpos, *lpos_next, *lname_end;
+	char *d_name, *dpos, *dpos_next, *d_name_end;
+	int d_name_len, field_len, long_name_len;
+	int i, cnt, err;
+	int score, score_max = 0, d_index = -1;
+	int  is_first_field;
+
+	if (get_card_long_name(mgr) < 0) {
+		/* cannot get long name, use card name as the conf file name */
+		strcpy(mgr->conf_file_name, mgr->card_name);
+		return;
+	}
+
+	strncpy(card_long_name, mgr->card_long_name, MAX_CARD_LONG_NAME);
+	trim_space(card_long_name); /* trim SPACE for matching */
+	lname_end = card_long_name + strlen(card_long_name);
+
+	/* get list of card directories under /usr/share/alsa/ucm */
+	snprintf(name, sizeof(name)-1,
+		"%s", env ? env : ALSA_USE_CASE_DIR);
+	name[MAX_FILE-1] = '\0';
+
+	err = scandir(name, &namelist, filename_filter, alphasort);
+	if (err < 0) {
+		err = -errno;
+		uc_error("error: could not scan directory %s: %s",
+				name, strerror(-err));
+		return;
+	}
+	cnt = err;
+
+	/* scan the card directory names */
+	for (i = 0; i < cnt; i++) {
+
+		/* Skip the directories for component devices */
+		if (is_component_directory(namelist[i]->d_name))
+			continue;
+
+		score = 0;
+		lpos = card_long_name;
+
+		d_name = namelist[i]->d_name;
+		d_name_len = strlen(d_name);
+		d_name_end = d_name + d_name_len;
+		is_first_field = 1;
+		dpos = d_name;
+
+		/* scan fields in the card directory name, separated by '.' */
+		while (1) {
+			dpos_next = strchr(dpos, '.');
+			if (dpos_next == dpos)	/* start with '.' */
+				goto next_field;
+
+			if (!dpos_next) /* last field */
+				field_len = d_name_end - dpos;
+			else
+				field_len = dpos_next - dpos;
+
+			memcpy(name, dpos, field_len);
+			name[field_len] = '\0';
+
+			/* search the field in the given card long name */
+			lpos_next = strstr(lpos, name);
+			if (!lpos_next) {
+				/* first field is the card name, must match */
+				if (is_first_field)
+					break;
+				goto next_field;
+			} else {
+				/* The more characters match,
+				 * the higher the score is.
+				 */
+				score += field_len;
+				if (lpos_next + field_len >= lname_end)
+					break; /* reach end of long name */
+
+				/* Skip the matched field,
+				 * for searching next field.
+				 */
+				lpos = lpos_next + field_len;
+			}
+
+next_field:
+			if (!dpos_next)
+				break; /* no more fields */
+
+			dpos = dpos_next + 1; /* skip the separator '.' */
+			is_first_field = 0;
+			if (dpos >= d_name_end)
+				break;
+		}
+
+		if (score > score_max) {
+			score_max = score;
+			d_index = i;
+		} else if (score == 0 && score_max > 0) {
+			/* passed the card directories that can match,
+			 * since directories are in alphabetical order.
+			 */
+			break;
+		}
+	}
+
+	if (d_index >= 0)
+		strncpy(mgr->conf_file_name, namelist[d_index]->d_name,
+			MAX_CARD_LONG_NAME);
+	else
+		strncpy(mgr->conf_file_name, mgr->card_name,
+			MAX_CARD_LONG_NAME);
+}
+
 static int load_master_config(const char *card_name, snd_config_t **cfg)
 {
 	char filename[MAX_FILE];
@@ -1355,7 +1562,9 @@ int uc_mgr_import_master_config(snd_use_case_mgr_t *uc_mgr)
 	snd_config_t *cfg;
 	int err;
 
-	err = load_master_config(uc_mgr->card_name, &cfg);
+	find_best_config_file(uc_mgr);
+
+	err = load_master_config(uc_mgr->conf_file_name, &cfg);
 	if (err < 0)
 		return err;
 	err = parse_master_file(uc_mgr, cfg);
src/ucm/ucm_local.h +3 -0
index 6d3302f..299a5b9 100644
@@ -41,6 +41,7 @@
 #include "use-case.h"
 
 #define MAX_FILE		256
+#define MAX_CARD_LONG_NAME	80
 #define ALSA_USE_CASE_DIR	ALSA_CONFIG_DIR "/ucm"
 
 #define SEQUENCE_ELEMENT_TYPE_CDEV	1
@@ -190,6 +191,8 @@ struct use_case_verb {
  */
 struct snd_use_case_mgr {
 	char *card_name;
+	char card_long_name[MAX_CARD_LONG_NAME];
+	char conf_file_name[MAX_CARD_LONG_NAME];
 	char *comment;
 
 	/* use case verb, devices and modifier configs parsed from files */
#2 lore raw
Quoted 14 lines

-----Original Message-----
From: Liam Girdwood [mailto:[email protected]]
Sent: Wednesday, December 21, 2016 10:39 PM

Quoted 8 lines · On Wed, 2016-12-21 at 21:09 +0800, [email protected] wrote:

From: Mengdong Lin <[email protected]>

Intel DSP platform drivers are used by many different devices. For user space to differentiate them, ASoC machine driver may include the DMI info (vendor, product and board) in card long name. Possible card long names
are:
broadwell-rt286-Dell Inc.-XPS 13 9343-0310JH

Quoted 4 lines

See my previous comments on the kernel patch, but the longname should be like :-

"Dell Inc.-XPS 13"

May we keep it? It can make the matching code simpler.

Quoted 146 lines
Quoted 4 lines

broadwell-rt286-Intel Corp.-Broadwell Client platform-Wilson Beach SDS bytcr-rt5640-ASUSTeK COMPUTER INC.-T100TA-T100TA bytcr-rt5651-Circuitco-Minnowboard Max D0 PLATFORM-MinnowBoard

MAX ...

Quoted 5 lines

And user space can define configuration files including fields separated by '.' as below:
broadwell-rt286
broadwell-rt286.Dell.XPS

Dont need to use a . as the names should be unique.

src/ucm/parser.c static int

Quoted 29 lines

bytcr-rt5640
bytcr-rt5640.ASUS.T100
bytcr-rt5651.MinnowboardMax
...

When being asked to load configuration file of a card, UCM will try to find the card long name from the local machine, and then scan all available configuration file names, search every field of config file name in the card long name. The more characters match, the higher score the file has. Finally, the file with the highest score will be loaded to configure the sound card.

src/ucm/parser.c index renamed from src/ucm/parser.c +0 -0

c98373a..ff75da7 100644

src/ucm/parser.c +3 -0
@@ -55,6 +55,9 @@ static const char * const component_dir[] = {
 	NULL,		/* terminator */
 };
 
+static int filename_filter(const struct dirent *dirent); static int
+is_component_directory(const char *dir);
+
 static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
 			  struct list_head *base,
 			  snd_config_t *cfg);
@@ -1328,6 +1331,210 @@ static int

parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 70 lines
src/ucm/parser.c +67 -0
 	return 0;
 }
 
+/* trim SPACE (0x20) from the string */ static void trim_space(char
+*str) {
+	int i, j = 0;
+
+	for (i = 0; str[i] && i < MAX_FILE; i++) {
+		if (str[i] != 0x20)
+			str[j++] = str[i];
+	}
+
+	str[j] = '\0';
+}
+
+/* find and store the card long name if the card is in this machine
+*/ static int get_card_long_name(snd_use_case_mgr_t *mgr) {
+	const char *card_name = mgr->card_name;
+	snd_ctl_t *handle;
+	int card, err, dev, idx;
+	snd_ctl_card_info_t *info;
+	const char *_name, *_long_name;
+
+	snd_ctl_card_info_alloca(&info);
+
+	card = -1;
+	if (snd_card_next(&card) < 0 || card < 0) {
+		uc_error("no soundcards found...");
+		return -1;
+	}
+
+	while (card >= 0) {
+		char name[32];
+
+		sprintf(name, "hw:%d", card);
+		err = snd_ctl_open(&handle, name, 0);
+		if (err < 0) {
+			uc_error("control open (%i): %s", card,
+				 snd_strerror(err));
+			goto next_card;
+		}
+
+		err = snd_ctl_card_info(handle, info);
+		if (err < 0) {
+			uc_error("control hardware info (%i): %s", card,
+				 snd_strerror(err));
+			snd_ctl_close(handle);
+			goto next_card;
+		}
+
+		_name = snd_ctl_card_info_get_name(info);
+		if (!strncmp(card_name, _name, 32)) {
+			_long_name = snd_ctl_card_info_get_longname(info);
+			strncpy(mgr->card_long_name, _long_name,
+				MAX_CARD_LONG_NAME);
+			snd_ctl_close(handle);
+			return 0;
+		}
+
+		snd_ctl_close(handle);
+next_card:
+		if (snd_card_next(&card) < 0) {
+			uc_error("snd_card_next");
+			break;
+		}
+	}
+
+	return -1;
+}
+

src/ucm/parser.c static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 10 lines
src/ucm/parser.c +10 -0
+/* This function will find the best device-specific configuration
+file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus the
+same sound
+ * card name (short name), but they may still need different
+device-specific
+ * configurations. For user space to differentiate them, kernel
+drivers may
+ * include the DMI info (vendor, product and board) in the card long

name.

Quoted 6 lines
src/ucm/parser.c +6 -0
+ * And user space can define configuration file names appending DMI
+keywords
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *

src/ucm/parser.c static int · line 1426

Quoted 10 lines
src/ucm/parser.c +10 -0
+ * When being asked to load the configuration file for a card, this
+function
+ * will try to find the card long name from the local machine, and
+then scan
+ * all available configuration file names, search every field of the
+config
+ * file name in the card long name. The more characters match, the
+higher
+ * score the file has. Finally, the file with the highest score will be loaded.
+ */

Id' expect this function to try and open card longname and then card name if longname is not found. So providing we use the exact same names as the DMI name we wont need any string formatting or scoring (i.e. file open("longname/longname.conf") will either succeed or fail)

Quoted 1 line

Liam

I feel we cannot use the exact same names for the configuration file and card long name. The DMI info in the card long name can be lengthy, including '.' , SPACE, meaningless info like "Corp." and sometime duplicated info for some OEMs.I hope developers can just extract key words from the messy DMI info to make a simple configuration file name, and UCM automatically do the matching and give each configuration file a score. Then the file with highest score will be used for the card.

Thanks
Mengdong
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#3 lore raw
Quoted 14 lines · Mengdong
Quoted 14 lines

-----Original Message-----
From: Liam Girdwood [mailto:[email protected]]
Sent: Wednesday, December 21, 2016 10:39 PM

Quoted 8 lines · On Wed, 2016-12-21 at 21:09 +0800, [email protected] wrote:

From: Mengdong Lin <[email protected]>

Intel DSP platform drivers are used by many different devices. For user space to differentiate them, ASoC machine driver may include the DMI info (vendor, product and board) in card long name. Possible card long names
are:
broadwell-rt286-Dell Inc.-XPS 13 9343-0310JH

Quoted 6 lines
Quoted 4 lines

See my previous comments on the kernel patch, but the longname should be like :-

"Dell Inc.-XPS 13"

May we keep it? It can make the matching code simpler.

I'll remove the card name field from the card long name, to remove the duplicated info and so save the size of long name. Removing the card name field could save more room for the possible "flavor" field.

If we include the card name in the long name, the maximum length of long name I observed is 70 characters, that means we don't have much room left to add the "flavor" field if need.

In user space, the UCM configure file names will still have the "card name" as the first field, and UCM will check this field with card name and other fields with the card long name (DMI-flavor).

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

broadwell-rt286-Intel Corp.-Broadwell Client platform-Wilson Beach SDS bytcr-rt5640-ASUSTeK COMPUTER INC.-T100TA-T100TA bytcr-rt5651-Circuitco-Minnowboard Max D0 PLATFORM-MinnowBoard

Quoted 8 lines
Quoted 8 lines

MAX ...

Quoted 5 lines

And user space can define configuration files including fields separated by '.' as below:
broadwell-rt286
broadwell-rt286.Dell.XPS

Dont need to use a . as the names should be unique.

Users can define configuration file name like "cardname.longname/cardname.longname", and the longname can be verbatim copy of the card long name. It will have the highest match score.

To avoid unnecessary scan and string matching, I'll revise the function: it will try to directly open the card file "cardname.longname". And only if this file does not exist, fall back to do the scan and score the available card files to find the best match.

Take ASUS T100TA as example: its card name is 'bytcr-rt5640', long name is 'ASUSTeK COMPUTER INC.-T100TA-T100TA'. UCM will try to open card file "bytcr-rt5640.ASUSTeK COMPUTER INC.-T100TA-T100TA". If the file is not found, "bytcr-rt5640.ASUS.T100TA" may match, ... and the last fallback is "bytcr-rt5640".

For Dell Broadwell-based XPS family: its card name is "broadwell-rt286", long name is "Dell Inc.-XPS xx xxxx-xxxxxx". UCM will try file "broadwell-rt286.Dell Inc.-XPS xx xxxx-xxxxxx" at first, and may fall back to "broadwell-rt286.Dell.XPS" or "broadwell-rt286" at last.

Thanks
Mengdong

Quoted 136 lines
Quoted 134 lines

src/ucm/parser.c static int

Quoted 30 lines

bytcr-rt5640
bytcr-rt5640.ASUS.T100
bytcr-rt5651.MinnowboardMax
...

When being asked to load configuration file of a card, UCM will try to find the card long name from the local machine, and then scan all available configuration file names, search every field of config file name in the card long name. The more characters match, the higher score the file has. Finally, the file with the highest score will be loaded to configure the sound card.

src/ucm/parser.c index renamed from src/ucm/parser.c +0 -0

c98373a..ff75da7 100644

src/ucm/parser.c +3 -0
@@ -55,6 +55,9 @@ static const char * const component_dir[] = {
  	NULL,		/* terminator */
  };
 
+static int filename_filter(const struct dirent *dirent); static int
+is_component_directory(const char *dir);
+
  static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
  			  struct list_head *base,
  			  snd_config_t *cfg);
@@ -1328,6 +1331,210 @@ static int

parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 70 lines
src/ucm/parser.c +67 -0
  	return 0;
  }
 
+/* trim SPACE (0x20) from the string */ static void trim_space(char
+*str) {
+	int i, j = 0;
+
+	for (i = 0; str[i] && i < MAX_FILE; i++) {
+		if (str[i] != 0x20)
+			str[j++] = str[i];
+	}
+
+	str[j] = '\0';
+}
+
+/* find and store the card long name if the card is in this machine
+*/ static int get_card_long_name(snd_use_case_mgr_t *mgr) {
+	const char *card_name = mgr->card_name;
+	snd_ctl_t *handle;
+	int card, err, dev, idx;
+	snd_ctl_card_info_t *info;
+	const char *_name, *_long_name;
+
+	snd_ctl_card_info_alloca(&info);
+
+	card = -1;
+	if (snd_card_next(&card) < 0 || card < 0) {
+		uc_error("no soundcards found...");
+		return -1;
+	}
+
+	while (card >= 0) {
+		char name[32];
+
+		sprintf(name, "hw:%d", card);
+		err = snd_ctl_open(&handle, name, 0);
+		if (err < 0) {
+			uc_error("control open (%i): %s", card,
+				 snd_strerror(err));
+			goto next_card;
+		}
+
+		err = snd_ctl_card_info(handle, info);
+		if (err < 0) {
+			uc_error("control hardware info (%i): %s", card,
+				 snd_strerror(err));
+			snd_ctl_close(handle);
+			goto next_card;
+		}
+
+		_name = snd_ctl_card_info_get_name(info);
+		if (!strncmp(card_name, _name, 32)) {
+			_long_name = snd_ctl_card_info_get_longname(info);
+			strncpy(mgr->card_long_name, _long_name,
+				MAX_CARD_LONG_NAME);
+			snd_ctl_close(handle);
+			return 0;
+		}
+
+		snd_ctl_close(handle);
+next_card:
+		if (snd_card_next(&card) < 0) {
+			uc_error("snd_card_next");
+			break;
+		}
+	}
+
+	return -1;
+}
+

src/ucm/parser.c static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 10 lines
src/ucm/parser.c +10 -0
+/* This function will find the best device-specific configuration
+file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus the
+same sound
+ * card name (short name), but they may still need different
+device-specific
+ * configurations. For user space to differentiate them, kernel
+drivers may
+ * include the DMI info (vendor, product and board) in the card long

name.

Quoted 6 lines
src/ucm/parser.c +6 -0
+ * And user space can define configuration file names appending DMI
+keywords
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *

src/ucm/parser.c static int · line 1426

Quoted 10 lines
src/ucm/parser.c +10 -0
+ * When being asked to load the configuration file for a card, this
+function
+ * will try to find the card long name from the local machine, and
+then scan
+ * all available configuration file names, search every field of the
+config
+ * file name in the card long name. The more characters match, the
+higher
+ * score the file has. Finally, the file with the highest score will be loaded.
+ */

Id' expect this function to try and open card longname and then card name if longname is not found. So providing we use the exact same names as the DMI name we wont need any string formatting or scoring (i.e. file open("longname/longname.conf") will either succeed or fail)

Quoted 1 line

Liam

Quoted 9 lines

I feel we cannot use the exact same names for the configuration file and card long name. The DMI info in the card long name can be lengthy, including '.' , SPACE, meaningless info like "Corp." and sometime duplicated info for some OEMs.I hope developers can just extract key words from the messy DMI info to make a simple configuration file name, and UCM automatically do the matching and give each configuration file a score. Then the file with highest score will be used for the card.

Thanks
Mengdong
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#4 lore raw
In reply to Lin, Mengdong
Quoted 14 lines · Mengdong
Quoted 14 lines

-----Original Message-----
From: Liam Girdwood [mailto:[email protected]]
Sent: Wednesday, December 21, 2016 10:39 PM

Quoted 8 lines · On Wed, 2016-12-21 at 21:09 +0800, [email protected] wrote:

From: Mengdong Lin <[email protected]>

Intel DSP platform drivers are used by many different devices. For user space to differentiate them, ASoC machine driver may include the DMI info (vendor, product and board) in card long name. Possible card long names
are:
broadwell-rt286-Dell Inc.-XPS 13 9343-0310JH

Quoted 6 lines
Quoted 4 lines

See my previous comments on the kernel patch, but the longname should be like :-

"Dell Inc.-XPS 13"

May we keep it? It can make the matching code simpler.

Sorry, dont follow.

Quoted 148 lines
Quoted 146 lines
Quoted 4 lines

broadwell-rt286-Intel Corp.-Broadwell Client platform-Wilson Beach SDS bytcr-rt5640-ASUSTeK COMPUTER INC.-T100TA-T100TA bytcr-rt5651-Circuitco-Minnowboard Max D0 PLATFORM-MinnowBoard

MAX ...

Quoted 5 lines

And user space can define configuration files including fields separated by '.' as below:
broadwell-rt286
broadwell-rt286.Dell.XPS

Dont need to use a . as the names should be unique.

src/ucm/parser.c static int

Quoted 29 lines

bytcr-rt5640
bytcr-rt5640.ASUS.T100
bytcr-rt5651.MinnowboardMax
...

When being asked to load configuration file of a card, UCM will try to find the card long name from the local machine, and then scan all available configuration file names, search every field of config file name in the card long name. The more characters match, the higher score the file has. Finally, the file with the highest score will be loaded to configure the sound card.

src/ucm/parser.c index renamed from src/ucm/parser.c +0 -0

c98373a..ff75da7 100644

src/ucm/parser.c +3 -0
@@ -55,6 +55,9 @@ static const char * const component_dir[] = {
 	NULL,		/* terminator */
 };
 
+static int filename_filter(const struct dirent *dirent); static int
+is_component_directory(const char *dir);
+
 static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
 			  struct list_head *base,
 			  snd_config_t *cfg);
@@ -1328,6 +1331,210 @@ static int

parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 70 lines
src/ucm/parser.c +67 -0
 	return 0;
 }
 
+/* trim SPACE (0x20) from the string */ static void trim_space(char
+*str) {
+	int i, j = 0;
+
+	for (i = 0; str[i] && i < MAX_FILE; i++) {
+		if (str[i] != 0x20)
+			str[j++] = str[i];
+	}
+
+	str[j] = '\0';
+}
+
+/* find and store the card long name if the card is in this machine
+*/ static int get_card_long_name(snd_use_case_mgr_t *mgr) {
+	const char *card_name = mgr->card_name;
+	snd_ctl_t *handle;
+	int card, err, dev, idx;
+	snd_ctl_card_info_t *info;
+	const char *_name, *_long_name;
+
+	snd_ctl_card_info_alloca(&info);
+
+	card = -1;
+	if (snd_card_next(&card) < 0 || card < 0) {
+		uc_error("no soundcards found...");
+		return -1;
+	}
+
+	while (card >= 0) {
+		char name[32];
+
+		sprintf(name, "hw:%d", card);
+		err = snd_ctl_open(&handle, name, 0);
+		if (err < 0) {
+			uc_error("control open (%i): %s", card,
+				 snd_strerror(err));
+			goto next_card;
+		}
+
+		err = snd_ctl_card_info(handle, info);
+		if (err < 0) {
+			uc_error("control hardware info (%i): %s", card,
+				 snd_strerror(err));
+			snd_ctl_close(handle);
+			goto next_card;
+		}
+
+		_name = snd_ctl_card_info_get_name(info);
+		if (!strncmp(card_name, _name, 32)) {
+			_long_name = snd_ctl_card_info_get_longname(info);
+			strncpy(mgr->card_long_name, _long_name,
+				MAX_CARD_LONG_NAME);
+			snd_ctl_close(handle);
+			return 0;
+		}
+
+		snd_ctl_close(handle);
+next_card:
+		if (snd_card_next(&card) < 0) {
+			uc_error("snd_card_next");
+			break;
+		}
+	}
+
+	return -1;
+}
+

src/ucm/parser.c static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 10 lines
src/ucm/parser.c +10 -0
+/* This function will find the best device-specific configuration
+file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus the
+same sound
+ * card name (short name), but they may still need different
+device-specific
+ * configurations. For user space to differentiate them, kernel
+drivers may
+ * include the DMI info (vendor, product and board) in the card long

name.

Quoted 6 lines
src/ucm/parser.c +6 -0
+ * And user space can define configuration file names appending DMI
+keywords
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *

src/ucm/parser.c static int · line 1426

Quoted 10 lines
src/ucm/parser.c +10 -0
+ * When being asked to load the configuration file for a card, this
+function
+ * will try to find the card long name from the local machine, and
+then scan
+ * all available configuration file names, search every field of the
+config
+ * file name in the card long name. The more characters match, the
+higher
+ * score the file has. Finally, the file with the highest score will be loaded.
+ */

Id' expect this function to try and open card longname and then card name if longname is not found. So providing we use the exact same names as the DMI name we wont need any string formatting or scoring (i.e. file open("longname/longname.conf") will either succeed or fail)

Quoted 1 line

Liam

Quoted 8 lines

I feel we cannot use the exact same names for the configuration file and card long name. The DMI info in the card long name can be lengthy, including '.' , SPACE, meaningless info like "Corp." and sometime duplicated info for some OEMs.I hope developers can just extract key words from the messy DMI info to make a simple configuration file name, and UCM automatically do the matching and give each configuration file a score. Then the file with highest score will be used for the card.

Providing the DMI name does not use invalid filename characters we are ok. Extracting key words and matching is prone to many problems and painful to debug....

The alternative is to include the exact DMI name in a top level config file that points to the UCM config.

Quoted 3 lines

Thanks
Mengdong

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#5 lore raw
Quoted 26 lines

-----Original Message-----
From: Liam Girdwood [mailto:[email protected]]
Sent: Thursday, December 22, 2016 8:15 PM
To: Lin, Mengdong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Koul, Vinod <[email protected]>; Bossart, Pierre-louis <[email protected]>
Subject: Re: [alsa-devel] [PATCH 1/2] ucm: Automatically load the best config file based on the card long name

Quoted 5 lines · Mengdong
Quoted 5 lines

-----Original Message-----
From: Liam Girdwood [mailto:[email protected]]
Sent: Wednesday, December 21, 2016 10:39 PM

On Wed, 2016-12-21 at 21:09 +0800, [email protected]

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 8 lines

From: Mengdong Lin <[email protected]>

Intel DSP platform drivers are used by many different devices. For user space to differentiate them, ASoC machine driver may include the DMI info (vendor, product and board) in card long name. Possible card long names
are:
broadwell-rt286-Dell Inc.-XPS 13 9343-0310JH

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

See my previous comments on the kernel patch, but the longname should be like :-

"Dell Inc.-XPS 13"

May we keep it? It can make the matching code simpler.

Sorry, dont follow.

I'll remove the card name (driver name) from the long name as you suggested, please see my previous mail:
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-December/115989.html

Quoted 163 lines
Quoted 47 lines
Quoted 47 lines
Quoted 5 lines

broadwell-rt286-Intel Corp.-Broadwell Client platform-Wilson Beach SDS bytcr-rt5640-ASUSTeK COMPUTER INC.-T100TA-T100TA bytcr-rt5651-Circuitco-Minnowboard Max D0 PLATFORM-MinnowBoard

MAX ...

Quoted 5 lines

And user space can define configuration files including fields separated by '.' as below:
broadwell-rt286
broadwell-rt286.Dell.XPS

Dont need to use a . as the names should be unique.

src/ucm/parser.c static int

Quoted 29 lines

bytcr-rt5640
bytcr-rt5640.ASUS.T100
bytcr-rt5651.MinnowboardMax
...

When being asked to load configuration file of a card, UCM will try to find the card long name from the local machine, and then scan all available configuration file names, search every field of config file name in the card long name. The more characters match, the higher score the file has. Finally, the file with the highest score will be loaded to configure the sound card.

src/ucm/parser.c index renamed from src/ucm/parser.c +0 -0

c98373a..ff75da7 100644

src/ucm/parser.c +3 -0
@@ -55,6 +55,9 @@ static const char * const component_dir[] = {
 	NULL,		/* terminator */
 };
 
+static int filename_filter(const struct dirent *dirent); static
+int is_component_directory(const char *dir);
+
 static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
 			  struct list_head *base,
 			  snd_config_t *cfg);
@@ -1328,6 +1331,210 @@ static int

parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 3 lines
src/ucm/parser.c +0 -0
 	return 0;
 }
 
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
src/ucm/parser.c +7 -0
+/* trim SPACE (0x20) from the string */ static void
+trim_space(char
+*str) {
+	int i, j = 0;
+
+	for (i = 0; str[i] && i < MAX_FILE; i++) {
+		if (str[i] != 0x20)
Quoted 8 lines

src/ucm/parser.c static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 8 lines
src/ucm/parser.c +8 -0
+			str[j++] = str[i];
+	}
+
+	str[j] = '\0';
+}
+
+/* find and store the card long name if the card is in this
+machine */ static int get_card_long_name(snd_use_case_mgr_t *mgr)

{

Quoted 65 lines
Quoted 65 lines
Quoted 54 lines
src/ucm/parser.c +54 -0
+	const char *card_name = mgr->card_name;
+	snd_ctl_t *handle;
+	int card, err, dev, idx;
+	snd_ctl_card_info_t *info;
+	const char *_name, *_long_name;
+
+	snd_ctl_card_info_alloca(&info);
+
+	card = -1;
+	if (snd_card_next(&card) < 0 || card < 0) {
+		uc_error("no soundcards found...");
+		return -1;
+	}
+
+	while (card >= 0) {
+		char name[32];
+
+		sprintf(name, "hw:%d", card);
+		err = snd_ctl_open(&handle, name, 0);
+		if (err < 0) {
+			uc_error("control open (%i): %s", card,
+				 snd_strerror(err));
+			goto next_card;
+		}
+
+		err = snd_ctl_card_info(handle, info);
+		if (err < 0) {
+			uc_error("control hardware info (%i): %s", card,
+				 snd_strerror(err));
+			snd_ctl_close(handle);
+			goto next_card;
+		}
+
+		_name = snd_ctl_card_info_get_name(info);
+		if (!strncmp(card_name, _name, 32)) {
+			_long_name = snd_ctl_card_info_get_longname(info);
+			strncpy(mgr->card_long_name, _long_name,
+				MAX_CARD_LONG_NAME);
+			snd_ctl_close(handle);
+			return 0;
+		}
+
+		snd_ctl_close(handle);
+next_card:
+		if (snd_card_next(&card) < 0) {
+			uc_error("snd_card_next");
+			break;
+		}
+	}
+
+	return -1;
+}
+
+/* This function will find the best device-specific configuration

src/ucm/parser.c static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 10 lines
src/ucm/parser.c +10 -0
+file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus the
+same sound
+ * card name (short name), but they may still need different
+device-specific
+ * configurations. For user space to differentiate them, kernel
+drivers may
+ * include the DMI info (vendor, product and board) in the card
+long

name.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
src/ucm/parser.c +7 -0
+ * And user space can define configuration file names appending
+DMI keywords
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *
+ * When being asked to load the configuration file for a card,
Quoted 8 lines

src/ucm/parser.c static int · line 1427

Quoted 8 lines
src/ucm/parser.c +8 -0
+this function
+ * will try to find the card long name from the local machine,
+and then scan
+ * all available configuration file names, search every field of
+the config
+ * file name in the card long name. The more characters match,
+the higher
+ * score the file has. Finally, the file with the highest score will be

loaded.

Quoted 10 lines
Quoted 9 lines

src/ucm/parser.c static int · line 1428

Quoted 1 line
src/ucm/parser.c +1 -0
+ */

Id' expect this function to try and open card longname and then card name if longname is not found. So providing we use the exact same names as the DMI name we wont need any string formatting or scoring (i.e. file
open("longname/longname.conf") will either succeed or fail)

Liam

Quoted 8 lines

I feel we cannot use the exact same names for the configuration file and card long name. The DMI info in the card long name can be lengthy, including '.' , SPACE, meaningless info like "Corp." and sometime duplicated info for some OEMs.I hope developers can just extract key words from the messy DMI info to make a simple configuration file name, and UCM automatically do the matching and give each configuration file a score. Then the file with highest score will be used for the card.

Quoted 3 lines

Providing the DMI name does not use invalid filename characters we are ok. Extracting key words and matching is prone to many problems and painful to debug....

May I revise the UCM code like this? It will try to open the file with DMI name at first. And only if that file is not available, fall back to key words matching.

I hope to keep the possibility that user can use a simple configuration file for a product family, without generating too many card directories and files.

Thanks
Mengdong

Quoted 3 lines

The alternative is to include the exact DMI name in a top level config file that points to the UCM config.

Thanks
Mengdong
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#6 lore raw
Quoted 205 lines · Mengdong
Quoted 26 lines

-----Original Message-----
From: Liam Girdwood [mailto:[email protected]]
Sent: Thursday, December 22, 2016 8:15 PM
To: Lin, Mengdong <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Koul, Vinod <[email protected]>; Bossart, Pierre-louis <[email protected]>
Subject: Re: [alsa-devel] [PATCH 1/2] ucm: Automatically load the best config file based on the card long name

Quoted 5 lines · Mengdong
Quoted 5 lines

-----Original Message-----
From: Liam Girdwood [mailto:[email protected]]
Sent: Wednesday, December 21, 2016 10:39 PM

On Wed, 2016-12-21 at 21:09 +0800, [email protected]

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 8 lines

From: Mengdong Lin <[email protected]>

Intel DSP platform drivers are used by many different devices. For user space to differentiate them, ASoC machine driver may include the DMI info (vendor, product and board) in card long name. Possible card long names
are:
broadwell-rt286-Dell Inc.-XPS 13 9343-0310JH

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

See my previous comments on the kernel patch, but the longname should be like :-

"Dell Inc.-XPS 13"

May we keep it? It can make the matching code simpler.

Sorry, dont follow.

I'll remove the card name (driver name) from the long name as you suggested, please see my previous mail:
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-December/115989.html

Quoted 163 lines
Quoted 47 lines
Quoted 47 lines
Quoted 5 lines

broadwell-rt286-Intel Corp.-Broadwell Client platform-Wilson Beach SDS bytcr-rt5640-ASUSTeK COMPUTER INC.-T100TA-T100TA bytcr-rt5651-Circuitco-Minnowboard Max D0 PLATFORM-MinnowBoard

MAX ...

Quoted 5 lines

And user space can define configuration files including fields separated by '.' as below:
broadwell-rt286
broadwell-rt286.Dell.XPS

Dont need to use a . as the names should be unique.

src/ucm/parser.c static int

Quoted 29 lines

bytcr-rt5640
bytcr-rt5640.ASUS.T100
bytcr-rt5651.MinnowboardMax
...

When being asked to load configuration file of a card, UCM will try to find the card long name from the local machine, and then scan all available configuration file names, search every field of config file name in the card long name. The more characters match, the higher score the file has. Finally, the file with the highest score will be loaded to configure the sound card.

src/ucm/parser.c index renamed from src/ucm/parser.c +0 -0

c98373a..ff75da7 100644

src/ucm/parser.c +3 -0
@@ -55,6 +55,9 @@ static const char * const component_dir[] = {
 	NULL,		/* terminator */
 };
 
+static int filename_filter(const struct dirent *dirent); static
+int is_component_directory(const char *dir);
+
 static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
 			  struct list_head *base,
 			  snd_config_t *cfg);
@@ -1328,6 +1331,210 @@ static int

parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 3 lines
src/ucm/parser.c +0 -0
 	return 0;
 }
 
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
src/ucm/parser.c +7 -0
+/* trim SPACE (0x20) from the string */ static void
+trim_space(char
+*str) {
+	int i, j = 0;
+
+	for (i = 0; str[i] && i < MAX_FILE; i++) {
+		if (str[i] != 0x20)
Quoted 8 lines

src/ucm/parser.c static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 8 lines
src/ucm/parser.c +8 -0
+			str[j++] = str[i];
+	}
+
+	str[j] = '\0';
+}
+
+/* find and store the card long name if the card is in this
+machine */ static int get_card_long_name(snd_use_case_mgr_t *mgr)

{

Quoted 65 lines
Quoted 65 lines
Quoted 54 lines
src/ucm/parser.c +54 -0
+	const char *card_name = mgr->card_name;
+	snd_ctl_t *handle;
+	int card, err, dev, idx;
+	snd_ctl_card_info_t *info;
+	const char *_name, *_long_name;
+
+	snd_ctl_card_info_alloca(&info);
+
+	card = -1;
+	if (snd_card_next(&card) < 0 || card < 0) {
+		uc_error("no soundcards found...");
+		return -1;
+	}
+
+	while (card >= 0) {
+		char name[32];
+
+		sprintf(name, "hw:%d", card);
+		err = snd_ctl_open(&handle, name, 0);
+		if (err < 0) {
+			uc_error("control open (%i): %s", card,
+				 snd_strerror(err));
+			goto next_card;
+		}
+
+		err = snd_ctl_card_info(handle, info);
+		if (err < 0) {
+			uc_error("control hardware info (%i): %s", card,
+				 snd_strerror(err));
+			snd_ctl_close(handle);
+			goto next_card;
+		}
+
+		_name = snd_ctl_card_info_get_name(info);
+		if (!strncmp(card_name, _name, 32)) {
+			_long_name = snd_ctl_card_info_get_longname(info);
+			strncpy(mgr->card_long_name, _long_name,
+				MAX_CARD_LONG_NAME);
+			snd_ctl_close(handle);
+			return 0;
+		}
+
+		snd_ctl_close(handle);
+next_card:
+		if (snd_card_next(&card) < 0) {
+			uc_error("snd_card_next");
+			break;
+		}
+	}
+
+	return -1;
+}
+
+/* This function will find the best device-specific configuration

src/ucm/parser.c static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)

Quoted 10 lines
src/ucm/parser.c +10 -0
+file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus the
+same sound
+ * card name (short name), but they may still need different
+device-specific
+ * configurations. For user space to differentiate them, kernel
+drivers may
+ * include the DMI info (vendor, product and board) in the card
+long

name.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
src/ucm/parser.c +7 -0
+ * And user space can define configuration file names appending
+DMI keywords
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *
+ * When being asked to load the configuration file for a card,
Quoted 8 lines

src/ucm/parser.c static int · line 1427

Quoted 8 lines
src/ucm/parser.c +8 -0
+this function
+ * will try to find the card long name from the local machine,
+and then scan
+ * all available configuration file names, search every field of
+the config
+ * file name in the card long name. The more characters match,
+the higher
+ * score the file has. Finally, the file with the highest score will be

loaded.

Quoted 10 lines
Quoted 9 lines

src/ucm/parser.c static int · line 1428

Quoted 1 line
src/ucm/parser.c +1 -0
+ */

Id' expect this function to try and open card longname and then card name if longname is not found. So providing we use the exact same names as the DMI name we wont need any string formatting or scoring (i.e. file
open("longname/longname.conf") will either succeed or fail)

Liam

Quoted 8 lines

I feel we cannot use the exact same names for the configuration file and card long name. The DMI info in the card long name can be lengthy, including '.' , SPACE, meaningless info like "Corp." and sometime duplicated info for some OEMs.I hope developers can just extract key words from the messy DMI info to make a simple configuration file name, and UCM automatically do the matching and give each configuration file a score. Then the file with highest score will be used for the card.

Quoted 3 lines

Providing the DMI name does not use invalid filename characters we are ok. Extracting key words and matching is prone to many problems and painful to debug....

Quoted 8 lines

May I revise the UCM code like this? It will try to open the file with DMI name at first. And only if that file is not available, fall back to key words matching.

I hope to keep the possibility that user can use a simple configuration file for a product family, without generating too many card directories and files.

If the DMI names are too complex for directory names, then you could add an alias file at the top level that would list the DMI name and the shortened name i.e.

# DMI name # UCM directory name
"Dell blah Corp. XPS, 13 blah" "Dell XPS13 BDW"

So the alias file could be searched for the DMI name, before the legacy name was tried.

The alias method above also allows for reuse of configs on machines that are similar, but with different DMI names. So this would also keep the number of configs low.

Liam

Quoted 11 lines

Thanks
Mengdong

Quoted 3 lines

The alternative is to include the exact DMI name in a top level config file that points to the UCM config.

Thanks
Mengdong

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#7 lore raw
Quoted 67 lines · Liam Girdwood
Quoted 51 lines
Quoted 47 lines
Quoted 12 lines
Quoted 12 lines

Review

Quoted 11 lines
(quoted diff) +11 -0
+/* This function will find the best device-specific configuration
+file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus the
+same sound
+ * card name (short name), but they may still need different
+device-specific
+ * configurations. For user space to differentiate them, kernel
+drivers may
+ * include the DMI info (vendor, product and board) in the card
+long

name.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines

+ * And user space can define configuration file names appending +DMI keywords
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *
+ * When being asked to load the configuration file for a card,

Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+this function
+ * will try to find the card long name from the local machine,
+and then scan
+ * all available configuration file names, search every field of
+the config
+ * file name in the card long name. The more characters match,
+the higher
+ * score the file has. Finally, the file with the highest score will be

loaded.

Quoted 10 lines
Quoted 9 lines
Quoted 1 line

+ */

Id' expect this function to try and open card longname and then card name if longname is not found. So providing we use the exact same names as the DMI name we wont need any string formatting or scoring (i.e. file
open("longname/longname.conf") will either succeed or fail)

Liam

Quoted 8 lines

I feel we cannot use the exact same names for the configuration file and card long name. The DMI info in the card long name can be lengthy, including '.' , SPACE, meaningless info like "Corp." and sometime duplicated info for some OEMs.I hope developers can just extract key words from the messy DMI info to make a simple configuration file name, and UCM automatically do the matching and give each configuration file a score. Then the file with highest score will be used for the card.

Quoted 3 lines

Providing the DMI name does not use invalid filename characters we are ok. Extracting key words and matching is prone to many problems and painful to debug....

Quoted 8 lines

May I revise the UCM code like this? It will try to open the file with DMI name at first. And only if that file is not available, fall back to key words matching.

I hope to keep the possibility that user can use a simple configuration file for a product family, without generating too many card directories and files.

If the DMI names are too complex for directory names, then you could add an alias file at the top level that would list the DMI name and the shortened name i.e.

# DMI name # UCM directory name
"Dell blah Corp. XPS, 13 blah" "Dell XPS13 BDW"

Quoted 8 lines

So the alias file could be searched for the DMI name, before the legacy name was tried.

The alias method above also allows for reuse of configs on machines that are similar, but with different DMI names. So this would also keep the number of configs low.

Liam

I'll try to use the alias file. But it seems we need to maintain a lot of entries in the file :-(

In addition, I found we cannot use paths with SPACE as the UCM directory name. Autoconf cannot support this. It complains although I tried \ or " to escape. We need something like "Dell.XPS13.BDW" as the UCM directory names.

Thanks
mengdong

Quoted 10 lines
Quoted 10 lines

Thanks
Mengdong

Quoted 3 lines

The alternative is to include the exact DMI name in a top level config file that points to the UCM config.

Quoted 9 lines
Quoted 2 lines

Thanks
Mengdong

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#8 lore raw
Quoted 78 lines · Mengdong Lin
Quoted 67 lines · Liam Girdwood
Quoted 51 lines
Quoted 47 lines
Quoted 12 lines
Quoted 12 lines

Review

Quoted 11 lines
(quoted diff) +11 -0
+/* This function will find the best device-specific configuration
+file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus the
+same sound
+ * card name (short name), but they may still need different
+device-specific
+ * configurations. For user space to differentiate them, kernel
+drivers may
+ * include the DMI info (vendor, product and board) in the card
+long

name.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines

+ * And user space can define configuration file names appending +DMI keywords
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *
+ * When being asked to load the configuration file for a card,

Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+this function
+ * will try to find the card long name from the local machine,
+and then scan
+ * all available configuration file names, search every field of
+the config
+ * file name in the card long name. The more characters match,
+the higher
+ * score the file has. Finally, the file with the highest score will be

loaded.

Quoted 10 lines
Quoted 9 lines
Quoted 1 line

+ */

Id' expect this function to try and open card longname and then card name if longname is not found. So providing we use the exact same names as the DMI name we wont need any string formatting or scoring (i.e. file
open("longname/longname.conf") will either succeed or fail)

Liam

Quoted 8 lines

I feel we cannot use the exact same names for the configuration file and card long name. The DMI info in the card long name can be lengthy, including '.' , SPACE, meaningless info like "Corp." and sometime duplicated info for some OEMs.I hope developers can just extract key words from the messy DMI info to make a simple configuration file name, and UCM automatically do the matching and give each configuration file a score. Then the file with highest score will be used for the card.

Quoted 3 lines

Providing the DMI name does not use invalid filename characters we are ok. Extracting key words and matching is prone to many problems and painful to debug....

Quoted 8 lines

May I revise the UCM code like this? It will try to open the file with DMI name at first. And only if that file is not available, fall back to key words matching.

I hope to keep the possibility that user can use a simple configuration file for a product family, without generating too many card directories and files.

If the DMI names are too complex for directory names, then you could add an alias file at the top level that would list the DMI name and the shortened name i.e.

# DMI name # UCM directory name
"Dell blah Corp. XPS, 13 blah" "Dell XPS13 BDW"

Quoted 8 lines

So the alias file could be searched for the DMI name, before the legacy name was tried.

The alias method above also allows for reuse of configs on machines that are similar, but with different DMI names. So this would also keep the number of configs low.

Liam

Quoted 8 lines

I'll try to use the alias file. But it seems we need to maintain a lot of entries in the file :-(

In addition, I found we cannot use paths with SPACE as the UCM directory name. Autoconf cannot support this. It complains although I tried \ or " to escape. We need something like "Dell.XPS13.BDW" as the UCM directory names.

Gah, it looks like autoconf may have defeated this ! Autoconf has special uses for some chars in names.

So you may want to "fix" the DMI name to exclude any special chars when creating your longname (maybe also set a shorter length too). I still dont want any scoring, we just want to open the "longname.conf" then "drivername.conf"

Liam

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#9 lore raw
Quoted 105 lines

-----Original Message-----
From: Liam Girdwood [mailto:[email protected]]
Sent: Friday, December 23, 2016 5:08 PM
To: Mengdong Lin <[email protected]>
Cc: Lin, Mengdong <[email protected]>; [email protected]; [email protected]; Koul, Vinod <[email protected]>; [email protected]; Bossart, Pierre-louis <[email protected]>
Subject: Re: [alsa-devel] [PATCH 1/2] ucm: Automatically load the best config file based on the card long name

Quoted 39 lines · Mengdong Lin
Quoted 37 lines · Liam Girdwood
Quoted 37 lines
Quoted 37 lines
Quoted 12 lines
Quoted 12 lines

Review

Quoted 11 lines
(quoted diff) +11 -0
+/* This function will find the best device-specific
+configuration file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus
+the same sound
+ * card name (short name), but they may still need different
+device-specific
+ * configurations. For user space to differentiate them,
+kernel drivers may
+ * include the DMI info (vendor, product and board) in the
+card long

name.

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines

+ * And user space can define configuration file names

(quoted diff) +7 -0
+appending DMI keywords
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *
+ * When being asked to load the configuration file for a card,
+this function
Quoted 8 lines

Review

Quoted 8 lines

+ * will try to find the card long name from the local machine,

(quoted diff) +7 -0
+and then scan
+ * all available configuration file names, search every field
+of the config
+ * file name in the card long name. The more characters match,
+the higher
+ * score the file has. Finally, the file with the highest
+score will be

loaded.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

+ */

Id' expect this function to try and open card longname and then card name if longname is not found. So providing we use the exact same names as the DMI name we wont need any string formatting or scoring (i.e. file open("longname/longname.conf") will either succeed or fail)

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

Liam

I feel we cannot use the exact same names for the configuration file and card long name. The DMI info in the card long name can be lengthy, including '.' , SPACE, meaningless info like "Corp." and sometime duplicated info for some OEMs.I hope developers

can

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

just extract key words from the messy DMI info to make a simple configuration file name, and UCM automatically do the matching and give each configuration file a score. Then the file with highest score will be used for the card.

Providing the DMI name does not use invalid filename characters we

are ok.

Quoted 26 lines
Quoted 26 lines
Quoted 11 lines
Quoted 2 lines

Extracting key words and matching is prone to many problems and painful to debug....

May I revise the UCM code like this? It will try to open the file with DMI name at first. And only if that file is not available, fall back to key words matching.

I hope to keep the possibility that user can use a simple configuration file for a product family, without generating too many card directories and files.

If the DMI names are too complex for directory names, then you could add an alias file at the top level that would list the DMI name and the shortened name i.e.

# DMI name # UCM directory name
"Dell blah Corp. XPS, 13 blah" "Dell XPS13 BDW"

So the alias file could be searched for the DMI name, before the legacy name was tried.

The alias method above also allows for reuse of configs on machines that are similar, but with different DMI names. So this would also keep the number of configs low.

Quoted 7 lines
Quoted 1 line

Liam

I'll try to use the alias file. But it seems we need to maintain a lot of entries in the file :-(

In addition, I found we cannot use paths with SPACE as the UCM directory name. Autoconf cannot support this. It complains although I tried

\ or "

Quoted 3 lines

to escape. We need something like "Dell.XPS13.BDW" as the UCM directory names.

Gah, it looks like autoconf may have defeated this ! Autoconf has special uses for some chars in names.

Quoted 7 lines

So you may want to "fix" the DMI name to exclude any special chars when creating your longname (maybe also set a shorter length too). I still dont want any scoring, we just want to open the "longname.conf" then "drivername.conf"

Liam

Okay. I'll remove the special chars from the card long name and make UCM code simpler as you suggested :-)

Thanks
Mengdong

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#10 lore raw
In reply to [email protected]
Quoted 12 lines · On 12/21/16 7:09 AM, [email protected] wrote:

From: Mengdong Lin <[email protected]>

Intel DSP platform drivers are used by many different devices. For user space to differentiate them, ASoC machine driver may include the DMI info (vendor, product and board) in card long name. Possible card long names are:
broadwell-rt286-Dell Inc.-XPS 13 9343-0310JH broadwell-rt286-Intel Corp.-Broadwell Client platform-Wilson Beach SDS bytcr-rt5640-ASUSTeK COMPUTER INC.-T100TA-T100TA bytcr-rt5651-Circuitco-Minnowboard Max D0 PLATFORM-MinnowBoard MAX
...

Quoted 8 lines

And user space can define configuration files including fields separated by '.' as below:
broadwell-rt286
broadwell-rt286.Dell.XPS
bytcr-rt5640
bytcr-rt5640.ASUS.T100
bytcr-rt5651.MinnowboardMax
...

It's weird to use a different naming convention in driver and userspace. Now the '.' is a separator?

Quoted 6 lines

When being asked to load configuration file of a card, UCM will try to find the card long name from the local machine, and then scan all available configuration file names, search every field of config file name in the card long name. The more characters match, the higher score the file has. Finally, the file with the highest score will be loaded to configure the sound card.

There are cases where we absolutely don't want to let users use a shorter name. T100 is terrible for example, it would work for T100TA, T100TAF, T00HA which are completely different platforms.

While the partial matching is elegant, I would err on the side of simplicity and keep the filename as reported by the driver. that way people just copy/paste the longname name and there are fewer opportunities for screwups. Yes the file names would be a tad long but we are not using DOS, are we?

Quoted 261 lines
src/ucm/parser.c +210 -1
index c98373a..ff75da7 100644
@@ -55,6 +55,9 @@ static const char * const component_dir[] = {
 	NULL,		/* terminator */
 };
 
+static int filename_filter(const struct dirent *dirent);
+static int is_component_directory(const char *dir);
+
 static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
 			  struct list_head *base,
 			  snd_config_t *cfg);
@@ -1328,6 +1331,210 @@ static int parse_master_file(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)
 	return 0;
 }
 
+/* trim SPACE (0x20) from the string */
+static void trim_space(char *str)
+{
+	int i, j = 0;
+
+	for (i = 0; str[i] && i < MAX_FILE; i++) {
+		if (str[i] != 0x20)
+			str[j++] = str[i];
+	}
+
+	str[j] = '\0';
+}
+
+/* find and store the card long name if the card is in this machine */
+static int get_card_long_name(snd_use_case_mgr_t *mgr)
+{
+	const char *card_name = mgr->card_name;
+	snd_ctl_t *handle;
+	int card, err, dev, idx;
+	snd_ctl_card_info_t *info;
+	const char *_name, *_long_name;
+
+	snd_ctl_card_info_alloca(&info);
+
+	card = -1;
+	if (snd_card_next(&card) < 0 || card < 0) {
+		uc_error("no soundcards found...");
+		return -1;
+	}
+
+	while (card >= 0) {
+		char name[32];
+
+		sprintf(name, "hw:%d", card);
+		err = snd_ctl_open(&handle, name, 0);
+		if (err < 0) {
+			uc_error("control open (%i): %s", card,
+				 snd_strerror(err));
+			goto next_card;
+		}
+
+		err = snd_ctl_card_info(handle, info);
+		if (err < 0) {
+			uc_error("control hardware info (%i): %s", card,
+				 snd_strerror(err));
+			snd_ctl_close(handle);
+			goto next_card;
+		}
+
+		_name = snd_ctl_card_info_get_name(info);
+		if (!strncmp(card_name, _name, 32)) {
+			_long_name = snd_ctl_card_info_get_longname(info);
+			strncpy(mgr->card_long_name, _long_name,
+				MAX_CARD_LONG_NAME);
+			snd_ctl_close(handle);
+			return 0;
+		}
+
+		snd_ctl_close(handle);
+next_card:
+		if (snd_card_next(&card) < 0) {
+			uc_error("snd_card_next");
+			break;
+		}
+	}
+
+	return -1;
+}
+
+/* This function will find the best device-specific configuration file based
+ * on the sound card long name.
+ * Different devices may share the same sound driver and thus the same sound
+ * card name (short name), but they may still need different device-specific
+ * configurations. For user space to differentiate them, kernel drivers may
+ * include the DMI info (vendor, product and board) in the card long name.
+ * And user space can define configuration file names appending DMI keywords
+ * to the card name, like:
+ * bytcr-rt5640.ASUS.T100
+ * bytcr-rt5651.MinnowBoard
+ *
+ * When being asked to load the configuration file for a card, this function
+ * will try to find the card long name from the local machine, and then scan
+ * all available configuration file names, search every field of the config
+ * file name in the card long name. The more characters match, the higher
+ * score the file has. Finally, the file with the highest score will be loaded.
+ */
+static void find_best_config_file(snd_use_case_mgr_t *mgr)
+{
+	const char *card_name = mgr->card_name;
+	char name[MAX_FILE];
+	char *env = getenv(ALSA_CONFIG_UCM_VAR);
+	struct dirent **namelist;
+	char card_long_name[MAX_CARD_LONG_NAME];
+	char *lpos, *lpos_next, *lname_end;
+	char *d_name, *dpos, *dpos_next, *d_name_end;
+	int d_name_len, field_len, long_name_len;
+	int i, cnt, err;
+	int score, score_max = 0, d_index = -1;
+	int  is_first_field;
+
+	if (get_card_long_name(mgr) < 0) {
+		/* cannot get long name, use card name as the conf file name */
+		strcpy(mgr->conf_file_name, mgr->card_name);
+		return;
+	}
+
+	strncpy(card_long_name, mgr->card_long_name, MAX_CARD_LONG_NAME);
+	trim_space(card_long_name); /* trim SPACE for matching */
+	lname_end = card_long_name + strlen(card_long_name);
+
+	/* get list of card directories under /usr/share/alsa/ucm */
+	snprintf(name, sizeof(name)-1,
+		"%s", env ? env : ALSA_USE_CASE_DIR);
+	name[MAX_FILE-1] = '\0';
+
+	err = scandir(name, &namelist, filename_filter, alphasort);
+	if (err < 0) {
+		err = -errno;
+		uc_error("error: could not scan directory %s: %s",
+				name, strerror(-err));
+		return;
+	}
+	cnt = err;
+
+	/* scan the card directory names */
+	for (i = 0; i < cnt; i++) {
+
+		/* Skip the directories for component devices */
+		if (is_component_directory(namelist[i]->d_name))
+			continue;
+
+		score = 0;
+		lpos = card_long_name;
+
+		d_name = namelist[i]->d_name;
+		d_name_len = strlen(d_name);
+		d_name_end = d_name + d_name_len;
+		is_first_field = 1;
+		dpos = d_name;
+
+		/* scan fields in the card directory name, separated by '.' */
+		while (1) {
+			dpos_next = strchr(dpos, '.');
+			if (dpos_next == dpos)	/* start with '.' */
+				goto next_field;
+
+			if (!dpos_next) /* last field */
+				field_len = d_name_end - dpos;
+			else
+				field_len = dpos_next - dpos;
+
+			memcpy(name, dpos, field_len);
+			name[field_len] = '\0';
+
+			/* search the field in the given card long name */
+			lpos_next = strstr(lpos, name);
+			if (!lpos_next) {
+				/* first field is the card name, must match */
+				if (is_first_field)
+					break;
+				goto next_field;
+			} else {
+				/* The more characters match,
+				 * the higher the score is.
+				 */
+				score += field_len;
+				if (lpos_next + field_len >= lname_end)
+					break; /* reach end of long name */
+
+				/* Skip the matched field,
+				 * for searching next field.
+				 */
+				lpos = lpos_next + field_len;
+			}
+
+next_field:
+			if (!dpos_next)
+				break; /* no more fields */
+
+			dpos = dpos_next + 1; /* skip the separator '.' */
+			is_first_field = 0;
+			if (dpos >= d_name_end)
+				break;
+		}
+
+		if (score > score_max) {
+			score_max = score;
+			d_index = i;
+		} else if (score == 0 && score_max > 0) {
+			/* passed the card directories that can match,
+			 * since directories are in alphabetical order.
+			 */
+			break;
+		}
+	}
+
+	if (d_index >= 0)
+		strncpy(mgr->conf_file_name, namelist[d_index]->d_name,
+			MAX_CARD_LONG_NAME);
+	else
+		strncpy(mgr->conf_file_name, mgr->card_name,
+			MAX_CARD_LONG_NAME);
+}
+
 static int load_master_config(const char *card_name, snd_config_t **cfg)
 {
 	char filename[MAX_FILE];
@@ -1355,7 +1562,9 @@ int uc_mgr_import_master_config(snd_use_case_mgr_t *uc_mgr)
 	snd_config_t *cfg;
 	int err;
 
-	err = load_master_config(uc_mgr->card_name, &cfg);
+	find_best_config_file(uc_mgr);
+
+	err = load_master_config(uc_mgr->conf_file_name, &cfg);
 	if (err < 0)
 		return err;
 	err = parse_master_file(uc_mgr, cfg);
src/ucm/ucm_local.h +3 -0
index 6d3302f..299a5b9 100644
@@ -41,6 +41,7 @@
 #include "use-case.h"
 
 #define MAX_FILE		256
+#define MAX_CARD_LONG_NAME	80
 #define ALSA_USE_CASE_DIR	ALSA_CONFIG_DIR "/ucm"
 
 #define SEQUENCE_ELEMENT_TYPE_CDEV	1
@@ -190,6 +191,8 @@ struct use_case_verb {
  */
 struct snd_use_case_mgr {
 	char *card_name;
+	char card_long_name[MAX_CARD_LONG_NAME];
+	char conf_file_name[MAX_CARD_LONG_NAME];
 	char *comment;
 
 	/* use case verb, devices and modifier configs parsed from files */
#11 lore raw
Quoted 27 lines

-----Original Message-----
From: Pierre-Louis Bossart [mailto:[email protected]]
Sent: Wednesday, December 21, 2016 10:47 PM

Quoted 10 lines · On 12/21/16 7:09 AM, [email protected] wrote:

From: Mengdong Lin <[email protected]>

Intel DSP platform drivers are used by many different devices. For user space to differentiate them, ASoC machine driver may include the DMI info (vendor, product and board) in card long name. Possible card long names
are:
broadwell-rt286-Dell Inc.-XPS 13 9343-0310JH broadwell-rt286-Intel Corp.-Broadwell Client platform-Wilson Beach SDS bytcr-rt5640-ASUSTeK COMPUTER INC.-T100TA-T100TA bytcr-rt5651-Circuitco-Minnowboard Max

D0

Quoted 10 lines

PLATFORM-MinnowBoard MAX ...

And user space can define configuration files including fields separated by '.' as below:
broadwell-rt286
broadwell-rt286.Dell.XPS
bytcr-rt5640
bytcr-rt5640.ASUS.T100
bytcr-rt5651.MinnowboardMax
...

Quoted 2 lines

It's weird to use a different naming convention in driver and userspace. Now the '.' is a separator?

Yes. Now '.' is a separator in user space. The code use it to separate each keyword for matching in the card long name. We can also use '.' as separators in kernel, it will not affect the matching.

Quoted 11 lines
Quoted 6 lines

When being asked to load configuration file of a card, UCM will try to find the card long name from the local machine, and then scan all available configuration file names, search every field of config file name in the card long name. The more characters match, the higher score the file has. Finally, the file with the highest score will be loaded to configure the sound card.

There are cases where we absolutely don't want to let users use a shorter name. T100 is terrible for example, it would work for T100TA, T100TAF, T00HA which are completely different platforms.

Quoted 5 lines

While the partial matching is elegant, I would err on the side of simplicity and keep the filename as reported by the driver. that way people just copy/paste the longname name and there are fewer opportunities for screwups. Yes the file names would be a tad long but we are not using DOS, are we?

The file names would be really long and machines have different product name can potentially use the same configuration file for DELL XPS 13 or 15(2014) and DELL XPS 13 or 15 (2015) although they have a slight different number in DMI product and board names. For such products, a simple configuration name as "broadwell-rt286.Dell.XPS" can serve them all.

For the AUS T100 family, we could define different configuration files as below:
bytcr-rt5640.ASUS.T100TA
bytcr-rt5640.ASUS.T100TAF
bytcr-rt5640.ASUS.T100HA

They will have different scores, so UCM can choose the best one.

Thanks
Mengdong