From patchwork Thu Mar 31 08:58:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: han.lu@intel.com X-Patchwork-Id: 8708841 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6B0CBC0554 for ; Thu, 31 Mar 2016 08:57:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7EC0B20221 for ; Thu, 31 Mar 2016 08:57:30 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 3A23520272 for ; Thu, 31 Mar 2016 08:57:29 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id CB8C4266636; Thu, 31 Mar 2016 10:57:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id A02832650E7; Thu, 31 Mar 2016 10:57:00 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id B2A562614A9; Thu, 31 Mar 2016 10:56:58 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by alsa0.perex.cz (Postfix) with ESMTP id C76FD2612AF for ; Thu, 31 Mar 2016 10:56:52 +0200 (CEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 31 Mar 2016 01:56:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,421,1455004800"; d="scan'208";a="76443181" Received: from hanlu-optiplex-9020.sh.intel.com ([10.239.13.11]) by fmsmga004.fm.intel.com with ESMTP; 31 Mar 2016 01:56:49 -0700 From: han.lu@intel.com To: broonie@kernel.org, tiwai@suse.de, vinod.koul@intel.com, pierre-louis.bossart@linux.intel.com, liam.r.girdwood@linux.intel.com, alsa-devel@alsa-project.org Date: Thu, 31 Mar 2016 16:58:03 +0800 Message-Id: <79fd64c59dd44d44e018245ad411d48f5ba01b24.1459414492.git.han.lu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: In-Reply-To: References: Cc: "Lu, Han" Subject: [alsa-devel] [PATCH V3 1/2] ASoC: core: add API for registering DMI card names X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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..8f9c13f 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1828,6 +1828,59 @@ 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 = kmalloc(buf_size, GFP_KERNEL); + if (!name) + return -ENOMEM; + snprintf(name, buf_size, "%s:%s:%s:%s", card->name, + card->driver_name, vendor, firmware); + ret = snd_component_add(card->snd_card, name); + card->long_name = card->snd_card->components; + + kfree(name); + return ret; +} +EXPORT_SYMBOL_GPL(snd_soc_set_card_names); + static int snd_soc_instantiate_card(struct snd_soc_card *card) { struct snd_soc_codec *codec;