11802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
296596aa0SKevin-CW Chen /* Copyright (c) 2017 MediaTek Inc.
396596aa0SKevin-CW Chen  * Author: Kevin Chen <kevin-cw.chen@mediatek.com>
496596aa0SKevin-CW Chen  */
596596aa0SKevin-CW Chen 
696596aa0SKevin-CW Chen #include <linux/clk-provider.h>
796596aa0SKevin-CW Chen #include <linux/platform_device.h>
896596aa0SKevin-CW Chen #include <dt-bindings/clock/mt6797-clk.h>
996596aa0SKevin-CW Chen 
1096596aa0SKevin-CW Chen #include "clk-mtk.h"
1196596aa0SKevin-CW Chen #include "clk-gate.h"
1296596aa0SKevin-CW Chen 
1396596aa0SKevin-CW Chen static const struct mtk_gate_regs img_cg_regs = {
1496596aa0SKevin-CW Chen 	.set_ofs = 0x0004,
1596596aa0SKevin-CW Chen 	.clr_ofs = 0x0008,
1696596aa0SKevin-CW Chen 	.sta_ofs = 0x0000,
1796596aa0SKevin-CW Chen };
1896596aa0SKevin-CW Chen 
1996596aa0SKevin-CW Chen #define GATE_IMG(_id, _name, _parent, _shift) {		\
2096596aa0SKevin-CW Chen 		.id = _id,				\
2196596aa0SKevin-CW Chen 		.name = _name,				\
2296596aa0SKevin-CW Chen 		.parent_name = _parent,			\
2396596aa0SKevin-CW Chen 		.regs = &img_cg_regs,			\
2496596aa0SKevin-CW Chen 		.shift = _shift,			\
2596596aa0SKevin-CW Chen 		.ops = &mtk_clk_gate_ops_setclr,	\
2696596aa0SKevin-CW Chen 	}
2796596aa0SKevin-CW Chen 
2896596aa0SKevin-CW Chen static const struct mtk_gate img_clks[] = {
2996596aa0SKevin-CW Chen 	GATE_IMG(CLK_IMG_FDVT, "img_fdvt", "mm_sel", 11),
3096596aa0SKevin-CW Chen 	GATE_IMG(CLK_IMG_DPE, "img_dpe", "mm_sel", 10),
3196596aa0SKevin-CW Chen 	GATE_IMG(CLK_IMG_DIP, "img_dip", "mm_sel", 6),
3296596aa0SKevin-CW Chen 	GATE_IMG(CLK_IMG_LARB6, "img_larb6", "mm_sel", 0),
3396596aa0SKevin-CW Chen };
3496596aa0SKevin-CW Chen 
35*a481c6c7SMiles Chen static const struct mtk_clk_desc img_desc = {
36*a481c6c7SMiles Chen 	.clks = img_clks,
37*a481c6c7SMiles Chen 	.num_clks = ARRAY_SIZE(img_clks),
3896596aa0SKevin-CW Chen };
3996596aa0SKevin-CW Chen 
40*a481c6c7SMiles Chen static const struct of_device_id of_match_clk_mt6797_img[] = {
4196596aa0SKevin-CW Chen 	{
42*a481c6c7SMiles Chen 		.compatible = "mediatek,mt6797-imgsys",
43*a481c6c7SMiles Chen 		.data = &img_desc,
44*a481c6c7SMiles Chen 	}, {
45*a481c6c7SMiles Chen 		/* sentinel */
4696596aa0SKevin-CW Chen 	}
47*a481c6c7SMiles Chen };
4896596aa0SKevin-CW Chen 
4996596aa0SKevin-CW Chen static struct platform_driver clk_mt6797_img_drv = {
50*a481c6c7SMiles Chen 	.probe = mtk_clk_simple_probe,
51*a481c6c7SMiles Chen 	.remove = mtk_clk_simple_remove,
5296596aa0SKevin-CW Chen 	.driver = {
5396596aa0SKevin-CW Chen 		.name = "clk-mt6797-img",
5496596aa0SKevin-CW Chen 		.of_match_table = of_match_clk_mt6797_img,
5596596aa0SKevin-CW Chen 	},
5696596aa0SKevin-CW Chen };
5796596aa0SKevin-CW Chen 
5896596aa0SKevin-CW Chen builtin_platform_driver(clk_mt6797_img_drv);
59