Skip to contentSkip to conversation

ASoC: share more product information with user space

PATCH Superseded [email protected] 3 participants 5 messages Apr 1, 2016

Subsystems (3)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover ASoC: share more product information with user space

From: "Lu, Han" <[email protected]>

Share more product information, so user space utils such as PA and UCM can distinguish different products.
1. Add a core API.
2. Apply the API to bytcr-rt5640 driver.

changes on V4:
1. Replace kmalloc() and snprintf() with ksaprintf() to simplify code

changes on V3:
1. Split the core API and the API call to two patches
2. Replace misused strcat() with snprintf()
3. Code and comment fix

Lu, Han (2):
ASoC: core: add API for registering DMI card names
ASoC: bytcr-rt5640: register DMI names to card

 include/sound/soc.h                   |  3 ++
 sound/soc/intel/boards/bytcr_rt5640.c | 15 ++++++++++
 sound/soc/soc-core.c                  | 56 +++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
Signature · 1 line
2.5.0
#1 lore raw

PATCH v4 1/2 ASoC: core: add API for registering DMI card names

From: "Lu, Han" <[email protected]>

Add core API for registering DMI card names, so user space utils such as PA and UCM can distinguish various products.
Previously on ASoC, the card short name, driver name and long name are all the same as the machine driver name.
The patch adds more board information:
card driver name ---> machine driver name
card short name ---> DMI_BOARD_NAME or DMI_PRODUCT_NAME card long name and
card component ---> short name:driver name:(DMI_SYS_VENDOR if
available):(the firmware name if available)

include/sound/soc.h +3 -0
index 02b4a21..4e80444 100644
@@ -486,6 +486,9 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
 	unsigned int dai_fmt);
 
+int snd_soc_set_card_names(struct snd_soc_card *card, const char *board,
+		const char *vendor, const char *firmware);
+
 /* Utility functions to get clock rates from various things */
 int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
 int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
sound/soc/soc-core.c +56 -0

62 lines not on this page · raw message

Signature · 1 line
2.5.0
#2 lore raw

Re: [PATCH V4 1/2] ASoC: core: add API for registering DMI card names

Quoted 78 lines · On Fri, 01 Apr 2016 07:46:31 +0200, [email protected] wrote:

From: "Lu, Han" <[email protected]>

Add core API for registering DMI card names, so user space utils such as PA and UCM can distinguish various products.
Previously on ASoC, the card short name, driver name and long name are all the same as the machine driver name.
The patch adds more board information:
card driver name ---> machine driver name
card short name ---> DMI_BOARD_NAME or DMI_PRODUCT_NAME card long name and
card component ---> short name:driver name:(DMI_SYS_VENDOR if
available):(the firmware name if available)

include/sound/soc.h +3 -0
index 02b4a21..4e80444 100644
@@ -486,6 +486,9 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
 	unsigned int dai_fmt);
 
+int snd_soc_set_card_names(struct snd_soc_card *card, const char *board,
+		const char *vendor, const char *firmware);
+
 /* Utility functions to get clock rates from various things */
 int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
 int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
sound/soc/soc-core.c +40 -0
index d2e62b15..3faaa59 100644
@@ -1828,6 +1828,62 @@ int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
 }
 EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
 
+/**
+ * snd_soc_set_card_names() - Set the shortname/drivername/longname/component
+ * of a ASoC card.
+ * @card: The card to set names
+ * @board: DMI_BOARD_NAME or DMI_PRODUCT_NAME
+ * @vendor: DMI_SYS_VENDOR
+ * @firmware: The firmware name
+ *
+ * This function registers DMI names to card for the userspace to distinguish
+ * different boards/products:
+ *   card driver name --->  machine driver name
+ *   card short name  --->  DMI_BOARD_NAME or DMI_PRODUCT_NAME
+ *   card long name and
+ *   card component   --->  short name:driver name:(DMI_SYS_VENDOR)
+ *                          :(firmware name)
+ *
+ * Returns 0 on success, otherwise a negative error code.
+ */
+int snd_soc_set_card_names(struct snd_soc_card *card, const char *board,
+		const char *vendor, const char *firmware)
+{
+	int ret = 0;
+	size_t buf_size, name_size;
+	char *name;
+
+	if (!board) {
+		dev_err(card->dev, "ASoC: the board/product name is empty!\n");
+		return -EINVAL;
+	}
+
+	/* card driver name */
+	card->driver_name = card->name;
+
+	/* card short name */
+	card->name = board;
+
+	/* card long name / card component */
+	buf_size = sizeof(card->snd_card->longname);
+	name_size = strlen(card->name) + strlen(card->driver_name)
+			+ strlen(vendor) + strlen(firmware) + 4;

sound/soc/soc-core.c int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, · line 1880

Quoted 10 lines
sound/soc/soc-core.c +10 -0
+	if (buf_size < name_size + strlen(card->snd_card->components))
+		return -ENOMEM;
+
+	name = kasprintf(GFP_KERNEL, "%s:%s:%s:%s", card->name,
+			card->driver_name, vendor, firmware);
+	if (!name)
+		return -ENOMEM;
+
+	ret = snd_component_add(card->snd_card, name);
+	card->long_name = card->snd_card->components;

This can't be used so. First off, both have the different sizes. And a driver might have already put some string in components that is irrelevant to long name.

And what if name strings contain ':' letter?

Also, in this version, firmware is no longer optional but mandatory?

Takashi

#3 lore raw

Re: [PATCH V4 1/2] ASoC: core: add API for registering DMI card names

Quoted 84 lines · Takashi Iwai
Quoted 82 lines · On Fri, 01 Apr 2016 07:46:31 +0200, [email protected] wrote:

From: "Lu, Han" <[email protected]>

Add core API for registering DMI card names, so user space utils such as PA and UCM can distinguish various products.
Previously on ASoC, the card short name, driver name and long name are all the same as the machine driver name.
The patch adds more board information:
card driver name ---> machine driver name
card short name ---> DMI_BOARD_NAME or DMI_PRODUCT_NAME card long name and
card component ---> short name:driver name:(DMI_SYS_VENDOR if
available):(the firmware name if available)

include/sound/soc.h +3 -0
index 02b4a21..4e80444 100644
@@ -486,6 +486,9 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
  int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
  	unsigned int dai_fmt);
 
+int snd_soc_set_card_names(struct snd_soc_card *card, const char *board,
+		const char *vendor, const char *firmware);
+
  /* Utility functions to get clock rates from various things */
  int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
sound/soc/soc-core.c +45 -0
index d2e62b15..3faaa59 100644
@@ -1828,6 +1828,62 @@ int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
  }
  EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
 
+/**
+ * snd_soc_set_card_names() - Set the shortname/drivername/longname/component
+ * of a ASoC card.
+ * @card: The card to set names
+ * @board: DMI_BOARD_NAME or DMI_PRODUCT_NAME
+ * @vendor: DMI_SYS_VENDOR
+ * @firmware: The firmware name
+ *
+ * This function registers DMI names to card for the userspace to distinguish
+ * different boards/products:
+ *   card driver name --->  machine driver name
+ *   card short name  --->  DMI_BOARD_NAME or DMI_PRODUCT_NAME
+ *   card long name and
+ *   card component   --->  short name:driver name:(DMI_SYS_VENDOR)
+ *                          :(firmware name)
+ *
+ * Returns 0 on success, otherwise a negative error code.
+ */
+int snd_soc_set_card_names(struct snd_soc_card *card, const char *board,
+		const char *vendor, const char *firmware)
+{
+	int ret = 0;
+	size_t buf_size, name_size;
+	char *name;
+
+	if (!board) {
+		dev_err(card->dev, "ASoC: the board/product name is empty!\n");
+		return -EINVAL;
+	}
+
+	/* card driver name */
+	card->driver_name = card->name;
+
+	/* card short name */
+	card->name = board;
+
+	/* card long name / card component */
+	buf_size = sizeof(card->snd_card->longname);
+	name_size = strlen(card->name) + strlen(card->driver_name)
+			+ strlen(vendor) + strlen(firmware) + 4;
+	if (buf_size < name_size + strlen(card->snd_card->components))
+		return -ENOMEM;
+
+	name = kasprintf(GFP_KERNEL, "%s:%s:%s:%s", card->name,
+			card->driver_name, vendor, firmware);
Quoted 8 lines

sound/soc/soc-core.c int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, · line 1880

Quoted 5 lines
sound/soc/soc-core.c +5 -0
+	if (!name)
+		return -ENOMEM;
+
+	ret = snd_component_add(card->snd_card, name);
+	card->long_name = card->snd_card->components;

This can't be used so. First off, both have the different sizes. And a driver might have already put some string in components that is irrelevant to long name.

OK, I can assign static buffer in rt5640 driver to store card->long_name, so no need to share the space of card->snd_card->components.

Quoted 2 lines

And what if name strings contain ':' letter?

This is indeed the problem and I have no good idea so far. Maybe use some less common characters or brackets/braces to separate strings?

Quoted 2 lines

Also, in this version, firmware is no longer optional but mandatory?

Sorry, I only tested empty string "" but ignored NULL string. Will fix it.

BR,
Han

Quoted 7 lines

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

#4 lore raw

PATCH v4 2/2 ASoC: bytcr-rt5640: register DMI names to card

In reply to [email protected]

From: "Lu, Han" <[email protected]>

Register DMI names for products using bytcr-rt5640 driver, such as ASUS T100TA and Dell Venue 8 Pro 5830, for user space utils to distinguish different products.

For example, previously on T100TA:

  $ cat /proc/asound/cards
    0 [bytcrrt5640 ]: bytcr-rt5640 -  bytcr-rt5640
                      bytcr-rt5640
  $ amixer -c0 info
  Card hw:0 'bytcrrt5640'/'bytcr-rt5640'
    Mixer name    : ''
    Components    : ''
    Controls      : 256
    Simple ctrls  : 228

After apply the patch:

  $ cat /proc/asound/cards
    0 [T100TA      ]: bytcr-rt5640 -  T100TA
                      T100TA:bytcr-rt5640:ASUSTek COMPUTER INC.:intel/fw_
  sst_0f28.bin
  $ amixer -c0 info
  Card hw:0 'T100TA'/'T100TA:bytcr-rt5640:ASUSTek COMPUTER INC.:intel/fw_
  sst_0f28.bin'
    Mixer name    : ''
    Components    : 'T100TA:bytcr-rt5640:ASUSTek COMPUTER INC.:intel/fw_s
  st_0f28.bin'
    Controls      : 256
    Simple ctrls  : 228
sound/soc/intel/boards/bytcr_rt5640.c +15 -0
index 032a2e7..468a724 100644
@@ -152,6 +152,8 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
 	{}
 };
 
+static struct snd_soc_card byt_rt5640_card;
+
 static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
 {
 	int ret;
@@ -159,6 +161,19 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
 	struct snd_soc_card *card = runtime->card;
 	const struct snd_soc_dapm_route *custom_map;
 	int num_routes;
+	const char *board, *vendor;
+	struct sst_acpi_mach *mach = byt_rt5640_card.dev->platform_data;
+
+	/* Add board/product/vendor/firmware name for userspace */
+	board = dmi_get_system_info(DMI_BOARD_NAME);
+	if (!board)
+		board = dmi_get_system_info(DMI_PRODUCT_NAME);
+	vendor = dmi_get_system_info(DMI_SYS_VENDOR);
+	ret = snd_soc_set_card_names(card, board, vendor, mach->fw_filename);
+	if (ret < 0) {
+		dev_err(card->dev, "unable to set card names\n");
+		return ret;
+	}
 
 	card->dapm.idle_bias_off = true;
 
Signature · 1 line
2.5.0