From patchwork Thu May 21 16:14:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1295345 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=cSgMhAlt; 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 49SZZ02QLcz9sSd for ; Fri, 22 May 2020 02:19:04 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B197D81EAE; Thu, 21 May 2020 18:16:06 +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="cSgMhAlt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 07C4D81E50; Thu, 21 May 2020 18:15:47 +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-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) (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 237DB81D08 for ; Thu, 21 May 2020 18:15:44 +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-qt1-x843.google.com with SMTP id x12so5884531qts.9 for ; Thu, 21 May 2020 09:15:44 -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=cSgMhAltxsWCjL6qgMkERZ2q+rszlKSiNpX00HOlQB4E8mXh4EnSg5VQqHzmlX6S5C 69ys9RevN685xUxw5e8LmZA2+mbVYrVra7t+7vpjxQ6aIsa9D03ohnx+nQsnUsTalmK4 TTPQuzxe72tU9MP3kz7N+EfihHI239lzIIXNh9OYgyZRX7Vkao0pC0Cr6gEQmMifdLi8 PUgXkD2wO8ba5XJGLeohdCLwSseGl2vyeYA8S77xPSzGcgmzKEfM5mGgEwm4x8ABeTU3 cAlviGEG/mlNJvycrqTfGkm60zWY12zCw6TMzeTXtx6adXWAEcUaHBVcwB+guOkiu/s9 dEzA== 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=gABHkZfnLD0JhH0zhrIDjB6SPOpqCYkn/M9aOcKFxz0bJIaOo1Qu4pDHU01m5xQOyv uE5YgPrDYh18V7AEUs4XtjPSrAYL1zuvsTXIyBLr3QK2/0J8AIDn/5YCZtEhzVcrtG1s zRFnADxBsedcS+WxOQqMDV1cQRua7QkFJaV/DRon+zsoU6FeInANY8eqhPhlhnub/e8i EZ9/dz4r6z3NyrwzI2Ul036fx3f/BIKgxC6y07Io456LO1RQokX4DkiJ7T3ry6XIm6Tv lBG5Gf3vubz88lxVR/bR31TlyASV9nzqOEgmsoMbofZ85dfyqEW4sJ0Hn73ipE/qiROm 3BIg== X-Gm-Message-State: AOAM531s2FJN91/p+ppSLFQY2fp316A1eRgxWBvKVGpC5VKRqqi0pqQv ncLDKz+4tkl3Yo/vlMYAYK/6hmaMIGw= X-Google-Smtp-Source: ABdhPJzhCHP1Sx4M6HHqaulwUeM+gR73g7aChR/zPeVjvmLhBrLomGj16XJLOL3bVZTWFNgSln2JOA== X-Received: by 2002:ac8:4cce:: with SMTP id l14mr11337339qtv.3.1590077742691; Thu, 21 May 2020 09:15:42 -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 e28sm5183538qkn.17.2020.05.21.09.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 09:15:42 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Rick Chen , Sean Anderson Subject: [PATCH v13 17/21] riscv: Try to get cpu frequency from a "clocks" node if it exists Date: Thu, 21 May 2020 12:14:59 -0400 Message-Id: <20200521161503.384823-18-seanga2@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521161503.384823-1-seanga2@gmail.com> References: <20200521161503.384823-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)