// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2022 MediaTek Inc.
* Author: Garmin Chang <garmin.chang@mediatek.com>
*/
#include <dt-bindings/clock/mediatek,mt8188-clk.h>
#include <linux/mod_devicetable.h>
#include <linux/platform_device.h>
#include "clk-gate.h"
#include "clk-mtk.h"
#include "clk-pll.h"
static const struct mtk_gate_regs apmixed_cg_regs = {
.set_ofs = 0 x8,
.clr_ofs = 0 x8,
.sta_ofs = 0 x8,
};
#define GATE_APMIXED(_id, _name, _parent, _shift) \
GATE_MTK(_id, _name, _parent, &apmixed_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
static const struct mtk_gate apmixed_clks[] = {
GATE_APMIXED(CLK_APMIXED_PLL_SSUSB26M_EN, "pll_ssusb26m_en" , "clk26m" , 1 ),
};
#define MT8188_PLL_FMAX (3800 UL * MHZ)
#define MT8188_PLL_FMIN (1500 UL * MHZ)
#define MT8188_INTEGER_BITS 8
#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
_rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
_tuner_reg, _tuner_en_reg, _tuner_en_bit, \
_pcw_reg, _pcw_shift, _pcw_chg_reg, \
_en_reg, _pll_en_bit) { \
.id = _id, \
.name = _name, \
.reg = _reg, \
.pwr_reg = _pwr_reg, \
.en_mask = _en_mask, \
.flags = _flags, \
.rst_bar_mask = _rst_bar_mask, \
.fmax = MT8188_PLL_FMAX, \
.fmin = MT8188_PLL_FMIN, \
.pcwbits = _pcwbits, \
.pcwibits = MT8188_INTEGER_BITS, \
.pd_reg = _pd_reg, \
.pd_shift = _pd_shift, \
.tuner_reg = _tuner_reg, \
.tuner_en_reg = _tuner_en_reg, \
.tuner_en_bit = _tuner_en_bit, \
.pcw_reg = _pcw_reg, \
.pcw_shift = _pcw_shift, \
.pcw_chg_reg = _pcw_chg_reg, \
.en_reg = _en_reg, \
.pll_en_bit = _pll_en_bit, \
}
static const struct mtk_pll_data plls[] = {
PLL(CLK_APMIXED_ETHPLL, "ethpll" , 0 x044C, 0 x0458, 0 ,
0 , 0 , 22 , 0 x0450, 24 , 0 , 0 , 0 , 0 x0450, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_MSDCPLL, "msdcpll" , 0 x0514, 0 x0520, 0 ,
0 , 0 , 22 , 0 x0518, 24 , 0 , 0 , 0 , 0 x0518, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_TVDPLL1, "tvdpll1" , 0 x0524, 0 x0530, 0 ,
0 , 0 , 22 , 0 x0528, 24 , 0 , 0 , 0 , 0 x0528, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_TVDPLL2, "tvdpll2" , 0 x0534, 0 x0540, 0 ,
0 , 0 , 22 , 0 x0538, 24 , 0 , 0 , 0 , 0 x0538, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_MMPLL, "mmpll" , 0 x0544, 0 x0550, 0 xff000000,
HAVE_RST_BAR, BIT(23 ), 22 , 0 x0548, 24 , 0 , 0 , 0 , 0 x0548, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_MAINPLL, "mainpll" , 0 x045C, 0 x0468, 0 xff000000,
HAVE_RST_BAR, BIT(23 ), 22 , 0 x0460, 24 , 0 , 0 , 0 , 0 x0460, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_IMGPLL, "imgpll" , 0 x0554, 0 x0560, 0 ,
0 , 0 , 22 , 0 x0558, 24 , 0 , 0 , 0 , 0 x0558, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_UNIVPLL, "univpll" , 0 x0504, 0 x0510, 0 xff000000,
HAVE_RST_BAR, BIT(23 ), 22 , 0 x0508, 24 , 0 , 0 , 0 , 0 x0508, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_ADSPPLL, "adsppll" , 0 x042C, 0 x0438, 0 ,
0 , 0 , 22 , 0 x0430, 24 , 0 , 0 , 0 , 0 x0430, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_APLL1, "apll1" , 0 x0304, 0 x0314, 0 ,
0 , 0 , 32 , 0 x0308, 24 , 0 x0034, 0 x0000, 12 , 0 x030C, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_APLL2, "apll2" , 0 x0318, 0 x0328, 0 ,
0 , 0 , 32 , 0 x031C, 24 , 0 x0038, 0 x0000, 13 , 0 x0320, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_APLL3, "apll3" , 0 x032C, 0 x033C, 0 ,
0 , 0 , 32 , 0 x0330, 24 , 0 x003C, 0 x0000, 14 , 0 x0334, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_APLL4, "apll4" , 0 x0404, 0 x0414, 0 ,
0 , 0 , 32 , 0 x0408, 24 , 0 x0040, 0 x0000, 15 , 0 x040C, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_APLL5, "apll5" , 0 x0418, 0 x0428, 0 ,
0 , 0 , 32 , 0 x041C, 24 , 0 x0044, 0 x0000, 16 , 0 x0420, 0 , 0 , 0 , 9 ),
PLL(CLK_APMIXED_MFGPLL, "mfgpll" , 0 x0340, 0 x034C, 0 ,
0 , 0 , 22 , 0 x0344, 24 , 0 , 0 , 0 , 0 x0344, 0 , 0 , 0 , 9 ),
};
static const struct of_device_id of_match_clk_mt8188_apmixed[] = {
{ .compatible = "mediatek,mt8188-apmixedsys" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8188_apmixed);
static int clk_mt8188_apmixed_probe(struct platform_device *pdev)
{
struct clk_hw_onecell_data *clk_data;
struct device_node *node = pdev->dev.of_node;
int r;
clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
if (!clk_data)
return -ENOMEM;
r = mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
if (r)
goto free_apmixed_data;
r = mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
ARRAY_SIZE(apmixed_clks), clk_data);
if (r)
goto unregister_plls;
r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
if (r)
goto unregister_gates;
platform_set_drvdata(pdev, clk_data);
return 0 ;
unregister_gates:
mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
unregister_plls:
mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
free_apmixed_data:
mtk_free_clk_data(clk_data);
return r;
}
static void clk_mt8188_apmixed_remove(struct platform_device *pdev)
{
struct device_node *node = pdev->dev.of_node;
struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
of_clk_del_provider(node);
mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
mtk_free_clk_data(clk_data);
}
static struct platform_driver clk_mt8188_apmixed_drv = {
.probe = clk_mt8188_apmixed_probe,
.remove = clk_mt8188_apmixed_remove,
.driver = {
.name = "clk-mt8188-apmixed" ,
.of_match_table = of_match_clk_mt8188_apmixed,
},
};
module_platform_driver(clk_mt8188_apmixed_drv);
MODULE_DESCRIPTION("MediaTek MT8188 apmixedsys clocks driver" );
MODULE_LICENSE("GPL" );
Messung V0.5 in Prozent C=93 H=96 G=94