162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2022 MediaTek Inc.
462306a36Sopenharmony_ci * Author: Garmin Chang <garmin.chang@mediatek.com>
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#include <dt-bindings/clock/mediatek,mt8188-clk.h>
862306a36Sopenharmony_ci#include <linux/clk-provider.h>
962306a36Sopenharmony_ci#include <linux/platform_device.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include "clk-gate.h"
1262306a36Sopenharmony_ci#include "clk-mtk.h"
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cistatic const struct mtk_gate_regs vdec0_cg_regs = {
1562306a36Sopenharmony_ci	.set_ofs = 0x0,
1662306a36Sopenharmony_ci	.clr_ofs = 0x4,
1762306a36Sopenharmony_ci	.sta_ofs = 0x0,
1862306a36Sopenharmony_ci};
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cistatic const struct mtk_gate_regs vdec1_cg_regs = {
2162306a36Sopenharmony_ci	.set_ofs = 0x200,
2262306a36Sopenharmony_ci	.clr_ofs = 0x204,
2362306a36Sopenharmony_ci	.sta_ofs = 0x200,
2462306a36Sopenharmony_ci};
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_cistatic const struct mtk_gate_regs vdec2_cg_regs = {
2762306a36Sopenharmony_ci	.set_ofs = 0x8,
2862306a36Sopenharmony_ci	.clr_ofs = 0xc,
2962306a36Sopenharmony_ci	.sta_ofs = 0x8,
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define GATE_VDEC0(_id, _name, _parent, _shift)			\
3362306a36Sopenharmony_ci	GATE_MTK(_id, _name, _parent, &vdec0_cg_regs, _shift, &mtk_clk_gate_ops_setclr_inv)
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define GATE_VDEC1(_id, _name, _parent, _shift)			\
3662306a36Sopenharmony_ci	GATE_MTK(_id, _name, _parent, &vdec1_cg_regs, _shift, &mtk_clk_gate_ops_setclr_inv)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define GATE_VDEC2(_id, _name, _parent, _shift)			\
3962306a36Sopenharmony_ci	GATE_MTK(_id, _name, _parent, &vdec2_cg_regs, _shift, &mtk_clk_gate_ops_setclr_inv)
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_cistatic const struct mtk_gate vdec1_clks[] = {
4262306a36Sopenharmony_ci	/* VDEC1_0 */
4362306a36Sopenharmony_ci	GATE_VDEC0(CLK_VDEC1_SOC_VDEC, "vdec1_soc_vdec", "top_vdec", 0),
4462306a36Sopenharmony_ci	GATE_VDEC0(CLK_VDEC1_SOC_VDEC_ACTIVE, "vdec1_soc_vdec_active", "top_vdec", 4),
4562306a36Sopenharmony_ci	GATE_VDEC0(CLK_VDEC1_SOC_VDEC_ENG, "vdec1_soc_vdec_eng", "top_vdec", 8),
4662306a36Sopenharmony_ci	/* VDEC1_1 */
4762306a36Sopenharmony_ci	GATE_VDEC1(CLK_VDEC1_SOC_LAT, "vdec1_soc_lat", "top_vdec", 0),
4862306a36Sopenharmony_ci	GATE_VDEC1(CLK_VDEC1_SOC_LAT_ACTIVE, "vdec1_soc_lat_active", "top_vdec", 4),
4962306a36Sopenharmony_ci	GATE_VDEC1(CLK_VDEC1_SOC_LAT_ENG, "vdec1_soc_lat_eng", "top_vdec", 8),
5062306a36Sopenharmony_ci	/* VDEC1_2 */
5162306a36Sopenharmony_ci	GATE_VDEC2(CLK_VDEC1_SOC_LARB1, "vdec1_soc_larb1", "top_vdec", 0),
5262306a36Sopenharmony_ci};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistatic const struct mtk_gate vdec2_clks[] = {
5562306a36Sopenharmony_ci	/* VDEC2_0 */
5662306a36Sopenharmony_ci	GATE_VDEC0(CLK_VDEC2_VDEC, "vdec2_vdec", "top_vdec", 0),
5762306a36Sopenharmony_ci	GATE_VDEC0(CLK_VDEC2_VDEC_ACTIVE, "vdec2_vdec_active", "top_vdec", 4),
5862306a36Sopenharmony_ci	GATE_VDEC0(CLK_VDEC2_VDEC_ENG, "vdec2_vdec_eng", "top_vdec", 8),
5962306a36Sopenharmony_ci	/* VDEC2_1 */
6062306a36Sopenharmony_ci	GATE_VDEC1(CLK_VDEC2_LAT, "vdec2_lat", "top_vdec", 0),
6162306a36Sopenharmony_ci	/* VDEC2_2 */
6262306a36Sopenharmony_ci	GATE_VDEC2(CLK_VDEC2_LARB1, "vdec2_larb1", "top_vdec", 0),
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistatic const struct mtk_clk_desc vdec1_desc = {
6662306a36Sopenharmony_ci	.clks = vdec1_clks,
6762306a36Sopenharmony_ci	.num_clks = ARRAY_SIZE(vdec1_clks),
6862306a36Sopenharmony_ci};
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistatic const struct mtk_clk_desc vdec2_desc = {
7162306a36Sopenharmony_ci	.clks = vdec2_clks,
7262306a36Sopenharmony_ci	.num_clks = ARRAY_SIZE(vdec2_clks),
7362306a36Sopenharmony_ci};
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_cistatic const struct of_device_id of_match_clk_mt8188_vdec[] = {
7662306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8188-vdecsys-soc", .data = &vdec1_desc },
7762306a36Sopenharmony_ci	{ .compatible = "mediatek,mt8188-vdecsys", .data = &vdec2_desc },
7862306a36Sopenharmony_ci	{ /* sentinel */ }
7962306a36Sopenharmony_ci};
8062306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, of_match_clk_mt8188_vdec);
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_cistatic struct platform_driver clk_mt8188_vdec_drv = {
8362306a36Sopenharmony_ci	.probe = mtk_clk_simple_probe,
8462306a36Sopenharmony_ci	.remove_new = mtk_clk_simple_remove,
8562306a36Sopenharmony_ci	.driver = {
8662306a36Sopenharmony_ci		.name = "clk-mt8188-vdec",
8762306a36Sopenharmony_ci		.of_match_table = of_match_clk_mt8188_vdec,
8862306a36Sopenharmony_ci	},
8962306a36Sopenharmony_ci};
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_cimodule_platform_driver(clk_mt8188_vdec_drv);
9262306a36Sopenharmony_ciMODULE_LICENSE("GPL");
93