From patchwork Wed Jun 3 13:36:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 1302992 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=libero.it Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=libero.it header.i=@libero.it header.a=rsa-sha256 header.s=s2014 header.b=FLY+Gub6; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49cVM5264wz9sSc for ; Wed, 3 Jun 2020 23:37:02 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1BF3780929; Wed, 3 Jun 2020 15:36:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=libero.it Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=libero.it header.i=@libero.it header.b="FLY+Gub6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A654180A01; Wed, 3 Jun 2020 15:36:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,FREEMAIL_FROM,SPF_HELO_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from libero.it (smtp-16.italiaonline.it [213.209.10.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E04CE808E0 for ; Wed, 3 Jun 2020 15:36:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=libero.it Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=dariobin@libero.it Received: from localhost.localdomain ([185.33.57.41]) by smtp-16.iol.local with ESMTPA id gTZUjU5rbj8kvgTZYjGX5C; Wed, 03 Jun 2020 15:36:48 +0200 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1591191408; bh=RDjo4Wiph1OXcz3bCYyE/fodN0K8/ZhmboEH59V7OVw=; h=From; b=FLY+Gub661P9b3nqLMLiS3DmrNQxHcwRNsHJ8M8Bu/eWrYnWE3HukDDO0tMdS2xyw 2OQBnLd3cgNvKGdRWYi94BKi88+AXWTDv8sUelx0HClb8QqBbDT3IhCzW+RIG3R/rm v5n97TF78dm2VZV6N5wDJzvzaGzFBLzBhPF6EySjJ8YwwB5DHMm1wM61bj15mRytFb 662JB6v3S2MOM2m3jt3oxR7CJ9AMxCfZCs6rIEPw/uCoiFrnjfIss3aFml1xfb47F/ ThBFtb5J9QZUHXnzcE8J2eWL5AWF7Qs03VbK1RWdghMcD4LB1HU+pozWIB+wrkXusZ GwzLvphh8hkCg== X-CNFS-Analysis: v=2.3 cv=V9gDLtvi c=1 sm=1 tr=0 a=7k5bMzoTbf4q2w+SfadHRQ==:117 a=7k5bMzoTbf4q2w+SfadHRQ==:17 a=g-850U7pSUD1QzQCJlwA:9 a=7Zwj6sZBwVKJAoWSPKxL6X1jA+E=:19 From: Dario Binacchi To: swarren@nvidia.com Cc: u-boot@lists.denx.de, dariobin@libero.it Subject: [PATCH 1/1] clk: ccf: mux: change the get_rate helper Date: Wed, 3 Jun 2020 15:36:25 +0200 Message-Id: <20200603133625.6597-1-dariobin@libero.it> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfEAckQUirnbRh0AVKZYGJ0etOQEexr6y8TVj7yqjCrr85VZOK7MrRiL0+/kh4TCZveQPUVLO29xSqYFdFyH9ad8p85FUGKLf3m2Z1xvp6nODadKt5fJ+ UkOGm4n10lpE9MCq/6d92Qm5hYhq1S8C0uW0E+n/J0kWzz6m1hR+APKrdP8h2HR+aCgwIgkpfKWFvs7XmTJYtidbJreogbCn31X44B+u26MiPseeesw0yVQ4 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean The previous version of the get_rate helper does not work if the mux clock parent is changed after the probe. This error has not been detected because this condition has not been tested. The error occurs because the set_parent helper does not change the parent of the clock device but only the clock selection register. Since changing the parent of a probed device can be tricky, the new version of the get_rate helper provides the rate of the selected clock and not that of the parent. Signed-off-by: Dario Binacchi --- drivers/clk/clk-mux.c | 26 +++++++++++++++++++++++++- test/dm/clk_ccf.c | 24 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c index 8f85e84ae9..1f2dab647f 100644 --- a/drivers/clk/clk-mux.c +++ b/drivers/clk/clk-mux.c @@ -152,8 +152,32 @@ static int clk_mux_set_parent(struct clk *clk, struct clk *parent) return 0; } +static ulong clk_mux_get_rate(struct clk *clk) +{ + struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ? + dev_get_clk_ptr(clk->dev) : clk); + struct udevice *parent; + struct clk *pclk; + int err, index; + + index = clk_mux_get_parent(clk); + if (index >= mux->num_parents) + return -EFAULT; + + err = uclass_get_device_by_name(UCLASS_CLK, mux->parent_names[index], + &parent); + if (err) + return err; + + pclk = dev_get_clk_ptr(parent); + if (!pclk) + return -ENODEV; + + return clk_get_rate(pclk); +} + const struct clk_ops clk_mux_ops = { - .get_rate = clk_generic_get_rate, + .get_rate = clk_mux_get_rate, .set_parent = clk_mux_set_parent, }; diff --git a/test/dm/clk_ccf.c b/test/dm/clk_ccf.c index ae3a4d8a76..bf99776ac1 100644 --- a/test/dm/clk_ccf.c +++ b/test/dm/clk_ccf.c @@ -46,6 +46,18 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) rate = clk_get_parent_rate(clk); ut_asserteq(rate, 60000000); + rate = clk_get_rate(clk); + ut_asserteq(rate, 60000000); + + ret = clk_get_by_id(SANDBOX_CLK_PLL3_80M, &pclk); + ut_assertok(ret); + + ret = clk_set_parent(clk, pclk); + ut_assertok(ret); + + rate = clk_get_rate(clk); + ut_asserteq(rate, 80000000); + ret = clk_get_by_id(SANDBOX_CLK_USDHC2_SEL, &clk); ut_assertok(ret); ut_asserteq_str("usdhc2_sel", clk->dev->name); @@ -56,6 +68,18 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) pclk = clk_get_parent(clk); ut_asserteq_str("pll3_80m", pclk->dev->name); + rate = clk_get_rate(clk); + ut_asserteq(rate, 80000000); + + ret = clk_get_by_id(SANDBOX_CLK_PLL3_60M, &pclk); + ut_assertok(ret); + + ret = clk_set_parent(clk, pclk); + ut_assertok(ret); + + rate = clk_get_rate(clk); + ut_asserteq(rate, 60000000); + /* Test the composite of CCF */ ret = clk_get_by_id(SANDBOX_CLK_I2C, &clk); ut_assertok(ret);