1acddfc2cSWeiyi Lu // SPDX-License-Identifier: GPL-2.0
2acddfc2cSWeiyi Lu //
3acddfc2cSWeiyi Lu // Copyright (c) 2018 MediaTek Inc.
4acddfc2cSWeiyi Lu // Author: Weiyi Lu <weiyi.lu@mediatek.com>
5acddfc2cSWeiyi Lu 
6acddfc2cSWeiyi Lu #include <linux/clk-provider.h>
7acddfc2cSWeiyi Lu #include <linux/platform_device.h>
8acddfc2cSWeiyi Lu 
9acddfc2cSWeiyi Lu #include "clk-mtk.h"
10acddfc2cSWeiyi Lu #include "clk-gate.h"
11acddfc2cSWeiyi Lu 
12acddfc2cSWeiyi Lu #include <dt-bindings/clock/mt8183-clk.h>
13acddfc2cSWeiyi Lu 
14acddfc2cSWeiyi Lu static const struct mtk_gate_regs mm0_cg_regs = {
15acddfc2cSWeiyi Lu 	.set_ofs = 0x104,
16acddfc2cSWeiyi Lu 	.clr_ofs = 0x108,
17acddfc2cSWeiyi Lu 	.sta_ofs = 0x100,
18acddfc2cSWeiyi Lu };
19acddfc2cSWeiyi Lu 
20acddfc2cSWeiyi Lu static const struct mtk_gate_regs mm1_cg_regs = {
21acddfc2cSWeiyi Lu 	.set_ofs = 0x114,
22acddfc2cSWeiyi Lu 	.clr_ofs = 0x118,
23acddfc2cSWeiyi Lu 	.sta_ofs = 0x110,
24acddfc2cSWeiyi Lu };
25acddfc2cSWeiyi Lu 
26acddfc2cSWeiyi Lu #define GATE_MM0(_id, _name, _parent, _shift)			\
27acddfc2cSWeiyi Lu 	GATE_MTK(_id, _name, _parent, &mm0_cg_regs, _shift,	\
28acddfc2cSWeiyi Lu 		&mtk_clk_gate_ops_setclr)
29acddfc2cSWeiyi Lu 
30acddfc2cSWeiyi Lu #define GATE_MM1(_id, _name, _parent, _shift)			\
31acddfc2cSWeiyi Lu 	GATE_MTK(_id, _name, _parent, &mm1_cg_regs, _shift,	\
32acddfc2cSWeiyi Lu 		&mtk_clk_gate_ops_setclr)
33acddfc2cSWeiyi Lu 
34acddfc2cSWeiyi Lu static const struct mtk_gate mm_clks[] = {
35acddfc2cSWeiyi Lu 	/* MM0 */
36acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_SMI_COMMON, "mm_smi_common", "mm_sel", 0),
37acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_SMI_LARB0, "mm_smi_larb0", "mm_sel", 1),
38acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_SMI_LARB1, "mm_smi_larb1", "mm_sel", 2),
39acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_GALS_COMM0, "mm_gals_comm0", "mm_sel", 3),
40acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_GALS_COMM1, "mm_gals_comm1", "mm_sel", 4),
41acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_GALS_CCU2MM, "mm_gals_ccu2mm", "mm_sel", 5),
42acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_GALS_IPU12MM, "mm_gals_ipu12mm", "mm_sel", 6),
43acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_GALS_IMG2MM, "mm_gals_img2mm", "mm_sel", 7),
44acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_GALS_CAM2MM, "mm_gals_cam2mm", "mm_sel", 8),
45acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_GALS_IPU2MM, "mm_gals_ipu2mm", "mm_sel", 9),
46acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_MDP_DL_TXCK, "mm_mdp_dl_txck", "mm_sel", 10),
47acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_IPU_DL_TXCK, "mm_ipu_dl_txck", "mm_sel", 11),
48acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_MDP_RDMA0, "mm_mdp_rdma0", "mm_sel", 12),
49acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_MDP_RDMA1, "mm_mdp_rdma1", "mm_sel", 13),
50acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_MDP_RSZ0, "mm_mdp_rsz0", "mm_sel", 14),
51acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_MDP_RSZ1, "mm_mdp_rsz1", "mm_sel", 15),
52acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_MDP_TDSHP, "mm_mdp_tdshp", "mm_sel", 16),
53acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_MDP_WROT0, "mm_mdp_wrot0", "mm_sel", 17),
54acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_MDP_WDMA0, "mm_mdp_wdma0", "mm_sel", 18),
55acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_FAKE_ENG, "mm_fake_eng", "mm_sel", 19),
56acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_OVL0, "mm_disp_ovl0", "mm_sel", 20),
57acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_OVL0_2L, "mm_disp_ovl0_2l", "mm_sel", 21),
58acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_OVL1_2L, "mm_disp_ovl1_2l", "mm_sel", 22),
59acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_RDMA0, "mm_disp_rdma0", "mm_sel", 23),
60acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_RDMA1, "mm_disp_rdma1", "mm_sel", 24),
61acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_WDMA0, "mm_disp_wdma0", "mm_sel", 25),
62acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_COLOR0, "mm_disp_color0", "mm_sel", 26),
63acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_CCORR0, "mm_disp_ccorr0", "mm_sel", 27),
64acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_AAL0, "mm_disp_aal0", "mm_sel", 28),
65acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_GAMMA0, "mm_disp_gamma0", "mm_sel", 29),
66acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_DITHER0, "mm_disp_dither0", "mm_sel", 30),
67acddfc2cSWeiyi Lu 	GATE_MM0(CLK_MM_DISP_SPLIT, "mm_disp_split", "mm_sel", 31),
68acddfc2cSWeiyi Lu 	/* MM1 */
69acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_DSI0_MM, "mm_dsi0_mm", "mm_sel", 0),
70acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_DSI0_IF, "mm_dsi0_if", "mm_sel", 1),
71acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_DPI_MM, "mm_dpi_mm", "mm_sel", 2),
72acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_DPI_IF, "mm_dpi_if", "dpi0_sel", 3),
73acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_FAKE_ENG2, "mm_fake_eng2", "mm_sel", 4),
74acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_MDP_DL_RX, "mm_mdp_dl_rx", "mm_sel", 5),
75acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_IPU_DL_RX, "mm_ipu_dl_rx", "mm_sel", 6),
76acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_26M, "mm_26m", "f_f26m_ck", 7),
77acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_MMSYS_R2Y, "mm_mmsys_r2y", "mm_sel", 8),
78acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_DISP_RSZ, "mm_disp_rsz", "mm_sel", 9),
79acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_MDP_AAL, "mm_mdp_aal", "mm_sel", 10),
80acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_MDP_CCORR, "mm_mdp_ccorr", "mm_sel", 11),
81acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_DBI_MM, "mm_dbi_mm", "mm_sel", 12),
82acddfc2cSWeiyi Lu 	GATE_MM1(CLK_MM_DBI_IF, "mm_dbi_if", "dpi0_sel", 13),
83acddfc2cSWeiyi Lu };
84acddfc2cSWeiyi Lu 
8565c10c50SAngeloGioacchino Del Regno static const struct mtk_clk_desc mm_desc = {
8665c10c50SAngeloGioacchino Del Regno 	.clks = mm_clks,
8765c10c50SAngeloGioacchino Del Regno 	.num_clks = ARRAY_SIZE(mm_clks),
8865c10c50SAngeloGioacchino Del Regno };
89acddfc2cSWeiyi Lu 
9065c10c50SAngeloGioacchino Del Regno static const struct platform_device_id clk_mt8183_mm_id_table[] = {
9165c10c50SAngeloGioacchino Del Regno 	{ .name = "clk-mt8183-mm", .driver_data = (kernel_ulong_t)&mm_desc },
9265c10c50SAngeloGioacchino Del Regno 	{ /* sentinel */ }
9365c10c50SAngeloGioacchino Del Regno };
9465c9ad77SAngeloGioacchino Del Regno MODULE_DEVICE_TABLE(platform, clk_mt8183_mm_id_table);
95acddfc2cSWeiyi Lu 
96acddfc2cSWeiyi Lu static struct platform_driver clk_mt8183_mm_drv = {
9765c10c50SAngeloGioacchino Del Regno 	.probe = mtk_clk_pdev_probe,
98*b3bc7275SUwe Kleine-König 	.remove_new = mtk_clk_pdev_remove,
99acddfc2cSWeiyi Lu 	.driver = {
100acddfc2cSWeiyi Lu 		.name = "clk-mt8183-mm",
101acddfc2cSWeiyi Lu 	},
10265c10c50SAngeloGioacchino Del Regno 	.id_table = clk_mt8183_mm_id_table,
103acddfc2cSWeiyi Lu };
104164d240dSAngeloGioacchino Del Regno module_platform_driver(clk_mt8183_mm_drv);
105a451da86SAngeloGioacchino Del Regno MODULE_LICENSE("GPL");
106