From patchwork Sun Jan 1 17:57:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 13086415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0AD30C4167B for ; Sun, 1 Jan 2023 18:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RkB5ML5XKRVahilC+fp8/B1lI/3A1oAoFfgvisTabC4=; b=ShZCH1xXxDOk7h ymelBql4VAF054IE/6GJ3Z+DQpqEJWzz6sKdeVqt1VSqBtnBWts8HpiGOqiAJeB9tugpS9J6Dr5Gw PaOyIWfwGjK7VDQiRsJrfjUMpKi5cOHiyXlFPViA9ZBVax8xejZleH2PtwAXdwmj37BJj6lSZ19lW 4SkJWbeGOgRtUWXvbGFO8Hf1BTPzATNGHBgA4exGRCeOls/beSC1U8Hbe++XLRE36WFurr7w/Xfnu ngHBIWIY3eupS/iR7k1wwIrEfb1CL47cs5RLMcNE55Bp9jImz3bw/SeImJo8Csr9upiaBcvDG1xW8 BRv1MKyTyTMLs0MK7VJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pC2gZ-003VVH-Us; Sun, 01 Jan 2023 18:03:53 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pC2at-003Sg1-DQ for linux-arm-kernel@lists.infradead.org; Sun, 01 Jan 2023 17:58:01 +0000 Received: by mail-ej1-x630.google.com with SMTP id fc4so62184927ejc.12 for ; Sun, 01 Jan 2023 09:57:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MLDPwIRHLBEzFrNMDd85lbKLR9rlsRWR9lQbk5mvRTo=; b=JLVKvue/o9CAWRLa18rsHSmXIkadbvT+YQGR3dNfCfvq5dx4I+8c8agfGLlEr8vIEC 76cWrvxHMef/pUeG5BaKehESuTaiyevWPgW+ZNR02UgVR0vnxBxtRNI9tCLdSTDHC3xe AwKqE/HGDcFshTZOEsELJXcsrJi5HElEv4+t4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MLDPwIRHLBEzFrNMDd85lbKLR9rlsRWR9lQbk5mvRTo=; b=w9gK8reDcmm5FUTHC23drvGTRLyGO56t5L0a9fbsxhc86ItAQ/3dgrfhjSBZ+X9tYf DM4tnBZ4K7nhkx8aLx6EL10wVHYYUpQLbhAp38wDtCgkgogrp7X7ut/PE9YSIXiGNHZM N2CTUEy1RShKSKq9wvfWqwkDDjZyf9oib+usWrIDymnCeQBDekVfjclrmi8FahtFc/vj nHLN71YbMxi8GIbPs30+TJD4eqm+rUQlsLTooZKnhepK+kexWFC6J6jCzoglmKtRBwxv GGq/R1UmKymSSCRHA2jpWvc/XVTQmf5N+y8MeY5g43qchvfW0MF8IgK9Y9bP63ch0/Es 5xRw== X-Gm-Message-State: AFqh2krn+KXQGTaMKOIcq/JMHt+c2MafECcYyO2cVl7YnDP04ToyIwxC eQF4kIMk1DF43XJrPR0Bf2Bdmw== X-Google-Smtp-Source: AMrXdXue59OOyc4Qus3KY0gCjjRGY6RHTdubhxNnBOUVsir2bJHxWwxXxVuRbK3jjaem8N4N6NyKHA== X-Received: by 2002:a17:906:f854:b0:849:7688:3e3e with SMTP id ks20-20020a170906f85400b0084976883e3emr24437974ejb.44.1672595878202; Sun, 01 Jan 2023 09:57:58 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-180-23-57.retail.telecomitalia.it. [80.180.23.57]) by smtp.gmail.com with ESMTPSA id q2-20020a1709063d4200b0082ddfb47d06sm12273018ejf.148.2023.01.01.09.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Jan 2023 09:57:57 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: angelo@amarulasolutions.com, michael@amarulasolutions.com, tommaso.merciai@amarulasolutions.com, Chen-Yu Tsai , linux-amarula@amarulasolutions.com, anthony@amarulasolutions.com, jagan@amarulasolutions.com, Dario Binacchi , Abel Vesa , Fabio Estevam , Michael Turquette , NXP Linux Team , Pengutronix Kernel Team , Sascha Hauer , Shawn Guo , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org Subject: [RFC PATCH v2 08/11] clk: imx: gate2: add device tree support Date: Sun, 1 Jan 2023 18:57:37 +0100 Message-Id: <20230101175740.1010258-9-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230101175740.1010258-1-dario.binacchi@amarulasolutions.com> References: <20230101175740.1010258-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230101_095759_535143_4B3E9885 X-CRM114-Status: GOOD ( 17.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The patch, backwards compatible, extends the driver to initialize the clock directly from the device tree. Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/clk/imx/clk-gate2.c | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/drivers/clk/imx/clk-gate2.c b/drivers/clk/imx/clk-gate2.c index f16c4019f402..b28150bf1ff6 100644 --- a/drivers/clk/imx/clk-gate2.c +++ b/drivers/clk/imx/clk-gate2.c @@ -12,9 +12,26 @@ #include #include #include +#include +#include #include #include "clk.h" +#define CLK_GATE2_CGR_DISABLED 0 +#define CLK_GATE2_CGR_RUN 1 +#define CLK_GATE2_CGR_RUN_WAIT 2 +#define CLK_GATE2_CGR_RUN_WAIT_STOP 3 +#define CLK_GATE2_CGR_MASK 3 + +#define CLK_GATE2_MAX_GROUPS 16 + +struct clk_gate2_group { + const char *name; + unsigned int share_count; +}; + +static struct clk_gate2_group clk_gate2_groups[CLK_GATE2_MAX_GROUPS]; + /** * DOC: basic gateable clock which can gate and ungate its output * @@ -175,3 +192,72 @@ struct clk_hw *clk_hw_register_gate2(struct device *dev, const char *name, return hw; } EXPORT_SYMBOL_GPL(clk_hw_register_gate2); + +/** + * of_imx_gate2_clk_setup() - Setup function for imx low power gate + * clock + * @node: device node for the clock + */ +static void __init of_imx_gate2_clk_setup(struct device_node *node) +{ + void __iomem *reg; + u8 i, bit_idx = 0; + u8 cgr_val = CLK_GATE2_CGR_RUN_WAIT_STOP; + u8 cgr_mask = CLK_GATE2_CGR_MASK; + unsigned long flags = CLK_OPS_PARENT_ENABLE | CLK_SET_RATE_PARENT; + u8 gate2_flags = 0; + unsigned int *share_count = NULL; + const char *name = node->name, *parent_name; + const char *str; + struct clk_hw *hw; + u32 val; + + reg = of_iomap(node, 0); + if (IS_ERR(reg)) { + pr_err("failed to get reg address for %pOFn\n", node); + return; + } + + if (!of_property_read_u32(node, "fsl,bit-shift", &val)) + bit_idx = val; + + if (of_clk_get_parent_count(node) != 1) { + pr_err("%pOFn must have 1 parent clock\n", node); + return; + } + + if (!of_property_read_string(node, "sharing-group", &str)) { + for (i = 0; clk_gate2_groups[i].name && + i < ARRAY_SIZE(clk_gate2_groups); i++) { + if (!strcmp(clk_gate2_groups[i].name, str)) { + share_count = &clk_gate2_groups[i].share_count; + break; + } + } + + if (i == ARRAY_SIZE(clk_gate2_groups)) { + pr_err("failed to get shared count for %pOFn\n", node); + return; + } + + if (!share_count) { + clk_gate2_groups[i].name = + kstrdup_const(str, GFP_KERNEL); + share_count = &clk_gate2_groups[i].share_count; + } + } + + parent_name = of_clk_get_parent_name(node, 0); + of_property_read_string(node, "clock-output-names", &name); + + hw = clk_hw_register_gate2(NULL, name, parent_name, flags, reg, bit_idx, + cgr_val, cgr_mask, gate2_flags, + &imx_ccm_lock, share_count); + if (!IS_ERR(hw)) + of_clk_add_hw_provider(node, of_clk_hw_simple_get, hw); + + pr_debug("name: %s, parent: %s, enable-bit: %d, flags: 0x%lx, gate2_flags: 0x%x\n", + name, parent_name, bit_idx, flags, gate2_flags); +} +CLK_OF_DECLARE(fsl_imx8mn_gate2_clk, "fsl,imx8mn-low-power-gate-clock", + of_imx_gate2_clk_setup);