From patchwork Sun Dec 3 09:17:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 843964 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dlED+7cC"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yqMsZ5MXkz9s7g for ; Sun, 3 Dec 2017 20:19:46 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 68860C2201E; Sun, 3 Dec 2017 09:18:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 14247C2200F; Sun, 3 Dec 2017 09:18:23 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8931AC22008; Sun, 3 Dec 2017 09:18:11 +0000 (UTC) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by lists.denx.de (Postfix) with ESMTPS id 502C4C21FF2 for ; Sun, 3 Dec 2017 09:18:08 +0000 (UTC) Received: by mail-wr0-f195.google.com with SMTP id l22so14133709wrc.11 for ; Sun, 03 Dec 2017 01:18:08 -0800 (PST) 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; bh=BlsLmxf2dQJMwd9pZ6EvN+Ui+69wnytVynkiBCgPSbY=; b=dlED+7cC/HsInLdjlswhZotmGQGkcMN+9L8qgVPxwfoyJ5TAGibVMvqUeuoZd5qLkt qYkoOTaAoULT2QZRB9q/kSuow2egPBTDP6605TwbyIdvHFGef7IPbrQBCDg/zgeBhTIa Mfx5ZGyOm0csgfRlIe9T9khsJcEt3SVqXhWgFjXd0HK/2W1XVmwyCdnhrux8hV7Ph4Vy 6uUFGVn5H11KxFG3x6Htg065z+7eabRRIKOar5ZpMfD/FGEaRHab4gN4huuVkIlptFe9 N4WKuR0bGoUaIL7CtRtmfVFfeiaV2u8ZgCazsrLuJ/GqDJdrWig5uZD+i40ZGJu3ayOt CCnA== 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; bh=BlsLmxf2dQJMwd9pZ6EvN+Ui+69wnytVynkiBCgPSbY=; b=a+lhDJzvxPxqYzNRBLhTth44Egql7IUX4yPDCMq1nS54Aja1RplqJPiYB4XlRCPYGK DNt7y2QgI3+hlX26avVcg+MaFfAPQSvxIyoSt7q2F/bTkFOEj/grJaZcbWhIYg0tParb HBfEUjph4DSIARsTAbKF9lOFYlzizdiIYhhC4VW9DLL+7rK3mGDJNrwlSry4hdMuKzts JR2vZqshaSVuzTjo+eLRpEwFxYS/euMP4y14QVIxCs+dRCwdm/QAD8XuQh5yQEssC9XW loHeNbwDalvWrcps0EMNjaIs6HMmfQjuQiEm28cUwRiylwpIMRLFxj5tyq2qQXp217zZ rGrQ== X-Gm-Message-State: AJaThX4JaB7lg/Sehl0pS5tUttkfSpF+DBe+6YmRZBD1PTW9luqKJVzX T7E6xZxo1hiPH3UfYHrGW7A1XkA7 X-Google-Smtp-Source: AGs4zMYbu4fWKMPfc1z8Fm5goywh/UBz2rqiqYdO7X5/5dtqyAr7X2Ek/foC6BLTdAUBRDQggHcomA== X-Received: by 10.223.165.19 with SMTP id i19mr10692756wrb.227.1512292687566; Sun, 03 Dec 2017 01:18:07 -0800 (PST) Received: from sark.homenet.telecomitalia.it (host96-211-dynamic.211-62-r.retail.telecomitalia.it. [62.211.211.96]) by smtp.gmail.com with ESMTPSA id y99sm5414172wmh.0.2017.12.03.01.18.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 03 Dec 2017 01:18:06 -0800 (PST) From: Beniamino Galvani To: u-boot@lists.denx.de Date: Sun, 3 Dec 2017 10:17:11 +0100 Message-Id: <20171203091713.22029-3-b.galvani@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171203091713.22029-1-b.galvani@gmail.com> References: <20171203091713.22029-1-b.galvani@gmail.com> Cc: Tom Rini , linux-amlogic@lists.infradead.org, =?utf-8?q?Andreas_F=C3=A4rber?= Subject: [U-Boot] [PATCH 2/4] ARM: meson: add clock measurement function X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add add a function to measure the current clock rate. Signed-off-by: Beniamino Galvani Reviewed-by: Neil Armstrong --- arch/arm/include/asm/arch-meson/clock.h | 34 +++++++++++++++++++++++++ arch/arm/mach-meson/Makefile | 2 +- arch/arm/mach-meson/clock.c | 45 +++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 arch/arm/include/asm/arch-meson/clock.h create mode 100644 arch/arm/mach-meson/clock.c diff --git a/arch/arm/include/asm/arch-meson/clock.h b/arch/arm/include/asm/arch-meson/clock.h new file mode 100644 index 0000000000..b43b23386c --- /dev/null +++ b/arch/arm/include/asm/arch-meson/clock.h @@ -0,0 +1,34 @@ +/* + * Copyright 2017 - Beniamino Galvani + * + * SPDX-License-Identifier: GPL-2.0+ + */ +#ifndef _MESON_CLOCK_H_ +#define _MESON_CLOCK_H_ + +/* CBUS clock measure registers */ +#define MSR_CLK_DUTY 0xc1108758 +#define MSR_CLK_REG0 0xc110875c +#define MSR_CLK_REG1 0xc1108760 +#define MSR_CLK_REG2 0xc1108764 + +#define CLK_GP0_PLL 4 +#define CLK_GP1_PLL 5 +#define CLK_81 7 +#define CLK_MMC 23 +#define CLK_MOD_ETH_TX 40 +#define CLK_MOD_ETH_RX_RMII 41 +#define CLK_FCLK_DIV5 43 +#define CLK_SD_EMMC_CLK_C 51 +#define CLK_SD_EMMC_CLK_B 52 + +/* Clock gates */ +#define HHI_GCLK_MPEG0 0x140 +#define HHI_GCLK_MPEG1 0x144 +#define HHI_GCLK_MPEG2 0x148 +#define HHI_GCLK_OTHER 0x150 +#define HHI_GCLK_AO 0x154 + +ulong meson_measure_clk_rate(unsigned int clk); + +#endif diff --git a/arch/arm/mach-meson/Makefile b/arch/arm/mach-meson/Makefile index bf49b8b1e5..e7ea4fc5b0 100644 --- a/arch/arm/mach-meson/Makefile +++ b/arch/arm/mach-meson/Makefile @@ -4,4 +4,4 @@ # SPDX-License-Identifier: GPL-2.0+ # -obj-y += board.o sm.o +obj-y += board.o clock.o sm.o diff --git a/arch/arm/mach-meson/clock.c b/arch/arm/mach-meson/clock.c new file mode 100644 index 0000000000..73be11e90d --- /dev/null +++ b/arch/arm/mach-meson/clock.c @@ -0,0 +1,45 @@ +/* + * (C) Copyright 2016 Beniamino Galvani + * + * SPDX-License-Identifier: GPL-2.0+ + * + * Clock rate measuring. + */ + +#include +#include +#include + +ulong meson_measure_clk_rate(unsigned int clk) +{ + ulong start; + ulong mhz; + + writel(0, MSR_CLK_REG0); + + /* Set the measurement gate to 64uS */ + clrsetbits_le32(MSR_CLK_REG0, 0xffff, 64 - 1); + clrbits_le32(MSR_CLK_REG0, + BIT(17) | /* disable continuous measurement */ + BIT(18)); /* disable interrupts */ + clrsetbits_le32(MSR_CLK_REG0, + GENMASK(20, 26), + clk << 20); /* select the clock */ + setbits_le32(MSR_CLK_REG0, + BIT(19) | /* enable the clock */ + BIT(16)); /* enable measuring */ + + start = get_timer(0); + while (readl(MSR_CLK_REG0) & BIT(31)) { + if (get_timer(start) > 100) { + debug("could not measure clk %u rate\n", clk); + return -ETIMEDOUT; + } + } + + /* Disable measuring */ + clrbits_le32(MSR_CLK_REG0, BIT(16)); + + mhz = ((readl(MSR_CLK_REG2) + 31) & 0xfffff) >> 6; + return mhz * 1000000; +}