From patchwork Wed May 20 06:41:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1294022 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=cz/+80RI; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49RjtR14KXz9sT8 for ; Wed, 20 May 2020 16:45:18 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 43DCD81EDA; Wed, 20 May 2020 08:42:32 +0200 (CEST) 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="cz/+80RI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4CB4A81E97; Wed, 20 May 2020 08:41:43 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) (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 DA1DA81E6E for ; Wed, 20 May 2020 08:41:37 +0200 (CEST) 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-xf44.google.com with SMTP id l3so839331qvo.7 for ; Tue, 19 May 2020 23:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OQlMPnye4sN/cv4hXeehc7L500LGY0n4H96p4nRXXKo=; b=cz/+80RIJaosUyiErlvxaFPfRkGyfsjNSGbhyjSkwMkeDJTpVPs3qEwN3/wroyNIgt rCvc3zZf9Ypa2yf/mtfZdkLzscVpNe0Y3bk3wEzpKYpV9P8Xts+uAIwrAAJZaPmuiVe5 92y4UdrSsrvQrN1WqCAeuPVBULxN7GY+XMuXPUUZ6Vg8AGJKG0W43NFxOGSrsZfS4z6T I/Zye9XMRyc8QBoW6PoWqyi/5s6uiiI6rIdTwyGJA17I1WX270PYr6Xz/LttvZbMZI8F eAfioFDl/Lh8H5h6SA3k2p8gXii3Hx796sSe0V4ShMxEl6TEP0OLSdHnz+VjS3l75D7Z TR6A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=OQlMPnye4sN/cv4hXeehc7L500LGY0n4H96p4nRXXKo=; b=rbm2V4dMACHtNmdJwJ+iM3Xc48PQ+TdtYF7wxO3v8jxxEoKS2SsxsWkS/IYRSe0c59 jNPWLClnKWx4siZbppJlz6qeHxHnYp4uJqwLgDDn5U5EcHa1lzU8FVt/etB2P6Zn6owa K2BqCwLt/UjvBiDsMXkNwVoNZFKheoxPsriT7b3bNLYgd+kIQE+3y2dt9xRdPo1UxcfB 16DO4b/Bze6YFZKT1TR9H4g3UhdlR8Qs1IZiLhwH1C+oYzObc7T9s4g+mxNKagHu1/+0 /Aoi//iGyv9nDonK+4bwVTPQZ912DZf7zRMJzlsSl3thtBMzwTudXhXvn8RZ6Ati1StI 2wzA== X-Gm-Message-State: AOAM53344VTPPx6g+oA/AffpeZm8Q67eW3K3EEVMwocgSoV/Co3hirtq igc7XhAQfeutYVQ9NLdzxxmJBw4fHEc= X-Google-Smtp-Source: ABdhPJw2yTwJZ/MdWD6B+5le26K8jDkaMPyXgGz9xqOIdMbCFyviDPYc73WuH6/3TulWMDXYXBS3Zg== X-Received: by 2002:ad4:40ca:: with SMTP id x10mr3398035qvp.220.1589956896516; Tue, 19 May 2020 23:41:36 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id i59sm1600393qtb.58.2020.05.19.23.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 23:41:36 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Bin Meng , Sean Anderson Subject: [PATCH v11 17/21] riscv: Try to get cpu frequency from a "clocks" node if it exists Date: Wed, 20 May 2020 02:41:07 -0400 Message-Id: <20200520064111.317605-18-seanga2@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200520064111.317605-1-seanga2@gmail.com> References: <20200520064111.317605-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean Instead of always using the "clock-frequency" property to determine cpu frequency, try using a clock in "clocks" if it exists. This patch also fixes a bug where there could be spurious higher frequencies if sizeof(u32) != sizeof(ulong). Signed-off-by: Sean Anderson Reviewed-by: Bin Meng --- This patch was previously sumbitted on its own as https://patchwork.ozlabs.org/patch/1232420/ This patch is the combination of the patches https://patchwork.ozlabs.org/patch/1223933/ https://patchwork.ozlabs.org/patch/1224957/ "riscv: Fix incorrect cpu frequency on RV64" "riscv: Try to get cpu frequency from device tree" Changes in v5: - Include linux/err.h explicitly - Reword commit message Changes in v4: - New drivers/cpu/riscv_cpu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/cpu/riscv_cpu.c b/drivers/cpu/riscv_cpu.c index cb04f5638d..2d44d1c17b 100644 --- a/drivers/cpu/riscv_cpu.c +++ b/drivers/cpu/riscv_cpu.c @@ -3,6 +3,7 @@ * Copyright (C) 2018, Bin Meng */ +#include #include #include #include @@ -11,6 +12,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -29,9 +31,24 @@ static int riscv_cpu_get_desc(struct udevice *dev, char *buf, int size) static int riscv_cpu_get_info(struct udevice *dev, struct cpu_info *info) { + int ret; + struct clk clk; const char *mmu; - dev_read_u32(dev, "clock-frequency", (u32 *)&info->cpu_freq); + /* Zero out the frequency, in case sizeof(ulong) != sizeof(u32) */ + info->cpu_freq = 0; + + /* First try getting the frequency from the assigned clock */ + ret = clk_get_by_index(dev, 0, &clk); + if (!ret) { + ret = clk_get_rate(&clk); + if (!IS_ERR_VALUE(ret)) + info->cpu_freq = ret; + clk_free(&clk); + } + + if (!info->cpu_freq) + dev_read_u32(dev, "clock-frequency", (u32 *)&info->cpu_freq); mmu = dev_read_string(dev, "mmu-type"); if (!mmu)