From patchwork Tue Mar 13 16:27:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier MOYSAN X-Patchwork-Id: 10279881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B84F7601A0 for ; Tue, 13 Mar 2018 16:27:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7A7D284B3 for ; Tue, 13 Mar 2018 16:27:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C029290A8; Tue, 13 Mar 2018 16:27:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B708284B3 for ; Tue, 13 Mar 2018 16:27:23 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id DB02D266E77; Tue, 13 Mar 2018 17:27:21 +0100 (CET) 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 06C3B267294; Tue, 13 Mar 2018 17:27:20 +0100 (CET) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [62.209.51.94]) by alsa0.perex.cz (Postfix) with ESMTP id 6BF17266E60 for ; Tue, 13 Mar 2018 17:27:17 +0100 (CET) Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w2DGNjVx003126; Tue, 13 Mar 2018 17:27:16 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2gpc5s9xn8-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 13 Mar 2018 17:27:16 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 45AE331; Tue, 13 Mar 2018 16:27:14 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 09D5FA5DB; Tue, 13 Mar 2018 16:27:14 +0000 (GMT) Received: from SAFEX1HUBCAS24.st.com (10.75.90.94) by SAFEX1HUBCAS21.st.com (10.75.90.44) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 13 Mar 2018 17:27:13 +0100 Received: from localhost (10.201.23.16) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 13 Mar 2018 17:27:13 +0100 From: Olivier Moysan To: , , , , , , , , , , , , , Date: Tue, 13 Mar 2018 17:27:06 +0100 Message-ID: <1520958428-10930-2-git-send-email-olivier.moysan@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1520958428-10930-1-git-send-email-olivier.moysan@st.com> References: <1520958428-10930-1-git-send-email-olivier.moysan@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.16] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-13_07:, , signatures=0 Cc: jsarha@ti.com, arnaud.pouliquen@st.com, benjamin.gaignard@st.com, rmk@arm.linux.org.uk Subject: [alsa-devel] [PATCH 1/3] ALSA: pcm: add IEC958 channel status control helper 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Arnaud Pouliquen Add IEC958 channel status helper that creates control to handle the IEC60958 status bits. Signed-off-by: Arnaud Pouliquen Signed-off-by: Olivier Moysan --- include/sound/pcm_iec958.h | 19 ++++++++ sound/core/pcm_iec958.c | 113 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) diff --git a/include/sound/pcm_iec958.h b/include/sound/pcm_iec958.h index 0939aa45e2fe..3c9701a9b1b0 100644 --- a/include/sound/pcm_iec958.h +++ b/include/sound/pcm_iec958.h @@ -4,9 +4,28 @@ #include +/** + * struct snd_pcm_iec958_params: IEC 60958 controls parameters + * @ctrl_set: control set callback + * This callback is optional and shall be used to set associated driver + * configuration. + * @iec: Mandatory pointer to iec958 structure. + * @cs: Mandatory pointer to AES/IEC958 channel status bits. + * @cs_len: size in byte of the AES/IEC958 channel status bits. + * @private_data: Optional private pointer to driver context. + */ +struct snd_pcm_iec958_params { + int (*ctrl_set)(struct snd_pcm_iec958_params *iec_param); + unsigned char *cs; + unsigned char cs_len; + void *private_data; +}; + int snd_pcm_create_iec958_consumer(struct snd_pcm_runtime *runtime, u8 *cs, size_t len); int snd_pcm_create_iec958_consumer_hw_params(struct snd_pcm_hw_params *params, u8 *cs, size_t len); +int snd_pcm_add_iec958_ctl(struct snd_pcm *pcm, int subdevice, int stream, + struct snd_pcm_iec958_params *params); #endif diff --git a/sound/core/pcm_iec958.c b/sound/core/pcm_iec958.c index 5e6aed64f451..aba1f522e98a 100644 --- a/sound/core/pcm_iec958.c +++ b/sound/core/pcm_iec958.c @@ -7,11 +7,88 @@ */ #include #include +#include #include +#include #include #include #include +static int snd_pcm_iec958_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; + uinfo->count = 1; + return 0; +} + +/* + * IEC958 channel status default controls callbacks + */ +static int snd_pcm_iec958_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *uctl) +{ + struct snd_pcm_iec958_params *params = snd_kcontrol_chip(kcontrol); + int i; + + for (i = 0; i < params->cs_len; i++) + uctl->value.iec958.status[i] = params->cs[i]; + + return 0; +} + +static int snd_pcm_iec958_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *uctl) +{ + struct snd_pcm_iec958_params *params = snd_kcontrol_chip(kcontrol); + int err = 0; + unsigned int i, updated = 0; + unsigned char old_status[5]; + + for (i = 0; i < params->cs_len; i++) { + if (params->cs[i] != uctl->value.iec958.status[i]) + updated = 1; + } + + if (!updated) + return 0; + + /* Store current status to restore them in error case */ + for (i = 0; i < params->cs_len; i++) { + old_status[i] = params->cs[i]; + params->cs[i] = uctl->value.iec958.status[i]; + } + + if (params->ctrl_set) + err = params->ctrl_set(params); + if (err < 0) { + for (i = 0; i < params->cs_len; i++) + params->cs[i] = old_status[i]; + } + + return err; +} + +static const struct snd_kcontrol_new iec958_ctls[] = { + { + .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | + SNDRV_CTL_ELEM_ACCESS_VOLATILE), + .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), + .info = snd_pcm_iec958_info, + .get = snd_pcm_iec958_get, + .put = snd_pcm_iec958_put, + }, + { + .access = (SNDRV_CTL_ELEM_ACCESS_READ | + SNDRV_CTL_ELEM_ACCESS_VOLATILE), + .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT), + .info = snd_pcm_iec958_info, + .get = snd_pcm_iec958_get, + }, +}; + static int create_iec958_consumer(uint rate, uint sample_width, u8 *cs, size_t len) { @@ -21,6 +98,9 @@ static int create_iec958_consumer(uint rate, uint sample_width, return -EINVAL; switch (rate) { + case 0: + fs = IEC958_AES3_CON_FS_NOTID; + break; case 32000: fs = IEC958_AES3_CON_FS_32000; break; @@ -48,6 +128,9 @@ static int create_iec958_consumer(uint rate, uint sample_width, if (len > 4) { switch (sample_width) { + case 0: + ws = IEC958_AES4_CON_WORDLEN_NOTID; + break; case 16: ws = IEC958_AES4_CON_WORDLEN_20_16; break; @@ -124,3 +207,33 @@ int snd_pcm_create_iec958_consumer_hw_params(struct snd_pcm_hw_params *params, cs, len); } EXPORT_SYMBOL(snd_pcm_create_iec958_consumer_hw_params); + +/** + * snd_pcm_add_iec958_ctl - Add a IEC958 control associated to the pcm device + * @pcm: pcm device to associate to the control. + * @subdevice: subdevice index.Must be set to 0 if unused + * @iec958: snd_pcm_iec958_params structure that contains callbacks + * and channel status buffer. + * @stream: stream type SNDRV_PCM_STREAM_PLAYBACK or SNDRV_PCM_STREAM_CATURE. + * Returns: negative error code if something failed. + */ +int snd_pcm_add_iec958_ctl(struct snd_pcm *pcm, int subdevice, int stream, + struct snd_pcm_iec958_params *params) +{ + struct snd_kcontrol_new knew; + + if (stream > SNDRV_PCM_STREAM_LAST) + return -EINVAL; + if (!params->cs) + return -EINVAL; + if (params->cs_len < 4) + return -EINVAL; + + create_iec958_consumer(0, 0, params->cs, params->cs_len); + knew = iec958_ctls[stream]; + knew.device = pcm->device; + knew.subdevice = subdevice; + + return snd_ctl_add(pcm->card, snd_ctl_new1(&knew, params)); +} +EXPORT_SYMBOL(snd_pcm_add_iec958_ctl);