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=-15.8 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 B0068C433EF for ; Sat, 11 Sep 2021 17:21:06 +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 1875460FE6 for ; Sat, 11 Sep 2021 17:21:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1875460FE6 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 4F4EB83838; Sat, 11 Sep 2021 19:20:46 +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="CaOknn5d"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 24B118382E; Sat, 11 Sep 2021 19:20:34 +0200 (CEST) Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) (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 6E0AC83835 for ; Sat, 11 Sep 2021 19:20:17 +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-qv1-xf2f.google.com with SMTP id w8so3436118qvt.0 for ; Sat, 11 Sep 2021 10:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SmR49mkuHexYgD16TKvu0pvgPOXm3FnLkfDB8Wjw8bE=; b=CaOknn5dI7eyF38ilK2l2Yz8nC/RZyno+NfPBrmFuoFFh9Zm7pq4SK2N7hptJM6BUQ R+XlDaLmzRW40kQaUW9lCKYJ/GAOoCHthSyNMZZGn06tl00N8UvFMecnNjfyQJwzN+b7 /rXktufm70kQqZ/uFa49UyUNm3Z9O/+UnYJS9AvAvFECyfKCLy9+6P+qUTauPEX12spa IEu2zV9lVeMUDZXvgJpO6co4tHVkgYalw3eS2xjO+nz6qkTbMfJrySx2Z3Pfa/8yuXJz 5h4UsIvkNyLbtYSFAWwQfdndyqD4URpljsuSmbTAsAodH2ZwWd8isHmBpSaWnTcqurV8 UGDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SmR49mkuHexYgD16TKvu0pvgPOXm3FnLkfDB8Wjw8bE=; b=OhnwdLsXEeETECKBbWy81zizzWuPpB8KQW/ZlDwi1eqRWJ+pdItM/PmdgrusUsF62j OpC+nzRy21k5HmCFt0kbzZ6EAs4iRsnPg+8PUOv3w8PR6W7UAT1usZOVmOa91LVK0Qvl LHUjfazh6HXFIABKdzq2HUCYcNYnEiObyzN4DFhGDe8+0wMx2+awARMwOGxZLvBqbgCm QA3F3MxbzX4Me2UkfnHGpeXlV5sUpU1Ak5dxrVCBp5awwKU7kKE37Pyg8QJf3/jNkmtV lizrEn3B+/aTXRVUxmN6GOEbsBQ0F5v37cssU2XRBa14nPFsFQzDBD4w/PdyTlHobsR6 uS2g== X-Gm-Message-State: AOAM5310fTZIwKPil6M/usC6jWU+PbeL+oZtI6lmkPn7SlWaENbpb1i6 s+RSjNDZ33WCyRR+YTOIUGjKWadzJcM= X-Google-Smtp-Source: ABdhPJxUnOHFCcja6t7RysPLqZCFjFIJmSSIoPGge7KJyqgHAzcm7wTC2pVnAyb6TPMA2mJcCWuOdQ== X-Received: by 2002:a0c:a88a:: with SMTP id x10mr2953872qva.66.1631380816119; Sat, 11 Sep 2021 10:20:16 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-45-127-224.washdc.fios.verizon.net. [108.45.127.224]) by smtp.gmail.com with ESMTPSA id d12sm1295669qtq.61.2021.09.11.10.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 10:20:15 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de, Leo Liang Cc: Bin Meng , Damien Le Moal , Lukasz Majewski , Sean Anderson , Simon Glass Subject: [PATCH v2 4/4] clk: k210: Try harder to get the best config Date: Sat, 11 Sep 2021 13:20:03 -0400 Message-Id: <20210911172003.899301-4-seanga2@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210911172003.899301-1-seanga2@gmail.com> References: <20210911172003.899301-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 --- (no changes since v1) 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 69691c4a04..97efda5b6f 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.33.0