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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_SANE_1 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 ADECAC43331 for ; Tue, 12 Nov 2019 16:30:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C31920679 for ; Tue, 12 Nov 2019 16:30:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727010AbfKLQaA (ORCPT ); Tue, 12 Nov 2019 11:30:00 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51424 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726799AbfKLQaA (ORCPT ); Tue, 12 Nov 2019 11:30:00 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 4558129064A Received: by earth.universe (Postfix, from userid 1000) id D9F353C0C78; Tue, 12 Nov 2019 17:29:54 +0100 (CET) Date: Tue, 12 Nov 2019 17:29:54 +0100 From: Sebastian Reichel To: Adam Thomson Cc: Support Opensource , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , "alsa-devel@alsa-project.org" , "linux-kernel@vger.kernel.org" , "kernel@collabora.com" Subject: Re: [PATCHv1 5/5] ASoC: da7213: add default clock handling Message-ID: <20191112162954.aac77rtfbl6mlut6@earth.universe> References: <20191108174843.11227-1-sebastian.reichel@collabora.com> <20191108174843.11227-6-sebastian.reichel@collabora.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="apjhnqdgp22efygn" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --apjhnqdgp22efygn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Mon, Nov 11, 2019 at 02:20:07PM +0000, Adam Thomson wrote: > On 08 November 2019 17:49, Sebastian Reichel wrote: >=20 > > This adds default clock/PLL configuration to the driver > > for usage with generic drivers like simple-card for usage > > with a fixed rate clock. > >=20 > > Upstreaming this requires a good way to disable the automatic > > clock handling for systems doing it manually to avoid breaking > > existing setups. > >=20 > > Signed-off-by: Sebastian Reichel > > --- > > sound/soc/codecs/da7213.c | 34 +++++++++++++++++++++++++++++++++- > > sound/soc/codecs/da7213.h | 1 + > > 2 files changed, 34 insertions(+), 1 deletion(-) > >=20 > > diff --git a/sound/soc/codecs/da7213.c b/sound/soc/codecs/da7213.c > > index 197609691525..a4ed382ddfc7 100644 > > --- a/sound/soc/codecs/da7213.c > > +++ b/sound/soc/codecs/da7213.c > > @@ -1163,6 +1163,8 @@ static int da7213_hw_params(struct > > snd_pcm_substream *substream, > > struct snd_soc_dai *dai) > > { > > struct snd_soc_component *component =3D dai->component; > > + struct da7213_priv *da7213 =3D > > snd_soc_component_get_drvdata(component); > > + int freq =3D 0; > > u8 dai_ctrl =3D 0; > > u8 fs; > >=20 > > @@ -1188,38 +1190,54 @@ static int da7213_hw_params(struct > > snd_pcm_substream *substream, > > switch (params_rate(params)) { > > case 8000: > > fs =3D DA7213_SR_8000; > > + freq =3D DA7213_PLL_FREQ_OUT_98304000; > > break; > > case 11025: > > fs =3D DA7213_SR_11025; > > + freq =3D DA7213_PLL_FREQ_OUT_90316800; > > break; > > case 12000: > > fs =3D DA7213_SR_12000; > > + freq =3D DA7213_PLL_FREQ_OUT_98304000; > > break; > > case 16000: > > fs =3D DA7213_SR_16000; > > + freq =3D DA7213_PLL_FREQ_OUT_98304000; > > break; > > case 22050: > > fs =3D DA7213_SR_22050; > > + freq =3D DA7213_PLL_FREQ_OUT_90316800; > > break; > > case 32000: > > fs =3D DA7213_SR_32000; > > + freq =3D DA7213_PLL_FREQ_OUT_98304000; > > break; > > case 44100: > > fs =3D DA7213_SR_44100; > > + freq =3D DA7213_PLL_FREQ_OUT_90316800; > > break; > > case 48000: > > fs =3D DA7213_SR_48000; > > + freq =3D DA7213_PLL_FREQ_OUT_98304000; > > break; > > case 88200: > > fs =3D DA7213_SR_88200; > > + freq =3D DA7213_PLL_FREQ_OUT_90316800; > > break; > > case 96000: > > fs =3D DA7213_SR_96000; > > + freq =3D DA7213_PLL_FREQ_OUT_98304000; > > break; > > default: > > return -EINVAL; > > } > >=20 > > + /* setup PLL */ > > + if (da7213->fixed_clk_auto) { > > + snd_soc_component_set_pll(component, 0, > > DA7213_SYSCLK_PLL, > > + da7213->mclk_rate, freq); > > + } > > + >=20 > Are we happy with the PLL being always enabled? Seems like a power drain, > especially if you're using an MCLK which is a natural harmonic for the SR= in=20 > question in which case the PLL can be bypassed. Also the bias level funct= ion in > this driver will enable and disable the MCLK, if it has been provided, so= it's a > bit strange to have the PLL enabled but it's clock source taken away. So you are suggesting adding something like this to da7213_set_bias_level()? if (freq % da7213->mclk_rate =3D=3D 0) source =3D DA7213_SYSCLK_MCLK else source =3D DA7213_SYSCLK_PLL snd_soc_component_set_pll(component, 0, source, da7213->mclk_rate, freq); > > snd_soc_component_update_bits(component, DA7213_DAI_CTRL, > > DA7213_DAI_WORD_LENGTH_MASK, > > dai_ctrl); > > snd_soc_component_write(component, DA7213_SR, fs); > > @@ -1700,10 +1718,10 @@ static struct da7213_platform_data > > return pdata; > > } > >=20 > > - > > static int da7213_probe(struct snd_soc_component *component) > > { > > struct da7213_priv *da7213 =3D > > snd_soc_component_get_drvdata(component); > > + int ret; > >=20 > > pm_runtime_get_sync(component->dev); > >=20 > > @@ -1836,6 +1854,20 @@ static int da7213_probe(struct snd_soc_component > > *component) > > return PTR_ERR(da7213->mclk); > > else > > da7213->mclk =3D NULL; > > + } else { > > + /* Store clock rate for fixed clocks for automatic PLL setup */ > > + ret =3D clk_prepare_enable(da7213->mclk); > > + if (ret) { > > + dev_err(component->dev, "Failed to enable mclk\n"); > > + return ret; > > + } >=20 > I've not gone through the clk framework code but surprised to see the nee= d to > enable a clock to retrieve it's rate. /** * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. * This is only valid once the clock source has been enabled. * @clk: clock source */ unsigned long clk_get_rate(struct clk *clk); Which makes sense for a non-fixed clock, which uses the same API. > > + da7213->mclk_rate =3D clk_get_rate(da7213->mclk); > > + > > + clk_disable_unprepare(da7213->mclk); > > + > > + /* assume fixed clock until set_sysclk() is being called */ > > + da7213->fixed_clk_auto =3D true; >=20 > I don't see any code where 'fixed_clk_auto' is set to false so it seems t= hat > previous operational usage is being broken here. oops. > > } > >=20 > > return 0; > > diff --git a/sound/soc/codecs/da7213.h b/sound/soc/codecs/da7213.h > > index 97a250ea39e6..00aca0126cdb 100644 > > --- a/sound/soc/codecs/da7213.h > > +++ b/sound/soc/codecs/da7213.h > > @@ -532,6 +532,7 @@ struct da7213_priv { > > bool master; > > bool alc_calib_auto; > > bool alc_en; > > + bool fixed_clk_auto; > > struct da7213_platform_data *pdata; > > }; > >=20 > > -- > > 2.24.0.rc1 >=20 -- Sebastian --apjhnqdgp22efygn Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAl3K3d8ACgkQ2O7X88g7 +ppe/w/+NNfpGUUIY83SxgZnAoEPqGHlitffk72hH8jOod5umEbyNBIO5m7QAluw QiBgVetwFXJ547ETC6hZof4jwiKip2B+XKO2JFkiOnjUdkctOTjYgT6d5Kb2kg1K tyEYg00vY9Ht+kRVrOANUCWA6XkB4aQHWQmT1Bpm+irl4ntG4xOwgFbUuqlhkh73 UA/bX4YFfnpGbA88BPp/2+nwER3I9xF4yG0eaRMVpsv4SKlHsSal1EeJZxc8Mbs7 kww7Eytw8NTCiv4NhCxzduY/97mR8YvPyKRr6aDDRF2n10O46zr5TtY0hFBmuZoy aHX5IMkHhHFZygzhLHGrZiS4w/fbcf1AY96Nns1iajN2Wi4GDAVZjtFZR6VIxOp7 w8IL3OdVMXoksoa6zA2AUueuEUdI8yJUEY8WXaaJFW4fOKf0MWqENVes4sUDh+GA FT9wEOyWeUV5KkX04goWDtNemZgIoxVGlCY/OSWtiGzlXVfSvVkAsin5uqb+Lo4h WDMvzi1mVUWjr1pWIR7OFtQVR2ta3nqecRqAi2pTGprc0eAifFdz+Jn+BIsssDft 6+HqFzuUFF6XiZjbI+jVpjGmJS13ImEDadMM/Pq9t6D0SMs+j1zWWi0/G0ZWB5p9 v4lraEsoDRGf4qCWSkrUAqfnC3mi3zWprs+xjC7ur6DdTsNh3K8= =ZaXT -----END PGP SIGNATURE----- --apjhnqdgp22efygn--