From patchwork Wed Aug 10 13:29:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venkata Prasad Potturu X-Patchwork-Id: 596436 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC4E7C3F6B0 for ; Wed, 10 Aug 2022 13:27:52 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 73C651651; Wed, 10 Aug 2022 15:27:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 73C651651 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1660138070; bh=p13nKtS9ne7Ak1sv4vxTSTk7l5rhzLjsVvZ2BlLR07c=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=UPh8slGf0FwQXZ5O7CGHMubRJAeseKyr6ODO9IAyUPBk67tnc4zSXbzYUa+Xe9dBN cDFJ+aLscqgPFJBLsHWjXu846+PcHErNic0JxkgoPv+Z5XC2aOmX6RgBOLOEBQNDdV UAsuTQ1f/pvDUMwNgs71g4GDK+cE1iV20pCR2wIg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id BD393F802E3; Wed, 10 Aug 2022 15:26:33 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C0114F802E3; Wed, 10 Aug 2022 15:26:32 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2041.outbound.protection.outlook.com [40.107.93.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 3D5B4F80154 for ; Wed, 10 Aug 2022 15:26:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3D5B4F80154 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="UmWshlz7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GgBvRe6IuRahQxsmnysKdyU/QtjkZnbwjqKIuvcCi+/5awJYcYqC3JzxIdd1IrXykWGk6JDTKnUoHJMs4pCy1E1MNPJLeVLq/Pjm1OCiGIucN0r70pkH6lfBwia3A5Nv+XNSoYL7B8BdU6prIQLbRMDIjHBCbCegwjln9x03wijkz520Ru2Y7ccur4vd+oF8QNtfxY3jCEtxT3HwghAjoYrkRVg1rzV6MQKcFt5X5EsgBRtSkyvyoA/j7G+SQF9cS1K0dnif3NrOVR22umglwMll+tb/D1WYOn3RWCkdAHQsaU0+Tfbn/hE0QYQvS6NX61/+s3b1DDxtd42Xwsavvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2FteUpw9UPC6QnEzgQZquD1FS608rwf9T42I5hnTZs0=; b=dz6UA5rs/LIXoq9RiCKQxzhgGBMNui3fRKIiRLt8iqUcc+gi0LK/LEP069VAGFKk2o8AjGrI9kZP7eESgBBFbLhnq9uqnvD7hR2cgZmci0DxUr/XX8k3H/SDlheP6URdQitRDjzLwULdfXIuthQeILfNjQkqzg+8UYLHtf+KTU3J2A3DaD53mMpaD2egGPzXIiwMJrv+9FKNVM2ecWieaj1oZ7PhiGH8L8rMzpKja2NRn7dG2ALWRcCRvt0VptwtYY7hp2R44tasJJ8QL0du/X3TyH3+I/APV7RXPIxCJpbuvbs3VS2tgI7xmaAnuzZ/iD/0L5x2cLhNK/nGx/v3Lw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2FteUpw9UPC6QnEzgQZquD1FS608rwf9T42I5hnTZs0=; b=UmWshlz7Qg89T2espCj+REgBhEe1IY5dkTrLOA5anaJKFIiyvblBNjqA1gHp7ZnXIgv+i21LgJBODcR7+6Ape6xDgVQDKC3LeYHurvq7b1F1jUx+KAZSW0/FfHOuJQ7mIf1Ddj8wA4Oq78d32yMlhTArg8/SVvdp7XyE5vaBoyc= Received: from BN0PR04CA0208.namprd04.prod.outlook.com (2603:10b6:408:e9::33) by SN7PR12MB6887.namprd12.prod.outlook.com (2603:10b6:806:261::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16; Wed, 10 Aug 2022 13:26:21 +0000 Received: from BN8NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e9:cafe::65) by BN0PR04CA0208.outlook.office365.com (2603:10b6:408:e9::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16 via Frontend Transport; Wed, 10 Aug 2022 13:26:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT057.mail.protection.outlook.com (10.13.177.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Wed, 10 Aug 2022 13:26:21 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 10 Aug 2022 08:26:20 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 10 Aug 2022 08:26:20 -0500 Received: from amd-System-Product-Name.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.28 via Frontend Transport; Wed, 10 Aug 2022 08:26:10 -0500 From: Venkata Prasad Potturu To: , Subject: [RESEND v4 1/2] ASoC: amd: acp: Initialize list to store acp_stream during pcm_open Date: Wed, 10 Aug 2022 18:59:12 +0530 Message-ID: <20220810132913.1181247-2-venkataprasad.potturu@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810132913.1181247-1-venkataprasad.potturu@amd.com> References: <20220810132913.1181247-1-venkataprasad.potturu@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 43973845-9ebc-4151-f21d-08da7ad3ea4b X-MS-TrafficTypeDiagnostic: SN7PR12MB6887:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PP3YdD5acFM5zdA/frzvMR4H8C0iJ0IOMXAeKbhWmg0TaIVbAppInfuc0tTPPwhftg/2olT5xM4nWUizpxfPadk9ob1eMIIP8LPs2O5wiZYB90PeJc/2UhTRmseiSevO8CvKOYe++Rg+wG50EK1kKx7Ei7IVJbIpOAygqy1H6Lme79BQBK8Y7MyA0VD+riZg3XXgNq/+glpi3DlTjJgIUaxzLLWB1k0cu/PthZFAgs9HMlynkhMtJOvXuVRTBd479UJSKBVTTNw8J+d2vx8XhhK1g1f5apE4CT8MvuMueuk8V+dMZy47gjd/1844z4JDsv24kPcphRcqkKNAyJFiPztUe4sHP4IrTR8imftCCmgtFzoST8oZPesD+LLQNS6Rw4n+0h+plueazHEIWGOYG7P3iIPwbFmgEg1/offajn5ys1EiR/y226Dh53ZL/8JwSuym8+XAiCz+OuMjKOTlJmx4cewvj2rHpg1syAwgNTXlRC07IMyTSsFKEfRyM9/pR1IKe21d0XvTA22kvdaAIg+x2oUlUC8FjahyTkA+5yebGUtYdp2DLm+IMMTc5+HGK9ihajlY9+fzFdg0RZMq7qAhIbcuaRViSQeBCLbuWUz39r+xkesi/WMPWRGiNefFcgc9w/HOXx7TBYgGD335oHYt11Ezaxbjxf+qNxitxg24Nnwl95DAKxi9OFnYfCmbM3lh8HfVakvyzsWcxEzv1n/re551mo47baAzKzFRxP7/yKpXYTNERva7VQxpmby/gMQ+oOB72JCa9SHB52G3VYDyebG+JiWkfw4clnqsO6rJQMZsOLPxE/qDfOwQ20aEQ/q85dhe1zWyoQBeUG9meA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(396003)(346002)(376002)(136003)(36840700001)(40470700004)(46966006)(70586007)(5660300002)(70206006)(40480700001)(40460700003)(82310400005)(4326008)(8676002)(2906002)(316002)(36860700001)(2616005)(41300700001)(8936002)(47076005)(86362001)(36756003)(336012)(81166007)(478600001)(82740400003)(26005)(110136005)(186003)(426003)(356005)(54906003)(83380400001)(1076003)(7696005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2022 13:26:21.3255 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 43973845-9ebc-4151-f21d-08da7ad3ea4b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6887 Cc: Sunil-kumar.Dommati@amd.com, Charles Keepax , ssabakar@amd.com, Ajit Kumar Pandey , Venkata Prasad Potturu , open list , Basavaraj.Hiregoudar@amd.com, Takashi Iwai , Liam Girdwood , Nathan Chancellor , Yang Yingliang , Vijendar.Mukunda@amd.com, V sujith kumar Reddy X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" From: Ajit Kumar Pandey We are currently allocating acp_stream during pcm_open and saving it in static array corresponds to array index calculated based on cpu dai->driver id. This approach will fail if we have single dai linked to multiple pcm device as we will have same dai->driver id or array index for multiple pcm open. Initialize new linked list stream_list to store opened pcm stream info dynamically. Signed-off-by: Ajit Kumar Pandey Signed-off-by: Venkata Prasad Potturu Reviewed-by: Vijendar Mukunda --- sound/soc/amd/acp/acp-platform.c | 40 +++++++++++++++----------------- sound/soc/amd/acp/amd.h | 4 +++- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/sound/soc/amd/acp/acp-platform.c b/sound/soc/amd/acp/acp-platform.c index f561d39b33e2..beee53aedeaf 100644 --- a/sound/soc/amd/acp/acp-platform.c +++ b/sound/soc/amd/acp/acp-platform.c @@ -94,7 +94,7 @@ static irqreturn_t i2s_irq_handler(int irq, void *data) struct acp_resource *rsrc = adata->rsrc; struct acp_stream *stream; u16 i2s_flag = 0; - u32 ext_intr_stat, ext_intr_stat1, i; + u32 ext_intr_stat, ext_intr_stat1; if (!adata) return IRQ_NONE; @@ -104,14 +104,13 @@ static irqreturn_t i2s_irq_handler(int irq, void *data) ext_intr_stat = readl(ACP_EXTERNAL_INTR_STAT(adata, rsrc->irqp_used)); - for (i = 0; i < ACP_MAX_STREAM; i++) { - stream = adata->stream[i]; + spin_lock(&adata->acp_lock); + list_for_each_entry(stream, &adata->stream_list, list) { if (stream && (ext_intr_stat & stream->irq_bit)) { writel(stream->irq_bit, ACP_EXTERNAL_INTR_STAT(adata, rsrc->irqp_used)); snd_pcm_period_elapsed(stream->substream); i2s_flag = 1; - break; } if (adata->rsrc->no_of_ctrls == 2) { if (stream && (ext_intr_stat1 & stream->irq_bit)) { @@ -119,10 +118,10 @@ static irqreturn_t i2s_irq_handler(int irq, void *data) (rsrc->irqp_used - 1))); snd_pcm_period_elapsed(stream->substream); i2s_flag = 1; - break; } } } + spin_unlock(&adata->acp_lock); if (i2s_flag) return IRQ_HANDLED; @@ -146,9 +145,8 @@ static void config_pte_for_stream(struct acp_dev_data *adata, struct acp_stream writel(0x01, adata->acp_base + ACPAXI2AXI_ATU_CTRL); } -static void config_acp_dma(struct acp_dev_data *adata, int cpu_id, int size) +static void config_acp_dma(struct acp_dev_data *adata, struct acp_stream *stream, int size) { - struct acp_stream *stream = adata->stream[cpu_id]; struct snd_pcm_substream *substream = stream->substream; struct acp_resource *rsrc = adata->rsrc; dma_addr_t addr = substream->dma_buffer.addr; @@ -174,13 +172,10 @@ static void config_acp_dma(struct acp_dev_data *adata, int cpu_id, int size) static int acp_dma_open(struct snd_soc_component *component, struct snd_pcm_substream *substream) { - struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream); - struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0); struct snd_pcm_runtime *runtime = substream->runtime; struct device *dev = component->dev; struct acp_dev_data *adata = dev_get_drvdata(dev); struct acp_stream *stream; - int stream_id = cpu_dai->driver->id * 2 + substream->stream; int ret; stream = kzalloc(sizeof(*stream), GFP_KERNEL); @@ -188,7 +183,10 @@ static int acp_dma_open(struct snd_soc_component *component, struct snd_pcm_subs return -ENOMEM; stream->substream = substream; - adata->stream[stream_id] = stream; + + spin_lock_irq(&adata->acp_lock); + list_add_tail(&stream->list, &adata->stream_list); + spin_unlock_irq(&adata->acp_lock); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) runtime->hw = acp_pcm_hardware_playback; @@ -212,16 +210,13 @@ static int acp_dma_hw_params(struct snd_soc_component *component, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { - struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream); struct acp_dev_data *adata = snd_soc_component_get_drvdata(component); - struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0); struct acp_stream *stream = substream->runtime->private_data; - int stream_id = cpu_dai->driver->id * 2 + substream->stream; u64 size = params_buffer_bytes(params); /* Configure ACP DMA block with params */ config_pte_for_stream(adata, stream); - config_acp_dma(adata, stream_id, size); + config_acp_dma(adata, stream, size); return 0; } @@ -261,16 +256,15 @@ static int acp_dma_new(struct snd_soc_component *component, static int acp_dma_close(struct snd_soc_component *component, struct snd_pcm_substream *substream) { - struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream); - struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0); struct device *dev = component->dev; struct acp_dev_data *adata = dev_get_drvdata(dev); - struct acp_stream *stream; - int stream_id = cpu_dai->driver->id * 2 + substream->stream; + struct acp_stream *stream = substream->runtime->private_data; - stream = adata->stream[stream_id]; + /* Remove entry from list */ + spin_lock_irq(&adata->acp_lock); + list_del(&stream->list); + spin_unlock_irq(&adata->acp_lock); kfree(stream); - adata->stream[stream_id] = NULL; return 0; } @@ -305,6 +299,10 @@ int acp_platform_register(struct device *dev) dev_err(dev, "Fail to register acp i2s component\n"); return status; } + + INIT_LIST_HEAD(&adata->stream_list); + spin_lock_init(&adata->acp_lock); + return 0; } EXPORT_SYMBOL_NS_GPL(acp_platform_register, SND_SOC_ACP_COMMON); diff --git a/sound/soc/amd/acp/amd.h b/sound/soc/amd/acp/amd.h index 60a7c95f134f..be8bb8247c4e 100644 --- a/sound/soc/amd/acp/amd.h +++ b/sound/soc/amd/acp/amd.h @@ -91,6 +91,7 @@ struct acp_chip_info { }; struct acp_stream { + struct list_head list; struct snd_pcm_substream *substream; int irq_bit; int dai_id; @@ -123,7 +124,8 @@ struct acp_dev_data { struct snd_soc_dai_driver *dai_driver; int num_dai; - struct acp_stream *stream[ACP_MAX_STREAM]; + struct list_head stream_list; + spinlock_t acp_lock; struct snd_soc_acpi_mach *machines; struct platform_device *mach_dev; From patchwork Wed Aug 10 13:29:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venkata Prasad Potturu X-Patchwork-Id: 597045 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54CCFC00140 for ; Wed, 10 Aug 2022 13:28:14 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 459341660; Wed, 10 Aug 2022 15:27:22 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 459341660 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1660138092; bh=6aDDWu+QZsKCxzeQO4TQp5vlDRzkOtbDM/+A50T8QsM=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=O9NtWU4Er9dmlmWiL0LMjgqAzMxJAAvgbdO/+1SndOJtVQf1dQTln43QPQgPXhAQd zYOB5nmO0j2iqnuvcZh3wa8aqu8dMpyl/oPp0ppHmOA4oqjDU4AWQPf27mB0XTE6An 3T5n1iCwz5I0C34tjnIUww48IKKo93nzhL7N6zJw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 60D29F80539; Wed, 10 Aug 2022 15:26:52 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 84288F80544; Wed, 10 Aug 2022 15:26:50 +0200 (CEST) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2061.outbound.protection.outlook.com [40.107.102.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 5D1A3F8051F for ; Wed, 10 Aug 2022 15:26:41 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5D1A3F8051F Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="AiImLccY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Owtuv0jagRjKpJMpft2T8/hpE2web3jqIv1hAVH9Z9eByIwhsIj/5Chm9t+YZaGxl7D81aJK78GU5VV7dOZT6e1bEMWNIEV0UDrHjJijzyBXnVXZeEvQoURtGnM5rN06GMnWMZPYJmV1kobh1LFrTnn6FtjLVjOKJs0t+aAT4SGiWEGTNteAaXGVDkbON9PtBNnf77sOK4t9R5zgcaZSmp96/Jc2/jN9f3l09nqH+6FXCwkSdr5DE6J4L/AVYoBJeqyupoi9l6a2m+oZRIMaSNqRH1/dT+UvTXoY2k5cljkGN3M1F3Y4Oybl7nAk4jfVLazpSpBrYMXC2qqoNGOZ1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9oB12A43Fbn31nx7F/9xlv1XkstVMJWnHbxcSeYEjEI=; b=DCVDifKQSjSS1W5BFXmKhAxSblTf6pb5ALfVAKwBb3joku/n4BSbc8550rnyHSKQuO/xfDq+M18tVF49y+mwoKSgYzz4qJgtpvZLFzhA9BuU1tyfdjy39K3lgX1mHvmIzOdy9m7wHTY3baXNZSCplASJ2E+mLi5/CMaKod8WAJSAMCo8LnBkW1/RiF8ejaGRhiVIBjVYKchKE8AZt4Pu3n7z354+cDHF/FSatRs7M7NOwcEKyStuSqPuf2zI1jiMjURhsfy4I+vyr9Vc0LuxogWA1IRVPKcmBcxSNGnwbUUgVPwn88UElBMNyGd2Un14aT30ubhC6SlTkQO7lSLCBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9oB12A43Fbn31nx7F/9xlv1XkstVMJWnHbxcSeYEjEI=; b=AiImLccYJSxFojoHb15beJwi+RcOXvs14RFlHIbd+SsjF/AHX3MduG0vpmJLE0Y3Y4ihekqZOcQX4x4a/cWfJ2nS5KhfjRTB2GCLxlqyqFx9lMew/KKgGkIIHb0dgwxrLLJ6txkRyXZtB2DIKCtW8gtqnzdj/5mAdsdUwMul5/w= Received: from MW4P220CA0030.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::35) by LV2PR12MB5966.namprd12.prod.outlook.com (2603:10b6:408:171::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.20; Wed, 10 Aug 2022 13:26:36 +0000 Received: from CO1NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::50) by MW4P220CA0030.outlook.office365.com (2603:10b6:303:115::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14 via Frontend Transport; Wed, 10 Aug 2022 13:26:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT013.mail.protection.outlook.com (10.13.174.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5525.11 via Frontend Transport; Wed, 10 Aug 2022 13:26:35 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 10 Aug 2022 08:26:34 -0500 Received: from amd-System-Product-Name.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.28 via Frontend Transport; Wed, 10 Aug 2022 08:26:25 -0500 From: Venkata Prasad Potturu To: , Subject: [RESEND v4 2/2] ASoC: amd: acp: Add TDM support for acp i2s stream Date: Wed, 10 Aug 2022 18:59:13 +0530 Message-ID: <20220810132913.1181247-3-venkataprasad.potturu@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810132913.1181247-1-venkataprasad.potturu@amd.com> References: <20220810132913.1181247-1-venkataprasad.potturu@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f4eda401-c8fb-484f-f808-08da7ad3f31a X-MS-TrafficTypeDiagnostic: LV2PR12MB5966:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4dfxqQDAVVmnDlIfNzbGG/Vg3IJONgh/qOZ76r5ATXp9F4L8h2edtvWYaW0/8rdN8QI4hOOI2qATq49IUYYqNsYZuz1AqvM1oj2+5Uy9/1+Uy/MMYPjaTMuvfJw9/r+7IrhERwIVcYCr5U6QDgvt00n26Ow7vIDO5+AkC9WJHM6Fh/Ciws3TS5SE7SRqmlCPMuApWa9LZzvGms3BbJ/Sf03ZaKrUFUjtJkbO6L+Zw7GfgxL5dw7rKtjLP7cNLV5ML+Hcw8gI9/R+6g9hbR9FDa3f+C32vaZd/ioBG71qFxSZFtGbix2uDE1p5Dm1+pC7TWtE3W+elEWA/86ipHJ9uA9agaUCkDCArAArMHt4njoCcm1khJigQfnnTM89qyM11prf3+ryRvDmlOwN1bQkWl0OnYOsQ5bMrw4P3nlqKZWvW8MLdBPl4ys5iqccEGvPfHgc5yAVXjNcDAxkyaZmLm26avUqeA64gApcC43bCAw1pX06EGHDCq7MiUR2q1h5L/4wemJMxVDjLNwgCSxiaqyI0tD7Txw483Bh1z2/KyX2b2I9f4zOy5kj+4/rViH9uwAMu087vqIxDOCDJLoohY/yONXbBWeL8mSr6XmYiWCFmR02diiPxFqghQKGYMVTldVsoH6AGvs5+nrqae3MzvcrW+c0aWGox38mr8OxKEjiyOdusazyqLHcVC6+7p+P2/xw1payPgc3OKCGiopmDZ55q+cuPsGyL2Zu5QdpbSoVuSctZ8trdf8Zi2hvGHLzhViKZvISl8/fgxPRMRsTPkGDka44vI+UnnFsUDVLXe2hh2mKuy+qEFhBKvDXVQn6vdkYZMXFCQWA+m+8m2pE5Q== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB03.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(376002)(136003)(346002)(396003)(36840700001)(40470700004)(46966006)(336012)(26005)(41300700001)(7696005)(426003)(6666004)(47076005)(2616005)(2906002)(86362001)(40460700003)(82740400003)(356005)(40480700001)(83380400001)(81166007)(1076003)(36860700001)(82310400005)(8936002)(186003)(70586007)(70206006)(4326008)(5660300002)(54906003)(36756003)(478600001)(110136005)(8676002)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2022 13:26:35.9634 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f4eda401-c8fb-484f-f808-08da7ad3f31a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5966 Cc: Sunil-kumar.Dommati@amd.com, ssabakar@amd.com, Ajit Kumar Pandey , Venkata Prasad Potturu , open list , Basavaraj.Hiregoudar@amd.com, Takashi Iwai , Liam Girdwood , Vijendar.Mukunda@amd.com, V sujith kumar Reddy X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" Add callback and code changes to enable ACP I2S controller in TDM mode. Add new fields in acp_stream and acp_dev_data struct to configure tdm related registers for ACP i2s controllers. Signed-off-by: Venkata Prasad Potturu --- sound/soc/amd/acp/acp-i2s.c | 80 ++++++++++++++++++++++++++++++++++++- sound/soc/amd/acp/amd.h | 12 ++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/sound/soc/amd/acp/acp-i2s.c b/sound/soc/amd/acp/acp-i2s.c index 393f729ef561..ac416572db0d 100644 --- a/sound/soc/amd/acp/acp-i2s.c +++ b/sound/soc/amd/acp/acp-i2s.c @@ -25,6 +25,65 @@ #define DRV_NAME "acp_i2s_playcap" +static int acp_i2s_set_fmt(struct snd_soc_dai *cpu_dai, + unsigned int fmt) +{ + struct acp_dev_data *adata = snd_soc_dai_get_drvdata(cpu_dai); + int mode; + + mode = fmt & SND_SOC_DAIFMT_FORMAT_MASK; + switch (mode) { + case SND_SOC_DAIFMT_I2S: + adata->tdm_mode = TDM_DISABLE; + break; + case SND_SOC_DAIFMT_DSP_A: + adata->tdm_mode = TDM_ENABLE; + break; + default: + return -EINVAL; + } + return 0; +} + +static int acp_i2s_set_tdm_slot(struct snd_soc_dai *dai, u32 tx_mask, u32 rx_mask, + int slots, int slot_width) +{ + struct device *dev = dai->component->dev; + struct acp_dev_data *adata = snd_soc_dai_get_drvdata(dai); + struct acp_stream *stream; + int slot_len; + + switch (slot_width) { + case SLOT_WIDTH_8: + slot_len = 8; + break; + case SLOT_WIDTH_16: + slot_len = 16; + break; + case SLOT_WIDTH_24: + slot_len = 24; + break; + case SLOT_WIDTH_32: + slot_len = 0; + break; + default: + dev_err(dev, "Unsupported bitdepth %d\n", slot_width); + return -EINVAL; + } + + spin_lock_irq(&adata->acp_lock); + list_for_each_entry(stream, &adata->stream_list, list) { + if (tx_mask && stream->dir == SNDRV_PCM_STREAM_PLAYBACK) + adata->tdm_tx_fmt[stream->dai_id - 1] = + FRM_LEN | (slots << 15) | (slot_len << 18); + else if (rx_mask && stream->dir == SNDRV_PCM_STREAM_CAPTURE) + adata->tdm_rx_fmt[stream->dai_id - 1] = + FRM_LEN | (slots << 15) | (slot_len << 18); + } + spin_unlock_irq(&adata->acp_lock); + return 0; +} + static int acp_i2s_hwparams(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { @@ -33,7 +92,7 @@ static int acp_i2s_hwparams(struct snd_pcm_substream *substream, struct snd_pcm_ struct acp_resource *rsrc; u32 val; u32 xfer_resolution; - u32 reg_val; + u32 reg_val, fmt_reg, tdm_fmt; u32 lrclk_div_val, bclk_div_val; adata = snd_soc_dai_get_drvdata(dai); @@ -62,12 +121,15 @@ static int acp_i2s_hwparams(struct snd_pcm_substream *substream, struct snd_pcm_ switch (dai->driver->id) { case I2S_BT_INSTANCE: reg_val = ACP_BTTDM_ITER; + fmt_reg = ACP_BTTDM_TXFRMT; break; case I2S_SP_INSTANCE: reg_val = ACP_I2STDM_ITER; + fmt_reg = ACP_I2STDM_TXFRMT; break; case I2S_HS_INSTANCE: reg_val = ACP_HSTDM_ITER; + fmt_reg = ACP_HSTDM_TXFRMT; break; default: dev_err(dev, "Invalid dai id %x\n", dai->driver->id); @@ -77,12 +139,15 @@ static int acp_i2s_hwparams(struct snd_pcm_substream *substream, struct snd_pcm_ switch (dai->driver->id) { case I2S_BT_INSTANCE: reg_val = ACP_BTTDM_IRER; + fmt_reg = ACP_BTTDM_RXFRMT; break; case I2S_SP_INSTANCE: reg_val = ACP_I2STDM_IRER; + fmt_reg = ACP_I2STDM_RXFRMT; break; case I2S_HS_INSTANCE: reg_val = ACP_HSTDM_IRER; + fmt_reg = ACP_HSTDM_RXFRMT; break; default: dev_err(dev, "Invalid dai id %x\n", dai->driver->id); @@ -95,6 +160,16 @@ static int acp_i2s_hwparams(struct snd_pcm_substream *substream, struct snd_pcm_ val = val | (xfer_resolution << 3); writel(val, adata->acp_base + reg_val); + if (adata->tdm_mode) { + val = readl(adata->acp_base + reg_val); + writel(val | BIT(1), adata->acp_base + reg_val); + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + tdm_fmt = adata->tdm_tx_fmt[dai->driver->id - 1]; + else + tdm_fmt = adata->tdm_rx_fmt[dai->driver->id - 1]; + writel(tdm_fmt, adata->acp_base + fmt_reg); + } + if (rsrc->soc_mclk) { switch (params_format(params)) { case SNDRV_PCM_FORMAT_S16_LE: @@ -443,6 +518,7 @@ static int acp_i2s_startup(struct snd_pcm_substream *substream, struct snd_soc_d stream->id = dai->driver->id + dir; stream->dai_id = dai->driver->id; stream->irq_bit = irq_bit; + stream->dir = substream->stream; return 0; } @@ -452,6 +528,8 @@ const struct snd_soc_dai_ops asoc_acp_cpu_dai_ops = { .hw_params = acp_i2s_hwparams, .prepare = acp_i2s_prepare, .trigger = acp_i2s_trigger, + .set_fmt = acp_i2s_set_fmt, + .set_tdm_slot = acp_i2s_set_tdm_slot, }; EXPORT_SYMBOL_NS_GPL(asoc_acp_cpu_dai_ops, SND_SOC_ACP_COMMON); diff --git a/sound/soc/amd/acp/amd.h b/sound/soc/amd/acp/amd.h index be8bb8247c4e..5f2119f42271 100644 --- a/sound/soc/amd/acp/amd.h +++ b/sound/soc/amd/acp/amd.h @@ -84,6 +84,14 @@ #define ACP_MAX_STREAM 8 +#define TDM_ENABLE 1 +#define TDM_DISABLE 0 + +#define SLOT_WIDTH_8 0x8 +#define SLOT_WIDTH_16 0x10 +#define SLOT_WIDTH_24 0x18 +#define SLOT_WIDTH_32 0x20 + struct acp_chip_info { char *name; /* Platform name */ unsigned int acp_rev; /* ACP Revision id */ @@ -96,6 +104,7 @@ struct acp_stream { int irq_bit; int dai_id; int id; + int dir; u64 bytescount; u32 reg_offset; u32 pte_offset; @@ -120,6 +129,7 @@ struct acp_dev_data { void __iomem *acp_base; unsigned int i2s_irq; + bool tdm_mode; /* SOC specific dais */ struct snd_soc_dai_driver *dai_driver; int num_dai; @@ -134,6 +144,8 @@ struct acp_dev_data { u32 lrclk_div; struct acp_resource *rsrc; + u32 tdm_tx_fmt[3]; + u32 tdm_rx_fmt[3]; }; union acp_i2stdm_mstrclkgen {