blob: 62717e7a72acc8902ec38cbd9d571f774bad20fd [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2019 MediaTek Inc.
4 */
5
6#include <linux/clk-provider.h>
7#include <linux/platform_device.h>
8
9#include "clk-mtk.h"
10#include "clk-gate.h"
11
12#include <dt-bindings/clock/mt8168-clk.h>
13
14static const struct mtk_gate_regs apu_cg_regs = {
15 .set_ofs = 0x4,
16 .clr_ofs = 0x8,
17 .sta_ofs = 0x0,
18};
19
20#define GATE_APU(_id, _name, _parent, _shift) { \
21 .id = _id, \
22 .name = _name, \
23 .parent_name = _parent, \
24 .regs = &apu_cg_regs, \
25 .shift = _shift, \
26 .ops = &mtk_clk_gate_ops_setclr, \
27 }
28
29static const struct mtk_gate apu_clks[] = {
30 GATE_APU(CLK_APU_AHB, "apu_ahb", "ifr_apu_axi", 5),
31 GATE_APU(CLK_APU_EDMA, "apu_edma", "apu_sel", 4),
32 GATE_APU(CLK_APU_IF_CK, "apu_if_ck", "apu_if_sel", 3),
33 GATE_APU(CLK_APU_JTAG, "apu_jtag", "clk26m_ck", 2),
34 GATE_APU(CLK_APU_AXI, "apu_axi", "apu_sel", 1),
35 GATE_APU(CLK_APU_IPU_CK, "apu_ck", "apu_sel", 0),
36};
37
38static int clk_mt8168_apu_probe(struct platform_device *pdev)
39{
40 struct clk_onecell_data *clk_data;
41 int r;
42 struct device_node *node = pdev->dev.of_node;
43
44 clk_data = mtk_alloc_clk_data(CLK_APU_NR_CLK);
45
46 mtk_clk_register_gates(node, apu_clks, ARRAY_SIZE(apu_clks),
47 clk_data);
48
49 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
50
51 if (r)
52 pr_err("%s(): could not register clock provider: %d\n",
53 __func__, r);
54
55 return r;
56}
57
58static const struct of_device_id of_match_clk_mt8168_apu[] = {
59 { .compatible = "mediatek,mt8168-apu", },
60 {}
61};
62
63static struct platform_driver clk_mt8168_apu_drv = {
64 .probe = clk_mt8168_apu_probe,
65 .driver = {
66 .name = "clk-mt8168-apu",
67 .of_match_table = of_match_clk_mt8168_apu,
68 },
69};
70
71builtin_platform_driver(clk_mt8168_apu_drv);