| // SPDX-License-Identifier: GPL-2.0 |
| /* |
| * Copyright (c) 2022 MediaTek Inc. |
| * Author: Chong-ming Wei <chong-ming.wei@mediatek.com> |
| */ |
| |
| #include <linux/clk-provider.h> |
| #include <linux/module.h> |
| #include <linux/of_device.h> |
| #include <linux/platform_device.h> |
| |
| #include "clk-mtk.h" |
| #include "clk-gate.h" |
| |
| #include <dt-bindings/clock/mt6886-clk.h> |
| |
| #define MT_CCF_BRINGUP 1 |
| |
| /* Regular Number Definition */ |
| #define INV_OFS -1 |
| #define INV_BIT -1 |
| |
| static const struct mtk_gate_regs vde20_cg_regs = { |
| .set_ofs = 0x0, |
| .clr_ofs = 0x4, |
| .sta_ofs = 0x0, |
| }; |
| |
| static const struct mtk_gate_regs vde21_cg_regs = { |
| .set_ofs = 0x190, |
| .clr_ofs = 0x190, |
| .sta_ofs = 0x190, |
| }; |
| |
| static const struct mtk_gate_regs vde22_cg_regs = { |
| .set_ofs = 0x200, |
| .clr_ofs = 0x204, |
| .sta_ofs = 0x200, |
| }; |
| |
| static const struct mtk_gate_regs vde23_cg_regs = { |
| .set_ofs = 0x8, |
| .clr_ofs = 0xC, |
| .sta_ofs = 0x8, |
| }; |
| |
| #define GATE_VDE20(_id, _name, _parent, _shift) { \ |
| .id = _id, \ |
| .name = _name, \ |
| .parent_name = _parent, \ |
| .regs = &vde20_cg_regs, \ |
| .shift = _shift, \ |
| .ops = &mtk_clk_gate_ops_setclr_inv, \ |
| } |
| |
| #define GATE_VDE21(_id, _name, _parent, _shift) { \ |
| .id = _id, \ |
| .name = _name, \ |
| .parent_name = _parent, \ |
| .regs = &vde21_cg_regs, \ |
| .shift = _shift, \ |
| .ops = &mtk_clk_gate_ops_no_setclr_inv, \ |
| } |
| |
| #define GATE_VDE22(_id, _name, _parent, _shift) { \ |
| .id = _id, \ |
| .name = _name, \ |
| .parent_name = _parent, \ |
| .regs = &vde22_cg_regs, \ |
| .shift = _shift, \ |
| .ops = &mtk_clk_gate_ops_setclr_inv, \ |
| } |
| |
| #define GATE_VDE23(_id, _name, _parent, _shift) { \ |
| .id = _id, \ |
| .name = _name, \ |
| .parent_name = _parent, \ |
| .regs = &vde23_cg_regs, \ |
| .shift = _shift, \ |
| .ops = &mtk_clk_gate_ops_setclr_inv, \ |
| } |
| |
| static const struct mtk_gate vde2_clks[] = { |
| /* VDE20 */ |
| GATE_VDE20(CLK_VDE2_VDEC_CKEN, "vde2_vdec_cken", |
| "vdec_ck"/* parent */, 0), |
| GATE_VDE20(CLK_VDE2_VDEC_ACTIVE, "vde2_vdec_active", |
| "vdec_ck"/* parent */, 4), |
| /* VDE21 */ |
| GATE_VDE21(CLK_VDE2_MINI_MDP_EN, "vde2_mini_mdp_en", |
| "vdec_ck"/* parent */, 0), |
| /* VDE22 */ |
| GATE_VDE22(CLK_VDE2_LAT_CKEN, "vde2_lat_cken", |
| "vdec_ck"/* parent */, 0), |
| GATE_VDE22(CLK_VDE2_LAT_ACTIVE, "vde2_lat_active", |
| "vdec_ck"/* parent */, 4), |
| /* VDE23 */ |
| GATE_VDE23(CLK_VDE2_LARB1_CKEN, "vde2_larb1_cken", |
| "vdec_ck"/* parent */, 0), |
| }; |
| |
| static const struct mtk_clk_desc vde2_mcd = { |
| .clks = vde2_clks, |
| .num_clks = CLK_VDE2_NR_CLK, |
| }; |
| |
| static const struct mtk_gate_regs ven_cg_regs = { |
| .set_ofs = 0x4, |
| .clr_ofs = 0x8, |
| .sta_ofs = 0x0, |
| }; |
| |
| #define GATE_VEN(_id, _name, _parent, _shift) { \ |
| .id = _id, \ |
| .name = _name, \ |
| .parent_name = _parent, \ |
| .regs = &ven_cg_regs, \ |
| .shift = _shift, \ |
| .ops = &mtk_clk_gate_ops_setclr_inv, \ |
| } |
| |
| static const struct mtk_gate ven_clks[] = { |
| GATE_VEN(CLK_VEN_CKE0_LARB, "ven_larb", |
| "venc_ck"/* parent */, 0), |
| GATE_VEN(CLK_VEN_CKE1_VENC, "ven_venc", |
| "venc_ck"/* parent */, 4), |
| GATE_VEN(CLK_VEN_CKE2_JPGENC, "ven_jpgenc", |
| "venc_ck"/* parent */, 8), |
| GATE_VEN(CLK_VEN_CKE5_GALS, "ven_gals", |
| "venc_ck"/* parent */, 28), |
| GATE_VEN(CLK_VEN_CKE6_GALS_SRAM, "ven_gals_sram", |
| "venc_ck"/* parent */, 31), |
| }; |
| |
| static const struct mtk_clk_desc ven_mcd = { |
| .clks = ven_clks, |
| .num_clks = CLK_VEN_NR_CLK, |
| }; |
| |
| static const struct of_device_id of_match_clk_mt6886_vcodec[] = { |
| { |
| .compatible = "mediatek,mt6886-vdecsys", |
| .data = &vde2_mcd, |
| }, { |
| .compatible = "mediatek,mt6886-vencsys", |
| .data = &ven_mcd, |
| }, { |
| /* sentinel */ |
| } |
| }; |
| |
| |
| static int clk_mt6886_vcodec_grp_probe(struct platform_device *pdev) |
| { |
| int r; |
| |
| #if MT_CCF_BRINGUP |
| pr_notice("%s: %s init begin\n", __func__, pdev->name); |
| #endif |
| |
| r = mtk_clk_simple_probe(pdev); |
| if (r) |
| dev_err(&pdev->dev, |
| "could not register clock provider: %s: %d\n", |
| pdev->name, r); |
| |
| #if MT_CCF_BRINGUP |
| pr_notice("%s: %s init end\n", __func__, pdev->name); |
| #endif |
| |
| return r; |
| } |
| |
| static struct platform_driver clk_mt6886_vcodec_drv = { |
| .probe = clk_mt6886_vcodec_grp_probe, |
| .driver = { |
| .name = "clk-mt6886-vcodec", |
| .of_match_table = of_match_clk_mt6886_vcodec, |
| }, |
| }; |
| |
| module_platform_driver(clk_mt6886_vcodec_drv); |
| MODULE_LICENSE("GPL"); |