xref: /linux/drivers/clk/mediatek/clk-mt8195-vpp1.c (revision b132c2a8ea115cf2353acf1e1ba06c71a46aead0)
150df7722SChun-Jie Chen // SPDX-License-Identifier: GPL-2.0-only
250df7722SChun-Jie Chen //
350df7722SChun-Jie Chen // Copyright (c) 2021 MediaTek Inc.
450df7722SChun-Jie Chen // Author: Chun-Jie Chen <chun-jie.chen@mediatek.com>
550df7722SChun-Jie Chen 
650df7722SChun-Jie Chen #include "clk-gate.h"
750df7722SChun-Jie Chen #include "clk-mtk.h"
850df7722SChun-Jie Chen 
950df7722SChun-Jie Chen #include <dt-bindings/clock/mt8195-clk.h>
1050df7722SChun-Jie Chen #include <linux/clk-provider.h>
1150df7722SChun-Jie Chen #include <linux/platform_device.h>
1250df7722SChun-Jie Chen 
1350df7722SChun-Jie Chen static const struct mtk_gate_regs vpp1_0_cg_regs = {
1450df7722SChun-Jie Chen 	.set_ofs = 0x104,
1550df7722SChun-Jie Chen 	.clr_ofs = 0x108,
1650df7722SChun-Jie Chen 	.sta_ofs = 0x100,
1750df7722SChun-Jie Chen };
1850df7722SChun-Jie Chen 
1950df7722SChun-Jie Chen static const struct mtk_gate_regs vpp1_1_cg_regs = {
2050df7722SChun-Jie Chen 	.set_ofs = 0x114,
2150df7722SChun-Jie Chen 	.clr_ofs = 0x118,
2250df7722SChun-Jie Chen 	.sta_ofs = 0x110,
2350df7722SChun-Jie Chen };
2450df7722SChun-Jie Chen 
2550df7722SChun-Jie Chen #define GATE_VPP1_0(_id, _name, _parent, _shift)			\
2650df7722SChun-Jie Chen 	GATE_MTK(_id, _name, _parent, &vpp1_0_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
2750df7722SChun-Jie Chen 
2850df7722SChun-Jie Chen #define GATE_VPP1_1(_id, _name, _parent, _shift)			\
2950df7722SChun-Jie Chen 	GATE_MTK(_id, _name, _parent, &vpp1_1_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
3050df7722SChun-Jie Chen 
3150df7722SChun-Jie Chen static const struct mtk_gate vpp1_clks[] = {
3250df7722SChun-Jie Chen 	/* VPP1_0 */
3350df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_MDP_OVL, "vpp1_svpp1_mdp_ovl", "top_vpp", 0),
3450df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_MDP_TCC, "vpp1_svpp1_mdp_tcc", "top_vpp", 1),
3550df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_MDP_WROT, "vpp1_svpp1_mdp_wrot", "top_vpp", 2),
3650df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_VPP_PAD, "vpp1_svpp1_vpp_pad", "top_vpp", 3),
3750df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP2_MDP_WROT, "vpp1_svpp2_mdp_wrot", "top_vpp", 4),
3850df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP2_VPP_PAD, "vpp1_svpp2_vpp_pad", "top_vpp", 5),
3950df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP3_MDP_WROT, "vpp1_svpp3_mdp_wrot", "top_vpp", 6),
4050df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP3_VPP_PAD, "vpp1_svpp3_vpp_pad", "top_vpp", 7),
4150df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_MDP_RDMA, "vpp1_svpp1_mdp_rdma", "top_vpp", 8),
4250df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_MDP_FG, "vpp1_svpp1_mdp_fg", "top_vpp", 9),
4350df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP2_MDP_RDMA, "vpp1_svpp2_mdp_rdma", "top_vpp", 10),
4450df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP2_MDP_FG, "vpp1_svpp2_mdp_fg", "top_vpp", 11),
4550df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP3_MDP_RDMA, "vpp1_svpp3_mdp_rdma", "top_vpp", 12),
4650df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP3_MDP_FG, "vpp1_svpp3_mdp_fg", "top_vpp", 13),
4750df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_VPP_SPLIT, "vpp1_vpp_split", "top_vpp", 14),
4850df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP2_VDO0_DL_RELAY, "vpp1_svpp2_vdo0_dl_relay", "top_vpp", 15),
4950df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_MDP_TDSHP, "vpp1_svpp1_mdp_tdshp", "top_vpp", 16),
5050df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_MDP_COLOR, "vpp1_svpp1_mdp_color", "top_vpp", 17),
5150df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP3_VDO1_DL_RELAY, "vpp1_svpp3_vdo1_dl_relay", "top_vpp", 18),
5250df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP2_VPP_MERGE, "vpp1_svpp2_vpp_merge", "top_vpp", 19),
5350df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP2_MDP_COLOR, "vpp1_svpp2_mdp_color", "top_vpp", 20),
5450df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_VPPSYS1_GALS, "vpp1_vppsys1_gals", "top_vpp", 21),
5550df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP3_VPP_MERGE, "vpp1_svpp3_vpp_merge", "top_vpp", 22),
5650df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP3_MDP_COLOR, "vpp1_svpp3_mdp_color", "top_vpp", 23),
5750df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_VPPSYS1_LARB, "vpp1_vppsys1_larb", "top_vpp", 24),
5850df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_MDP_RSZ, "vpp1_svpp1_mdp_rsz", "top_vpp", 25),
5950df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_MDP_HDR, "vpp1_svpp1_mdp_hdr", "top_vpp", 26),
6050df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP1_MDP_AAL, "vpp1_svpp1_mdp_aal", "top_vpp", 27),
6150df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP2_MDP_HDR, "vpp1_svpp2_mdp_hdr", "top_vpp", 28),
6250df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_SVPP2_MDP_AAL, "vpp1_svpp2_mdp_aal", "top_vpp", 29),
6350df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_DL_ASYNC, "vpp1_dl_async", "top_vpp", 30),
6450df7722SChun-Jie Chen 	GATE_VPP1_0(CLK_VPP1_LARB5_FAKE_ENG, "vpp1_larb5_fake_eng", "top_vpp", 31),
6550df7722SChun-Jie Chen 	/* VPP1_1 */
6650df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_SVPP3_MDP_HDR, "vpp1_svpp3_mdp_hdr", "top_vpp", 0),
6750df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_SVPP3_MDP_AAL, "vpp1_svpp3_mdp_aal", "top_vpp", 1),
6850df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_SVPP2_VDO1_DL_RELAY, "vpp1_svpp2_vdo1_dl_relay", "top_vpp", 2),
6950df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_LARB6_FAKE_ENG, "vpp1_larb6_fake_eng", "top_vpp", 3),
7050df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_SVPP2_MDP_RSZ, "vpp1_svpp2_mdp_rsz", "top_vpp", 4),
7150df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_SVPP3_MDP_RSZ, "vpp1_svpp3_mdp_rsz", "top_vpp", 5),
7250df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_SVPP3_VDO0_DL_RELAY, "vpp1_svpp3_vdo0_dl_relay", "top_vpp", 6),
7350df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_DISP_MUTEX, "vpp1_disp_mutex", "top_vpp", 7),
7450df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_SVPP2_MDP_TDSHP, "vpp1_svpp2_mdp_tdshp", "top_vpp", 8),
7550df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_SVPP3_MDP_TDSHP, "vpp1_svpp3_mdp_tdshp", "top_vpp", 9),
7650df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_VPP0_DL1_RELAY, "vpp1_vpp0_dl1_relay", "top_vpp", 10),
7750df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_HDMI_META, "vpp1_hdmi_meta", "hdmirx_p", 11),
7850df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_VPP_SPLIT_HDMI, "vpp1_vpp_split_hdmi", "hdmirx_p", 12),
7950df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_DGI_IN, "vpp1_dgi_in", "in_dgi", 13),
8050df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_DGI_OUT, "vpp1_dgi_out", "top_dgi_out", 14),
8150df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_VPP_SPLIT_DGI, "vpp1_vpp_split_dgi", "top_dgi_out", 15),
8250df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_VPP0_DL_ASYNC, "vpp1_vpp0_dl_async", "top_vpp", 16),
8350df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_VPP0_DL_RELAY, "vpp1_vpp0_dl_relay", "top_vpp", 17),
8450df7722SChun-Jie Chen 	GATE_VPP1_1(CLK_VPP1_VPP_SPLIT_26M, "vpp1_vpp_split_26m", "clk26m", 26),
8550df7722SChun-Jie Chen };
8650df7722SChun-Jie Chen 
87*b132c2a8SMoudy Ho static int clk_mt8195_vpp1_probe(struct platform_device *pdev)
8850df7722SChun-Jie Chen {
89*b132c2a8SMoudy Ho 	struct device *dev = &pdev->dev;
90*b132c2a8SMoudy Ho 	struct device_node *node = dev->parent->of_node;
91*b132c2a8SMoudy Ho 	struct clk_hw_onecell_data *clk_data;
92*b132c2a8SMoudy Ho 	int r;
93*b132c2a8SMoudy Ho 
94*b132c2a8SMoudy Ho 	clk_data = mtk_alloc_clk_data(CLK_VPP1_NR_CLK);
95*b132c2a8SMoudy Ho 	if (!clk_data)
96*b132c2a8SMoudy Ho 		return -ENOMEM;
97*b132c2a8SMoudy Ho 
98*b132c2a8SMoudy Ho 	r = mtk_clk_register_gates(dev, node, vpp1_clks, ARRAY_SIZE(vpp1_clks), clk_data);
99*b132c2a8SMoudy Ho 	if (r)
100*b132c2a8SMoudy Ho 		goto free_vpp1_data;
101*b132c2a8SMoudy Ho 
102*b132c2a8SMoudy Ho 	r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
103*b132c2a8SMoudy Ho 	if (r)
104*b132c2a8SMoudy Ho 		goto unregister_gates;
105*b132c2a8SMoudy Ho 
106*b132c2a8SMoudy Ho 	platform_set_drvdata(pdev, clk_data);
107*b132c2a8SMoudy Ho 
108*b132c2a8SMoudy Ho 	return r;
109*b132c2a8SMoudy Ho 
110*b132c2a8SMoudy Ho unregister_gates:
111*b132c2a8SMoudy Ho 	mtk_clk_unregister_gates(vpp1_clks, ARRAY_SIZE(vpp1_clks), clk_data);
112*b132c2a8SMoudy Ho free_vpp1_data:
113*b132c2a8SMoudy Ho 	mtk_free_clk_data(clk_data);
114*b132c2a8SMoudy Ho 	return r;
11550df7722SChun-Jie Chen }
116*b132c2a8SMoudy Ho 
117*b132c2a8SMoudy Ho static int clk_mt8195_vpp1_remove(struct platform_device *pdev)
118*b132c2a8SMoudy Ho {
119*b132c2a8SMoudy Ho 	struct device *dev = &pdev->dev;
120*b132c2a8SMoudy Ho 	struct device_node *node = dev->parent->of_node;
121*b132c2a8SMoudy Ho 	struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
122*b132c2a8SMoudy Ho 
123*b132c2a8SMoudy Ho 	of_clk_del_provider(node);
124*b132c2a8SMoudy Ho 	mtk_clk_unregister_gates(vpp1_clks, ARRAY_SIZE(vpp1_clks), clk_data);
125*b132c2a8SMoudy Ho 	mtk_free_clk_data(clk_data);
126*b132c2a8SMoudy Ho 
127*b132c2a8SMoudy Ho 	return 0;
128*b132c2a8SMoudy Ho }
12950df7722SChun-Jie Chen 
13050df7722SChun-Jie Chen static struct platform_driver clk_mt8195_vpp1_drv = {
131*b132c2a8SMoudy Ho 	.probe = clk_mt8195_vpp1_probe,
132*b132c2a8SMoudy Ho 	.remove = clk_mt8195_vpp1_remove,
13350df7722SChun-Jie Chen 	.driver = {
13450df7722SChun-Jie Chen 		.name = "clk-mt8195-vpp1",
13550df7722SChun-Jie Chen 	},
13650df7722SChun-Jie Chen };
13750df7722SChun-Jie Chen builtin_platform_driver(clk_mt8195_vpp1_drv);
138