From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76B02C4363A for ; Thu, 8 Oct 2020 13:04:20 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F21532145D for ; Thu, 8 Oct 2020 13:04:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZteVWall"; dkim=temperror (0-bit key) header.d=cerno.tech header.i=@cerno.tech header.b="NYylp3Sc"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nLW1XWUE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F21532145D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cerno.tech Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SQu4tUn3wZ4PbWmjc4/oL8w5OoNzrZj6QBFg1H0KQaY=; b=ZteVWallBvG1Q31JA93Sp3pf1 QC5dkPPIe3hR/oXyyQ7EdqNTubAlbi/qslrHsLB/+ZkEwSBohphgCIkUMCWvcsp/DgiRF+uhoZ9Ao 5pL9CTxbpWzh2/GJj+/r4xARwNl1vlGutl7oHZxPADIhwTfyfdF+e1T0/j5U9pJe+VAFeSfkJBROI Ub9K/Nj6MBSlqcYUTMk66b6MEhn6ANwzmCY51EI0WTTwQi1Rl/rH1QwdG29OUWZ0SybSKwR3sdVAK gnrshheXFoh+GudnSy6diYajZNWUxmb0uh8wLu1q5NFmPgFrA644l9ne57BbSUVrBGAT9vlmDX6Pk uozE2Dd7g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQVZK-0007Pw-HH; Thu, 08 Oct 2020 13:02:50 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQVZH-0007Ot-Di for linux-arm-kernel@lists.infradead.org; Thu, 08 Oct 2020 13:02:48 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 8CE38B69; Thu, 8 Oct 2020 09:02:45 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 08 Oct 2020 09:02:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=OnX2OclxUMbS2YHgH9OBLagClcV 8/eB+1eHYfJZoPcc=; b=NYylp3Scv0U41vEA323yHi1GV10gD9r94Ble+fzQ8i9 T8ucGY05g80hQQ2imFXkgNsxD/BmBcKujiUa/tTzQjGwozaUxUROuXzWH1c7RxqU 9OFCURdinvVZMKvV7Oei8O2pkz27cPlbS4CJhP85KCDv5OnpffVL10QxpR4OTIBd gKzH/mBwgNVdqm4wmwstK17+oXTAEwx5qt4VWtLg8YsZsgcGv03havdobuGV9Vuw orT7meEOiQqXSurhSy26W47Cvuo+Ir311jOC2F4s+0ffIN3DPkvkQSDzD4eTV1oo ui9frIXBP2hmidE3K2Te1Z4wZT1i517SNbm0dC4MY0Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=OnX2Oc lxUMbS2YHgH9OBLagClcV8/eB+1eHYfJZoPcc=; b=nLW1XWUE6LKvGPKt8xvmFf QrpCp6NfagO2jJzkOKRqygxf4hc5mH9h772F/ZEuM++AR20Hti62BQoHooIhhKgf Q9o3aquCVbzwCFJ/ky7aU6TYrZjLwN3KAQKmDbJsuZ3Rv8STBGrR75GTpreeg02d 78+YHgveFdhnfqzPPuuommOpmgQWM6c5lGiPUJK+pxdJwdilq3TvAhhPFs3ftwQF deDsMKBSu+jTiniZv5Hz6ExPHKmy3IF22ukM+Zoxx5FrvVXTbKF4mrQ92ApmJeOC 87Lw5EXvADItHrVNDZzuEsJRumjMmXE35gKd6/phEKtvgcZDORa0+xz8tIpPOdfw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrgeelgdefvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomhepofgrgihimhgv ucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtffrrghtth gvrhhnpeelkeeghefhuddtleejgfeljeffheffgfeijefhgfeufefhtdevteegheeiheeg udenucfkphepledtrdekledrieekrdejieenucevlhhushhtvghrufhiiigvpedunecurf grrhgrmhepmhgrihhlfhhrohhmpehmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Received: from localhost (lfbn-tou-1-1502-76.w90-89.abo.wanadoo.fr [90.89.68.76]) by mail.messagingengine.com (Postfix) with ESMTPA id 466093064674; Thu, 8 Oct 2020 09:02:42 -0400 (EDT) Date: Thu, 8 Oct 2020 15:02:41 +0200 From: Maxime Ripard To: Samuel Holland Subject: Re: [PATCH 20/25] ASoC: sun8i-codec: Protect the clock rate while streams are open Message-ID: <20201008130241.uigiys7iv72hca7r@gilmour.lan> References: <20201001021148.15852-1-samuel@sholland.org> <20201001021148.15852-21-samuel@sholland.org> <20201005120101.igzzwosnq6bzbua6@gilmour.lan> <5ef4351f-e9ed-1a38-b79e-53e62a70437e@sholland.org> MIME-Version: 1.0 In-Reply-To: <5ef4351f-e9ed-1a38-b79e-53e62a70437e@sholland.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201008_090247_593594_E2A5913D X-CRM114-Status: GOOD ( 28.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ondrej Jirman , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Takashi Iwai , Liam Girdwood , Chen-Yu Tsai , Mark Brown , Jaroslav Kysela , linux-arm-kernel@lists.infradead.org Content-Type: multipart/mixed; boundary="===============1914320125548464446==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============1914320125548464446== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="os5ttu6dxe7xjvcl" Content-Disposition: inline --os5ttu6dxe7xjvcl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Oct 05, 2020 at 11:43:51PM -0500, Samuel Holland wrote: > On 10/5/20 7:01 AM, Maxime Ripard wrote: > > On Wed, Sep 30, 2020 at 09:11:43PM -0500, Samuel Holland wrote: > >> The codec's clock input is shared among all AIFs, and shared with other > >> audio-related hardware in the SoC, including I2S and SPDIF controllers. > >> To ensure sample rates selected by userspace or by codec2codec DAI lin= ks > >> are maintained, the clock rate must be protected while it is in use. > >> > >> Signed-off-by: Samuel Holland > >> --- > >> sound/soc/sunxi/sun8i-codec.c | 25 ++++++++++++++++++++++--- > >> 1 file changed, 22 insertions(+), 3 deletions(-) > >> > >> diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-cod= ec.c > >> index 501af64d43a0..86065bee7cd3 100644 > >> --- a/sound/soc/sunxi/sun8i-codec.c > >> +++ b/sound/soc/sunxi/sun8i-codec.c > >> @@ -416,27 +416,32 @@ static int sun8i_codec_get_lrck_div_order(unsign= ed int slots, > >> unsigned int div =3D slots * slot_width; > >> =20 > >> if (div < 16 || div > 256) > >> return -EINVAL; > >> =20 > >> return order_base_2(div); > >> } > >> =20 > >> +static unsigned int sun8i_codec_get_sysclk_rate(unsigned int sample_r= ate) > >> +{ > >> + return sample_rate % 4000 ? 22579200 : 24576000; > >> +} > >> + > >> static int sun8i_codec_hw_params(struct snd_pcm_substream *substream, > >> struct snd_pcm_hw_params *params, > >> struct snd_soc_dai *dai) > >> { > >> struct sun8i_codec *scodec =3D snd_soc_dai_get_drvdata(dai); > >> struct sun8i_codec_aif *aif =3D &scodec->aifs[dai->id]; > >> unsigned int sample_rate =3D params_rate(params); > >> unsigned int slots =3D aif->slots ?: params_channels(params); > >> unsigned int slot_width =3D aif->slot_width ?: params_width(params); > >> - unsigned int sysclk_rate =3D clk_get_rate(scodec->clk_module); > >> - int lrck_div_order, word_size; > >> + unsigned int sysclk_rate =3D sun8i_codec_get_sysclk_rate(sample_rate= ); > >> + int lrck_div_order, ret, word_size; > >> u8 bclk_div; > >> =20 > >> /* word size */ > >> switch (params_width(params)) { > >> case 8: > >> word_size =3D 0x0; > >> break; > >> case 16: > >> @@ -466,17 +471,30 @@ static int sun8i_codec_hw_params(struct snd_pcm_= substream *substream, > >> (lrck_div_order - 4) << SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV); > >> =20 > >> /* BCLK divider (SYSCLK/BCLK ratio) */ > >> bclk_div =3D sun8i_codec_get_bclk_div(sysclk_rate, lrck_div_order, s= ample_rate); > >> regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL, > >> SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV_MASK, > >> bclk_div << SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV); > >> =20 > >> - if (!aif->open_streams) { > >> + /* SYSCLK rate */ > >> + if (aif->open_streams) { > >> + ret =3D clk_set_rate(scodec->clk_module, sysclk_rate); > >> + if (ret < 0) > >> + return ret; > >> + } else { > >> + ret =3D clk_set_rate_exclusive(scodec->clk_module, sysclk_rate); > >=20 > > It's not really clear to me why we wouldn't want to always protect the > > clock rate here? >=20 > From Documentation/sound/kernel-api/writing-an-alsa-driver.rst: >=20 > hw_params callback > ... > Note that this and ``prepare`` callbacks may be called multiple > times per initialization. For example, the OSS emulation may call > these callbacks at each change via its ioctl. >=20 > Clock rate protection is reference counted, so we must only take one > reference (or at least a known number of references) per stream. Ah, right. Can you add a comment to make that more obvious? > >> + if (ret =3D=3D -EBUSY) > >> + dev_err(dai->dev, "%s: clock is busy! Sample rate %u Hz " > >> + "conflicts with other audio streams.\n", > >=20 > > This string creates a checkpatch warning. >=20 > I will put it on one line, though >100 columns is also a checkpatch warni= ng. Yeah, but in general having an error on a single line is more important. That way you can then grep for that error message Maxime --os5ttu6dxe7xjvcl Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCX38N8QAKCRDj7w1vZxhR xeeGAP0cFB8uWUUs+EZIcN6bxqGf/Bf/dWy9iwe3GhQXO0PhlgEA3YDzSc4+mvs5 7RfAvmCMM9CZpNlLZYle3uVbztf7Wwk= =yu/i -----END PGP SIGNATURE----- --os5ttu6dxe7xjvcl-- --===============1914320125548464446== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============1914320125548464446==--