From patchwork Thu Oct 13 20:34:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michal_Such=C3=A1nek?= X-Patchwork-Id: 1689762 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=tylhdnjk; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=beHDE+aV; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MpLq96ZQkz23jc for ; Fri, 14 Oct 2022 07:34:45 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6EB4E84E89; Thu, 13 Oct 2022 22:34:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="tylhdnjk"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="beHDE+aV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 862BC8455E; Thu, 13 Oct 2022 22:34:37 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6BA0A84E8D for ; Thu, 13 Oct 2022 22:34:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=msuchanek@suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 3171C1F895; Thu, 13 Oct 2022 20:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1665693271; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ui9vER+xK2aPoKI9J3AXSgZccGNqGtoPVpsH6rKfFB0=; b=tylhdnjkHxY5jlm3FWnIBVZEZlpBMi7oX7mxMaIG9xO1LDVKNP/s5+qC67vgnJw7qGHDL9 rG3Meh5rTKoULW+D0YcSQkzyTCd+CZkmtYmW7IU5X3LFQXA1AnvSM2hhTrMuzBhDEIDREf q81Ujkyi/J54C525f88ogCi+t8gb72Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1665693271; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ui9vER+xK2aPoKI9J3AXSgZccGNqGtoPVpsH6rKfFB0=; b=beHDE+aVHXxEGG7CeO26XyGbKiYQHLZwGlTG3qHFZ7i/vQwP6lVvXe16DIbxkPwb/ZKlOv 2dqx76NYfhe/N8BQ== Received: from naga.suse.cz (unknown [10.100.224.114]) by relay2.suse.de (Postfix) with ESMTP id 01F742C141; Thu, 13 Oct 2022 20:34:30 +0000 (UTC) From: Michal Suchanek To: u-boot@lists.denx.de Cc: Michal Suchanek , Lukasz Majewski , Sean Anderson , Simon Glass Subject: [PATCH] clk: k210: Fix error calculation on 32bit Date: Thu, 13 Oct 2022 22:34:29 +0200 Message-Id: <20221013203429.15200-1-msuchanek@suse.de> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean k210 is 64bit but the driver and tests are also built in sandbox, and that can be built 32bit. BIT(32) does not work on 32bit, shift before subtraction to fit into 32bit integer with BIT values. Signed-off-by: Michal Suchanek --- drivers/clk/clk_k210.c | 2 +- test/dm/k210_pll.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk_k210.c b/drivers/clk/clk_k210.c index 1961efaa5e..e85f8ae14a 100644 --- a/drivers/clk/clk_k210.c +++ b/drivers/clk/clk_k210.c @@ -846,7 +846,7 @@ again: error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16)); if (error < best_error) { best->r = r; diff --git a/test/dm/k210_pll.c b/test/dm/k210_pll.c index a0cc84c396..622b1c9bef 100644 --- a/test/dm/k210_pll.c +++ b/test/dm/k210_pll.c @@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate, u32 rate_in, error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16)); if (error < best_error) { best->r = r; best->f = f;