1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 2020 MediaTek Inc.
4*4882a593Smuzhiyun * Copyright (c) 2020 BayLibre, SAS
5*4882a593Smuzhiyun * Author: James Liao <jamesjj.liao@mediatek.com>
6*4882a593Smuzhiyun * Fabien Parent <fparent@baylibre.com>
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/clk-provider.h>
10*4882a593Smuzhiyun #include <linux/of.h>
11*4882a593Smuzhiyun #include <linux/of_address.h>
12*4882a593Smuzhiyun #include <linux/of_device.h>
13*4882a593Smuzhiyun #include <linux/platform_device.h>
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include "clk-mtk.h"
16*4882a593Smuzhiyun #include "clk-gate.h"
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #include <dt-bindings/clock/mt8167-clk.h>
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun static const struct mtk_gate_regs mfg_cg_regs = {
21*4882a593Smuzhiyun .set_ofs = 0x4,
22*4882a593Smuzhiyun .clr_ofs = 0x8,
23*4882a593Smuzhiyun .sta_ofs = 0x0,
24*4882a593Smuzhiyun };
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #define GATE_MFG(_id, _name, _parent, _shift) { \
27*4882a593Smuzhiyun .id = _id, \
28*4882a593Smuzhiyun .name = _name, \
29*4882a593Smuzhiyun .parent_name = _parent, \
30*4882a593Smuzhiyun .regs = &mfg_cg_regs, \
31*4882a593Smuzhiyun .shift = _shift, \
32*4882a593Smuzhiyun .ops = &mtk_clk_gate_ops_setclr, \
33*4882a593Smuzhiyun }
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun static const struct mtk_gate mfg_clks[] __initconst = {
36*4882a593Smuzhiyun GATE_MFG(CLK_MFG_BAXI, "mfg_baxi", "ahb_infra_sel", 0),
37*4882a593Smuzhiyun GATE_MFG(CLK_MFG_BMEM, "mfg_bmem", "gfmux_emi1x_sel", 1),
38*4882a593Smuzhiyun GATE_MFG(CLK_MFG_BG3D, "mfg_bg3d", "mfg_mm", 2),
39*4882a593Smuzhiyun GATE_MFG(CLK_MFG_B26M, "mfg_b26m", "clk26m_ck", 3),
40*4882a593Smuzhiyun };
41*4882a593Smuzhiyun
mtk_mfgcfg_init(struct device_node * node)42*4882a593Smuzhiyun static void __init mtk_mfgcfg_init(struct device_node *node)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun struct clk_onecell_data *clk_data;
45*4882a593Smuzhiyun int r;
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun clk_data = mtk_alloc_clk_data(CLK_MFG_NR_CLK);
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun mtk_clk_register_gates(node, mfg_clks, ARRAY_SIZE(mfg_clks), clk_data);
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun if (r)
54*4882a593Smuzhiyun pr_err("%s(): could not register clock provider: %d\n",
55*4882a593Smuzhiyun __func__, r);
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun CLK_OF_DECLARE(mtk_mfgcfg, "mediatek,mt8167-mfgcfg", mtk_mfgcfg_init);
59