1 From 907d65c5020fefc9944ec57a9e0bd66dc648823e Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Wed, 31 Aug 2022 19:04:59 +0800
4 Subject: [PATCH 22/32] clk: mediatek: add CLK_BYPASS_XTAL flag to allow
5 bypassing searching clock parent of xtal clock
7 The mtk clock framework in u-boot uses array index for searching clock
8 parent (kernel uses strings for search), so we need to specify a special
9 clock with ID=0 for CLK_XTAL in u-boot.
11 In the mt7622/mt7629 clock tree, the clocks with ID=0 never call
12 mtk_topckgen_get_mux_rate, adn return xtal clock directly. This what we
15 However for newer chips, they may have some clocks with ID=0 not
16 representing the xtal clock and still needs mtk_topckgen_get_mux_rate be
17 called. Current logic will make entire clock driver not working.
19 This patch adds a flag to indicate that whether a clock driver needs clocks
20 with ID=0 to call mtk_topckgen_get_mux_rate.
22 Reviewed-by: Simon Glass <sjg@chromium.org>
23 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
25 drivers/clk/mediatek/clk-mtk.c | 4 +++-
26 drivers/clk/mediatek/clk-mtk.h | 6 ++++++
27 2 files changed, 9 insertions(+), 1 deletion(-)
29 --- a/drivers/clk/mediatek/clk-mtk.c
30 +++ b/drivers/clk/mediatek/clk-mtk.c
31 @@ -319,7 +319,9 @@ static ulong mtk_topckgen_get_mux_rate(s
32 index &= mux->mux_mask << mux->mux_shift;
33 index = index >> mux->mux_shift;
35 - if (mux->parent[index])
36 + if (mux->parent[index] > 0 ||
37 + (mux->parent[index] == CLK_XTAL &&
38 + priv->tree->flags & CLK_BYPASS_XTAL))
39 return mtk_clk_find_parent_rate(clk, mux->parent[index],
42 --- a/drivers/clk/mediatek/clk-mtk.h
43 +++ b/drivers/clk/mediatek/clk-mtk.h
46 #define MHZ (1000 * 1000)
48 +/* flags in struct mtk_clk_tree */
50 +/* clk id == 0 doesn't mean it's xtal clk */
51 +#define CLK_BYPASS_XTAL BIT(0)
53 #define HAVE_RST_BAR BIT(0)
54 #define CLK_DOMAIN_SCPSYS BIT(0)
55 #define CLK_MUX_SETCLR_UPD BIT(1)
56 @@ -197,6 +202,7 @@ struct mtk_clk_tree {
57 const struct mtk_fixed_clk *fclks;
58 const struct mtk_fixed_factor *fdivs;
59 const struct mtk_composite *muxes;