From patchwork Sun May 3 02:46:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1281853 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=tP5LzCZB; 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 49F9Tj51rZz9sRf for ; Sun, 3 May 2020 12:50:49 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 10903822D8; Sun, 3 May 2020 04:47:19 +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="tP5LzCZB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7672381F0C; Sun, 3 May 2020 04:47:06 +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-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) (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 D0EA881EFD for ; Sun, 3 May 2020 04:47:01 +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-xf41.google.com with SMTP id h6so6682651qvz.8 for ; Sat, 02 May 2020 19:47:01 -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=W8XR8O2ClYkH5rbMLgk12zLZE+0jTAEtRK3imMiiaAA=; b=tP5LzCZBuyf+GILCrOGH439favv6KnRORemB8VnGE88ySz6pB7B5GE/9B57oX/3TR1 7nItuk7X7lL34tiU32+XJe1EG8CIugVGfjUgxmQbMqXywoUXqrXClt5rrPFH9gF36f4Z OgVbAgyn1ND0TqRiFQuu5JygoHoSWNSUFF8Cy41L+c86o3zfNg+SI1MjBVCF5F5X03NW YCDDUPU5GdtMfNORYuqFEUl9TvdBkOfFJL16nNOYlhqGgux0lgbIPqWPE6xIq6l3b8H8 EBTONS652SASXfkBJZTLrfvzs/YHrCf9GiVOTMSA3VqKYtndC4EmtFtbpppeMMBW3bny Yo+g== 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=W8XR8O2ClYkH5rbMLgk12zLZE+0jTAEtRK3imMiiaAA=; b=rQl4z7L2NS4g+XtlsOF/fDSCY82UMH+V52KBqmG2YXcbhD5HfwujlS9p5bMJ9VxOgt w66SCO5LoC/HneI1PWpBda5YOd6QUpfH8T1Rje/B46fQ7ZDk9DkXJUWen+CreeYxc0/v B+k/+N25muZKTPnjz5DdeplQJRc420r+pA/SNfZQItWk95uVkms9aVZds2e3MxlkycIW odd0eOHVdf4gIso31pxjhazajkH67sFYSk7OInCmyTPp371Thskudm19ydaennOr2M5L ThIQ7pbT+y8S0rh9yPGbupCC8MwZb7WOEEDfIQ5y6Jl+izbK/iGtiVpAxi0TCjuWXrfp DwMg== X-Gm-Message-State: AGi0PuZmOSJxka6Z6Eok7LDEi4xYBFte5h/mqqYZe1euo50FSS86Wc2q /4d7F5pBGJZRlvDDUcegcolZ84uPKOQ= X-Google-Smtp-Source: APiQypLxlGahom1Fx+bgTO3EuSlreK4hsXvlaGqCGW6kOA1q1pVEJueEXkYQ2Mvqd9MSUdfZBx4sWA== X-Received: by 2002:ad4:4e65:: with SMTP id ec5mr10987369qvb.32.1588474020486; Sat, 02 May 2020 19:47:00 -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 h2sm6610696qkh.91.2020.05.02.19.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 May 2020 19:46:59 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Bin Meng , Rick Chen , Sean Anderson Subject: [PATCH v10 17/21] riscv: Try to get cpu frequency from a "clocks" node if it exists Date: Sat, 2 May 2020 22:46:33 -0400 Message-Id: <20200503024637.327733-18-seanga2@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200503024637.327733-1-seanga2@gmail.com> References: <20200503024637.327733-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)