Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3239656pxb; Tue, 20 Apr 2021 04:00:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy45jGSRxFbaY9Enb++oytU3AR17ce+ygpvY4MK+3mzmkSn5qu6LznnmtfZUWIsvF9O02oM X-Received: by 2002:a17:90b:33c6:: with SMTP id lk6mr4402230pjb.37.1618916417724; Tue, 20 Apr 2021 04:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618916417; cv=none; d=google.com; s=arc-20160816; b=WbCm5ttoPbHbiuZUdLFzLl0VeyoNCO8GLcV7jObfMGqk9z/tiC2tM+39gNKKnVJg3Z 3E+u85CnwAPBcZVdR5/W6BCslt5FIpfti2BCp135LOpd6fgliIfNXbauPk/FVidatUdr ZSfOEH2mrkut1iU/gcrkG8Ah/WdgiF0uogX31tj4jyioamSiZw/Y4WNDEBTC6XMw6D+i haJoB6knoTHlZYCxtRwtUEa/w6Z9L858uKA2rh6Px+iRu94sJc+od4qhc+SDGdN/UQvA L8osK/TLBNZz0H71/0rYg6BcXs6NWdgODtIrtqwAWclwZG3dUmQC5OOFdSnwo9Pd7/a9 juzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from; bh=akdea91SQ+90Z799xvh04uby/t8kcJ3Xf9im+h7rMXY=; b=Bkr88SkBQjfzsp9XIHg5oWJ4yuHawQiHnf8x6s3rxYtBlaBWlU8IRCCrhAOgTCsJTA Fx5bfJSMXGZXipxcAB7J1BfDchC0SD2fDSlt0crE0/YI9V7cjKlTdx9dNGERJiwaeBbH +X01KX0oNy8YDAUCpkpOYRoBl0B10PqGHA+mhHAv9Dfz6/RKL91vIgnS1BrPPvTlDbij NPbTFXN4ssrA2TlXRZuEPV4VAzHo925y+Cy3aRO048Sm/AlZOI8Vc3pcfQBcqNouzyYW KVY5ps7vyKt3L4CJIWmaaIzcaffU4r+Z7X5Su608VUuoe3VaRxsXZBJdcGfLIgcn1dHm mvAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p27si19146705pgb.92.2021.04.20.04.00.04; Tue, 20 Apr 2021 04:00:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231466AbhDTK7y (ORCPT + 99 others); Tue, 20 Apr 2021 06:59:54 -0400 Received: from inva020.nxp.com ([92.121.34.13]:34776 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231415AbhDTK7x (ORCPT ); Tue, 20 Apr 2021 06:59:53 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 774151A157E; Tue, 20 Apr 2021 12:59:21 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id CC2091A2FF4; Tue, 20 Apr 2021 12:59:18 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 3AC0B40291; Tue, 20 Apr 2021 12:59:15 +0200 (CEST) From: Shengjiu Wang To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: ak4458: enable daisy chain Date: Tue, 20 Apr 2021 18:44:13 +0800 Message-Id: <1618915453-29445-1-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Viorel Suman Enable Daisy Chain if in TDM mode and the number of played channels is bigger than the maximum supported number of channels. Signed-off-by: Viorel Suman Signed-off-by: Shengjiu Wang --- sound/soc/codecs/ak4458.c | 47 ++++++++++++++++++++++++++------------- sound/soc/codecs/ak4458.h | 1 + 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/sound/soc/codecs/ak4458.c b/sound/soc/codecs/ak4458.c index 3088128816bb..29eb78702bf3 100644 --- a/sound/soc/codecs/ak4458.c +++ b/sound/soc/codecs/ak4458.c @@ -306,6 +306,20 @@ static const struct snd_soc_dapm_route ak4497_intercon[] = { }; +static int ak4458_get_tdm_mode(struct ak4458_priv *ak4458) +{ + switch (ak4458->slots * ak4458->slot_width) { + case 128: + return 1; + case 256: + return 2; + case 512: + return 3; + default: + return 0; + } +} + static int ak4458_rstn_control(struct snd_soc_component *component, int bit) { int ret; @@ -333,13 +347,16 @@ static int ak4458_hw_params(struct snd_pcm_substream *substream, struct snd_soc_component *component = dai->component; struct ak4458_priv *ak4458 = snd_soc_component_get_drvdata(component); int pcm_width = max(params_physical_width(params), ak4458->slot_width); - u8 format, dsdsel0, dsdsel1; - int nfs1, dsd_bclk, ret; + u8 format, dsdsel0, dsdsel1, dchn; + int nfs1, dsd_bclk, ret, channels, channels_max; nfs1 = params_rate(params); ak4458->fs = nfs1; /* calculate bit clock */ + channels = params_channels(params); + channels_max = dai->driver->playback.channels_max; + switch (params_format(params)) { case SNDRV_PCM_FORMAT_DSD_U8: case SNDRV_PCM_FORMAT_DSD_U16_LE: @@ -419,6 +436,17 @@ static int ak4458_hw_params(struct snd_pcm_substream *substream, snd_soc_component_update_bits(component, AK4458_00_CONTROL1, AK4458_DIF_MASK, format); + /* + * Enable/disable Daisy Chain if in TDM mode and the number of played + * channels is bigger than the maximum supported number of channels + */ + dchn = ak4458_get_tdm_mode(ak4458) && + (ak4458->fmt == SND_SOC_DAIFMT_DSP_B) && + (channels > channels_max) ? AK4458_DCHAIN_MASK : 0; + + snd_soc_component_update_bits(component, AK4458_0B_CONTROL7, + AK4458_DCHAIN_MASK, dchn); + ret = ak4458_rstn_control(component, 0); if (ret) return ret; @@ -519,20 +547,7 @@ static int ak4458_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, ak4458->slots = slots; ak4458->slot_width = slot_width; - switch (slots * slot_width) { - case 128: - mode = AK4458_MODE_TDM128; - break; - case 256: - mode = AK4458_MODE_TDM256; - break; - case 512: - mode = AK4458_MODE_TDM512; - break; - default: - mode = AK4458_MODE_NORMAL; - break; - } + mode = ak4458_get_tdm_mode(ak4458) << AK4458_MODE_SHIFT; snd_soc_component_update_bits(component, AK4458_0A_CONTROL6, AK4458_MODE_MASK, diff --git a/sound/soc/codecs/ak4458.h b/sound/soc/codecs/ak4458.h index 9548c5d78621..9ad869575f8d 100644 --- a/sound/soc/codecs/ak4458.h +++ b/sound/soc/codecs/ak4458.h @@ -82,6 +82,7 @@ * */ #define AK4458_ATS_SHIFT 6 #define AK4458_ATS_MASK GENMASK(7, 6) +#define AK4458_DCHAIN_MASK (0x1 << 1) #define AK4458_DSDSEL_MASK (0x1 << 0) #define AK4458_DP_MASK (0x1 << 7) -- 2.27.0