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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 65BB5C4338F for ; Tue, 27 Jul 2021 03:52:33 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DCB6761078 for ; Tue, 27 Jul 2021 03:52:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DCB6761078 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5F1A383428; Tue, 27 Jul 2021 05:52:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="VD+BVHiu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7BDFA8334E; Tue, 27 Jul 2021 05:52:06 +0200 (CEST) Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E500883392 for ; Tue, 27 Jul 2021 05:51:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x72f.google.com with SMTP id t66so11174429qkb.0 for ; Mon, 26 Jul 2021 20:51:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GjZhm1v0prSx8zbJhXLQeqRt780MTwtU1DOHzLuxo3s=; b=VD+BVHiuULOgfgoNT7+kwSmDubejTYna36O3IQme9r4k904nSDrNwgzDPx8HeWKQzO AKQPRtGmMRfr8RdSqt7fUAiBqMgnzbXc1BTPSaI1Gn0rUvV9DZYCR8DiZTYzDp6oLkKM DTF92nweF0QPqO2K9cfjNyqgxCKs5si+uU+aZD2Vvoefd6/mj4AwQcSH3OtG/w/kd8Bb YxsDD1jXv8CRW+BI8VR3RSyKjM4cokQZibG7SparZusMblAxmo+UzRLSYGWEuSJj+mfY c/zqozfnp0/Uc24sV3zJs+wPsfki+kR/+7AOXX2GqA9Lmis4qeUEiz8aifZFVW+fl85v kuyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GjZhm1v0prSx8zbJhXLQeqRt780MTwtU1DOHzLuxo3s=; b=oMV+JRJC7QJMzQdUrgKff9qFvbXWenNa8czpPcoiWLSiAOqxt+svnIettfZJnWUhp7 Eq8stbH2yev0IiGv8E+eIfyIjiWRZwWzcvqRlb79zYmuJniNX7Z67Btyd1iiGPmW0Glg yHIb/bbV8SrwRhAdyk+K0/uLcpwxiUuZ0TPOdXm8nTvKUIFj66kYL1x70vKejq4Sg+yo VNnGfmmnTil9ugfRlzBn8/w5qMRTo/CJiqK+NA147bK7Bc7QUZJUAdDZDXd/APZciwas MlC4rMeGBmX6/LJyzU/eSg/aARMr4xRauVKEFLmYQOu3IW4cdKD67QfEcdPZtoMLjqIW d6YQ== X-Gm-Message-State: AOAM5331fCRCx6Aw0rcHUZg0iI7IOZfmmetyGklY6HLjQL9aIzoF4Srg sTI4JJbRxpxTu/7IDI3YOPu/JcdNIdg= X-Google-Smtp-Source: ABdhPJxvAtYlvlO/wn71ejeeYsVGJdt1IkFLg95Sw28dFILTDJAtIdPtTUwRYrWDwPP7aYOz6bZy8g== X-Received: by 2002:a05:620a:7d3:: with SMTP id 19mr20183294qkb.351.1627357910717; Mon, 26 Jul 2021 20:51:50 -0700 (PDT) Received: from godwin.fios-router.home (pool-74-96-87-9.washdc.fios.verizon.net. [74.96.87.9]) by smtp.gmail.com with ESMTPSA id y67sm1096211qkd.58.2021.07.26.20.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 20:51:50 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de, Leo Liang Cc: Lukasz Majewski , Damien Le Moal , Sean Anderson , Simon Glass Subject: [PATCH 4/4] clk: k210: Try harder to get the best config Date: Mon, 26 Jul 2021 23:51:44 -0400 Message-Id: <20210727035144.298277-4-seanga2@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210727035144.298277-1-seanga2@gmail.com> References: <20210727035144.298277-1-seanga2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean In some cases, the best config cannot be used because the VCO would be out-of-spec. In these cases, we may need to try a worse combination of r/od in order to find the best representable config. This also adds a few test cases to catch this and other (possible) unlikely errors. Signed-off-by: Sean Anderson --- drivers/clk/clk_kendryte.c | 24 ++++++++++++++++++++++++ test/dm/k210_pll.c | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/drivers/clk/clk_kendryte.c b/drivers/clk/clk_kendryte.c index d2cee2cf97..e90550ef33 100644 --- a/drivers/clk/clk_kendryte.c +++ b/drivers/clk/clk_kendryte.c @@ -816,6 +816,30 @@ again: i--; } + /* + * Try looking back to see if there is a worse ratio + * that we could try anyway + */ + while (i > 0) { + i--; + new_r = UNPACK_R(factors[i]); + new_od = UNPACK_OD(factors[i]); + /* + * Don't loop over factors for the same product + * to avoid getting stuck because of the above + * clause + */ + if (r * od != new_r * new_od) { + if (new_r * new_od > last_r * last_od) { + r = new_r; + od = new_od; + swapped = false; + goto again; + } + break; + } + } + /* We ran out of things to try */ continue; } diff --git a/test/dm/k210_pll.c b/test/dm/k210_pll.c index 5574ac96fa..f55379f336 100644 --- a/test/dm/k210_pll.c +++ b/test/dm/k210_pll.c @@ -84,6 +84,10 @@ static int dm_test_k210_pll(struct unit_test_state *uts) compare(400000000, 26000000); compare(27000000, 26000000); compare(26000000, 27000000); + compare(13300000 * 64, 13300000); + compare(21250000, 21250000 * 70); + compare(21250000, 1750000000); + compare(1750000000, 1750000000); return 0; } -- 2.32.0