162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2022 MediaTek Inc. 462306a36Sopenharmony_ci * Copyright (c) 2023 Collabora Ltd. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include <dt-bindings/clock/mediatek,mt8365-clk.h> 862306a36Sopenharmony_ci#include <linux/clk.h> 962306a36Sopenharmony_ci#include <linux/of.h> 1062306a36Sopenharmony_ci#include <linux/platform_device.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include "clk-pll.h" 1362306a36Sopenharmony_ci#include "clk-mtk.h" 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#define MT8365_PLL_FMAX (3800UL * MHZ) 1662306a36Sopenharmony_ci#define MT8365_PLL_FMIN (1500UL * MHZ) 1762306a36Sopenharmony_ci#define CON0_MT8365_RST_BAR BIT(23) 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \ 2062306a36Sopenharmony_ci _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \ 2162306a36Sopenharmony_ci _tuner_en_bit, _pcw_reg, _pcw_shift, _div_table, \ 2262306a36Sopenharmony_ci _rst_bar_mask, _pcw_chg_reg) { \ 2362306a36Sopenharmony_ci .id = _id, \ 2462306a36Sopenharmony_ci .name = _name, \ 2562306a36Sopenharmony_ci .reg = _reg, \ 2662306a36Sopenharmony_ci .pwr_reg = _pwr_reg, \ 2762306a36Sopenharmony_ci .en_mask = _en_mask, \ 2862306a36Sopenharmony_ci .flags = _flags, \ 2962306a36Sopenharmony_ci .rst_bar_mask = _rst_bar_mask, \ 3062306a36Sopenharmony_ci .fmax = MT8365_PLL_FMAX, \ 3162306a36Sopenharmony_ci .fmin = MT8365_PLL_FMIN, \ 3262306a36Sopenharmony_ci .pcwbits = _pcwbits, \ 3362306a36Sopenharmony_ci .pcwibits = 8, \ 3462306a36Sopenharmony_ci .pd_reg = _pd_reg, \ 3562306a36Sopenharmony_ci .pd_shift = _pd_shift, \ 3662306a36Sopenharmony_ci .tuner_reg = _tuner_reg, \ 3762306a36Sopenharmony_ci .tuner_en_reg = _tuner_en_reg, \ 3862306a36Sopenharmony_ci .tuner_en_bit = _tuner_en_bit, \ 3962306a36Sopenharmony_ci .pcw_reg = _pcw_reg, \ 4062306a36Sopenharmony_ci .pcw_shift = _pcw_shift, \ 4162306a36Sopenharmony_ci .pcw_chg_reg = _pcw_chg_reg, \ 4262306a36Sopenharmony_ci .div_table = _div_table, \ 4362306a36Sopenharmony_ci } 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \ 4662306a36Sopenharmony_ci _pd_reg, _pd_shift, _tuner_reg, \ 4762306a36Sopenharmony_ci _tuner_en_reg, _tuner_en_bit, _pcw_reg, \ 4862306a36Sopenharmony_ci _pcw_shift, _rst_bar_mask, _pcw_chg_reg) \ 4962306a36Sopenharmony_ci PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \ 5062306a36Sopenharmony_ci _pcwbits, _pd_reg, _pd_shift, \ 5162306a36Sopenharmony_ci _tuner_reg, _tuner_en_reg, _tuner_en_bit, \ 5262306a36Sopenharmony_ci _pcw_reg, _pcw_shift, NULL, _rst_bar_mask, \ 5362306a36Sopenharmony_ci _pcw_chg_reg) \ 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_cistatic const struct mtk_pll_div_table armpll_div_table[] = { 5662306a36Sopenharmony_ci { .div = 0, .freq = MT8365_PLL_FMAX }, 5762306a36Sopenharmony_ci { .div = 1, .freq = 1500 * MHZ }, 5862306a36Sopenharmony_ci { .div = 2, .freq = 750 * MHZ }, 5962306a36Sopenharmony_ci { .div = 3, .freq = 375 * MHZ }, 6062306a36Sopenharmony_ci { .div = 4, .freq = 182500000 }, 6162306a36Sopenharmony_ci { } /* sentinel */ 6262306a36Sopenharmony_ci}; 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_cistatic const struct mtk_pll_div_table mfgpll_div_table[] = { 6562306a36Sopenharmony_ci { .div = 0, .freq = MT8365_PLL_FMAX }, 6662306a36Sopenharmony_ci { .div = 1, .freq = 1600 * MHZ }, 6762306a36Sopenharmony_ci { .div = 2, .freq = 800 * MHZ }, 6862306a36Sopenharmony_ci { .div = 3, .freq = 400 * MHZ }, 6962306a36Sopenharmony_ci { .div = 4, .freq = 200 * MHZ }, 7062306a36Sopenharmony_ci { } /* sentinel */ 7162306a36Sopenharmony_ci}; 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_cistatic const struct mtk_pll_div_table dsppll_div_table[] = { 7462306a36Sopenharmony_ci { .div = 0, .freq = MT8365_PLL_FMAX }, 7562306a36Sopenharmony_ci { .div = 1, .freq = 1600 * MHZ }, 7662306a36Sopenharmony_ci { .div = 2, .freq = 600 * MHZ }, 7762306a36Sopenharmony_ci { .div = 3, .freq = 400 * MHZ }, 7862306a36Sopenharmony_ci { .div = 4, .freq = 200 * MHZ }, 7962306a36Sopenharmony_ci { } /* sentinel */ 8062306a36Sopenharmony_ci}; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_cistatic const struct mtk_pll_data plls[] = { 8362306a36Sopenharmony_ci PLL_B(CLK_APMIXED_ARMPLL, "armpll", 0x030C, 0x0318, 0x00000001, PLL_AO, 8462306a36Sopenharmony_ci 22, 0x0310, 24, 0, 0, 0, 0x0310, 0, armpll_div_table, 0, 0), 8562306a36Sopenharmony_ci PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0228, 0x0234, 0xFF000001, 8662306a36Sopenharmony_ci HAVE_RST_BAR, 22, 0x022C, 24, 0, 0, 0, 0x022C, 0, CON0_MT8365_RST_BAR, 0), 8762306a36Sopenharmony_ci PLL(CLK_APMIXED_UNIVPLL, "univpll2", 0x0208, 0x0214, 0xFF000001, 8862306a36Sopenharmony_ci HAVE_RST_BAR, 22, 0x020C, 24, 0, 0, 0, 0x020C, 0, CON0_MT8365_RST_BAR, 0), 8962306a36Sopenharmony_ci PLL_B(CLK_APMIXED_MFGPLL, "mfgpll", 0x0218, 0x0224, 0x00000001, 0, 22, 9062306a36Sopenharmony_ci 0x021C, 24, 0, 0, 0, 0x021C, 0, mfgpll_div_table, 0, 0), 9162306a36Sopenharmony_ci PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0350, 0x035C, 0x00000001, 0, 22, 9262306a36Sopenharmony_ci 0x0354, 24, 0, 0, 0, 0x0354, 0, 0, 0), 9362306a36Sopenharmony_ci PLL(CLK_APMIXED_MMPLL, "mmpll", 0x0330, 0x033C, 0x00000001, 0, 22, 9462306a36Sopenharmony_ci 0x0334, 24, 0, 0, 0, 0x0334, 0, 0, 0), 9562306a36Sopenharmony_ci PLL(CLK_APMIXED_APLL1, "apll1", 0x031C, 0x032C, 0x00000001, 0, 32, 9662306a36Sopenharmony_ci 0x0320, 24, 0x0040, 0x000C, 0, 0x0324, 0, 0, 0x0320), 9762306a36Sopenharmony_ci PLL(CLK_APMIXED_APLL2, "apll2", 0x0360, 0x0370, 0x00000001, 0, 32, 9862306a36Sopenharmony_ci 0x0364, 24, 0x004C, 0x000C, 5, 0x0368, 0, 0, 0x0364), 9962306a36Sopenharmony_ci PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x0374, 0x0380, 0x00000001, 0, 22, 10062306a36Sopenharmony_ci 0x0378, 24, 0, 0, 0, 0x0378, 0, 0, 0), 10162306a36Sopenharmony_ci PLL_B(CLK_APMIXED_DSPPLL, "dsppll", 0x0390, 0x039C, 0x00000001, 0, 22, 10262306a36Sopenharmony_ci 0x0394, 24, 0, 0, 0, 0x0394, 0, dsppll_div_table, 0, 0), 10362306a36Sopenharmony_ci PLL(CLK_APMIXED_APUPLL, "apupll", 0x03A0, 0x03AC, 0x00000001, 0, 22, 10462306a36Sopenharmony_ci 0x03A4, 24, 0, 0, 0, 0x03A4, 0, 0, 0), 10562306a36Sopenharmony_ci}; 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_cistatic int clk_mt8365_apmixed_probe(struct platform_device *pdev) 10862306a36Sopenharmony_ci{ 10962306a36Sopenharmony_ci void __iomem *base; 11062306a36Sopenharmony_ci struct clk_hw_onecell_data *clk_data; 11162306a36Sopenharmony_ci struct device_node *node = pdev->dev.of_node; 11262306a36Sopenharmony_ci struct device *dev = &pdev->dev; 11362306a36Sopenharmony_ci struct clk_hw *hw; 11462306a36Sopenharmony_ci int ret; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci base = devm_platform_ioremap_resource(pdev, 0); 11762306a36Sopenharmony_ci if (IS_ERR(base)) 11862306a36Sopenharmony_ci return PTR_ERR(base); 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci clk_data = mtk_devm_alloc_clk_data(dev, CLK_APMIXED_NR_CLK); 12162306a36Sopenharmony_ci if (!clk_data) 12262306a36Sopenharmony_ci return -ENOMEM; 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci hw = devm_clk_hw_register_gate(dev, "univ_en", "univpll2", 0, 12562306a36Sopenharmony_ci base + 0x204, 0, 0, NULL); 12662306a36Sopenharmony_ci if (IS_ERR(hw)) 12762306a36Sopenharmony_ci return PTR_ERR(hw); 12862306a36Sopenharmony_ci clk_data->hws[CLK_APMIXED_UNIV_EN] = hw; 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci hw = devm_clk_hw_register_gate(dev, "usb20_en", "univ_en", 0, 13162306a36Sopenharmony_ci base + 0x204, 1, 0, NULL); 13262306a36Sopenharmony_ci if (IS_ERR(hw)) 13362306a36Sopenharmony_ci return PTR_ERR(hw); 13462306a36Sopenharmony_ci clk_data->hws[CLK_APMIXED_USB20_EN] = hw; 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci ret = mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data); 13762306a36Sopenharmony_ci if (ret) 13862306a36Sopenharmony_ci return ret; 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data); 14162306a36Sopenharmony_ci if (ret) 14262306a36Sopenharmony_ci goto unregister_plls; 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci return 0; 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ciunregister_plls: 14762306a36Sopenharmony_ci mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data); 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci return ret; 15062306a36Sopenharmony_ci} 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_cistatic const struct of_device_id of_match_clk_mt8365_apmixed[] = { 15362306a36Sopenharmony_ci { .compatible = "mediatek,mt8365-apmixedsys" }, 15462306a36Sopenharmony_ci { /* sentinel */ } 15562306a36Sopenharmony_ci}; 15662306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, of_match_clk_mt8365_apmixed); 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_cistatic struct platform_driver clk_mt8365_apmixed_drv = { 15962306a36Sopenharmony_ci .probe = clk_mt8365_apmixed_probe, 16062306a36Sopenharmony_ci .driver = { 16162306a36Sopenharmony_ci .name = "clk-mt8365-apmixed", 16262306a36Sopenharmony_ci .of_match_table = of_match_clk_mt8365_apmixed, 16362306a36Sopenharmony_ci }, 16462306a36Sopenharmony_ci}; 16562306a36Sopenharmony_cibuiltin_platform_driver(clk_mt8365_apmixed_drv) 16662306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 167