From: Laura Nao <laura.nao@collabora.com>
To: wenst@chromium.org
Cc: angelogioacchino.delregno@collabora.com, conor+dt@kernel.org,
devicetree@vger.kernel.org, guangjie.song@mediatek.com,
kernel@collabora.com, krzk+dt@kernel.org,
laura.nao@collabora.com, linux-arm-kernel@lists.infradead.org,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mediatek@lists.infradead.org, matthias.bgg@gmail.com,
mturquette@baylibre.com, netdev@vger.kernel.org,
nfraprado@collabora.com, p.zabel@pengutronix.de,
richardcochran@gmail.com, robh@kernel.org, sboyd@kernel.org
Subject: Re: [PATCH v4 05/27] clk: mediatek: clk-mux: Add ops for mux gates with HW voter and FENC
Date: Mon, 25 Aug 2025 14:45:48 +0200 [thread overview]
Message-ID: <20250825124548.209157-1-laura.nao@collabora.com> (raw)
In-Reply-To: <CAGXv+5GyKoTb3iQTuQPWEc5Ewa+kr4dJUET8sAFRZ7T5RyNzLQ@mail.gmail.com>
On 8/15/25 05:31, Chen-Yu Tsai wrote:
> On Tue, Aug 5, 2025 at 10:55 PM Laura Nao <laura.nao@collabora.com> wrote:
>>
>> MT8196 use a HW voter for mux gate enable/disable control, along with a
>> FENC status bit to check the status. Voting is performed using
>> set/clr/upd registers, with a status bit used to verify the vote state.
>> Add new set of mux gate clock operations with support for voting via
>> set/clr/upd regs and FENC status logic.
>>
>> Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
>> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> Signed-off-by: Laura Nao <laura.nao@collabora.com>
>> ---
>> drivers/clk/mediatek/clk-mtk.h | 1 +
>> drivers/clk/mediatek/clk-mux.c | 71 +++++++++++++++++++++++++++++++++-
>> drivers/clk/mediatek/clk-mux.h | 42 ++++++++++++++++++++
>> 3 files changed, 113 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
>> index 8ed2c9208b1f..e2cefd9bc5b8 100644
>> --- a/drivers/clk/mediatek/clk-mtk.h
>> +++ b/drivers/clk/mediatek/clk-mtk.h
>> @@ -20,6 +20,7 @@
>>
>> #define MHZ (1000 * 1000)
>>
>> +#define MTK_WAIT_HWV_DONE_US 30
>> #define MTK_WAIT_FENC_DONE_US 30
>>
>> struct platform_device;
>> diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c
>> index b1b8eeb0b501..65889fc6a3e5 100644
>> --- a/drivers/clk/mediatek/clk-mux.c
>> +++ b/drivers/clk/mediatek/clk-mux.c
>> @@ -8,6 +8,7 @@
>> #include <linux/clk-provider.h>
>> #include <linux/compiler_types.h>
>> #include <linux/container_of.h>
>> +#include <linux/dev_printk.h>
>> #include <linux/err.h>
>> #include <linux/mfd/syscon.h>
>> #include <linux/module.h>
>> @@ -21,6 +22,7 @@
>> struct mtk_clk_mux {
>> struct clk_hw hw;
>> struct regmap *regmap;
>> + struct regmap *regmap_hwv;
>> const struct mtk_mux *data;
>> spinlock_t *lock;
>> bool reparent;
>> @@ -118,6 +120,41 @@ static int mtk_clk_mux_is_enabled(struct clk_hw *hw)
>> return (val & BIT(mux->data->gate_shift)) == 0;
>> }
>>
>> +static int mtk_clk_mux_hwv_fenc_enable(struct clk_hw *hw)
>> +{
>> + struct mtk_clk_mux *mux = to_mtk_clk_mux(hw);
>> + u32 val;
>> + int ret;
>> +
>> + regmap_write(mux->regmap_hwv, mux->data->hwv_set_ofs,
>> + BIT(mux->data->gate_shift));
>> +
>> + ret = regmap_read_poll_timeout_atomic(mux->regmap_hwv, mux->data->hwv_sta_ofs,
>> + val, val & BIT(mux->data->gate_shift), 0,
>> + MTK_WAIT_HWV_DONE_US);
>> + if (ret)
>> + return ret;
>> +
>> + ret = regmap_read_poll_timeout_atomic(mux->regmap, mux->data->fenc_sta_mon_ofs,
>> + val, val & BIT(mux->data->fenc_shift), 1,
>> + MTK_WAIT_FENC_DONE_US);
>> +
>> + return ret;
>> +}
>> +
>> +static void mtk_clk_mux_hwv_disable(struct clk_hw *hw)
>> +{
>> + struct mtk_clk_mux *mux = to_mtk_clk_mux(hw);
>> + u32 val;
>> +
>> + regmap_write(mux->regmap_hwv, mux->data->hwv_clr_ofs,
>> + BIT(mux->data->gate_shift));
>> +
>> + regmap_read_poll_timeout_atomic(mux->regmap_hwv, mux->data->hwv_sta_ofs,
>> + val, (val & BIT(mux->data->gate_shift)),
>> + 0, MTK_WAIT_HWV_DONE_US);
>> +}
>> +
>> static u8 mtk_clk_mux_get_parent(struct clk_hw *hw)
>> {
>> struct mtk_clk_mux *mux = to_mtk_clk_mux(hw);
>> @@ -189,6 +226,14 @@ static int mtk_clk_mux_determine_rate(struct clk_hw *hw,
>> return clk_mux_determine_rate_flags(hw, req, mux->data->flags);
>> }
>>
>> +static bool mtk_clk_mux_uses_hwv(const struct clk_ops *ops)
>> +{
>> + if (ops == &mtk_mux_gate_hwv_fenc_clr_set_upd_ops)
>> + return true;
>> +
>> + return false;
>> +}
>> +
>> const struct clk_ops mtk_mux_clr_set_upd_ops = {
>> .get_parent = mtk_clk_mux_get_parent,
>> .set_parent = mtk_clk_mux_set_parent_setclr_lock,
>> @@ -216,9 +261,20 @@ const struct clk_ops mtk_mux_gate_fenc_clr_set_upd_ops = {
>> };
>> EXPORT_SYMBOL_GPL(mtk_mux_gate_fenc_clr_set_upd_ops);
>>
>> +const struct clk_ops mtk_mux_gate_hwv_fenc_clr_set_upd_ops = {
>> + .enable = mtk_clk_mux_hwv_fenc_enable,
>> + .disable = mtk_clk_mux_hwv_disable,
>> + .is_enabled = mtk_clk_mux_fenc_is_enabled,
>> + .get_parent = mtk_clk_mux_get_parent,
>> + .set_parent = mtk_clk_mux_set_parent_setclr_lock,
>> + .determine_rate = mtk_clk_mux_determine_rate,
>> +};
>> +EXPORT_SYMBOL_GPL(mtk_mux_gate_hwv_fenc_clr_set_upd_ops);
>> +
>> static struct clk_hw *mtk_clk_register_mux(struct device *dev,
>> const struct mtk_mux *mux,
>> struct regmap *regmap,
>> + struct regmap *regmap_hwv,
>> spinlock_t *lock)
>> {
>> struct mtk_clk_mux *clk_mux;
>> @@ -234,8 +290,13 @@ static struct clk_hw *mtk_clk_register_mux(struct device *dev,
>> init.parent_names = mux->parent_names;
>> init.num_parents = mux->num_parents;
>> init.ops = mux->ops;
>> + if (mtk_clk_mux_uses_hwv(init.ops) && !regmap_hwv) {
>> + dev_err(dev, "regmap not found for hardware voter clocks\n");
>> + return ERR_PTR(-ENXIO);
>> + }
>>
>> clk_mux->regmap = regmap;
>> + clk_mux->regmap_hwv = regmap_hwv;
>> clk_mux->data = mux;
>> clk_mux->lock = lock;
>> clk_mux->hw.init = &init;
>> @@ -268,6 +329,7 @@ int mtk_clk_register_muxes(struct device *dev,
>> struct clk_hw_onecell_data *clk_data)
>> {
>> struct regmap *regmap;
>> + struct regmap *regmap_hwv;
>> struct clk_hw *hw;
>> int i;
>>
>> @@ -277,6 +339,13 @@ int mtk_clk_register_muxes(struct device *dev,
>> return PTR_ERR(regmap);
>> }
>>
>> + regmap_hwv = mtk_clk_get_hwv_regmap(node);
>> + if (IS_ERR(regmap_hwv)) {
>> + pr_err("Cannot find hardware voter regmap for %pOF: %pe\n",
>> + node, regmap_hwv);
>> + return PTR_ERR(regmap_hwv);
>
> Is there a reason why we aren't using dev_err() or even dev_err_probe()
> here?
>
Not really, just got swayed by the surrounding pr_* calls. I’ll fix it
here and in the other mtk_clk_get_hwv_regmap call. We can clean up the
remaining pr_* calls in a separate patch.
Thanks,
Laura
> The rest looks OK.
>
> ChenYu
>
>> + }
>> +
>> for (i = 0; i < num; i++) {
>> const struct mtk_mux *mux = &muxes[i];
>>
>> @@ -286,7 +355,7 @@ int mtk_clk_register_muxes(struct device *dev,
>> continue;
>> }
>>
>> - hw = mtk_clk_register_mux(dev, mux, regmap, lock);
>> + hw = mtk_clk_register_mux(dev, mux, regmap, regmap_hwv, lock);
>>
>> if (IS_ERR(hw)) {
>> pr_err("Failed to register clk %s: %pe\n", mux->name,
>> diff --git a/drivers/clk/mediatek/clk-mux.h b/drivers/clk/mediatek/clk-mux.h
>> index c65cfb7f8fc3..fb6f7951379c 100644
>> --- a/drivers/clk/mediatek/clk-mux.h
>> +++ b/drivers/clk/mediatek/clk-mux.h
>> @@ -28,6 +28,10 @@ struct mtk_mux {
>> u32 set_ofs;
>> u32 clr_ofs;
>> u32 upd_ofs;
>> +
>> + u32 hwv_set_ofs;
>> + u32 hwv_clr_ofs;
>> + u32 hwv_sta_ofs;
>> u32 fenc_sta_mon_ofs;
>>
>> u8 mux_shift;
>> @@ -80,6 +84,7 @@ struct mtk_mux {
>> extern const struct clk_ops mtk_mux_clr_set_upd_ops;
>> extern const struct clk_ops mtk_mux_gate_clr_set_upd_ops;
>> extern const struct clk_ops mtk_mux_gate_fenc_clr_set_upd_ops;
>> +extern const struct clk_ops mtk_mux_gate_hwv_fenc_clr_set_upd_ops;
>>
>> #define MUX_GATE_CLR_SET_UPD_FLAGS(_id, _name, _parents, _mux_ofs, \
>> _mux_set_ofs, _mux_clr_ofs, _shift, _width, \
>> @@ -121,6 +126,43 @@ extern const struct clk_ops mtk_mux_gate_fenc_clr_set_upd_ops;
>> 0, _upd_ofs, _upd, CLK_SET_RATE_PARENT, \
>> mtk_mux_clr_set_upd_ops)
>>
>> +#define MUX_GATE_HWV_FENC_CLR_SET_UPD_FLAGS(_id, _name, _parents, \
>> + _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
>> + _hwv_sta_ofs, _hwv_set_ofs, _hwv_clr_ofs, \
>> + _shift, _width, _gate, _upd_ofs, _upd, \
>> + _fenc_sta_mon_ofs, _fenc, _flags) { \
>> + .id = _id, \
>> + .name = _name, \
>> + .mux_ofs = _mux_ofs, \
>> + .set_ofs = _mux_set_ofs, \
>> + .clr_ofs = _mux_clr_ofs, \
>> + .hwv_sta_ofs = _hwv_sta_ofs, \
>> + .hwv_set_ofs = _hwv_set_ofs, \
>> + .hwv_clr_ofs = _hwv_clr_ofs, \
>> + .upd_ofs = _upd_ofs, \
>> + .fenc_sta_mon_ofs = _fenc_sta_mon_ofs, \
>> + .mux_shift = _shift, \
>> + .mux_width = _width, \
>> + .gate_shift = _gate, \
>> + .upd_shift = _upd, \
>> + .fenc_shift = _fenc, \
>> + .parent_names = _parents, \
>> + .num_parents = ARRAY_SIZE(_parents), \
>> + .flags = _flags, \
>> + .ops = &mtk_mux_gate_hwv_fenc_clr_set_upd_ops, \
>> + }
>> +
>> +#define MUX_GATE_HWV_FENC_CLR_SET_UPD(_id, _name, _parents, \
>> + _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
>> + _hwv_sta_ofs, _hwv_set_ofs, _hwv_clr_ofs, \
>> + _shift, _width, _gate, _upd_ofs, _upd, \
>> + _fenc_sta_mon_ofs, _fenc) \
>> + MUX_GATE_HWV_FENC_CLR_SET_UPD_FLAGS(_id, _name, _parents, \
>> + _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
>> + _hwv_sta_ofs, _hwv_set_ofs, _hwv_clr_ofs, \
>> + _shift, _width, _gate, _upd_ofs, _upd, \
>> + _fenc_sta_mon_ofs, _fenc, 0)
>> +
>> #define MUX_GATE_FENC_CLR_SET_UPD_FLAGS(_id, _name, _parents, _paridx, \
>> _num_parents, _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
>> _shift, _width, _gate, _upd_ofs, _upd, \
>> --
>> 2.39.5
>>
next prev parent reply other threads:[~2025-08-25 12:46 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-05 13:54 [PATCH v4 00/27] Add support for MT8196 clock controllers Laura Nao
2025-08-05 13:54 ` [PATCH v4 01/27] clk: mediatek: clk-pll: Add set/clr regs for shared PLL enable control Laura Nao
2025-08-15 3:03 ` Chen-Yu Tsai
2025-08-05 13:54 ` [PATCH v4 02/27] clk: mediatek: clk-pll: Add ops for PLLs using set/clr regs and FENC Laura Nao
2025-08-15 3:18 ` Chen-Yu Tsai
2025-08-25 12:39 ` Laura Nao
2025-08-28 9:09 ` Laura Nao
2025-08-05 13:54 ` [PATCH v4 03/27] clk: mediatek: clk-mux: Add ops for mux gates with set/clr/upd " Laura Nao
2025-08-15 3:23 ` Chen-Yu Tsai
2025-08-25 12:42 ` Laura Nao
2025-08-05 13:54 ` [PATCH v4 04/27] clk: mediatek: clk-mtk: Introduce mtk_clk_get_hwv_regmap() Laura Nao
2025-08-15 3:25 ` Chen-Yu Tsai
2025-08-05 13:54 ` [PATCH v4 05/27] clk: mediatek: clk-mux: Add ops for mux gates with HW voter and FENC Laura Nao
2025-08-15 3:31 ` Chen-Yu Tsai
2025-08-25 12:45 ` Laura Nao [this message]
2025-08-05 13:54 ` [PATCH v4 06/27] clk: mediatek: clk-gate: Refactor mtk_clk_register_gate to use mtk_gate struct Laura Nao
2025-08-15 3:42 ` Chen-Yu Tsai
2025-08-25 12:49 ` Laura Nao
2025-08-05 13:54 ` [PATCH v4 07/27] clk: mediatek: clk-gate: Add ops for gates with HW voter Laura Nao
2025-08-15 3:37 ` Chen-Yu Tsai
2025-08-25 12:51 ` Laura Nao
2025-08-25 14:50 ` Chen-Yu Tsai
2025-08-26 8:36 ` Laura Nao
2025-08-05 13:54 ` [PATCH v4 08/27] clk: mediatek: clk-mtk: Add MUX_DIV_GATE macro Laura Nao
2025-08-15 3:43 ` Chen-Yu Tsai
2025-08-05 13:54 ` [PATCH v4 09/27] dt-bindings: clock: mediatek: Describe MT8196 clock controllers Laura Nao
2025-08-07 6:58 ` Krzysztof Kozlowski
2025-08-05 13:54 ` [PATCH v4 10/27] clk: mediatek: Add MT8196 apmixedsys clock support Laura Nao
2025-08-05 13:54 ` [PATCH v4 11/27] clk: mediatek: Add MT8196 topckgen " Laura Nao
2025-08-05 13:54 ` [PATCH v4 12/27] clk: mediatek: Add MT8196 topckgen2 " Laura Nao
2025-08-05 13:54 ` [PATCH v4 13/27] clk: mediatek: Add MT8196 vlpckgen " Laura Nao
2025-08-25 13:12 ` Laura Nao
2025-08-05 13:54 ` [PATCH v4 14/27] clk: mediatek: Add MT8196 peripheral " Laura Nao
2025-08-05 13:54 ` [PATCH v4 15/27] clk: mediatek: Add MT8196 ufssys " Laura Nao
2025-08-15 3:50 ` Chen-Yu Tsai
2025-08-25 12:54 ` Laura Nao
2025-08-05 13:54 ` [PATCH v4 16/27] clk: mediatek: Add MT8196 pextpsys " Laura Nao
2025-08-15 3:53 ` Chen-Yu Tsai
2025-08-05 13:54 ` [PATCH v4 17/27] clk: mediatek: Add MT8196 I2C " Laura Nao
2025-08-15 6:13 ` Chen-Yu Tsai
2025-08-05 13:54 ` [PATCH v4 18/27] clk: mediatek: Add MT8196 mcu " Laura Nao
2025-08-05 13:54 ` [PATCH v4 19/27] clk: mediatek: Add MT8196 mdpsys " Laura Nao
2025-08-15 7:16 ` Chen-Yu Tsai
2025-08-05 13:54 ` [PATCH v4 20/27] clk: mediatek: Add MT8196 mfg " Laura Nao
2025-08-05 13:54 ` [PATCH v4 21/27] clk: mediatek: Add MT8196 disp0 " Laura Nao
2025-08-05 13:54 ` [PATCH v4 22/27] clk: mediatek: Add MT8196 disp1 " Laura Nao
2025-08-05 13:54 ` [PATCH v4 23/27] clk: mediatek: Add MT8196 disp-ao " Laura Nao
2025-08-05 13:54 ` [PATCH v4 24/27] clk: mediatek: Add MT8196 ovl0 " Laura Nao
2025-08-05 13:54 ` [PATCH v4 25/27] clk: mediatek: Add MT8196 ovl1 " Laura Nao
2025-08-05 13:54 ` [PATCH v4 26/27] clk: mediatek: Add MT8196 vdecsys " Laura Nao
2025-08-05 13:54 ` [PATCH v4 27/27] clk: mediatek: Add MT8196 vencsys " Laura Nao
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=20250825124548.209157-1-laura.nao@collabora.com \
--to=laura.nao@collabora.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=guangjie.song@mediatek.com \
--cc=kernel@collabora.com \
--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=nfraprado@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=richardcochran@gmail.com \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=wenst@chromium.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
all inboxes | Powered by JetHome®