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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id AB549C433F5 for ; Thu, 17 Mar 2022 12:41:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 67CAD83C2C; Thu, 17 Mar 2022 13:41:42 +0100 (CET) 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="DtoBzAfl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E92EB8301E; Thu, 17 Mar 2022 13:41:39 +0100 (CET) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 CF7B483CD8 for ; Thu, 17 Mar 2022 13:41:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heiko.thiery@gmail.com Received: by mail-wr1-x42c.google.com with SMTP id u16so6186219wru.4 for ; Thu, 17 Mar 2022 05:41:36 -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:mime-version :content-transfer-encoding; bh=/nvXvonukxcwS88h3Zi+lT4chQRDCAnxpvPPp5qZlwE=; b=DtoBzAflnjjLdpdPsg4+I4zcK2sYyeyPnhQIpDaW40QE+tmL7aAATHl/bS2qmLlX3f QA5ZaJkxhP5lc0zWIwVy4swWlBeHUM70yHTJ7Ah4AyW3cG+/BcUwq5gkCLs9sNCuZOeI o9loMLTjmgooIu5lXQUOOHrHO1XjMBD3EvjNiUrMnFKuB0LzrnNx8q2CWnITgRmh62No wQV1sWW8msUZTQXbZPasFZycybBMnYRsHIPz6QZ7hrwEKuUwFRA2gPSYXHVoFRiMze+/ 1OkukJzFCyKyeqVZKKdRpLyta7s1g949PMd/VHJv5SM9CglflIJDNRsaAx+RnvboJWIt figQ== 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:mime-version :content-transfer-encoding; bh=/nvXvonukxcwS88h3Zi+lT4chQRDCAnxpvPPp5qZlwE=; b=CHkurBcg/oar5RSQ0uTjMTSWcmIgTBdWRez9X+A+Po4LPNaSzBJ6EFvlXQtS/T8Z9n lYaOEBB+vxHRa9r/JVqGA2p0gJEsZjn8c3QVBvDBSsy6vUgDQoiR62VL8r5UQXwY1HHc VJldLWNM0/f5XlYPXaSxk7i94KOvOvkqjtT/67LQjW06LBXmNb+hJXv6lMdIsNOdT0u1 R1/ThfWm3876gGIBYCcKttBXC3FKvIN2XnfhGT7JNdqVNOFW7UP+SIri+fN/EUM4c3/a nv25JDIX+3cL102KP18bm1wbEgutghB66s1w+vGQcfMMeWIKAoJlc/89ChoC8nM23UCn n75A== X-Gm-Message-State: AOAM532ItjhGfAGFwFrYy4gDN6rlp8C7BfDSA6mEjb+2nWADPLy6ixJn pIGuuUyiZncKdGXrH9O+pz5ZA+zAcA51oZQK X-Google-Smtp-Source: ABdhPJx40HgtOzoztEC8pkv5Y3aE1Us9hqOfBojPW5yg5qrEkVoI/G0KJwn/gA8DCWg7BDIF4k3TWg== X-Received: by 2002:adf:ce03:0:b0:1f0:62b9:3c7a with SMTP id p3-20020adfce03000000b001f062b93c7amr3925993wrn.102.1647520895732; Thu, 17 Mar 2022 05:41:35 -0700 (PDT) Received: from hthiery.kontron.local ([213.135.10.150]) by smtp.gmail.com with ESMTPSA id bk19-20020a0560001d9300b001a65e479d20sm3883316wrb.83.2022.03.17.05.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 05:41:35 -0700 (PDT) From: Heiko Thiery To: u-boot@lists.denx.de Cc: Marek Vasut , Michale Walle , Angus Ainslie , Angus Ainslie , lukma@denx.de, seanga2@gmail.com, sbabic@denx.de, festevam@gmail.com, uboot-imx@nxp.com, peng.fan@nxp.com, Heiko Thiery Subject: [RFC] serial: mxc: get the clock frequency from the used clock for the device Date: Thu, 17 Mar 2022 13:41:28 +0100 Message-Id: <20220317124127.1783768-1-heiko.thiery@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.5 at phobos.denx.de X-Virus-Status: Clean With the clock driver enabled for the imx8mq, it was noticed that the frequency used to calculate the baud rate is always taken from the root clock of UART1. This can cause problems if UART1 is not used as console and the settings are different from UART1. The result is that the console output is garbage. To do this correctly the UART frequency is taken from the used device. For the implementations that don't have the igp clock frequency written or can't return it the old way is tried. Signed-off-by: Heiko Thiery --- drivers/serial/serial_mxc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c index e4970a169b..6fdb2b2397 100644 --- a/drivers/serial/serial_mxc.c +++ b/drivers/serial/serial_mxc.c @@ -3,6 +3,7 @@ * (c) 2007 Sascha Hauer */ +#include #include #include #include @@ -266,9 +267,19 @@ __weak struct serial_device *default_serial_console(void) int mxc_serial_setbrg(struct udevice *dev, int baudrate) { struct mxc_serial_plat *plat = dev_get_plat(dev); - u32 clk = imx_get_uartclk(); + u32 rate = 0; + + if (IS_ENABLED(CONFIG_CLK)) { + struct clk clk; + if(!clk_get_by_name(dev, "ipg", &clk)) + rate = clk_get_rate(&clk); + } + + /* as fallback we try to get the clk rate that way */ + if (rate == 0) + rate = imx_get_uartclk(); - _mxc_serial_setbrg(plat->reg, clk, baudrate, plat->use_dte); + _mxc_serial_setbrg(plat->reg, rate, baudrate, plat->use_dte); return 0; } -- 2.30.2