From patchwork Tue Sep 24 18:12:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 277560 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 524A02C00CE for ; Wed, 25 Sep 2013 04:13:29 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOX6v-0005lA-9X; Tue, 24 Sep 2013 18:13:21 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOX6s-0000IE-Rx; Tue, 24 Sep 2013 18:13:18 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOX6p-0000GX-Ir for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2013 18:13:16 +0000 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1VOX6M-0002Hs-5C; Tue, 24 Sep 2013 20:12:46 +0200 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1VOX6K-00024M-6A; Tue, 24 Sep 2013 20:12:44 +0200 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Liam Girdwood , Mark Brown Subject: [PATCH] ASoC: kirkwood: simplify clock handling Date: Tue, 24 Sep 2013 20:12:35 +0200 Message-Id: <1380046355-7920-1-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1379951159-8294-1-git-send-email-u.kleine-koenig@pengutronix.de> References: <1379951159-8294-1-git-send-email-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130924_141315_995164_A537A663 X-CRM114-Status: GOOD ( 20.63 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Thomas Petazzoni , Jean-Francois Moine , alsa-devel@alsa-project.org, kernel@pengutronix.de, Russell King , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org There is no need to not use extclk if it is identical to the main clk. The main motivation for this patch is dropping devm_clk_put which is used in a wrong way by all other users. While at it also extend the comments. Signed-off-by: Uwe Kleine-König --- Hello, there might be some further optimisations possible. I only note them here because I don't have the hardware to test: - only enable extclk if it a clock rate used that makes use of the external clock. Not sure if that works; hardware docs reading necessary. - only provide extclk if it's != the internal clock. - The code uses: priv->clk = devm_clk_get(&pdev->dev, np ? "internal" : NULL); i.e. provides a con_id in the dt-case. I think that using NULL unconditionally should also work, i.e. return the first clk associated to the device. OTOH the current code might make things clearer because it's more explicit. Best regards Uwe --- sound/soc/kirkwood/kirkwood-i2s.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sound/soc/kirkwood/kirkwood-i2s.c b/sound/soc/kirkwood/kirkwood-i2s.c index 0f3d73d..8224f93 100644 --- a/sound/soc/kirkwood/kirkwood-i2s.c +++ b/sound/soc/kirkwood/kirkwood-i2s.c @@ -104,16 +104,25 @@ static void kirkwood_set_rate(struct snd_soc_dai *dai, uint32_t clks_ctrl; if (rate == 44100 || rate == 48000 || rate == 96000) { - /* use internal dco for the supported rates - * defined in kirkwood_i2s_dai */ + /* + * use internal dco for the supported rates + * defined in kirkwood_i2s_dai + * Note: For these specific rates the dco is also used if + * kirkwood_i2s_dai_extclk is in use. + */ dev_dbg(dai->dev, "%s: dco set rate = %lu\n", __func__, rate); kirkwood_set_dco(priv->io, rate); clks_ctrl = KIRKWOOD_MCLK_SOURCE_DCO; } else { - /* use the external clock for the other rates - * defined in kirkwood_i2s_dai_extclk */ + /* + * use the external clock for the other rates + * defined in kirkwood_i2s_dai_extclk + * This case isn't reached if kirkwood_i2s_dai is in use (and so + * extclk isn't valid) because it only supports the three rates + * above. + */ dev_dbg(dai->dev, "%s: extclk set rate = %lu -> %lu\n", __func__, rate, 256 * rate); clk_set_rate(priv->extclk, 256 * rate); @@ -497,12 +506,9 @@ static int kirkwood_i2s_dev_probe(struct platform_device *pdev) priv->extclk = devm_clk_get(&pdev->dev, "extclk"); if (!IS_ERR(priv->extclk)) { - if (priv->extclk == priv->clk) { - devm_clk_put(&pdev->dev, priv->extclk); - priv->extclk = ERR_PTR(-EINVAL); - } else { + clk_prepare_enable(priv->extclk); + if (priv->extclk != priv->clk) { dev_info(&pdev->dev, "found external clock\n"); - clk_prepare_enable(priv->extclk); soc_dai = &kirkwood_i2s_dai_extclk; } }