From patchwork Thu Apr 23 02:33:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1275516 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=85.214.62.61; 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=u6zi3YuG; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4971f920v7z9sP7 for ; Thu, 23 Apr 2020 12:36:49 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DF1F081C76; Thu, 23 Apr 2020 04:34:28 +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="u6zi3YuG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E28BD81915; Thu, 23 Apr 2020 04:33:51 +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-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) (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 CB3358192F for ; Thu, 23 Apr 2020 04:33:42 +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-qk1-x741.google.com with SMTP id 20so4851801qkl.10 for ; Wed, 22 Apr 2020 19:33:42 -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=T9vzUcE3ek1UBP1zwO9WrkGxUlPiQMRQK9tkO8tmxuE=; b=u6zi3YuGP14128MOSG3xb0XCDF9cCrF4pD+q+dQefgb2vDPloNC5eZsgKnyA8uQ7eQ aenl3XGPscY1G77IGUaiY8ltQ7hWIyG7gT0tuZSppL9TnNVWATY7I2V/TLaIjns7GAaw 24Nv48cFvZ8Tp59dhAcVr8axqX6MauwRS1/1svi8Yn+zfPTlMqJtQsP0n0Ga5jO/58Pm BPyAmxLzbj0mRkOpbY/2tp/7Jtr1Ow/dVZtcTYuEpY8f9/Km7ypgNAVdmV0MWYqkUVKQ TiemOiSmqLpGFMB/IBncLpbcF/YmAeS0ekNcoPZOWr1lTiYgM5u83YewM90s4i6d1dMB FkHA== 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=T9vzUcE3ek1UBP1zwO9WrkGxUlPiQMRQK9tkO8tmxuE=; b=KqY8w6Ct+6DlOhTLpa25SS6dLCxBNRXTSwc/879RDqqBpjDPc3oLYbU9yMmtsFXfmq b/gHm0y/UNLa1vRc0fnGeiwPIoy6xWIG4wXkRbdftSeXKgjPwG4UsU+iK4AAgIcVjEpm MNCuSbFXiVEhDmJpHe9DXB/upv9M+fV2E16utYAwsKrqAyVrJ/YZkHXVCuN86nEt75AR InJyvM2wZu+onj/oM/Cg8n032mBgnuy/REWwPpbEyUKnEKPjTrD7FVueo7NJao7nEM5Z WpuiKasYbw7lYnBp08SLmDBWdtpeHyqLiRAU53p1zbWSqk+hlEEVnYgv5XSn5Ku4LjrX TK0Q== X-Gm-Message-State: AGi0PuafyOo4aNgvZta70J3A0TFKS4ml8PAFx9AsVM9T+fUCoFnR/CHy 4ZX4czqpkYXAODjt2JPiVpTB3kiobHE= X-Google-Smtp-Source: APiQypK6AapA3EuaIOhYoCkHGgv9RmoqngixJjil8+nqoE+2hgyHpWKI1YxpmekOrNzkb7eFJql7iA== X-Received: by 2002:a37:a509:: with SMTP id o9mr1405034qke.460.1587609221569; Wed, 22 Apr 2020 19:33:41 -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 d23sm841971qtj.9.2020.04.22.19.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2020 19:33:41 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Rick Chen , Bin Meng , Sean Anderson Subject: [PATCH v9 17/21] riscv: Try to get cpu frequency from a "clocks" node if it exists Date: Wed, 22 Apr 2020 22:33:16 -0400 Message-Id: <20200423023320.1380090-18-seanga2@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200423023320.1380090-1-seanga2@gmail.com> References: <20200423023320.1380090-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 28ad0aa30f..c6ed060abc 100644 --- a/drivers/cpu/riscv_cpu.c +++ b/drivers/cpu/riscv_cpu.c @@ -3,12 +3,14 @@ * Copyright (C) 2018, Bin Meng */ +#include #include #include #include #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -27,9 +29,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)