18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2020 MediaTek Inc. 48c2ecf20Sopenharmony_ci * Copyright (c) 2020 BayLibre, SAS 58c2ecf20Sopenharmony_ci * Author: James Liao <jamesjj.liao@mediatek.com> 68c2ecf20Sopenharmony_ci * Fabien Parent <fparent@baylibre.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 108c2ecf20Sopenharmony_ci#include <linux/of.h> 118c2ecf20Sopenharmony_ci#include <linux/of_address.h> 128c2ecf20Sopenharmony_ci#include <linux/of_device.h> 138c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include "clk-mtk.h" 168c2ecf20Sopenharmony_ci#include "clk-gate.h" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include <dt-bindings/clock/mt8167-clk.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs vdec0_cg_regs = { 218c2ecf20Sopenharmony_ci .set_ofs = 0x0, 228c2ecf20Sopenharmony_ci .clr_ofs = 0x4, 238c2ecf20Sopenharmony_ci .sta_ofs = 0x0, 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs vdec1_cg_regs = { 278c2ecf20Sopenharmony_ci .set_ofs = 0x8, 288c2ecf20Sopenharmony_ci .clr_ofs = 0xc, 298c2ecf20Sopenharmony_ci .sta_ofs = 0x8, 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define GATE_VDEC0_I(_id, _name, _parent, _shift) { \ 338c2ecf20Sopenharmony_ci .id = _id, \ 348c2ecf20Sopenharmony_ci .name = _name, \ 358c2ecf20Sopenharmony_ci .parent_name = _parent, \ 368c2ecf20Sopenharmony_ci .regs = &vdec0_cg_regs, \ 378c2ecf20Sopenharmony_ci .shift = _shift, \ 388c2ecf20Sopenharmony_ci .ops = &mtk_clk_gate_ops_setclr_inv, \ 398c2ecf20Sopenharmony_ci } 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define GATE_VDEC1_I(_id, _name, _parent, _shift) { \ 428c2ecf20Sopenharmony_ci .id = _id, \ 438c2ecf20Sopenharmony_ci .name = _name, \ 448c2ecf20Sopenharmony_ci .parent_name = _parent, \ 458c2ecf20Sopenharmony_ci .regs = &vdec1_cg_regs, \ 468c2ecf20Sopenharmony_ci .shift = _shift, \ 478c2ecf20Sopenharmony_ci .ops = &mtk_clk_gate_ops_setclr_inv, \ 488c2ecf20Sopenharmony_ci } 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic const struct mtk_gate vdec_clks[] __initconst = { 518c2ecf20Sopenharmony_ci /* VDEC0 */ 528c2ecf20Sopenharmony_ci GATE_VDEC0_I(CLK_VDEC_CKEN, "vdec_cken", "rg_vdec", 0), 538c2ecf20Sopenharmony_ci /* VDEC1 */ 548c2ecf20Sopenharmony_ci GATE_VDEC1_I(CLK_VDEC_LARB1_CKEN, "vdec_larb1_cken", "smi_mm", 0), 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic void __init mtk_vdecsys_init(struct device_node *node) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci struct clk_onecell_data *clk_data; 608c2ecf20Sopenharmony_ci int r; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci clk_data = mtk_alloc_clk_data(CLK_VDEC_NR_CLK); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci mtk_clk_register_gates(node, vdec_clks, ARRAY_SIZE(vdec_clks), clk_data); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci if (r) 698c2ecf20Sopenharmony_ci pr_err("%s(): could not register clock provider: %d\n", 708c2ecf20Sopenharmony_ci __func__, r); 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci} 738c2ecf20Sopenharmony_ciCLK_OF_DECLARE(mtk_vdecsys, "mediatek,mt8167-vdecsys", mtk_vdecsys_init); 74