Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9782604rwl; Sun, 1 Jan 2023 10:01:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXtoMzTwJu4Uf9soXqfG2dGzM+bkjynGzPEs6Y35Xz8ri/dSnlmM8fK4b2eJ+2qCfyd3hORo X-Received: by 2002:a17:906:555:b0:7c1:47bd:1814 with SMTP id k21-20020a170906055500b007c147bd1814mr32067864eja.63.1672596078582; Sun, 01 Jan 2023 10:01:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672596078; cv=none; d=google.com; s=arc-20160816; b=BDawMzdl+oJWXMlzDfX3CyNNXQlXTDl89rsHgGbGgb2huhP6XvIubNNZD4MVypNYih BttmwpkWf8ajOq2j4cdU8jOL3naAiLxMZV+A9Z53cUTFwLL/2owsA6NUpoxE19wvYZXk TrgAdNmn12a+dWFlAatoiEUmRn4aYTGv1DPZ9y8Ix5Fbsmg/3HyaFoUwmkPU7pWgvnLK vViL73qwAy6sVqdWYihvBeM5IBO+g0w4WtyQ3imWma8S3/ENYMUnz9dseaOPRbsoUykZ gZ4Y2dSqPYqFsW3s9Pbj86JNua9q26d3E26eKADU5zcSO6XxsEmznlyKsjhDj9WFIxjK epzg== 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=MLDPwIRHLBEzFrNMDd85lbKLR9rlsRWR9lQbk5mvRTo=; b=x4Ci9kfqhREpVq5bIiXyzRWwzmtd9nGXaPy3f76RjAOaEGqDOeMyMzOPBCsMLkrFlI X44PVUwLw7eE34Prha+rl+wVZtWi2zy5SxjApDec2e9M1Bpo+NDpTCT7L3yovVGMzofV mBxB6KmuySOV36nrr1t+ZkZNZr9mQeAzsS73dqv+dokIWF8rgXq/G6uRpQvYr/Ly1vCY aRdrPbHhXSFhzHbg2sERko64LLTg3QGYqxJuJNwkr4svv/evCBltC5g4er36nRayu7lo /sdqQg4hQ75nwFpDrwEHM3ONyfdZJCfzeAH/KJ9wTPx5Mpogw5k6J5nW0WsWAw2LJY/X E+oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="JLVKvue/"; 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 hb7-20020a170907160700b007c60482a110si24883850ejc.625.2023.01.01.10.00.59; Sun, 01 Jan 2023 10:01:18 -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="JLVKvue/"; 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 S230269AbjAAR6V (ORCPT + 60 others); Sun, 1 Jan 2023 12:58:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231582AbjAAR6D (ORCPT ); Sun, 1 Jan 2023 12:58:03 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C06262DEC for ; Sun, 1 Jan 2023 09:57:59 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id kw15so62160609ejc.10 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=IKLR9h8HrNwPnuFDsy5stzwFinjl8v2Am2U+6xRcqkgySWWohXKK7z/fFzzuSbSih3 mgj8O6IGTJ1ijf4qFxXiTJayK+rGgCd/+u9uZJfJnHnPzjN9AXo7zUVJku8qo7agOFrK qYcTFXydqUGtXl9iK+PbsaHvdHOsS2W1MvNmKKb8ZJAMgs3C3G0aITFk5FSQKLFu1KXg XGfSytunxrrY9+qbNzjurqEX0mEGlGcWIrfM4al7hWHGaE1SVYLHET6+94Q4gmnRuYFy gjwr10kZyNOaj0predQHzHdet5U5NUY/a4bXz/Viuj5WluNqpsZkd4MCfwdakGnbRwsg Onrg== X-Gm-Message-State: AFqh2kpDc+TxMmvOAm/Jy8fAFCN1AVhiMP7Y8P7BwC83/4e8GbAeOgNy 6AtIwhTTSQCtduzAwyN/dwl4Az1uVKs2uUvHbfY= 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 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 --- (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); -- 2.32.0