From: Guangjie Song <guangjie.song@mediatek.com>
To: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Richard Cochran <richardcochran@gmail.com>
Cc: <linux-clk@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>, <netdev@vger.kernel.org>,
Guangjie Song <guangjie.song@mediatek.com>,
<Project_Global_Chrome_Upstream_Group@mediatek.com>
Subject: [PATCH 02/26] clk: mediatek: Support voting for pll
Date: Fri, 7 Mar 2025 11:26:58 +0800 [thread overview]
Message-ID: <20250307032942.10447-3-guangjie.song@mediatek.com> (raw)
In-Reply-To: <20250307032942.10447-1-guangjie.song@mediatek.com>
Add data fields and ops to support voting for pll.
Signed-off-by: Guangjie Song <guangjie.song@mediatek.com>
---
drivers/clk/mediatek/clk-pll.c | 51 +++++++++++++++++++++++++++++++++-
drivers/clk/mediatek/clk-pll.h | 5 ++++
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c
index ce453e1718e5..fdaa4ee74608 100644
--- a/drivers/clk/mediatek/clk-pll.c
+++ b/drivers/clk/mediatek/clk-pll.c
@@ -13,6 +13,7 @@
#include <linux/of_address.h>
#include <linux/slab.h>
+#include "clk-mtk.h"
#include "clk-pll.h"
#define MHZ (1000 * 1000)
@@ -37,6 +38,13 @@ int mtk_pll_is_prepared(struct clk_hw *hw)
return (readl(pll->en_addr) & BIT(pll->data->pll_en_bit)) != 0;
}
+static int mtk_pll_fenc_is_prepared(struct clk_hw *hw)
+{
+ struct mtk_clk_pll *pll = to_mtk_clk_pll(hw);
+
+ return (((readl(pll->fenc_addr) & pll->fenc_mask) != 0) || (pll->onoff_cnt != 0));
+}
+
static unsigned long __mtk_pll_recalc_rate(struct mtk_clk_pll *pll, u32 fin,
u32 pcw, int postdiv)
{
@@ -274,6 +282,30 @@ void mtk_pll_unprepare(struct clk_hw *hw)
writel(r, pll->pwr_addr);
}
+static int mtk_pll_fenc_prepare(struct clk_hw *hw)
+{
+ struct mtk_clk_pll *pll = to_mtk_clk_pll(hw);
+
+ if (pll->onoff_cnt == 1) {
+ pr_err("%s: %s is already prepared\n", __func__, clk_hw_get_name(hw));
+ return -EPERM;
+ }
+
+ pll->onoff_cnt = 1;
+
+ return 0;
+}
+
+static void mtk_pll_fenc_unprepare(struct clk_hw *hw)
+{
+ struct mtk_clk_pll *pll = to_mtk_clk_pll(hw);
+
+ if (pll->onoff_cnt == 0)
+ pr_err("%s: %s is not prepared\n", __func__, clk_hw_get_name(hw));
+ else
+ pll->onoff_cnt = 0;
+}
+
const struct clk_ops mtk_pll_ops = {
.is_prepared = mtk_pll_is_prepared,
.prepare = mtk_pll_prepare,
@@ -283,6 +315,15 @@ const struct clk_ops mtk_pll_ops = {
.set_rate = mtk_pll_set_rate,
};
+static const struct clk_ops mtk_pll_fenc_ops = {
+ .is_prepared = mtk_pll_fenc_is_prepared,
+ .prepare = mtk_pll_fenc_prepare,
+ .unprepare = mtk_pll_fenc_unprepare,
+ .recalc_rate = mtk_pll_recalc_rate,
+ .round_rate = mtk_pll_round_rate,
+ .set_rate = mtk_pll_set_rate,
+};
+
struct clk_hw *mtk_clk_register_pll_ops(struct mtk_clk_pll *pll,
const struct mtk_pll_data *data,
void __iomem *base,
@@ -313,6 +354,11 @@ struct clk_hw *mtk_clk_register_pll_ops(struct mtk_clk_pll *pll,
init.name = data->name;
init.flags = (data->flags & PLL_AO) ? CLK_IS_CRITICAL : 0;
+ if (data->flags & CLK_FENC_ENABLE) {
+ pll->fenc_addr = base + data->fenc_sta_ofs;
+ pll->fenc_mask = BIT(data->fenc_sta_bit);
+ }
+
init.ops = pll_ops;
if (data->parent_name)
init.parent_names = &data->parent_name;
@@ -338,7 +384,10 @@ struct clk_hw *mtk_clk_register_pll(const struct mtk_pll_data *data,
if (!pll)
return ERR_PTR(-ENOMEM);
- hw = mtk_clk_register_pll_ops(pll, data, base, &mtk_pll_ops);
+ if (data->flags & CLK_FENC_ENABLE)
+ hw = mtk_clk_register_pll_ops(pll, data, base, &mtk_pll_fenc_ops);
+ else
+ hw = mtk_clk_register_pll_ops(pll, data, base, &mtk_pll_ops);
if (IS_ERR(hw))
kfree(pll);
diff --git a/drivers/clk/mediatek/clk-pll.h b/drivers/clk/mediatek/clk-pll.h
index 285c8db958b3..3a1e48006e34 100644
--- a/drivers/clk/mediatek/clk-pll.h
+++ b/drivers/clk/mediatek/clk-pll.h
@@ -29,6 +29,7 @@ struct mtk_pll_data {
u32 reg;
u32 pwr_reg;
u32 en_mask;
+ u32 fenc_sta_ofs;
u32 pd_reg;
u32 tuner_reg;
u32 tuner_en_reg;
@@ -49,6 +50,7 @@ struct mtk_pll_data {
u32 en_reg;
u8 pll_en_bit; /* Assume 0, indicates BIT(0) by default */
u8 pcw_chg_bit;
+ u8 fenc_sta_bit;
};
/*
@@ -69,6 +71,9 @@ struct mtk_clk_pll {
void __iomem *pcw_chg_addr;
void __iomem *en_addr;
const struct mtk_pll_data *data;
+ void __iomem *fenc_addr;
+ u32 fenc_mask;
+ u32 onoff_cnt;
};
int mtk_clk_register_plls(struct device_node *node,
--
2.45.2
next prev parent reply other threads:[~2025-03-07 3:32 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 3:26 [PATCH 00/26] clk: mediatek: Add MT8196 clock support Guangjie Song
2025-03-07 3:26 ` [PATCH 01/26] clk: mediatek: Add defines for vote Guangjie Song
2025-03-07 3:26 ` Guangjie Song [this message]
2025-03-07 3:26 ` [PATCH 03/26] clk: mediatek: Support voting for mux Guangjie Song
2025-03-10 14:12 ` AngeloGioacchino Del Regno
2025-03-07 3:27 ` [PATCH 04/26] clk: mediatek: Support voting for gate Guangjie Song
2025-03-07 3:27 ` [PATCH 05/26] clk: mediatek: Add gate ops without disable Guangjie Song
2025-03-07 3:27 ` [PATCH 06/26] dt-bindings: clock: mediatek: Add new MT8196 clock Guangjie Song
2025-03-07 4:16 ` Rob Herring (Arm)
2025-03-07 7:29 ` Krzysztof Kozlowski
2025-04-16 9:20 ` Chen-Yu Tsai
2025-03-07 3:27 ` [PATCH 07/26] clk: mediatek: Add MT8196 apmixedsys clock support Guangjie Song
2025-03-11 17:05 ` Jeff Johnson
2025-03-07 3:27 ` [PATCH 08/26] clk: mediatek: Add MT8196 apmixedsys_gp2 " Guangjie Song
2025-03-07 3:27 ` [PATCH 09/26] clk: mediatek: Add MT8196 topckgen " Guangjie Song
2025-04-16 9:04 ` Chen-Yu Tsai
2025-03-07 3:27 ` [PATCH 10/26] clk: mediatek: Add MT8196 topckgen2 " Guangjie Song
2025-03-07 3:27 ` [PATCH 11/26] clk: mediatek: Add MT8196 vlpckgen " Guangjie Song
2025-03-07 3:27 ` [PATCH 12/26] clk: mediatek: Add MT8196 peripheral " Guangjie Song
2025-03-07 3:27 ` [PATCH 13/26] clk: mediatek: Add MT8196 adsp " Guangjie Song
2025-03-07 3:27 ` [PATCH 14/26] clk: mediatek: Add MT8196 i2c " Guangjie Song
2025-03-07 3:27 ` [PATCH 15/26] clk: mediatek: Add MT8196 mcu " Guangjie Song
2025-03-07 3:27 ` [PATCH 16/26] clk: mediatek: Add MT8196 mdpsys " Guangjie Song
2025-03-07 3:27 ` [PATCH 17/26] clk: mediatek: Add MT8196 mfg " Guangjie Song
2025-03-07 3:27 ` [PATCH 18/26] clk: mediatek: Add MT8196 disp0 " Guangjie Song
2025-03-07 3:27 ` [PATCH 19/26] clk: mediatek: Add MT8196 disp1 " Guangjie Song
2025-03-07 3:27 ` [PATCH 20/26] clk: mediatek: Add MT8196 disp-ao " Guangjie Song
2025-03-07 3:27 ` [PATCH 21/26] clk: mediatek: Add MT8196 ovl0 " Guangjie Song
2025-03-07 7:29 ` Krzysztof Kozlowski
2025-03-07 3:27 ` [PATCH 22/26] clk: mediatek: Add MT8196 ovl1 " Guangjie Song
2025-03-07 3:27 ` [PATCH 23/26] clk: mediatek: Add MT8196 pextpsys " Guangjie Song
2025-03-07 3:27 ` [PATCH 24/26] clk: mediatek: Add MT8196 ufssys " Guangjie Song
2025-03-07 3:27 ` [PATCH 25/26] clk: mediatek: Add MT8196 vdecsys " Guangjie Song
2025-03-07 3:27 ` [PATCH 26/26] clk: mediatek: Add MT8196 vencsys " Guangjie Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250307032942.10447-3-guangjie.song@mediatek.com \
--to=guangjie.song@mediatek.com \
--cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=mturquette@baylibre.com \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox