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: 10089131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A6A7E60327 for ; Sun, 3 Dec 2017 09:18:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BD8728EF4 for ; Sun, 3 Dec 2017 09:18:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 904CB28F19; Sun, 3 Dec 2017 09:18:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BBD2428F50 for ; Sun, 3 Dec 2017 09:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=opWJzi/jdCMP8HTHJhBH240Ycz9cd6+Iz5wXMta348o=; b=UDzNc7WdiHHIZxLJ/96XOWvSpl Lq5SMacCAqJfSb9qUtZaSaTR1eNUZfhPJJIgaJI5FT5ifn6r+2I21QcIJs9u6Unob2bZ/GCpZIL6n sBaCwXOtWLxoUZt7htDZjBfMOGftHUegvmUZgu8yfhxkHV7gzfA1oN2TmzVVYzHnwK/eaq7cMm1Vw F5U6Jqzi8JWOqbrRrVbuLrVtlVUEpgxFduLHtU9sGbRBzd4aFSM1RLHR2+MAomy2GHpYErqQm5GYW Q/Ox0q8ZMQbeyMgdfEHWdvP/Q5wX7MIpEcqdHqaUS2IqFH9fCY6FBtNk4LYV8ZoPoWMPl9geVtsKs 3GkatbjA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eLQQ2-0002GA-MT; Sun, 03 Dec 2017 09:18:38 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLQPu-0002A8-1n for linux-amlogic@lists.infradead.org; Sun, 03 Dec 2017 09:18:33 +0000 Received: by mail-wr0-x242.google.com with SMTP id z34so14146681wrz.10 for ; Sun, 03 Dec 2017 01:18:09 -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=H6dFKWIPTFHK+18i+8fujIyU3pSiwW1vvxppHhcxaA3X1eOHreUox34AAgoB4D22dT NZbCQoYVqDy4+EBzBe3xA0jLIr3J7PAoAqYB+u3J/iuEflD/zNOozQ11hGOdsCA/1Yww ekt3YyRYk3i7cXD6ZDZfTpJ0zB2BaouYkoFk5HlMQ7TlDEVWqe+lH3lL0jPhxC9RV7PC RUAqqzrb93IH/XWCgm7bXTMFZ7dg91z4PsTQaqcQILlu+wKqYJFR9xhSIYO4+OZ/YvOG OADv4P/vbSjAKiMUF53kESfpwYjfsM5UjC4HBZ1pBkLUIFcs5hn+xi6tvg4iLhmIYxnh QACQ== X-Gm-Message-State: AJaThX7DtyMhls9eRZzzeHMidGQTa/9/wK2KEYHJKQfe5hX5jQP5s604 enVlw0AGVGgDWHIHjejvzjM= 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 Subject: [PATCH 2/4] ARM: meson: add clock measurement function 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171203_011830_507664_FC60CEC1 X-CRM114-Status: GOOD ( 13.95 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Rini , Albert Aribaud , Neil Armstrong , Simon Glass , Beniamino Galvani , linux-amlogic@lists.infradead.org, Heiko Schocher , =?UTF-8?q?Andreas=20F=C3=A4rber?= MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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; +}