18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2017 MediaTek Inc. 48c2ecf20Sopenharmony_ci * Author: Kevin-CW Chen <kevin-cw.chen@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/mt6797-clk.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs vdec0_cg_regs = { 168c2ecf20Sopenharmony_ci .set_ofs = 0x0000, 178c2ecf20Sopenharmony_ci .clr_ofs = 0x0004, 188c2ecf20Sopenharmony_ci .sta_ofs = 0x0000, 198c2ecf20Sopenharmony_ci}; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs vdec1_cg_regs = { 228c2ecf20Sopenharmony_ci .set_ofs = 0x0008, 238c2ecf20Sopenharmony_ci .clr_ofs = 0x000c, 248c2ecf20Sopenharmony_ci .sta_ofs = 0x0008, 258c2ecf20Sopenharmony_ci}; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define GATE_VDEC0(_id, _name, _parent, _shift) { \ 288c2ecf20Sopenharmony_ci .id = _id, \ 298c2ecf20Sopenharmony_ci .name = _name, \ 308c2ecf20Sopenharmony_ci .parent_name = _parent, \ 318c2ecf20Sopenharmony_ci .regs = &vdec0_cg_regs, \ 328c2ecf20Sopenharmony_ci .shift = _shift, \ 338c2ecf20Sopenharmony_ci .ops = &mtk_clk_gate_ops_setclr_inv, \ 348c2ecf20Sopenharmony_ci} 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define GATE_VDEC1(_id, _name, _parent, _shift) { \ 378c2ecf20Sopenharmony_ci .id = _id, \ 388c2ecf20Sopenharmony_ci .name = _name, \ 398c2ecf20Sopenharmony_ci .parent_name = _parent, \ 408c2ecf20Sopenharmony_ci .regs = &vdec1_cg_regs, \ 418c2ecf20Sopenharmony_ci .shift = _shift, \ 428c2ecf20Sopenharmony_ci .ops = &mtk_clk_gate_ops_setclr_inv, \ 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic const struct mtk_gate vdec_clks[] = { 468c2ecf20Sopenharmony_ci GATE_VDEC0(CLK_VDEC_CKEN_ENG, "vdec_cken_eng", "vdec_sel", 8), 478c2ecf20Sopenharmony_ci GATE_VDEC0(CLK_VDEC_ACTIVE, "vdec_active", "vdec_sel", 4), 488c2ecf20Sopenharmony_ci GATE_VDEC0(CLK_VDEC_CKEN, "vdec_cken", "vdec_sel", 0), 498c2ecf20Sopenharmony_ci GATE_VDEC1(CLK_VDEC_LARB1_CKEN, "vdec_larb1_cken", "mm_sel", 0), 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic const struct of_device_id of_match_clk_mt6797_vdec[] = { 538c2ecf20Sopenharmony_ci { .compatible = "mediatek,mt6797-vdecsys", }, 548c2ecf20Sopenharmony_ci {} 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic int clk_mt6797_vdec_probe(struct platform_device *pdev) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci struct clk_onecell_data *clk_data; 608c2ecf20Sopenharmony_ci int r; 618c2ecf20Sopenharmony_ci struct device_node *node = pdev->dev.of_node; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci clk_data = mtk_alloc_clk_data(CLK_VDEC_NR); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci mtk_clk_register_gates(node, vdec_clks, ARRAY_SIZE(vdec_clks), 668c2ecf20Sopenharmony_ci clk_data); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); 698c2ecf20Sopenharmony_ci if (r) 708c2ecf20Sopenharmony_ci dev_err(&pdev->dev, 718c2ecf20Sopenharmony_ci "could not register clock provider: %s: %d\n", 728c2ecf20Sopenharmony_ci pdev->name, r); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci return r; 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic struct platform_driver clk_mt6797_vdec_drv = { 788c2ecf20Sopenharmony_ci .probe = clk_mt6797_vdec_probe, 798c2ecf20Sopenharmony_ci .driver = { 808c2ecf20Sopenharmony_ci .name = "clk-mt6797-vdec", 818c2ecf20Sopenharmony_ci .of_match_table = of_match_clk_mt6797_vdec, 828c2ecf20Sopenharmony_ci }, 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cibuiltin_platform_driver(clk_mt6797_vdec_drv); 86