xref: /linux/drivers/clk/mediatek/clk-mt8365-mm.c (revision 266679ffd867cb247c36717ea4d7998e9304823b)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2022 MediaTek Inc.
4  * Copyright (c) 2022 BayLibre, SAS
5  */
6 
7 #include <dt-bindings/clock/mediatek,mt8365-clk.h>
8 #include <linux/clk-provider.h>
9 #include <linux/platform_device.h>
10 
11 #include "clk-gate.h"
12 #include "clk-mtk.h"
13 
14 static const struct mtk_gate_regs mm0_cg_regs = {
15 	.set_ofs = 0x104,
16 	.clr_ofs = 0x108,
17 	.sta_ofs = 0x100,
18 };
19 
20 static const struct mtk_gate_regs mm1_cg_regs = {
21 	.set_ofs = 0x114,
22 	.clr_ofs = 0x118,
23 	.sta_ofs = 0x110,
24 };
25 
26 #define GATE_MM0(_id, _name, _parent, _shift) \
27 		GATE_MTK(_id, _name, _parent, &mm0_cg_regs, _shift, \
28 			 &mtk_clk_gate_ops_setclr)
29 
30 #define GATE_MM1(_id, _name, _parent, _shift) \
31 		GATE_MTK(_id, _name, _parent, &mm1_cg_regs, _shift, \
32 			 &mtk_clk_gate_ops_setclr)
33 
34 static const struct mtk_gate mm_clks[] = {
35 	/* MM0 */
36 	GATE_MM0(CLK_MM_MM_MDP_RDMA0, "mm_mdp_rdma0", "mm_sel", 0),
37 	GATE_MM0(CLK_MM_MM_MDP_CCORR0, "mm_mdp_ccorr0", "mm_sel", 1),
38 	GATE_MM0(CLK_MM_MM_MDP_RSZ0, "mm_mdp_rsz0", "mm_sel", 2),
39 	GATE_MM0(CLK_MM_MM_MDP_RSZ1, "mm_mdp_rsz1", "mm_sel", 3),
40 	GATE_MM0(CLK_MM_MM_MDP_TDSHP0, "mm_mdp_tdshp0", "mm_sel", 4),
41 	GATE_MM0(CLK_MM_MM_MDP_WROT0, "mm_mdp_wrot0", "mm_sel", 5),
42 	GATE_MM0(CLK_MM_MM_MDP_WDMA0, "mm_mdp_wdma0", "mm_sel", 6),
43 	GATE_MM0(CLK_MM_MM_DISP_OVL0, "mm_disp_ovl0", "mm_sel", 7),
44 	GATE_MM0(CLK_MM_MM_DISP_OVL0_2L, "mm_disp_ovl0_2l", "mm_sel", 8),
45 	GATE_MM0(CLK_MM_MM_DISP_RSZ0, "mm_disp_rsz0", "mm_sel", 9),
46 	GATE_MM0(CLK_MM_MM_DISP_RDMA0, "mm_disp_rdma0", "mm_sel", 10),
47 	GATE_MM0(CLK_MM_MM_DISP_WDMA0, "mm_disp_wdma0", "mm_sel", 11),
48 	GATE_MM0(CLK_MM_MM_DISP_COLOR0, "mm_disp_color0", "mm_sel", 12),
49 	GATE_MM0(CLK_MM_MM_DISP_CCORR0, "mm_disp_ccorr0", "mm_sel", 13),
50 	GATE_MM0(CLK_MM_MM_DISP_AAL0, "mm_disp_aal0", "mm_sel", 14),
51 	GATE_MM0(CLK_MM_MM_DISP_GAMMA0, "mm_disp_gamma0", "mm_sel", 15),
52 	GATE_MM0(CLK_MM_MM_DISP_DITHER0, "mm_disp_dither0", "mm_sel", 16),
53 	GATE_MM0(CLK_MM_MM_DSI0, "mm_dsi0", "mm_sel", 17),
54 	GATE_MM0(CLK_MM_MM_DISP_RDMA1, "mm_disp_rdma1", "mm_sel", 18),
55 	GATE_MM0(CLK_MM_MM_MDP_RDMA1, "mm_mdp_rdma1", "mm_sel", 19),
56 	GATE_MM0(CLK_MM_DPI0_DPI0, "mm_dpi0_dpi0", "vpll_dpix", 20),
57 	GATE_MM0(CLK_MM_MM_FAKE, "mm_fake", "mm_sel", 21),
58 	GATE_MM0(CLK_MM_MM_SMI_COMMON, "mm_smi_common", "mm_sel", 22),
59 	GATE_MM0(CLK_MM_MM_SMI_LARB0, "mm_smi_larb0", "mm_sel", 23),
60 	GATE_MM0(CLK_MM_MM_SMI_COMM0, "mm_smi_comm0", "mm_sel", 24),
61 	GATE_MM0(CLK_MM_MM_SMI_COMM1, "mm_smi_comm1", "mm_sel", 25),
62 	GATE_MM0(CLK_MM_MM_CAM_MDP, "mm_cam_mdp", "mm_sel", 26),
63 	GATE_MM0(CLK_MM_MM_SMI_IMG, "mm_smi_img", "mm_sel", 27),
64 	GATE_MM0(CLK_MM_MM_SMI_CAM, "mm_smi_cam", "mm_sel", 28),
65 	GATE_MM0(CLK_MM_IMG_IMG_DL_RELAY, "mm_dl_relay", "mm_sel", 29),
66 	GATE_MM0(CLK_MM_IMG_IMG_DL_ASYNC_TOP, "mm_dl_async_top", "mm_sel", 30),
67 	GATE_MM0(CLK_MM_DSI0_DIG_DSI, "mm_dsi0_dig_dsi", "dsi0_lntc_dsick", 31),
68 	/* MM1 */
69 	GATE_MM1(CLK_MM_26M_HRTWT, "mm_f26m_hrtwt", "clk26m", 0),
70 	GATE_MM1(CLK_MM_MM_DPI0, "mm_dpi0", "mm_sel", 1),
71 	GATE_MM1(CLK_MM_LVDSTX_PXL, "mm_flvdstx_pxl", "vpll_dpix", 2),
72 	GATE_MM1(CLK_MM_LVDSTX_CTS, "mm_flvdstx_cts", "lvdstx_dig_cts", 3),
73 };
74 
75 static int clk_mt8365_mm_probe(struct platform_device *pdev)
76 {
77 	struct device *dev = &pdev->dev;
78 	struct device_node *node = dev->parent->of_node;
79 	struct clk_hw_onecell_data *clk_data;
80 	int ret;
81 
82 	clk_data = mtk_alloc_clk_data(CLK_MM_NR_CLK);
83 
84 	ret = mtk_clk_register_gates(dev, node, mm_clks,
85 				     ARRAY_SIZE(mm_clks), clk_data);
86 	if (ret)
87 		goto err_free_clk_data;
88 
89 	ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
90 	if (ret)
91 		goto err_unregister_gates;
92 
93 	return 0;
94 
95 err_unregister_gates:
96 	mtk_clk_unregister_gates(mm_clks, ARRAY_SIZE(mm_clks), clk_data);
97 
98 err_free_clk_data:
99 	mtk_free_clk_data(clk_data);
100 
101 	return ret;
102 }
103 
104 static struct platform_driver clk_mt8365_mm_drv = {
105 	.probe = clk_mt8365_mm_probe,
106 	.driver = {
107 		.name = "clk-mt8365-mm",
108 	},
109 };
110 builtin_platform_driver(clk_mt8365_mm_drv);
111 MODULE_LICENSE("GPL");
112