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: 10682581 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 385EC17F3 for ; Wed, 14 Nov 2018 13:16:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1F0D2836F for ; Wed, 14 Nov 2018 13:16:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B63602B461; Wed, 14 Nov 2018 13:16: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 6D5892AF5C for ; Wed, 14 Nov 2018 13:16:47 +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=YzYfvKTOJp1vKqA0WizrLGipNsM4GQYajtz64/YGg14=; b=d5pnDGhVwIKLiB sdRI/T1iNxx60mD8m4pIxaQNJ8iQUaum6XjQYh+gTpu9EdfdbMbGkWgTeXsk5s1nUhPQCdGou4hvF VDjSbm+60QFMUstCeVW2iw7ufhqr1BsXT4S6JcTOp1bqozzLCD3WC69XDTK5xe91+jgMGPbGiL7rC pK1ea+C+EN8TbDv3vrfdWqnjfJM7tGuVOuAA3JPkpNhdMkpy1abdn0LDHkTiwNi1wtH/mF69k1aft XUaQ4layHRWYcELo8juoK7b6a4IsNSFslDi6p3rJARTLxzcgB22PH7RYdJDYfuhzlWcIkaVny4Ja1 lfwpxiADg0gLzdCL55bw==; 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 1gMv2E-0004vz-1p; Wed, 14 Nov 2018 13:16:46 +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 1gMv2A-0004sU-Bf for linux-amlogic@lists.infradead.org; Wed, 14 Nov 2018 13:16:43 +0000 Received: by mail-wr1-x443.google.com with SMTP id v18-v6so17246251wrt.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=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=IcuNYOxBgLqa1Or6darbvsAz4RUyhm58UZs63i5G5sXGrpSineIsABYYBKYDKPyxKt rF7dQYmSNPovsax7quP0P65CwGuHXXgVn99IMwZHs/Y9LEw8uEoKm1+3h/ghBWzgH7qe L6BYeMCm7lhhBzKfp2Ms2imT5zuaA21kMJAFUlGc2zEBd7hkC8Tse1WLL/OA3LIDExqm 0mc75ZkZM97tWHg4HilnbXwlTVBMdtR2CRgr6BaJgvyUvjCJShvyoPh10eqf6DZSIy66 beshQv1E46FWNMhdOxQbiJPUb9Gg5bIRLF70oK9rDYtZr98k3x8ayiLzLTgX8s2TOiWz eOfA== X-Gm-Message-State: AGRZ1gIVMQ5g2Fi/noqbuI9seQtNdGB6fkc+f37k1adSoyjxP0N3IIV4 +tmMSI0Wiq3q5ksgfCglbtb1+JuqcSA= 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_399175_DE3DB09A X-CRM114-Status: UNSURE ( 9.82 ) X-CRM114-Notice: Please train this message. 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: linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=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: 10682603 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 D719817F3 for ; Wed, 14 Nov 2018 13:18:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6BEB2836F for ; Wed, 14 Nov 2018 13:18:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAF142B2A4; Wed, 14 Nov 2018 13:18:09 +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=unavailable 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 1BC5F2836F for ; Wed, 14 Nov 2018 13:18:09 +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=olCAt/l9WIc9K0+OaHH8FG6JuOgDKzqV4ajuNmzhCfQ=; b=DAGqI8Sxh+yXO8 nXd9teT/qyVdXf99frwRnI4AFXn30inuK5UpM1lBngVA5V0goc8AYSd3S/0y0nC/V+FG8bkOz+FlZ iHfmegPVe+6Mci27Gm3XxptZQPoB52Rs+mMCtRA7koQ/I5mAfaTHYRVB19yImvblmLweeYTEVEJlx VoElAhp6iuf/I5e8O4taRlBEPyUGILEyI6gT+YnlP+IZ0t8tmSfwzWzZQ8YYmenPgFY0V0NF6tUI1 Qqkp6icZc9ROqaiCtIlaQ3S+FwwUoxPWrtNfYxAOmbZoDilmW6WJiMohr7zbLsUkxlmGl0Qtet1Be MfrIZesD/3tPmY+aQ6Zg==; 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 1gMv3X-00068i-8E; Wed, 14 Nov 2018 13:18:07 +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-0004sg-J2 for linux-amlogic@lists.infradead.org; Wed, 14 Nov 2018 13:16:45 +0000 Received: by mail-wr1-x444.google.com with SMTP id e3-v6so17273607wrs.5 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=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=FGdgwPRUv0xLgwwiYjTI2+d//HPdzakx7E+cXPu0tTNoSy7rj2J6aBujTFQFsUCMz4 167Zg+PzqaPPxHrWIHjvfNxCp8Ur1tW7daZgj/50MsgVh3gsqgTbrBGwHmOKg53208ro eLEaus4/srv+/NU8dwjBUQff8M2vP7Tgb8iwfY1uoJs4EviGgSPaDbWylBNt6rMYkhY5 JETHN+VbzwifXC7RHQ/A37JRvlT0pDk2wjRakY0yxKVPejkypFDY/wttdH0/U646Qd80 sYgXOnPbXjGZgDG4YWaHTIwlAg5GeaumalS9w90Oh6iiRyVaXDfbhaOYrN5NEdQA5Env yWLQ== X-Gm-Message-State: AGRZ1gL/CbdHxWxC7Ma/mtwfonwIqCFik4yIvA3sgwTKz6WWUr58naCB HLzemKhPV6upR9soTx9nS/K7TQ== 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_652959_18812D92 X-CRM114-Status: GOOD ( 19.41 ) 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: linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=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: 10682605 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 17DA5109C for ; Wed, 14 Nov 2018 13:18:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 098B4285E1 for ; Wed, 14 Nov 2018 13:18:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F18FB2B2A4; Wed, 14 Nov 2018 13:18:14 +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 72FE0285E1 for ; Wed, 14 Nov 2018 13:18:14 +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=IZdm8WbuOz+9XQlyY4mntoijbi8S7h0SI+85iayFhow=; b=DHGWwVD+Taowbs XiuRmYeWh0/YLHe+U5CY5WR3RxErvWACklNTHxwuyqANPiBRdS+YWfsH/1sld3Id5onY+6qp4bv/5 8pL8NeodmalrfrcbYQSfV9KQOOm5j2CcwA5X+WFXthYh86mpfI5y8ayxtmdPrRb3VU6isOYSiC1Yc r5s1RSDdVGcTr/+BJ0uGvBgXsgi8PBmdf0ydRBZsv9gP1C+bcJjbLVMph8aA8R5bhNqRGe933bmUL jCaLOv3r5rgPRMXV/knhp0ejlOPPSdw49uvbuLPyn36ZNjg7FCwTZGdQaAcq5eKB2xJNKwqTv8iTm lwcjfyaFIYrhgGipWECg==; 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 1gMv3a-0006BC-9Q; Wed, 14 Nov 2018 13:18:10 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMv2B-0004sj-Tq for linux-amlogic@lists.infradead.org; Wed, 14 Nov 2018 13:16:46 +0000 Received: by mail-wm1-x343.google.com with SMTP id r11-v6so15375006wmb.2 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=cx4GC7cMb4Z+rIy8Zhumog3NmUdwKvFBNauh56uSCriIqQyV8BMuUGjKH12SNyjyWB mHlk3raFhX2uqogVaYSgU/1rY/oH0LJGgBCiBtZo/lvywkWRr0mAaqFz/m7CQdbtpLFc fynaO9717A9SyHS1GK8QMzeYkfw4ViCquJpw6LhScAAXALlugxBYl/BerEyOBJDnr2I1 XCpKdhp8NetdTz313X61D7RQ5zoffK0/mgI2+NF9HQjd89+4zROckAg5BZdj0e/duBl7 /N7ws3jOaylrsMdbQVdUA1p6JTGSFGIN2yB90bOBfIxB2uvKFHCx9SmtafHQPFA4FLS7 OlWA== X-Gm-Message-State: AGRZ1gIiv8DDXHJvKHpQ6STrCFElnF2yIsdltgiZCJelVHzHRlXZbK5x swxWHwnoAZMNPeKMC6cS1hTu4Q== 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_980202_71582074 X-CRM114-Status: GOOD ( 10.36 ) 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: linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=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>;