clk-mt8195-vdo1.c (6342B)
1// SPDX-License-Identifier: GPL-2.0-only 2// 3// Copyright (c) 2021 MediaTek Inc. 4// Author: Chun-Jie Chen <chun-jie.chen@mediatek.com> 5 6#include "clk-gate.h" 7#include "clk-mtk.h" 8 9#include <dt-bindings/clock/mt8195-clk.h> 10#include <linux/clk-provider.h> 11#include <linux/platform_device.h> 12 13static const struct mtk_gate_regs vdo1_0_cg_regs = { 14 .set_ofs = 0x104, 15 .clr_ofs = 0x108, 16 .sta_ofs = 0x100, 17}; 18 19static const struct mtk_gate_regs vdo1_1_cg_regs = { 20 .set_ofs = 0x124, 21 .clr_ofs = 0x128, 22 .sta_ofs = 0x120, 23}; 24 25static const struct mtk_gate_regs vdo1_2_cg_regs = { 26 .set_ofs = 0x134, 27 .clr_ofs = 0x138, 28 .sta_ofs = 0x130, 29}; 30 31static const struct mtk_gate_regs vdo1_3_cg_regs = { 32 .set_ofs = 0x144, 33 .clr_ofs = 0x148, 34 .sta_ofs = 0x140, 35}; 36 37#define GATE_VDO1_0(_id, _name, _parent, _shift) \ 38 GATE_MTK(_id, _name, _parent, &vdo1_0_cg_regs, _shift, &mtk_clk_gate_ops_setclr) 39 40#define GATE_VDO1_1(_id, _name, _parent, _shift) \ 41 GATE_MTK(_id, _name, _parent, &vdo1_1_cg_regs, _shift, &mtk_clk_gate_ops_setclr) 42 43#define GATE_VDO1_2(_id, _name, _parent, _shift) \ 44 GATE_MTK(_id, _name, _parent, &vdo1_2_cg_regs, _shift, &mtk_clk_gate_ops_setclr) 45 46#define GATE_VDO1_3(_id, _name, _parent, _shift) \ 47 GATE_MTK(_id, _name, _parent, &vdo1_3_cg_regs, _shift, &mtk_clk_gate_ops_setclr) 48 49static const struct mtk_gate vdo1_clks[] = { 50 /* VDO1_0 */ 51 GATE_VDO1_0(CLK_VDO1_SMI_LARB2, "vdo1_smi_larb2", "top_vpp", 0), 52 GATE_VDO1_0(CLK_VDO1_SMI_LARB3, "vdo1_smi_larb3", "top_vpp", 1), 53 GATE_VDO1_0(CLK_VDO1_GALS, "vdo1_gals", "top_vpp", 2), 54 GATE_VDO1_0(CLK_VDO1_FAKE_ENG0, "vdo1_fake_eng0", "top_vpp", 3), 55 GATE_VDO1_0(CLK_VDO1_FAKE_ENG, "vdo1_fake_eng", "top_vpp", 4), 56 GATE_VDO1_0(CLK_VDO1_MDP_RDMA0, "vdo1_mdp_rdma0", "top_vpp", 5), 57 GATE_VDO1_0(CLK_VDO1_MDP_RDMA1, "vdo1_mdp_rdma1", "top_vpp", 6), 58 GATE_VDO1_0(CLK_VDO1_MDP_RDMA2, "vdo1_mdp_rdma2", "top_vpp", 7), 59 GATE_VDO1_0(CLK_VDO1_MDP_RDMA3, "vdo1_mdp_rdma3", "top_vpp", 8), 60 GATE_VDO1_0(CLK_VDO1_VPP_MERGE0, "vdo1_vpp_merge0", "top_vpp", 9), 61 GATE_VDO1_0(CLK_VDO1_VPP_MERGE1, "vdo1_vpp_merge1", "top_vpp", 10), 62 GATE_VDO1_0(CLK_VDO1_VPP_MERGE2, "vdo1_vpp_merge2", "top_vpp", 11), 63 GATE_VDO1_0(CLK_VDO1_VPP_MERGE3, "vdo1_vpp_merge3", "top_vpp", 12), 64 GATE_VDO1_0(CLK_VDO1_VPP_MERGE4, "vdo1_vpp_merge4", "top_vpp", 13), 65 GATE_VDO1_0(CLK_VDO1_VPP2_TO_VDO1_DL_ASYNC, "vdo1_vpp2_to_vdo1_dl_async", "top_vpp", 14), 66 GATE_VDO1_0(CLK_VDO1_VPP3_TO_VDO1_DL_ASYNC, "vdo1_vpp3_to_vdo1_dl_async", "top_vpp", 15), 67 GATE_VDO1_0(CLK_VDO1_DISP_MUTEX, "vdo1_disp_mutex", "top_vpp", 16), 68 GATE_VDO1_0(CLK_VDO1_MDP_RDMA4, "vdo1_mdp_rdma4", "top_vpp", 17), 69 GATE_VDO1_0(CLK_VDO1_MDP_RDMA5, "vdo1_mdp_rdma5", "top_vpp", 18), 70 GATE_VDO1_0(CLK_VDO1_MDP_RDMA6, "vdo1_mdp_rdma6", "top_vpp", 19), 71 GATE_VDO1_0(CLK_VDO1_MDP_RDMA7, "vdo1_mdp_rdma7", "top_vpp", 20), 72 GATE_VDO1_0(CLK_VDO1_DP_INTF0_MM, "vdo1_dp_intf0_mm", "top_vpp", 21), 73 GATE_VDO1_0(CLK_VDO1_DPI0_MM, "vdo1_dpi0_mm", "top_vpp", 22), 74 GATE_VDO1_0(CLK_VDO1_DPI1_MM, "vdo1_dpi1_mm", "top_vpp", 23), 75 GATE_VDO1_0(CLK_VDO1_DISP_MONITOR, "vdo1_disp_monitor", "top_vpp", 24), 76 GATE_VDO1_0(CLK_VDO1_MERGE0_DL_ASYNC, "vdo1_merge0_dl_async", "top_vpp", 25), 77 GATE_VDO1_0(CLK_VDO1_MERGE1_DL_ASYNC, "vdo1_merge1_dl_async", "top_vpp", 26), 78 GATE_VDO1_0(CLK_VDO1_MERGE2_DL_ASYNC, "vdo1_merge2_dl_async", "top_vpp", 27), 79 GATE_VDO1_0(CLK_VDO1_MERGE3_DL_ASYNC, "vdo1_merge3_dl_async", "top_vpp", 28), 80 GATE_VDO1_0(CLK_VDO1_MERGE4_DL_ASYNC, "vdo1_merge4_dl_async", "top_vpp", 29), 81 GATE_VDO1_0(CLK_VDO1_VDO0_DSC_TO_VDO1_DL_ASYNC, "vdo1_vdo0_dsc_to_vdo1_dl_async", 82 "top_vpp", 30), 83 GATE_VDO1_0(CLK_VDO1_VDO0_MERGE_TO_VDO1_DL_ASYNC, "vdo1_vdo0_merge_to_vdo1_dl_async", 84 "top_vpp", 31), 85 /* VDO1_1 */ 86 GATE_VDO1_1(CLK_VDO1_HDR_VDO_FE0, "vdo1_hdr_vdo_fe0", "top_vpp", 0), 87 GATE_VDO1_1(CLK_VDO1_HDR_GFX_FE0, "vdo1_hdr_gfx_fe0", "top_vpp", 1), 88 GATE_VDO1_1(CLK_VDO1_HDR_VDO_BE, "vdo1_hdr_vdo_be", "top_vpp", 2), 89 GATE_VDO1_1(CLK_VDO1_HDR_VDO_FE1, "vdo1_hdr_vdo_fe1", "top_vpp", 16), 90 GATE_VDO1_1(CLK_VDO1_HDR_GFX_FE1, "vdo1_hdr_gfx_fe1", "top_vpp", 17), 91 GATE_VDO1_1(CLK_VDO1_DISP_MIXER, "vdo1_disp_mixer", "top_vpp", 18), 92 GATE_VDO1_1(CLK_VDO1_HDR_VDO_FE0_DL_ASYNC, "vdo1_hdr_vdo_fe0_dl_async", "top_vpp", 19), 93 GATE_VDO1_1(CLK_VDO1_HDR_VDO_FE1_DL_ASYNC, "vdo1_hdr_vdo_fe1_dl_async", "top_vpp", 20), 94 GATE_VDO1_1(CLK_VDO1_HDR_GFX_FE0_DL_ASYNC, "vdo1_hdr_gfx_fe0_dl_async", "top_vpp", 21), 95 GATE_VDO1_1(CLK_VDO1_HDR_GFX_FE1_DL_ASYNC, "vdo1_hdr_gfx_fe1_dl_async", "top_vpp", 22), 96 GATE_VDO1_1(CLK_VDO1_HDR_VDO_BE_DL_ASYNC, "vdo1_hdr_vdo_be_dl_async", "top_vpp", 23), 97 /* VDO1_2 */ 98 GATE_VDO1_2(CLK_VDO1_DPI0, "vdo1_dpi0", "top_vpp", 0), 99 GATE_VDO1_2(CLK_VDO1_DISP_MONITOR_DPI0, "vdo1_disp_monitor_dpi0", "top_vpp", 1), 100 GATE_VDO1_2(CLK_VDO1_DPI1, "vdo1_dpi1", "top_vpp", 8), 101 GATE_VDO1_2(CLK_VDO1_DISP_MONITOR_DPI1, "vdo1_disp_monitor_dpi1", "top_vpp", 9), 102 GATE_VDO1_2(CLK_VDO1_DPINTF, "vdo1_dpintf", "top_vpp", 16), 103 GATE_VDO1_2(CLK_VDO1_DISP_MONITOR_DPINTF, "vdo1_disp_monitor_dpintf", "top_vpp", 17), 104 /* VDO1_3 */ 105 GATE_VDO1_3(CLK_VDO1_26M_SLOW, "vdo1_26m_slow", "clk26m", 8), 106}; 107 108static int clk_mt8195_vdo1_probe(struct platform_device *pdev) 109{ 110 struct device *dev = &pdev->dev; 111 struct device_node *node = dev->parent->of_node; 112 struct clk_hw_onecell_data *clk_data; 113 int r; 114 115 clk_data = mtk_alloc_clk_data(CLK_VDO1_NR_CLK); 116 if (!clk_data) 117 return -ENOMEM; 118 119 r = mtk_clk_register_gates(node, vdo1_clks, ARRAY_SIZE(vdo1_clks), clk_data); 120 if (r) 121 goto free_vdo1_data; 122 123 r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data); 124 if (r) 125 goto unregister_gates; 126 127 platform_set_drvdata(pdev, clk_data); 128 129 return r; 130 131unregister_gates: 132 mtk_clk_unregister_gates(vdo1_clks, ARRAY_SIZE(vdo1_clks), clk_data); 133free_vdo1_data: 134 mtk_free_clk_data(clk_data); 135 return r; 136} 137 138static int clk_mt8195_vdo1_remove(struct platform_device *pdev) 139{ 140 struct device *dev = &pdev->dev; 141 struct device_node *node = dev->parent->of_node; 142 struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev); 143 144 of_clk_del_provider(node); 145 mtk_clk_unregister_gates(vdo1_clks, ARRAY_SIZE(vdo1_clks), clk_data); 146 mtk_free_clk_data(clk_data); 147 148 return 0; 149} 150 151static struct platform_driver clk_mt8195_vdo1_drv = { 152 .probe = clk_mt8195_vdo1_probe, 153 .remove = clk_mt8195_vdo1_remove, 154 .driver = { 155 .name = "clk-mt8195-vdo1", 156 }, 157}; 158builtin_platform_driver(clk_mt8195_vdo1_drv);