18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci//
38c2ecf20Sopenharmony_ci// Copyright (c) 2018 MediaTek Inc.
48c2ecf20Sopenharmony_ci// Author: Weiyi Lu <weiyi.lu@mediatek.com>
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
78c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "clk-mtk.h"
108c2ecf20Sopenharmony_ci#include "clk-gate.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <dt-bindings/clock/mt8183-clk.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs cam_cg_regs = {
158c2ecf20Sopenharmony_ci	.set_ofs = 0x4,
168c2ecf20Sopenharmony_ci	.clr_ofs = 0x8,
178c2ecf20Sopenharmony_ci	.sta_ofs = 0x0,
188c2ecf20Sopenharmony_ci};
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define GATE_CAM(_id, _name, _parent, _shift)			\
218c2ecf20Sopenharmony_ci	GATE_MTK(_id, _name, _parent, &cam_cg_regs, _shift,	\
228c2ecf20Sopenharmony_ci		&mtk_clk_gate_ops_setclr)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic const struct mtk_gate cam_clks[] = {
258c2ecf20Sopenharmony_ci	GATE_CAM(CLK_CAM_LARB6, "cam_larb6", "cam_sel", 0),
268c2ecf20Sopenharmony_ci	GATE_CAM(CLK_CAM_DFP_VAD, "cam_dfp_vad", "cam_sel", 1),
278c2ecf20Sopenharmony_ci	GATE_CAM(CLK_CAM_LARB3, "cam_larb3", "cam_sel", 2),
288c2ecf20Sopenharmony_ci	GATE_CAM(CLK_CAM_CAM, "cam_cam", "cam_sel", 6),
298c2ecf20Sopenharmony_ci	GATE_CAM(CLK_CAM_CAMTG, "cam_camtg", "cam_sel", 7),
308c2ecf20Sopenharmony_ci	GATE_CAM(CLK_CAM_SENINF, "cam_seninf", "cam_sel", 8),
318c2ecf20Sopenharmony_ci	GATE_CAM(CLK_CAM_CAMSV0, "cam_camsv0", "cam_sel", 9),
328c2ecf20Sopenharmony_ci	GATE_CAM(CLK_CAM_CAMSV1, "cam_camsv1", "cam_sel", 10),
338c2ecf20Sopenharmony_ci	GATE_CAM(CLK_CAM_CAMSV2, "cam_camsv2", "cam_sel", 11),
348c2ecf20Sopenharmony_ci	GATE_CAM(CLK_CAM_CCU, "cam_ccu", "cam_sel", 12),
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic int clk_mt8183_cam_probe(struct platform_device *pdev)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	struct clk_onecell_data *clk_data;
408c2ecf20Sopenharmony_ci	struct device_node *node = pdev->dev.of_node;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	clk_data = mtk_alloc_clk_data(CLK_CAM_NR_CLK);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	mtk_clk_register_gates(node, cam_clks, ARRAY_SIZE(cam_clks),
458c2ecf20Sopenharmony_ci			clk_data);
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
488c2ecf20Sopenharmony_ci}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic const struct of_device_id of_match_clk_mt8183_cam[] = {
518c2ecf20Sopenharmony_ci	{ .compatible = "mediatek,mt8183-camsys", },
528c2ecf20Sopenharmony_ci	{}
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic struct platform_driver clk_mt8183_cam_drv = {
568c2ecf20Sopenharmony_ci	.probe = clk_mt8183_cam_probe,
578c2ecf20Sopenharmony_ci	.driver = {
588c2ecf20Sopenharmony_ci		.name = "clk-mt8183-cam",
598c2ecf20Sopenharmony_ci		.of_match_table = of_match_clk_mt8183_cam,
608c2ecf20Sopenharmony_ci	},
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cibuiltin_platform_driver(clk_mt8183_cam_drv);
64