From patchwork Sun Nov 18 13:53:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10687903 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1026A15A7 for ; Sun, 18 Nov 2018 13:53:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F07B7285D3 for ; Sun, 18 Nov 2018 13:53:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDF9E28630; Sun, 18 Nov 2018 13:53:36 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 6421A285D3 for ; Sun, 18 Nov 2018 13:53:36 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=45JNlYvyvqI/WHs5xVyr7/F5vOPSgH9vWhWcEK3Abf8=; b=BWs5RhbAmGHJf5 UBtBjQCCvhe4wgBI7Udc/o8fUOHJBAqo/m4JibKGTj2PROWbrsO+sQTDSrOjgiwDSi/QKuBC//r0v 1rWmCw/8IXP8uwkUUiDDEUHDDiJF6n1OL9rGFHFHe5wqEHf7TaN0J3GlI+j0rxtnV8ZX/dVOoBclV RptwLWW+x8Y1fTZwYqZVTaAapQ11JaTNpKFpQ4jJTgSKfOgZ2A73N2nEAxboxsKXWZYpA3Ho89nho 03dpp0qvhs+YsGw8j7elaIUNRUQv/C6aaDPNQkRrDgnLHBsXQgVExmgK+mif93RtNNxYgLSgbsl72 19s/V9XXGQRwg3Y8O8Tw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gONVy-0006Ci-C7; Sun, 18 Nov 2018 13:53:30 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gONVv-0006Bd-4r for linux-arm-kernel@lists.infradead.org; Sun, 18 Nov 2018 13:53:28 +0000 Received: by mail-wr1-x443.google.com with SMTP id z13-v6so29278294wrs.3 for ; Sun, 18 Nov 2018 05:53:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R6warBK4AjkYFZ7MKEhC6ZGCgZpodJEII/OqLNckPO8=; b=PJOOpV0XoYz4KtqrUJunrRuwREBRs5gmFWyBXXCJExjL20NXJZ1Nyay8Qt1Y0MqoLJ 9oIATxhOyPn4ihlQeObmG9lYL4d/m4bhnrdOyvaP2MloARjxvRwxFsg7E2Fz3Iqpz12p oYFCK0jA9NGOATRv37ksxGHa0i7dRYFiYfQq2TIKvM0Ruknf3BzQZtSajReSTJozZcvB PlnDqnFxspmfrbEPTRTI48TpzJ14Cex2vx1xXA6C/WMXTWXvf/SeQhWsKzkLWRzX11RU mro3nQIDnnVEf31uzMMEBq53bbrAZFCkun/OhPjUZg/GWRg5a/Xj8ULT3DjzmRmOllKe zm6w== 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=R6warBK4AjkYFZ7MKEhC6ZGCgZpodJEII/OqLNckPO8=; b=L1FE+d7y8eHytCJquBFZjEIElHN6OcKefUOiciww/AgwQMuNa/ZEVq3zTLKDpuEuG7 4/iGCjRzAYxEoz89oFROCJJuxbP5E9ZChNRogANxTzazVRt7xLCQJTzlUu/lWNFfv3as Sa9RfV+cHJfSkwsjjqQaoQk7G1iwv/QghdoXEWkaSNj0hjSHVK4AnOVrdoVLj0xl3nhs iLmoYULRPVxI0sYk1wo5OYUeqIjsC/0+4xoEr3AuuxHGwTSlsV3zldNmOyIVZAcxbe7l GjUJr4x3wtDu2HRT9njjJsFDT/a/z8HrgQqoAI2+tBLSeJbZsvF9PP3ywCjYmA/f/zh9 CSAQ== X-Gm-Message-State: AGRZ1gIIS9PNIq7xbsXWyVmpnA/PznEkRgRCtDH6VnfVC7MPTctBb6rY /bAgColhYR5syKdohBDPq99J/Q== X-Google-Smtp-Source: AJdET5dX7zsWYM4SnCkA9mURcIl6V8Wq1v+aQe9gZzIfaRSan0/n6p3e0EYZmFUR+xGnQQ3n5OmbTg== X-Received: by 2002:adf:f04d:: with SMTP id t13-v6mr14727273wro.170.1542549195111; Sun, 18 Nov 2018 05:53:15 -0800 (PST) Received: from bender.home (lfbn-nic-1-84-209.w2-15.abo.wanadoo.fr. [2.15.173.209]) by smtp.gmail.com with ESMTPSA id t5sm14906385wmd.15.2018.11.18.05.53.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Nov 2018 05:53:14 -0800 (PST) From: Neil Armstrong To: devicetree@vger.kernel.org Subject: [PATCH v3 1/3] dt-bindings: amlogic: Add Internal Clock Measurer bindings Date: Sun, 18 Nov 2018 14:53:10 +0100 Message-Id: <20181118135310.31458-1-narmstrong@baylibre.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181118135024.30720-1-narmstrong@baylibre.com> References: <20181118135024.30720-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181118_055327_183312_BA228178 X-CRM114-Status: GOOD ( 11.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The Amlogic Meson SoCs embeds a clock measurer IP to measure the internal clock paths frequencies. Acked-by: Martin Blumenstingl Signed-off-by: Neil Armstrong Reviewed-by: Rob Herring --- Rob, I didn't take your v2 Reviewed-by since I changed the compatible list, tell me if i can still keep the tag. Thanks, Neil .../bindings/soc/amlogic/clk-measure.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/amlogic/clk-measure.txt diff --git a/Documentation/devicetree/bindings/soc/amlogic/clk-measure.txt b/Documentation/devicetree/bindings/soc/amlogic/clk-measure.txt new file mode 100644 index 000000000000..205a54bcd7c7 --- /dev/null +++ b/Documentation/devicetree/bindings/soc/amlogic/clk-measure.txt @@ -0,0 +1,18 @@ +Amlogic Internal Clock Measurer +=============================== + +The Amlogic SoCs contains an IP to measure the internal clocks. +The precision is multiple of MHz, useful to debug the clock states. + +Required properties: +- compatible: Shall contain one of the following : + "amlogic,meson-gx-clk-measure" for GX SoCs + "amlogic,meson8-clk-measure" for Meson8 SoCs + "amlogic,meson8b-clk-measure" for Meson8b SoCs +- reg: base address and size of the Clock Measurer register space. + +Example: + clock-measure@8758 { + compatible = "amlogic,meson-gx-clk-measure"; + reg = <0x0 0x8758 0x0 0x10>; + }; From patchwork Sun Nov 18 13:50:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10687895 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8FBA014DB for ; Sun, 18 Nov 2018 13:51:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D02D29B6C for ; Sun, 18 Nov 2018 13:51:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70EC729B93; Sun, 18 Nov 2018 13:51:13 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 7E8B729B6C for ; Sun, 18 Nov 2018 13:51:12 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=ufKUZHS05Bh8Fk4n+GIJCtrhBsdpsM+28+59p0HW1qE=; b=B10DKHRjADWM5p SywUmGvJ1eqMCm6UvkA+Qr4j477L31iJXl3LxyBb9psLJkDgx5c4LG8c8euLgw2j+gvVnTPijTG6G 3Vr29KKJ4RSjA3mspcK98+GN6nlnA84DgF5xsbLWRusvE/8ykWBUTbImPIvEbNfxPZwo/8BZVYvBN UHb8zbNqiMcKcYv0vZ2mc0ImoSTZj0BGrb9ktNEDnFqbnWUeKXq9YBPoGwht/pk9lvsYYoSgSvFH6 dd1hom8TsdARaTMpKn4CBqTMfZ9buVnj3jXC2nQeIFWSSMVcRBrepKvgxSHUye9+wzHIbmz/SIESB oywArIWX0p5UXG5h3Xrg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gONTY-0005Tr-LC; Sun, 18 Nov 2018 13:51:00 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gONTH-0005AR-Ai for linux-arm-kernel@lists.infradead.org; Sun, 18 Nov 2018 13:50:45 +0000 Received: by mail-wm1-x344.google.com with SMTP id u13-v6so2760138wmc.4 for ; Sun, 18 Nov 2018 05:50:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cSanyqGLxfR52pTIFsFhcpyd7ANY/cvY9eKdTay6P+Y=; b=pWEOJ4K6zTiWylIps3rxdrwM/s472KaeRzcFou58JO75fP8Q6is8XfMCOMkN5JGrEX oxUBTiJZsWg0fChqqpNn0JvhnyKnQJjV8kqboYVGtdjyZU1IBRqmfjHcxOHCSIEHDhzq aDg5o6cTLlO+hk3xMU5hgOnwzbpfvTkE+jU+BKlVYQcTf6StNKwSQx6uDxpDcthsD2QZ hL8n7PF8omGl5JW9tlAjk6B+I1+B7UzPvR/zyc3TSpUIQQuSc+lxMb8/CabMUIcld0ez NUIhHxcHcHkn8e7UoKqkw8PI7dTzOwPQNwKuKZFgeowOFR+dRc7iVwgrsphictetDWpI AWQw== 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=cSanyqGLxfR52pTIFsFhcpyd7ANY/cvY9eKdTay6P+Y=; b=IAroPfPLCMPalOLn6vTKhaCvtWDQTxExnIsTHl4+BI0K2MsyjeF7TSSUYfw6oM5OGG cnlSV8WCsoFR7FdEhwTHZLVUL7y/g1UPF+4TE4N68GENXbt5RuIyxOA2K8p6I5wwAGbe dXwKlx7SVUAswPufsK8OH12gRda2OK6fYn12/AEgvpW+SgxkWhS8EhFQ3UamodFW1cp7 ERhMYGaBDQUkV6beFtFZS0ciV50xVh17HRkrDg+pINbuXLVvu/L363ON6Ov7iESCn5nd BOvFqYqLKqkehp57tdhTojWneASh+gWof4ycpi2Dmqt+e2qkWb/loFgs1Tk8WAPqBcjP vnJA== X-Gm-Message-State: AGRZ1gL+WRJQ81K6g7uF4ruNwWhbjfNvyOjqdr8UVs/5hqXDtLIClxIo v0K30S3HjeRxt6GiJ3euon9TrQ== X-Google-Smtp-Source: AJdET5cpkXGRIdJKQYjcxmkil00aEm/2wkv8JPCCBmo4V3h1RZjp/hP4MuGVuFecWDBE62Xhehz3mA== X-Received: by 2002:a1c:4d12:: with SMTP id o18mr4365635wmh.92.1542549031389; Sun, 18 Nov 2018 05:50:31 -0800 (PST) Received: from bender.home (lfbn-nic-1-84-209.w2-15.abo.wanadoo.fr. [2.15.173.209]) by smtp.gmail.com with ESMTPSA id y9sm4491721wrq.55.2018.11.18.05.50.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Nov 2018 05:50:30 -0800 (PST) From: Neil Armstrong To: khilman@baylibre.com Subject: [PATCH v3 2/3] soc: amlogic: Add Meson Clock Measure driver Date: Sun, 18 Nov 2018 14:50:23 +0100 Message-Id: <20181118135024.30720-3-narmstrong@baylibre.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181118135024.30720-1-narmstrong@baylibre.com> References: <20181118135024.30720-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181118_055043_367781_76C71CC2 X-CRM114-Status: GOOD ( 19.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The Amlogic Meson SoCs embeds a clock measurer IP to measure the internal clock paths frequencies. The precision is determined by stepping into the duration until the counter overflows. The debugfs slows a pretty summary and each clock can be measured individually aswell. Cc: Martin Blumenstingl Signed-off-by: Neil Armstrong Reviewed-by: Martin Blumenstingl Tested-by: Martin Blumenstingl --- drivers/soc/amlogic/Kconfig | 8 + drivers/soc/amlogic/Makefile | 1 + drivers/soc/amlogic/meson-clk-measure.c | 350 ++++++++++++++++++++++++ 3 files changed, 359 insertions(+) create mode 100644 drivers/soc/amlogic/meson-clk-measure.c diff --git a/drivers/soc/amlogic/Kconfig b/drivers/soc/amlogic/Kconfig index 2f282b472912..36633bb6c8bb 100644 --- a/drivers/soc/amlogic/Kconfig +++ b/drivers/soc/amlogic/Kconfig @@ -7,6 +7,14 @@ config MESON_CANVAS help Say yes to support the canvas IP for Amlogic SoCs. +config MESON_CLK_MEASURE + bool "Amlogic Meson SoC Clock Measure driver" + depends on ARCH_MESON || COMPILE_TEST + default ARCH_MESON + help + Say yes to support of Measuring a set of internal SoC clocks + from the debugfs interface. + config MESON_GX_SOCINFO bool "Amlogic Meson GX SoC Information driver" depends on ARCH_MESON || COMPILE_TEST diff --git a/drivers/soc/amlogic/Makefile b/drivers/soc/amlogic/Makefile index 0ab16d35ac36..bf2d109f61e9 100644 --- a/drivers/soc/amlogic/Makefile +++ b/drivers/soc/amlogic/Makefile @@ -1,4 +1,5 @@ obj-$(CONFIG_MESON_CANVAS) += meson-canvas.o +obj-$(CONFIG_MESON_CLK_MEASURE) += meson-clk-measure.o obj-$(CONFIG_MESON_GX_SOCINFO) += meson-gx-socinfo.o obj-$(CONFIG_MESON_GX_PM_DOMAINS) += meson-gx-pwrc-vpu.o obj-$(CONFIG_MESON_MX_SOCINFO) += meson-mx-socinfo.o diff --git a/drivers/soc/amlogic/meson-clk-measure.c b/drivers/soc/amlogic/meson-clk-measure.c new file mode 100644 index 000000000000..daea191a66fa --- /dev/null +++ b/drivers/soc/amlogic/meson-clk-measure.c @@ -0,0 +1,350 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2018 BayLibre, SAS + * Author: Neil Armstrong + */ + +#include +#include +#include +#include +#include +#include + +#define MSR_CLK_DUTY 0x0 +#define MSR_CLK_REG0 0x4 +#define MSR_CLK_REG1 0x8 +#define MSR_CLK_REG2 0xc + +#define MSR_DURATION GENMASK(15, 0) +#define MSR_ENABLE BIT(16) +#define MSR_CONT BIT(17) /* continuous measurement */ +#define MSR_INTR BIT(18) /* interrupts */ +#define MSR_RUN BIT(19) +#define MSR_CLK_SRC GENMASK(26, 20) +#define MSR_BUSY BIT(31) + +#define MSR_VAL_MASK GENMASK(15, 0) + +#define DIV_MIN 32 +#define DIV_STEP 32 +#define DIV_MAX 640 + +#define CLK_MSR_MAX 128 + +struct meson_msr_id { + struct meson_msr *priv; + unsigned int id; + const char *name; +}; + +struct meson_msr { + struct regmap *regmap; + struct meson_msr_id msr_table[CLK_MSR_MAX]; +}; + +#define CLK_MSR_ID(__id, __name) \ + [__id] = {.id = __id, .name = __name,} + +static struct meson_msr_id clk_msr_m8[CLK_MSR_MAX] = { + CLK_MSR_ID(0, "ring_osc_out_ee0"), + CLK_MSR_ID(1, "ring_osc_out_ee1"), + CLK_MSR_ID(2, "ring_osc_out_ee2"), + CLK_MSR_ID(3, "a9_ring_osck"), + CLK_MSR_ID(6, "vid_pll"), + CLK_MSR_ID(7, "clk81"), + CLK_MSR_ID(8, "encp"), + CLK_MSR_ID(9, "encl"), + CLK_MSR_ID(11, "eth_rmii"), + CLK_MSR_ID(13, "amclk"), + CLK_MSR_ID(14, "fec_clk_0"), + CLK_MSR_ID(15, "fec_clk_1"), + CLK_MSR_ID(16, "fec_clk_2"), + CLK_MSR_ID(18, "a9_clk_div16"), + CLK_MSR_ID(19, "hdmi_sys"), + CLK_MSR_ID(20, "rtc_osc_clk_out"), + CLK_MSR_ID(21, "i2s_clk_in_src0"), + CLK_MSR_ID(22, "clk_rmii_from_pad"), + CLK_MSR_ID(23, "hdmi_ch0_tmds"), + CLK_MSR_ID(24, "lvds_fifo"), + CLK_MSR_ID(26, "sc_clk_int"), + CLK_MSR_ID(28, "sar_adc"), + CLK_MSR_ID(30, "mpll_clk_test_out"), + CLK_MSR_ID(31, "audac_clkpi"), + CLK_MSR_ID(32, "vdac"), + CLK_MSR_ID(33, "sdhc_rx"), + CLK_MSR_ID(34, "sdhc_sd"), + CLK_MSR_ID(35, "mali"), + CLK_MSR_ID(36, "hdmi_tx_pixel"), + CLK_MSR_ID(38, "vdin_meas"), + CLK_MSR_ID(39, "pcm_sclk"), + CLK_MSR_ID(40, "pcm_mclk"), + CLK_MSR_ID(41, "eth_rx_tx"), + CLK_MSR_ID(42, "pwm_d"), + CLK_MSR_ID(43, "pwm_c"), + CLK_MSR_ID(44, "pwm_b"), + CLK_MSR_ID(45, "pwm_a"), + CLK_MSR_ID(46, "pcm2_sclk"), + CLK_MSR_ID(47, "ddr_dpll_pt"), + CLK_MSR_ID(48, "pwm_f"), + CLK_MSR_ID(49, "pwm_e"), + CLK_MSR_ID(59, "hcodec"), + CLK_MSR_ID(60, "usb_32k_alt"), + CLK_MSR_ID(61, "gpio"), + CLK_MSR_ID(62, "vid2_pll"), + CLK_MSR_ID(63, "mipi_csi_cfg"), +}; + +static struct meson_msr_id clk_msr_gx[CLK_MSR_MAX] = { + CLK_MSR_ID(0, "ring_osc_out_ee_0"), + CLK_MSR_ID(1, "ring_osc_out_ee_1"), + CLK_MSR_ID(2, "ring_osc_out_ee_2"), + CLK_MSR_ID(3, "a53_ring_osc"), + CLK_MSR_ID(4, "gp0_pll"), + CLK_MSR_ID(6, "enci"), + CLK_MSR_ID(7, "clk81"), + CLK_MSR_ID(8, "encp"), + CLK_MSR_ID(9, "encl"), + CLK_MSR_ID(10, "vdac"), + CLK_MSR_ID(11, "rgmii_tx"), + CLK_MSR_ID(12, "pdm"), + CLK_MSR_ID(13, "amclk"), + CLK_MSR_ID(14, "fec_0"), + CLK_MSR_ID(15, "fec_1"), + CLK_MSR_ID(16, "fec_2"), + CLK_MSR_ID(17, "sys_pll_div16"), + CLK_MSR_ID(18, "sys_cpu_div16"), + CLK_MSR_ID(19, "hdmitx_sys"), + CLK_MSR_ID(20, "rtc_osc_out"), + CLK_MSR_ID(21, "i2s_in_src0"), + CLK_MSR_ID(22, "eth_phy_ref"), + CLK_MSR_ID(23, "hdmi_todig"), + CLK_MSR_ID(26, "sc_int"), + CLK_MSR_ID(28, "sar_adc"), + CLK_MSR_ID(31, "mpll_test_out"), + CLK_MSR_ID(32, "vdec"), + CLK_MSR_ID(35, "mali"), + CLK_MSR_ID(36, "hdmi_tx_pixel"), + CLK_MSR_ID(37, "i958"), + CLK_MSR_ID(38, "vdin_meas"), + CLK_MSR_ID(39, "pcm_sclk"), + CLK_MSR_ID(40, "pcm_mclk"), + CLK_MSR_ID(41, "eth_rx_or_rmii"), + CLK_MSR_ID(42, "mp0_out"), + CLK_MSR_ID(43, "fclk_div5"), + CLK_MSR_ID(44, "pwm_b"), + CLK_MSR_ID(45, "pwm_a"), + CLK_MSR_ID(46, "vpu"), + CLK_MSR_ID(47, "ddr_dpll_pt"), + CLK_MSR_ID(48, "mp1_out"), + CLK_MSR_ID(49, "mp2_out"), + CLK_MSR_ID(50, "mp3_out"), + CLK_MSR_ID(51, "nand_core"), + CLK_MSR_ID(52, "sd_emmc_b"), + CLK_MSR_ID(53, "sd_emmc_a"), + CLK_MSR_ID(55, "vid_pll_div_out"), + CLK_MSR_ID(56, "cci"), + CLK_MSR_ID(57, "wave420l_c"), + CLK_MSR_ID(58, "wave420l_b"), + CLK_MSR_ID(59, "hcodec"), + CLK_MSR_ID(60, "alt_32k"), + CLK_MSR_ID(61, "gpio_msr"), + CLK_MSR_ID(62, "hevc"), + CLK_MSR_ID(66, "vid_lock"), + CLK_MSR_ID(70, "pwm_f"), + CLK_MSR_ID(71, "pwm_e"), + CLK_MSR_ID(72, "pwm_d"), + CLK_MSR_ID(73, "pwm_c"), + CLK_MSR_ID(75, "aoclkx2_int"), + CLK_MSR_ID(76, "aoclk_int"), + CLK_MSR_ID(77, "rng_ring_osc_0"), + CLK_MSR_ID(78, "rng_ring_osc_1"), + CLK_MSR_ID(79, "rng_ring_osc_2"), + CLK_MSR_ID(80, "rng_ring_osc_3"), + CLK_MSR_ID(81, "vapb"), + CLK_MSR_ID(82, "ge2d"), +}; + +static int meson_measure_id(struct meson_msr_id *clk_msr_id, + unsigned int duration) +{ + struct meson_msr *priv = clk_msr_id->priv; + unsigned int val; + int ret; + + regmap_write(priv->regmap, MSR_CLK_REG0, 0); + + /* Set measurement duration */ + regmap_update_bits(priv->regmap, MSR_CLK_REG0, MSR_DURATION, + FIELD_PREP(MSR_DURATION, duration - 1)); + + /* Set ID */ + regmap_update_bits(priv->regmap, MSR_CLK_REG0, MSR_CLK_SRC, + FIELD_PREP(MSR_CLK_SRC, clk_msr_id->id)); + + /* Enable & Start */ + regmap_update_bits(priv->regmap, MSR_CLK_REG0, + MSR_RUN | MSR_ENABLE, + MSR_RUN | MSR_ENABLE); + + ret = regmap_read_poll_timeout(priv->regmap, MSR_CLK_REG0, + val, !(val & MSR_BUSY), 10, 10000); + if (ret) + return ret; + + /* Disable */ + regmap_update_bits(priv->regmap, MSR_CLK_REG0, MSR_ENABLE, 0); + + /* Get the value in multiple of gate time counts */ + regmap_read(priv->regmap, MSR_CLK_REG2, &val); + + if (val >= MSR_VAL_MASK) + return -EINVAL; + + return DIV_ROUND_CLOSEST_ULL((val & MSR_VAL_MASK) * 1000000ULL, + duration); +} + +static int meson_measure_best_id(struct meson_msr_id *clk_msr_id, + unsigned int *precision) +{ + unsigned int duration = DIV_MAX; + int ret; + + /* Start from max duration and down to min duration */ + do { + ret = meson_measure_id(clk_msr_id, duration); + if (ret >= 0) + *precision = (2 * 1000000) / duration; + else + duration -= DIV_STEP; + } while (duration >= DIV_MIN && ret == -EINVAL); + + return ret; +} + +static int clk_msr_show(struct seq_file *s, void *data) +{ + struct meson_msr_id *clk_msr_id = s->private; + unsigned int precision = 0; + int val; + + val = meson_measure_best_id(clk_msr_id, &precision); + if (val < 0) + return val; + + seq_printf(s, "%d\t+/-%dHz\n", val, precision); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(clk_msr); + +static int clk_msr_summary_show(struct seq_file *s, void *data) +{ + struct meson_msr_id *msr_table = s->private; + unsigned int precision = 0; + int val, i; + + seq_puts(s, " clock rate precision\n"); + seq_puts(s, "---------------------------------------------\n"); + + for (i = 0 ; i < CLK_MSR_MAX ; ++i) { + if (!msr_table[i].name) + continue; + + val = meson_measure_best_id(&msr_table[i], &precision); + if (val < 0) + return val; + + seq_printf(s, " %-20s %10d +/-%dHz\n", + msr_table[i].name, val, precision); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(clk_msr_summary); + +static const struct regmap_config meson_clk_msr_regmap_config = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .max_register = MSR_CLK_REG2, +}; + +static int meson_msr_probe(struct platform_device *pdev) +{ + const struct meson_msr_id *match_data; + struct meson_msr *priv; + struct resource *res; + struct dentry *root, *clks; + void __iomem *base; + int i; + + priv = devm_kzalloc(&pdev->dev, sizeof(struct meson_msr), + GFP_KERNEL); + if (!priv) + return -ENOMEM; + + match_data = device_get_match_data(&pdev->dev); + if (!match_data) { + dev_err(&pdev->dev, "failed to get match data\n"); + return -ENODEV; + } + + memcpy(priv->msr_table, match_data, sizeof(priv->msr_table)); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(base)) { + dev_err(&pdev->dev, "io resource mapping failed\n"); + return PTR_ERR(base); + } + + priv->regmap = devm_regmap_init_mmio(&pdev->dev, base, + &meson_clk_msr_regmap_config); + if (IS_ERR(priv->regmap)) + return PTR_ERR(priv->regmap); + + root = debugfs_create_dir("meson-clk-msr", NULL); + clks = debugfs_create_dir("clks", root); + + debugfs_create_file("measure_summary", 0444, root, + priv->msr_table, &clk_msr_summary_fops); + + for (i = 0 ; i < CLK_MSR_MAX ; ++i) { + if (!priv->msr_table[i].name) + continue; + + priv->msr_table[i].priv = priv; + + debugfs_create_file(priv->msr_table[i].name, 0444, clks, + &priv->msr_table[i], &clk_msr_fops); + } + + return 0; +} + +static const struct of_device_id meson_msr_match_table[] = { + { + .compatible = "amlogic,meson-gx-clk-measure", + .data = (void *)clk_msr_gx, + }, + { + .compatible = "amlogic,meson8-clk-measure", + .data = (void *)clk_msr_m8, + }, + { + .compatible = "amlogic,meson8b-clk-measure", + .data = (void *)clk_msr_m8, + }, + { /* sentinel */ } +}; + +static struct platform_driver meson_msr_driver = { + .probe = meson_msr_probe, + .driver = { + .name = "meson_msr", + .of_match_table = meson_msr_match_table, + }, +}; +builtin_platform_driver(meson_msr_driver); From patchwork Sun Nov 18 13:50:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10687891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BAD1714DB for ; Sun, 18 Nov 2018 13:50:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9B2329B79 for ; Sun, 18 Nov 2018 13:50:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D91A29B97; Sun, 18 Nov 2018 13:50: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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 09DC829B79 for ; Sun, 18 Nov 2018 13:50:54 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=D5RCix+6ybiWXJkPiSmjmjyO5sWvdBzDRqT59ZgjpqM=; b=MliA+7BkfaEWzD 20yayG7eGvSq0JTXM0WvKes6BWLKogPb0hNKIB9nggJ4O12pF8VmvRdZoKAL3hzXFBhPf7QcJQDjb el/EFymn+3G71Qq1Bdo0C+/gL4c94Ss7i6gXRki8bq64RaBYoWRwnbE3/tM3GJIUbMiSAXZwYM2bt qO1xvJwoZk2+JV53OaXMpa/sk/uGLZfXqDfpR38lLF9texU56PETX81COUfp90ZnC9EnF1YdF/ebG SYn/GwBZLbQAFlpYYDUumLzjvPNcFTZ0x6cq8+l/8AwppUMvX7qQNA4lu1PSbBdfoCnDEdKxsfkgg PfzKemPn1FQk197gQYvQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gONTI-0005Ct-3p; Sun, 18 Nov 2018 13:50:44 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gONTE-0005AT-IK for linux-arm-kernel@lists.infradead.org; Sun, 18 Nov 2018 13:50:42 +0000 Received: by mail-wm1-x341.google.com with SMTP id r63-v6so2784509wma.4 for ; Sun, 18 Nov 2018 05:50:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K6byBe9Al5tAC5NstU3tZ5zh348CSZIw2l0zT1ZAN88=; b=ZYTs2W/TcQ3RFOb6c5F4SLjBfUpVX0gMS4GKl4c8y/HzIX3wnFf8URxkQ8bC/CMAi/ tZIZVtDO8VSwW3Twu+AG+JIfRXyTwztoAzFTn8NkMHYCYR8HIZ6/hg2bL0vkoBTZawem OBelggp4cux+WKC7WloPLJ17OfQFv2PaXRkCAp/Hp02cYokynOygIheC/Zo6/E+B3zbL ceGUNpNVw9/qLHqs3WSS937gKP5CD5TL5DXapgaSt9kmQlnBB2NdO7T5pJiX1yT7eOFK pCTmHkpebGb8dtD8lSIN3obSNeVUNVjE6/NKEUvmQhinMXAifqYLe65n6RqusdyX0yPY GiPA== 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=K6byBe9Al5tAC5NstU3tZ5zh348CSZIw2l0zT1ZAN88=; b=qkqesmkI0OpEoGU7gIURbK4+F2H1jZ1BxLuxHtJKj43EVZdtYx2wnrMs20M/7WYYAe fzgKyIiUPTcecb0SIoXzZUGkypex0CGl2dMDY7Lrp/nj2sff7CnYh3qGRVbwzp/cETJI IflsS120Qzaf0S1TNCpQq/+MMeSy6c6joyMQ6bmPrxbTVPTY62KgFGiGpRv1URCS0yEt BG5q9eqDcsIRBajnfzgjMwKx5fVQZt5m4PIE6/Fo5iKOmDivZjeVQh4w0EBEfrqbNzub sF2rP5w7eT46OdFFC8jCS5UXpRBFG+vZiqQUzdpMmrQewR9HNn7hXQR15NXy/07QO3IC 0ZZw== X-Gm-Message-State: AA+aEWZuR6fB8TjyvWOzzPvSM9MBbhV+UTNNOaqzXi8Ssx/iI1proeXz 2DDhr0ZuepvsFgi/ZUCjRuMc9Q== X-Google-Smtp-Source: AJdET5dELMzl2U6sF4ce+R7m7aS7S7427SG7AvCT9KvAFO2HbREctYwAZDKVyYBAOf/9kMueTeyk7w== X-Received: by 2002:a1c:cb84:: with SMTP id b126mr3816967wmg.64.1542549032591; Sun, 18 Nov 2018 05:50:32 -0800 (PST) Received: from bender.home (lfbn-nic-1-84-209.w2-15.abo.wanadoo.fr. [2.15.173.209]) by smtp.gmail.com with ESMTPSA id y9sm4491721wrq.55.2018.11.18.05.50.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Nov 2018 05:50:31 -0800 (PST) From: Neil Armstrong To: khilman@baylibre.com Subject: [PATCH v3 3/3] ARM64: dts: meson-gx: Add Internal Clock Measurer node Date: Sun, 18 Nov 2018 14:50:24 +0100 Message-Id: <20181118135024.30720-4-narmstrong@baylibre.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181118135024.30720-1-narmstrong@baylibre.com> References: <20181118135024.30720-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181118_055040_609256_907601E0 X-CRM114-Status: GOOD ( 11.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The Amlogic Meson GX SoCs embeds a clock measurer IP to measure the internal clock paths frequencies. This patch adds the node in the top-level meson-gx dtsi. Signed-off-by: Neil Armstrong Acked-by: Martin Blumenstingl --- arch/arm64/boot/dts/amlogic/meson-gx.dtsi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-gx.dtsi b/arch/arm64/boot/dts/amlogic/meson-gx.dtsi index f1e5cdbade5e..ed336c7a98a7 100644 --- a/arch/arm64/boot/dts/amlogic/meson-gx.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-gx.dtsi @@ -262,6 +262,11 @@ status = "disabled"; }; + clock-measure@8758 { + compatible = "amlogic,meson-gx-clk-measure"; + reg = <0x0 0x8758 0x0 0x10>; + }; + i2c_B: i2c@87c0 { compatible = "amlogic,meson-gx-i2c", "amlogic,meson-gxbb-i2c"; reg = <0x0 0x087c0 0x0 0x20>;