[alsa-devel] [PATCH 1/2] ASoC: core: Add API to use DMI name in sound card long name

Liam Girdwood liam.r.girdwood at linux.intel.com
Wed Dec 21 15:27:11 CET 2016


On Wed, 2016-12-21 at 21:04 +0800, mengdong.lin at linux.intel.com wrote:
> From: Liam Girdwood <liam.r.girdwood at linux.intel.com>
> 
> Intel DSP platform drivers are used by many different devices but are
> difficult for userspace to differentiate. This patch adds an API to allow
> the DMI name to be used in the sound card long name, thereby helping
> userspace load the correct UCM configuration. Usually machine drivers
> uses their own name as the sound card name (short name), and leave the
> long name and driver name blank. This API will append the DMI info
> like vendor, product and board info, to the card name to make up the card
> long name. If the machine driver has already explicitly set the long name,
> this API will do nothing.
> 
> This patch also allows for further differentiation as many devices that
> share the same DMI name i.e. Minnowboards, UP boards may be configured
> with different codecs or firmwares. The API supports flavoring the DMI
> name into the card longname to provide the extra differentiation required
> for these devices.
> 
> Signed-off-by: Liam Girdwood <liam.r.girdwood at linux.intel.com>
> Signed-off-by: Mengdong Lin <mengdong.lin at linux.intel.com>
> 
> diff --git a/include/sound/soc.h b/include/sound/soc.h
> index 795e6c4..e4f1844 100644
> --- a/include/sound/soc.h
> +++ b/include/sound/soc.h
> @@ -497,6 +497,8 @@ 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_dmi_name(struct snd_soc_card *card, const char *flavour);
> +
>  /* 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);
> @@ -1094,6 +1096,8 @@ struct snd_soc_card {
>  	const char *name;
>  	const char *long_name;
>  	const char *driver_name;
> +	char dmi_longname[80];
> +
>  	struct device *dev;
>  	struct snd_card *snd_card;
>  	struct module *owner;
> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
> index aaab26a..8bcf241 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -34,6 +34,7 @@
>  #include <linux/ctype.h>
>  #include <linux/slab.h>
>  #include <linux/of.h>
> +#include <linux/dmi.h>
>  #include <sound/core.h>
>  #include <sound/jack.h>
>  #include <sound/pcm.h>
> @@ -1886,6 +1887,86 @@ 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_dmi_name() - Register DMI names to card
> + * @card: The card to register DMI names
> + * @flavour: The flavour "differentiator" for the card amongst its peers.
> + *
> + * Intel DSP platform drivers are used by many different devices but are
> + * difficult for userspace to differentiate, since machine drivers ususally
> + * use their own name as the card name (short name) and leave the card long
> + * name blank. This function will allow DMI info to be used in the sound
> + * card long name, thereby helping userspace load the correct UCM (Use Case
> + * Manager) configuration.
> + * Possible card long names may be:
> + * 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
> + *


Lets keep it simpler, we dont need to prepend the driver name to the
longname as it's already available in driver_name. 

The purpose of the patch is to uniquely identify the machine, so we dont
need to provide or duplicate other information in the name.

So longname should be "dmi-flavour" where dmi is product OR board (if
product is not available).

Liam

> + * This function also supports flavoring the card longname to provide
> + * the extra differentiation.
> + *
> + * Returns 0 on success, otherwise a negative error code.
> + */
> +int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
> +{
> +	const char *vendor, *product, *board;
> +
> +	if (card->long_name)
> +		return 0; /* long name already set by driver or from DMI */
> +
> +	vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
> +	if (!vendor) {
> +		dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
> +		return 0;
> +	}
> +
> +	product = dmi_get_system_info(DMI_PRODUCT_NAME);
> +	board = dmi_get_system_info(DMI_BOARD_NAME);
> +	if (!board && !product) {
> +		/* fall back to using legacy name */
> +		dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
> +		return 0;
> +	}
> +
> +	/* make up dmi long name as:
> +	 * card name (usually machine driver name) -vendor -product -board
> +	 */
> +	snprintf(card->dmi_longname, sizeof(card->snd_card->longname),
> +			"%s-%s", card->name, vendor);
> +
> +	if (product) {
> +		strncat(card->dmi_longname, "-",
> +			sizeof(card->snd_card->longname));
> +		strncat(card->dmi_longname, product,
> +			sizeof(card->snd_card->longname));
> +	}
> +
> +	if (board) {
> +		strncat(card->dmi_longname, "-",
> +			sizeof(card->snd_card->longname));
> +		strncat(card->dmi_longname, board,
> +			sizeof(card->snd_card->longname));
> +	}
> +
> +
> +	/* Add flavour to dmi long name */
> +	if (flavour) {
> +		strncat(card->dmi_longname, "-",
> +			sizeof(card->snd_card->longname));
> +		strncat(card->dmi_longname, flavour,
> +			sizeof(card->snd_card->longname));
> +	}
> +
> +	/* set long name */
> +	card->long_name = card->dmi_longname;
> +
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);
> +
>  static int snd_soc_instantiate_card(struct snd_soc_card *card)
>  {
>  	struct snd_soc_codec *codec;




More information about the Alsa-devel mailing list