Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5295431ybv; Tue, 11 Feb 2020 12:57:25 -0800 (PST) X-Google-Smtp-Source: APXvYqzS7N3z/m7vvXu0zqPBgG93zkhJIDcuFJ+1UuzW1sQtND0n0ccumOGXp5695G/u2KoH+fu7 X-Received: by 2002:a9d:6183:: with SMTP id g3mr6752659otk.304.1581454644874; Tue, 11 Feb 2020 12:57:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581454644; cv=none; d=google.com; s=arc-20160816; b=bVNP/m813hWuK/p0w0O1Bx7srjwGBe/9rlGWkxjPB3IBZYY9KlWO99hoprL6Qh5AM3 NlvDhRWthFZgWu0mZfSBV2r9uIrIHQeg70fyn4SuekJViSy9TZkAR/rrMMjkmPkPUK5G ln/faQ0OJeUlGxrQL9QvUbjFQnpJd95MBFVjYY71R97bzm9zA7WOIGzzrgjdTYRT1+cX Lg3vQMNVxIpc5R6MRW+ohnCI2P4XN/W4u/nisUHR8+XrvFmKYpUpHDfcP7kzJ1VbMv0S Ns55k6tZtSSi/+bdkj49ztmV2234QU38SCWcxxLvfmueg3HWO7LS99fPeqPL0xB5lPI/ lqlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=uWpI2CiFyuw53wyX0cddSUYAQI3ioQdEAD1Q64ipafk=; b=VJ33GHKqQDBCIYsDcaCb6oWI9eWNA1HTziqtgXi6HD8HbyGO6cMPKAq9lymxqir98J gZrMldeiNaOXPLgAhV9pc/vXSM/wIuYzdp4ANYitws57W1sJvcs5Z97tdqQrnRARFizc zB+r928x3VrV+eupVJAP01cw5PIo2SP2YON+Q/YuJqkb1ltDzfYpfX5bDJ8bpTmLuRtN BOaTf3zOWpyeULCT0DQaxU/QgG8wyip2HeqfUI/mpc//3ZtcoQPy+SgBRE4QQnJgzYl0 TGKdD0oIqDCBzbSAhmNg8klmKoJ9EdPrdcHHWCHhZRiI0iEsgvOrFv23LAkxDArbfodB c4pQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v17si2738275otp.244.2020.02.11.12.57.09; Tue, 11 Feb 2020 12:57:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729114AbgBKRQ5 (ORCPT + 99 others); Tue, 11 Feb 2020 12:16:57 -0500 Received: from muru.com ([72.249.23.125]:54736 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727954AbgBKRQ5 (ORCPT ); Tue, 11 Feb 2020 12:16:57 -0500 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id DA26E80D4; Tue, 11 Feb 2020 17:17:39 +0000 (UTC) From: Tony Lindgren To: Mark Brown Cc: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, Aaro Koskinen , "Arthur D ." , Jarkko Nikula , Merlijn Wajer , Pavel Machek , Peter Ujfalusi , Sebastian Reichel Subject: [PATCH] ASoC: ti: Allocate dais dynamically for TDM and audio graph card Date: Tue, 11 Feb 2020 09:16:45 -0800 Message-Id: <20200211171645.41990-1-tony@atomide.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We can have multiple connections on a single McBSP instance configured with audio graph card when using TDM (Time Division Multiplexing). Let's allow that by configuring dais dynamically. See Documentation/devicetree/bindings/sound/audio-graph-card.txt and Documentation/devicetree/bindings/graph.txt for more details for multiple endpoints. I've tested this with droid4 where cpcap pmic and modem voice are both both wired to mcbsp3. I've also tested this on droid4 both with and without the pending modem audio codec driver that is waiting for n_gsm serdev dependencies to clear. Cc: Aaro Koskinen Cc: Arthur D. Cc: Jarkko Nikula Cc: Merlijn Wajer Cc: Pavel Machek Cc: Peter Ujfalusi Cc: Sebastian Reichel Signed-off-by: Tony Lindgren --- sound/soc/ti/omap-mcbsp-priv.h | 2 + sound/soc/ti/omap-mcbsp.c | 76 ++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/sound/soc/ti/omap-mcbsp-priv.h b/sound/soc/ti/omap-mcbsp-priv.h --- a/sound/soc/ti/omap-mcbsp-priv.h +++ b/sound/soc/ti/omap-mcbsp-priv.h @@ -262,6 +262,8 @@ struct omap_mcbsp { struct omap_mcbsp_platform_data *pdata; struct omap_mcbsp_st_data *st_data; struct omap_mcbsp_reg_cfg cfg_regs; + struct snd_soc_dai_driver *dais; + int dai_count; struct snd_dmaengine_dai_dma_data dma_data[2]; unsigned int dma_req[2]; int dma_op_mode; diff --git a/sound/soc/ti/omap-mcbsp.c b/sound/soc/ti/omap-mcbsp.c --- a/sound/soc/ti/omap-mcbsp.c +++ b/sound/soc/ti/omap-mcbsp.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1304,23 +1305,53 @@ static int omap_mcbsp_remove(struct snd_soc_dai *dai) return 0; } -static struct snd_soc_dai_driver omap_mcbsp_dai = { - .probe = omap_mcbsp_probe, - .remove = omap_mcbsp_remove, - .playback = { - .channels_min = 1, - .channels_max = 16, - .rates = OMAP_MCBSP_RATES, - .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, - }, - .capture = { - .channels_min = 1, - .channels_max = 16, - .rates = OMAP_MCBSP_RATES, - .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, - }, - .ops = &mcbsp_dai_ops, -}; +static int omap_mcbsp_init_dais(struct omap_mcbsp *mcbsp) +{ + struct device_node *np = mcbsp->dev->of_node; + int i; + + if (np) + mcbsp->dai_count = of_graph_get_endpoint_count(np); + + if (!mcbsp->dai_count) + mcbsp->dai_count = 1; + + mcbsp->dais = devm_kcalloc(mcbsp->dev, mcbsp->dai_count, + sizeof(*mcbsp->dais), GFP_KERNEL); + if (!mcbsp->dais) + return -ENOMEM; + + for (i = 0; i < mcbsp->dai_count; i++) { + struct snd_soc_dai_driver *dai = &mcbsp->dais[i]; + + dai->name = devm_kasprintf(mcbsp->dev, GFP_KERNEL, "%s-dai%i", + dev_name(mcbsp->dev), i); + + if (i == 0) { + dai->probe = omap_mcbsp_probe; + dai->remove = omap_mcbsp_remove; + dai->ops = &mcbsp_dai_ops; + } + dai->playback.channels_min = 1; + dai->playback.channels_max = 16; + dai->playback.rates = OMAP_MCBSP_RATES; + if (mcbsp->pdata->reg_size == 2) + dai->playback.formats = SNDRV_PCM_FMTBIT_S16_LE; + else + dai->playback.formats = SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S32_LE; + dai->capture.channels_min = 1; + dai->capture.channels_max = 16; + dai->capture.rates = OMAP_MCBSP_RATES; + if (mcbsp->pdata->reg_size == 2) + dai->capture.formats = SNDRV_PCM_FMTBIT_S16_LE; + else + dai->capture.formats = SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S32_LE; + } + + return 0; +} static const struct snd_soc_component_driver omap_mcbsp_component = { .name = "omap-mcbsp", @@ -1409,18 +1440,17 @@ static int asoc_mcbsp_probe(struct platform_device *pdev) mcbsp->dev = &pdev->dev; platform_set_drvdata(pdev, mcbsp); - ret = omap_mcbsp_init(pdev); + ret = omap_mcbsp_init_dais(mcbsp); if (ret) return ret; - if (mcbsp->pdata->reg_size == 2) { - omap_mcbsp_dai.playback.formats = SNDRV_PCM_FMTBIT_S16_LE; - omap_mcbsp_dai.capture.formats = SNDRV_PCM_FMTBIT_S16_LE; - } + ret = omap_mcbsp_init(pdev); + if (ret) + return ret; ret = devm_snd_soc_register_component(&pdev->dev, &omap_mcbsp_component, - &omap_mcbsp_dai, 1); + mcbsp->dais, mcbsp->dai_count); if (ret) return ret; -- 2.25.0