From patchwork Sat Dec 23 21:38:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10131677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 352ED6019D for ; Sat, 23 Dec 2017 21:39:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28FF728AA0 for ; Sat, 23 Dec 2017 21:39:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C25828AFF; Sat, 23 Dec 2017 21:39:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD17728AA0 for ; Sat, 23 Dec 2017 21:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=siTYOUbnMuQ7ZaWjFoJxDuLLn6QeXSoo86VSqPJg7VY=; b=tE2 gJ4AuPIZbFucPMpGaNdjN7jkL4ockPAmaTkcdw+kPJYW50AAOq1DjZywmI7vZKAHVA6mRTW/pUiYl URlNyJpo99YQXb5W+IByH1mZwWcEhSaNpAMrFN5coDR1WwhSVntzMicoGxFRxiB35PgyTFmZYKukF NXDXcRJ3KzfvZok63fhq5I0NS8mh2fBaKLOUbHK9sZbV1MJAg9yPoxA6iboYX3zQvjWQem/bj9XM9 jpqcp9/aNID89V5iaNUuXBckjPLXKIuBzvL6wOxtJNqaqFHVi/cv5IlE9b1eN0cX0qpMM3pLJhnSf x0ED+0h/MZ/4VM1nIhZTBC8YlG0xKhw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eSrVY-0001va-R0; Sat, 23 Dec 2017 21:39:04 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eSrVV-0001tM-NS for linux-amlogic@lists.infradead.org; Sat, 23 Dec 2017 21:39:03 +0000 Received: by mail-wr0-x243.google.com with SMTP id v21so19911383wrc.0 for ; Sat, 23 Dec 2017 13:38:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=xeZ8Aqs57R8WPMjx3K97xdlQCRF8ptwj2kw6AD3ITbg=; b=GemDQDgPxGJJrYFaJ2VQSvfD+DLKkM69MGyiMR5J82F1qC7Efe9BuG6CCKkmwMZTTV HnKZHlUjDuQVEPurYErNQzrfJNzC16IzWT42Q9GFX5ZZXbwrO3Q4YhcaoaC/WWK5VQzg matxIW4LujbwEtJ8WnxiNXW3grcpcuYo6G2E6b4DBlrYMzPsAhqxnFJSM6abFfY3j/r1 ftdQSBmbMzzU8srCTPqZGQFfH5FfPHsIAZoNtYHZHS5NLiUqyMMj8eeM+ig7aAKA15oe Wv0yAzZ0awWqM8W0qNAO/CCwvzunb6lVywMFMEwGKKQ/vhp/9A5IT4ZxYw4Tlt1xnEA3 Wyrw== 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; bh=xeZ8Aqs57R8WPMjx3K97xdlQCRF8ptwj2kw6AD3ITbg=; b=i15uiJLotVJRrljriZ3HQIJZhha1AajhsjYU9Qyt6cvpgpd+dRa/79WC8Kx24er8p3 1p3pXgOrcNN2XDDfaiqrQJmfYrxrMBNEKH0NKMx4FLynA8YurAadzzw47Qmx3QNiNH4S AuzQpOA8SbzTLT4HX9QJiYFDVSbBQhEhpl1FDIzhxTe+dvyFV1SDPbXdYUE7DudHBiY7 JiEB66BpnVbW1TvedUgG9z6rgnf3YZNlDHI9MxhJMpU6VVBEA8iuI6wTb5X0rkqQzgFm 8hFu9VT0+ZIvWCnUE5EW+XCD7cFbvYbmklZZRWzEOtkR0+QEUqV9FrRSql02CkSMopAX dvow== X-Gm-Message-State: AKGB3mLtbga0d6L05qR8M6zS2RzVoOHhdfIdH44Wvk6ABRRZUPJpqC5q yVu6xheKyK/v1nwb/et005k= X-Google-Smtp-Source: ACJfBosHaLrgA10J43TN73HjSMRuYOAfI/UibptsoWp2TQp8g1ONRcMX920JeQUPCvRm70XziHq57A== X-Received: by 10.223.185.85 with SMTP id b21mr17805464wrg.264.1514065130035; Sat, 23 Dec 2017 13:38:50 -0800 (PST) Received: from blackbox.darklights.net (p200300DCD3DA8504EC6066EA0395CAD7.dip0.t-ipconnect.de. [2003:dc:d3da:8504:ec60:66ea:395:cad7]) by smtp.googlemail.com with ESMTPSA id r64sm36324392wrb.62.2017.12.23.13.38.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Dec 2017 13:38:49 -0800 (PST) From: Martin Blumenstingl To: jbrunet@baylibre.com, narmstrong@baylibre.com, linux-amlogic@lists.infradead.org Subject: [PATCH] clk: meson: mpll: use 64-bit maths in params_from_rate Date: Sat, 23 Dec 2017 22:38:32 +0100 Message-Id: <20171223213832.16552-1-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.15.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171223_133901_786338_68DE877B X-CRM114-Status: UNSURE ( 9.30 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: carlo@caione.org, khilman@baylibre.com, Martin Blumenstingl , linux-clk@vger.kernel.org MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP "rem * SDM_DEN" can easily overflow on the 32-bit Meson8 and Meson8b SoCs if the "remainder" (after the division operation) is greater than 262143Hz. This is likely to happen since the input clock for the MPLLs on Meson8 and Meson8b is "fixed_pll", which is running at a rate of 2550MHz. One example where this was observed to be problematic was the Ethernet clock calculation (which takes MPLL2 as input). When requesting a rate of 125MHz there is a remainder of 2500000Hz. The resulting MPLL2 rate before this patch was 127488329Hz. The resulting MPLL2 rate after this patch is 124999103Hz. Commit b609338b26f5 ("clk: meson: mpll: use 64bit math in rate_from_params") already fixed a similar issue in rate_from_params. Fixes: 007e6e5c5f01d3 ("clk: meson: mpll: add rw operation") Signed-off-by: Martin Blumenstingl --- drivers/clk/meson/clk-mpll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/meson/clk-mpll.c b/drivers/clk/meson/clk-mpll.c index 44a5a535ca63..5144360e2c80 100644 --- a/drivers/clk/meson/clk-mpll.c +++ b/drivers/clk/meson/clk-mpll.c @@ -98,7 +98,7 @@ static void params_from_rate(unsigned long requested_rate, *sdm = SDM_DEN - 1; } else { *n2 = div; - *sdm = DIV_ROUND_UP(rem * SDM_DEN, requested_rate); + *sdm = DIV_ROUND_UP_ULL((u64)rem * SDM_DEN, requested_rate); } }