From patchwork Wed Nov 17 19:44:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 12692989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5855C433F5 for ; Wed, 17 Nov 2021 19:46:37 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7A11561B64 for ; Wed, 17 Nov 2021 19:46:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7A11561B64 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=RIl6/ZiQhSkELD6DAx+jedj51Y7mtOTYg8KpOnmOORY=; b=u2BVn6xA0j/kyb qkJDechhCdTAEA9nrPe19UlgPE0MgxPUZ5QeDKDJ7cyrry20+MvziRq2Nz9a5qvH/haJnkE88xlgo iN8k5UpzudT00WHt6+quaPZ4LNL1MbPAl7OUKRAWprc+sgNYTXwOgSN95hs5zftFg3CtTxdSmh8Aa n9EoPY/lA6X7WPG28/BW2f9CYQNx8VaTHbBaBHsoHKhGv3W0KqeR5XWfx06QsRpFW+LN5x6D8XmXs DlzKzunHmwWuma3r7cRHBNka0rrq4Vb7QjyCsfvV6sCpb3YtrgOwtSWzHT82R/xuJv9AAYuErS9n6 EsTMbyC7lkoXjP4A7O0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnQrl-006BWj-Hd; Wed, 17 Nov 2021 19:45:09 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnQrh-006BW3-Vc for linux-arm-kernel@lists.infradead.org; Wed, 17 Nov 2021 19:45:07 +0000 Received: by mail-wr1-x432.google.com with SMTP id a9so6834170wrr.8 for ; Wed, 17 Nov 2021 11:45:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=944R6VkEBj9im8jiA+ivAeCJ/qxWRZNjJgR3j1HHJsI=; b=FqUXYaL8OmqBwrutkMC4FUcb8GQLxJQhrs2IZACoWWYJT5i2lMRi84N8GZYnqtuXi/ 5GQmAO+GCAH77andbguKDbha8P1jUGAdx5/Z6BCNar9LMvTDaWQnjRkB+8dom7rZT+oA GjvaV4+Q+0fE/0EyxVjzd1/zuRceH9bxbN7a+ZflzoAER51Lmtc9UjHYC7+5tS9uDrwT akSqVBxgEfwLCANkL+F4UlMXgGI9PnvZMht7BTc1+tdWs5Tr9pU2DCiPM6vY1bAsCVYG qCKYAdMSGQH9tZrJ2QfjikBNQs0czpdfFQU7Rfms7x+qgD5VQdUJBd3+xjVDebuFoqyD UWWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=944R6VkEBj9im8jiA+ivAeCJ/qxWRZNjJgR3j1HHJsI=; b=baNOyzpy9VREDoG72+W/NjFrMK+kT8o+7xVAiwH4CQmXuXdi8LHfiqXpOAX9wcnOyo 6aNXwoZjCHCfzzajFp7C4C8xSHcj/Gztr348I7tlc8bTIOmhjUONaqE0XhEKgS6ljsZP 9DKvGRpACFn+CXy26bxEEBCdQBtOTy6NjP+SageXc/0RdrFv6Hb6gez7m93OXqCvjOrU 54zt+P++qyk1nHXs6A/2JYp+fIrwZjAZXyWP5T3BKpVqFuF7WgP1KnXHiEhcddriJjYh d9HPJkyIjGD2fMtkdA63NYsyPTu8HfggfdOhXu4KausnM/Vb6QAvoJZhvmyaNnIQyVQ6 ZWGg== X-Gm-Message-State: AOAM531M996BdyurklYJTMUhfCMSPedDH8iwQE5PS61aKlLV+sXIikBX G0bqN8DSeSL+VCLMrQq0U9s= X-Google-Smtp-Source: ABdhPJzk26xdBnc/SuVaoCsMCFhCY+mkLSr/cpJ1B4mSZ/wAFinxM5dmhULQy/yAq6xfFjdSrrSG5w== X-Received: by 2002:a5d:4563:: with SMTP id a3mr23974817wrc.130.1637178301973; Wed, 17 Nov 2021 11:45:01 -0800 (PST) Received: from kista.localdomain (cpe-86-58-29-253.static.triera.net. [86.58.29.253]) by smtp.gmail.com with ESMTPSA id g198sm712529wme.23.2021.11.17.11.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 11:45:01 -0800 (PST) From: Jernej Skrabec To: mripard@kernel.org, wens@csie.org Cc: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec Subject: [PATCH v2] ASoC: sunxi: sun4i-spdif: Implement IEC958 control Date: Wed, 17 Nov 2021 20:44:58 +0100 Message-Id: <20211117194458.2249643-1-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211117_114506_068222_6641A083 X-CRM114-Status: GOOD ( 16.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org SPDIF core is capable of sending custom status. Implement IEC958 control handling. Signed-off-by: Jernej Skrabec --- Changes from v1: - return 1 if there was a change in sun4i_spdif_set_status() - added locking for reading and writing status sound/soc/sunxi/sun4i-spdif.c | 115 ++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/sound/soc/sunxi/sun4i-spdif.c b/sound/soc/sunxi/sun4i-spdif.c index a10949bf0ca1..17090f43150e 100644 --- a/sound/soc/sunxi/sun4i-spdif.c +++ b/sound/soc/sunxi/sun4i-spdif.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include #include @@ -186,6 +188,7 @@ struct sun4i_spdif_dev { struct regmap *regmap; struct snd_dmaengine_dai_dma_data dma_params_tx; const struct sun4i_spdif_quirks *quirks; + spinlock_t lock; }; static void sun4i_spdif_configure(struct sun4i_spdif_dev *host) @@ -385,11 +388,122 @@ static int sun4i_spdif_trigger(struct snd_pcm_substream *substream, int cmd, return ret; } +static int sun4i_spdif_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; + uinfo->count = 1; + + return 0; +} + +static int sun4i_spdif_get_status_mask(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + u8 *status = ucontrol->value.iec958.status; + + status[0] = 0xff; + status[1] = 0xff; + status[2] = 0xff; + status[3] = 0xff; + status[4] = 0xff; + status[5] = 0x03; + + return 0; +} + +static int sun4i_spdif_get_status(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol); + struct sun4i_spdif_dev *host = snd_soc_dai_get_drvdata(cpu_dai); + u8 *status = ucontrol->value.iec958.status; + unsigned long flags; + unsigned int reg; + + spin_lock_irqsave(&host->lock, flags); + + regmap_read(host->regmap, SUN4I_SPDIF_TXCHSTA0, ®); + + status[0] = reg & 0xff; + status[1] = (reg >> 8) & 0xff; + status[2] = (reg >> 16) & 0xff; + status[3] = (reg >> 24) & 0xff; + + regmap_read(host->regmap, SUN4I_SPDIF_TXCHSTA1, ®); + + status[4] = reg & 0xff; + status[5] = (reg >> 8) & 0x3; + + spin_unlock_irqrestore(&host->lock, flags); + + return 0; +} + +static int sun4i_spdif_set_status(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol); + struct sun4i_spdif_dev *host = snd_soc_dai_get_drvdata(cpu_dai); + u8 *status = ucontrol->value.iec958.status; + unsigned long flags; + unsigned int reg; + bool chg0, chg1; + + spin_lock_irqsave(&host->lock, flags); + + reg = (u32)status[3] << 24; + reg |= (u32)status[2] << 16; + reg |= (u32)status[1] << 8; + reg |= (u32)status[0]; + + regmap_update_bits_check(host->regmap, SUN4I_SPDIF_TXCHSTA0, + GENMASK(31,0), reg, &chg0); + + reg = (u32)status[5] << 8; + reg |= (u32)status[4]; + + regmap_update_bits_check(host->regmap, SUN4I_SPDIF_TXCHSTA1, + GENMASK(9,0), reg, &chg1); + + reg = SUN4I_SPDIF_TXCFG_CHSTMODE; + if (status[0] & IEC958_AES0_NONAUDIO) + reg |= SUN4I_SPDIF_TXCFG_NONAUDIO; + + regmap_update_bits(host->regmap, SUN4I_SPDIF_TXCFG, + SUN4I_SPDIF_TXCFG_CHSTMODE | + SUN4I_SPDIF_TXCFG_NONAUDIO, reg); + + spin_unlock_irqrestore(&host->lock, flags); + + return chg0 || chg1; +} + +static struct snd_kcontrol_new sun4i_spdif_controls[] = { + { + .access = SNDRV_CTL_ELEM_ACCESS_READ, + .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK), + .info = sun4i_spdif_info, + .get = sun4i_spdif_get_status_mask + }, + { + .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), + .info = sun4i_spdif_info, + .get = sun4i_spdif_get_status, + .put = sun4i_spdif_set_status + } +}; + static int sun4i_spdif_soc_dai_probe(struct snd_soc_dai *dai) { struct sun4i_spdif_dev *host = snd_soc_dai_get_drvdata(dai); snd_soc_dai_init_dma_data(dai, &host->dma_params_tx, NULL); + snd_soc_add_dai_controls(dai, sun4i_spdif_controls, + ARRAY_SIZE(sun4i_spdif_controls)); + return 0; } @@ -512,6 +626,7 @@ static int sun4i_spdif_probe(struct platform_device *pdev) return -ENOMEM; host->pdev = pdev; + spin_lock_init(&host->lock); /* Initialize this copy of the CPU DAI driver structure */ memcpy(&host->cpu_dai_drv, &sun4i_spdif_dai, sizeof(sun4i_spdif_dai));