xref: /OK3568_Linux_fs/kernel/drivers/clk/mediatek/clk-mt8183-ipu_conn.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun //
3*4882a593Smuzhiyun // Copyright (c) 2018 MediaTek Inc.
4*4882a593Smuzhiyun // Author: Weiyi Lu <weiyi.lu@mediatek.com>
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #include <linux/clk-provider.h>
7*4882a593Smuzhiyun #include <linux/platform_device.h>
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include "clk-mtk.h"
10*4882a593Smuzhiyun #include "clk-gate.h"
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <dt-bindings/clock/mt8183-clk.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun static const struct mtk_gate_regs ipu_conn_cg_regs = {
15*4882a593Smuzhiyun 	.set_ofs = 0x4,
16*4882a593Smuzhiyun 	.clr_ofs = 0x8,
17*4882a593Smuzhiyun 	.sta_ofs = 0x0,
18*4882a593Smuzhiyun };
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun static const struct mtk_gate_regs ipu_conn_apb_cg_regs = {
21*4882a593Smuzhiyun 	.set_ofs = 0x10,
22*4882a593Smuzhiyun 	.clr_ofs = 0x10,
23*4882a593Smuzhiyun 	.sta_ofs = 0x10,
24*4882a593Smuzhiyun };
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun static const struct mtk_gate_regs ipu_conn_axi_cg_regs = {
27*4882a593Smuzhiyun 	.set_ofs = 0x18,
28*4882a593Smuzhiyun 	.clr_ofs = 0x18,
29*4882a593Smuzhiyun 	.sta_ofs = 0x18,
30*4882a593Smuzhiyun };
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun static const struct mtk_gate_regs ipu_conn_axi1_cg_regs = {
33*4882a593Smuzhiyun 	.set_ofs = 0x1c,
34*4882a593Smuzhiyun 	.clr_ofs = 0x1c,
35*4882a593Smuzhiyun 	.sta_ofs = 0x1c,
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun static const struct mtk_gate_regs ipu_conn_axi2_cg_regs = {
39*4882a593Smuzhiyun 	.set_ofs = 0x20,
40*4882a593Smuzhiyun 	.clr_ofs = 0x20,
41*4882a593Smuzhiyun 	.sta_ofs = 0x20,
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #define GATE_IPU_CONN(_id, _name, _parent, _shift)			\
45*4882a593Smuzhiyun 	GATE_MTK(_id, _name, _parent, &ipu_conn_cg_regs, _shift,	\
46*4882a593Smuzhiyun 		&mtk_clk_gate_ops_setclr)
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #define GATE_IPU_CONN_APB(_id, _name, _parent, _shift)			\
49*4882a593Smuzhiyun 	GATE_MTK(_id, _name, _parent, &ipu_conn_apb_cg_regs, _shift,	\
50*4882a593Smuzhiyun 		&mtk_clk_gate_ops_no_setclr)
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #define GATE_IPU_CONN_AXI_I(_id, _name, _parent, _shift)		\
53*4882a593Smuzhiyun 	GATE_MTK(_id, _name, _parent, &ipu_conn_axi_cg_regs, _shift,	\
54*4882a593Smuzhiyun 		&mtk_clk_gate_ops_no_setclr_inv)
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #define GATE_IPU_CONN_AXI1_I(_id, _name, _parent, _shift)		\
57*4882a593Smuzhiyun 	GATE_MTK(_id, _name, _parent, &ipu_conn_axi1_cg_regs, _shift,	\
58*4882a593Smuzhiyun 		&mtk_clk_gate_ops_no_setclr_inv)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun #define GATE_IPU_CONN_AXI2_I(_id, _name, _parent, _shift)		\
61*4882a593Smuzhiyun 	GATE_MTK(_id, _name, _parent, &ipu_conn_axi2_cg_regs, _shift,	\
62*4882a593Smuzhiyun 		&mtk_clk_gate_ops_no_setclr_inv)
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun static const struct mtk_gate ipu_conn_clks[] = {
65*4882a593Smuzhiyun 	GATE_IPU_CONN(CLK_IPU_CONN_IPU,
66*4882a593Smuzhiyun 		"ipu_conn_ipu", "dsp_sel", 0),
67*4882a593Smuzhiyun 	GATE_IPU_CONN(CLK_IPU_CONN_AHB,
68*4882a593Smuzhiyun 		"ipu_conn_ahb", "dsp_sel", 1),
69*4882a593Smuzhiyun 	GATE_IPU_CONN(CLK_IPU_CONN_AXI,
70*4882a593Smuzhiyun 		"ipu_conn_axi", "dsp_sel", 2),
71*4882a593Smuzhiyun 	GATE_IPU_CONN(CLK_IPU_CONN_ISP,
72*4882a593Smuzhiyun 		"ipu_conn_isp", "dsp_sel", 3),
73*4882a593Smuzhiyun 	GATE_IPU_CONN(CLK_IPU_CONN_CAM_ADL,
74*4882a593Smuzhiyun 		"ipu_conn_cam_adl", "dsp_sel", 4),
75*4882a593Smuzhiyun 	GATE_IPU_CONN(CLK_IPU_CONN_IMG_ADL,
76*4882a593Smuzhiyun 		"ipu_conn_img_adl", "dsp_sel", 5),
77*4882a593Smuzhiyun 	GATE_IPU_CONN_APB(CLK_IPU_CONN_DAP_RX,
78*4882a593Smuzhiyun 		"ipu_conn_dap_rx", "dsp1_sel", 0),
79*4882a593Smuzhiyun 	GATE_IPU_CONN_APB(CLK_IPU_CONN_APB2AXI,
80*4882a593Smuzhiyun 		"ipu_conn_apb2axi", "dsp1_sel", 3),
81*4882a593Smuzhiyun 	GATE_IPU_CONN_APB(CLK_IPU_CONN_APB2AHB,
82*4882a593Smuzhiyun 		"ipu_conn_apb2ahb", "dsp1_sel", 20),
83*4882a593Smuzhiyun 	GATE_IPU_CONN_AXI_I(CLK_IPU_CONN_IPU_CAB1TO2,
84*4882a593Smuzhiyun 		"ipu_conn_ipu_cab1to2", "dsp1_sel", 6),
85*4882a593Smuzhiyun 	GATE_IPU_CONN_AXI_I(CLK_IPU_CONN_IPU1_CAB1TO2,
86*4882a593Smuzhiyun 		"ipu_conn_ipu1_cab1to2", "dsp1_sel", 13),
87*4882a593Smuzhiyun 	GATE_IPU_CONN_AXI_I(CLK_IPU_CONN_IPU2_CAB1TO2,
88*4882a593Smuzhiyun 		"ipu_conn_ipu2_cab1to2", "dsp1_sel", 20),
89*4882a593Smuzhiyun 	GATE_IPU_CONN_AXI1_I(CLK_IPU_CONN_CAB3TO3,
90*4882a593Smuzhiyun 		"ipu_conn_cab3to3", "dsp1_sel", 0),
91*4882a593Smuzhiyun 	GATE_IPU_CONN_AXI2_I(CLK_IPU_CONN_CAB2TO1,
92*4882a593Smuzhiyun 		"ipu_conn_cab2to1", "dsp1_sel", 14),
93*4882a593Smuzhiyun 	GATE_IPU_CONN_AXI2_I(CLK_IPU_CONN_CAB3TO1_SLICE,
94*4882a593Smuzhiyun 		"ipu_conn_cab3to1_slice", "dsp1_sel", 17),
95*4882a593Smuzhiyun };
96*4882a593Smuzhiyun 
clk_mt8183_ipu_conn_probe(struct platform_device * pdev)97*4882a593Smuzhiyun static int clk_mt8183_ipu_conn_probe(struct platform_device *pdev)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun 	struct clk_onecell_data *clk_data;
100*4882a593Smuzhiyun 	struct device_node *node = pdev->dev.of_node;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	clk_data = mtk_alloc_clk_data(CLK_IPU_CONN_NR_CLK);
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	mtk_clk_register_gates(node, ipu_conn_clks, ARRAY_SIZE(ipu_conn_clks),
105*4882a593Smuzhiyun 			clk_data);
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun static const struct of_device_id of_match_clk_mt8183_ipu_conn[] = {
111*4882a593Smuzhiyun 	{ .compatible = "mediatek,mt8183-ipu_conn", },
112*4882a593Smuzhiyun 	{}
113*4882a593Smuzhiyun };
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun static struct platform_driver clk_mt8183_ipu_conn_drv = {
116*4882a593Smuzhiyun 	.probe = clk_mt8183_ipu_conn_probe,
117*4882a593Smuzhiyun 	.driver = {
118*4882a593Smuzhiyun 		.name = "clk-mt8183-ipu_conn",
119*4882a593Smuzhiyun 		.of_match_table = of_match_clk_mt8183_ipu_conn,
120*4882a593Smuzhiyun 	},
121*4882a593Smuzhiyun };
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun builtin_platform_driver(clk_mt8183_ipu_conn_drv);
124