Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8264340rwl; Sat, 31 Dec 2022 02:51:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXvpg/zhGyMKDvCW2k/K5E1oF5VFrgA576CNIL/GmoIRQrHhIzq7Mtt2om0bBHwovSYtdy00 X-Received: by 2002:a17:907:674e:b0:7c1:92b2:fa9e with SMTP id qm14-20020a170907674e00b007c192b2fa9emr30456775ejc.59.1672483860001; Sat, 31 Dec 2022 02:51:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672483859; cv=none; d=google.com; s=arc-20160816; b=ENuF4JZ0kEVazvW+ez+vgr8zvb8mLGBr9gLOYhet9PPIiNYBhxHg6X1R8WZjsCqfu1 pr1tMiFMk2gVvv2oATnvCjOLelkX5OYZNFHDsKUccI87Vq31xxop/EvISB0neKQJnmE7 dS5t1bc+osGhIo64d7blhU/rgAJNUNTxI6aQYHzUAYwe5po7AGxC41U+0rUXpvGITN+E VYLJyupoRPMIybchQSVbbB4cR89HPp9axrWPAX8+z2mbxxzeGEiZ8ZcLd7RHPbyiNGxw ROuqUG+PF+nmV2o3iMYRrN4lLl3qMUfrgW2tVooRq1DsuP1+5EBYwQhw/YTiF00eW3Ly 2g3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2nmJF3bEeRxJYrFQdgL7c1Fy/VFwyyC/ez/jfHGKmTk=; b=MwgvJdAB5avIWb6Cegk/gAFkc7KN6zm5Hk8cGkGVCMxQb12tXkuwNPEI8Jgcpr0GYV BB76uk6RLIlgSbO9+5Doi9hQaMc73+VsEf5QxSdIFx/nNM+CbEoNLLvd0BVwY63bNQY7 a+8JwEuLG/cgHUJn+zT859uDwdhT44UggeKArcWcT7YWLPze9IMyfGjfjZ9qnpJ+DSM7 K8kYk/oqZNKHpkgcNBIIHi/eo2kXuhZjG5UOtj77W8RZMKQgIFqRVT0h/EtLQcGCB3kQ k9IjI8b7qlaQNIflSEt0ojUz4kLKFhngxWJsfuFdrTDbcUJgkF4sKO31kFU/80G64ESp Bukg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EIHtuJl7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs16-20020a1709072d1000b007c4f6c37193si20999626ejc.223.2022.12.31.02.50.45; Sat, 31 Dec 2022 02:50:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=EIHtuJl7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235541AbiLaKs2 (ORCPT + 62 others); Sat, 31 Dec 2022 05:48:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231903AbiLaKsH (ORCPT ); Sat, 31 Dec 2022 05:48:07 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C05CFDECA for ; Sat, 31 Dec 2022 02:48:03 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id u9so56514081ejo.0 for ; Sat, 31 Dec 2022 02:48:03 -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=2nmJF3bEeRxJYrFQdgL7c1Fy/VFwyyC/ez/jfHGKmTk=; b=EIHtuJl7Px5jzWvOr0qcRutxwgf6dnRNYLj1qy6cx/ApezQRL7YwyNkTmofDy153pm WUyMaeEYCyXqFkvC13Jq7KilR7OTFSYZqtQCj+EEoZUdG6tHVy8Gn/pzaZUiKv9CihUW tEAOczd8T+FnFe18k9Ndsdg31yarDkD8InlzQ= 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=2nmJF3bEeRxJYrFQdgL7c1Fy/VFwyyC/ez/jfHGKmTk=; b=zJyG5pKHZa8sqca8qCFh3mhuDIKpsPtdoketo1Fyrp9TIDLUeG63mwH7wo+M14uBD2 dA5SV9gm0k0glj9SLiIqSFBh4kXhRTRBw7CUz+ECrV22cJNNSvhLZNxl35QeXTLI9gjN 9srudeq79JNwmi7//UbvCJEWtKHaSmc+bjdZfl6t566+4ZGjcT/Up71UOqr5qTMGz7cK YIDLgR2lqyhq8Y2KbXN1h89bToX31o/E9KESWfoJDLRNHU/uBfh3KxypPh6G3ErmUW0g qx4fJSI3fxuBpjmfPVcMwqmr/Ws86mJUlAneUAgWTCdfbek1bko88RE8hIK4nWaFIM5T kxPA== X-Gm-Message-State: AFqh2krDwjIBsm5yeqAuL4UR4KqNDph5FEBNb97zb6j6gqgDGrnGJPJ9 v6KAwFLzk4GDkjnaoBmePuVgoovNRocc0SCzZk8= X-Received: by 2002:a17:907:8c08:b0:7c1:65d1:c4ca with SMTP id ta8-20020a1709078c0800b007c165d1c4camr10045321ejc.33.1672483682160; Sat, 31 Dec 2022 02:48:02 -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 z4-20020a17090655c400b0083ffb81f01esm10765438ejp.136.2022.12.31.02.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Dec 2022 02:48:01 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: tommaso.merciai@amarulasolutions.com, linux-amarula@amarulasolutions.com, Chen-Yu Tsai , jagan@amarulasolutions.com, angelo@amarulasolutions.com, anthony@amarulasolutions.com, michael@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 08/11] clk: imx: gate2: add device tree support Date: Sat, 31 Dec 2022 11:47:33 +0100 Message-Id: <20221231104736.12635-9-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20221231104736.12635-1-dario.binacchi@amarulasolutions.com> References: <20221231104736.12635-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch, backwards compatible, extends the driver to initialize the clock directly from the device tree. Signed-off-by: Dario Binacchi --- 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); -- 2.32.0