From patchwork Wed Feb 2 13:48:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732902 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49D24C433EF for ; Wed, 2 Feb 2022 13:49:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344442AbiBBNtl (ORCPT ); Wed, 2 Feb 2022 08:49:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344452AbiBBNtl (ORCPT ); Wed, 2 Feb 2022 08:49:41 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6634C06173B for ; Wed, 2 Feb 2022 05:49:40 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id s2-20020a17090ad48200b001b501977b23so6918710pju.2 for ; Wed, 02 Feb 2022 05:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AhwOTUu+Yd20QptHanrLUKzOx+jJe492GmL7ESL7vr4=; b=LNILHH+++jRLvWWQTkAQWqu97BJ7NWdeEpf3QQ/Nb02vGJIVrh4kamufWLTcQPTKPZ tDl3V7uaE75cuttLOlBPJkFDDrsRxIpcQvVmwsAUh/f/1nQcJkX867/Q0fy8qX2K9GEi dZwIOjBOZKpxDGxaALbpSKXrQ8vpOij/GCYTY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AhwOTUu+Yd20QptHanrLUKzOx+jJe492GmL7ESL7vr4=; b=GbmaX6kwt2TX+b/439J2Br3Y8qKhyvqkoYT1B4FeHLGLZQlEZha/XBgqq5m2AFs1Ur F+K2JnzUF4rt542kdkRDH48f24KeD/HHPmnYgXoXmr2p+MSSVc6yAVpViv5BAmsKa8/6 ld7xQ3i9Tuixxb2ZWBd2ELJaYoI2R98l1DA9WmZciCWtMHrovv//MmDj9361Cn0IgpXY O+7tOz2HIUnN0CjC8MKlEihfI/TsyA3VQrerdgVe7c+pnCOwSqZ9jkX4nh/wkOw8kRyT G7FS8cJP4E1GNffElfws6O3gx+kv5VevAncQLqjg7gRIADjGObn5Vip1jMzMdnJwUYI1 OWvQ== X-Gm-Message-State: AOAM531vgiu5bvBJwHjs5iU1nEwxfOD58xk1l3Ev+oLoQHFaS8nxRlVM OcUTxrf3pVoNdOx2mh0V4o4/KQ== X-Google-Smtp-Source: ABdhPJzEyx+/Bw2d/SVDspKOv5Ko/HfJV+vTaXfMFR6X4ILc47iPMqAsQ7piF3VBEKt9W04apdGYOQ== X-Received: by 2002:a17:903:2352:: with SMTP id c18mr30838789plh.104.1643809780396; Wed, 02 Feb 2022 05:49:40 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:49:40 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/31] clk: mediatek: Use %pe to print errors Date: Wed, 2 Feb 2022 21:48:04 +0800 Message-Id: <20220202134834.690675-2-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org If %pe is used to print errors, a string representation of the error would be printed instead of a number as with %ld. Also, all the sites printing errors are deriving the error code from a pointer. Using %pe is more straightforward. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-apmixed.c | 2 +- drivers/clk/mediatek/clk-cpumux.c | 6 ++---- drivers/clk/mediatek/clk-mtk.c | 18 ++++++------------ drivers/clk/mediatek/clk-mux.c | 6 ++---- drivers/clk/mediatek/clk-pll.c | 3 +-- drivers/clk/mediatek/reset.c | 3 +-- 6 files changed, 13 insertions(+), 25 deletions(-) diff --git a/drivers/clk/mediatek/clk-apmixed.c b/drivers/clk/mediatek/clk-apmixed.c index caa9119413f1..a29339cc26c4 100644 --- a/drivers/clk/mediatek/clk-apmixed.c +++ b/drivers/clk/mediatek/clk-apmixed.c @@ -92,7 +92,7 @@ struct clk * __init mtk_clk_register_ref2usb_tx(const char *name, clk = clk_register(NULL, &tx->hw); if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %ld\n", name, PTR_ERR(clk)); + pr_err("Failed to register clk %s: %pe\n", name, clk); kfree(tx); } diff --git a/drivers/clk/mediatek/clk-cpumux.c b/drivers/clk/mediatek/clk-cpumux.c index e188018bc906..cab5095416b6 100644 --- a/drivers/clk/mediatek/clk-cpumux.c +++ b/drivers/clk/mediatek/clk-cpumux.c @@ -87,8 +87,7 @@ int mtk_clk_register_cpumuxes(struct device_node *node, regmap = device_node_to_regmap(node); if (IS_ERR(regmap)) { - pr_err("Cannot find regmap for %pOF: %ld\n", node, - PTR_ERR(regmap)); + pr_err("Cannot find regmap for %pOF: %pe\n", node, regmap); return PTR_ERR(regmap); } @@ -97,8 +96,7 @@ int mtk_clk_register_cpumuxes(struct device_node *node, clk = mtk_clk_register_cpumux(mux, regmap); if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %ld\n", - mux->name, PTR_ERR(clk)); + pr_err("Failed to register clk %s: %pe\n", mux->name, clk); continue; } diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 8d5791b3f460..519a461cbb6f 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -70,8 +70,7 @@ void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, rc->rate); if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %ld\n", - rc->name, PTR_ERR(clk)); + pr_err("Failed to register clk %s: %pe\n", rc->name, clk); continue; } @@ -97,8 +96,7 @@ void mtk_clk_register_factors(const struct mtk_fixed_factor *clks, CLK_SET_RATE_PARENT, ff->mult, ff->div); if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %ld\n", - ff->name, PTR_ERR(clk)); + pr_err("Failed to register clk %s: %pe\n", ff->name, clk); continue; } @@ -122,8 +120,7 @@ int mtk_clk_register_gates_with_dev(struct device_node *node, regmap = device_node_to_regmap(node); if (IS_ERR(regmap)) { - pr_err("Cannot find regmap for %pOF: %ld\n", node, - PTR_ERR(regmap)); + pr_err("Cannot find regmap for %pOF: %pe\n", node, regmap); return PTR_ERR(regmap); } @@ -141,8 +138,7 @@ int mtk_clk_register_gates_with_dev(struct device_node *node, gate->shift, gate->ops, gate->flags, dev); if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %ld\n", - gate->name, PTR_ERR(clk)); + pr_err("Failed to register clk %s: %pe\n", gate->name, clk); continue; } @@ -264,8 +260,7 @@ void mtk_clk_register_composites(const struct mtk_composite *mcs, clk = mtk_clk_register_composite(mc, base, lock); if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %ld\n", - mc->name, PTR_ERR(clk)); + pr_err("Failed to register clk %s: %pe\n", mc->name, clk); continue; } @@ -293,8 +288,7 @@ void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, mcd->div_width, mcd->clk_divider_flags, lock); if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %ld\n", - mcd->name, PTR_ERR(clk)); + pr_err("Failed to register clk %s: %pe\n", mcd->name, clk); continue; } diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c index 6d3a50eb7d6f..89f23e111d91 100644 --- a/drivers/clk/mediatek/clk-mux.c +++ b/drivers/clk/mediatek/clk-mux.c @@ -175,8 +175,7 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes, regmap = device_node_to_regmap(node); if (IS_ERR(regmap)) { - pr_err("Cannot find regmap for %pOF: %ld\n", node, - PTR_ERR(regmap)); + pr_err("Cannot find regmap for %pOF: %pe\n", node, regmap); return PTR_ERR(regmap); } @@ -187,8 +186,7 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes, clk = mtk_clk_register_mux(mux, regmap, lock); if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %ld\n", - mux->name, PTR_ERR(clk)); + pr_err("Failed to register clk %s: %pe\n", mux->name, clk); continue; } diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c index 60d7ffa0b924..f04f724e12e5 100644 --- a/drivers/clk/mediatek/clk-pll.c +++ b/drivers/clk/mediatek/clk-pll.c @@ -378,8 +378,7 @@ void mtk_clk_register_plls(struct device_node *node, clk = mtk_clk_register_pll(pll, base); if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %ld\n", - pll->name, PTR_ERR(clk)); + pr_err("Failed to register clk %s: %pe\n", pll->name, clk); continue; } diff --git a/drivers/clk/mediatek/reset.c b/drivers/clk/mediatek/reset.c index ffe464ce7ff8..bcec4b89f449 100644 --- a/drivers/clk/mediatek/reset.c +++ b/drivers/clk/mediatek/reset.c @@ -100,8 +100,7 @@ static void mtk_register_reset_controller_common(struct device_node *np, regmap = device_node_to_regmap(np); if (IS_ERR(regmap)) { - pr_err("Cannot find regmap for %pOF: %ld\n", np, - PTR_ERR(regmap)); + pr_err("Cannot find regmap for %pOF: %pe\n", np, regmap); return; } From patchwork Wed Feb 2 13:48:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E52C7C433F5 for ; Wed, 2 Feb 2022 13:49:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344460AbiBBNts (ORCPT ); Wed, 2 Feb 2022 08:49:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344464AbiBBNtm (ORCPT ); Wed, 2 Feb 2022 08:49:42 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB42FC06173B for ; Wed, 2 Feb 2022 05:49:42 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id c9so18256784plg.11 for ; Wed, 02 Feb 2022 05:49:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X1oq+g3gVExEjeGdLYmngTgVL65VIrxCvqUJ/+BHwmE=; b=KCRz8XVjXX7vecmmRDBxedtGoijXz9TKG/d5rsC2rSpg49m8IDaJTYwj6tNINwiJc4 cf6wYYj7zZkQzPNmpbLePfd+xtlKFdsGUYQ6HnmIzphxnsU2IsvvXssDdSF2wD33M8Fr 02XV01bw4fMu1jhtMJzXxsQ3v3JGSYPfCYifw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X1oq+g3gVExEjeGdLYmngTgVL65VIrxCvqUJ/+BHwmE=; b=UFgvwyusNsdbMFA1qRZ4bdRJWlEGM3OEjtKPFPt9P5Z/XNwPZxqln67sdK/l9jLiN/ Hb/Kricetzr3RdMHNtB/1uO4DNoFvSpwghrw/TeMbssoHhayQrSKB7qKV5rTfVxC4L4+ pDGzj/ALlPJvO6fCwKohayT7n9KVml/3oLfhyywTQxGAK/GKgzs6PRljf8dIUgpigQzb baALlskgE1qiWygWNKcKEA/TXh5xcczayZni+Z7oZupobRjiZQYIw0VBjngUvk4Ndeal TwUsXjftqW1XXE33lk6F57N0nRwGwcQqsXmaP+TYIYXOsESMw1qn3oGrv2mmdIuR9Okn szzA== X-Gm-Message-State: AOAM532sf6QCswZkwEOs+528AYW9HfsKrfScYaQkIRuqwhKL2iioLnaU QN2kXUcUvquqHD/4jpgsXdh/GQ== X-Google-Smtp-Source: ABdhPJwUP4oFnhoAAEegJwmf5AZyAl8asv85imOoFVDn2fHx/GxBYDFVhY5z2Nhp76MfsHNMogifhQ== X-Received: by 2002:a17:902:b212:: with SMTP id t18mr15548529plr.80.1643809782491; Wed, 02 Feb 2022 05:49:42 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:49:42 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 02/31] clk: mediatek: gate: Consolidate gate type clk related code Date: Wed, 2 Feb 2022 21:48:05 +0800 Message-Id: <20220202134834.690675-3-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Right now some bits of the gate type clk code are in clk-gate.[ch], but other bits are in clk-mtk.[ch]. This is different from the cpumux and mux type clks, for which all of the code are found in the same files. Move the functions that register multiple clks from a given list, mtk_clk_register_gates_with_dev() and mtk_clk_register_gates(), to clk-gate.[ch] to consolidate all the code for the gate type clks. This commit only moves code with minor whitespace fixups to correct the code style. Further improvements, such as internalizing various functions and structures will be done in later commits. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-gate.c | 53 ++++++++++++++++++++++++++++++++- drivers/clk/mediatek/clk-gate.h | 25 ++++++++++++++++ drivers/clk/mediatek/clk-mtk.c | 51 ------------------------------- drivers/clk/mediatek/clk-mtk.h | 25 ---------------- 4 files changed, 77 insertions(+), 77 deletions(-) diff --git a/drivers/clk/mediatek/clk-gate.c b/drivers/clk/mediatek/clk-gate.c index 5d88b428565b..54921768bfba 100644 --- a/drivers/clk/mediatek/clk-gate.c +++ b/drivers/clk/mediatek/clk-gate.c @@ -11,9 +11,9 @@ #include #include #include +#include #include -#include "clk-mtk.h" #include "clk-gate.h" static u32 mtk_get_clockgating(struct clk_hw *hw) @@ -182,4 +182,55 @@ struct clk *mtk_clk_register_gate( } EXPORT_SYMBOL_GPL(mtk_clk_register_gate); +int mtk_clk_register_gates_with_dev(struct device_node *node, + const struct mtk_gate *clks, int num, + struct clk_onecell_data *clk_data, + struct device *dev) +{ + int i; + struct clk *clk; + struct regmap *regmap; + + if (!clk_data) + return -ENOMEM; + + regmap = device_node_to_regmap(node); + if (IS_ERR(regmap)) { + pr_err("Cannot find regmap for %pOF: %pe\n", node, regmap); + return PTR_ERR(regmap); + } + + for (i = 0; i < num; i++) { + const struct mtk_gate *gate = &clks[i]; + + if (!IS_ERR_OR_NULL(clk_data->clks[gate->id])) + continue; + + clk = mtk_clk_register_gate(gate->name, gate->parent_name, + regmap, + gate->regs->set_ofs, + gate->regs->clr_ofs, + gate->regs->sta_ofs, + gate->shift, gate->ops, + gate->flags, dev); + + if (IS_ERR(clk)) { + pr_err("Failed to register clk %s: %pe\n", gate->name, clk); + continue; + } + + clk_data->clks[gate->id] = clk; + } + + return 0; +} + +int mtk_clk_register_gates(struct device_node *node, + const struct mtk_gate *clks, int num, + struct clk_onecell_data *clk_data) +{ + return mtk_clk_register_gates_with_dev(node, clks, num, clk_data, NULL); +} +EXPORT_SYMBOL_GPL(mtk_clk_register_gates); + MODULE_LICENSE("GPL"); diff --git a/drivers/clk/mediatek/clk-gate.h b/drivers/clk/mediatek/clk-gate.h index 3c3329ec54b7..432b571d23b3 100644 --- a/drivers/clk/mediatek/clk-gate.h +++ b/drivers/clk/mediatek/clk-gate.h @@ -43,6 +43,22 @@ struct clk *mtk_clk_register_gate( unsigned long flags, struct device *dev); +struct mtk_gate_regs { + u32 sta_ofs; + u32 clr_ofs; + u32 set_ofs; +}; + +struct mtk_gate { + int id; + const char *name; + const char *parent_name; + const struct mtk_gate_regs *regs; + int shift; + const struct clk_ops *ops; + unsigned long flags; +}; + #define GATE_MTK_FLAGS(_id, _name, _parent, _regs, _shift, \ _ops, _flags) { \ .id = _id, \ @@ -57,4 +73,13 @@ struct clk *mtk_clk_register_gate( #define GATE_MTK(_id, _name, _parent, _regs, _shift, _ops) \ GATE_MTK_FLAGS(_id, _name, _parent, _regs, _shift, _ops, 0) +int mtk_clk_register_gates(struct device_node *node, + const struct mtk_gate *clks, int num, + struct clk_onecell_data *clk_data); + +int mtk_clk_register_gates_with_dev(struct device_node *node, + const struct mtk_gate *clks, int num, + struct clk_onecell_data *clk_data, + struct device *dev); + #endif /* __DRV_CLK_GATE_H */ diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 519a461cbb6f..0c5db3c71fdd 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -106,57 +106,6 @@ void mtk_clk_register_factors(const struct mtk_fixed_factor *clks, } EXPORT_SYMBOL_GPL(mtk_clk_register_factors); -int mtk_clk_register_gates_with_dev(struct device_node *node, - const struct mtk_gate *clks, - int num, struct clk_onecell_data *clk_data, - struct device *dev) -{ - int i; - struct clk *clk; - struct regmap *regmap; - - if (!clk_data) - return -ENOMEM; - - regmap = device_node_to_regmap(node); - if (IS_ERR(regmap)) { - pr_err("Cannot find regmap for %pOF: %pe\n", node, regmap); - return PTR_ERR(regmap); - } - - for (i = 0; i < num; i++) { - const struct mtk_gate *gate = &clks[i]; - - if (!IS_ERR_OR_NULL(clk_data->clks[gate->id])) - continue; - - clk = mtk_clk_register_gate(gate->name, gate->parent_name, - regmap, - gate->regs->set_ofs, - gate->regs->clr_ofs, - gate->regs->sta_ofs, - gate->shift, gate->ops, gate->flags, dev); - - if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %pe\n", gate->name, clk); - continue; - } - - clk_data->clks[gate->id] = clk; - } - - return 0; -} - -int mtk_clk_register_gates(struct device_node *node, - const struct mtk_gate *clks, - int num, struct clk_onecell_data *clk_data) -{ - return mtk_clk_register_gates_with_dev(node, - clks, num, clk_data, NULL); -} -EXPORT_SYMBOL_GPL(mtk_clk_register_gates); - struct clk *mtk_clk_register_composite(const struct mtk_composite *mc, void __iomem *base, spinlock_t *lock) { diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index 0ff289d93452..bdec7dc5e07a 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -150,31 +150,6 @@ void mtk_clk_register_composites(const struct mtk_composite *mcs, int num, void __iomem *base, spinlock_t *lock, struct clk_onecell_data *clk_data); -struct mtk_gate_regs { - u32 sta_ofs; - u32 clr_ofs; - u32 set_ofs; -}; - -struct mtk_gate { - int id; - const char *name; - const char *parent_name; - const struct mtk_gate_regs *regs; - int shift; - const struct clk_ops *ops; - unsigned long flags; -}; - -int mtk_clk_register_gates(struct device_node *node, - const struct mtk_gate *clks, int num, - struct clk_onecell_data *clk_data); - -int mtk_clk_register_gates_with_dev(struct device_node *node, - const struct mtk_gate *clks, - int num, struct clk_onecell_data *clk_data, - struct device *dev); - struct mtk_clk_divider { int id; const char *name; From patchwork Wed Feb 2 13:48:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732904 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 325F0C433EF for ; Wed, 2 Feb 2022 13:49:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344464AbiBBNts (ORCPT ); Wed, 2 Feb 2022 08:49:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344474AbiBBNtr (ORCPT ); Wed, 2 Feb 2022 08:49:47 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E83C3C061741 for ; Wed, 2 Feb 2022 05:49:44 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id e16so18362383pgn.4 for ; Wed, 02 Feb 2022 05:49:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MyQRwL6DQLrE4xYNw8mcC0XQoGB02nn/7BR8gOXw12k=; b=NK4YiiG50hLCWW7qrayFHDYOcnbrImJU+goMnLjQsBS0f/CxfUGlpHC4pVOWiKG3fN rSRcfrqrLj7IqMGTuyIgDwVddgHV70pVyPfC5bvgF3zu7I+0lI8jMhUZtU8YY1kKicvG HTr7ZcyBbY3OePwWetp1EXwJPg+7X3uzvMl30= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MyQRwL6DQLrE4xYNw8mcC0XQoGB02nn/7BR8gOXw12k=; b=ynLlJ84bG6AD0Mhg3pq4XJob0J3jHv+gbcdp92xacAjxVJf3WNM5Odt5UYYzCFDmxJ 3V4I9e2f32b8PbAwbfYBFipfwezs9Qzk/iNmZa6trEW/i/TKwH+vh1E9Lk8dkn/ET5m7 aRFsUQjLNSskOLHOOQPYaqaRkp05WiVmxqCNZPN/QyHWx8Q3F1sKZ3PmyL8wReJFDA6u olDr9kkFQMmKoxgAsc8p8BW9GVgfJ4r3FNvZ7ZsitAy3FizpRYA7PaRkx4WzH2TfbpMu MBjrsxHTmoBxjDIOcAFzwgRXjSlBdXRXmQ1KcKsefHHNd5Kgn7vktY8WmdtlqS5ZhCOO 6LoA== X-Gm-Message-State: AOAM530D8XhPbVvj40p7AFmT9qaROqQipUYCDDFyGy/prO7vvTkmzqR2 GKpEgzou6E8rKDa7B3/2S+YII+lKXnJd5g== X-Google-Smtp-Source: ABdhPJxChN04B73w38gJYqKkMrX28K/rq+/lHQmKeoCJv2N1BvoTeTJonWoE6d0/86Dq5UJT8ZgveQ== X-Received: by 2002:aa7:9498:: with SMTP id z24mr29581913pfk.80.1643809784501; Wed, 02 Feb 2022 05:49:44 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:49:44 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 03/31] clk: mediatek: gate: Internalize clk implementation Date: Wed, 2 Feb 2022 21:48:06 +0800 Message-Id: <20220202134834.690675-4-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org struct mtk_clk_gate and mtk_clk_register_gate() are not used outside of the gate clk library. Only the API that handles a list of clks is used by the individual platform clk drivers. Internalize the parts that aren't used outside of the implementation. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-gate.c | 35 ++++++++++++++++++++++----------- drivers/clk/mediatek/clk-gate.h | 31 ++--------------------------- 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/drivers/clk/mediatek/clk-gate.c b/drivers/clk/mediatek/clk-gate.c index 54921768bfba..e51cfd8c653c 100644 --- a/drivers/clk/mediatek/clk-gate.c +++ b/drivers/clk/mediatek/clk-gate.c @@ -11,11 +11,28 @@ #include #include #include +#include +#include #include #include +#include #include "clk-gate.h" +struct mtk_clk_gate { + struct clk_hw hw; + struct regmap *regmap; + int set_ofs; + int clr_ofs; + int sta_ofs; + u8 bit; +}; + +static inline struct mtk_clk_gate *to_mtk_clk_gate(struct clk_hw *hw) +{ + return container_of(hw, struct mtk_clk_gate, hw); +} + static u32 mtk_get_clockgating(struct clk_hw *hw) { struct mtk_clk_gate *cg = to_mtk_clk_gate(hw); @@ -140,17 +157,12 @@ const struct clk_ops mtk_clk_gate_ops_no_setclr_inv = { }; EXPORT_SYMBOL_GPL(mtk_clk_gate_ops_no_setclr_inv); -struct clk *mtk_clk_register_gate( - const char *name, - const char *parent_name, - struct regmap *regmap, - int set_ofs, - int clr_ofs, - int sta_ofs, - u8 bit, - const struct clk_ops *ops, - unsigned long flags, - struct device *dev) +static struct clk *mtk_clk_register_gate(const char *name, + const char *parent_name, + struct regmap *regmap, int set_ofs, + int clr_ofs, int sta_ofs, u8 bit, + const struct clk_ops *ops, + unsigned long flags, struct device *dev) { struct mtk_clk_gate *cg; struct clk *clk; @@ -180,7 +192,6 @@ struct clk *mtk_clk_register_gate( return clk; } -EXPORT_SYMBOL_GPL(mtk_clk_register_gate); int mtk_clk_register_gates_with_dev(struct device_node *node, const struct mtk_gate *clks, int num, diff --git a/drivers/clk/mediatek/clk-gate.h b/drivers/clk/mediatek/clk-gate.h index 432b571d23b3..3d75521ba20c 100644 --- a/drivers/clk/mediatek/clk-gate.h +++ b/drivers/clk/mediatek/clk-gate.h @@ -7,42 +7,15 @@ #ifndef __DRV_CLK_GATE_H #define __DRV_CLK_GATE_H -#include #include - -struct clk; - -struct mtk_clk_gate { - struct clk_hw hw; - struct regmap *regmap; - int set_ofs; - int clr_ofs; - int sta_ofs; - u8 bit; -}; - -static inline struct mtk_clk_gate *to_mtk_clk_gate(struct clk_hw *hw) -{ - return container_of(hw, struct mtk_clk_gate, hw); -} +#include +#include extern const struct clk_ops mtk_clk_gate_ops_setclr; extern const struct clk_ops mtk_clk_gate_ops_setclr_inv; extern const struct clk_ops mtk_clk_gate_ops_no_setclr; extern const struct clk_ops mtk_clk_gate_ops_no_setclr_inv; -struct clk *mtk_clk_register_gate( - const char *name, - const char *parent_name, - struct regmap *regmap, - int set_ofs, - int clr_ofs, - int sta_ofs, - u8 bit, - const struct clk_ops *ops, - unsigned long flags, - struct device *dev); - struct mtk_gate_regs { u32 sta_ofs; u32 clr_ofs; From patchwork Wed Feb 2 13:48:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15FDCC4332F for ; Wed, 2 Feb 2022 13:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344482AbiBBNtt (ORCPT ); Wed, 2 Feb 2022 08:49:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344461AbiBBNtr (ORCPT ); Wed, 2 Feb 2022 08:49:47 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9384C061748 for ; Wed, 2 Feb 2022 05:49:46 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id d5so20295074pjk.5 for ; Wed, 02 Feb 2022 05:49:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OMf5nn0OsphTZ/Hydc0tEKhYqnEvXUsEDc+DYG029q8=; b=D1FG1V52XitFXeVkZqAsn3QQZcUCbdgmnDi1C+T4ZeKRV5XYbuCYvD2EJY9qjTKCpb MbAGy2uJfxe59OBmHq360f5NmvFRHApC5Al8uvO5R/D4delH7iNnMbbwp8ZOIzZLJFm3 xz2mFBH6KjdxEslLp3g5Eb9Kekp0dEZku3FL8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OMf5nn0OsphTZ/Hydc0tEKhYqnEvXUsEDc+DYG029q8=; b=QdA2foWY+5frYCoVZp2S4PLvLutmw8CjjTyQAstkHKvYnbl6vcYabJyuDxPKKErUY7 Y8Kw8ZhcKlSN1KviC5SNCusBbR2m1XHRZghE6gmI3HvrYGfVWmUKdemvGACeX6adRHJe +noBx1gMW5HSYzgaCn89p2SAQEFGtvx29mRj5m4yaWBVgYtMET4GY3zJNFTvKyIeofQZ ODZXxUvmdXnf5GKeOxnG6v2uCSj/EVA1ZUaOJ894id6EuwGmsphgezltajBloyAbDKCB mK+Bz6p67RZ1CxLjj1aK5r+9lB4uXsojxuVUdO1VpTcj5mDR0usdep1PjE348u46TDYG gHRA== X-Gm-Message-State: AOAM532UXUJyXaePAAOCJcO67/6BuUnW81HnJYxPkA2DRy3QSkO93vS9 F1wUgw0SFwV4ssSp7SK3OM7IMw== X-Google-Smtp-Source: ABdhPJzO/sxpRO82Jk6BAZ8mlR/cHgAnt4r+ZC3pxjQmzzd5jN8tM5TqUBAd/Z1uDl1xDWJQs63yKg== X-Received: by 2002:a17:902:6f10:: with SMTP id w16mr4474576plk.142.1643809786494; Wed, 02 Feb 2022 05:49:46 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:49:46 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 04/31] clk: mediatek: gate: Implement unregister API Date: Wed, 2 Feb 2022 21:48:07 +0800 Message-Id: <20220202134834.690675-5-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The gate clk type within the MediaTek clk driver library only has a register function, and no corresponding unregister function. This means there is no way for its users to properly implement cleanup and removal. Add a matching unregister function for the gate type clk. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-gate.c | 35 +++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-gate.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/drivers/clk/mediatek/clk-gate.c b/drivers/clk/mediatek/clk-gate.c index e51cfd8c653c..ed1ad5535d41 100644 --- a/drivers/clk/mediatek/clk-gate.c +++ b/drivers/clk/mediatek/clk-gate.c @@ -193,6 +193,21 @@ static struct clk *mtk_clk_register_gate(const char *name, return clk; } +static void mtk_clk_unregister_gate(struct clk *clk) +{ + struct mtk_clk_gate *cg; + struct clk_hw *hw; + + hw = __clk_get_hw(clk); + if (!hw) + return; + + cg = to_mtk_clk_gate(hw); + + clk_unregister(clk); + kfree(cg); +} + int mtk_clk_register_gates_with_dev(struct device_node *node, const struct mtk_gate *clks, int num, struct clk_onecell_data *clk_data, @@ -244,4 +259,24 @@ int mtk_clk_register_gates(struct device_node *node, } EXPORT_SYMBOL_GPL(mtk_clk_register_gates); +void mtk_clk_unregister_gates(const struct mtk_gate *clks, int num, + struct clk_onecell_data *clk_data) +{ + int i; + + if (!clk_data) + return; + + for (i = num; i > 0; i--) { + const struct mtk_gate *gate = &clks[i - 1]; + + if (IS_ERR_OR_NULL(clk_data->clks[gate->id])) + continue; + + mtk_clk_unregister_gate(clk_data->clks[gate->id]); + clk_data->clks[gate->id] = ERR_PTR(-ENOENT); + } +} +EXPORT_SYMBOL_GPL(mtk_clk_unregister_gates); + MODULE_LICENSE("GPL"); diff --git a/drivers/clk/mediatek/clk-gate.h b/drivers/clk/mediatek/clk-gate.h index 3d75521ba20c..344adffb6578 100644 --- a/drivers/clk/mediatek/clk-gate.h +++ b/drivers/clk/mediatek/clk-gate.h @@ -55,4 +55,7 @@ int mtk_clk_register_gates_with_dev(struct device_node *node, struct clk_onecell_data *clk_data, struct device *dev); +void mtk_clk_unregister_gates(const struct mtk_gate *clks, int num, + struct clk_onecell_data *clk_data); + #endif /* __DRV_CLK_GATE_H */ From patchwork Wed Feb 2 13:48:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732906 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4350C4321E for ; Wed, 2 Feb 2022 13:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344484AbiBBNtu (ORCPT ); Wed, 2 Feb 2022 08:49:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344474AbiBBNtt (ORCPT ); Wed, 2 Feb 2022 08:49:49 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D948BC06173B for ; Wed, 2 Feb 2022 05:49:48 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id p125so18355501pga.2 for ; Wed, 02 Feb 2022 05:49:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MnC5wd+W1Uub0jyBTii0bw1jKUM0SD+MmltxaETPxmI=; b=ifkWBdljLlCdQrsnHb2AaA0xiVXH5i/9qcSv1GL6LW/PoUV26HY1RZyR5xcnjsOr+z uhIw6zBd7oLaRiZv9+E5Nf7YQ9SgfnPGAFRR4NBLw3veNFLU0UCkMO55TcQkWkEoldYV 0nhn7rMWunukBQmGpuPAbvZXiLDhoeuy/Ko8Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MnC5wd+W1Uub0jyBTii0bw1jKUM0SD+MmltxaETPxmI=; b=yBJRwaMC9ff6WexjdZ3QutY2xu7xq08kDng8Nbak9GDGHP73u3Iqwk30wdVFxMfRLX W/gydDY4+wGUEb7agZPfnDz7y3KTKs+sx+zzCNYXy/iABT1Rij0FVdjqmhL5FZBftlV+ ZiNFKjUMXlaadzrPg5C/uDvcilPxxF3+trfF5/rpLe7p0rKD4i6owCV8Kd6fEvq4jxqg npZ2vJc0VbR425JkN1XxCWOdF9TRxi2xLr5absHv/ulQcPQG/dFpmNX/Iag+nVHwRduA wHNBzAhQXNiumNlTenBqcodd/0jCFGbHnvdFCMmfNF6yhYIZrarV8+2OcM8s96Uc6YUR AK2A== X-Gm-Message-State: AOAM533H/Q2V0N6SwE4a5ejc6FQcqxba0HAEd9iRZbLDUkIjrMOjvZIJ LNTUVUyV3X2w2/aVcZ+gCtFQVA== X-Google-Smtp-Source: ABdhPJyE1fU1DE0Y18OMUQ3BYgMoazVLDzDLvc5zUeGVpD74dfmN2S3rdVUMXCpYNy7oMRTOlZT5Ow== X-Received: by 2002:a65:400a:: with SMTP id f10mr24302297pgp.161.1643809788467; Wed, 02 Feb 2022 05:49:48 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:49:48 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/31] clk: mediatek: gate: Clean up included headers Date: Wed, 2 Feb 2022 21:48:08 +0800 Message-Id: <20220202134834.690675-6-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Some included headers aren't actually used anywhere, while other headers with the declaration of functions and structures aren't directly included. Get rid of the unused ones, and add the ones that should be included directly. On the header side, replace headers that are included purely for data structure definitions with forward declarations. This decreases the amount of preprocessing and compilation effort required for each inclusion. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-gate.c | 11 +++-------- drivers/clk/mediatek/clk-gate.h | 10 +++++++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/clk/mediatek/clk-gate.c b/drivers/clk/mediatek/clk-gate.c index ed1ad5535d41..e8881ae1489a 100644 --- a/drivers/clk/mediatek/clk-gate.c +++ b/drivers/clk/mediatek/clk-gate.c @@ -4,18 +4,13 @@ * Author: James Liao */ -#include -#include - -#include -#include -#include -#include #include -#include #include #include +#include #include +#include +#include #include "clk-gate.h" diff --git a/drivers/clk/mediatek/clk-gate.h b/drivers/clk/mediatek/clk-gate.h index 344adffb6578..6b5738826a22 100644 --- a/drivers/clk/mediatek/clk-gate.h +++ b/drivers/clk/mediatek/clk-gate.h @@ -7,9 +7,13 @@ #ifndef __DRV_CLK_GATE_H #define __DRV_CLK_GATE_H -#include -#include -#include +#include + +struct clk; +struct clk_onecell_data; +struct clk_ops; +struct device; +struct device_node; extern const struct clk_ops mtk_clk_gate_ops_setclr; extern const struct clk_ops mtk_clk_gate_ops_setclr_inv; From patchwork Wed Feb 2 13:48:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAFF9C433F5 for ; Wed, 2 Feb 2022 13:49:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344494AbiBBNtz (ORCPT ); Wed, 2 Feb 2022 08:49:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344474AbiBBNtv (ORCPT ); Wed, 2 Feb 2022 08:49:51 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBDFEC061714 for ; Wed, 2 Feb 2022 05:49:50 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id e28so18843821pfj.5 for ; Wed, 02 Feb 2022 05:49:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PAT5iAIzHvPdv8HvSTIRh/VZmmqGpu7uXPWf6w5slEo=; b=aT66B3ceArqj3A+My12rUgKDeIZDNAyAaKTXpJwq+IRh6cHvAHtFutZl6LADWDNpIS 6cn26Ot9iaUON3ThryQ49iPhKw7Zi0VWGJkPDD1vrz88/NX3NGIyW3XVNCnGYFb76f2S 2MjQy6svJ/3ARBBrPlrMST7tSK3EI+QqsIsbQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PAT5iAIzHvPdv8HvSTIRh/VZmmqGpu7uXPWf6w5slEo=; b=cXY0kNo1UR1K5N6uaRP8tAvM6tvrgeQ6xIRM3jZ4CdkrZmJT0XKB2Bb2ee/zbg7tBd 4fByy6V9xS2Sm9mcVkt+F3InslMaME5tm7O7Sx1LS2NSpnMWN2OQdTw5niY2QuRErxKq x61FOofSeHGcymTYxVJ9Mm35QE5tXfXlxuwcwmyBd1eQ6PG72jX5/A05lCM+bDWNMziQ 6Jw7AxITXs7muuH0o3M7Bv9HL7JctU+v4nvkqhaNIanYzaflefUvpMXhv1n8Tu9A0BZ2 chLxR6aXh1s6e075yNKB3+YgzywB+MHWLWLKajklkp6gBvHU/2IPSiM89dQGwBF27Xsw PqOA== X-Gm-Message-State: AOAM532MNreKFxwUAxjEYFnpa8gdvh0iRwEVkKspEqlCiydXdKqKFKQg ID0IR9H6j7sHvhBPvZ5eBmOGIA== X-Google-Smtp-Source: ABdhPJzG4Q3lOFHtjmjY2NY9uFw3Smv0rstZjKXfu8HTfaJsZcy3bw3p9dDCi1Cn5CUyDYqxAzg7bg== X-Received: by 2002:a63:88c6:: with SMTP id l189mr24612847pgd.229.1643809790552; Wed, 02 Feb 2022 05:49:50 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:49:50 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/31] clk: mediatek: cpumux: Implement unregister API Date: Wed, 2 Feb 2022 21:48:09 +0800 Message-Id: <20220202134834.690675-7-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The cpumux clk type within the MediaTek clk driver library only has a register function, and no corresponding unregister function. This means there is no way for its users to properly implement cleanup and removal. Add a matching unregister function for the cpumux type clk. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-cpumux.c | 31 +++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-cpumux.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/drivers/clk/mediatek/clk-cpumux.c b/drivers/clk/mediatek/clk-cpumux.c index cab5095416b6..99a819e3673f 100644 --- a/drivers/clk/mediatek/clk-cpumux.c +++ b/drivers/clk/mediatek/clk-cpumux.c @@ -77,6 +77,21 @@ mtk_clk_register_cpumux(const struct mtk_composite *mux, return clk; } +static void mtk_clk_unregister_cpumux(struct clk *clk) +{ + struct mtk_clk_cpumux *cpumux; + struct clk_hw *hw; + + hw = __clk_get_hw(clk); + if (!hw) + return; + + cpumux = to_mtk_clk_cpumux(hw); + + clk_unregister(clk); + kfree(cpumux); +} + int mtk_clk_register_cpumuxes(struct device_node *node, const struct mtk_composite *clks, int num, struct clk_onecell_data *clk_data) @@ -106,4 +121,20 @@ int mtk_clk_register_cpumuxes(struct device_node *node, return 0; } +void mtk_clk_unregister_cpumuxes(const struct mtk_composite *clks, int num, + struct clk_onecell_data *clk_data) +{ + int i; + + for (i = num; i > 0; i--) { + const struct mtk_composite *mux = &clks[i - 1]; + + if (IS_ERR_OR_NULL(clk_data->clks[mux->id])) + continue; + + mtk_clk_unregister_cpumux(clk_data->clks[mux->id]); + clk_data->clks[mux->id] = ERR_PTR(-ENOENT); + } +} + MODULE_LICENSE("GPL"); diff --git a/drivers/clk/mediatek/clk-cpumux.h b/drivers/clk/mediatek/clk-cpumux.h index 2aaf1afd4e5f..fda7770fd803 100644 --- a/drivers/clk/mediatek/clk-cpumux.h +++ b/drivers/clk/mediatek/clk-cpumux.h @@ -19,4 +19,7 @@ int mtk_clk_register_cpumuxes(struct device_node *node, const struct mtk_composite *clks, int num, struct clk_onecell_data *clk_data); +void mtk_clk_unregister_cpumuxes(const struct mtk_composite *clks, int num, + struct clk_onecell_data *clk_data); + #endif /* __DRV_CLK_CPUMUX_H */ From patchwork Wed Feb 2 13:48:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D947C433F5 for ; Wed, 2 Feb 2022 13:50:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344503AbiBBNuB (ORCPT ); Wed, 2 Feb 2022 08:50:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344507AbiBBNtx (ORCPT ); Wed, 2 Feb 2022 08:49:53 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECE25C061741 for ; Wed, 2 Feb 2022 05:49:52 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id c9so18257208plg.11 for ; Wed, 02 Feb 2022 05:49:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RrfW8Hvna1qE6lZZCejwLQWPkb90Uz2sIj+oZ4VQ2w0=; b=eAVTevsFRW5AshLLU6rlWfH8qccGjQxZFQ+bd1of7avCkX7/yZX5r9fzXx+7vVQOfn X4fidgXCTtUrs4NCMzIJWKKvOZ1lXZtoN1++lfoz3azn5qYssjtY0YS9QTKwtdaF2rTS hZzA6LH1AuERdElBEbB/Pzl59dRlCgQjTMRVM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RrfW8Hvna1qE6lZZCejwLQWPkb90Uz2sIj+oZ4VQ2w0=; b=mQelgci4mCLiXKX+hs8mxhK3H/hbjp8T32xLwltXI1tF7FW98LGpwgA1bEXB8LmxHt xwN3FdeB0US90YtJHLAfy4o5TPA/lex7az2k1jFV/TF0k5WT9N0A7kgGDFP/x8esQ1rs OfrvHMMlUXLVm0YV0V8AuLEwuNpad2MVlEY0bDETkt4F3qf/rBq3pH7mvsOl+UFmO9ho /wgTRGUcfQsOD01+9/m7vJDZpKIH1iJ1RfxrIlWguzSRLJhJVMkP1RoUK5FwLW/88tMx PYksxdNVS6EGeeLQfPa00WQvo+zMVM8AeWTpNC+wrMH2Ien6mSQ0jEOkG6DsbGuOGi5Z phMA== X-Gm-Message-State: AOAM532MHpuFbjiNkvYJzUy/ME4wzTC6t2EPOBKt9sHlHx9q7j6QqAPL DmHaH3IwWFo7rJ/p7xAezWIAhw== X-Google-Smtp-Source: ABdhPJyhaR40431uojvn+aN27kxAQL0PWlBqTRA9tg58qSu/BSHP+Xmo8SPpTCFupcg0zxUxemhY9A== X-Received: by 2002:a17:902:ab04:: with SMTP id ik4mr30206215plb.23.1643809792536; Wed, 02 Feb 2022 05:49:52 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:49:52 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/31] clk: mediatek: cpumux: Internalize struct mtk_clk_cpumux Date: Wed, 2 Feb 2022 21:48:10 +0800 Message-Id: <20220202134834.690675-8-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org struct mtk_clk_cpumux is an implementation detail of the cpumux clk type, and is not used outside of the implementation. Internalize the definition to minimize leakage of details and shrink the header file. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-cpumux.c | 8 ++++++++ drivers/clk/mediatek/clk-cpumux.h | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/clk/mediatek/clk-cpumux.c b/drivers/clk/mediatek/clk-cpumux.c index 99a819e3673f..344c6399b22f 100644 --- a/drivers/clk/mediatek/clk-cpumux.c +++ b/drivers/clk/mediatek/clk-cpumux.c @@ -12,6 +12,14 @@ #include "clk-mtk.h" #include "clk-cpumux.h" +struct mtk_clk_cpumux { + struct clk_hw hw; + struct regmap *regmap; + u32 reg; + u32 mask; + u8 shift; +}; + static inline struct mtk_clk_cpumux *to_mtk_clk_cpumux(struct clk_hw *_hw) { return container_of(_hw, struct mtk_clk_cpumux, hw); diff --git a/drivers/clk/mediatek/clk-cpumux.h b/drivers/clk/mediatek/clk-cpumux.h index fda7770fd803..a538f2bbef0d 100644 --- a/drivers/clk/mediatek/clk-cpumux.h +++ b/drivers/clk/mediatek/clk-cpumux.h @@ -7,14 +7,6 @@ #ifndef __DRV_CLK_CPUMUX_H #define __DRV_CLK_CPUMUX_H -struct mtk_clk_cpumux { - struct clk_hw hw; - struct regmap *regmap; - u32 reg; - u32 mask; - u8 shift; -}; - int mtk_clk_register_cpumuxes(struct device_node *node, const struct mtk_composite *clks, int num, struct clk_onecell_data *clk_data); From patchwork Wed Feb 2 13:48:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78263C433EF for ; Wed, 2 Feb 2022 13:50:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344474AbiBBNuB (ORCPT ); Wed, 2 Feb 2022 08:50:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344510AbiBBNtz (ORCPT ); Wed, 2 Feb 2022 08:49:55 -0500 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA995C06173B for ; Wed, 2 Feb 2022 05:49:54 -0800 (PST) Received: by mail-pg1-x529.google.com with SMTP id e16so18362787pgn.4 for ; Wed, 02 Feb 2022 05:49:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FrZ/0MdvYKx4iaQqido6RE0SQZOpyPkZyyEsJWJ6uvQ=; b=kr16j1M0ul8lOBTGXLrQNyQAn0031+sSYig0cCR7kjq/VDai6jwZxUPCannWakW7ov t6eL4uUJmLgO2yfgvEwb8IVL01LHyy6huvnflt/lirwoirOJb6TT6YYCKkTo8SDSFA3G B8xh+k350+mauwcTQQcRRUHrq0wnUKHmsd0Io= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FrZ/0MdvYKx4iaQqido6RE0SQZOpyPkZyyEsJWJ6uvQ=; b=Mvae1G39qOvbHMx51iKdToERM2Gj823akvMg5h/EYnhGv25TSKvCSa7P1YwS/rd4L7 XZmZbaafd3CrhEAtrX44JPLboDM7y+8uuwKWoEkwttbJSRzIgP8gKwhn+tw0AQRIGU6q gv/0S3Nuc/4Rj/7TPC6JQ0dceS6d/fBdgqZ/V7BpMlKPGF9LhlfaWTVjzQy2pVdc7Qre hbQA06ChR44mYHM6YWKbDAKELogl6/8SXnOhfsTNlZQvOvimf11+LsFydmeDBI3DfPrA mKh0QlDAMbxurfqQWKdTVXl59wKyEu9En2/BFSZTDM+i6pYxtsQ0Ei069DHZwyckPVCd lhWw== X-Gm-Message-State: AOAM533nIUIKkT31OcG2bCD07g9GPuUSGEiMJoOPzQrj8f7hXXNyVGBp KGAh7Jn3mNrEcwBKXY6RtqmpfQ== X-Google-Smtp-Source: ABdhPJz6RliNQTrYa3nwSg3QqKgNI7uqG/4+XpmghPiK9Jj3ex4tFYMUF5mHVSMN/zT1r/+Ay6SMtg== X-Received: by 2002:a05:6a00:238b:: with SMTP id f11mr1606430pfc.73.1643809794541; Wed, 02 Feb 2022 05:49:54 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:49:54 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 08/31] clk: mediatek: cpumux: Clean up included headers Date: Wed, 2 Feb 2022 21:48:11 +0800 Message-Id: <20220202134834.690675-9-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Some headers with the declaration of functions and structures aren't directly included. Explicitly include them so that future changes to other headers would not result in an unexpected build break. On the header side, add forward declarations for any data structures whose pointers are used in function signatures. No headers are required. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-cpumux.c | 3 +++ drivers/clk/mediatek/clk-cpumux.h | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/drivers/clk/mediatek/clk-cpumux.c b/drivers/clk/mediatek/clk-cpumux.c index 344c6399b22f..658aee789f44 100644 --- a/drivers/clk/mediatek/clk-cpumux.c +++ b/drivers/clk/mediatek/clk-cpumux.c @@ -5,8 +5,11 @@ */ #include +#include +#include #include #include +#include #include #include "clk-mtk.h" diff --git a/drivers/clk/mediatek/clk-cpumux.h b/drivers/clk/mediatek/clk-cpumux.h index a538f2bbef0d..b07e89f7c283 100644 --- a/drivers/clk/mediatek/clk-cpumux.h +++ b/drivers/clk/mediatek/clk-cpumux.h @@ -7,6 +7,10 @@ #ifndef __DRV_CLK_CPUMUX_H #define __DRV_CLK_CPUMUX_H +struct clk_onecell_data; +struct device_node; +struct mtk_composite; + int mtk_clk_register_cpumuxes(struct device_node *node, const struct mtk_composite *clks, int num, struct clk_onecell_data *clk_data); From patchwork Wed Feb 2 13:48:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE279C4332F for ; Wed, 2 Feb 2022 13:50:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344512AbiBBNuC (ORCPT ); Wed, 2 Feb 2022 08:50:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344521AbiBBNt5 (ORCPT ); Wed, 2 Feb 2022 08:49:57 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F27C6C061401 for ; Wed, 2 Feb 2022 05:49:56 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id e28so18844014pfj.5 for ; Wed, 02 Feb 2022 05:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XZjlD3mrJU3KRhgIhEHQUnXO0d3r7KCSCVQooNCOn9c=; b=KogdZmATlMROP/F6aSz15lBpRSu2RQLF2SycEunEeLa1FXHgcV6h9NvAr67fnbWQis 7lQEjjtlNg6iEVri/qEgOvPQNAhLS2zRUVGrZJtyfH/uYV8HiDBk8Z23Bdma80XgGK4F zjph6RcOMkbn7eBtStd5VnNBBwqT4IUAI4cNA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XZjlD3mrJU3KRhgIhEHQUnXO0d3r7KCSCVQooNCOn9c=; b=huGRNW9vGRo0EpKWga/ATWp4z/izj0w/EH0sSS1CDkt5PFRTrxu2YKEyrOlsApD1p8 1kTmV2tTd9KEi+W+cpOep9HN9mVpuRfWm+UmSJkZIAIfIOLFiUTjyiUH8hPd8+zL8ecu sRzit4h05JwxTDD5zHwYMPKBiML4Uaq8zgH9H3LrX3Xnl9b2pqnJuqIgBWeGjYqwqDx6 75Eghghv6r+QozmxAUUhl2Czs147G4n3dhOMT8XDzr6OLaCzD63FxMScLjWE7n7qyXfg OKYgrQAs7R/Ql7Bxdd6YWzoegsCnnvf1FK+2oBcV7n7V7MOXgHjz18eopOEZFa3z5P/Y p8Nw== X-Gm-Message-State: AOAM5338idhHY2i5RqVbT1dKCQ5rHTIeHMX/qdx8IoKsDVJqKXDxKI+l i6PpLejZGGlImpiPCLnsj2HNG+nWDwu9SQ== X-Google-Smtp-Source: ABdhPJyJAUdGvQ7twSvegXn6iv2II/t+vRes3AMNAo/+BTUsC44azlgruL/e4qWbpPr9iVXGt7AYJw== X-Received: by 2002:a05:6a00:158e:: with SMTP id u14mr21749001pfk.38.1643809796527; Wed, 02 Feb 2022 05:49:56 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:49:56 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/31] clk: mediatek: mux: Implement unregister API Date: Wed, 2 Feb 2022 21:48:12 +0800 Message-Id: <20220202134834.690675-10-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The mux clk type within the MediaTek clk driver library only has a register function, and no corresponding unregister function. This means there is no way for its users to properly implement cleanup and removal. Add a matching unregister function for the mux type clk. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mux.c | 35 ++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mux.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c index 89f23e111d91..6f0c22a699c3 100644 --- a/drivers/clk/mediatek/clk-mux.c +++ b/drivers/clk/mediatek/clk-mux.c @@ -164,6 +164,21 @@ static struct clk *mtk_clk_register_mux(const struct mtk_mux *mux, return clk; } +static void mtk_clk_unregister_mux(struct clk *clk) +{ + struct mtk_clk_mux *mux; + struct clk_hw *hw; + + hw = __clk_get_hw(clk); + if (!hw) + return; + + mux = to_mtk_clk_mux(hw); + + clk_unregister(clk); + kfree(mux); +} + int mtk_clk_register_muxes(const struct mtk_mux *muxes, int num, struct device_node *node, spinlock_t *lock, @@ -198,4 +213,24 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes, } EXPORT_SYMBOL_GPL(mtk_clk_register_muxes); +void mtk_clk_unregister_muxes(const struct mtk_mux *muxes, int num, + struct clk_onecell_data *clk_data) +{ + int i; + + if (!clk_data) + return; + + for (i = num; i > 0; i--) { + const struct mtk_mux *mux = &muxes[i - 1]; + + if (IS_ERR_OR_NULL(clk_data->clks[mux->id])) + continue; + + mtk_clk_unregister_mux(clk_data->clks[mux->id]); + clk_data->clks[mux->id] = ERR_PTR(-ENOENT); + } +} +EXPORT_SYMBOL_GPL(mtk_clk_unregister_muxes); + MODULE_LICENSE("GPL"); diff --git a/drivers/clk/mediatek/clk-mux.h b/drivers/clk/mediatek/clk-mux.h index 27841d649118..cb2ac4f04c58 100644 --- a/drivers/clk/mediatek/clk-mux.h +++ b/drivers/clk/mediatek/clk-mux.h @@ -88,4 +88,7 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes, spinlock_t *lock, struct clk_onecell_data *clk_data); +void mtk_clk_unregister_muxes(const struct mtk_mux *muxes, int num, + struct clk_onecell_data *clk_data); + #endif /* __DRV_CLK_MTK_MUX_H */ From patchwork Wed Feb 2 13:48:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7117FC433F5 for ; Wed, 2 Feb 2022 13:50:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238446AbiBBNuT (ORCPT ); Wed, 2 Feb 2022 08:50:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344552AbiBBNuB (ORCPT ); Wed, 2 Feb 2022 08:50:01 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0CFCC061755 for ; Wed, 2 Feb 2022 05:49:58 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id i65so18829935pfc.9 for ; Wed, 02 Feb 2022 05:49:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=koVwH4W47ZnmdMQC+i7F7tu84t6ApcfQpNxUmrQL9bs=; b=EUM4BcWxvZOnU+GfCT/HmA+o6iiYZ40xeNYZXdyjB43nQld9ZRzxpOBZJN3lPU1dkh nNfqSuXf5AQE4HSoKTJJowRfXBPTAHMVVa4V+AwB2qZoP1hvwei1qItoMr/uwbVyENfO R/SOqvzD2gT1TnOw+QeTbgU2hZ08ncFdINjaU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=koVwH4W47ZnmdMQC+i7F7tu84t6ApcfQpNxUmrQL9bs=; b=UNTnT7tfqdhzXM69tSN4NaYDRnVoXzesRyAVu4VCooZsE8fzLb+MWIU5BfrPxmVQxX 2lh/X4IKv7ZGMM20q9TMAN3JClOXLaRNYP1+TaGN8gLmxppZ3+R7/9Z6Bh+gQAaYPUnD uO35nWJ+PUNCjN0DqSDdA3bXf0RREaa7Ko/IZzn0RXIeDrefTd6NHM1KSxGOFzSt/oI+ ujkV9ijlAfcxovXAAxc8vRbhw17c7zHtOnhTCA3YzrA8jGaTOpwKUmfhR/NE7+d04qg2 428k4+aS/vRXbP/WS0xMj436bkrsIAcJfAx0t086//ViBimK0EgL9yAAr8+B7tI+MVSy KHxg== X-Gm-Message-State: AOAM531XQ54Mw1syBeNjXSWkHizHcmWDN3S66ETYaB8TW7BFbseD0gFF LgarkHDFbl3vRF9iqEU/4HiLzw== X-Google-Smtp-Source: ABdhPJxTnVZoIVxU07+X5AzoQO2ik1+O5errakn66KV31/A9bAV8mo0hGkeH+5Qokg4S8y6zDVCYZQ== X-Received: by 2002:a05:6a00:841:: with SMTP id q1mr8267625pfk.21.1643809798495; Wed, 02 Feb 2022 05:49:58 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:49:58 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 10/31] clk: mediatek: mux: Internalize struct mtk_clk_mux Date: Wed, 2 Feb 2022 21:48:13 +0800 Message-Id: <20220202134834.690675-11-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org struct mtk_clk_mux is an implementation detail of the mux clk type, and is not used outside of the implementation. Internalize the definition to minimize leakage of details and shrink the header file. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mux.c | 8 ++++++++ drivers/clk/mediatek/clk-mux.h | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c index 6f0c22a699c3..2d4d8dc0120a 100644 --- a/drivers/clk/mediatek/clk-mux.c +++ b/drivers/clk/mediatek/clk-mux.c @@ -13,6 +13,14 @@ #include "clk-mtk.h" #include "clk-mux.h" +struct mtk_clk_mux { + struct clk_hw hw; + struct regmap *regmap; + const struct mtk_mux *data; + spinlock_t *lock; + bool reparent; +}; + static inline struct mtk_clk_mux *to_mtk_clk_mux(struct clk_hw *hw) { return container_of(hw, struct mtk_clk_mux, hw); diff --git a/drivers/clk/mediatek/clk-mux.h b/drivers/clk/mediatek/clk-mux.h index cb2ac4f04c58..38a2b6014b08 100644 --- a/drivers/clk/mediatek/clk-mux.h +++ b/drivers/clk/mediatek/clk-mux.h @@ -9,14 +9,6 @@ #include -struct mtk_clk_mux { - struct clk_hw hw; - struct regmap *regmap; - const struct mtk_mux *data; - spinlock_t *lock; - bool reparent; -}; - struct mtk_mux { int id; const char *name; From patchwork Wed Feb 2 13:48:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732916 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99BFCC433EF for ; Wed, 2 Feb 2022 13:50:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238980AbiBBNuS (ORCPT ); Wed, 2 Feb 2022 08:50:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344556AbiBBNuB (ORCPT ); Wed, 2 Feb 2022 08:50:01 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E08B6C06175A for ; Wed, 2 Feb 2022 05:50:00 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id h23so18329630pgk.11 for ; Wed, 02 Feb 2022 05:50:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=atVL6xJF/54HJ2aWxtM+9tGv7OBG0H7yvFIiBDi452k=; b=KokZ29ZgNuAl3t+XgjfUEk3Bpr7iTEs+HxAkSQTAjFt8MtVd92B7EM//xJfeoxHFcG CURs15ExfQ68RVYPKdkpcVHsJ21gFZHbfjRcl6tSu5KwHMu7ghFUrJxeLlmkYGyzqhJY eJSDBxTcm6jX8Ys5/RBbe5fsYH5hpW/v1bP7Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=atVL6xJF/54HJ2aWxtM+9tGv7OBG0H7yvFIiBDi452k=; b=wanmUdMZEG6dw0rc4hu3hnHWcf0iU6oot22Nn/9ObrNEBV/foub+wc/A1JcWLoSkTP bOpl8JudWJ8sfA6pixBrr0m/nOqU8DDUtHnV35Kp8q/qN2YBpSbJzaEDKfL8rtXnwebS KfFMztcU7PW3NOsatOZzNHxQr9cygS925EahFpfjmQboR9Sv3KJs897kNYTi6b7C8Sa3 u9PL9ksnO6PBMUz+qi5yK6sCrHrwq0OTZ5zwXNdGYIJ1CyJpxY55iDxIdI7Gh5E6/pBX tESn1H/PtnCMwTFGfTV6Lmw3TGPUIlYbetekEOJ9yMdl0V9CWvxaPRbD0G4dQVdVUjE+ tOvA== X-Gm-Message-State: AOAM533b8tO9Vl/iF3D6E0r6u0qER3uoJM2/471i8VWuB7SEcKv5Y0Gr U4PkSVJUI89/tgdflJi3AtIP3g== X-Google-Smtp-Source: ABdhPJwJNNtXsmuuzMgKjlUyJSyJMix5Mr8FLafmoEYLOBjBKCisUB5Vl/24ORK+SOxnDNq5ZWil8A== X-Received: by 2002:a05:6a00:15d5:: with SMTP id o21mr3872002pfu.9.1643809800457; Wed, 02 Feb 2022 05:50:00 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:00 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 11/31] clk: mediatek: mux: Clean up included headers Date: Wed, 2 Feb 2022 21:48:14 +0800 Message-Id: <20220202134834.690675-12-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Some included headers aren't actually used anywhere, while other headers with the declaration of functions and structures aren't directly included. Get rid of the unused ones, and add the ones that should be included directly. On the header side, replace headers that are included purely for data structure definitions with forward declarations. This decreases the amount of preprocessing and compilation effort required for each inclusion. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mux.c | 11 +++++++---- drivers/clk/mediatek/clk-mux.h | 8 +++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c index 2d4d8dc0120a..01af6a52711a 100644 --- a/drivers/clk/mediatek/clk-mux.c +++ b/drivers/clk/mediatek/clk-mux.c @@ -4,13 +4,16 @@ * Author: Owen Chen */ -#include -#include -#include +#include +#include +#include +#include #include #include +#include +#include +#include -#include "clk-mtk.h" #include "clk-mux.h" struct mtk_clk_mux { diff --git a/drivers/clk/mediatek/clk-mux.h b/drivers/clk/mediatek/clk-mux.h index 38a2b6014b08..903a3c937959 100644 --- a/drivers/clk/mediatek/clk-mux.h +++ b/drivers/clk/mediatek/clk-mux.h @@ -7,7 +7,13 @@ #ifndef __DRV_CLK_MTK_MUX_H #define __DRV_CLK_MTK_MUX_H -#include +#include +#include + +struct clk; +struct clk_onecell_data; +struct clk_ops; +struct device_node; struct mtk_mux { int id; From patchwork Wed Feb 2 13:48:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F33A8C433FE for ; Wed, 2 Feb 2022 13:50:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238484AbiBBNuG (ORCPT ); Wed, 2 Feb 2022 08:50:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344530AbiBBNuD (ORCPT ); Wed, 2 Feb 2022 08:50:03 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF9AC06173D for ; Wed, 2 Feb 2022 05:50:03 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id n32so18826074pfv.11 for ; Wed, 02 Feb 2022 05:50:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BRWNc4zNXSvV4mEvS8tdAAERyYeqWWOQLJ/TN7+vUyc=; b=T1HCoh98CppV0n89frXBKQsPm5p32a+tTthI8umurYHwxBkWrZkT2TtX/FBR6dmvvE vnmt6nJbDW2p7C7Rxam0QSvlBvSO+gVPW3Z6zXX+vStCjH5STa/PwZfajj+YdNQzv3hK Hzxp+ci9Q7oISlxM0994ZTcqXzLeULaOgAnVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BRWNc4zNXSvV4mEvS8tdAAERyYeqWWOQLJ/TN7+vUyc=; b=dYsNPLijCP2cqZ+BljsXJbmKpqWj/lcP6Zzc9WMa3Bxwznt+MNfbP+u8VIDYGOtDPW 6DzvjTfvZrdrlyuPRp62T2AoC4lCLFpK0PCBCU2tufVQmhtoigHfjNgsQdSqrG9dCDmv WlTbjdsP4WTrdtgEwxoC0UHmBG/xT/VycR8uRjfINDVjSkyiLlahpxvimmi91Kz7Y9d0 m18CHkQ8FnsKXJm2C6iB3Vnzmt0xZNUmHHm/Wf2MYmQ1bLLgKOdDdUbHc/ubAFiGtrXy w/8QtNXrt6D7rat+a/WQZ21rivUYXr6NKvXoAjhxPJZ6diqHO9VaV2zvdy2lUHMXxVAA qrSQ== X-Gm-Message-State: AOAM531gyUGjTCEGPQCvPeF3c7uuh6YIjfddchIjZt3+vVEZepFW3PCw eICZjDi7nG7Zxn+ZOezRL56USQ== X-Google-Smtp-Source: ABdhPJy70g7h9zUMATj6TiUekok7CP+bfix6vVF9iJndPA76fGznJw+/2TJbmYsQsONKXuHXm2m33Q== X-Received: by 2002:a62:7c42:: with SMTP id x63mr29766601pfc.31.1643809802476; Wed, 02 Feb 2022 05:50:02 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:02 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 12/31] clk: mediatek: pll: Split definitions into separate header file Date: Wed, 2 Feb 2022 21:48:15 +0800 Message-Id: <20220202134834.690675-13-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org When the PLL type clk was implemented in the MediaTek clk driver library, the data structure definitions and function declaration were put in the common header file. Since it is its own type of clk, and not all platform clk drivers utilize it, having the definitions in the common header results in wasted cycles during compilation. Split out the related definitions and declarations into its own header file, and include that only in the platform clk drivers that need it. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mt2701.c | 5 +- drivers/clk/mediatek/clk-mt2712.c | 3 +- drivers/clk/mediatek/clk-mt6765.c | 3 +- drivers/clk/mediatek/clk-mt6779.c | 3 +- drivers/clk/mediatek/clk-mt6797.c | 3 +- drivers/clk/mediatek/clk-mt7622.c | 5 +- drivers/clk/mediatek/clk-mt7629.c | 5 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 4 +- drivers/clk/mediatek/clk-mt8135.c | 3 +- drivers/clk/mediatek/clk-mt8167.c | 3 +- drivers/clk/mediatek/clk-mt8173.c | 5 +- drivers/clk/mediatek/clk-mt8183.c | 3 +- drivers/clk/mediatek/clk-mt8192.c | 3 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 1 + drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 1 + drivers/clk/mediatek/clk-mt8516.c | 3 +- drivers/clk/mediatek/clk-mtk.h | 39 -------------- drivers/clk/mediatek/clk-pll.c | 1 + drivers/clk/mediatek/clk-pll.h | 55 ++++++++++++++++++++ 19 files changed, 91 insertions(+), 57 deletions(-) create mode 100644 drivers/clk/mediatek/clk-pll.h diff --git a/drivers/clk/mediatek/clk-mt2701.c b/drivers/clk/mediatek/clk-mt2701.c index 695be0f77427..1eb3e4563c3f 100644 --- a/drivers/clk/mediatek/clk-mt2701.c +++ b/drivers/clk/mediatek/clk-mt2701.c @@ -10,9 +10,10 @@ #include #include -#include "clk-mtk.h" -#include "clk-gate.h" #include "clk-cpumux.h" +#include "clk-gate.h" +#include "clk-mtk.h" +#include "clk-pll.h" #include diff --git a/drivers/clk/mediatek/clk-mt2712.c b/drivers/clk/mediatek/clk-mt2712.c index a3bd9a107209..ff72b9ab945b 100644 --- a/drivers/clk/mediatek/clk-mt2712.c +++ b/drivers/clk/mediatek/clk-mt2712.c @@ -13,8 +13,9 @@ #include #include -#include "clk-mtk.h" #include "clk-gate.h" +#include "clk-pll.h" +#include "clk-mtk.h" #include diff --git a/drivers/clk/mediatek/clk-mt6765.c b/drivers/clk/mediatek/clk-mt6765.c index d77ea5aff292..24829ca3bd1f 100644 --- a/drivers/clk/mediatek/clk-mt6765.c +++ b/drivers/clk/mediatek/clk-mt6765.c @@ -12,9 +12,10 @@ #include #include -#include "clk-mtk.h" #include "clk-gate.h" +#include "clk-mtk.h" #include "clk-mux.h" +#include "clk-pll.h" #include diff --git a/drivers/clk/mediatek/clk-mt6779.c b/drivers/clk/mediatek/clk-mt6779.c index 9825385c9f94..7b61664da18f 100644 --- a/drivers/clk/mediatek/clk-mt6779.c +++ b/drivers/clk/mediatek/clk-mt6779.c @@ -10,9 +10,10 @@ #include #include +#include "clk-gate.h" #include "clk-mtk.h" #include "clk-mux.h" -#include "clk-gate.h" +#include "clk-pll.h" #include diff --git a/drivers/clk/mediatek/clk-mt6797.c b/drivers/clk/mediatek/clk-mt6797.c index 428eb24ffec5..02259e81625a 100644 --- a/drivers/clk/mediatek/clk-mt6797.c +++ b/drivers/clk/mediatek/clk-mt6797.c @@ -9,8 +9,9 @@ #include #include -#include "clk-mtk.h" #include "clk-gate.h" +#include "clk-mtk.h" +#include "clk-pll.h" #include diff --git a/drivers/clk/mediatek/clk-mt7622.c b/drivers/clk/mediatek/clk-mt7622.c index ef5947e15c75..0e1fb30a1e98 100644 --- a/drivers/clk/mediatek/clk-mt7622.c +++ b/drivers/clk/mediatek/clk-mt7622.c @@ -11,9 +11,10 @@ #include #include -#include "clk-mtk.h" -#include "clk-gate.h" #include "clk-cpumux.h" +#include "clk-gate.h" +#include "clk-mtk.h" +#include "clk-pll.h" #include #include /* for consumer */ diff --git a/drivers/clk/mediatek/clk-mt7629.c b/drivers/clk/mediatek/clk-mt7629.c index a0ee079670c7..c0e023bf31eb 100644 --- a/drivers/clk/mediatek/clk-mt7629.c +++ b/drivers/clk/mediatek/clk-mt7629.c @@ -12,9 +12,10 @@ #include #include -#include "clk-mtk.h" -#include "clk-gate.h" #include "clk-cpumux.h" +#include "clk-gate.h" +#include "clk-mtk.h" +#include "clk-pll.h" #include diff --git a/drivers/clk/mediatek/clk-mt7986-apmixed.c b/drivers/clk/mediatek/clk-mt7986-apmixed.c index 98ec3887585f..21d4c82e782a 100644 --- a/drivers/clk/mediatek/clk-mt7986-apmixed.c +++ b/drivers/clk/mediatek/clk-mt7986-apmixed.c @@ -10,9 +10,11 @@ #include #include #include -#include "clk-mtk.h" + #include "clk-gate.h" +#include "clk-mtk.h" #include "clk-mux.h" +#include "clk-pll.h" #include #include diff --git a/drivers/clk/mediatek/clk-mt8135.c b/drivers/clk/mediatek/clk-mt8135.c index 9b4b645aea99..09ad272d51f1 100644 --- a/drivers/clk/mediatek/clk-mt8135.c +++ b/drivers/clk/mediatek/clk-mt8135.c @@ -11,8 +11,9 @@ #include #include -#include "clk-mtk.h" #include "clk-gate.h" +#include "clk-mtk.h" +#include "clk-pll.h" static DEFINE_SPINLOCK(mt8135_clk_lock); diff --git a/drivers/clk/mediatek/clk-mt8167.c b/drivers/clk/mediatek/clk-mt8167.c index e5ea10e31799..812b33a57530 100644 --- a/drivers/clk/mediatek/clk-mt8167.c +++ b/drivers/clk/mediatek/clk-mt8167.c @@ -12,8 +12,9 @@ #include #include -#include "clk-mtk.h" #include "clk-gate.h" +#include "clk-mtk.h" +#include "clk-pll.h" #include diff --git a/drivers/clk/mediatek/clk-mt8173.c b/drivers/clk/mediatek/clk-mt8173.c index 8f898ac476c0..46b7655feeaa 100644 --- a/drivers/clk/mediatek/clk-mt8173.c +++ b/drivers/clk/mediatek/clk-mt8173.c @@ -8,9 +8,10 @@ #include #include -#include "clk-mtk.h" -#include "clk-gate.h" #include "clk-cpumux.h" +#include "clk-gate.h" +#include "clk-mtk.h" +#include "clk-pll.h" #include diff --git a/drivers/clk/mediatek/clk-mt8183.c b/drivers/clk/mediatek/clk-mt8183.c index 5046852eb0fd..68496554dd3d 100644 --- a/drivers/clk/mediatek/clk-mt8183.c +++ b/drivers/clk/mediatek/clk-mt8183.c @@ -11,9 +11,10 @@ #include #include +#include "clk-gate.h" #include "clk-mtk.h" #include "clk-mux.h" -#include "clk-gate.h" +#include "clk-pll.h" #include diff --git a/drivers/clk/mediatek/clk-mt8192.c b/drivers/clk/mediatek/clk-mt8192.c index 79ddb3cc0b98..ab27cd66b866 100644 --- a/drivers/clk/mediatek/clk-mt8192.c +++ b/drivers/clk/mediatek/clk-mt8192.c @@ -12,9 +12,10 @@ #include #include +#include "clk-gate.h" #include "clk-mtk.h" #include "clk-mux.h" -#include "clk-gate.h" +#include "clk-pll.h" #include diff --git a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c index 6156ceeed71e..5b1b7dc447eb 100644 --- a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c +++ b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c @@ -5,6 +5,7 @@ #include "clk-gate.h" #include "clk-mtk.h" +#include "clk-pll.h" #include #include diff --git a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c index f1c84186346e..db449ff877d7 100644 --- a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c +++ b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c @@ -4,6 +4,7 @@ // Author: Chun-Jie Chen #include "clk-mtk.h" +#include "clk-pll.h" #include #include diff --git a/drivers/clk/mediatek/clk-mt8516.c b/drivers/clk/mediatek/clk-mt8516.c index 9d4261ecc760..a37143f920ce 100644 --- a/drivers/clk/mediatek/clk-mt8516.c +++ b/drivers/clk/mediatek/clk-mt8516.c @@ -11,8 +11,9 @@ #include #include -#include "clk-mtk.h" #include "clk-gate.h" +#include "clk-mtk.h" +#include "clk-pll.h" #include diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index bdec7dc5e07a..168220f85489 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -179,45 +179,6 @@ void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num); void mtk_free_clk_data(struct clk_onecell_data *clk_data); -#define HAVE_RST_BAR BIT(0) -#define PLL_AO BIT(1) - -struct mtk_pll_div_table { - u32 div; - unsigned long freq; -}; - -struct mtk_pll_data { - int id; - const char *name; - u32 reg; - u32 pwr_reg; - u32 en_mask; - u32 pd_reg; - u32 tuner_reg; - u32 tuner_en_reg; - u8 tuner_en_bit; - int pd_shift; - unsigned int flags; - const struct clk_ops *ops; - u32 rst_bar_mask; - unsigned long fmin; - unsigned long fmax; - int pcwbits; - int pcwibits; - u32 pcw_reg; - int pcw_shift; - u32 pcw_chg_reg; - const struct mtk_pll_div_table *div_table; - const char *parent_name; - u32 en_reg; - u8 pll_en_bit; /* Assume 0, indicates BIT(0) by default */ -}; - -void mtk_clk_register_plls(struct device_node *node, - const struct mtk_pll_data *plls, int num_plls, - struct clk_onecell_data *clk_data); - struct clk *mtk_clk_register_ref2usb_tx(const char *name, const char *parent_name, void __iomem *reg); diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c index f04f724e12e5..64f59554bc9b 100644 --- a/drivers/clk/mediatek/clk-pll.c +++ b/drivers/clk/mediatek/clk-pll.c @@ -13,6 +13,7 @@ #include #include "clk-mtk.h" +#include "clk-pll.h" #define REG_CON0 0 #define REG_CON1 4 diff --git a/drivers/clk/mediatek/clk-pll.h b/drivers/clk/mediatek/clk-pll.h new file mode 100644 index 000000000000..d01b0c38311d --- /dev/null +++ b/drivers/clk/mediatek/clk-pll.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2014 MediaTek Inc. + * Author: James Liao + */ + +#ifndef __DRV_CLK_MTK_PLL_H +#define __DRV_CLK_MTK_PLL_H + +#include + +struct clk_ops; +struct clk_onecell_data; +struct device_node; + +struct mtk_pll_div_table { + u32 div; + unsigned long freq; +}; + +#define HAVE_RST_BAR BIT(0) +#define PLL_AO BIT(1) + +struct mtk_pll_data { + int id; + const char *name; + u32 reg; + u32 pwr_reg; + u32 en_mask; + u32 pd_reg; + u32 tuner_reg; + u32 tuner_en_reg; + u8 tuner_en_bit; + int pd_shift; + unsigned int flags; + const struct clk_ops *ops; + u32 rst_bar_mask; + unsigned long fmin; + unsigned long fmax; + int pcwbits; + int pcwibits; + u32 pcw_reg; + int pcw_shift; + u32 pcw_chg_reg; + const struct mtk_pll_div_table *div_table; + const char *parent_name; + u32 en_reg; + u8 pll_en_bit; /* Assume 0, indicates BIT(0) by default */ +}; + +void mtk_clk_register_plls(struct device_node *node, + const struct mtk_pll_data *plls, int num_plls, + struct clk_onecell_data *clk_data); + +#endif /* __DRV_CLK_MTK_PLL_H */ From patchwork Wed Feb 2 13:48:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23794C433EF for ; Wed, 2 Feb 2022 13:50:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344584AbiBBNuI (ORCPT ); Wed, 2 Feb 2022 08:50:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344576AbiBBNuF (ORCPT ); Wed, 2 Feb 2022 08:50:05 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBEAAC061741 for ; Wed, 2 Feb 2022 05:50:04 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id e6so18836445pfc.7 for ; Wed, 02 Feb 2022 05:50:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pu1eEdNAtHQ3VmVoh3gnbPNdE4vdn2pwQinjoq/O1Tc=; b=XxrvETu43smOM+759hn3mDrz6X0CXmFDosOhmu1IBEX13G+3hWSBYQqrjAggRHGLtO pbKKjaE+Gi6g37qLGUg+xcVKcyPTSTT4E8RzY6y2ZOed+7ctgQKaiYHhyAy1QtCQa3VY o2IcpfMzV1RUduRMLrflAuqvyPz6MwmFD2MYY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pu1eEdNAtHQ3VmVoh3gnbPNdE4vdn2pwQinjoq/O1Tc=; b=7K/vDOZ8n46Omm8WSjo/PKKM00YC7gwijcY6rvluYCekDv9AwaPUWBR3ar7cKcAvom BWl60w7NC1dQaX7AsYe9T67fuigQOilNH/aV3+EnFpDnkIbakO47F3D0WE2NV0ygMPyK FUxz55QY4aSwAAvNUcsTo3QbDashheaBwyPgKg/PG+cZeyFsNxHNlgq+Im8l4RLqmKYP SWXKRWJGNii7qz6X9yrvmRFD7I2bKF/DIqMUyAF1s1tt7q6otb0155i/u63adi5qRoLg y18Ot7MQfWQ0GZJL3eBuFuzgwogkLZjtG3ucJXa8NmO2s9U8F3g1hZTR+XBJwt+uUOcx ScCg== X-Gm-Message-State: AOAM531OPLqkHCpJbUoCVf5q5NDZy8jUZzwd+wbF7r5hHLz1xGVOiZGL fkrWNUorkUqUEWCHFxA85Rt9Ew== X-Google-Smtp-Source: ABdhPJw18NufROymgGz/nDz0CyPOetP8fX0Kdc2e1irdYQpm7ZsWLGU25ERBQFI7Y9hn/tbWac7ouQ== X-Received: by 2002:a63:d711:: with SMTP id d17mr24557543pgg.429.1643809804449; Wed, 02 Feb 2022 05:50:04 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:04 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 13/31] clk: mediatek: pll: Implement unregister API Date: Wed, 2 Feb 2022 21:48:16 +0800 Message-Id: <20220202134834.690675-14-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The PLL clk type within the MediaTek clk driver library only has a register function, and no corresponding unregister function. This means there is no way for its users to properly implement cleanup and removal. Add a matching unregister function for the PLL type clk. Signed-off-by: Chen-Yu Tsai Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Miles Chen --- drivers/clk/mediatek/clk-pll.c | 55 ++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-pll.h | 2 ++ 2 files changed, 57 insertions(+) diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c index 64f59554bc9b..b54e33b75d4e 100644 --- a/drivers/clk/mediatek/clk-pll.c +++ b/drivers/clk/mediatek/clk-pll.c @@ -360,6 +360,21 @@ static struct clk *mtk_clk_register_pll(const struct mtk_pll_data *data, return clk; } +static void mtk_clk_unregister_pll(struct clk *clk) +{ + struct clk_hw *hw; + struct mtk_clk_pll *pll; + + hw = __clk_get_hw(clk); + if (!hw) + return; + + pll = to_mtk_clk_pll(hw); + + clk_unregister(clk); + kfree(pll); +} + void mtk_clk_register_plls(struct device_node *node, const struct mtk_pll_data *plls, int num_plls, struct clk_onecell_data *clk_data) { @@ -388,4 +403,44 @@ void mtk_clk_register_plls(struct device_node *node, } EXPORT_SYMBOL_GPL(mtk_clk_register_plls); +static __iomem void *mtk_clk_pll_get_base(struct clk *clk, + const struct mtk_pll_data *data) +{ + struct clk_hw *hw = __clk_get_hw(clk); + struct mtk_clk_pll *pll = to_mtk_clk_pll(hw); + + return pll->base_addr - data->reg; +} + +void mtk_clk_unregister_plls(const struct mtk_pll_data *plls, int num_plls, + struct clk_onecell_data *clk_data) +{ + __iomem void *base = NULL; + int i; + + if (!clk_data) + return; + + for (i = num_plls; i > 0; i--) { + const struct mtk_pll_data *pll = &plls[i - 1]; + + if (IS_ERR_OR_NULL(clk_data->clks[pll->id])) + continue; + + /* + * This is quite ugly but unfortunately the clks don't have + * any device tied to them, so there's no place to store the + * pointer to the I/O region base address. We have to fetch + * it from one of the registered clks. + */ + base = mtk_clk_pll_get_base(clk_data->clks[pll->id], pll); + + mtk_clk_unregister_pll(clk_data->clks[pll->id]); + clk_data->clks[pll->id] = ERR_PTR(-ENOENT); + } + + iounmap(base); +} +EXPORT_SYMBOL_GPL(mtk_clk_unregister_plls); + MODULE_LICENSE("GPL"); diff --git a/drivers/clk/mediatek/clk-pll.h b/drivers/clk/mediatek/clk-pll.h index d01b0c38311d..a889b1e472e7 100644 --- a/drivers/clk/mediatek/clk-pll.h +++ b/drivers/clk/mediatek/clk-pll.h @@ -51,5 +51,7 @@ struct mtk_pll_data { void mtk_clk_register_plls(struct device_node *node, const struct mtk_pll_data *plls, int num_plls, struct clk_onecell_data *clk_data); +void mtk_clk_unregister_plls(const struct mtk_pll_data *plls, int num_plls, + struct clk_onecell_data *clk_data); #endif /* __DRV_CLK_MTK_PLL_H */ From patchwork Wed Feb 2 13:48:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DD4CC433F5 for ; Wed, 2 Feb 2022 13:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344594AbiBBNuI (ORCPT ); Wed, 2 Feb 2022 08:50:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344537AbiBBNuG (ORCPT ); Wed, 2 Feb 2022 08:50:06 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC928C061714 for ; Wed, 2 Feb 2022 05:50:06 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id c194so6319766pfb.12 for ; Wed, 02 Feb 2022 05:50:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o96FYGbHJ72XBS1HhlvbpoWVDn8elKqn4OTG7Iw+mEs=; b=RhLz21DXPJQfKR+n26oncQXVj4xqQ04C52QcLlmftxu0nWOcTJ6Y5dYYkD9/QSgXhw JfOiFZAQSUL3eQTzvcQQBKph1gciE1wZgXFlj/zYQljKWURs7XFvrEXNGtNx/nQ34RV3 bt0VE1z5lCh5z8dM+b/Jin29QyTIS4H7MUYv4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o96FYGbHJ72XBS1HhlvbpoWVDn8elKqn4OTG7Iw+mEs=; b=ylB4fJb2pX8Di1uahstuVQZQkFISz3uWyqhwOim1YrXeYUpAJWD39KjG3TdesBDKJk EqzJmTa7UzruDJb9b8Sd8ePk40Esi0pAeWOUaG3FTNIMYC/jUij/eAIxzTIBSmLhYa7L IXCTc0wAUdo31lhaxli1PHF51YFamjgZUdUx7vd/HeCcJ1+pl/uYBH45SV3BRRhZByDb C0iaKtIZgLpp0Q8zZv7UV04JqAVeiAfz/LfzncfldpJOBh1WbeGmOfR1tPAQiKacCPEv WGevThwNXj+vtboRENH80KFtMc/jVVP82A0IZFolpNKBi3OSURLoL+9hkXosKbyz7kJX XBlQ== X-Gm-Message-State: AOAM533np4kC14Ft9d6jjv1ST3Mw/o3EX5G5VKQlKYOEHyR74shKNfzG wsew4GN5nzuUn95MF27EVnOfSw== X-Google-Smtp-Source: ABdhPJwGk4mMv+6QTWbFNcM4eaBrE2MyeosyxrmnAMXK3NCjCSxZCRqIb3HJDTR1SsrBYzKnGI0BBw== X-Received: by 2002:a63:d943:: with SMTP id e3mr24468905pgj.427.1643809806414; Wed, 02 Feb 2022 05:50:06 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:06 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 14/31] clk: mediatek: pll: Clean up included headers Date: Wed, 2 Feb 2022 21:48:17 +0800 Message-Id: <20220202134834.690675-15-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Some included headers aren't actually used anywhere, while other headers with the declaration of functions and structures aren't directly included. Get rid of the unused ones, and add the ones that should be included directly. Also, copy the MHZ macro from clk-mtk.h, and drop clk-mtk.h from the included headers. Signed-off-by: Chen-Yu Tsai Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Miles Chen --- drivers/clk/mediatek/clk-pll.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c index b54e33b75d4e..8439d37e354d 100644 --- a/drivers/clk/mediatek/clk-pll.c +++ b/drivers/clk/mediatek/clk-pll.c @@ -4,17 +4,19 @@ * Author: James Liao */ -#include -#include +#include +#include +#include +#include #include #include +#include #include -#include -#include -#include "clk-mtk.h" #include "clk-pll.h" +#define MHZ (1000 * 1000) + #define REG_CON0 0 #define REG_CON1 4 From patchwork Wed Feb 2 13:48:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732914 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B182AC433EF for ; Wed, 2 Feb 2022 13:50:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344549AbiBBNuL (ORCPT ); Wed, 2 Feb 2022 08:50:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344595AbiBBNuI (ORCPT ); Wed, 2 Feb 2022 08:50:08 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4C57C06173D for ; Wed, 2 Feb 2022 05:50:08 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id e16so18363297pgn.4 for ; Wed, 02 Feb 2022 05:50:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZiK2XIbHygUp2e9+jzr8Jt6sIllwZaRaY/96jv41JNQ=; b=QPQOWHGcG0FhTl+ujSaIWEHoxMADagiEXp90XeOlMwZkYwx9ojL8OrJNcHCeyQ8B0U R/yXL+qZKdIOKC4LaWKtoAskERPkRqTwhJKOVTUlQAUyxmHvny5/jSM4zTEdrFpqY/iC kXk//XSfqc8FbSmSdylQVoRQRUn8lg1tsPcPo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZiK2XIbHygUp2e9+jzr8Jt6sIllwZaRaY/96jv41JNQ=; b=e0+vCapAQZsy7BO4rd/s9cFvZipsHNuvNx/ykMooP8mt5ts2YihFUe6DfQt5g7H1mo lm8avg8ukFsVToLp6X7zpqZanYUiUdftf9cwPULJKbnTRtp+qCsS/lKfle+yRJwwSmDR PwvSpHyH8t60+kJZJ+LH9D4cNM2Y0y0P898S1HnwzbZ2959MhGWMKe4fy+B5uhRzvwNC pT12frl6U1Z9yXivqZm+ZUpRgisQHgaRA5vuCOofiveidJL6duhlxqRoIeUYpZiJ5uGc y7uRI52ZTphpuL7odxYGPMudz2CNvZGPVEM61ESm34o+RVCPa14Q/p1cdpZtFV6+y5S6 71Qw== X-Gm-Message-State: AOAM531dZNR/GFN69bJtrDnZkaih7ChTDh/EEGZB3gwVj9aUi+L5h/Hi Mz7T+FHMfK69McHkjt7bozSTGA== X-Google-Smtp-Source: ABdhPJzwy7/E419LuvX14RpwYTVofcCB4seqnwxBWNGVvuMqYrjsbRzAkFsSwOwwb553aJSU0DlW0A== X-Received: by 2002:a65:5543:: with SMTP id t3mr24333608pgr.180.1643809808363; Wed, 02 Feb 2022 05:50:08 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:08 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 15/31] clk: mediatek: Implement mtk_clk_unregister_fixed_clks() API Date: Wed, 2 Feb 2022 21:48:18 +0800 Message-Id: <20220202134834.690675-16-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org mtk_clk_register_fixed_clks(), as the name suggests, is used to register a given list of fixed rate clks. However it is lacking a counterpart unregister API. Implement said unregister API so that the various clock platform drivers can utilize it to do proper unregistration, cleanup and removal. In the header file, the register function's declaration is also reformatted to fit code style guidelines. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mtk.c | 20 ++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 6 ++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 0c5db3c71fdd..7c0d5706eed7 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -80,6 +80,26 @@ void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, } EXPORT_SYMBOL_GPL(mtk_clk_register_fixed_clks); +void mtk_clk_unregister_fixed_clks(const struct mtk_fixed_clk *clks, int num, + struct clk_onecell_data *clk_data) +{ + int i; + + if (!clk_data) + return; + + for (i = num; i > 0; i--) { + const struct mtk_fixed_clk *rc = &clks[i - 1]; + + if (IS_ERR_OR_NULL(clk_data->clks[rc->id])) + continue; + + clk_unregister_fixed_rate(clk_data->clks[rc->id]); + clk_data->clks[rc->id] = ERR_PTR(-ENOENT); + } +} +EXPORT_SYMBOL_GPL(mtk_clk_unregister_fixed_clks); + void mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num, struct clk_onecell_data *clk_data) { diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index 168220f85489..cc7f920eabb4 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -34,8 +34,10 @@ struct mtk_fixed_clk { .rate = _rate, \ } -void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, - int num, struct clk_onecell_data *clk_data); +void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num, + struct clk_onecell_data *clk_data); +void mtk_clk_unregister_fixed_clks(const struct mtk_fixed_clk *clks, int num, + struct clk_onecell_data *clk_data); struct mtk_fixed_factor { int id; From patchwork Wed Feb 2 13:48:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62999C433FE for ; Wed, 2 Feb 2022 13:50:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344574AbiBBNuO (ORCPT ); Wed, 2 Feb 2022 08:50:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344475AbiBBNuK (ORCPT ); Wed, 2 Feb 2022 08:50:10 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0126C06173B for ; Wed, 2 Feb 2022 05:50:10 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id c3so18296760pls.5 for ; Wed, 02 Feb 2022 05:50:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8Wqt8bANP5ifvGkIaVLK4/SfxJUiMOM5777d8fxcmLM=; b=m2ksXmN7GxvSJ/YH+L/9081yGbKbVptVViQ7mbt5uZRnW8oCM+USFPKAP+awj9+dFG jO235c+pDT2bEX4Nr7VfDXg1JwB+GOzcK6xg5uUworwikrQ4prvPI/CJ3qNxqaLTyMGD paUb6rV0mbYbYGkmOIZ+tDuDktrRvNfBZkToM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Wqt8bANP5ifvGkIaVLK4/SfxJUiMOM5777d8fxcmLM=; b=AXns9tqSndqAr2u6xWjuXBHs72QV8xdhdCjrvgwkLWWU7Sz3XRZR6410mh9gZxxB+E 0v2f0gMpQcYkFMU19ee/5JEnG3/2BaxnLhyKZe7ZXsUq2p9D96oGy0K1UdYGXu/M7EQn aJjmLDJLg9wNMtVx2eIefnzsUc0M8G2msrVsQZKs/lncylWYa5ufx6amuqwL8qbaXw+N 6l6lZEhIy1+BQiKoV0J8MrjNFgB9ix5xlsAc+qlb9ntdyjz6KLyZn5YZkjggaqzPc4Ks cr8lgonIvv0SDuxA7+qQvtNKe/7zJkz7U/nETk//DxBxtN9Dx3RS3/pBZfKY66O1QMKh iuxA== X-Gm-Message-State: AOAM530HZ2aG5/NfYqV/MfminiCyXRmxTbd9qJbyTzLfhmyedI+95XQB 6SxO5/+N7KFrge+g0MXDAzr+Lg== X-Google-Smtp-Source: ABdhPJz8hyWt2PyEVsnlaUWVM4Es83yV7JTMjXR/JmTG23iFKVNdT73cJkCBQTXNY12fQ41KC/4EBg== X-Received: by 2002:a17:90b:358e:: with SMTP id mm14mr8052020pjb.229.1643809810312; Wed, 02 Feb 2022 05:50:10 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:10 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 16/31] clk: mediatek: Implement mtk_clk_unregister_factors() API Date: Wed, 2 Feb 2022 21:48:19 +0800 Message-Id: <20220202134834.690675-17-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org mtk_clk_register_factors(), as the name suggests, is used to register a given list of fixed factor clks. However it is lacking a counterpart unregister API. Implement said unregister API so that the various clock platform drivers can utilize it to do proper unregistration, cleanup and removal. In the header file, the register function's declaration is also reformatted to fit code style guidelines. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mtk.c | 20 ++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 6 ++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 7c0d5706eed7..b267b2f04b84 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -126,6 +126,26 @@ void mtk_clk_register_factors(const struct mtk_fixed_factor *clks, } EXPORT_SYMBOL_GPL(mtk_clk_register_factors); +void mtk_clk_unregister_factors(const struct mtk_fixed_factor *clks, int num, + struct clk_onecell_data *clk_data) +{ + int i; + + if (!clk_data) + return; + + for (i = num; i > 0; i--) { + const struct mtk_fixed_factor *ff = &clks[i - 1]; + + if (IS_ERR_OR_NULL(clk_data->clks[ff->id])) + continue; + + clk_unregister_fixed_factor(clk_data->clks[ff->id]); + clk_data->clks[ff->id] = ERR_PTR(-ENOENT); + } +} +EXPORT_SYMBOL_GPL(mtk_clk_unregister_factors); + struct clk *mtk_clk_register_composite(const struct mtk_composite *mc, void __iomem *base, spinlock_t *lock) { diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index cc7f920eabb4..4db1a97c1250 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -55,8 +55,10 @@ struct mtk_fixed_factor { .div = _div, \ } -void mtk_clk_register_factors(const struct mtk_fixed_factor *clks, - int num, struct clk_onecell_data *clk_data); +void mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num, + struct clk_onecell_data *clk_data); +void mtk_clk_unregister_factors(const struct mtk_fixed_factor *clks, int num, + struct clk_onecell_data *clk_data); struct mtk_composite { int id; From patchwork Wed Feb 2 13:48:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732918 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1D37C433EF for ; Wed, 2 Feb 2022 13:50:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344508AbiBBNuZ (ORCPT ); Wed, 2 Feb 2022 08:50:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233666AbiBBNuN (ORCPT ); Wed, 2 Feb 2022 08:50:13 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0F7CC061744 for ; Wed, 2 Feb 2022 05:50:12 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id h23so18330068pgk.11 for ; Wed, 02 Feb 2022 05:50:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UdqER8KY39o0M6o27IczZWTaw020kfn22yTWl5kyALY=; b=n2JpvMVhjjJwqFphVfrI15VQG+1JJMJYetDB/WjD2E8sp8Ij+mxAKVC47NL1bh9cxy OmLwDMeOBZkgOzmt2C6eXbDqkA2Lxf814gH361WFKjl84b+IxJSHBW75t/fkNG/o5c9J COqyZj7X+WUmh75irkthHjmowhyJYhq9S2Z4g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UdqER8KY39o0M6o27IczZWTaw020kfn22yTWl5kyALY=; b=6DgPu0soVGT6f5u/CYRMgIjfu3dkmhdAYh8MUWZt58MS7gWwBE+KFNPFGTtUepDo9C 5ryVP5O+MONkHKZ/OFUDjl5el3B8iAmFjt7e/0c8NkQsKakNceFYByhBCTvyhMr3nwRk KJuVyTPckYG1bu5KfvMjFdt9KppcfAmiyJuGPmIzvBtWxE4FkJKL6r90leLFpwy8K+p4 vaH5tz+y3nMfU67TBKVGeF8ofMj+WJCvwkGBwNfexd8sJwzSzVO3tLfg91ccSot8+gVm Y08YrO2Ovu/UQEmaf+pMdrojLdyAqu0xoBB7vynRPE15KMB3VgDizSKPX9mde8VERggE iAiA== X-Gm-Message-State: AOAM530DExsIVSPs7IS8uzirR8ZPg+AFgGJd1xU+2ZJBiBFGIbuLKSmw Ibey4j3aS29pLPXkbah2NVU5yA== X-Google-Smtp-Source: ABdhPJwCruA99cnWXBiBLPDrFAMecZSCJ1O6DvdO/JNkZf58An/l4/zDvP7K+QHNRULGEqTyKmJi3Q== X-Received: by 2002:a63:6c87:: with SMTP id h129mr24978840pgc.530.1643809812274; Wed, 02 Feb 2022 05:50:12 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:12 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 17/31] clk: mediatek: Implement mtk_clk_unregister_divider_clks() API Date: Wed, 2 Feb 2022 21:48:20 +0800 Message-Id: <20220202134834.690675-18-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org mtk_clk_register_divider_clks(), as the name suggests, is used to register a given list of divider clks. However it is lacking a counterpart unregister API. Implement said unregister API so that the various clock platform drivers can utilize it to do proper unregistration, cleanup and removal. In the header file, the register function's declaration is also reformatted to fit code style guidelines. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mtk.c | 19 +++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 8 +++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index b267b2f04b84..3a6dfe445e63 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -286,6 +286,25 @@ void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, } } +void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num, + struct clk_onecell_data *clk_data) +{ + int i; + + if (!clk_data) + return; + + for (i = num; i > 0; i--) { + const struct mtk_clk_divider *mcd = &mcds[i - 1]; + + if (IS_ERR_OR_NULL(clk_data->clks[mcd->id])) + continue; + + clk_unregister_divider(clk_data->clks[mcd->id]); + clk_data->clks[mcd->id] = ERR_PTR(-ENOENT); + } +} + int mtk_clk_simple_probe(struct platform_device *pdev) { const struct mtk_clk_desc *mcd; diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index 4db1a97c1250..e3ae22fb0334 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -176,9 +176,11 @@ struct mtk_clk_divider { .div_width = _width, \ } -void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, - int num, void __iomem *base, spinlock_t *lock, - struct clk_onecell_data *clk_data); +void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num, + void __iomem *base, spinlock_t *lock, + struct clk_onecell_data *clk_data); +void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num, + struct clk_onecell_data *clk_data); struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num); void mtk_free_clk_data(struct clk_onecell_data *clk_data); From patchwork Wed Feb 2 13:48:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF45FC433F5 for ; Wed, 2 Feb 2022 13:50:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235079AbiBBNu1 (ORCPT ); Wed, 2 Feb 2022 08:50:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344581AbiBBNuP (ORCPT ); Wed, 2 Feb 2022 08:50:15 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35E51C06173D for ; Wed, 2 Feb 2022 05:50:15 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id cq9-20020a17090af98900b001b8262fe2d5so2093445pjb.0 for ; Wed, 02 Feb 2022 05:50:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N2rFtWf6KqBF9xTPNkR58mW4Ft7tifSnYgDGOnwZWmM=; b=A2TEbWyazowLCHaF4sxnFrf/4MM/80w5Zdz/MSmRbHBlI6qrtBt0Of872ysILEMFiv dXzigYiyj8HuPfx1+CcFTvhZ+LKD2BhHfWQRjgyMaV9if77Y7HZzO7aQfsUMNKPhBPx+ MJqeBSg80HFwiQO6wfGOeSCdZs1aft8j7xe1c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N2rFtWf6KqBF9xTPNkR58mW4Ft7tifSnYgDGOnwZWmM=; b=fJhitekVjd+x0rufFqQFFBUHWt6WWoFuv2/qNWBlkMbRK0kFkJoxwqksjEbDxgp8cD 4dOcwNb74orae+PLPDq4KSOeA/MQ+TkHzFfEysyjFWVPX9ufqt6P4RcCWk4b13tURdql p1TU6+Na8R1ChtWJeY4RyeTHPXd3XpSAG14or9kc88HfRwWLv+dob5SiyCniEuhyk1fs VYe4Ia9h6NhsWcCImmt+n9unkeg/OowaemoCHpbluTIIPz660AYizD/1XgzTSRo7vgA0 CWescJwpZVtjF4or+HpLDoz1F568/5u8Ml4WItciBOkiXC5mz3aYxi7YCLD8nh74IZ0j 0CnQ== X-Gm-Message-State: AOAM532Dl2hVYts7S9xJVzONlvQ4W5g3PPwnSl/hEOcUjMi/AEJ+yJl5 z7dAwcFrArXxXVJFlYIhkXNvsQ== X-Google-Smtp-Source: ABdhPJygRG8bYFhtlnVoNGsOJ6b3CgRc73OX4/Ug88WdrqeRvZXVJKZrLyD9KeAy+tMCvIi8t72LFg== X-Received: by 2002:a17:90b:3e8e:: with SMTP id rj14mr8071807pjb.112.1643809814237; Wed, 02 Feb 2022 05:50:14 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:14 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 18/31] clk: mediatek: Implement mtk_clk_unregister_composites() API Date: Wed, 2 Feb 2022 21:48:21 +0800 Message-Id: <20220202134834.690675-19-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org mtk_clk_register_composites(), as the name suggests, is used to register a given list of composite clks. However it is lacking a counterpart unregister API. Implement said unregister API so that the various clock platform drivers can utilize it to do proper unregistration, cleanup and removal. In the header file, the register function's declaration is also reformatted to fit code style guidelines. Signed-off-by: Chen-Yu Tsai Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Miles Chen --- drivers/clk/mediatek/clk-mtk.c | 46 ++++++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 2 ++ 2 files changed, 48 insertions(+) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 3a6dfe445e63..869e6ae55c82 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -233,6 +233,32 @@ struct clk *mtk_clk_register_composite(const struct mtk_composite *mc, return ERR_PTR(ret); } +static void mtk_clk_unregister_composite(struct clk *clk) +{ + struct clk_hw *hw; + struct clk_composite *composite; + struct clk_mux *mux = NULL; + struct clk_gate *gate = NULL; + struct clk_divider *div = NULL; + + hw = __clk_get_hw(clk); + if (!hw) + return; + + composite = to_clk_composite(hw); + if (composite->mux_hw) + mux = to_clk_mux(composite->mux_hw); + if (composite->gate_hw) + gate = to_clk_gate(composite->gate_hw); + if (composite->rate_hw) + div = to_clk_divider(composite->rate_hw); + + clk_unregister_composite(clk); + kfree(div); + kfree(gate); + kfree(mux); +} + void mtk_clk_register_composites(const struct mtk_composite *mcs, int num, void __iomem *base, spinlock_t *lock, struct clk_onecell_data *clk_data) @@ -259,6 +285,26 @@ void mtk_clk_register_composites(const struct mtk_composite *mcs, } EXPORT_SYMBOL_GPL(mtk_clk_register_composites); +void mtk_clk_unregister_composites(const struct mtk_composite *mcs, int num, + struct clk_onecell_data *clk_data) +{ + int i; + + if (!clk_data) + return; + + for (i = num; i > 0; i--) { + const struct mtk_composite *mc = &mcs[i - 1]; + + if (IS_ERR_OR_NULL(clk_data->clks[mc->id])) + continue; + + mtk_clk_unregister_composite(clk_data->clks[mc->id]); + clk_data->clks[mc->id] = ERR_PTR(-ENOENT); + } +} +EXPORT_SYMBOL_GPL(mtk_clk_unregister_composites); + void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num, void __iomem *base, spinlock_t *lock, struct clk_onecell_data *clk_data) diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index e3ae22fb0334..3c3a934f53cd 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -153,6 +153,8 @@ struct clk *mtk_clk_register_composite(const struct mtk_composite *mc, void mtk_clk_register_composites(const struct mtk_composite *mcs, int num, void __iomem *base, spinlock_t *lock, struct clk_onecell_data *clk_data); +void mtk_clk_unregister_composites(const struct mtk_composite *mcs, int num, + struct clk_onecell_data *clk_data); struct mtk_clk_divider { int id; From patchwork Wed Feb 2 13:48:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732920 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38CB4C433EF for ; Wed, 2 Feb 2022 13:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231927AbiBBNun (ORCPT ); Wed, 2 Feb 2022 08:50:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344631AbiBBNuY (ORCPT ); Wed, 2 Feb 2022 08:50:24 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27CC8C061753 for ; Wed, 2 Feb 2022 05:50:17 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id q63so20313449pja.1 for ; Wed, 02 Feb 2022 05:50:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TnJY4R7pNFq+r1c9Hai8pZCAxCplMW9W4uneml+9vI4=; b=oWAUpCfdpiugCygrTgIA9X8C/lV3LzbqgqOMRZO7X7MfSgx4XOx/FBGQjiEP1bNdkV P2XpD8hAcBq+sHWNb0+VbeAN7xU9Cuc9a+imNhgeUIjXLwNyKzYfeDgonqpaKz5oGpI2 UFpiuHKEjD3JbhenDiu1XBlBW/6fU2qYI2Fko= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TnJY4R7pNFq+r1c9Hai8pZCAxCplMW9W4uneml+9vI4=; b=n+oHHO97I3jRAIQU2v2Jo58498cVuYn3ZWHR0Rm19jXwQbmBEKQAFDbw+0U9AbfsEC 25Ao3Vdci8UGM9Ijfg7h6QCpmJ6OZkzErfa4GBwZ/e97mMCRB6NvShk41e+0L8uV021Z /a8KSsLhBpRy43Mb0hdegHYX/nf1F4kFFdxynQcP73NmnOgBNKqo1vyPwU2le9f/o3g4 tZpdjYkAwgf0ynTIpsnwfV8A2fW2ExBC82P0ACuJCPc6TFul2BDPXPEdaumf4QoYlFjI 10jZGitrYTtpPILPkru915T2wKEbZGcnW+4CkdC2yew8eLxRbwkFHqobNmBuseNZS/hc Eeyg== X-Gm-Message-State: AOAM5338pp24cOLtEMlYgRmAmwjXDT3rtXG+9GZuONJVMxunYGMC9lGS dV/R/VVjA0WcNiIahGZAjbKmSA== X-Google-Smtp-Source: ABdhPJzr0WbMa8H3fmltc1g6gtQpUKUFkIR/O0axG2tZ5a2Jx5HPYVY+Zgn++LYql9+AsJykPkGzBA== X-Received: by 2002:a17:90a:601:: with SMTP id j1mr8278507pjj.192.1643809816732; Wed, 02 Feb 2022 05:50:16 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:16 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 19/31] clk: mediatek: Add mtk_clk_simple_remove() Date: Wed, 2 Feb 2022 21:48:22 +0800 Message-Id: <20220202134834.690675-20-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org In commit c58cd0e40ffa ("clk: mediatek: Add mtk_clk_simple_probe() to simplify clock providers"), a generic probe function was added to simplify clk drivers that only needed to support clk gates. However due to the lack of unregister APIs, a corresponding remove function was not added. Now that the unregister APIs have been implemented, add aforementioned remove function to make it complete. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mtk.c | 15 +++++++++++++++ drivers/clk/mediatek/clk-mtk.h | 1 + 2 files changed, 16 insertions(+) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 869e6ae55c82..f108786caeda 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -374,6 +374,8 @@ int mtk_clk_simple_probe(struct platform_device *pdev) if (r) goto free_data; + platform_set_drvdata(pdev, clk_data); + return r; free_data: @@ -381,4 +383,17 @@ int mtk_clk_simple_probe(struct platform_device *pdev) return r; } +int mtk_clk_simple_remove(struct platform_device *pdev) +{ + const struct mtk_clk_desc *mcd = of_device_get_match_data(&pdev->dev); + struct clk_onecell_data *clk_data = platform_get_drvdata(pdev); + struct device_node *node = pdev->dev.of_node; + + of_clk_del_provider(node); + mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data); + mtk_free_clk_data(clk_data); + + return 0; +} + MODULE_LICENSE("GPL"); diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index 3c3a934f53cd..4fa658f5d934 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -202,5 +202,6 @@ struct mtk_clk_desc { }; int mtk_clk_simple_probe(struct platform_device *pdev); +int mtk_clk_simple_remove(struct platform_device *pdev); #endif /* __DRV_CLK_MTK_H */ From patchwork Wed Feb 2 13:48:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21DEFC433F5 for ; Wed, 2 Feb 2022 13:52:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229812AbiBBNwh (ORCPT ); Wed, 2 Feb 2022 08:52:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344630AbiBBNuY (ORCPT ); Wed, 2 Feb 2022 08:50:24 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2523EC061757 for ; Wed, 2 Feb 2022 05:50:19 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id d187so18836363pfa.10 for ; Wed, 02 Feb 2022 05:50:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r6U16I5h4NQIjHAoaMFFGHeoaBszozzi/qTuoY6Zxwc=; b=mW+92Gk+2VySYb/AfQ9MCdHff8aHAQmOwUwW4znhKb8lsVxKFTjYUvLHGRGAeAoufe ClXBe4+x/DLP2gWSqwN5azWWea5MVH52cj+FPbJB4BU6Wm9i2loDIkA2YT/eNy9PQi8L pFXuGZf780EuBWYfwCRlCbCHOJpKEtlPfVy+o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r6U16I5h4NQIjHAoaMFFGHeoaBszozzi/qTuoY6Zxwc=; b=p4mAQSSHcRtHxDRrMAmvZ7iWGlGap0ucXFu2UVOSjdQbEMWMnZCQ/ci9PGH6VhUy8Z 4wkmg3l6fSqRoDztLOIuFnpStnMyw7Sl/wCf+XUpCKmqQ1P8IOB2wi/kWLcYmGuqi9xd YyaID6bGPUGmGWfEFvaxNh1+/mTaGlupcV/sXRHPP1OrpegXTfrnBa5OVxSex/nu9Zgr 09Nr76xYDq/ahhm+cN8iS6tLk6ghZhCOnpwyybviFNETxeBLbYy7ZN0tFoix0bznS+zD 3JNwBFPBQZQmDswHNJXiVnIh53/FmcgWY74h1r6V94+pOWp72nXazi4c0pch9UFfq7Hh uUFg== X-Gm-Message-State: AOAM532zGTf6DYfYQQkb4tthcTtEENKwTOWwtvGRt2PUM8giT1ANnYsA 1AGkvXTvNB/qUpmWljxCB04WnQ== X-Google-Smtp-Source: ABdhPJxpwUACsdmtBArNe8Uc2yPifRus+Qkti7/z+fL5OuoV24IhqhLUkZIBSHII1LdUHWVjcaw8Qw== X-Received: by 2002:aa7:9f1b:: with SMTP id g27mr30524486pfr.30.1643809818708; Wed, 02 Feb 2022 05:50:18 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:18 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 20/31] clk: mediatek: mtk: Clean up included headers Date: Wed, 2 Feb 2022 21:48:23 +0800 Message-Id: <20220202134834.690675-21-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Some included headers aren't actually used anywhere, while other headers with the declaration of functions and structures aren't directly included. Get rid of the unused ones, and add the ones that should be included directly. On the header side, replace headers that are included purely for data structure definitions with forward declarations. This decreases the amount of preprocessing and compilation effort required for each inclusion. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mtk.c | 13 ++++++------- drivers/clk/mediatek/clk-mtk.h | 12 ++++++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index f108786caeda..5618c84e4e08 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -4,17 +4,16 @@ * Author: James Liao */ -#include -#include +#include +#include #include #include -#include -#include -#include -#include #include -#include +#include +#include #include +#include +#include #include "clk-mtk.h" #include "clk-gate.h" diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index 4fa658f5d934..7f902581a115 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -7,19 +7,19 @@ #ifndef __DRV_CLK_MTK_H #define __DRV_CLK_MTK_H -#include -#include #include -#include - -struct clk; -struct clk_onecell_data; +#include +#include +#include +#include #define MAX_MUX_GATE_BIT 31 #define INVALID_MUX_GATE_BIT (MAX_MUX_GATE_BIT + 1) #define MHZ (1000 * 1000) +struct platform_device; + struct mtk_fixed_clk { int id; const char *name; From patchwork Wed Feb 2 13:48:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B55FC433FE for ; Wed, 2 Feb 2022 13:50:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233666AbiBBNuo (ORCPT ); Wed, 2 Feb 2022 08:50:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244292AbiBBNu1 (ORCPT ); Wed, 2 Feb 2022 08:50:27 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C640C061759 for ; Wed, 2 Feb 2022 05:50:21 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id h14so18314221plf.1 for ; Wed, 02 Feb 2022 05:50:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cx6a8R97PjsjOv6cebI4Z/2hIOUwaDl4/YWSX9mOExw=; b=LECTsKvy7t8JOP59Uuw4WqU16hg3GYtSw3sCr0w8VJYVeRfS9yHbZOGJqoXab7B9u0 tlEfn86K0vk+YtlKRJTlsdK62A7mWfXsfsyGm/ptvH04zxs8M1w5q8zsW13X+Uy8a3VH PmrtpQZ9Us4qnZFpKDO84gckboYbX79QVwqJg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cx6a8R97PjsjOv6cebI4Z/2hIOUwaDl4/YWSX9mOExw=; b=2/rP85P+bosr20swdP3zM/4u20qM5Yn2njxbwTGg7XORDYD4HS06GRYAkVvuhP5RwI AUdIXTbHVjwaRLxlk7hP8keJjG3VMgJCOf60xVoZLrwZg5OcZvjhwZuEJb8jFPci7nfe UhusUVl5TpHd96AQVMJFrylhyA1zA/WmAa0TbZHjlu9UBaN3oteze949VZFVxD62n+sh C7DhqptE6PSWf6/1RrnUUJP8ZIm1sAKR6tohl2MTw0IldRwCraQeojQxTp9nxMOSvfC/ vVb3PcF75VvTFmW21z97/NfKph0g/MQcZFH60qA7uBhwpYHgTl9maUsfdfVTEiYkTve+ vYGA== X-Gm-Message-State: AOAM5339DgLch86sH9EMNjmQcDgXdbfRuH8wIPaToKcuUP/n/H7MRzAp BTbvCgFFUWqPYp6WZWrSg8ocne2XMhKSCw== X-Google-Smtp-Source: ABdhPJy+zXksxAcSN75EufsBADoPuhChK3JsWvZAjPXNL3ClKCXJ80y1WkJ/1oQJsghUAMYjzltDag== X-Received: by 2002:a17:902:6807:: with SMTP id h7mr31294827plk.22.1643809820674; Wed, 02 Feb 2022 05:50:20 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:20 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 21/31] clk: mediatek: cpumux: Implement error handling in register API Date: Wed, 2 Feb 2022 21:48:24 +0800 Message-Id: <20220202134834.690675-22-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The cpumux clk type registration function does not stop or return errors if any clk failed to be registered, nor does it implement an error handling path. This may result in a partially working device if any step failed. Make the register function return proper error codes, and bail out if errors occur. Proper cleanup, i.e. unregister any clks that were successfully registered, is done in the new error path. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-cpumux.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/clk/mediatek/clk-cpumux.c b/drivers/clk/mediatek/clk-cpumux.c index 658aee789f44..499c60432280 100644 --- a/drivers/clk/mediatek/clk-cpumux.c +++ b/drivers/clk/mediatek/clk-cpumux.c @@ -123,13 +123,26 @@ int mtk_clk_register_cpumuxes(struct device_node *node, clk = mtk_clk_register_cpumux(mux, regmap); if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", mux->name, clk); - continue; + goto err; } clk_data->clks[mux->id] = clk; } return 0; + +err: + while (--i >= 0) { + const struct mtk_composite *mux = &clks[i]; + + if (IS_ERR_OR_NULL(clk_data->clks[mux->id])) + continue; + + mtk_clk_unregister_cpumux(clk_data->clks[mux->id]); + clk_data->clks[mux->id] = ERR_PTR(-ENOENT); + } + + return PTR_ERR(clk); } void mtk_clk_unregister_cpumuxes(const struct mtk_composite *clks, int num, From patchwork Wed Feb 2 13:48:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732922 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0241C433EF for ; Wed, 2 Feb 2022 13:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343548AbiBBNur (ORCPT ); Wed, 2 Feb 2022 08:50:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344541AbiBBNu1 (ORCPT ); Wed, 2 Feb 2022 08:50:27 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11E5EC06175E for ; Wed, 2 Feb 2022 05:50:23 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id i65so18830888pfc.9 for ; Wed, 02 Feb 2022 05:50:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UVzLtEErhGtWV1STn1xNEVEnPyyTfBz7V3UiBlfriHg=; b=XQ+2EGR/cYRsPyHfBXXF9d1J9msyxxFm800JBKViuiIz+3BmpFAaHWZHT90R5nj5x+ RaqgfY9Y0tqPoUWPg2ezdtqs+0Lh9Ps6Fnt4cv1CWcOg3OPidhT3t5iYomsoxjX1Z05a 5RVDJ7Jhed3DlnGH/zsGsgqiHzv4xNt29Wx44= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UVzLtEErhGtWV1STn1xNEVEnPyyTfBz7V3UiBlfriHg=; b=HRYFzYQt6C0D/xMwz5mpIsJxCLnb0Xe3ooKYyHn1b58Fh699KX/yvx0QSa8SlTb4tS zk1eO6Sq9/saZFLwzW0S9+TVFAxzAfRSlfBlQMS5nAaJ6vytI5ltIxVzjdB5DbCz5eoS NK996Epw4dPCoLtZOZkrTGch9uH+qmJq+3BBhjyeB3d0N7P8vOHY/WGR2ownTXGG28xh CmjYs0X80RbH1+kbtcSP7vY2V/1+s6dsyj+QwTHvP7DqLK3Fi9knEh1koM2iTOdOoOQu IcVdtw6Xt43BTf63h9j2P8Hel54olQnIGGw4TsD8gfvDZoy/s6oYNdWYhK3u3sqSrPb/ qLdg== X-Gm-Message-State: AOAM5339/8eLtqLi3YL3HgVrrMQpczmSTw4wyqgNKXJlQE8MCfB/tbdv Mc9aFU36szkDLcsi4LYOKDryFw== X-Google-Smtp-Source: ABdhPJyE+pAn7gWEZTYj9bqNkprgRbIA8ZjA9M8QTJUnb3pEdI+FzNwtwWMFArF/buYt6wDUM7t07Q== X-Received: by 2002:a05:6a00:1652:: with SMTP id m18mr17396585pfc.56.1643809822645; Wed, 02 Feb 2022 05:50:22 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:22 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 22/31] clk: mediatek: gate: Implement error handling in register API Date: Wed, 2 Feb 2022 21:48:25 +0800 Message-Id: <20220202134834.690675-23-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The gate clk type registration function does not stop or return errors if any clk failed to be registered, nor does it implement an error handling path. This may result in a partially working device if any step failed. Make the register function return proper error codes, and bail out if errors occur. Proper cleanup, i.e. unregister any clks that were successfully registered, is done in the new error path. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-gate.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/clk/mediatek/clk-gate.c b/drivers/clk/mediatek/clk-gate.c index e8881ae1489a..631ff170b7b9 100644 --- a/drivers/clk/mediatek/clk-gate.c +++ b/drivers/clk/mediatek/clk-gate.c @@ -237,13 +237,26 @@ int mtk_clk_register_gates_with_dev(struct device_node *node, if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", gate->name, clk); - continue; + goto err; } clk_data->clks[gate->id] = clk; } return 0; + +err: + while (--i >= 0) { + const struct mtk_gate *gate = &clks[i]; + + if (IS_ERR_OR_NULL(clk_data->clks[gate->id])) + continue; + + mtk_clk_unregister_gate(clk_data->clks[gate->id]); + clk_data->clks[gate->id] = ERR_PTR(-ENOENT); + } + + return PTR_ERR(clk); } int mtk_clk_register_gates(struct device_node *node, From patchwork Wed Feb 2 13:48:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E1E1C433F5 for ; Wed, 2 Feb 2022 13:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344697AbiBBNuz (ORCPT ); Wed, 2 Feb 2022 08:50:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344746AbiBBNum (ORCPT ); Wed, 2 Feb 2022 08:50:42 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0688CC06173E for ; Wed, 2 Feb 2022 05:50:25 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id b15so18316301plg.3 for ; Wed, 02 Feb 2022 05:50:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QNRljrWOAeUndIQnSVvEuUfXq7FasZjB3yC6SLPOuYM=; b=U4vn34H0WZLQA8MoBFSj8XH+wsm8GLd/vRb1NzXQolOCQ6oqrB9XEHDXlwVR+0Yef6 wkYdmZeZSVKK9vVy6IiPGuwINl7+oHUyqqzA63Zn+h4F4mV51am7/giIRB415XQRleoF nPc0iVKyIb/sVzkHaTRkm8kkWuk4z/cWbCzx4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QNRljrWOAeUndIQnSVvEuUfXq7FasZjB3yC6SLPOuYM=; b=kEJY5dnH5DguljcJwzNPSplW2+iog7bDqrtXtUjmnOjratXLtZQ+oCXE4tzuNv/aJW /DVy5gDpdmh3aHMp/q/+PzEMGD+2/qb2dl/qJWcxokLdw8CKSoFPVTDbBcIGAvvz+MhY xz75edfVCZkVPG1tAJj3ZjC1sGkNSk5Ou9hznJFoQQF5ZhlUBJ/dR/f8vB8yNqAJWQR+ HT0Lp+pWa2AxtqIdRs6PKSAoQcf+Df1RlMwQlrKZnUzJfWNr7r0MP81CnIfmZE7plSzj rCKL85kfUg68KW5/T+Y4pMKkaTMh30VXpEuCMP9I86a+lNUXTlvVknQB1exaqHu9CM/N rWuA== X-Gm-Message-State: AOAM533y0DhTkG5gautkiud2rECla3gH5K2bXoQQLhpQwE56hGOgOG5x oYG087jPxJUUtMSVa0Q9r2gadQ== X-Google-Smtp-Source: ABdhPJxg9luWRJ9r/j2zVez342YUr/p2ncftDzjGtTu9Ak9s1/hRg0GpZyJdP3tIQGpruvbs2nlMjQ== X-Received: by 2002:a17:903:1110:: with SMTP id n16mr32138856plh.120.1643809824608; Wed, 02 Feb 2022 05:50:24 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:24 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 23/31] clk: mediatek: mux: Reverse check for existing clk to reduce nesting level Date: Wed, 2 Feb 2022 21:48:26 +0800 Message-Id: <20220202134834.690675-24-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The clk registration code here currently does: if (IS_ERR_OR_NULL(clk_data->clks[mux->id])) { ... do clk registration ... } This extra level of nesting wastes screen real estate. Reduce the nesting level by reversing the conditional shown above. Other than that, functionality is not changed. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mux.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c index 01af6a52711a..70aa42144632 100644 --- a/drivers/clk/mediatek/clk-mux.c +++ b/drivers/clk/mediatek/clk-mux.c @@ -208,16 +208,17 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes, for (i = 0; i < num; i++) { const struct mtk_mux *mux = &muxes[i]; - if (IS_ERR_OR_NULL(clk_data->clks[mux->id])) { - clk = mtk_clk_register_mux(mux, regmap, lock); + if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) + continue; - if (IS_ERR(clk)) { - pr_err("Failed to register clk %s: %pe\n", mux->name, clk); - continue; - } + clk = mtk_clk_register_mux(mux, regmap, lock); - clk_data->clks[mux->id] = clk; + if (IS_ERR(clk)) { + pr_err("Failed to register clk %s: %pe\n", mux->name, clk); + continue; } + + clk_data->clks[mux->id] = clk; } return 0; From patchwork Wed Feb 2 13:48:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94225C433FE for ; Wed, 2 Feb 2022 13:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344533AbiBBNu4 (ORCPT ); Wed, 2 Feb 2022 08:50:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344750AbiBBNum (ORCPT ); Wed, 2 Feb 2022 08:50:42 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 048A6C061763 for ; Wed, 2 Feb 2022 05:50:27 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id x11so18290366plg.6 for ; Wed, 02 Feb 2022 05:50:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TrOltClYvXVjDtDBwVIhzlzFVA2EZyTl5dU5D+b2Jm4=; b=LE43wTzJh/Wmm0fyvbCb8wCh+3oWVC8adNS/jdl5+42RJ8DxvGICSM+qdZwruOzsIr DyHrISocYIMJ6qskgAbWNERefJpsBiQa/dzh4PKqC0vzzTvQp/Z0Ub31MqFITrjPZhzH 6Xz4xkV2eseSkFUHg+BmD9me17wZXcLr27Fic= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TrOltClYvXVjDtDBwVIhzlzFVA2EZyTl5dU5D+b2Jm4=; b=TKEyHQlDkE0fardIhhx+3QmJOEZ6osJzE3719uhYcFw1OwISTfVjzNOJVCmtAHfMOp oFsx5V3pBvuLLLD8/iz6DkEuzCClBTZJ/l07X/5e+INAxiXBr+WGxpVKJ/O80M4WZD+/ CB6TxNKE5tdwB4HfiWaRPfPWjZOt1U1kd0m3+ksFMV3+bBl23liXxPEE9UoTjDkuqG7g RtXfhyWidMbMoT2CRqwx+x8329Oa7IZltYD66u6wRTknopPuWEYe4nI1Q7mfqSQakRWn hs8uRAxi3n7VfzFhavB7RguTueVIDtyAQPWBP3wEoDFJkWS54md9zQQreCFdztHkOG5p lbkA== X-Gm-Message-State: AOAM533G+k1utw3xnA0p2mfMTh/X+xkHNO2UokfpU0JDziIM3Iuz1N9k H5ZN1gdRPhWae2buqrFQwqxuow8Eeyi9ww== X-Google-Smtp-Source: ABdhPJxwytrlAarn/g53qU18olqhBZj5GI3l8fMGrFcFpltGq3c95Omxs6sHFPOWJMUCA6/RAdqcQA== X-Received: by 2002:a17:902:9a01:: with SMTP id v1mr13233814plp.56.1643809826597; Wed, 02 Feb 2022 05:50:26 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:26 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 24/31] clk: mediatek: mux: Implement error handling in register API Date: Wed, 2 Feb 2022 21:48:27 +0800 Message-Id: <20220202134834.690675-25-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The mux clk type registration function does not stop or return errors if any clk failed to be registered, nor does it implement an error handling path. This may result in a partially working device if any step failed. Make the register function return proper error codes, and bail out if errors occur. Proper cleanup, i.e. unregister any clks that were successfully registered, is done in the new error path. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mux.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c index 70aa42144632..f51e67650f03 100644 --- a/drivers/clk/mediatek/clk-mux.c +++ b/drivers/clk/mediatek/clk-mux.c @@ -215,13 +215,26 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes, if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", mux->name, clk); - continue; + goto err; } clk_data->clks[mux->id] = clk; } return 0; + +err: + while (--i >= 0) { + const struct mtk_mux *mux = &muxes[i]; + + if (IS_ERR_OR_NULL(clk_data->clks[mux->id])) + continue; + + mtk_clk_unregister_mux(clk_data->clks[mux->id]); + clk_data->clks[mux->id] = ERR_PTR(-ENOENT); + } + + return PTR_ERR(clk); } EXPORT_SYMBOL_GPL(mtk_clk_register_muxes); From patchwork Wed Feb 2 13:48:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6090CC433FE for ; Wed, 2 Feb 2022 13:50:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344704AbiBBNu4 (ORCPT ); Wed, 2 Feb 2022 08:50:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344756AbiBBNum (ORCPT ); Wed, 2 Feb 2022 08:50:42 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3003EC061765 for ; Wed, 2 Feb 2022 05:50:29 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id s6so12750662plg.12 for ; Wed, 02 Feb 2022 05:50:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/X1xbqtIcStarTs4c2+W6s0YHf8t7yF3UKC31OhAY/I=; b=aF+d4V20wz3PCFjPHAZuLztiRKZsart1Aj14opdzWw7+9yapzvxbwicJNonkhZRjO3 PKJ+VB7NjzujZClFOs2I16KAAF/iDFkmMkYoSgH5knW+pPKb/GTJIdTYbRJsQNRh9JTz CUlwLMNOUQ1rUEEcGWFjJLSUiz30l+rEAd/uI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/X1xbqtIcStarTs4c2+W6s0YHf8t7yF3UKC31OhAY/I=; b=0iwOIfRaJC3Wh3J2AVP3psxaSxZXSZN0w1N5flTNUA0Q5yBj1uYK3hyc2tl2Dv8asU 2tGbK9OjFbdKZq4Wi+Ks7ovQ9ktXLEY7w0M/Fp3yuQ/B/QK4/RJ7z7f9DFO+cvFYMlE3 OaVigpHGehwzhaF9MGa3yuKyc7v0xxaO1DBwrU7zAmB1Nn+CYIdA3Po+vrAlvuZmDiN3 rMctqv9ddafkHFNoYqouCy3Pu0G4mfVhWDRbe3Q78DzX4K+6wBRJ7G83q5zeDz0bcgM0 4oGvUmoWX8ggbIY3N+Tm4Y/goYwuy9kuv+x11VTBm3a8/4uewp/PM3BrSnRNuDNMYqee exww== X-Gm-Message-State: AOAM533TW6fZyEn7nbLPJc4AK4ygTUyHWfutrWAGbMM1Uc9u4HG6jX/p E3Z1dpY16Cp2BJcB0YUq1jjLzQ== X-Google-Smtp-Source: ABdhPJxlPoarr0PYhm4khqpH/LZy+sL3IANoFaQkok7/pMhWzxpEt8o+PM6/CSoMpKaNSmyBZ4leCw== X-Received: by 2002:a17:903:124e:: with SMTP id u14mr30286128plh.146.1643809828752; Wed, 02 Feb 2022 05:50:28 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:28 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 25/31] clk: mediatek: pll: Implement error handling in register API Date: Wed, 2 Feb 2022 21:48:28 +0800 Message-Id: <20220202134834.690675-26-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The pll clk type registration function does not stop or return errors if any clk failed to be registered, nor does it implement an error handling path. This may result in a partially working device if any step failed. Make the register function return proper error codes, and bail out if errors occur. Proper cleanup, i.e. unregister any clks that were successfully registered, and unmap the I/O space, is done in the new error path. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-pll.c | 23 +++++++++++++++++++---- drivers/clk/mediatek/clk-pll.h | 6 +++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c index 8439d37e354d..817a80293bfc 100644 --- a/drivers/clk/mediatek/clk-pll.c +++ b/drivers/clk/mediatek/clk-pll.c @@ -377,8 +377,9 @@ static void mtk_clk_unregister_pll(struct clk *clk) kfree(pll); } -void mtk_clk_register_plls(struct device_node *node, - const struct mtk_pll_data *plls, int num_plls, struct clk_onecell_data *clk_data) +int mtk_clk_register_plls(struct device_node *node, + const struct mtk_pll_data *plls, int num_plls, + struct clk_onecell_data *clk_data) { void __iomem *base; int i; @@ -387,7 +388,7 @@ void mtk_clk_register_plls(struct device_node *node, base = of_iomap(node, 0); if (!base) { pr_err("%s(): ioremap failed\n", __func__); - return; + return -EINVAL; } for (i = 0; i < num_plls; i++) { @@ -397,11 +398,25 @@ void mtk_clk_register_plls(struct device_node *node, if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", pll->name, clk); - continue; + goto err; } clk_data->clks[pll->id] = clk; } + + return 0; + +err: + while (--i >= 0) { + const struct mtk_pll_data *pll = &plls[i]; + + mtk_clk_unregister_pll(clk_data->clks[pll->id]); + clk_data->clks[pll->id] = ERR_PTR(-ENOENT); + } + + iounmap(base); + + return PTR_ERR(clk); } EXPORT_SYMBOL_GPL(mtk_clk_register_plls); diff --git a/drivers/clk/mediatek/clk-pll.h b/drivers/clk/mediatek/clk-pll.h index a889b1e472e7..bf06e44caef9 100644 --- a/drivers/clk/mediatek/clk-pll.h +++ b/drivers/clk/mediatek/clk-pll.h @@ -48,9 +48,9 @@ struct mtk_pll_data { u8 pll_en_bit; /* Assume 0, indicates BIT(0) by default */ }; -void mtk_clk_register_plls(struct device_node *node, - const struct mtk_pll_data *plls, int num_plls, - struct clk_onecell_data *clk_data); +int mtk_clk_register_plls(struct device_node *node, + const struct mtk_pll_data *plls, int num_plls, + struct clk_onecell_data *clk_data); void mtk_clk_unregister_plls(const struct mtk_pll_data *plls, int num_plls, struct clk_onecell_data *clk_data); From patchwork Wed Feb 2 13:48:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64D68C433F5 for ; Wed, 2 Feb 2022 13:51:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344783AbiBBNvP (ORCPT ); Wed, 2 Feb 2022 08:51:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241860AbiBBNun (ORCPT ); Wed, 2 Feb 2022 08:50:43 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B1A0C061770 for ; Wed, 2 Feb 2022 05:50:31 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id h125so1416131pgc.3 for ; Wed, 02 Feb 2022 05:50:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZD3EmaxNMmkNDH9YMuv4dVpEMyioyD7mDGdog5MJ0RA=; b=LqY4JjTmI9WDdS5TS71tyMO/unwp+4qkszVjBMiHoY4ZebrkaWbay5j7B4TG8ouktM ufqkwKEfU90FZx9yj9qFDk6O1k06yI2tj6aUuGoWWSyP7pUv9y9M3sWPzHvj783ZAskv MrOQCdsFU6bPL05z1dry3TqfCiQGeqvq1mgl4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZD3EmaxNMmkNDH9YMuv4dVpEMyioyD7mDGdog5MJ0RA=; b=g+eDL7tTVN+whMKMAAxKLKzsh77BdHqc9qh9OTt2xR14vB82U6T+1vdnDB8tW5BtAJ jocLm47Niu/qitvZfI/MVCt93l+PteJgw6990PP88nBtVFzH00BN55Gl0/PcmM2ElMGQ GJ4glHJvCg4aznu/9hsG20yqsltqCt2AdJ+eo5e7ToIwPLXAOE504ydY+xoW4nrfI440 uiEUdWhQu+wLvJuMk593nO4SBAgy/bUsTUDmnlAEBqXG1dRiKGbhx0DEUqOCs4ILHzwG p7pkmpci9UcIleqcrQasCcjTVFNTfupf1pwVTYMscXPJV/LOSZsY03i58VQQtJYvKJeN EYjg== X-Gm-Message-State: AOAM531wLQlJ5R4cjXAgGANPMB2XmkEWZsmvSozo0zP1883OKUpFdfjD o/zN88LilAq73LKYofaF21qqHA== X-Google-Smtp-Source: ABdhPJxOzg1kM+4ahDtql/F/DNBldvevB4UDc4TdRP6MTcyGTTvun6Q2NsxLdGwnJQaQTE7YwF/nxQ== X-Received: by 2002:a05:6a00:8c5:: with SMTP id s5mr29647596pfu.18.1643809830752; Wed, 02 Feb 2022 05:50:30 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:30 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 26/31] clk: mediatek: mtk: Implement error handling in register APIs Date: Wed, 2 Feb 2022 21:48:29 +0800 Message-Id: <20220202134834.690675-27-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The remaining clk registration functions do not stop or return errors if any clk failed to be registered, nor do they implement error handling paths. This may result in a partially working device if any step fails. Make the register functions return proper error codes, and bail out if errors occur. Proper cleanup, i.e. unregister any clks that were successfully registered, is done in the new error path. This also makes the |struct clk_data *| argument mandatory, as it is used to track the list of clks registered. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mtk.c | 118 ++++++++++++++++++++++++++------- drivers/clk/mediatek/clk-mtk.h | 20 +++--- 2 files changed, 103 insertions(+), 35 deletions(-) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 5618c84e4e08..8f15e9de742e 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -53,16 +53,19 @@ void mtk_free_clk_data(struct clk_onecell_data *clk_data) kfree(clk_data); } -void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, - int num, struct clk_onecell_data *clk_data) +int mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num, + struct clk_onecell_data *clk_data) { int i; struct clk *clk; + if (!clk_data) + return -ENOMEM; + for (i = 0; i < num; i++) { const struct mtk_fixed_clk *rc = &clks[i]; - if (clk_data && !IS_ERR_OR_NULL(clk_data->clks[rc->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[rc->id])) continue; clk = clk_register_fixed_rate(NULL, rc->name, rc->parent, 0, @@ -70,12 +73,26 @@ void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", rc->name, clk); - continue; + goto err; } - if (clk_data) - clk_data->clks[rc->id] = clk; + clk_data->clks[rc->id] = clk; } + + return 0; + +err: + while (--i >= 0) { + const struct mtk_fixed_clk *rc = &clks[i]; + + if (IS_ERR_OR_NULL(clk_data->clks[rc->id])) + continue; + + clk_unregister_fixed_rate(clk_data->clks[rc->id]); + clk_data->clks[rc->id] = ERR_PTR(-ENOENT); + } + + return PTR_ERR(clk); } EXPORT_SYMBOL_GPL(mtk_clk_register_fixed_clks); @@ -99,16 +116,19 @@ void mtk_clk_unregister_fixed_clks(const struct mtk_fixed_clk *clks, int num, } EXPORT_SYMBOL_GPL(mtk_clk_unregister_fixed_clks); -void mtk_clk_register_factors(const struct mtk_fixed_factor *clks, - int num, struct clk_onecell_data *clk_data) +int mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num, + struct clk_onecell_data *clk_data) { int i; struct clk *clk; + if (!clk_data) + return -ENOMEM; + for (i = 0; i < num; i++) { const struct mtk_fixed_factor *ff = &clks[i]; - if (clk_data && !IS_ERR_OR_NULL(clk_data->clks[ff->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[ff->id])) continue; clk = clk_register_fixed_factor(NULL, ff->name, ff->parent_name, @@ -116,12 +136,26 @@ void mtk_clk_register_factors(const struct mtk_fixed_factor *clks, if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", ff->name, clk); - continue; + goto err; } - if (clk_data) - clk_data->clks[ff->id] = clk; + clk_data->clks[ff->id] = clk; + } + + return 0; + +err: + while (--i >= 0) { + const struct mtk_fixed_factor *ff = &clks[i]; + + if (IS_ERR_OR_NULL(clk_data->clks[ff->id])) + continue; + + clk_unregister_fixed_factor(clk_data->clks[ff->id]); + clk_data->clks[ff->id] = ERR_PTR(-ENOENT); } + + return PTR_ERR(clk); } EXPORT_SYMBOL_GPL(mtk_clk_register_factors); @@ -258,13 +292,16 @@ static void mtk_clk_unregister_composite(struct clk *clk) kfree(mux); } -void mtk_clk_register_composites(const struct mtk_composite *mcs, - int num, void __iomem *base, spinlock_t *lock, - struct clk_onecell_data *clk_data) +int mtk_clk_register_composites(const struct mtk_composite *mcs, int num, + void __iomem *base, spinlock_t *lock, + struct clk_onecell_data *clk_data) { struct clk *clk; int i; + if (!clk_data) + return -ENOMEM; + for (i = 0; i < num; i++) { const struct mtk_composite *mc = &mcs[i]; @@ -275,12 +312,26 @@ void mtk_clk_register_composites(const struct mtk_composite *mcs, if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", mc->name, clk); - continue; + goto err; } - if (clk_data) - clk_data->clks[mc->id] = clk; + clk_data->clks[mc->id] = clk; + } + + return 0; + +err: + while (--i >= 0) { + const struct mtk_composite *mc = &mcs[i]; + + if (IS_ERR_OR_NULL(clk_data->clks[mcs->id])) + continue; + + mtk_clk_unregister_composite(clk_data->clks[mc->id]); + clk_data->clks[mc->id] = ERR_PTR(-ENOENT); } + + return PTR_ERR(clk); } EXPORT_SYMBOL_GPL(mtk_clk_register_composites); @@ -304,17 +355,20 @@ void mtk_clk_unregister_composites(const struct mtk_composite *mcs, int num, } EXPORT_SYMBOL_GPL(mtk_clk_unregister_composites); -void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, - int num, void __iomem *base, spinlock_t *lock, - struct clk_onecell_data *clk_data) +int mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num, + void __iomem *base, spinlock_t *lock, + struct clk_onecell_data *clk_data) { struct clk *clk; int i; + if (!clk_data) + return -ENOMEM; + for (i = 0; i < num; i++) { const struct mtk_clk_divider *mcd = &mcds[i]; - if (clk_data && !IS_ERR_OR_NULL(clk_data->clks[mcd->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id])) continue; clk = clk_register_divider(NULL, mcd->name, mcd->parent_name, @@ -323,12 +377,26 @@ void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", mcd->name, clk); - continue; + goto err; } - if (clk_data) - clk_data->clks[mcd->id] = clk; + clk_data->clks[mcd->id] = clk; + } + + return 0; + +err: + while (--i >= 0) { + const struct mtk_clk_divider *mcd = &mcds[i]; + + if (IS_ERR_OR_NULL(clk_data->clks[mcd->id])) + continue; + + mtk_clk_unregister_composite(clk_data->clks[mcd->id]); + clk_data->clks[mcd->id] = ERR_PTR(-ENOENT); } + + return PTR_ERR(clk); } void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num, diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index 7f902581a115..bf6565aa7319 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -34,8 +34,8 @@ struct mtk_fixed_clk { .rate = _rate, \ } -void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num, - struct clk_onecell_data *clk_data); +int mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num, + struct clk_onecell_data *clk_data); void mtk_clk_unregister_fixed_clks(const struct mtk_fixed_clk *clks, int num, struct clk_onecell_data *clk_data); @@ -55,8 +55,8 @@ struct mtk_fixed_factor { .div = _div, \ } -void mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num, - struct clk_onecell_data *clk_data); +int mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num, + struct clk_onecell_data *clk_data); void mtk_clk_unregister_factors(const struct mtk_fixed_factor *clks, int num, struct clk_onecell_data *clk_data); @@ -150,9 +150,9 @@ struct mtk_composite { struct clk *mtk_clk_register_composite(const struct mtk_composite *mc, void __iomem *base, spinlock_t *lock); -void mtk_clk_register_composites(const struct mtk_composite *mcs, - int num, void __iomem *base, spinlock_t *lock, - struct clk_onecell_data *clk_data); +int mtk_clk_register_composites(const struct mtk_composite *mcs, int num, + void __iomem *base, spinlock_t *lock, + struct clk_onecell_data *clk_data); void mtk_clk_unregister_composites(const struct mtk_composite *mcs, int num, struct clk_onecell_data *clk_data); @@ -178,9 +178,9 @@ struct mtk_clk_divider { .div_width = _width, \ } -void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num, - void __iomem *base, spinlock_t *lock, - struct clk_onecell_data *clk_data); +int mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num, + void __iomem *base, spinlock_t *lock, + struct clk_onecell_data *clk_data); void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num, struct clk_onecell_data *clk_data); From patchwork Wed Feb 2 13:48:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61DEFC4321E for ; Wed, 2 Feb 2022 13:50:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344718AbiBBNu5 (ORCPT ); Wed, 2 Feb 2022 08:50:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344562AbiBBNuq (ORCPT ); Wed, 2 Feb 2022 08:50:46 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21DB9C061775 for ; Wed, 2 Feb 2022 05:50:33 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id i65so18831300pfc.9 for ; Wed, 02 Feb 2022 05:50:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+daluWI6BZRIIo6jD7cHJViSYXk0pP6IWtsEBRin450=; b=Tpd1Y5ycji6S6pWD2XDf2SPMtoJdCSlWpqa5WQ0rz036vkv6p90/OEXloIQ1CsAkGL buh3iG4TyghoF0YDogBgAeLC2VzMf1iYDwfXL6Vf9G6tOqVf1CLVbGsBl/FZOAP822jB VuhIm7GlgM3Uqijk5XMVny+frQUbsvt0GJ/P0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+daluWI6BZRIIo6jD7cHJViSYXk0pP6IWtsEBRin450=; b=RMLAZpqFwqeFzFqI0btuYm/kTevldpbl5qmRDOvXgNLkNpvZdcMC6ej9PZV4n/eJxh I0Rc/R+TPJT3E4PGkLNtMYedo/Spkp6Puec7fbKrWWK0i8mZVdMT6hWb8Gl613BErgBg tK2j+1K9VrNKgiml5MewYjYiBUNast99bb9w9gkG6Kp+YuT3doPiBPlH2YlSu2Hl/fdy /mcywbXWlHHNW6kd2PDb1vc1JiKEE+6E4MGlYB6HngndImw78LTLKcU1rzScDdzmd4vC W6vAJIlSeOueC13/pCqWB0ghdLbsvf8K8xXf7Gm243bl+xrgoy+KEEHgpKtxROzPYDjY qzOg== X-Gm-Message-State: AOAM532We+0ltf8Q3xWf/o+iqzt75M9sKWfZgOxQKpMW2Q+nrgpWoz79 dNYQwQ/ULR//GcQwgBk3Dvql5A== X-Google-Smtp-Source: ABdhPJwgB9Kfv9ToZpcQLJRwpxFqkgMwlv0Lnc1Fod0ARERNSW52V7MEPKDRm9oXXveifEe8s/FX+A== X-Received: by 2002:aa7:9498:: with SMTP id z24mr29584316pfk.80.1643809832727; Wed, 02 Feb 2022 05:50:32 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:32 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 27/31] clk: mediatek: Unregister clks in mtk_clk_simple_probe() error path Date: Wed, 2 Feb 2022 21:48:30 +0800 Message-Id: <20220202134834.690675-28-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Until now the mediatek clk driver library did not have any way to unregister clks, and so all drivers did not do proper cleanup in their error paths. Now that the library does have APIs to unregister clks, use them in the error path of mtk_clk_simple_probe() to do proper cleanup. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-mtk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 8f15e9de742e..0e027be0d5fc 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -439,12 +439,14 @@ int mtk_clk_simple_probe(struct platform_device *pdev) r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); if (r) - goto free_data; + goto unregister_clks; platform_set_drvdata(pdev, clk_data); return r; +unregister_clks: + mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data); free_data: mtk_free_clk_data(clk_data); return r; From patchwork Wed Feb 2 13:48:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11120C4332F for ; Wed, 2 Feb 2022 13:50:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344714AbiBBNu4 (ORCPT ); Wed, 2 Feb 2022 08:50:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344575AbiBBNuq (ORCPT ); Wed, 2 Feb 2022 08:50:46 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28FEFC061778 for ; Wed, 2 Feb 2022 05:50:35 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id z131so18325338pgz.12 for ; Wed, 02 Feb 2022 05:50:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=werugQ/PNY3DJV7X3KvlbPf+KInlI+F1nzzIi8IaHE4=; b=KYkY3NyXGsUq6OIVPtRqpq3aJDlnMpaQUNiUFpUp01u+6+4Yc1yifF/EtbaGdUU/EZ 4jEv5ZgMAYQcaLnxJB0bvWCQkKF+4W1FbaJH6EeNJEW0bHkHAjMlxBJ+d5TYFL136A2u nzkbgFLBZCLeCWxrGK2OUkA/Ej5DUe7Bbtauk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=werugQ/PNY3DJV7X3KvlbPf+KInlI+F1nzzIi8IaHE4=; b=ZDm/x/kNottA0Ipy8Fy8TadjLFVMdsFr3Gtc7E0xDFaJBKcdyU3VbECL9eB7e5SrOg kou1IOXfDND5tbgC7IvGZWzOFyP0XFNcaXZ9FL5lJP2Zj1/9PsMyKRWqIoB4niCVguMd 42X4D9MpO2k5+Lqg8xYc6eK/5NxD8eshwBi8907sw61EkBC3bt2K2IgV1hjnzzoAjBN9 /gQ9HVxGZqIymbdmMoNZ4ZMOFJYkcw52ErVvlVqJRRaV+WtM8mqJAMjOVNy4qFcOB9J/ k87b0giZxxqueHTiNWhW2vQJJ+uTNCh1+aMELUmxgOA8se4uok8IIztFoHsZ4EfVjYMZ z9iQ== X-Gm-Message-State: AOAM530E7td0otH9hyNUwGC/6glmNMMzBj8GY4HIdVuO++FRE4DDGuBj WKhxuySqW/N7fA/ZIM8OqJiwlQ== X-Google-Smtp-Source: ABdhPJw49ttlFrKC1MjrGeTsHqkfQ7FGmibvO4l4NXQ5dLVTeAEc4UPt1ZaOdrUzMnvvsBWWMGkZow== X-Received: by 2002:a05:6a00:2490:: with SMTP id c16mr30157692pfv.36.1643809834717; Wed, 02 Feb 2022 05:50:34 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:34 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 28/31] clk: mediatek: mt8195: Hook up mtk_clk_simple_remove() Date: Wed, 2 Feb 2022 21:48:31 +0800 Message-Id: <20220202134834.690675-29-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Various small clock controllers only have clock gates, and utilize mtk_clk_simple_probe() as their driver probe function. Now that we have a matching remove function, hook it up for the relevant drivers. This was done with the following command: sed -i -e '/mtk_clk_simple_probe/a \ .remove = mtk_clk_simple_remove,' drivers/clk/mediatek/clk-mt8195-*.c Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen --- drivers/clk/mediatek/clk-mt8195-cam.c | 1 + drivers/clk/mediatek/clk-mt8195-ccu.c | 1 + drivers/clk/mediatek/clk-mt8195-img.c | 1 + drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c | 1 + drivers/clk/mediatek/clk-mt8195-infra_ao.c | 1 + drivers/clk/mediatek/clk-mt8195-ipe.c | 1 + drivers/clk/mediatek/clk-mt8195-mfg.c | 1 + drivers/clk/mediatek/clk-mt8195-peri_ao.c | 1 + drivers/clk/mediatek/clk-mt8195-scp_adsp.c | 1 + drivers/clk/mediatek/clk-mt8195-vdec.c | 1 + drivers/clk/mediatek/clk-mt8195-venc.c | 1 + drivers/clk/mediatek/clk-mt8195-vpp0.c | 1 + drivers/clk/mediatek/clk-mt8195-vpp1.c | 1 + drivers/clk/mediatek/clk-mt8195-wpe.c | 1 + 14 files changed, 14 insertions(+) diff --git a/drivers/clk/mediatek/clk-mt8195-cam.c b/drivers/clk/mediatek/clk-mt8195-cam.c index 3d261fc3848e..e4d00fe6e757 100644 --- a/drivers/clk/mediatek/clk-mt8195-cam.c +++ b/drivers/clk/mediatek/clk-mt8195-cam.c @@ -134,6 +134,7 @@ static const struct of_device_id of_match_clk_mt8195_cam[] = { static struct platform_driver clk_mt8195_cam_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-cam", .of_match_table = of_match_clk_mt8195_cam, diff --git a/drivers/clk/mediatek/clk-mt8195-ccu.c b/drivers/clk/mediatek/clk-mt8195-ccu.c index f846f1d73605..4e326b6301ba 100644 --- a/drivers/clk/mediatek/clk-mt8195-ccu.c +++ b/drivers/clk/mediatek/clk-mt8195-ccu.c @@ -42,6 +42,7 @@ static const struct of_device_id of_match_clk_mt8195_ccu[] = { static struct platform_driver clk_mt8195_ccu_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-ccu", .of_match_table = of_match_clk_mt8195_ccu, diff --git a/drivers/clk/mediatek/clk-mt8195-img.c b/drivers/clk/mediatek/clk-mt8195-img.c index 22b52a8f15fe..12f5c436d075 100644 --- a/drivers/clk/mediatek/clk-mt8195-img.c +++ b/drivers/clk/mediatek/clk-mt8195-img.c @@ -88,6 +88,7 @@ static const struct of_device_id of_match_clk_mt8195_img[] = { static struct platform_driver clk_mt8195_img_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-img", .of_match_table = of_match_clk_mt8195_img, diff --git a/drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c b/drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c index 4ab312eb26a5..fbc809d05072 100644 --- a/drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c +++ b/drivers/clk/mediatek/clk-mt8195-imp_iic_wrap.c @@ -58,6 +58,7 @@ static const struct of_device_id of_match_clk_mt8195_imp_iic_wrap[] = { static struct platform_driver clk_mt8195_imp_iic_wrap_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-imp_iic_wrap", .of_match_table = of_match_clk_mt8195_imp_iic_wrap, diff --git a/drivers/clk/mediatek/clk-mt8195-infra_ao.c b/drivers/clk/mediatek/clk-mt8195-infra_ao.c index 5f9b69967459..8ebe3b9415c4 100644 --- a/drivers/clk/mediatek/clk-mt8195-infra_ao.c +++ b/drivers/clk/mediatek/clk-mt8195-infra_ao.c @@ -198,6 +198,7 @@ static const struct of_device_id of_match_clk_mt8195_infra_ao[] = { static struct platform_driver clk_mt8195_infra_ao_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-infra_ao", .of_match_table = of_match_clk_mt8195_infra_ao, diff --git a/drivers/clk/mediatek/clk-mt8195-ipe.c b/drivers/clk/mediatek/clk-mt8195-ipe.c index fc1d42b6ac84..b0d745cf7752 100644 --- a/drivers/clk/mediatek/clk-mt8195-ipe.c +++ b/drivers/clk/mediatek/clk-mt8195-ipe.c @@ -43,6 +43,7 @@ static const struct of_device_id of_match_clk_mt8195_ipe[] = { static struct platform_driver clk_mt8195_ipe_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-ipe", .of_match_table = of_match_clk_mt8195_ipe, diff --git a/drivers/clk/mediatek/clk-mt8195-mfg.c b/drivers/clk/mediatek/clk-mt8195-mfg.c index aca6d9c0837c..9411c556a5a9 100644 --- a/drivers/clk/mediatek/clk-mt8195-mfg.c +++ b/drivers/clk/mediatek/clk-mt8195-mfg.c @@ -39,6 +39,7 @@ static const struct of_device_id of_match_clk_mt8195_mfg[] = { static struct platform_driver clk_mt8195_mfg_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-mfg", .of_match_table = of_match_clk_mt8195_mfg, diff --git a/drivers/clk/mediatek/clk-mt8195-peri_ao.c b/drivers/clk/mediatek/clk-mt8195-peri_ao.c index 907a92b22de8..2f6b3bb657db 100644 --- a/drivers/clk/mediatek/clk-mt8195-peri_ao.c +++ b/drivers/clk/mediatek/clk-mt8195-peri_ao.c @@ -54,6 +54,7 @@ static const struct of_device_id of_match_clk_mt8195_peri_ao[] = { static struct platform_driver clk_mt8195_peri_ao_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-peri_ao", .of_match_table = of_match_clk_mt8195_peri_ao, diff --git a/drivers/clk/mediatek/clk-mt8195-scp_adsp.c b/drivers/clk/mediatek/clk-mt8195-scp_adsp.c index 26b4846c5894..e16c383f631b 100644 --- a/drivers/clk/mediatek/clk-mt8195-scp_adsp.c +++ b/drivers/clk/mediatek/clk-mt8195-scp_adsp.c @@ -39,6 +39,7 @@ static const struct of_device_id of_match_clk_mt8195_scp_adsp[] = { static struct platform_driver clk_mt8195_scp_adsp_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-scp_adsp", .of_match_table = of_match_clk_mt8195_scp_adsp, diff --git a/drivers/clk/mediatek/clk-mt8195-vdec.c b/drivers/clk/mediatek/clk-mt8195-vdec.c index a1df04f42a90..a1446b666385 100644 --- a/drivers/clk/mediatek/clk-mt8195-vdec.c +++ b/drivers/clk/mediatek/clk-mt8195-vdec.c @@ -96,6 +96,7 @@ static const struct of_device_id of_match_clk_mt8195_vdec[] = { static struct platform_driver clk_mt8195_vdec_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-vdec", .of_match_table = of_match_clk_mt8195_vdec, diff --git a/drivers/clk/mediatek/clk-mt8195-venc.c b/drivers/clk/mediatek/clk-mt8195-venc.c index 7339851a0856..622f57804f96 100644 --- a/drivers/clk/mediatek/clk-mt8195-venc.c +++ b/drivers/clk/mediatek/clk-mt8195-venc.c @@ -61,6 +61,7 @@ static const struct of_device_id of_match_clk_mt8195_venc[] = { static struct platform_driver clk_mt8195_venc_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-venc", .of_match_table = of_match_clk_mt8195_venc, diff --git a/drivers/clk/mediatek/clk-mt8195-vpp0.c b/drivers/clk/mediatek/clk-mt8195-vpp0.c index c3241466a8d0..bf2939c3a023 100644 --- a/drivers/clk/mediatek/clk-mt8195-vpp0.c +++ b/drivers/clk/mediatek/clk-mt8195-vpp0.c @@ -102,6 +102,7 @@ static const struct of_device_id of_match_clk_mt8195_vpp0[] = { static struct platform_driver clk_mt8195_vpp0_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-vpp0", .of_match_table = of_match_clk_mt8195_vpp0, diff --git a/drivers/clk/mediatek/clk-mt8195-vpp1.c b/drivers/clk/mediatek/clk-mt8195-vpp1.c index ce0b9a40a179..ffd52c762890 100644 --- a/drivers/clk/mediatek/clk-mt8195-vpp1.c +++ b/drivers/clk/mediatek/clk-mt8195-vpp1.c @@ -100,6 +100,7 @@ static const struct of_device_id of_match_clk_mt8195_vpp1[] = { static struct platform_driver clk_mt8195_vpp1_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-vpp1", .of_match_table = of_match_clk_mt8195_vpp1, diff --git a/drivers/clk/mediatek/clk-mt8195-wpe.c b/drivers/clk/mediatek/clk-mt8195-wpe.c index 274d60838d8e..b483fab10e18 100644 --- a/drivers/clk/mediatek/clk-mt8195-wpe.c +++ b/drivers/clk/mediatek/clk-mt8195-wpe.c @@ -135,6 +135,7 @@ static const struct of_device_id of_match_clk_mt8195_wpe[] = { static struct platform_driver clk_mt8195_wpe_drv = { .probe = mtk_clk_simple_probe, + .remove = mtk_clk_simple_remove, .driver = { .name = "clk-mt8195-wpe", .of_match_table = of_match_clk_mt8195_wpe, From patchwork Wed Feb 2 13:48:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 212CEC433FE for ; Wed, 2 Feb 2022 13:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344597AbiBBNvN (ORCPT ); Wed, 2 Feb 2022 08:51:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344600AbiBBNuq (ORCPT ); Wed, 2 Feb 2022 08:50:46 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D66EC06177B for ; Wed, 2 Feb 2022 05:50:37 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id v74so18863403pfc.1 for ; Wed, 02 Feb 2022 05:50:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TkaavcwwSXTQYMjq565kI3sdhI7vHLgYjSyu32Ij/SU=; b=K6e5WAOoxDzAZqzS5QW9srT4xlvXXSy1liamjvDMGpDzU5SsClz/NgwM/EbE5xEeWe cHo25PYHAH3uYLhHf+0Eqy0/RF2yYUdBl3xNrzGf4ENi0QYlf2NVHUq+lAuQy0lEe93p bJY3ZPK2e+7dvKjyq91nH52155kRLQI0DKANI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TkaavcwwSXTQYMjq565kI3sdhI7vHLgYjSyu32Ij/SU=; b=G8znM6slHBpIo32U9LIvubo9vn4z1AzEgoLHICLNc89rFfprB56fmNIgwixMU7eFxN qGpCpYLseUfhhBlOAn6G8d70WKl8NA+0T/ZLhn02g57gRwVqaQI+2dgZBGlogMrr6uYv UGnKSrOvbi9Icg2kzqJ/a5pBD2hwd+pFaR5PqiAk/pgWZFI/LjRPQVRjKT8OnOkExCx5 5CMxn0BDBg0RNTEbcUzqiCP1ohqXv67PNrKbXcDXrHoB53MrsbYP411x3jGBupotVO3q yI5V7cVupiWnr68RYkzNmEIC65Y29fNNeJ13C2Vka6h7V+gqH/O+J+V3crNNxfU5UqOA JCYg== X-Gm-Message-State: AOAM531YE+tkCtV2p0uWPmDsGa3qbFAnE6qaBJTwmhGvXHD9f/GaaAhH MXUiCFvjvunt63INoy+Jupranw== X-Google-Smtp-Source: ABdhPJwGbOa1EL0uMe/CmGhPSvMaCjBAcmSaT/Chf4TJ5lvBozpl+Bpyy18AGf2k7ZUaZr60LVmGEg== X-Received: by 2002:a05:6a00:158e:: with SMTP id u14mr21751032pfk.38.1643809836688; Wed, 02 Feb 2022 05:50:36 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:36 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 29/31] clk: mediatek: mt8195: Implement error handling in probe functions Date: Wed, 2 Feb 2022 21:48:32 +0800 Message-Id: <20220202134834.690675-30-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Until now the mediatek clk driver library did not have any way to unregister clks, and so all drivers did not do proper cleanup in their error paths. Now that the library does have APIs to unregister clks, use them in the error path of the probe functions for the mt8195 clk drivers to do proper cleanup. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen --- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 13 ++++-- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 11 ++++- drivers/clk/mediatek/clk-mt8195-topckgen.c | 49 +++++++++++++++----- drivers/clk/mediatek/clk-mt8195-vdo0.c | 4 +- drivers/clk/mediatek/clk-mt8195-vdo1.c | 4 +- 5 files changed, 63 insertions(+), 18 deletions(-) diff --git a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c index 5b1b7dc447eb..af8d80f25f30 100644 --- a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c +++ b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c @@ -120,17 +120,24 @@ static int clk_mt8195_apmixed_probe(struct platform_device *pdev) if (!clk_data) return -ENOMEM; - mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data); - r = mtk_clk_register_gates(node, apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data); + r = mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data); if (r) goto free_apmixed_data; + r = mtk_clk_register_gates(node, apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data); + if (r) + goto unregister_plls; + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); if (r) - goto free_apmixed_data; + goto unregister_gates; return r; +unregister_gates: + mtk_clk_register_gates(node, apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data); +unregister_plls: + mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data); free_apmixed_data: mtk_free_clk_data(clk_data); return r; diff --git a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c index db449ff877d7..1fff6f3d2dc7 100644 --- a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c +++ b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c @@ -66,13 +66,20 @@ static int clk_mt8195_apusys_pll_probe(struct platform_device *pdev) if (!clk_data) return -ENOMEM; - mtk_clk_register_plls(node, apusys_plls, ARRAY_SIZE(apusys_plls), clk_data); - r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); + r = mtk_clk_register_plls(node, apusys_plls, ARRAY_SIZE(apusys_plls), clk_data); if (r) goto free_apusys_pll_data; + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); + if (r) + goto unregister_plls; + + platform_set_drvdata(pdev, clk_data); + return r; +unregister_plls: + mtk_clk_unregister_plls(apusys_plls, ARRAY_SIZE(apusys_plls), clk_data); free_apusys_pll_data: mtk_free_clk_data(clk_data); return r; diff --git a/drivers/clk/mediatek/clk-mt8195-topckgen.c b/drivers/clk/mediatek/clk-mt8195-topckgen.c index 3e2aba9c40bb..3631f49a5e5a 100644 --- a/drivers/clk/mediatek/clk-mt8195-topckgen.c +++ b/drivers/clk/mediatek/clk-mt8195-topckgen.c @@ -1239,25 +1239,52 @@ static int clk_mt8195_topck_probe(struct platform_device *pdev) goto free_top_data; } - mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks), - top_clk_data); - mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data); - mtk_clk_register_muxes(top_mtk_muxes, ARRAY_SIZE(top_mtk_muxes), node, - &mt8195_clk_lock, top_clk_data); - mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base, - &mt8195_clk_lock, top_clk_data); - mtk_clk_register_composites(top_adj_divs, ARRAY_SIZE(top_adj_divs), base, - &mt8195_clk_lock, top_clk_data); - r = mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks), top_clk_data); + r = mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks), + top_clk_data); if (r) goto free_top_data; + r = mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data); + if (r) + goto unregister_fixed_clks; + + r = mtk_clk_register_muxes(top_mtk_muxes, ARRAY_SIZE(top_mtk_muxes), node, + &mt8195_clk_lock, top_clk_data); + if (r) + goto unregister_factors; + + r = mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base, + &mt8195_clk_lock, top_clk_data); + if (r) + goto unregister_muxes; + + r = mtk_clk_register_composites(top_adj_divs, ARRAY_SIZE(top_adj_divs), base, + &mt8195_clk_lock, top_clk_data); + if (r) + goto unregister_composite_muxes; + + r = mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks), top_clk_data); + if (r) + goto unregister_composite_divs; + r = of_clk_add_provider(node, of_clk_src_onecell_get, top_clk_data); if (r) - goto free_top_data; + goto unregister_gates; return r; +unregister_gates: + mtk_clk_unregister_gates(top_clks, ARRAY_SIZE(top_clks), top_clk_data); +unregister_composite_divs: + mtk_clk_unregister_composites(top_adj_divs, ARRAY_SIZE(top_adj_divs), top_clk_data); +unregister_composite_muxes: + mtk_clk_unregister_composites(top_muxes, ARRAY_SIZE(top_muxes), top_clk_data); +unregister_muxes: + mtk_clk_unregister_muxes(top_mtk_muxes, ARRAY_SIZE(top_mtk_muxes), top_clk_data); +unregister_factors: + mtk_clk_unregister_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data); +unregister_fixed_clks: + mtk_clk_unregister_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks), top_clk_data); free_top_data: mtk_free_clk_data(top_clk_data); return r; diff --git a/drivers/clk/mediatek/clk-mt8195-vdo0.c b/drivers/clk/mediatek/clk-mt8195-vdo0.c index f7ff7618c714..af34eb564b1d 100644 --- a/drivers/clk/mediatek/clk-mt8195-vdo0.c +++ b/drivers/clk/mediatek/clk-mt8195-vdo0.c @@ -105,10 +105,12 @@ static int clk_mt8195_vdo0_probe(struct platform_device *pdev) r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); if (r) - goto free_vdo0_data; + goto unregister_gates; return r; +unregister_gates: + mtk_clk_unregister_gates(vdo0_clks, ARRAY_SIZE(vdo0_clks), clk_data); free_vdo0_data: mtk_free_clk_data(clk_data); return r; diff --git a/drivers/clk/mediatek/clk-mt8195-vdo1.c b/drivers/clk/mediatek/clk-mt8195-vdo1.c index 03df8eae8838..6b502bbc730c 100644 --- a/drivers/clk/mediatek/clk-mt8195-vdo1.c +++ b/drivers/clk/mediatek/clk-mt8195-vdo1.c @@ -122,10 +122,12 @@ static int clk_mt8195_vdo1_probe(struct platform_device *pdev) r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); if (r) - goto free_vdo1_data; + goto unregister_gates; return r; +unregister_gates: + mtk_clk_unregister_gates(vdo1_clks, ARRAY_SIZE(vdo1_clks), clk_data); free_vdo1_data: mtk_free_clk_data(clk_data); return r; From patchwork Wed Feb 2 13:48:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B173C433F5 for ; Wed, 2 Feb 2022 13:51:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240561AbiBBNvD (ORCPT ); Wed, 2 Feb 2022 08:51:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344679AbiBBNuy (ORCPT ); Wed, 2 Feb 2022 08:50:54 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25688C06177F for ; Wed, 2 Feb 2022 05:50:39 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id d186so1023922pgc.9 for ; Wed, 02 Feb 2022 05:50:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ijN/BZfheyHW/Ftdh2OzE64JyIBXkLbGIov7Fg65t6I=; b=cpXbUfJhQei5E5o6agVsB48RWnK8Gjl5mHtXN6W0xdVogGo4zUtm1cjc6lDp4Y8N2F D9c0Fa5p7wFl6/Sq6QamXEN43Clw5tRLmpyzFsUjXFPuj0CH9Qvj8XpJkcLt8+5o4SuZ VFCc+C+arBcsn9ruW8gtCKU6rYHJXtlkElpLE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ijN/BZfheyHW/Ftdh2OzE64JyIBXkLbGIov7Fg65t6I=; b=I4PYbvwFScQ4yPxGJhKSxgdwnhBvoqSu6FzoIN2n434xQNQgIronShua/1tguYrgqN GuTfpwHv93RAaJgGqK/JgNmPWs1lj8OgVrPNEyxnoNVZ5qymh5KRthGQDTbx2P2txtVT HHdi2ruN4hTRJCmXlpkpsMrr8e/9k5ruF/dAIPNFymb2qEUTDLZtr5lyKOa5fv+ppmhk Qq5JnuXOoVA66itmMlp/f844I7ETcKrsxPo9s4p/z6+/r9M2l6ypXsnvlYpd3jiA/tZE 8X2YJx4hvYw2ygCKHRkj3lYfLoEI/LCQtSjopXB2NEvlEcyTpcTtezvi04ty1NFtLwgq uMfA== X-Gm-Message-State: AOAM533TWbi0i72X7wOsfJ+QMb5jggxRP+U9Kv/A7/uk09JquV799rz4 lU+GJJKVzTj1b5sC9wYqu7TUWam5Ngl4DQ== X-Google-Smtp-Source: ABdhPJxZqK+D6Acx9WwhmplzUWeUHcMgIvnvta9wUiIEi+QRtZPy09eepK41+WE9UKByjkZmyMZj8A== X-Received: by 2002:a05:6a00:841:: with SMTP id q1mr8269709pfk.21.1643809838673; Wed, 02 Feb 2022 05:50:38 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:38 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 30/31] clk: mediatek: mt8195: Implement remove functions Date: Wed, 2 Feb 2022 21:48:33 +0800 Message-Id: <20220202134834.690675-31-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Until now the mediatek clk driver library did not have any way to unregister clks, and so none of the drivers implemented remove functions. Now that the library does have APIs to unregister clks, use them to implement remove functions for the mt8195 clk drivers. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen --- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 16 ++++++++++++++++ drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt8195-topckgen.c | 20 ++++++++++++++++++++ drivers/clk/mediatek/clk-mt8195-vdo0.c | 16 ++++++++++++++++ drivers/clk/mediatek/clk-mt8195-vdo1.c | 16 ++++++++++++++++ 5 files changed, 81 insertions(+) diff --git a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c index af8d80f25f30..29cac3cf5f53 100644 --- a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c +++ b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c @@ -132,6 +132,8 @@ static int clk_mt8195_apmixed_probe(struct platform_device *pdev) if (r) goto unregister_gates; + platform_set_drvdata(pdev, clk_data); + return r; unregister_gates: @@ -143,8 +145,22 @@ static int clk_mt8195_apmixed_probe(struct platform_device *pdev) return r; } +static int clk_mt8195_apmixed_remove(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + struct clk_onecell_data *clk_data = platform_get_drvdata(pdev); + + of_clk_del_provider(node); + mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data); + mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data); + mtk_free_clk_data(clk_data); + + return 0; +} + static struct platform_driver clk_mt8195_apmixed_drv = { .probe = clk_mt8195_apmixed_probe, + .remove = clk_mt8195_apmixed_remove, .driver = { .name = "clk-mt8195-apmixed", .of_match_table = of_match_clk_mt8195_apmixed, diff --git a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c index 1fff6f3d2dc7..8cd88dfc3283 100644 --- a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c +++ b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c @@ -85,6 +85,18 @@ static int clk_mt8195_apusys_pll_probe(struct platform_device *pdev) return r; } +static int clk_mt8195_apusys_pll_remove(struct platform_device *pdev) +{ + struct clk_onecell_data *clk_data = platform_get_drvdata(pdev); + struct device_node *node = pdev->dev.of_node; + + of_clk_del_provider(node); + mtk_clk_unregister_plls(apusys_plls, ARRAY_SIZE(apusys_plls), clk_data); + mtk_free_clk_data(clk_data); + + return 0; +} + static const struct of_device_id of_match_clk_mt8195_apusys_pll[] = { { .compatible = "mediatek,mt8195-apusys_pll", }, {} @@ -92,6 +104,7 @@ static const struct of_device_id of_match_clk_mt8195_apusys_pll[] = { static struct platform_driver clk_mt8195_apusys_pll_drv = { .probe = clk_mt8195_apusys_pll_probe, + .remove = clk_mt8195_apusys_pll_remove, .driver = { .name = "clk-mt8195-apusys_pll", .of_match_table = of_match_clk_mt8195_apusys_pll, diff --git a/drivers/clk/mediatek/clk-mt8195-topckgen.c b/drivers/clk/mediatek/clk-mt8195-topckgen.c index 3631f49a5e5a..b602fcd7f1d1 100644 --- a/drivers/clk/mediatek/clk-mt8195-topckgen.c +++ b/drivers/clk/mediatek/clk-mt8195-topckgen.c @@ -1271,6 +1271,8 @@ static int clk_mt8195_topck_probe(struct platform_device *pdev) if (r) goto unregister_gates; + platform_set_drvdata(pdev, top_clk_data); + return r; unregister_gates: @@ -1290,8 +1292,26 @@ static int clk_mt8195_topck_probe(struct platform_device *pdev) return r; } +static int clk_mt8195_topck_remove(struct platform_device *pdev) +{ + struct clk_onecell_data *top_clk_data = platform_get_drvdata(pdev); + struct device_node *node = pdev->dev.of_node; + + of_clk_del_provider(node); + mtk_clk_unregister_gates(top_clks, ARRAY_SIZE(top_clks), top_clk_data); + mtk_clk_unregister_composites(top_adj_divs, ARRAY_SIZE(top_adj_divs), top_clk_data); + mtk_clk_unregister_composites(top_muxes, ARRAY_SIZE(top_muxes), top_clk_data); + mtk_clk_unregister_muxes(top_mtk_muxes, ARRAY_SIZE(top_mtk_muxes), top_clk_data); + mtk_clk_unregister_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data); + mtk_clk_unregister_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks), top_clk_data); + mtk_free_clk_data(top_clk_data); + + return 0; +} + static struct platform_driver clk_mt8195_topck_drv = { .probe = clk_mt8195_topck_probe, + .remove = clk_mt8195_topck_remove, .driver = { .name = "clk-mt8195-topck", .of_match_table = of_match_clk_mt8195_topck, diff --git a/drivers/clk/mediatek/clk-mt8195-vdo0.c b/drivers/clk/mediatek/clk-mt8195-vdo0.c index af34eb564b1d..3bc7ed19d550 100644 --- a/drivers/clk/mediatek/clk-mt8195-vdo0.c +++ b/drivers/clk/mediatek/clk-mt8195-vdo0.c @@ -107,6 +107,8 @@ static int clk_mt8195_vdo0_probe(struct platform_device *pdev) if (r) goto unregister_gates; + platform_set_drvdata(pdev, clk_data); + return r; unregister_gates: @@ -116,8 +118,22 @@ static int clk_mt8195_vdo0_probe(struct platform_device *pdev) return r; } +static int clk_mt8195_vdo0_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *node = dev->parent->of_node; + struct clk_onecell_data *clk_data = platform_get_drvdata(pdev); + + of_clk_del_provider(node); + mtk_clk_unregister_gates(vdo0_clks, ARRAY_SIZE(vdo0_clks), clk_data); + mtk_free_clk_data(clk_data); + + return 0; +} + static struct platform_driver clk_mt8195_vdo0_drv = { .probe = clk_mt8195_vdo0_probe, + .remove = clk_mt8195_vdo0_remove, .driver = { .name = "clk-mt8195-vdo0", }, diff --git a/drivers/clk/mediatek/clk-mt8195-vdo1.c b/drivers/clk/mediatek/clk-mt8195-vdo1.c index 6b502bbc730c..90c738a85ff1 100644 --- a/drivers/clk/mediatek/clk-mt8195-vdo1.c +++ b/drivers/clk/mediatek/clk-mt8195-vdo1.c @@ -124,6 +124,8 @@ static int clk_mt8195_vdo1_probe(struct platform_device *pdev) if (r) goto unregister_gates; + platform_set_drvdata(pdev, clk_data); + return r; unregister_gates: @@ -133,8 +135,22 @@ static int clk_mt8195_vdo1_probe(struct platform_device *pdev) return r; } +static int clk_mt8195_vdo1_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *node = dev->parent->of_node; + struct clk_onecell_data *clk_data = platform_get_drvdata(pdev); + + of_clk_del_provider(node); + mtk_clk_unregister_gates(vdo1_clks, ARRAY_SIZE(vdo1_clks), clk_data); + mtk_free_clk_data(clk_data); + + return 0; +} + static struct platform_driver clk_mt8195_vdo1_drv = { .probe = clk_mt8195_vdo1_probe, + .remove = clk_mt8195_vdo1_remove, .driver = { .name = "clk-mt8195-vdo1", }, From patchwork Wed Feb 2 13:48:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732928 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46E33C4332F for ; Wed, 2 Feb 2022 13:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344686AbiBBNvD (ORCPT ); Wed, 2 Feb 2022 08:51:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344684AbiBBNuy (ORCPT ); Wed, 2 Feb 2022 08:50:54 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16322C0613E5 for ; Wed, 2 Feb 2022 05:50:41 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id b15so18316943plg.3 for ; Wed, 02 Feb 2022 05:50:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DcodRynrZT4K1y4jFzGbVCT5AiqDNSLFELqoGf2FUNM=; b=iIh9m3/8GG896qPnlmsQHULgkIHYDJcdsWz+nMJrvSJew/rLC3HQRQflstPh10xlAg dhP4UV0Zb63srMjtRR2v/nFrif8CIVfmRsy0a6+ObfGGx/gdIM+PYAAKglJ050u9A+Lu Sbu6o6Ob59qEGUExWBcJRttXXVb/TNfPjbQPw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DcodRynrZT4K1y4jFzGbVCT5AiqDNSLFELqoGf2FUNM=; b=ZlmHmy60Nza9Lfb2Uikd8InfkVq16DyWm3j4ecl2ggB+xijq5kJ34laz2ggoEhKr10 LfKd0VC3lcOE/Z3q1LJ+O9XS3eqssbSvw5GUa+YCiNrhrVpgP8D+FGe0waxh2xmO0NmW 3oNbJeQe9IMES9QSKM3oPCxsKeT0JyXHP8sJrx/j8D9Def9+jvygvKxs5XbUdoRSdm9F Q8afq77lKRJcO70g2FVEJprM/NDvoNJQra7mJv6BVrJylKYJgdfzEpLPeR1K0VBg/uaL ErwAwltiWYeg6CMimXF1CIsjhrKa9bxQlsUZe9eacrDx+3VpejaCJj1YugjShpWOWxPX eGHA== X-Gm-Message-State: AOAM532CEdxHjSkfpps/bpU9JMd6c4QUimU+sk9ps/naFiw8jqzCVxoC 1ceH4+b5/bonhvRZzWsBX4kLQg== X-Google-Smtp-Source: ABdhPJxUF7/m48cLrDNij/awsAkaEf+fHj9Xq5ZY2PYGHzKoDTTstU5XgjxnLPMvsSdd4WIDdcInHw== X-Received: by 2002:a17:90b:f10:: with SMTP id br16mr8206870pjb.57.1643809840655; Wed, 02 Feb 2022 05:50:40 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:40 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 31/31] clk: mediatek: Warn if clk IDs are duplicated Date: Wed, 2 Feb 2022 21:48:34 +0800 Message-Id: <20220202134834.690675-32-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The Mediatek clk driver library handles duplicate clock IDs in two different ways: either ignoring the duplicate entry, or overwriting the old clk. Either way may cause unexpected behavior, and the latter also causes an orphan clk that cannot be cleaned up. Align the behavior so that later duplicate entries are ignored, and a warning printed. The warning will also aid in making the issue noticeable. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-cpumux.c | 6 ++++++ drivers/clk/mediatek/clk-gate.c | 5 ++++- drivers/clk/mediatek/clk-mtk.c | 18 ++++++++++++++---- drivers/clk/mediatek/clk-mux.c | 5 ++++- drivers/clk/mediatek/clk-pll.c | 6 ++++++ 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/drivers/clk/mediatek/clk-cpumux.c b/drivers/clk/mediatek/clk-cpumux.c index 499c60432280..c11b3fae622e 100644 --- a/drivers/clk/mediatek/clk-cpumux.c +++ b/drivers/clk/mediatek/clk-cpumux.c @@ -120,6 +120,12 @@ int mtk_clk_register_cpumuxes(struct device_node *node, for (i = 0; i < num; i++) { const struct mtk_composite *mux = &clks[i]; + if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) { + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", + node, mux->id); + continue; + } + clk = mtk_clk_register_cpumux(mux, regmap); if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", mux->name, clk); diff --git a/drivers/clk/mediatek/clk-gate.c b/drivers/clk/mediatek/clk-gate.c index 631ff170b7b9..da52023f8455 100644 --- a/drivers/clk/mediatek/clk-gate.c +++ b/drivers/clk/mediatek/clk-gate.c @@ -224,8 +224,11 @@ int mtk_clk_register_gates_with_dev(struct device_node *node, for (i = 0; i < num; i++) { const struct mtk_gate *gate = &clks[i]; - if (!IS_ERR_OR_NULL(clk_data->clks[gate->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[gate->id])) { + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", + node, gate->id); continue; + } clk = mtk_clk_register_gate(gate->name, gate->parent_name, regmap, diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 0e027be0d5fc..b4063261cf56 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -65,8 +65,10 @@ int mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num, for (i = 0; i < num; i++) { const struct mtk_fixed_clk *rc = &clks[i]; - if (!IS_ERR_OR_NULL(clk_data->clks[rc->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[rc->id])) { + pr_warn("Trying to register duplicate clock ID: %d\n", rc->id); continue; + } clk = clk_register_fixed_rate(NULL, rc->name, rc->parent, 0, rc->rate); @@ -128,8 +130,10 @@ int mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num, for (i = 0; i < num; i++) { const struct mtk_fixed_factor *ff = &clks[i]; - if (!IS_ERR_OR_NULL(clk_data->clks[ff->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[ff->id])) { + pr_warn("Trying to register duplicate clock ID: %d\n", ff->id); continue; + } clk = clk_register_fixed_factor(NULL, ff->name, ff->parent_name, CLK_SET_RATE_PARENT, ff->mult, ff->div); @@ -305,8 +309,11 @@ int mtk_clk_register_composites(const struct mtk_composite *mcs, int num, for (i = 0; i < num; i++) { const struct mtk_composite *mc = &mcs[i]; - if (clk_data && !IS_ERR_OR_NULL(clk_data->clks[mc->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[mc->id])) { + pr_warn("Trying to register duplicate clock ID: %d\n", + mc->id); continue; + } clk = mtk_clk_register_composite(mc, base, lock); @@ -368,8 +375,11 @@ int mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num, for (i = 0; i < num; i++) { const struct mtk_clk_divider *mcd = &mcds[i]; - if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id])) { + pr_warn("Trying to register duplicate clock ID: %d\n", + mcd->id); continue; + } clk = clk_register_divider(NULL, mcd->name, mcd->parent_name, mcd->flags, base + mcd->div_reg, mcd->div_shift, diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c index f51e67650f03..21ad5a4afd65 100644 --- a/drivers/clk/mediatek/clk-mux.c +++ b/drivers/clk/mediatek/clk-mux.c @@ -208,8 +208,11 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes, for (i = 0; i < num; i++) { const struct mtk_mux *mux = &muxes[i]; - if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) + if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) { + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", + node, mux->id); continue; + } clk = mtk_clk_register_mux(mux, regmap, lock); diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c index 817a80293bfc..ccaa2085ab4d 100644 --- a/drivers/clk/mediatek/clk-pll.c +++ b/drivers/clk/mediatek/clk-pll.c @@ -394,6 +394,12 @@ int mtk_clk_register_plls(struct device_node *node, for (i = 0; i < num_plls; i++) { const struct mtk_pll_data *pll = &plls[i]; + if (!IS_ERR_OR_NULL(clk_data->clks[pll->id])) { + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", + node, pll->id); + continue; + } + clk = mtk_clk_register_pll(pll, base); if (IS_ERR(clk)) {