From mboxrd@z Thu Jan 1 00:00:00 1970 From: Han Lu Subject: Re: [PATCH V4 1/2] ASoC: core: add API for registering DMI card names Date: Fri, 1 Apr 2016 16:55:13 +0800 Message-ID: <56FE3771.7090806@linux.intel.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by alsa0.perex.cz (Postfix) with ESMTP id DDDD72651BE for ; Fri, 1 Apr 2016 10:54:02 +0200 (CEST) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Takashi Iwai , han.lu@intel.com Cc: vinod.koul@intel.com, liam.r.girdwood@linux.intel.com, alsa-devel@alsa-project.org, broonie@kernel.org, pierre-louis.bossart@linux.intel.com List-Id: alsa-devel@alsa-project.org On 04/01/2016 01:52 PM, Takashi Iwai wrote: > On Fri, 01 Apr 2016 07:46:31 +0200, > han.lu@intel.com wrote: >> From: "Lu, Han" >> >> 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) >> >> Signed-off-by: Lu, Han >> >> diff --git a/include/sound/soc.h b/include/sound/soc.h >> index 02b4a21..4e80444 100644 >> --- a/include/sound/soc.h >> +++ b/include/sound/soc.h >> @@ -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); >> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c >> index d2e62b15..3faaa59 100644 >> --- a/sound/soc/soc-core.c >> +++ b/sound/soc/soc-core.c >> @@ -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); >> + 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. > > 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? > > 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 > > Takashi > _______________________________________________ > Alsa-devel mailing list > Alsa-devel@alsa-project.org > http://mailman.alsa-project.org/mailman/listinfo/alsa-devel >