From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F0D83A16BD for ; Sun, 28 Jun 2026 11:43:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782646986; cv=none; b=A/QNaytiYlezcFH6IVvHX6dtvnbNaAQF/IqAHePDZeBnFErAI39byXyvPVcFFKUp4gWnZarqupyfzD5j/O53QTMAUFa1j4vZhBm9XS6bcGmcIyncNMQeZQRv4OpcKEI9pIRUBHa6Lt3xoJmW2YoT6tacn01HLxCdfLI6PPkGtCc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782646986; c=relaxed/simple; bh=vCwTWhx34mxI5VtL9yfZYBRYlRieG7N9OPwOIARXohg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l50md6I/9wyer/QfTWC4s37PbCxRZiih1IlLOANrQb9RcF2fmg7zfCBS55PBPq+L5pb4r9A7AoetH+2K237QO5dvXWBrpu6t9mMfKQ3JayoowbCeZgwQ7/8Q0g1WuIzfKeVREIkPh7gxDs0yn3dUkz6II63oZaVDYgf+oXxF+jE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ql5qUjlZ; arc=none smtp.client-ip=74.125.82.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ql5qUjlZ" Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-30e7eb50b83so855269eec.1 for ; Sun, 28 Jun 2026 04:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782646985; x=1783251785; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=f2b3SDdqWpmyJY1eiorrtcZL1eV0O0v8ZeY+y7/BcKo=; b=ql5qUjlZW47mKwUt+kn9gTtuC8mcF2iMCg3hKEI/y4Yf3iGcwxyZgqbCogxL5ua/rh nO5+OazI/g8BfbBrn3NCzmDcJqDjjY+eFLi+cKFQtcUtIgkLdaie9N7SnSJ1eHoIQMje c7HxkTnjrxxdv10utEpeoaRFj1dpk5u2rxJbrKCERSkMc710+OvvMDo4MacRiUrxVOZo KchcLo0mhh9EVw5BF0YqAYiS7CYiGcd58zsjnJFqUJFvwf1V2MkROUk59qbqx0thm/6w xS+GOl+UEs+5pzRVhwsXyYoSKNO6swSK7SK6n2AAYdrbjHVWDqJTzZ+ePGELt5rAbXSY f0hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782646985; x=1783251785; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=f2b3SDdqWpmyJY1eiorrtcZL1eV0O0v8ZeY+y7/BcKo=; b=Hl91xb+a2rPCvlToxKFoUaB3m8WzsGNd8kU2EWS85ZxAfomdqTgz1SA1y0j0wEOtZ2 X3VGRVVrTVnqStQiOBcXe/wPs8weHbVYzVCbjhOemcacrskrLJ2tRa0vrFrJndcdbHko keZtEPXwKThkXzO68HlcT/x0a4Tu7PJ2+/ceD5xnmj6n02grKUvcNTbA6ICRifmIRCqi 0LgUFApfj72rLhzgks7BVSgf+q3EPBRbCXls6ruwHDsX3ha4NJASk1ttYb75/TmFYToD 5iNtde+FcAKPPWNs0cSyHpPx7yVQYAzYQmVMsHLeN5FmF9+A3p40Q86lG5IzxIGv0giM 4eUw== X-Forwarded-Encrypted: i=1; AHgh+RqhyqaXEp8iMGrjOxqUvg8dml57YZTi6Q3O9/fFYfcXsEv6wVGLYLsvmhMdj7XCXZzO7VbpqU+EbpHp87k=@vger.kernel.org X-Gm-Message-State: AOJu0Yx07ytFBJuPlAy3bNP258Dv2uggzXEJQjBPeoDXaA5iYqvUsU9P 11k5prebQ3nG8yi2Z7sk3A2ybmnnO0eEdsR6QaT64GBJbfJ4SS6uUhpe X-Gm-Gg: AfdE7cmhSsKvs9S70fnRwTQY6yZI1+rvz+X0H3WfBYBmJE0zR7y+VwT39xoBmrEHJ5R gp1gF+cNFc94JRMk/KxTxjuRMYvwGT8xD6MJVlnPLbYpAK5LaNogUzmR85oEgWO/Ssz8tYWY3kS CQVIBW8VtxcdJmBqveDButLnZLgrHs8c13GQ1WBG8juBzBeSwAejlyOCEDbjDt8pFLyoRxgoCIo XhouJGuEFH3TnBrM0syPdHb/fyKnGVfcWYGp1bIQqDoppof1v7DrcUXyJbR2Wq4DghZoexTrizN oOlNWtfw1AogVWmjGR5nY+VWk3clgLEb7+i5hykXOmfcVsZvTYc4EwJ7BxC0O9iI7MkLUL2acLp 9zVPVONq0QOJXpJg2Jk0zrEs4F7WJW0wsnfvIrybAY8NodcEh4RJ4itz074mMlvb/bRIaA4e4El aEs5w9gfmbwMhImNIVNfckxmVazSw1O8lsTNjoKCDtIZFxaKzDmR9Bk25X65yrS2j8U4dOzLjGj gmghymFS4MRKGVPt7LKT3XrfjbLMZukh5pjVbQpdN8pf04xdE4OEBs4ryVMQftVog== X-Received: by 2002:a05:7300:aca8:b0:2ea:edc0:4fbe with SMTP id 5a478bee46e88-30c84b8a06bmr11982279eec.14.1782646984691; Sun, 28 Jun 2026 04:43:04 -0700 (PDT) Received: from [192.168.2.3] ([2403:581e:d87e:0:fc2d:ed31:e80e:412d]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c7c8b1a80sm34520756eec.18.2026.06.28.04.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jun 2026 04:43:04 -0700 (PDT) From: James Calligeros Date: Sun, 28 Jun 2026 21:42:00 +1000 Subject: [PATCH v2 2/7] ASoC: apple: mca: Separate data & clock port setup Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260628-apple-audio-redux-v2-2-6328269c9652@gmail.com> References: <20260628-apple-audio-redux-v2-0-6328269c9652@gmail.com> In-Reply-To: <20260628-apple-audio-redux-v2-0-6328269c9652@gmail.com> To: =?utf-8?q?Martin_Povi=C5=A1er?= , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: asahi@lists.linux.dev, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, James Calligeros X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5618; i=jcalligeros99@gmail.com; h=from:subject:message-id; bh=GgliJOoSvzcQza50Y86eOaSmstcrXgaFkvgkZNNfLKM=; b=owGbwMvMwCV2xczoYuD3ygTG02pJDFmOHLvlf+7vcfZauepng+/9lnPCRacsz3DmZ97gkrKUd TssHPa9YyILgxgXg6WYIsuGJiGP2UZsN/tFKvfCzGFlAhkiLdLAAAQsDHy5iXmlRjpGeqbahnqG RjrGOkYMXJwCMNVPKxh+s1QEvTpdJPJN8kvDhfCZO+ecVDv279+7t0f9HU/pXVL8xcfwV/63jk0 au1bdTl+tIPFIt+M7+zfMW7tH/8BVRu63B/fxsQIA X-Developer-Key: i=jcalligeros99@gmail.com; a=openpgp; fpr=B08212489B3206D98F1479BDD43632D151F77960 From: Martin Povišer Up until now FEs were always the clock providers -- feeding the clocks on any ports (BEs) they are attached to. This will soon change and FEs will be allowed to be clock consumers. Once that happens, the routing of clocks and data will to some degree decouple. In advance of the change, make preparations: * Narrow down semantics of what was formerly the 'port_driver' field to refer to clocks only. * On 'startup' of BEs, separate the clock and data aspects of the port setup. Signed-off-by: Martin Povišer Signed-off-by: James Calligeros --- sound/soc/apple/mca.c | 63 ++++++++++++++++--------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/sound/soc/apple/mca.c b/sound/soc/apple/mca.c index ebe116f32661..feaf60a4912f 100644 --- a/sound/soc/apple/mca.c +++ b/sound/soc/apple/mca.c @@ -133,8 +133,8 @@ struct mca_cluster { struct clk *clk_parent; struct dma_chan *dma_chans[SNDRV_PCM_STREAM_LAST + 1]; - bool port_started[SNDRV_PCM_STREAM_LAST + 1]; - int port_driver; /* The cluster driving this cluster's port */ + bool port_clk_started[SNDRV_PCM_STREAM_LAST + 1]; + int port_clk_driver; /* The cluster driving this cluster's port */ bool clocks_in_use[SNDRV_PCM_STREAM_LAST + 1]; struct device_link *pd_link; @@ -157,7 +157,7 @@ struct mca_data { struct reset_control *rstc; struct device_link *pd_link; - /* Mutex for accessing port_driver of foreign clusters */ + /* Mutex for accessing port_clk_driver of foreign clusters */ struct mutex port_mutex; int nclusters; @@ -311,7 +311,7 @@ static bool mca_fe_clocks_in_use(struct mca_cluster *cl) for (i = 0; i < mca->nclusters; i++) { be_cl = &mca->clusters[i]; - if (be_cl->port_driver != cl->no) + if (be_cl->port_clk_driver != cl->no) continue; for_each_pcm_streams(stream) { @@ -331,10 +331,10 @@ static int mca_be_prepare(struct snd_pcm_substream *substream, struct mca_cluster *fe_cl; int ret; - if (cl->port_driver < 0) + if (cl->port_clk_driver < 0) return -EINVAL; - fe_cl = &mca->clusters[cl->port_driver]; + fe_cl = &mca->clusters[cl->port_clk_driver]; /* * Typically the CODECs we are paired with will require clocks @@ -708,12 +708,15 @@ static const struct snd_soc_dai_ops mca_fe_ops = { .trigger = mca_fe_trigger, }; -static bool mca_be_started(struct mca_cluster *cl) +/* + * Is there a FE attached which will be feeding this port's clocks? + */ +static bool mca_be_clk_started(struct mca_cluster *cl) { int stream; for_each_pcm_streams(stream) - if (cl->port_started[stream]) + if (cl->port_clk_started[stream]) return true; return false; } @@ -744,28 +747,38 @@ static int mca_be_startup(struct snd_pcm_substream *substream, fe_cl = mca_dai_to_cluster(snd_soc_rtd_to_cpu(fe, 0)); - if (mca_be_started(cl)) { + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + writel_relaxed(PORT_DATA_SEL_TXA(fe_cl->no), + cl->base + REG_PORT_DATA_SEL); + mca_modify(cl, REG_PORT_ENABLES, PORT_ENABLES_TX_DATA, + PORT_ENABLES_TX_DATA); + } + + if (mca_be_clk_started(cl)) { /* * Port is already started in the other direction. * Make sure there isn't a conflict with another cluster - * driving the port. + * driving the port clocks. */ - if (cl->port_driver != fe_cl->no) + if (cl->port_clk_driver != fe_cl->no) return -EINVAL; - cl->port_started[substream->stream] = true; + cl->port_clk_started[substream->stream] = true; return 0; } - writel_relaxed(PORT_ENABLES_CLOCKS | PORT_ENABLES_TX_DATA, - cl->base + REG_PORT_ENABLES); writel_relaxed(FIELD_PREP(PORT_CLOCK_SEL, fe_cl->no + 1), cl->base + REG_PORT_CLOCK_SEL); + writel_relaxed(PORT_DATA_SEL_TXA(fe_cl->no), cl->base + REG_PORT_DATA_SEL); + + mca_modify(cl, REG_PORT_ENABLES, PORT_ENABLES_CLOCKS, + PORT_ENABLES_CLOCKS); + scoped_guard(mutex, &mca->port_mutex) - cl->port_driver = fe_cl->no; - cl->port_started[substream->stream] = true; + cl->port_clk_driver = fe_cl->no; + cl->port_clk_started[substream->stream] = true; return 0; } @@ -776,17 +789,21 @@ static void mca_be_shutdown(struct snd_pcm_substream *substream, struct mca_cluster *cl = mca_dai_to_cluster(dai); struct mca_data *mca = cl->host; - cl->port_started[substream->stream] = false; + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + mca_modify(cl, REG_PORT_ENABLES, PORT_ENABLES_TX_DATA, 0); + writel_relaxed(0, cl->base + REG_PORT_DATA_SEL); + } - if (!mca_be_started(cl)) { + cl->port_clk_started[substream->stream] = false; + if (!mca_be_clk_started(cl)) { /* * Were we the last direction to shutdown? - * Turn off the lights. + * Turn off the lights (clocks). */ - writel_relaxed(0, cl->base + REG_PORT_ENABLES); - writel_relaxed(0, cl->base + REG_PORT_DATA_SEL); + mca_modify(cl, REG_PORT_ENABLES, PORT_ENABLES_CLOCKS, 0); + writel_relaxed(0, cl->base + REG_PORT_CLOCK_SEL); scoped_guard(mutex, &mca->port_mutex) - cl->port_driver = -1; + cl->port_clk_driver = -1; } } @@ -1092,7 +1109,7 @@ static int apple_mca_probe(struct platform_device *pdev) cl->host = mca; cl->no = i; cl->base = base + CLUSTER_STRIDE * i; - cl->port_driver = -1; + cl->port_clk_driver = -1; cl->clk_parent = of_clk_get(pdev->dev.of_node, i); if (IS_ERR(cl->clk_parent)) { dev_err(&pdev->dev, "unable to obtain clock %d: %ld\n", -- 2.54.0