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: 2601 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C976F40F4A for ; Sun, 1 Jan 2023 18:57:59 +0100 (CET) Received: by mail-ed1-f72.google.com with SMTP id c12-20020a05640227cc00b004853521ef55sf10680987ede.8 for ; Sun, 01 Jan 2023 09:57:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1672595879; cv=pass; d=google.com; s=arc-20160816; b=SNJpLNTjP8ocMD03m5TRyVfrEt6Y1FRpbBRCyqho3UYN1NvaZYoc0OqA0LaTUSjXfU mwOMKwtkVNYjNuQWZo7vWYip8ug94Z3Z++MMsFVF74TCGHAmT37DF45MiBrMbUU6WaMc Lwx+l/xZ3pAApXq63MAb161JgGQlxk++43vJ7pb0VsxtNf3EYv5iYs9evZPCkY8oN7Fl NKTb5fU3T/iSN2Ai7p57ZL6VjVQnppKEhZhISqJ0emW1mp1np2xz8Eeh5xJFGtsYzSZf L5H205P3gECCFZtXeDgjv1ArciRVF53cF+GUTYW3vx8nshH+yehuma7Ha7RucTul8cL0 ItDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=LeSicX3Y6Q9JZStYxnbUShus9AZ3eG5qSm2Zcj8WzeA=; b=YgRffEnE41Zui1BKb0POrLDk41B9owvVvDRO4TFtr9cs+zWafzn97i9j+DMY6yNvI7 JnbwFLZFv45Le4MZimigFh++u6pF2+sPjgGs94vxnU332twvoYD3vXh9tuct0TN0IpOY gOJ8RImg9gVvKfSMsf8s949J6E3/uhDsxYMLH9Q8b6FOaq99aX99P3fyvXCnu0btOhNE PoT2+qZT9dBtczPceX6MReYBD/r/Q97Zqiej73JJJIoJ4lykZGUm4ZS223hBpiIEkgwn EPFkEKtJWaZYu0m4PRuDT8HgitvsCwS4xa3HyHPgeiO9ywL0i+8wyEaz5F0bLGq9MsKR NB7A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="JLVKvue/"; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=LeSicX3Y6Q9JZStYxnbUShus9AZ3eG5qSm2Zcj8WzeA=; b=Davu5sCeie907rUBbqQjply42KzzRb3QDTN4uKHvMeuivFymbDmVj3PvlF53e+knej HEmzT5rvFJFL+QNheeqKXotmIXdGnOKdseS2Aa9rl7W/815lPrJr8zMS1XbjuLr4jnBQ QQxcYo3DhaiOXovYMk4gODGOPbpbxphtBsEmY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender: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=LeSicX3Y6Q9JZStYxnbUShus9AZ3eG5qSm2Zcj8WzeA=; b=8NATJEHG6enyyP2xwscwl/oLl9WiMBXweUZ/rrywz0Y2kKfoa798GoR7S5QT+SB8XC M57Vz+ZhdaPKOPdimiD1C0aZDFTiO81d6XBbAFW481IPr57zRlsInEw52aXmIQ3yudD8 HOhYPEtdSd+l7VVVdpDAGuz+2RjA17vC0rCkx2+Fn5aq2LTEUndK/7t/9P7Q1yubOW5S AmQ2dbMhdmlulRmi2ham58FARrqLie2Rm0sFJkZYOXP009SvU4JWr2BPvNRvTCyVSgop 69Mg2ZTjGbeaf3hGUbXuj8BErRnXYH912wqth6TlTmFBcE42BD1zpzeYrLPGbuJgd4KK 5c2Q== X-Gm-Message-State: AFqh2koMfHXsDgLTPlDijKqZc1WPqWaZC96oeehCt0xmBe+/iuj4xuQD kTyEoB7lveNT8Oxl/+svFdtMQcbH X-Google-Smtp-Source: AMrXdXs7rfWz5J7yxmpGFUCk2XKg7LsmZfGap04lJC6OOKSkYy2tAl8Icg0Q2tWTiL8re79SZGksmQ== X-Received: by 2002:a17:906:2452:b0:7c0:d6bb:fd7 with SMTP id a18-20020a170906245200b007c0d6bb0fd7mr2774580ejb.726.1672595879479; Sun, 01 Jan 2023 09:57:59 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:55c1:b0:7c1:2050:cc5f with SMTP id z1-20020a17090655c100b007c12050cc5fls2016742ejp.0.-pod-prod-gmail; Sun, 01 Jan 2023 09:57:58 -0800 (PST) X-Received: by 2002:a17:907:c78e:b0:7c5:f0a3:5d71 with SMTP id tz14-20020a170907c78e00b007c5f0a35d71mr33378185ejc.0.1672595878428; Sun, 01 Jan 2023 09:57:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672595878; cv=none; d=google.com; s=arc-20160816; b=uy1dRgEBkig4h7zZc2czu8oHf2DzRZDL7rB49TJ5f/+oCN6f5dn7O0r0rFyvds/T3G 7/t1L0ZHumP9xOY+H8l6ruomiNGKXynBcyJqtud5cSlWgwnn1Pw9b8m8HS305pKVP7+X 1QL7nw1XJkDmAy4WdRlyTItG/BDCw1hseLA6jDakoXbDTS0Zwwb7lsA++DeHhHa9YTUV jGkMBOqbHRg0HNu72tspAyaJjmI3nvvczoqSo6nLvODg8xtS3e2h1PWLXws/Pd4lo4kc fdaWg3mdvHj+RApSo57QkSR571A2PXHNUgGd5tPndfSmw9ErjnBU4Dlkb+C/O+KEz1tz ceIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=MLDPwIRHLBEzFrNMDd85lbKLR9rlsRWR9lQbk5mvRTo=; b=tcD/nLlFq3eppil3+r1XzRY/lTH8/XUrIQh0qTFeD5SwuenNFIfFXb3Z6vLqRYeMJp 8/luIdU5m92BxMLMBufioLnnHEyeveu5qHDFNyrZehcTzGow5q1XkqYB5EgmDN8RipPP KwjmCVTu+9/1YKBdU2SB6DJH7c/+opcTIE3YuFT5ozmH14BAnR0Uf6Qa5bE8PqeAhEOb VVK0/C7aok0PIYmf+KruC506sgi7r2qirDQxpH+Ia5DQwmmIozgZGuy/xVpqsS3j581Y RCwnaQ9x/CkdgK1pd40tSzZv8lQyZUFxNfAeV7oZ/sUF+w47zygcx9alDG0XZZHr9Qs1 ZoFA== 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 dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id h18-20020a170906829200b008460fa69a61sor11813166ejx.85.2023.01.01.09.57.58 for (Google Transport Security); Sun, 01 Jan 2023 09:57:58 -0800 (PST) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; 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-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="JLVKvue/"; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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);