From patchwork Tue Jul 15 06:47:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 4551491 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 01B4B9F1D6 for ; Tue, 15 Jul 2014 06:51:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 25E7D20172 for ; Tue, 15 Jul 2014 06:51:17 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id B7FCA2012F for ; Tue, 15 Jul 2014 06:51:15 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0F3DF264F09; Tue, 15 Jul 2014 08:51:13 +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, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 0CC5A261A2C; Tue, 15 Jul 2014 08:51:08 +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 2BCC4261A95; Tue, 15 Jul 2014 08:51:06 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by alsa0.perex.cz (Postfix) with ESMTP id 66F0126172C for ; Tue, 15 Jul 2014 08:50:58 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 14 Jul 2014 23:50:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,663,1400050800"; d="scan'208";a="561881395" Received: from vkoul-udesk3.iind.intel.com (HELO localhost.localdomain) ([10.223.96.11]) by fmsmga001.fm.intel.com with ESMTP; 14 Jul 2014 23:50:43 -0700 From: Vinod Koul To: alsa-devel@alsa-project.org Date: Tue, 15 Jul 2014 12:17:45 +0530 Message-Id: <1405406865-10636-1-git-send-email-vinod.koul@intel.com> X-Mailer: git-send-email 1.7.0.4 Cc: Charles Keepax , Dimitris Papastamos , tiwai@suse.de, lgirdwood@gmail.com, Vinod Koul , broonie@kernel.org, Omair Mohammed Abdullah , pierre-louis.bossart@intel.com Subject: [alsa-devel] [RFC v2] ASoC: core: add a helper for extended byte controls using TLV 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: Omair Mohammed Abdullah ALSA supports arbitrary length TLVs for each kcontrol that can be used to pass metadata about the control (e.g. volumes, enum information). The same transport mechanism is now used for arbitrary length data by defining a new helper. Signed-off-by: Omair Mohammed Abdullah Signed-off-by: Vinod Koul --- As discussed in [1] we are adding a new approach to solve the byte control extensions by using existing TLVs and combining them with byte controls. The usermode on seeing byte control + TLV can treat it differently as it does for control + TLV combination today. This way we don't change kernel API and existing users will be happy, while providing embedded folks facility to pass large bytes data to kcontrols [1]: http://mailman.alsa-project.org/pipermail/alsa-devel/2013-November/069483.html include/sound/soc.h | 14 +++++++++++++- sound/soc/soc-core.c | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletions(-) diff --git a/include/sound/soc.h b/include/sound/soc.h index ed9e2d7..7522221 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -270,7 +270,14 @@ .get = xhandler_get, .put = xhandler_put, \ .private_value = (unsigned long)&(struct soc_bytes_ext) \ {.max = xcount} } - +#define SND_SOC_BYTES_TLV(xname, xcount, xhandler_get, xhandler_put) \ +{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ + .access = SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | \ + SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \ + .tlv.c = (snd_soc_bytes_tlv_callback), \ + .info = snd_soc_info_bytes_ext, \ + .private_value = (unsigned long)&(struct soc_bytes_ext) \ + {.max = xcount, .get = xhandler_get, .put = xhandler_put, }} #define SOC_SINGLE_XR_SX(xname, xregbase, xregcount, xnbits, \ xmin, xmax, xinvert) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ @@ -552,6 +559,8 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol); int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *ucontrol); +int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag, + unsigned int size, unsigned int __user *tlv); int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo); int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol, @@ -1119,6 +1128,9 @@ struct soc_bytes { struct soc_bytes_ext { int max; + /* used for TLV byte control */ + int (*get)(unsigned int __user *bytes, unsigned int size); + int (*put)(const unsigned int __user *bytes, unsigned int size); }; /* multi register control */ diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index b87d7d8..e6ad95b 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3267,6 +3267,28 @@ int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol, } EXPORT_SYMBOL_GPL(snd_soc_bytes_info_ext); +int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag, + unsigned int size, unsigned int __user *tlv) +{ + struct soc_bytes_ext *params = (void *)kcontrol->private_value; + unsigned int count = size < params->max ? size : params->max; + + switch (op_flag) { + case 0: + if (params->get) + params->get(tlv, count); + break; + case 1: + if (params->put) + params->put(tlv, count); + break; + default: + return -ENXIO; + } + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback); + /** * snd_soc_info_xr_sx - signed multi register info callback * @kcontrol: mreg control