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 97BF4C433F5 for ; Fri, 18 Mar 2022 02:19:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 101D383CDE; Fri, 18 Mar 2022 03:19:44 +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="F4REiErM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7E28F83CDE; Fri, 18 Mar 2022 03:19:42 +0100 (CET) Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) (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 761D182EBB for ; Fri, 18 Mar 2022 03:19:37 +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=seanga2@gmail.com Received: by mail-qt1-x82b.google.com with SMTP id 10so5921995qtz.11 for ; Thu, 17 Mar 2022 19:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=veO/dQdpASRj9bWFvflA/ErG1t2B5/tLHzyYirNd6/A=; b=F4REiErMNcCA09EHyAgRUNnT63uMKTHt/g6TZB3cDVgDtiXdM16yovmj+8nM9R//x3 4CMkHQuTSphabNj4fPP9/S11kTGCA3kQKFMZlInGz6Grh0BcjFs6+/bInOunMtjZ1Z7+ jF+lEpZbJ1L0UiR9NSXsI1/z4fYF1TlAvvPKCTn2co6EdSrE1naidQ/GsFbk3nzjFbC7 7NkrRKAlOyvCAoxM2XfZ5ILWFAXeD9JD+m5iq9F04KEYmGeYsaACcXbVtZuNkiq3vKl0 4q4PT2UXkYkJ25ZstME/NVw/fMULD2i/Vu5seWysP7d1mtUTjXKglJGjeSLCQ3Rr0mYX nsyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=veO/dQdpASRj9bWFvflA/ErG1t2B5/tLHzyYirNd6/A=; b=E9gpxI5YaW3sszB0lQLC9AIbIIPcsKECKu2FFgnJX8lhxPuIuszE/+q+snrB5s4yDH KlA5KZMDwvkdf+OCN5hmDl2HTaFP6QwULj8RO+h1XdMIpZkzJaI87i0aM/QiCst0cARl PTv1Qlm/MMXhuatuPjXnCbu1p9JTNWqtFqdjMiS1eLYQcgkrsWeo9h4rLmvqQ6BXwIMu 1uUBLnCXXSYOTLXfyrabH+HKL+RQQJwFtH48n5QOI3y4eXKhSJLp5VCcTV0C/K4HjQbo UnK/tHJ3nSs9fd7ZpKu9QjukK+rjV+MlwZ0vAOWrLWui/f8bNv1mo1NShdYR87Zo+iMs 6ATg== X-Gm-Message-State: AOAM530Z6eRcJZ1v/rUtE6v52WJlVc57kG0x3CxZShFccZ2nqxIhF8u5 8t5Lma/3La3b/cxWQwfs/js= X-Google-Smtp-Source: ABdhPJy6UXFH8SOUbTUQYKXj5LH2IyhrcQl2OOljwr1zuzgmnolodBgW53FayfOFJOQKVenygUUAWw== X-Received: by 2002:a05:622a:1745:b0:2e1:c930:e0dc with SMTP id l5-20020a05622a174500b002e1c930e0dcmr5959112qtk.263.1647569976126; Thu, 17 Mar 2022 19:19:36 -0700 (PDT) Received: from [192.168.1.201] (pool-108-18-137-133.washdc.fios.verizon.net. [108.18.137.133]) by smtp.googlemail.com with ESMTPSA id h27-20020a05620a13fb00b0067b3615e4acsm3183238qkl.70.2022.03.17.19.19.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Mar 2022 19:19:35 -0700 (PDT) Subject: Re: [RFC] serial: mxc: get the clock frequency from the used clock for the device To: Heiko Thiery Cc: u-boot@lists.denx.de, Marek Vasut , Michale Walle , Angus Ainslie , Angus Ainslie , lukma@denx.de, sbabic@denx.de, festevam@gmail.com, uboot-imx@nxp.com, peng.fan@nxp.com References: <20220317124127.1783768-1-heiko.thiery@gmail.com> <99e5643a-ade5-655d-937f-ee6ce711a99d@gmail.com> From: Sean Anderson Message-ID: <513bb930-59b5-d42d-70dc-f3e0d57801d8@gmail.com> Date: Thu, 17 Mar 2022 22:19:34 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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 On 3/17/22 3:14 PM, Heiko Thiery wrote: > Hi Sean, >=20 > Am Do., 17. M=C3=A4rz 2022 um 15:38 Uhr schrieb Sean Anderson : >> >> Hi Heiko, >> >> On 3/17/22 8:41 AM, Heiko Thiery wrote: >>> 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 ro= ot >>> clock of UART1. This can cause problems if UART1 is not used as conso= le >>> and the settings are different from UART1. The result is that the con= sole >>> output is garbage. To do this correctly the UART frequency is taken f= rom >>> the used device. For the implementations that don't have the igp cloc= k >>> 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_cons= ole(void) >>> int mxc_serial_setbrg(struct udevice *dev, int baudrate) >>> { >>> struct mxc_serial_plat *plat =3D dev_get_plat(dev); >>> - u32 clk =3D imx_get_uartclk(); >>> + u32 rate =3D 0; >>> + >>> + if (IS_ENABLED(CONFIG_CLK)) { >> >> CONFIG_IS_ENABLED? >=20 > This should be correct. The CONFIG_IS_ENABLED is a preprocessor macro > and the IS_ENABLED can be used in c code. Or do you mean something > else? I mean you should be using CONFIG_IS_ENABLED(CLK) so that this code is correct for both SPL and U-Boot proper. But it is also fine to "try and fail" (making this check unnecessary). >> >> mx6ull at least does not have CONFIG_SPL_CLK enabled. >=20 > I expect that in that case it will fallback to the old behavior ... not= ? Yes, if you handle -ENOSYS correctly. >> >>> + struct clk clk; >>> + if(!clk_get_by_name(dev, "ipg", &clk)) >>> + rate =3D clk_get_rate(&clk); You may also need to enable this clock. >>> + } >>> + >>> + /* as fallback we try to get the clk rate that way */ >>> + if (rate =3D=3D 0) >> >> !rate || IS_ERR_VALUE(rate) >> >>> + rate =3D 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; >>> } >>> >> --Sean >=20