Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3511466pxb; Mon, 4 Apr 2022 19:21:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAI+yDoTtQpq/B7vmPS0nof9k7GQfX/sse3zP/Z3hpRCcVHfUKxAG7lqLy3kod3hyAvLoO X-Received: by 2002:a63:c015:0:b0:385:fe06:eb86 with SMTP id h21-20020a63c015000000b00385fe06eb86mr968728pgg.132.1649125309942; Mon, 04 Apr 2022 19:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649125309; cv=none; d=google.com; s=arc-20160816; b=QJLZJVBga7nY9N5WSB0yNwADFIvLxECfgEetWVuyRRJmzEYNDdWTneKwX5b386Gn7P 66BhfZZBz7sLIqVA/L8/1MPX0AgkCqzFR87p6+skfemNLUUvNOoODcSK5r8Z/ABr/p4W A7MXhTe4AypP5c83ieNkFxN3ztqRpAs5Lch0xyi3FL9QkT4++GFDlZcHVcahVeqal5jN jb5006QG140CdNbu19laYj5pEMn+3i+dz8zSX/uBbfQM8SsxGEEe/eepeTKsEIrSn5dq 7CRNYOj/B4e7YybJKsvd71+cTzsw7PH1VE3IinB9GiDj+T15BUFB4plRK0qkcmRA0jMk qGCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=LpwuEfIs2cgjcVOl0/eZAJ55mes8AUF/9lxT/njPa6s=; b=nd8/CYcV+UTIzzrrirjDInREVbTfF4nERkv6LCBOyWk3t/ApbG2eMp0Km4xcVE6DUF 5aJb0MM2CBHH1syyghNGTt/DU5ulBTGB2uR4oUCxraRUXmvGcqiL5gSJhRcHunFnSAtS uz1lKKFmeoZMTzDHkW7YPQ4VjWM1AG8Y6eukUTD+px99h5tLsReHG4WrqMzwN5FFFnTz kzr5kXY5tP/pUIhpLUraRSYietJ+heqwG8XCR80fgKiO8RM8HV0IR9u7jW6TDi+G1qBJ p6HdwYu1bQl3++V56sNcxTPv5rotWC37zwHmOZIIuWxahCUj4YrcDpyWdqacgk5gBIyb 8jrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=xlM7j3wu; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=MRSh4tzI; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s10-20020a056a0008ca00b004fe3a6f4b19si1408508pfu.152.2022.04.04.19.21.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 19:21:49 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=xlM7j3wu; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=MRSh4tzI; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5DC372AD098; Mon, 4 Apr 2022 17:43:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347791AbiDDMxz (ORCPT + 99 others); Mon, 4 Apr 2022 08:53:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238402AbiDDMxx (ORCPT ); Mon, 4 Apr 2022 08:53:53 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFC0F6272; Mon, 4 Apr 2022 05:51:57 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4FA4C1F383; Mon, 4 Apr 2022 12:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1649076716; 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=LpwuEfIs2cgjcVOl0/eZAJ55mes8AUF/9lxT/njPa6s=; b=xlM7j3wuVAXjLaFbvkQYvTRMZCdZ//+Ilkj1a20gP1I1M9bak5V7MPL8nxOhBAotnvfOCL sey7BXCtH2TL8uCcmT9SVnIDflznC0ACgd7H6Ccc43YrW3kHM8fH43/Pm8exxPBxjHOkgp j2DLIldBOJ6bb2ZwqcxOsYy7AuMDiss= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1649076716; 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=LpwuEfIs2cgjcVOl0/eZAJ55mes8AUF/9lxT/njPa6s=; b=MRSh4tzIp4uV7H/grQTZ5TpXRgcVOEALU5NtzUk/IMb3RSpdf7AxeT8WNU+dNPupOL9Vn+ 1V8TL+pdcnEjgcBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 25D8412FC5; Mon, 4 Apr 2022 12:51:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id h+b6COzpSmJ5DQAAMHmgww (envelope-from ); Mon, 04 Apr 2022 12:51:56 +0000 From: "Ivan T. Ivanov" To: Michael Turquette , Stephen Boyd , Nicolas Saenz Julienne , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: "Ivan T. Ivanov" , Phil Elwell , kernel test robot , linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v2] clk: bcm2835: Round UART input clock up Date: Mon, 4 Apr 2022 15:51:13 +0300 Message-Id: <20220404125113.80239-1-iivanov@suse.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The UART clock is initialised to be as close to the requested frequency as possible without exceeding it. Now that there is a clock manager that returns the actual frequencies, an expected 48MHz clock is reported as 47999625. If the requested baudrate == requested clock/16, there is no headroom and the slight reduction in actual clock rate results in failure. If increasing a clock by less than 0.1% changes it from ..999.. to ..000.., round it up. This is reworked version of a downstream fix: https://github.com/raspberrypi/linux/commit/ab3f1b39537f6d3825b8873006fbe2fc5ff057b7 Cc: Phil Elwell Signed-off-by: Ivan T. Ivanov --- Changes since v1 Make bcm2835_clock_round() static to fix following warning when compiling for riscv: drivers/clk/bcm/clk-bcm2835.c:997:15: warning: no previous prototype for 'bcm2835_clock_round' [-Wmissing-prototypes] Reported-by: kernel test robot drivers/clk/bcm/clk-bcm2835.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c index 3ad20e75fd23..c29b643d1bf5 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c @@ -502,6 +502,8 @@ struct bcm2835_clock_data { bool low_jitter; u32 tcnt_mux; + + bool round_up; }; struct bcm2835_gate_data { @@ -992,12 +994,30 @@ static long bcm2835_clock_rate_from_divisor(struct bcm2835_clock *clock, return temp; } +static unsigned long bcm2835_clock_round(unsigned long clk) +{ + unsigned long scaler; + + /* + * If increasing a clock by less than 0.1% changes it + * from ..999.. to ..000.., round up. + */ + scaler = 1; + while (scaler * 100000 < clk) + scaler *= 10; + if ((clk + scaler - 1) / scaler % 1000 == 0) + clk = (clk / scaler + 1) * scaler; + + return clk; +} + static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw, unsigned long parent_rate) { struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw); struct bcm2835_cprman *cprman = clock->cprman; const struct bcm2835_clock_data *data = clock->data; + unsigned long rate; u32 div; if (data->int_bits == 0 && data->frac_bits == 0) @@ -1005,7 +1025,12 @@ static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw, div = cprman_read(cprman, data->div_reg); - return bcm2835_clock_rate_from_divisor(clock, parent_rate, div); + rate = bcm2835_clock_rate_from_divisor(clock, parent_rate, div); + + if (data->round_up) + rate = bcm2835_clock_round(rate); + + return rate; } static void bcm2835_clock_wait_busy(struct bcm2835_clock *clock) @@ -2142,7 +2167,8 @@ static const struct bcm2835_clk_desc clk_desc_array[] = { .div_reg = CM_UARTDIV, .int_bits = 10, .frac_bits = 12, - .tcnt_mux = 28), + .tcnt_mux = 28, + .round_up = true), /* TV encoder clock. Only operating frequency is 108Mhz. */ [BCM2835_CLOCK_VEC] = REGISTER_PER_CLK( -- 2.26.2