From patchwork Wed Nov 14 13:16:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10682587 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 B2AD7109C for ; Wed, 14 Nov 2018 13:17:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2BA02836F for ; Wed, 14 Nov 2018 13:17:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6C4028678; Wed, 14 Nov 2018 13:17:03 +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 762252836F for ; Wed, 14 Nov 2018 13:17:03 +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=YuHMuZodQrhCcZaDZgPDgF42uIZHq5Fd7h4gMC+6cE8=; b=PKc7eLOHQPBMJ4 W2S+Rkd6gU7oowIvrsDFpeWS45KzsIpXHz6Dcm2dJgCw9rqZrYePyZqcBoX5Mp1HSDu0gUj62iD1b ADv/hgeHSy0O/5Nro3Kjdw9mXg0/buuoIntc650oPb7sdtIfscLSvlcmb065E+vqweludzrzjui5X BfVoGdYU0zzHK92XVbcgtnQfbWz9lj0x0qvKFd1XUYe++PawE2nIG6KVUAzM/8BZLlnA5sA8hv59/ gno50HxwVelCImWY++haLm8ZnbpXdyYCFoxqJzSP+cA+5AYwPrZCsrMQGJlbPv0o9ir1W9IyKnpeA bCPy8ex98DXdwsBSnBhw==; 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 1gMv2J-0004yB-2w; Wed, 14 Nov 2018 13:16:51 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMv2A-0004sT-J3 for linux-arm-kernel@lists.infradead.org; Wed, 14 Nov 2018 13:16:45 +0000 Received: by mail-wr1-x444.google.com with SMTP id j17-v6so17220878wrq.11 for ; Wed, 14 Nov 2018 05:16: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=pgKVcQTS0Dv7S1Mc2VdYYbFDx3oeYWl2gIMRZsO6SZU=; b=tyYMzBdNX5cR36EE6Ssr7Rf0mFGRktykuDw4WKKZFBGppoL31FRPe5JEj9cr4aAMgL 5YofpuCEK+mFP7Gbec5c2t4jA+GpuuKOctnaiV6HBhNs9IeTVOHc50DE/v3rFrm6ngWR hfdFlDvmIhgPKKFAU0ghXcQAz7qha4Y3MUvnXH1P9shZRQZcfGbxVYPVha6u5xuGS226 4OYrTUMUaJe022D4xAOvrzEtJicqgRcGXbLivCBOYG4PZt8N65r3pQ9TCjeKVwcqMdbt hQuJqBVbBYBkDluK3k3kUwyUjlpnkSmTJC223uZShuUHpPoaj9FbGmcz6y+3+akVv5s3 tRRQ== 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=pgKVcQTS0Dv7S1Mc2VdYYbFDx3oeYWl2gIMRZsO6SZU=; b=YEETOfPQoazCVfC2c4CKYLK/FMqMIzz9K6LPHOE7NHMZkKk45nDA/TyCHy0sqHIdkf 3dui2IV7Or2rSZmvS3fxva/94jdISMsv8iG2AjZtHJaOS2E5mJDqmc5mOcLozEmwXTJQ 6flVOTPheTpYotp5RQHXkteR3eLqzjk8yibaJIq5jBvpijxD+FgpXASRfRuZ0lGA/ksN V9EXOD7xecOUbHQVPBtnZycumK4EoDUZQAD7kz2jzcE7uLi+uJV3y0yJi6cwJGmV4cb1 dkULrfhFlUrWNnc8i7UOvGvGcShTncxJTtMoILpjKWNua8ZcPzf5yBYh4fk1QLeGXArG AfHQ== X-Gm-Message-State: AGRZ1gJqHEAyJqoZD43yucrU0R1nEJRUK+YJXeTkJsIDqiosaN/pbLAC zW2W2wVLOUkqWN5hOsgXh+Afow== X-Google-Smtp-Source: AJdET5cnSxLlH4PclEF/AfKHG6Khgq8cXN3ywZMP6uGg+MWK3EidmaKjSq9r7b5UAPsSldMUQBEGBA== X-Received: by 2002:a5d:69ce:: with SMTP id s14-v6mr2035025wrw.177.1542201390632; Wed, 14 Nov 2018 05:16:30 -0800 (PST) Received: from bender.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id z7-v6sm22715225wrv.21.2018.11.14.05.16.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Nov 2018 05:16:30 -0800 (PST) From: Neil Armstrong To: khilman@baylibre.com, devicetree@vger.kernel.org Subject: [PATCH v2 1/3] dt-bindings: amlogic: Add Internal Clock Measurer bindings Date: Wed, 14 Nov 2018 14:16:25 +0100 Message-Id: <20181114131627.17766-2-narmstrong@baylibre.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181114131627.17766-1-narmstrong@baylibre.com> References: <20181114131627.17766-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_051642_632055_BD836E0C X-CRM114-Status: GOOD ( 11.69 ) 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. Signed-off-by: Neil Armstrong Reviewed-by: Rob Herring Acked-by: Martin Blumenstingl --- .../bindings/soc/amlogic/clk-measure.txt | 15 +++++++++++++++ 1 file changed, 15 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..ba9183a42032 --- /dev/null +++ b/Documentation/devicetree/bindings/soc/amlogic/clk-measure.txt @@ -0,0 +1,15 @@ +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 "amlogic,meson-gx-clk-measure" +- 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 Wed Nov 14 13:16:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10682601 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 E0A4614BA for ; Wed, 14 Nov 2018 13:17:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D08222836F for ; Wed, 14 Nov 2018 13:17:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4AFD2AF5C; Wed, 14 Nov 2018 13:17:47 +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 A1A242836F for ; Wed, 14 Nov 2018 13:17:46 +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=nMNlXaaVE/WIhU2bxbA6V3xNya7CHrK4hn+V+qyKW7I=; b=U/uF3Cl4AKMGqA 6YsJTeUvTAath2mU4fXfuSeqWILCJF+fPl4JXwS0mUlJ2EFcS/mT5F5jKhvh1eZzH8RtAG2nUqW7A Dt1MjzfOCtrKgm8paCzUTUOVIfEl/QvOc9xYJb9FZSoFnv4rxejeXDqRoHeDAFyfcJGK31JOv6SGm Qv6foka/crTs/PyqWOL/2IuC2NuGbw3euZvakGBhVpz6to6+QD2Lk/OPcybgBu0OlYDXYI7AGsiYD zxyemBoaAdTt665qVbDsg82KB1NFsaKAMgNsrSnD7g438oDlWPvPzqohxGANiUqHbvFthka2Dt1ds 3E1cvkb29wjghGOyogKQ==; 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 1gMv3B-0005s3-Fz; Wed, 14 Nov 2018 13:17:45 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMv2A-0004sf-J5 for linux-arm-kernel@lists.infradead.org; Wed, 14 Nov 2018 13:16:45 +0000 Received: by mail-wr1-x444.google.com with SMTP id v18-v6so17246311wrt.8 for ; Wed, 14 Nov 2018 05:16: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=bDeoCsW4e2/PqpYJWhPRhKB9U67T/OsHGtJ3I/CIM6o=; b=H866HoLOLhOjyFjFG5YOBroezSr86LkTspEZ7Un1kpUZtTEW0uWt2q+jnyAHAOYSut c4PTWcThNpc90PcIJKkXaxFbDv5bDth22k4auLBdAkb4BS9FqhRO3VzQv1PI9EITRyHk uqT3BGDkNBoF14DHZKmiWa0LRvgZNyclpd1k64TU9h14m16+U5A1qdpkdkaxzey14Sfo s+9zt4ttFfvuzF53WQxHWVplXEMnu889yxGbWrCCD66HO5MzYjQpIjfECyq0RqNhRIXg vd42qyNLopK3f+aAI5HJMPnCb8smVZhacvcuD0Si4q6qCrlC8eRTZFhT4VwGeo/x4Yaq +n0w== 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=bDeoCsW4e2/PqpYJWhPRhKB9U67T/OsHGtJ3I/CIM6o=; b=t4mzmCdy6dlEq07SNDY0Ok8fX/KUJbiM8xQH3R5aaNmW0Qm+fPirb6HeumE5YUMAqH Cz12vwinzUJEhSUHwb9S+o/gKp6Nh664gMQLSvEzzXAdKt1/+wN/apJLx8RCyhq3TEJe wVmLsSnViJfSym8yhSD4Tee5egW2TmMvfhzD7DBGi8fPQopZRSFXIl+sc01twDWrWmSE IthV39owl4iHNt+KzF8SjVm7tTUas1lscPu2yPzbAZwLGopgXH3mpWPli+n1UOQ0mSyo wSK9lMTqlfta94vbxRcfrrVBDa7xE4jDtb9F5q+C4jV+ZHWvXLpJq/+6LNzH3e08oHq4 1rCg== X-Gm-Message-State: AGRZ1gJED8MpCIupmbfBiR0TmbeNyr/7R4FEtTklo+n5VBP4BX+/lcA/ +9XHeM9MF/1Xw/FJXVMNAA52og== X-Google-Smtp-Source: AJdET5eyC2q1R6TmxI8SeOlUg1JHYj9yU12R/veRxvnuALJnNSC9ySkAMg8/MTOxR5g17bxeeS6s2A== X-Received: by 2002:adf:e808:: with SMTP id o8-v6mr1915118wrm.112.1542201391407; Wed, 14 Nov 2018 05:16:31 -0800 (PST) Received: from bender.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id z7-v6sm22715225wrv.21.2018.11.14.05.16.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Nov 2018 05:16:30 -0800 (PST) From: Neil Armstrong To: khilman@baylibre.com Subject: [PATCH v2 2/3] soc: amlogic: Add Meson GX Clock Measure driver Date: Wed, 14 Nov 2018 14:16:26 +0100 Message-Id: <20181114131627.17766-3-narmstrong@baylibre.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181114131627.17766-1-narmstrong@baylibre.com> References: <20181114131627.17766-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_051642_651662_20CA71DC X-CRM114-Status: GOOD ( 21.28 ) 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. The precision is determined by stepping into the divider until the counter overflows. The debugfs slows a pretty summary and each clock can be measured individually aswell. The clock table covers all GX SoCs (GXBB, GXL & GXM) even if some clocks are only present on GXBB or GXM (i.e. wave420l) but the counter returns 0 when the clocks are invalid. Signed-off-by: Neil Armstrong --- drivers/soc/amlogic/Kconfig | 8 + drivers/soc/amlogic/Makefile | 1 + drivers/soc/amlogic/meson-gx-clk-measure.c | 293 +++++++++++++++++++++ 3 files changed, 302 insertions(+) create mode 100644 drivers/soc/amlogic/meson-gx-clk-measure.c diff --git a/drivers/soc/amlogic/Kconfig b/drivers/soc/amlogic/Kconfig index 2f282b472912..155868830773 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_GX_CLK_MEASURE + bool "Amlogic Meson GX 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..2cc0f9c2f715 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_GX_CLK_MEASURE) += meson-gx-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-gx-clk-measure.c b/drivers/soc/amlogic/meson-gx-clk-measure.c new file mode 100644 index 000000000000..da1a0001cef9 --- /dev/null +++ b/drivers/soc/amlogic/meson-gx-clk-measure.c @@ -0,0 +1,293 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2017 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_CLK_DIV 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_gx_msr_id { + struct meson_gx_msr *priv; + unsigned int id; + const char *name; +}; + +struct meson_gx_msr { + struct regmap *regmap; + struct meson_gx_msr_id msr_table[CLK_MSR_MAX]; +}; + +#define CLK_MSR_ID(__id, __name) \ + [__id] = {.id = __id, .name = __name,} + +static struct meson_gx_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_gx_measure_id(struct meson_gx_msr_id *clk_msr_id, + unsigned int divider) +{ + struct meson_gx_msr *priv = clk_msr_id->priv; + unsigned int val; + int ret; + + regmap_write(priv->regmap, MSR_CLK_REG0, 0); + + /* Set measurement divider */ + regmap_update_bits(priv->regmap, MSR_CLK_REG0, MSR_CLK_DIV, + FIELD_PREP(MSR_CLK_DIV, divider - 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((val & MSR_VAL_MASK) * 1000000, + divider); +} + +static int meson_gx_measure_best_id(struct meson_gx_msr_id *clk_msr_id, + unsigned int *precision) +{ + unsigned int divider = DIV_MAX; + int ret; + + /* Start from max divider and down to min divider */ + do { + ret = meson_gx_measure_id(clk_msr_id, divider); + if (ret >= 0) + *precision = (2 * 1000000) / divider; + else + divider -= DIV_STEP; + } while (divider >= DIV_MIN && ret == -EINVAL); + + return ret; +} + +static int clk_msr_show(struct seq_file *s, void *data) +{ + struct meson_gx_msr_id *clk_msr_id = s->private; + unsigned int precision = 0; + int val; + + val = meson_gx_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_gx_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_gx_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 clk_msr_regmap_config = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .max_register = MSR_CLK_REG2, +}; + +static int meson_gx_msr_probe(struct platform_device *pdev) +{ + const struct meson_gx_msr_id *match_data; + struct meson_gx_msr *priv; + struct resource *res; + struct dentry *root, *clks; + void __iomem *base; + int i; + + priv = devm_kzalloc(&pdev->dev, sizeof(struct meson_gx_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, + &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_gx_msr_match_table[] = { + { + .compatible = "amlogic,meson-gx-clk-measure", + .data = (void *)clk_msr_gx, + }, + { /* sentinel */ } +}; + +static struct platform_driver meson_gx_msr_driver = { + .probe = meson_gx_msr_probe, + .driver = { + .name = "meson_gx_msr", + .of_match_table = meson_gx_msr_match_table, + }, +}; +builtin_platform_driver(meson_gx_msr_driver); From patchwork Wed Nov 14 13:16:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 10682599 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 C97A3109C for ; Wed, 14 Nov 2018 13:17:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA1112836F for ; Wed, 14 Nov 2018 13:17:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE9D528623; Wed, 14 Nov 2018 13:17:28 +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 675E92836F for ; Wed, 14 Nov 2018 13:17:28 +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=dSRdf1N2fAYWNV HrXSABBfjemi0qL75vtghvAQXcA44WIHD2aFynKcuIH8wqBpXSWlKI990+ogTHJlPdJluVyuyk4nR 6TXYVjKaxpsLg6D6rB7JV88G5EzmJCJrZIRG28U4DZhmgp0n8OxzR2sWWrywy5eekddRe9ZZJOKki ZWErGyGqm63scJuV/MTbCGWIn64f7rKvF5J/rjITtIxWVqwCLDGeyxPmyZP1lOi2RnsmiUwY57lRW Y/NqhyOMa5tOf2hIAufBymVf29IlxFYcD5O78Aq0xQ8rs1yYsjsphgerDKZdr9XIQoiaPMGgNTqCI f+9klQYTCyruxUngFXlw==; 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 1gMv2l-0005W3-1a; Wed, 14 Nov 2018 13:17:19 +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 1gMv2B-0004sk-U0 for linux-arm-kernel@lists.infradead.org; Wed, 14 Nov 2018 13:16:45 +0000 Received: by mail-wm1-x344.google.com with SMTP id s11so5390610wmh.1 for ; Wed, 14 Nov 2018 05:16:33 -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=aY3gUgK1VqOiJyFbuySLbyRUgLQLb973zDN8JI8a2/+3XFmsjsspToDZ11s475G9sO /F1qnHs3nc67BMxm5k9xRl3uiV4LWKRnnS3b0mkTads5HwMNtbFhVgF8Rxs9tNIVx2K9 fxjvk3qbMUCvU/KH8Dl81BFwLmWxQlD/nufoDkVXLkeLzT7RTy1DD7xrG85Y6XdN9Up1 axXFtLdQHQBM6t5j7VSCYsFUgM245WnfAK0MtkE4h243R8i5K7oPjCIR+Iiw1wpgAFO2 es2Uj3spaUDHX6vTxKg9AzdHf/yUizxpUzjtRZ3349GdjgvFTNj4te+dQ9hiU+x8EGVh Ym5Q== 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=dqNprtEdlM4KcZzTr7tq6KRub/j0z8GrtECDJLfp1o/s+GFRv61tctBblogIaNvUsA EvTJ9iYCZkKVg2/CNxzqZqcysZH+T4X1JEbaH5iiOd6OrnyangGPOFloAI0K78IWJR2T N/dQ/clkxKkU2km19qwX1CMyX1GHbZ1frtnWaTReealz5p1jK0QWlm10hfUgr/q3K1bP BjVBwpaMn10I+epsl/H15qocm3gbniU87pwAsli3kBZnAIrbRPNBV1UHMn1PX763pFX7 VWZOre4TU8YLOiIMAqc8NhuKC54rNqziC/hPAcIR1yW68kHiCBzpal3yJ48sScm0CkY+ 9/QA== X-Gm-Message-State: AGRZ1gK7TjL0Cak1nSgf+FzbhIkp21lKklPSc/MtVwcYdWT1Iz3HOF+K 8ixpDir8fWgQ6JjYm9xyRqoKkg== X-Google-Smtp-Source: AJdET5cT5noX5Z24TSDlbfpGKr46Fzbd2z9R23ntFeaYAcs/fJlnJTPzmyw8wBB192M6wXLHuH+uAw== X-Received: by 2002:a7b:ce8b:: with SMTP id q11-v6mr1980133wmj.10.1542201392123; Wed, 14 Nov 2018 05:16:32 -0800 (PST) Received: from bender.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id z7-v6sm22715225wrv.21.2018.11.14.05.16.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Nov 2018 05:16:31 -0800 (PST) From: Neil Armstrong To: khilman@baylibre.com Subject: [PATCH v2 3/3] ARM64: dts: meson-gx: Add Internal Clock Measurer node Date: Wed, 14 Nov 2018 14:16:27 +0100 Message-Id: <20181114131627.17766-4-narmstrong@baylibre.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181114131627.17766-1-narmstrong@baylibre.com> References: <20181114131627.17766-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_051643_983790_D615324E X-CRM114-Status: GOOD ( 12.24 ) 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 --- 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>;