1 // SPDX-License-Identifier: GPL-2.0
3 // mt6797-afe-clk.c -- Mediatek 6797 afe clock ctrl
5 // Copyright (c) 2018 MediaTek Inc.
6 // Author: KaiChieh Chuang <kaichieh.chuang@mediatek.com>
10 #include "mt6797-afe-common.h"
11 #include "mt6797-afe-clk.h"
15 CLK_INFRA_SYS_AUD_26M
,
24 static const char *aud_clks
[CLK_NUM
] = {
25 [CLK_INFRA_SYS_AUD
] = "infra_sys_audio_clk",
26 [CLK_INFRA_SYS_AUD_26M
] = "infra_sys_audio_26m",
27 [CLK_TOP_MUX_AUD
] = "top_mux_audio",
28 [CLK_TOP_MUX_AUD_BUS
] = "top_mux_aud_intbus",
29 [CLK_TOP_SYSPLL3_D4
] = "top_sys_pll3_d4",
30 [CLK_TOP_SYSPLL1_D4
] = "top_sys_pll1_d4",
31 [CLK_CLK26M
] = "top_clk26m_clk",
34 int mt6797_init_clock(struct mtk_base_afe
*afe
)
36 struct mt6797_afe_private
*afe_priv
= afe
->platform_priv
;
39 afe_priv
->clk
= devm_kcalloc(afe
->dev
, CLK_NUM
, sizeof(*afe_priv
->clk
),
44 for (i
= 0; i
< CLK_NUM
; i
++) {
45 afe_priv
->clk
[i
] = devm_clk_get(afe
->dev
, aud_clks
[i
]);
46 if (IS_ERR(afe_priv
->clk
[i
])) {
47 dev_err(afe
->dev
, "%s(), devm_clk_get %s fail, ret %ld\n",
48 __func__
, aud_clks
[i
],
49 PTR_ERR(afe_priv
->clk
[i
]));
50 return PTR_ERR(afe_priv
->clk
[i
]);
57 int mt6797_afe_enable_clock(struct mtk_base_afe
*afe
)
59 struct mt6797_afe_private
*afe_priv
= afe
->platform_priv
;
62 ret
= clk_prepare_enable(afe_priv
->clk
[CLK_INFRA_SYS_AUD
]);
64 dev_err(afe
->dev
, "%s(), clk_prepare_enable %s fail %d\n",
65 __func__
, aud_clks
[CLK_INFRA_SYS_AUD
], ret
);
66 goto CLK_INFRA_SYS_AUDIO_ERR
;
69 ret
= clk_prepare_enable(afe_priv
->clk
[CLK_INFRA_SYS_AUD_26M
]);
71 dev_err(afe
->dev
, "%s(), clk_prepare_enable %s fail %d\n",
72 __func__
, aud_clks
[CLK_INFRA_SYS_AUD_26M
], ret
);
73 goto CLK_INFRA_SYS_AUD_26M_ERR
;
76 ret
= clk_prepare_enable(afe_priv
->clk
[CLK_TOP_MUX_AUD
]);
78 dev_err(afe
->dev
, "%s(), clk_prepare_enable %s fail %d\n",
79 __func__
, aud_clks
[CLK_TOP_MUX_AUD
], ret
);
80 goto CLK_MUX_AUDIO_ERR
;
83 ret
= clk_set_parent(afe_priv
->clk
[CLK_TOP_MUX_AUD
],
84 afe_priv
->clk
[CLK_CLK26M
]);
86 dev_err(afe
->dev
, "%s(), clk_set_parent %s-%s fail %d\n",
87 __func__
, aud_clks
[CLK_TOP_MUX_AUD
],
88 aud_clks
[CLK_CLK26M
], ret
);
89 goto CLK_MUX_AUDIO_ERR
;
92 ret
= clk_prepare_enable(afe_priv
->clk
[CLK_TOP_MUX_AUD_BUS
]);
94 dev_err(afe
->dev
, "%s(), clk_prepare_enable %s fail %d\n",
95 __func__
, aud_clks
[CLK_TOP_MUX_AUD_BUS
], ret
);
96 goto CLK_MUX_AUDIO_INTBUS_ERR
;
101 CLK_MUX_AUDIO_INTBUS_ERR
:
102 clk_disable_unprepare(afe_priv
->clk
[CLK_TOP_MUX_AUD_BUS
]);
104 clk_disable_unprepare(afe_priv
->clk
[CLK_TOP_MUX_AUD
]);
105 CLK_INFRA_SYS_AUD_26M_ERR
:
106 clk_disable_unprepare(afe_priv
->clk
[CLK_INFRA_SYS_AUD_26M
]);
107 CLK_INFRA_SYS_AUDIO_ERR
:
108 clk_disable_unprepare(afe_priv
->clk
[CLK_INFRA_SYS_AUD
]);
113 int mt6797_afe_disable_clock(struct mtk_base_afe
*afe
)
115 struct mt6797_afe_private
*afe_priv
= afe
->platform_priv
;
117 clk_disable_unprepare(afe_priv
->clk
[CLK_TOP_MUX_AUD_BUS
]);
118 clk_disable_unprepare(afe_priv
->clk
[CLK_TOP_MUX_AUD
]);
119 clk_disable_unprepare(afe_priv
->clk
[CLK_INFRA_SYS_AUD_26M
]);
120 clk_disable_unprepare(afe_priv
->clk
[CLK_INFRA_SYS_AUD
]);