1813c3b53SDaniel Golle // SPDX-License-Identifier: GPL-2.0
2813c3b53SDaniel Golle /*
3813c3b53SDaniel Golle * Copyright (c) 2021 MediaTek Inc.
4813c3b53SDaniel Golle * Author: Sam Shih <sam.shih@mediatek.com>
5813c3b53SDaniel Golle * Author: Wenzhen Yu <wenzhen.yu@mediatek.com>
6813c3b53SDaniel Golle * Author: Jianhui Zhao <zhaojh329@gmail.com>
7813c3b53SDaniel Golle * Author: Daniel Golle <daniel@makrotopia.org>
8813c3b53SDaniel Golle */
9813c3b53SDaniel Golle
10813c3b53SDaniel Golle #include <linux/clk-provider.h>
11*a96cbb14SRob Herring #include <linux/mod_devicetable.h>
12813c3b53SDaniel Golle #include <linux/platform_device.h>
13813c3b53SDaniel Golle
14813c3b53SDaniel Golle #include "clk-gate.h"
15813c3b53SDaniel Golle #include "clk-mtk.h"
16813c3b53SDaniel Golle #include "clk-mux.h"
17813c3b53SDaniel Golle #include "clk-pll.h"
18813c3b53SDaniel Golle
19813c3b53SDaniel Golle #include <dt-bindings/clock/mediatek,mt7981-clk.h>
20813c3b53SDaniel Golle #include <linux/clk.h>
21813c3b53SDaniel Golle
22813c3b53SDaniel Golle #define MT7981_PLL_FMAX (2500UL * MHZ)
23813c3b53SDaniel Golle #define CON0_MT7981_RST_BAR BIT(27)
24813c3b53SDaniel Golle
25813c3b53SDaniel Golle #define PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
26813c3b53SDaniel Golle _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
27813c3b53SDaniel Golle _div_table, _parent_name) \
28813c3b53SDaniel Golle { \
29813c3b53SDaniel Golle .id = _id, .name = _name, .reg = _reg, .pwr_reg = _pwr_reg, \
30813c3b53SDaniel Golle .en_mask = _en_mask, .flags = _flags, \
31813c3b53SDaniel Golle .rst_bar_mask = CON0_MT7981_RST_BAR, .fmax = MT7981_PLL_FMAX, \
32813c3b53SDaniel Golle .pcwbits = _pcwbits, .pd_reg = _pd_reg, .pd_shift = _pd_shift, \
33813c3b53SDaniel Golle .tuner_reg = _tuner_reg, .pcw_reg = _pcw_reg, \
34813c3b53SDaniel Golle .pcw_shift = _pcw_shift, .div_table = _div_table, \
35813c3b53SDaniel Golle .parent_name = _parent_name, \
36813c3b53SDaniel Golle }
37813c3b53SDaniel Golle
38813c3b53SDaniel Golle #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, \
39813c3b53SDaniel Golle _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift) \
40813c3b53SDaniel Golle PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
41813c3b53SDaniel Golle _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, NULL, \
42813c3b53SDaniel Golle "clkxtal")
43813c3b53SDaniel Golle
44813c3b53SDaniel Golle static const struct mtk_pll_data plls[] = {
45813c3b53SDaniel Golle PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0200, 0x020C, 0x00000001, PLL_AO,
46813c3b53SDaniel Golle 32, 0x0200, 4, 0, 0x0204, 0),
47813c3b53SDaniel Golle PLL(CLK_APMIXED_NET2PLL, "net2pll", 0x0210, 0x021C, 0x00000001, 0, 32,
48813c3b53SDaniel Golle 0x0210, 4, 0, 0x0214, 0),
49813c3b53SDaniel Golle PLL(CLK_APMIXED_MMPLL, "mmpll", 0x0220, 0x022C, 0x00000001, 0, 32,
50813c3b53SDaniel Golle 0x0220, 4, 0, 0x0224, 0),
51813c3b53SDaniel Golle PLL(CLK_APMIXED_SGMPLL, "sgmpll", 0x0230, 0x023C, 0x00000001, 0, 32,
52813c3b53SDaniel Golle 0x0230, 4, 0, 0x0234, 0),
53813c3b53SDaniel Golle PLL(CLK_APMIXED_WEDMCUPLL, "wedmcupll", 0x0240, 0x024C, 0x00000001, 0, 32,
54813c3b53SDaniel Golle 0x0240, 4, 0, 0x0244, 0),
55813c3b53SDaniel Golle PLL(CLK_APMIXED_NET1PLL, "net1pll", 0x0250, 0x025C, 0x00000001, 0, 32,
56813c3b53SDaniel Golle 0x0250, 4, 0, 0x0254, 0),
57813c3b53SDaniel Golle PLL(CLK_APMIXED_MPLL, "mpll", 0x0260, 0x0270, 0x00000001, 0, 32,
58813c3b53SDaniel Golle 0x0260, 4, 0, 0x0264, 0),
59813c3b53SDaniel Golle PLL(CLK_APMIXED_APLL2, "apll2", 0x0278, 0x0288, 0x00000001, 0, 32,
60813c3b53SDaniel Golle 0x0278, 4, 0, 0x027C, 0),
61813c3b53SDaniel Golle };
62813c3b53SDaniel Golle
63813c3b53SDaniel Golle static const struct of_device_id of_match_clk_mt7981_apmixed[] = {
64813c3b53SDaniel Golle { .compatible = "mediatek,mt7981-apmixedsys", },
65813c3b53SDaniel Golle { /* sentinel */ }
66813c3b53SDaniel Golle };
6765c9ad77SAngeloGioacchino Del Regno MODULE_DEVICE_TABLE(of, of_match_clk_mt7981_apmixed);
68813c3b53SDaniel Golle
clk_mt7981_apmixed_probe(struct platform_device * pdev)69813c3b53SDaniel Golle static int clk_mt7981_apmixed_probe(struct platform_device *pdev)
70813c3b53SDaniel Golle {
71813c3b53SDaniel Golle struct clk_hw_onecell_data *clk_data;
72813c3b53SDaniel Golle struct device_node *node = pdev->dev.of_node;
73813c3b53SDaniel Golle int r;
74813c3b53SDaniel Golle
75813c3b53SDaniel Golle clk_data = mtk_alloc_clk_data(ARRAY_SIZE(plls));
76813c3b53SDaniel Golle if (!clk_data)
77813c3b53SDaniel Golle return -ENOMEM;
78813c3b53SDaniel Golle
79813c3b53SDaniel Golle mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
80813c3b53SDaniel Golle
81813c3b53SDaniel Golle r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
82813c3b53SDaniel Golle if (r) {
83813c3b53SDaniel Golle pr_err("%s(): could not register clock provider: %d\n",
84813c3b53SDaniel Golle __func__, r);
85813c3b53SDaniel Golle goto free_apmixed_data;
86813c3b53SDaniel Golle }
87813c3b53SDaniel Golle return r;
88813c3b53SDaniel Golle
89813c3b53SDaniel Golle free_apmixed_data:
90813c3b53SDaniel Golle mtk_free_clk_data(clk_data);
91813c3b53SDaniel Golle return r;
92813c3b53SDaniel Golle }
93813c3b53SDaniel Golle
94813c3b53SDaniel Golle static struct platform_driver clk_mt7981_apmixed_drv = {
95813c3b53SDaniel Golle .probe = clk_mt7981_apmixed_probe,
96813c3b53SDaniel Golle .driver = {
97813c3b53SDaniel Golle .name = "clk-mt7981-apmixed",
98813c3b53SDaniel Golle .of_match_table = of_match_clk_mt7981_apmixed,
99813c3b53SDaniel Golle },
100813c3b53SDaniel Golle };
101813c3b53SDaniel Golle builtin_platform_driver(clk_mt7981_apmixed_drv);
102a451da86SAngeloGioacchino Del Regno MODULE_LICENSE("GPL");
103