{"id":2197491,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2197491/?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":"<20260217-mtk-mt8189-clocks-v2-3-cd381cd05251@baylibre.com>","date":"2026-02-17T23:30:10","name":"[v2,3/7] clk: mediatek: add mtk_clk_id_is_* helper functions","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"01d04fae3445c6b57c02f4c068cd4dfdd2f0342f","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/20260217-mtk-mt8189-clocks-v2-3-cd381cd05251@baylibre.com/mbox/","series":[{"id":492497,"url":"http://patchwork.ozlabs.org/api/1.0/series/492497/?format=json","date":"2026-02-17T23:30:08","name":"clk: mediatek: new mt8189 driver","version":2,"mbox":"http://patchwork.ozlabs.org/series/492497/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2197491/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=GGNrkQAj;\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=\"GGNrkQAj\";\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 4fFwsN0zpkz1xvq\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 18 Feb 2026 10:32:08 +1100 (AEDT)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 8AA0D83E13;\n\tWed, 18 Feb 2026 00:31:19 +0100 (CET)","by phobos.denx.de (Postfix, from userid 109)\n id 3ADEF83D17; Wed, 18 Feb 2026 00:31:18 +0100 (CET)","from mail-ot1-x330.google.com (mail-ot1-x330.google.com\n [IPv6:2607:f8b0:4864:20::330])\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 72C6583D17\n for <u-boot@lists.denx.de>; Wed, 18 Feb 2026 00:31:15 +0100 (CET)","by mail-ot1-x330.google.com with SMTP id\n 46e09a7af769-7d4b9c839b1so1846639a34.1\n for <u-boot@lists.denx.de>; Tue, 17 Feb 2026 15:31:15 -0800 (PST)","from [127.0.1.1] ([2600:8803:e7e4:500:b8c6:5b3:8109:1f08])\n by smtp.gmail.com with ESMTPSA id\n 46e09a7af769-7d4c7288d34sm11122198a34.18.2026.02.17.15.31.13\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 17 Feb 2026 15:31:13 -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=1771371074;\n x=1771975874;\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=3Z6HAJgraz4h2NN+YeuMwU+ctavLJKBeaQj87gOsYYM=;\n b=GGNrkQAjtRX2plM2IybC4gP9jNx+bayRQiKs+WnybTttDXNBQWrX7KwcuXEtw6T4yx\n 10GL2CWzmZIDN+bnWEJ+Q9nRjcGGK51r0T1tb+fa6SewCGz5Oc1AaefVHW6dJRbwTerg\n qEaEmN1nOS5es/b1p2h1ypL1L7c+B7ibmk8aNiurSUxoc3vFNW/VMpmuUUbxS2Usni9Q\n wacg3yhWhImhxyvlWMjxx2ACKbpfC0ZZWpo0NNUWa4WJRV92orq+2oQIJTv/PwmUlz1R\n 2BkswVgJm5qAf8QHElqkQmjCxC86DRIxCTiIrICKk6Xxtp0ySUV176Dln3xmXmojE90R\n e0Dg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1771371074; x=1771975874;\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:reply-to;\n bh=3Z6HAJgraz4h2NN+YeuMwU+ctavLJKBeaQj87gOsYYM=;\n b=Ttu47MnTIKxrvduD+5hhmUdEDaqelmZ7FCnPYfH8IDPI3NiPQbN0uB7VoueR/DsYqE\n 4lqHyFezcOrz4GjpinxDu7/o8MwQDs4ugXVjTXwg+pkFrgwUOUN/O7hVv0Fw8+0+bC6B\n 4dblswnwLhxpZnsntYOpuIrtYq+M6/iY+d9TI6yoWCdsmvJkTT0tZZ+l4Ko/j841Zs/L\n tqLxdmQkVyl0JIDtrQDvuXAMEN4g7p9hjf++1rwj1Axfwe5Eoc23NCFGtOn6u0Rycwe0\n vX62sh+hXj86Q/AGpdKsPk/Rdt7fcPOig1+3+h7TSSOmy5x33gPZ9MZAlQlu8TLMnInm\n aT8g==","X-Forwarded-Encrypted":"i=1;\n AJvYcCVWBnyJ2j+zVsYtCmgQfaTIT7MnB96tN6zwzrZrirFRYdR0QSdCdo33Qp4xd3/kimL0lH0yb3Q=@lists.denx.de","X-Gm-Message-State":"AOJu0YykrQMC+Wn3Pkgy3KYmgay8vfjBGDimFik6zin3o1edLpAynfP/\n Tg0b7Bx2sI7o87qedEaFsKvUJs1wqaMFC09ZjG88Ocd2djpSAWN7IsAtD0n+mvzjkGk=","X-Gm-Gg":"AZuq6aITanLYf5xSoGYzgeGGB6C+PMfRf0RncqSX0N+Bd0MbKWAXVer+u12vfXQCmeQ\n pYNgw7UokbO2yLxa0xOpfM3H3wfbbSW3nqH696jOxFbf8z53q6QG7NQ69baScHLNWLkbEzIYlIc\n ugkvXOTGy6DZYGcVTznwEe6KkmQDjv8Ph9n5EpcH+irB+44+rhsavOCvHE8IPWx3dzk9BOWnggy\n 22JrDmwbg+e0g38bl6px1pvXkmb+NjilgI0xdB8X+jUMtHyvku6m68ByT9dJS624hB+YE7q4P5w\n ETlU8+yXQkBkLy6WD6564YOaoBHskThEAxTsNdrp55e/D3aPnJON+xRDUNH+2IkEylzyY6CjeAA\n qji3isw/H7FfpDjLewf77DQG9gNarRkC5rp9LA1s1c1hz1TReKEzAeaJZkIgz/aIudiH9eogPEg\n IXBOO5xrAdKOzzmZPNb9/hK9AoVg==","X-Received":"by 2002:a05:6830:8554:10b0:7d4:ee07:e1b1 with SMTP id\n 46e09a7af769-7d4ee07e2d2mr2713273a34.0.1771371074144;\n Tue, 17 Feb 2026 15:31:14 -0800 (PST)","From":"David Lechner <dlechner@baylibre.com>","Date":"Tue, 17 Feb 2026 17:30:10 -0600","Subject":"[PATCH v2 3/7] clk: mediatek: add mtk_clk_id_is_* helper functions","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20260217-mtk-mt8189-clocks-v2-3-cd381cd05251@baylibre.com>","References":"<20260217-mtk-mt8189-clocks-v2-0-cd381cd05251@baylibre.com>","In-Reply-To":"<20260217-mtk-mt8189-clocks-v2-0-cd381cd05251@baylibre.com>","To":"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>,\n Tom Rini <trini@konsulko.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=9958; i=dlechner@baylibre.com;\n h=from:subject:message-id;\n bh=rQtZzGMOm61RptZkKnMBsoG1ARBDiNoGJZyL1uCk2Gs=;\n b=owEBhAF7/pANAwAKAcLMIAH/AY/AAcsmYgBplPodvV3UPgpxexZbKOTpIbqQc47zWXRZm1ab/\n IoHAAX10guJAUoEAAEKADQWIQTsGNmeYg6D1pzYaJjCzCAB/wGPwAUCaZT6HRYcZGxlY2huZXJA\n YmF5bGlicmUuY29tAAoJEMLMIAH/AY/ABFEH/3hNp+xolEhmrZUzW5iDUO0hU+DoQIxtu8Txp4A\n mklKjwwuxQnVBjNqAXAXW3AQqmWPIG1meWxJYzCopLFVwr/UrT9brMVwtULwuP8kuk/tK236IJb\n qBpE+8nK1DqsAZidnsuze1mnAE4+YHNY+Q68XerGDnaqlrfBigu/qY+vrt0zO1JuCkZl7dm+9P3\n fiZdRrqApdcWV/EL02Jjisu4Qzu+JnYvjkVXftOTXwxAcKjZ9n2B8tOuyT01L5MDlB8lsbYQP0Z\n LVrd6lYAUq5y0r+ThNGntcctNkbJSGia/petjReJRaa/R1Jo2rbLRF+L5KhgZKzNNzEFu9fFAYU\n x4QI=","X-Developer-Key":"i=dlechner@baylibre.com; a=openpgp;\n fpr=8A73D82A6A1F509907F373881F8AF88C82F77C03","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 helper functions to check if a clock ID corresponds to a particular\nclock type (mux, gate, fdiv). This simplifies the code and makes it more\nreadable.\n\nAdditionally, it removes the restriction that fdivs_offs < muxes_offs <\ngates_offs by making the checking more strict in some places. This will\nallow future drivers to not have to define a mapping to meet this\nrequirement.\n\nSigned-off-by: David Lechner <dlechner@baylibre.com>\n---\n drivers/clk/mediatek/clk-mtk.c | 128 ++++++++++++++++++++---------------------\n 1 file changed, 64 insertions(+), 64 deletions(-)","diff":"diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c\nindex 0123b0ce7b1..3bd9021b9cf 100644\n--- a/drivers/clk/mediatek/clk-mtk.c\n+++ b/drivers/clk/mediatek/clk-mtk.c\n@@ -85,6 +85,34 @@ static int mtk_common_clk_get_unmapped_id(struct clk *clk)\n \treturn -ENOENT;\n }\n \n+static bool mtk_clk_id_is_pll(const struct mtk_clk_tree *tree, int mapped_id)\n+{\n+\treturn tree->plls && mapped_id < tree->num_plls;\n+}\n+\n+static bool mtk_clk_id_is_fclk(const struct mtk_clk_tree *tree, int mapped_id)\n+{\n+\treturn tree->fclks && mapped_id < tree->num_fclks;\n+}\n+\n+static bool mtk_clk_id_is_fdiv(const struct mtk_clk_tree *tree, int mapped_id)\n+{\n+\treturn tree->fdivs && mapped_id >= tree->fdivs_offs &&\n+\t       mapped_id < tree->fdivs_offs + tree->num_fdivs;\n+}\n+\n+static bool mtk_clk_id_is_mux(const struct mtk_clk_tree *tree, int mapped_id)\n+{\n+\treturn tree->muxes && mapped_id >= tree->muxes_offs &&\n+\t       mapped_id < tree->muxes_offs + tree->num_muxes;\n+}\n+\n+static bool mtk_clk_id_is_gate(const struct mtk_clk_tree *tree, int mapped_id)\n+{\n+\treturn tree->gates && mapped_id >= tree->gates_offs &&\n+\t       mapped_id < tree->gates_offs + tree->num_gates;\n+}\n+\n static int mtk_dummy_enable(struct clk *clk)\n {\n \treturn 0;\n@@ -375,15 +403,10 @@ static const int mtk_apmixedsys_of_xlate(struct clk *clk,\n \t\treturn ret;\n \n \t/* apmixedsys only uses plls and gates. */\n+\tif (!mtk_clk_id_is_pll(tree, clk->id) && !mtk_clk_id_is_gate(tree, clk->id))\n+\t\treturn -ENOENT;\n \n-\tif (tree->plls && clk->id < tree->num_plls)\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+\treturn 0;\n }\n \n static unsigned long __mtk_pll_recalc_rate(const struct mtk_pll_data *pll,\n@@ -497,7 +520,7 @@ static ulong mtk_apmixedsys_set_rate(struct clk *clk, ulong rate)\n \tu32 pcw = 0;\n \tu32 postdiv;\n \n-\tif (priv->tree->gates && clk->id >= priv->tree->gates_offs)\n+\tif (!mtk_clk_id_is_pll(priv->tree, clk->id))\n \t\treturn -EINVAL;\n \n \tmtk_pll_calc_values(priv, clk->id, &pcw, &postdiv, rate);\n@@ -515,7 +538,7 @@ static ulong mtk_apmixedsys_get_rate(struct clk *clk)\n \tu32 pcw;\n \n \t/* GATE handling */\n-\tif (priv->tree->gates && clk->id >= priv->tree->gates_offs) {\n+\tif (mtk_clk_id_is_gate(priv->tree, clk->id)) {\n \t\tgate = &priv->tree->gates[clk->id - priv->tree->gates_offs];\n \t\treturn mtk_clk_find_parent_rate(clk, gate->parent, NULL);\n \t}\n@@ -541,7 +564,7 @@ static int mtk_apmixedsys_enable(struct clk *clk)\n \tu32 r;\n \n \t/* GATE handling */\n-\tif (priv->tree->gates && clk->id >= priv->tree->gates_offs) {\n+\tif (mtk_clk_id_is_gate(priv->tree, clk->id)) {\n \t\tgate = &priv->tree->gates[clk->id - priv->tree->gates_offs];\n \t\treturn mtk_gate_enable(priv->base, gate);\n \t}\n@@ -579,7 +602,7 @@ static int mtk_apmixedsys_disable(struct clk *clk)\n \tu32 r;\n \n \t/* GATE handling */\n-\tif (priv->tree->gates && clk->id >= priv->tree->gates_offs) {\n+\tif (mtk_clk_id_is_gate(priv->tree, clk->id)) {\n \t\tgate = &priv->tree->gates[clk->id - priv->tree->gates_offs];\n \t\treturn mtk_gate_disable(priv->base, gate);\n \t}\n@@ -649,23 +672,11 @@ static const int mtk_topckgen_of_xlate(struct clk *clk,\n \t\treturn ret;\n \n \t/* topckgen only uses fclks, fdivs, muxes and gates. */\n+\tif (!mtk_clk_id_is_fclk(tree, clk->id) && !mtk_clk_id_is_fdiv(tree, clk->id) &&\n+\t    !mtk_clk_id_is_mux(tree, clk->id) && !mtk_clk_id_is_gate(tree, clk->id))\n+\t\treturn -ENOENT;\n \n-\tif (tree->fclks && clk->id < tree->num_fclks)\n-\t\treturn 0;\n-\n-\tif (tree->fdivs && clk->id >= tree->fdivs_offs &&\n-\t    clk->id < tree->fdivs_offs + tree->num_fdivs)\n-\t\treturn 0;\n-\n-\tif (tree->muxes && clk->id >= tree->muxes_offs &&\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+\treturn 0;\n }\n \n static ulong mtk_factor_recalc_rate(const struct mtk_fixed_factor *fdiv,\n@@ -723,21 +734,22 @@ static ulong mtk_topckgen_get_rate(struct clk *clk)\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+\tif (mtk_clk_id_is_fclk(tree, clk->id))\n+\t\treturn tree->fclks[clk->id].rate;\n+\n+\tif (mtk_clk_id_is_fdiv(tree, clk->id))\n+\t\treturn mtk_topckgen_get_factor_rate(clk, clk->id - tree->fdivs_offs);\n+\n+\tif (mtk_clk_id_is_mux(tree, clk->id))\n+\t\treturn mtk_topckgen_get_mux_rate(clk, clk->id - tree->muxes_offs);\n+\n+\tif (mtk_clk_id_is_gate(tree, clk->id)) {\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-\telse if (clk->id < priv->tree->muxes_offs)\n-\t\treturn mtk_topckgen_get_factor_rate(clk, clk->id -\n-\t\t\t\t\t\t    priv->tree->fdivs_offs);\n-\telse\n-\t\treturn mtk_topckgen_get_mux_rate(clk, clk->id -\n-\t\t\t\t\t\t priv->tree->muxes_offs);\n+\treturn -ENOENT;\n }\n \n static int mtk_clk_mux_enable(struct clk *clk)\n@@ -746,7 +758,7 @@ static int mtk_clk_mux_enable(struct clk *clk)\n \tconst struct mtk_composite *mux;\n \tu32 val;\n \n-\tif (clk->id < priv->tree->muxes_offs)\n+\tif (!mtk_clk_id_is_mux(priv->tree, clk->id))\n \t\treturn 0;\n \n \tmux = &priv->tree->muxes[clk->id - priv->tree->muxes_offs];\n@@ -778,8 +790,7 @@ static int mtk_topckgen_enable(struct clk *clk)\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+\tif (mtk_clk_id_is_gate(tree, clk->id)) {\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@@ -794,7 +805,7 @@ static int mtk_clk_mux_disable(struct clk *clk)\n \tconst struct mtk_composite *mux;\n \tu32 val;\n \n-\tif (clk->id < priv->tree->muxes_offs)\n+\tif (!mtk_clk_id_is_mux(priv->tree, clk->id))\n \t\treturn 0;\n \n \tmux = &priv->tree->muxes[clk->id - priv->tree->muxes_offs];\n@@ -819,8 +830,7 @@ static int mtk_topckgen_disable(struct clk *clk)\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+\tif (mtk_clk_id_is_gate(tree, clk->id)) {\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@@ -836,8 +846,7 @@ static int mtk_common_clk_set_parent(struct clk *clk, struct clk *parent)\n \tint parent_unmapped_id;\n \tu32 parent_type;\n \n-\tif (!priv->tree->muxes || clk->id < priv->tree->muxes_offs ||\n-\t    clk->id >= priv->tree->muxes_offs + priv->tree->num_muxes)\n+\tif (!mtk_clk_id_is_mux(priv->tree, clk->id))\n \t\treturn 0;\n \n \tif (!parent_priv)\n@@ -917,20 +926,11 @@ static const int mtk_infrasys_of_xlate(struct clk *clk,\n \t\treturn ret;\n \n \t/* ifrasys only uses fdivs, muxes and gates. */\n+\tif (!mtk_clk_id_is_fdiv(tree, clk->id) && !mtk_clk_id_is_mux(tree, clk->id) &&\n+\t    !mtk_clk_id_is_gate(tree, clk->id))\n+\t\treturn -ENOENT;\n \n-\tif (tree->fdivs && clk->id >= tree->fdivs_offs &&\n-\t    clk->id < tree->fdivs_offs + tree->num_fdivs)\n-\t\treturn 0;\n-\n-\tif (tree->muxes && clk->id >= tree->muxes_offs &&\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+\treturn 0;\n }\n \n static int mtk_clk_infrasys_enable(struct clk *clk)\n@@ -939,7 +939,7 @@ static int mtk_clk_infrasys_enable(struct clk *clk)\n \tconst struct mtk_gate *gate;\n \n \t/* MUX handling */\n-\tif (!priv->tree->gates || clk->id < priv->tree->gates_offs)\n+\tif (!mtk_clk_id_is_gate(priv->tree, clk->id))\n \t\treturn mtk_clk_mux_enable(clk);\n \n \tgate = &priv->tree->gates[clk->id - priv->tree->gates_offs];\n@@ -952,7 +952,7 @@ static int mtk_clk_infrasys_disable(struct clk *clk)\n \tconst struct mtk_gate *gate;\n \n \t/* MUX handling */\n-\tif (!priv->tree->gates || clk->id < priv->tree->gates_offs)\n+\tif (!mtk_clk_id_is_gate(priv->tree, clk->id))\n \t\treturn mtk_clk_mux_disable(clk);\n \n \tgate = &priv->tree->gates[clk->id - priv->tree->gates_offs];\n@@ -1004,13 +1004,13 @@ static ulong mtk_infrasys_get_rate(struct clk *clk)\n \tstruct mtk_clk_priv *priv = dev_get_priv(clk->dev);\n \tulong rate;\n \n-\tif (clk->id < priv->tree->fdivs_offs) {\n+\tif (mtk_clk_id_is_fclk(priv->tree, clk->id)) {\n \t\trate = priv->tree->fclks[clk->id].rate;\n-\t} else if (clk->id < priv->tree->muxes_offs) {\n+\t} else if (mtk_clk_id_is_fdiv(priv->tree, clk->id)) {\n \t\trate = mtk_infrasys_get_factor_rate(clk, clk->id -\n \t\t\t\t\t\t    priv->tree->fdivs_offs);\n \t/* No gates defined or ID is a MUX */\n-\t} else if (!priv->tree->gates || clk->id < priv->tree->gates_offs) {\n+\t} else if (!mtk_clk_id_is_gate(priv->tree, clk->id)) {\n \t\trate = mtk_infrasys_get_mux_rate(clk, clk->id -\n \t\t\t\t\t\t priv->tree->muxes_offs);\n \t/* Only valid with muxes + gates implementation */\n","prefixes":["v2","3/7"]}