{"id":2175813,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2175813/?format=json","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/1.0/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20251218-clk-mtk-mt8365-fixes-v1-7-4f8ff0de3268@baylibre.com>","date":"2025-12-18T23:23:27","name":"[7/9] clk: mediatek: allow gates in topckgen drivers","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"2df5866425492e62fb1848bc832c8d9622493bea","submitter":{"id":87228,"url":"http://patchwork.ozlabs.org/api/1.0/people/87228/?format=json","name":"David Lechner","email":"dlechner@baylibre.com"},"delegate":{"id":3651,"url":"http://patchwork.ozlabs.org/api/1.0/users/3651/?format=json","username":"trini","first_name":"Tom","last_name":"Rini","email":"trini@ti.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20251218-clk-mtk-mt8365-fixes-v1-7-4f8ff0de3268@baylibre.com/mbox/","series":[{"id":485931,"url":"http://patchwork.ozlabs.org/api/1.0/series/485931/?format=json","date":"2025-12-18T23:23:20","name":"clk: mediatek: mt8365: fix clocks","version":1,"mbox":"http://patchwork.ozlabs.org/series/485931/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2175813/checks/","tags":{},"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=baylibre-com.20230601.gappssmtp.com\n header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256\n header.s=20230601 header.b=HhxqxYC6;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)","phobos.denx.de;\n dmarc=none (p=none dis=none) header.from=baylibre.com","phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de","phobos.denx.de;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=baylibre-com.20230601.gappssmtp.com\n header.i=@baylibre-com.20230601.gappssmtp.com header.b=\"HhxqxYC6\";\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=none (p=none dis=none) header.from=baylibre.com","phobos.denx.de;\n spf=pass smtp.mailfrom=dlechner@baylibre.com"],"Received":["from phobos.denx.de (phobos.denx.de\n [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4dXRhv0kZ5z1y2r\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 19 Dec 2025 10:29:51 +1100 (AEDT)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id CD082839DF;\n\tFri, 19 Dec 2025 00:28:37 +0100 (CET)","by phobos.denx.de (Postfix, from userid 109)\n id D6209838A5; Fri, 19 Dec 2025 00:24:47 +0100 (CET)","from mail-oi1-x229.google.com (mail-oi1-x229.google.com\n [IPv6:2607:f8b0:4864:20::229])\n (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id A0FE0835B3\n for <u-boot@lists.denx.de>; Fri, 19 Dec 2025 00:24:45 +0100 (CET)","by mail-oi1-x229.google.com with SMTP id\n 5614622812f47-4510974a6bbso438483b6e.3\n for <u-boot@lists.denx.de>; Thu, 18 Dec 2025 15:24:45 -0800 (PST)","from [127.0.1.1] ([2600:8803:e7e4:500:67e5:27b0:56a0:f05d])\n by smtp.gmail.com with ESMTPSA id\n 5614622812f47-457b3be228asm300334b6e.9.2025.12.18.15.24.42\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 18 Dec 2025 15:24:43 -0800 (PST)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,\n DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham\n autolearn_force=no version=3.4.2","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1766100284;\n x=1766705084;\n darn=lists.denx.de;\n h=cc:to:in-reply-to:references:message-id:content-transfer-encoding\n :mime-version:subject:date:from:from:to:cc:subject:date:message-id\n :reply-to; bh=VNnsYUzluZah7JCthe9zOSPNJoqqZGPX0lsyTM7RmkI=;\n b=HhxqxYC6bDoOu+Y+A6F0kzg4Ve6WY3yBZoWgVZqVOlGCCZR+z7+w6w2XJk8jVfFnXt\n 9j2QMyGfV1eUst7ec0LjGqib83DYMsC1cB1vct7pXmuUk04L76lBOfBsZPg7DWaaAF9H\n 8RI6FeEUw6mJUzRtwWzofRfoGaOO/ERnfuPFFDIlkU1hOKXGQgTl3OkkglcO6Di0SB0T\n Yej40LhE5PfZ7FlCCfgPb7jnSZymMtPw/BE0Z04vWYCPFyI/dMds0wV0yowek3lHQ4Vj\n JbXxsJxsu/n/LDesOWHp33yeLeMlKdKlWyA4KTdLZyvP8Wc9MxRDz15OhxzZ+KH54uMJ\n RfoQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1766100284; x=1766705084;\n h=cc:to:in-reply-to:references:message-id:content-transfer-encoding\n :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to\n :cc:subject:date:message-id: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k77jWNOI89aHTSzRdPNLe7wXqDgMkeaOQrHl5+qIRj+FFO21K/\n QYT8ukpZQ4cSxQvxA=","X-Google-Smtp-Source":"\n AGHT+IEWahqvjVO97F5Lxd24hKoAqX18NcgdmEcZzxQxt9ZW6mw2F5KpMg3vJRVckSH2DM2hf/+TGw==","X-Received":"by 2002:a05:6808:159a:b0:450:125d:d9e with SMTP id\n 5614622812f47-457b20b0d14mr706132b6e.21.1766100284370;\n Thu, 18 Dec 2025 15:24:44 -0800 (PST)","From":"David Lechner <dlechner@baylibre.com>","Date":"Thu, 18 Dec 2025 17:23:27 -0600","Subject":"[PATCH 7/9] clk: mediatek: allow gates in topckgen drivers","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20251218-clk-mtk-mt8365-fixes-v1-7-4f8ff0de3268@baylibre.com>","References":"<20251218-clk-mtk-mt8365-fixes-v1-0-4f8ff0de3268@baylibre.com>","In-Reply-To":"<20251218-clk-mtk-mt8365-fixes-v1-0-4f8ff0de3268@baylibre.com>","To":"Julien Masson <jmasson@baylibre.com>, Tom Rini <trini@konsulko.com>,\n Lukasz Majewski <lukma@denx.de>, Ryder Lee <ryder.lee@mediatek.com>,\n Weijie Gao <weijie.gao@mediatek.com>,\n Chunfeng Yun <chunfeng.yun@mediatek.com>,\n Igor Belwon <igor.belwon@mentallysanemainliners.org>,\n GSS_MTK_Uboot_upstream <GSS_MTK_Uboot_upstream@mediatek.com>","Cc":"Julien Stephan <jstephan@baylibre.com>, u-boot@lists.denx.de,\n David Lechner <dlechner@baylibre.com>","X-Mailer":"b4 0.14.3","X-Developer-Signature":"v=1; a=openpgp-sha256; l=4310; i=dlechner@baylibre.com;\n h=from:subject:message-id;\n bh=VTQb0wPygvFq7lX9ZsvswsYreIjNQQ8htn6irAWc6W8=;\n b=owEBhAF7/pANAwAKAcLMIAH/AY/AAcsmYgBpRI0cHLUQv2PL/m0/1SE+eqn9uPSi/nNIV4vHt\n O7w4ha2AreJAUoEAAEKADQWIQTsGNmeYg6D1pzYaJjCzCAB/wGPwAUCaUSNHBYcZGxlY2huZXJA\n YmF5bGlicmUuY29tAAoJEMLMIAH/AY/A2nsH/jE6SysRU8PxFSIe1j1XCk1KIfnQszNlw0nQgDe\n uSvnuPaJtK7qIy6iESq38OMrOw/CHEn/mGL27HKOVrQrYbgaz0UGBBTFDHLznaLCBYJD5Vyspmh\n /ZRdTdCJmjNiY3OY8ULFGS/xXunXi0fVvd13evdq75tN30QrQ9S9p40Py1iLT6POPf6Ly+6e8NQ\n 3JsyLfJ0idhJvhfSRqqE6eJrYFok+i95ILEZaT3rgVxfrbxftTVxCdZvRmUr1OS1gwuBdf9z/Kd\n aJ1ciZ86b3BVkMwnHP9K11jKeGDbxyb47lTZwObT72ILXVf8ArpEUPMTwtr2geNhieUFD5SCHD3\n oAlQ=","X-Developer-Key":"i=dlechner@baylibre.com; a=openpgp;\n fpr=8A73D82A6A1F509907F373881F8AF88C82F77C03","X-Mailman-Approved-At":"Fri, 19 Dec 2025 00:28:35 +0100","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.39","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<https://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>","X-Virus-Scanned":"clamav-milter 0.103.8 at phobos.denx.de","X-Virus-Status":"Clean"},"content":"Add handling for gates in the topckgen clk drivers. This avoids the need\nto have separate topckgen-cg drivers and devicetree nodes for the same\naddress space and clock ID range.\n\nSigned-off-by: David Lechner <dlechner@baylibre.com>\n---\n drivers/clk/mediatek/clk-mtk.c | 61 +++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 57 insertions(+), 4 deletions(-)","diff":"diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c\nindex e370d304c03..82306ae285c 100644\n--- a/drivers/clk/mediatek/clk-mtk.c\n+++ b/drivers/clk/mediatek/clk-mtk.c\n@@ -582,7 +582,7 @@ static const int mtk_topckgen_of_xlate(struct clk *clk,\n \tif (ret)\n \t\treturn ret;\n \n-\t/* topckgen only uses fclks, fdivs and muxes. */\n+\t/* topckgen only uses fclks, fdivs, muxes and gates. */\n \n \tif (tree->fclks && clk->id < tree->num_fclks)\n \t\treturn 0;\n@@ -595,6 +595,10 @@ static const int mtk_topckgen_of_xlate(struct clk *clk,\n \t    clk->id < tree->muxes_offs + tree->num_muxes)\n \t\treturn 0;\n \n+\tif (tree->gates && clk->id >= tree->gates_offs &&\n+\t    clk->id < tree->gates_offs + tree->num_gates)\n+\t\treturn 0;\n+\n \treturn -ENOENT;\n }\n \n@@ -696,6 +700,14 @@ static ulong mtk_find_parent_rate(struct mtk_clk_priv *priv, struct clk *clk,\n static ulong mtk_topckgen_get_rate(struct clk *clk)\n {\n \tstruct mtk_clk_priv *priv = dev_get_priv(clk->dev);\n+\tconst struct mtk_clk_tree *tree = priv->tree;\n+\n+\tif (tree->gates && clk->id >= tree->gates_offs &&\n+\t    clk->id < tree->gates_offs + tree->num_gates) {\n+\t\tconst struct mtk_gate *gate = &tree->gates[clk->id - tree->gates_offs];\n+\n+\t\treturn mtk_clk_find_parent_rate(clk, gate->parent, NULL);\n+\t}\n \n \tif (clk->id < priv->tree->fdivs_offs)\n \t\treturn priv->tree->fclks[clk->id].rate;\n@@ -740,6 +752,21 @@ static int mtk_clk_mux_enable(struct clk *clk)\n \treturn 0;\n }\n \n+static int mtk_topckgen_enable(struct clk *clk)\n+{\n+\tstruct mtk_clk_priv *priv = dev_get_priv(clk->dev);\n+\tconst struct mtk_clk_tree *tree = priv->tree;\n+\n+\tif (tree->gates && clk->id >= tree->gates_offs &&\n+\t    clk->id < tree->gates_offs + tree->num_gates) {\n+\t\tconst struct mtk_gate *gate = &tree->gates[clk->id - tree->gates_offs];\n+\n+\t\treturn mtk_gate_enable(priv->base, gate);\n+\t}\n+\n+\treturn mtk_clk_mux_enable(clk);\n+}\n+\n static int mtk_clk_mux_disable(struct clk *clk)\n {\n \tstruct mtk_clk_priv *priv = dev_get_priv(clk->dev);\n@@ -766,13 +793,29 @@ static int mtk_clk_mux_disable(struct clk *clk)\n \treturn 0;\n }\n \n+static int mtk_topckgen_disable(struct clk *clk)\n+{\n+\tstruct mtk_clk_priv *priv = dev_get_priv(clk->dev);\n+\tconst struct mtk_clk_tree *tree = priv->tree;\n+\n+\tif (tree->gates && clk->id >= tree->gates_offs &&\n+\t    clk->id < tree->gates_offs + tree->num_gates) {\n+\t\tconst struct mtk_gate *gate = &tree->gates[clk->id - tree->gates_offs];\n+\n+\t\treturn mtk_gate_disable(priv->base, gate);\n+\t}\n+\n+\treturn mtk_clk_mux_disable(clk);\n+}\n+\n static int mtk_common_clk_set_parent(struct clk *clk, struct clk *parent)\n {\n \tstruct mtk_clk_priv *parent_priv = dev_get_priv(parent->dev);\n \tstruct mtk_clk_priv *priv = dev_get_priv(clk->dev);\n \tu32 parent_type;\n \n-\tif (clk->id < priv->tree->muxes_offs)\n+\tif (!priv->tree->muxes || clk->id < priv->tree->muxes_offs ||\n+\t    clk->id >= priv->tree->muxes_offs + priv->tree->num_muxes)\n \t\treturn 0;\n \n \tif (!parent_priv)\n@@ -821,6 +864,16 @@ static void mtk_topckgen_dump(struct udevice *dev)\n \t\tmtk_clk_print_mux_parents(priv, mux);\n \t\tprintf(\"\\n\");\n \t}\n+\n+\tfor (i = 0; i < tree->num_gates; i++) {\n+\t\tconst struct mtk_gate *gate = &tree->gates[i];\n+\n+\t\tprintf(\"[GATE%u] DT: %u\", i, gate->id);\n+\t\tmtk_clk_print_mapped_id(gate->id, i + tree->gates_offs, tree->id_offs_map);\n+\t\tmtk_clk_print_rate(dev, i + tree->gates_offs);\n+\t\tmtk_clk_print_single_parent(gate->parent, gate->flags);\n+\t\tprintf(\"\\n\");\n+\t}\n }\n #endif\n \n@@ -1124,8 +1177,8 @@ const struct clk_ops mtk_clk_fixed_pll_ops = {\n \n const struct clk_ops mtk_clk_topckgen_ops = {\n \t.of_xlate = mtk_topckgen_of_xlate,\n-\t.enable = mtk_clk_mux_enable,\n-\t.disable = mtk_clk_mux_disable,\n+\t.enable = mtk_topckgen_enable,\n+\t.disable = mtk_topckgen_disable,\n \t.get_rate = mtk_topckgen_get_rate,\n \t.set_parent = mtk_common_clk_set_parent,\n #if CONFIG_IS_ENABLED(CMD_CLK)\n","prefixes":["7/9"]}