18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2017 MediaTek Inc.
48c2ecf20Sopenharmony_ci * Author: Weiyi Lu <weiyi.lu@mediatek.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
88c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include "clk-mtk.h"
118c2ecf20Sopenharmony_ci#include "clk-gate.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <dt-bindings/clock/mt2712-clk.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs bdp_cg_regs = {
168c2ecf20Sopenharmony_ci	.set_ofs = 0x100,
178c2ecf20Sopenharmony_ci	.clr_ofs = 0x100,
188c2ecf20Sopenharmony_ci	.sta_ofs = 0x100,
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define GATE_BDP(_id, _name, _parent, _shift) {	\
228c2ecf20Sopenharmony_ci		.id = _id,				\
238c2ecf20Sopenharmony_ci		.name = _name,				\
248c2ecf20Sopenharmony_ci		.parent_name = _parent,			\
258c2ecf20Sopenharmony_ci		.regs = &bdp_cg_regs,			\
268c2ecf20Sopenharmony_ci		.shift = _shift,			\
278c2ecf20Sopenharmony_ci		.ops = &mtk_clk_gate_ops_no_setclr,	\
288c2ecf20Sopenharmony_ci	}
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic const struct mtk_gate bdp_clks[] = {
318c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_BRIDGE_B, "bdp_bridge_b", "mm_sel", 0),
328c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_BRIDGE_DRAM, "bdp_bridge_d", "mm_sel", 1),
338c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_LARB_DRAM, "bdp_larb_d", "mm_sel", 2),
348c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_WR_CHANNEL_VDI_PXL, "bdp_vdi_pxl", "tvd_sel", 3),
358c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_WR_CHANNEL_VDI_DRAM, "bdp_vdi_d", "mm_sel", 4),
368c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_WR_CHANNEL_VDI_B, "bdp_vdi_b", "mm_sel", 5),
378c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_MT_B, "bdp_fmt_b", "mm_sel", 9),
388c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_DISPFMT_27M, "bdp_27m", "di_sel", 10),
398c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_DISPFMT_27M_VDOUT, "bdp_27m_vdout", "di_sel", 11),
408c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_DISPFMT_27_74_74, "bdp_27_74_74", "di_sel", 12),
418c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_DISPFMT_2FS, "bdp_2fs", "di_sel", 13),
428c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_DISPFMT_2FS_2FS74_148, "bdp_2fs74_148", "di_sel", 14),
438c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_DISPFMT_B, "bdp_b", "mm_sel", 15),
448c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_VDO_DRAM, "bdp_vdo_d", "mm_sel", 16),
458c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_VDO_2FS, "bdp_vdo_2fs", "di_sel", 17),
468c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_VDO_B, "bdp_vdo_b", "mm_sel", 18),
478c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_WR_CHANNEL_DI_PXL, "bdp_di_pxl", "di_sel", 19),
488c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_WR_CHANNEL_DI_DRAM, "bdp_di_d", "mm_sel", 20),
498c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_WR_CHANNEL_DI_B, "bdp_di_b", "mm_sel", 21),
508c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_NR_AGENT, "bdp_nr_agent", "nr_sel", 22),
518c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_NR_DRAM, "bdp_nr_d", "mm_sel", 23),
528c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_NR_B, "bdp_nr_b", "mm_sel", 24),
538c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_BRIDGE_RT_B, "bdp_bridge_rt_b", "mm_sel", 25),
548c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_BRIDGE_RT_DRAM, "bdp_bridge_rt_d", "mm_sel", 26),
558c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_LARB_RT_DRAM, "bdp_larb_rt_d", "mm_sel", 27),
568c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_TVD_TDC, "bdp_tvd_tdc", "mm_sel", 28),
578c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_TVD_54, "bdp_tvd_clk_54", "tvd_sel", 29),
588c2ecf20Sopenharmony_ci	GATE_BDP(CLK_BDP_TVD_CBUS, "bdp_tvd_cbus", "mm_sel", 30),
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic int clk_mt2712_bdp_probe(struct platform_device *pdev)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci	struct clk_onecell_data *clk_data;
648c2ecf20Sopenharmony_ci	int r;
658c2ecf20Sopenharmony_ci	struct device_node *node = pdev->dev.of_node;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	clk_data = mtk_alloc_clk_data(CLK_BDP_NR_CLK);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	mtk_clk_register_gates(node, bdp_clks, ARRAY_SIZE(bdp_clks),
708c2ecf20Sopenharmony_ci			clk_data);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	if (r != 0)
758c2ecf20Sopenharmony_ci		pr_err("%s(): could not register clock provider: %d\n",
768c2ecf20Sopenharmony_ci			__func__, r);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	return r;
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistatic const struct of_device_id of_match_clk_mt2712_bdp[] = {
828c2ecf20Sopenharmony_ci	{ .compatible = "mediatek,mt2712-bdpsys", },
838c2ecf20Sopenharmony_ci	{}
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistatic struct platform_driver clk_mt2712_bdp_drv = {
878c2ecf20Sopenharmony_ci	.probe = clk_mt2712_bdp_probe,
888c2ecf20Sopenharmony_ci	.driver = {
898c2ecf20Sopenharmony_ci		.name = "clk-mt2712-bdp",
908c2ecf20Sopenharmony_ci		.of_match_table = of_match_clk_mt2712_bdp,
918c2ecf20Sopenharmony_ci	},
928c2ecf20Sopenharmony_ci};
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cibuiltin_platform_driver(clk_mt2712_bdp_drv);
95