From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 89D0D4DD6F3 for ; Fri, 5 Jun 2026 12:20:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780662060; cv=none; b=fiiPY5KnofRAQsYcs6xFoLCiepDMJanUOwB9vxXSqN3scylEN13dvy3nhwErvgLDRUbqz+s31tkabMQz/XOyph+lH+O5fuPBeKe48P4PDLcNumYzXajaz52ZoJdorzUj3tC54Au0MwfvqMcQorwYAp2aokj3R15A6r/leEWrsDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780662060; c=relaxed/simple; bh=ceY3n9dzbLrF6UzskKUXhtBxJklxdTRM4gCgSQyi9G0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hLY9yXE714dPyHwmQpvPOSDPOsjZWLovoqMwNt3YukZNCbcYZwOSwfMojekoS0Ezeo/bik1Qw0SU/toRx2qRBMJy59WWDTb5xbQUAAwM3gel8ATBbqjJDEOVhBpqZTAJyaNjiCtHYPMIzOuc3nQXfAcl0/fxXnxV5U684spY7Ds= 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=iXMcPuMo; arc=none smtp.client-ip=209.85.210.170 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="iXMcPuMo" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-8423f1e2f8eso1442517b3a.1 for ; Fri, 05 Jun 2026 05:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780662058; x=1781266858; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uRIkhCmMLekSBDwmbxb2dx0SojXZ81/d3iroLxefd9A=; b=iXMcPuMoXYl5EXmyoVRDxdb1Ar7YmqbkVx7ARA4mwLoLiDoF/DZSoMlNn/Maww8iZK J4JSlZzX8fo7GafYlV2SNshAFOZ435f22S8Iv61cLLyENFweXITtCAJF7Zc/hjQR+yvk M/IBGxAiiQnxdDPWkjDMSKxPtyl2SwjAT5TuUHvsmN+BEZqoFwHmaLb4X5j5BdfzOKj7 E1OhX6Fno+aRz5Udix5HRL5aV8kk9zENN1f6xBV1lKCj5mJf3OhWin3AGwleYxi1xSdy khF/aGVvCSEO/bu7+u7Yhquz7Nt7tDJfls7BQulHiI7XioRCMJ9LpUWrxZI7I8YfT/Pt BHxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780662058; x=1781266858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uRIkhCmMLekSBDwmbxb2dx0SojXZ81/d3iroLxefd9A=; b=ayfBCUN2VYuKXCPtCnX4nrY6SxYEJMJY5YP7pMVVxLstM0mHZ59eBRA3N06qXr57Vu WhZ3NOlH/ejwlfcC6kzG0J1znAM3LkpvEEHD2DVGdY2pFP4OMk2gZbevMupHioo4w2aH LPtw/sled26UaNoy1gBlyKXuhYdeYswHm8ORUqj/rRpxpv48qRHhmGDn9r6BFN8cFGJy x4pDZxiP2gr9gF5IekJTnq/OUMVP/XalqRd3zkuc7r4tdTB5MFcMI1s362Gtcd4oGgKT sf5UB09PVvybBFZB82fN5Yt6MefP0X+LEpzbWhmTAmrZr7/V7i471O/DLuNbsSVwWlgl WFcg== X-Forwarded-Encrypted: i=1; AFNElJ88SNJ7ezPFsjuXMnyMbpSUfyoqEJ38opGizgW9GI/0fCunIOM5OwCAbuIzWODBRNuEx5e/EgWEgBXQ5kA=@vger.kernel.org X-Gm-Message-State: AOJu0YwJ3EoFi/75ATX0Jf+qAIbtky09UMm6iejopktV0HBLly1+qWk5 WV4dBLILBvafxGuXpa4d8wBDPqf+7ojjiY8j5uxleBtNq9OPLROLyfMB X-Gm-Gg: Acq92OFioptp+PEYf5/Lto7rcDnUqN+luZAh8VGkC7vxokrIydzS6KYfNMFYCa+3g0s 4CKx73wfOCOkLZYHErPun3Fxd39z65ksD0CHMaiGmtRmG5fhtXqANt3D/p6E4vDhZnh7ZzppoUx kT2CO3D7+7mMW2D911VVQwI5x0MTjblelzXh4jYMyYJAkbwqbo1RKx42RrMhcdw2KSK0O6a7EbB BHyY2jD39cjE5s5Yuu3wGpZDFYyc+n3NKIMkQ4p/jtIBdlcmSDcDd5AtiJLMEjTOdU0Sx1ogWhH 5N4cwDLfpOHIWCm50WQKJmcuray8ima2GChQG9KP/DE0LF5fXBrpKMN8Fd8ZQK338TxnGvQqyte wF8jIL+oLkF16KwvF+Cg7H/yliGLu0Qyz6F67uSM6HR11BrPSiIY+OPJjM1YfAxWuAQE5sez7+R fYiigEMcUUa0oe/ZyEZwXsbToYwcqs9U8e4mfVBSRiGQduxeNeUXWjPsA7ozjmiMSR3X6y X-Received: by 2002:a05:6a00:1d8e:b0:842:6099:c55c with SMTP id d2e1a72fcca58-842b0d82a44mr3266499b3a.3.1780662057726; Fri, 05 Jun 2026 05:20:57 -0700 (PDT) Received: from phuc-desktop.. ([183.91.15.56]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84282221059sm8594381b3a.7.2026.06.05.05.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2026 05:20:57 -0700 (PDT) From: phucduc.bui@gmail.com To: Kuninori Morimoto , Mark Brown , Geert Uytterhoeven Cc: Liam Girdwood , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Magnus Damm , Jaroslav Kysela , Takashi Iwai , linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, bui duc phuc Subject: [PATCH v4 09/10] ASoC: renesas: fsi: add fsi_clk_prepare/unprepare() Date: Fri, 5 Jun 2026 19:19:53 +0700 Message-ID: <20260605121955.105661-10-phucduc.bui@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260605121955.105661-1-phucduc.bui@gmail.com> References: <20260605121955.105661-1-phucduc.bui@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: bui duc phuc Add fsi_clk_prepare() and fsi_clk_unprepare() helpers and call them from fsi_dai_startup() and fsi_dai_shutdown(). This ensures clk_prepare() and clk_unprepare() are executed from sleepable contexts and keeps clocks prepared only while audio streams are active. Suggested-by: Kuninori Morimoto Signed-off-by: bui duc phuc --- Changes in v4: - Move clock->count early return check to the beginning of fsi_clk_[un]prepare() to simplify the code. sound/soc/renesas/fsi.c | 77 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/sound/soc/renesas/fsi.c b/sound/soc/renesas/fsi.c index 3f303e15e835..6537321242c0 100644 --- a/sound/soc/renesas/fsi.c +++ b/sound/soc/renesas/fsi.c @@ -294,6 +294,7 @@ struct fsi_master { struct fsi_priv fsib; struct clk *clk_spu; const struct fsi_core *core; + int spu_count; spinlock_t lock; }; @@ -730,6 +731,78 @@ static int fsi_clk_is_valid(struct fsi_priv *fsi) fsi->clock.rate; } +static int fsi_clk_prepare(struct fsi_priv *fsi) +{ + struct fsi_clk *clock = &fsi->clock; + struct clk *spu = fsi->master->clk_spu; + struct clk *xck = clock->xck; + struct clk *ick = clock->ick; + struct clk *div = clock->div; + int ret; + + if (clock->count != 0) + return 0; + + if (!IS_ERR_OR_NULL(spu) && fsi->master->spu_count == 0) { + ret = clk_prepare(spu); + if (ret) + return ret; + } + + if (!IS_ERR_OR_NULL(xck)) { + ret = clk_prepare(xck); + if (ret) + goto err_spu; + } + + if (!IS_ERR_OR_NULL(ick)) { + ret = clk_prepare(ick); + if (ret) + goto err_xck; + } + + if (!IS_ERR_OR_NULL(div)) { + ret = clk_prepare(div); + if (ret) + goto err_ick; + } + + return 0; + +err_ick: + clk_unprepare(ick); +err_xck: + clk_unprepare(xck); +err_spu: + clk_unprepare(spu); + + return ret; +} + +static void fsi_clk_unprepare(struct fsi_priv *fsi) +{ + struct fsi_clk *clock = &fsi->clock; + struct clk *spu = fsi->master->clk_spu; + struct clk *xck = clock->xck; + struct clk *ick = clock->ick; + struct clk *div = clock->div; + + if (clock->count != 0) + return; + + if (!IS_ERR_OR_NULL(div)) + clk_unprepare(div); + + if (!IS_ERR_OR_NULL(ick)) + clk_unprepare(ick); + + if (!IS_ERR_OR_NULL(xck)) + clk_unprepare(xck); + + if (!IS_ERR_OR_NULL(spu) && fsi->master->spu_count == 0) + clk_unprepare(spu); +} + static int fsi_clk_enable(struct device *dev, struct fsi_priv *fsi) { @@ -1580,7 +1653,7 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream, fsi_clk_invalid(fsi); - return 0; + return fsi_clk_prepare(fsi); } static void fsi_dai_shutdown(struct snd_pcm_substream *substream, @@ -1588,6 +1661,7 @@ static void fsi_dai_shutdown(struct snd_pcm_substream *substream, { struct fsi_priv *fsi = fsi_get_priv(substream); + fsi_clk_unprepare(fsi); fsi_clk_invalid(fsi); } @@ -1975,6 +2049,7 @@ static int fsi_probe(struct platform_device *pdev) /* master setting */ master->core = core; + master->spu_count = 0; spin_lock_init(&master->lock); /* FSI A setting */ -- 2.43.0