From patchwork Tue Jul 27 03:51:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1510271 X-Patchwork-Delegate: uboot@andestech.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=H1ToacIJ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4GYjXg1L7Wz9sPf for ; Tue, 27 Jul 2021 13:52:03 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 460BC832DC; Tue, 27 Jul 2021 05:51:57 +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="H1ToacIJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A847D832DC; Tue, 27 Jul 2021 05:51:55 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) (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 EEE9083358 for ; Tue, 27 Jul 2021 05:51:49 +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-xf29.google.com with SMTP id x12so2757827qvo.12 for ; Mon, 26 Jul 2021 20:51:49 -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:mime-version :content-transfer-encoding; bh=0RO9Qj+feYxKJhIMiF6BY7XJAybF43IxFxBkbYSx4xc=; b=H1ToacIJSgiEVKYME3IsZGP2AArA1TFFz/+KoIj3DieQTchAFk2XsGyzL/x85h6js1 xeEX+BhV6DOyAugt9gcPf46cPU6j+TuifTYmVqpHtSFlWbMdJZdsSEseDCtytB6UZUi2 +HF5OSjegQhsij8trPg4/TaZ5U2X1op/BPxGS+bT4+kVfK+VMEcioSZ6zBGN9L60pTS/ H8urmY50L3TVxN85TGTaeyFPf6jo9+Gm/TOSobZnL0j9WSKyb+c157BGNlV8efa58UH2 wKLR6rYpx1D7YNNsB5z+Gaus1oOEH+8Hd8fThFaKfmXVPDoDyHwxkC0WxPhVSPrv9Tx2 gU0g== 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:mime-version :content-transfer-encoding; bh=0RO9Qj+feYxKJhIMiF6BY7XJAybF43IxFxBkbYSx4xc=; b=huyRAwxPstb5SO46AX59+Ond8lq4BCAJYwkTca9zkGXG7wGI6pO6+St9lTc1Of1F03 iYDpfAhJK6i+7TnObz/XB3AeS01jDwxtXQbnGNoDxMJp4B1d7UoGlXVuv5b6FuJC1/H+ sDiltsrRcGbb8UeE92gJ364GwoQlkXk6bMOoxt5QWvAajEBIIs/84EaQxdOPF3SPQitA 5wUQ0YZ77/Wi7BeaH/6OqKPkxyyHoUVVgl+k2eFnaVly+6lp8PUIE8zoA0ircRJj7zAz SPn9RPhrs4D9G9etW0AUVuH0vDeK/pvZ1KpOTGaU+CGWhS2XyPNlk1LxAr1N2+/yMF83 Fdpw== X-Gm-Message-State: AOAM530QkNyd1aATO2F905NshnYeZtT6zxgi6cEMh1RKMUe9BGQ7g9ZX 6kYmpaiR8q3tYsapoqgICa8zK7Qn27Y= X-Google-Smtp-Source: ABdhPJxhBxJLCagaaF/6leM4PUs761XMgasjtC/jb5ecv3LFIOcDZWXIAUIxSBqU5DNfo8lRwRO9fQ== X-Received: by 2002:a05:6214:1303:: with SMTP id a3mr21065140qvv.49.1627357908485; Mon, 26 Jul 2021 20:51:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 20:51:48 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de, Leo Liang Cc: Lukasz Majewski , Damien Le Moal , Sean Anderson , Coverity Scan Subject: [PATCH 1/4] clk: k210: Fix checking if ulongs are less than 0 Date: Mon, 26 Jul 2021 23:51:41 -0400 Message-Id: <20210727035144.298277-1-seanga2@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 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 Some clock functions return ulong but still have "negative" errors. To deal with this, cast the relevant arguments to long. Fixes: 609bd60b94 ("clk: k210: Rewrite to remove CCF") Reported-by: Coverity Scan Signed-off-by: Sean Anderson --- drivers/clk/clk_kendryte.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/clk/clk_kendryte.c b/drivers/clk/clk_kendryte.c index 3148756968..37bd624eca 100644 --- a/drivers/clk/clk_kendryte.c +++ b/drivers/clk/clk_kendryte.c @@ -439,7 +439,7 @@ static const struct k210_clk_params k210_clks[] = { #ifdef CONFIG_CLK_K210_SET_RATE static int k210_pll_enable(struct k210_clk_priv *priv, int id); static int k210_pll_disable(struct k210_clk_priv *priv, int id); -static ulong k210_pll_get_rate(struct k210_clk_priv *priv, int id, ulong rate_in); +static ulong k210_pll_get_rate(struct k210_clk_priv *priv, int id, long rate_in); /* * The PLL included with the Kendryte K210 appears to be a True Circuits, Inc. @@ -841,7 +841,7 @@ TEST_STATIC int k210_pll_calc_config(u32 rate, u32 rate_in, } static ulong k210_pll_set_rate(struct k210_clk_priv *priv, int id, ulong rate, - ulong rate_in) + long rate_in) { int err; const struct k210_pll_params *pll = &k210_plls[id]; @@ -890,7 +890,7 @@ static ulong k210_pll_set_rate(struct k210_clk_priv *priv, int id, ulong rate, #endif /* CONFIG_CLK_K210_SET_RATE */ static ulong k210_pll_get_rate(struct k210_clk_priv *priv, int id, - ulong rate_in) + long rate_in) { u64 r, f, od; u32 reg = readl(priv->base + k210_plls[id].off); From patchwork Tue Jul 27 03:51:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1510272 X-Patchwork-Delegate: uboot@andestech.com 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; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=DvuyGmp/; 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 4GYjXv1tncz9sPf for ; Tue, 27 Jul 2021 13:52:15 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2741983358; Tue, 27 Jul 2021 05:52:10 +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="DvuyGmp/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DBDA883417; Tue, 27 Jul 2021 05:51:59 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) (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 9A73B8334E for ; Tue, 27 Jul 2021 05:51:50 +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-x732.google.com with SMTP id b20so11137861qkj.3 for ; Mon, 26 Jul 2021 20:51:50 -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=uO0RYPNlCEXdVYSfiBQJr4Hf2D59ePxQEWV6RiRM58I=; b=DvuyGmp/R4F/+3E7Ol9xSN7syHoDRyFNAVj2/jUtDqzDx2bCpJKDOP7D2DfM5+MFi+ 5MJPlh/Ghq2uN9LWb1AFeYZYzhkDE3LvKrACdJrvMHkVxTJomXOCX8dRPsxkzDGpCdgY vsKiE59SN9M+Gfwy4zR8j+5U1v3nsgSWDI22qD2QLZpzA7sIOfl+ZW4Q9mKcAYftUpOT 1Tcop3qBxgJ24LX6o30oeW/PLLS/QnK1hzittWxxHg5+NxleDfdkVYHbIbIAaRG34uID XVR+vQOdwKoYv6tm3ykZF29eR2VkgSzX7QoVPNnagGC9t1tzv9iIPgCqu/m8bNry1NG0 pCvA== 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=uO0RYPNlCEXdVYSfiBQJr4Hf2D59ePxQEWV6RiRM58I=; b=Nqmq3HRR2WdBoKkIiRYb9uPAxpR8uGIvJ09JJM+ht/x6dJtpHWUNeL4L5sKcDGb2Yu uWYmRdZIAqAO47I4QyMgVfwZXonc42I3vvHAMmHxMByc1Nn+V2AGOZivoHWOGIREKfRP 3ELmjK+A9fW6M3A82FUNYlFIImFRhtZ5F15xHiatSvG4Yzhtif3W+aRMIDp3rR4Z3btF i9O0nZPGU54k1P9cuxJN0mo508zkP2TGxh6znPWOR1GpvIiS6MFDJnBoh6aGpq4np0oZ wg3SMge1wEBOyGdupuCPhRr9UaD6VoQcqIqL3vYJXX22Q9vP48ZO/1rsTF/6Mzf/OsVo /jxg== X-Gm-Message-State: AOAM533KPxh59WsURkLKghVZ++d9g/mrze8fJdH09EAp+2rP2NesNNeA sm9lLe4RERoqaeQz1iyvJfKdTtzGrd0= X-Google-Smtp-Source: ABdhPJxO4/siBKEr00+oiWe0Iev4Gp+DV0ScFGdW1FYtkMk2yOiy7qlu+TF66NypHzXGkgOBGZ8bDg== X-Received: by 2002:ae9:e109:: with SMTP id g9mr20811925qkm.95.1627357909219; Mon, 26 Jul 2021 20:51:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 20:51:48 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de, Leo Liang Cc: Lukasz Majewski , Damien Le Moal , Sean Anderson Subject: [PATCH 2/4] k210: clk: Refactor out_of_spec tests Date: Mon, 26 Jul 2021 23:51:42 -0400 Message-Id: <20210727035144.298277-2-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 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 Everything here sits in a while (true) loop. However, this introduces a couple of layers of indentation. We can simplify the code by introducing a single goto instead of using continue/break. This will also make adding loops in the next patch easier. Signed-off-by: Sean Anderson --- drivers/clk/clk_kendryte.c | 105 ++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/drivers/clk/clk_kendryte.c b/drivers/clk/clk_kendryte.c index 37bd624eca..d2cee2cf97 100644 --- a/drivers/clk/clk_kendryte.c +++ b/drivers/clk/clk_kendryte.c @@ -709,6 +709,10 @@ TEST_STATIC int k210_pll_calc_config(u32 rate, u32 rate_in, * Whether we swapped r and od while enforcing frequency limits */ bool swapped = false; + /* + * Whether the intermediate frequencies are out-of-spec + */ + bool out_of_spec; u64 last_od = od; u64 last_r = r; @@ -767,76 +771,71 @@ TEST_STATIC int k210_pll_calc_config(u32 rate, u32 rate_in, * aren't in spec, try swapping r and od. If everything is * in-spec, calculate the relative error. */ - while (true) { +again: + out_of_spec = false; + if (r > max_r) { + out_of_spec = true; + } else { /* - * Whether the intermediate frequencies are out-of-spec + * There is no way to only divide once; we need + * to examine the frequency with and without the + * effect of od. */ - bool out_of_spec = false; + u64 vco = DIV_ROUND_CLOSEST_ULL(rate_in * f, r); - if (r > max_r) { + if (vco > 1750000000 || vco < 340000000) out_of_spec = true; - } else { - /* - * There is no way to only divide once; we need - * to examine the frequency with and without the - * effect of od. - */ - u64 vco = DIV_ROUND_CLOSEST_ULL(rate_in * f, r); + } - if (vco > 1750000000 || vco < 340000000) - out_of_spec = true; + if (out_of_spec) { + u64 new_r, new_od; + + if (!swapped) { + u64 tmp = r; + + r = od; + od = tmp; + swapped = true; + goto again; } - if (out_of_spec) { - if (!swapped) { - u64 tmp = r; - - r = od; - od = tmp; - swapped = true; - continue; - } else { - /* - * Try looking ahead to see if there are - * additional factors for the same - * product. - */ - if (i + 1 < ARRAY_SIZE(factors)) { - u64 new_r, new_od; - - i++; - new_r = UNPACK_R(factors[i]); - new_od = UNPACK_OD(factors[i]); - if (r * od == new_r * new_od) { - r = new_r; - od = new_od; - swapped = false; - continue; - } - i--; - } - break; + /* + * Try looking ahead to see if there are additional + * factors for the same product. + */ + if (i + 1 < ARRAY_SIZE(factors)) { + i++; + new_r = UNPACK_R(factors[i]); + new_od = UNPACK_OD(factors[i]); + if (r * od == new_r * new_od) { + r = new_r; + od = new_od; + swapped = false; + goto again; } + i--; } - error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); - /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + /* We ran out of things to try */ + continue; + } - if (error < best_error) { - best->r = r; - best->f = f; - best->od = od; - best_error = error; - } - break; + error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); + /* The lower 16 bits are spurious */ + error = abs((error - BIT(32))) >> 16; + + if (error < best_error) { + best->r = r; + best->f = f; + best->od = od; + best_error = error; } } while (f < 64 && i + 1 < ARRAY_SIZE(factors) && error != 0); + log_debug("best error %lld\n", best_error); if (best_error == S64_MAX) return -EINVAL; - log_debug("best error %lld\n", best_error); return 0; } From patchwork Tue Jul 27 03:51:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1510273 X-Patchwork-Delegate: uboot@andestech.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=gv9knttp; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4GYjY55LCfz9sPf for ; Tue, 27 Jul 2021 13:52:25 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 707058341F; Tue, 27 Jul 2021 05:52:13 +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="gv9knttp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E3A068334E; Tue, 27 Jul 2021 05:52:03 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) (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 2E8228335E 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-qv1-xf31.google.com with SMTP id s14so6277838qvm.4 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=3l8I/xTP7CUoTABz9s50gz1Qg4ubiaMlSqnli5kik7M=; b=gv9knttpG43J+n6xOFn4+xP5V26ZsdzkyB1soJNIqhln7HFaxZMOE6ntTYVOtDFyI9 XU1Wy9VDw3e7tXIynGD4Ig2xfM0A1RAdZNRgoaYoGhVJqnn0krdcOW9G86VqsjxT60fx mPDU9lfxHeQ56Mpc6bMF4gzrBz1iZY59hsfzGuDyooMazREkRb/KG6ZkFB3oFLU1jkHf whOD1OlnWOHBo8RuIvxAqzHfry/BUmbBSbZJvn4F9/9iGAoWTFagH0cKgKHsaW9YFKFl ftKyH2VNQEtnOFw2Ef1zLg2cEps2Seg5IDkcHy8MzHqVPYOQsJNzbX1KU/fkjrdYzxNm q47w== 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=3l8I/xTP7CUoTABz9s50gz1Qg4ubiaMlSqnli5kik7M=; b=RZZ+VCRnkF0uTreloOaJXBBAkHY1M7y12If9AR6WLrhWuw4MyyMmd9XDbOUGRVuK9Q VidVyLXgYzSgd22V3qw09bnH2ACO1peebg/7WhBD3tUB0HnEdxHYSHIxRpgz2Ed++7Xo QuSLSii05XiHI6w3aFfVXDt3h8jRSyyNMDBWiCb8KffTh7Zvan53XxKUS9yMd0LrkfAi SJWc4XtX6MlMsn+m4ec+sEluazBMtlZg2qW9uNv8NfMf9+9LyAoOeYmSL7d6sa2xkBpa 0Xat7HcxFO/e+qssUkCkcAgPDgCo4tSryzr0buY+XVyhO3IhHzMEVx4/Yn1mujjVfPht VGBw== X-Gm-Message-State: AOAM533j8vE5W9EYt3aEOBAyjXfwN/W1utrlEb8ykbsuQjcVGRnjVqS0 7/MfJehsiur0o8cZvCqJF+Gl3fyyLwY= X-Google-Smtp-Source: ABdhPJy5YTy4UjhavsE3aJ0KebYh2q+lUgcwwow1FYQfPqYuoLZG0AMM93QKK+yjKqd0Pl47wZmZyA== X-Received: by 2002:a0c:de08:: with SMTP id t8mr3401315qvk.53.1627357909923; Mon, 26 Jul 2021 20:51:49 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 20:51:49 -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 3/4] test: dm: k210: Reduce duplication in test cases Date: Mon, 26 Jul 2021 23:51:43 -0400 Message-Id: <20210727035144.298277-3-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 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 Having to copy-paste the same 3 lines makes adding new test cases error-prone. Use a macro. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- test/dm/k210_pll.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/test/dm/k210_pll.c b/test/dm/k210_pll.c index 54764f269c..5574ac96fa 100644 --- a/test/dm/k210_pll.c +++ b/test/dm/k210_pll.c @@ -69,27 +69,21 @@ static int dm_test_k210_pll(struct unit_test_state *uts) &theirs)); ut_asserteq(-EINVAL, k210_pll_calc_config(1500000000, 20000000, &theirs)); + ut_asserteq(-EINVAL, k210_pll_calc_config(1750000000, 13300000, + &theirs)); /* Verify we get the same output with brute-force */ - ut_assertok(dm_test_k210_pll_calc_config(390000000, 26000000, &ours)); - ut_assertok(k210_pll_calc_config(390000000, 26000000, &theirs)); - ut_assertok(dm_test_k210_pll_compare(&ours, &theirs)); +#define compare(rate, rate_in) do { \ + ut_assertok(dm_test_k210_pll_calc_config(rate, rate_in, &ours)); \ + ut_assertok(k210_pll_calc_config(rate, rate_in, &theirs)); \ + ut_assertok(dm_test_k210_pll_compare(&ours, &theirs)); \ +} while (0) - ut_assertok(dm_test_k210_pll_calc_config(26000000, 390000000, &ours)); - ut_assertok(k210_pll_calc_config(26000000, 390000000, &theirs)); - ut_assertok(dm_test_k210_pll_compare(&ours, &theirs)); - - ut_assertok(dm_test_k210_pll_calc_config(400000000, 26000000, &ours)); - ut_assertok(k210_pll_calc_config(400000000, 26000000, &theirs)); - ut_assertok(dm_test_k210_pll_compare(&ours, &theirs)); - - ut_assertok(dm_test_k210_pll_calc_config(27000000, 26000000, &ours)); - ut_assertok(k210_pll_calc_config(27000000, 26000000, &theirs)); - ut_assertok(dm_test_k210_pll_compare(&ours, &theirs)); - - ut_assertok(dm_test_k210_pll_calc_config(26000000, 27000000, &ours)); - ut_assertok(k210_pll_calc_config(26000000, 27000000, &theirs)); - ut_assertok(dm_test_k210_pll_compare(&ours, &theirs)); + compare(390000000, 26000000); + compare(26000000, 390000000); + compare(400000000, 26000000); + compare(27000000, 26000000); + compare(26000000, 27000000); return 0; } From patchwork Tue Jul 27 03:51:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1510274 X-Patchwork-Delegate: uboot@andestech.com 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; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VD+BVHiu; 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 4GYjYH49Tgz9sPf for ; Tue, 27 Jul 2021 13:52:35 +1000 (AEST) 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) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.2 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 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; }