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 35852C433F5 for ; Fri, 18 Mar 2022 02:15:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D98E682EBB; Fri, 18 Mar 2022 03:15:19 +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="pd77piKk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3C80681B5B; Fri, 18 Mar 2022 03:15:17 +0100 (CET) Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) (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 A853882EBB for ; Fri, 18 Mar 2022 03:15:13 +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-qv1-xf29.google.com with SMTP id k7so127475qvc.4 for ; Thu, 17 Mar 2022 19:15:13 -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=FCXN8maSuiUrVr6Gyv2JGbdIPGiXOEim9loPQRBPdx4=; b=pd77piKkjX6nS8YtB+zGtv5Ln8jmYNoBob3IJ0yHu8gR3QE1Dw+8BAqUN30st+wa76 9sVneVLqaUYm37URcRZ6tuVVoRC3RhDNATQgZMvQm3YsH2xaCgHp3Y3XoPcal2vTZFvq u6lS94bilBwhp9S9Qtm5KzYZvi08G59hmkDRetqZDJj9quItU7yik8w/qoOBCaed95JG ffyxDJ/4FTdFMMzz+aG6pQASD/wkmea0G/2UMGig3/d6j1gEYjKjVb8qlUPFi5KmhyUg TxVZSmUcayNCrT80n77W4QYY4L+oeTuUrYW/Penfu42HXgLZ9i2XtSDPkBSGyRTPEYN1 RiAQ== 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=FCXN8maSuiUrVr6Gyv2JGbdIPGiXOEim9loPQRBPdx4=; b=xxW0hvHY99RlAInsjqVhUHpRtdfuDgZvjlqVPkm9n8dKmHEpSm9rqF0S8EJQuopi0f PSF6dbn+wLG+b9VxGYeOD3MpzqDVD+vcvLcvrqX04Ef5zdvoLFYlDNyMl8sbzJ2pUBnG 9PcOXAWwcxEPNjCB3Ng2Y7NTB/fPDGiizmPkbru5nV0iKthCL8BRcT03UjPOvyUNwLH7 5WyDvMUjyx5VqytONc/ufF+UIri6UPX9XiuF0D5GAGqgoKA4+/uNdk2x4N1oq2T/wgeC muYfkWvciLPJEzvs42KsWEXEyJpqLMbPlj0Hl6DADaDnnXnqyx7u6Tmoi+cPmseCAuNK 6dZg== X-Gm-Message-State: AOAM533F0TyTAPkPoy0sC6VYbcO7JzRaXwI8o6T8JhGXXKYOZwkwW/qq GMSFTVJay+xoecWqjnZ/7BU= X-Google-Smtp-Source: ABdhPJwasnan35YfUPE6EXGSlRSA7KPHgOMPjGS96l0160ANXYcO6lZHJHc3jea+poEtfiuhV7HLlg== X-Received: by 2002:a05:6214:21cf:b0:42d:cc:4121 with SMTP id d15-20020a05621421cf00b0042d00cc4121mr5854856qvh.70.1647569712262; Thu, 17 Mar 2022 19:15:12 -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 x19-20020a05622a001300b002e1e78062e3sm4934582qtw.84.2022.03.17.19.15.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Mar 2022 19:15:11 -0700 (PDT) Subject: Re: [RFC] serial: mxc: get the clock frequency from the used clock for the device To: Michael Walle Cc: Heiko Thiery , u-boot@lists.denx.de, Marek Vasut , 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> <25046b02eb285f3f281cd003961e4900@walle.cc> From: Sean Anderson Message-ID: <112363c5-d7b7-80ec-17eb-4b5d91729c34@gmail.com> Date: Thu, 17 Mar 2022 22:15:09 -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: <25046b02eb285f3f281cd003961e4900@walle.cc> 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 10:47 AM, Michael Walle wrote: >=20 >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct clk clk; >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(!clk_get_by_name(dev, = "ipg", &clk)) >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 r= ate =3D clk_get_rate(&clk); >>> +=C2=A0=C2=A0=C2=A0 } >>> + >>> +=C2=A0=C2=A0=C2=A0 /* as fallback we try to get the clk rate that wa= y */ >>> +=C2=A0=C2=A0=C2=A0 if (rate =3D=3D 0) >> >> !rate || IS_ERR_VALUE(rate) >=20 > This looked so weird I had to actually look at clk_get_rate() > in u-boot. >=20 > /** > =C2=A0* clk_get_rate() - Get current clock rate. > =C2=A0* @clk:=C2=A0=C2=A0=C2=A0 A clock struct that was previously suc= cessfully requested by > =C2=A0*=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 clk_request/get_by_*= (). > =C2=A0* > =C2=A0* Return: clock rate in Hz on success, 0 for invalid clock, or -= ve error code > =C2=A0*=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for other errors. > =C2=A0*/ > ulong clk_get_rate(struct clk *clk); >=20 > How can an ulong return a negative error value? It can't. Which is why we need IS_ERR_VALUE and not < 0. > What if the clock speed happens to be the same as -errno? Due to physical constraints, this isn't an issue on 64 bit systems. And y= ou could run into trouble if you have a 32-bit system with a 4GHz processor.= I don't think it's the best interface. In e.g. Linux clk_get_rate returns= 0 on failure, which I think is reasonable. If you are interested, please send = a patch series :) --Sean