xref: /linux/drivers/clk/mediatek/clk-mt8188-cam.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2022 MediaTek Inc.
4  * Author: Garmin Chang <garmin.chang@mediatek.com>
5  */
6 
7 #include <dt-bindings/clock/mediatek,mt8188-clk.h>
8 #include <linux/clk-provider.h>
9 #include <linux/platform_device.h>
10 
11 #include "clk-gate.h"
12 #include "clk-mtk.h"
13 
14 static const struct mtk_gate_regs cam_cg_regs = {
15 	.set_ofs = 0x4,
16 	.clr_ofs = 0x8,
17 	.sta_ofs = 0x0,
18 };
19 
20 #define GATE_CAM(_id, _name, _parent, _shift)			\
21 	GATE_MTK(_id, _name, _parent, &cam_cg_regs, _shift, &mtk_clk_gate_ops_setclr)
22 
23 static const struct mtk_gate cam_main_clks[] = {
24 	GATE_CAM(CLK_CAM_MAIN_LARB13, "cam_main_larb13", "top_cam", 0),
25 	GATE_CAM(CLK_CAM_MAIN_LARB14, "cam_main_larb14", "top_cam", 1),
26 	GATE_CAM(CLK_CAM_MAIN_CAM, "cam_main_cam", "top_cam", 2),
27 	GATE_CAM(CLK_CAM_MAIN_CAM_SUBA, "cam_main_cam_suba", "top_cam", 3),
28 	GATE_CAM(CLK_CAM_MAIN_CAM_SUBB, "cam_main_cam_subb", "top_cam", 4),
29 	GATE_CAM(CLK_CAM_MAIN_CAMTG, "cam_main_camtg", "top_cam", 7),
30 	GATE_CAM(CLK_CAM_MAIN_SENINF, "cam_main_seninf", "top_cam", 8),
31 	GATE_CAM(CLK_CAM_MAIN_GCAMSVA, "cam_main_gcamsva", "top_cam", 9),
32 	GATE_CAM(CLK_CAM_MAIN_GCAMSVB, "cam_main_gcamsvb", "top_cam", 10),
33 	GATE_CAM(CLK_CAM_MAIN_GCAMSVC, "cam_main_gcamsvc", "top_cam", 11),
34 	GATE_CAM(CLK_CAM_MAIN_GCAMSVD, "cam_main_gcamsvd", "top_cam", 12),
35 	GATE_CAM(CLK_CAM_MAIN_GCAMSVE, "cam_main_gcamsve", "top_cam", 13),
36 	GATE_CAM(CLK_CAM_MAIN_GCAMSVF, "cam_main_gcamsvf", "top_cam", 14),
37 	GATE_CAM(CLK_CAM_MAIN_GCAMSVG, "cam_main_gcamsvg", "top_cam", 15),
38 	GATE_CAM(CLK_CAM_MAIN_GCAMSVH, "cam_main_gcamsvh", "top_cam", 16),
39 	GATE_CAM(CLK_CAM_MAIN_GCAMSVI, "cam_main_gcamsvi", "top_cam", 17),
40 	GATE_CAM(CLK_CAM_MAIN_GCAMSVJ, "cam_main_gcamsvj", "top_cam", 18),
41 	GATE_CAM(CLK_CAM_MAIN_CAMSV_TOP, "cam_main_camsv", "top_cam", 19),
42 	GATE_CAM(CLK_CAM_MAIN_CAMSV_CQ_A, "cam_main_camsv_cq_a", "top_cam", 20),
43 	GATE_CAM(CLK_CAM_MAIN_CAMSV_CQ_B, "cam_main_camsv_cq_b", "top_cam", 21),
44 	GATE_CAM(CLK_CAM_MAIN_CAMSV_CQ_C, "cam_main_camsv_cq_c", "top_cam", 22),
45 	GATE_CAM(CLK_CAM_MAIN_FAKE_ENG, "cam_main_fake_eng", "top_cam", 28),
46 	GATE_CAM(CLK_CAM_MAIN_CAM2MM0_GALS, "cam_main_cam2mm0_gals", "top_cam", 29),
47 	GATE_CAM(CLK_CAM_MAIN_CAM2MM1_GALS, "cam_main_cam2mm1_gals", "top_cam", 30),
48 	GATE_CAM(CLK_CAM_MAIN_CAM2SYS_GALS, "cam_main_cam2sys_gals", "top_cam", 31),
49 };
50 
51 static const struct mtk_gate cam_rawa_clks[] = {
52 	GATE_CAM(CLK_CAM_RAWA_LARBX, "cam_rawa_larbx", "top_cam", 0),
53 	GATE_CAM(CLK_CAM_RAWA_CAM, "cam_rawa_cam", "top_cam", 1),
54 	GATE_CAM(CLK_CAM_RAWA_CAMTG, "cam_rawa_camtg", "top_cam", 2),
55 };
56 
57 static const struct mtk_gate cam_rawb_clks[] = {
58 	GATE_CAM(CLK_CAM_RAWB_LARBX, "cam_rawb_larbx", "top_cam", 0),
59 	GATE_CAM(CLK_CAM_RAWB_CAM, "cam_rawb_cam", "top_cam", 1),
60 	GATE_CAM(CLK_CAM_RAWB_CAMTG, "cam_rawb_camtg", "top_cam", 2),
61 };
62 
63 static const struct mtk_gate cam_yuva_clks[] = {
64 	GATE_CAM(CLK_CAM_YUVA_LARBX, "cam_yuva_larbx", "top_cam", 0),
65 	GATE_CAM(CLK_CAM_YUVA_CAM, "cam_yuva_cam", "top_cam", 1),
66 	GATE_CAM(CLK_CAM_YUVA_CAMTG, "cam_yuva_camtg", "top_cam", 2),
67 };
68 
69 static const struct mtk_gate cam_yuvb_clks[] = {
70 	GATE_CAM(CLK_CAM_YUVB_LARBX, "cam_yuvb_larbx", "top_cam", 0),
71 	GATE_CAM(CLK_CAM_YUVB_CAM, "cam_yuvb_cam", "top_cam", 1),
72 	GATE_CAM(CLK_CAM_YUVB_CAMTG, "cam_yuvb_camtg", "top_cam", 2),
73 };
74 
75 static const struct mtk_clk_desc cam_main_desc = {
76 	.clks = cam_main_clks,
77 	.num_clks = ARRAY_SIZE(cam_main_clks),
78 };
79 
80 static const struct mtk_clk_desc cam_rawa_desc = {
81 	.clks = cam_rawa_clks,
82 	.num_clks = ARRAY_SIZE(cam_rawa_clks),
83 };
84 
85 static const struct mtk_clk_desc cam_rawb_desc = {
86 	.clks = cam_rawb_clks,
87 	.num_clks = ARRAY_SIZE(cam_rawb_clks),
88 };
89 
90 static const struct mtk_clk_desc cam_yuva_desc = {
91 	.clks = cam_yuva_clks,
92 	.num_clks = ARRAY_SIZE(cam_yuva_clks),
93 };
94 
95 static const struct mtk_clk_desc cam_yuvb_desc = {
96 	.clks = cam_yuvb_clks,
97 	.num_clks = ARRAY_SIZE(cam_yuvb_clks),
98 };
99 
100 static const struct of_device_id of_match_clk_mt8188_cam[] = {
101 	{ .compatible = "mediatek,mt8188-camsys", .data = &cam_main_desc },
102 	{ .compatible = "mediatek,mt8188-camsys-rawa", .data = &cam_rawa_desc },
103 	{ .compatible = "mediatek,mt8188-camsys-rawb", .data = &cam_rawb_desc },
104 	{ .compatible = "mediatek,mt8188-camsys-yuva", .data = &cam_yuva_desc },
105 	{ .compatible = "mediatek,mt8188-camsys-yuvb", .data = &cam_yuvb_desc },
106 	{ /* sentinel */ }
107 };
108 MODULE_DEVICE_TABLE(of, of_match_clk_mt8188_cam);
109 
110 static struct platform_driver clk_mt8188_cam_drv = {
111 	.probe = mtk_clk_simple_probe,
112 	.remove = mtk_clk_simple_remove,
113 	.driver = {
114 		.name = "clk-mt8188-cam",
115 		.of_match_table = of_match_clk_mt8188_cam,
116 	},
117 };
118 module_platform_driver(clk_mt8188_cam_drv);
119 
120 MODULE_DESCRIPTION("MediaTek MT8188 Camera clocks driver");
121 MODULE_LICENSE("GPL");
122